Author: Pavel Labath Date: 2020-03-03T16:40:27+01:00 New Revision: 573e0776996425dd0567448d4a1f805a1f613e6d
URL: https://github.com/llvm/llvm-project/commit/573e0776996425dd0567448d4a1f805a1f613e6d DIFF: https://github.com/llvm/llvm-project/commit/573e0776996425dd0567448d4a1f805a1f613e6d.diff LOG: [lldb] Add detailed tests for the "disassemble" command While we have some tests for this command already, they are very vague. This is not surprising -- it's hard to make strict assertions about the assembly if your input is a c++ source file. This means that the tests can more-or-less only detect when the command breaks completely, and not when there is a subtle change in meaning due to e.g. a code refactor -- which is something that I am getting ready to do. This tests in this patch create binaries with well known data (via assembler and yaml2obj). This means that we are able to make precise assertions about the text that lldb is supposed to print. As some of the features of this command are only available with a real process, I use a minidump core file to create a sufficiently realistic process object. Added: lldb/test/Shell/Commands/Inputs/command-disassemble-process.lldbinit lldb/test/Shell/Commands/Inputs/command-disassemble.lldbinit lldb/test/Shell/Commands/command-disassemble-process.yaml lldb/test/Shell/Commands/command-disassemble.s lldb/test/Shell/Commands/lit.local.cfg Modified: Removed: ################################################################################ diff --git a/lldb/test/Shell/Commands/Inputs/command-disassemble-process.lldbinit b/lldb/test/Shell/Commands/Inputs/command-disassemble-process.lldbinit new file mode 100644 index 000000000000..a8f314a7759f --- /dev/null +++ b/lldb/test/Shell/Commands/Inputs/command-disassemble-process.lldbinit @@ -0,0 +1,7 @@ +disassemble +disassemble --line +disassemble --frame +disassemble --pc +disassemble --address 0x4004 +disassemble --address 0xdead +disassemble --pc --count 7 diff --git a/lldb/test/Shell/Commands/Inputs/command-disassemble.lldbinit b/lldb/test/Shell/Commands/Inputs/command-disassemble.lldbinit new file mode 100644 index 000000000000..6a328ffc7c32 --- /dev/null +++ b/lldb/test/Shell/Commands/Inputs/command-disassemble.lldbinit @@ -0,0 +1,12 @@ +disassemble +disassemble --line +disassemble --frame +disassemble --pc +disassemble --start-address 0x0 +disassemble --start-address 0x4 --end-address 0x8 +disassemble --start-address 0x8 --end-address 0x4 +disassemble --address 0x0 +disassemble --address 0xdead +disassemble --start-address 0x0 --count 7 +disassemble --start-address 0x0 --end-address 0x20 --count 7 +disassemble --address 0x0 --count 7 diff --git a/lldb/test/Shell/Commands/command-disassemble-process.yaml b/lldb/test/Shell/Commands/command-disassemble-process.yaml new file mode 100644 index 000000000000..9f932dca0289 --- /dev/null +++ b/lldb/test/Shell/Commands/command-disassemble-process.yaml @@ -0,0 +1,120 @@ +# REQUIRES: x86 + +# RUN: yaml2obj --docnum=1 %s > %T/command-disassemble-process.exe +# RUN: yaml2obj --docnum=2 %s > %t + +# RUN: %lldb -c %t %T/command-disassemble-process.exe \ +# RUN: -o "settings set interpreter.stop-command-source-on-error false" \ +# RUN: -s %S/Inputs/command-disassemble-process.lldbinit -o exit 2>&1 \ +# RUN: | FileCheck %s + +# CHECK: (lldb) disassemble +# CHECK-NEXT: command-disassemble-process.exe`main: +# CHECK-NEXT: 0x4002 <+0>: addb %al, (%rcx) +# 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 --line +# CHECK-NEXT: command-disassemble-process.exe`main: +# CHECK-NEXT: -> 0x4004 <+2>: addb %al, (%rdx) +# CHECK-NEXT: 0x4006 <+4>: addb %al, (%rbx) +# CHECK-NEXT: 0x4008 <+6>: addb %al, (%rsi) +# 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: -> 0x4004 <+2>: addb %al, (%rdx) +# CHECK-NEXT: 0x4006 <+4>: addb %al, (%rbx) +# CHECK-NEXT: 0x4008 <+6>: addb %al, (%rsi) +# CHECK-NEXT: (lldb) disassemble --pc +# CHECK-NEXT: command-disassemble-process.exe`main: +# CHECK-NEXT: -> 0x4004 <+2>: addb %al, (%rdx) +# CHECK-NEXT: 0x4006 <+4>: addb %al, (%rbx) +# CHECK-NEXT: 0x4008 <+6>: addb %al, (%rsi) +# 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: -> 0x4004 <+2>: addb %al, (%rdx) +# CHECK-NEXT: 0x4006 <+4>: addb %al, (%rbx) +# CHECK-NEXT: 0x4008 <+6>: addb %al, (%rsi) +# CHECK-NEXT: (lldb) disassemble --address 0xdead +# CHECK-NEXT: error: Could not find function bounds for address 0xdead +# CHECK-NEXT: (lldb) disassemble --pc --count 7 +# CHECK-NEXT: command-disassemble-process.exe`main: +# CHECK-NEXT: -> 0x4004 <+2>: addb %al, (%rdx) +# CHECK-NEXT: 0x4006 <+4>: addb %al, (%rbx) +# CHECK-NEXT: 0x4008 <+6>: addb %al, (%rsi) +# CHECK-NEXT: 0x400a: addb %al, (%rdi) +# CHECK-NEXT: 0x400c: addb %cl, (%rax) +# CHECK-NEXT: 0x400e: addb %cl, (%rcx) +# CHECK-NEXT: 0x4010: addb %cl, (%rdx) + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_EXEC + Machine: EM_X86_64 +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + Address: 0x0000000000004000 + AddressAlign: 0x0000000000001000 + Content: 00000001000200030006000700080009000A000B000E000F00100011001200130016001700180019001A001B001E001F00200021002200230026002700280029002A002B002E002F + - Name: .note.gnu.build-id + Type: SHT_NOTE + Flags: [ SHF_ALLOC ] + Address: 0x0000000000005000 + AddressAlign: 0x0000000000001000 + Content: 040000000800000003000000474E5500DEADBEEFBAADF00D +Symbols: + - Name: main + Type: STT_FUNC + Section: .text + Value: 0x0000000000004002 + Size: 0x0000000000000008 +ProgramHeaders: + - Type: PT_LOAD + Flags: [ PF_X, PF_R ] + VAddr: 0x4000 + Align: 0x1000 + Sections: + - Section: .text + - Type: PT_LOAD + Flags: [ PF_W, PF_R ] + VAddr: 0x5000 + Align: 0x1000 + Sections: + - Section: .note.gnu.build-id +... + +--- !minidump +Streams: + - Type: ModuleList + Modules: + - Base of Image: 0x0000000000004000 + Size of Image: 0x00002000 + Module Name: 'command-disassemble-process.yaml' + CodeView Record: 4C457042DEADBEEFBAADF00D + + - Type: SystemInfo + Processor Arch: AMD64 + Platform ID: Linux + CPU: + Vendor ID: GenuineIntel + Version Info: 0x00000000 + Feature Info: 0x00000000 + - Type: ThreadList + Threads: + - Thread Id: 0x000074F3 + Context: 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000B001000000000006CAE000000006B7FC05A0000C81D415A0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000A2BF9E5A6B7F0000000000000000000000000000000000008850C14BFD7F00009850C14BFD7F00000100000000000000B04AC14BFD7F0000000000000000000060812D01000000000800000000000000B065E05A6B7F00008004400000000000E050C14BFD7F00000000000000000000000000000000000004400000000000007F03FFFF0000FFFFFFFFFFFF000000000000000000000000801F00006B7F00000400000000000000B84CC14BFD7F0000304D405A6B7F0000C84DC14BFD7F0000C0AA405A6B7F00004F033D0000000000B84DC14BFD7F0000E84DC14BFD7F0000000000000000000000000000000000000070E05A6B7F000078629E5A6B7F0000C81D415A6B7F0000804F9E5A6B7F00000000000001000000E603000001000000E093115A6B7F0000804EC14BFD7F0000584EC14BFD7F000099ADC05A6B7F00000100000000000000AAAAD77D0000000002000000000000000800000000000000B065E05A6B7F0000E6B7C05A6B7F0000010000006B7F0000884DC14BFD7F0000106F7C5A6B7F0000984EC14BFD7F0000488B7C5A6B7F0000C4A71CB90000000001000000000000000800000000000000B065E05A6B7F000048B6C05A6B7F0000702AE25A6B7F0000D84DC14BFD7F000030489E5A6B7F0000E84EC14BFD7F0000E05E9E5A6B7F00000991F0460000000001000000000000000800000000000000B065E05A6B7F000048B6C05A6B7F00000100000000000000284EC14BFD7F00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 + Stack: + Start of Memory Range: 0x00007FFD4BC15080 + Content: 30044000000000000000000000000000 + - Type: MemoryList + Memory Ranges: + - Start of Memory Range: 0x00007FFD4BC15080 + Content: 30044000000000000000000000000000 +... diff --git a/lldb/test/Shell/Commands/command-disassemble.s b/lldb/test/Shell/Commands/command-disassemble.s new file mode 100644 index 000000000000..51053c7b8af3 --- /dev/null +++ b/lldb/test/Shell/Commands/command-disassemble.s @@ -0,0 +1,104 @@ +# REQUIRES: x86 + +# RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux %s -o %t +# RUN: %lldb %t -o "settings set interpreter.stop-command-source-on-error false" \ +# RUN: -s %S/Inputs/command-disassemble.lldbinit -o exit 2>&1 | FileCheck %s + +# CHECK: (lldb) disassemble +# CHECK-NEXT: error: Cannot disassemble around the current function without a selected frame. +# CHECK-EMPTY: +# CHECK-NEXT: (lldb) disassemble --line +# CHECK-NEXT: error: Cannot disassemble around the current line without a selected frame. +# CHECK-EMPTY: +# CHECK-NEXT: (lldb) disassemble --frame +# CHECK-NEXT: error: Cannot disassemble around the current function without a selected frame. +# CHECK-EMPTY: +# CHECK-NEXT: (lldb) disassemble --pc +# CHECK-NEXT: error: Cannot disassemble around the current PC without a selected frame. +# CHECK-EMPTY: +# 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[0x2] <+2>: int $0x11 +# CHECK-NEXT: command-disassemble.s.tmp[0x4] <+4>: int $0x12 +# CHECK-NEXT: command-disassemble.s.tmp[0x6] <+6>: int $0x13 +# CHECK-NEXT: command-disassemble.s.tmp[0x8] <+8>: int $0x14 +# CHECK-NEXT: command-disassemble.s.tmp[0xa] <+10>: int $0x15 +# CHECK-NEXT: command-disassemble.s.tmp[0xc] <+12>: int $0x16 +# CHECK-EMPTY: +# CHECK-NEXT: command-disassemble.s.tmp`bar: +# CHECK-NEXT: command-disassemble.s.tmp[0xe] <+0>: int $0x17 +# CHECK-NEXT: command-disassemble.s.tmp[0x10] <+2>: int $0x18 +# CHECK-NEXT: command-disassemble.s.tmp[0x12] <+4>: int $0x19 +# CHECK-NEXT: command-disassemble.s.tmp[0x14] <+6>: int $0x1a +# CHECK-NEXT: command-disassemble.s.tmp[0x16] <+8>: int $0x1b +# CHECK-NEXT: command-disassemble.s.tmp[0x18] <+10>: int $0x1c +# CHECK-NEXT: command-disassemble.s.tmp[0x1a] <+12>: int $0x1d +# CHECK-NEXT: command-disassemble.s.tmp[0x1c] <+14>: int $0x1e +# CHECK-NEXT: command-disassemble.s.tmp[0x1e] <+16>: int $0x1f +# CHECK-NEXT: (lldb) disassemble --start-address 0x4 --end-address 0x8 +# CHECK-NEXT: command-disassemble.s.tmp`foo: +# CHECK-NEXT: command-disassemble.s.tmp[0x4] <+4>: int $0x12 +# CHECK-NEXT: command-disassemble.s.tmp[0x6] <+6>: int $0x13 +# CHECK-NEXT: (lldb) disassemble --start-address 0x8 --end-address 0x4 +# 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[0x2] <+2>: int $0x11 +# CHECK-NEXT: command-disassemble.s.tmp[0x4] <+4>: int $0x12 +# CHECK-NEXT: command-disassemble.s.tmp[0x6] <+6>: int $0x13 +# CHECK-NEXT: command-disassemble.s.tmp[0x8] <+8>: int $0x14 +# CHECK-NEXT: command-disassemble.s.tmp[0xa] <+10>: int $0x15 +# CHECK-NEXT: command-disassemble.s.tmp[0xc] <+12>: int $0x16 +# CHECK-NEXT: (lldb) disassemble --address 0xdead +# CHECK-NEXT: error: invalid frame +# 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[0x2] <+2>: int $0x11 +# CHECK-NEXT: command-disassemble.s.tmp[0x4] <+4>: int $0x12 +# CHECK-NEXT: command-disassemble.s.tmp[0x6] <+6>: int $0x13 +# CHECK-NEXT: command-disassemble.s.tmp[0x8] <+8>: int $0x14 +# CHECK-NEXT: command-disassemble.s.tmp[0xa] <+10>: int $0x15 +# CHECK-NEXT: command-disassemble.s.tmp[0xc] <+12>: int $0x16 +# CHECK-NEXT: (lldb) disassemble --start-address 0x0 --end-address 0x20 --count 7 +# CHECK-NEXT: error: invalid combination of options for the given command +# CHECK-NEXT: (lldb) disassemble --address 0x0 --count 7 +# CHECK-NEXT: error: invalid combination of options for the given command + + .text +foo: + int $0x10 + int $0x11 + int $0x12 + int $0x13 + int $0x14 + int $0x15 + int $0x16 +bar: + int $0x17 + int $0x18 + int $0x19 + int $0x1a + int $0x1b + int $0x1c + int $0x1d + int $0x1e + int $0x1f + int $0x20 + int $0x21 + int $0x22 + int $0x23 + int $0x24 + int $0x25 + int $0x26 + int $0x27 + int $0x28 + int $0x29 + int $0x2a + int $0x2b + int $0x2c + int $0x2d + int $0x2e + int $0x2f diff --git a/lldb/test/Shell/Commands/lit.local.cfg b/lldb/test/Shell/Commands/lit.local.cfg new file mode 100644 index 000000000000..60e87e4624e5 --- /dev/null +++ b/lldb/test/Shell/Commands/lit.local.cfg @@ -0,0 +1 @@ +config.suffixes = ['.s', '.test', '.yaml'] _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits