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/Host/windows/windows.h"
14 #include "lldb/lldb-forward.h"
15 #include <dbghelp.h>
16 
17 #include <memory>
18 #include <vector>
19 
20 namespace lldb_private {
21 
22 //----------------------------------------------------------------------
23 // ExceptionRecord
24 //
25 // ExceptionRecord defines an interface which allows implementors to receive
26 // notification of events that happen in a debugged process.
27 //----------------------------------------------------------------------
28 class ExceptionRecord {
29 public:
30   ExceptionRecord(const EXCEPTION_RECORD &record, lldb::tid_t thread_id) {
31     m_code = record.ExceptionCode;
32     m_continuable = (record.ExceptionFlags == 0);
33     if (record.ExceptionRecord)
34       m_next_exception.reset(
35           new ExceptionRecord(*record.ExceptionRecord, thread_id));
36     m_exception_addr = reinterpret_cast<lldb::addr_t>(record.ExceptionAddress);
37     m_thread_id = thread_id;
38     m_arguments.assign(record.ExceptionInformation,
39                        record.ExceptionInformation + record.NumberParameters);
40   }
41 
42   // MINIDUMP_EXCEPTIONs are almost identical to EXCEPTION_RECORDs.
43   ExceptionRecord(const MINIDUMP_EXCEPTION &record, lldb::tid_t thread_id)
44       : m_code(record.ExceptionCode), m_continuable(record.ExceptionFlags == 0),
45         m_next_exception(nullptr),
46         m_exception_addr(static_cast<lldb::addr_t>(record.ExceptionAddress)),
47         m_thread_id(thread_id),
48         m_arguments(record.ExceptionInformation,
49                     record.ExceptionInformation + record.NumberParameters) {
50     // Set up link to nested exception.
51     if (record.ExceptionRecord) {
52       m_next_exception.reset(new ExceptionRecord(
53           *reinterpret_cast<const MINIDUMP_EXCEPTION *>(record.ExceptionRecord),
54           thread_id));
55     }
56   }
57 
58   virtual ~ExceptionRecord() {}
59 
60   DWORD
61   GetExceptionCode() const { return m_code; }
62   bool IsContinuable() const { return m_continuable; }
63   const ExceptionRecord *GetNextException() const {
64     return m_next_exception.get();
65   }
66   lldb::addr_t GetExceptionAddress() const { return m_exception_addr; }
67 
68   lldb::tid_t GetThreadID() const { return m_thread_id; }
69 
70 private:
71   DWORD m_code;
72   bool m_continuable;
73   std::shared_ptr<ExceptionRecord> m_next_exception;
74   lldb::addr_t m_exception_addr;
75   lldb::tid_t m_thread_id;
76   std::vector<ULONG_PTR> m_arguments;
77 };
78 }
79 
80 #endif
81