@@ -188,7 +188,71 @@ AddressClass ObjectFileXCOFF::GetAddressClass(addr_t file_addr) {
188
188
return AddressClass::eUnknown;
189
189
}
190
190
191
- void ObjectFileXCOFF::ParseSymtab (Symtab &lldb_symtab) {}
191
+ lldb::SymbolType MapSymbolType (llvm::object::SymbolRef::Type sym_type) {
192
+ if (sym_type == llvm::object::SymbolRef::ST_Function)
193
+ return lldb::eSymbolTypeCode;
194
+ else if (sym_type == llvm::object::SymbolRef::ST_Data)
195
+ return lldb::eSymbolTypeData;
196
+ else if (sym_type == llvm::object::SymbolRef::ST_File)
197
+ return lldb::eSymbolTypeSourceFile;
198
+ return lldb::eSymbolTypeInvalid;
199
+ }
200
+
201
+ void ObjectFileXCOFF::ParseSymtab (Symtab &lldb_symtab) {
202
+ SectionList *sectionList = GetSectionList ();
203
+
204
+ for (const auto &symbol_ref : m_binary->symbols ()) {
205
+ llvm::object::XCOFFSymbolRef xcoff_sym_ref (symbol_ref);
206
+ llvm::Expected<llvm::StringRef> name_or_err = xcoff_sym_ref.getName ();
207
+ if (!name_or_err) {
208
+ consumeError (name_or_err.takeError ());
209
+ continue ;
210
+ }
211
+ llvm::StringRef symbolName = name_or_err.get ();
212
+ // Remove the dot prefix for demangle
213
+ llvm::StringRef symbol_name =
214
+ symbolName.starts_with (" ." ) ? symbolName.drop_front () : symbolName;
215
+ auto storageClass = xcoff_sym_ref.getStorageClass ();
216
+ if (storageClass == XCOFF::C_HIDEXT && symbolName != " TOC" ) {
217
+ if (xcoff_sym_ref.getNumberOfAuxEntries () != 1 )
218
+ continue ;
219
+ auto aux_csect_or_err = xcoff_sym_ref.getXCOFFCsectAuxRef ();
220
+ if (!aux_csect_or_err) {
221
+ consumeError (aux_csect_or_err.takeError ());
222
+ continue ;
223
+ }
224
+ const llvm::object::XCOFFCsectAuxRef csect_aux = aux_csect_or_err.get ();
225
+ if (csect_aux.getStorageMappingClass () != XCOFF::XMC_PR ||
226
+ (m_binary->is64Bit () ? (csect_aux.getAuxType64 () != XCOFF::AUX_CSECT)
227
+ : false ))
228
+ continue ;
229
+ }
230
+
231
+ Symbol symbol;
232
+ symbol.GetMangled ().SetValue (ConstString (symbol_name));
233
+
234
+ int16_t sectionNumber = xcoff_sym_ref.getSectionNumber ();
235
+ size_t sectionIndex = static_cast <size_t >(sectionNumber - 1 );
236
+ if (sectionNumber > 0 && sectionIndex < sectionList->GetSize ()) {
237
+ lldb::SectionSP section_sp =
238
+ sectionList->GetSectionAtIndex (sectionNumber - 1 );
239
+ if (!section_sp || section_sp->GetFileAddress () == LLDB_INVALID_ADDRESS)
240
+ continue ;
241
+ lldb::addr_t file_addr = section_sp->GetFileAddress ();
242
+ lldb::addr_t symbolValue = xcoff_sym_ref.getValue ();
243
+ if (symbolValue < file_addr)
244
+ continue ;
245
+ symbol.GetAddressRef () = Address (section_sp, symbolValue - file_addr);
246
+ }
247
+
248
+ Expected<llvm::object::SymbolRef::Type> sym_type_or_err =
249
+ symbol_ref.getType ();
250
+ symbol.SetType (MapSymbolType (sym_type_or_err.get ()));
251
+ printf (" %s %d\n " , symbol.GetName (), *sym_type_or_err);
252
+
253
+ lldb_symtab.AddSymbol (symbol);
254
+ }
255
+ }
192
256
193
257
bool ObjectFileXCOFF::IsStripped () { return false ; }
194
258
0 commit comments