[PATCH] D156978: [symbolizer][NFC] Move file argument parsing into separate function
Serge Pavlov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Aug 5 08:43:29 PDT 2023
sepavloff updated this revision to Diff 547491.
sepavloff added a comment.
Pass `Source` by reference in `getSpaceDelimitedWord`
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D156978/new/
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,11 +135,32 @@
HTTPClient::initialize();
}
+static StringRef getSpaceDelimitedWord(StringRef &Source) {
+ const char kDelimiters[] = " \n\r";
+ const char *Pos = Source.data();
+ StringRef Result;
+ Pos += strspn(Pos, kDelimiters);
+ if (*Pos == '"' || *Pos == '\'') {
+ char Quote = *Pos;
+ Pos++;
+ const char *End = strchr(Pos, Quote);
+ if (!End)
+ return StringRef();
+ Result = StringRef(Pos, End - Pos);
+ Pos = End + 1;
+ } else {
+ int NameLength = strcspn(Pos, kDelimiters);
+ Result = StringRef(Pos, NameLength);
+ Pos += NameLength;
+ }
+ Source = StringRef(Pos, Source.end() - Pos);
+ return Result;
+}
+
static bool parseCommand(StringRef BinaryName, bool IsAddr2Line,
StringRef InputString, Command &Cmd,
std::string &ModuleName, object::BuildID &BuildID,
uint64_t &ModuleOffset) {
- const char kDelimiters[] = " \n\r";
ModuleName = "";
if (InputString.consume_front("CODE ")) {
Cmd = Command::Code;
@@ -152,7 +173,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 +195,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;
- }
+ ModuleName = getSpaceDelimitedWord(InputString);
+ if (ModuleName.empty())
+ return false;
if (HasBuildIDPrefix) {
BuildID = parseBuildID(ModuleName);
if (BuildID.empty())
@@ -197,13 +205,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(" \n\r");
+ 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.547491.patch
Type: text/x-patch
Size: 2867 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230805/566d097c/attachment.bin>
More information about the llvm-commits
mailing list