VirtualBox

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

Last change on this file since 2273 was 2138, checked in by vboxsync, 18 years ago

Use hidden selector register in DBGFR3DisasInstrEx

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