1
0
Fork 0

DBG: improved symcache

This commit is contained in:
mrexodia 2016-10-09 23:40:50 +02:00
parent 294a806a31
commit d5a621b20c
No known key found for this signature in database
GPG Key ID: FC89E0AAA0C1AAD8
2 changed files with 68 additions and 19 deletions

View File

@ -2,16 +2,22 @@
#include "addrinfo.h" #include "addrinfo.h"
#include "threading.h" #include "threading.h"
static std::map<Range, SymbolInfo, RangeCompare> symbolRange; template<typename T>
using RangeMap = std::map<Range, T, RangeCompare>;
static RangeMap<RangeMap<SymbolInfo>> symbolRange;
static std::unordered_map<duint, duint> symbolName; static std::unordered_map<duint, duint> symbolName;
bool SymbolFromAddr(duint addr, SymbolInfo & symbol) bool SymbolFromAddr(duint addr, SymbolInfo & symbol)
{ {
SHARED_ACQUIRE(LockSymbolCache); SHARED_ACQUIRE(LockSymbolCache);
auto found = symbolRange.find(Range(addr, addr)); auto foundR = symbolRange.find(Range(addr, addr));
if(found == symbolRange.end()) if(foundR == symbolRange.end())
return false; return false;
symbol = found->second; auto foundS = foundR->second.find(Range(addr, addr));
if(foundS == foundR->second.end())
return false;
symbol = foundS->second;
return true; return true;
} }
@ -30,30 +36,52 @@ bool SymbolFromName(const char* name, SymbolInfo & symbol)
bool SymbolAdd(const SymbolInfo & symbol) bool SymbolAdd(const SymbolInfo & symbol)
{ {
EXCLUSIVE_ACQUIRE(LockSymbolCache); EXCLUSIVE_ACQUIRE(LockSymbolCache);
auto found = symbolRange.find(Range(symbol.addr, symbol.addr)); auto foundR = symbolRange.find(Range(symbol.addr, symbol.addr));
if(found != symbolRange.end()) if(foundR != symbolRange.end())
return false;
auto foundS = foundR->second.find(Range(symbol.addr, symbol.addr));
if(foundS != foundR->second.end())
return false; return false;
auto dec = symbol.size ? 1 : 0; auto dec = symbol.size ? 1 : 0;
symbolRange.insert({ Range(symbol.addr, symbol.addr + symbol.size - dec), symbol }); foundR->second.insert({ Range(symbol.addr, symbol.addr + symbol.size - dec), symbol });
auto hash = ModHashFromName(symbol.decoratedName.c_str()); auto hash = ModHashFromName(symbol.decoratedName.c_str());
symbolName.insert({ hash, symbol.addr }); symbolName.insert({ hash, symbol.addr });
return true; return true;
} }
void SymbolDelRange(duint start, duint end) bool SymbolAddRange(duint start, duint size)
{ {
EXCLUSIVE_ACQUIRE(LockSymbolCache);
auto foundR = symbolRange.find(Range(start, start + size - 1));
if(foundR != symbolRange.end())
return false;
symbolRange.insert({ Range(start, start + size - 1), RangeMap<SymbolInfo>() });
return true;
} }
static std::map<Range, LineInfo, RangeCompare> lineRange; bool SymbolDelRange(duint addr)
{
EXCLUSIVE_ACQUIRE(LockSymbolCache);
auto foundR = symbolRange.find(Range(addr, addr));
if(foundR == symbolRange.end())
return false;
symbolRange.erase(foundR);
return true;
}
static RangeMap<RangeMap<LineInfo>> lineRange;
static std::unordered_map<duint, duint> lineName; static std::unordered_map<duint, duint> lineName;
bool LineFromAddr(duint addr, LineInfo & line) bool LineFromAddr(duint addr, LineInfo & line)
{ {
SHARED_ACQUIRE(LockLineCache); SHARED_ACQUIRE(LockLineCache);
auto found = lineRange.find(Range(addr, addr)); auto foundR = lineRange.find(Range(addr, addr));
if(found == lineRange.end()) if(foundR == lineRange.end())
return false; return false;
line = found->second; auto foundL = foundR->second.find(Range(addr, addr));
if(foundL == foundR->second.end())
return false;
line = foundL->second;
return true; return true;
} }
@ -72,16 +100,35 @@ bool LineFromName(const char* sourceFile, int lineNumber, LineInfo & line)
bool LineAdd(const LineInfo & line) bool LineAdd(const LineInfo & line)
{ {
EXCLUSIVE_ACQUIRE(LockLineCache); EXCLUSIVE_ACQUIRE(LockLineCache);
auto found = lineRange.find(Range(line.addr, line.addr)); auto foundR = lineRange.find(Range(line.addr, line.addr));
if(found != lineRange.end()) if(foundR != lineRange.end())
return false; return false;
auto dec = line.addr ? 1 : 0; auto foundL = foundR->second.find(Range(line.addr, line.addr));
lineRange.insert({ Range(line.addr, line.addr + line.size - dec), line }); if(foundL != foundR->second.end())
return false;
auto dec = line.size ? 1 : 0;
foundR->second.insert({ Range(line.addr, line.addr + line.size - dec), line });
auto hash = ModHashFromName(line.sourceFile.c_str()) + line.lineNumber; auto hash = ModHashFromName(line.sourceFile.c_str()) + line.lineNumber;
lineName.insert({ hash, line.addr }); lineName.insert({ hash, line.addr });
return true; return true;
} }
void LineDelRange(duint start, duint end) bool LineAddRange(duint start, duint size)
{ {
EXCLUSIVE_ACQUIRE(LockLineCache);
auto foundR = lineRange.find(Range(start, start + size - 1));
if(foundR != lineRange.end())
return false;
lineRange.insert({ Range(start, start + size - 1), RangeMap<LineInfo>() });
return true;
}
bool LineDelRange(duint addr)
{
EXCLUSIVE_ACQUIRE(LockLineCache);
auto foundR = lineRange.find(Range(addr, addr));
if(foundR == lineRange.end())
return false;
lineRange.erase(foundR);
return true;
} }

View File

@ -21,9 +21,11 @@ struct LineInfo
bool SymbolFromAddr(duint addr, SymbolInfo & symbol); bool SymbolFromAddr(duint addr, SymbolInfo & symbol);
bool SymbolFromName(const char* name, SymbolInfo & symbol); bool SymbolFromName(const char* name, SymbolInfo & symbol);
bool SymbolAdd(const SymbolInfo & symbol); bool SymbolAdd(const SymbolInfo & symbol);
void SymbolDelRange(duint start, duint end); bool SymbolAddRange(duint start, duint size);
bool SymbolDelRange(duint addr);
bool LineFromAddr(duint addr, LineInfo & line); bool LineFromAddr(duint addr, LineInfo & line);
bool LineFromName(const char* sourceFile, int lineNumber, LineInfo & line); bool LineFromName(const char* sourceFile, int lineNumber, LineInfo & line);
bool LineAdd(const LineInfo & line); bool LineAdd(const LineInfo & line);
void LineDelRange(duint start, duint end); bool LineAddRange(duint start, duint size);
bool LineDelRange(duint addr);