Skip to content

Commit 720c09c

Browse files
authored
Update callback (#4)
1 parent 619d313 commit 720c09c

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

Sources/SimpleDebugger/SimpleDebugger.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,11 @@ void* SimpleDebugger::exceptionServer() {
146146
printf("Error getting thread state: %s\n", mach_error_string(kr));
147147
}
148148
if (exceptionCallback) {
149-
exceptionCallback(state, [this, exceptionMessage, state, state_count]() {
150-
continueFromBreak(exceptionMessage, state, state_count);
149+
exceptionCallback(thread, state, [this, exceptionMessage, state, state_count](bool removeBreak) {
150+
continueFromBreak(removeBreak, exceptionMessage, state, state_count);
151151
});
152152
} else {
153-
continueFromBreak(exceptionMessage, state, state_count);
153+
continueFromBreak(true, exceptionMessage, state, state_count);
154154
}
155155
} else {
156156
os_log(OS_LOG_DEFAULT, "Not breakpoint message");
@@ -160,16 +160,18 @@ void* SimpleDebugger::exceptionServer() {
160160
return nullptr;
161161
}
162162

163-
void SimpleDebugger::continueFromBreak(MachExceptionMessage exceptionMessage, arm_thread_state64_t state, mach_msg_type_number_t state_count) {
163+
void SimpleDebugger::continueFromBreak(bool removeBreak, MachExceptionMessage exceptionMessage, arm_thread_state64_t state, mach_msg_type_number_t state_count) {
164164

165-
if (originalInstruction.contains(state.__pc)) {
166-
uint32_t orig = originalInstruction.at(state.__pc);
167-
setInstruction(state.__pc, orig);
168-
originalInstruction.erase(state.__pc);
169-
} else {
170-
// Address was not tracked, do nothing. Maybe this was a thread that hit the breakpoint
171-
// at the same time another thread cleared it.
172-
printf("Unexpected not tracked address\n");
165+
if (removeBreak) {
166+
if (originalInstruction.contains(state.__pc)) {
167+
uint32_t orig = originalInstruction.at(state.__pc);
168+
setInstruction(state.__pc, orig);
169+
originalInstruction.erase(state.__pc);
170+
} else {
171+
// Address was not tracked, do nothing. Maybe this was a thread that hit the breakpoint
172+
// at the same time another thread cleared it.
173+
printf("Unexpected not tracked address\n");
174+
}
173175
}
174176

175177
MachReplyMessage replyMessage = {{0}};

Sources/SimpleDebugger/include/SimpleDebugger.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ struct MachExceptionMessage;
2121

2222
class SimpleDebugger {
2323
public:
24-
using ExceptionCallback = std::function<void(arm_thread_state64_t state, std::function<void()>)>;
24+
using ExceptionCallback = std::function<void(mach_port_t thread, arm_thread_state64_t state, std::function<void(bool removeBreak)>)>;
2525

2626
SimpleDebugger();
2727

@@ -40,7 +40,7 @@ class SimpleDebugger {
4040

4141
static void* exceptionServerWrapper(void* arg);
4242
void* exceptionServer();
43-
void continueFromBreak(MachExceptionMessage exceptionMessage, arm_thread_state64_t state, mach_msg_type_number_t state_count);
43+
void continueFromBreak(bool removeBreak, MachExceptionMessage exceptionMessage, arm_thread_state64_t state, mach_msg_type_number_t state_count);
4444
};
4545
}
4646
#endif

0 commit comments

Comments
 (0)