17
17
#include " lld/Common/Memory.h"
18
18
#include " llvm/ADT/STLExtras.h"
19
19
#include " llvm/CodeGen/Analysis.h"
20
- #include " llvm/DebugInfo/DWARF/DWARFContext.h"
21
20
#include " llvm/IR/LLVMContext.h"
22
21
#include " llvm/IR/Module.h"
23
22
#include " llvm/LTO/LTO.h"
@@ -252,57 +251,8 @@ std::string InputFile::getSrcMsg(const Symbol &Sym, InputSectionBase &Sec,
252
251
}
253
252
254
253
template <class ELFT > void ObjFile<ELFT>::initializeDwarf() {
255
- Dwarf = llvm::make_unique<DWARFContext>(make_unique<LLDDwarfObj<ELFT>>(this ));
256
- for (std::unique_ptr<DWARFUnit> &CU : Dwarf->compile_units ()) {
257
- auto Report = [](Error Err) {
258
- handleAllErrors (std::move (Err),
259
- [](ErrorInfoBase &Info) { warn (Info.message ()); });
260
- };
261
- Expected<const DWARFDebugLine::LineTable *> ExpectedLT =
262
- Dwarf->getLineTableForUnit (CU.get (), Report);
263
- const DWARFDebugLine::LineTable *LT = nullptr ;
264
- if (ExpectedLT)
265
- LT = *ExpectedLT;
266
- else
267
- Report (ExpectedLT.takeError ());
268
- if (!LT)
269
- continue ;
270
- LineTables.push_back (LT);
271
-
272
- // Loop over variable records and insert them to VariableLoc.
273
- for (const auto &Entry : CU->dies ()) {
274
- DWARFDie Die (CU.get (), &Entry);
275
- // Skip all tags that are not variables.
276
- if (Die.getTag () != dwarf::DW_TAG_variable)
277
- continue ;
278
-
279
- // Skip if a local variable because we don't need them for generating
280
- // error messages. In general, only non-local symbols can fail to be
281
- // linked.
282
- if (!dwarf::toUnsigned (Die.find (dwarf::DW_AT_external), 0 ))
283
- continue ;
284
-
285
- // Get the source filename index for the variable.
286
- unsigned File = dwarf::toUnsigned (Die.find (dwarf::DW_AT_decl_file), 0 );
287
- if (!LT->hasFileAtIndex (File))
288
- continue ;
289
-
290
- // Get the line number on which the variable is declared.
291
- unsigned Line = dwarf::toUnsigned (Die.find (dwarf::DW_AT_decl_line), 0 );
292
-
293
- // Here we want to take the variable name to add it into VariableLoc.
294
- // Variable can have regular and linkage name associated. At first, we try
295
- // to get linkage name as it can be different, for example when we have
296
- // two variables in different namespaces of the same object. Use common
297
- // name otherwise, but handle the case when it also absent in case if the
298
- // input object file lacks some debug info.
299
- StringRef Name =
300
- dwarf::toString (Die.find (dwarf::DW_AT_linkage_name),
301
- dwarf::toString (Die.find (dwarf::DW_AT_name), " " ));
302
- if (!Name.empty ())
303
- VariableLoc.insert ({Name, {LT, File, Line}});
304
- }
305
- }
254
+ dwarf = make<DWARFCache>(std::make_unique<DWARFContext>(
255
+ std::make_unique<LLDDwarfObj<ELFT>>(this )));
306
256
}
307
257
308
258
// Returns the pair of file name and line number describing location of data
@@ -312,19 +262,7 @@ Optional<std::pair<std::string, unsigned>>
312
262
ObjFile<ELFT>::getVariableLoc(StringRef Name) {
313
263
llvm::call_once (InitDwarfLine, [this ]() { initializeDwarf (); });
314
264
315
- // Return if we have no debug information about data object.
316
- auto It = VariableLoc.find (Name);
317
- if (It == VariableLoc.end ())
318
- return None;
319
-
320
- // Take file name string from line table.
321
- std::string FileName;
322
- if (!It->second .LT ->getFileNameByIndex (
323
- It->second .File , nullptr ,
324
- DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath, FileName))
325
- return None;
326
-
327
- return std::make_pair (FileName, It->second .Line );
265
+ return dwarf->getVariableLoc (Name);
328
266
}
329
267
330
268
// Returns source line information for a given offset
@@ -346,14 +284,7 @@ Optional<DILineInfo> ObjFile<ELFT>::getDILineInfo(InputSectionBase *S,
346
284
347
285
// Use fake address calcuated by adding section file offset and offset in
348
286
// section. See comments for ObjectInfo class.
349
- DILineInfo Info;
350
- for (const llvm::DWARFDebugLine::LineTable *LT : LineTables) {
351
- if (LT->getFileLineInfoForAddress (
352
- {S->getOffsetInFile () + Offset, SectionIndex}, nullptr ,
353
- DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath, Info))
354
- return Info;
355
- }
356
- return None;
287
+ return dwarf->getDILineInfo (S->getOffsetInFile () + Offset, SectionIndex);
357
288
}
358
289
359
290
// Returns "<internal>", "foo.a(bar.o)" or "baz.o".
0 commit comments