tatyana-krasnukha updated this revision to Diff 122966.
tatyana-krasnukha added a comment.

Sorry for wrong formatting, I've removed it.

What I've actually done:

- grouped cases returning WriteMemoryPrivate in the top of function;
- moved last comment to code it relates;
- change other comment according what really will be returned in that case.

I hope that these changes improves readability and will help to avoid errors 
like I tried to fix in D39969 <https://reviews.llvm.org/D39969>


Repository:
  rL LLVM

https://reviews.llvm.org/D39967

Files:
  source/Target/Process.cpp

Index: source/Target/Process.cpp
===================================================================
--- source/Target/Process.cpp
+++ source/Target/Process.cpp
@@ -2423,65 +2423,64 @@
 
   BreakpointSiteList bp_sites_in_range;
 
-  if (m_breakpoint_site_list.FindInRange(addr, addr + size,
-                                         bp_sites_in_range)) {
+  if (!m_breakpoint_site_list.FindInRange(addr, addr + size,
+                                          bp_sites_in_range) ||
+      bp_sites_in_range.IsEmpty()) {
+
     // No breakpoint sites overlap
-    if (bp_sites_in_range.IsEmpty())
-      return WriteMemoryPrivate(addr, buf, size, error);
-    else {
-      const uint8_t *ubuf = (const uint8_t *)buf;
-      uint64_t bytes_written = 0;
+    return WriteMemoryPrivate(addr, buf, size, error);
+  }
 
-      bp_sites_in_range.ForEach([this, addr, size, &bytes_written, &ubuf,
-                                 &error](BreakpointSite *bp) -> void {
+  const uint8_t *ubuf = (const uint8_t *)buf;
+  uint64_t bytes_written = 0;
 
-        if (error.Success()) {
-          addr_t intersect_addr;
-          size_t intersect_size;
-          size_t opcode_offset;
-          const bool intersects = bp->IntersectsRange(
-              addr, size, &intersect_addr, &intersect_size, &opcode_offset);
-          UNUSED_IF_ASSERT_DISABLED(intersects);
-          assert(intersects);
-          assert(addr <= intersect_addr && intersect_addr < addr + size);
-          assert(addr < intersect_addr + intersect_size &&
-                 intersect_addr + intersect_size <= addr + size);
-          assert(opcode_offset + intersect_size <= bp->GetByteSize());
+  bp_sites_in_range.ForEach([this, addr, size, &bytes_written, &ubuf,
+                             &error](BreakpointSite *bp) -> void {
 
-          // Check for bytes before this breakpoint
-          const addr_t curr_addr = addr + bytes_written;
-          if (intersect_addr > curr_addr) {
-            // There are some bytes before this breakpoint that we need to
-            // just write to memory
-            size_t curr_size = intersect_addr - curr_addr;
-            size_t curr_bytes_written = WriteMemoryPrivate(
-                curr_addr, ubuf + bytes_written, curr_size, error);
-            bytes_written += curr_bytes_written;
-            if (curr_bytes_written != curr_size) {
-              // We weren't able to write all of the requested bytes, we
-              // are done looping and will return the number of bytes that
-              // we have written so far.
-              if (error.Success())
-                error.SetErrorToGenericError();
-            }
-          }
-          // Now write any bytes that would cover up any software breakpoints
-          // directly into the breakpoint opcode buffer
-          ::memcpy(bp->GetSavedOpcodeBytes() + opcode_offset,
-                   ubuf + bytes_written, intersect_size);
-          bytes_written += intersect_size;
+    if (error.Success()) {
+      addr_t intersect_addr;
+      size_t intersect_size;
+      size_t opcode_offset;
+      const bool intersects = bp->IntersectsRange(
+          addr, size, &intersect_addr, &intersect_size, &opcode_offset);
+      UNUSED_IF_ASSERT_DISABLED(intersects);
+      assert(intersects);
+      assert(addr <= intersect_addr && intersect_addr < addr + size);
+      assert(addr < intersect_addr + intersect_size &&
+             intersect_addr + intersect_size <= addr + size);
+      assert(opcode_offset + intersect_size <= bp->GetByteSize());
+
+      // Check for bytes before this breakpoint
+      const addr_t curr_addr = addr + bytes_written;
+      if (intersect_addr > curr_addr) {
+        // There are some bytes before this breakpoint that we need to
+        // just write to memory
+        size_t curr_size = intersect_addr - curr_addr;
+        size_t curr_bytes_written = WriteMemoryPrivate(
+            curr_addr, ubuf + bytes_written, curr_size, error);
+        bytes_written += curr_bytes_written;
+        if (curr_bytes_written != curr_size) {
+          // We weren't able to write all of the requested bytes, we
+          // are done looping and will return zero.
+          if (error.Success())
+            error.SetErrorToGenericError();
+
+          return;
         }
-      });
-
-      if (bytes_written < size)
-        WriteMemoryPrivate(addr + bytes_written, ubuf + bytes_written,
-                           size - bytes_written, error);
+      }
+      // Now write any bytes that would cover up any software breakpoints
+      // directly into the breakpoint opcode buffer
+      ::memcpy(bp->GetSavedOpcodeBytes() + opcode_offset, ubuf + bytes_written,
+               intersect_size);
+      bytes_written += intersect_size;
     }
-  } else {
-    return WriteMemoryPrivate(addr, buf, size, error);
-  }
+  });
 
   // Write any remaining bytes after the last breakpoint if we have any left
+  if (error.Success() && bytes_written < size)
+    WriteMemoryPrivate(addr + bytes_written, ubuf + bytes_written,
+                       size - bytes_written, error);
+
   return 0; // bytes_written;
 }
 
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to