aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Core/Disassembler.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2021-02-16 20:13:02 +0000
committerDimitry Andric <dim@FreeBSD.org>2021-02-16 20:13:02 +0000
commitb60736ec1405bb0a8dd40989f67ef4c93da068ab (patch)
tree5c43fbb7c9fc45f0f87e0e6795a86267dbd12f9d /lldb/source/Core/Disassembler.cpp
parentcfca06d7963fa0909f90483b42a6d7d194d01e08 (diff)
Diffstat (limited to 'lldb/source/Core/Disassembler.cpp')
-rw-r--r--lldb/source/Core/Disassembler.cpp92
1 files changed, 27 insertions, 65 deletions
diff --git a/lldb/source/Core/Disassembler.cpp b/lldb/source/Core/Disassembler.cpp
index 4da823c7a243..3a975d9296f4 100644
--- a/lldb/source/Core/Disassembler.cpp
+++ b/lldb/source/Core/Disassembler.cpp
@@ -58,9 +58,7 @@ using namespace lldb_private;
DisassemblerSP Disassembler::FindPlugin(const ArchSpec &arch,
const char *flavor,
const char *plugin_name) {
- static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
- Timer scoped_timer(func_cat,
- "Disassembler::FindPlugin (arch = %s, plugin_name = %s)",
+ LLDB_SCOPED_TIMERF("Disassembler::FindPlugin (arch = %s, plugin_name = %s)",
arch.GetArchitectureName(), plugin_name);
DisassemblerCreateInstance create_callback = nullptr;
@@ -540,34 +538,29 @@ void Disassembler::PrintInstructions(Debugger &debugger, const ArchSpec &arch,
}
bool Disassembler::Disassemble(Debugger &debugger, const ArchSpec &arch,
- const char *plugin_name, const char *flavor,
- const ExecutionContext &exe_ctx,
- uint32_t num_instructions,
- bool mixed_source_and_assembly,
- uint32_t num_mixed_context_lines,
- uint32_t options, Stream &strm) {
+ StackFrame &frame, Stream &strm) {
AddressRange range;
- StackFrame *frame = exe_ctx.GetFramePtr();
- if (frame) {
- SymbolContext sc(
- frame->GetSymbolContext(eSymbolContextFunction | eSymbolContextSymbol));
- if (sc.function) {
- range = sc.function->GetAddressRange();
- } else if (sc.symbol && sc.symbol->ValueIsAddress()) {
- range.GetBaseAddress() = sc.symbol->GetAddressRef();
- range.SetByteSize(sc.symbol->GetByteSize());
- } else {
- range.GetBaseAddress() = frame->GetFrameCodeAddress();
- }
+ SymbolContext sc(
+ frame.GetSymbolContext(eSymbolContextFunction | eSymbolContextSymbol));
+ if (sc.function) {
+ range = sc.function->GetAddressRange();
+ } else if (sc.symbol && sc.symbol->ValueIsAddress()) {
+ range.GetBaseAddress() = sc.symbol->GetAddressRef();
+ range.SetByteSize(sc.symbol->GetByteSize());
+ } else {
+ range.GetBaseAddress() = frame.GetFrameCodeAddress();
+ }
if (range.GetBaseAddress().IsValid() && range.GetByteSize() == 0)
range.SetByteSize(DEFAULT_DISASM_BYTE_SIZE);
- }
- return Disassemble(
- debugger, arch, plugin_name, flavor, exe_ctx, range.GetBaseAddress(),
- {Limit::Instructions, num_instructions}, mixed_source_and_assembly,
- num_mixed_context_lines, options, strm);
+ Disassembler::Limit limit = {Disassembler::Limit::Bytes,
+ range.GetByteSize()};
+ if (limit.value == 0)
+ limit.value = DEFAULT_DISASM_BYTE_SIZE;
+
+ return Disassemble(debugger, arch, nullptr, nullptr, frame,
+ range.GetBaseAddress(), limit, false, 0, 0, strm);
}
Instruction::Instruction(const Address &address, AddressClass addr_class)
@@ -957,6 +950,13 @@ InstructionSP InstructionList::GetInstructionAtIndex(size_t idx) const {
return inst_sp;
}
+InstructionSP InstructionList::GetInstructionAtAddress(const Address &address) {
+ uint32_t index = GetIndexOfInstructionAtAddress(address);
+ if (index != UINT32_MAX)
+ return GetInstructionAtIndex(index);
+ return nullptr;
+}
+
void InstructionList::Dump(Stream *s, bool show_address, bool show_bytes,
const ExecutionContext *exe_ctx) {
const uint32_t max_opcode_byte_size = GetMaxOpcocdeByteSize();
@@ -990,17 +990,15 @@ void InstructionList::Append(lldb::InstructionSP &inst_sp) {
uint32_t
InstructionList::GetIndexOfNextBranchInstruction(uint32_t start,
- Target &target,
bool ignore_calls,
bool *found_calls) const {
size_t num_instructions = m_instructions.size();
uint32_t next_branch = UINT32_MAX;
- size_t i;
if (found_calls)
*found_calls = false;
- for (i = start; i < num_instructions; i++) {
+ for (size_t i = start; i < num_instructions; i++) {
if (m_instructions[i]->DoesBranch()) {
if (ignore_calls && m_instructions[i]->IsCall()) {
if (found_calls)
@@ -1012,42 +1010,6 @@ InstructionList::GetIndexOfNextBranchInstruction(uint32_t start,
}
}
- // Hexagon needs the first instruction of the packet with the branch. Go
- // backwards until we find an instruction marked end-of-packet, or until we
- // hit start.
- if (target.GetArchitecture().GetTriple().getArch() == llvm::Triple::hexagon) {
- // If we didn't find a branch, find the last packet start.
- if (next_branch == UINT32_MAX) {
- i = num_instructions - 1;
- }
-
- while (i > start) {
- --i;
-
- Status error;
- uint32_t inst_bytes;
- bool prefer_file_cache = false; // Read from process if process is running
- lldb::addr_t load_addr = LLDB_INVALID_ADDRESS;
- target.ReadMemory(m_instructions[i]->GetAddress(), prefer_file_cache,
- &inst_bytes, sizeof(inst_bytes), error, &load_addr);
- // If we have an error reading memory, return start
- if (!error.Success())
- return start;
- // check if this is the last instruction in a packet bits 15:14 will be
- // 11b or 00b for a duplex
- if (((inst_bytes & 0xC000) == 0xC000) ||
- ((inst_bytes & 0xC000) == 0x0000)) {
- // instruction after this should be the start of next packet
- next_branch = i + 1;
- break;
- }
- }
-
- if (next_branch == UINT32_MAX) {
- // We couldn't find the previous packet, so return start
- next_branch = start;
- }
- }
return next_branch;
}