[ros-diffs] [ion] 24577: - Implement DbgkpConvertKernelToUserStateChange. I just remembered that there's actually 3 debug subsystems in NT: Win32, Native and Kernel, so this structure will still need to be heavily parsed at the Win32 level (in kernel32) before user-mode debuggers can work (so I'll have to write a small native-mode debugger test app to test this implementation first). - Implement DbgkpMarkProcessPeb.

ion at svn.reactos.org ion at svn.reactos.org
Fri Oct 20 08:12:54 CEST 2006


Author: ion
Date: Fri Oct 20 10:12:54 2006
New Revision: 24577

URL: http://svn.reactos.org/svn/reactos?rev=24577&view=rev
Log:
- Implement DbgkpConvertKernelToUserStateChange. I just remembered that there's actually 3 debug subsystems in NT: Win32, Native and Kernel, so this structure will still need to be heavily parsed at the Win32 level (in kernel32) before user-mode debuggers can work (so I'll have to write a small native-mode debugger test app to test this implementation first).
- Implement DbgkpMarkProcessPeb.

Modified:
    trunk/reactos/ntoskrnl/dbgk/dbgkutil.c
    trunk/reactos/ntoskrnl/dbgk/debug.c

Modified: trunk/reactos/ntoskrnl/dbgk/dbgkutil.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/dbgk/dbgkutil.c?rev=24577&r1=24576&r2=24577&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/dbgk/dbgkutil.c (original)
+++ trunk/reactos/ntoskrnl/dbgk/dbgkutil.c Fri Oct 20 10:12:54 2006
@@ -1,13 +1,12 @@
 /*
- * COPYRIGHT:       See COPYING in the top level directory
  * PROJECT:         ReactOS Kernel
+ * LICENSE:         GPL - See COPYING in the top level directory
  * FILE:            ntoskrnl/dbgk/dbgkutil.c
  * PURPOSE:         User-Mode Debugging Support, Internal Debug Functions.
- *
- * PROGRAMMERS:     Alex Ionescu (alex at relsoft.net)
+ * PROGRAMMERS:     Alex Ionescu (alex.ionescu at reactos.org)
  */
 
-/* INCLUDES *****************************************************************/
+/* INCLUDES ******************************************************************/
 
 #include <ntoskrnl.h>
 #define NDEBUG
@@ -19,39 +18,7 @@
 NTAPI
 DbgkCreateThread(PVOID StartAddress)
 {
-#if 0
-    LPC_DBG_MESSAGE Message;
-    LPC_DBG_MESSAGE Reply;
-    NTSTATUS Status;
-
-    if (PsGetCurrentThread()->ThreadsProcess->DebugPort == NULL)
-    {
-        return;
-    }
-
-    Message.Header.MessageSize = sizeof(LPC_DBG_MESSAGE);
-    Message.Header.DataSize = sizeof(LPC_DBG_MESSAGE) -
-        sizeof(LPC_MESSAGE);
-    Message.Type = DBG_EVENT_CREATE_THREAD;
-    Message.Status = STATUS_SUCCESS;
-    Message.Data.CreateThread.Reserved = 0;
-    Message.Data.CreateThread.StartAddress = StartAddress;
-
-    /* FIXME: Freeze all threads in process */
-
-    /* Send the message to the process's debug port and wait for a reply */
-    Status =
-       LpcSendDebugMessagePort(PsGetCurrentThread()->ThreadsProcess->DebugPort,
-                               &Message,
-                               &Reply);
-    if (!NT_SUCCESS(Status))
-    {
-        return;
-    }
-
-    /* FIXME: Examine reply */
-    return;
-#endif
+    /* FIXME */
 }
 
 VOID

Modified: trunk/reactos/ntoskrnl/dbgk/debug.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/dbgk/debug.c?rev=24577&r1=24576&r2=24577&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/dbgk/debug.c (original)
+++ trunk/reactos/ntoskrnl/dbgk/debug.c Fri Oct 20 10:12:54 2006
@@ -1,10 +1,9 @@
 /*
- * COPYRIGHT:       See COPYING in the top level directory
  * PROJECT:         ReactOS Kernel
- * FILE:            ntoskrnl/dbgk/debug.c
+ * LICENSE:         GPL - See COPYING in the top level directory
+ * FILE:            ntoskrnl/dbgk/dbgkobj.c
  * PURPOSE:         User-Mode Debugging Support, Debug Object Management.
- *
- * PROGRAMMERS:     Alex Ionescu (alex at relsoft.net)
+ * PROGRAMMERS:     Alex Ionescu (alex.ionescu at reactos.org)
  */
 
 /* INCLUDES ******************************************************************/
