X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fstacktrace_windows-inl.h;h=726318879d8d95302c91d0d18a58d637620d561a;hb=028d37889a1e80e8a07da1b8945ac706259e5fd8;hp=56064089dfa8c938151c174d161a1039ce5f8bc2;hpb=e5d36443c6d03453f985721a6b16b4f1749846c4;p=platform%2Fupstream%2Fglog.git diff --git a/src/stacktrace_windows-inl.h b/src/stacktrace_windows-inl.h index 5606408..7263188 100644 --- a/src/stacktrace_windows-inl.h +++ b/src/stacktrace_windows-inl.h @@ -31,56 +31,20 @@ // // Windows implementation - just use CaptureStackBackTrace +#include "config.h" #include "port.h" #include "stacktrace.h" -#include "Dbghelp.h" -#include +#include _START_GOOGLE_NAMESPACE_ -static bool ready_to_run = false; -class StackTraceInit { -public: - HANDLE hProcess; - StackTraceInit() { - // Initialize the symbol handler - // https://msdn.microsoft.com/en-us/library/windows/desktop/ms680344(v=vs.85).aspx - hProcess = GetCurrentProcess(); - SymSetOptions(SYMOPT_UNDNAME | SYMOPT_DEFERRED_LOADS); - SymInitialize(hProcess, NULL, true); - ready_to_run = true; - } - ~StackTraceInit() { - SymCleanup(hProcess); - ready_to_run = false; - } -}; - -static const StackTraceInit module_initializer; // Force initialization - -// If you change this function, also change GetStackFrames below. int GetStackTrace(void** result, int max_depth, int skip_count) { - if (!ready_to_run) { - return 0; - } - skip_count++; // we want to skip the current frame as well if (max_depth > 64) { max_depth = 64; } - std::vector stack(max_depth); + skip_count++; // we want to skip the current frame as well // This API is thread-safe (moreover it walks only the current thread). - int size = CaptureStackBackTrace(skip_count, max_depth, &stack[0], NULL); - for (int i = 0; i < size; ++i) { - // Resolve symbol information from address. - char buffer[sizeof(SYMBOL_INFO) + MAX_SYM_NAME * sizeof(TCHAR)]; - SYMBOL_INFO* symbol = reinterpret_cast(buffer); - symbol->SizeOfStruct = sizeof(SYMBOL_INFO); - symbol->MaxNameLen = MAX_SYM_NAME; - SymFromAddr(module_initializer.hProcess, reinterpret_cast(stack[i]), 0, symbol); - result[i] = stack[i]; - } - - return size; + return CaptureStackBackTrace(skip_count, max_depth, result, NULL); } _END_GOOGLE_NAMESPACE_