XTL  0.1
eXtended Template Library
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
dbghelp.hpp
Go to the documentation of this file.
1 
5 #pragma once
6 
7 #include <xtd/xtd.hpp>
8 #include <dbghelp.h>
9 #include <mutex>
10 #include <map>
11 #include <xtd/debug.hpp>
12 #include <xtd/exception.hpp>
13 
14 namespace xtd{
15  namespace windows{
16 
20  class debug_symbol{
21  friend class debug_help;
22  std::unique_ptr<SYMBOL_INFO> _symbol_info;
23  debug_symbol(){}
24  public:
25  ~debug_symbol(){}
26  };
27 
28 
32  class debug_help{
33  public:
35  using pointer = std::shared_ptr<debug_help>;
36 
41 
43  static pointer make(){ return pointer(new debug_help); }
44 
45  private:
46 
47  class initializer{
48  public:
49 
50  using action_strings_map = std::map<ULONG, const char *>;
51 
52  initializer(){
53  SymSetOptions(SYMOPT_UNDNAME | SYMOPT_DEFERRED_LOADS);
54  xtd::windows::exception::throw_if(SymInitialize(GetCurrentProcess(), nullptr, TRUE), [](BOOL b){return FALSE == b; });
55  xtd::windows::exception::throw_if(SymRegisterCallback64(GetCurrentProcess(), SymCallback, 0), [](BOOL b){return FALSE == b; });
56  }
57  ~initializer(){
58  SymCleanup(GetCurrentProcess());
59  }
60 
61  static action_strings_map& action_strings(){
62  static action_strings_map _action_strings = {
63  { CBA_DEBUG_INFO, "CBA_DEBUG_INFO" },
64  { CBA_DEFERRED_SYMBOL_LOAD_CANCEL , "CBA_DEFERRED_SYMBOL_LOAD_CANCEL" },
65  { CBA_DEFERRED_SYMBOL_LOAD_COMPLETE, "CBA_DEFERRED_SYMBOL_LOAD_COMPLETE" },
66  { CBA_DEFERRED_SYMBOL_LOAD_FAILURE , "CBA_DEFERRED_SYMBOL_LOAD_FAILURE" },
67  { CBA_DEFERRED_SYMBOL_LOAD_PARTIAL , "CBA_DEFERRED_SYMBOL_LOAD_PARTIAL" },
68  { CBA_DEFERRED_SYMBOL_LOAD_START , "CBA_DEFERRED_SYMBOL_LOAD_START" },
69  { CBA_DUPLICATE_SYMBOL , "CBA_DUPLICATE_SYMBOL" },
70  { CBA_EVENT , "CBA_EVENT" },
71  { CBA_READ_MEMORY , "CBA_READ_MEMORY" },
72  { CBA_SET_OPTIONS , "CBA_SET_OPTIONS" },
73  { CBA_SRCSRV_EVENT , "CBA_SRCSRV_EVENT" },
74  { CBA_SRCSRV_INFO , "CBA_SRCSRV_INFO" },
75  { CBA_SYMBOLS_UNLOADED , "CBA_SYMBOLS_UNLOADED" },
76  };
77  return _action_strings;
78  }
79 
80  static BOOL CALLBACK SymCallback(HANDLE, ULONG ActionCode, ULONG64 CallbackData, ULONG64){
81  switch (ActionCode){
82  case CBA_DEBUG_INFO:{
83  DBG(reinterpret_cast<const char*>(CallbackData));
84  break;
85  }
86  case CBA_DEFERRED_SYMBOL_LOAD_COMPLETE:
87  case CBA_DEFERRED_SYMBOL_LOAD_FAILURE:
88  case CBA_DEFERRED_SYMBOL_LOAD_PARTIAL:
89  case CBA_DEFERRED_SYMBOL_LOAD_START:
90  case CBA_DUPLICATE_SYMBOL:
91  case CBA_EVENT:
92  case CBA_READ_MEMORY:
93  case CBA_SET_OPTIONS:
94  case CBA_SRCSRV_EVENT:
95  case CBA_SRCSRV_INFO:
96  case CBA_DEFERRED_SYMBOL_LOAD_CANCEL:
97  case CBA_SYMBOLS_UNLOADED:
98  break;
99  }
100  return FALSE;
101  }
102 
103  };
104 
105  static std::mutex& library_lock(){
106  static initializer _initializer;
107  static std::mutex _library_lock;
108  return _library_lock;
109  }
110  };
111  }
112 }
C++ interface to the dbghelp library.
Definition: dbghelp.hpp:32
std::shared_ptr< debug_help > pointer
the default pointer type used by the library
Definition: dbghelp.hpp:35
static pointer make()
constructs a new debug_help and returns a pointer type
Definition: dbghelp.hpp:43
host, target and build configurations and settings Various components are purpose built for specific ...
#define throw_if(_test, _expression)
Simplifies use of exception::_throw_if.
Definition: exception.hpp:22
generic and special purpose exceptions
Debugging.
Represents a debug symbol.
Definition: dbghelp.hpp:20