[PATCH] D157203: [symbolizer][NFC] Reorganize parsing input binary file

Serge Pavlov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 10 23:27:51 PDT 2023


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7afd3a398922: [symbolizer][NFC] Reorganize parsing input binary file (authored by sepavloff).

Changed prior to commit:
  https://reviews.llvm.org/D157203?vs=547530&id=549254#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157203/new/

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
@@ -153,7 +153,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 ")) {
@@ -165,39 +165,51 @@
     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.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D157203.549254.patch
Type: text/x-patch
Size: 3109 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230811/beaa3625/attachment.bin>


More information about the llvm-commits mailing list