DBGFStack.cpp revision c97989161fbe75bc14cea477a5443bbf474dd3ad
1633838b8255282d10af15c5c84cee5a51466712Bob Halley/* $Id$ */
a7c412f37cc73d0332887a746e81220cbf09dd00Mark Andrews/** @file
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * VMM DBGF - Debugger Facility, Call Stack Analyser.
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence */
ec5347e2c775f027573ce5648b910361aa926c01Automatic Updater
1633838b8255282d10af15c5c84cee5a51466712Bob Halley/*
1633838b8255282d10af15c5c84cee5a51466712Bob Halley * Copyright (C) 2006-2007 innotek GmbH
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence *
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * This file is part of VirtualBox Open Source Edition (OSE), as
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * available from http://www.virtualbox.org. This file is free software;
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * you can redistribute it and/or modify it under the terms of the GNU
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * General Public License as published by the Free Software Foundation,
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * distribution. VirtualBox OSE is distributed in the hope that it will
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * be useful, but WITHOUT ANY WARRANTY of any kind.
1633838b8255282d10af15c5c84cee5a51466712Bob Halley *
94e25967cda41b886e33ec254b917d21df21a187Bob Halley * If you received this file as part of a commercial VirtualBox
28a8f5b0de57d269cf2845c69cb6abe18cbd3b3aMark Andrews * distribution, then only the terms of your commercial VirtualBox
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * license agreement apply instead of the previous paragraph.
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein */
9c3531d72aeaad6c5f01efe6a1c82023e1379e4dDavid Lawrence
d25afd60ee2286cb171c4960a790f3d7041b6f85Bob Halley
d25afd60ee2286cb171c4960a790f3d7041b6f85Bob Halley/*******************************************************************************
94e25967cda41b886e33ec254b917d21df21a187Bob Halley* Header Files *
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence*******************************************************************************/
903247531a10d699ef239a7351554ba0a1e3cd22Evan Hunt#define LOG_GROUP LOG_GROUP_DBGF
70ec7dd74103fa9e92a6d56a0e3b0fc30e17af0dMark Andrews#include <VBox/dbgf.h>
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence#include <VBox/selm.h>
94e25967cda41b886e33ec254b917d21df21a187Bob Halley#include "DBGFInternal.h"
6e3a8256eed85f6704861d269ccfb35bdaeed5ffDavid Lawrence#include <VBox/vm.h>
6e3a8256eed85f6704861d269ccfb35bdaeed5ffDavid Lawrence#include <VBox/mm.h>
df0f58959ed82a2a43ca8d816ce9592541df9f2fMark Andrews#include <VBox/err.h>
33f87146a856eb6c3dfd55a8ee9c173c94f82150Andreas Gustafsson#include <VBox/log.h>
4b87939256ede703385e9cab92d3c58d03c31098Mark Andrews#include <iprt/assert.h>
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence#include <iprt/string.h>
94e25967cda41b886e33ec254b917d21df21a187Bob Halley#include <iprt/alloca.h>
364a82f7c25b62967678027043425201a5e5171aBob Halley
94e25967cda41b886e33ec254b917d21df21a187Bob Halley
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/**
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * Read stack memory.
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence */
6fa1cb5754695d550a58c6e8978fda65f5146af7David LawrenceDECLINLINE(int) dbgfR3Read(PVM pVM, void *pvBuf, RTGCUINTPTR GCPtr, size_t cb, size_t *pcbRead)
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence{
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence int rc = MMR3ReadGCVirt(pVM, pvBuf, GCPtr, cb);
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence if (VBOX_FAILURE(rc))
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence {
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence size_t cbRead;
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence for (cbRead = 0; cbRead < cb; cbRead++)
df0f58959ed82a2a43ca8d816ce9592541df9f2fMark Andrews {
df0f58959ed82a2a43ca8d816ce9592541df9f2fMark Andrews rc = MMR3ReadGCVirt(pVM, (uint8_t *)pvBuf + cbRead, GCPtr + cbRead, 1);
df0f58959ed82a2a43ca8d816ce9592541df9f2fMark Andrews if (VBOX_FAILURE(rc))
df0f58959ed82a2a43ca8d816ce9592541df9f2fMark Andrews break;
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein }
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley if (cbRead)
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley rc = VINF_SUCCESS;
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley memset((char *)pvBuf + cbRead, 0, cb - cbRead);
27809a2ee5db141b684e53bf1d94da26e9f92d3aMark Andrews *pcbRead = cbRead;
27809a2ee5db141b684e53bf1d94da26e9f92d3aMark Andrews }
afdb3abb9b06ed4070ac9021f1f4427b4cb3a286Bob Halley else
70ec7dd74103fa9e92a6d56a0e3b0fc30e17af0dMark Andrews *pcbRead = cb;
70ec7dd74103fa9e92a6d56a0e3b0fc30e17af0dMark Andrews return rc;
70ec7dd74103fa9e92a6d56a0e3b0fc30e17af0dMark Andrews}
70ec7dd74103fa9e92a6d56a0e3b0fc30e17af0dMark Andrews
70ec7dd74103fa9e92a6d56a0e3b0fc30e17af0dMark Andrews
70ec7dd74103fa9e92a6d56a0e3b0fc30e17af0dMark Andrews
70ec7dd74103fa9e92a6d56a0e3b0fc30e17af0dMark Andrews
70ec7dd74103fa9e92a6d56a0e3b0fc30e17af0dMark Andrews/**
70ec7dd74103fa9e92a6d56a0e3b0fc30e17af0dMark Andrews * Internal worker routine.
70ec7dd74103fa9e92a6d56a0e3b0fc30e17af0dMark Andrews *
70ec7dd74103fa9e92a6d56a0e3b0fc30e17af0dMark Andrews * On x86 the typical stack frame layout is like this:
70ec7dd74103fa9e92a6d56a0e3b0fc30e17af0dMark Andrews * .. ..
70ec7dd74103fa9e92a6d56a0e3b0fc30e17af0dMark Andrews * 16 parameter 2
70ec7dd74103fa9e92a6d56a0e3b0fc30e17af0dMark Andrews * 12 parameter 1
70ec7dd74103fa9e92a6d56a0e3b0fc30e17af0dMark Andrews * 8 parameter 0
70ec7dd74103fa9e92a6d56a0e3b0fc30e17af0dMark Andrews * 4 return address
70ec7dd74103fa9e92a6d56a0e3b0fc30e17af0dMark Andrews * 0 old ebp; current ebp points here
70ec7dd74103fa9e92a6d56a0e3b0fc30e17af0dMark Andrews */
70ec7dd74103fa9e92a6d56a0e3b0fc30e17af0dMark Andrewsstatic int dbgfR3StackWalk(PVM pVM, PDBGFSTACKFRAME pFrame)
70ec7dd74103fa9e92a6d56a0e3b0fc30e17af0dMark Andrews{
70ec7dd74103fa9e92a6d56a0e3b0fc30e17af0dMark Andrews /*
70ec7dd74103fa9e92a6d56a0e3b0fc30e17af0dMark Andrews * Stop if we got a read error in the previous run.
1f1d36a87b65186d9f89aac7f456ab1fd2a39ef6Andreas Gustafsson */
70ec7dd74103fa9e92a6d56a0e3b0fc30e17af0dMark Andrews if (pFrame->fFlags & DBGFSTACKFRAME_FLAGS_LAST)
70ec7dd74103fa9e92a6d56a0e3b0fc30e17af0dMark Andrews return VERR_NO_MORE_FILES;
70ec7dd74103fa9e92a6d56a0e3b0fc30e17af0dMark Andrews
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley /*
3740b569ae76295b941d57a724a43beb75b533baBob Halley * Read the raw frame data.
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence */
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence const DBGFADDRESS AddrOldPC = pFrame->AddrPC;
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley const unsigned cbRetAddr = DBGFReturnTypeSize(pFrame->enmReturnType);
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence unsigned cbStackItem;
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley switch (AddrOldPC.fFlags & DBGFADDRESS_FLAGS_TYPE_MASK)
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley {
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley case DBGFADDRESS_FLAGS_FAR16: cbStackItem = 2; break;
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley case DBGFADDRESS_FLAGS_FAR32: cbStackItem = 4; break;
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley case DBGFADDRESS_FLAGS_FAR64: cbStackItem = 8; break;
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley default: cbStackItem = 4; break; /// @todo 64-bit guests.
26f327f1f53afdb8256affa1c197ed138bf3cb2fAndreas Gustafsson }
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence union
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley {
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley uint64_t *pu64;
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley uint32_t *pu32;
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley uint16_t *pu16;
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley uint8_t *pb;
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley void *pv;
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley } u, uRet, uArgs, uBp;
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley size_t cbRead = cbRetAddr + cbStackItem + sizeof(pFrame->Args);
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley u.pv = alloca(cbRead);
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley uBp = u;
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley uRet.pb = u.pb + cbStackItem;
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley uArgs.pb = u.pb + cbStackItem + cbRetAddr;
27809a2ee5db141b684e53bf1d94da26e9f92d3aMark Andrews
27809a2ee5db141b684e53bf1d94da26e9f92d3aMark Andrews Assert(DBGFADDRESS_IS_VALID(&pFrame->AddrFrame));
afdb3abb9b06ed4070ac9021f1f4427b4cb3a286Bob Halley int rc = dbgfR3Read(pVM, u.pv,
585529aaeb95a71cd3d95df2602a4688fc7c3292David Lawrence pFrame->fFlags & DBGFSTACKFRAME_FLAGS_ALL_VALID
585529aaeb95a71cd3d95df2602a4688fc7c3292David Lawrence ? pFrame->AddrReturnFrame.FlatPtr
585529aaeb95a71cd3d95df2602a4688fc7c3292David Lawrence : pFrame->AddrFrame.FlatPtr,
232fd751edcb5dd2b1fd2666e039efe83d2e2b55Michael Sawyer cbRead, &cbRead);
585529aaeb95a71cd3d95df2602a4688fc7c3292David Lawrence if ( VBOX_FAILURE(rc)
585529aaeb95a71cd3d95df2602a4688fc7c3292David Lawrence || cbRead < cbRetAddr + cbStackItem)
585529aaeb95a71cd3d95df2602a4688fc7c3292David Lawrence pFrame->fFlags |= DBGFSTACKFRAME_FLAGS_LAST;
585529aaeb95a71cd3d95df2602a4688fc7c3292David Lawrence
585529aaeb95a71cd3d95df2602a4688fc7c3292David Lawrence /*
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley * The first step is taken in a different way than the others.
3740b569ae76295b941d57a724a43beb75b533baBob Halley */
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley if (!(pFrame->fFlags & DBGFSTACKFRAME_FLAGS_ALL_VALID))
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley {
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley pFrame->fFlags |= DBGFSTACKFRAME_FLAGS_ALL_VALID;
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley pFrame->iFrame = 0;
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley /* Current PC - set by caller, just find symbol & line. */
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley if (DBGFADDRESS_IS_VALID(&pFrame->AddrPC))
26f327f1f53afdb8256affa1c197ed138bf3cb2fAndreas Gustafsson {
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley pFrame->pSymPC = DBGFR3SymbolByAddrAlloc(pVM, pFrame->AddrPC.FlatPtr, NULL);
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence pFrame->pLinePC = DBGFR3LineByAddrAlloc(pVM, pFrame->AddrPC.FlatPtr, NULL);
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley }
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley }
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley else /* 2nd and subsequent steps */
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley {
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley /* frame, pc and stack is taken from the existing frames return members. */
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley pFrame->AddrFrame = pFrame->AddrReturnFrame;
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley pFrame->AddrPC = pFrame->AddrReturnPC;
df0f58959ed82a2a43ca8d816ce9592541df9f2fMark Andrews pFrame->pSymPC = pFrame->pSymReturnPC;
4d6964d70a114b53a11a3bd778d9b8f5179a7934Bob Halley pFrame->pLinePC = pFrame->pLineReturnPC;
afdb3abb9b06ed4070ac9021f1f4427b4cb3a286Bob Halley
94e25967cda41b886e33ec254b917d21df21a187Bob Halley /* increment the frame number. */
4b87939256ede703385e9cab92d3c58d03c31098Mark Andrews pFrame->iFrame++;
94e25967cda41b886e33ec254b917d21df21a187Bob Halley }
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence /*
94e25967cda41b886e33ec254b917d21df21a187Bob Halley * Return Frame address.
4b87939256ede703385e9cab92d3c58d03c31098Mark Andrews */
4b87939256ede703385e9cab92d3c58d03c31098Mark Andrews pFrame->AddrReturnFrame = pFrame->AddrFrame;
94e25967cda41b886e33ec254b917d21df21a187Bob Halley switch (cbStackItem)
94e25967cda41b886e33ec254b917d21df21a187Bob Halley {
94e25967cda41b886e33ec254b917d21df21a187Bob Halley case 2: pFrame->AddrReturnFrame.off = *uBp.pu16; break;
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence case 4: pFrame->AddrReturnFrame.off = *uBp.pu32; break;
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence case 8: pFrame->AddrReturnFrame.off = *uBp.pu64; break;
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence default: AssertMsgFailed(("cbStackItem=%d\n", cbStackItem)); return VERR_INTERNAL_ERROR;
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence }
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence pFrame->AddrReturnFrame.FlatPtr += pFrame->AddrReturnFrame.off - pFrame->AddrFrame.off;
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence /*
df0f58959ed82a2a43ca8d816ce9592541df9f2fMark Andrews * Return PC and Stack Addresses.
70ec7dd74103fa9e92a6d56a0e3b0fc30e17af0dMark Andrews */
70ec7dd74103fa9e92a6d56a0e3b0fc30e17af0dMark Andrews /** @todo AddrReturnStack is not correct for stdcall and pascal. (requires scope info) */
df0f58959ed82a2a43ca8d816ce9592541df9f2fMark Andrews pFrame->AddrReturnStack = pFrame->AddrFrame;
df0f58959ed82a2a43ca8d816ce9592541df9f2fMark Andrews pFrame->AddrReturnStack.off += cbStackItem + cbRetAddr;
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence pFrame->AddrReturnStack.FlatPtr += cbStackItem + cbRetAddr;
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence
df0f58959ed82a2a43ca8d816ce9592541df9f2fMark Andrews pFrame->AddrReturnPC = pFrame->AddrPC;
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence switch (pFrame->enmReturnType)
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence {
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence case DBGFRETURNTYPE_NEAR16:
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence if (DBGFADDRESS_IS_VALID(&pFrame->AddrReturnPC))
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence {
5eb91bd90e3ad3426e5e3213031556a737cf3809Mark Andrews pFrame->AddrReturnPC.FlatPtr += *uRet.pu16 - pFrame->AddrReturnPC.off;
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence pFrame->AddrReturnPC.off = *uRet.pu16;
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence }
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley else
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence DBGFR3AddrFromFlat(pVM, &pFrame->AddrReturnPC, *uRet.pu16);
94e25967cda41b886e33ec254b917d21df21a187Bob Halley break;
94e25967cda41b886e33ec254b917d21df21a187Bob Halley case DBGFRETURNTYPE_NEAR32:
94e25967cda41b886e33ec254b917d21df21a187Bob Halley if (DBGFADDRESS_IS_VALID(&pFrame->AddrReturnPC))
94e25967cda41b886e33ec254b917d21df21a187Bob Halley {
afdb3abb9b06ed4070ac9021f1f4427b4cb3a286Bob Halley pFrame->AddrReturnPC.FlatPtr += *uRet.pu32 - pFrame->AddrReturnPC.off;
26f327f1f53afdb8256affa1c197ed138bf3cb2fAndreas Gustafsson pFrame->AddrReturnPC.off = *uRet.pu32;
afdb3abb9b06ed4070ac9021f1f4427b4cb3a286Bob Halley }
4b87939256ede703385e9cab92d3c58d03c31098Mark Andrews else
afdb3abb9b06ed4070ac9021f1f4427b4cb3a286Bob Halley DBGFR3AddrFromFlat(pVM, &pFrame->AddrReturnPC, *uRet.pu32);
afdb3abb9b06ed4070ac9021f1f4427b4cb3a286Bob Halley break;
afdb3abb9b06ed4070ac9021f1f4427b4cb3a286Bob Halley case DBGFRETURNTYPE_NEAR64:
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence if (DBGFADDRESS_IS_VALID(&pFrame->AddrReturnPC))
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence {
afdb3abb9b06ed4070ac9021f1f4427b4cb3a286Bob Halley pFrame->AddrReturnPC.FlatPtr += *uRet.pu64 - pFrame->AddrReturnPC.off;
4b87939256ede703385e9cab92d3c58d03c31098Mark Andrews pFrame->AddrReturnPC.off = *uRet.pu64;
4b87939256ede703385e9cab92d3c58d03c31098Mark Andrews }
afdb3abb9b06ed4070ac9021f1f4427b4cb3a286Bob Halley else
afdb3abb9b06ed4070ac9021f1f4427b4cb3a286Bob Halley DBGFR3AddrFromFlat(pVM, &pFrame->AddrReturnPC, *uRet.pu64);
afdb3abb9b06ed4070ac9021f1f4427b4cb3a286Bob Halley break;
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence case DBGFRETURNTYPE_FAR16:
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence DBGFR3AddrFromSelOff(pVM, &pFrame->AddrReturnPC, uRet.pu16[1], uRet.pu16[0]);
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence break;
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence case DBGFRETURNTYPE_FAR32:
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence DBGFR3AddrFromSelOff(pVM, &pFrame->AddrReturnPC, uRet.pu16[2], uRet.pu32[0]);
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence break;
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence case DBGFRETURNTYPE_FAR64:
70ec7dd74103fa9e92a6d56a0e3b0fc30e17af0dMark Andrews DBGFR3AddrFromSelOff(pVM, &pFrame->AddrReturnPC, uRet.pu16[4], uRet.pu64[0]);
70ec7dd74103fa9e92a6d56a0e3b0fc30e17af0dMark Andrews break;
70ec7dd74103fa9e92a6d56a0e3b0fc30e17af0dMark Andrews case DBGFRETURNTYPE_IRET16:
70ec7dd74103fa9e92a6d56a0e3b0fc30e17af0dMark Andrews DBGFR3AddrFromSelOff(pVM, &pFrame->AddrReturnPC, uRet.pu16[1], uRet.pu16[0]);
70ec7dd74103fa9e92a6d56a0e3b0fc30e17af0dMark Andrews break;
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence case DBGFRETURNTYPE_IRET32:
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence DBGFR3AddrFromSelOff(pVM, &pFrame->AddrReturnPC, uRet.pu16[2], uRet.pu32[0]);
70ec7dd74103fa9e92a6d56a0e3b0fc30e17af0dMark Andrews break;
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence case DBGFRETURNTYPE_IRET32_PRIV:
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence DBGFR3AddrFromSelOff(pVM, &pFrame->AddrReturnPC, uRet.pu16[2], uRet.pu32[0]);
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence break;
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence case DBGFRETURNTYPE_IRET32_V86:
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence DBGFR3AddrFromSelOff(pVM, &pFrame->AddrReturnPC, uRet.pu16[2], uRet.pu32[0]);
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence break;
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence case DBGFRETURNTYPE_IRET64:
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence DBGFR3AddrFromSelOff(pVM, &pFrame->AddrReturnPC, uRet.pu16[4], uRet.pu64[0]);
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence break;
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence default:
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence AssertMsgFailed(("enmReturnType=%d\n", pFrame->enmReturnType));
afdb3abb9b06ed4070ac9021f1f4427b4cb3a286Bob Halley return VERR_INVALID_PARAMETER;
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence }
9e8947d9e606b967d0792d0ab1ee7afac5e5f39dMark Andrews
afdb3abb9b06ed4070ac9021f1f4427b4cb3a286Bob Halley pFrame->pSymReturnPC = DBGFR3SymbolByAddrAlloc(pVM, pFrame->AddrReturnPC.FlatPtr, NULL);
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence pFrame->pLineReturnPC = DBGFR3LineByAddrAlloc(pVM, pFrame->AddrReturnPC.FlatPtr, NULL);
afdb3abb9b06ed4070ac9021f1f4427b4cb3a286Bob Halley
afdb3abb9b06ed4070ac9021f1f4427b4cb3a286Bob Halley /*
afdb3abb9b06ed4070ac9021f1f4427b4cb3a286Bob Halley * The arguments.
afdb3abb9b06ed4070ac9021f1f4427b4cb3a286Bob Halley */
afdb3abb9b06ed4070ac9021f1f4427b4cb3a286Bob Halley memcpy(&pFrame->Args, uArgs.pv, sizeof(pFrame->Args));
94e25967cda41b886e33ec254b917d21df21a187Bob Halley
26f327f1f53afdb8256affa1c197ed138bf3cb2fAndreas Gustafsson return VINF_SUCCESS;
bf6d2e39124ab3d51c253f7acad9a4abef059be6Bob Halley}
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence
94e25967cda41b886e33ec254b917d21df21a187Bob Halley
bf6d2e39124ab3d51c253f7acad9a4abef059be6Bob Halley/**
94e25967cda41b886e33ec254b917d21df21a187Bob Halley * Walks the entire stack allocating memory as we walk.
bf6d2e39124ab3d51c253f7acad9a4abef059be6Bob Halley */
94e25967cda41b886e33ec254b917d21df21a187Bob Halleystatic DECLCALLBACK(int) dbgfR3StackWalkCtxFull(PVM pVM, PDBGFSTACKFRAME pFrame, PCCPUMCTXCORE pCtxCore, bool fGuest)
bf6d2e39124ab3d51c253f7acad9a4abef059be6Bob Halley{
94e25967cda41b886e33ec254b917d21df21a187Bob Halley pFrame->pNext = NULL;
bf6d2e39124ab3d51c253f7acad9a4abef059be6Bob Halley pFrame->pFirst = NULL;
94e25967cda41b886e33ec254b917d21df21a187Bob Halley
94e25967cda41b886e33ec254b917d21df21a187Bob Halley /* alloc first frame. */
94e25967cda41b886e33ec254b917d21df21a187Bob Halley PDBGFSTACKFRAME pCur = (PDBGFSTACKFRAME)MMR3HeapAllocZ(pVM, MM_TAG_DBGF_STACK, sizeof(*pCur));
94e25967cda41b886e33ec254b917d21df21a187Bob Halley if (!pCur)
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence return VERR_NO_MEMORY;
26f327f1f53afdb8256affa1c197ed138bf3cb2fAndreas Gustafsson
26f327f1f53afdb8256affa1c197ed138bf3cb2fAndreas Gustafsson /* copy input frame */
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley pCur->AddrFrame = pFrame->AddrFrame;
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence pCur->AddrStack = pFrame->AddrStack;
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence pCur->AddrPC = pFrame->AddrPC;
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence pCur->enmReturnType = pFrame->enmReturnType;
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence pCur->pNext = NULL;
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence pCur->pFirst = pCur;
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence int rc = VINF_SUCCESS;
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence if (!DBGFADDRESS_IS_VALID(&pCur->AddrPC))
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence rc = DBGFR3AddrFromSelOff(pVM, &pCur->AddrPC, pCtxCore->cs, pCtxCore->eip);
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence if (VBOX_SUCCESS(rc) /*&& pCur->enmReturnType == DBGFRETURNTYPE_INVALID*/)
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence {
94e25967cda41b886e33ec254b917d21df21a187Bob Halley switch (pCur->AddrPC.fFlags & DBGFADDRESS_FLAGS_TYPE_MASK)
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley {
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley case DBGFADDRESS_FLAGS_FAR16: pCur->enmReturnType = DBGFRETURNTYPE_NEAR16; break;
c89ac488df58cf6a37918cd00236eedf015830f8Andreas Gustafsson case DBGFADDRESS_FLAGS_FAR32: pCur->enmReturnType = DBGFRETURNTYPE_NEAR32; break;
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley case DBGFADDRESS_FLAGS_FAR64: pCur->enmReturnType = DBGFRETURNTYPE_NEAR64; break;
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence default: pCur->enmReturnType = DBGFRETURNTYPE_NEAR32; break; /// @todo 64-bit guests
94e25967cda41b886e33ec254b917d21df21a187Bob Halley }
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence }
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence uint64_t u64Mask = UINT64_MAX;
94e25967cda41b886e33ec254b917d21df21a187Bob Halley if (VBOX_SUCCESS(rc) && DBGFADDRESS_IS_FAR16(&pCur->AddrPC) && fGuest)
94e25967cda41b886e33ec254b917d21df21a187Bob Halley u64Mask = UINT16_MAX;
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence if (VBOX_SUCCESS(rc) && !DBGFADDRESS_IS_VALID(&pCur->AddrStack))
26f327f1f53afdb8256affa1c197ed138bf3cb2fAndreas Gustafsson rc = DBGFR3AddrFromSelOff(pVM, &pCur->AddrStack, pCtxCore->ss, pCtxCore->esp & u64Mask);
26f327f1f53afdb8256affa1c197ed138bf3cb2fAndreas Gustafsson if (VBOX_SUCCESS(rc) && !DBGFADDRESS_IS_VALID(&pCur->AddrFrame))
26f327f1f53afdb8256affa1c197ed138bf3cb2fAndreas Gustafsson rc = DBGFR3AddrFromSelOff(pVM, &pCur->AddrFrame, pCtxCore->ss, pCtxCore->ebp & u64Mask);
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence /*
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence * The first frame.
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence */
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence if (VBOX_SUCCESS(rc))
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence rc = dbgfR3StackWalk(pVM, pCur);
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence if (VBOX_FAILURE(rc))
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence {
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley DBGFR3StackWalkEnd(pVM, pCur);
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley return rc;
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley }
94e25967cda41b886e33ec254b917d21df21a187Bob Halley
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence /*
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley * The other frames.
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley */
94e25967cda41b886e33ec254b917d21df21a187Bob Halley DBGFSTACKFRAME Next = *pCur;
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence while (!(pCur->fFlags & (DBGFSTACKFRAME_FLAGS_LAST | DBGFSTACKFRAME_FLAGS_MAX_DEPTH | DBGFSTACKFRAME_FLAGS_LOOP)))
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence {
94e25967cda41b886e33ec254b917d21df21a187Bob Halley /* try walk. */
4ad9b25e6ddf948ffb3b8198c5540d251f26c52eDavid Lawrence rc = dbgfR3StackWalk(pVM, &Next);
4ad9b25e6ddf948ffb3b8198c5540d251f26c52eDavid Lawrence if (VBOX_FAILURE(rc))
26f327f1f53afdb8256affa1c197ed138bf3cb2fAndreas Gustafsson break;
4ad9b25e6ddf948ffb3b8198c5540d251f26c52eDavid Lawrence
4ad9b25e6ddf948ffb3b8198c5540d251f26c52eDavid Lawrence /* add the next frame to the chain. */
4ad9b25e6ddf948ffb3b8198c5540d251f26c52eDavid Lawrence PDBGFSTACKFRAME pNext = (PDBGFSTACKFRAME)MMR3HeapAlloc(pVM, MM_TAG_DBGF_STACK, sizeof(*pNext));
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence if (!pNext)
4ad9b25e6ddf948ffb3b8198c5540d251f26c52eDavid Lawrence {
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence DBGFR3StackWalkEnd(pVM, pCur);
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence return VERR_NO_MEMORY;
4ad9b25e6ddf948ffb3b8198c5540d251f26c52eDavid Lawrence }
4ad9b25e6ddf948ffb3b8198c5540d251f26c52eDavid Lawrence *pNext = Next;
4ad9b25e6ddf948ffb3b8198c5540d251f26c52eDavid Lawrence pCur = pCur->pNext = pNext;
4ad9b25e6ddf948ffb3b8198c5540d251f26c52eDavid Lawrence Assert(pCur->pNext == NULL);
4ad9b25e6ddf948ffb3b8198c5540d251f26c52eDavid Lawrence
4ad9b25e6ddf948ffb3b8198c5540d251f26c52eDavid Lawrence /* check for loop */
4ad9b25e6ddf948ffb3b8198c5540d251f26c52eDavid Lawrence for (PDBGFSTACKFRAME pLoop = pCur->pFirst; pLoop && pLoop != pCur; pLoop = pLoop->pNext)
4ad9b25e6ddf948ffb3b8198c5540d251f26c52eDavid Lawrence if (pLoop->AddrFrame.FlatPtr == pCur->AddrFrame.FlatPtr)
4ad9b25e6ddf948ffb3b8198c5540d251f26c52eDavid Lawrence {
0874abad14e3e9ecfc3dc1a1a2b9969f2f027724Mark Andrews pCur->fFlags |= DBGFSTACKFRAME_FLAGS_LOOP;
4ad9b25e6ddf948ffb3b8198c5540d251f26c52eDavid Lawrence break;
4ad9b25e6ddf948ffb3b8198c5540d251f26c52eDavid Lawrence }
4ad9b25e6ddf948ffb3b8198c5540d251f26c52eDavid Lawrence
114d0d1642b5ede0ab154532159fe38c30762d82David Lawrence /* check for insane recursion */
114d0d1642b5ede0ab154532159fe38c30762d82David Lawrence if (pCur->iFrame >= 2048)
ae5df22719a9e2c252ea1fcccd2cadb44c8bd8d4Mark Andrews pCur->fFlags |= DBGFSTACKFRAME_FLAGS_MAX_DEPTH;
585529aaeb95a71cd3d95df2602a4688fc7c3292David Lawrence }
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence
585529aaeb95a71cd3d95df2602a4688fc7c3292David Lawrence *pFrame = *pCur->pFirst;
114d0d1642b5ede0ab154532159fe38c30762d82David Lawrence return rc;
114d0d1642b5ede0ab154532159fe38c30762d82David Lawrence}
114d0d1642b5ede0ab154532159fe38c30762d82David Lawrence
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence
26f327f1f53afdb8256affa1c197ed138bf3cb2fAndreas Gustafsson/**
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence * Begins a stack walk.
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence * This will construct and obtain the first frame.
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence *
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence * @returns VINF_SUCCESS on success.
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence * @returns VERR_NO_MEMORY if we're out of memory.
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence * @param pVM The VM handle.
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence * @param pFrame The stack frame info structure.
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence * On input this structure must be memset to zero.
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence * If wanted, the AddrPC, AddrStack and AddrFrame fields may be set
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence * to valid addresses after memsetting it. Any of those fields not set
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence * will be fetched from the guest CPU state.
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence * On output the structure will contain all the information we were able to
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence * obtain about the stack frame.
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence */
6fa1cb5754695d550a58c6e8978fda65f5146af7David LawrenceDBGFR3DECL(int) DBGFR3StackWalkBeginGuest(PVM pVM, PDBGFSTACKFRAME pFrame)
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence{
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence pFrame->pFirst = NULL;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence pFrame->pNext = NULL;
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence
269c07173e24d7811e2fd09304023e3104fcbe0bMark Andrews PVMREQ pReq;
269c07173e24d7811e2fd09304023e3104fcbe0bMark Andrews int rc = VMR3ReqCall(pVM, &pReq, RT_INDEFINITE_WAIT, (PFNRT)dbgfR3StackWalkCtxFull, 4,
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence pVM, pFrame, CPUMGetGuestCtxCore(pVM), true);
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence if (VBOX_SUCCESS(rc))
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence rc = pReq->iStatus;
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence VMR3ReqFree(pReq);
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence return rc;
5fa46bc91672ef5737aee6f99763161511566c24Tinderbox User}
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence/**
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence * Begins a stack walk.
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence * This will construct and obtain the first frame.
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence *
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence * @returns VINF_SUCCESS on success.
114d0d1642b5ede0ab154532159fe38c30762d82David Lawrence * @returns VERR_NO_MEMORY if we're out of memory.
26f327f1f53afdb8256affa1c197ed138bf3cb2fAndreas Gustafsson * @param pVM The VM handle.
585529aaeb95a71cd3d95df2602a4688fc7c3292David Lawrence * @param pFrame The stack frame info structure.
585529aaeb95a71cd3d95df2602a4688fc7c3292David Lawrence * On input this structure must be memset to zero.
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence * If wanted, the AddrPC, AddrStack and AddrFrame fields may be set
114d0d1642b5ede0ab154532159fe38c30762d82David Lawrence * to valid addresses after memsetting it. Any of those fields not set
114d0d1642b5ede0ab154532159fe38c30762d82David Lawrence * will be fetched from the hypervisor CPU state.
114d0d1642b5ede0ab154532159fe38c30762d82David Lawrence * On output the structure will contain all the information we were able to
c8563aaf86c04f0e2284bcc8e444a0651c157ea0Andreas Gustafsson * obtain about the stack frame.
c8563aaf86c04f0e2284bcc8e444a0651c157ea0Andreas Gustafsson */
c8563aaf86c04f0e2284bcc8e444a0651c157ea0Andreas GustafssonDBGFR3DECL(int) DBGFR3StackWalkBeginHyper(PVM pVM, PDBGFSTACKFRAME pFrame)
c8563aaf86c04f0e2284bcc8e444a0651c157ea0Andreas Gustafsson{
c8563aaf86c04f0e2284bcc8e444a0651c157ea0Andreas Gustafsson pFrame->pFirst = NULL;
c8563aaf86c04f0e2284bcc8e444a0651c157ea0Andreas Gustafsson pFrame->pNext = NULL;
6184f9fc1e65ef131ea308a1a92882595bb1aeeaAndreas Gustafsson
6184f9fc1e65ef131ea308a1a92882595bb1aeeaAndreas Gustafsson PVMREQ pReq;
c8563aaf86c04f0e2284bcc8e444a0651c157ea0Andreas Gustafsson int rc = VMR3ReqCall(pVM, &pReq, RT_INDEFINITE_WAIT, (PFNRT)dbgfR3StackWalkCtxFull, 4,
c36f45e354c0d5b6ab9f821bfe315d0ce9d95a29Mark Andrews pVM, pFrame, CPUMGetHyperCtxCore(pVM), 4);
ff6e834f7d48d4b116627ecf8cafa0fbacc25bd4Andreas Gustafsson if (VBOX_SUCCESS(rc))
ff6e834f7d48d4b116627ecf8cafa0fbacc25bd4Andreas Gustafsson rc = pReq->iStatus;
ff6e834f7d48d4b116627ecf8cafa0fbacc25bd4Andreas Gustafsson VMR3ReqFree(pReq);
ff6e834f7d48d4b116627ecf8cafa0fbacc25bd4Andreas Gustafsson
ff6e834f7d48d4b116627ecf8cafa0fbacc25bd4Andreas Gustafsson return rc;
6475e22cc98c2386d0a259089e959bf8616f661dAutomatic Updater}
c8563aaf86c04f0e2284bcc8e444a0651c157ea0Andreas Gustafsson
186e7f37c9fc985a7a7264cc8170e48a25bed434Mark Andrews
186e7f37c9fc985a7a7264cc8170e48a25bed434Mark Andrews/**
186e7f37c9fc985a7a7264cc8170e48a25bed434Mark Andrews * Gets the next stack frame.
186e7f37c9fc985a7a7264cc8170e48a25bed434Mark Andrews *
186e7f37c9fc985a7a7264cc8170e48a25bed434Mark Andrews * @returns VINF_SUCCESS
186e7f37c9fc985a7a7264cc8170e48a25bed434Mark Andrews * @returns VERR_NO_MORE_FILES if not more stack frames.
186e7f37c9fc985a7a7264cc8170e48a25bed434Mark Andrews * @param pVM The VM handle.
186e7f37c9fc985a7a7264cc8170e48a25bed434Mark Andrews * @param pFrame Pointer to the current frame on input, content is replaced with the next frame on successful return.
186e7f37c9fc985a7a7264cc8170e48a25bed434Mark Andrews */
186e7f37c9fc985a7a7264cc8170e48a25bed434Mark AndrewsDBGFR3DECL(int) DBGFR3StackWalkNext(PVM pVM, PDBGFSTACKFRAME pFrame)
186e7f37c9fc985a7a7264cc8170e48a25bed434Mark Andrews{
186e7f37c9fc985a7a7264cc8170e48a25bed434Mark Andrews if (pFrame->pNext)
186e7f37c9fc985a7a7264cc8170e48a25bed434Mark Andrews {
903247531a10d699ef239a7351554ba0a1e3cd22Evan Hunt *pFrame = *pFrame->pNext;
903247531a10d699ef239a7351554ba0a1e3cd22Evan Hunt return VINF_SUCCESS;
903247531a10d699ef239a7351554ba0a1e3cd22Evan Hunt }
903247531a10d699ef239a7351554ba0a1e3cd22Evan Hunt return VERR_NO_MORE_FILES;
903247531a10d699ef239a7351554ba0a1e3cd22Evan Hunt}
903247531a10d699ef239a7351554ba0a1e3cd22Evan Hunt
903247531a10d699ef239a7351554ba0a1e3cd22Evan Hunt
903247531a10d699ef239a7351554ba0a1e3cd22Evan Hunt/**
903247531a10d699ef239a7351554ba0a1e3cd22Evan Hunt * Ends a stack walk process.
903247531a10d699ef239a7351554ba0a1e3cd22Evan Hunt *
903247531a10d699ef239a7351554ba0a1e3cd22Evan Hunt * This *must* be called after a successful first call to any of the stack
903247531a10d699ef239a7351554ba0a1e3cd22Evan Hunt * walker functions. If not called we will leak memory or other resources.
903247531a10d699ef239a7351554ba0a1e3cd22Evan Hunt *
903247531a10d699ef239a7351554ba0a1e3cd22Evan Hunt * @param pVM The VM handle.
903247531a10d699ef239a7351554ba0a1e3cd22Evan Hunt * @param pFrame The stackframe as returned by the last stack walk call.
903247531a10d699ef239a7351554ba0a1e3cd22Evan Hunt */
903247531a10d699ef239a7351554ba0a1e3cd22Evan HuntDBGFR3DECL(void) DBGFR3StackWalkEnd(PVM pVM, PDBGFSTACKFRAME pFrame)
903247531a10d699ef239a7351554ba0a1e3cd22Evan Hunt{
903247531a10d699ef239a7351554ba0a1e3cd22Evan Hunt if (!pFrame || !pFrame->pFirst)
903247531a10d699ef239a7351554ba0a1e3cd22Evan Hunt return;
903247531a10d699ef239a7351554ba0a1e3cd22Evan Hunt
903247531a10d699ef239a7351554ba0a1e3cd22Evan Hunt pFrame = pFrame->pFirst;
903247531a10d699ef239a7351554ba0a1e3cd22Evan Hunt while (pFrame)
903247531a10d699ef239a7351554ba0a1e3cd22Evan Hunt {
903247531a10d699ef239a7351554ba0a1e3cd22Evan Hunt PDBGFSTACKFRAME pCur = pFrame;
789252d55f025db52ee02aa933c9f09a4aadfa97Evan Hunt pFrame = pCur->pNext;
789252d55f025db52ee02aa933c9f09a4aadfa97Evan Hunt if (pFrame)
789252d55f025db52ee02aa933c9f09a4aadfa97Evan Hunt {
789252d55f025db52ee02aa933c9f09a4aadfa97Evan Hunt if (pCur->pSymReturnPC == pFrame->pSymPC)
789252d55f025db52ee02aa933c9f09a4aadfa97Evan Hunt pFrame->pSymPC = NULL;
789252d55f025db52ee02aa933c9f09a4aadfa97Evan Hunt if (pCur->pSymReturnPC == pFrame->pSymReturnPC)
789252d55f025db52ee02aa933c9f09a4aadfa97Evan Hunt pFrame->pSymReturnPC = NULL;
789252d55f025db52ee02aa933c9f09a4aadfa97Evan Hunt
903247531a10d699ef239a7351554ba0a1e3cd22Evan Hunt if (pCur->pSymPC == pFrame->pSymPC)
789252d55f025db52ee02aa933c9f09a4aadfa97Evan Hunt pFrame->pSymPC = NULL;
789252d55f025db52ee02aa933c9f09a4aadfa97Evan Hunt if (pCur->pSymPC == pFrame->pSymReturnPC)
903247531a10d699ef239a7351554ba0a1e3cd22Evan Hunt pFrame->pSymReturnPC = NULL;
789252d55f025db52ee02aa933c9f09a4aadfa97Evan Hunt
789252d55f025db52ee02aa933c9f09a4aadfa97Evan Hunt if (pCur->pLineReturnPC == pFrame->pLinePC)
789252d55f025db52ee02aa933c9f09a4aadfa97Evan Hunt pFrame->pLinePC = NULL;
789252d55f025db52ee02aa933c9f09a4aadfa97Evan Hunt if (pCur->pLineReturnPC == pFrame->pLineReturnPC)
789252d55f025db52ee02aa933c9f09a4aadfa97Evan Hunt pFrame->pLineReturnPC = NULL;
789252d55f025db52ee02aa933c9f09a4aadfa97Evan Hunt
186e7f37c9fc985a7a7264cc8170e48a25bed434Mark Andrews if (pCur->pLinePC == pFrame->pLinePC)
186e7f37c9fc985a7a7264cc8170e48a25bed434Mark Andrews pFrame->pLinePC = NULL;
186e7f37c9fc985a7a7264cc8170e48a25bed434Mark Andrews if (pCur->pLinePC == pFrame->pLineReturnPC)
186e7f37c9fc985a7a7264cc8170e48a25bed434Mark Andrews pFrame->pLineReturnPC = NULL;
186e7f37c9fc985a7a7264cc8170e48a25bed434Mark Andrews }
186e7f37c9fc985a7a7264cc8170e48a25bed434Mark Andrews
186e7f37c9fc985a7a7264cc8170e48a25bed434Mark Andrews DBGFR3SymbolFree(pCur->pSymPC);
186e7f37c9fc985a7a7264cc8170e48a25bed434Mark Andrews DBGFR3SymbolFree(pCur->pSymReturnPC);
96ea71632887c58a9d00f47eb318bf76b35903c3Mark Andrews DBGFR3LineFree(pCur->pLinePC);
186e7f37c9fc985a7a7264cc8170e48a25bed434Mark Andrews DBGFR3LineFree(pCur->pLineReturnPC);
186e7f37c9fc985a7a7264cc8170e48a25bed434Mark Andrews
pCur->pNext = NULL;
pCur->pFirst = NULL;
pCur->fFlags = 0;
MMR3HeapFree(pCur);
}
}