-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
Copy pathnative_symbol_win.cc
109 lines (95 loc) · 3 KB
/
native_symbol_win.cc
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
105
106
107
108
109
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
#include "vm/globals.h"
#if defined(DART_HOST_OS_WINDOWS)
#include "vm/lockers.h"
#include "vm/native_symbol.h"
#include "vm/os.h"
#include "vm/os_thread.h"
#include <dbghelp.h> // NOLINT
namespace dart {
static bool running_ = false;
static Mutex* lock_ = nullptr;
void NativeSymbolResolver::Init() {
ASSERT(running_ == false);
if (lock_ == nullptr) {
lock_ = new Mutex();
}
running_ = true;
// Symbol resolution API's used in this file are not supported
// when compiled in UWP.
#ifndef DART_TARGET_OS_WINDOWS_UWP
SymSetOptions(SYMOPT_UNDNAME | SYMOPT_DEFERRED_LOADS);
HANDLE hProcess = GetCurrentProcess();
if (!SymInitialize(hProcess, nullptr, TRUE)) {
DWORD error = GetLastError();
OS::PrintErr("Failed to init NativeSymbolResolver (SymInitialize %" Pu32
")\n",
error);
return;
}
#endif
}
void NativeSymbolResolver::Cleanup() {
MutexLocker lock(lock_);
if (!running_) {
return;
}
running_ = false;
#ifndef DART_TARGET_OS_WINDOWS_UWP
HANDLE hProcess = GetCurrentProcess();
if (!SymCleanup(hProcess)) {
DWORD error = GetLastError();
OS::PrintErr("Failed to shutdown NativeSymbolResolver (SymCleanup %" Pu32
")\n",
error);
}
#endif
}
const char* NativeSymbolResolver::LookupSymbolName(uword pc, uword* start) {
#ifdef DART_TARGET_OS_WINDOWS_UWP
return nullptr;
#else
const intptr_t kMaxNameLength = 2048;
const intptr_t kSymbolInfoSize = sizeof(SYMBOL_INFO); // NOLINT.
static char buffer[kSymbolInfoSize + kMaxNameLength];
MutexLocker lock(lock_);
if (!running_) {
return nullptr;
}
if (start != nullptr) {
*start = 0;
}
memset(&buffer[0], 0, sizeof(buffer));
HANDLE hProcess = GetCurrentProcess();
DWORD64 address = static_cast<DWORD64>(pc);
PSYMBOL_INFO pSymbol = reinterpret_cast<PSYMBOL_INFO>(&buffer[0]);
pSymbol->SizeOfStruct = kSymbolInfoSize;
pSymbol->MaxNameLen = kMaxNameLength;
DWORD64 displacement;
BOOL r = SymFromAddr(hProcess, address, &displacement, pSymbol);
if (r == FALSE) {
return nullptr;
}
if (start != nullptr) {
*start = pc - displacement;
}
return Utils::StrDup(pSymbol->Name);
#endif // ifdef DART_TARGET_OS_WINDOWS_UWP
}
void NativeSymbolResolver::FreeSymbolName(const char* name) {
free(const_cast<char*>(name));
}
bool NativeSymbolResolver::LookupSharedObject(uword pc,
uword* dso_base,
const char** dso_name) {
return false;
}
void NativeSymbolResolver::AddSymbols(const char* dso_name,
void* buffer,
size_t size) {
OS::PrintErr("warning: Dart_AddSymbols has no effect on Windows\n");
}
} // namespace dart
#endif // defined(DART_HOST_OS_WINDOWS)