Fixed null pointer exceptions.
authorDavid Welch <welch@cwcom.net>
Wed, 17 Jul 2002 22:56:11 +0000 (22:56 +0000)
committerDavid Welch <welch@cwcom.net>
Wed, 17 Jul 2002 22:56:11 +0000 (22:56 +0000)
Removed private install script.
Moved stabs reading to a seperate file.
Added hooks for the kernel debugger.

svn path=/trunk/; revision=3245

reactos/drivers/fs/ms/msfs.c
reactos/install.bochs [deleted file]
reactos/ntoskrnl/dbg/dbgctrl.c
reactos/ntoskrnl/include/internal/kd.h
reactos/ntoskrnl/io/pnpmgr.c
reactos/ntoskrnl/ke/i386/exp.c
reactos/ntoskrnl/ke/i386/usertrap.c
reactos/ntoskrnl/ldr/loader.c
reactos/ntoskrnl/ps/process.c

index 4c3278a..bb68620 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: msfs.c,v 1.2 2001/06/12 12:33:42 ekohl Exp $
+/* $Id: msfs.c,v 1.3 2002/07/17 22:56:10 dwelch Exp $
  *
  * COPYRIGHT:  See COPYING in the top level directory
  * PROJECT:    ReactOS kernel
@@ -29,7 +29,7 @@ DriverEntry(PDRIVER_OBJECT DriverObject,
    
    DbgPrint("Mailslot FSD 0.0.1\n");
    
-   DeviceObject->Flags = 0;
+   DriverObject->Flags = 0;
    DriverObject->MajorFunction[IRP_MJ_CREATE] = MsfsCreate;
    DriverObject->MajorFunction[IRP_MJ_CREATE_MAILSLOT] =
      MsfsCreateMailslot;
@@ -66,7 +66,7 @@ DriverEntry(PDRIVER_OBJECT DriverObject,
      {
        return(Status);
      }
-   
+
    /* initialize device extension */
    DeviceExtension = DeviceObject->DeviceExtension;
    InitializeListHead(&DeviceExtension->MailslotListHead);
