1 //===-- ExceptionRecord.h ---------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef liblldb_Plugins_Process_Windows_ExceptionRecord_H_
10 #define liblldb_Plugins_Process_Windows_ExceptionRecord_H_
11 
12 #include "lldb/Host/windows/windows.h"
13 #include "lldb/lldb-forward.h"
14 #include <dbghelp.h>
15 
16 #include <memory>
17 #include <vector>
18 
19 namespace lldb_private {
20 
21 // ExceptionRecord
22 //
23 // ExceptionRecord defines an interface which allows implementors to receive
24 // notification of events that happen in a debugged process.
25 class ExceptionRecord {
26 public:
ExceptionRecord(const EXCEPTION_RECORD & record,lldb::tid_t thread_id)27   ExceptionRecord(const EXCEPTION_RECORD &record, lldb::tid_t thread_id) {
28     m_code = record.ExceptionCode;
29     m_continuable = (record.ExceptionFlags == 0);
30     if (record.ExceptionRecord)
31       m_next_exception.reset(
32           new ExceptionRecord(*record.ExceptionRecord, thread_id));
33     m_exception_addr = reinterpret_cast<lldb::addr_t>(record.ExceptionAddress);
34     m_thread_id = thread_id;
35     m_arguments.assign(record.ExceptionInformation,
36                        record.ExceptionInformation + record.NumberParameters);
37   }
38 
39   // MINIDUMP_EXCEPTIONs are almost identical to EXCEPTION_RECORDs.
ExceptionRecord(const MINIDUMP_EXCEPTION & record,lldb::tid_t thread_id)40   ExceptionRecord(const MINIDUMP_EXCEPTION &record, lldb::tid_t thread_id)
41       : m_code(record.ExceptionCode), m_continuable(record.ExceptionFlags == 0),
42         m_next_exception(nullptr),
43         m_exception_addr(static_cast<lldb::addr_t>(record.ExceptionAddress)),
44         m_thread_id(thread_id),
45         m_arguments(record.ExceptionInformation,
46                     record.ExceptionInformation + record.NumberParameters) {
47     // Set up link to nested exception.
48     if (record.ExceptionRecord) {
49       m_next_exception.reset(new ExceptionRecord(
50           *reinterpret_cast<const MINIDUMP_EXCEPTION *>(record.ExceptionRecord),
51           thread_id));
52     }
53   }
54 
~ExceptionRecord()55   virtual ~ExceptionRecord() {}
56 
57   DWORD
GetExceptionCode()58   GetExceptionCode() const { return m_code; }
IsContinuable()59   bool IsContinuable() const { return m_continuable; }
GetNextException()60   const ExceptionRecord *GetNextException() const {
61     return m_next_exception.get();
62   }
GetExceptionAddress()63   lldb::addr_t GetExceptionAddress() const { return m_exception_addr; }
64 
GetThreadID()65   lldb::tid_t GetThreadID() const { return m_thread_id; }
66 
GetExceptionArguments()67   const std::vector<ULONG_PTR>& GetExceptionArguments() const { return m_arguments; }
68 
69 private:
70   DWORD m_code;
71   bool m_continuable;
72   std::shared_ptr<ExceptionRecord> m_next_exception;
73   lldb::addr_t m_exception_addr;
74   lldb::tid_t m_thread_id;
75   std::vector<ULONG_PTR> m_arguments;
76 };
77 }
78 
79 #endif
80