[Lldb-commits] [lldb] [lldb] [mostly NFC] Large WP foundation: WatchpointResources (PR #68845)

Alex Langford via lldb-commits lldb-commits at lists.llvm.org
Mon Oct 23 17:58:53 PDT 2023


================
@@ -3105,102 +3122,184 @@ Status ProcessGDBRemote::DisableBreakpointSite(BreakpointSite *bp_site) {
 }
 
 // Pre-requisite: wp != NULL.
-static GDBStoppointType GetGDBStoppointType(Watchpoint *wp) {
-  assert(wp);
-  bool watch_read = wp->WatchpointRead();
-  bool watch_write = wp->WatchpointWrite();
-  bool watch_modify = wp->WatchpointModify();
-
-  // watch_read, watch_write, watch_modify cannot all be false.
-  assert((watch_read || watch_write || watch_modify) &&
-         "watch_read, watch_write, watch_modify cannot all be false.");
-  if (watch_read && (watch_write || watch_modify))
+static GDBStoppointType
+GetGDBStoppointType(const WatchpointResourceSP &wp_res_sp) {
+  assert(wp_res_sp);
+  bool read, write;
+  wp_res_sp->GetType(read, write);
+
+  assert((read || write) && "read and write cannot both be false.");
+  if (read && write)
     return eWatchpointReadWrite;
-  else if (watch_read)
+  else if (read)
     return eWatchpointRead;
-  else // Must be watch_write or watch_modify, then.
+  else
     return eWatchpointWrite;
 }
 
-Status ProcessGDBRemote::EnableWatchpoint(Watchpoint *wp, bool notify) {
+Status ProcessGDBRemote::EnableWatchpoint(WatchpointSP wp_sp, bool notify) {
   Status error;
-  if (wp) {
-    user_id_t watchID = wp->GetID();
-    addr_t addr = wp->GetLoadAddress();
+  if (wp_sp) {
----------------
bulbazord wrote:

Since you're already refactoring this part, maybe you could flip the condition and do the error handling up front. It's small, but it saves a level of indentation in an already large code block.

https://github.com/llvm/llvm-project/pull/68845


More information about the lldb-commits mailing list