[lld] [lld][ELF] Add --debug-names to create merged .debug_names. (PR #86508)
David Blaikie via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 18 08:54:09 PDT 2024
================
@@ -2782,83 +2866,23 @@ void DebugNamesBaseSection::parseDebugNames(
ne.hashValue = caseFoldingDjbHash(name);
// Read a series of index entries that end with abbreviation code 0.
- const char *errMsg = nullptr;
+ std::string errMsg;
uint64_t offset = locs.EntriesBase + entryOffsets[i];
while (offset < namesSec.Data.size() && namesSec.Data[offset] != 0) {
// Read & store all entries (for the same string).
- auto ie = makeThreadLocal<IndexEntry>();
- ie->poolOffset = offset;
- Error err = Error::success();
- ie->abbrevCode =
- static_cast<uint32_t>(namesExtractor.getULEB128(&offset, &err));
- if (err) {
- consumeError(std::move(err));
- errMsg = ": invalid abbrev code in entry";
- break;
+ Expected<IndexEntry *> ieOrErr =
+ readEntry(offset, ni, locs.EntriesBase, namesExtractor, namesSec);
+ if (!ieOrErr) {
+ errorOrWarn(toString(namesSec.sec) +
+ Twine(toString(ieOrErr.takeError())));
+ return;
}
- auto it = ni.getAbbrevs().find_as(ie->abbrevCode);
- if (it == ni.getAbbrevs().end()) {
- errMsg = ": invalid abbrev code in entry";
- break;
- }
-
- AttrValue attr, cuAttr = {0, 0};
- for (DWARFDebugNames::AttributeEncoding a : it->Attributes) {
- if (a.Index == dwarf::DW_IDX_parent) {
- if (a.Form == dwarf::DW_FORM_ref4) {
- attr.attrValue = namesExtractor.getU32(&offset, &err);
- attr.attrSize = 4;
- ie->parentOffset = locs.EntriesBase + attr.attrValue;
- } else if (a.Form != DW_FORM_flag_present) {
- errMsg = ": invalid form for DW_IDX_parent";
- }
- } else {
- switch (a.Form) {
- case DW_FORM_data1:
- case DW_FORM_ref1: {
- attr.attrValue = namesExtractor.getU8(&offset, &err);
- attr.attrSize = 1;
- break;
- }
- case DW_FORM_data2:
- case DW_FORM_ref2: {
- attr.attrValue = namesExtractor.getU16(&offset, &err);
- attr.attrSize = 2;
- break;
- }
- case DW_FORM_data4:
- case DW_FORM_ref4: {
- attr.attrValue = namesExtractor.getU32(&offset, &err);
- attr.attrSize = 4;
- break;
- }
- default:
- errorOrWarn(toString(namesSec.sec) +
- Twine(": unrecognized form encoding ") +
- Twine(a.Form) + Twine(" in abbrev table"));
- return;
- }
- }
- if (err) {
- errorOrWarn(toString(namesSec.sec) +
- Twine(": error while reading attributes: ") +
- toString(std::move(err)));
- return;
- }
- if (a.Index == DW_IDX_compile_unit)
- cuAttr = attr;
- else if (a.Form != DW_FORM_flag_present)
- ie->attrValues.push_back(attr);
- }
-
- // Canonicalize abbrev by placing the CU/TU index at the end.
- ie->attrValues.push_back(cuAttr);
- ne.indexEntries.push_back(std::move(ie));
+ ne.indexEntries.push_back(std::move(*ieOrErr));
}
if (offset >= namesSec.Data.size())
errMsg = ": index entry is out of bounds";
- if (errMsg)
- errorOrWarn(toString(namesSec.sec) + Twine(errMsg));
+ if (!errMsg.empty())
+ errorOrWarn(toString(namesSec.sec) + Twine(errMsg.c_str()));
----------------
dwblaikie wrote:
drop `errMsg` here (& remove its declaration above) - since it's only used in this immediate scope, simplify this code to:
```
if (offset >= namesSec.Data.size())
errorOrWarn(toString(namesSec.sec) + ": index entry is out of bounds");
```
https://github.com/llvm/llvm-project/pull/86508
More information about the llvm-commits
mailing list