Skip to content

[lldb][AIX] Added XCOFF ParseSymtab handling #141577

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 101 additions & 1 deletion lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,107 @@ AddressClass ObjectFileXCOFF::GetAddressClass(addr_t file_addr) {
return AddressClass::eUnknown;
}

void ObjectFileXCOFF::ParseSymtab(Symtab &lldb_symtab) {}
static lldb::SymbolType MapSymbolType(llvm::object::SymbolRef::Type sym_type) {
switch (sym_type) {
case llvm::object::SymbolRef::ST_Function:
return lldb::eSymbolTypeCode;
case llvm::object::SymbolRef::ST_Data:
return lldb::eSymbolTypeData;
case llvm::object::SymbolRef::ST_File:
return lldb::eSymbolTypeSourceFile;
default:
return lldb::eSymbolTypeInvalid;
}
}

void ObjectFileXCOFF::ParseSymtab(Symtab &lldb_symtab) {
Log *log = GetLog(LLDBLog::Object);
SectionList *sectionList = GetSectionList();

for (const auto &symbol_ref : m_binary->symbols()) {
llvm::object::XCOFFSymbolRef xcoff_sym_ref(symbol_ref);

llvm::Expected<llvm::StringRef> name_or_err = xcoff_sym_ref.getName();
if (!name_or_err) {
LLDB_LOG_ERROR(log, name_or_err.takeError(),
"Unable to extract name from the xcoff symbol ref object");
continue;
}

llvm::StringRef symbolName = name_or_err.get();
// Remove the . prefix added during compilation. This prefix is usually
// added to differentiate between reference to the code and function
// descriptor. For instance, Adding .func will only allow user to put bp on
// .func, which is not known to the user, instead of func.
llvm::StringRef name_no_dot =
symbolName.starts_with(".") ? symbolName.drop_front() : symbolName;
auto storageClass = xcoff_sym_ref.getStorageClass();
// C_HIDEXT symbols are not needed to be exposed, with the exception of TOC
// which is responsible for storing references to global data
if (storageClass == XCOFF::C_HIDEXT && symbolName != "TOC") {

// Zero or muliple aux entries may suggest ambiguous data
if (xcoff_sym_ref.getNumberOfAuxEntries() != 1)
continue;

auto aux_csect_or_err = xcoff_sym_ref.getXCOFFCsectAuxRef();
if (!aux_csect_or_err) {
LLDB_LOG_ERROR(log, aux_csect_or_err.takeError(),
"Unable to access xcoff csect aux ref object");
continue;
}

const llvm::object::XCOFFCsectAuxRef csect_aux = aux_csect_or_err.get();

// Only add hidden ext entries which come under Program Code, skip others
// as they are not useful as debugging data.
if (csect_aux.getStorageMappingClass() != XCOFF::XMC_PR)
continue;

// This does not apply to 32-bit,
// Only add csect symbols identified by the aux entry, as they are
// needed to reference section information. Skip others
if (m_binary->is64Bit())
if (csect_aux.getAuxType64() != XCOFF::AUX_CSECT)
continue;
}

Symbol symbol;
symbol.GetMangled().SetValue(ConstString(name_no_dot));

int16_t sectionNumber = xcoff_sym_ref.getSectionNumber();
// Note that XCOFF section headers are numbered from 1 and not 0.
size_t sectionIndex = static_cast<size_t>(sectionNumber - 1);
if (sectionNumber > 0) {
if (sectionIndex < sectionList->GetSize()) {

lldb::SectionSP section_sp =
sectionList->GetSectionAtIndex(sectionIndex);
if (!section_sp || section_sp->GetFileAddress() == LLDB_INVALID_ADDRESS)
continue;

lldb::addr_t file_addr = section_sp->GetFileAddress();
lldb::addr_t symbolValue = xcoff_sym_ref.getValue();
if (symbolValue < file_addr)
continue;

symbol.GetAddressRef() = Address(section_sp, symbolValue - file_addr);
}
}

Expected<llvm::object::SymbolRef::Type> sym_type_or_err =
symbol_ref.getType();
if (!sym_type_or_err) {
LLDB_LOG_ERROR(log, sym_type_or_err.takeError(),
"Unable to access xcoff symbol type");
continue;
}

symbol.SetType(MapSymbolType(sym_type_or_err.get()));

lldb_symtab.AddSymbol(symbol);
}
}

