Changeset 9274 in vbox
- Timestamp:
- May 31, 2008 6:47:25 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/VMM/DBGFDisas.cpp
r9273 r9274 19 19 * additional information or have any questions. 20 20 */ 21 22 #define USE_DIS_FORMAT23 21 24 22 /******************************************************************************* … … 103 101 Assert((uintptr_t)GCPtr == GCPtr); 104 102 uint32_t cbInstr; 105 #ifdef USE_DIS_FORMAT106 103 int rc = DISCoreOneEx(GCPtr, 107 104 pSelInfo->Raw.Gen.u1DefBig … … 114 111 &pState->Cpu, 115 112 &cbInstr); 116 #else117 pState->Cpu.mode = pSelInfo->Raw.Gen.u1DefBig ? CPUMODE_32BIT : CPUMODE_16BIT;118 pState->Cpu.pfnReadBytes = dbgfR3DisasInstrRead;119 int rc = DISInstr(&pState->Cpu, GCPtr, 0, &cbInstr, NULL);120 #endif121 113 if (VBOX_SUCCESS(rc)) 122 114 { … … 245 237 246 238 247 #ifdef USE_DIS_FORMAT248 239 /** 249 240 * @copydoc FNDISGETSYMBOL … … 285 276 return rc; 286 277 } 287 #else288 /**289 * Copy a string and return pointer to the terminator char in the copy.290 */291 inline char *mystrpcpy(char *pszDst, const char *pszSrc)292 {293 size_t cch = strlen(pszSrc);294 memcpy(pszDst, pszSrc, cch + 1);295 return pszDst + cch;296 }297 #endif298 278 299 279 … … 417 397 * Format it. 418 398 */ 419 #ifdef USE_DIS_FORMAT420 399 char szBuf[512]; 421 400 DISFormatYasmEx(&State.Cpu, szBuf, sizeof(szBuf), … … 423 402 fFlags & DBGF_DISAS_FLAGS_NO_SYMBOLS ? NULL : dbgfR3DisasGetSymbol, 424 403 &SelInfo); 425 #else426 char szBuf[512];427 char *psz = &szBuf[0];428 429 /* prefix */430 if (State.Cpu.prefix & PREFIX_LOCK)431 psz = (char *)memcpy(psz, "lock ", sizeof("lock ")) + sizeof("lock ") - 1;432 if (State.Cpu.prefix & PREFIX_REP)433 psz = (char *)memcpy(psz, "rep(e) ", sizeof("rep(e) ")) + sizeof("rep(e) ") - 1;434 else if(State.Cpu.prefix & PREFIX_REPNE)435 psz = (char *)memcpy(psz, "repne ", sizeof("repne ")) + sizeof("repne ") - 1;436 437 /* the instruction */438 const char *pszFormat = State.Cpu.pszOpcode;439 char ch;440 while ((ch = *pszFormat) && !isspace(ch) && ch != '%')441 {442 *psz++ = ch;443 pszFormat++;444 }445 if (isspace(ch))446 {447 do *psz++ = ' ';448 #ifdef DEBUG_bird /* Not sure if Sander want's this because of log size */449 while (psz - szBuf < 8);450 #else451 while (0);452 #endif453 while (isspace(*pszFormat))454 pszFormat++;455 }456 457 if (fFlags & DBGF_DISAS_FLAGS_NO_ANNOTATION)458 pCtxCore = NULL;459 460 /** @todo implement annotation and symbol lookup! */461 int iParam = 1;462 for (;;)463 {464 ch = *pszFormat;465 if (ch == '%')466 {467 ch = pszFormat[1];468 switch (ch)469 {470 /*471 * Relative jump offset.472 */473 case 'J':474 {475 AssertMsg(iParam == 1, ("Invalid branch parameter nr %d\n", iParam));476 int32_t i32Disp;477 if (State.Cpu.param1.flags & USE_IMMEDIATE8_REL)478 i32Disp = (int32_t)(int8_t)State.Cpu.param1.parval;479 else if (State.Cpu.param1.flags & USE_IMMEDIATE16_REL)480 i32Disp = (int32_t)(int16_t)State.Cpu.param1.parval;481 else if (State.Cpu.param1.flags & USE_IMMEDIATE32_REL)482 i32Disp = (int32_t)State.Cpu.param1.parval;483 else484 {485 AssertMsgFailed(("Oops!\n"));486 dbgfR3DisasInstrDone(&State);487 return VERR_GENERAL_FAILURE;488 }489 RTGCUINTPTR GCPtrTarget = (RTGCUINTPTR)GCPtr + State.Cpu.opsize + i32Disp;490 switch (State.Cpu.opmode)491 {492 case CPUMODE_16BIT: GCPtrTarget &= UINT16_MAX; break;493 case CPUMODE_32BIT: GCPtrTarget &= UINT32_MAX; break;494 case CPUMODE_64BIT: GCPtrTarget &= UINT64_MAX; break;495 default: break;496 }497 #ifdef DEBUG_bird /* an experiment. */498 DBGFSYMBOL Sym;499 RTGCINTPTR off;500 int rc = DBGFR3SymbolByAddr(pVM, GCPtrTarget + SelInfo.GCPtrBase, &off, &Sym);501 if ( VBOX_SUCCESS(rc)502 && Sym.Value - SelInfo.GCPtrBase <= SelInfo.cbLimit503 && off < _1M * 16 && off > -_1M * 16)504 {505 psz += RTStrPrintf(psz, &szBuf[sizeof(szBuf)] - psz, "%s", Sym.szName);506 if (off > 0)507 psz += RTStrPrintf(psz, &szBuf[sizeof(szBuf)] - psz, "+%#x", (int)off);508 else if (off > 0)509 psz += RTStrPrintf(psz, &szBuf[sizeof(szBuf)] - psz, "-%#x", -(int)off);510 switch (State.Cpu.opmode)511 {512 case CPUMODE_16BIT:513 psz += RTStrPrintf(psz, &szBuf[sizeof(szBuf)] - psz,514 i32Disp >= 0 ? " (%04VGv/+%x)" : " (%04VGv/-%x)",515 GCPtrTarget, i32Disp >= 0 ? i32Disp : -i32Disp);516 break;517 case CPUMODE_32BIT:518 psz += RTStrPrintf(psz, &szBuf[sizeof(szBuf)] - psz,519 i32Disp >= 0 ? " (%08VGv/+%x)" : " (%08VGv/-%x)",520 GCPtrTarget, i32Disp >= 0 ? i32Disp : -i32Disp);521 break;522 default:523 psz += RTStrPrintf(psz, &szBuf[sizeof(szBuf)] - psz,524 i32Disp >= 0 ? " (%VGv/+%x)" : " (%VGv/-%x)",525 GCPtrTarget, i32Disp >= 0 ? i32Disp : -i32Disp);526 break;527 }528 }529 else530 #endif /* DEBUG_bird */531 {532 switch (State.Cpu.opmode)533 {534 case CPUMODE_16BIT:535 psz += RTStrPrintf(psz, &szBuf[sizeof(szBuf)] - psz,536 i32Disp >= 0 ? "%04VGv (+%x)" : "%04VGv (-%x)",537 GCPtrTarget, i32Disp >= 0 ? i32Disp : -i32Disp);538 break;539 case CPUMODE_32BIT:540 psz += RTStrPrintf(psz, &szBuf[sizeof(szBuf)] - psz,541 i32Disp >= 0 ? "%08VGv (+%x)" : "%08VGv (-%x)",542 GCPtrTarget, i32Disp >= 0 ? i32Disp : -i32Disp);543 break;544 default:545 psz += RTStrPrintf(psz, &szBuf[sizeof(szBuf)] - psz,546 i32Disp >= 0 ? "%VGv (+%x)" : "%VGv (-%x)",547 GCPtrTarget, i32Disp >= 0 ? i32Disp : -i32Disp);548 break;549 }550 }551 break;552 }553 554 case 'A': //direct address555 case 'C': //control register556 case 'D': //debug register557 case 'E': //ModRM specifies parameter558 case 'F': //Eflags register559 case 'G': //ModRM selects general register560 case 'I': //Immediate data561 case 'M': //ModRM may only refer to memory562 case 'O': //No ModRM byte563 case 'P': //ModRM byte selects MMX register564 case 'Q': //ModRM byte selects MMX register or memory address565 case 'R': //ModRM byte may only refer to a general register566 case 'S': //ModRM byte selects a segment register567 case 'T': //ModRM byte selects a test register568 case 'V': //ModRM byte selects an XMM/SSE register569 case 'W': //ModRM byte selects an XMM/SSE register or a memory address570 case 'X': //DS:SI571 case 'Y': //ES:DI572 switch (iParam)573 {574 case 1: psz = mystrpcpy(psz, State.Cpu.param1.szParam); break;575 case 2: psz = mystrpcpy(psz, State.Cpu.param2.szParam); break;576 case 3: psz = mystrpcpy(psz, State.Cpu.param3.szParam); break;577 }578 pszFormat += 2;579 break;580 581 case 'e': //register based on operand size (e.g. %eAX)582 if (State.Cpu.opmode == CPUMODE_32BIT)583 *psz++ = 'E';584 *psz++ = pszFormat[2];585 *psz++ = pszFormat[3];586 pszFormat += 4;587 break;588 589 default:590 AssertMsgFailed(("Oops! ch=%c\n", ch));591 break;592 }593 594 /* Skip to the next parameter in the format string. */595 pszFormat = strchr(pszFormat, ',');596 if (!pszFormat)597 break;598 pszFormat++;599 *psz++ = ch = ',';600 iParam++;601 }602 else603 {604 /* output char, but check for parameter separator first. */605 if (ch == ',')606 iParam++;607 *psz++ = ch;608 if (!ch)609 break;610 pszFormat++;611 }612 613 #ifdef DEBUG_bird /* Not sure if Sander want's this because of log size */614 /* space after commas */615 if (ch == ',')616 {617 while (isspace(*pszFormat))618 pszFormat++;619 *psz++ = ' ';620 }621 #endif622 } /* foreach char in pszFormat */623 *psz = '\0';624 #endif /* !USE_DIS_FORMAT */625 404 626 405 /*
Note:
See TracChangeset
for help on using the changeset viewer.