[Lldb-commits] [lldb] [lldb] Use if-with-initializer pattern in SBTarget (NFC) (PR #141284)
Pavel Labath via lldb-commits
lldb-commits at lists.llvm.org
Wed May 28 00:18:18 PDT 2025
================
@@ -1355,29 +1312,30 @@ SBTarget::WatchpointCreateByAddress(lldb::addr_t addr, size_t size,
SBWatchpoint sb_watchpoint;
lldb::WatchpointSP watchpoint_sp;
- TargetSP target_sp(GetSP());
- uint32_t watch_type = 0;
- if (options.GetWatchpointTypeRead())
- watch_type |= LLDB_WATCH_TYPE_READ;
- if (options.GetWatchpointTypeWrite() == eWatchpointWriteTypeAlways)
- watch_type |= LLDB_WATCH_TYPE_WRITE;
- if (options.GetWatchpointTypeWrite() == eWatchpointWriteTypeOnModify)
- watch_type |= LLDB_WATCH_TYPE_MODIFY;
- if (watch_type == 0) {
- error.SetErrorString("Can't create a watchpoint that is neither read nor "
- "write nor modify.");
- return sb_watchpoint;
- }
- if (target_sp && addr != LLDB_INVALID_ADDRESS && size > 0) {
- std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
- // Target::CreateWatchpoint() is thread safe.
- Status cw_error;
- // This API doesn't take in a type, so we can't figure out what it is.
- CompilerType *type = nullptr;
- watchpoint_sp =
- target_sp->CreateWatchpoint(addr, size, type, watch_type, cw_error);
- error.SetError(std::move(cw_error));
- sb_watchpoint.SetSP(watchpoint_sp);
+ if (TargetSP target_sp = GetSP()) {
+ uint32_t watch_type = 0;
+ if (options.GetWatchpointTypeRead())
+ watch_type |= LLDB_WATCH_TYPE_READ;
+ if (options.GetWatchpointTypeWrite() == eWatchpointWriteTypeAlways)
+ watch_type |= LLDB_WATCH_TYPE_WRITE;
+ if (options.GetWatchpointTypeWrite() == eWatchpointWriteTypeOnModify)
+ watch_type |= LLDB_WATCH_TYPE_MODIFY;
+ if (watch_type == 0) {
+ error.SetErrorString("Can't create a watchpoint that is neither read nor "
+ "write nor modify.");
+ return sb_watchpoint;
+ }
+ if (addr != LLDB_INVALID_ADDRESS && size > 0) {
----------------
labath wrote:
```suggestion
uint32_t watch_type = 0;
if (options.GetWatchpointTypeRead())
watch_type |= LLDB_WATCH_TYPE_READ;
if (options.GetWatchpointTypeWrite() == eWatchpointWriteTypeAlways)
watch_type |= LLDB_WATCH_TYPE_WRITE;
if (options.GetWatchpointTypeWrite() == eWatchpointWriteTypeOnModify)
watch_type |= LLDB_WATCH_TYPE_MODIFY;
if (watch_type == 0) {
error.SetErrorString("Can't create a watchpoint that is neither read nor "
"write nor modify.");
return sb_watchpoint;
}
if (TargetSP target_sp = GetSP();
target_sp && addr != LLDB_INVALID_ADDRESS && size > 0) {
```
https://github.com/llvm/llvm-project/pull/141284
More information about the lldb-commits
mailing list