bool ObjectFileXCOFF::IsStripped() { return false; }

Expand Down
94 changes: 94 additions & 0 deletions lldb/test/Shell/ObjectFile/XCOFF/basic-info.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@
# CHECK-NEXT: Type: dwarf-abbrev
# CHECK-NEXT: Permissions: r--

# RUN: %lldb %t -o "image dump symtab" -o exit | FileCheck %s --check-prefix=CHECK-SYMBOL
# CHECK-SYMBOL:Index UserID DSX Type File Address/Value Load Address Size Flags Name
# CHECK-SYMBOL:[ 0] 4294967295 Invalid 0xffffffffffffffff 0x0000000000000000 0x00000000 errno
# CHECK-SYMBOL:[ 1] 4294967295 Code 0x0000000100000500 0x0000000000000398 0x00000000 __threads_init
# CHECK-SYMBOL:[ 2] 4294967295 Data 0x0000000110000a70 0x0000000000000060 0x00000000 __threads_init
# CHECK-SYMBOL:[ 3] 4294967295 Invalid 0x0000000110000ad0 0x00000000000000b0 0x00000000 TOC
# CHECK-SYMBOL:[ 4] 4294967295 Invalid 0x0000000100000898 0x00000000100001d8 0x00000000 text
# CHECK-SYMBOL:[ 5] 4294967295 Code 0x0000000100000898 0x00000000100001d8 0x00000000 main

--- !XCOFF
FileHeader:
MagicNumber: 0x1F7
Expand Down Expand Up @@ -104,5 +113,90 @@ Sections:
NumberOfLineNumbers: 0x0
Flags: [ STYP_DWARF ]
SectionData: 01110125
Symbols:
- Name: errno
Value: 0x0
Section: N_UNDEF
Type: 0x0
StorageClass: C_EXT
NumberOfAuxEntries: 1
AuxEntries:
- Type: AUX_CSECT
ParameterHashIndex: 0
TypeChkSectNum: 0
SymbolAlignmentAndType: 0
StorageMappingClass: XMC_RW
SectionOrLengthLo: 0
SectionOrLengthHi: 0
- Name: .__threads_init
Value: 0x100000500
Section: .text
Type: 0x20
StorageClass: C_EXT
NumberOfAuxEntries: 1
AuxEntries:
- Type: AUX_CSECT
ParameterHashIndex: 0
TypeChkSectNum: 0
SymbolAlignmentAndType: 2
StorageMappingClass: XMC_PR
SectionOrLengthLo: 80
SectionOrLengthHi: 0
- Name: __threads_init
Value: 0x110000A70
Section: .data
Type: 0x0
StorageClass: C_EXT
NumberOfAuxEntries: 1
AuxEntries:
- Type: AUX_CSECT
ParameterHashIndex: 0
TypeChkSectNum: 0
SymbolAlignmentAndType: 25
StorageMappingClass: XMC_DS
SectionOrLengthLo: 24
SectionOrLengthHi: 0
- Name: TOC
Value: 0x110000AD0
Section: .data
Type: 0x0
StorageClass: C_HIDEXT
NumberOfAuxEntries: 1
AuxEntries:
- Type: AUX_CSECT
ParameterHashIndex: 0
TypeChkSectNum: 0
SymbolAlignmentAndType: 25
StorageMappingClass: XMC_TC0
SectionOrLengthLo: 0
SectionOrLengthHi: 0
- Name: .text
Value: 0x100000898
Section: .text
Type: 0x0
StorageClass: C_HIDEXT
NumberOfAuxEntries: 1
AuxEntries:
- Type: AUX_CSECT
ParameterHashIndex: 0
TypeChkSectNum: 0
SymbolAlignmentAndType: 17
StorageMappingClass: XMC_PR
SectionOrLengthLo: 58
SectionOrLengthHi: 0
- Name: .main
Value: 0x100000898
Section: .text
Type: 0x0
StorageClass: C_EXT
NumberOfAuxEntries: 1
AuxEntries:
- Type: AUX_CSECT
ParameterHashIndex: 0
TypeChkSectNum: 0
SymbolAlignmentAndType: 2
StorageMappingClass: XMC_PR
SectionOrLengthLo: 135
SectionOrLengthHi: 0
StringTable: {}
...
96 changes: 96 additions & 0 deletions lldb/test/Shell/ObjectFile/XCOFF/basic-info32.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@
# CHECK-NEXT: Type: dwarf-abbrev
# CHECK-NEXT: Permissions: r--


