RTLdrFlt.cpp revision 2d8870843ff566fee9bd3a6a5942414254106479
/* $Id$ */
/** @file
* IPRT - Utility for translating addresses into symbols+offset.
*/
/*
* Copyright (C) 2006-2011 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 <iprt/initterm.h>
/**
* Tries to parse out an address at the head of the string.
*
* @returns true if found address, false if not.
* @param psz Where to start parsing.
* @param pcchAddress Where to store the address length.
* @param pu64Address Where to store the address value.
*/
{
/*
* Hex prefix?
*/
psz += 2;
/*
* How many hex digits? We want at least 4 and at most 16.
*/
off++;
return false;
/*
* Check for separator (xxxxxxxx'yyyyyyyy).
*/
if (fHave64bitSep)
{
if (rc != VWRN_TRAILING_CHARS)
return false;
if ( rc != VINF_SUCCESS
&& rc != VWRN_TRAILING_SPACES
&& rc != VWRN_TRAILING_CHARS)
return false;
}
else
{
if ( rc != VINF_SUCCESS
&& rc != VWRN_TRAILING_SPACES
&& rc != VWRN_TRAILING_CHARS)
return false;
}
return true;
}
{
if (RT_FAILURE(rc))
return RTMsgInitFailure(rc);
/*
* Create an empty address space that we can load modules and stuff into
* as we parse the parameters.
*/
if (RT_FAILURE(rc))
/*
* Parse arguments.
*/
static const RTGETOPTDEF s_aOptions[] =
{
};
unsigned cVerbosityLevel = 0;
{
switch (rc)
{
case 'i':
if (RT_FAILURE(rc))
return RTMsgErrorExit(RTEXITCODE_FAILURE, "Failed to open '%s' for reading: %Rrc", ValueUnion.psz, rc);
break;
case 'v':
break;
case 'h':
RTPrintf("Usage: %s [options] <module> <address> [<module> <address> [..]]\n"
"\n"
"Options:\n"
" -i,--input=file\n"
" Specify a input file instead of standard input.\n"
" -v, --verbose\n"
" Display the address space before doing the filtering.\n"
" -h, -?, --help\n"
" Display this help text and exit successfully.\n"
" -V, --version\n"
" Display the revision and exit successfully.\n"
, RTPathFilename(argv[0]));
return RTEXITCODE_SUCCESS;
case 'V':
RTPrintf("$Revision$\n");
return RTEXITCODE_SUCCESS;
case VINF_GETOPT_NOT_OPTION:
{
/* <module> <address> */
if (RT_FAILURE(rc))
if (RT_FAILURE(rc))
if (RT_FAILURE(rc))
return RTMsgErrorExit(RTEXITCODE_FAILURE, "RTDbgAsModuleLink(,%s,%llx,) -> %Rrc", pszModule, u64Address, rc);
break;
}
default:
}
}
/*
* Display the address space.
*/
if (cVerbosityLevel)
{
RTPrintf("*** Address Space Dump ***\n");
{
if (RT_SUCCESS(rc))
{
{
RTPrintf(" mapping #%u: %RTptr-%RTptr\n",
else
{
if (RT_SUCCESS(rc))
RTPrintf(" mapping #%u: %RTptr-%RTptr (segment #%u - '%s')",
else
}
if (cVerbosityLevel > 1)
{
{
if (RT_SUCCESS(rc))
RTPrintf(" #%04u at %08x:%RTptr %05llx %s\n",
}
}
}
}
else
}
RTPrintf("*** End of Address Space Dump ***\n");
}
/*
* Read text from standard input and see if there is anything we can translate.
*/
for (;;)
{
/* Get a line. */
break;
if (RT_FAILURE(rc))
/*
* Search the line for potential addresses and replace them with
* symbols+offset.
*/
char ch;
{
if ( ( ch == '0'
|| ( RT_C_IS_XDIGIT(ch)
)
{
/* Print. */
psz += cchAddress;
/* Try get the module. */
if (RT_SUCCESS(rc))
{
if (iSeg != UINT32_MAX)
else
/*
* Do we have symbols?
*/
rc = RTDbgAsSymbolByAddr(hDbgAs, u64Address, RTDBGSYMADDR_FLAGS_LESS_OR_EQUAL, &offSym, &Symbol, NULL);
if (RT_SUCCESS(rc))
{
if (!offSym)
else if (offSym > 0)
else
}
else
/*
* Do we have line numbers?
*/
if (RT_SUCCESS(rc))
}
}
else
psz++;
}
}
return RTEXITCODE_SUCCESS;
}