VirtualBox

source: vbox/trunk/src/VBox/VMM/DBGFDisas.cpp@ 2505

Last change on this file since 2505 was 2302, checked in by vboxsync, 18 years ago

style

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 24.9 KB
Line 
1/* $Id: DBGFDisas.cpp 2302 2007-04-21 00:22:50Z vboxsync $ */
2/** @file
3 * VMM DBGF - Debugger Facility, Disassembler.
4 */
5
6/*
7 * Copyright (C) 2006 InnoTek Systemberatung GmbH
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License as published by the Free Software Foundation,
13 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
14 * distribution. VirtualBox OSE is distributed in the hope that it will
15 * be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * If you received this file as part of a commercial VirtualBox
18 * distribution, then only the terms of your commercial VirtualBox
19 * license agreement apply instead of the previous paragraph.
20 */
21
22
23/*******************************************************************************
24* Header Files *
25*******************************************************************************/
26#define LOG_GROUP LOG_GROUP_DBGF
27#include <VBox/dbgf.h>
28#include <VBox/selm.h>
29#include <VBox/mm.h>
30#include <VBox/pgm.h>
31#include "DBGFInternal.h"
32#include <VBox/dis.h>
33#include <VBox/err.h>
34#include <VBox/param.h>
35
36#include <VBox/log.h>
37#include <iprt/assert.h>
38#include <iprt/string.h>
39#include <iprt/alloca.h>
40#include <iprt/ctype.h>
41
42
43/*******************************************************************************
44* Internal Functions *
45*******************************************************************************/
46static DECLCALLBACK(int32_t) dbgfR3DisasInstrRead(RTHCUINTPTR pSrc, uint8_t *pDest, uint32_t size, RTHCUINTPTR dwUserdata);
47
48
49/**
50 * Structure used when disassembling and instructions in DBGF.
51 * This is used so the reader function can get the stuff it needs.
52 */
53typedef struct
54{
55 /** The core structure. */
56 DISCPUSTATE Cpu;
57 /** The VM handle. */
58 PVM pVM;
59 /** Pointer to the first byte in the segemnt. */
60 RTGCUINTPTR GCPtrSegBase;
61 /** Pointer to the byte after the end of the segment. (might have wrapped!) */
62 RTGCUINTPTR GCPtrSegEnd;
63 /** The size of the segment minus 1. */
64 RTGCUINTPTR cbSegLimit;
65 /** The guest paging mode. */
66 PGMMODE enmMode;
67 /** Pointer to the current page - HC Ptr. */
68 void *pvPageHC;
69 /** Pointer to the current page - GC Ptr. */
70 RTGCPTR pvPageGC;
71 /** The rc of the operation.
72 * @todo r=bird: it's rather annoying that we have to keep track of the status code of the operation.
73 * When we've got time we should adjust the disassembler to use VBox status codes and not
74 * boolean returns.
75 */
76 int rc;
77 /** Pointer to the next instruction (relative to GCPtrSegBase). */
78 RTGCUINTPTR GCPtrNext;
79} DBGFDISASSTATE, *PDBGFDISASSTATE;
80
81
82
83/**
84 * Calls the dissassembler with the proper reader functions and such for disa
85 *
86 * @returns VBox status code.
87 * @param pVM VM handle
88 * @param pSelInfo The selector info.
89 * @param enmMode The guest paging mode.
90 * @param GCPtr The GC pointer (selector offset).
91 * @param pState The disas CPU state.
92 */
93static int dbgfR3DisasInstrFirst(PVM pVM, PSELMSELINFO pSelInfo, PGMMODE enmMode, RTGCPTR GCPtr, PDBGFDISASSTATE pState)
94{
95 pState->Cpu.mode = pSelInfo->Raw.Gen.u1DefBig ? CPUMODE_32BIT : CPUMODE_16BIT;
96 pState->Cpu.pfnReadBytes = dbgfR3DisasInstrRead;
97 pState->GCPtrSegBase = pSelInfo->GCPtrBase;
98 pState->GCPtrSegEnd = pSelInfo->cbLimit + 1 + (RTGCUINTPTR)pSelInfo->GCPtrBase;
99 pState->cbSegLimit = pSelInfo->cbLimit;
100 pState->enmMode = enmMode;
101 pState->pvPageGC = 0;
102 pState->pvPageHC = NULL;
103 pState->rc = VINF_SUCCESS;
104 pState->pVM = pVM;
105 Assert((uintptr_t)GCPtr == GCPtr);
106 uint32_t cbInstr;
107 if (DISInstr(&pState->Cpu, GCPtr, 0, &cbInstr, NULL))
108 {
109 pState->GCPtrNext = GCPtr + cbInstr;
110 return VINF_SUCCESS;
111 }
112 if (VBOX_FAILURE(pState->rc))
113 return pState->rc;
114 return VERR_GENERAL_FAILURE;
115}
116
117
118#if 0
119/**
120 * Calls the dissassembler for disassembling the next instruction.
121 *
122 * @returns VBox status code.
123 * @param pState The disas CPU state.
124 */
125static int dbgfR3DisasInstrNext(PDBGFDISASSTATE pState)
126{
127 pState->rc = VINF_SUCCESS;
128 uint32_t cbInstr;
129 if (DISInstr(&pState->Cpu, (void *)pState->GCPtrNext, 0, &cbInstr, NULL))
130 {
131 pState->GCPtrNext = GCPtr + cbInstr;
132 return VINF_SUCCESS;
133 }
134 if (VBOX_FAILURE(pState->rc))
135 return pState->rc;
136 return VERR_GENERAL_FAILURE;
137}
138#endif
139
140
141/**
142 * Instruction reader.
143 *
144 * @returns VBox status code. (Why this is a int32_t and not just an int is also beyond me.)
145 * @param PtrSrc Address to read from.
146 * In our case this is relative to the selector pointed to by the 2nd user argument of uDisCpu.
147 * @param pu8Dst Where to store the bytes.
148 * @param cbRead Number of bytes to read.
149 * @param uDisCpu Pointer to the disassembler cpu state. (Why this is a VBOXHUINTPTR is beyond me...)
150 * In this context it's always pointer to the Core of a DBGFDISASSTATE.
151 */
152static DECLCALLBACK(int32_t) dbgfR3DisasInstrRead(RTHCUINTPTR PtrSrc, uint8_t *pu8Dst, uint32_t cbRead, RTHCUINTPTR uDisCpu)
153{
154 PDBGFDISASSTATE pState = (PDBGFDISASSTATE)uDisCpu;
155 Assert(cbRead > 0);
156 for (;;)
157 {
158 RTGCUINTPTR GCPtr = PtrSrc + pState->GCPtrSegBase;
159
160 /* Need to update the page translation? */
161 if ( !pState->pvPageHC
162 || (GCPtr >> PAGE_SHIFT) != (pState->pvPageGC >> PAGE_SHIFT))
163 {
164 /* translate the address */
165 pState->pvPageGC = GCPtr & PAGE_BASE_GC_MASK;
166 if (MMHyperIsInsideArea(pState->pVM, pState->pvPageGC))
167 {
168 pState->pvPageHC = MMHyperGC2HC(pState->pVM, pState->pvPageGC);
169 if (!pState->pvPageHC)
170 pState->rc = VERR_INVALID_POINTER;
171 }
172 else if (pState->enmMode <= PGMMODE_PROTECTED)
173 pState->rc = PGMPhysGCPhys2HCPtr(pState->pVM, pState->pvPageGC, PAGE_SIZE, &pState->pvPageHC);
174 else
175 pState->rc = PGMPhysGCPtr2HCPtr(pState->pVM, pState->pvPageGC, &pState->pvPageHC);
176 if (VBOX_FAILURE(pState->rc))
177 {
178 pState->pvPageHC = NULL;
179 return pState->rc;
180 }
181 }
182
183 /* check the segemnt limit */
184 if (PtrSrc > pState->cbSegLimit)
185 return pState->rc = VERR_OUT_OF_SELECTOR_BOUNDS;
186
187 /* calc how much we can read */
188 uint32_t cb = PAGE_SIZE - (GCPtr & PAGE_OFFSET_MASK);
189 RTGCUINTPTR cbSeg = pState->GCPtrSegEnd - GCPtr;
190 if (cb > cbSeg && cbSeg)
191 cb = cbSeg;
192 if (cb > cbRead)
193 cb = cbRead;
194
195 /* read and advance */
196 memcpy(pu8Dst, (char *)pState->pvPageHC + (GCPtr & PAGE_OFFSET_MASK), cb);
197 cbRead -= cb;
198 if (!cbRead)
199 return VINF_SUCCESS;
200 pu8Dst += cb;
201 PtrSrc += cb;
202 }
203}
204
205
206/**
207 * Copy a string and return pointer to the terminator char in the copy.
208 */
209inline char *mystrpcpy(char *pszDst, const char *pszSrc)
210{
211 size_t cch = strlen(pszSrc);
212 memcpy(pszDst, pszSrc, cch + 1);
213 return pszDst + cch;
214}
215
216
217/**
218 * Disassembles the one instruction according to the specified flags and address.
219 *
220 * @returns VBox status code.
221 * @param pVM VM handle.
222 * @param Sel The code selector. This used to determin the 32/16 bit ness and
223 * calculation of the actual instruction address.
224 * @param GCPtr The code address relative to the base of Sel.
225 * @param fFlags Flags controlling where to start and how to format.
226 * A combination of the DBGF_DISAS_FLAGS_* \#defines.
227 * @param pszOutput Output buffer.
228 * @param cchOutput Size of the output buffer.
229 * @param pcbInstr Where to return the size of the instruction.
230 */
231DBGFR3DECL(int) DBGFR3DisasInstrEx(PVM pVM, RTSEL Sel, RTGCPTR GCPtr, unsigned fFlags, char *pszOutput, uint32_t cchOutput, uint32_t *pcbInstr)
232{
233 /*
234 * Get the Sel and GCPtr if fFlags requests that.
235 */
236 PCCPUMCTXCORE pCtxCore = NULL;
237 CPUMSELREGHID *pHiddenSel = NULL;
238 int rc;
239 if (fFlags & (DBGF_DISAS_FLAGS_CURRENT_GUEST | DBGF_DISAS_FLAGS_CURRENT_HYPER))
240 {
241 if (fFlags & DBGF_DISAS_FLAGS_CURRENT_GUEST)
242 pCtxCore = CPUMGetGuestCtxCore(pVM);
243 else
244 pCtxCore = CPUMGetHyperCtxCore(pVM);
245 Sel = pCtxCore->cs;
246 pHiddenSel = (CPUMSELREGHID *)&pCtxCore->csHid;
247 GCPtr = pCtxCore->eip;
248 }
249
250 /*
251 * Read the selector info - assume no stale selectors and nasty stuff like that.
252 * Since the selector flags in the CPUMCTX structures aren't up to date unless
253 * we recently visited REM, we'll not search for the selector there.
254 */
255 SELMSELINFO SelInfo;
256 const PGMMODE enmMode = PGMGetGuestMode(pVM);
257 bool fRealModeAddress = false;
258
259 if ( pHiddenSel
260 && CPUMAreHiddenSelRegsValid(pVM))
261 {
262 SelInfo.GCPtrBase = pHiddenSel->u32Base;
263 SelInfo.cbLimit = pHiddenSel->u32Limit;
264 SelInfo.fHyper = false;
265 SelInfo.fRealMode = !!(pCtxCore && pCtxCore->eflags.Bits.u1VM || enmMode == PGMMODE_REAL);
266 SelInfo.Raw.au32[0] = 0;
267 SelInfo.Raw.au32[1] = 0;
268 SelInfo.Raw.Gen.u16LimitLow = ~0;
269 SelInfo.Raw.Gen.u4LimitHigh = ~0;
270 SelInfo.Raw.Gen.u1Present = pHiddenSel->Attr.n.u1Present;
271 SelInfo.Raw.Gen.u1Granularity = pHiddenSel->Attr.n.u1Granularity;;
272 SelInfo.Raw.Gen.u1DefBig = pHiddenSel->Attr.n.u1DefBig;
273 SelInfo.Raw.Gen.u1DescType = pHiddenSel->Attr.n.u1DescType;
274 SelInfo.Raw.Gen.u4Type = pHiddenSel->Attr.n.u4Type;
275 fRealModeAddress = SelInfo.fRealMode;
276 }
277 else if ( !(fFlags & DBGF_DISAS_FLAGS_CURRENT_HYPER)
278 && ( (pCtxCore && pCtxCore->eflags.Bits.u1VM)
279 || enmMode == PGMMODE_REAL) )
280 { /* V86 mode or real mode - real mode addressing */
281 SelInfo.GCPtrBase = Sel * 16;
282 SelInfo.cbLimit = ~0;
283 SelInfo.fHyper = false;
284 SelInfo.fRealMode = true;
285 SelInfo.Raw.au32[0] = 0;
286 SelInfo.Raw.au32[1] = 0;
287 SelInfo.Raw.Gen.u16LimitLow = ~0;
288 SelInfo.Raw.Gen.u4LimitHigh = ~0;
289 SelInfo.Raw.Gen.u1Present = 1;
290 SelInfo.Raw.Gen.u1Granularity = 1;
291 SelInfo.Raw.Gen.u1DefBig = 0; /* 16 bits */
292 SelInfo.Raw.Gen.u1DescType = 1;
293 SelInfo.Raw.Gen.u4Type = X86_SEL_TYPE_EO;
294 fRealModeAddress = true;
295 }
296 else if (Sel == DBGF_SEL_FLAT)
297 {
298 SelInfo.GCPtrBase = 0;
299 SelInfo.cbLimit = ~0;
300 SelInfo.fHyper = false;
301 SelInfo.fRealMode = false;
302 SelInfo.Raw.au32[0] = 0;
303 SelInfo.Raw.au32[1] = 0;
304 SelInfo.Raw.Gen.u16LimitLow = ~0;
305 SelInfo.Raw.Gen.u4LimitHigh = ~0;
306 SelInfo.Raw.Gen.u1Present = 1;
307 SelInfo.Raw.Gen.u1Granularity = 1;
308 SelInfo.Raw.Gen.u1DefBig = 1;
309 SelInfo.Raw.Gen.u1DescType = 1;
310 SelInfo.Raw.Gen.u4Type = X86_SEL_TYPE_EO;
311 }
312 else
313 {
314 rc = SELMR3GetSelectorInfo(pVM, Sel, &SelInfo);
315 if (VBOX_FAILURE(rc))
316 {
317 RTStrPrintf(pszOutput, cchOutput, "Sel=%04x -> %Vrc\n", Sel, rc);
318 return rc;
319 }
320 }
321
322 /*
323 * Disassemble it.
324 */
325 DBGFDISASSTATE State;
326 rc = dbgfR3DisasInstrFirst(pVM, &SelInfo, enmMode, GCPtr, &State);
327 if (VBOX_FAILURE(rc))
328 {
329 RTStrPrintf(pszOutput, cchOutput, "Disas -> %Vrc\n", rc);
330 return rc;
331 }
332
333 /*
334 * Format it.
335 */
336 char szBuf[512];
337 char *psz = &szBuf[0];
338
339 /* prefix */
340 if (State.Cpu.prefix & PREFIX_LOCK)
341 psz = (char *)memcpy(psz, "lock ", sizeof("lock ")) + sizeof("lock ") - 1;
342 if (State.Cpu.prefix & PREFIX_REP)
343 psz = (char *)memcpy(psz, "rep(e) ", sizeof("rep(e) ")) + sizeof("rep(e) ") - 1;
344 else if(State.Cpu.prefix & PREFIX_REPNE)
345 psz = (char *)memcpy(psz, "repne ", sizeof("repne ")) + sizeof("repne ") - 1;
346
347 /* the instruction */
348 const char *pszFormat = State.Cpu.pszOpcode;
349 char ch;
350 while ((ch = *pszFormat) && !isspace(ch) && ch != '%')
351 {
352 *psz++ = ch;
353 pszFormat++;
354 }
355 if (isspace(ch))
356 {
357 do *psz++ = ' ';
358#ifdef DEBUG_bird /* Not sure if Sander want's this because of log size */
359 while (psz - szBuf < 8);
360#else
361 while (0);
362#endif
363 while (isspace(*pszFormat))
364 pszFormat++;
365 }
366
367 if (fFlags & DBGF_DISAS_FLAGS_NO_ANNOTATION)
368 pCtxCore = NULL;
369
370 /** @todo implement annotation and symbol lookup! */
371 int iParam = 1;
372 for (;;)
373 {
374 ch = *pszFormat;
375 if (ch == '%')
376 {
377 ch = pszFormat[1];
378 switch (ch)
379 {
380 /*
381 * Relative jump offset.
382 */
383 case 'J':
384 {
385 AssertMsg(iParam == 1, ("Invalid branch parameter nr %d\n", iParam));
386 int32_t i32Disp;
387 if (State.Cpu.param1.flags & USE_IMMEDIATE8_REL)
388 i32Disp = (int32_t)(int8_t)State.Cpu.param1.parval;
389 else if (State.Cpu.param1.flags & USE_IMMEDIATE16_REL)
390 i32Disp = (int32_t)(int16_t)State.Cpu.param1.parval;
391 else if (State.Cpu.param1.flags & USE_IMMEDIATE32_REL)
392 i32Disp = (int32_t)State.Cpu.param1.parval;
393 else
394 {
395 AssertMsgFailed(("Oops!\n"));
396 return VERR_GENERAL_FAILURE;
397 }
398 RTGCUINTPTR GCPtrTarget = (RTGCUINTPTR)GCPtr + State.Cpu.opsize + i32Disp;
399 switch (State.Cpu.opmode)
400 {
401 case CPUMODE_16BIT: GCPtrTarget &= UINT16_MAX; break;
402 case CPUMODE_32BIT: GCPtrTarget &= UINT32_MAX; break;
403 }
404#ifdef DEBUG_bird /* an experiment. */
405 DBGFSYMBOL Sym;
406 RTGCINTPTR off;
407 int rc = DBGFR3SymbolByAddr(pVM, GCPtrTarget + SelInfo.GCPtrBase, &off, &Sym);
408 if ( VBOX_SUCCESS(rc)
409 && Sym.Value - SelInfo.GCPtrBase <= SelInfo.cbLimit
410 && off < _1M * 16 && off > -_1M * 16)
411 {
412 psz += RTStrPrintf(psz, &szBuf[sizeof(szBuf)] - psz, "%s", Sym.szName);
413 if (off > 0)
414 psz += RTStrPrintf(psz, &szBuf[sizeof(szBuf)] - psz, "+%#x", (int)off);
415 else if (off > 0)
416 psz += RTStrPrintf(psz, &szBuf[sizeof(szBuf)] - psz, "-%#x", -(int)off);
417 switch (State.Cpu.opmode)
418 {
419 case CPUMODE_16BIT:
420 psz += RTStrPrintf(psz, &szBuf[sizeof(szBuf)] - psz,
421 i32Disp >= 0 ? " (%04VGv/+%x)" : " (%04VGv/-%x)",
422 GCPtrTarget, i32Disp >= 0 ? i32Disp : -i32Disp);
423 break;
424 case CPUMODE_32BIT:
425 psz += RTStrPrintf(psz, &szBuf[sizeof(szBuf)] - psz,
426 i32Disp >= 0 ? " (%08VGv/+%x)" : " (%08VGv/-%x)",
427 GCPtrTarget, i32Disp >= 0 ? i32Disp : -i32Disp);
428 break;
429 default:
430 psz += RTStrPrintf(psz, &szBuf[sizeof(szBuf)] - psz,
431 i32Disp >= 0 ? " (%VGv/+%x)" : " (%VGv/-%x)",
432 GCPtrTarget, i32Disp >= 0 ? i32Disp : -i32Disp);
433 break;
434 }
435 }
436 else
437#endif /* DEBUG_bird */
438 {
439 switch (State.Cpu.opmode)
440 {
441 case CPUMODE_16BIT:
442 psz += RTStrPrintf(psz, &szBuf[sizeof(szBuf)] - psz,
443 i32Disp >= 0 ? "%04VGv (+%x)" : "%04VGv (-%x)",
444 GCPtrTarget, i32Disp >= 0 ? i32Disp : -i32Disp);
445 break;
446 case CPUMODE_32BIT:
447 psz += RTStrPrintf(psz, &szBuf[sizeof(szBuf)] - psz,
448 i32Disp >= 0 ? "%08VGv (+%x)" : "%08VGv (-%x)",
449 GCPtrTarget, i32Disp >= 0 ? i32Disp : -i32Disp);
450 break;
451 default:
452 psz += RTStrPrintf(psz, &szBuf[sizeof(szBuf)] - psz,
453 i32Disp >= 0 ? "%VGv (+%x)" : "%VGv (-%x)",
454 GCPtrTarget, i32Disp >= 0 ? i32Disp : -i32Disp);
455 break;
456 }
457 }
458 break;
459 }
460
461 case 'A': //direct address
462 case 'C': //control register
463 case 'D': //debug register
464 case 'E': //ModRM specifies parameter
465 case 'F': //Eflags register
466 case 'G': //ModRM selects general register
467 case 'I': //Immediate data
468 case 'M': //ModRM may only refer to memory
469 case 'O': //No ModRM byte
470 case 'P': //ModRM byte selects MMX register
471 case 'Q': //ModRM byte selects MMX register or memory address
472 case 'R': //ModRM byte may only refer to a general register
473 case 'S': //ModRM byte selects a segment register
474 case 'T': //ModRM byte selects a test register
475 case 'V': //ModRM byte selects an XMM/SSE register
476 case 'W': //ModRM byte selects an XMM/SSE register or a memory address
477 case 'X': //DS:SI
478 case 'Y': //ES:DI
479 switch (iParam)
480 {
481 case 1: psz = mystrpcpy(psz, State.Cpu.param1.szParam); break;
482 case 2: psz = mystrpcpy(psz, State.Cpu.param2.szParam); break;
483 case 3: psz = mystrpcpy(psz, State.Cpu.param3.szParam); break;
484 }
485 pszFormat += 2;
486 break;
487
488 case 'e': //register based on operand size (e.g. %eAX)
489 if (State.Cpu.opmode == CPUMODE_32BIT)
490 *psz++ = 'E';
491 *psz++ = pszFormat[2];
492 *psz++ = pszFormat[3];
493 pszFormat += 4;
494 break;
495
496 default:
497 AssertMsgFailed(("Oops! ch=%c\n", ch));
498 break;
499 }
500
501 /* Skip to the next parameter in the format string. */
502 pszFormat = strchr(pszFormat, ',');
503 if (!pszFormat)
504 break;
505 pszFormat++;
506 *psz++ = ch = ',';
507 iParam++;
508 }
509 else
510 {
511 /* output char, but check for parameter separator first. */
512 if (ch == ',')
513 iParam++;
514 *psz++ = ch;
515 if (!ch)
516 break;
517 pszFormat++;
518 }
519
520#ifdef DEBUG_bird /* Not sure if Sander want's this because of log size */
521 /* space after commas */
522 if (ch == ',')
523 {
524 while (isspace(*pszFormat))
525 pszFormat++;
526 *psz++ = ' ';
527 }
528#endif
529 } /* foreach char in pszFormat */
530 *psz = '\0';
531
532 /*
533 * Print it to the user specified buffer.
534 */
535 if (fFlags & DBGF_DISAS_FLAGS_NO_BYTES)
536 {
537 if (fFlags & DBGF_DISAS_FLAGS_NO_ADDRESS)
538 RTStrPrintf(pszOutput, cchOutput, "%s", szBuf);
539 else if (fRealModeAddress)
540 RTStrPrintf(pszOutput, cchOutput, "%04x:%04x %s", Sel, (unsigned)GCPtr, szBuf);
541 else if (Sel == DBGF_SEL_FLAT)
542 RTStrPrintf(pszOutput, cchOutput, "%VGv %s", GCPtr, szBuf);
543 else
544 RTStrPrintf(pszOutput, cchOutput, "%04x:%VGv %s", Sel, GCPtr, szBuf);
545 }
546 else
547 {
548 size_t cbBits = State.Cpu.opsize;
549 uint8_t *pau8Bits = (uint8_t *)alloca(cbBits);
550 rc = dbgfR3DisasInstrRead(GCPtr, pau8Bits, cbBits, (uintptr_t)&State);
551 AssertRC(rc);
552 if (fFlags & DBGF_DISAS_FLAGS_NO_ADDRESS)
553 RTStrPrintf(pszOutput, cchOutput, "%.*Vhxs%*s %s",
554 cbBits, pau8Bits, cbBits < 8 ? (8 - cbBits) * 3 : 0, "",
555 szBuf);
556 else if (fRealModeAddress)
557 RTStrPrintf(pszOutput, cchOutput, "%04x:%04x %.*Vhxs%*s %s",
558 Sel, (unsigned)GCPtr,
559 cbBits, pau8Bits, cbBits < 8 ? (8 - cbBits) * 3 : 0, "",
560 szBuf);
561 else if (Sel == DBGF_SEL_FLAT)
562 RTStrPrintf(pszOutput, cchOutput, "%VGv %.*Vhxs%*s %s",
563 GCPtr,
564 cbBits, pau8Bits, cbBits < 8 ? (8 - cbBits) * 3 : 0, "",
565 szBuf);
566 else
567 RTStrPrintf(pszOutput, cchOutput, "%04x:%VGv %.*Vhxs%*s %s",
568 Sel, GCPtr,
569 cbBits, pau8Bits, cbBits < 8 ? (8 - cbBits) * 3 : 0, "",
570 szBuf);
571
572 }
573
574 if (pcbInstr)
575 *pcbInstr = State.Cpu.opsize;
576 return VINF_SUCCESS;
577}
578
579
580/**
581 * Disassembles an instruction.
582 * Addresses will be tried resolved to symbols
583 *
584 * @returns VBox status code.
585 * @param pVM VM handle.
586 * @param Sel The code selector. This used to determin the 32/16 bit ness and
587 * calculation of the actual instruction address.
588 * @param GCPtr The code address relative to the base of Sel.
589 * @param pszOutput Output buffer.
590 * @param cchOutput Size of the output buffer.
591 */
592DBGFR3DECL(int) DBGFR3DisasInstr(PVM pVM, RTSEL Sel, RTGCPTR GCPtr, char *pszOutput, uint32_t cchOutput)
593{
594 return DBGFR3DisasInstrEx(pVM, Sel, GCPtr, 0, pszOutput, cchOutput, NULL);
595}
596
597
598/**
599 * Disassembles the current guest context instruction.
600 * All registers and data will be displayed. Addresses will be attempted resolved to symbols.
601 *
602 * @returns VBox status code.
603 * @param pVM VM handle.
604 * @param pszOutput Output buffer.
605 * @param cchOutput Size of the output buffer.
606 */
607DBGFR3DECL(int) DBGFR3DisasInstrCurrent(PVM pVM, char *pszOutput, uint32_t cchOutput)
608{
609 return DBGFR3DisasInstrEx(pVM, 0, 0, DBGF_DISAS_FLAGS_CURRENT_GUEST, pszOutput, cchOutput, NULL);
610}
611
612
613/**
614 * Disassembles the current guest context instruction and writes it to the log.
615 * All registers and data will be displayed. Addresses will be attempted resolved to symbols.
616 *
617 * @returns VBox status code.
618 * @param pVM VM handle.
619 * @param pszPrefix Short prefix string to the dissassembly string. (optional)
620 */
621DBGFR3DECL(int) DBGFR3DisasInstrCurrentLogInternal(PVM pVM, const char *pszPrefix)
622{
623 char szBuf[256];
624 szBuf[0] = '\0';
625 int rc = DBGFR3DisasInstrCurrent(pVM, &szBuf[0], sizeof(szBuf));
626 if (VBOX_FAILURE(rc))
627 RTStrPrintf(szBuf, sizeof(szBuf), "DBGFR3DisasInstrCurrentLog failed with rc=%Vrc\n", rc);
628 if (pszPrefix && *pszPrefix)
629 RTLogPrintf("%s: %s\n", pszPrefix, szBuf);
630 else
631 RTLogPrintf("%s\n", szBuf);
632 return rc;
633}
634
635
636
637/**
638 * Disassembles the specified guest context instruction and writes it to the log.
639 * Addresses will be attempted resolved to symbols.
640 *
641 * @returns VBox status code.
642 * @param pVM VM handle.
643 * @param Sel The code selector. This used to determin the 32/16 bit-ness and
644 * calculation of the actual instruction address.
645 * @param GCPtr The code address relative to the base of Sel.
646 */
647DBGFR3DECL(int) DBGFR3DisasInstrLogInternal(PVM pVM, RTSEL Sel, RTGCPTR GCPtr)
648{
649 char szBuf[256];
650 szBuf[0] = '\0';
651 int rc = DBGFR3DisasInstr(pVM, Sel, GCPtr, &szBuf[0], sizeof(szBuf));
652 if (VBOX_FAILURE(rc))
653 RTStrPrintf(szBuf, sizeof(szBuf), "DBGFR3DisasInstrLog(, %RTsel, %RGv) failed with rc=%Vrc\n", Sel, GCPtr, rc);
654 RTLogPrintf("%s\n", szBuf);
655 return rc;
656}
657
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette