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"
|
2011-11-29 09:09:49 +08:00
|
|
|
#include "llvm/Support/TargetSelect.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
#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;
|
|
|
|
}
|
|
|
|
|
2011-04-06 07:22:54 +08:00
|
|
|
InstructionLLVM::InstructionLLVM (const Address &addr,
|
|
|
|
AddressClass addr_class,
|
Centralized a lot of the status information for processes,
threads, and stack frame down in the lldb_private::Process,
lldb_private::Thread, lldb_private::StackFrameList and the
lldb_private::StackFrame classes. We had some command line
commands that had duplicate versions of the process status
output ("thread list" and "process status" for example).
Removed the "file" command and placed it where it should
have been: "target create". Made an alias for "file" to
"target create" so we stay compatible with GDB commands.
We can now have multple usable targets in lldb at the
same time. This is nice for comparing two runs of a program
or debugging more than one binary at the same time. The
new command is "target select <target-idx>" and also to see
a list of the current targets you can use the new "target list"
command. The flow in a debug session can be:
(lldb) target create /path/to/exe/a.out
(lldb) breakpoint set --name main
(lldb) run
... hit breakpoint
(lldb) target create /bin/ls
(lldb) run /tmp
Process 36001 exited with status = 0 (0x00000000)
(lldb) target list
Current targets:
target #0: /tmp/args/a.out ( arch=x86_64-apple-darwin, platform=localhost, pid=35999, state=stopped )
* target #1: /bin/ls ( arch=x86_64-apple-darwin, platform=localhost, pid=36001, state=exited )
(lldb) target select 0
Current targets:
* target #0: /tmp/args/a.out ( arch=x86_64-apple-darwin, platform=localhost, pid=35999, state=stopped )
target #1: /bin/ls ( arch=x86_64-apple-darwin, platform=localhost, pid=36001, state=exited )
(lldb) bt
* thread #1: tid = 0x2d03, 0x0000000100000b9a a.out`main + 42 at main.c:16, stop reason = breakpoint 1.1
frame #0: 0x0000000100000b9a a.out`main + 42 at main.c:16
frame #1: 0x0000000100000b64 a.out`start + 52
Above we created a target for "a.out" and ran and hit a
breakpoint at "main". Then we created a new target for /bin/ls
and ran it. Then we listed the targest and selected our original
"a.out" program, so we showed two concurent debug sessions
going on at the same time.
llvm-svn: 129695
2011-04-18 16:33:37 +08:00
|
|
|
EDDisassemblerRef disassembler,
|
2011-05-13 06:25:53 +08:00
|
|
|
llvm::Triple::ArchType arch_type) :
|
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
|
|
|
Instruction (addr, addr_class),
|
Centralized a lot of the status information for processes,
threads, and stack frame down in the lldb_private::Process,
lldb_private::Thread, lldb_private::StackFrameList and the
lldb_private::StackFrame classes. We had some command line
commands that had duplicate versions of the process status
output ("thread list" and "process status" for example).
Removed the "file" command and placed it where it should
have been: "target create". Made an alias for "file" to
"target create" so we stay compatible with GDB commands.
We can now have multple usable targets in lldb at the
same time. This is nice for comparing two runs of a program
or debugging more than one binary at the same time. The
new command is "target select <target-idx>" and also to see
a list of the current targets you can use the new "target list"
command. The flow in a debug session can be:
(lldb) target create /path/to/exe/a.out
(lldb) breakpoint set --name main
(lldb) run
... hit breakpoint
(lldb) target create /bin/ls
(lldb) run /tmp
Process 36001 exited with status = 0 (0x00000000)
(lldb) target list
Current targets:
target #0: /tmp/args/a.out ( arch=x86_64-apple-darwin, platform=localhost, pid=35999, state=stopped )
* target #1: /bin/ls ( arch=x86_64-apple-darwin, platform=localhost, pid=36001, state=exited )
(lldb) target select 0
Current targets:
* target #0: /tmp/args/a.out ( arch=x86_64-apple-darwin, platform=localhost, pid=35999, state=stopped )
target #1: /bin/ls ( arch=x86_64-apple-darwin, platform=localhost, pid=36001, state=exited )
(lldb) bt
* thread #1: tid = 0x2d03, 0x0000000100000b9a a.out`main + 42 at main.c:16, stop reason = breakpoint 1.1
frame #0: 0x0000000100000b9a a.out`main + 42 at main.c:16
frame #1: 0x0000000100000b64 a.out`start + 52
Above we created a target for "a.out" and ran and hit a
breakpoint at "main". Then we created a new target for /bin/ls
and ran it. Then we listed the targest and selected our original
"a.out" program, so we showed two concurent debug sessions
going on at the same time.
llvm-svn: 129695
2011-04-18 16:33:37 +08:00
|
|
|
m_disassembler (disassembler),
|
2011-11-01 06:50:49 +08:00
|
|
|
m_inst (NULL),
|
|
|
|
m_arch_type (arch_type)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-04-06 07:22:54 +08:00
|
|
|
InstructionLLVM::~InstructionLLVM()
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2011-10-28 06:16:42 +08:00
|
|
|
if (m_inst)
|
|
|
|
{
|
|
|
|
EDReleaseInst(m_inst);
|
|
|
|
m_inst = NULL;
|
|
|
|
}
|
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());
|
|
|
|
}
|
2011-05-24 07:29:23 +08:00
|
|
|
static void
|
2011-09-26 15:11:27 +08:00
|
|
|
AddSymbolicInfo (ExecutionContextScope *exe_scope,
|
|
|
|
StreamString &comment,
|
|
|
|
uint64_t operand_value,
|
|
|
|
const Address &inst_addr)
|
2011-05-24 07:29:23 +08:00
|
|
|
{
|
|
|
|
Address so_addr;
|
2011-09-22 12:58:26 +08:00
|
|
|
Target *target = NULL;
|
2011-09-26 15:11:27 +08:00
|
|
|
if (exe_scope)
|
|
|
|
target = exe_scope->CalculateTarget();
|
2011-09-22 12:58:26 +08:00
|
|
|
if (target && !target->GetSectionLoadList().IsEmpty())
|
2011-05-24 07:29:23 +08:00
|
|
|
{
|
2011-09-22 12:58:26 +08:00
|
|
|
if (target->GetSectionLoadList().ResolveLoadAddress(operand_value, so_addr))
|
2011-05-24 07:29:23 +08:00
|
|
|
so_addr.Dump(&comment, exe_scope, Address::DumpStyleResolvedDescriptionNoModule, Address::DumpStyleSectionNameOffset);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Module *module = inst_addr.GetModule();
|
|
|
|
if (module)
|
|
|
|
{
|
|
|
|
if (module->ResolveFileAddress(operand_value, so_addr))
|
|
|
|
so_addr.Dump(&comment, exe_scope, Address::DumpStyleResolvedDescriptionNoModule, Address::DumpStyleSectionNameOffset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2011-05-19 09:05:37 +08:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
2011-05-24 07:29:23 +08:00
|
|
|
static inline void StripSpaces(llvm::StringRef &Str)
|
2011-05-19 09:05:37 +08:00
|
|
|
{
|
|
|
|
while (!Str.empty() && isspace(Str[0]))
|
|
|
|
Str = Str.substr(1);
|
|
|
|
while (!Str.empty() && isspace(Str.back()))
|
|
|
|
Str = Str.substr(0, Str.size()-1);
|
|
|
|
}
|
2011-05-24 07:29:23 +08:00
|
|
|
static inline void RStrip(llvm::StringRef &Str, char c)
|
|
|
|
{
|
|
|
|
if (!Str.empty() && Str.back() == c)
|
|
|
|
Str = Str.substr(0, Str.size()-1);
|
|
|
|
}
|
2011-05-25 04:36:40 +08:00
|
|
|
// Aligns the raw disassembly (passed as 'str') with the rest of edis'ed disassembly output.
|
|
|
|
// This is called from non-raw mode when edis of the current m_inst fails for some reason.
|
2011-05-21 08:55:57 +08:00
|
|
|
static void
|
2011-05-24 02:00:40 +08:00
|
|
|
Align(Stream *s, const char *str, size_t opcodeColWidth, size_t operandColWidth)
|
2011-05-21 08:55:57 +08:00
|
|
|
{
|
|
|
|
llvm::StringRef raw_disasm(str);
|
|
|
|
StripSpaces(raw_disasm);
|
2011-05-24 02:00:40 +08:00
|
|
|
// Split the raw disassembly into opcode and operands.
|
|
|
|
std::pair<llvm::StringRef, llvm::StringRef> p = raw_disasm.split('\t');
|
|
|
|
PadString(s, p.first, opcodeColWidth);
|
|
|
|
if (!p.second.empty())
|
|
|
|
PadString(s, p.second, operandColWidth);
|
2011-05-21 08:55:57 +08:00
|
|
|
}
|
2011-05-19 09:05:37 +08:00
|
|
|
|
2011-08-03 12:50:37 +08:00
|
|
|
#define AlignPC(pc_val) (pc_val & 0xFFFFFFFC)
|
2010-06-09 00:52:24 +08:00
|
|
|
void
|
2011-04-06 07:22:54 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-08 06:46:35 +08:00
|
|
|
int numTokens = -1;
|
|
|
|
|
2011-05-13 06:25:53 +08:00
|
|
|
// FIXME!!!
|
|
|
|
/* Remove the following section of code related to force_raw .... */
|
2011-05-24 02:00:40 +08:00
|
|
|
/*
|
2011-05-13 06:25:53 +08:00
|
|
|
bool force_raw = m_arch_type == llvm::Triple::arm ||
|
|
|
|
m_arch_type == llvm::Triple::thumb;
|
Centralized a lot of the status information for processes,
threads, and stack frame down in the lldb_private::Process,
lldb_private::Thread, lldb_private::StackFrameList and the
lldb_private::StackFrame classes. We had some command line
commands that had duplicate versions of the process status
output ("thread list" and "process status" for example).
Removed the "file" command and placed it where it should
have been: "target create". Made an alias for "file" to
"target create" so we stay compatible with GDB commands.
We can now have multple usable targets in lldb at the
same time. This is nice for comparing two runs of a program
or debugging more than one binary at the same time. The
new command is "target select <target-idx>" and also to see
a list of the current targets you can use the new "target list"
command. The flow in a debug session can be:
(lldb) target create /path/to/exe/a.out
(lldb) breakpoint set --name main
(lldb) run
... hit breakpoint
(lldb) target create /bin/ls
(lldb) run /tmp
Process 36001 exited with status = 0 (0x00000000)
(lldb) target list
Current targets:
target #0: /tmp/args/a.out ( arch=x86_64-apple-darwin, platform=localhost, pid=35999, state=stopped )
* target #1: /bin/ls ( arch=x86_64-apple-darwin, platform=localhost, pid=36001, state=exited )
(lldb) target select 0
Current targets:
* target #0: /tmp/args/a.out ( arch=x86_64-apple-darwin, platform=localhost, pid=35999, state=stopped )
target #1: /bin/ls ( arch=x86_64-apple-darwin, platform=localhost, pid=36001, state=exited )
(lldb) bt
* thread #1: tid = 0x2d03, 0x0000000100000b9a a.out`main + 42 at main.c:16, stop reason = breakpoint 1.1
frame #0: 0x0000000100000b9a a.out`main + 42 at main.c:16
frame #1: 0x0000000100000b64 a.out`start + 52
Above we created a target for "a.out" and ran and hit a
breakpoint at "main". Then we created a new target for /bin/ls
and ran it. Then we listed the targest and selected our original
"a.out" program, so we showed two concurent debug sessions
going on at the same time.
llvm-svn: 129695
2011-04-18 16:33:37 +08:00
|
|
|
if (!raw)
|
2011-05-13 06:25:53 +08:00
|
|
|
raw = force_raw;
|
2011-05-24 02:00:40 +08:00
|
|
|
*/
|
2011-05-13 06:25:53 +08:00
|
|
|
/* .... when we fix the edis for arm/thumb. */
|
Centralized a lot of the status information for processes,
threads, and stack frame down in the lldb_private::Process,
lldb_private::Thread, lldb_private::StackFrameList and the
lldb_private::StackFrame classes. We had some command line
commands that had duplicate versions of the process status
output ("thread list" and "process status" for example).
Removed the "file" command and placed it where it should
have been: "target create". Made an alias for "file" to
"target create" so we stay compatible with GDB commands.
We can now have multple usable targets in lldb at the
same time. This is nice for comparing two runs of a program
or debugging more than one binary at the same time. The
new command is "target select <target-idx>" and also to see
a list of the current targets you can use the new "target list"
command. The flow in a debug session can be:
(lldb) target create /path/to/exe/a.out
(lldb) breakpoint set --name main
(lldb) run
... hit breakpoint
(lldb) target create /bin/ls
(lldb) run /tmp
Process 36001 exited with status = 0 (0x00000000)
(lldb) target list
Current targets:
target #0: /tmp/args/a.out ( arch=x86_64-apple-darwin, platform=localhost, pid=35999, state=stopped )
* target #1: /bin/ls ( arch=x86_64-apple-darwin, platform=localhost, pid=36001, state=exited )
(lldb) target select 0
Current targets:
* target #0: /tmp/args/a.out ( arch=x86_64-apple-darwin, platform=localhost, pid=35999, state=stopped )
target #1: /bin/ls ( arch=x86_64-apple-darwin, platform=localhost, pid=36001, state=exited )
(lldb) bt
* thread #1: tid = 0x2d03, 0x0000000100000b9a a.out`main + 42 at main.c:16, stop reason = breakpoint 1.1
frame #0: 0x0000000100000b9a a.out`main + 42 at main.c:16
frame #1: 0x0000000100000b64 a.out`start + 52
Above we created a target for "a.out" and ran and hit a
breakpoint at "main". Then we created a new target for /bin/ls
and ran it. Then we listed the targest and selected our original
"a.out" program, so we showed two concurent debug sessions
going on at the same time.
llvm-svn: 129695
2011-04-18 16:33:37 +08:00
|
|
|
|
2011-08-20 01:31:59 +08:00
|
|
|
if (!raw)
|
2011-04-08 06:46:35 +08:00
|
|
|
numTokens = EDNumTokens(m_inst);
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
int currentOpIndex = -1;
|
|
|
|
|
2011-04-08 06:46:35 +08:00
|
|
|
bool printTokenized = false;
|
|
|
|
|
|
|
|
if (numTokens != -1 && !raw)
|
2010-07-23 10:19:15 +08:00
|
|
|
{
|
|
|
|
addr_t base_addr = LLDB_INVALID_ADDRESS;
|
2011-09-26 15:11:27 +08:00
|
|
|
uint32_t addr_nibble_size = 8;
|
2011-09-22 12:58:26 +08:00
|
|
|
Target *target = NULL;
|
|
|
|
if (exe_ctx)
|
|
|
|
target = exe_ctx->GetTargetPtr();
|
2011-09-26 15:11:27 +08:00
|
|
|
if (target)
|
|
|
|
{
|
|
|
|
if (!target->GetSectionLoadList().IsEmpty())
|
|
|
|
base_addr = GetAddress().GetLoadAddress (target);
|
|
|
|
addr_nibble_size = target->GetArchitecture().GetAddressByteSize() * 2;
|
|
|
|
}
|
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 ();
|
2011-04-08 06:46:35 +08:00
|
|
|
|
2011-05-13 06:25:53 +08:00
|
|
|
lldb::addr_t PC = base_addr + EDInstByteSize(m_inst);
|
|
|
|
|
|
|
|
// When executing an ARM instruction, PC reads as the address of the
|
|
|
|
// current instruction plus 8. And for Thumb, it is plus 4.
|
|
|
|
if (m_arch_type == llvm::Triple::arm)
|
|
|
|
PC = base_addr + 8;
|
|
|
|
else if (m_arch_type == llvm::Triple::thumb)
|
|
|
|
PC = base_addr + 4;
|
|
|
|
|
|
|
|
RegisterReaderArg rra(PC, m_disassembler);
|
2011-05-13 02:48:11 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
printTokenized = true;
|
|
|
|
|
|
|
|
// Handle the opcode column.
|
|
|
|
|
|
|
|
StreamString opcode;
|
|
|
|
|
|
|
|
int tokenIndex = 0;
|
|
|
|
|
|
|
|
EDTokenRef token;
|
|
|
|
const char *tokenStr;
|
|
|
|
|
2011-05-19 06:48:41 +08:00
|
|
|
if (EDGetToken(&token, m_inst, tokenIndex)) // 0 on success
|
2010-06-09 00:52:24 +08:00
|
|
|
printTokenized = false;
|
2011-05-19 06:48:41 +08:00
|
|
|
else if (!EDTokenIsOpcode(token))
|
2010-06-09 00:52:24 +08:00
|
|
|
printTokenized = false;
|
2011-05-19 06:48:41 +08:00
|
|
|
else if (EDGetTokenString(&tokenStr, token)) // 0 on success
|
2010-06-09 00:52:24 +08:00
|
|
|
printTokenized = false;
|
|
|
|
|
2011-05-19 06:48:41 +08:00
|
|
|
if (printTokenized)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2011-05-19 06:48:41 +08:00
|
|
|
// Put the token string into our opcode string
|
|
|
|
opcode.PutCString(tokenStr);
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2011-05-19 06:48:41 +08:00
|
|
|
// If anything follows, it probably starts with some whitespace. Skip it.
|
|
|
|
if (++tokenIndex < numTokens)
|
|
|
|
{
|
|
|
|
if (EDGetToken(&token, m_inst, tokenIndex)) // 0 on success
|
|
|
|
printTokenized = false;
|
|
|
|
else if (!EDTokenIsWhitespace(token))
|
|
|
|
printTokenized = false;
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2011-05-19 06:48:41 +08:00
|
|
|
++tokenIndex;
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
// Handle the operands and the comment.
|
|
|
|
StreamString operands;
|
|
|
|
StreamString comment;
|
|
|
|
|
|
|
|
if (printTokenized)
|
|
|
|
{
|
2011-05-19 09:05:37 +08:00
|
|
|
bool show_token = false;
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
for (; tokenIndex < numTokens; ++tokenIndex)
|
|
|
|
{
|
|
|
|
if (EDGetToken(&token, m_inst, tokenIndex))
|
|
|
|
return;
|
|
|
|
|
2011-05-19 06:08:52 +08:00
|
|
|
int operandIndex = EDOperandIndexForToken(token);
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2011-05-19 06:08:52 +08:00
|
|
|
if (operandIndex >= 0)
|
|
|
|
{
|
|
|
|
if (operandIndex != currentOpIndex)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2011-05-19 06:08:52 +08:00
|
|
|
show_token = true;
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2011-05-19 06:08:52 +08:00
|
|
|
currentOpIndex = operandIndex;
|
|
|
|
EDOperandRef operand;
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2011-05-19 06:08:52 +08:00
|
|
|
if (!EDGetOperand(&operand, m_inst, currentOpIndex))
|
|
|
|
{
|
|
|
|
if (EDOperandIsMemory(operand))
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2011-05-19 06:08:52 +08:00
|
|
|
uint64_t operand_value;
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2011-05-19 06:08:52 +08:00
|
|
|
if (!EDEvaluateOperand(&operand_value, operand, IPRegisterReader, &rra))
|
|
|
|
{
|
|
|
|
if (EDInstIsBranch(m_inst))
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2011-09-26 15:11:27 +08:00
|
|
|
operands.Printf("0x%*.*llx ", addr_nibble_size, addr_nibble_size, operand_value);
|
2011-05-19 06:08:52 +08:00
|
|
|
show_token = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Put the address value into the comment
|
2011-09-26 15:11:27 +08:00
|
|
|
comment.Printf("0x%*.*llx ", addr_nibble_size, addr_nibble_size, operand_value);
|
2011-05-19 06:08:52 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2011-09-26 15:11:27 +08:00
|
|
|
AddSymbolicInfo(exe_scope, comment, operand_value, GetAddress());
|
2011-05-19 06:08:52 +08:00
|
|
|
} // EDEvaluateOperand
|
|
|
|
} // EDOperandIsMemory
|
|
|
|
} // EDGetOperand
|
|
|
|
} // operandIndex != currentOpIndex
|
|
|
|
} // operandIndex >= 0
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
if (show_token)
|
|
|
|
{
|
The implementation of categories is now synchronization safe
Code cleanup:
- The Format Manager implementation is now split between two files: FormatClasses.{h|cpp} where the
actual formatter classes (ValueFormat, SummaryFormat, ...) are implemented and
FormatManager.{h|cpp} where the infrastructure classes (FormatNavigator, FormatManager, ...)
are contained. The wrapper code always remains in Debugger.{h|cpp}
- Several leftover fields, methods and comments from previous design choices have been removed
type category subcommands (enable, disable, delete) now can take a list of category names as input
- for type category enable, saying "enable A B C" is the same as saying
enable C
enable B
enable A
(the ordering is relevant in enabling categories, and it is expected that a user typing
enable A B C wants to look into category A, then into B, then into C and not the other
way round)
- for the other two commands, the order is not really relevant (however, the same inverted ordering
is used for consistency)
llvm-svn: 135494
2011-07-20 02:03:25 +08:00
|
|
|
if (EDGetTokenString(&tokenStr, token))
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
printTokenized = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
operands.PutCString(tokenStr);
|
|
|
|
}
|
|
|
|
} // for (tokenIndex)
|
|
|
|
|
2011-05-21 01:27:37 +08:00
|
|
|
// FIXME!!!
|
|
|
|
// Workaround for llvm::tB's operands not properly parsed by ARMAsmParser.
|
|
|
|
if (m_arch_type == llvm::Triple::thumb && opcode.GetString() == "b") {
|
|
|
|
const char *inst_str;
|
2011-05-21 06:42:59 +08:00
|
|
|
const char *pos = NULL;
|
2011-05-24 03:41:31 +08:00
|
|
|
operands.Clear(); comment.Clear();
|
2011-05-21 01:27:37 +08:00
|
|
|
if (EDGetInstString(&inst_str, m_inst) == 0 && (pos = strstr(inst_str, "#")) != NULL) {
|
|
|
|
uint64_t operand_value = PC + atoi(++pos);
|
2011-05-24 07:29:23 +08:00
|
|
|
// Put the address value into the operands.
|
2011-09-26 15:11:27 +08:00
|
|
|
operands.Printf("0x%8.8llx ", operand_value);
|
|
|
|
AddSymbolicInfo(exe_scope, comment, operand_value, GetAddress());
|
2011-05-24 03:41:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// Yet more workaround for "bl #..." and "blx #...".
|
|
|
|
if ((m_arch_type == llvm::Triple::arm || m_arch_type == llvm::Triple::thumb) &&
|
|
|
|
(opcode.GetString() == "bl" || opcode.GetString() == "blx")) {
|
|
|
|
const char *inst_str;
|
|
|
|
const char *pos = NULL;
|
|
|
|
operands.Clear(); comment.Clear();
|
|
|
|
if (EDGetInstString(&inst_str, m_inst) == 0 && (pos = strstr(inst_str, "#")) != NULL) {
|
2011-08-03 12:50:37 +08:00
|
|
|
if (m_arch_type == llvm::Triple::thumb && opcode.GetString() == "blx") {
|
|
|
|
// A8.6.23 BLX (immediate)
|
|
|
|
// Target Address = Align(PC,4) + offset value
|
|
|
|
PC = AlignPC(PC);
|
|
|
|
}
|
2011-05-24 03:41:31 +08:00
|
|
|
uint64_t operand_value = PC + atoi(++pos);
|
2011-05-24 07:29:23 +08:00
|
|
|
// Put the address value into the comment.
|
2011-09-26 15:11:27 +08:00
|
|
|
comment.Printf("0x%8.8llx ", operand_value);
|
2011-05-24 07:29:23 +08:00
|
|
|
// And the original token string into the operands.
|
|
|
|
llvm::StringRef Str(pos - 1);
|
|
|
|
RStrip(Str, '\n');
|
|
|
|
operands.PutCString(Str.str().c_str());
|
2011-09-26 15:11:27 +08:00
|
|
|
AddSymbolicInfo(exe_scope, comment, operand_value, GetAddress());
|
2011-05-21 01:27:37 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// END of workaround.
|
|
|
|
|
2011-05-19 09:05:37 +08:00
|
|
|
// If both operands and comment are empty, we will just print out
|
|
|
|
// the raw disassembly.
|
|
|
|
if (operands.GetString().empty() && comment.GetString().empty())
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2011-05-19 09:05:37 +08:00
|
|
|
const char *str;
|
|
|
|
|
|
|
|
if (EDGetInstString(&str, m_inst))
|
|
|
|
return;
|
2011-05-24 02:00:40 +08:00
|
|
|
Align(s, str, opcodeColumnWidth, operandColumnWidth);
|
2011-05-19 09:05:37 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PadString(s, opcode.GetString(), opcodeColumnWidth);
|
|
|
|
|
|
|
|
if (comment.GetString().empty())
|
|
|
|
s->PutCString(operands.GetString().c_str());
|
2010-06-09 00:52:24 +08:00
|
|
|
else
|
|
|
|
{
|
2011-05-19 09:05:37 +08:00
|
|
|
PadString(s, operands.GetString(), operandColumnWidth);
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2011-05-19 09:05:37 +08:00
|
|
|
s->PutCString("; ");
|
|
|
|
s->PutCString(comment.GetString().c_str());
|
|
|
|
} // else (comment.GetString().empty())
|
|
|
|
} // else (operands.GetString().empty() && comment.GetString().empty())
|
|
|
|
} // printTokenized
|
2010-06-09 00:52:24 +08:00
|
|
|
} // numTokens != -1
|
|
|
|
|
|
|
|
if (!printTokenized)
|
|
|
|
{
|
|
|
|
const char *str;
|
|
|
|
|
2011-05-19 09:05:37 +08:00
|
|
|
if (EDGetInstString(&str, m_inst)) // 0 on success
|
2010-06-09 00:52:24 +08:00
|
|
|
return;
|
2011-05-21 08:44:42 +08:00
|
|
|
if (raw)
|
|
|
|
s->Write(str, strlen(str) - 1);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// EDis fails to parse the tokens of this inst. Need to align this
|
2011-05-21 08:55:57 +08:00
|
|
|
// raw disassembly's opcode with the rest of output.
|
2011-05-24 02:00:40 +08:00
|
|
|
Align(s, str, opcodeColumnWidth, operandColumnWidth);
|
2011-05-21 08:44:42 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-26 15:11:27 +08:00
|
|
|
void
|
2011-09-27 08:58:45 +08:00
|
|
|
InstructionLLVM::CalculateMnemonic (ExecutionContextScope *exe_scope)
|
2011-09-26 15:11:27 +08:00
|
|
|
{
|
|
|
|
const int num_tokens = EDNumTokens(m_inst);
|
|
|
|
if (num_tokens > 0)
|
|
|
|
{
|
|
|
|
const char *token_cstr = NULL;
|
|
|
|
int currentOpIndex = -1;
|
|
|
|
StreamString comment;
|
|
|
|
uint32_t addr_nibble_size = 8;
|
|
|
|
addr_t base_addr = LLDB_INVALID_ADDRESS;
|
|
|
|
Target *target = NULL;
|
|
|
|
if (exe_scope)
|
|
|
|
target = exe_scope->CalculateTarget();
|
|
|
|
if (target && !target->GetSectionLoadList().IsEmpty())
|
|
|
|
base_addr = GetAddress().GetLoadAddress (target);
|
|
|
|
if (base_addr == LLDB_INVALID_ADDRESS)
|
|
|
|
base_addr = GetAddress().GetFileAddress ();
|
|
|
|
addr_nibble_size = target->GetArchitecture().GetAddressByteSize() * 2;
|
|
|
|
|
|
|
|
lldb::addr_t PC = base_addr + EDInstByteSize(m_inst);
|
|
|
|
|
|
|
|
// When executing an ARM instruction, PC reads as the address of the
|
|
|
|
// current instruction plus 8. And for Thumb, it is plus 4.
|
|
|
|
if (m_arch_type == llvm::Triple::arm)
|
|
|
|
PC = base_addr + 8;
|
|
|
|
else if (m_arch_type == llvm::Triple::thumb)
|
|
|
|
PC = base_addr + 4;
|
|
|
|
|
|
|
|
RegisterReaderArg rra(PC, m_disassembler);
|
|
|
|
|
|
|
|
for (int token_idx = 0; token_idx < num_tokens; ++token_idx)
|
|
|
|
{
|
|
|
|
EDTokenRef token;
|
|
|
|
if (EDGetToken(&token, m_inst, token_idx))
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (EDTokenIsOpcode(token) == 1)
|
|
|
|
{
|
|
|
|
if (EDGetTokenString(&token_cstr, token) == 0) // 0 on success
|
|
|
|
{
|
|
|
|
if (token_cstr)
|
|
|
|
m_opcode_name.assign(token_cstr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int operandIndex = EDOperandIndexForToken(token);
|
|
|
|
|
|
|
|
if (operandIndex >= 0)
|
|
|
|
{
|
|
|
|
if (operandIndex != currentOpIndex)
|
|
|
|
{
|
|
|
|
currentOpIndex = operandIndex;
|
|
|
|
EDOperandRef operand;
|
|
|
|
|
|
|
|
if (!EDGetOperand(&operand, m_inst, currentOpIndex))
|
|
|
|
{
|
|
|
|
if (EDOperandIsMemory(operand))
|
|
|
|
{
|
|
|
|
uint64_t operand_value;
|
|
|
|
|
|
|
|
if (!EDEvaluateOperand(&operand_value, operand, IPRegisterReader, &rra))
|
|
|
|
{
|
|
|
|
comment.Printf("0x%*.*llx ", addr_nibble_size, addr_nibble_size, operand_value);
|
|
|
|
AddSymbolicInfo (exe_scope, comment, operand_value, GetAddress());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (m_mnemocics.empty() && EDTokenIsWhitespace (token) == 1)
|
|
|
|
continue;
|
|
|
|
if (EDGetTokenString (&token_cstr, token))
|
|
|
|
break;
|
|
|
|
m_mnemocics.append (token_cstr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// FIXME!!!
|
|
|
|
// Workaround for llvm::tB's operands not properly parsed by ARMAsmParser.
|
|
|
|
if (m_arch_type == llvm::Triple::thumb && m_opcode_name.compare("b") == 0)
|
|
|
|
{
|
|
|
|
const char *inst_str;
|
|
|
|
const char *pos = NULL;
|
|
|
|
comment.Clear();
|
|
|
|
if (EDGetInstString(&inst_str, m_inst) == 0 && (pos = strstr(inst_str, "#")) != NULL)
|
|
|
|
{
|
|
|
|
uint64_t operand_value = PC + atoi(++pos);
|
|
|
|
// Put the address value into the operands.
|
|
|
|
comment.Printf("0x%*.*llx ", addr_nibble_size, addr_nibble_size, operand_value);
|
|
|
|
AddSymbolicInfo (exe_scope, comment, operand_value, GetAddress());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Yet more workaround for "bl #..." and "blx #...".
|
|
|
|
if ((m_arch_type == llvm::Triple::arm || m_arch_type == llvm::Triple::thumb) &&
|
|
|
|
(m_opcode_name.compare("bl") == 0 || m_opcode_name.compare("blx") == 0))
|
|
|
|
{
|
|
|
|
const char *inst_str;
|
|
|
|
const char *pos = NULL;
|
|
|
|
comment.Clear();
|
|
|
|
if (EDGetInstString(&inst_str, m_inst) == 0 && (pos = strstr(inst_str, "#")) != NULL)
|
|
|
|
{
|
|
|
|
if (m_arch_type == llvm::Triple::thumb && m_opcode_name.compare("blx") == 0)
|
|
|
|
{
|
|
|
|
// A8.6.23 BLX (immediate)
|
|
|
|
// Target Address = Align(PC,4) + offset value
|
|
|
|
PC = AlignPC(PC);
|
|
|
|
}
|
|
|
|
uint64_t operand_value = PC + atoi(++pos);
|
|
|
|
// Put the address value into the comment.
|
|
|
|
comment.Printf("0x%*.*llx ", addr_nibble_size, addr_nibble_size, operand_value);
|
|
|
|
// And the original token string into the operands.
|
|
|
|
// llvm::StringRef Str(pos - 1);
|
|
|
|
// RStrip(Str, '\n');
|
|
|
|
// operands.PutCString(Str.str().c_str());
|
|
|
|
AddSymbolicInfo (exe_scope, comment, operand_value, GetAddress());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// END of workaround.
|
|
|
|
|
|
|
|
m_comment.swap (comment.GetString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-09-27 08:58:45 +08:00
|
|
|
InstructionLLVM::CalculateOperands(ExecutionContextScope *exe_scope)
|
2011-09-26 15:11:27 +08:00
|
|
|
{
|
2011-09-27 08:58:45 +08:00
|
|
|
// Do all of the work in CalculateMnemonic()
|
|
|
|
CalculateMnemonic (exe_scope);
|
2011-09-26 15:11:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
InstructionLLVM::CalculateComment(ExecutionContextScope *exe_scope)
|
|
|
|
{
|
2011-09-27 08:58:45 +08:00
|
|
|
// Do all of the work in CalculateMnemonic()
|
|
|
|
CalculateMnemonic (exe_scope);
|
2011-09-26 15:11:27 +08:00
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
bool
|
2011-04-06 07:22:54 +08:00
|
|
|
InstructionLLVM::DoesBranch() const
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
return EDInstIsBranch(m_inst);
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
2011-04-06 07:22:54 +08:00
|
|
|
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-04-20 07:30:03 +08:00
|
|
|
{
|
|
|
|
if (GetAddressClass() == eAddressClassCodeAlternateISA)
|
|
|
|
{
|
|
|
|
// If it is a 32-bit THUMB instruction, we need to swap the upper & lower halves.
|
|
|
|
uint32_t orig_bytes = data.GetU32 (&offset);
|
|
|
|
uint16_t upper_bits = (orig_bytes >> 16) & ((1u << 16) - 1);
|
|
|
|
uint16_t lower_bits = orig_bytes & ((1u << 16) - 1);
|
|
|
|
uint32_t swapped = (lower_bits << 16) | upper_bits;
|
|
|
|
m_opcode.SetOpcode32 (swapped);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
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));
|
|
|
|
|
2011-04-06 02:46:00 +08:00
|
|
|
if (disasm_ap.get() && disasm_ap->IsValid())
|
2011-02-16 08:00:43 +08:00
|
|
|
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-11-29 09:09:49 +08:00
|
|
|
// Initialize the LLVM objects needed to use the disassembler.
|
|
|
|
static struct InitializeLLVM {
|
|
|
|
InitializeLLVM() {
|
|
|
|
llvm::InitializeAllTargetInfos();
|
|
|
|
llvm::InitializeAllTargetMCs();
|
|
|
|
llvm::InitializeAllAsmParsers();
|
|
|
|
llvm::InitializeAllDisassemblers();
|
|
|
|
}
|
|
|
|
} InitializeLLVM;
|
|
|
|
|
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)
|
|
|
|
{
|
2011-12-17 02:15:52 +08:00
|
|
|
if (EDGetDisassembler(&m_disassembler_thumb, "thumbv7-apple-darwin", kEDAssemblySyntaxARMUAL))
|
2011-03-19 09:12:21 +08:00
|
|
|
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-05-13 06:25:53 +08:00
|
|
|
|
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,
|
Centralized a lot of the status information for processes,
threads, and stack frame down in the lldb_private::Process,
lldb_private::Thread, lldb_private::StackFrameList and the
lldb_private::StackFrame classes. We had some command line
commands that had duplicate versions of the process status
output ("thread list" and "process status" for example).
Removed the "file" command and placed it where it should
have been: "target create". Made an alias for "file" to
"target create" so we stay compatible with GDB commands.
We can now have multple usable targets in lldb at the
same time. This is nice for comparing two runs of a program
or debugging more than one binary at the same time. The
new command is "target select <target-idx>" and also to see
a list of the current targets you can use the new "target list"
command. The flow in a debug session can be:
(lldb) target create /path/to/exe/a.out
(lldb) breakpoint set --name main
(lldb) run
... hit breakpoint
(lldb) target create /bin/ls
(lldb) run /tmp
Process 36001 exited with status = 0 (0x00000000)
(lldb) target list
Current targets:
target #0: /tmp/args/a.out ( arch=x86_64-apple-darwin, platform=localhost, pid=35999, state=stopped )
* target #1: /bin/ls ( arch=x86_64-apple-darwin, platform=localhost, pid=36001, state=exited )
(lldb) target select 0
Current targets:
* target #0: /tmp/args/a.out ( arch=x86_64-apple-darwin, platform=localhost, pid=35999, state=stopped )
target #1: /bin/ls ( arch=x86_64-apple-darwin, platform=localhost, pid=36001, state=exited )
(lldb) bt
* thread #1: tid = 0x2d03, 0x0000000100000b9a a.out`main + 42 at main.c:16, stop reason = breakpoint 1.1
frame #0: 0x0000000100000b9a a.out`main + 42 at main.c:16
frame #1: 0x0000000100000b64 a.out`start + 52
Above we created a target for "a.out" and ran and hit a
breakpoint at "main". Then we created a new target for /bin/ls
and ran it. Then we listed the targest and selected our original
"a.out" program, so we showed two concurent debug sessions
going on at the same time.
llvm-svn: 129695
2011-04-18 16:33:37 +08:00
|
|
|
use_thumb ? m_disassembler_thumb : m_disassembler,
|
2011-05-19 02:22:16 +08:00
|
|
|
use_thumb ? llvm::Triple::thumb : m_arch.GetMachine()));
|
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;
|
|
|
|
}
|
|
|
|
|