[Lldb-commits] [lldb] [lldb] Use if-with-initializer pattern in SBTarget (NFC) (PR #141284)
Alex Langford via lldb-commits
lldb-commits at lists.llvm.org
Fri May 23 15:19:09 PDT 2025
================
@@ -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
More information about the lldb-commits
mailing list