[Lldb-commits] [lldb] [lldb] Fix a crash in lldb-server during RemoveSoftwareBreakpoint() (PR #148738)

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Wed Jul 16 00:43:10 PDT 2025


================
@@ -73,6 +73,97 @@ TEST(NativeProcessProtocolTest, SetBreakpointFailVerify) {
                     llvm::Failed());
 }
 
+TEST(NativeProcessProtocolTest, RemoveSoftwareBreakpoint) {
+  NiceMock<MockDelegate> DummyDelegate;
+  MockProcess<NativeProcessProtocol> Process(DummyDelegate,
+                                             ArchSpec("x86_64-pc-linux"));
+  auto Trap = cantFail(Process.GetSoftwareBreakpointTrapOpcode(1));
+  auto Original = std::vector<uint8_t>{0xbb};
+
+  // Set up a breakpoint.
+  {
+    InSequence S;
+    EXPECT_CALL(Process, ReadMemory(0x47, 1))
+        .WillOnce(Return(ByMove(Original)));
+    EXPECT_CALL(Process, WriteMemory(0x47, Trap)).WillOnce(Return(ByMove(1)));
+    EXPECT_CALL(Process, ReadMemory(0x47, 1)).WillOnce(Return(ByMove(Trap)));
+    EXPECT_THAT_ERROR(Process.SetBreakpoint(0x47, 0, false).ToError(),
+                      llvm::Succeeded());
+  }
----------------
labath wrote:

A helper function is one way. Another is to provide a default implementation of the read/write functions (using `ON_CALL`) that would "emulate" emulate a real memory (by using the "address" as an index into a vector). That way you'd only need to program the assertions that you intend to check.

However, I think this is fine. This file doesn't get a lot of traffic.

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


More information about the lldb-commits mailing list