Skip to content

Commit 2c082b4

Browse files
committed
[lldb][ELF] Read symbols from .gnu_debugdata sect.
Summary: If the .symtab section is stripped from the binary it might be that there's a .gnu_debugdata section which contains a smaller .symtab in order to provide enough information to create a backtrace with function names or to set and hit a breakpoint on a function name. This change looks for a .gnu_debugdata section in the ELF object file. The .gnu_debugdata section contains a xz-compressed ELF file with a .symtab section inside. Symbols from that compressed .symtab section are merged with the main object file's .dynsym symbols (if any). In addition we always load the .dynsym even if there's a .symtab section. For example, the Fedora and RHEL operating systems strip their binaries but keep a .gnu_debugdata section. While gdb already can read this section, LLDB until this patch couldn't. To test this patch on a Fedora or RHEL operating system, try to set a breakpoint on the "help" symbol in the "zip" binary. Before this patch, only GDB can set this breakpoint; now LLDB also can do so without installing extra debug symbols: lldb /usr/bin/zip -b -o "b help" -o "r" -o "bt" -- -h The above line runs LLDB in batch mode and on the "/usr/bin/zip -h" target: (lldb) target create "/usr/bin/zip" Current executable set to '/usr/bin/zip' (x86_64). (lldb) settings set -- target.run-args "-h" Before the program starts, we set a breakpoint on the "help" symbol: (lldb) b help Breakpoint 1: where = zip`help, address = 0x00000000004093b0 Once the program is run and has hit the breakpoint we ask for a backtrace: (lldb) r Process 10073 stopped * thread #1, name = 'zip', stop reason = breakpoint 1.1 frame #0: 0x00000000004093b0 zip`help zip`help: -> 0x4093b0 <+0>: pushq %r12 0x4093b2 <+2>: movq 0x2af5f(%rip), %rsi ; + 4056 0x4093b9 <+9>: movl $0x1, %edi 0x4093be <+14>: xorl %eax, %eax Process 10073 launched: '/usr/bin/zip' (x86_64) (lldb) bt * thread #1, name = 'zip', stop reason = breakpoint 1.1 * frame #0: 0x00000000004093b0 zip`help frame #1: 0x0000000000403970 zip`main + 3248 frame #2: 0x00007ffff7d8bf33 libc.so.6`__libc_start_main + 243 frame #3: 0x0000000000408cee zip`_start + 46 In order to support the .gnu_debugdata section, one has to have LZMA development headers installed. The CMake section, that controls this part looks for the LZMA headers and enables .gnu_debugdata support by default if they are found; otherwise or if explicitly requested, the minidebuginfo support is disabled. GDB supports the "mini debuginfo" section .gnu_debugdata since v7.6 (2013). Reviewers: espindola, labath, jankratochvil, alexshap Reviewed By: labath Subscribers: rnkovacs, wuzish, shafik, emaste, mgorny, arichardson, hiraditya, MaskRay, lldb-commits Tags: #lldb, #llvm Differential Revision: https://reviews.llvm.org/D66791 llvm-svn: 373891
1 parent 5ce8c39 commit 2c082b4

15 files changed

+481
-8
lines changed

lldb/cmake/modules/LLDBConfig.cmake

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
include(CheckCXXSymbolExists)
22
include(CheckTypeSize)
3+
include(CMakeDependentOption)
34

