diff options
author | Daniel Thornburgh <dthorn@google.com> | 2023-04-03 11:15:31 -0700 |
---|---|---|
committer | Daniel Thornburgh <dthorn@google.com> | 2023-04-05 11:25:26 -0700 |
commit | 9812948d22328e6f810c7654b93b063ce97ecfec (patch) | |
tree | 2282e12214e44bd1e68e87943e0d08a5aae0e534 /llvm/tools/llvm-objdump/llvm-objdump.cpp | |
parent | e289b53f4d9bffd71613d6f91747bf9bda0ae352 (diff) | |
download | llvm-9812948d22328e6f810c7654b93b063ce97ecfec.zip llvm-9812948d22328e6f810c7654b93b063ce97ecfec.tar.gz llvm-9812948d22328e6f810c7654b93b063ce97ecfec.tar.bz2 |
[Object] Refactor build ID parsing into Object lib.
This makes parsing for build IDs in the markup filter slightly more
permissive, in line with fromHex.
It also removes the distinction between missing build ID and empty build
ID; empty build IDs aren't a useful concept, since their purpose is to
uniquely identify a binary. This removes a layer of indirection wherever
build IDs are obtained.
Reviewed By: jhenderson
Differential Revision: https://reviews.llvm.org/D147485
Diffstat (limited to 'llvm/tools/llvm-objdump/llvm-objdump.cpp')
-rw-r--r-- | llvm/tools/llvm-objdump/llvm-objdump.cpp | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp index e3d1419..5abcdcc 100644 --- a/llvm/tools/llvm-objdump/llvm-objdump.cpp +++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp @@ -1285,10 +1285,10 @@ static void createFakeELFSections(ObjectFile &Obj) { // Build ID. Returns std::nullopt if nothing was found. static std::optional<OwningBinary<Binary>> fetchBinaryByBuildID(const ObjectFile &Obj) { - std::optional<object::BuildIDRef> BuildID = getBuildID(&Obj); - if (!BuildID) + object::BuildIDRef BuildID = getBuildID(&Obj); + if (BuildID.empty()) return std::nullopt; - std::optional<std::string> Path = BIDFetcher->fetch(*BuildID); + std::optional<std::string> Path = BIDFetcher->fetch(BuildID); if (!Path) return std::nullopt; Expected<OwningBinary<Binary>> DebugBinary = createBinary(*Path); @@ -2943,13 +2943,11 @@ static void parseIntArg(const llvm::opt::InputArgList &InputArgs, int ID, static object::BuildID parseBuildIDArg(const opt::Arg *A) { StringRef V(A->getValue()); - std::string Bytes; - if (!tryGetFromHex(V, Bytes)) + object::BuildID BID = parseBuildID(V); + if (BID.empty()) reportCmdLineError(A->getSpelling() + ": expected a build ID, but got '" + V + "'"); - ArrayRef<uint8_t> BuildID(reinterpret_cast<const uint8_t *>(Bytes.data()), - Bytes.size()); - return object::BuildID(BuildID.begin(), BuildID.end()); + return BID; } void objdump::invalidArgValue(const opt::Arg *A) { |