# RUN: %lldb %t -o "image dump symtab" -o exit | FileCheck %s --check-prefix=CHECK-SYMBOL
# CHECK-SYMBOL:Index UserID DSX Type File Address/Value Load Address Size Flags Name
#[ 0] 4294967295 Invalid 0xffffffffffffffff 0x0000000000000000 0x00000000 errno
# CHECK-SYMBOL:[ 1] 4294967295 Code 0x0000000010000320 0x0000000000000420 0x00000000 __threads_init
# CHECK-SYMBOL:[ 2] 4294967295 Data 0x0000000020000920 0x000000000000003c 0x00000000 __threads_init
# CHECK-SYMBOL:[ 3] 4294967295 Invalid 0x000000002000095c 0x0000000000000060 0x00000000 TOC
# CHECK-SYMBOL:[ 4] 4294967295 Invalid 0x0000000010000740 0x000000000000003a 0x00000000 text
# CHECK-SYMBOL:[ 5] 4294967295 Invalid 0x0000000010000740 0x000000000000003a 0x00000000 main

--- !XCOFF
FileHeader:
MagicNumber: 0x1DF
Expand Down Expand Up @@ -106,5 +116,91 @@ Sections:
NumberOfLineNumbers: 0x0
Flags: [ STYP_DWARF ]
SectionData: 01110125
Symbols:
- Name: errno
Value: 0x0
Section: N_UNDEF
Type: 0x0
StorageClass: C_EXT
NumberOfAuxEntries: 1
AuxEntries:
- Type: AUX_CSECT
ParameterHashIndex: 0
TypeChkSectNum: 0
StorageMappingClass: XMC_RW
SectionOrLength: 0
StabInfoIndex: 0
StabSectNum: 0
- Name: .__threads_init
Value: 0x10000320
Section: .text
Type: 0x20
StorageClass: C_EXT
NumberOfAuxEntries: 1
AuxEntries:
- Type: AUX_CSECT
ParameterHashIndex: 0
TypeChkSectNum: 0
StorageMappingClass: XMC_PR
SectionOrLength: 84
StabInfoIndex: 0
StabSectNum: 0
- Name: __threads_init
Value: 0x20000920
Section: .data
Type: 0x0
StorageClass: C_EXT
NumberOfAuxEntries: 1
AuxEntries:
- Type: AUX_CSECT
ParameterHashIndex: 0
TypeChkSectNum: 0
StorageMappingClass: XMC_DS
SectionOrLength: 12
StabInfoIndex: 0
StabSectNum: 0
- Name: TOC
Value: 0x2000095C
Section: .data
Type: 0x0
StorageClass: C_HIDEXT
NumberOfAuxEntries: 1
AuxEntries:
- Type: AUX_CSECT
ParameterHashIndex: 0
TypeChkSectNum: 0
StorageMappingClass: XMC_TC0
SectionOrLength: 0
StabInfoIndex: 0
StabSectNum: 0
- Name: .text
Value: 0x10000740
Section: .text
Type: 0x0
StorageClass: C_HIDEXT
NumberOfAuxEntries: 1
AuxEntries:
- Type: AUX_CSECT
ParameterHashIndex: 0
TypeChkSectNum: 0
StorageMappingClass: XMC_PR
SectionOrLength: 58
StabInfoIndex: 0
StabSectNum: 0
- Name: .main
Value: 0x10000740
Section: .text
Type: 0x0
StorageClass: C_EXT
NumberOfAuxEntries: 1
AuxEntries:
- Type: AUX_CSECT
ParameterHashIndex: 0
TypeChkSectNum: 0
StorageMappingClass: XMC_PR
SectionOrLength: 137
StabInfoIndex: 0
StabSectNum: 0

StringTable: {}
...
Loading