1
0
Fork 0

DBG: initial work for symbol cache

This commit is contained in:
mrexodia 2016-09-07 08:06:27 +02:00
parent 82316efa4e
commit e7d09811e5
No known key found for this signature in database
GPG Key ID: FC89E0AAA0C1AAD8
5 changed files with 126 additions and 0 deletions

87
src/dbg/symcache.cpp Normal file
View File

@ -0,0 +1,87 @@
#include "symcache.h"
#include "addrinfo.h"
#include "threading.h"
static std::map<Range, SymbolInfo, RangeCompare> symbolRange;
static std::unordered_map<duint, duint> symbolName;
bool SymbolFromAddr(duint addr, SymbolInfo & symbol)
{
SHARED_ACQUIRE(LockSymbolCache);
auto found = symbolRange.find(Range(addr, addr));
if(found == symbolRange.end())
return false;
symbol = found->second;
return true;
}
bool SymbolFromName(const char* name, SymbolInfo & symbol)
{
if(!name)
return false;
auto hash = ModHashFromName(name);
SHARED_ACQUIRE(LockSymbolCache);
auto found = symbolName.find(hash);
if(found == symbolName.end())
return false;
return SymbolFromAddr(found->second, symbol);
}
bool SymbolAdd(const SymbolInfo & symbol)
{
EXCLUSIVE_ACQUIRE(LockSymbolCache);
auto found = symbolRange.find(Range(symbol.addr, symbol.addr));
if(found != symbolRange.end())
return false;
auto dec = symbol.size ? 1 : 0;
symbolRange.insert({ Range(symbol.addr, symbol.addr + symbol.size - dec), symbol });
auto hash = ModHashFromName(symbol.decoratedName.c_str());
symbolName.insert({ hash, symbol.addr });
return true;
}
void SymbolDelRange(duint start, duint end)
{
}
static std::map<Range, LineInfo, RangeCompare> lineRange;
static std::unordered_map<duint, duint> lineName;
bool LineFromAddr(duint addr, LineInfo & line)
{
SHARED_ACQUIRE(LockLineCache);
auto found = lineRange.find(Range(addr, addr));
if(found == lineRange.end())
return false;
line = found->second;
return true;
}
bool LineFromName(const char* sourceFile, int lineNumber, LineInfo & line)
{
if(!sourceFile)
return false;
auto hash = ModHashFromName(sourceFile) + lineNumber;
SHARED_ACQUIRE(LockLineCache);
auto found = lineName.find(hash);
if(found == lineName.end())
return false;
return LineFromAddr(found->second, line);
}
bool LineAdd(const LineInfo & line)
{
EXCLUSIVE_ACQUIRE(LockLineCache);
auto found = lineRange.find(Range(line.addr, line.addr));
if(found != lineRange.end())
return false;
auto dec = line.addr ? 1 : 0;
lineRange.insert({ Range(line.addr, line.addr + line.size - dec), line });
auto hash = ModHashFromName(line.sourceFile.c_str()) + line.lineNumber;
lineName.insert({ hash, line.addr });
return true;
}
void LineDelRange(duint start, duint end)
{
}

29
src/dbg/symcache.h Normal file
View File

@ -0,0 +1,29 @@
#pragma once
#include "_global.h"
struct SymbolInfo
{
duint addr;
duint size;
String decoratedName;
String undecoratedName;
};
struct LineInfo
{
duint addr;
duint size;
int lineNumber;
String sourceFile;
};
bool SymbolFromAddr(duint addr, SymbolInfo & symbol);
bool SymbolFromName(const char* name, SymbolInfo & symbol);
bool SymbolAdd(const SymbolInfo & symbol);
void SymbolDelRange(duint start, duint end);
bool LineFromAddr(duint addr, LineInfo & line);
bool LineFromName(const char* sourceFile, int lineNumber, LineInfo & line);
bool LineAdd(const LineInfo & line);
void LineDelRange(duint start, duint end);

View File

@ -67,6 +67,8 @@ enum SectionLock
LockWatch,
LockExpressionFunctions,
LockHistory,
LockSymbolCache,
LockLineCache,
// Number of elements in this enumeration. Must always be the last
// index.

View File

@ -80,6 +80,7 @@
<ClCompile Include="stringformat.cpp" />
<ClCompile Include="stringutils.cpp" />
<ClCompile Include="symbolinfo.cpp" />
<ClCompile Include="symcache.cpp" />
<ClCompile Include="tcpconnections.cpp" />
<ClCompile Include="thread.cpp" />
<ClCompile Include="threading.cpp" />
@ -186,6 +187,7 @@
<ClInclude Include="plugin_loader.h" />
<ClInclude Include="reference.h" />
<ClInclude Include="serializablemap.h" />
<ClInclude Include="symcache.h" />
<ClInclude Include="taskthread.h" />
<ClInclude Include="tcpconnections.h" />
<ClInclude Include="TraceRecord.h" />

View File

@ -353,6 +353,9 @@
<ClCompile Include="breakpoint_commands.cpp">
<Filter>Source Files\Debugger Core</Filter>
</ClCompile>
<ClCompile Include="symcache.cpp">
<Filter>Source Files\Information</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="x64_dbg.h">
@ -799,5 +802,8 @@
<ClInclude Include="animate.h">
<Filter>Header Files\Utilities</Filter>
</ClInclude>
<ClInclude Include="symcache.h">
<Filter>Header Files\Information</Filter>
</ClInclude>
</ItemGroup>
</Project>