VirtualBox

source: vbox/trunk/src/VBox/VMM/VMMR3/DBGFStack.cpp@ 45499

Last change on this file since 45499 was 44528, checked in by vboxsync, 12 years ago

header (C) fixes

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 21.3 KB
Line 
1/* $Id: DBGFStack.cpp 44528 2013-02-04 14:27:54Z vboxsync $ */
2/** @file
3 * DBGF - Debugger Facility, Call Stack Analyser.
4 */
5
6/*
7 * Copyright (C) 2006-2013 Oracle Corporation
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 (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18
19/*******************************************************************************
20* Header Files *
21*******************************************************************************/
22#define LOG_GROUP LOG_GROUP_DBGF
23#include <VBox/vmm/dbgf.h>
24#include <VBox/vmm/selm.h>
25#include <VBox/vmm/mm.h>
26#include "DBGFInternal.h"
27#include <VBox/vmm/vm.h>
28#include <VBox/vmm/uvm.h>
29#include <VBox/err.h>
30#include <VBox/log.h>
31#include <iprt/param.h>
32#include <iprt/assert.h>
33#include <iprt/string.h>
34#include <iprt/alloca.h>
35
36
37
38/**
39 * Read stack memory.
40 */
41DECLINLINE(int) dbgfR3Read(PUVM pUVM, VMCPUID idCpu, void *pvBuf, PCDBGFADDRESS pSrcAddr, size_t cb, size_t *pcbRead)
42{
43 int rc = DBGFR3MemRead(pUVM, idCpu, pSrcAddr, pvBuf, cb);
44 if (RT_FAILURE(rc))
45 {
46 /* fallback: byte by byte and zero the ones we fail to read. */
47 size_t cbRead;
48 for (cbRead = 0; cbRead < cb; cbRead++)
49 {
50 DBGFADDRESS Addr = *pSrcAddr;
51 rc = DBGFR3MemRead(pUVM, idCpu, DBGFR3AddrAdd(&Addr, cbRead), (uint8_t *)pvBuf + cbRead, 1);
52 if (RT_FAILURE(rc))
53 break;
54 }
55 if (cbRead)
56 rc = VINF_SUCCESS;
57 memset((char *)pvBuf + cbRead, 0, cb - cbRead);
58 *pcbRead = cbRead;
59 }
60 else
61 *pcbRead = cb;
62 return rc;
63}
64
65
66/**
67 * Internal worker routine.
68 *
69 * On x86 the typical stack frame layout is like this:
70 * .. ..
71 * 16 parameter 2
72 * 12 parameter 1
73 * 8 parameter 0
74 * 4 return address
75 * 0 old ebp; current ebp points here
76 *
77 * @todo Add AMD64 support (needs teaming up with the module management for
78 * unwind tables).
79 */
80static int dbgfR3StackWalk(PUVM pUVM, VMCPUID idCpu, RTDBGAS hAs, PDBGFSTACKFRAME pFrame)
81{
82 /*
83 * Stop if we got a read error in the previous run.
84 */
85 if (pFrame->fFlags & DBGFSTACKFRAME_FLAGS_LAST)
86 return VERR_NO_MORE_FILES;
87
88 /*
89 * Read the raw frame data.
90 */
91 const DBGFADDRESS AddrOldPC = pFrame->AddrPC;
92 const unsigned cbRetAddr = DBGFReturnTypeSize(pFrame->enmReturnType);
93 unsigned cbStackItem;
94 switch (AddrOldPC.fFlags & DBGFADDRESS_FLAGS_TYPE_MASK)
95 {
96 case DBGFADDRESS_FLAGS_FAR16: cbStackItem = 2; break;
97 case DBGFADDRESS_FLAGS_FAR32: cbStackItem = 4; break;
98 case DBGFADDRESS_FLAGS_FAR64: cbStackItem = 8; break;
99 case DBGFADDRESS_FLAGS_RING0: cbStackItem = sizeof(RTHCUINTPTR); break;
100 default:
101 switch (pFrame->enmReturnType)
102 {
103 case DBGFRETURNTYPE_FAR16:
104 case DBGFRETURNTYPE_IRET16:
105 case DBGFRETURNTYPE_IRET32_V86:
106 case DBGFRETURNTYPE_NEAR16: cbStackItem = 2; break;
107
108 case DBGFRETURNTYPE_FAR32:
109 case DBGFRETURNTYPE_IRET32:
110 case DBGFRETURNTYPE_IRET32_PRIV:
111 case DBGFRETURNTYPE_NEAR32: cbStackItem = 4; break;
112
113 case DBGFRETURNTYPE_FAR64:
114 case DBGFRETURNTYPE_IRET64:
115 case DBGFRETURNTYPE_NEAR64: cbStackItem = 8; break;
116
117 default:
118 AssertMsgFailed(("%d\n", pFrame->enmReturnType));
119 cbStackItem = 4;
120 break;
121 }
122 }
123
124 union
125 {
126 uint64_t *pu64;
127 uint32_t *pu32;
128 uint16_t *pu16;
129 uint8_t *pb;
130 void *pv;
131 } u, uRet, uArgs, uBp;
132 size_t cbRead = cbRetAddr + cbStackItem + sizeof(pFrame->Args);
133 u.pv = alloca(cbRead);
134 uBp = u;
135 uRet.pb = u.pb + cbStackItem;
136 uArgs.pb = u.pb + cbStackItem + cbRetAddr;
137
138 Assert(DBGFADDRESS_IS_VALID(&pFrame->AddrFrame));
139 int rc = dbgfR3Read(pUVM, idCpu, u.pv,
140 pFrame->fFlags & DBGFSTACKFRAME_FLAGS_ALL_VALID
141 ? &pFrame->AddrReturnFrame
142 : &pFrame->AddrFrame,
143 cbRead, &cbRead);
144 if ( RT_FAILURE(rc)
145 || cbRead < cbRetAddr + cbStackItem)
146 pFrame->fFlags |= DBGFSTACKFRAME_FLAGS_LAST;
147
148 /*
149 * The first step is taken in a different way than the others.
150 */
151 if (!(pFrame->fFlags & DBGFSTACKFRAME_FLAGS_ALL_VALID))
152 {
153 pFrame->fFlags |= DBGFSTACKFRAME_FLAGS_ALL_VALID;
154 pFrame->iFrame = 0;
155
156 /* Current PC - set by caller, just find symbol & line. */
157 if (DBGFADDRESS_IS_VALID(&pFrame->AddrPC))
158 {
159 pFrame->pSymPC = DBGFR3AsSymbolByAddrA(pUVM, hAs, &pFrame->AddrPC, NULL /*offDisp*/, NULL /*phMod*/);
160 pFrame->pLinePC = DBGFR3LineByAddrAlloc(pUVM, pFrame->AddrPC.FlatPtr, NULL);
161 }
162 }
163 else /* 2nd and subsequent steps */
164 {
165 /* frame, pc and stack is taken from the existing frames return members. */
166 pFrame->AddrFrame = pFrame->AddrReturnFrame;
167 pFrame->AddrPC = pFrame->AddrReturnPC;
168 pFrame->pSymPC = pFrame->pSymReturnPC;
169 pFrame->pLinePC = pFrame->pLineReturnPC;
170
171 /* increment the frame number. */
172 pFrame->iFrame++;
173 }
174
175 /*
176 * Return Frame address.
177 */
178 pFrame->AddrReturnFrame = pFrame->AddrFrame;
179 switch (cbStackItem)
180 {
181 case 2: pFrame->AddrReturnFrame.off = *uBp.pu16; break;
182 case 4: pFrame->AddrReturnFrame.off = *uBp.pu32; break;
183 case 8: pFrame->AddrReturnFrame.off = *uBp.pu64; break;
184 default: AssertMsgFailedReturn(("cbStackItem=%d\n", cbStackItem), VERR_DBGF_STACK_IPE_1);
185 }
186 pFrame->AddrReturnFrame.FlatPtr += pFrame->AddrReturnFrame.off - pFrame->AddrFrame.off;
187
188 /*
189 * Return PC and Stack Addresses.
190 */
191 /** @todo AddrReturnStack is not correct for stdcall and pascal. (requires scope info) */
192 pFrame->AddrReturnStack = pFrame->AddrFrame;
193 pFrame->AddrReturnStack.off += cbStackItem + cbRetAddr;
194 pFrame->AddrReturnStack.FlatPtr += cbStackItem + cbRetAddr;
195
196 pFrame->AddrReturnPC = pFrame->AddrPC;
197 switch (pFrame->enmReturnType)
198 {
199 case DBGFRETURNTYPE_NEAR16:
200 if (DBGFADDRESS_IS_VALID(&pFrame->AddrReturnPC))
201 {
202 pFrame->AddrReturnPC.FlatPtr += *uRet.pu16 - pFrame->AddrReturnPC.off;
203 pFrame->AddrReturnPC.off = *uRet.pu16;
204 }
205 else
206 DBGFR3AddrFromFlat(pUVM, &pFrame->AddrReturnPC, *uRet.pu16);
207 break;
208 case DBGFRETURNTYPE_NEAR32:
209 if (DBGFADDRESS_IS_VALID(&pFrame->AddrReturnPC))
210 {
211 pFrame->AddrReturnPC.FlatPtr += *uRet.pu32 - pFrame->AddrReturnPC.off;
212 pFrame->AddrReturnPC.off = *uRet.pu32;
213 }
214 else
215 DBGFR3AddrFromFlat(pUVM, &pFrame->AddrReturnPC, *uRet.pu32);
216 break;
217 case DBGFRETURNTYPE_NEAR64:
218 if (DBGFADDRESS_IS_VALID(&pFrame->AddrReturnPC))
219 {
220 pFrame->AddrReturnPC.FlatPtr += *uRet.pu64 - pFrame->AddrReturnPC.off;
221 pFrame->AddrReturnPC.off = *uRet.pu64;
222 }
223 else
224 DBGFR3AddrFromFlat(pUVM, &pFrame->AddrReturnPC, *uRet.pu64);
225 break;
226 case DBGFRETURNTYPE_FAR16:
227 DBGFR3AddrFromSelOff(pUVM, idCpu, &pFrame->AddrReturnPC, uRet.pu16[1], uRet.pu16[0]);
228 break;
229 case DBGFRETURNTYPE_FAR32:
230 DBGFR3AddrFromSelOff(pUVM, idCpu, &pFrame->AddrReturnPC, uRet.pu16[2], uRet.pu32[0]);
231 break;
232 case DBGFRETURNTYPE_FAR64:
233 DBGFR3AddrFromSelOff(pUVM, idCpu, &pFrame->AddrReturnPC, uRet.pu16[4], uRet.pu64[0]);
234 break;
235 case DBGFRETURNTYPE_IRET16:
236 DBGFR3AddrFromSelOff(pUVM, idCpu, &pFrame->AddrReturnPC, uRet.pu16[1], uRet.pu16[0]);
237 break;
238 case DBGFRETURNTYPE_IRET32:
239 DBGFR3AddrFromSelOff(pUVM, idCpu, &pFrame->AddrReturnPC, uRet.pu16[2], uRet.pu32[0]);
240 break;
241 case DBGFRETURNTYPE_IRET32_PRIV:
242 DBGFR3AddrFromSelOff(pUVM, idCpu, &pFrame->AddrReturnPC, uRet.pu16[2], uRet.pu32[0]);
243 break;
244 case DBGFRETURNTYPE_IRET32_V86:
245 DBGFR3AddrFromSelOff(pUVM, idCpu, &pFrame->AddrReturnPC, uRet.pu16[2], uRet.pu32[0]);
246 break;
247 case DBGFRETURNTYPE_IRET64:
248 DBGFR3AddrFromSelOff(pUVM, idCpu, &pFrame->AddrReturnPC, uRet.pu16[4], uRet.pu64[0]);
249 break;
250 default:
251 AssertMsgFailed(("enmReturnType=%d\n", pFrame->enmReturnType));
252 return VERR_INVALID_PARAMETER;
253 }
254
255 pFrame->pSymReturnPC = DBGFR3AsSymbolByAddrA(pUVM, hAs, &pFrame->AddrReturnPC, NULL /*offDisp*/, NULL /*phMod*/);
256 pFrame->pLineReturnPC = DBGFR3LineByAddrAlloc(pUVM, pFrame->AddrReturnPC.FlatPtr, NULL);
257
258 /*
259 * Frame bitness flag.
260 */
261 switch (cbStackItem)
262 {
263 case 2: pFrame->fFlags |= DBGFSTACKFRAME_FLAGS_16BIT; break;
264 case 4: pFrame->fFlags |= DBGFSTACKFRAME_FLAGS_32BIT; break;
265 case 8: pFrame->fFlags |= DBGFSTACKFRAME_FLAGS_64BIT; break;
266 default: AssertMsgFailedReturn(("cbStackItem=%d\n", cbStackItem), VERR_DBGF_STACK_IPE_2);
267 }
268
269 /*
270 * The arguments.
271 */
272 memcpy(&pFrame->Args, uArgs.pv, sizeof(pFrame->Args));
273
274 return VINF_SUCCESS;
275}
276
277
278/**
279 * Walks the entire stack allocating memory as we walk.
280 */
281static DECLCALLBACK(int) dbgfR3StackWalkCtxFull(PUVM pUVM, VMCPUID idCpu, PCCPUMCTXCORE pCtxCore, RTDBGAS hAs,
282 DBGFCODETYPE enmCodeType,
283 PCDBGFADDRESS pAddrFrame,
284 PCDBGFADDRESS pAddrStack,
285 PCDBGFADDRESS pAddrPC,
286 DBGFRETURNTYPE enmReturnType,
287 PCDBGFSTACKFRAME *ppFirstFrame)
288{
289 /* alloc first frame. */
290 PDBGFSTACKFRAME pCur = (PDBGFSTACKFRAME)MMR3HeapAllocZU(pUVM, MM_TAG_DBGF_STACK, sizeof(*pCur));
291 if (!pCur)
292 return VERR_NO_MEMORY;
293
294 /*
295 * Initialize the frame.
296 */
297 pCur->pNextInternal = NULL;
298 pCur->pFirstInternal = pCur;
299
300 int rc = VINF_SUCCESS;
301 if (pAddrPC)
302 pCur->AddrPC = *pAddrPC;
303 else if (enmCodeType != DBGFCODETYPE_GUEST)
304 DBGFR3AddrFromFlat(pUVM, &pCur->AddrPC, pCtxCore->rip);
305 else
306 rc = DBGFR3AddrFromSelOff(pUVM, idCpu, &pCur->AddrPC, pCtxCore->cs.Sel, pCtxCore->rip);
307 if (RT_SUCCESS(rc))
308 {
309 if (enmReturnType == DBGFRETURNTYPE_INVALID)
310 switch (pCur->AddrPC.fFlags & DBGFADDRESS_FLAGS_TYPE_MASK)
311 {
312 case DBGFADDRESS_FLAGS_FAR16: pCur->enmReturnType = DBGFRETURNTYPE_NEAR16; break;
313 case DBGFADDRESS_FLAGS_FAR32: pCur->enmReturnType = DBGFRETURNTYPE_NEAR32; break;
314 case DBGFADDRESS_FLAGS_FAR64: pCur->enmReturnType = DBGFRETURNTYPE_NEAR64; break;
315 case DBGFADDRESS_FLAGS_RING0: pCur->enmReturnType = HC_ARCH_BITS == 64 ? DBGFRETURNTYPE_NEAR64 : DBGFRETURNTYPE_NEAR32; break;
316 default: pCur->enmReturnType = DBGFRETURNTYPE_NEAR32; break; /// @todo 64-bit guests
317 }
318
319 uint64_t fAddrMask;
320 if (enmCodeType == DBGFCODETYPE_RING0)
321 fAddrMask = HC_ARCH_BITS == 64 ? UINT64_MAX : UINT32_MAX;
322 else if (enmCodeType == DBGFCODETYPE_HYPER)
323 fAddrMask = UINT32_MAX;
324 else if (DBGFADDRESS_IS_FAR16(&pCur->AddrPC))
325 fAddrMask = UINT16_MAX;
326 else if (DBGFADDRESS_IS_FAR32(&pCur->AddrPC))
327 fAddrMask = UINT32_MAX;
328 else if (DBGFADDRESS_IS_FAR64(&pCur->AddrPC))
329 fAddrMask = UINT64_MAX;
330 else
331 {
332 PVMCPU pVCpu = VMMGetCpuById(pUVM->pVM, idCpu);
333 CPUMMODE CpuMode = CPUMGetGuestMode(pVCpu);
334 if (CpuMode == CPUMMODE_REAL)
335 fAddrMask = UINT16_MAX;
336 else if ( CpuMode == CPUMMODE_PROTECTED
337 || !CPUMIsGuestIn64BitCode(pVCpu))
338 fAddrMask = UINT32_MAX;
339 else
340 fAddrMask = UINT64_MAX;
341 }
342
343 if (pAddrStack)
344 pCur->AddrStack = *pAddrStack;
345 else if (enmCodeType != DBGFCODETYPE_GUEST)
346 DBGFR3AddrFromFlat(pUVM, &pCur->AddrStack, pCtxCore->rsp & fAddrMask);
347 else
348 rc = DBGFR3AddrFromSelOff(pUVM, idCpu, &pCur->AddrStack, pCtxCore->ss.Sel, pCtxCore->rsp & fAddrMask);
349
350 if (pAddrFrame)
351 pCur->AddrFrame = *pAddrFrame;
352 else if (enmCodeType != DBGFCODETYPE_GUEST)
353 DBGFR3AddrFromFlat(pUVM, &pCur->AddrFrame, pCtxCore->rbp & fAddrMask);
354 else if (RT_SUCCESS(rc))
355 rc = DBGFR3AddrFromSelOff(pUVM, idCpu, &pCur->AddrFrame, pCtxCore->ss.Sel, pCtxCore->rbp & fAddrMask);
356 }
357 else
358 pCur->enmReturnType = enmReturnType;
359
360 /*
361 * The first frame.
362 */
363 if (RT_SUCCESS(rc))
364 rc = dbgfR3StackWalk(pUVM, idCpu, hAs, pCur);
365 if (RT_FAILURE(rc))
366 {
367 DBGFR3StackWalkEnd(pCur);
368 return rc;
369 }
370
371 /*
372 * The other frames.
373 */
374 DBGFSTACKFRAME Next = *pCur;
375 while (!(pCur->fFlags & (DBGFSTACKFRAME_FLAGS_LAST | DBGFSTACKFRAME_FLAGS_MAX_DEPTH | DBGFSTACKFRAME_FLAGS_LOOP)))
376 {
377 /* try walk. */
378 rc = dbgfR3StackWalk(pUVM, idCpu, hAs, &Next);
379 if (RT_FAILURE(rc))
380 break;
381
382 /* add the next frame to the chain. */
383 PDBGFSTACKFRAME pNext = (PDBGFSTACKFRAME)MMR3HeapAllocU(pUVM, MM_TAG_DBGF_STACK, sizeof(*pNext));
384 if (!pNext)
385 {
386 DBGFR3StackWalkEnd(pCur);
387 return VERR_NO_MEMORY;
388 }
389 *pNext = Next;
390 pCur->pNextInternal = pNext;
391 pCur = pNext;
392 Assert(pCur->pNextInternal == NULL);
393
394 /* check for loop */
395 for (PCDBGFSTACKFRAME pLoop = pCur->pFirstInternal;
396 pLoop && pLoop != pCur;
397 pLoop = pLoop->pNextInternal)
398 if (pLoop->AddrFrame.FlatPtr == pCur->AddrFrame.FlatPtr)
399 {
400 pCur->fFlags |= DBGFSTACKFRAME_FLAGS_LOOP;
401 break;
402 }
403
404 /* check for insane recursion */
405 if (pCur->iFrame >= 2048)
406 pCur->fFlags |= DBGFSTACKFRAME_FLAGS_MAX_DEPTH;
407 }
408
409 *ppFirstFrame = pCur->pFirstInternal;
410 return rc;
411}
412
413
414/**
415 * Common worker for DBGFR3StackWalkBeginGuestEx, DBGFR3StackWalkBeginHyperEx,
416 * DBGFR3StackWalkBeginGuest and DBGFR3StackWalkBeginHyper.
417 */
418static int dbgfR3StackWalkBeginCommon(PUVM pUVM,
419 VMCPUID idCpu,
420 DBGFCODETYPE enmCodeType,
421 PCDBGFADDRESS pAddrFrame,
422 PCDBGFADDRESS pAddrStack,
423 PCDBGFADDRESS pAddrPC,
424 DBGFRETURNTYPE enmReturnType,
425 PCDBGFSTACKFRAME *ppFirstFrame)
426{
427 /*
428 * Validate parameters.
429 */
430 *ppFirstFrame = NULL;
431 UVM_ASSERT_VALID_EXT_RETURN(pUVM, VERR_INVALID_VM_HANDLE);
432 PVM pVM = pUVM->pVM;
433 VM_ASSERT_VALID_EXT_RETURN(pVM, VERR_INVALID_VM_HANDLE);
434 AssertReturn(idCpu < pVM->cCpus, VERR_INVALID_CPU_ID);
435 if (pAddrFrame)
436 AssertReturn(DBGFR3AddrIsValid(pUVM, pAddrFrame), VERR_INVALID_PARAMETER);
437 if (pAddrStack)
438 AssertReturn(DBGFR3AddrIsValid(pUVM, pAddrStack), VERR_INVALID_PARAMETER);
439 if (pAddrPC)
440 AssertReturn(DBGFR3AddrIsValid(pUVM, pAddrPC), VERR_INVALID_PARAMETER);
441 AssertReturn(enmReturnType >= DBGFRETURNTYPE_INVALID && enmReturnType < DBGFRETURNTYPE_END, VERR_INVALID_PARAMETER);
442
443 /*
444 * Get the CPUM context pointer and pass it on the specified EMT.
445 */
446 RTDBGAS hAs;
447 PCCPUMCTXCORE pCtxCore;
448 switch (enmCodeType)
449 {
450 case DBGFCODETYPE_GUEST:
451 pCtxCore = CPUMGetGuestCtxCore(VMMGetCpuById(pVM, idCpu));
452 hAs = DBGF_AS_GLOBAL;
453 break;
454 case DBGFCODETYPE_HYPER:
455 pCtxCore = CPUMGetHyperCtxCore(VMMGetCpuById(pVM, idCpu));
456 hAs = DBGF_AS_RC_AND_GC_GLOBAL;
457 break;
458 case DBGFCODETYPE_RING0:
459 pCtxCore = NULL; /* No valid context present. */
460 hAs = DBGF_AS_R0;
461 break;
462 default:
463 AssertFailedReturn(VERR_INVALID_PARAMETER);
464 }
465 return VMR3ReqPriorityCallWaitU(pUVM, idCpu, (PFNRT)dbgfR3StackWalkCtxFull, 10,
466 pUVM, idCpu, pCtxCore, hAs, enmCodeType,
467 pAddrFrame, pAddrStack, pAddrPC, enmReturnType, ppFirstFrame);
468}
469
470
471/**
472 * Begins a guest stack walk, extended version.
473 *
474 * This will walk the current stack, constructing a list of info frames which is
475 * returned to the caller. The caller uses DBGFR3StackWalkNext to traverse the
476 * list and DBGFR3StackWalkEnd to release it.
477 *
478 * @returns VINF_SUCCESS on success.
479 * @returns VERR_NO_MEMORY if we're out of memory.
480 *
481 * @param pUVM The user mode VM handle.
482 * @param idCpu The ID of the virtual CPU which stack we want to walk.
483 * @param enmCodeType Code type
484 * @param pAddrFrame Frame address to start at. (Optional)
485 * @param pAddrStack Stack address to start at. (Optional)
486 * @param pAddrPC Program counter to start at. (Optional)
487 * @param enmReturnType The return address type. (Optional)
488 * @param ppFirstFrame Where to return the pointer to the first info frame.
489 */
490VMMR3DECL(int) DBGFR3StackWalkBeginEx(PUVM pUVM,
491 VMCPUID idCpu,
492 DBGFCODETYPE enmCodeType,
493 PCDBGFADDRESS pAddrFrame,
494 PCDBGFADDRESS pAddrStack,
495 PCDBGFADDRESS pAddrPC,
496 DBGFRETURNTYPE enmReturnType,
497 PCDBGFSTACKFRAME *ppFirstFrame)
498{
499 return dbgfR3StackWalkBeginCommon(pUVM, idCpu, enmCodeType, pAddrFrame, pAddrStack, pAddrPC, enmReturnType, ppFirstFrame);
500}
501
502
503/**
504 * Begins a guest stack walk.
505 *
506 * This will walk the current stack, constructing a list of info frames which is
507 * returned to the caller. The caller uses DBGFR3StackWalkNext to traverse the
508 * list and DBGFR3StackWalkEnd to release it.
509 *
510 * @returns VINF_SUCCESS on success.
511 * @returns VERR_NO_MEMORY if we're out of memory.
512 *
513 * @param pUVM The user mode VM handle.
514 * @param idCpu The ID of the virtual CPU which stack we want to walk.
515 * @param enmCodeType Code type
516 * @param ppFirstFrame Where to return the pointer to the first info frame.
517 */
518VMMR3DECL(int) DBGFR3StackWalkBegin(PUVM pUVM, VMCPUID idCpu, DBGFCODETYPE enmCodeType, PCDBGFSTACKFRAME *ppFirstFrame)
519{
520 return dbgfR3StackWalkBeginCommon(pUVM, idCpu, enmCodeType, NULL, NULL, NULL, DBGFRETURNTYPE_INVALID, ppFirstFrame);
521}
522
523/**
524 * Gets the next stack frame.
525 *
526 * @returns Pointer to the info for the next stack frame.
527 * NULL if no more frames.
528 *
529 * @param pCurrent Pointer to the current stack frame.
530 *
531 */
532VMMR3DECL(PCDBGFSTACKFRAME) DBGFR3StackWalkNext(PCDBGFSTACKFRAME pCurrent)
533{
534 return pCurrent
535 ? pCurrent->pNextInternal
536 : NULL;
537}
538
539
540/**
541 * Ends a stack walk process.
542 *
543 * This *must* be called after a successful first call to any of the stack
544 * walker functions. If not called we will leak memory or other resources.
545 *
546 * @param pFirstFrame The frame returned by one of the begin functions.
547 */
548VMMR3DECL(void) DBGFR3StackWalkEnd(PCDBGFSTACKFRAME pFirstFrame)
549{
550 if ( !pFirstFrame
551 || !pFirstFrame->pFirstInternal)
552 return;
553
554 PDBGFSTACKFRAME pFrame = (PDBGFSTACKFRAME)pFirstFrame->pFirstInternal;
555 while (pFrame)
556 {
557 PDBGFSTACKFRAME pCur = pFrame;
558 pFrame = (PDBGFSTACKFRAME)pCur->pNextInternal;
559 if (pFrame)
560 {
561 if (pCur->pSymReturnPC == pFrame->pSymPC)
562 pFrame->pSymPC = NULL;
563 if (pCur->pSymReturnPC == pFrame->pSymReturnPC)
564 pFrame->pSymReturnPC = NULL;
565
566 if (pCur->pSymPC == pFrame->pSymPC)
567 pFrame->pSymPC = NULL;
568 if (pCur->pSymPC == pFrame->pSymReturnPC)
569 pFrame->pSymReturnPC = NULL;
570
571 if (pCur->pLineReturnPC == pFrame->pLinePC)
572 pFrame->pLinePC = NULL;
573 if (pCur->pLineReturnPC == pFrame->pLineReturnPC)
574 pFrame->pLineReturnPC = NULL;
575
576 if (pCur->pLinePC == pFrame->pLinePC)
577 pFrame->pLinePC = NULL;
578 if (pCur->pLinePC == pFrame->pLineReturnPC)
579 pFrame->pLineReturnPC = NULL;
580 }
581
582 RTDbgSymbolFree(pCur->pSymPC);
583 RTDbgSymbolFree(pCur->pSymReturnPC);
584 DBGFR3LineFree(pCur->pLinePC);
585 DBGFR3LineFree(pCur->pLineReturnPC);
586
587 pCur->pNextInternal = NULL;
588 pCur->pFirstInternal = NULL;
589 pCur->fFlags = 0;
590 MMR3HeapFree(pCur);
591 }
592}
593
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