@@ -73,6 +73,97 @@ TEST(NativeProcessProtocolTest, SetBreakpointFailVerify) {
7373 llvm::Failed ());
7474}
7575
76+ TEST (NativeProcessProtocolTest, RemoveSoftwareBreakpoint) {
77+ NiceMock<MockDelegate> DummyDelegate;
78+ MockProcess<NativeProcessProtocol> Process (DummyDelegate,
79+ ArchSpec (" x86_64-pc-linux" ));
80+ auto Trap = cantFail (Process.GetSoftwareBreakpointTrapOpcode (1 ));
81+ auto Original = std::vector<uint8_t >{0xbb };
82+
83+ // Set up a breakpoint.
84+ {
85+ InSequence S;
86+ EXPECT_CALL (Process, ReadMemory (0x47 , 1 ))
87+ .WillOnce (Return (ByMove (Original)));
88+ EXPECT_CALL (Process, WriteMemory (0x47 , Trap)).WillOnce (Return (ByMove (1 )));
89+ EXPECT_CALL (Process, ReadMemory (0x47 , 1 )).WillOnce (Return (ByMove (Trap)));
90+ EXPECT_THAT_ERROR (Process.SetBreakpoint (0x47 , 0 , false ).ToError (),
91+ llvm::Succeeded ());
92+ }
93+
94+ // Remove the breakpoint for the first time. This should remove the breakpoint
95+ // from m_software_breakpoints.
96+ //
97+ // Should succeed.
98+ {
99+ InSequence S;
100+ EXPECT_CALL (Process, ReadMemory (0x47 , 1 )).WillOnce (Return (ByMove (Trap)));
101+ EXPECT_CALL (Process, WriteMemory (0x47 , llvm::ArrayRef (Original)))
102+ .WillOnce (Return (ByMove (1 )));
103+ EXPECT_CALL (Process, ReadMemory (0x47 , 1 ))
104+ .WillOnce (Return (ByMove (Original)));
105+ EXPECT_THAT_ERROR (Process.RemoveBreakpoint (0x47 , false ).ToError (),
106+ llvm::Succeeded ());
107+ }
108+
109+ // Remove the breakpoint for the second time.
110+ //
111+ // Should fail. None of the ReadMemory() or WriteMemory() should be called,
112+ // because the function should early return when seeing that the breakpoint
113+ // isn't in m_software_breakpoints.
114+ {
115+ EXPECT_CALL (Process, ReadMemory (_, _)).Times (0 );
116+ EXPECT_CALL (Process, WriteMemory (_, _)).Times (0 );
117+ EXPECT_THAT_ERROR (Process.RemoveBreakpoint (0x47 , false ).ToError (),
118+ llvm::Failed ());
119+ }
120+ }
121+
122+ TEST (NativeProcessProtocolTest, RemoveSoftwareBreakpointMemoryError) {
123+ NiceMock<MockDelegate> DummyDelegate;
124+ MockProcess<NativeProcessProtocol> Process (DummyDelegate,
125+ ArchSpec (" x86_64-pc-linux" ));
126+ auto Trap = cantFail (Process.GetSoftwareBreakpointTrapOpcode (1 ));
127+ auto Original = std::vector<uint8_t >{0xbb };
128+ auto SomethingElse = std::vector<uint8_t >{0xaa };
129+
130+ // Set up a breakpoint.
131+ {
132+ InSequence S;
133+ EXPECT_CALL (Process, ReadMemory (0x47 , 1 ))
134+ .WillOnce (Return (ByMove (Original)));
135+ EXPECT_CALL (Process, WriteMemory (0x47 , Trap)).WillOnce (Return (ByMove (1 )));
136+ EXPECT_CALL (Process, ReadMemory (0x47 , 1 )).WillOnce (Return (ByMove (Trap)));
137+ EXPECT_THAT_ERROR (Process.SetBreakpoint (0x47 , 0 , false ).ToError (),
138+ llvm::Succeeded ());
139+ }
140+
141+ // Remove the breakpoint for the first time, with an unexpected value read by
142+ // the first ReadMemory(). This should cause an early return, with the
143+ // breakpoint removed from m_software_breakpoints.
144+ //
145+ // Should fail.
146+ {
147+ InSequence S;
148+ EXPECT_CALL (Process, ReadMemory (0x47 , 1 ))
149+ .WillOnce (Return (ByMove (SomethingElse)));
150+ EXPECT_THAT_ERROR (Process.RemoveBreakpoint (0x47 , false ).ToError (),
151+ llvm::Failed ());
152+ }
153+
154+ // Remove the breakpoint for the second time.
155+ //
156+ // Should fail. None of the ReadMemory() or WriteMemory() should be called,
157+ // because the function should early return when seeing that the breakpoint
158+ // isn't in m_software_breakpoints.
159+ {
160+ EXPECT_CALL (Process, ReadMemory (_, _)).Times (0 );
161+ EXPECT_CALL (Process, WriteMemory (_, _)).Times (0 );
162+ EXPECT_THAT_ERROR (Process.RemoveBreakpoint (0x47 , false ).ToError (),
163+ llvm::Failed ());
164+ }
165+ }
166+
76167TEST (NativeProcessProtocolTest, ReadMemoryWithoutTrap) {
77168 NiceMock<MockDelegate> DummyDelegate;
78169 MockProcess<NativeProcessProtocol> Process (DummyDelegate,
@@ -146,4 +237,4 @@ TEST(NativeProcessProtocolTest, ReadCStringFromMemory_CrossPageBoundary) {
146237 bytes_read),
147238 llvm::HasValue (llvm::StringRef (" hello" )));
148239 EXPECT_EQ (bytes_read, 6UL );
149- }
240+ }
0 commit comments