VirtualBox

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

Last change on this file since 400 was 23, checked in by vboxsync, 18 years ago

string.h & stdio.h + header cleanups.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 23.9 KB
Line 
1/* $Id: DBGFDisas.cpp 23 2007-01-15 14:08:28Z 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, &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 int rc;
238 if (fFlags & (DBGF_DISAS_FLAGS_CURRENT_GUEST | DBGF_DISAS_FLAGS_CURRENT_HYPER))
239 {
240 if (fFlags & DBGF_DISAS_FLAGS_CURRENT_GUEST)
241 pCtxCore = CPUMGetGuestCtxCore(pVM);
242 else
243 pCtxCore = CPUMGetHyperCtxCore(pVM);
244 Sel = pCtxCore->cs;
245 GCPtr = pCtxCore->eip;
246 }
247
248 /*
249 * Read the selector info - assume no stale selectors and nasty stuff like that.
250 * Since the selector flags in the CPUMCTX structures aren't up to date unless
251 * we recently visited REM, we'll not search for the selector there.
252 */
253 SELMSELINFO SelInfo;
254 const PGMMODE enmMode = PGMGetGuestMode(pVM);
255 bool fRealModeAddress = false;
256 if ( (pCtxCore && pCtxCore->eflags.Bits.u1VM == 1)
257 || enmMode == PGMMODE_REAL)
258 { /* V86 mode or real mode - real mode addressing */
259 SelInfo.GCPtrBase = Sel * 16;
260 SelInfo.cbLimit = ~0;
261 SelInfo.fHyper = false;
262 SelInfo.fRealMode = true;
263 SelInfo.Raw.au32[0] = 0;
264 SelInfo.Raw.au32[1] = 0;
265 SelInfo.Raw.Gen.u16LimitLow = ~0;
266 SelInfo.Raw.Gen.u4LimitHigh = ~0;
267 SelInfo.Raw.Gen.u1Present = 1;
268 SelInfo.Raw.Gen.u1Granularity = 1;
269 SelInfo.Raw.Gen.u1DefBig = 0; /* 16 bits */
270 SelInfo.Raw.Gen.u1DescType = 1;
271 SelInfo.Raw.Gen.u4Type = X86_SEL_TYPE_EO;
272 fRealModeAddress = true;
273 }
274 else if (Sel == DBGF_SEL_FLAT)
275 {
276 SelInfo.GCPtrBase = 0;
277 SelInfo.cbLimit = ~0;
278 SelInfo.fHyper = false;
279 SelInfo.fRealMode = false;
280 SelInfo.Raw.au32[0] = 0;
281 SelInfo.Raw.au32[1] = 0;
282 SelInfo.Raw.Gen.u16LimitLow = ~0;
283 SelInfo.Raw.Gen.u4LimitHigh = ~0;
284 SelInfo.Raw.Gen.u1Present = 1;
285 SelInfo.Raw.Gen.u1Granularity = 1;
286 SelInfo.Raw.Gen.u1DefBig = 1;
287 SelInfo.Raw.Gen.u1DescType = 1;
288 SelInfo.Raw.Gen.u4Type = X86_SEL_TYPE_EO;
289 }
290 else
291 {
292 rc = SELMR3GetSelectorInfo(pVM, Sel, &SelInfo);
293 if (VBOX_FAILURE(rc))
294 {
295 RTStrPrintf(pszOutput, cchOutput, "Sel=%04x -> %Vrc\n", Sel, rc);
296 return rc;
297 }
298 }
299
300 /*
301 * Disassemble it.
302 */
303 DBGFDISASSTATE State;
304 rc = dbgfR3DisasInstrFirst(pVM, &SelInfo, enmMode, GCPtr, &State);
305 if (VBOX_FAILURE(rc))
306 {
307 RTStrPrintf(pszOutput, cchOutput, "Disas -> %Vrc\n", rc);
308 return rc;
309 }
310
311 /*
312 * Format it.
313 */
314 char szBuf[512];
315 char *psz = &szBuf[0];
316
317 /* prefix */
318 if (State.Cpu.prefix & PREFIX_LOCK)
319 psz = (char *)memcpy(psz, "lock ", sizeof("lock ")) + sizeof("lock ") - 1;
320 if (State.Cpu.prefix & PREFIX_REP)
321 psz = (char *)memcpy(psz, "rep(e) ", sizeof("rep(e) ")) + sizeof("rep(e) ") - 1;
322 else if(State.Cpu.prefix & PREFIX_REPNE)
323 psz = (char *)memcpy(psz, "repne ", sizeof("repne ")) + sizeof("repne ") - 1;
324
325 /* the instruction */
326 const char *pszFormat = State.Cpu.pszOpcode;
327 char ch;
328 while ((ch = *pszFormat) && !isspace(ch) && ch != '%')
329 {
330 *psz++ = ch;
331 pszFormat++;
332 }
333 if (isspace(ch))
334 {
335 do *psz++ = ' ';
336#ifdef DEBUG_bird /* Not sure if Sander want's this because of log size */
337 while (psz - szBuf < 8);
338#else
339 while (0);
340#endif
341 while (isspace(*pszFormat))
342 pszFormat++;
343 }
344
345 if (fFlags & DBGF_DISAS_FLAGS_NO_ANNOTATION)
346 pCtxCore = NULL;
347
348 /** @todo implement annotation and symbol lookup! */
349 int iParam = 1;
350 for (;;)
351 {
352 ch = *pszFormat;
353 if (ch == '%')
354 {
355 ch = pszFormat[1];
356 switch (ch)
357 {
358 /*
359 * Relative jump offset.
360 */
361 case 'J':
362 {
363 AssertMsg(iParam == 1, ("Invalid branch parameter nr %d\n", iParam));
364 int32_t i32Disp;
365 if (State.Cpu.param1.flags & USE_IMMEDIATE8_REL)
366 i32Disp = (int32_t)(int8_t)State.Cpu.param1.parval;
367 else if (State.Cpu.param1.flags & USE_IMMEDIATE16_REL)
368 i32Disp = (int32_t)(int16_t)State.Cpu.param1.parval;
369 else if (State.Cpu.param1.flags & USE_IMMEDIATE32_REL)
370 i32Disp = (int32_t)State.Cpu.param1.parval;
371 else
372 {
373 AssertMsgFailed(("Oops!\n"));
374 return VERR_GENERAL_FAILURE;
375 }
376 RTGCUINTPTR GCPtrTarget = (RTGCUINTPTR)GCPtr + State.Cpu.opsize + i32Disp;
377 switch (State.Cpu.opmode)
378 {
379 case CPUMODE_16BIT: GCPtrTarget &= UINT16_MAX; break;
380 case CPUMODE_32BIT: GCPtrTarget &= UINT32_MAX; break;
381 }
382#ifdef DEBUG_bird /* an experiment. */
383 DBGFSYMBOL Sym;
384 RTGCINTPTR off;
385 int rc = DBGFR3SymbolByAddr(pVM, GCPtrTarget + SelInfo.GCPtrBase, &off, &Sym);
386 if ( VBOX_SUCCESS(rc)
387 && Sym.Value - SelInfo.GCPtrBase <= SelInfo.cbLimit
388 && off < _1M * 16 && off > -_1M * 16)
389 {
390 psz += RTStrPrintf(psz, &szBuf[sizeof(szBuf)] - psz, "%s", Sym.szName);
391 if (off > 0)
392 psz += RTStrPrintf(psz, &szBuf[sizeof(szBuf)] - psz, "+%#x", (int)off);
393 else if (off > 0)
394 psz += RTStrPrintf(psz, &szBuf[sizeof(szBuf)] - psz, "-%#x", -(int)off);
395 switch (State.Cpu.opmode)
396 {
397 case CPUMODE_16BIT:
398 psz += RTStrPrintf(psz, &szBuf[sizeof(szBuf)] - psz,
399 i32Disp >= 0 ? " (%04VGv/+%x)" : " (%04VGv/-%x)",
400 GCPtrTarget, i32Disp >= 0 ? i32Disp : -i32Disp);
401 break;
402 case CPUMODE_32BIT:
403 psz += RTStrPrintf(psz, &szBuf[sizeof(szBuf)] - psz,
404 i32Disp >= 0 ? " (%08VGv/+%x)" : " (%08VGv/-%x)",
405 GCPtrTarget, i32Disp >= 0 ? i32Disp : -i32Disp);
406 break;
407 default:
408 psz += RTStrPrintf(psz, &szBuf[sizeof(szBuf)] - psz,
409 i32Disp >= 0 ? " (%VGv/+%x)" : " (%VGv/-%x)",
410 GCPtrTarget, i32Disp >= 0 ? i32Disp : -i32Disp);
411 break;
412 }
413 }
414 else
415#endif /* DEBUG_bird */
416 {
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 break;
437 }
438
439 case 'A': //direct address
440 case 'C': //control register
441 case 'D': //debug register
442 case 'E': //ModRM specifies parameter
443 case 'F': //Eflags register
444 case 'G': //ModRM selects general register
445 case 'I': //Immediate data
446 case 'M': //ModRM may only refer to memory
447 case 'O': //No ModRM byte
448 case 'P': //ModRM byte selects MMX register
449 case 'Q': //ModRM byte selects MMX register or memory address
450 case 'R': //ModRM byte may only refer to a general register
451 case 'S': //ModRM byte selects a segment register
452 case 'T': //ModRM byte selects a test register
453 case 'V': //ModRM byte selects an XMM/SSE register
454 case 'W': //ModRM byte selects an XMM/SSE register or a memory address
455 case 'X': //DS:SI
456 case 'Y': //ES:DI
457 switch (iParam)
458 {
459 case 1: psz = mystrpcpy(psz, State.Cpu.param1.szParam); break;
460 case 2: psz = mystrpcpy(psz, State.Cpu.param2.szParam); break;
461 case 3: psz = mystrpcpy(psz, State.Cpu.param3.szParam); break;
462 }
463 pszFormat += 2;
464 break;
465
466 case 'e': //register based on operand size (e.g. %eAX)
467 if (State.Cpu.opmode == CPUMODE_32BIT)
468 *psz++ = 'E';
469 *psz++ = pszFormat[2];
470 *psz++ = pszFormat[3];
471 pszFormat += 4;
472 break;
473
474 default:
475 AssertMsgFailed(("Oops! ch=%c\n", ch));
476 break;
477 }
478
479 /* Skip to the next parameter in the format string. */
480 pszFormat = strchr(pszFormat, ',');
481 if (!pszFormat)
482 break;
483 pszFormat++;
484 *psz++ = ch = ',';
485 iParam++;
486 }
487 else
488 {
489 /* output char, but check for parameter separator first. */
490 if (ch == ',')
491 iParam++;
492 *psz++ = ch;
493 if (!ch)
494 break;
495 pszFormat++;
496 }
497
498#ifdef DEBUG_bird /* Not sure if Sander want's this because of log size */
499 /* space after commas */
500 if (ch == ',')
501 {
502 while (isspace(*pszFormat))
503 pszFormat++;
504 *psz++ = ' ';
505 }
506#endif
507 } /* foreach char in pszFormat */
508 *psz = '\0';
509
510 /*
511 * Print it to the user specified buffer.
512 */
513 if (fFlags & DBGF_DISAS_FLAGS_NO_BYTES)
514 {
515 if (fFlags & DBGF_DISAS_FLAGS_NO_ADDRESS)
516 RTStrPrintf(pszOutput, cchOutput, "%s", szBuf);
517 else if (fRealModeAddress)
518 RTStrPrintf(pszOutput, cchOutput, "%04x:%04x %s", Sel, (unsigned)GCPtr, szBuf);
519 else if (Sel == DBGF_SEL_FLAT)
520 RTStrPrintf(pszOutput, cchOutput, "%VGv %s", GCPtr, szBuf);
521 else
522 RTStrPrintf(pszOutput, cchOutput, "%04x:%VGv %s", Sel, GCPtr, szBuf);
523 }
524 else
525 {
526 size_t cbBits = State.Cpu.opsize;
527 uint8_t *pau8Bits = (uint8_t *)alloca(cbBits);
528 rc = dbgfR3DisasInstrRead(GCPtr, pau8Bits, cbBits, (uintptr_t)&State);
529 AssertRC(rc);
530 if (fFlags & DBGF_DISAS_FLAGS_NO_ADDRESS)
531 RTStrPrintf(pszOutput, cchOutput, "%.*Vhxs%*s %s",
532 cbBits, pau8Bits, cbBits < 8 ? (8 - cbBits) * 3 : 0, "",
533 szBuf);
534 else if (fRealModeAddress)
535 RTStrPrintf(pszOutput, cchOutput, "%04x:%04x %.*Vhxs%*s %s",
536 Sel, (unsigned)GCPtr,
537 cbBits, pau8Bits, cbBits < 8 ? (8 - cbBits) * 3 : 0, "",
538 szBuf);
539 else if (Sel == DBGF_SEL_FLAT)
540 RTStrPrintf(pszOutput, cchOutput, "%VGv %.*Vhxs%*s %s",
541 GCPtr,
542 cbBits, pau8Bits, cbBits < 8 ? (8 - cbBits) * 3 : 0, "",
543 szBuf);
544 else
545 RTStrPrintf(pszOutput, cchOutput, "%04x:%VGv %.*Vhxs%*s %s",
546 Sel, GCPtr,
547 cbBits, pau8Bits, cbBits < 8 ? (8 - cbBits) * 3 : 0, "",
548 szBuf);
549
550 }
551
552 if (pcbInstr)
553 *pcbInstr = State.Cpu.opsize;
554 return VINF_SUCCESS;
555}
556
557
558/**
559 * Disassembles an instruction.
560 * Addresses will be tried resolved to symbols
561 *
562 * @returns VBox status code.
563 * @param pVM VM handle.
564 * @param Sel The code selector. This used to determin the 32/16 bit ness and
565 * calculation of the actual instruction address.
566 * @param GCPtr The code address relative to the base of Sel.
567 * @param pszOutput Output buffer.
568 * @param cchOutput Size of the output buffer.
569 */
570DBGFR3DECL(int) DBGFR3DisasInstr(PVM pVM, RTSEL Sel, RTGCPTR GCPtr, char *pszOutput, uint32_t cchOutput)
571{
572 return DBGFR3DisasInstrEx(pVM, Sel, GCPtr, 0, pszOutput, cchOutput, NULL);
573}
574
575
576/**
577 * Disassembles the current guest context instruction.
578 * All registers and data will be displayed. Addresses will be attempted resolved to symbols.
579 *
580 * @returns VBox status code.
581 * @param pVM VM handle.
582 * @param pszOutput Output buffer.
583 * @param cchOutput Size of the output buffer.
584 */
585DBGFR3DECL(int) DBGFR3DisasInstrCurrent(PVM pVM, char *pszOutput, uint32_t cchOutput)
586{
587 return DBGFR3DisasInstrEx(pVM, 0, 0, DBGF_DISAS_FLAGS_CURRENT_GUEST, pszOutput, cchOutput, NULL);
588}
589
590
591/**
592 * Disassembles the current guest context instruction and writes it to the log.
593 * All registers and data will be displayed. Addresses will be attempted resolved to symbols.
594 *
595 * @returns VBox status code.
596 * @param pVM VM handle.
597 * @param pszPrefix Short prefix string to the dissassembly string. (optional)
598 */
599DBGFR3DECL(int) DBGFR3DisasInstrCurrentLogInternal(PVM pVM, const char *pszPrefix)
600{
601 char szBuf[256];
602 szBuf[0] = '\0';
603 int rc = DBGFR3DisasInstrCurrent(pVM, &szBuf[0], sizeof(szBuf));
604 if (VBOX_FAILURE(rc))
605 RTStrPrintf(szBuf, sizeof(szBuf), "DBGFR3DisasInstrCurrentLog failed with rc=%Vrc\n", rc);
606 if (pszPrefix && *pszPrefix)
607 RTLogPrintf("%s: %s\n", pszPrefix, szBuf);
608 else
609 RTLogPrintf("%s\n", szBuf);
610 return rc;
611}
612
613
614
615/**
616 * Disassembles the specified guest context instruction and writes it to the log.
617 * Addresses will be attempted resolved to symbols.
618 *
619 * @returns VBox status code.
620 * @param pVM VM handle.
621 * @param Sel The code selector. This used to determin the 32/16 bit-ness and
622 * calculation of the actual instruction address.
623 * @param GCPtr The code address relative to the base of Sel.
624 */
625DBGFR3DECL(int) DBGFR3DisasInstrLogInternal(PVM pVM, RTSEL Sel, RTGCPTR GCPtr)
626{
627 char szBuf[256];
628 szBuf[0] = '\0';
629 int rc = DBGFR3DisasInstr(pVM, Sel, GCPtr, &szBuf[0], sizeof(szBuf));
630 if (VBOX_FAILURE(rc))
631 RTStrPrintf(szBuf, sizeof(szBuf), "DBGFR3DisasInstrLog(, %RTsel, %RGv) failed with rc=%Vrc\n", Sel, GCPtr, rc);
632 RTLogPrintf("%s\n", szBuf);
633 return rc;
634}
635
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