@@ -188,78 +188,102 @@ AddressClass ObjectFileXCOFF::GetAddressClass(addr_t file_addr) {
188
188
return AddressClass::eUnknown;
189
189
}
190
190
191
- lldb::SymbolType MapSymbolType (llvm::object::SymbolRef::Type sym_type) {
192
- if (sym_type == llvm::object::SymbolRef::ST_Function)
191
+ static lldb::SymbolType MapSymbolType (llvm::object::SymbolRef::Type sym_type) {
192
+ switch (sym_type) {
193
+ case llvm::object::SymbolRef::ST_Function:
193
194
return lldb::eSymbolTypeCode;
194
- else if (sym_type == llvm::object::SymbolRef::ST_Data)
195
+ case llvm::object::SymbolRef::ST_Data:
195
196
return lldb::eSymbolTypeData;
196
- else if (sym_type == llvm::object::SymbolRef::ST_File)
197
+ case llvm::object::SymbolRef::ST_File:
197
198
return lldb::eSymbolTypeSourceFile;
198
- return lldb::eSymbolTypeInvalid;
199
+ default :
200
+ return lldb::eSymbolTypeInvalid;
201
+ }
199
202
}
200
203
201
204
void ObjectFileXCOFF::ParseSymtab (Symtab &lldb_symtab) {
205
+ Log *log = GetLog (LLDBLog::Object);
202
206
SectionList *sectionList = GetSectionList ();
203
207
204
208
for (const auto &symbol_ref : m_binary->symbols ()) {
205
209
llvm::object::XCOFFSymbolRef xcoff_sym_ref (symbol_ref);
210
+
206
211
llvm::Expected<llvm::StringRef> name_or_err = xcoff_sym_ref.getName ();
207
212
if (!name_or_err) {
208
213
LLDB_LOG_ERROR (log, name_or_err.takeError (),
209
214
" Unable to extract name from the xcoff symbol ref object" );
210
215
continue ;
211
216
}
217
+
212
218
llvm::StringRef symbolName = name_or_err.get ();
213
- // Remove the dot prefix from symbol names.
219
+ // Remove the . prefix added during compilation. This prefix is usually
220
+ // added to differentiate between reference to the code and function
221
+ // descriptor. For instance, Adding .func will only allow user to put bp on
222
+ // .func, which is not known to the user, instead of func.
214
223
llvm::StringRef name_no_dot =
215
224
symbolName.starts_with (" ." ) ? symbolName.drop_front () : symbolName;
216
225
auto storageClass = xcoff_sym_ref.getStorageClass ();
217
- // If its the hidden ext TOC symbol, add it directly,
218
- // for all other C_HIDEXT symbols, proceed to other checks.
226
+ // C_HIDEXT symbols are not needed to be exposed, with the exception of TOC
227
+ // which is responsible for storing references to global data
219
228
if (storageClass == XCOFF::C_HIDEXT && symbolName != " TOC" ) {
220
- // We do not need to add entries with 0 or >1 auxiliary data
229
+
230
+ // Zero or muliple aux entries may suggest ambiguous data
221
231
if (xcoff_sym_ref.getNumberOfAuxEntries () != 1 )
222
232
continue ;
233
+
223
234
auto aux_csect_or_err = xcoff_sym_ref.getXCOFFCsectAuxRef ();
224
235
if (!aux_csect_or_err) {
225
236
LLDB_LOG_ERROR (log, aux_csect_or_err.takeError (),
226
237
" Unable to access xcoff csect aux ref object" );
227
238
continue ;
228
239
}
240
+
229
241
const llvm::object::XCOFFCsectAuxRef csect_aux = aux_csect_or_err.get ();
242
+
230
243
// Only add hidden ext entries which come under Program Code, skip others
244
+ // as they are not useful as debugging data.
231
245
if (csect_aux.getStorageMappingClass () != XCOFF::XMC_PR)
232
246
continue ;
247
+
233
248
// This does not apply to 32-bit,
234
- // Only add csect symbols identified by the aux entry, skip others
235
- if (m_binary->is64Bit () ? (csect_aux.getAuxType64 () != XCOFF::AUX_CSECT))
236
- continue ;
249
+ // Only add csect symbols identified by the aux entry, as they are
250
+ // needed to reference section information. Skip others
251
+ if (m_binary->is64Bit ())
252
+ if (csect_aux.getAuxType64 () != XCOFF::AUX_CSECT)
253
+ continue ;
237
254
}
238
255
239
256
Symbol symbol;
240
257
symbol.GetMangled ().SetValue (ConstString (name_no_dot));
241
258
242
259
int16_t sectionNumber = xcoff_sym_ref.getSectionNumber ();
260
+ // Note that XCOFF section headers are numbered from 1 and not 0.
243
261
size_t sectionIndex = static_cast <size_t >(sectionNumber - 1 );
244
- if (sectionNumber > 0 && sectionIndex < sectionList->GetSize ()) {
245
- lldb::SectionSP section_sp =
246
- sectionList->GetSectionAtIndex (sectionNumber - 1 );
247
- if (!section_sp || section_sp->GetFileAddress () == LLDB_INVALID_ADDRESS)
248
- continue ;
249
- lldb::addr_t file_addr = section_sp->GetFileAddress ();
250
- lldb::addr_t symbolValue = xcoff_sym_ref.getValue ();
251
- if (symbolValue < file_addr)
252
- continue ;
253
- symbol.GetAddressRef () = Address (section_sp, symbolValue - file_addr);
262
+ if (sectionNumber > 0 ) {
263
+ if (sectionIndex < sectionList->GetSize ()) {
264
+
265
+ lldb::SectionSP section_sp =
266
+ sectionList->GetSectionAtIndex (sectionIndex);
267
+ if (!section_sp || section_sp->GetFileAddress () == LLDB_INVALID_ADDRESS)
268
+ continue ;
269
+
270
+ lldb::addr_t file_addr = section_sp->GetFileAddress ();
271
+ lldb::addr_t symbolValue = xcoff_sym_ref.getValue ();
272
+ if (symbolValue < file_addr)
273
+ continue ;
274
+
275
+ symbol.GetAddressRef () = Address (section_sp, symbolValue - file_addr);
276
+ }
254
277
}
255
278
256
279
Expected<llvm::object::SymbolRef::Type> sym_type_or_err =
257
280
symbol_ref.getType ();
258
281
if (!sym_type_or_err) {
259
- LLDB_LOG_ERROR (log, aux_csect_or_err .takeError (),
282
+ LLDB_LOG_ERROR (log, sym_type_or_err .takeError (),
260
283
" Unable to access xcoff symbol type" );
261
284
continue ;
262
285
}
286
+
263
287
symbol.SetType (MapSymbolType (sym_type_or_err.get ()));
264
288
265
289
lldb_symtab.AddSymbol (symbol);
@@ -315,7 +339,6 @@ void ObjectFileXCOFF::CreateSectionsWithBitness(
315
339
.Case (" .dwinfo" , eSectionTypeDWARFDebugInfo)
316
340
.Case (" .dwline" , eSectionTypeDWARFDebugLine)
317
341
.Case (" .dwabrev" , eSectionTypeDWARFDebugAbbrev)
318
- .Case (" .dwrnges" , eSectionTypeDWARFDebugRanges)
319
342
.Default (eSectionTypeInvalid);
320
343
}
321
344
0 commit comments