Sync to trunk head (r42241)
[reactos.git] / reactos / ntoskrnl / kdbg / kdb.c
index 2155e40..3c1fd71 100644 (file)
 
 /* GLOBALS *******************************************************************/
 
-STATIC LONG KdbEntryCount = 0;
-STATIC CHAR KdbStack[KDB_STACK_SIZE];
-
-STATIC ULONG KdbBreakPointCount = 0;  /* Number of used breakpoints in the array */
-STATIC KDB_BREAKPOINT KdbBreakPoints[KDB_MAXIMUM_BREAKPOINT_COUNT] = {{0}};  /* Breakpoint array */
-STATIC ULONG KdbSwBreakPointCount = 0;  /* Number of enabled software breakpoints */
-STATIC ULONG KdbHwBreakPointCount = 0;  /* Number of enabled hardware breakpoints */
-STATIC PKDB_BREAKPOINT KdbSwBreakPoints[KDB_MAXIMUM_SW_BREAKPOINT_COUNT]; /* Enabled software breakpoints, orderless */
-STATIC PKDB_BREAKPOINT KdbHwBreakPoints[KDB_MAXIMUM_HW_BREAKPOINT_COUNT]; /* Enabled hardware breakpoints, orderless */
-STATIC PKDB_BREAKPOINT KdbBreakPointToReenable = NULL; /* Set to a breakpoint struct when single stepping after
+static LONG KdbEntryCount = 0;
+static CHAR KdbStack[KDB_STACK_SIZE];
+
+static ULONG KdbBreakPointCount = 0;  /* Number of used breakpoints in the array */
+static KDB_BREAKPOINT KdbBreakPoints[KDB_MAXIMUM_BREAKPOINT_COUNT] = {{0}};  /* Breakpoint array */
+static ULONG KdbSwBreakPointCount = 0;  /* Number of enabled software breakpoints */
+static ULONG KdbHwBreakPointCount = 0;  /* Number of enabled hardware breakpoints */
+static PKDB_BREAKPOINT KdbSwBreakPoints[KDB_MAXIMUM_SW_BREAKPOINT_COUNT]; /* Enabled software breakpoints, orderless */
+static PKDB_BREAKPOINT KdbHwBreakPoints[KDB_MAXIMUM_HW_BREAKPOINT_COUNT]; /* Enabled hardware breakpoints, orderless */
+static PKDB_BREAKPOINT KdbBreakPointToReenable = NULL; /* Set to a breakpoint struct when single stepping after
                                                           a software breakpoint was hit, to reenable it */
 LONG KdbLastBreakPointNr = -1;  /* Index of the breakpoint which cause KDB to be entered */
 ULONG KdbNumSingleSteps = 0; /* How many single steps to do */
 BOOLEAN KdbSingleStepOver = FALSE; /* Whether to step over calls/reps. */
 ULONG KdbDebugState = 0; /* KDBG Settings (NOECHO, KDSERIAL) */
-STATIC BOOLEAN KdbEnteredOnSingleStep = FALSE; /* Set to true when KDB was entered because of single step */
+static BOOLEAN KdbEnteredOnSingleStep = FALSE; /* Set to true when KDB was entered because of single step */
 PEPROCESS KdbCurrentProcess = NULL;  /* The current process context in which KDB runs */
 PEPROCESS KdbOriginalProcess = NULL; /* The process in whichs context KDB was intered */
 PETHREAD KdbCurrentThread = NULL;  /* The current thread context in which KDB runs */
 PETHREAD KdbOriginalThread = NULL; /* The thread in whichs context KDB was entered */
 PKDB_KTRAP_FRAME KdbCurrentTrapFrame = NULL; /* Pointer to the current trapframe */
-STATIC KDB_KTRAP_FRAME KdbTrapFrame = { { 0 } };  /* The trapframe which was passed to KdbEnterDebuggerException */
-STATIC KDB_KTRAP_FRAME KdbThreadTrapFrame = { { 0 } }; /* The trapframe of the current thread (KdbCurrentThread) */
-STATIC KAPC_STATE KdbApcState;
+static KDB_KTRAP_FRAME KdbTrapFrame = { { 0 } };  /* The trapframe which was passed to KdbEnterDebuggerException */
+static KDB_KTRAP_FRAME KdbThreadTrapFrame = { { 0 } }; /* The trapframe of the current thread (KdbCurrentThread) */
+static KAPC_STATE KdbApcState;
 extern BOOLEAN KdbpBugCheckRequested;
 
 /* Array of conditions when to enter KDB */
