DBG: function to get source + line from address
This commit is contained in:
parent
02c3d44cb8
commit
03b0d8b971
|
@ -180,6 +180,18 @@ static duint _getaddrfromline(const char* szSourceFile, int line)
|
|||
return (duint)lineData.Address;
|
||||
}
|
||||
|
||||
static bool _getsourcefromaddr(duint addr, char* szSourceFile, int* line)
|
||||
{
|
||||
char sourceFile[MAX_STRING_SIZE] = "";
|
||||
if(!SymGetSourceLine(addr, sourceFile, line))
|
||||
return false;
|
||||
if(!FileExists(sourceFile))
|
||||
return false;
|
||||
if(szSourceFile)
|
||||
strcpy_s(szSourceFile, MAX_STRING_SIZE, sourceFile);
|
||||
return true;
|
||||
}
|
||||
|
||||
void dbgfunctionsinit()
|
||||
{
|
||||
_dbgfunctions.AssembleAtEx = _assembleatex;
|
||||
|
@ -215,4 +227,5 @@ void dbgfunctionsinit()
|
|||
_dbgfunctions.FileOffsetToVa = valfileoffsettova;
|
||||
_dbgfunctions.VaToFileOffset = valvatofileoffset;
|
||||
_dbgfunctions.GetAddrFromLine = _getaddrfromline;
|
||||
_dbgfunctions.GetSourceFromAddr = _getsourcefromaddr;
|
||||
}
|
||||
|
|
|
@ -66,6 +66,7 @@ typedef bool (*SETCMDLINE)(const char* cmdline);
|
|||
typedef duint (*FILEOFFSETTOVA)(const char* modname, duint offset);
|
||||
typedef duint (*VATOFILEOFFSET)(duint va);
|
||||
typedef duint (*GETADDRFROMLINE)(const char* szSourceFile, int line);
|
||||
typedef bool(*GETSOURCEFROMADDR)(duint addr, char* szSourceFile, int* line);
|
||||
|
||||
typedef struct DBGFUNCTIONS_
|
||||
{
|
||||
|
@ -102,6 +103,7 @@ typedef struct DBGFUNCTIONS_
|
|||
FILEOFFSETTOVA FileOffsetToVa;
|
||||
VATOFILEOFFSET VaToFileOffset;
|
||||
GETADDRFROMLINE GetAddrFromLine;
|
||||
GETSOURCEFROMADDR GetSourceFromAddr;
|
||||
} DBGFUNCTIONS;
|
||||
|
||||
#ifdef BUILD_DBG
|
||||
|
|
|
@ -254,7 +254,7 @@ const char* SymGetSymbolicName(uint Address)
|
|||
|
||||
bool SymGetSourceLine(uint Cip, char* FileName, int* Line)
|
||||
{
|
||||
IMAGEHLP_LINE64 lineInfo;
|
||||
IMAGEHLP_LINEW64 lineInfo;
|
||||
memset(&lineInfo, 0, sizeof(IMAGEHLP_LINE64));
|
||||
|
||||
lineInfo.SizeOfStruct = sizeof(IMAGEHLP_LINE64);
|
||||
|
@ -262,9 +262,11 @@ bool SymGetSourceLine(uint Cip, char* FileName, int* Line)
|
|||
// Perform a symbol lookup from a specific address
|
||||
DWORD displacement;
|
||||
|
||||
if(!SafeSymGetLineFromAddr64(fdProcessInfo->hProcess, Cip, &displacement, &lineInfo))
|
||||
if(!SymGetLineFromAddrW64(fdProcessInfo->hProcess, Cip, &displacement, &lineInfo))
|
||||
return false;
|
||||
|
||||
String NewFile = StringUtils::Utf16ToUtf8(lineInfo.FileName);
|
||||
|
||||
// Copy line number if requested
|
||||
if(Line)
|
||||
*Line = lineInfo.LineNumber;
|
||||
|
@ -273,10 +275,10 @@ bool SymGetSourceLine(uint Cip, char* FileName, int* Line)
|
|||
if(FileName)
|
||||
{
|
||||
// Check if it was a full path
|
||||
if(lineInfo.FileName[1] == ':' && lineInfo.FileName[2] == '\\')
|
||||
if(NewFile[1] == ':' && NewFile[2] == '\\')
|
||||
{
|
||||
// Success: no more parsing
|
||||
strcpy_s(FileName, MAX_STRING_SIZE, lineInfo.FileName);
|
||||
strcpy_s(FileName, MAX_STRING_SIZE, NewFile.c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -296,7 +298,7 @@ bool SymGetSourceLine(uint Cip, char* FileName, int* Line)
|
|||
|
||||
// Copy back to the caller's buffer
|
||||
strcpy_s(FileName, MAX_STRING_SIZE, modInfo.LoadedPdbName);
|
||||
strcat_s(FileName, MAX_STRING_SIZE, lineInfo.FileName);
|
||||
strcat_s(FileName, MAX_STRING_SIZE, NewFile.c_str());
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
Loading…
Reference in New Issue