Initial framework for win32 backtrace
This commit is contained in:
parent
71a1592413
commit
ac5a5d3a7d
@ -96,10 +96,12 @@ UTIL_FILES = \
|
|||||||
version.hpp
|
version.hpp
|
||||||
|
|
||||||
|
|
||||||
if HAVE_EXECINFO
|
if PLATFORM_LINUX
|
||||||
UTIL_FILES += backtrace_execinfo.cpp
|
UTIL_FILES += backtrace_execinfo.cpp
|
||||||
else
|
endif
|
||||||
UTIL_FILES += backtrace_null.cpp
|
|
||||||
|
if PLATFORM_WIN32
|
||||||
|
UTIL_FILES += backtrace_win32.cpp
|
||||||
endif
|
endif
|
||||||
|
|
||||||
CLEANFILES = json.cpp version.cpp ip.cpp
|
CLEANFILES = json.cpp version.cpp ip.cpp
|
||||||
|
@ -15,8 +15,9 @@ namespace debug {
|
|||||||
const decltype(m_frames)& frames(void) const
|
const decltype(m_frames)& frames(void) const
|
||||||
{ return m_frames; }
|
{ return m_frames; }
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
std::ostream&
|
std::ostream&
|
||||||
operator <<(std::ostream&, const debug::backtrace&);
|
operator <<(std::ostream&, const debug::backtrace&);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ debug::backtrace::backtrace (void):
|
|||||||
|
|
||||||
|
|
||||||
ostream&
|
ostream&
|
||||||
operator <<(ostream &os, const debug::backtrace &rhs) {
|
debug::operator <<(ostream &os, const debug::backtrace &rhs) {
|
||||||
const auto frames = rhs.frames ();
|
const auto frames = rhs.frames ();
|
||||||
|
|
||||||
typedef unique_ptr<char *[], decltype(&std::free)> unique_str;
|
typedef unique_ptr<char *[], decltype(&std::free)> unique_str;
|
||||||
|
48
backtrace_win32.cpp
Normal file
48
backtrace_win32.cpp
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
#include "backtrace.hpp"
|
||||||
|
|
||||||
|
#include "debug.hpp"
|
||||||
|
#include "except.hpp"
|
||||||
|
#include "memory.hpp"
|
||||||
|
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <iostream>
|
||||||
|
#include <windows.h>
|
||||||
|
#include <dbghelp.h>
|
||||||
|
|
||||||
|
|
||||||
|
debug::backtrace::backtrace (void) {
|
||||||
|
m_frames.resize (DEFAULT_DEPTH);
|
||||||
|
|
||||||
|
auto process = GetCurrentProcess();
|
||||||
|
if (!SymInitialize (process, NULL, TRUE))
|
||||||
|
win32_error::throw_code ();
|
||||||
|
|
||||||
|
while (CaptureStackBackTrace (1, m_frames.size (), m_frames.data (), NULL) == m_frames.size ())
|
||||||
|
m_frames.resize (m_frames.size () * 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::ostream&
|
||||||
|
debug::operator <<(std::ostream &os, const debug::backtrace &rhs) {
|
||||||
|
os << "Fuck Windows and it's stupid backtracing\n";
|
||||||
|
return os;
|
||||||
|
|
||||||
|
auto process = GetCurrentProcess ();
|
||||||
|
if (!process)
|
||||||
|
win32_error::throw_code ();
|
||||||
|
|
||||||
|
static const size_t MAX_LENGTH = 255;
|
||||||
|
scoped_malloc<void> symbol_mem (calloc (sizeof (SYMBOL_INFO) + MAX_LENGTH + 1, 1));
|
||||||
|
|
||||||
|
SYMBOL_INFO *symbol = static_cast<SYMBOL_INFO*> (symbol_mem.get ());
|
||||||
|
symbol->MaxNameLen = MAX_LENGTH;
|
||||||
|
symbol->SizeOfStruct = sizeof (SYMBOL_INFO);
|
||||||
|
|
||||||
|
for (void *frame: rhs.frames ()) {
|
||||||
|
std::cerr << process << " " << frame << " " << symbol << "\n";
|
||||||
|
SymFromAddr (process, (DWORD64)frame, 0, symbol);
|
||||||
|
std::cerr << frame << "\t" << symbol->Name << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
return os;
|
||||||
|
}
|
@ -95,9 +95,14 @@ COMMON_CFLAGS="$COMMON_CFLAGS -D_GNU_SOURCE"
|
|||||||
|
|
||||||
case $host_os in
|
case $host_os in
|
||||||
mingw32)
|
mingw32)
|
||||||
|
AM_CONDITIONAL([PLATFORM_WIN32], [true])
|
||||||
|
AM_CONDITIONAL([PLATFORM_LINUX], [false])
|
||||||
|
COMMON_LDFLAGS="$COMMON_LDFLAGS -ldbghelp"
|
||||||
;;
|
;;
|
||||||
|
|
||||||
linux-gnu)
|
linux-gnu)
|
||||||
|
AM_CONDITIONAL([PLATFORM_WIN32], [false])
|
||||||
|
AM_CONDITIONAL([PLATFORM_LINUX], [true])
|
||||||
;;
|
;;
|
||||||
|
|
||||||
*)
|
*)
|
||||||
|
Loading…
Reference in New Issue
Block a user