74 lines · c
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-exception6//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 19namespace lldb_private {20 21// ExceptionRecord22//23// ExceptionRecord defines an interface which allows implementors to receive24// notification of events that happen in a debugged process.25class ExceptionRecord {26public:27 ExceptionRecord(const EXCEPTION_RECORD &record, lldb::tid_t thread_id) {28 // Notes about the `record.ExceptionRecord` field:29 // In the past, some code tried to parse the nested exception with it, but30 // in practice, that code just causes Access Violation. I suspect31 // `ExceptionRecord` here actually points to the address space of the32 // debuggee process. However, I did not manage to find any official or33 // unofficial reference that clarifies this point. If anyone would like to34 // reimplement this, please also keep in mind to check how this behaves when35 // debugging a WOW64 process. I suspect you may have to use the explicit36 // `EXCEPTION_RECORD32` and `EXCEPTION_RECORD64` structs.37 m_code = record.ExceptionCode;38 m_continuable = (record.ExceptionFlags == 0);39 m_exception_addr = reinterpret_cast<lldb::addr_t>(record.ExceptionAddress);40 m_thread_id = thread_id;41 m_arguments.assign(record.ExceptionInformation,42 record.ExceptionInformation + record.NumberParameters);43 }44 45 // MINIDUMP_EXCEPTIONs are almost identical to EXCEPTION_RECORDs.46 ExceptionRecord(const MINIDUMP_EXCEPTION &record, lldb::tid_t thread_id)47 : m_code(record.ExceptionCode), m_continuable(record.ExceptionFlags == 0),48 m_exception_addr(static_cast<lldb::addr_t>(record.ExceptionAddress)),49 m_thread_id(thread_id),50 m_arguments(record.ExceptionInformation,51 record.ExceptionInformation + record.NumberParameters) {}52 53 virtual ~ExceptionRecord() {}54 55 DWORD56 GetExceptionCode() const { return m_code; }57 bool IsContinuable() const { return m_continuable; }58 lldb::addr_t GetExceptionAddress() const { return m_exception_addr; }59 60 lldb::tid_t GetThreadID() const { return m_thread_id; }61 62 const std::vector<ULONG_PTR>& GetExceptionArguments() const { return m_arguments; }63 64private:65 DWORD m_code;66 bool m_continuable;67 lldb::addr_t m_exception_addr;68 lldb::tid_t m_thread_id;69 std::vector<ULONG_PTR> m_arguments;70};71}72 73#endif74