[lldb] Have disassembler show load addresses when using a core file by labath · Pull Request #115453 · llvm/llvm-project (original) (raw)

@llvm/pr-subscribers-lldb

Author: Pavel Labath (labath)

Changes

We got a bug report that the disassember output was not relocated (i.e. a load address) for a core file (like it is for a live process). It turns out this behavior it depends on whether the instructions were read from an executable file or from process memory (a core file will not typically contain the memory image for segments backed by an executable file).

It's unclear whether this behavior is intentional, or if it was just trying to handle the case where we're dissassembling a module without a process, but I think it's undesirable. What makes it particularly confusing is that the instruction addresses are relocated in this case (unlike the when we don't have a process), so with large files and adresses it gets very hard to see whether the relocation has been applied or not.

This patch removes the data_from_file check so that the instruction is relocated regardless of where it was read from. It will still not get relocated for the raw module use case, as those can't be relocated anywhere as they don't have a load address.


Full diff: https://github.com/llvm/llvm-project/pull/115453.diff

3 Files Affected:

diff --git a/lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp b/lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp index 31edd8d46c444e..08264d837f9c23 100644 --- a/lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp +++ b/lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp @@ -583,7 +583,6 @@ class InstructionLLVMC : public lldb_private::Instruction { lldb::addr_t pc = m_address.GetFileAddress(); m_using_file_addr = true;

@@ -593,12 +592,10 @@ class InstructionLLVMC : public lldb_private::Instruction { use_hex_immediates = target->GetUseHexImmediates(); hex_style = target->GetHexImmediateStyle();

diff --git a/lldb/test/Shell/Commands/command-disassemble-process.yaml b/lldb/test/Shell/Commands/command-disassemble-process.yaml index 75be1a42fb196d..ce1b37bc8aea7a 100644 --- a/lldb/test/Shell/Commands/command-disassemble-process.yaml +++ b/lldb/test/Shell/Commands/command-disassemble-process.yaml @@ -20,7 +20,7 @@

CHECK: (lldb) disassemble

CHECK-NEXT: command-disassemble-process.exe`main:

-# CHECK-NEXT: 0x4002 <+0>: addb %al, (%rcx) +# CHECK-NEXT: 0x4002 <+0>: jmp 0x4004 ; <+2>

CHECK-NEXT: -> 0x4004 <+2>: addb %al, (%rdx)

CHECK-NEXT: 0x4006 <+4>: addb %al, (%rbx)

CHECK-NEXT: 0x4008 <+6>: addb %al, (%rsi)

@@ -32,7 +32,7 @@

CHECK-NEXT: 0x400a: addb %al, (%rdi)

CHECK-NEXT: (lldb) disassemble --frame

CHECK-NEXT: command-disassemble-process.exe`main:

-# CHECK-NEXT: 0x4002 <+0>: addb %al, (%rcx) +# CHECK-NEXT: 0x4002 <+0>: jmp 0x4004 ; <+2>

CHECK-NEXT: -> 0x4004 <+2>: addb %al, (%rdx)

CHECK-NEXT: 0x4006 <+4>: addb %al, (%rbx)

CHECK-NEXT: 0x4008 <+6>: addb %al, (%rsi)

@@ -44,13 +44,13 @@

CHECK-NEXT: 0x400a: addb %al, (%rdi)

CHECK-NEXT: (lldb) disassemble --address 0x4004

CHECK-NEXT: command-disassemble-process.exe`main:

-# CHECK-NEXT: 0x4002 <+0>: addb %al, (%rcx) +# CHECK-NEXT: 0x4002 <+0>: jmp 0x4004 ; <+2>

CHECK-NEXT: -> 0x4004 <+2>: addb %al, (%rdx)

CHECK-NEXT: 0x4006 <+4>: addb %al, (%rbx)

CHECK-NEXT: 0x4008 <+6>: addb %al, (%rsi)

CHECK-NEXT: (lldb) disassemble --count 7

CHECK-NEXT: command-disassemble-process.exe`main:

-# CHECK-NEXT: 0x4002 <+0>: addb %al, (%rcx) +# CHECK-NEXT: 0x4002 <+0>: jmp 0x4004 ; <+2>

CHECK-NEXT: -> 0x4004 <+2>: addb %al, (%rdx)

CHECK-NEXT: 0x4006 <+4>: addb %al, (%rbx)

CHECK-NEXT: 0x4008 <+6>: addb %al, (%rsi)

@@ -81,32 +81,32 @@ Sections:

CHECK-NEXT: error: Cannot disassemble around the current PC without a selected frame: no currently running process.

CHECK-NEXT: (lldb) disassemble --start-address 0x0

CHECK-NEXT: command-disassemble.s.tmp`foo:

-# CHECK-NEXT: command-disassemble.s.tmp[0x0] <+0>: int $0x10 +# CHECK-NEXT: command-disassemble.s.tmp[0x0] <+0>: jmp 0x2 ; <+2>

CHECK-NEXT: command-disassemble.s.tmp[0x2] <+2>: int $0x11

CHECK-NEXT: command-disassemble.s.tmp[0x4] <+4>: int $0x12

CHECK-NEXT: command-disassemble.s.tmp[0x6] <+6>: int $0x13

@@ -41,7 +41,7 @@

CHECK-NEXT: error: End address before start address.

CHECK-NEXT: (lldb) disassemble --address 0x0

CHECK-NEXT: command-disassemble.s.tmp`foo:

-# CHECK-NEXT: command-disassemble.s.tmp[0x0] <+0>: int $0x10 +# CHECK-NEXT: command-disassemble.s.tmp[0x0] <+0>: jmp 0x2 ; <+2>

CHECK-NEXT: command-disassemble.s.tmp[0x2] <+2>: int $0x11

CHECK-NEXT: command-disassemble.s.tmp[0x4] <+4>: int $0x12

CHECK-NEXT: command-disassemble.s.tmp[0x6] <+6>: int $0x13

@@ -63,7 +63,7 @@

CHECK: command-disassemble.s.tmp[0x203e] <+8190>: int $0x2a

CHECK-NEXT: (lldb) disassemble --start-address 0x0 --count 7

CHECK-NEXT: command-disassemble.s.tmp`foo:

-# CHECK-NEXT: command-disassemble.s.tmp[0x0] <+0>: int $0x10 +# CHECK-NEXT: command-disassemble.s.tmp[0x0] <+0>: jmp 0x2 ; <+2>

CHECK-NEXT: command-disassemble.s.tmp[0x2] <+2>: int $0x11

CHECK-NEXT: command-disassemble.s.tmp[0x4] <+4>: int $0x12

CHECK-NEXT: command-disassemble.s.tmp[0x6] <+6>: int $0x13

@@ -101,8 +101,8 @@

     .text

foo:

+1: int $0x11 int $0x12 int $0x13 int $0x14