[llvm] 7afd3a3 - [symbolizer][NFC] Reorganize parsing input binary file
Serge Pavlov via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 10 23:27:44 PDT 2023
Author: Serge Pavlov
Date: 2023-08-11T13:26:09+07:00
New Revision: 7afd3a398922d6c44cca7bc112ff7cf1d2431135
URL: https://github.com/llvm/llvm-project/commit/7afd3a398922d6c44cca7bc112ff7cf1d2431135
DIFF: https://github.com/llvm/llvm-project/commit/7afd3a398922d6c44cca7bc112ff7cf1d2431135.diff
LOG: [symbolizer][NFC] Reorganize parsing input binary file
Now llvm-symbolizer prints input string if parsing command failed,
whithout explanation that is wrong. As a first step in making the
interface more user-friendly, this change reorganize parsing so that
generation of messages becomes easier.
Differential Revision: https://reviews.llvm.org/D157203
Added:
Modified:
llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp
Removed:
################################################################################
diff --git a/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp b/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp
index ba9df51d5a5865..4d9a7edd3dfa14 100644
--- a/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp
+++ b/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp
@@ -153,7 +153,7 @@ static bool parseCommand(StringRef BinaryName, bool IsAddr2Line,
StringRef InputString, Command &Cmd,
std::string &ModuleName, object::BuildID &BuildID,
uint64_t &ModuleOffset) {
- ModuleName = "";
+ ModuleName = BinaryName;
if (InputString.consume_front("CODE ")) {
Cmd = Command::Code;
} else if (InputString.consume_front("DATA ")) {
@@ -165,39 +165,51 @@ static bool parseCommand(StringRef BinaryName, bool IsAddr2Line,
Cmd = Command::Code;
}
- // Skip delimiters and parse input filename (if needed).
- if (BinaryName.empty() && BuildID.empty()) {
- bool HasFilePrefix = false;
- bool HasBuildIDPrefix = false;
- while (true) {
- if (InputString.consume_front("FILE:")) {
- if (HasFilePrefix)
- return false;
- HasFilePrefix = true;
- continue;
- }
- if (InputString.consume_front("BUILDID:")) {
- if (HasBuildIDPrefix)
- return false;
- HasBuildIDPrefix = true;
- continue;
- }
- break;
+ // Parse optional input file specification.
+ bool HasFilePrefix = false;
+ bool HasBuildIDPrefix = false;
+ while (!InputString.empty()) {
+ InputString = InputString.ltrim();
+ if (InputString.consume_front("FILE:")) {
+ if (HasFilePrefix || HasBuildIDPrefix)
+ // Input file specification prefix has already been seen.
+ return false;
+ HasFilePrefix = true;
+ continue;
}
- if (HasFilePrefix && HasBuildIDPrefix)
- return false;
+ if (InputString.consume_front("BUILDID:")) {
+ if (HasBuildIDPrefix || HasFilePrefix)
+ // Input file specification prefix has already been seen.
+ return false;
+ HasBuildIDPrefix = true;
+ continue;
+ }
+ break;
+ }
- ModuleName = getSpaceDelimitedWord(InputString);
- if (ModuleName.empty())
+ if (HasBuildIDPrefix || HasFilePrefix) {
+ if (!BinaryName.empty() || !BuildID.empty())
+ // Input file has already been specified on the command line.
+ return false;
+ StringRef Name = getSpaceDelimitedWord(InputString);
+ if (Name.empty())
+ // Wrong name for module file.
return false;
if (HasBuildIDPrefix) {
- BuildID = parseBuildID(ModuleName);
+ BuildID = parseBuildID(Name);
if (BuildID.empty())
+ // Wrong format of BuildID hash.
return false;
- ModuleName.clear();
+ } else {
+ ModuleName = Name;
}
- } else {
- ModuleName = BinaryName.str();
+ } else if (BinaryName.empty() && BuildID.empty()) {
+ // No input file has been specified. If the input string contains at least
+ // two items, assume that the first item is a file name.
+ ModuleName = getSpaceDelimitedWord(InputString);
+ if (ModuleName.empty() || InputString.empty())
+ // No input filename has been specified.
+ return false;
}
// Skip delimiters and parse module offset.
More information about the llvm-commits
mailing list