================
@@ -1219,45 +1191,42 @@ lldb::SBError 
SBTarget::BreakpointsCreateFromFile(SBFileSpec &source_file,
   LLDB_INSTRUMENT_VA(this, source_file, matching_names, new_bps);
 
   SBError sberr;
-  TargetSP target_sp(GetSP());
-  if (!target_sp) {
-    sberr.SetErrorString(
-        "BreakpointCreateFromFile called with invalid target.");
-    return sberr;
-  }
-  std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
+  if (TargetSP target_sp = GetSP()) {
+    std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
 
-  BreakpointIDList bp_ids;
+    BreakpointIDList bp_ids;
 
-  std::vector<std::string> name_vector;
-  size_t num_names = matching_names.GetSize();
-  for (size_t i = 0; i < num_names; i++)
-    name_vector.push_back(matching_names.GetStringAtIndex(i));
+    std::vector<std::string> name_vector;
+    size_t num_names = matching_names.GetSize();
+    for (size_t i = 0; i < num_names; i++)
+      name_vector.push_back(matching_names.GetStringAtIndex(i));
 
-  sberr.ref() = target_sp->CreateBreakpointsFromFile(source_file.ref(),
-                                                     name_vector, bp_ids);
-  if (sberr.Fail())
-    return sberr;
+    sberr.ref() = target_sp->CreateBreakpointsFromFile(source_file.ref(),
+                                                       name_vector, bp_ids);
+    if (sberr.Fail())
+      return sberr;
 
-  size_t num_bkpts = bp_ids.GetSize();
-  for (size_t i = 0; i < num_bkpts; i++) {
-    BreakpointID bp_id = bp_ids.GetBreakpointIDAtIndex(i);
-    new_bps.AppendByID(bp_id.GetBreakpointID());
+    size_t num_bkpts = bp_ids.GetSize();
+    for (size_t i = 0; i < num_bkpts; i++) {
+      BreakpointID bp_id = bp_ids.GetBreakpointIDAtIndex(i);
+      new_bps.AppendByID(bp_id.GetBreakpointID());
+    }
+    return sberr;
   }
+  sberr.SetErrorString("BreakpointCreateFromFile called with invalid target.");
----------------
bulbazord wrote:

Suggestion: Put the `SetErrorString` in an `else` clause and have both paths 
fall into the following `return sberr;`.

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

Reply via email to