Improve FreeBSD kernel debugging

FreeBSD kernel modules are actually relocatable (.o) ELF files and this
previously caused some issues for LLDB. This change addresses these when
using lldb to symbolicate FreeBSD kernel backtraces. 

The major problems:

- Relocations were not being applied to the DWARF debug info despite
  there being code to do this. Several issues prevented it from working:

  - Relocations are computed at the same time as the symbol table, but
    in the case of split debug files, symbol table parsing always
    redirects to the primary object file, meaning that relocations would
    never be applied in the debug file.

  - There's actually no guarantee that the symbol table has been parsed
    yet when trying to parse debug information.

  - When actually applying relocations, it will segfault because the
    object files are not mapped with MAP_PRIVATE and PROT_WRITE.

- LLDB returned invalid results when performing ordinary address-to-
  symbol resolution. It turned out that the addresses specified in the
  section headers were all 0, so LLDB believed all the sections had
  overlapping "file addresses" and would sometimes return a symbol from
  the wrong section.

Patch by Brian Koropoff

Differential Revision:	https://reviews.llvm.org/D38142

llvm-svn: 314672
This commit is contained in:
Ed Maste
2017-10-02 14:35:07 +00:00
parent e2aa5b2ace
commit d13f691f41
11 changed files with 125 additions and 59 deletions

View File

@@ -230,9 +230,9 @@ bool ObjectFileJIT::SetLoadAddress(Target &target, lldb::addr_t value,
return num_loaded_sections > 0;
}
size_t ObjectFileJIT::ReadSectionData(const lldb_private::Section *section,
size_t ObjectFileJIT::ReadSectionData(lldb_private::Section *section,
lldb::offset_t section_offset, void *dst,
size_t dst_len) const {
size_t dst_len) {
lldb::offset_t file_size = section->GetFileSize();
if (section_offset < file_size) {
size_t src_len = file_size - section_offset;
@@ -248,8 +248,8 @@ size_t ObjectFileJIT::ReadSectionData(const lldb_private::Section *section,
}
size_t ObjectFileJIT::ReadSectionData(
const lldb_private::Section *section,
lldb_private::DataExtractor &section_data) const {
lldb_private::Section *section,
lldb_private::DataExtractor &section_data) {
if (section->GetFileSize()) {
const void *src = (void *)(uintptr_t)section->GetFileOffset();