Beispiel #1
0
const IMAGEHLP_LINE64 Symbols::GetSymbolLineInfo(const char * const pName, const char * const pFileName,
    const DWORD dwLineNumber, LONG &lDisplacement, bool &bSuccess)
{
    IMAGEHLP_LINE64 lineInfo = { 0 };
    lineInfo.SizeOfStruct = sizeof(IMAGEHLP_LINE64);

    bSuccess = BOOLIFY(SymGetLineFromName64(m_hProcess, pName, pFileName, dwLineNumber,
        &lDisplacement, &lineInfo));
    if (!bSuccess)
    {
        fprintf(stderr, "Could not get virtual address for symbol %s:%s on line %i.\n"
            "Error = %X.\n", pFileName, pName, dwLineNumber, GetLastError());
    }

    return lineInfo;
}
//显示源文件中的一行。
void DisplayLine(LPCTSTR sourceFile, const std::wstring& line, int lineNumber, BOOL isCurLine) {

	if (isCurLine == TRUE) {
		std::wcout << TEXT("=>");
	}
	else {
		std::wcout << TEXT("  ");
	}

	LONG displacement;
	IMAGEHLP_LINE64 lineInfo = { 0 };
	lineInfo.SizeOfStruct = sizeof(lineInfo);

	if (SymGetLineFromName64(
		GetDebuggeeHandle(),
		NULL,
		sourceFile,
		lineNumber, 
		&displacement,
		&lineInfo) == FALSE) {

		std::wcout << TEXT("SymGetLineFromName64 failed: ") << GetLastError() << std::endl;
		return;
	}

	std::wcout << std::setw(4) << std::setfill(TEXT(' ')) << lineNumber << TEXT("  ");

	if (displacement == 0) {

		PrintHex((unsigned int)lineInfo.Address, FALSE);
	}
	else {

		std::wcout << std::setw(8) << TEXT(" ");
	}

	std::wcout << TEXT("  ") << line << std::endl;
}