diff --git a/reactos/install.bochs b/reactos/install.bochs
deleted file mode 100644 (file)
index 9f08db2..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-#!/bin/sh
-/sbin/modprobe loop
-echo "Installing to disk."
-mount -t vfat /home/welch/devel/bochs/10M.vga.dos /mnt/floppy -o loop,offset=8704,rw
-cp -rv reactos /mnt/floppy
-umount /mnt/floppy
-
-
-
-
-
-
-
-
-
-
-
index 33e25f3..2e8580c 100644 (file)
@@ -50,7 +50,7 @@ NtSystemDebugControl(DEBUG_CONTROL_CODE ControlCode,
     case DebugQuerySpecialCalls:
     case DebugDbgBreakPoint:
       break;
-#ifdef DBG
+#ifdef KDBG
     case DebugDbgLoadSymbols:
       LdrLoadUserModuleSymbols((PLDR_MODULE) InputBuffer);
 #endif /* DBG */
index f21b333..44ddd9e 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: kd.h,v 1.10 2002/07/04 19:56:35 dwelch Exp $
+/* $Id: kd.h,v 1.11 2002/07/17 22:56:10 dwelch Exp $
  *
  * kernel debugger prototypes
  */
@@ -67,4 +67,14 @@ KdEnterDebuggerException(PEXCEPTION_RECORD ExceptionRecord,
 VOID KdInitializeMda(VOID);
 VOID KdPrintMda(PCH pch);
 
+#ifndef KDBG
+#define KDB_DELETEPROCESS_HOOK(PROCESS)
+#define KDB_LOADDRIVER_HOOK(MODULE)
+#define KDB_UNLOADDRIVER_HOOK(MODULE)
+#else
+#define KDB_DELETEPROCESS_HOOK(PROCESS) XXXX
+#define KDB_LOADDRIVER_HOOK(MODULE) XXXX
+#define KDB_UNLOADDRIVER_HOOK(MODULE) XXXX
+#endif /* KDBG */
+
 #endif /* __INCLUDE_INTERNAL_KERNEL_DEBUGGER_H */
index 14b1378..f96c610 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: pnpmgr.c,v 1.5 2002/06/10 23:03:33 ekohl Exp $
+/* $Id: pnpmgr.c,v 1.6 2002/07/17 22:56:10 dwelch Exp $
  *
  * COPYRIGHT:      See COPYING in the top level directory
  * PROJECT:        ReactOS kernel
@@ -350,7 +350,10 @@ IopCreateDeviceNode(PDEVICE_NODE ParentNode,
       KeAcquireSpinLock(&IopDeviceTreeLock, &OldIrql);
       Node->Parent = ParentNode;
       Node->NextSibling = ParentNode->Child;
-      ParentNode->Child->PrevSibling = Node;
+      if (ParentNode->Child != NULL)
+       {
+         ParentNode->Child->PrevSibling = Node;          
+       }
       ParentNode->Child = Node;
       KeReleaseSpinLock(&IopDeviceTreeLock, OldIrql);
     }
@@ -1061,17 +1064,6 @@ IopInterrogateBusExtender(
 
   DPRINT("Got %d PDOs\n", DeviceRelations->Count);
 
-#ifdef DBG
-  {
-    ULONG i;
-
-    DPRINT("DeviceRelations %x\n", DeviceRelations);
-    DPRINT("Count %x\n", DeviceRelations->Count);
-    for (i = 0; i < DeviceRelations->Count; i++)
-      DPRINT("Object(PDO) %x\n", DeviceRelations->Objects[i]);
-  }
-#endif
-
   /* Create device nodes for all discovered devices */
   for (i = 0; i < DeviceRelations->Count; i++)
   {
index 30bcc26..96efcdd 100644 (file)
 
 /* GLOBALS *****************************************************************/
 
-#ifdef DBG
-
-NTSTATUS
-LdrGetAddressInformation(IN PIMAGE_SYMBOL_INFO  SymbolInfo,
-  IN ULONG_PTR  RelativeAddress,
-  OUT PULONG LineNumber,
-  OUT PCH FileName  OPTIONAL,
-  OUT PCH FunctionName  OPTIONAL);
-
-#endif /* DBG */
-
 #define _STR(x) #x
 #define STR(x) _STR(x)
 
@@ -139,12 +128,6 @@ print_address(PVOID address)
    MODULE_TEXT_SECTION* current;
    extern LIST_ENTRY ModuleTextListHead;
    ULONG_PTR RelativeAddress;
-#ifdef DBG
-   NTSTATUS Status;
-   ULONG LineNumber;
-   CHAR FileName[256];
-   CHAR FunctionName[256];
-#endif
 
    current_entry = ModuleTextListHead.Flink;
    
@@ -158,25 +141,8 @@ print_address(PVOID address)
            address < (PVOID)(current->Base + current->Length))
          {
             RelativeAddress = (ULONG_PTR) address - current->Base;
-#ifdef DBG
-            Status = LdrGetAddressInformation(&current->SymbolInfo,
-              RelativeAddress,
-              &LineNumber,
-              FileName,
-              FunctionName);
-            if (NT_SUCCESS(Status))
-              {
-                DbgPrint("<%ws: %x (%s:%d (%s))>",
-                  current->Name, RelativeAddress, FileName, LineNumber, FunctionName);
-              }
-            else
-             {
-               DbgPrint("<%ws: %x>", current->Name, RelativeAddress);
-             }
-#else /* !DBG */
-             DbgPrint("<%ws: %x>", current->Name, RelativeAddress);
-#endif /* !DBG */
-            return(TRUE);
+           DbgPrint("<%ws: %x>", current->Name, RelativeAddress);
+           return(TRUE);
          }
        current_entry = current_entry->Flink;
      }
index 576f91d..619eded 100644 (file)
 
 /* GLOBALS *****************************************************************/
 
-#ifdef DBG
-
-NTSTATUS
-LdrGetAddressInformation(IN PIMAGE_SYMBOL_INFO  SymbolInfo,
-  IN ULONG_PTR  RelativeAddress,
-  OUT PULONG LineNumber,
-  OUT PCH FileName  OPTIONAL,
-  OUT PCH FunctionName  OPTIONAL);
-
-#endif /* DBG */
-
 static char *ExceptionTypeStrings[] = 
   {
     "Divide Error",
@@ -88,12 +77,6 @@ print_user_address(PVOID address)
    PEPROCESS CurrentProcess;
    PPEB Peb = NULL;
    ULONG_PTR RelativeAddress;
-#ifdef DBG
-   NTSTATUS Status;
-   ULONG LineNumber;
-   CHAR FileName[256];
-   CHAR FunctionName[256];
-#endif
 
    CurrentProcess = PsGetCurrentProcess();
    if (NULL != CurrentProcess)
@@ -118,27 +101,10 @@ print_user_address(PVOID address)
        if (address >= (PVOID)current->BaseAddress &&
            address < (PVOID)(current->BaseAddress + current->SizeOfImage))
          {
-            RelativeAddress = (ULONG_PTR) address - (ULONG_PTR)current->BaseAddress;
-#ifdef DBG
-            Status = LdrGetAddressInformation(&current->SymbolInfo,
-              RelativeAddress,
-              &LineNumber,
-              FileName,
-              FunctionName);
-            if (NT_SUCCESS(Status))
-              {
-                DbgPrint("<%wZ: %x (%s:%d (%s))>",
-                  &current->BaseDllName, RelativeAddress, FileName, LineNumber, FunctionName);
-              }
-            else
-             {
-               DbgPrint("<%wZ: %x>", &current->BaseDllName, RelativeAddress);
-             }
-#else /* !DBG */
-             DbgPrint("<%wZ: %x>", &current->BaseDllName, RelativeAddress);
-#endif /* !DBG */
-
-            return(TRUE);
+            RelativeAddress = 
+             (ULONG_PTR) address - (ULONG_PTR)current->BaseAddress;
+           DbgPrint("<%wZ: %x>", &current->BaseDllName, RelativeAddress);
+           return(TRUE);
          }
 
        current_entry = current_entry->Flink;
index b6a1584..dfe8d2d 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: loader.c,v 1.116 2002/07/17 21:04:56 dwelch Exp $
+/* $Id: loader.c,v 1.117 2002/07/17 22:56:11 dwelch Exp $
  * 
  * COPYRIGHT:       See COPYING in the top level directory
  * PROJECT:         ReactOS kernel
@@ -34,6 +34,7 @@
 #include <internal/ps.h>
 #include <internal/ldr.h>
 #include <internal/pool.h>
+#include <internal/kd.h>
 
 #ifdef HALDBG
 #include <internal/ntosdbg.h>
 
 /* GLOBALS *******************************************************************/
 
-#ifdef DBG
-
-typedef struct _SYMBOLFILE_HEADER {
-  unsigned long StabsOffset;
-  unsigned long StabsLength;
-  unsigned long StabstrOffset;
-  unsigned long StabstrLength;
-} SYMBOLFILE_HEADER, *PSYMBOLFILE_HEADER;
-
-typedef struct _IMAGE_SYMBOL_INFO_CACHE {
-  LIST_ENTRY ListEntry;
-  UNICODE_STRING FullName;
-  PVOID FileBuffer;
-  PVOID SymbolsBase;
-  ULONG SymbolsLength;
-  PVOID SymbolStringsBase;
-  ULONG SymbolStringsLength;
-} IMAGE_SYMBOL_INFO_CACHE, *PIMAGE_SYMBOL_INFO_CACHE;
-
-
-typedef struct _STAB_ENTRY {
-  unsigned long n_strx;         /* index into string table of name */
-  unsigned char n_type;         /* type of symbol */
-  unsigned char n_other;        /* misc info (usually empty) */
-  unsigned short n_desc;        /* description field */
-  unsigned long n_value;        /* value of symbol */
-} _STAB_ENTRY, *PSTAB_ENTRY;
-
-/*
- * Desc - Line number
- * Value - Relative virtual address
- */
-#define N_FUN 0x24
-
-/*
- * Desc - Line number
- * Value - Relative virtual address
- */
-#define N_SLINE 0x44
-
-/*
- * String - First containing a '/' is the compillation directory (CD)
- *          Not containing a '/' is a source file relative to CD
- */
-#define N_SO 0x64
-
-LIST_ENTRY SymbolListHead;
-
-#endif /* DBG */
-
 LIST_ENTRY ModuleListHead;
 KSPIN_LOCK ModuleListLock;
 
@@ -194,11 +145,6 @@ LdrInit1(VOID)
   NtoskrnlTextSection.Length = SectionList[0].Misc.VirtualSize +
     SectionList[0].VirtualAddress;
   NtoskrnlTextSection.Name = KERNEL_MODULE_NAME;
-#ifdef DBG
-  RtlZeroMemory(&NtoskrnlTextSection.SymbolInfo, sizeof(NtoskrnlTextSection.SymbolInfo));
-  NtoskrnlTextSection.SymbolInfo.ImageBase = OptionalHeader->ImageBase;
-  NtoskrnlTextSection.SymbolInfo.ImageSize = NtoskrnlTextSection.Length;
-#endif
   InsertTailList(&ModuleTextListHead, &NtoskrnlTextSection.ListEntry);
 
   /* Setup hal.dll text section */
@@ -214,16 +160,7 @@ LdrInit1(VOID)
   LdrHalTextSection.Length = SectionList[0].Misc.VirtualSize +
     SectionList[0].VirtualAddress;
   LdrHalTextSection.Name = HAL_MODULE_NAME;
-#ifdef DBG
-  RtlZeroMemory(&LdrHalTextSection.SymbolInfo, sizeof(LdrHalTextSection.SymbolInfo));
-  LdrHalTextSection.SymbolInfo.ImageBase = OptionalHeader->ImageBase;
-  LdrHalTextSection.SymbolInfo.ImageSize = LdrHalTextSection.Length;
-#endif
   InsertTailList(&ModuleTextListHead, &LdrHalTextSection.ListEntry);
-
-#ifdef DBG
-  InitializeListHead(&SymbolListHead);
-#endif
 }
 
 
@@ -299,546 +236,6 @@ LdrInitModuleManagement(VOID)
                 &ModuleObject->ListEntry);
 }
 
