ntBldSymDb.cpp revision f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync/* $Id$ */
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync/** @file
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync * IPRT - RTDirCreateUniqueNumbered, generic implementation.
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync */
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync/*
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync * Copyright (C) 2013 Oracle Corporation
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync *
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync * available from http://www.virtualbox.org. This file is free software;
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync * you can redistribute it and/or modify it under the terms of the GNU
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync * General Public License (GPL) as published by the Free Software
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync *
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync * The contents of this file may alternatively be used under the terms
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync * of the Common Development and Distribution License Version 1.0
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync * VirtualBox OSE distribution, in which case the provisions of the
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync * CDDL are applicable instead of those of the GPL.
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync *
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync * You may elect to license modified versions of this file under the
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync * terms and conditions of either the GPL or the CDDL or both.
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync */
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync/*******************************************************************************
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync* Header Files *
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync*******************************************************************************/
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync#include <Windows.h>
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync#include <Dbghelp.h>
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync#include <iprt/initterm.h>
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync#include <iprt/message.h>
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync#include <iprt/path.h>
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync#include <iprt/stream.h>
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync#include <iprt/err.h>
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsyncstatic BOOL CALLBACK enumTypesCallback(PSYMBOL_INFO pSymInfo, ULONG cbSymbol, PVOID pvUser)
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync{
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync RTPrintf("pSymInfo=%p cbSymbol=%#x SizeOfStruct=%#x\n", pSymInfo, cbSymbol, pSymInfo->SizeOfStruct);
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync RTPrintf(" TypeIndex=%#x Reserved[0]=%#llx Reserved[1]=%#llx info=%#x\n",
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync pSymInfo->TypeIndex, pSymInfo->Reserved[0], pSymInfo->Reserved[1], pSymInfo->Index);
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync RTPrintf(" Size=%#x ModBase=%#llx Flags=%#x Value=%#llx Address=%#llx\n",
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync pSymInfo->Size, pSymInfo->ModBase, pSymInfo->Flags, pSymInfo->Value, pSymInfo->Address);
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync RTPrintf(" Register=%#x Scope=%#x Tag=%#x NameLen=%#x MaxNameLen=%#x Name=%s\n",
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync pSymInfo->Register, pSymInfo->Scope, pSymInfo->Tag, pSymInfo->NameLen, pSymInfo->MaxNameLen, pSymInfo->Name);
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync return TRUE;
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync}
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsyncstatic RTEXITCODE processOnePdb(const char *pszPdb)
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync{
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync /*
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync * We need the size later on, so get that now and present proper IPRT error
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync * info if the file is missing or inaccessible.
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync */
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync RTFSOBJINFO ObjInfo;
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync int rc = RTPathQueryInfo(pszPdb, &ObjInfo, RTFSOBJATTRADD_NOTHING);
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync if (RT_FAILURE(rc))
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync return RTMsgErrorExit(RTEXITCODE_FAILURE, "RTPathQueryInfo fail on '%s': %Rrc\n", pszPdb, rc);
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync /*
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync * Create a fake handle and open the PDB.
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync */
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync static uintptr_t s_iHandle = 0;
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync HANDLE hFake = (HANDLE)++s_iHandle;
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync if (!SymInitialize(hFake, NULL, FALSE))
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync return RTMsgErrorExit(RTEXITCODE_FAILURE, "SymInitialied failed: %u\n", GetLastError());
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync RTEXITCODE rcExit;
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync uint64_t uModAddr = UINT64_C(0x1000000);
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync uModAddr = SymLoadModuleEx(hFake, NULL /*hFile*/, pszPdb, NULL /*pszModuleName*/,
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync uModAddr, ObjInfo.cbObject, NULL /*pData*/, 0 /*fFlags*/);
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync if (uModAddr != 0)
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync {
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync RTPrintf("debug: uModAddr=%#llx\n", uModAddr);
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync /*
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync * Enumerate types.
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync */
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync if (SymEnumTypes(hFake, uModAddr, enumTypesCallback, NULL))
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync {
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync rcExit = RTEXITCODE_SUCCESS;
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync }
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync else
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync rcExit = RTMsgErrorExit(RTEXITCODE_FAILURE, "SymEnumTypes failed: %u\n", GetLastError());
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync }
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync if (!SymCleanup(hFake))
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync rcExit = RTMsgErrorExit(RTEXITCODE_FAILURE, "SymCleanup failed: %u\n", GetLastError());
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync return rcExit;
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync}
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsyncint main(int argc, char **argv)
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync{
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync int rc = RTR3InitExe(argc, &argv, 0 /*fFlags*/);
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync if (RT_FAILURE(rc))
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync return RTMsgInitFailure(rc);
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync /*
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync * Parse options.
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync */
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync /*
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync * Do job.
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync */
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync RTEXITCODE rcExit = processOnePdb(argv[argc - 1]);
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync return rcExit;
f43a0c088fd5cc014b52d34b0e7d23b9e5ca5858vboxsync}