45
set(LLDB_PROJECT_ROOT ${CMAKE_CURRENT_SOURCE_DIR})
56
set(LLDB_SOURCE_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/source")
@@ -384,6 +385,13 @@ endif()
384385
set(LLDB_VERSION "${LLDB_VERSION_MAJOR}.${LLDB_VERSION_MINOR}.${LLDB_VERSION_PATCH}${LLDB_VERSION_SUFFIX}")
385386
message(STATUS "LLDB version: ${LLDB_VERSION}")
386387

388+
find_package(LibLZMA)
389+
cmake_dependent_option(LLDB_ENABLE_LZMA "Support LZMA compression" ON "LIBLZMA_FOUND" OFF)
390+
if (LLDB_ENABLE_LZMA)
391+
include_directories(${LIBLZMA_INCLUDE_DIRS})
392+
endif()
393+
llvm_canonicalize_cmake_booleans(LLDB_ENABLE_LZMA)
394+
387395
include_directories(BEFORE
388396
${CMAKE_CURRENT_BINARY_DIR}/include
389397
${CMAKE_CURRENT_SOURCE_DIR}/include

lldb/include/lldb/Host/Config.h.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,6 @@
3535
#cmakedefine HAVE_LIBCOMPRESSION
3636
#endif
3737

38+
#cmakedefine01 LLDB_ENABLE_LZMA
39+
3840
#endif // #ifndef LLDB_HOST_CONFIG_H

lldb/include/lldb/Host/LZMA.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//===-- LZMA.h --------------------------------------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef liblldb_Host_LZMA_h_
10+
#define liblldb_Host_LZMA_h_
11+
12+
#include "llvm/ADT/ArrayRef.h"
13+
14+
namespace llvm {
15+
class Error;
16+
} // End of namespace llvm
17+
18+
namespace lldb_private {
19+
20+
namespace lzma {
21+
22+
bool isAvailable();
23+
24+
llvm::Expected<uint64_t>
25+
getUncompressedSize(llvm::ArrayRef<uint8_t> InputBuffer);
26+
27+
llvm::Error uncompress(llvm::ArrayRef<uint8_t> InputBuffer,
28+
llvm::SmallVectorImpl<uint8_t> &Uncompressed);
29+
30+
} // End of namespace lzma
31+
32+
} // End of namespace lldb_private
33+
34+
#endif // liblldb_Host_LZMA_h_

lldb/lit/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,11 @@ list(APPEND LLDB_TEST_DEPS
5656
lli
5757
llvm-config
5858
llvm-dwarfdump
59+
llvm-nm
5960
llvm-mc
6061
llvm-objcopy
6162
llvm-readobj
63+
llvm-strip
6264
)
6365

6466
if(TARGET lld)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// This function will be embedded within the .symtab section of the
2+
// .gnu_debugdata section.
3+
int multiplyByFour(int num) { return num * 4; }
4+
5+
// This function will be embedded within the .dynsym section of the main binary.
6+
int multiplyByThree(int num) { return num * 3; }
7+
8+
int main(int argc, char *argv[]) {
9+
int x = multiplyByThree(argc);
10+
int y = multiplyByFour(x);
11+
return y;
12+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# REQUIRES: lzma
2+
3+
# This test checks that an error occurs when a corrupted
4+
# .gnu_debugdata section is trying to be xz uncompressed.
5+
6+
# RUN: yaml2obj %s > %t.obj
7+
8+
# TODO(kwk): once yaml2obj doesn't auto-generate a .symtab section
9+
# when there's none in YAML, remove the following line:
10+
11+
# RUN: llvm-objcopy --remove-section=.symtab %t.obj
12+
13+
# RUN: %lldb -b -o 'image dump symtab' %t.obj 2>&1 | FileCheck %s
14+
15+
# CHECK: warning: (x86_64) {{.*}}.obj An error occurred while decompression the section .gnu_debugdata: lzma_stream_buffer_decode()=lzma error: LZMA_DATA_ERROR
16+
17+
--- !ELF
18+
FileHeader:
19+
Class: ELFCLASS64
20+
Data: ELFDATA2LSB
21+
Type: ET_EXEC
22+
Machine: EM_X86_64
23+
Entry: 0x00000000004004C0
24+
Sections:
25+
- Name: .gnu_debugdata
26+
Type: SHT_PROGBITS
27+
AddressAlign: 0x0000000000000001
28+
Content: FD377A585A000004E6D6B4460200210116000000742FE5A3E0180F05BA5D003F914584683D89A6DA8ACC93E24ED90802EC1FE2A7102958F4A42B6A7134F23922F6F35F529E133A8B5588025CFAC876C68510A157DBBCF8CA75E9854DED10FDD5CE0CDC136F6459B13B9847AEF79E9B1C7CD70EF4F3AF709F5DA0C1F40780154D72120A6A62A3F1A216E20DC597CE55BB23B48785957321A15FEE48808C1428B925DBC8022541CC594BD0AF2B51C6BE2854C81611017704DF6E509D21013B80BEC27D8919ACD3157E89353A08F4C86781ED708E89AB322D010F0F1605DAD9B9CE2B13C387769C83F5F85C647FD9C551E0E9C7D4A5CBE297970E486CB94AC283F98A7C6412A57F9C37952327549EEC4634D2CFA55B0F99923A14992D4293E0D87CEEF7FB6160C45928DE25074EEBF5329B5579AF01DB23DF22CBD48C8037B68FFFBE5CEA6CD26A936DD07D9B2E6006B7C6E5CC751072185EFE995D3F3C8DACF9039D4BEFB1F376B491568F6F00DB50FF477F36B90413E4FA30AE7C561A1249FD45FDFF884F70247FC21E57195A764151D8E341267E724D856C512BD243CDB33AB313758443877B2CB58F7F8F0461DE9766647F333A3531BDC4A26E9537EB314708D31212FCF4C21E9CB139F4DBFD21BB16A126C35E2BB3F7E30BF5A54961CECD4DD4D91A3757356F618754B21533C34F2BD97D70A02B1F338588BDBA9CDF5FC9FBE973E550194F07EC7A1E8E3C005FD60F8853223427628987E82E701CA7E2FDFA1B0ED564C37D115A72C3EC01E29C85C3630D8A385C4AE12F4F75F9F0BC12F2698345DD62A1F546A5953AF5CF3C0F22C7DA510F6739EB8CDB0E8A5A3BC13CFC31C1875C313908EFF23678869B76A6E1C10FE699E43BFFDE8F0752ED994A4A84BC0AD9D7381131D457C4917C4F6656F5C95D3221A79166C802D5F5A7C68554E54C42CA535465D224C7B641CF3417C3EAFD03CE5709BEA33DC7C9155CAC9D3C8033AF7CDA622020606A7C139D77FF85BC19323BF956C9C4662F60079BC7FE5F67B46211716A1A6CE4AB8AAB307D6444310CBC101071703EECC0B4622D91D705F5DA2932DA8BCEDA8E1CB0CDB20AAD652B8F86A521D3421287F1C175AE3BE6458AE6F8F3FB6FB7ED97B616B580D791E5FE0B74973F8604F419039B5B9D9A14397EE509F2B33AE404FF96DD0551472C5302E67910F0794B15CFE837351C6AF89B2FE88488B557BE8ACFFA331FB7AD553D35CAEB7D8BCEFB6CFF4A58E91355FE931408CF4CAFA9B97518B9E5C02078F64CE81279801B090348213DCAA7D12DC098BFF58C5A3202EFC38F64AD894379747B54AB5A9843F82E5FF1F394C8B78344A8F1655DDEF8D5FE09EBB3E703853ABD716743507000696FB6B35216B088E499F53880375521442ED45DCDD1B31AAEBDAD3C7DA958593425206C4B2A0BC6CADE3B0B1598499E08016E84F33E3EB9D7B03B9C9DFA91B8CE5C74DEF2BC97FEE9982B0AEC16C75EEB7AE9A858A9C37F6C12B040C68A49111DCF0F3A4780F3879E93D904676BE908FDC66373D34AA715A39EFBC2795C6C8F058CA24392FB2591AD06ACD6AED8746F926886180C2B007ED58C9884A8BEF6CCA1F549F5C4FB411A3FF78770D1147363AC80B98B5A8FDB3DEC4E61709F66A622BDA835B1FD67B7C7CB166ABB163FB7C5204AE200C71C6A18B532C407647323B8F2FAC7ECB68C250877FC8DD5FE05B2B39E66F687EBB6EEFB7D5209E22F451B76F57D90BB6641DFFDE1A1821C4D783E4756F3CEE7F63B9BA284F8E114B0D9A086D83233BED4A8F5B60933DC16AF4DDE19C9FC59BCC1646343ECE7007B1C4DC65C4A939CDD47F6ED8855913183149BECE66D8FE7793AE607EB8E28513749B9548252764110D3B58D1D8B348DB18F7F24F8CA0C7D9CB515D90F7F1848FF58472B2EF52EBAB123AFC7F87890CE9FC55B31160014294A9B7F81638A27335E29E15A10B1068D5E049B1C239814DBBCC1BB30E11EEBAD5ACF8FB1B986C4F48D73FEA6129D9708A0B5AC435402BEC8C79C71DB94394811B9A604141A125A4669F9A139A0264E93E822117BE8E0D93A1487C51214E9FBF5763A3FBE9DA700B9C9B435472AF9F0B4446B000000003239307DD8B645100001D60B90300000CA1EC9E9B1C467FB020000000004595A
29+
...
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# REQUIRES: lzma
2+
3+
# RUN: yaml2obj %s > %t.obj
4+
5+
# TODO(kwk): once yaml2obj doesn't auto-generate a .symtab section
6+
# when there's none in YAML, remove the following line:
7+
8+
# RUN: llvm-objcopy --remove-section=.symtab %t.obj
9+
10+
# RUN: %lldb -b -o 'image dump symtab' %t.obj | FileCheck %s
11+
12+
# CHECK: [ 0] 1 X Code 0x00000000004005b0 0x000000000000000f 0x00000012 multiplyByFour
13+
14+
--- !ELF
15+
FileHeader:
16+
Class: ELFCLASS64
17+
Data: ELFDATA2LSB
18+
Type: ET_EXEC
19+
Machine: EM_X86_64
20+
Entry: 0x00000000004004C0
21+
Sections:
22+
- Name: .gnu_debugdata
23+
Type: SHT_PROGBITS
24+
AddressAlign: 0x0000000000000001
25+
Content: FD377A585A000004E6D6B4460200210116000000742FE5A3E0180F05BA5D003F914584683D89A6DA8ACC93E24ED90802EC1FE2A7102958F4A42B6A7134F23922F6F35F529E133A8B5588025CFAC876C68510A157DBBCF8CA75E9854DED10FDD5CE0CDC136F6459B13B9847AEF79E9B1C7CD70EF4F3AF709F5DA0C1F40780154D72120A6A62A3F1A216E20DC597CE55BB23B48785957321A15FEE48808C1428B925DBC8022541CC594BD0AF2B51C6BE2854C81611017704DF6E509D21013B80BEC27D8919ACD3157E89353A08F4C86781ED708E89AB322D010F0F1605DAD9B9CE2B13C387769C83F5F85C647FD9C551E0E9C7D4A5CBE297970E486CB94AC283F98A7C6412A57F9C37952327549EEC4634D2CFA55B0F99923A14992D4293E0D87CEEF7FB6160C45928DE25074EEBF5329B5579AF01DB23DF22CBD48C8037B68FFFBE5CEA6CD26A936DD07D9B2E6006B7C6E5CC751072185EFE995D3F3C8DACF9039D4BEFB1F376B491568F6F00DB50FF477F36B90413E4FA30AE7C561A1249FD45FDFF884F70247FC21E57195A764151D8E341267E724D856C512BD243CDB33AB313758443877B2CB58F7F8F0461DE9766647F333A3531BDC4A26E9537EB314708D31212FCF4C21E9CB139F4DBFD21BB16A126C35E2BB3F7E30BF5A54961CECD4DD4D91A3757356F618754B21533C34F2BD97D70A02B1F338588BDBA9CDF5FC9FBE973E550194F07EC7A1E8E3C005FD60F8853223427628987E82E701CA7E2FDFA1B0ED564C37D115A72C3EC01E29C85C3630D8A385C4AE12F4F75F9F0BC12F2698345DD62A1F546A5953AF5CF3C0F22C7DA510F6739EB8CDB0E8A5A3BC13CFC31C1875C313908EFF23678869B76A6E1C10FE699E43BFFDE8F0752ED994A4A84BC0AD9D7381131D457C4917C4F6656F5C95D3221A79166C802D5F5A7C68554E54C42CA535465D224C7B641CF3417C3EAFD03CE5709BEA33DC7C9155CAC9D3C8033AF7CDA622020606A7C139D77FF85BC19323BF956C9C4662F60079BC7FE5F67B46211716A1A6CE4AB8AAB307D6444310CBC101071703EECC0B4622D91D705F5DA2932DA8BCEDA8E1CB0CDB20AAD652B8F86A521D3421287F1C175AE3BE6458AE6F8F3FB6FB7ED97B616B580D791E5FE0B74973F8604F419039B5B9D9A14397EE509F2B33AE404FF96DD0551472C5302E67910F0794B15CFE837351C6AF89B2FE88488B557BE8ACFFA331FB7AD553D35CAEB7D8BCEFB6CFF4A58E91355FE931408CF4CAFA9B97518B9E5C02078F64CE81279801B090348213DCAA7D12DC098BFF58C5A3202EFC38F64AD894379747B54AB5A9843F82E5FF1F394C8B783C3A8F1655DDEF8D5FE09EBB3E703853ABD716743507000696FB6B35216B088E499F53880375521442ED45DCDD1B31AAEBDAD3C7DA958593425206C4B2A0BC6CADE3B0B1598499E08016E84F33E3EB9D7B03B9C9DFA91B8CE5C74DEF2BC97FEE9982B0AEC16C75EEB7AE9A858A9C37F6C12B040C68A49111DCF0F3A4780F3879E93D904676BE908FDC66373D34AA715A39EFBC2795C6C8F058CA24392FB2591AD06ACD6AED8746F926886180C2B007ED58C9884A8BEF6CCA1F549F5C4FB411A3FF78770D1147363AC80B98B5A8FDB3DEC4E61709F66A622BDA835B1FD67B7C7CB166ABB163FB7C5204AE200C71C6A18B532C407647323B8F2FAC7ECB68C250877FC8DD5FE05B2B39E66F687EBB6EEFB7D5209E22F451B76F57D90BB6641DFFDE1A1821C4D783E4756F3CEE7F63B9BA284F8E114B0D9A086D83233BED4A8F5B60933DC16AF4DDE19C9FC59BCC1646343ECE7007B1C4DC65C4A939CDD47F6ED8855913183149BECE66D8FE7793AE607EB8E28513749B9548252764110D3B58D1D8B348DB18F7F24F8CA0C7D9CB515D90F7F1848FF58472B2EF52EBAB123AFC7F87890CE9FC55B31160014294A9B7F81638A27335E29E15A10B1068D5E049B1C239814DBBCC1BB30E11EEBAD5ACF8FB1B986C4F48D73FEA6129D9708A0B5AC435402BEC8C79C71DB94394811B9A604141A125A4669F9A139A0264E93E822117BE8E0D93A1487C51214E9FBF5763A3FBE9DA700B9C9B435472AF9F0B4446B000000003239307DD8B645100001D60B90300000CA1EC9E9B1C467FB020000000004595A
26+
...
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# REQUIRES: !lzma
2+
3+
# This test checks that a warning is printed when we're trying
4+
# to decompress a .gnu_debugdata section when no LZMA support was compiled in.
5+
6+
# RUN: yaml2obj %s > %t.obj
7+
8+
# TODO(kwk): once yaml2obj doesn't auto-generate a .symtab section
9+
# when there's none in YAML, remove the following line:
10+
11+
# RUN: llvm-objcopy --remove-section=.symtab %t.obj
12+
13+
# RUN: %lldb -b -o 'image dump symtab' %t.obj 2>&1 | FileCheck %s
14+
15+
# CHECK: warning: (x86_64) {{.*}}.obj No LZMA support found for reading .gnu_debugdata section
16+
17+
--- !ELF
18+
FileHeader:
19+
Class: ELFCLASS64
20+
Data: ELFDATA2LSB
21+
Type: ET_EXEC
22+
Machine: EM_X86_64
23+
Entry: 0x00000000004004C0
24+
Sections:
25+
- Name: .gnu_debugdata
26+
Type: SHT_PROGBITS
27+
AddressAlign: 0x0000000000000001
28+
Content: FD377A585A000004E6D6B4460200210116000000742FE5A3E0180F05BA5D003F914584683D89A6DA8ACC93E24ED90802EC1FE2A7102958F4A42B6A7134F23922F6F35F529E133A8B5588025CFAC876C68510A157DBBCF8CA75E9854DED10FDD5CE0CDC136F6459B13B9847AEF79E9B1C7CD70EF4F3AF709F5DA0C1F40780154D72120A6A62A3F1A216E20DC597CE55BB23B48785957321A15FEE48808C1428B925DBC8022541CC594BD0AF2B51C6BE2854C81611017704DF6E509D21013B80BEC27D8919ACD3157E89353A08F4C86781ED708E89AB322D010F0F1605DAD9B9CE2B13C387769C83F5F85C647FD9C551E0E9C7D4A5CBE297970E486CB94AC283F98A7C6412A57F9C37952327549EEC4634D2CFA55B0F99923A14992D4293E0D87CEEF7FB6160C45928DE25074EEBF5329B5579AF01DB23DF22CBD48C8037B68FFFBE5CEA6CD26A936DD07D9B2E6006B7C6E5CC751072185EFE995D3F3C8DACF9039D4BEFB1F376B491568F6F00DB50FF477F36B90413E4FA30AE7C561A1249FD45FDFF884F70247FC21E57195A764151D8E341267E724D856C512BD243CDB33AB313758443877B2CB58F7F8F0461DE9766647F333A3531BDC4A26E9537EB314708D31212FCF4C21E9CB139F4DBFD21BB16A126C35E2BB3F7E30BF5A54961CECD4DD4D91A3757356F618754B21533C34F2BD97D70A02B1F338588BDBA9CDF5FC9FBE973E550194F07EC7A1E8E3C005FD60F8853223427628987E82E701CA7E2FDFA1B0ED564C37D115A72C3EC01E29C85C3630D8A385C4AE12F4F75F9F0BC12F2698345DD62A1F546A5953AF5CF3C0F22C7DA510F6739EB8CDB0E8A5A3BC13CFC31C1875C313908EFF23678869B76A6E1C10FE699E43BFFDE8F0752ED994A4A84BC0AD9D7381131D457C4917C4F6656F5C95D3221A79166C802D5F5A7C68554E54C42CA535465D224C7B641CF3417C3EAFD03CE5709BEA33DC7C9155CAC9D3C8033AF7CDA622020606A7C139D77FF85BC19323BF956C9C4662F60079BC7FE5F67B46211716A1A6CE4AB8AAB307D6444310CBC101071703EECC0B4622D91D705F5DA2932DA8BCEDA8E1CB0CDB20AAD652B8F86A521D3421287F1C175AE3BE6458AE6F8F3FB6FB7ED97B616B580D791E5FE0B74973F8604F419039B5B9D9A14397EE509F2B33AE404FF96DD0551472C5302E67910F0794B15CFE837351C6AF89B2FE88488B557BE8ACFFA331FB7AD553D35CAEB7D8BCEFB6CFF4A58E91355FE931408CF4CAFA9B97518B9E5C02078F64CE81279801B090348213DCAA7D12DC098BFF58C5A3202EFC38F64AD894379747B54AB5A9843F82E5FF1F394C8B783C3A8F1655DDEF8D5FE09EBB3E703853ABD716743507000696FB6B35216B088E499F53880375521442ED45DCDD1B31AAEBDAD3C7DA958593425206C4B2A0BC6CADE3B0B1598499E08016E84F33E3EB9D7B03B9C9DFA91B8CE5C74DEF2BC97FEE9982B0AEC16C75EEB7AE9A858A9C37F6C12B040C68A49111DCF0F3A4780F3879E93D904676BE908FDC66373D34AA715A39EFBC2795C6C8F058CA24392FB2591AD06ACD6AED8746F926886180C2B007ED58C9884A8BEF6CCA1F549F5C4FB411A3FF78770D1147363AC80B98B5A8FDB3DEC4E61709F66A622BDA835B1FD67B7C7CB166ABB163FB7C5204AE200C71C6A18B532C407647323B8F2FAC7ECB68C250877FC8DD5FE05B2B39E66F687EBB6EEFB7D5209E22F451B76F57D90BB6641DFFDE1A1821C4D783E4756F3CEE7F63B9BA284F8E114B0D9A086D83233BED4A8F5B60933DC16AF4DDE19C9FC59BCC1646343ECE7007B1C4DC65C4A939CDD47F6ED8855913183149BECE66D8FE7793AE607EB8E28513749B9548252764110D3B58D1D8B348DB18F7F24F8CA0C7D9CB515D90F7F1848FF58472B2EF52EBAB123AFC7F87890CE9FC55B31160014294A9B7F81638A27335E29E15A10B1068D5E049B1C239814DBBCC1BB30E11EEBAD5ACF8FB1B986C4F48D73FEA6129D9708A0B5AC435402BEC8C79C71DB94394811B9A604141A125A4669F9A139A0264E93E822117BE8E0D93A1487C51214E9FBF5763A3FBE9DA700B9C9B435472AF9F0B4446B000000003239307DD8B645100001D60B90300000CA1EC9E9B1C467FB020000000004595A
29+
...
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# REQUIRES: system-linux, lzma, xz
2+
3+
# We want to keep the symbol "multiplyByThree" in the .dynamic section and not
4+
# have it put the default .symtab section.
5+
# RUN: echo "{multiplyByThree;};" > %T/dynmic-symbols.txt
6+
# RUN: %clang -Wl,--dynamic-list=%T/dynmic-symbols.txt -g -o %t.binary %p/Inputs/minidebuginfo-main.c
7+
8+
# The following section is adapted from GDB's official documentation:
9+
# http://sourceware.org/gdb/current/onlinedocs/gdb/MiniDebugInfo.html#MiniDebugInfo
10+
11+
# Extract the dynamic symbols from the main binary, there is no need
12+
# to also have these in the normal symbol table.
13+
14+
# IGNORE: llvm-nm -D %t.binary --format=posix --defined-only | awk '{ print $1 }' | sort > %t.dynsyms
15+
16+
# Extract all the text (i.e. function) symbols from the debuginfo.
17+
# (Note that we actually also accept "D" symbols, for the benefit
18+
# of platforms like PowerPC64 that use function descriptors.)
19+
20+
# IGNORE: llvm-nm %t.binary --format=posix --defined-only | awk '{ if ($2 == "T" || $2 == "t" || $2 == "D") print $1 }' | sort > %t.funcsyms
21+
22+
# Keep all the function symbols not already in the dynamic symbol
23+
# table.
24+
25+
# IGNORE: comm -13 %t.dynsyms %t.funcsyms > %t.keep_symbols
26+
# The result of the preceeding command can be preprocessed in %p/Inputs/minidebuginfo.keep_symbols
27+
# because we know what symbol to keep.
28+
# RUN: echo "multiplyByFour" > %p/Inputs/minidebuginfo.keep_symbols
29+
30+
# Separate full debug info into debug binary.
31+
32+
# RUN: llvm-objcopy --only-keep-debug %t.binary %t.debug
33+
34+
# Copy the full debuginfo, keeping only a minimal set of symbols and
35+
# removing some unnecessary sections.
36+
37+
# RUN: llvm-objcopy -S --remove-section .gdb_index --remove-section .comment --keep-symbols=%p/Inputs/minidebuginfo.keep_symbols %t.debug %t.mini_debuginfo
38+
39+
# This command is not from the GDB manual but it slims down embedded minidebug
40+
# info. On top if that, it ensures that we only have the multiplyByThree symbol
41+
# in the .dynsym section of the main binary.
42+
# RUN: llvm-objcopy --remove-section=.rela.dyn --remove-section=.gnu.version --remove-section=.gnu.hash --remove-section=.dynsym %t.mini_debuginfo
43+
44+
# Drop the full debug info from the original binary.
45+
46+
# RUN: llvm-strip --strip-all -R .comment %t.binary
47+
48+
# Inject the compressed data into the .gnu_debugdata section of the
49+
# original binary.
50+
51+
# RUN: xz --force --keep %t.mini_debuginfo
52+
53+
# RUN: llvm-objcopy --add-section .gnu_debugdata=%t.mini_debuginfo.xz %t.binary
54+
55+
# Now run the binary and see that we can set and hit a breakpoint
56+
# from within the .dynsym section (multiplyByThree) and one from
57+
# the .symtab section embedded in the .gnu_debugdata section (multiplyByFour).
58+
59+
# RUN: %lldb -b -o 'b multiplyByThree' -o 'b multiplyByFour' -o 'run' -o 'continue' -o 'breakpoint list -v' %t.binary | FileCheck %s
60+
61+
# CHECK: (lldb) b multiplyByThree
62+
# CHECK-NEXT: Breakpoint 1: where = minidebuginfo-set-and-hit-breakpoint.test.tmp.binary`multiplyByThree, address = 0x{{.*}}
63+
64+
# CHECK: (lldb) b multiplyByFour
65+
# CHECK-NEXT: Breakpoint 2: where = minidebuginfo-set-and-hit-breakpoint.test.tmp.binary`multiplyByFour, address = 0x{{.*}}
66+
67+
# CHECK: * thread #1, name = 'minidebuginfo-s', stop reason = breakpoint 1.1
68+
# CHECK: * thread #1, name = 'minidebuginfo-s', stop reason = breakpoint 2.1
69+
70+
# CHECK: (lldb) breakpoint list -v
71+
# CHECK-NEXT: Current breakpoints:
72+
# CHECK-NEXT: 1: name = 'multiplyByThree'
73+
# CHECK-NEXT: 1.1:
74+
# CHECK-NEXT: module = {{.*}}/minidebuginfo-set-and-hit-breakpoint.test.tmp.binary
75+
# CHECK-NEXT: symbol = multiplyByThree
76+
# CHECK-NEXT: address = 0x{{.*}}
77+
# CHECK-NEXT: resolved = true
78+
# CHECK-NEXT: hit count = 1
79+
80+
# CHECK: 2: name = 'multiplyByFour'
81+
# CHECK-NEXT: 2.1:
82+
# CHECK-NEXT: module = {{.*}}/minidebuginfo-set-and-hit-breakpoint.test.tmp.binary
83+
# CHECK-NEXT: symbol = multiplyByFour
84+
# CHECK-NEXT: address = 0x{{.*}}
85+
# CHECK-NEXT: resolved = true
86+
# CHECK-NEXT: hit count = 1

lldb/lit/lit.cfg.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from lit.llvm import llvm_config
1212
from lit.llvm.subst import FindTool
1313
from lit.llvm.subst import ToolSubst
14+
from distutils.spawn import find_executable
1415

1516
site.addsitedir(os.path.dirname(__file__))
1617
from helper import toolchain
@@ -98,3 +99,9 @@ def calculate_arch_features(arch_string):
9899

99100
if not config.lldb_disable_python:
100101
config.available_features.add('python')
102+
103+
if config.lldb_enable_lzma:
104+
config.available_features.add('lzma')
105+
106+
if find_executable('xz') != None:
107+
config.available_features.add('xz')

lldb/lit/lit.site.cfg.py.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ config.lldb_lit_tools_dir = r"@LLDB_LIT_TOOLS_DIR@"
1515
config.target_triple = "@TARGET_TRIPLE@"
1616
config.python_executable = "@PYTHON_EXECUTABLE@"
1717
config.have_zlib = @LLVM_ENABLE_ZLIB@
18+
config.lldb_enable_lzma = @LLDB_ENABLE_LZMA@
1819
config.host_triple = "@LLVM_HOST_TRIPLE@"
1920
config.lldb_bitness = 64 if @LLDB_IS_64_BITS@ else 32
2021
config.lldb_disable_python = @LLDB_DISABLE_PYTHON@

lldb/source/Host/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ add_host_subdirectory(common
2929
common/HostProcess.cpp
3030
common/HostThread.cpp
3131
common/LockFileBase.cpp
32+
common/LZMA.cpp
3233
common/MainLoop.cpp
3334
common/MonitoringProcessLauncher.cpp
3435
common/NativeProcessProtocol.cpp
@@ -157,6 +158,9 @@ endif()
157158
if (NOT LLDB_DISABLE_LIBEDIT)
158159
list(APPEND EXTRA_LIBS ${libedit_LIBRARIES})
159160
endif()
161+
if (LLDB_ENABLE_LZMA)
162+
list(APPEND EXTRA_LIBS ${LIBLZMA_LIBRARIES})
163+
endif()
160164

161165
if (NOT LLDB_DISABLE_LIBEDIT)
162166
list(APPEND LLDB_LIBEDIT_LIBS ${libedit_LIBRARIES})

0 commit comments

Comments
 (0)