Atempt to avoid inclusion of <windows.h> in header files

This commit is contained in:
Antony Polukhin
2016-09-27 23:35:52 +03:00
parent decdb41e66
commit 73206b9c64
2 changed files with 75 additions and 6 deletions

View File

@@ -0,0 +1,64 @@
// sym_from_addr.hpp --------------------------------------------------------------//
// Copyright 2016 Antony Polukhin
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
#ifndef BOOST_DETAIL_WINAPI_SYM_FROM_ADDR_HPP
#define BOOST_DETAIL_WINAPI_SYM_FROM_ADDR_HPP
#include <boost/detail/winapi/basic_types.hpp>
#ifdef BOOST_HAS_PRAGMA_ONCE
#pragma once
#endif
#if !defined( BOOST_USE_WINDOWS_H )
extern "C" {
struct _SYMBOL_INFO;
BOOST_SYMBOL_IMPORT boost::detail::winapi::BOOL_ WINAPI SymFromAddr(
/*HANDLE*/ boost::detail::winapi::HANDLE_ hProcess,
/*DWORD64*/ boost::detail::winapi::ULONGLONG_ Address,
/*PDWORD64*/ boost::detail::winapi::ULONGLONG_* Displacement,
/*PSYMBOL_INFO*/ _SYMBOL_INFO* Symbol);
}
#endif
namespace boost {
namespace detail {
namespace winapi {
typedef struct BOOST_DETAIL_WINAPI_MAY_ALIAS _SYMBOL_INFO {
ULONG_ SizeOfStruct;
ULONG_ TypeIndex;
ULONGLONG_ Reserved[2];
ULONG_ Index;
ULONG_ Size;
ULONGLONG_ ModBase;
ULONG_ Flags;
ULONGLONG_ Value;
ULONGLONG_ Address;
ULONG_ Register;
ULONG_ Scope;
ULONG_ Tag;
ULONG_ NameLen;
ULONG_ MaxNameLen;
CHAR_ Name[1];
} SYMBOL_INFO_, *PSYMBOL_INFO_;
using ::SymFromAddr;
BOOST_FORCEINLINE BOOL_ SymFromAddr(HANDLE_ hProcess, ULONGLONG_ Address, ULONGLONG_* Displacement, PSYMBOL_INFO_ Symbol)
{
return ::SymFromAddr(hProcess, Address, Displacement, reinterpret_cast< ::_SYMBOL_INFO* >(Symbol));
}
}
}
}
#endif // BOOST_DETAIL_WINAPI_SYM_FROM_ADDR_HPP

View File

@@ -19,6 +19,9 @@
#include "DbgHelp.h"
#include <WinBase.h>
#include <boost/detail/winapi/get_current_process.hpp>
#include <boost/detail/winapi/sym_from_addr.hpp>
#if !defined(BOOST_ALL_NO_LIB)
# define BOOST_LIB_NAME Dbghelp
# ifdef BOOST_STACKTRACE_DYN_LINK
@@ -30,16 +33,16 @@
namespace boost { namespace stacktrace { namespace detail {
struct symbol_info_with_stack {
BOOST_STATIC_CONSTEXPR std::size_t max_name_length = MAX_SYM_NAME * sizeof(char);
SYMBOL_INFO symbol;
BOOST_STATIC_CONSTEXPR std::size_t max_name_length = MAX_SYM_NAME * sizeof(char);
boost::detail::winapi::SYMBOL_INFO_ symbol;
char name_part[max_name_length];
};
struct symbol_initialization_structure {
HANDLE process;
boost::detail::winapi::HANDLE_ process;
inline symbol_initialization_structure() BOOST_NOEXCEPT
: process(GetCurrentProcess())
: process(boost::detail::winapi::GetCurrentProcess())
{
SymInitialize(process, 0, true);
}
@@ -70,8 +73,10 @@ struct backtrace_holder {
symbol_info_with_stack s;
s.symbol.MaxNameLen = symbol_info_with_stack::max_name_length;
s.symbol.SizeOfStruct = sizeof(SYMBOL_INFO);
const bool sym_res = !!SymFromAddr(symproc.process, reinterpret_cast<DWORD64>(buffer[frame]), 0, &s.symbol);
s.symbol.SizeOfStruct = sizeof(boost::detail::winapi::SYMBOL_INFO_);
const bool sym_res = !!boost::detail::winapi::SymFromAddr(
symproc.process, reinterpret_cast<boost::detail::winapi::ULONGLONG_>(buffer[frame]), 0, &s.symbol
);
if (sym_res) {
res = s.symbol.Name;
}