2010-06-09 00:52:24 +08:00
|
|
|
//===-- DisassemblerLLVM.cpp ------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "DisassemblerLLVM.h"
|
|
|
|
|
|
|
|
#include "llvm-c/EnhancedDisassembly.h"
|
|
|
|
|
|
|
|
#include "lldb/Core/Address.h"
|
|
|
|
#include "lldb/Core/DataExtractor.h"
|
|
|
|
#include "lldb/Core/Disassembler.h"
|
|
|
|
#include "lldb/Core/Module.h"
|
|
|
|
#include "lldb/Core/PluginManager.h"
|
|
|
|
#include "lldb/Core/Stream.h"
|
|
|
|
#include "lldb/Core/StreamString.h"
|
|
|
|
#include "lldb/Symbol/SymbolContext.h"
|
|
|
|
|
|
|
|
#include "lldb/Target/ExecutionContext.h"
|
|
|
|
#include "lldb/Target/Process.h"
|
|
|
|
#include "lldb/Target/RegisterContext.h"
|
|
|
|
#include "lldb/Target/Target.h"
|
|
|
|
|
A few of the issue I have been trying to track down and fix have been due to
the way LLDB lazily gets complete definitions for types within the debug info.
When we run across a class/struct/union definition in the DWARF, we will only
parse the full definition if we need to. This works fine for top level types
that are assigned directly to variables and arguments, but when we have a
variable with a class, lets say "A" for this example, that has a member:
"B *m_b". Initially we don't need to hunt down a definition for this class
unless we are ever asked to do something with it ("expr m_b->getDecl()" for
example). With my previous approach to lazy type completion, we would be able
to take a "A *a" and get a complete type for it, but we wouldn't be able to
then do an "a->m_b->getDecl()" unless we always expanded all types within a
class prior to handing out the type. Expanding everything is very costly and
it would be great if there were a better way.
A few months ago I worked with the llvm/clang folks to have the
ExternalASTSource class be able to complete classes if there weren't completed
yet:
class ExternalASTSource {
....
virtual void
CompleteType (clang::TagDecl *Tag);
virtual void
CompleteType (clang::ObjCInterfaceDecl *Class);
};
This was great, because we can now have the class that is producing the AST
(SymbolFileDWARF and SymbolFileDWARFDebugMap) sign up as external AST sources
and the object that creates the forward declaration types can now also
complete them anywhere within the clang type system.
This patch makes a few major changes:
- lldb_private::Module classes now own the AST context. Previously the TypeList
objects did.
- The DWARF parsers now sign up as an external AST sources so they can complete
types.
- All of the pure clang type system wrapper code we have in LLDB (ClangASTContext,
ClangASTType, and more) can now be iterating through children of any type,
and if a class/union/struct type (clang::RecordType or ObjC interface)
is found that is incomplete, we can ask the AST to get the definition.
- The SymbolFileDWARFDebugMap class now will create and use a single AST that
all child SymbolFileDWARF classes will share (much like what happens when
we have a complete linked DWARF for an executable).
We will need to modify some of the ClangUserExpression code to take more
advantage of this completion ability in the near future. Meanwhile we should
be better off now that we can be accessing any children of variables through
pointers and always be able to resolve the clang type if needed.
llvm-svn: 123613
2011-01-17 11:46:26 +08:00
|
|
|
#include <assert.h>
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
|
|
|
2011-03-19 09:12:21 +08:00
|
|
|
static int
|
2011-03-25 07:53:38 +08:00
|
|
|
DataExtractorByteReader (uint8_t *byte, uint64_t address, void *arg)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
DataExtractor &extractor = *((DataExtractor *)arg);
|
|
|
|
|
|
|
|
if (extractor.ValidOffset(address))
|
|
|
|
{
|
|
|
|
*byte = *(extractor.GetDataStart() + address);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
struct RegisterReaderArg {
|
|
|
|
const lldb::addr_t instructionPointer;
|
|
|
|
const EDDisassemblerRef disassembler;
|
|
|
|
|
|
|
|
RegisterReaderArg(lldb::addr_t ip,
|
|
|
|
EDDisassemblerRef dis) :
|
|
|
|
instructionPointer(ip),
|
|
|
|
disassembler(dis)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
static int IPRegisterReader(uint64_t *value, unsigned regID, void* arg)
|
|
|
|
{
|
|
|
|
uint64_t instructionPointer = ((RegisterReaderArg*)arg)->instructionPointer;
|
|
|
|
EDDisassemblerRef disassembler = ((RegisterReaderArg*)arg)->disassembler;
|
|
|
|
|
2011-03-19 09:12:21 +08:00
|
|
|
if (EDRegisterIsProgramCounter(disassembler, regID)) {
|
2010-06-09 00:52:24 +08:00
|
|
|
*value = instructionPointer;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
Added the ability to get the min and max instruction byte size for
an architecture into ArchSpec:
uint32_t
ArchSpec::GetMinimumOpcodeByteSize() const;
uint32_t
ArchSpec::GetMaximumOpcodeByteSize() const;
Added an AddressClass to the Instruction class in Disassembler.h.
This allows decoded instructions to know know if they are code,
code with alternate ISA (thumb), or even data which can be mixed
into code. The instruction does have an address, but it is a good
idea to cache this value so we don't have to look it up more than
once.
Fixed an issue in Opcode::SetOpcodeBytes() where the length wasn't
getting set.
Changed:
bool
SymbolContextList::AppendIfUnique (const SymbolContext& sc);
To:
bool
SymbolContextList::AppendIfUnique (const SymbolContext& sc,
bool merge_symbol_into_function);
This function was typically being used when looking up functions
and symbols. Now if you lookup a function, then find the symbol,
they can be merged into the same symbol context and not cause
multiple symbol contexts to appear in a symbol context list that
describes the same function.
Fixed the SymbolContext not equal operator which was causing mixed
mode disassembly to not work ("disassembler --mixed --name main").
Modified the disassembler classes to know about the fact we know,
for a given architecture, what the min and max opcode byte sizes
are. The InstructionList class was modified to return the max
opcode byte size for all of the instructions in its list.
These two fixes means when disassemble a list of instructions and dump
them and show the opcode bytes, we can format the output more
intelligently when showing opcode bytes. This affects any architectures
that have varying opcode byte sizes (x86_64 and i386). Knowing the max
opcode byte size also helps us to be able to disassemble N instructions
without having to re-read data if we didn't read enough bytes.
Added the ability to set the architecture for the disassemble command.
This means you can easily cross disassemble data for any supported
architecture. I also added the ability to specify "thumb" as an
architecture so that we can force disassembly into thumb mode when
needed. In GDB this was done using a hack of specifying an odd
address when disassembling. I don't want to repeat this hack in LLDB,
so the auto detection between ARM and thumb is failing, just specify
thumb when disassembling:
(lldb) disassemble --arch thumb --name main
You can also have data in say an x86_64 file executable and disassemble
data as any other supported architecture:
% lldb a.out
Current executable set to 'a.out' (x86_64).
(lldb) b main
(lldb) run
(lldb) disassemble --arch thumb --count 2 --start-address 0x0000000100001080 --bytes
0x100001080: 0xb580 push {r7, lr}
0x100001082: 0xaf00 add r7, sp, #0
Fixed Target::ReadMemory(...) to be able to deal with Address argument object
that isn't section offset. When an address object was supplied that was
out on the heap or stack, target read memory would fail. Disassembly uses
Target::ReadMemory(...), and the example above where we disassembler thumb
opcodes in an x86 binary was failing do to this bug.
llvm-svn: 128347
2011-03-27 03:14:58 +08:00
|
|
|
DisassemblerLLVM::InstructionLLVM::InstructionLLVM (const Address &addr,
|
|
|
|
AddressClass addr_class,
|
|
|
|
EDDisassemblerRef disassembler) :
|
|
|
|
Instruction (addr, addr_class),
|
2010-06-09 00:52:24 +08:00
|
|
|
m_disassembler (disassembler)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-10-06 11:09:58 +08:00
|
|
|
DisassemblerLLVM::InstructionLLVM::~InstructionLLVM()
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
PadString(Stream *s, const std::string &str, size_t width)
|
|
|
|
{
|
|
|
|
int diff = width - str.length();
|
|
|
|
|
|
|
|
if (diff > 0)
|
|
|
|
s->Printf("%s%*.*s", str.c_str(), diff, diff, "");
|
|
|
|
else
|
|
|
|
s->Printf("%s ", str.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-10-06 11:09:58 +08:00
|
|
|
DisassemblerLLVM::InstructionLLVM::Dump
|
2010-06-09 00:52:24 +08:00
|
|
|
(
|
|
|
|
Stream *s,
|
Added the ability to get the min and max instruction byte size for
an architecture into ArchSpec:
uint32_t
ArchSpec::GetMinimumOpcodeByteSize() const;
uint32_t
ArchSpec::GetMaximumOpcodeByteSize() const;
Added an AddressClass to the Instruction class in Disassembler.h.
This allows decoded instructions to know know if they are code,
code with alternate ISA (thumb), or even data which can be mixed
into code. The instruction does have an address, but it is a good
idea to cache this value so we don't have to look it up more than
once.
Fixed an issue in Opcode::SetOpcodeBytes() where the length wasn't
getting set.
Changed:
bool
SymbolContextList::AppendIfUnique (const SymbolContext& sc);
To:
bool
SymbolContextList::AppendIfUnique (const SymbolContext& sc,
bool merge_symbol_into_function);
This function was typically being used when looking up functions
and symbols. Now if you lookup a function, then find the symbol,
they can be merged into the same symbol context and not cause
multiple symbol contexts to appear in a symbol context list that
describes the same function.
Fixed the SymbolContext not equal operator which was causing mixed
mode disassembly to not work ("disassembler --mixed --name main").
Modified the disassembler classes to know about the fact we know,
for a given architecture, what the min and max opcode byte sizes
are. The InstructionList class was modified to return the max
opcode byte size for all of the instructions in its list.
These two fixes means when disassemble a list of instructions and dump
them and show the opcode bytes, we can format the output more
intelligently when showing opcode bytes. This affects any architectures
that have varying opcode byte sizes (x86_64 and i386). Knowing the max
opcode byte size also helps us to be able to disassemble N instructions
without having to re-read data if we didn't read enough bytes.
Added the ability to set the architecture for the disassemble command.
This means you can easily cross disassemble data for any supported
architecture. I also added the ability to specify "thumb" as an
architecture so that we can force disassembly into thumb mode when
needed. In GDB this was done using a hack of specifying an odd
address when disassembling. I don't want to repeat this hack in LLDB,
so the auto detection between ARM and thumb is failing, just specify
thumb when disassembling:
(lldb) disassemble --arch thumb --name main
You can also have data in say an x86_64 file executable and disassemble
data as any other supported architecture:
% lldb a.out
Current executable set to 'a.out' (x86_64).
(lldb) b main
(lldb) run
(lldb) disassemble --arch thumb --count 2 --start-address 0x0000000100001080 --bytes
0x100001080: 0xb580 push {r7, lr}
0x100001082: 0xaf00 add r7, sp, #0
Fixed Target::ReadMemory(...) to be able to deal with Address argument object
that isn't section offset. When an address object was supplied that was
out on the heap or stack, target read memory would fail. Disassembly uses
Target::ReadMemory(...), and the example above where we disassembler thumb
opcodes in an x86 binary was failing do to this bug.
llvm-svn: 128347
2011-03-27 03:14:58 +08:00
|
|
|
uint32_t max_opcode_byte_size,
|
2010-10-06 11:09:58 +08:00
|
|
|
bool show_address,
|
2011-03-26 02:03:16 +08:00
|
|
|
bool show_bytes,
|
2010-10-06 11:09:58 +08:00
|
|
|
const lldb_private::ExecutionContext* exe_ctx,
|
2010-06-09 00:52:24 +08:00
|
|
|
bool raw
|
|
|
|
)
|
|
|
|
{
|
|
|
|
const size_t opcodeColumnWidth = 7;
|
|
|
|
const size_t operandColumnWidth = 25;
|
|
|
|
|
2010-10-06 11:09:58 +08:00
|
|
|
ExecutionContextScope *exe_scope = NULL;
|
|
|
|
if (exe_ctx)
|
|
|
|
exe_scope = exe_ctx->GetBestExecutionContextScope();
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
// If we have an address, print it out
|
2010-11-10 09:38:28 +08:00
|
|
|
if (GetAddress().IsValid() && show_address)
|
2010-07-01 07:03:03 +08:00
|
|
|
{
|
2010-10-06 11:09:58 +08:00
|
|
|
if (GetAddress().Dump (s,
|
|
|
|
exe_scope,
|
|
|
|
Address::DumpStyleLoadAddress,
|
|
|
|
Address::DumpStyleModuleWithFileAddress,
|
|
|
|
0))
|
2010-07-01 07:03:03 +08:00
|
|
|
s->PutCString(": ");
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
// If we are supposed to show bytes, "bytes" will be non-NULL.
|
2011-03-26 02:03:16 +08:00
|
|
|
if (show_bytes)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2011-03-26 02:03:16 +08:00
|
|
|
if (m_opcode.GetType() == Opcode::eTypeBytes)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2011-03-26 02:03:16 +08:00
|
|
|
// x86_64 and i386 are the only ones that use bytes right now so
|
|
|
|
// pad out the byte dump to be able to always show 15 bytes (3 chars each)
|
|
|
|
// plus a space
|
Added the ability to get the min and max instruction byte size for
an architecture into ArchSpec:
uint32_t
ArchSpec::GetMinimumOpcodeByteSize() const;
uint32_t
ArchSpec::GetMaximumOpcodeByteSize() const;
Added an AddressClass to the Instruction class in Disassembler.h.
This allows decoded instructions to know know if they are code,
code with alternate ISA (thumb), or even data which can be mixed
into code. The instruction does have an address, but it is a good
idea to cache this value so we don't have to look it up more than
once.
Fixed an issue in Opcode::SetOpcodeBytes() where the length wasn't
getting set.
Changed:
bool
SymbolContextList::AppendIfUnique (const SymbolContext& sc);
To:
bool
SymbolContextList::AppendIfUnique (const SymbolContext& sc,
bool merge_symbol_into_function);
This function was typically being used when looking up functions
and symbols. Now if you lookup a function, then find the symbol,
they can be merged into the same symbol context and not cause
multiple symbol contexts to appear in a symbol context list that
describes the same function.
Fixed the SymbolContext not equal operator which was causing mixed
mode disassembly to not work ("disassembler --mixed --name main").
Modified the disassembler classes to know about the fact we know,
for a given architecture, what the min and max opcode byte sizes
are. The InstructionList class was modified to return the max
opcode byte size for all of the instructions in its list.
These two fixes means when disassemble a list of instructions and dump
them and show the opcode bytes, we can format the output more
intelligently when showing opcode bytes. This affects any architectures
that have varying opcode byte sizes (x86_64 and i386). Knowing the max
opcode byte size also helps us to be able to disassemble N instructions
without having to re-read data if we didn't read enough bytes.
Added the ability to set the architecture for the disassemble command.
This means you can easily cross disassemble data for any supported
architecture. I also added the ability to specify "thumb" as an
architecture so that we can force disassembly into thumb mode when
needed. In GDB this was done using a hack of specifying an odd
address when disassembling. I don't want to repeat this hack in LLDB,
so the auto detection between ARM and thumb is failing, just specify
thumb when disassembling:
(lldb) disassemble --arch thumb --name main
You can also have data in say an x86_64 file executable and disassemble
data as any other supported architecture:
% lldb a.out
Current executable set to 'a.out' (x86_64).
(lldb) b main
(lldb) run
(lldb) disassemble --arch thumb --count 2 --start-address 0x0000000100001080 --bytes
0x100001080: 0xb580 push {r7, lr}
0x100001082: 0xaf00 add r7, sp, #0
Fixed Target::ReadMemory(...) to be able to deal with Address argument object
that isn't section offset. When an address object was supplied that was
out on the heap or stack, target read memory would fail. Disassembly uses
Target::ReadMemory(...), and the example above where we disassembler thumb
opcodes in an x86 binary was failing do to this bug.
llvm-svn: 128347
2011-03-27 03:14:58 +08:00
|
|
|
if (max_opcode_byte_size > 0)
|
|
|
|
m_opcode.Dump (s, max_opcode_byte_size * 3 + 1);
|
|
|
|
else
|
|
|
|
m_opcode.Dump (s, 15 * 3 + 1);
|
2011-03-26 02:03:16 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Else, we have ARM which can show up to a uint32_t 0x00000000 (10 spaces)
|
|
|
|
// plus two for padding...
|
Added the ability to get the min and max instruction byte size for
an architecture into ArchSpec:
uint32_t
ArchSpec::GetMinimumOpcodeByteSize() const;
uint32_t
ArchSpec::GetMaximumOpcodeByteSize() const;
Added an AddressClass to the Instruction class in Disassembler.h.
This allows decoded instructions to know know if they are code,
code with alternate ISA (thumb), or even data which can be mixed
into code. The instruction does have an address, but it is a good
idea to cache this value so we don't have to look it up more than
once.
Fixed an issue in Opcode::SetOpcodeBytes() where the length wasn't
getting set.
Changed:
bool
SymbolContextList::AppendIfUnique (const SymbolContext& sc);
To:
bool
SymbolContextList::AppendIfUnique (const SymbolContext& sc,
bool merge_symbol_into_function);
This function was typically being used when looking up functions
and symbols. Now if you lookup a function, then find the symbol,
they can be merged into the same symbol context and not cause
multiple symbol contexts to appear in a symbol context list that
describes the same function.
Fixed the SymbolContext not equal operator which was causing mixed
mode disassembly to not work ("disassembler --mixed --name main").
Modified the disassembler classes to know about the fact we know,
for a given architecture, what the min and max opcode byte sizes
are. The InstructionList class was modified to return the max
opcode byte size for all of the instructions in its list.
These two fixes means when disassemble a list of instructions and dump
them and show the opcode bytes, we can format the output more
intelligently when showing opcode bytes. This affects any architectures
that have varying opcode byte sizes (x86_64 and i386). Knowing the max
opcode byte size also helps us to be able to disassemble N instructions
without having to re-read data if we didn't read enough bytes.
Added the ability to set the architecture for the disassemble command.
This means you can easily cross disassemble data for any supported
architecture. I also added the ability to specify "thumb" as an
architecture so that we can force disassembly into thumb mode when
needed. In GDB this was done using a hack of specifying an odd
address when disassembling. I don't want to repeat this hack in LLDB,
so the auto detection between ARM and thumb is failing, just specify
thumb when disassembling:
(lldb) disassemble --arch thumb --name main
You can also have data in say an x86_64 file executable and disassemble
data as any other supported architecture:
% lldb a.out
Current executable set to 'a.out' (x86_64).
(lldb) b main
(lldb) run
(lldb) disassemble --arch thumb --count 2 --start-address 0x0000000100001080 --bytes
0x100001080: 0xb580 push {r7, lr}
0x100001082: 0xaf00 add r7, sp, #0
Fixed Target::ReadMemory(...) to be able to deal with Address argument object
that isn't section offset. When an address object was supplied that was
out on the heap or stack, target read memory would fail. Disassembly uses
Target::ReadMemory(...), and the example above where we disassembler thumb
opcodes in an x86 binary was failing do to this bug.
llvm-svn: 128347
2011-03-27 03:14:58 +08:00
|
|
|
if (max_opcode_byte_size > 0)
|
|
|
|
m_opcode.Dump (s, max_opcode_byte_size * 3 + 1);
|
|
|
|
else
|
|
|
|
m_opcode.Dump (s, 12);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int numTokens = EDNumTokens(m_inst);
|
|
|
|
|
|
|
|
int currentOpIndex = -1;
|
|
|
|
|
2010-07-23 10:19:15 +08:00
|
|
|
std::auto_ptr<RegisterReaderArg> rra;
|
|
|
|
|
|
|
|
if (!raw)
|
|
|
|
{
|
|
|
|
addr_t base_addr = LLDB_INVALID_ADDRESS;
|
2010-10-06 11:09:58 +08:00
|
|
|
if (exe_ctx && exe_ctx->target && !exe_ctx->target->GetSectionLoadList().IsEmpty())
|
|
|
|
base_addr = GetAddress().GetLoadAddress (exe_ctx->target);
|
2010-07-23 10:19:15 +08:00
|
|
|
if (base_addr == LLDB_INVALID_ADDRESS)
|
2010-10-06 11:09:58 +08:00
|
|
|
base_addr = GetAddress().GetFileAddress ();
|
2010-07-23 10:19:15 +08:00
|
|
|
|
|
|
|
rra.reset(new RegisterReaderArg(base_addr + EDInstByteSize(m_inst), m_disassembler));
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
bool printTokenized = false;
|
|
|
|
|
|
|
|
if (numTokens != -1)
|
|
|
|
{
|
|
|
|
printTokenized = true;
|
|
|
|
|
|
|
|
// Handle the opcode column.
|
|
|
|
|
|
|
|
StreamString opcode;
|
|
|
|
|
|
|
|
int tokenIndex = 0;
|
|
|
|
|
|
|
|
EDTokenRef token;
|
|
|
|
const char *tokenStr;
|
|
|
|
|
|
|
|
if (EDGetToken(&token, m_inst, tokenIndex))
|
|
|
|
printTokenized = false;
|
|
|
|
|
|
|
|
if (!printTokenized || !EDTokenIsOpcode(token))
|
|
|
|
printTokenized = false;
|
|
|
|
|
|
|
|
if (!printTokenized || EDGetTokenString(&tokenStr, token))
|
|
|
|
printTokenized = false;
|
|
|
|
|
|
|
|
// Put the token string into our opcode string
|
|
|
|
opcode.PutCString(tokenStr);
|
|
|
|
|
|
|
|
// If anything follows, it probably starts with some whitespace. Skip it.
|
|
|
|
|
|
|
|
tokenIndex++;
|
|
|
|
|
|
|
|
if (printTokenized && tokenIndex < numTokens)
|
|
|
|
{
|
|
|
|
if(!printTokenized || EDGetToken(&token, m_inst, tokenIndex))
|
|
|
|
printTokenized = false;
|
|
|
|
|
|
|
|
if(!printTokenized || !EDTokenIsWhitespace(token))
|
|
|
|
printTokenized = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
tokenIndex++;
|
|
|
|
|
|
|
|
// Handle the operands and the comment.
|
|
|
|
|
|
|
|
StreamString operands;
|
|
|
|
StreamString comment;
|
|
|
|
|
|
|
|
if (printTokenized)
|
|
|
|
{
|
|
|
|
bool show_token;
|
|
|
|
|
|
|
|
for (; tokenIndex < numTokens; ++tokenIndex)
|
|
|
|
{
|
|
|
|
if (EDGetToken(&token, m_inst, tokenIndex))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (raw)
|
|
|
|
{
|
|
|
|
show_token = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int operandIndex = EDOperandIndexForToken(token);
|
|
|
|
|
|
|
|
if (operandIndex >= 0)
|
|
|
|
{
|
|
|
|
if (operandIndex != currentOpIndex)
|
|
|
|
{
|
|
|
|
show_token = true;
|
|
|
|
|
|
|
|
currentOpIndex = operandIndex;
|
|
|
|
EDOperandRef operand;
|
|
|
|
|
|
|
|
if (!EDGetOperand(&operand, m_inst, currentOpIndex))
|
|
|
|
{
|
|
|
|
if (EDOperandIsMemory(operand))
|
|
|
|
{
|
|
|
|
uint64_t operand_value;
|
|
|
|
|
2010-07-23 10:19:15 +08:00
|
|
|
if (!EDEvaluateOperand(&operand_value, operand, IPRegisterReader, rra.get()))
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
if (EDInstIsBranch(m_inst))
|
|
|
|
{
|
|
|
|
operands.Printf("0x%llx ", operand_value);
|
|
|
|
show_token = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Put the address value into the comment
|
|
|
|
comment.Printf("0x%llx ", operand_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
lldb_private::Address so_addr;
|
2010-10-06 11:09:58 +08:00
|
|
|
if (exe_ctx && exe_ctx->target && !exe_ctx->target->GetSectionLoadList().IsEmpty())
|
2010-07-01 07:03:03 +08:00
|
|
|
{
|
2010-10-06 11:09:58 +08:00
|
|
|
if (exe_ctx->target->GetSectionLoadList().ResolveLoadAddress (operand_value, so_addr))
|
2010-07-01 09:26:43 +08:00
|
|
|
so_addr.Dump(&comment, exe_scope, Address::DumpStyleResolvedDescriptionNoModule, Address::DumpStyleSectionNameOffset);
|
2010-07-01 07:03:03 +08:00
|
|
|
}
|
2010-10-06 11:09:58 +08:00
|
|
|
else
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-10-06 11:09:58 +08:00
|
|
|
Module *module = GetAddress().GetModule();
|
2010-07-01 07:03:03 +08:00
|
|
|
if (module)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-07-01 07:03:03 +08:00
|
|
|
if (module->ResolveFileAddress (operand_value, so_addr))
|
2010-07-01 09:26:43 +08:00
|
|
|
so_addr.Dump(&comment, exe_scope, Address::DumpStyleResolvedDescriptionNoModule, Address::DumpStyleSectionNameOffset);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
}
|
2010-07-01 07:03:03 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
} // EDEvaluateOperand
|
|
|
|
} // EDOperandIsMemory
|
|
|
|
} // EDGetOperand
|
|
|
|
} // operandIndex != currentOpIndex
|
|
|
|
} // operandIndex >= 0
|
|
|
|
} // else(raw)
|
|
|
|
|
|
|
|
if (show_token)
|
|
|
|
{
|
|
|
|
if(EDGetTokenString(&tokenStr, token))
|
|
|
|
{
|
|
|
|
printTokenized = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
operands.PutCString(tokenStr);
|
|
|
|
}
|
|
|
|
} // for (tokenIndex)
|
|
|
|
|
|
|
|
if (printTokenized)
|
|
|
|
{
|
|
|
|
if (operands.GetString().empty())
|
|
|
|
{
|
|
|
|
s->PutCString(opcode.GetString().c_str());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PadString(s, opcode.GetString(), opcodeColumnWidth);
|
|
|
|
|
|
|
|
if (comment.GetString().empty())
|
|
|
|
{
|
|
|
|
s->PutCString(operands.GetString().c_str());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PadString(s, operands.GetString(), operandColumnWidth);
|
|
|
|
|
|
|
|
s->PutCString("; ");
|
|
|
|
s->PutCString(comment.GetString().c_str());
|
|
|
|
} // else (comment.GetString().empty())
|
|
|
|
} // else (operands.GetString().empty())
|
|
|
|
} // printTokenized
|
|
|
|
} // for (tokenIndex)
|
|
|
|
} // numTokens != -1
|
|
|
|
|
|
|
|
if (!printTokenized)
|
|
|
|
{
|
|
|
|
const char *str;
|
|
|
|
|
|
|
|
if (EDGetInstString(&str, m_inst))
|
|
|
|
return;
|
|
|
|
else
|
|
|
|
s->PutCString(str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2010-10-06 11:09:58 +08:00
|
|
|
DisassemblerLLVM::InstructionLLVM::DoesBranch() const
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
return EDInstIsBranch(m_inst);
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
Added the ability to get the min and max instruction byte size for
an architecture into ArchSpec:
uint32_t
ArchSpec::GetMinimumOpcodeByteSize() const;
uint32_t
ArchSpec::GetMaximumOpcodeByteSize() const;
Added an AddressClass to the Instruction class in Disassembler.h.
This allows decoded instructions to know know if they are code,
code with alternate ISA (thumb), or even data which can be mixed
into code. The instruction does have an address, but it is a good
idea to cache this value so we don't have to look it up more than
once.
Fixed an issue in Opcode::SetOpcodeBytes() where the length wasn't
getting set.
Changed:
bool
SymbolContextList::AppendIfUnique (const SymbolContext& sc);
To:
bool
SymbolContextList::AppendIfUnique (const SymbolContext& sc,
bool merge_symbol_into_function);
This function was typically being used when looking up functions
and symbols. Now if you lookup a function, then find the symbol,
they can be merged into the same symbol context and not cause
multiple symbol contexts to appear in a symbol context list that
describes the same function.
Fixed the SymbolContext not equal operator which was causing mixed
mode disassembly to not work ("disassembler --mixed --name main").
Modified the disassembler classes to know about the fact we know,
for a given architecture, what the min and max opcode byte sizes
are. The InstructionList class was modified to return the max
opcode byte size for all of the instructions in its list.
These two fixes means when disassemble a list of instructions and dump
them and show the opcode bytes, we can format the output more
intelligently when showing opcode bytes. This affects any architectures
that have varying opcode byte sizes (x86_64 and i386). Knowing the max
opcode byte size also helps us to be able to disassemble N instructions
without having to re-read data if we didn't read enough bytes.
Added the ability to set the architecture for the disassemble command.
This means you can easily cross disassemble data for any supported
architecture. I also added the ability to specify "thumb" as an
architecture so that we can force disassembly into thumb mode when
needed. In GDB this was done using a hack of specifying an odd
address when disassembling. I don't want to repeat this hack in LLDB,
so the auto detection between ARM and thumb is failing, just specify
thumb when disassembling:
(lldb) disassemble --arch thumb --name main
You can also have data in say an x86_64 file executable and disassemble
data as any other supported architecture:
% lldb a.out
Current executable set to 'a.out' (x86_64).
(lldb) b main
(lldb) run
(lldb) disassemble --arch thumb --count 2 --start-address 0x0000000100001080 --bytes
0x100001080: 0xb580 push {r7, lr}
0x100001082: 0xaf00 add r7, sp, #0
Fixed Target::ReadMemory(...) to be able to deal with Address argument object
that isn't section offset. When an address object was supplied that was
out on the heap or stack, target read memory would fail. Disassembly uses
Target::ReadMemory(...), and the example above where we disassembler thumb
opcodes in an x86 binary was failing do to this bug.
llvm-svn: 128347
2011-03-27 03:14:58 +08:00
|
|
|
DisassemblerLLVM::InstructionLLVM::Decode (const Disassembler &disassembler,
|
|
|
|
const lldb_private::DataExtractor &data,
|
|
|
|
uint32_t data_offset)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
if (EDCreateInsts(&m_inst, 1, m_disassembler, DataExtractorByteReader, data_offset, (void*)(&data)))
|
2011-03-25 07:53:38 +08:00
|
|
|
{
|
|
|
|
const int byte_size = EDInstByteSize(m_inst);
|
|
|
|
uint32_t offset = data_offset;
|
|
|
|
// Make a copy of the opcode in m_opcode
|
|
|
|
switch (disassembler.GetArchitecture().GetMachine())
|
|
|
|
{
|
|
|
|
case llvm::Triple::x86:
|
|
|
|
case llvm::Triple::x86_64:
|
|
|
|
m_opcode.SetOpcodeBytes (data.PeekData (data_offset, byte_size), byte_size);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case llvm::Triple::arm:
|
|
|
|
case llvm::Triple::thumb:
|
2011-03-26 02:03:16 +08:00
|
|
|
switch (byte_size)
|
|
|
|
{
|
|
|
|
case 2:
|
|
|
|
m_opcode.SetOpcode16 (data.GetU16 (&offset));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 4:
|
2011-03-25 07:53:38 +08:00
|
|
|
m_opcode.SetOpcode32 (data.GetU32 (&offset));
|
2011-03-26 02:03:16 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
assert (!"Invalid ARM opcode size");
|
|
|
|
break;
|
|
|
|
}
|
2011-03-25 07:53:38 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
assert (!"This shouldn't happen since we control the architecture we allow DisassemblerLLVM to be created for");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return byte_size;
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline EDAssemblySyntax_t
|
2010-06-11 11:25:34 +08:00
|
|
|
SyntaxForArchSpec (const ArchSpec &arch)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2011-02-23 08:35:02 +08:00
|
|
|
switch (arch.GetMachine ())
|
2011-02-16 08:00:43 +08:00
|
|
|
{
|
2011-02-23 08:35:02 +08:00
|
|
|
case llvm::Triple::x86:
|
|
|
|
case llvm::Triple::x86_64:
|
2010-06-09 00:52:24 +08:00
|
|
|
return kEDAssemblySyntaxX86ATT;
|
2011-03-09 09:02:51 +08:00
|
|
|
case llvm::Triple::arm:
|
Added the ability to get the min and max instruction byte size for
an architecture into ArchSpec:
uint32_t
ArchSpec::GetMinimumOpcodeByteSize() const;
uint32_t
ArchSpec::GetMaximumOpcodeByteSize() const;
Added an AddressClass to the Instruction class in Disassembler.h.
This allows decoded instructions to know know if they are code,
code with alternate ISA (thumb), or even data which can be mixed
into code. The instruction does have an address, but it is a good
idea to cache this value so we don't have to look it up more than
once.
Fixed an issue in Opcode::SetOpcodeBytes() where the length wasn't
getting set.
Changed:
bool
SymbolContextList::AppendIfUnique (const SymbolContext& sc);
To:
bool
SymbolContextList::AppendIfUnique (const SymbolContext& sc,
bool merge_symbol_into_function);
This function was typically being used when looking up functions
and symbols. Now if you lookup a function, then find the symbol,
they can be merged into the same symbol context and not cause
multiple symbol contexts to appear in a symbol context list that
describes the same function.
Fixed the SymbolContext not equal operator which was causing mixed
mode disassembly to not work ("disassembler --mixed --name main").
Modified the disassembler classes to know about the fact we know,
for a given architecture, what the min and max opcode byte sizes
are. The InstructionList class was modified to return the max
opcode byte size for all of the instructions in its list.
These two fixes means when disassemble a list of instructions and dump
them and show the opcode bytes, we can format the output more
intelligently when showing opcode bytes. This affects any architectures
that have varying opcode byte sizes (x86_64 and i386). Knowing the max
opcode byte size also helps us to be able to disassemble N instructions
without having to re-read data if we didn't read enough bytes.
Added the ability to set the architecture for the disassemble command.
This means you can easily cross disassemble data for any supported
architecture. I also added the ability to specify "thumb" as an
architecture so that we can force disassembly into thumb mode when
needed. In GDB this was done using a hack of specifying an odd
address when disassembling. I don't want to repeat this hack in LLDB,
so the auto detection between ARM and thumb is failing, just specify
thumb when disassembling:
(lldb) disassemble --arch thumb --name main
You can also have data in say an x86_64 file executable and disassemble
data as any other supported architecture:
% lldb a.out
Current executable set to 'a.out' (x86_64).
(lldb) b main
(lldb) run
(lldb) disassemble --arch thumb --count 2 --start-address 0x0000000100001080 --bytes
0x100001080: 0xb580 push {r7, lr}
0x100001082: 0xaf00 add r7, sp, #0
Fixed Target::ReadMemory(...) to be able to deal with Address argument object
that isn't section offset. When an address object was supplied that was
out on the heap or stack, target read memory would fail. Disassembly uses
Target::ReadMemory(...), and the example above where we disassembler thumb
opcodes in an x86 binary was failing do to this bug.
llvm-svn: 128347
2011-03-27 03:14:58 +08:00
|
|
|
case llvm::Triple::thumb:
|
2011-03-09 09:02:51 +08:00
|
|
|
return kEDAssemblySyntaxARMUAL;
|
2011-02-16 08:00:43 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2010-06-11 11:25:34 +08:00
|
|
|
return (EDAssemblySyntax_t)0; // default
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Disassembler *
|
|
|
|
DisassemblerLLVM::CreateInstance(const ArchSpec &arch)
|
|
|
|
{
|
2011-02-16 08:00:43 +08:00
|
|
|
std::auto_ptr<DisassemblerLLVM> disasm_ap (new DisassemblerLLVM(arch));
|
|
|
|
|
|
|
|
if (disasm_ap->IsValid())
|
|
|
|
return disasm_ap.release();
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2010-06-11 11:25:34 +08:00
|
|
|
return NULL;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DisassemblerLLVM::DisassemblerLLVM(const ArchSpec &arch) :
|
A few of the issue I have been trying to track down and fix have been due to
the way LLDB lazily gets complete definitions for types within the debug info.
When we run across a class/struct/union definition in the DWARF, we will only
parse the full definition if we need to. This works fine for top level types
that are assigned directly to variables and arguments, but when we have a
variable with a class, lets say "A" for this example, that has a member:
"B *m_b". Initially we don't need to hunt down a definition for this class
unless we are ever asked to do something with it ("expr m_b->getDecl()" for
example). With my previous approach to lazy type completion, we would be able
to take a "A *a" and get a complete type for it, but we wouldn't be able to
then do an "a->m_b->getDecl()" unless we always expanded all types within a
class prior to handing out the type. Expanding everything is very costly and
it would be great if there were a better way.
A few months ago I worked with the llvm/clang folks to have the
ExternalASTSource class be able to complete classes if there weren't completed
yet:
class ExternalASTSource {
....
virtual void
CompleteType (clang::TagDecl *Tag);
virtual void
CompleteType (clang::ObjCInterfaceDecl *Class);
};
This was great, because we can now have the class that is producing the AST
(SymbolFileDWARF and SymbolFileDWARFDebugMap) sign up as external AST sources
and the object that creates the forward declaration types can now also
complete them anywhere within the clang type system.
This patch makes a few major changes:
- lldb_private::Module classes now own the AST context. Previously the TypeList
objects did.
- The DWARF parsers now sign up as an external AST sources so they can complete
types.
- All of the pure clang type system wrapper code we have in LLDB (ClangASTContext,
ClangASTType, and more) can now be iterating through children of any type,
and if a class/union/struct type (clang::RecordType or ObjC interface)
is found that is incomplete, we can ask the AST to get the definition.
- The SymbolFileDWARFDebugMap class now will create and use a single AST that
all child SymbolFileDWARF classes will share (much like what happens when
we have a complete linked DWARF for an executable).
We will need to modify some of the ClangUserExpression code to take more
advantage of this completion ability in the near future. Meanwhile we should
be better off now that we can be accessing any children of variables through
pointers and always be able to resolve the clang type if needed.
llvm-svn: 123613
2011-01-17 11:46:26 +08:00
|
|
|
Disassembler (arch),
|
2011-03-19 09:12:21 +08:00
|
|
|
m_disassembler (NULL),
|
|
|
|
m_disassembler_thumb (NULL) // For ARM only
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2011-02-16 08:00:43 +08:00
|
|
|
const std::string &arch_triple = arch.GetTriple().str();
|
|
|
|
if (!arch_triple.empty())
|
2010-06-11 11:25:34 +08:00
|
|
|
{
|
2011-02-16 08:00:43 +08:00
|
|
|
if (EDGetDisassembler(&m_disassembler, arch_triple.c_str(), SyntaxForArchSpec (arch)))
|
|
|
|
m_disassembler = NULL;
|
2011-03-19 09:12:21 +08:00
|
|
|
llvm::Triple::ArchType llvm_arch = arch.GetTriple().getArch();
|
Added the ability to get the min and max instruction byte size for
an architecture into ArchSpec:
uint32_t
ArchSpec::GetMinimumOpcodeByteSize() const;
uint32_t
ArchSpec::GetMaximumOpcodeByteSize() const;
Added an AddressClass to the Instruction class in Disassembler.h.
This allows decoded instructions to know know if they are code,
code with alternate ISA (thumb), or even data which can be mixed
into code. The instruction does have an address, but it is a good
idea to cache this value so we don't have to look it up more than
once.
Fixed an issue in Opcode::SetOpcodeBytes() where the length wasn't
getting set.
Changed:
bool
SymbolContextList::AppendIfUnique (const SymbolContext& sc);
To:
bool
SymbolContextList::AppendIfUnique (const SymbolContext& sc,
bool merge_symbol_into_function);
This function was typically being used when looking up functions
and symbols. Now if you lookup a function, then find the symbol,
they can be merged into the same symbol context and not cause
multiple symbol contexts to appear in a symbol context list that
describes the same function.
Fixed the SymbolContext not equal operator which was causing mixed
mode disassembly to not work ("disassembler --mixed --name main").
Modified the disassembler classes to know about the fact we know,
for a given architecture, what the min and max opcode byte sizes
are. The InstructionList class was modified to return the max
opcode byte size for all of the instructions in its list.
These two fixes means when disassemble a list of instructions and dump
them and show the opcode bytes, we can format the output more
intelligently when showing opcode bytes. This affects any architectures
that have varying opcode byte sizes (x86_64 and i386). Knowing the max
opcode byte size also helps us to be able to disassemble N instructions
without having to re-read data if we didn't read enough bytes.
Added the ability to set the architecture for the disassemble command.
This means you can easily cross disassemble data for any supported
architecture. I also added the ability to specify "thumb" as an
architecture so that we can force disassembly into thumb mode when
needed. In GDB this was done using a hack of specifying an odd
address when disassembling. I don't want to repeat this hack in LLDB,
so the auto detection between ARM and thumb is failing, just specify
thumb when disassembling:
(lldb) disassemble --arch thumb --name main
You can also have data in say an x86_64 file executable and disassemble
data as any other supported architecture:
% lldb a.out
Current executable set to 'a.out' (x86_64).
(lldb) b main
(lldb) run
(lldb) disassemble --arch thumb --count 2 --start-address 0x0000000100001080 --bytes
0x100001080: 0xb580 push {r7, lr}
0x100001082: 0xaf00 add r7, sp, #0
Fixed Target::ReadMemory(...) to be able to deal with Address argument object
that isn't section offset. When an address object was supplied that was
out on the heap or stack, target read memory would fail. Disassembly uses
Target::ReadMemory(...), and the example above where we disassembler thumb
opcodes in an x86 binary was failing do to this bug.
llvm-svn: 128347
2011-03-27 03:14:58 +08:00
|
|
|
// Don't have the lldb::Triple::thumb architecture here. If someone specifies
|
|
|
|
// "thumb" as the architecture, we want a thumb only disassembler. But if any
|
|
|
|
// architecture starting with "arm" if specified, we want to auto detect the
|
|
|
|
// arm/thumb code automatically using the AddressClass from section offset
|
|
|
|
// addresses.
|
2011-03-19 09:12:21 +08:00
|
|
|
if (llvm_arch == llvm::Triple::arm)
|
|
|
|
{
|
|
|
|
if (EDGetDisassembler(&m_disassembler_thumb, "thumb-apple-darwin", kEDAssemblySyntaxARMUAL))
|
|
|
|
m_disassembler_thumb = NULL;
|
|
|
|
}
|
2010-06-11 11:25:34 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DisassemblerLLVM::~DisassemblerLLVM()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
2010-07-01 07:03:03 +08:00
|
|
|
DisassemblerLLVM::DecodeInstructions
|
2010-06-09 00:52:24 +08:00
|
|
|
(
|
2010-10-06 11:09:58 +08:00
|
|
|
const Address &base_addr,
|
2010-06-09 00:52:24 +08:00
|
|
|
const DataExtractor& data,
|
|
|
|
uint32_t data_offset,
|
2011-03-22 09:48:42 +08:00
|
|
|
uint32_t num_instructions,
|
|
|
|
bool append
|
2010-06-09 00:52:24 +08:00
|
|
|
)
|
|
|
|
{
|
A few of the issue I have been trying to track down and fix have been due to
the way LLDB lazily gets complete definitions for types within the debug info.
When we run across a class/struct/union definition in the DWARF, we will only
parse the full definition if we need to. This works fine for top level types
that are assigned directly to variables and arguments, but when we have a
variable with a class, lets say "A" for this example, that has a member:
"B *m_b". Initially we don't need to hunt down a definition for this class
unless we are ever asked to do something with it ("expr m_b->getDecl()" for
example). With my previous approach to lazy type completion, we would be able
to take a "A *a" and get a complete type for it, but we wouldn't be able to
then do an "a->m_b->getDecl()" unless we always expanded all types within a
class prior to handing out the type. Expanding everything is very costly and
it would be great if there were a better way.
A few months ago I worked with the llvm/clang folks to have the
ExternalASTSource class be able to complete classes if there weren't completed
yet:
class ExternalASTSource {
....
virtual void
CompleteType (clang::TagDecl *Tag);
virtual void
CompleteType (clang::ObjCInterfaceDecl *Class);
};
This was great, because we can now have the class that is producing the AST
(SymbolFileDWARF and SymbolFileDWARFDebugMap) sign up as external AST sources
and the object that creates the forward declaration types can now also
complete them anywhere within the clang type system.
This patch makes a few major changes:
- lldb_private::Module classes now own the AST context. Previously the TypeList
objects did.
- The DWARF parsers now sign up as an external AST sources so they can complete
types.
- All of the pure clang type system wrapper code we have in LLDB (ClangASTContext,
ClangASTType, and more) can now be iterating through children of any type,
and if a class/union/struct type (clang::RecordType or ObjC interface)
is found that is incomplete, we can ask the AST to get the definition.
- The SymbolFileDWARFDebugMap class now will create and use a single AST that
all child SymbolFileDWARF classes will share (much like what happens when
we have a complete linked DWARF for an executable).
We will need to modify some of the ClangUserExpression code to take more
advantage of this completion ability in the near future. Meanwhile we should
be better off now that we can be accessing any children of variables through
pointers and always be able to resolve the clang type if needed.
llvm-svn: 123613
2011-01-17 11:46:26 +08:00
|
|
|
if (m_disassembler == NULL)
|
|
|
|
return 0;
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
size_t total_inst_byte_size = 0;
|
|
|
|
|
2011-03-22 09:48:42 +08:00
|
|
|
if (!append)
|
|
|
|
m_instruction_list.Clear();
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
while (data.ValidOffset(data_offset) && num_instructions)
|
|
|
|
{
|
2010-10-06 11:09:58 +08:00
|
|
|
Address inst_addr (base_addr);
|
|
|
|
inst_addr.Slide(data_offset);
|
2011-03-19 09:12:21 +08:00
|
|
|
|
|
|
|
bool use_thumb = false;
|
|
|
|
// If we have a thumb disassembler, then we have an ARM architecture
|
|
|
|
// so we need to check what the instruction address class is to make
|
|
|
|
// sure we shouldn't be disassembling as thumb...
|
Added the ability to get the min and max instruction byte size for
an architecture into ArchSpec:
uint32_t
ArchSpec::GetMinimumOpcodeByteSize() const;
uint32_t
ArchSpec::GetMaximumOpcodeByteSize() const;
Added an AddressClass to the Instruction class in Disassembler.h.
This allows decoded instructions to know know if they are code,
code with alternate ISA (thumb), or even data which can be mixed
into code. The instruction does have an address, but it is a good
idea to cache this value so we don't have to look it up more than
once.
Fixed an issue in Opcode::SetOpcodeBytes() where the length wasn't
getting set.
Changed:
bool
SymbolContextList::AppendIfUnique (const SymbolContext& sc);
To:
bool
SymbolContextList::AppendIfUnique (const SymbolContext& sc,
bool merge_symbol_into_function);
This function was typically being used when looking up functions
and symbols. Now if you lookup a function, then find the symbol,
they can be merged into the same symbol context and not cause
multiple symbol contexts to appear in a symbol context list that
describes the same function.
Fixed the SymbolContext not equal operator which was causing mixed
mode disassembly to not work ("disassembler --mixed --name main").
Modified the disassembler classes to know about the fact we know,
for a given architecture, what the min and max opcode byte sizes
are. The InstructionList class was modified to return the max
opcode byte size for all of the instructions in its list.
These two fixes means when disassemble a list of instructions and dump
them and show the opcode bytes, we can format the output more
intelligently when showing opcode bytes. This affects any architectures
that have varying opcode byte sizes (x86_64 and i386). Knowing the max
opcode byte size also helps us to be able to disassemble N instructions
without having to re-read data if we didn't read enough bytes.
Added the ability to set the architecture for the disassemble command.
This means you can easily cross disassemble data for any supported
architecture. I also added the ability to specify "thumb" as an
architecture so that we can force disassembly into thumb mode when
needed. In GDB this was done using a hack of specifying an odd
address when disassembling. I don't want to repeat this hack in LLDB,
so the auto detection between ARM and thumb is failing, just specify
thumb when disassembling:
(lldb) disassemble --arch thumb --name main
You can also have data in say an x86_64 file executable and disassemble
data as any other supported architecture:
% lldb a.out
Current executable set to 'a.out' (x86_64).
(lldb) b main
(lldb) run
(lldb) disassemble --arch thumb --count 2 --start-address 0x0000000100001080 --bytes
0x100001080: 0xb580 push {r7, lr}
0x100001082: 0xaf00 add r7, sp, #0
Fixed Target::ReadMemory(...) to be able to deal with Address argument object
that isn't section offset. When an address object was supplied that was
out on the heap or stack, target read memory would fail. Disassembly uses
Target::ReadMemory(...), and the example above where we disassembler thumb
opcodes in an x86 binary was failing do to this bug.
llvm-svn: 128347
2011-03-27 03:14:58 +08:00
|
|
|
AddressClass inst_address_class = eAddressClassInvalid;
|
2011-03-19 09:12:21 +08:00
|
|
|
if (m_disassembler_thumb)
|
|
|
|
{
|
Added the ability to get the min and max instruction byte size for
an architecture into ArchSpec:
uint32_t
ArchSpec::GetMinimumOpcodeByteSize() const;
uint32_t
ArchSpec::GetMaximumOpcodeByteSize() const;
Added an AddressClass to the Instruction class in Disassembler.h.
This allows decoded instructions to know know if they are code,
code with alternate ISA (thumb), or even data which can be mixed
into code. The instruction does have an address, but it is a good
idea to cache this value so we don't have to look it up more than
once.
Fixed an issue in Opcode::SetOpcodeBytes() where the length wasn't
getting set.
Changed:
bool
SymbolContextList::AppendIfUnique (const SymbolContext& sc);
To:
bool
SymbolContextList::AppendIfUnique (const SymbolContext& sc,
bool merge_symbol_into_function);
This function was typically being used when looking up functions
and symbols. Now if you lookup a function, then find the symbol,
they can be merged into the same symbol context and not cause
multiple symbol contexts to appear in a symbol context list that
describes the same function.
Fixed the SymbolContext not equal operator which was causing mixed
mode disassembly to not work ("disassembler --mixed --name main").
Modified the disassembler classes to know about the fact we know,
for a given architecture, what the min and max opcode byte sizes
are. The InstructionList class was modified to return the max
opcode byte size for all of the instructions in its list.
These two fixes means when disassemble a list of instructions and dump
them and show the opcode bytes, we can format the output more
intelligently when showing opcode bytes. This affects any architectures
that have varying opcode byte sizes (x86_64 and i386). Knowing the max
opcode byte size also helps us to be able to disassemble N instructions
without having to re-read data if we didn't read enough bytes.
Added the ability to set the architecture for the disassemble command.
This means you can easily cross disassemble data for any supported
architecture. I also added the ability to specify "thumb" as an
architecture so that we can force disassembly into thumb mode when
needed. In GDB this was done using a hack of specifying an odd
address when disassembling. I don't want to repeat this hack in LLDB,
so the auto detection between ARM and thumb is failing, just specify
thumb when disassembling:
(lldb) disassemble --arch thumb --name main
You can also have data in say an x86_64 file executable and disassemble
data as any other supported architecture:
% lldb a.out
Current executable set to 'a.out' (x86_64).
(lldb) b main
(lldb) run
(lldb) disassemble --arch thumb --count 2 --start-address 0x0000000100001080 --bytes
0x100001080: 0xb580 push {r7, lr}
0x100001082: 0xaf00 add r7, sp, #0
Fixed Target::ReadMemory(...) to be able to deal with Address argument object
that isn't section offset. When an address object was supplied that was
out on the heap or stack, target read memory would fail. Disassembly uses
Target::ReadMemory(...), and the example above where we disassembler thumb
opcodes in an x86 binary was failing do to this bug.
llvm-svn: 128347
2011-03-27 03:14:58 +08:00
|
|
|
inst_address_class = inst_addr.GetAddressClass ();
|
|
|
|
if (inst_address_class == eAddressClassCodeAlternateISA)
|
2011-03-19 09:12:21 +08:00
|
|
|
use_thumb = true;
|
|
|
|
}
|
2011-03-25 07:53:38 +08:00
|
|
|
InstructionSP inst_sp (new InstructionLLVM (inst_addr,
|
Added the ability to get the min and max instruction byte size for
an architecture into ArchSpec:
uint32_t
ArchSpec::GetMinimumOpcodeByteSize() const;
uint32_t
ArchSpec::GetMaximumOpcodeByteSize() const;
Added an AddressClass to the Instruction class in Disassembler.h.
This allows decoded instructions to know know if they are code,
code with alternate ISA (thumb), or even data which can be mixed
into code. The instruction does have an address, but it is a good
idea to cache this value so we don't have to look it up more than
once.
Fixed an issue in Opcode::SetOpcodeBytes() where the length wasn't
getting set.
Changed:
bool
SymbolContextList::AppendIfUnique (const SymbolContext& sc);
To:
bool
SymbolContextList::AppendIfUnique (const SymbolContext& sc,
bool merge_symbol_into_function);
This function was typically being used when looking up functions
and symbols. Now if you lookup a function, then find the symbol,
they can be merged into the same symbol context and not cause
multiple symbol contexts to appear in a symbol context list that
describes the same function.
Fixed the SymbolContext not equal operator which was causing mixed
mode disassembly to not work ("disassembler --mixed --name main").
Modified the disassembler classes to know about the fact we know,
for a given architecture, what the min and max opcode byte sizes
are. The InstructionList class was modified to return the max
opcode byte size for all of the instructions in its list.
These two fixes means when disassemble a list of instructions and dump
them and show the opcode bytes, we can format the output more
intelligently when showing opcode bytes. This affects any architectures
that have varying opcode byte sizes (x86_64 and i386). Knowing the max
opcode byte size also helps us to be able to disassemble N instructions
without having to re-read data if we didn't read enough bytes.
Added the ability to set the architecture for the disassemble command.
This means you can easily cross disassemble data for any supported
architecture. I also added the ability to specify "thumb" as an
architecture so that we can force disassembly into thumb mode when
needed. In GDB this was done using a hack of specifying an odd
address when disassembling. I don't want to repeat this hack in LLDB,
so the auto detection between ARM and thumb is failing, just specify
thumb when disassembling:
(lldb) disassemble --arch thumb --name main
You can also have data in say an x86_64 file executable and disassemble
data as any other supported architecture:
% lldb a.out
Current executable set to 'a.out' (x86_64).
(lldb) b main
(lldb) run
(lldb) disassemble --arch thumb --count 2 --start-address 0x0000000100001080 --bytes
0x100001080: 0xb580 push {r7, lr}
0x100001082: 0xaf00 add r7, sp, #0
Fixed Target::ReadMemory(...) to be able to deal with Address argument object
that isn't section offset. When an address object was supplied that was
out on the heap or stack, target read memory would fail. Disassembly uses
Target::ReadMemory(...), and the example above where we disassembler thumb
opcodes in an x86 binary was failing do to this bug.
llvm-svn: 128347
2011-03-27 03:14:58 +08:00
|
|
|
inst_address_class,
|
2011-03-25 07:53:38 +08:00
|
|
|
use_thumb ? m_disassembler_thumb : m_disassembler));
|
2010-06-09 00:52:24 +08:00
|
|
|
|
Added the ability to get the min and max instruction byte size for
an architecture into ArchSpec:
uint32_t
ArchSpec::GetMinimumOpcodeByteSize() const;
uint32_t
ArchSpec::GetMaximumOpcodeByteSize() const;
Added an AddressClass to the Instruction class in Disassembler.h.
This allows decoded instructions to know know if they are code,
code with alternate ISA (thumb), or even data which can be mixed
into code. The instruction does have an address, but it is a good
idea to cache this value so we don't have to look it up more than
once.
Fixed an issue in Opcode::SetOpcodeBytes() where the length wasn't
getting set.
Changed:
bool
SymbolContextList::AppendIfUnique (const SymbolContext& sc);
To:
bool
SymbolContextList::AppendIfUnique (const SymbolContext& sc,
bool merge_symbol_into_function);
This function was typically being used when looking up functions
and symbols. Now if you lookup a function, then find the symbol,
they can be merged into the same symbol context and not cause
multiple symbol contexts to appear in a symbol context list that
describes the same function.
Fixed the SymbolContext not equal operator which was causing mixed
mode disassembly to not work ("disassembler --mixed --name main").
Modified the disassembler classes to know about the fact we know,
for a given architecture, what the min and max opcode byte sizes
are. The InstructionList class was modified to return the max
opcode byte size for all of the instructions in its list.
These two fixes means when disassemble a list of instructions and dump
them and show the opcode bytes, we can format the output more
intelligently when showing opcode bytes. This affects any architectures
that have varying opcode byte sizes (x86_64 and i386). Knowing the max
opcode byte size also helps us to be able to disassemble N instructions
without having to re-read data if we didn't read enough bytes.
Added the ability to set the architecture for the disassemble command.
This means you can easily cross disassemble data for any supported
architecture. I also added the ability to specify "thumb" as an
architecture so that we can force disassembly into thumb mode when
needed. In GDB this was done using a hack of specifying an odd
address when disassembling. I don't want to repeat this hack in LLDB,
so the auto detection between ARM and thumb is failing, just specify
thumb when disassembling:
(lldb) disassemble --arch thumb --name main
You can also have data in say an x86_64 file executable and disassemble
data as any other supported architecture:
% lldb a.out
Current executable set to 'a.out' (x86_64).
(lldb) b main
(lldb) run
(lldb) disassemble --arch thumb --count 2 --start-address 0x0000000100001080 --bytes
0x100001080: 0xb580 push {r7, lr}
0x100001082: 0xaf00 add r7, sp, #0
Fixed Target::ReadMemory(...) to be able to deal with Address argument object
that isn't section offset. When an address object was supplied that was
out on the heap or stack, target read memory would fail. Disassembly uses
Target::ReadMemory(...), and the example above where we disassembler thumb
opcodes in an x86 binary was failing do to this bug.
llvm-svn: 128347
2011-03-27 03:14:58 +08:00
|
|
|
size_t inst_byte_size = inst_sp->Decode (*this, data, data_offset);
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
if (inst_byte_size == 0)
|
|
|
|
break;
|
|
|
|
|
2010-10-06 11:09:58 +08:00
|
|
|
m_instruction_list.Append (inst_sp);
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
total_inst_byte_size += inst_byte_size;
|
|
|
|
data_offset += inst_byte_size;
|
|
|
|
num_instructions--;
|
|
|
|
}
|
|
|
|
|
|
|
|
return total_inst_byte_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DisassemblerLLVM::Initialize()
|
|
|
|
{
|
|
|
|
PluginManager::RegisterPlugin (GetPluginNameStatic(),
|
|
|
|
GetPluginDescriptionStatic(),
|
|
|
|
CreateInstance);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DisassemblerLLVM::Terminate()
|
|
|
|
{
|
|
|
|
PluginManager::UnregisterPlugin (CreateInstance);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const char *
|
|
|
|
DisassemblerLLVM::GetPluginNameStatic()
|
|
|
|
{
|
2011-03-26 02:03:16 +08:00
|
|
|
return "llvm";
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
DisassemblerLLVM::GetPluginDescriptionStatic()
|
|
|
|
{
|
2011-03-26 02:03:16 +08:00
|
|
|
return "Disassembler that uses LLVM opcode tables to disassemble i386, x86_64 and ARM.";
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
// PluginInterface protocol
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
const char *
|
|
|
|
DisassemblerLLVM::GetPluginName()
|
|
|
|
{
|
|
|
|
return "DisassemblerLLVM";
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
DisassemblerLLVM::GetShortPluginName()
|
|
|
|
{
|
|
|
|
return GetPluginNameStatic();
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
DisassemblerLLVM::GetPluginVersion()
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|