Changeset View
Changeset View
Standalone View
Standalone View
llvm/lib/ObjectYAML/DWARFYAML.cpp
//===- DWARFYAML.cpp - DWARF YAMLIO implementation ------------------------===// | //===- DWARFYAML.cpp - DWARF YAMLIO implementation ------------------------===// | ||||
// | // | ||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||||
// See https://llvm.org/LICENSE.txt for license information. | // See https://llvm.org/LICENSE.txt for license information. | ||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||||
// | // | ||||
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||
// | // | ||||
// This file defines classes for handling the YAML representation of DWARF Debug | // This file defines classes for handling the YAML representation of DWARF Debug | ||||
// Info. | // Info. | ||||
// | // | ||||
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||
#include "llvm/ObjectYAML/DWARFYAML.h" | #include "llvm/ObjectYAML/DWARFYAML.h" | ||||
#include "llvm/BinaryFormat/Dwarf.h" | #include "llvm/BinaryFormat/Dwarf.h" | ||||
#include "llvm/Support/Errc.h" | |||||
#include "llvm/Support/Error.h" | |||||
namespace llvm { | namespace llvm { | ||||
bool DWARFYAML::Data::isEmpty() const { | bool DWARFYAML::Data::isEmpty() const { | ||||
return getNonEmptySectionNames().empty(); | return getNonEmptySectionNames().empty(); | ||||
} | } | ||||
SetVector<StringRef> DWARFYAML::Data::getNonEmptySectionNames() const { | SetVector<StringRef> DWARFYAML::Data::getNonEmptySectionNames() const { | ||||
Show All 24 Lines | if (DebugStrOffsets) | ||||
SecNames.insert("debug_str_offsets"); | SecNames.insert("debug_str_offsets"); | ||||
if (DebugRnglists) | if (DebugRnglists) | ||||
SecNames.insert("debug_rnglists"); | SecNames.insert("debug_rnglists"); | ||||
if (DebugLoclists) | if (DebugLoclists) | ||||
SecNames.insert("debug_loclists"); | SecNames.insert("debug_loclists"); | ||||
return SecNames; | return SecNames; | ||||
} | } | ||||
Expected<uint64_t> DWARFYAML::Data::getAbbrevTableIndexByID(uint64_t ID) { | |||||
if (AbbrevTableID2Index.empty()) { | |||||
for (auto &AbbrevTable : enumerate(DebugAbbrev)) { | |||||
// If the abbrev table's ID isn't specified, we use the index as its ID. | |||||
uint64_t AbbrevTableID = | |||||
AbbrevTable.value().ID.getValueOr(AbbrevTable.index()); | |||||
auto It = | |||||
AbbrevTableID2Index.insert({AbbrevTableID, AbbrevTable.index()}); | |||||
if (!It.second) | |||||
return createStringError( | |||||
errc::invalid_argument, | |||||
"the ID (%" PRIu64 ") of abbrev table with index %" PRIu64 | |||||
Higuoxing: The build failure is caused by the incorrect format string. `AbbrevTable.index()` returns… | |||||
" has been used by abbrev table with index %" PRIu64, | |||||
AbbrevTableID, AbbrevTable.index(), It.first->second); | |||||
} | |||||
} | |||||
auto It = AbbrevTableID2Index.find(ID); | |||||
if (It == AbbrevTableID2Index.end()) | |||||
return createStringError(errc::invalid_argument, | |||||
"cannot find abbrev table whose ID is %" PRIu64, | |||||
ID); | |||||
return It->second; | |||||
} | |||||
namespace yaml { | namespace yaml { | ||||
void MappingTraits<DWARFYAML::Data>::mapping(IO &IO, DWARFYAML::Data &DWARF) { | void MappingTraits<DWARFYAML::Data>::mapping(IO &IO, DWARFYAML::Data &DWARF) { | ||||
void *OldContext = IO.getContext(); | void *OldContext = IO.getContext(); | ||||
DWARFYAML::DWARFContext DWARFCtx; | DWARFYAML::DWARFContext DWARFCtx; | ||||
IO.setContext(&DWARFCtx); | IO.setContext(&DWARFCtx); | ||||
IO.mapOptional("debug_str", DWARF.DebugStrings); | IO.mapOptional("debug_str", DWARF.DebugStrings); | ||||
IO.mapOptional("debug_abbrev", DWARF.DebugAbbrev); | IO.mapOptional("debug_abbrev", DWARF.DebugAbbrev); | ||||
Show All 11 Lines | void MappingTraits<DWARFYAML::Data>::mapping(IO &IO, DWARFYAML::Data &DWARF) { | ||||
IO.mapOptional("debug_str_offsets", DWARF.DebugStrOffsets); | IO.mapOptional("debug_str_offsets", DWARF.DebugStrOffsets); | ||||
IO.mapOptional("debug_rnglists", DWARF.DebugRnglists); | IO.mapOptional("debug_rnglists", DWARF.DebugRnglists); | ||||
IO.mapOptional("debug_loclists", DWARF.DebugLoclists); | IO.mapOptional("debug_loclists", DWARF.DebugLoclists); | ||||
IO.setContext(OldContext); | IO.setContext(OldContext); | ||||
} | } | ||||
void MappingTraits<DWARFYAML::AbbrevTable>::mapping( | void MappingTraits<DWARFYAML::AbbrevTable>::mapping( | ||||
IO &IO, DWARFYAML::AbbrevTable &AbbrevTable) { | IO &IO, DWARFYAML::AbbrevTable &AbbrevTable) { | ||||
IO.mapOptional("ID", AbbrevTable.ID); | |||||
IO.mapOptional("Table", AbbrevTable.Table); | IO.mapOptional("Table", AbbrevTable.Table); | ||||
} | } | ||||
void MappingTraits<DWARFYAML::Abbrev>::mapping(IO &IO, | void MappingTraits<DWARFYAML::Abbrev>::mapping(IO &IO, | ||||
DWARFYAML::Abbrev &Abbrev) { | DWARFYAML::Abbrev &Abbrev) { | ||||
IO.mapOptional("Code", Abbrev.Code); | IO.mapOptional("Code", Abbrev.Code); | ||||
IO.mapRequired("Tag", Abbrev.Tag); | IO.mapRequired("Tag", Abbrev.Tag); | ||||
IO.mapRequired("Children", Abbrev.Children); | IO.mapRequired("Children", Abbrev.Children); | ||||
▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
void MappingTraits<DWARFYAML::Unit>::mapping(IO &IO, DWARFYAML::Unit &Unit) { | void MappingTraits<DWARFYAML::Unit>::mapping(IO &IO, DWARFYAML::Unit &Unit) { | ||||
IO.mapOptional("Format", Unit.Format, dwarf::DWARF32); | IO.mapOptional("Format", Unit.Format, dwarf::DWARF32); | ||||
IO.mapOptional("Length", Unit.Length); | IO.mapOptional("Length", Unit.Length); | ||||
IO.mapRequired("Version", Unit.Version); | IO.mapRequired("Version", Unit.Version); | ||||
if (Unit.Version >= 5) | if (Unit.Version >= 5) | ||||
IO.mapRequired("UnitType", Unit.Type); | IO.mapRequired("UnitType", Unit.Type); | ||||
IO.mapOptional("AbbrevTableID", Unit.AbbrevTableID); | |||||
IO.mapRequired("AbbrOffset", Unit.AbbrOffset); | IO.mapRequired("AbbrOffset", Unit.AbbrOffset); | ||||
IO.mapOptional("AddrSize", Unit.AddrSize); | IO.mapOptional("AddrSize", Unit.AddrSize); | ||||
IO.mapOptional("Entries", Unit.Entries); | IO.mapOptional("Entries", Unit.Entries); | ||||
} | } | ||||
void MappingTraits<DWARFYAML::Entry>::mapping(IO &IO, DWARFYAML::Entry &Entry) { | void MappingTraits<DWARFYAML::Entry>::mapping(IO &IO, DWARFYAML::Entry &Entry) { | ||||
IO.mapRequired("AbbrCode", Entry.AbbrCode); | IO.mapRequired("AbbrCode", Entry.AbbrCode); | ||||
IO.mapOptional("Values", Entry.Values); | IO.mapOptional("Values", Entry.Values); | ||||
▲ Show 20 Lines • Show All 132 Lines • Show Last 20 Lines |
The build failure is caused by the incorrect format string. AbbrevTable.index() returns size_t and it was formatted as %u. We should use %zu here.