[PATCH] D157203: [symbolizer][NFC] Reorganize parsing input binary file
Serge Pavlov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Aug 6 01:36:36 PDT 2023
sepavloff created this revision.
sepavloff added reviewers: jhenderson, dblaikie, mysterymath, MaskRay, ikudrin.
Herald added a project: All.
sepavloff requested review of this revision.
Herald added a project: LLVM.
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.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D157203
Files:
llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp
Index: llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp
===================================================================
--- llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp
+++ llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp
@@ -161,7 +161,7 @@
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 ")) {
@@ -173,39 +173,53 @@
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 is already seen.
+ return false;
+ HasFilePrefix = true;
+ continue;
+ }
+ if (InputString.consume_front("BUILDID:")) {
+ if (HasBuildIDPrefix || HasFilePrefix)
+ // Input file specification prefix is already seen.
+ return false;
+ HasBuildIDPrefix = true;
+ continue;
}
- if (HasFilePrefix && HasBuildIDPrefix)
+ break;
+ }
+ if (HasBuildIDPrefix || HasFilePrefix) {
+ if (!BinaryName.empty() || !BuildID.empty())
+ // Input file is already specified in command line.
return false;
-
- ModuleName = getSpaceDelimitedWord(InputString);
- if (ModuleName.empty())
+ 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();
+ if (BinaryName.empty() && BuildID.empty()) {
+ // No input file is specified. If the input string contains at least two
+ // items, assume that the first item is a file name.
+ StringRef Name = getSpaceDelimitedWord(InputString);
+ if (Name.empty() || InputString.empty())
+ // No input filename is specified.
+ return false;
+ ModuleName = Name;
+ }
}
// Skip delimiters and parse module offset.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D157203.547530.patch
Type: text/x-patch
Size: 3092 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230806/889c30f8/attachment.bin>
More information about the llvm-commits
mailing list