-#ifdef DBG
-
-VOID
-LdrpParseImageSymbols(PIMAGE_SYMBOL_INFO SymbolInfo)
-/* Note: It is important that the symbol strings buffer not be released after
-   this function is called because the strings are still referenced */
-{
-  PSYMBOL CurrentFileNameSymbol;
-  PSYMBOL CurrentFunctionSymbol;
-  PSYMBOL CurrentLineNumberSymbol;
-  PSYMBOL Symbol;
-  PSTAB_ENTRY StabEntry;
-  PVOID StabsEnd;
-  PCHAR String;
-  ULONG_PTR FunRelativeAddress;
-  ULONG FunLineNumber;
-  ULONG_PTR ImageBase;
-
-  assert(SymbolInfo);
-
-  DPRINT("Parsing symbols.\n");
-
-  SymbolInfo->FileNameSymbols.SymbolCount = 0;
-  SymbolInfo->FileNameSymbols.Symbols = NULL;
-  SymbolInfo->FunctionSymbols.SymbolCount = 0;
-  SymbolInfo->FunctionSymbols.Symbols = NULL;
-  SymbolInfo->LineNumberSymbols.SymbolCount = 0;
-  SymbolInfo->LineNumberSymbols.Symbols = NULL;
-  StabsEnd = SymbolInfo->SymbolsBase + SymbolInfo->SymbolsLength;
-  StabEntry = (PSTAB_ENTRY) SymbolInfo->SymbolsBase;
-  ImageBase = SymbolInfo->ImageBase;
-  FunRelativeAddress = 0;
-  FunLineNumber = 0;
-  CurrentFileNameSymbol = NULL;
-  CurrentFunctionSymbol = NULL;
-  CurrentLineNumberSymbol = NULL;
-  while ((ULONG_PTR) StabEntry < (ULONG_PTR) StabsEnd)
-    {
-      Symbol = NULL;
-
-      if (StabEntry->n_type == N_FUN)
-        {
-          if (StabEntry->n_desc > 0)
-            {
-              assert(StabEntry->n_value >= ImageBase);
-
-              FunRelativeAddress = StabEntry->n_value - ImageBase;
-              FunLineNumber = StabEntry->n_desc;
-
-              Symbol = ExAllocatePool(NonPagedPool, sizeof(SYMBOL));
-              assert(Symbol);
-              Symbol->Next = NULL;
-              Symbol->SymbolType = ST_FUNCTION;
-              Symbol->RelativeAddress = FunRelativeAddress;
-              Symbol->LineNumber = FunLineNumber;
-              String = (PCHAR)SymbolInfo->SymbolStringsBase + StabEntry->n_strx;
-              RtlInitAnsiString(&Symbol->Name, String);
-
-              DPRINT("FUN found. '%s' %d @ %x\n",
-                Symbol->Name.Buffer, FunLineNumber, FunRelativeAddress);
-            }
-        }
-      else if (StabEntry->n_type == N_SLINE)
-        {
-          Symbol = ExAllocatePool(NonPagedPool, sizeof(SYMBOL));
-          assert(Symbol);
-          Symbol->Next = NULL;
-          Symbol->SymbolType = ST_LINENUMBER;
-          Symbol->RelativeAddress = FunRelativeAddress + StabEntry->n_value;
-          Symbol->LineNumber = StabEntry->n_desc;
-
-          DPRINT("SLINE found. %d @ %x\n",
-            Symbol->LineNumber, Symbol->RelativeAddress);
-        }
-      else if (StabEntry->n_type == N_SO)
-        {
-          Symbol = ExAllocatePool(NonPagedPool, sizeof(SYMBOL));
-          assert(Symbol);
-          Symbol->Next = NULL;
-          Symbol->SymbolType = ST_FILENAME;
-          Symbol->RelativeAddress = StabEntry->n_value - ImageBase;
-          Symbol->LineNumber = 0;
-          String = (PCHAR)SymbolInfo->SymbolStringsBase + StabEntry->n_strx;
-          RtlInitAnsiString(&Symbol->Name, String);
-
-          DPRINT("SO found. '%s' @ %x\n",
-            Symbol->Name.Buffer, Symbol->RelativeAddress);
-        }
-
-      if (Symbol != NULL)
-        {
-          switch (Symbol->SymbolType)
-          {
-            case ST_FILENAME:
-              if (SymbolInfo->FileNameSymbols.Symbols == NULL)
-                SymbolInfo->FileNameSymbols.Symbols = Symbol;
-              else
-                CurrentFileNameSymbol->Next = Symbol;
-
-              CurrentFileNameSymbol = Symbol;
-
-              SymbolInfo->FileNameSymbols.SymbolCount++;
-              break;
-            case ST_FUNCTION:
-              if (SymbolInfo->FunctionSymbols.Symbols == NULL)
-                SymbolInfo->FunctionSymbols.Symbols = Symbol;
-              else
-                CurrentFunctionSymbol->Next = Symbol;
-
-              CurrentFunctionSymbol = Symbol;
-
-              SymbolInfo->FunctionSymbols.SymbolCount++;
-              break;
-            case ST_LINENUMBER:
-              if (SymbolInfo->LineNumberSymbols.Symbols == NULL)
-                SymbolInfo->LineNumberSymbols.Symbols = Symbol;
-              else
-                CurrentLineNumberSymbol->Next = Symbol;
-
-              CurrentLineNumberSymbol = Symbol;
-
-              SymbolInfo->LineNumberSymbols.SymbolCount++;
-              break;
-          }
-        }
-
-      StabEntry++;
-    }
-}
-
-static NTSTATUS
-LdrpGetFileName(IN PIMAGE_SYMBOL_INFO  SymbolInfo,
-  IN ULONG_PTR  RelativeAddress,
-  OUT PCH  FileName)
-{
-  PSYMBOL NextSymbol;
-  ULONG_PTR NextAddress;
-  PSYMBOL Symbol;
-
-  Symbol = SymbolInfo->FileNameSymbols.Symbols;
-  while (Symbol != NULL)
-    {
-      NextSymbol = Symbol->Next;
-      if (NextSymbol != NULL)
-        NextAddress = NextSymbol->RelativeAddress;
-      else
-        NextAddress = SymbolInfo->ImageSize;
-
-      DPRINT("FN SEARCH: Type %d  RelativeAddress %x >= Symbol->RelativeAddress %x  < NextAddress %x\n",
-        Symbol->SymbolType, RelativeAddress, Symbol->RelativeAddress, NextAddress);
-
-      if ((Symbol->SymbolType == ST_FILENAME) &&
-        (RelativeAddress >= Symbol->RelativeAddress) &&
-        (RelativeAddress < NextAddress))
-        {
-          DPRINT("FN found\n");
-          strcpy(FileName, Symbol->Name.Buffer);
-          return STATUS_SUCCESS;
-        }
-      Symbol = NextSymbol;
-    }
-
-  DPRINT("FN not found\n");
-
-  return STATUS_UNSUCCESSFUL;
-}
-
-static NTSTATUS
-LdrpGetFunctionName(IN PIMAGE_SYMBOL_INFO  SymbolInfo,
-  IN ULONG_PTR  RelativeAddress,
-  OUT PCH  FunctionName)
-{
-  PSYMBOL NextSymbol;
-  ULONG_PTR NextAddress;
-  PSYMBOL Symbol;
-
-  Symbol = SymbolInfo->FunctionSymbols.Symbols;
-  while (Symbol != NULL)
-    {
-      NextSymbol = Symbol->Next;
-      if (NextSymbol != NULL)
-        NextAddress = NextSymbol->RelativeAddress;
-      else
-        NextAddress = SymbolInfo->ImageSize;
-
-      DPRINT("FUN SEARCH: Type %d  RelativeAddress %x >= Symbol->RelativeAddress %x  < NextAddress %x\n",
-        Symbol->SymbolType, RelativeAddress, Symbol->RelativeAddress, NextAddress);
-
-      if ((Symbol->SymbolType == ST_FUNCTION) &&
-        (RelativeAddress >= Symbol->RelativeAddress) &&
-        (RelativeAddress < NextAddress))
-        {
-          PCHAR ExtraInfo;
-          ULONG Length;
-
-          DPRINT("FUN found\n");
-
-          /* Remove the extra information from the function name */
-          ExtraInfo = strchr(Symbol->Name.Buffer, ':');
-          if (ExtraInfo != NULL)
-            Length = ExtraInfo - Symbol->Name.Buffer;
-          else
-            Length = strlen(Symbol->Name.Buffer);
-
-          strncpy(FunctionName, Symbol->Name.Buffer, Length);
-          return STATUS_SUCCESS;
-        }
-      Symbol = NextSymbol;
-    }
-
-  DPRINT("FUN not found\n");
-
-  return STATUS_UNSUCCESSFUL;
-}
-
-static NTSTATUS
-LdrpGetLineNumber(IN PIMAGE_SYMBOL_INFO  SymbolInfo,
-  IN ULONG_PTR  RelativeAddress,
-  OUT PULONG  LineNumber)
-{
-  PSYMBOL NextSymbol;
-  ULONG_PTR NextAddress;
-  PSYMBOL Symbol;
-
-  Symbol = SymbolInfo->LineNumberSymbols.Symbols;
-  while (Symbol != NULL)
-    {
-      NextSymbol = Symbol->Next;
-      if (NextSymbol != NULL)
-        NextAddress = NextSymbol->RelativeAddress;
-      else
-        NextAddress = SymbolInfo->ImageSize;
-
-      DPRINT("LN SEARCH: Type %d  RelativeAddress %x >= Symbol->RelativeAddress %x  < NextAddress %x\n",
-        Symbol->SymbolType, RelativeAddress, Symbol->RelativeAddress, NextAddress);
-
-      if ((Symbol->SymbolType == ST_LINENUMBER) &&
-        (RelativeAddress >= Symbol->RelativeAddress) &&
-        (RelativeAddress < NextAddress))
-        {
-          DPRINT("LN found\n");
-          *LineNumber = Symbol->LineNumber;
-          return STATUS_SUCCESS;
-        }
-      Symbol = NextSymbol;
-    }
-
-  DPRINT("LN not found\n");
-
-  return STATUS_UNSUCCESSFUL;
-}
-
-NTSTATUS
-LdrGetAddressInformation(IN PIMAGE_SYMBOL_INFO  SymbolInfo,
-  IN ULONG_PTR  RelativeAddress,
-  OUT PULONG LineNumber,
-  OUT PCH FileName  OPTIONAL,
-  OUT PCH FunctionName  OPTIONAL)
-{
-  NTSTATUS Status;
-
-  *LineNumber = 0;
-
-  DPRINT("RelativeAddress %p\n", RelativeAddress);
-
-  if (RelativeAddress >= SymbolInfo->ImageSize)
-    {
-      DPRINT("Address is not within .text section. RelativeAddress %p  Length 0x%x\n",
-        RelativeAddress, SymbolInfo->ImageSize);
-      return STATUS_UNSUCCESSFUL;
-    }
-
-  if (!AreSymbolsParsed(SymbolInfo))
-    {
-      LdrpParseImageSymbols(SymbolInfo);
-    }
-
-  Status = LdrpGetLineNumber(SymbolInfo, RelativeAddress, LineNumber);
-  if (!NT_SUCCESS(Status))
-    {
-      return Status;
-    }
-
-  if (FileName)
-   {
-     Status = LdrpGetFileName(SymbolInfo, RelativeAddress, FileName);
-     if (!NT_SUCCESS(Status))
-       {
-         strcpy(FileName, "");
-       }
-   }
-
-  if (FunctionName)
-   {
-     Status = LdrpGetFunctionName(SymbolInfo, RelativeAddress, FunctionName);
-     if (!NT_SUCCESS(Status))
-       {
-         strcpy(FunctionName, "");
-       }
-   }
-
-  return STATUS_SUCCESS;
-}
-
-VOID
-LdrpLoadModuleSymbols(PUNICODE_STRING FileName,
-  PIMAGE_SYMBOL_INFO SymbolInfo)
-{
-  FILE_STANDARD_INFORMATION FileStdInfo;
-  OBJECT_ATTRIBUTES ObjectAttributes;
-  WCHAR TmpFileName[MAX_PATH];
-  UNICODE_STRING SymFileName;
-  LPWSTR Start, Ext;
-  HANDLE FileHandle;
-  PVOID FileBuffer;
-  NTSTATUS Status;
-  ULONG Length;
-  IO_STATUS_BLOCK IoStatusBlock;
-  PSYMBOLFILE_HEADER SymbolFileHeader;
-
-  /*  Get the path to the symbol store  */
-  wcscpy(TmpFileName, L"\\SystemRoot\\symbols\\");
-
-  /*  Get the symbol filename from the module name  */
-  Start = wcsrchr(FileName->Buffer, L'\\');
-  if (Start == NULL)
-    Start = FileName->Buffer;
-  else
-    Start++;
-
-  Ext = wcsrchr(FileName->Buffer, L'.');
-  if (Ext != NULL)
-    Length = Ext - Start;
-  else
-    Length = wcslen(Start);
-
-  wcsncat(TmpFileName, Start, Length);
-  wcscat(TmpFileName, L".sym");
-  RtlInitUnicodeString(&SymFileName, TmpFileName);
-
-  /*  Open the file  */
-  InitializeObjectAttributes(&ObjectAttributes,
-                             &SymFileName,
-                             0,
-                             NULL,
-                             NULL);
-
-  Status = ZwOpenFile(&FileHandle,
-                      FILE_ALL_ACCESS,
-                      &ObjectAttributes,
-                      &IoStatusBlock,
-                      0,
-                      0);
-  if (!NT_SUCCESS(Status))
-    {
-      DPRINT("Could not open symbol file: %wZ\n", &SymFileName);
-      return;
-    }
-
-  CPRINT("Loading symbols from %wZ...\n", &SymFileName);
-
-  /*  Get the size of the file  */
-  Status = ZwQueryInformationFile(FileHandle,
-                                  &IoStatusBlock,
-                                  &FileStdInfo,
-                                  sizeof(FileStdInfo),
-                                  FileStandardInformation);
-  if (!NT_SUCCESS(Status))
-    {
-      DPRINT("Could not get file size\n");
-      ZwClose(FileHandle);
-      return;
-    }
-
-  /*  Allocate nonpageable memory for symbol file  */
-  FileBuffer = ExAllocatePool(NonPagedPool,
-                              FileStdInfo.EndOfFile.u.LowPart);
-
-  if (FileBuffer == NULL)
-    {
-      DPRINT("Could not allocate memory for symbol file\n");
-      ZwClose(FileHandle);
-      return;
-    }
-   
-  /*  Load file into memory chunk  */
-  Status = ZwReadFile(FileHandle,
-                      0, 0, 0,
-                      &IoStatusBlock,
-                      FileBuffer,
-                      FileStdInfo.EndOfFile.u.LowPart,
-                      0, 0);
-  if (!NT_SUCCESS(Status))
-    {
-      DPRINT("Could not read symbol file into memory (Status 0x%x)\n", Status);
-      ExFreePool(FileBuffer);
-      ZwClose(FileHandle);
-      return;
-    }
-
-  ZwClose(FileHandle);
-
-  SymbolFileHeader = (PSYMBOLFILE_HEADER) FileBuffer;
-  SymbolInfo->FileBuffer = FileBuffer;
-  SymbolInfo->SymbolsBase = FileBuffer + SymbolFileHeader->StabsOffset;
-  SymbolInfo->SymbolsLength = SymbolFileHeader->StabsLength;
-  SymbolInfo->SymbolStringsBase = FileBuffer + SymbolFileHeader->StabstrOffset;
-  SymbolInfo->SymbolStringsLength = SymbolFileHeader->StabstrLength;
-}
-
-
-VOID
-LdrUnloadModuleSymbols(PIMAGE_SYMBOL_INFO SymbolInfo)
-{
-  PSYMBOL NextSymbol;
-  PSYMBOL Symbol;
-
-  DPRINT("Unloading symbols\n");
-
-  if (SymbolInfo != NULL)
-    {
-      Symbol = SymbolInfo->FileNameSymbols.Symbols;
-      while (Symbol != NULL)
-       {
-         NextSymbol = Symbol->Next;
-         RtlFreeAnsiString(&Symbol->Name);
-         ExFreePool(Symbol);
-         Symbol = NextSymbol;
-       }
-
-      SymbolInfo->FileNameSymbols.SymbolCount = 0;
-      SymbolInfo->FileNameSymbols.Symbols = NULL;
-
-      Symbol = SymbolInfo->FunctionSymbols.Symbols;
-      while (Symbol != NULL)
-       {
-         NextSymbol = Symbol->Next;
-         RtlFreeAnsiString(&Symbol->Name);
-         ExFreePool(Symbol);
-         Symbol = NextSymbol;
-       }
-
-      SymbolInfo->FunctionSymbols.SymbolCount = 0;
-      SymbolInfo->FunctionSymbols.Symbols = NULL;
-
-      Symbol = SymbolInfo->LineNumberSymbols.Symbols;
-      while (Symbol != NULL)
-       {
-         NextSymbol = Symbol->Next;
-         RtlFreeAnsiString(&Symbol->Name);
-         ExFreePool(Symbol);
-         Symbol = NextSymbol;
-       }
-
-      SymbolInfo->LineNumberSymbols.SymbolCount = 0;
-      SymbolInfo->LineNumberSymbols.Symbols = NULL;
-#if 0
-      /* Don't free buffers because we cache symbol buffers
-         (eg. they are shared across processes) */
-      /* FIXME: We can free them if we do reference counting */
-      if (SymbolInfo->FileBuffer != NULL)
-        {
-          ExFreePool(SymbolInfo->FileBuffer);
-          SymbolInfo->FileBuffer = NULL;
-          SymbolInfo->SymbolsBase = NULL;
-          SymbolInfo->SymbolsLength = 0;
-        }
-#endif
-    }
-}
-
-
-PIMAGE_SYMBOL_INFO_CACHE
-LdrpLookupUserSymbolInfo(PLDR_MODULE LdrModule)
-{
-  PIMAGE_SYMBOL_INFO_CACHE Current;
-  PLIST_ENTRY CurrentEntry;
-  KIRQL Irql;
-
-  DPRINT("Searching symbols for %S\n", LdrModule->FullDllName.Buffer);
-
-  KeAcquireSpinLock(&ModuleListLock,&Irql);
-
-  CurrentEntry = SymbolListHead.Flink;
-  while (CurrentEntry != (&SymbolListHead))
-    {
-      Current = CONTAINING_RECORD(CurrentEntry, IMAGE_SYMBOL_INFO_CACHE, ListEntry);
-
-      if (RtlEqualUnicodeString(&Current->FullName, &LdrModule->FullDllName, TRUE))
-        {
-          KeReleaseSpinLock(&ModuleListLock, Irql);
-          return Current;
-        }
-
-      CurrentEntry = CurrentEntry->Flink;
-    }
-
-  KeReleaseSpinLock(&ModuleListLock, Irql);
-
-  return(NULL);
-}
-
-
-VOID
-LdrLoadUserModuleSymbols(PLDR_MODULE LdrModule)
-{
-  PIMAGE_SYMBOL_INFO_CACHE CacheEntry;
-
-  DPRINT("LdrModule %p\n", LdrModule);
-
-  RtlZeroMemory(&LdrModule->SymbolInfo, sizeof(LdrModule->SymbolInfo));
-  LdrModule->SymbolInfo.ImageBase = (ULONG_PTR) LdrModule->BaseAddress;
-  LdrModule->SymbolInfo.ImageSize = LdrModule->SizeOfImage;
-
-  CacheEntry = LdrpLookupUserSymbolInfo(LdrModule);
-  if (CacheEntry != NULL)
-    {
-      DPRINT("Symbol cache hit for %S\n", CacheEntry->FullName.Buffer);
-   
-      LdrModule->SymbolInfo.FileBuffer = CacheEntry->FileBuffer;
-      LdrModule->SymbolInfo.SymbolsBase = CacheEntry->SymbolsBase;
-      LdrModule->SymbolInfo.SymbolsLength = CacheEntry->SymbolsLength;
-      LdrModule->SymbolInfo.SymbolStringsBase = CacheEntry->SymbolStringsBase;
-      LdrModule->SymbolInfo.SymbolStringsLength = CacheEntry->SymbolStringsLength;
-    }
-  else
-    {
-      CacheEntry = ExAllocatePool(NonPagedPool, sizeof(IMAGE_SYMBOL_INFO_CACHE));
-      assert(CacheEntry);
-      RtlZeroMemory(CacheEntry, sizeof(IMAGE_SYMBOL_INFO_CACHE));
-      RtlCreateUnicodeString(&CacheEntry->FullName, LdrModule->FullDllName.Buffer);
-      assert(CacheEntry->FullName.Buffer);
-      LdrpLoadModuleSymbols(&LdrModule->FullDllName, &LdrModule->SymbolInfo);
-      InsertTailList(&SymbolListHead, &CacheEntry->ListEntry);
-    }
-}
-
-#endif /* DBG */
-
-
 NTSTATUS
 LdrpLoadImage(PUNICODE_STRING DriverName,
              PVOID *ModuleBase,
@@ -1007,13 +404,11 @@ LdrLoadModule(PUNICODE_STRING Filename,
   /*  Cleanup  */
   ExFreePool(ModuleLoadBase);
 
-#ifdef DBG
-  /* Load symbols for the image if available */
-  LdrpLoadModuleSymbols(Filename, &Module->TextSection->SymbolInfo);
-#endif /* DBG */
-
   *ModuleObject = Module;
 
+  /* Hook for KDB on loading a driver. */
+  KDB_LOADDRIVER_HOOK(Module);
+
   return(STATUS_SUCCESS);
 }
 
@@ -1028,10 +423,8 @@ LdrUnloadModule(PMODULE_OBJECT ModuleObject)
   RemoveEntryList(&ModuleObject->ListEntry);
   KeReleaseSpinLock(&ModuleListLock, Irql);
 
-#ifdef DBG
-  /* Unload symbols for module if available */
-  LdrUnloadModuleSymbols(&ModuleObject->TextSection->SymbolInfo);
-#endif /* DBG */
+  /* Hook for KDB on unloading a driver. */
+  KDB_UNLOADDRIVER_HOOK(ModuleObject);
 
   /* Free text section */
   if (ModuleObject->TextSection != NULL)
@@ -1056,10 +449,6 @@ LdrInitializeBootStartDriver(PVOID ModuleLoadBase,
                             PCHAR FileName,
                             ULONG ModuleLength)
 {
-#ifdef DBG
-  PSYMBOLFILE_HEADER SymbolFileHeader;
-  PIMAGE_SYMBOL_INFO SymbolInfo;
-#endif /* DBG */
   PMODULE_OBJECT ModuleObject;
   UNICODE_STRING ModuleName;
   PDEVICE_NODE DeviceNode;
@@ -1074,12 +463,6 @@ LdrInitializeBootStartDriver(PVOID ModuleLoadBase,
   CHAR TextBuffer [256];
   ULONG x, y, cx, cy;
 
-#ifdef DBG
-  CHAR TmpBaseName[MAX_PATH];
-  CHAR TmpFileName[MAX_PATH];
-  ANSI_STRING AnsiString;
-#endif /* DBG */
-
   HalQueryDisplayParameters(&x, &y, &cx, &cy);
   RtlFillMemory(TextBuffer, x, ' ');
   TextBuffer[x] = '\0';
@@ -1098,53 +481,6 @@ LdrInitializeBootStartDriver(PVOID ModuleLoadBase,
   else
     Length = strlen(FileName);
 
-#ifdef DBG
-
-  if ((FileExt != NULL) && (strcmp(FileExt, ".sym") == 0))
-    {
-      DPRINT("Module %s is a symbol file\n", FileName);
-
-      strncpy(TmpBaseName, FileName, Length);
-      TmpBaseName[Length] = '\0';
-
-      DPRINT("base: %s (Length %d)\n", TmpBaseName, Length);
-
-      strcpy(TmpFileName, TmpBaseName);
-      strcat(TmpFileName, ".sys");
-      RtlInitAnsiString(&AnsiString, TmpFileName);
-
-      RtlAnsiStringToUnicodeString(&ModuleName, &AnsiString, TRUE);
-      ModuleObject = LdrGetModuleObject(&ModuleName);
-      RtlFreeUnicodeString(&ModuleName);
-      if (ModuleObject == NULL)
-       {
-         strcpy(TmpFileName, TmpBaseName);
-         strcat(TmpFileName, ".exe");
-         RtlInitAnsiString(&AnsiString, TmpFileName);
-         RtlAnsiStringToUnicodeString(&ModuleName, &AnsiString, TRUE);
-         ModuleObject = LdrGetModuleObject(&ModuleName);
-         RtlFreeUnicodeString(&ModuleName);
-       }
-      if (ModuleObject != NULL)
-       {
-          SymbolInfo = (PIMAGE_SYMBOL_INFO) &ModuleObject->TextSection->SymbolInfo;
-          SymbolFileHeader = (PSYMBOLFILE_HEADER) ModuleLoadBase;
-          SymbolInfo->FileBuffer = ModuleLoadBase;
-          SymbolInfo->SymbolsBase = ModuleLoadBase + SymbolFileHeader->StabsOffset;
-          SymbolInfo->SymbolsLength = SymbolFileHeader->StabsLength;
-          SymbolInfo->SymbolStringsBase = ModuleLoadBase + SymbolFileHeader->StabstrOffset;
-          SymbolInfo->SymbolStringsLength = SymbolFileHeader->StabstrLength;
-       }
-
-      return(STATUS_SUCCESS);
-    }
-  else
-    {
-      DPRINT("Module %s is non-symbol file\n", FileName);
-    }
-
-#endif /* !DBG */
-
   if ((FileExt != NULL) && !(strcmp(FileExt, ".sys") == 0))
     {
       CPRINT("Ignoring non-driver file %s\n", FileName);
@@ -1802,11 +1138,6 @@ LdrPEProcessModule(PVOID ModuleLoadBase,
   RtlZeroMemory(ModuleTextSection, sizeof(MODULE_TEXT_SECTION));
   ModuleTextSection->Base = (ULONG)DriverBase;
   ModuleTextSection->Length = DriverSize;
-#ifdef DBG
-  RtlZeroMemory(&ModuleTextSection->SymbolInfo, sizeof(ModuleTextSection->SymbolInfo));
-  ModuleTextSection->SymbolInfo.ImageBase = PEOptionalHeader->ImageBase;
-  ModuleTextSection->SymbolInfo.ImageSize = ModuleTextSection->Length;
-#endif /* DBG */
   ModuleTextSection->Name = 
     ExAllocatePool(NonPagedPool, 
                   (wcslen(NameBuffer) + 1) * sizeof(WCHAR));
index 771748b..ae09cba 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: process.c,v 1.86 2002/07/17 21:04:56 dwelch Exp $
+/* $Id: process.c,v 1.87 2002/07/17 22:56:11 dwelch Exp $
  *
  * COPYRIGHT:         See COPYING in the top level directory
  * PROJECT:           ReactOS kernel
@@ -27,6 +27,7 @@
 #include <internal/pool.h>
 #include <roscfg.h>
 #include <internal/se.h>
+#include <internal/kd.h>
 
 #define NDEBUG
 #include <internal/debug.h>
@@ -277,34 +278,6 @@ PsInitProcessManagment(VOID)
                  &SystemProcessHandle);
 }
 
-#ifdef DBG
-
-VOID
-PiFreeSymbols(PPEB Peb)
-{
-  PLIST_ENTRY CurrentEntry;
-  PLDR_MODULE Current;
-  PIMAGE_SYMBOL_INFO SymbolInfo;
-
-  assert (Peb);
-  assert (Peb->Ldr);
-
-  CurrentEntry = Peb->Ldr->InLoadOrderModuleList.Flink;
-  while (CurrentEntry != &Peb->Ldr->InLoadOrderModuleList && 
-        CurrentEntry != NULL)
-    {
-      Current = CONTAINING_RECORD(CurrentEntry, LDR_MODULE, 
-                                 InLoadOrderModuleList);
-
-      SymbolInfo = &Current->SymbolInfo;
-      LdrUnloadModuleSymbols(SymbolInfo);
-
-      CurrentEntry = CurrentEntry->Flink;
-    }
-}
-
-#endif /* DBG */
-
 VOID STDCALL
 PiDeleteProcess(PVOID ObjectBody)
 {
@@ -325,10 +298,8 @@ PiDeleteProcess(PVOID ObjectBody)
    RemoveEntryList(&Process->ProcessListEntry);
    KeReleaseSpinLock(&PsProcessListLock, oldIrql);
 
-#ifdef DBG
-   PiFreeSymbols(Process->Peb);
-#endif /* DBG */
-
+   /* KDB hook */
+   KDB_DELETEPROCESS_HOOK(Process);
 
    ObDereferenceObject(Process->Token);