Index: trunk/src/tools/qsysxcpt_pm.cpp
===================================================================
--- trunk/src/tools/qsysxcpt_pm.cpp	(revision 144)
+++ trunk/src/tools/qsysxcpt_pm.cpp	(revision 145)
@@ -216,14 +216,27 @@
     {
         APIRET arc;
-        ULONG ulCountPages = 1;
-        ULONG ulFlagsPage = 0;
-        arc = DosQueryMem( (PVOID) ulValue, &ulCountPages, &ulFlagsPage );
+        ULONG ulCount = 4;
+        ULONG ulFlags = 0;
+        arc = DosQueryMem( (PVOID) ulValue, &ulCount, &ulFlags );
     
         if ( arc == NO_ERROR || arc == ERROR_INVALID_ADDRESS )
         {
             if ( arc == NO_ERROR )
-                fprintf( file, " flags=\"%08lX\"/>\n", ulFlagsPage );
+            {
+                fprintf( file, " flags=\"%08lX\"", ulFlags );
+                if ( ulFlags & (PAG_COMMIT | PAG_READ) == (PAG_COMMIT | PAG_READ) )
+                    fprintf( file, " word=\"%08lX\"/>\n", *(ULONG *) ulValue );
+                else
+                    fprintf( file, "/>\n" );
+            }
             else
                 fprintf( file, " flags=\"invalid\"/>\n" );
+        }
+        else
+        {
+            fprintf( file, ">\n" );
+            qt_excWriteErrorMsg( file, 6, "DosQueryMem returned %lu"
+                                 "and flags %08lX", arc, ulFlags );
+            fprintf( file, "     </Register>\n" );
         }
     }
@@ -247,24 +260,22 @@
     else
         fprintf( file, "     <Frame pointer=\"current\">\n" );
-            
-    if ( ulAddress )
-    {
-        fprintf( file, "      <Location address=\"%08lX\">\n", ulAddress );
-    
-        arc = DosQueryModFromEIP( &hMod, &ulObject,
-                                  sizeof(szMod), szMod, &ulOffset,
-                                  ulAddress );
-    
-        if (arc != NO_ERROR)
-            qt_excWriteErrorMsg( file, 6, "%s: DosQueryModFromEIP returned %lu",
-                                 szMod, arc );
-        else
-        {
-            DosQueryModuleName( hMod, sizeof(szMod), szMod );
-            fprintf( file, "       <Module ID=\"%04lX\" name=\"", hMod );
-            qt_excEscapeString( file, szMod ); 
-            fprintf( file, "\" \n"
-                           "               segment=\"%04lX\" offset=\"%08lX\"/>\n",
-                     ulObject + 1, ulOffset ); 
+
+    fprintf( file, "      <Location address=\"%08lX\">\n", ulAddress );
+    
+    arc = DosQueryModFromEIP( &hMod, &ulObject,
+                              sizeof(szMod), szMod, &ulOffset,
+                              ulAddress );
+
+    if (arc != NO_ERROR)
+        qt_excWriteErrorMsg( file, 7, "%s: DosQueryModFromEIP returned %lu",
+                             szMod, arc );
+    else
+    {
+        DosQueryModuleName( hMod, sizeof(szMod), szMod );
+        fprintf( file, "       <Module ID=\"%04lX\" name=\"", hMod );
+        qt_excEscapeString( file, szMod ); 
+        fprintf( file, "\" \n"
+                       "               segment=\"%04lX\" offset=\"%08lX\"/>\n",
+                 ulObject + 1, ulOffset ); 
 /// @todo (r=dmik) use .DBG and .SYM files to get symbols
 //  (see debug.h and debug.c from the xwphelpers package) 
@@ -273,8 +284,52 @@
 //                           ulObject,
 //                           ulOffset);
-        }
-    }
-    else
-        qt_excWriteErrorMsg( file, 5, "Unable to access stack frame" );
+    }
+
+    {
+        enum { enmDelta = 8 };
+        UCHAR *pch = (UCHAR *) ulAddress - enmDelta;
+        UCHAR *pchEnd = (UCHAR *) ulAddress + enmDelta - 1;
+        ULONG ulCount = enmDelta * 2;
+        ULONG ulFlags = 0;
+        APIRET arc = NO_ERROR;
+        while ( 1 )
+        {
+            arc = DosQueryMem( (void *) (ULONG) pch, &ulCount, &ulFlags );
+            if ( arc == NO_ERROR )
+            {
+                if ( ulCount >= enmDelta * 2 )
+                    break;
+                if ( pch + ulCount <= (UCHAR *) ulAddress )
+                {   // ulAddress is outside the pch object
+                    pch += ulCount;
+                    ulCount = enmDelta * 2 - ulCount;
+                }
+                else
+                {   // ulAddress is within the pch object
+                    pchEnd = pch += ulCount;
+                    break;
+                }
+            }
+            else if ( arc == ERROR_INVALID_ADDRESS )
+            {
+                if ( ((ULONG) pch) & 0xFFFFF000 == ulAddress & 0xFFFFF000 )
+                    break; // the same page, ulAddress inaccessible
+                pch = (UCHAR *) (ulAddress & 0xFFFFF000);
+            }
+        }
+        fprintf( file, "       <Dump address=\"%08lX\">\n        ", pch );
+        if ( arc == NO_ERROR &&
+             ulFlags & (PAG_COMMIT|PAG_READ) == (PAG_COMMIT | PAG_READ) )
+        {
+            for ( ; pch < pchEnd; ++pch )
+                fprintf( file, "%02lX%c", (ULONG) *pch,
+                         ulAddress - (ULONG) pch == 1 ? '-' : ' ' );
+            fprintf( file, "\n" );
+        }
+        else
+            qt_excWriteErrorMsg( file, 0, "%08lX: DosQueryMem returned %lu"
+                                 "and flags %08lX", pch, arc, ulFlags );
+        fprintf( file, "       </Dump>\n" );
+    }
     
     fprintf( file, "      </Location>\n"
@@ -303,19 +358,17 @@
         {
             // we're on a page boundary: check access
-            ULONG ulCountPages = 0x1000;
-            ULONG ulFlagsPage = 0;
-            APIRET arc = DosQueryMem( (void *)pulStackWord,
-                                      &ulCountPages, &ulFlagsPage );
+            ULONG ulCount = 0x1000;
+            ULONG ulFlags = 0;
+            APIRET arc = DosQueryMem( (void *) pulStackWord,
+                                      &ulCount, &ulFlags );
             if (    (arc != NO_ERROR)
                  || (   arc == NO_ERROR
-                     && (ulFlagsPage & (PAG_COMMIT|PAG_READ))
+                     && (ulFlags & (PAG_COMMIT|PAG_READ))
                          != (PAG_COMMIT|PAG_READ)) )
             {
                 fprintf( file, "     <Frame pointer=\"%08lX\">\n",
                          (ULONG) pulStackWord );
-                qt_excWriteErrorMsg( file, 6,
-                                     "Unable to access stack frame, DosQueryMem "
-                                     "returned %lu and flags %08lX",
-                                     arc, ulFlagsPage );
+                qt_excWriteErrorMsg( file, 6, "DosQueryMem returned %lu "
+                                     "and flags %08lX", arc, ulFlags );
                 fprintf( file, "     </Frame>\n" );
                 pulStackWord += 0x1000;
