https://git.reactos.org/?p=reactos.git;a=commitdiff;h=309e9c13e14e3e3a4ddf55d0698b3772b762c9b9

commit 309e9c13e14e3e3a4ddf55d0698b3772b762c9b9
Author:     Sylvain Deverre <[email protected]>
AuthorDate: Sun Apr 19 14:20:58 2020 +0200
Commit:     Sylvain Deverre <[email protected]>
CommitDate: Sun Apr 19 15:01:41 2020 +0200

    [KDGDB] Allow kdgdb to continue when hit by a first-chance exception.
    
    When gdb receives a fault, it converts it to "signal", and send "C"
    command to server to transfer the signal it couldn't handle.
    
    On ReactOS (and Windows ?) side, we tell KD API that we continue with an
    error code, so the exception handler can be called.
    
    This is useful when playing with gflags, especially +soe, with KDGDB.
---
 drivers/base/kdgdb/gdb_input.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/drivers/base/kdgdb/gdb_input.c b/drivers/base/kdgdb/gdb_input.c
index ab2efdc10a4..e729beb37e1 100644
--- a/drivers/base/kdgdb/gdb_input.c
+++ b/drivers/base/kdgdb/gdb_input.c
@@ -902,6 +902,32 @@ handle_gdb_c(
     return ContinueManipulateStateHandler(State, MessageData, MessageLength, 
KdContext);
 }
 
+static
+KDSTATUS
+handle_gdb_C(
+    _Out_ DBGKD_MANIPULATE_STATE64* State,
+    _Out_ PSTRING MessageData,
+    _Out_ PULONG MessageLength,
+    _Inout_ PKD_CONTEXT KdContext)
+{
+    KDSTATUS Status;
+
+    /* Tell GDB everything is fine, we will handle it */
+    Status = send_gdb_packet("OK");
+    if (Status != KdPacketReceived)
+        return Status;
+
+    if (CurrentStateChange.NewState == DbgKdExceptionStateChange)
+    {
+        /* Debugger didn't handle the exception, report it back to the kernel 
*/
+        State->u.Continue2.ContinueStatus = 
CurrentStateChange.u.Exception.ExceptionRecord.ExceptionCode;
+        State->ApiNumber = DbgKdContinueApi2;
+        return KdPacketReceived;
+    }
+    /* We should never reach this ? */
+    return ContinueManipulateStateHandler(State, MessageData, MessageLength, 
KdContext);
+}
+
 static
 KDSTATUS
 handle_gdb_s(
@@ -982,6 +1008,9 @@ gdb_receive_and_interpret_packet(
         case 'c':
             Status = handle_gdb_c(State, MessageData, MessageLength, 
KdContext);
             break;
+        case 'C':
+            Status = handle_gdb_C(State, MessageData, MessageLength, 
KdContext);
+            break;
         case 'g':
             Status = LOOP_IF_SUCCESS(gdb_send_registers());
             break;

Reply via email to