[Lldb-commits] [PATCH] D151859: [lldb/Target] Add ability to set a label to targets

Alex Langford via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Thu Jun 1 14:09:21 PDT 2023


bulbazord added a comment.

I feel a little strange about having `SBTarget::SetLabel` give a label to a target that is anything other than what the user specified. In the test, you attempt to name 2 targets `cat`. The first one succeeds, the second one also succeeds but names it `cat 2` (where 2 is the index of the target). I think we should probably give some kind of error instead of doing that.



================
Comment at: lldb/source/API/SBTarget.cpp:1614-1620
+const char *SBTarget::SetLabel(const char *label) {
+  LLDB_INSTRUMENT_VA(this, label);
+
+  llvm::StringRef label_ref(label);
+  size_t label_is_integral = LLDB_INVALID_INDEX32;
+  if (!label_ref.empty() && llvm::to_integer(label_ref, label_is_integral))
+    return nullptr;
----------------
What if this method returned an SBError that communicated the issue? Specifically, something like `target labels cannot be integral values` or something?

I see you doing that below in the lldb_private code.


================
Comment at: lldb/source/Target/Target.cpp:2546
+    if (target_sp && target_sp->GetLabel() == label) {
+        formatted_label << " " << targets.GetIndexOfTarget(shared_from_this());
+        break;
----------------
nit: I know I'm arguing against this implementation, but in case this does go in with this implementation, you can probably just use `i` instead of getting the index of the target again.


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

https://reviews.llvm.org/D151859



More information about the lldb-commits mailing list