vul_debug.h
Go to the documentation of this file.
1 // This is core/vul/vul_debug.h
2 #ifndef vul_debug_h_
3 #define vul_debug_h_
4 
5 //:
6 // \file
7 // \author Ian Scott
8 
9 
10 //: Dump a core file.
11 // \param filename can have up to one "%d" option, which will be given a different index number
12 // on each core dump.
13 // \returns true on success, false when coredump could not be taken
14 bool vul_debug_core_dump(const char * filename);
15 
16 
17 //: Force a core dump whilst inside a Structured Exception Handler in a windows program.
18 // To get a core dump from a Windows structured exceptions
19 // \verbatim
20 // void main()
21 // {
22 // __try
23 // {
24 // // Rest of program
25 // }
26 // __except(vul_debug_core_dump2(filename, GetExceptionInformation()))
27 // {}
28 // }
29 // \endverbatim
30 // \param filename can have up to one "%d" option, which will be given a different index number
31 // on each core dump.
32 // \returns true on success, false when coredump could not be taken
33 bool vul_debug_core_dump_in_windows_se(const char * filename,
34  void* pep);
35 #include <exception>
36 #ifdef _MSC_VER
37 # include <vcl_msvc_warnings.h>
38 #endif
39 
40 //: A translated structured exception.
41 class vul_debug_windows_structured_exception : public std::exception
42 {
43  void * ex_ptr_;
44  public:
45  //: Windows structured exception code.
46  unsigned code() const;
47  //: Related execution address.
48  void *address() const;
49  const char *what( ) const throw() override;
50  vul_debug_windows_structured_exception(void * ex_ptr) : ex_ptr_(ex_ptr) {}
51  ~vul_debug_windows_structured_exception() throw() override = default;
52 };
53 
54 //: Setup the system to core dump and throw a C++ exception on detection of a Structured Exception
55 // The system will throw vul_debug_windows_structured_exception.
56 // You must compile your code with /EHa to get the compiler to correctly handle SEs.
57 // \param filename can have up to one "%d" option, which will be given a different index number
58 // on each core dump.
59 void vul_debug_set_coredump_and_throw_on_windows_se(const char * filename);
60 
61 //: Setup the system to core dump and throw a C++ exception on detection of out of memory.
62 // The system will throw std::bad_alloc.
63 // \param filename can have up to one "%d" option, which will be given a different index number
64 // on each core dump.
65 void vul_debug_set_coredump_and_throw_on_out_of_memory(const char * filename);
66 
67 
68 #endif // vul_debug_h_
A translated structured exception.
Definition: vul_debug.h:41
void * address() const
Related execution address.
void vul_debug_set_coredump_and_throw_on_windows_se(const char *filename)
Setup the system to core dump and throw a C++ exception on detection of a Structured Exception.
Definition: vul_debug.cxx:205
const char * what() const override
~vul_debug_windows_structured_exception() override=default
void vul_debug_set_coredump_and_throw_on_out_of_memory(const char *filename)
Setup the system to core dump and throw a C++ exception on detection of out of memory.
Definition: vul_debug.cxx:227
unsigned code() const
Windows structured exception code.
bool vul_debug_core_dump(const char *filename)
Dump a core file.
Definition: vul_debug.cxx:184
bool vul_debug_core_dump_in_windows_se(const char *filename, void *pep)
Force a core dump whilst inside a Structured Exception Handler in a windows program.