================
@@ -26,3 +30,74 @@ Expression::Expression(ExecutionContextScope &exe_scope)
       m_jit_end_addr(LLDB_INVALID_ADDRESS) {
   assert(m_target_wp.lock());
 }
+
+/// Returns the components of the specified function call label.
+///
+/// The format of \c label is described in \c FunctionCallLabel.
+/// The label prefix is not one of the components.
+static llvm::Expected<llvm::SmallVector<llvm::StringRef, 3>>
+splitFunctionCallLabel(llvm::StringRef label) {
+  if (!label.consume_front(FunctionCallLabelPrefix))
+    return llvm::createStringError(
+        "expected function call label prefix not found.");
+  if (!label.consume_front(":"))
+    return llvm::createStringError(
+        "expected ':' as the first character after prefix.");
+
+  auto sep1 = label.find_first_of(":");
+  if (sep1 == llvm::StringRef::npos)
+    return llvm::createStringError("no ':' separator found.");
+
+  auto sep2 = label.find_first_of(":", sep1 + 1);
+  if (sep2 == llvm::StringRef::npos)
+    return llvm::createStringError("only single ':' separator found.");
+
+  llvm::SmallVector<llvm::StringRef, 3> components;
+  components.push_back(label.slice(0, sep1));
+  components.push_back(label.slice(sep1 + 1, sep2));
+  components.push_back(label.slice(sep2 + 1, llvm::StringRef::npos));
+
+  return components;
+}
+
+llvm::Expected<FunctionCallLabel>
+lldb_private::FunctionCallLabel::fromString(llvm::StringRef label) {
+  auto components_or_err = splitFunctionCallLabel(label);
+  if (!components_or_err)
+    return llvm::joinErrors(
+        llvm::createStringError("failed to split function call label '%s'",
+                                label.data()),
+        components_or_err.takeError());
+
+  const auto &components = *components_or_err;
+
+  llvm::StringRef module_label = components[0];
+  llvm::StringRef die_label = components[1];
+
+  lldb::user_id_t module_id = 0;
+  if (module_label.consumeInteger(0, module_id))
----------------
labath wrote:

```suggestion
  if (!llvm::to_integer(module_label, module_id))
```

.. because you probably don't want to ignore trailing garbage.

https://github.com/llvm/llvm-project/pull/148877
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to