Skip to content

Commit d8ebb08

Browse files
authored
[lldb] Have disassembler show load addresses when using a core file (#115453)
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.
1 parent 21ef17c commit d8ebb08

File tree

3 files changed

+19
-22
lines changed

3 files changed

+19
-22
lines changed

lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,6 @@ class InstructionLLVMC : public lldb_private::Instruction {
583583
lldb::addr_t pc = m_address.GetFileAddress();
584584
m_using_file_addr = true;
585585

586-
const bool data_from_file = disasm->m_data_from_file;
587586
bool use_hex_immediates = true;
588587
Disassembler::HexImmediateStyle hex_style = Disassembler::eHexStyleC;
589588

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

596-
if (!data_from_file) {
597-
const lldb::addr_t load_addr = m_address.GetLoadAddress(target);
598-
if (load_addr != LLDB_INVALID_ADDRESS) {
599-
pc = load_addr;
600-
m_using_file_addr = false;
601-
}
595+
const lldb::addr_t load_addr = m_address.GetLoadAddress(target);
596+
if (load_addr != LLDB_INVALID_ADDRESS) {
597+
pc = load_addr;
598+
m_using_file_addr = false;
602599
}
603600
}
604601
}

lldb/test/Shell/Commands/command-disassemble-process.yaml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
# CHECK: (lldb) disassemble
2222
# CHECK-NEXT: command-disassemble-process.exe`main:
23-
# CHECK-NEXT: 0x4002 <+0>: addb %al, (%rcx)
23+
# CHECK-NEXT: 0x4002 <+0>: jmp 0x4004 ; <+2>
2424
# CHECK-NEXT: -> 0x4004 <+2>: addb %al, (%rdx)
2525
# CHECK-NEXT: 0x4006 <+4>: addb %al, (%rbx)
2626
# CHECK-NEXT: 0x4008 <+6>: addb %al, (%rsi)
@@ -32,7 +32,7 @@
3232
# CHECK-NEXT: 0x400a: addb %al, (%rdi)
3333
# CHECK-NEXT: (lldb) disassemble --frame
3434
# CHECK-NEXT: command-disassemble-process.exe`main:
35-
# CHECK-NEXT: 0x4002 <+0>: addb %al, (%rcx)
35+
# CHECK-NEXT: 0x4002 <+0>: jmp 0x4004 ; <+2>
3636
# CHECK-NEXT: -> 0x4004 <+2>: addb %al, (%rdx)
3737
# CHECK-NEXT: 0x4006 <+4>: addb %al, (%rbx)
3838
# CHECK-NEXT: 0x4008 <+6>: addb %al, (%rsi)
@@ -44,13 +44,13 @@
4444
# CHECK-NEXT: 0x400a: addb %al, (%rdi)
4545
# CHECK-NEXT: (lldb) disassemble --address 0x4004
4646
# CHECK-NEXT: command-disassemble-process.exe`main:
47-
# CHECK-NEXT: 0x4002 <+0>: addb %al, (%rcx)
47+
# CHECK-NEXT: 0x4002 <+0>: jmp 0x4004 ; <+2>
4848
# CHECK-NEXT: -> 0x4004 <+2>: addb %al, (%rdx)
4949
# CHECK-NEXT: 0x4006 <+4>: addb %al, (%rbx)
5050
# CHECK-NEXT: 0x4008 <+6>: addb %al, (%rsi)
5151
# CHECK-NEXT: (lldb) disassemble --count 7
5252
# CHECK-NEXT: command-disassemble-process.exe`main:
53-
# CHECK-NEXT: 0x4002 <+0>: addb %al, (%rcx)
53+
# CHECK-NEXT: 0x4002 <+0>: jmp 0x4004 ; <+2>
5454
# CHECK-NEXT: -> 0x4004 <+2>: addb %al, (%rdx)
5555
# CHECK-NEXT: 0x4006 <+4>: addb %al, (%rbx)
5656
# CHECK-NEXT: 0x4008 <+6>: addb %al, (%rsi)
@@ -81,32 +81,32 @@ Sections:
8181
- Name: .text
8282
Type: SHT_PROGBITS
8383
Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
84-
Address: 0x0000000000004000
84+
Address: 0x0000000000000000
8585
AddressAlign: 0x0000000000001000
86-
Content: 00000001000200030006000700080009000A000B000E000F00100011001200130016001700180019001A001B001E001F00200021002200230026002700280029002A002B002E002F
86+
Content: 0000EB00000200030006000700080009000A000B000E000F00100011001200130016001700180019001A001B001E001F00200021002200230026002700280029002A002B002E002F
8787
Size: 0x10000
8888
- Name: .note.gnu.build-id
8989
Type: SHT_NOTE
9090
Flags: [ SHF_ALLOC ]
91-
Address: 0x0000000000005000
91+
Address: 0x0000000000001000
9292
AddressAlign: 0x0000000000001000
9393
Content: 040000000800000003000000474E5500DEADBEEFBAADF00D
9494
Symbols:
9595
- Name: main
9696
Type: STT_FUNC
9797
Section: .text
98-
Value: 0x0000000000004002
98+
Value: 0x0000000000000002
9999
Size: [[MAIN_SIZE]]
100100
ProgramHeaders:
101101
- Type: PT_LOAD
102102
Flags: [ PF_X, PF_R ]
103-
VAddr: 0x4000
103+
VAddr: 0x0000
104104
Align: 0x1000
105105
FirstSec: .text
106106
LastSec: .text
107107
- Type: PT_LOAD
108108
Flags: [ PF_W, PF_R ]
109-
VAddr: 0x5000
109+
VAddr: 0x1000
110110
Align: 0x1000
111111
FirstSec: .note.gnu.build-id
112112
LastSec: .note.gnu.build-id

lldb/test/Shell/Commands/command-disassemble.s

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# CHECK-NEXT: error: Cannot disassemble around the current PC without a selected frame: no currently running process.
1616
# CHECK-NEXT: (lldb) disassemble --start-address 0x0
1717
# CHECK-NEXT: command-disassemble.s.tmp`foo:
18-
# CHECK-NEXT: command-disassemble.s.tmp[0x0] <+0>: int $0x10
18+
# CHECK-NEXT: command-disassemble.s.tmp[0x0] <+0>: jmp 0x2 ; <+2>
1919
# CHECK-NEXT: command-disassemble.s.tmp[0x2] <+2>: int $0x11
2020
# CHECK-NEXT: command-disassemble.s.tmp[0x4] <+4>: int $0x12
2121
# CHECK-NEXT: command-disassemble.s.tmp[0x6] <+6>: int $0x13
@@ -41,7 +41,7 @@
4141
# CHECK-NEXT: error: End address before start address.
4242
# CHECK-NEXT: (lldb) disassemble --address 0x0
4343
# CHECK-NEXT: command-disassemble.s.tmp`foo:
44-
# CHECK-NEXT: command-disassemble.s.tmp[0x0] <+0>: int $0x10
44+
# CHECK-NEXT: command-disassemble.s.tmp[0x0] <+0>: jmp 0x2 ; <+2>
4545
# CHECK-NEXT: command-disassemble.s.tmp[0x2] <+2>: int $0x11
4646
# CHECK-NEXT: command-disassemble.s.tmp[0x4] <+4>: int $0x12
4747
# CHECK-NEXT: command-disassemble.s.tmp[0x6] <+6>: int $0x13
@@ -63,7 +63,7 @@
6363
# CHECK: command-disassemble.s.tmp[0x203e] <+8190>: int $0x2a
6464
# CHECK-NEXT: (lldb) disassemble --start-address 0x0 --count 7
6565
# CHECK-NEXT: command-disassemble.s.tmp`foo:
66-
# CHECK-NEXT: command-disassemble.s.tmp[0x0] <+0>: int $0x10
66+
# CHECK-NEXT: command-disassemble.s.tmp[0x0] <+0>: jmp 0x2 ; <+2>
6767
# CHECK-NEXT: command-disassemble.s.tmp[0x2] <+2>: int $0x11
6868
# CHECK-NEXT: command-disassemble.s.tmp[0x4] <+4>: int $0x12
6969
# CHECK-NEXT: command-disassemble.s.tmp[0x6] <+6>: int $0x13
@@ -101,8 +101,8 @@
101101

102102
.text
103103
foo:
104-
int $0x10
105-
int $0x11
104+
jmp 1f
105+
1: int $0x11
106106
int $0x12
107107
int $0x13
108108
int $0x14

0 commit comments

Comments
 (0)