-
Notifications
You must be signed in to change notification settings - Fork 0
/
symbol_info.h
104 lines (77 loc) · 2.18 KB
/
symbol_info.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#pragma once
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <dbghelp.h>
#include <cstring>
#include "hash_map.h"
#include "function_info.h"
#include "source_info.h"
namespace muitv
{
namespace detail
{
inline unsigned d64Hash(const DWORD64& value)
{
return unsigned(value >> 4);
}
}
struct symbol_info
{
symbol_info()
{
process = GetCurrentProcess();
SymSetOptions(SYMOPT_LOAD_LINES | SYMOPT_DEFERRED_LOADS | SYMOPT_UNDNAME);
SymInitialize(process, 0, true);
}
~symbol_info()
{
SymCleanup(process);
}
static symbol_info& instance()
{
static symbol_info inst;
return inst;
}
function_info* get_function_info(void* ptr)
{
DWORD64 w = reinterpret_cast<DWORD64>(ptr);
if(DWORD64 *remap = addressRemap.find(w))
{
if(function_info *target = functionMap.find(*remap))
return target;
}
function_info info;
memset(info.functionInfo, 0, function_info::SYMBOLBUFFERSIZE);
info.functionInfo->SizeOfStruct = sizeof(SYMBOL_INFO);
info.functionInfo->MaxNameLen = function_info::MAXSYMBOLNAMELENGTH;
if(SymFromAddr(process, w, &info.displacement64, info.functionInfo))
{
DWORD64 remap = info.functionInfo->Address;
addressRemap.insert(w, remap);
if(function_info *target = functionMap.find(remap))
return target;
functionMap.insert(remap, info);
return functionMap.find(remap);
}
return 0;
}
source_info* get_source_info(void* ptr)
{
DWORD64 w = reinterpret_cast<DWORD64>(ptr);
if(source_info *info = sourceMap.find(w))
return info;
source_info info;
memset(&info.sourceInfo, 0, sizeof(IMAGEHLP_LINE64));
info.sourceInfo.SizeOfStruct = sizeof(IMAGEHLP_LINE64);
if(SymGetLineFromAddr64(process, w, &info.displacement, &info.sourceInfo))
{
sourceMap.insert(w, info);
}
return sourceMap.find(w);
}
HANDLE process;
hash_map<DWORD64, DWORD64, detail::d64Hash, 32 * 1024> addressRemap;
hash_map<DWORD64, function_info, detail::d64Hash, 32 * 1024> functionMap;
hash_map<DWORD64, source_info, detail::d64Hash, 32 * 1024> sourceMap;
};
}