SYMBOL_INFO的地址字段始终为0?

时间:2018-04-03 03:19:30

标签: debugging winapi pdb debug-symbols dbghelp

我尝试使用SymGetLineFromAddr64来获取从PDB加载的符号的源文件名。我加载PDB模块并枚举类型/符号,但我在枚举回调中得到的Address指针的SYMBOL_INFO字段始终为0,所以我无法使用它来获取源文件信息。 (SymGetLineFromAddr64error code 126失败 "找不到指定的模块。")

我也尝试使用TI_GET_ADDRESS中的SymInfo->Index属性,但它也是0。

这是我的main

int main(char **Argv, int Argc)
{
    HANDLE Process = GetCurrentProcess();
    DWORD ProcessId = GetProcessId(Process);

    DWORD Options = SymGetOptions();
    Options |= SYMOPT_DEBUG;
    Options |= SYMOPT_LOAD_LINES;
    Options |= SYMOPT_LOAD_ANYTHING; // Wanted to test if this would do anything at all, didn't do much
    SymSetOptions(Options);

    if (SymInitialize(Process, 0, 0) == TRUE)
    {
        char *FilePath = "C:\\Users\\pc\\Documents\\Saedo\\VSProjects\\x64\\Debug\\PDBReflector.pdb";
        DWORD64 BaseAddress = 0x10000000;
        DWORD FileSize = GetFileSize(FilePath);

        DWORD64 Module = SymLoadModuleEx(Process, 0, FilePath, 0, BaseAddress, FileSize, 0, 0);
        if (Module)
        {
            Reflector.Process = Process; //Reflector is just a global struct that contains the process and module base for use later
            Reflector.ModuleBase = Module;

            SymEnumTypes(Process, Module, EnumTypesProc, 0);
        }
    }

    SymCleanup(Process);

    return(0);
}

以下是调查员:

BOOL CALLBACK EnumTypesProc(SYMBOL_INFO *SymInfo, ULONG SymbolSize, VOID *UserContext)
{
    if (SymInfo)
    {
        ULONG64 Address = SymInfo->Address; // Address is 0
        //SymGetTypeInfo(Reflector.Process, Reflector.ModuleBase, SymInfo->Index, TI_GET_ADDRESS, &Address); // Address is 0 as well

        IMAGEHLP_LINE64 LineInfo = {};
        LineInfo.SizeOfStruct = sizeof(IMAGEHLP_LINE64);
        DWORD LineDisplacement = 0;
        if (SymGetLineFromAddr64(Reflector.Process, Address, &LineDisplacement, &LineInfo))
        {
            Log("FILE: %s\n", LineInfo.FileName);
        }
    }

    return(TRUE);
}

使用VS2015 Community Edition编译,使用/Zi进行调试信息格式的X64调试模式和使用"优化调试" (/DEBUG)。

请注意,我正在为正在运行的同一个可执行文件加载PDB。我不认为那会是问题因为我可以加载其他类型的信息就好了。我还尝试检查另一个PDB,地址也是0。

问题:为什么我在地址字段中获得0以及如何实际获取正确的地址以便我可以检索特定类型/标签的源文件? 很确定我在这里遗漏了一些明显的东西。

感谢您的帮助。

0 个答案:

没有答案