1
0
Fork 0

DBG: added 'srcline' exprfunc

This commit is contained in:
mrexodia 2016-07-09 17:41:16 +02:00
parent 88784b357a
commit e8c2e5c572
No known key found for this signature in database
GPG Key ID: D72F9A4FAA0073B4
7 changed files with 41 additions and 3 deletions

View File

@ -1,5 +1,6 @@
#include "expressionfunctions.h"
#include "threading.h"
#include "exprfunc.h"
std::unordered_map<String, ExpressionFunctions::Function> ExpressionFunctions::mFunctions;
@ -33,7 +34,11 @@ static bool RegisterEasy(const String & name, duint(*cbFunction)(Ts...))
void ExpressionFunctions::Init()
{
//TODO: register some functions
//TODO: register more functions
using namespace Exprfunc;
//undocumented
RegisterEasy("srcline", srcline);
}
bool ExpressionFunctions::Register(const String & name, int argc, CBEXPRESSIONFUNCTION cbFunction)

14
src/dbg/exprfunc.cpp Normal file
View File

@ -0,0 +1,14 @@
#include "exprfunc.h"
#include "symbolinfo.h"
namespace Exprfunc
{
duint srcline(duint addr)
{
int line = 0;
DWORD displacement = 0;
if(!SymGetSourceLine(addr, nullptr, &line, &displacement) || displacement)
return 0;
return line;
}
}

8
src/dbg/exprfunc.h Normal file
View File

@ -0,0 +1,8 @@
#pragma once
#include "_global.h"
namespace Exprfunc
{
duint srcline(duint addr);
}

View File

@ -262,7 +262,7 @@ String SymGetSymbolicName(duint Address)
return StringUtils::sprintf("<%s>", label);
}
bool SymGetSourceLine(duint Cip, char* FileName, int* Line)
bool SymGetSourceLine(duint Cip, char* FileName, int* Line, DWORD* disp)
{
IMAGEHLP_LINEW64 lineInfo;
memset(&lineInfo, 0, sizeof(IMAGEHLP_LINE64));
@ -275,6 +275,9 @@ bool SymGetSourceLine(duint Cip, char* FileName, int* Line)
if(!SymGetLineFromAddrW64(fdProcessInfo->hProcess, Cip, &displacement, &lineInfo))
return false;
if(disp)
*disp = displacement;
String NewFile = StringUtils::Utf16ToUtf8(lineInfo.FileName);
// Copy line number if requested

View File

@ -18,6 +18,6 @@ String SymGetSymbolicName(duint Address);
\param [out] nLine Line number. Can be null.
\return true if it succeeds, false if it fails.
*/
bool SymGetSourceLine(duint Cip, char* FileName, int* Line);
bool SymGetSourceLine(duint Cip, char* FileName, int* Line, DWORD* displacement = nullptr);
#endif // _SYMBOLINFO_H

View File

@ -50,6 +50,7 @@
<ClCompile Include="disasm_fast.cpp" />
<ClCompile Include="disasm_helper.cpp" />
<ClCompile Include="expressionfunctions.cpp" />
<ClCompile Include="exprfunc.cpp" />
<ClCompile Include="handles.cpp" />
<ClCompile Include="error.cpp" />
<ClCompile Include="exception.cpp" />
@ -143,6 +144,7 @@
<ClInclude Include="disasm_helper.h" />
<ClInclude Include="dynamicmem.h" />
<ClInclude Include="expressionfunctions.h" />
<ClInclude Include="exprfunc.h" />
<ClInclude Include="handles.h" />
<ClInclude Include="error.h" />
<ClInclude Include="exception.h" />

View File

@ -344,6 +344,9 @@
<ClCompile Include="analysis\xrefsanalysis.cpp">
<Filter>Source Files\Analysis</Filter>
</ClCompile>
<ClCompile Include="exprfunc.cpp">
<Filter>Source Files\Debugger Core</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="x64_dbg.h">
@ -778,5 +781,8 @@
<ClInclude Include="analysis\xrefsanalysis.h">
<Filter>Header Files\Analysis</Filter>
</ClInclude>
<ClInclude Include="exprfunc.h">
<Filter>Header Files\Debugger Core</Filter>
</ClInclude>
</ItemGroup>
</Project>