Author: ion
Date: Fri Dec  1 10:36:49 2006
New Revision: 25010
URL: 
http://svn.reactos.org/svn/reactos?rev=25010&view=rev
Log:
- Write DLL Being mapped into NtTib->ArbitraryUserPointer so that the debugger can pick
it up.
- Fix bugs in DbgkWakeTarget, DbgkCreateThread, DbgkMapViewOfSection and call from
NtMapViewOfSection.
Modified:
    trunk/reactos/dll/ntdll/dbg/dbgui.c
    trunk/reactos/dll/ntdll/ldr/utils.c
    trunk/reactos/ntoskrnl/dbgk/dbgkutil.c
    trunk/reactos/ntoskrnl/dbgk/debug.c
    trunk/reactos/ntoskrnl/include/internal/dbgk.h
    trunk/reactos/ntoskrnl/mm/section.c
Modified: trunk/reactos/dll/ntdll/dbg/dbgui.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/ntdll/dbg/dbgui.c?rev=…
==============================================================================
--- trunk/reactos/dll/ntdll/dbg/dbgui.c (original)
+++ trunk/reactos/dll/ntdll/dbg/dbgui.c Fri Dec  1 10:36:49 2006
@@ -280,8 +280,9 @@
             {
                 /* Save the image name from the TIB */
                 DebugEvent->u.LoadDll.lpImageName =
-                    &((PTEB)ThreadBasicInfo.TebBaseAddress)->
+                    ((PTEB)ThreadBasicInfo.TebBaseAddress)->
                     Tib.ArbitraryUserPointer;
+                DPRINT1("Image name: %p\n",
DebugEvent->u.LoadDll.lpImageName);
             }
             else
             {
Modified: trunk/reactos/dll/ntdll/ldr/utils.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/ntdll/ldr/utils.c?rev=…
==============================================================================
--- trunk/reactos/dll/ntdll/ldr/utils.c (original)
+++ trunk/reactos/dll/ntdll/ldr/utils.c Fri Dec  1 10:36:49 2006
@@ -1986,6 +1986,7 @@
     PVOID ImageBase;
     PIMAGE_NT_HEADERS NtHeaders;
     BOOLEAN MappedAsDataFile;
+    PVOID ArbitraryUserPointer;
     if (Module == NULL)
       {
@@ -2027,6 +2028,9 @@
         /* Map the dll into the process */
         ViewSize = 0;
         ImageBase = 0;
+        ArbitraryUserPointer = NtCurrentTeb()->Tib.ArbitraryUserPointer;
+        NtCurrentTeb()->Tib.ArbitraryUserPointer = FullDosName.Buffer;
+        DPRINT1("POI. DAT: %p %S\n",
NtCurrentTeb()->Tib.ArbitraryUserPointer, FullDosName.Buffer);
         Status = NtMapViewOfSection(SectionHandle,
                                     NtCurrentProcess(),
                                     &ImageBase,
@@ -2037,6 +2041,8 @@
                                     0,
                                     MEM_COMMIT,
                                     PAGE_READONLY);
+        NtCurrentTeb()->Tib.ArbitraryUserPointer = ArbitraryUserPointer;
+        DPRINT1("Poi gone!\n");
         if (!NT_SUCCESS(Status))
           {
             DPRINT1("map view of section failed (Status 0x%08lx)\n", Status);
Modified: trunk/reactos/ntoskrnl/dbgk/dbgkutil.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/dbgk/dbgkutil.c?r…
==============================================================================
--- trunk/reactos/ntoskrnl/dbgk/dbgkutil.c (original)
+++ trunk/reactos/ntoskrnl/dbgk/dbgkutil.c Fri Dec  1 10:36:49 2006
@@ -11,6 +11,8 @@
 #include <ntoskrnl.h>
 #define NDEBUG
 #include <debug.h>
+
+extern ULONG DbgkpTraceLevel;
 /* FUNCTIONS *****************************************************************/
@@ -236,9 +238,11 @@
         if (Teb)
         {
             /* Copy the system library name and link to it */
+#if 0
             wcsncpy(Teb->StaticUnicodeBuffer,
                     L"ntdll.dll",
-                    sizeof(Teb->StaticUnicodeBuffer));
+                    sizeof(Teb->StaticUnicodeBuffer) / sizeof(WCHAR));
+#endif
             Teb->Tib.ArbitraryUserPointer = Teb->StaticUnicodeBuffer;
             /* Return it in the debug event as well */
@@ -369,7 +373,7 @@
 VOID
 NTAPI
-DbgkMapViewOfSection(IN HANDLE SectionHandle,
+DbgkMapViewOfSection(IN PVOID Section,
                      IN PVOID BaseAddress,
                      IN ULONG SectionOffset,
                      IN ULONG_PTR ViewSize)
@@ -380,6 +384,8 @@
     PETHREAD Thread = PsGetCurrentThread();
     PIMAGE_NT_HEADERS NtHeader;
     PAGED_CODE();
+    DBGKTRACE(DBGK_PROCESS_DEBUG,
+              "Section: %p. Base: %p\n", Section, BaseAddress);
     /* Check if this thread is hidden, doesn't have a debug port, or died */
     if ((Thread->HideFromDebugger) ||
@@ -392,7 +398,7 @@
     }
     /* Setup the parameters */
-    LoadDll->FileHandle = DbgkpSectionToFileHandle(SectionHandle);
+    LoadDll->FileHandle = DbgkpSectionToFileHandle(Section);
     LoadDll->BaseOfDll = BaseAddress;
     LoadDll->DebugInfoFileOffset = 0;
     LoadDll->DebugInfoSize = 0;
Modified: trunk/reactos/ntoskrnl/dbgk/debug.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/dbgk/debug.c?rev=…
==============================================================================
--- trunk/reactos/ntoskrnl/dbgk/debug.c (original)
+++ trunk/reactos/ntoskrnl/dbgk/debug.c Fri Dec  1 10:36:49 2006
@@ -329,7 +329,7 @@
     PAGED_CODE();
     DBGKTRACE(DBGK_EXCEPTION_DEBUG,
               "ExceptionRecord: %p Port: %p\n", ExceptionRecord, DebugPort);
-    KEBUGCHECK(0);
+    while (TRUE);
     /* Setup the API Message */
     ApiMessage.h.u1.Length = sizeof(DBGKM_MSG) << 16 |
@@ -442,13 +442,13 @@
     /* Check if we have to wake up the event */
     if (DebugEvent->Flags & 2)
     {
+        /* Otherwise, free the debug event */
+        DbgkpFreeDebugEvent(DebugEvent);
+    }
+    else
+    {
         /* Signal the continue event */
         KeSetEvent(&DebugEvent->ContinueEvent, IO_NO_INCREMENT, FALSE);
-    }
-    else
-    {
-        /* Otherwise, free the debug event */
-        DbgkpFreeDebugEvent(DebugEvent);
     }
 }
Modified: trunk/reactos/ntoskrnl/include/internal/dbgk.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/include/internal/…
==============================================================================
--- trunk/reactos/ntoskrnl/include/internal/dbgk.h (original)
+++ trunk/reactos/ntoskrnl/include/internal/dbgk.h Fri Dec  1 10:36:49 2006
@@ -74,7 +74,7 @@
 VOID
 NTAPI
 DbgkMapViewOfSection(
-    IN HANDLE SectionHandle,
+    IN PVOID Section,
     IN PVOID BaseAddress,
     IN ULONG SectionOffset,
     IN ULONG_PTR ViewSize
Modified: trunk/reactos/ntoskrnl/mm/section.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/section.c?rev=…
==============================================================================
--- trunk/reactos/ntoskrnl/mm/section.c (original)
+++ trunk/reactos/ntoskrnl/mm/section.c Fri Dec  1 10:36:49 2006
@@ -3777,7 +3777,7 @@
        (Status != STATUS_IMAGE_NOT_AT_BASE))
    {
         /* Notify the debugger */
-       DbgkMapViewOfSection(SectionHandle,
+       DbgkMapViewOfSection(Section,
                             SafeBaseAddress,
                             SafeSectionOffset.LowPart,
                             SafeViewSize);