Changeset 147
- Timestamp:
- Oct 29, 2006, 9:22:35 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/tools/qsysxcpt_pm.cpp
r146 r147 35 35 36 36 /* 37 * The below code is partly based on the except.h and except.c sources 38 * from the xwphelpers package (which is a part of the xworkplace product, see 39 * http://www.xworkplace.org, http://xworkplace.netlabs.org/ for more info). 40 * XWorkplace is Copyright (C) 1999-2002 Ulrich Moeller. 37 * The below code was started as a partial cut & paste from the except.h 38 * and except.c sources from the xwphelpers package (which is a part of the 39 * xworkplace product, see www.xworkplace.org, xworkplace.netlabs.org). 40 * XWorkplace is Copyright (C) 1999-2002 Ulrich Moeller. It has changed a lot 41 * since then, but thanks to XWP authors for a good example. 41 42 */ 42 43 … … 249 250 Writes information about a signle stack frame. 250 251 */ 251 static void qt_excWriteStackFrame ( FILE *file, ULONG ulPointer, ULONG ulAddress)252 static void qt_excWriteStackFrame (FILE *file, ULONG ulRegEbp, ULONG ulRegEip) 252 253 { 253 254 APIRET arc = NO_ERROR; 254 255 HMODULE hMod = NULLHANDLE; 255 char szMod[CCHMAXPATH] = "";256 char szMod[CCHMAXPATH] = ""; 256 257 ULONG ulObject = 0, 257 258 ulOffset = 0; 258 259 259 if (ulPointer) 260 fprintf (file, " <Frame pointer=\"%08lX\">\n", ulPointer); 261 else 262 fprintf (file, " <Frame pointer=\"current\">\n"); 263 264 fprintf (file, " <Location address=\"%08lX\">\n", ulAddress); 260 fprintf (file, " <Frame pointer=\"%08lX\">\n", ulRegEbp); 261 fprintf (file, " <Location address=\"%08lX\">\n", ulRegEip); 265 262 266 263 arc = DosQueryModFromEIP (&hMod, &ulObject, 267 264 sizeof (szMod), szMod, &ulOffset, 268 ul Address);265 ulRegEip); 269 266 270 267 if (arc != NO_ERROR) … … 272 269 szMod, arc); 273 270 else 274 {275 271 fprintf (file, " <Module ID=\"%04lX\" segment=\"%04lX\" " 276 272 "offset=\"%08lX\"/>\n", 277 273 hMod, ulObject + 1, ulOffset); 278 } 279 274 275 /* write a small memory dump with the location address in the middle */ 280 276 { 281 277 enum { enmDelta = 8 }; 282 UCHAR *pch = (UCHAR *) ul Address- enmDelta;283 UCHAR *pchEnd = (UCHAR *) ul Address+ enmDelta - 1;278 UCHAR *pch = (UCHAR *) ulRegEip - enmDelta; 279 UCHAR *pchEnd = (UCHAR *) ulRegEip + enmDelta - 1; 284 280 ULONG ulCount = enmDelta * 2; 285 281 ULONG ulFlags = 0; … … 292 288 if (ulCount >= enmDelta * 2) 293 289 break; 294 if (pch + ulCount <= (UCHAR *) ul Address)290 if (pch + ulCount <= (UCHAR *) ulRegEip) 295 291 { 296 292 /* ulAddress is outside the pch object */ … … 307 303 else if (arc == ERROR_INVALID_ADDRESS) 308 304 { 309 if (((ULONG) pch) & 0xFFFFF000 == ul Address& 0xFFFFF000)305 if (((ULONG) pch) & 0xFFFFF000 == ulRegEip & 0xFFFFF000) 310 306 break; /* the same page, ulAddress inaccessible */ 311 pch = (UCHAR *) (ul Address& 0xFFFFF000);307 pch = (UCHAR *) (ulRegEip & 0xFFFFF000); 312 308 } 313 309 } … … 318 314 for (; pch < pchEnd; ++pch) 319 315 fprintf (file, "%02lX%c", (ULONG) *pch, 320 ul Address- (ULONG) pch == 1 ? '-' : ' ');316 ulRegEip - (ULONG) pch == 1 ? '-' : ' '); 321 317 fprintf (file, "\n"); 322 318 } … … 327 323 } 328 324 329 fprintf (file, " </Location>\n" 330 325 fprintf (file, " </Location>\n"); 326 fprintf (file, " </Frame>\n"); 331 327 } 332 328 … … 337 333 PCONTEXTRECORD pContextRec) 338 334 { 339 PULONG pulStackWord = 0; 335 ULONG ulRegEbp = pContextRec->ctx_RegEbp; 336 ULONG ulRegEip = pContextRec->ctx_RegEip; 340 337 341 338 fprintf (file, " <Frames>\n"); 342 339 343 340 /* first the trapping address itself */ 344 qt_excWriteStackFrame (file, 0, pContextRec->ctx_RegEip); 345 346 pulStackWord = (PULONG) pContextRec->ctx_RegEbp; 347 348 while ( pulStackWord != 0 349 && pulStackWord < (PULONG) ptib->tib_pstacklimit) 350 { 351 if (((ULONG) pulStackWord & 0x00000FFF) == 0x00000000) 341 qt_excWriteStackFrame (file, ulRegEbp, ulRegEip); 342 343 /* first call to qt_excWriteStackFrame() is done before the EBP validity 344 * check below to get a chance to call qt_excWriteStackFrame() for the 345 * trapping address itself even if EBP there is invalid. */ 346 347 while (ulRegEbp != 0 && ulRegEbp < (ULONG) ptib->tib_pstacklimit) 348 { 349 /* skip the trapping stack frame -- already written above */ 350 if (pContextRec->ctx_RegEbp != ulRegEbp) 351 qt_excWriteStackFrame (file, ulRegEbp, ulRegEip); 352 353 if ((ulRegEbp & 0x00000FFF) == 0x00000000) 352 354 { 353 355 /* we're on a page boundary: check access */ 354 356 ULONG ulCount = 0x1000; 355 357 ULONG ulFlags = 0; 356 APIRET arc = DosQueryMem ((void *) pulStackWord, 357 &ulCount, &ulFlags); 358 APIRET arc = DosQueryMem ((void *) ulRegEbp, &ulCount, &ulFlags); 358 359 if ( (arc != NO_ERROR) 359 360 || ( arc == NO_ERROR … … 361 362 != (PAG_COMMIT|PAG_READ))) 362 363 { 363 fprintf (file, " <Frame pointer=\"%08lX\">\n", 364 (ULONG) pulStackWord); 364 fprintf (file, " <Frame pointer=\"%08lX\">\n", ulRegEbp); 365 365 qt_excWriteErrorMsg (file, 6, "DosQueryMem returned %lu " 366 366 "and flags %08lX", arc, ulFlags); 367 367 fprintf (file, " </Frame>\n"); 368 pulStackWord += 0x1000; 368 /* try go to the next page */ 369 /// @todo (r=dmik) I don't know how much it is accurate, 370 // I've just taken the logic from xwphelpers sources. 371 ulRegEbp += 0x1000; 369 372 continue; /* while */ 370 373 } 371 374 } 372 375 373 qt_excWriteStackFrame (file, (ULONG) pulStackWord, *(pulStackWord + 1)); 374 pulStackWord = (PULONG) *(pulStackWord); 375 } /* end while */ 376 /* get the return address of the current call */ 377 ulRegEip = *(((PULONG) ulRegEbp) + 1); 378 /* get the address of the outer stack frame */ 379 ulRegEbp = *((PULONG) ulRegEbp); 380 } 376 381 377 382 fprintf (file, " </Frames>\n"); … … 573 578 } 574 579 575 /* we do EBP validity check here as well as before the recursive call below 576 * to get a chance to translate EIP passed on the first call (as taken 577 * from the CONTEXTRECORD even if EBP there is invalid. */ 580 /* we do EBP validity check here as well as before the recursive 581 * call below to get a chance for the above code (EIP to hmod translation) 582 * to be executed even if EBP there is invalid. */ 583 578 584 if (pState->ulRegEbp != 0 && pState->ulRegEbp < pState->ulStackLimit) 579 585 { … … 593 599 { 594 600 /* try go to the next page */ 595 /// @todo (r=dmik) I 'm not sure how much it is correct,601 /// @todo (r=dmik) I don't know how much it is accurate, 596 602 // I've just taken the logic from xwphelpers sources. 597 603 pState->ulRegEbp += 0x1000; … … 602 608 } 603 609 604 /* get the return address to the previouscall */610 /* get the return address of the current call */ 605 611 pState->ulRegEip = *(((PULONG) pState->ulRegEbp) + 1); 606 612 /* get the address of the outer stack frame */ … … 717 723 718 724 /* first, the current thread */ 719 QSTREC *pThrdRec = pInfo-> pProcRec->pThrdRec;725 QSTREC *pThrdRec = pInfo->bHaveSysState ? pInfo->pProcRec->pThrdRec : NULL; 720 726 if (pThrdRec) 721 727 {
Note:
See TracChangeset
for help on using the changeset viewer.