LLVM: lib/Object/BuildID.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
16
20
21using namespace llvm;
23
24namespace {
25
27 auto findBuildID = [&Obj](const auto &ShdrOrPhdr,
28 uint64_t Alignment) -> std::optional {
30 for (auto N : Obj.notes(ShdrOrPhdr, Err))
33 return N.getDesc(Alignment);
35 return std::nullopt;
36 };
37
39 for (const auto &S : Sections) {
41 continue;
42 if (std::optional ShdrRes = findBuildID(S, S.sh_addralign))
43 return ShdrRes.value();
44 }
45 auto PhdrsOrErr = Obj.program_headers();
46 if (!PhdrsOrErr) {
48 return {};
49 }
50 for (const auto &P : *PhdrsOrErr) {
52 continue;
53 if (std::optional PhdrRes = findBuildID(P, P.p_align))
54 return PhdrRes.value();
55 }
56 return {};
57}
58
59}
60
62 std::string Bytes;
64 return {};
66 Bytes.size());
68}
69
72 return ::getBuildID(O->getELFFile());
74 return ::getBuildID(O->getELFFile());
76 return ::getBuildID(O->getELFFile());
78 return ::getBuildID(O->getELFFile());
79 return {};
80}
81
83 auto GetDebugPath = [&](StringRef Directory) {
88 Path += ".debug";
89 return Path;
90 };
91 if (DebugFileDirectories.empty()) {
93#if defined(__NetBSD__)
94
95 "/usr/libdata/debug"
96#else
97
98 "/usr/lib/debug"
99#endif
100 );
102 return std::string(Path);
103 } else {
104 for (const auto &Directory : DebugFileDirectories) {
105
108 return std::string(Path);
109 }
110 }
111 return std::nullopt;
112}
This file declares a library for handling Build IDs and using them to find debug info.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
virtual std::optional< std::string > fetch(BuildIDRef BuildID) const
Returns the path to the debug file with the given build ID.
Definition BuildID.cpp:82
This class is the base class for all object file types.
constexpr const char * ELF_NOTE_GNU
SmallVector< uint8_t, 10 > BuildID
A build ID in binary form.
LLVM_ABI BuildIDRef getBuildID(const ObjectFile *Obj)
Returns the build ID, if any, contained in the given object file.
Definition BuildID.cpp:70
LLVM_ABI BuildID parseBuildID(StringRef Str)
Parses a build ID from a hex string.
Definition BuildID.cpp:61
ArrayRef< uint8_t > BuildIDRef
A reference to a BuildID in binary form.
LLVM_ABI bool exists(const basic_file_status &status)
Does file exist?
LLVM_ABI void append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast - Return the argument parameter cast to the specified type.
bool tryGetFromHex(StringRef Input, std::string &Output)
Convert hexadecimal string Input to its binary representation and store the result in Output....
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.
void toHex(ArrayRef< uint8_t > Input, bool LowerCase, SmallVectorImpl< char > &Output)
Convert buffer Input to its hexadecimal representation. The returned string is double the size of Inp...
void consumeError(Error Err)
Consume a Error without doing anything.