summaryrefslogtreecommitdiffstats
path: root/lldb/source/Plugins/Disassembler/llvm/DisassemblerLLVM.cpp
diff options
context:
space:
mode:
authorGreg Clayton <gclayton@apple.com>2012-05-10 02:52:23 +0000
committerGreg Clayton <gclayton@apple.com>2012-05-10 02:52:23 +0000
commitba812f42842530d6f2123fa34ca30e82ad3515cf (patch)
tree9940cde31aea9b0312d107d4497e876eac71623f /lldb/source/Plugins/Disassembler/llvm/DisassemblerLLVM.cpp
parentc67f223c9ee4cbfa478a1d6e9cfe5b03c524b4fa (diff)
downloadbcm5719-llvm-ba812f42842530d6f2123fa34ca30e82ad3515cf.tar.gz
bcm5719-llvm-ba812f42842530d6f2123fa34ca30e82ad3515cf.zip
<rdar://problem/11330621>
Fixed the DisassemblerLLVMC disassembler to parse more efficiently instead of parsing opcodes over and over. The InstructionLLVMC class now only reads the opcode in the InstructionLLVMC::Decode function. This can be done very efficiently for ARM and architectures that have fixed opcode sizes. For x64 it still calls the disassembler to get the byte size. Moved the lldb_private::Instruction::Dump(...) function up into the lldb_private::Instruction class and it now uses the function that gets the mnemonic, operandes and comments so that all disassembly is using the same code. Added StreamString::FillLastLineToColumn() to allow filling a line up to a column with a character (which is used by the lldb_private::Instruction::Dump(...) function). Modified the Opcode::GetData() fucntion to "do the right thing" for thumb instructions. llvm-svn: 156532
Diffstat (limited to 'lldb/source/Plugins/Disassembler/llvm/DisassemblerLLVM.cpp')
-rw-r--r--lldb/source/Plugins/Disassembler/llvm/DisassemblerLLVM.cpp287
1 files changed, 5 insertions, 282 deletions
diff --git a/lldb/source/Plugins/Disassembler/llvm/DisassemblerLLVM.cpp b/lldb/source/Plugins/Disassembler/llvm/DisassemblerLLVM.cpp
index dd77e3061d4..fd091fe8c57 100644
--- a/lldb/source/Plugins/Disassembler/llvm/DisassemblerLLVM.cpp
+++ b/lldb/source/Plugins/Disassembler/llvm/DisassemblerLLVM.cpp
@@ -165,285 +165,9 @@ Align(Stream *s, const char *str, size_t opcodeColWidth, size_t operandColWidth)
}
#define AlignPC(pc_val) (pc_val & 0xFFFFFFFC)
-void
-InstructionLLVM::Dump
-(
- Stream *s,
- uint32_t max_opcode_byte_size,
- bool show_address,
- bool show_bytes,
- const ExecutionContext* exe_ctx,
- bool raw
-)
-{
- const size_t opcodeColumnWidth = 7;
- const size_t operandColumnWidth = 25;
-
- ExecutionContextScope *exe_scope = NULL;
- if (exe_ctx)
- exe_scope = exe_ctx->GetBestExecutionContextScope();
-
- // If we have an address, print it out
- if (GetAddress().IsValid() && show_address)
- {
- if (GetAddress().Dump (s,
- exe_scope,
- Address::DumpStyleLoadAddress,
- Address::DumpStyleModuleWithFileAddress,
- 0))
- s->PutCString(": ");
- }
-
- // If we are supposed to show bytes, "bytes" will be non-NULL.
- if (show_bytes)
- {
- if (m_opcode.GetType() == Opcode::eTypeBytes)
- {
- // 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
- if (max_opcode_byte_size > 0)
- m_opcode.Dump (s, max_opcode_byte_size * 3 + 1);
- else
- m_opcode.Dump (s, 15 * 3 + 1);
- }
- else
- {
- // Else, we have ARM which can show up to a uint32_t 0x00000000 (10 spaces)
- // plus two for padding...
- if (max_opcode_byte_size > 0)
- m_opcode.Dump (s, max_opcode_byte_size * 3 + 1);
- else
- m_opcode.Dump (s, 12);
- }
- }
-
- int numTokens = -1;
-
- // FIXME!!!
- /* Remove the following section of code related to force_raw .... */
- /*
- bool force_raw = m_arch_type == llvm::Triple::arm ||
- m_arch_type == llvm::Triple::thumb;
- if (!raw)
- raw = force_raw;
- */
- /* .... when we fix the edis for arm/thumb. */
-
- if (!raw)
- numTokens = EDNumTokens(m_inst);
-
- int currentOpIndex = -1;
-
- bool printTokenized = false;
-
- if (numTokens != -1 && !raw)
- {
- addr_t base_addr = LLDB_INVALID_ADDRESS;
- uint32_t addr_nibble_size = 8;
- Target *target = NULL;
- if (exe_ctx)
- target = exe_ctx->GetTargetPtr();
- if (target)
- {
- if (!target->GetSectionLoadList().IsEmpty())
- base_addr = GetAddress().GetLoadAddress (target);
- addr_nibble_size = target->GetArchitecture().GetAddressByteSize() * 2;
- }
- if (base_addr == LLDB_INVALID_ADDRESS)
- base_addr = GetAddress().GetFileAddress ();
-
- 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);
-
- printTokenized = true;
-
- // Handle the opcode column.
-
- StreamString opcode;
-
- int tokenIndex = 0;
-
- EDTokenRef token;
- const char *tokenStr;
-
- if (EDGetToken(&token, m_inst, tokenIndex)) // 0 on success
- printTokenized = false;
- else if (!EDTokenIsOpcode(token))
- printTokenized = false;
- else if (EDGetTokenString(&tokenStr, token)) // 0 on success
- printTokenized = false;
-
- if (printTokenized)
- {
- // Put the token string into our opcode string
- opcode.PutCString(tokenStr);
-
- // 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;
- }
-
- ++tokenIndex;
- }
-
- // Handle the operands and the comment.
- StreamString operands;
- StreamString comment;
-
- if (printTokenized)
- {
- bool show_token = false;
-
- for (; tokenIndex < numTokens; ++tokenIndex)
- {
- if (EDGetToken(&token, m_inst, tokenIndex))
- return;
-
- 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;
-
- if (!EDEvaluateOperand(&operand_value, operand, IPRegisterReader, &rra))
- {
- if (EDInstIsBranch(m_inst))
- {
- operands.Printf("0x%*.*llx ", addr_nibble_size, addr_nibble_size, operand_value);
- show_token = false;
- }
- else
- {
- // Put the address value into the comment
- comment.Printf("0x%*.*llx ", addr_nibble_size, addr_nibble_size, operand_value);
- }
-
- AddSymbolicInfo(exe_ctx, comment, operand_value, GetAddress());
- } // EDEvaluateOperand
- } // EDOperandIsMemory
- } // EDGetOperand
- } // operandIndex != currentOpIndex
- } // operandIndex >= 0
-
- if (show_token)
- {
- if (EDGetTokenString(&tokenStr, token))
- {
- printTokenized = false;
- break;
- }
-
- operands.PutCString(tokenStr);
- }
- } // for (tokenIndex)
-
- // 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;
- const char *pos = NULL;
- operands.Clear(); 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.
- operands.Printf("0x%8.8llx ", operand_value);
- AddSymbolicInfo(exe_ctx, comment, operand_value, GetAddress());
- }
- }
- // 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) {
- 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);
- }
- uint64_t operand_value = PC + atoi(++pos);
- // Put the address value into the comment.
- comment.Printf("0x%8.8llx ", 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_ctx, comment, operand_value, GetAddress());
- }
- }
- // END of workaround.
-
- // If both operands and comment are empty, we will just print out
- // the raw disassembly.
- if (operands.GetString().empty() && comment.GetString().empty())
- {
- const char *str;
-
- if (EDGetInstString(&str, m_inst))
- return;
- Align(s, str, opcodeColumnWidth, operandColumnWidth);
- }
- 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() && comment.GetString().empty())
- } // printTokenized
- } // numTokens != -1
-
- if (!printTokenized)
- {
- const char *str;
-
- if (EDGetInstString(&str, m_inst)) // 0 on success
- return;
- if (raw)
- s->Write(str, strlen(str) - 1);
- else
- {
- // EDis fails to parse the tokens of this inst. Need to align this
- // raw disassembly's opcode with the rest of output.
- Align(s, str, opcodeColumnWidth, operandColumnWidth);
- }
- }
-}
void
-InstructionLLVM::CalculateMnemonicOperandsAndComment (ExecutionContextScope *exe_scope)
+InstructionLLVM::CalculateMnemonicOperandsAndComment (const ExecutionContext* exe_ctx)
{
const int num_tokens = EDNumTokens(m_inst);
if (num_tokens > 0)
@@ -453,8 +177,7 @@ InstructionLLVM::CalculateMnemonicOperandsAndComment (ExecutionContextScope *exe
StreamString comment;
uint32_t addr_nibble_size = 8;
addr_t base_addr = LLDB_INVALID_ADDRESS;
- ExecutionContext exe_ctx (exe_scope);
- Target *target = exe_ctx.GetTargetPtr();
+ Target *target = exe_ctx ? exe_ctx->GetTargetPtr() : NULL;
if (target && !target->GetSectionLoadList().IsEmpty())
base_addr = GetAddress().GetLoadAddress (target);
if (base_addr == LLDB_INVALID_ADDRESS)
@@ -506,7 +229,7 @@ InstructionLLVM::CalculateMnemonicOperandsAndComment (ExecutionContextScope *exe
if (!EDEvaluateOperand(&operand_value, operand, IPRegisterReader, &rra))
{
comment.Printf("0x%*.*llx ", addr_nibble_size, addr_nibble_size, operand_value);
- AddSymbolicInfo (&exe_ctx, comment, operand_value, GetAddress());
+ AddSymbolicInfo (exe_ctx, comment, operand_value, GetAddress());
}
}
}
@@ -531,7 +254,7 @@ InstructionLLVM::CalculateMnemonicOperandsAndComment (ExecutionContextScope *exe
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_ctx, comment, operand_value, GetAddress());
+ AddSymbolicInfo (exe_ctx, comment, operand_value, GetAddress());
}
}
// Yet more workaround for "bl #..." and "blx #...".
@@ -556,7 +279,7 @@ InstructionLLVM::CalculateMnemonicOperandsAndComment (ExecutionContextScope *exe
// llvm::StringRef Str(pos - 1);
// RStrip(Str, '\n');
// operands.PutCString(Str.str().c_str());
- AddSymbolicInfo (&exe_ctx, comment, operand_value, GetAddress());
+ AddSymbolicInfo (exe_ctx, comment, operand_value, GetAddress());
}
}
// END of workaround.
OpenPOWER on IntegriCloud