@@ -219,9 +219,45 @@ CompUnitSP SymbolFileBreakpad::ParseCompileUnitAtIndex(uint32_t index) {
219
219
return cu_sp;
220
220
}
221
221
222
+ FunctionSP SymbolFileBreakpad::GetOrCreateFunction (CompileUnit &comp_unit) {
223
+ user_id_t id = comp_unit.GetID ();
224
+ if (FunctionSP func_sp = comp_unit.FindFunctionByUID (id))
225
+ return func_sp;
226
+
227
+ Log *log = GetLogIfAllCategoriesSet (LIBLLDB_LOG_SYMBOLS);
228
+ FunctionSP func_sp;
229
+ addr_t base = GetBaseFileAddress ();
230
+ if (base == LLDB_INVALID_ADDRESS) {
231
+ LLDB_LOG (log, " Unable to fetch the base address of object file. Skipping "
232
+ " symtab population." );
233
+ return func_sp;
234
+ }
235
+
236
+ const SectionList *list = comp_unit.GetModule ()->GetSectionList ();
237
+ CompUnitData &data = m_cu_data->GetEntryRef (id).data ;
238
+ LineIterator It (*m_objfile_sp, Record::Func, data.bookmark );
239
+ assert (Record::classify (*It) == Record::Func);
240
+
241
+ if (auto record = FuncRecord::parse (*It)) {
242
+ Mangled func_name;
243
+ func_name.SetValue (ConstString (record->Name ), false );
244
+ addr_t address = record->Address + base;
245
+ SectionSP section_sp = list->FindSectionContainingFileAddress (address);
246
+ if (section_sp) {
247
+ AddressRange func_range (
248
+ section_sp, address - section_sp->GetFileAddress (), record->Size );
249
+ // Use the CU's id because every CU has only one function inside.
250
+ func_sp = std::make_shared<Function>(&comp_unit, id, 0 , func_name,
251
+ nullptr , func_range);
252
+ comp_unit.AddFunction (func_sp);
253
+ }
254
+ }
255
+ return func_sp;
256
+ }
257
+
222
258
size_t SymbolFileBreakpad::ParseFunctions (CompileUnit &comp_unit) {
223
- // TODO
224
- return 0 ;
259
+ std::lock_guard<std::recursive_mutex> guard ( GetModuleMutex ());
260
+ return GetOrCreateFunction (comp_unit) ? 1 : 0 ;
225
261
}
226
262
227
263
bool SymbolFileBreakpad::ParseLineTable (CompileUnit &comp_unit) {
@@ -251,7 +287,8 @@ SymbolFileBreakpad::ResolveSymbolContext(const Address &so_addr,
251
287
SymbolContextItem resolve_scope,
252
288
SymbolContext &sc) {
253
289
std::lock_guard<std::recursive_mutex> guard (GetModuleMutex ());
254
- if (!(resolve_scope & (eSymbolContextCompUnit | eSymbolContextLineEntry)))
290
+ if (!(resolve_scope & (eSymbolContextCompUnit | eSymbolContextLineEntry |
291
+ eSymbolContextFunction)))
255
292
return 0 ;
256
293
257
294
ParseCUData ();
@@ -268,6 +305,13 @@ SymbolFileBreakpad::ResolveSymbolContext(const Address &so_addr,
268
305
result |= eSymbolContextLineEntry;
269
306
}
270
307
}
308
+ if (resolve_scope & eSymbolContextFunction) {
309
+ FunctionSP func_sp = GetOrCreateFunction (*sc.comp_unit );
310
+ if (func_sp) {
311
+ sc.function = func_sp.get ();
312
+ result |= eSymbolContextFunction;
313
+ }
314
+ }
271
315
272
316
return result;
273
317
}
@@ -291,7 +335,20 @@ void SymbolFileBreakpad::FindFunctions(
291
335
ConstString name, const CompilerDeclContext &parent_decl_ctx,
292
336
FunctionNameType name_type_mask, bool include_inlines,
293
337
SymbolContextList &sc_list) {
294
- // TODO
338
+ std::lock_guard<std::recursive_mutex> guard (GetModuleMutex ());
339
+ // TODO: Implement this with supported FunctionNameType.
340
+
341
+ for (uint32_t i = 0 ; i < GetNumCompileUnits (); ++i) {
342
+ CompUnitSP cu_sp = GetCompileUnitAtIndex (i);
343
+ FunctionSP func_sp = GetOrCreateFunction (*cu_sp);
344
+ if (func_sp && name == func_sp->GetNameNoArguments ()) {
345
+ SymbolContext sc;
346
+ sc.comp_unit = cu_sp.get ();
347
+ sc.function = func_sp.get ();
348
+ sc.module_sp = func_sp->CalculateSymbolContextModule ();
349
+ sc_list.Append (sc);
350
+ }
351
+ }
295
352
}
296
353
297
354
void SymbolFileBreakpad::FindFunctions (const RegularExpression ®ex,
@@ -346,11 +403,6 @@ void SymbolFileBreakpad::AddSymbols(Symtab &symtab) {
346
403
size.hasValue (), /* contains_linker_annotations*/ false , /* flags*/ 0 );
347
404
};
348
405
349
- for (llvm::StringRef line : lines (Record::Func)) {
350
- if (auto record = FuncRecord::parse (line))
351
- add_symbol (record->Address , record->Size , record->Name );
352
- }
353
-
354
406
for (llvm::StringRef line : lines (Record::Public)) {
355
407
if (auto record = PublicRecord::parse (line))
356
408
add_symbol (record->Address , llvm::None, record->Name );
0 commit comments