1 //===-- ExceptionRecord.h ---------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef liblldb_Plugins_Process_Windows_ExceptionRecord_H_
11 #define liblldb_Plugins_Process_Windows_ExceptionRecord_H_
12 
13 #include "lldb/lldb-forward.h"
14 #include "lldb/Host/windows/windows.h"
15 #include <DbgHelp.h>
16 
17 #include <memory>
18 #include <vector>
19 
20 namespace lldb_private
21 {
22 
23 //----------------------------------------------------------------------
24 // ExceptionRecord
25 //
26 // ExceptionRecord defines an interface which allows implementors to receive
27 // notification of events that happen in a debugged process.
28 //----------------------------------------------------------------------
29 class ExceptionRecord
30 {
31   public:
32     ExceptionRecord(const EXCEPTION_RECORD &record, lldb::tid_t thread_id)
33     {
34         m_code = record.ExceptionCode;
35         m_continuable = (record.ExceptionFlags == 0);
36         if (record.ExceptionRecord)
37             m_next_exception.reset(new ExceptionRecord(*record.ExceptionRecord, thread_id));
38         m_exception_addr = reinterpret_cast<lldb::addr_t>(record.ExceptionAddress);
39         m_thread_id = thread_id;
40         m_arguments.assign(record.ExceptionInformation, record.ExceptionInformation + record.NumberParameters);
41     }
42 
43     // MINIDUMP_EXCEPTIONs are almost identical to EXCEPTION_RECORDs.
44     ExceptionRecord(const MINIDUMP_EXCEPTION &record, lldb::tid_t thread_id) :
45         m_code(record.ExceptionCode),
46         m_continuable(record.ExceptionFlags == 0),
47         m_next_exception(nullptr),
48         m_exception_addr(static_cast<lldb::addr_t>(record.ExceptionAddress)),
49         m_thread_id(thread_id),
50         m_arguments(record.ExceptionInformation, record.ExceptionInformation + record.NumberParameters)
51     {
52         // Set up link to nested exception.
53         if (record.ExceptionRecord)
54         {
55             m_next_exception.reset(new ExceptionRecord(*reinterpret_cast<const MINIDUMP_EXCEPTION *>(record.ExceptionRecord),
56                                                        thread_id));
57         }
58     }
59 
60     virtual ~ExceptionRecord() {}
61 
62     DWORD
63     GetExceptionCode() const
64     {
65         return m_code;
66     }
67     bool
68     IsContinuable() const
69     {
70         return m_continuable;
71     }
72     const ExceptionRecord *
73     GetNextException() const
74     {
75         return m_next_exception.get();
76     }
77     lldb::addr_t
78     GetExceptionAddress() const
79     {
80         return m_exception_addr;
81     }
82 
83     lldb::tid_t
84     GetThreadID() const
85     {
86         return m_thread_id;
87     }
88 
89   private:
90     DWORD m_code;
91     bool m_continuable;
92     std::shared_ptr<ExceptionRecord> m_next_exception;
93     lldb::addr_t m_exception_addr;
94     lldb::tid_t m_thread_id;
95     std::vector<ULONG_PTR> m_arguments;
96 };
97 }
98 
99 #endif
100