DBG: improved symcache
This commit is contained in:
parent
294a806a31
commit
d5a621b20c
|
@ -2,16 +2,22 @@
|
|||
#include "addrinfo.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;
|
||||
|
||||
bool SymbolFromAddr(duint addr, SymbolInfo & symbol)
|
||||
{
|
||||
SHARED_ACQUIRE(LockSymbolCache);
|
||||
auto found = symbolRange.find(Range(addr, addr));
|
||||
if(found == symbolRange.end())
|
||||
auto foundR = symbolRange.find(Range(addr, addr));
|
||||
if(foundR == symbolRange.end())
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -30,30 +36,52 @@ bool SymbolFromName(const char* name, SymbolInfo & symbol)
|
|||
bool SymbolAdd(const SymbolInfo & symbol)
|
||||
{
|
||||
EXCLUSIVE_ACQUIRE(LockSymbolCache);
|
||||
auto found = symbolRange.find(Range(symbol.addr, symbol.addr));
|
||||
if(found != symbolRange.end())
|
||||
auto foundR = symbolRange.find(Range(symbol.addr, symbol.addr));
|
||||
if(foundR != symbolRange.end())
|
||||
return false;
|
||||
auto foundS = foundR->second.find(Range(symbol.addr, symbol.addr));
|
||||
if(foundS != foundR->second.end())
|
||||
return false;
|
||||
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());
|
||||
symbolName.insert({ hash, symbol.addr });
|
||||
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;
|
||||
|
||||
bool LineFromAddr(duint addr, LineInfo & line)
|
||||
{
|
||||
SHARED_ACQUIRE(LockLineCache);
|
||||
auto found = lineRange.find(Range(addr, addr));
|
||||
if(found == lineRange.end())
|
||||
auto foundR = lineRange.find(Range(addr, addr));
|
||||
if(foundR == lineRange.end())
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -72,16 +100,35 @@ bool LineFromName(const char* sourceFile, int lineNumber, LineInfo & line)
|
|||
bool LineAdd(const LineInfo & line)
|
||||
{
|
||||
EXCLUSIVE_ACQUIRE(LockLineCache);
|
||||
auto found = lineRange.find(Range(line.addr, line.addr));
|
||||
if(found != lineRange.end())
|
||||
auto foundR = lineRange.find(Range(line.addr, line.addr));
|
||||
if(foundR != lineRange.end())
|
||||
return false;
|
||||
auto dec = line.addr ? 1 : 0;
|
||||
lineRange.insert({ Range(line.addr, line.addr + line.size - dec), line });
|
||||
auto foundL = foundR->second.find(Range(line.addr, line.addr));
|
||||
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;
|
||||
lineName.insert({ hash, line.addr });
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -21,9 +21,11 @@ struct LineInfo
|
|||
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 SymbolAddRange(duint start, duint size);
|
||||
bool SymbolDelRange(duint addr);
|
||||
|
||||
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);
|
||||
bool LineAddRange(duint start, duint size);
|
||||
bool LineDelRange(duint addr);
|
Loading…
Reference in New Issue