Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(99)

Side by Side Diff: runtime/vm/native_symbol_win.cc

Issue 25909002: Sampling profiler (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/native_symbol_macos.cc ('k') | runtime/vm/object.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 #include "vm/globals.h"
6 #if defined(TARGET_OS_WINDOWS)
7
8 #include "vm/native_symbol.h"
9 #include "vm/thread.h"
10
11 #include <dbghelp.h> // NOLINT
12
13 namespace dart {
14
15 static bool running_ = false;
16 static Mutex* lock_ = NULL;
17
18 void NativeSymbolResolver::InitOnce() {
19 ASSERT(running_ == false);
20 SymSetOptions(SYMOPT_UNDNAME | SYMOPT_DEFERRED_LOADS);
21 HANDLE hProcess = GetCurrentProcess();
22 if (!SymInitialize(hProcess, NULL, TRUE)) {
23 DWORD error = GetLastError();
24 printf("Failed to init NativeSymbolResolver (SymInitialize %d)\n", error);
25 return;
26 }
27 lock_ = new Mutex();
28 running_ = true;
29 }
30
31
32 void NativeSymbolResolver::ShutdownOnce() {
33 ScopedMutex lock(lock_);
34 if (!running_) {
35 return;
36 }
37 running_ = false;
38 HANDLE hProcess = GetCurrentProcess();
39 if (!SymCleanup(hProcess)) {
40 DWORD error = GetLastError();
41 printf("Failed to shutdown NativeSymbolResolver (SymCleanup %d)\n", error);
42 }
43 }
44
45
46 char* NativeSymbolResolver::LookupSymbolName(uintptr_t pc) {
47 static const intptr_t kMaxNameLength = 2048;
48 static const intptr_t kSymbolInfoSize = sizeof(SYMBOL_INFO); // NOLINT.
49 static char buffer[kSymbolInfoSize + kMaxNameLength];
50 static char name_buffer[kMaxNameLength];
51 ScopedMutex lock(lock_);
52 if (!running_) {
53 return NULL;
54 }
55 memset(&buffer[0], 0, sizeof(buffer));
56 HANDLE hProcess = GetCurrentProcess();
57 DWORD64 address = static_cast<DWORD64>(pc);
58 PSYMBOL_INFO pSymbol = reinterpret_cast<PSYMBOL_INFO>(&buffer[0]);
59 pSymbol->SizeOfStruct = kSymbolInfoSize;
60 pSymbol->MaxNameLen = kMaxNameLength;
61 BOOL r = SymFromAddr(hProcess, address, NULL, pSymbol);
62 if (r == FALSE) {
63 return NULL;
64 }
65 return strdup(pSymbol->Name);
66 }
67
68
69 void NativeSymbolResolver::FreeSymbolName(char* name) {
70 free(name);
71 }
72
73
74 } // namespace dart
75
76 #endif // defined(TARGET_OS_WINDOWS)
OLDNEW
« no previous file with comments | « runtime/vm/native_symbol_macos.cc ('k') | runtime/vm/object.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698