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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: runtime/vm/native_symbol_win.cc
diff --git a/runtime/vm/native_symbol_win.cc b/runtime/vm/native_symbol_win.cc
new file mode 100644
index 0000000000000000000000000000000000000000..bc08eaf3d3eb68a2f49bd515069efcd548476980
--- /dev/null
+++ b/runtime/vm/native_symbol_win.cc
@@ -0,0 +1,76 @@
+// 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(TARGET_OS_WINDOWS)
+
+#include "vm/native_symbol.h"
+#include "vm/thread.h"
+
+#include <dbghelp.h> // NOLINT
+
+namespace dart {
+
+static bool running_ = false;
+static Mutex* lock_ = NULL;
+
+void NativeSymbolResolver::InitOnce() {
+ ASSERT(running_ == false);
+ SymSetOptions(SYMOPT_UNDNAME | SYMOPT_DEFERRED_LOADS);
+ HANDLE hProcess = GetCurrentProcess();
+ if (!SymInitialize(hProcess, NULL, TRUE)) {
+ DWORD error = GetLastError();
+ printf("Failed to init NativeSymbolResolver (SymInitialize %d)\n", error);
+ return;
+ }
+ lock_ = new Mutex();
+ running_ = true;
+}
+
+
+void NativeSymbolResolver::ShutdownOnce() {
+ ScopedMutexLock lock(lock_);
+ if (!running_) {
+ return;
+ }
+ running_ = false;
+ HANDLE hProcess = GetCurrentProcess();
+ if (!SymCleanup(hProcess)) {
+ DWORD error = GetLastError();
+ printf("Failed to shutdown NativeSymbolResolver (SymCleanup %d)\n", error);
+ }
+}
+
+
+char* NativeSymbolResolver::LookupSymbolName(uintptr_t pc) {
+ static const intptr_t kMaxNameLength = 2048;
+ static const intptr_t kSymbolInfoSize = sizeof(SYMBOL_INFO); // NOLINT.
+ static char buffer[kSymbolInfoSize + kMaxNameLength];
+ static char name_buffer[kMaxNameLength];
+ ScopedMutexLock lock(lock_);
+ if (!running_) {
+ return NULL;
+ }
+ 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;
+ BOOL r = SymFromAddr(hProcess, address, NULL, pSymbol);
+ if (r == FALSE) {
+ return NULL;
+ }
+ return strdup(pSymbol->Name);
+}
+
+
+void NativeSymbolResolver::FreeSymbolName(char* name) {
+ free(name);
+}
+
+
+} // namespace dart
+
+#endif // defined(TARGET_OS_WINDOWS)

Powered by Google App Engine
This is Rietveld 408576698