dbghelp.hpp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. // dbghelp.hpp --------------------------------------------------------------//
  2. // Copyright 2015 Klemens Morgenstern
  3. // Copyright 2016 Jorge Lodos
  4. // Copyright 2016 Andrey Semashev
  5. // Distributed under the Boost Software License, Version 1.0.
  6. // See http://www.boost.org/LICENSE_1_0.txt
  7. #ifndef BOOST_DETAIL_WINAPI_DBGHELP_HPP
  8. #define BOOST_DETAIL_WINAPI_DBGHELP_HPP
  9. #include <boost/detail/winapi/basic_types.hpp>
  10. #if defined( BOOST_USE_WINDOWS_H )
  11. #if !defined( BOOST_WINAPI_IS_MINGW )
  12. #include <dbghelp.h>
  13. #else
  14. // In MinGW there is no dbghelp.h but an older imagehlp.h header defines some of the symbols from it.
  15. // Note that the user has to link with libimagehlp.a instead of libdbghelp.a for it to work.
  16. #include <imagehlp.h>
  17. #endif
  18. #endif
  19. #ifdef BOOST_HAS_PRAGMA_ONCE
  20. #pragma once
  21. #endif
  22. // Some symbols declared below are not present in all versions of Windows SDK, MinGW and MinGW-w64.
  23. // dbghelp.h/imagehlp.h define the API_VERSION_NUMBER macro which we use to detect its version.
  24. // When the macro is not available we can only guess based on the compiler version or SDK type.
  25. #if defined(API_VERSION_NUMBER)
  26. #if API_VERSION_NUMBER >= 11
  27. // UnDecorateSymbolNameW available since Windows SDK 6.0A and MinGW-w64 (as of 2016-02-14)
  28. #define BOOST_DETAIL_WINAPI_HAS_UNDECORATESYMBOLNAMEW
  29. #endif
  30. #elif defined(_MSC_VER) && _MSC_VER >= 1500
  31. // Until MSVC 9.0 Windows SDK was bundled in Visual Studio and didn't have UnDecorateSymbolNameW.
  32. // Supposedly, Windows SDK 6.0A was the first standalone one and it is used with MSVC 9.0.
  33. #define BOOST_DETAIL_WINAPI_HAS_UNDECORATESYMBOLNAMEW
  34. #elif !defined(BOOST_WINAPI_IS_MINGW)
  35. // MinGW does not provide UnDecorateSymbolNameW (as of 2016-02-14)
  36. #define BOOST_DETAIL_WINAPI_HAS_UNDECORATESYMBOLNAMEW
  37. #endif
  38. #if !defined( BOOST_USE_WINDOWS_H )
  39. extern "C" {
  40. struct API_VERSION;
  41. BOOST_SYMBOL_IMPORT boost::detail::winapi::DWORD_ WINAPI
  42. UnDecorateSymbolName(
  43. boost::detail::winapi::LPCSTR_ DecoratedName,
  44. boost::detail::winapi::LPSTR_ UnDecoratedName,
  45. boost::detail::winapi::DWORD_ UndecoratedLength,
  46. boost::detail::winapi::DWORD_ Flags);
  47. #if defined( BOOST_DETAIL_WINAPI_HAS_UNDECORATESYMBOLNAMEW )
  48. BOOST_SYMBOL_IMPORT boost::detail::winapi::DWORD_ WINAPI
  49. UnDecorateSymbolNameW(
  50. boost::detail::winapi::LPCWSTR_ DecoratedName,
  51. boost::detail::winapi::LPWSTR_ UnDecoratedName,
  52. boost::detail::winapi::DWORD_ UndecoratedLength,
  53. boost::detail::winapi::DWORD_ Flags);
  54. #endif
  55. BOOST_SYMBOL_IMPORT API_VERSION* WINAPI
  56. ImagehlpApiVersion(BOOST_DETAIL_WINAPI_VOID);
  57. } // extern "C"
  58. #endif
  59. namespace boost {
  60. namespace detail {
  61. namespace winapi {
  62. #if defined( BOOST_USE_WINDOWS_H )
  63. const DWORD_ UNDNAME_COMPLETE_ = UNDNAME_COMPLETE;
  64. const DWORD_ UNDNAME_NO_LEADING_UNDERSCORES_ = UNDNAME_NO_LEADING_UNDERSCORES;
  65. const DWORD_ UNDNAME_NO_MS_KEYWORDS_ = UNDNAME_NO_MS_KEYWORDS;
  66. const DWORD_ UNDNAME_NO_FUNCTION_RETURNS_ = UNDNAME_NO_FUNCTION_RETURNS;
  67. const DWORD_ UNDNAME_NO_ALLOCATION_MODEL_ = UNDNAME_NO_ALLOCATION_MODEL;
  68. const DWORD_ UNDNAME_NO_ALLOCATION_LANGUAGE_ = UNDNAME_NO_ALLOCATION_LANGUAGE;
  69. const DWORD_ UNDNAME_NO_MS_THISTYPE_ = UNDNAME_NO_MS_THISTYPE;
  70. const DWORD_ UNDNAME_NO_CV_THISTYPE_ = UNDNAME_NO_CV_THISTYPE;
  71. const DWORD_ UNDNAME_NO_THISTYPE_ = UNDNAME_NO_THISTYPE;
  72. const DWORD_ UNDNAME_NO_ACCESS_SPECIFIERS_ = UNDNAME_NO_ACCESS_SPECIFIERS;
  73. const DWORD_ UNDNAME_NO_THROW_SIGNATURES_ = UNDNAME_NO_THROW_SIGNATURES;
  74. const DWORD_ UNDNAME_NO_MEMBER_TYPE_ = UNDNAME_NO_MEMBER_TYPE;
  75. const DWORD_ UNDNAME_NO_RETURN_UDT_MODEL_ = UNDNAME_NO_RETURN_UDT_MODEL;
  76. const DWORD_ UNDNAME_32_BIT_DECODE_ = UNDNAME_32_BIT_DECODE;
  77. const DWORD_ UNDNAME_NAME_ONLY_ = UNDNAME_NAME_ONLY;
  78. const DWORD_ UNDNAME_NO_ARGUMENTS_ = UNDNAME_NO_ARGUMENTS;
  79. const DWORD_ UNDNAME_NO_SPECIAL_SYMS_ = UNDNAME_NO_SPECIAL_SYMS;
  80. #else // defined( BOOST_USE_WINDOWS_H )
  81. const DWORD_ UNDNAME_COMPLETE_ = 0x00000000;
  82. const DWORD_ UNDNAME_NO_LEADING_UNDERSCORES_ = 0x00000001;
  83. const DWORD_ UNDNAME_NO_MS_KEYWORDS_ = 0x00000002;
  84. const DWORD_ UNDNAME_NO_FUNCTION_RETURNS_ = 0x00000004;
  85. const DWORD_ UNDNAME_NO_ALLOCATION_MODEL_ = 0x00000008;
  86. const DWORD_ UNDNAME_NO_ALLOCATION_LANGUAGE_ = 0x00000010;
  87. const DWORD_ UNDNAME_NO_MS_THISTYPE_ = 0x00000020;
  88. const DWORD_ UNDNAME_NO_CV_THISTYPE_ = 0x00000040;
  89. const DWORD_ UNDNAME_NO_THISTYPE_ = 0x00000060;
  90. const DWORD_ UNDNAME_NO_ACCESS_SPECIFIERS_ = 0x00000080;
  91. const DWORD_ UNDNAME_NO_THROW_SIGNATURES_ = 0x00000100;
  92. const DWORD_ UNDNAME_NO_MEMBER_TYPE_ = 0x00000200;
  93. const DWORD_ UNDNAME_NO_RETURN_UDT_MODEL_ = 0x00000400;
  94. const DWORD_ UNDNAME_32_BIT_DECODE_ = 0x00000800;
  95. const DWORD_ UNDNAME_NAME_ONLY_ = 0x00001000;
  96. const DWORD_ UNDNAME_NO_ARGUMENTS_ = 0x00002000;
  97. const DWORD_ UNDNAME_NO_SPECIAL_SYMS_ = 0x00004000;
  98. #endif // defined( BOOST_USE_WINDOWS_H )
  99. using ::UnDecorateSymbolName;
  100. #if defined( BOOST_DETAIL_WINAPI_HAS_UNDECORATESYMBOLNAMEW )
  101. using ::UnDecorateSymbolNameW;
  102. #endif
  103. typedef struct BOOST_DETAIL_WINAPI_MAY_ALIAS API_VERSION {
  104. USHORT_ MajorVersion;
  105. USHORT_ MinorVersion;
  106. USHORT_ Revision;
  107. USHORT_ Reserved;
  108. } API_VERSION_, *LPAPI_VERSION_;
  109. BOOST_FORCEINLINE LPAPI_VERSION_ ImagehlpApiVersion()
  110. {
  111. return reinterpret_cast<LPAPI_VERSION_>(::ImagehlpApiVersion());
  112. }
  113. BOOST_FORCEINLINE DWORD_ undecorate_symbol_name(
  114. LPCSTR_ DecoratedName,
  115. LPSTR_ UnDecoratedName,
  116. DWORD_ UndecoratedLength,
  117. DWORD_ Flags)
  118. {
  119. return ::UnDecorateSymbolName(
  120. DecoratedName,
  121. UnDecoratedName,
  122. UndecoratedLength,
  123. Flags);
  124. }
  125. #if defined( BOOST_DETAIL_WINAPI_HAS_UNDECORATESYMBOLNAMEW )
  126. BOOST_FORCEINLINE DWORD_ undecorate_symbol_name(
  127. LPCWSTR_ DecoratedName,
  128. LPWSTR_ UnDecoratedName,
  129. DWORD_ UndecoratedLength,
  130. DWORD_ Flags)
  131. {
  132. return ::UnDecorateSymbolNameW(
  133. DecoratedName,
  134. UnDecoratedName,
  135. UndecoratedLength,
  136. Flags);
  137. }
  138. #endif
  139. }
  140. }
  141. }
  142. #endif // BOOST_DETAIL_WINAPI_DBGHELP_HPP