aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools/llvm-objdump/llvm-objdump.cpp
diff options
context:
space:
mode:
authorDaniel Thornburgh <dthorn@google.com>2022-09-20 10:51:14 -0700
committerDaniel Thornburgh <dthorn@google.com>2022-10-04 13:44:25 -0700
commit2e91a5f546ad0d934e9619222983efe230b344b6 (patch)
tree799c51484409bfcce329dd870ac562a2d9e6dfa5 /llvm/tools/llvm-objdump/llvm-objdump.cpp
parent3d4f1169563e3aa9e7fce3c6d8445adf8256a142 (diff)
downloadllvm-2e91a5f546ad0d934e9619222983efe230b344b6.zip
llvm-2e91a5f546ad0d934e9619222983efe230b344b6.tar.gz
llvm-2e91a5f546ad0d934e9619222983efe230b344b6.tar.bz2
[llvm-objdump] Add --build-id flag for debuginfod lookups without binary.
Adding a --build-id flag allows handling binaries that are referenced in logs from remote systems, but that aren't necessarily present on the local machine. These are fetched via debuginfod and handled as if they were input filenames. Reviewed By: jhenderson, MaskRay Differential Revision: https://reviews.llvm.org/D133992
Diffstat (limited to 'llvm/tools/llvm-objdump/llvm-objdump.cpp')
-rw-r--r--llvm/tools/llvm-objdump/llvm-objdump.cpp27
1 files changed, 25 insertions, 2 deletions
diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp
index 689aa0a..f7d6666d 100644
--- a/llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp
@@ -2916,6 +2916,17 @@ 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))
+ 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());
+}
+
static void invalidArgValue(const opt::Arg *A) {
reportCmdLineError("'" + StringRef(A->getValue()) +
"' is not a valid value for '" + A->getSpelling() + "'");
@@ -3084,6 +3095,17 @@ static void parseObjdumpOptions(const llvm::opt::InputArgList &InputArgs) {
llvm::cl::ParseCommandLineOptions(2, Argv);
}
+ // Look up any provided build IDs, then append them to the input filenames.
+ for (const opt::Arg *A : InputArgs.filtered(OBJDUMP_build_id)) {
+ object::BuildID BuildID = parseBuildIDArg(A);
+ Optional<std::string> Path = BIDFetcher->fetch(BuildID);
+ if (!Path) {
+ reportCmdLineError(A->getSpelling() + ": could not find build ID '" +
+ A->getValue() + "'");
+ }
+ InputFilenames.push_back(std::move(*Path));
+ }
+
// objdump defaults to a.out if no filenames specified.
if (InputFilenames.empty())
InputFilenames.push_back("a.out");
@@ -3153,8 +3175,9 @@ int main(int argc, char **argv) {
// Initialize debuginfod.
const bool ShouldUseDebuginfodByDefault =
- HTTPClient::isAvailable() &&
- !ExitOnErr(getDefaultDebuginfodUrls()).empty();
+ InputArgs.hasArg(OBJDUMP_build_id) ||
+ (HTTPClient::isAvailable() &&
+ !ExitOnErr(getDefaultDebuginfodUrls()).empty());
std::vector<std::string> DebugFileDirectories =
InputArgs.getAllArgValues(OBJDUMP_debug_file_directory);
if (InputArgs.hasFlag(OBJDUMP_debuginfod, OBJDUMP_no_debuginfod,