@@ -33,12 +33,12 @@ using namespace lldb_private::plugin::dwarf;
33
33
extern int g_verbose;
34
34
35
35
DWARFUnit::DWARFUnit (SymbolFileDWARF &dwarf, lldb::user_id_t uid,
36
- const DWARFUnitHeader &header,
36
+ const llvm:: DWARFUnitHeader &header,
37
37
const llvm::DWARFAbbreviationDeclarationSet &abbrevs,
38
38
DIERef::Section section, bool is_dwo)
39
39
: UserID(uid), m_dwarf(dwarf), m_header(header), m_abbrevs(&abbrevs),
40
40
m_cancel_scopes(false ), m_section(section), m_is_dwo(is_dwo),
41
- m_has_parsed_non_skeleton_unit(false ), m_dwo_id(header.GetDWOId ()) {}
41
+ m_has_parsed_non_skeleton_unit(false ), m_dwo_id(header.getDWOId ()) {}
42
42
43
43
DWARFUnit::~DWARFUnit () = default ;
44
44
@@ -345,7 +345,7 @@ void DWARFUnit::ExtractDIEsRWLocked() {
345
345
void DWARFUnit::SetDwoStrOffsetsBase () {
346
346
lldb::offset_t baseOffset = 0 ;
347
347
348
- if (const llvm::DWARFUnitIndex::Entry *entry = m_header.GetIndexEntry ()) {
348
+ if (const llvm::DWARFUnitIndex::Entry *entry = m_header.getIndexEntry ()) {
349
349
if (const auto *contribution =
350
350
entry->getContribution (llvm::DW_SECT_STR_OFFSETS))
351
351
baseOffset = contribution->getOffset ();
@@ -489,7 +489,7 @@ ParseListTableHeader(const llvm::DWARFDataExtractor &data, uint64_t offset,
489
489
490
490
void DWARFUnit::SetLoclistsBase (dw_addr_t loclists_base) {
491
491
uint64_t offset = 0 ;
492
- if (const llvm::DWARFUnitIndex::Entry *entry = m_header.GetIndexEntry ()) {
492
+ if (const llvm::DWARFUnitIndex::Entry *entry = m_header.getIndexEntry ()) {
493
493
const auto *contribution = entry->getContribution (llvm::DW_SECT_LOCLISTS);
494
494
if (!contribution) {
495
495
GetSymbolFileDWARF ().GetObjectFile ()->GetModule ()->ReportError (
@@ -533,7 +533,7 @@ DWARFDataExtractor DWARFUnit::GetLocationData() const {
533
533
DWARFContext &Ctx = GetSymbolFileDWARF ().GetDWARFContext ();
534
534
const DWARFDataExtractor &data =
535
535
GetVersion () >= 5 ? Ctx.getOrLoadLocListsData () : Ctx.getOrLoadLocData ();
536
- if (const llvm::DWARFUnitIndex::Entry *entry = m_header.GetIndexEntry ()) {
536
+ if (const llvm::DWARFUnitIndex::Entry *entry = m_header.getIndexEntry ()) {
537
537
if (const auto *contribution = entry->getContribution (
538
538
GetVersion () >= 5 ? llvm::DW_SECT_LOCLISTS : llvm::DW_SECT_EXT_LOC))
539
539
return DWARFDataExtractor (data, contribution->getOffset (),
@@ -546,7 +546,7 @@ DWARFDataExtractor DWARFUnit::GetLocationData() const {
546
546
DWARFDataExtractor DWARFUnit::GetRnglistData () const {
547
547
DWARFContext &Ctx = GetSymbolFileDWARF ().GetDWARFContext ();
548
548
const DWARFDataExtractor &data = Ctx.getOrLoadRngListsData ();
549
- if (const llvm::DWARFUnitIndex::Entry *entry = m_header.GetIndexEntry ()) {
549
+ if (const llvm::DWARFUnitIndex::Entry *entry = m_header.getIndexEntry ()) {
550
550
if (const auto *contribution =
551
551
entry->getContribution (llvm::DW_SECT_RNGLISTS))
552
552
return DWARFDataExtractor (data, contribution->getOffset (),
@@ -924,111 +924,42 @@ const DWARFDebugAranges &DWARFUnit::GetFunctionAranges() {
924
924
return *m_func_aranges_up;
925
925
}
926
926
927
- llvm::Error DWARFUnitHeader::ApplyIndexEntry (
928
- const llvm::DWARFUnitIndex::Entry *index_entry) {
929
- // We should only be calling this function when the index entry is not set and
930
- // we have a valid one to set it to.
931
- assert (index_entry);
932
- assert (!m_index_entry);
933
-
934
- if (m_abbr_offset)
935
- return llvm::createStringError (
936
- llvm::inconvertibleErrorCode (),
937
- " Package unit with a non-zero abbreviation offset" );
938
-
939
- auto *unit_contrib = index_entry->getContribution ();
940
- if (!unit_contrib || unit_contrib->getLength32 () != m_length + 4 )
941
- return llvm::createStringError (llvm::inconvertibleErrorCode (),
942
- " Inconsistent DWARF package unit index" );
943
-
944
- auto *abbr_entry = index_entry->getContribution (llvm::DW_SECT_ABBREV);
945
- if (!abbr_entry)
946
- return llvm::createStringError (
947
- llvm::inconvertibleErrorCode (),
948
- " DWARF package index missing abbreviation column" );
949
-
950
- m_abbr_offset = abbr_entry->getOffset ();
951
- m_index_entry = index_entry;
952
- return llvm::Error::success ();
953
- }
954
-
955
- llvm::Expected<DWARFUnitHeader>
956
- DWARFUnitHeader::extract (const DWARFDataExtractor &data,
957
- DIERef::Section section, DWARFContext &context,
958
- lldb::offset_t *offset_ptr) {
959
- DWARFUnitHeader header;
960
- header.m_offset = *offset_ptr;
961
- header.m_length = data.GetDWARFInitialLength (offset_ptr);
962
- header.m_version = data.GetU16 (offset_ptr);
963
- if (header.m_version == 5 ) {
964
- header.m_unit_type = data.GetU8 (offset_ptr);
965
- header.m_addr_size = data.GetU8 (offset_ptr);
966
- header.m_abbr_offset = data.GetDWARFOffset (offset_ptr);
967
- if (header.m_unit_type == llvm::dwarf::DW_UT_skeleton ||
968
- header.m_unit_type == llvm::dwarf::DW_UT_split_compile)
969
- header.m_dwo_id = data.GetU64 (offset_ptr);
970
- } else {
971
- header.m_abbr_offset = data.GetDWARFOffset (offset_ptr);
972
- header.m_addr_size = data.GetU8 (offset_ptr);
973
- header.m_unit_type =
974
- section == DIERef::Section::DebugTypes ? DW_UT_type : DW_UT_compile;
975
- }
976
-
977
- if (header.IsTypeUnit ()) {
978
- header.m_type_hash = data.GetU64 (offset_ptr);
979
- header.m_type_offset = data.GetDWARFOffset (offset_ptr);
980
- }
981
-
982
- bool length_OK = data.ValidOffset (header.GetNextUnitOffset () - 1 );
983
- bool version_OK = SymbolFileDWARF::SupportedVersion (header.m_version );
984
- bool addr_size_OK = (header.m_addr_size == 2 ) || (header.m_addr_size == 4 ) ||
985
- (header.m_addr_size == 8 );
986
- bool type_offset_OK =
987
- !header.IsTypeUnit () || (header.m_type_offset <= header.GetLength ());
988
-
989
- if (!length_OK)
990
- return llvm::make_error<llvm::object::GenericBinaryError>(
991
- " Invalid unit length" );
992
- if (!version_OK)
993
- return llvm::make_error<llvm::object::GenericBinaryError>(
994
- " Unsupported unit version" );
995
- if (!addr_size_OK)
996
- return llvm::make_error<llvm::object::GenericBinaryError>(
997
- " Invalid unit address size" );
998
- if (!type_offset_OK)
999
- return llvm::make_error<llvm::object::GenericBinaryError>(
1000
- " Type offset out of range" );
1001
-
1002
- return header;
1003
- }
1004
-
1005
927
llvm::Expected<DWARFUnitSP>
1006
928
DWARFUnit::extract (SymbolFileDWARF &dwarf, user_id_t uid,
1007
929
const DWARFDataExtractor &debug_info,
1008
930
DIERef::Section section, lldb::offset_t *offset_ptr) {
1009
931
assert (debug_info.ValidOffset (*offset_ptr));
1010
932
1011
933
DWARFContext &context = dwarf.GetDWARFContext ();
1012
- auto expected_header =
1013
- DWARFUnitHeader::extract (debug_info, section, context, offset_ptr);
1014
- if (!expected_header)
1015
- return expected_header.takeError ();
934
+
935
+ // FIXME: Either properly map between DIERef::Section and
936
+ // llvm::DWARFSectionKind or switch to llvm's definition entirely.
937
+ llvm::DWARFSectionKind section_kind_llvm =
938
+ section == DIERef::Section::DebugInfo
939
+ ? llvm::DWARFSectionKind::DW_SECT_INFO
940
+ : llvm::DWARFSectionKind::DW_SECT_EXT_TYPES;
941
+
942
+ llvm::DWARFDataExtractor debug_info_llvm = debug_info.GetAsLLVMDWARF ();
943
+ llvm::DWARFUnitHeader header;
944
+ if (llvm::Error extract_err = header.extract (
945
+ context.GetAsLLVM (), debug_info_llvm, offset_ptr, section_kind_llvm))
946
+ return std::move (extract_err);
1016
947
1017
948
if (context.isDwo ()) {
1018
949
const llvm::DWARFUnitIndex::Entry *entry = nullptr ;
1019
- const llvm::DWARFUnitIndex &index = expected_header-> IsTypeUnit ()
950
+ const llvm::DWARFUnitIndex &index = header. isTypeUnit ()
1020
951
? context.GetAsLLVM ().getTUIndex ()
1021
952
: context.GetAsLLVM ().getCUIndex ();
1022
953
if (index ) {
1023
- if (expected_header-> IsTypeUnit ())
1024
- entry = index .getFromHash (expected_header-> GetTypeHash ());
1025
- else if (auto dwo_id = expected_header-> GetDWOId ())
954
+ if (header. isTypeUnit ())
955
+ entry = index .getFromHash (header. getTypeHash ());
956
+ else if (auto dwo_id = header. getDWOId ())
1026
957
entry = index .getFromHash (*dwo_id);
1027
958
}
1028
959
if (!entry)
1029
- entry = index .getFromOffset (expected_header-> GetOffset ());
960
+ entry = index .getFromOffset (header. getOffset ());
1030
961
if (entry)
1031
- if (llvm::Error err = expected_header-> ApplyIndexEntry (entry))
962
+ if (llvm::Error err = header. applyIndexEntry (entry))
1032
963
return std::move (err);
1033
964
}
1034
965
@@ -1039,13 +970,13 @@ DWARFUnit::extract(SymbolFileDWARF &dwarf, user_id_t uid,
1039
970
1040
971
bool abbr_offset_OK =
1041
972
dwarf.GetDWARFContext ().getOrLoadAbbrevData ().ValidOffset (
1042
- expected_header-> GetAbbrOffset ());
973
+ header. getAbbrOffset ());
1043
974
if (!abbr_offset_OK)
1044
975
return llvm::make_error<llvm::object::GenericBinaryError>(
1045
976
" Abbreviation offset for unit is not valid" );
1046
977
1047
978
llvm::Expected<const llvm::DWARFAbbreviationDeclarationSet *> abbrevs_or_err =
1048
- abbr->getAbbreviationDeclarationSet (expected_header-> GetAbbrOffset ());
979
+ abbr->getAbbreviationDeclarationSet (header. getAbbrOffset ());
1049
980
if (!abbrevs_or_err)
1050
981
return abbrevs_or_err.takeError ();
1051
982
@@ -1055,11 +986,11 @@ DWARFUnit::extract(SymbolFileDWARF &dwarf, user_id_t uid,
1055
986
" No abbrev exists at the specified offset." );
1056
987
1057
988
bool is_dwo = dwarf.GetDWARFContext ().isDwo ();
1058
- if (expected_header-> IsTypeUnit ())
1059
- return DWARFUnitSP (new DWARFTypeUnit (dwarf, uid, *expected_header, *abbrevs,
1060
- section, is_dwo));
1061
- return DWARFUnitSP (new DWARFCompileUnit (dwarf, uid, *expected_header,
1062
- *abbrevs, section, is_dwo));
989
+ if (header. isTypeUnit ())
990
+ return DWARFUnitSP (
991
+ new DWARFTypeUnit (dwarf, uid, header, *abbrevs, section, is_dwo));
992
+ return DWARFUnitSP (
993
+ new DWARFCompileUnit (dwarf, uid, header, *abbrevs, section, is_dwo));
1063
994
}
1064
995
1065
996
const lldb_private::DWARFDataExtractor &DWARFUnit::GetData () const {
@@ -1069,7 +1000,7 @@ const lldb_private::DWARFDataExtractor &DWARFUnit::GetData() const {
1069
1000
}
1070
1001
1071
1002
uint32_t DWARFUnit::GetHeaderByteSize () const {
1072
- switch (m_header.GetUnitType ()) {
1003
+ switch (m_header.getUnitType ()) {
1073
1004
case llvm::dwarf::DW_UT_compile:
1074
1005
case llvm::dwarf::DW_UT_partial:
1075
1006
return GetVersion () < 5 ? 11 : 12 ;
@@ -1106,7 +1037,7 @@ DWARFUnit::FindRnglistFromOffset(dw_offset_t offset) {
1106
1037
llvm::DWARFDataExtractor data = GetRnglistData ().GetAsLLVMDWARF ();
1107
1038
1108
1039
// As DW_AT_rnglists_base may be missing we need to call setAddressSize.
1109
- data.setAddressSize (m_header.GetAddressByteSize ());
1040
+ data.setAddressSize (m_header.getAddressByteSize ());
1110
1041
auto range_list_or_error = GetRnglistTable ()->findList (data, offset);
1111
1042
if (!range_list_or_error)
1112
1043
return range_list_or_error.takeError ();
0 commit comments