xref: /llvm-project/lldb/test/Shell/ObjectFile/ELF/elf-memory.test (revision 99cec7ff8eabbec929d3d0b3a15b272867cf2a46)
1// REQUIRES: system-linux, native, python
2
3// This test verifies that loading an ELF file from memory works and the new
4// features that were added when loading from memory work like:
5// - Loading the .dynamic section from the PT_DYNAMIC since ELF files loaded
6//   from memory don't have the section headers available.
7// This test will make a simple executable that:
8//   - links against libc
9//   - runs and stops at a breakpoint
10//   - create a memory ELF file
11//   - verify that "image dump objfile" will dump the dynamic section of the
12//     memory elf file and find the .dynamic string table.
13
14// RUN: %clang_host %p/Inputs/memory-elf.cpp -g -O0 -o %t
15
16// RUN: %lldb %t -b \
17// RUN:   -o "b main" \
18// RUN:   -o "run" \
19// RUN:   -o "script real_module = lldb.target.module[0]" \
20// RUN:   -o "script base_addr = real_module.GetObjectFileHeaderAddress().GetLoadAddress(lldb.target)" \
21// RUN:   -o "script mem_module = lldb.SBModule(lldb.process, base_addr)" \
22// RUN:   -o "script target2 = lldb.debugger.CreateTarget('')" \
23// RUN:   -o "script target2.AddModule(mem_module)" \
24// RUN:   -o "target select 1" \
25// RUN:   -o "image dump objfile" \
26// RUN:   | FileCheck %s --check-prefix=MAIN --dump-input=always
27// MAIN: (lldb) image dump objfile
28// MAIN: Dumping headers for 1 module(s).
29// MAIN: ObjectFileELF, file = '', arch = {{.*, addr = 0x[0-9a-f]+}}
30// MAIN: ELF Header
31
32// Make sure we find the program headers and see a PT_DYNAMIC entry.
33// MAIN: Program Headers
34// MAIN: ] PT_DYNAMIC
35
36// Make sure we see some sections created from the program headers
37// MAIN: SectID
38// MAIN: PT_LOAD[0]
39
40// Ensure we find some dependent modules as won't find these if we aren't able
41// to load the .dynamic section from the PT_DYNAMIC program header.
42// MAIN: Dependent Modules:
43
44// Check for the .dynamic dump and ensure we find all dynamic entries that are
45// required to be there and needed to get the .dynstr section and the symbol
46// table, and the DT_DEBUG entry to find the list of shared libraries.
47// MAIN: .dynamic:
48// Make sure we found the .dynstr section by checking for valid strings after NEEDED
49// MAIN-DAG: NEEDED {{0x[0-9a-f]+ ".*libc.*"}}
50// MAIN-DAG: STRTAB {{0x[0-9a-f]+}}
51// MAIN-DAG: SYMTAB {{0x[0-9a-f]+}}
52// MAIN-DAG: STRSZ {{0x[0-9a-f]+}}
53// MAIN-DAG: SYMENT {{0x[0-9a-f]+}}
54// MAIN-DAG: DEBUG {{0x[0-9a-f]+}}
55// MAIN:     NULL {{0x[0-9a-f]+}}
56