-STATIC KDB_ENTER_CONDITION KdbEnterConditions[][2] =
+static KDB_ENTER_CONDITION KdbEnterConditions[][2] =
 {
    /* First chance       Last chance */
    { KdbDoNotEnter,      KdbEnterFromKmode },   /* Zero devide */
@@ -81,7 +81,7 @@ STATIC KDB_ENTER_CONDITION KdbEnterConditions[][2] =
 };
 
 /* Exception descriptions */
-STATIC CONST CHAR *ExceptionNrToString[] =
+static const CHAR *ExceptionNrToString[] =
 {
    "Divide Error",
    "Debug Trap",
@@ -133,7 +133,7 @@ HalReleaseDisplayOwnership(
 
 /* FUNCTIONS *****************************************************************/
 
-STATIC VOID
+static VOID
 KdbpTrapFrameToKdbTrapFrame(PKTRAP_FRAME TrapFrame, PKDB_KTRAP_FRAME KdbTrapFrame)
 {
    ULONG TrapCr0, TrapCr2, TrapCr3, TrapCr4;
@@ -180,7 +180,7 @@ KdbpTrapFrameToKdbTrapFrame(PKTRAP_FRAME TrapFrame, PKDB_KTRAP_FRAME KdbTrapFram
    /* FIXME: copy v86 registers if TrapFrame is a V86 trapframe */
 }
 
-STATIC VOID
+static VOID
 KdbpKdbTrapFrameToTrapFrame(PKDB_KTRAP_FRAME KdbTrapFrame, PKTRAP_FRAME TrapFrame)
 {
    /* Copy the TrapFrame only up to Eflags and zero the rest*/
@@ -194,7 +194,7 @@ KdbpKdbTrapFrameToTrapFrame(PKDB_KTRAP_FRAME KdbTrapFrame, PKTRAP_FRAME TrapFram
    /* FIXME: copy v86 registers if TrapFrame is a V86 trapframe */
 }
 
-STATIC VOID
+static VOID
 KdbpKdbTrapFrameFromKernelStack(PVOID KernelStack,
                                 PKDB_KTRAP_FRAME KdbTrapFrame)
 {
@@ -202,6 +202,7 @@ KdbpKdbTrapFrameFromKernelStack(PVOID KernelStack,
 
    RtlZeroMemory(KdbTrapFrame, sizeof(KDB_KTRAP_FRAME));
    StackPtr = (ULONG_PTR *) KernelStack;
+#if _M_X86_
    KdbTrapFrame->Tf.Ebp = StackPtr[3];
    KdbTrapFrame->Tf.Edi = StackPtr[4];
    KdbTrapFrame->Tf.Esi = StackPtr[5];
@@ -213,6 +214,7 @@ KdbpKdbTrapFrameFromKernelStack(PVOID KernelStack,
    KdbTrapFrame->Tf.SegDs = KGDT_R0_DATA;
    KdbTrapFrame->Tf.SegEs = KGDT_R0_DATA;
    KdbTrapFrame->Tf.SegGs = KGDT_R0_DATA;
+#endif
 
    /* FIXME: what about the other registers??? */
 }
@@ -227,7 +229,7 @@ KdbpKdbTrapFrameFromKernelStack(PVOID KernelStack,
  *
  * \returns NTSTATUS
  */
-STATIC NTSTATUS
+static NTSTATUS
 KdbpOverwriteInstruction(
    IN  PEPROCESS Process,
    IN  ULONG_PTR Address,
@@ -406,7 +408,7 @@ KdbpStepIntoInstruction(ULONG_PTR Eip)
    }
 
    /* Get the interrupt descriptor */
-   if (!NT_SUCCESS(KdbpSafeReadMemory(IntDesc, (PVOID)(Idtr.Base + (IntVect * 8)), sizeof (IntDesc))))
+   if (!NT_SUCCESS(KdbpSafeReadMemory(IntDesc, (PVOID)(ULONG_PTR)(Idtr.Base + (IntVect * 8)), sizeof (IntDesc))))
    {
       /*KdbpPrint("Couldn't access memory at 0x%p\n", (ULONG_PTR)Idtr.Base + (IntVect * 8));*/
       return FALSE;
@@ -698,7 +700,7 @@ KdbpDeleteBreakPoint(
  *
  * \returns Breakpoint number, -1 on error.
  */
-STATIC LONG
+static LONG
 KdbpIsBreakPointOurs(
    IN NTSTATUS ExceptionCode,
    IN PKTRAP_FRAME TrapFrame)
@@ -1074,7 +1076,7 @@ KdbpAttachToThread(
    /* Get a pointer to the thread */
    if (!NT_SUCCESS(PsLookupThreadByThreadId(ThreadId, &Thread)))
    {
-      KdbpPrint("Invalid thread id: 0x%08x\n", (ULONG)ThreadId);
+      KdbpPrint("Invalid thread id: 0x%08x\n", (ULONG_PTR)ThreadId);
       return FALSE;
    }
    Process = Thread->ThreadsProcess;
@@ -1155,7 +1157,7 @@ KdbpAttachToProcess(
    /* Get a pointer to the process */
    if (!NT_SUCCESS(PsLookupProcessByProcessId(ProcessId, &Process)))
    {
-      KdbpPrint("Invalid process id: 0x%08x\n", (ULONG)ProcessId);
+      KdbpPrint("Invalid process id: 0x%08x\n", (ULONG_PTR)ProcessId);
       return FALSE;
    }
 
@@ -1163,7 +1165,7 @@ KdbpAttachToProcess(
    ObDereferenceObject(Process);
    if (Entry == &KdbCurrentProcess->ThreadListHead)
    {
-      KdbpPrint("No threads in process 0x%08x, cannot attach to process!\n", (ULONG)ProcessId);
+      KdbpPrint("No threads in process 0x%p, cannot attach to process!\n", ProcessId);
       return FALSE;
    }
 
@@ -1174,8 +1176,8 @@ KdbpAttachToProcess(
 
 /*!\brief Calls the main loop ...
  */
-STATIC VOID
-KdbpCallMainLoop()
+static VOID
+KdbpCallMainLoop(VOID)
 {
    KdbpCliMainLoop(KdbEnteredOnSingleStep);
 }
@@ -1184,7 +1186,7 @@ KdbpCallMainLoop()
  *
  * Disables interrupts, releases display ownership, ...
  */
-STATIC VOID
+static VOID
 KdbpInternalEnter()
 {
    PETHREAD Thread;
@@ -1204,7 +1206,7 @@ KdbpInternalEnter()
    SavedStackLimit = Thread->Tcb.StackLimit;
    SavedKernelStack = Thread->Tcb.KernelStack;
    Thread->Tcb.InitialStack = Thread->Tcb.StackBase = (char*)KdbStack + KDB_STACK_SIZE;
-   Thread->Tcb.StackLimit = (ULONG)KdbStack;
+   Thread->Tcb.StackLimit = (ULONG_PTR)KdbStack;
    Thread->Tcb.KernelStack = (char*)KdbStack + KDB_STACK_SIZE;
 
    /*KdbpPrint("Switching to KDB stack 0x%08x-0x%08x (Current Stack is 0x%08x)\n", Thread->Tcb.StackLimit, Thread->Tcb.StackBase, Esp);*/
@@ -1218,7 +1220,7 @@ KdbpInternalEnter()
    KbdEnableMouse();
 }
 
-STATIC ULONG
+static ULONG
 KdbpGetExceptionNumberFromStatus(IN NTSTATUS ExceptionCode)
 {
     ULONG Ret;
@@ -1507,7 +1509,7 @@ KdbEnterDebuggerException(
    }
    else
    {
-      CONST CHAR *ExceptionString = (ExpNr < RTL_NUMBER_OF(ExceptionNrToString)) ?
+      const CHAR *ExceptionString = (ExpNr < RTL_NUMBER_OF(ExceptionNrToString)) ?
                                     (ExceptionNrToString[ExpNr]) :
                                     ("Unknown/User defined exception");