DBGFStack.cpp revision bc8991845b5bd7e98758795748d3d76408756793
/* $Id$ */
/** @file
* DBGF - Debugger Facility, Call Stack Analyser.
*/
/*
* Copyright (C) 2006-2007 Sun Microsystems, Inc.
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 USA or visit http://www.sun.com if you need
* additional information or have any questions.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#define LOG_GROUP LOG_GROUP_DBGF
#include "DBGFInternal.h"
/**
* Read stack memory.
*/
DECLINLINE(int) dbgfR3Read(PVM pVM, VMCPUID idCpu, void *pvBuf, PCDBGFADDRESS pSrcAddr, size_t cb, size_t *pcbRead)
{
if (RT_FAILURE(rc))
{
/* fallback: byte by byte and zero the ones we fail to read. */
{
if (RT_FAILURE(rc))
break;
}
if (cbRead)
rc = VINF_SUCCESS;
}
else
return rc;
}
/**
* Internal worker routine.
*
* On x86 the typical stack frame layout is like this:
* .. ..
* 16 parameter 2
* 12 parameter 1
* 8 parameter 0
* 4 return address
* 0 old ebp; current ebp points here
*
* @todo Add AMD64 support (needs teaming up with the module management for
* unwind tables).
*/
{
/*
* Stop if we got a read error in the previous run.
*/
return VERR_NO_MORE_FILES;
/*
* Read the raw frame data.
*/
unsigned cbStackItem;
{
}
union
{
void *pv;
uBp = u;
if ( RT_FAILURE(rc)
/*
* The first step is taken in a different way than the others.
*/
{
/* Current PC - set by caller, just find symbol & line. */
{
}
}
else /* 2nd and subsequent steps */
{
/* frame, pc and stack is taken from the existing frames return members. */
/* increment the frame number. */
}
/*
* Return Frame address.
*/
switch (cbStackItem)
{
}
/*
* Return PC and Stack Addresses.
*/
/** @todo AddrReturnStack is not correct for stdcall and pascal. (requires scope info) */
switch (pFrame->enmReturnType)
{
case DBGFRETURNTYPE_NEAR16:
{
}
else
break;
case DBGFRETURNTYPE_NEAR32:
{
}
else
break;
case DBGFRETURNTYPE_NEAR64:
{
}
else
break;
case DBGFRETURNTYPE_FAR16:
break;
case DBGFRETURNTYPE_FAR32:
break;
case DBGFRETURNTYPE_FAR64:
break;
case DBGFRETURNTYPE_IRET16:
break;
case DBGFRETURNTYPE_IRET32:
break;
break;
break;
case DBGFRETURNTYPE_IRET64:
break;
default:
return VERR_INVALID_PARAMETER;
}
/*
* The arguments.
*/
return VINF_SUCCESS;
}
/**
* Walks the entire stack allocating memory as we walk.
*/
{
/* alloc first frame. */
if (!pCur)
return VERR_NO_MEMORY;
/*
* Initialize the frame.
*/
int rc = VINF_SUCCESS;
if (pAddrPC)
else
if (RT_SUCCESS(rc))
{
if (enmReturnType == DBGFRETURNTYPE_INVALID)
{
}
if (enmCodeType == DBGFCODETYPE_RING0)
else
if (enmCodeType == DBGFCODETYPE_HYPER)
{
if (CpuMode == CPUMMODE_REAL)
else if (CpuMode == CPUMMODE_PROTECTED)
}
if (pAddrStack)
else
if (pAddrFrame)
else if (RT_SUCCESS(rc))
}
else
/*
* The first frame.
*/
if (RT_SUCCESS(rc))
if (RT_FAILURE(rc))
{
return rc;
}
/*
* The other frames.
*/
while (!(pCur->fFlags & (DBGFSTACKFRAME_FLAGS_LAST | DBGFSTACKFRAME_FLAGS_MAX_DEPTH | DBGFSTACKFRAME_FLAGS_LOOP)))
{
/* try walk. */
if (RT_FAILURE(rc))
break;
/* add the next frame to the chain. */
if (!pNext)
{
return VERR_NO_MEMORY;
}
/* check for loop */
{
break;
}
/* check for insane recursion */
}
return rc;
}
/**
* Common worker for DBGFR3StackWalkBeginGuestEx, DBGFR3StackWalkBeginHyperEx,
* DBGFR3StackWalkBeginGuest and DBGFR3StackWalkBeginHyper.
*/
{
#if HC_ARCH_BITS == 64
/** @todo Not implemented for 64 bits hosts yet */
if (enmCodeType == DBGFCODETYPE_RING0)
return VINF_SUCCESS;
#endif
/*
* Validate parameters.
*/
*ppFirstFrame = NULL;
if (pAddrFrame)
if (pAddrStack)
if (pAddrPC)
AssertReturn(enmReturnType >= DBGFRETURNTYPE_INVALID && enmReturnType < DBGFRETURNTYPE_END, VERR_INVALID_PARAMETER);
/*
* Get the CPUM context pointer and pass it on the specified EMT.
*/
if (RT_SUCCESS(rc))
return rc;
}
/**
* Begins a guest stack walk, extended version.
*
* This will walk the current stack, constructing a list of info frames which is
* returned to the caller. The caller uses DBGFR3StackWalkNext to traverse the
* list and DBGFR3StackWalkEnd to release it.
*
* @returns VINF_SUCCESS on success.
* @returns VERR_NO_MEMORY if we're out of memory.
*
* @param pVM The VM handle.
* @param idCpu The ID of the virtual CPU which stack we want to walk.
* @param enmCodeType Code type
* @param pAddrFrame Frame address to start at. (Optional)
* @param pAddrStack Stack address to start at. (Optional)
* @param pAddrPC Program counter to start at. (Optional)
* @param enmReturnType The return address type. (Optional)
* @param ppFirstFrame Where to return the pointer to the first info frame.
*/
{
return dbgfR3StackWalkBeginCommon(pVM, idCpu, enmCodeType, pAddrFrame, pAddrStack, pAddrPC, enmReturnType, ppFirstFrame);
}
/**
* Begins a guest stack walk.
*
* This will walk the current stack, constructing a list of info frames which is
* returned to the caller. The caller uses DBGFR3StackWalkNext to traverse the
* list and DBGFR3StackWalkEnd to release it.
*
* @returns VINF_SUCCESS on success.
* @returns VERR_NO_MEMORY if we're out of memory.
*
* @param pVM The VM handle.
* @param idCpu The ID of the virtual CPU which stack we want to walk.
* @param enmCodeType Code type
* @param ppFirstFrame Where to return the pointer to the first info frame.
*/
VMMR3DECL(int) DBGFR3StackWalkBegin(PVM pVM, VMCPUID idCpu, DBGFCODETYPE enmCodeType, PCDBGFSTACKFRAME *ppFirstFrame)
{
return dbgfR3StackWalkBeginCommon(pVM, idCpu, enmCodeType, NULL, NULL, NULL, DBGFRETURNTYPE_INVALID, ppFirstFrame);
}
/**
* Gets the next stack frame.
*
* @returns Pointer to the info for the next stack frame.
* NULL if no more frames.
*
* @param pCurrent Pointer to the current stack frame.
*
*/
{
return pCurrent
: NULL;
}
/**
* Ends a stack walk process.
*
* This *must* be called after a successful first call to any of the stack
* walker functions. If not called we will leak memory or other resources.
*
* @param pFirstFrame The frame returned by one of the the begin
* functions.
*/
{
if ( !pFirstFrame
|| !pFirstFrame->pFirstInternal)
return;
while (pFrame)
{
if (pFrame)
{
}
}
}