RTNtDbgHelp.cpp revision 0c3b158e1a6ce423f4499f472f3717050476897d
/* $Id$ */
/** @file
*/
/*
* Copyright (C) 2013 Oracle Corporation
*
* 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.
*
* The contents of this file may alternatively be used under the terms
* of the Common Development and Distribution License Version 1.0
* (CDDL) only, as it comes in the "COPYING.CDDL" file of the
* VirtualBox OSE distribution, in which case the provisions of the
* CDDL are applicable instead of those of the GPL.
*
* You may elect to license modified versions of this file under the
* terms and conditions of either the GPL or the CDDL or both.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include <Windows.h>
#include <Dbghelp.h>
#include <iprt/initterm.h>
/*******************************************************************************
* Structures and Typedefs *
*******************************************************************************/
/**
* Debug module record.
*
* Used for dumping the whole context.
*/
typedef struct RTNTDBGHELPMOD
{
/** The list bits. */
/** The module address. */
/** Pointer to the name part of szFullName. */
char *pszName;
/** The module name. */
char szFullName[1];
/** Pointer to a debug module. */
typedef RTNTDBGHELPMOD *PRTNTDBGHELPMOD;
/*******************************************************************************
* Global Variables *
*******************************************************************************/
/** Verbosity level. */
static int g_iOptVerbose = 1;
/** Fake process handle. */
/** Number of modules in the list. */
static uint32_t g_cModules = 0;
/** Module list. */
static RTLISTANCHOR g_ModuleList;
/** Set when initialized, clear until then. Lazy init on first operation. */
static bool g_fInitialized = false;
/** The current address register. */
static uint64_t g_uCurAddress = 0;
/**
*
* @param iMin The minimum verbosity level for this message.
* @param pszFormat The format string.
* @param ... The arguments referenced in the format string.
*/
{
if (g_iOptVerbose >= iMin)
{
RTPrintf("info: ");
}
}
static BOOL CALLBACK symDebugCallback64(HANDLE hProcess, ULONG uAction, ULONG64 ullData, ULONG64 ullUserCtx)
{
switch (uAction)
{
case CBA_DEBUG_INFO:
{
else
return TRUE;
}
return FALSE;
case CBA_EVENT:
return FALSE;
default:
break;
}
return FALSE;
}
/**
* Lazy initialization.
* @returns Exit code with any relevant complaints printed.
*/
static RTEXITCODE ensureInitialized(void)
{
if (!g_fInitialized)
{
g_fInitialized = true;
}
return RTEXITCODE_SUCCESS;
}
/**
* Loads the given module, the address is either automatic or a previously given
* one.
*
* @returns Exit code with any relevant complaints printed.
* @param pszFile The file to load.
*/
{
if (rcExit != RTEXITCODE_SUCCESS)
return rcExit;
if (uModAddrGot == 0)
PRTNTDBGHELPMOD pMod = (PRTNTDBGHELPMOD)RTMemAlloc(RT_OFFSETOF(RTNTDBGHELPMOD, szFullName[cbFullName + 1]));
return RTEXITCODE_SUCCESS;
}
/**
* Translates SYM_TYPE to string.
*
* @returns String.
* @param enmType The symbol type value.
*/
{
switch (enmType)
{
case SymCoff: return "SymCoff";
case SymCv: return "SymCv";
case SymPdb: return "SymPdb";
case SymExport: return "SymExport";
case SymDeferred: return "SymDeferred";
case SymSym: return "SymSym";
case SymDia: return "SymDia";
case SymVirtual: return "SymVirtual";
}
static char s_szBuf[32];
return s_szBuf;
}
/**
* Symbol enumeration callback.
*
* @returns TRUE (continue enum).
* @param pSymInfo The symbol info.
* @param cbSymbol The symbol length (calculated).
* @param pvUser NULL.
*/
{
return TRUE;
}
/**
* Dumps all info.
* @returns Exit code with any relevant complaints printed.
*/
static RTEXITCODE dumpAll(void)
{
{
{
/** @todo CVData. */
}
else
}
return rcExit;
}
{
if (RT_FAILURE(rc))
return RTMsgInitFailure(rc);
/*
* Parse options.
*/
static const RTGETOPTDEF s_aOptions[] =
{
#define OPT_SET_DEBUG_INFO 0x1000
};
const char *pszOutput = "-";
int ch;
{
switch (ch)
{
case 'v':
break;
case 'q':
break;
case 'l':
break;
case 'a':
break;
case 'd':
break;
case OPT_SET_DEBUG_INFO:
rcExit = ensureInitialized();
break;
case 'V':
RTPrintf("$Revision$");
break;
case 'h':
RTPrintf("usage: %s [-v|--verbose] [-q|--quiet] [-a <addr>] [-l <file>] [-d] [...]\n"
" or: %s [-V|--version]\n"
" or: %s [-h|--help]\n",
return RTEXITCODE_SUCCESS;
case VINF_GETOPT_NOT_OPTION:
default:
}
if (rcExit != RTEXITCODE_SUCCESS)
break;
}
return rcExit;
}