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"
@@ -265,57 +264,8 @@ std::string InputFile::getSrcMsg(const Symbol &sym, InputSectionBase &sec,
265
264
}
266
265
267
266
template <class ELFT > void ObjFile<ELFT>::initializeDwarf() {
268
- dwarf = std::make_unique<DWARFContext>(std::make_unique<LLDDwarfObj<ELFT>>(this ));
269
- for (std::unique_ptr<DWARFUnit> &cu : dwarf->compile_units ()) {
270
- auto report = [](Error err) {
271
- handleAllErrors (std::move (err),
272
- [](ErrorInfoBase &info) { warn (info.message ()); });
273
- };
274
- Expected<const DWARFDebugLine::LineTable *> expectedLT =
275
- dwarf->getLineTableForUnit (cu.get (), report);
276
- const DWARFDebugLine::LineTable *lt = nullptr ;
277
- if (expectedLT)
278
- lt = *expectedLT;
279
- else
280
- report (expectedLT.takeError ());
281
- if (!lt)
282
- continue ;
283
- lineTables.push_back (lt);
284
-
285
- // Loop over variable records and insert them to variableLoc.
286
- for (const auto &entry : cu->dies ()) {
287
- DWARFDie die (cu.get (), &entry);
288
- // Skip all tags that are not variables.
289
- if (die.getTag () != dwarf::DW_TAG_variable)
290
- continue ;
291
-
292
- // Skip if a local variable because we don't need them for generating
293
- // error messages. In general, only non-local symbols can fail to be
294
- // linked.
295
- if (!dwarf::toUnsigned (die.find (dwarf::DW_AT_external), 0 ))
296
- continue ;
297
-
298
- // Get the source filename index for the variable.
299
- unsigned file = dwarf::toUnsigned (die.find (dwarf::DW_AT_decl_file), 0 );
300
- if (!lt->hasFileAtIndex (file))
301
- continue ;
302
-
303
- // Get the line number on which the variable is declared.
304
- unsigned line = dwarf::toUnsigned (die.find (dwarf::DW_AT_decl_line), 0 );
305
-
306
- // Here we want to take the variable name to add it into variableLoc.
307
- // Variable can have regular and linkage name associated. At first, we try
308
- // to get linkage name as it can be different, for example when we have
309
- // two variables in different namespaces of the same object. Use common
310
- // name otherwise, but handle the case when it also absent in case if the
311
- // input object file lacks some debug info.
312
- StringRef name =
313
- dwarf::toString (die.find (dwarf::DW_AT_linkage_name),
314
- dwarf::toString (die.find (dwarf::DW_AT_name), " " ));
315
- if (!name.empty ())
316
- variableLoc.insert ({name, {lt, file, line}});
317
- }
318
- }
267
+ dwarf = make<DWARFCache>(std::make_unique<DWARFContext>(
268
+ std::make_unique<LLDDwarfObj<ELFT>>(this )));
319
269
}
320
270
321
271
// Returns the pair of file name and line number describing location of data
@@ -325,19 +275,7 @@ Optional<std::pair<std::string, unsigned>>
325
275
ObjFile<ELFT>::getVariableLoc(StringRef name) {
326
276
llvm::call_once (initDwarfLine, [this ]() { initializeDwarf (); });
327
277
328
- // Return if we have no debug information about data object.
329
- auto it = variableLoc.find (name);
330
- if (it == variableLoc.end ())
331
- return None;
332
-
333
- // Take file name string from line table.
334
- std::string fileName;
335
- if (!it->second .lt ->getFileNameByIndex (
336
- it->second .file , {},
337
- DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath, fileName))
338
- return None;
339
-
340
- return std::make_pair (fileName, it->second .line );
278
+ return dwarf->getVariableLoc (name);
341
279
}
342
280
343
281
// Returns source line information for a given offset
@@ -359,14 +297,7 @@ Optional<DILineInfo> ObjFile<ELFT>::getDILineInfo(InputSectionBase *s,
359
297
360
298
// Use fake address calcuated by adding section file offset and offset in
361
299
// section. See comments for ObjectInfo class.
362
- DILineInfo info;
363
- for (const llvm::DWARFDebugLine::LineTable *lt : lineTables) {
364
- if (lt->getFileLineInfoForAddress (
365
- {s->getOffsetInFile () + offset, sectionIndex}, nullptr ,
366
- DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath, info))
367
- return info;
368
- }
369
- return None;
300
+ return dwarf->getDILineInfo (s->getOffsetInFile () + offset, sectionIndex);
370
301
}
371
302
372
303
ELFFileBase::ELFFileBase (Kind k, MemoryBufferRef mb) : InputFile(k, mb) {
0 commit comments