[NTOSKRNL] Make the memory dumper available as a kdbg command: !poolused
authorPierre Schweitzer <pierre@reactos.org>
Fri, 29 Dec 2017 07:21:40 +0000 (08:21 +0100)
committerPierre Schweitzer <pierre@reactos.org>
Fri, 29 Dec 2017 16:23:36 +0000 (17:23 +0100)
ntoskrnl/kdbg/kdb_cli.c
ntoskrnl/mm/ARM3/expool.c

index f5e71bd..ff87f56 100644 (file)
@@ -92,6 +92,7 @@ static BOOLEAN KdbpCmdHelp(ULONG Argc, PCHAR Argv[]);
 static BOOLEAN KdbpCmdDmesg(ULONG Argc, PCHAR Argv[]);
 
 BOOLEAN ExpKdbgExtPool(ULONG Argc, PCHAR Argv[]);
+BOOLEAN ExpKdbgExtPoolUsed(ULONG Argc, PCHAR Argv[]);
 
 #ifdef __ROS_DWARF__
 static BOOLEAN KdbpCmdPrintStruct(ULONG Argc, PCHAR Argv[]);
@@ -183,7 +184,8 @@ static const struct
     { "dmesg", "dmesg", "Display debug messages on screen, with navigation on pages.", KdbpCmdDmesg },
     { "kmsg", "kmsg", "Kernel dmesg. Alias for dmesg.", KdbpCmdDmesg },
     { "help", "help", "Display help screen.", KdbpCmdHelp },
-    { "!pool", "!pool [Address [Flags]]", "Display information about pool allocations.", ExpKdbgExtPool }
+    { "!pool", "!pool [Address [Flags]]", "Display information about pool allocations.", ExpKdbgExtPool },
+    { "!poolused", "!poolused", "Display non-paged pool usage.", ExpKdbgExtPoolUsed },
 };
 
 /* FUNCTIONS *****************************************************************/
index 13a75be..129b3d0 100644 (file)
@@ -475,13 +475,23 @@ ExpTagAllowPrint(CHAR Tag)
     return FALSE;
 }
 
+#define MiDumperPrint(dbg, fmt, ...)        \
+    if (dbg) KdbpPrint(fmt, ##__VA_ARGS__); \
+    else DPRINT1(fmt, ##__VA_ARGS__)
+
 VOID
-MiDumpNonPagedPoolConsumers(VOID)
+MiDumpNonPagedPoolConsumers(BOOLEAN CalledFromDbg)
 {
     SIZE_T i;
 
-    DPRINT1("---------------------\n");
-    DPRINT1("Out of memory dumper!\n");
+    //
+    // Only print header if called from OOM situation
+    //
+    if (!CalledFromDbg)
+    {
+        DPRINT1("---------------------\n");
+        DPRINT1("Out of memory dumper!\n");
+    }
 
     //
     // We'll extract allocations for all the tracked pools
@@ -517,21 +527,24 @@ MiDumpNonPagedPoolConsumers(VOID)
                     //
                     // Print in reversed order to match what is in source code
                     //
-                    DPRINT1("Tag: '%c%c%c%c', Size: %ld\n", Tag[3], Tag[2], Tag[1], Tag[0], TableEntry->NonPagedBytes);
+                    MiDumperPrint(CalledFromDbg, "Tag: '%c%c%c%c', Size: %ld\n", Tag[3], Tag[2], Tag[1], Tag[0], TableEntry->NonPagedBytes);
                 }
                 else
                 {
-                    DPRINT1("Tag: %x, Size: %ld\n", TableEntry->Key, TableEntry->NonPagedBytes);
+                    MiDumperPrint(CalledFromDbg, "Tag: %x, Size: %ld\n", TableEntry->Key, TableEntry->NonPagedBytes);
                 }
             }
             else
             {
-                DPRINT1("Anon, Size: %ld\n", TableEntry->NonPagedBytes);
+                MiDumperPrint(CalledFromDbg, "Anon, Size: %ld\n", TableEntry->NonPagedBytes);
             }
         }
     }
 
-    DPRINT1("---------------------\n");
+    if (!CalledFromDbg)
+    {
+        DPRINT1("---------------------\n");
+    }
 }
 #endif
 
@@ -1722,7 +1735,7 @@ ExAllocatePoolWithTag(IN POOL_TYPE PoolType,
             //
             if ((OriginalType & BASE_POOL_TYPE_MASK) == NonPagedPool)
             {
-                MiDumpNonPagedPoolConsumers();
+                MiDumpNonPagedPoolConsumers(FALSE);
             }
 #endif
 
@@ -2058,7 +2071,7 @@ ExAllocatePoolWithTag(IN POOL_TYPE PoolType,
         //
         if ((OriginalType & BASE_POOL_TYPE_MASK) == NonPagedPool)
         {
-            MiDumpNonPagedPoolConsumers();
+            MiDumpNonPagedPoolConsumers(FALSE);
         }
 #endif
 
@@ -2914,6 +2927,16 @@ ExpKdbgExtPool(
     return TRUE;
 }
 
+BOOLEAN
+ExpKdbgExtPoolUsed(
+    ULONG Argc,
+    PCHAR Argv[])
+{
+    MiDumpNonPagedPoolConsumers(TRUE);
+
+    return TRUE;
+}
+
 #endif // DBG && KDBG
 
 /* EOF */