@@ -318,16 +317,144 @@
 DbgkpConvertKernelToUserStateChange(IN PDBGUI_WAIT_STATE_CHANGE WaitStateChange,
                                     IN PDEBUG_EVENT DebugEvent)
 {
-    /* FIXME: TODO */
-    return;
+    /* Start by copying the client ID */
+    WaitStateChange->AppClientId = DebugEvent->ClientId;
+
+    /* Now check which kind of event this was */
+    switch (DebugEvent->ApiMsg.ApiNumber)
+    {
+        /* New process */
+        case DbgKmCreateProcessApi:
+
+            /* Set the right native code */
+            WaitStateChange->NewState = DbgCreateProcessStateChange;
+
+            /* Copy the information */
+            WaitStateChange->StateInfo.CreateProcessInfo.NewProcess =
+                DebugEvent->ApiMsg.CreateProcess;
+
+            /* Clear the file handle for us */
+            DebugEvent->ApiMsg.CreateProcess.FileHandle = NULL;
+            break;
+
+        /* New thread */
+        case DbgKmCreateThreadApi:
+
+            /* Set the right native code */
+            WaitStateChange->NewState = DbgCreateThreadStateChange;
+
+            /* Copy information */
+            WaitStateChange->StateInfo.CreateThread.NewThread.StartAddress =
+                DebugEvent->ApiMsg.CreateThread.StartAddress;
+            WaitStateChange->StateInfo.CreateThread.NewThread.SubSystemKey =
+                DebugEvent->ApiMsg.CreateThread.SubSystemKey;
+            break;
+
+        /* Exception (or breakpoint/step) */
+        case DbgKmExceptionApi:
+
+            /* Look at the exception code */
+            if (DebugEvent->ApiMsg.Exception.ExceptionRecord.ExceptionCode ==
+                STATUS_BREAKPOINT)
+            {
+                /* Update this as a breakpoint exception */
+                WaitStateChange->NewState = DbgBreakpointStateChange;
+            }
+            else if (DebugEvent->ApiMsg.Exception.ExceptionRecord.ExceptionCode ==
+                     STATUS_SINGLE_STEP)
+            {
+                /* Update this as a single step exception */
+                WaitStateChange->NewState = DbgSingleStepStateChange;
+            }
+            else
+            {
+                /* Otherwise, set default exception */
+                WaitStateChange->NewState = DbgExceptionStateChange;
+            }
+
+            /* Copy the exception record */
+            WaitStateChange->StateInfo.Exception.ExceptionRecord =
+                DebugEvent->ApiMsg.Exception.ExceptionRecord;
+            break;
+
+        /* Process exited */
+        case DbgKmExitProcessApi:
+
+            /* Set the right native code and copy the exit code */
+            WaitStateChange->NewState = DbgExitProcessStateChange;
+            WaitStateChange->StateInfo.ExitProcess.ExitStatus =
+                DebugEvent->ApiMsg.ExitProcess.ExitStatus;
+            break;
+
+        /* Thread exited */
+        case DbgKmExitThreadApi:
+
+            /* Set the right native code */
+            WaitStateChange->NewState = DbgExitThreadStateChange;
+            WaitStateChange->StateInfo.ExitThread.ExitStatus =
+                DebugEvent->ApiMsg.ExitThread.ExitStatus;
+            break;
+
+        /* DLL Load */
+        case DbgKmLoadDllApi:
+
+            /* Set the native code */
+            WaitStateChange->NewState = DbgLoadDllStateChange;
+
+            /* Copy the data */
+            WaitStateChange->StateInfo.LoadDll = DebugEvent->ApiMsg.LoadDll;
+
+            /* Clear the file handle for us */
+            DebugEvent->ApiMsg.LoadDll.FileHandle = NULL;
+            break;
+
+        /* DLL Unload */
+        case DbgKmUnloadDllApi:
+
+            /* Set the native code and copy the address */
+            WaitStateChange->NewState = DbgUnloadDllStateChange;
+            WaitStateChange->StateInfo.UnloadDll.BaseAddress =
+                DebugEvent->ApiMsg.UnloadDll.BaseAddress;
+            break;
+
+        default:
+
+            /* Shouldn't happen */
+            ASSERT(FALSE);
+    }
 }
 
 VOID
 NTAPI
 DbgkpMarkProcessPeb(IN PEPROCESS Process)
 {
-    /* FIXME: TODO */
-    return;
+    KAPC_STATE ApcState;
+    PAGED_CODE();
+
+    /* Acquire process rundown */
+    if (!ExAcquireRundownProtection(&Process->RundownProtect)) return;
+
+    /* Make sure we have a PEB */
+    if (Process->Peb)
+    {
+        /* Attach to the process */
+        KeStackAttachProcess(&Process->Pcb, &ApcState);
+
+        /* Acquire the debug port mutex */
+        ExAcquireFastMutex(&DbgkpProcessDebugPortMutex);
+
+        /* Set the IsBeingDebugged member of the PEB */
+        Process->Peb->BeingDebugged = (Process->DebugPort) ? TRUE: FALSE;
+
+        /* Release lock */
+        ExReleaseFastMutex(&DbgkpProcessDebugPortMutex);
+
+        /* Detach from the process */
+        KeUnstackDetachProcess(&ApcState);
+    }
+
+    /* Release rundown protection */
+    ExReleaseRundownProtection(&Process->RundownProtect);
 }
 
 VOID




More information about the Ros-diffs mailing list