[PATCH] D156978: [symbolizer][NFC] Move file argument parsing into separate function
Serge Pavlov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 3 02:40:34 PDT 2023
sepavloff created this revision.
sepavloff added reviewers: jhenderson, dblaikie, MaskRay, ikudrin.
Herald added a project: All.
sepavloff requested review of this revision.
Herald added a project: LLVM.
The code that gets binary file name is moved to a separate function.
It makes the code of `parseCommand` cleaner and allows to reuse the
parsing code.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D156978
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
@@ -135,6 +135,28 @@
HTTPClient::initialize();
}
+static std::pair<std::string, StringRef>
+getSpaceDelimitedWord(StringRef Source) {
+ const char kDelimiters[] = " \n\r";
+ const char *Pos = Source.data();
+ std::string Result;
+ Pos += strspn(Pos, kDelimiters);
+ if (*Pos == '"' || *Pos == '\'') {
+ char Quote = *Pos;
+ Pos++;
+ const char *End = strchr(Pos, Quote);
+ if (!End)
+ return std::make_pair(Result, Source);
+ Result = std::string(Pos, End - Pos);
+ Pos = End + 1;
+ } else {
+ int NameLength = strcspn(Pos, kDelimiters);
+ Result = std::string(Pos, NameLength);
+ Pos += NameLength;
+ }
+ return std::make_pair(Result, StringRef(Pos, Source.end() - Pos));
+}
+
static bool parseCommand(StringRef BinaryName, bool IsAddr2Line,
StringRef InputString, Command &Cmd,
std::string &ModuleName, object::BuildID &BuildID,
@@ -152,7 +174,6 @@
Cmd = Command::Code;
}
- const char *Pos;
// Skip delimiters and parse input filename (if needed).
if (BinaryName.empty() && BuildID.empty()) {
bool HasFilePrefix = false;
@@ -175,21 +196,9 @@
if (HasFilePrefix && HasBuildIDPrefix)
return false;
- Pos = InputString.data();
- Pos += strspn(Pos, kDelimiters);
- if (*Pos == '"' || *Pos == '\'') {
- char Quote = *Pos;
- Pos++;
- const char *End = strchr(Pos, Quote);
- if (!End)
- return false;
- ModuleName = std::string(Pos, End - Pos);
- Pos = End + 1;
- } else {
- int NameLength = strcspn(Pos, kDelimiters);
- ModuleName = std::string(Pos, NameLength);
- Pos += NameLength;
- }
+ std::tie(ModuleName, InputString) = getSpaceDelimitedWord(InputString);
+ if (ModuleName.empty())
+ return false;
if (HasBuildIDPrefix) {
BuildID = parseBuildID(ModuleName);
if (BuildID.empty())
@@ -197,13 +206,13 @@
ModuleName.clear();
}
} else {
- Pos = InputString.data();
ModuleName = BinaryName.str();
}
+
// Skip delimiters and parse module offset.
- Pos += strspn(Pos, kDelimiters);
- int OffsetLength = strcspn(Pos, kDelimiters);
- StringRef Offset(Pos, OffsetLength);
+ InputString = InputString.ltrim();
+ int OffsetLength = InputString.find_first_of(kDelimiters);
+ StringRef Offset = InputString.substr(0, OffsetLength);
// GNU addr2line assumes the offset is hexadecimal and allows a redundant
// "0x" or "0X" prefix; do the same for compatibility.
if (IsAddr2Line)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D156978.546771.patch
Type: text/x-patch
Size: 2764 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230803/24c83099/attachment.bin>
More information about the llvm-commits
mailing list