1053eb356SAaron Smith //===-- ProcessDebugger.h ---------------------------------------*- C++ -*-===// 2053eb356SAaron Smith // 3053eb356SAaron Smith // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4053eb356SAaron Smith // See https://llvm.org/LICENSE.txt for license information. 5053eb356SAaron Smith // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6053eb356SAaron Smith // 7053eb356SAaron Smith //===----------------------------------------------------------------------===// 8053eb356SAaron Smith 9053eb356SAaron Smith #ifndef liblldb_ProcessDebugger_h_ 10053eb356SAaron Smith #define liblldb_ProcessDebugger_h_ 11053eb356SAaron Smith 12053eb356SAaron Smith #include "lldb/Host/windows/windows.h" 13053eb356SAaron Smith 14053eb356SAaron Smith #include "lldb/Utility/Status.h" 15053eb356SAaron Smith #include "lldb/lldb-forward.h" 16053eb356SAaron Smith #include "lldb/lldb-types.h" 17053eb356SAaron Smith #include "llvm/Support/Mutex.h" 18053eb356SAaron Smith 19053eb356SAaron Smith #include "ForwardDecl.h" 20053eb356SAaron Smith #include <map> 21053eb356SAaron Smith #include <set> 22053eb356SAaron Smith 23053eb356SAaron Smith namespace lldb_private { 24053eb356SAaron Smith 25053eb356SAaron Smith class HostProcess; 26053eb356SAaron Smith class HostThread; 27053eb356SAaron Smith class ProcessLaunchInfo; 28053eb356SAaron Smith class ProcessAttachInfo; 29053eb356SAaron Smith 30053eb356SAaron Smith class ProcessWindowsData { 31053eb356SAaron Smith public: ProcessWindowsData(bool stop_at_entry)32053eb356SAaron Smith ProcessWindowsData(bool stop_at_entry) : m_stop_at_entry(stop_at_entry) { 33053eb356SAaron Smith m_initial_stop_event = ::CreateEvent(nullptr, TRUE, FALSE, nullptr); 34053eb356SAaron Smith } 35053eb356SAaron Smith ~ProcessWindowsData()36053eb356SAaron Smith ~ProcessWindowsData() { ::CloseHandle(m_initial_stop_event); } 37053eb356SAaron Smith 38053eb356SAaron Smith Status m_launch_error; 39053eb356SAaron Smith DebuggerThreadSP m_debugger; 40053eb356SAaron Smith // StopInfoSP m_pending_stop_info; 41053eb356SAaron Smith HANDLE m_initial_stop_event = nullptr; 42053eb356SAaron Smith bool m_initial_stop_received = false; 43053eb356SAaron Smith bool m_stop_at_entry; 446179c0ebSAleksandr Urakov std::map<lldb::tid_t, lldb::ThreadSP> m_new_threads; 45053eb356SAaron Smith std::set<lldb::tid_t> m_exited_threads; 46053eb356SAaron Smith }; 47053eb356SAaron Smith 48053eb356SAaron Smith class ProcessDebugger { 49053eb356SAaron Smith 50053eb356SAaron Smith public: 51403cd574SMartin Storsjö virtual ~ProcessDebugger(); 52403cd574SMartin Storsjö 53053eb356SAaron Smith virtual void OnExitProcess(uint32_t exit_code); 54053eb356SAaron Smith virtual void OnDebuggerConnected(lldb::addr_t image_base); 55053eb356SAaron Smith virtual ExceptionResult OnDebugException(bool first_chance, 56053eb356SAaron Smith const ExceptionRecord &record); 57053eb356SAaron Smith virtual void OnCreateThread(const HostThread &thread); 58053eb356SAaron Smith virtual void OnExitThread(lldb::tid_t thread_id, uint32_t exit_code); 59053eb356SAaron Smith virtual void OnLoadDll(const ModuleSpec &module_spec, 60053eb356SAaron Smith lldb::addr_t module_addr); 61053eb356SAaron Smith virtual void OnUnloadDll(lldb::addr_t module_addr); 62053eb356SAaron Smith virtual void OnDebugString(const std::string &string); 63053eb356SAaron Smith virtual void OnDebuggerError(const Status &error, uint32_t type); 64053eb356SAaron Smith 65053eb356SAaron Smith protected: 66053eb356SAaron Smith Status DetachProcess(); 67053eb356SAaron Smith 68053eb356SAaron Smith Status LaunchProcess(ProcessLaunchInfo &launch_info, 69053eb356SAaron Smith DebugDelegateSP delegate); 70053eb356SAaron Smith 71053eb356SAaron Smith Status AttachProcess(lldb::pid_t pid, const ProcessAttachInfo &attach_info, 72053eb356SAaron Smith DebugDelegateSP delegate); 73053eb356SAaron Smith 74053eb356SAaron Smith Status DestroyProcess(lldb::StateType process_state); 75053eb356SAaron Smith 76053eb356SAaron Smith Status HaltProcess(bool &caused_stop); 77053eb356SAaron Smith 78*5fbcf677SDavid Spickett Status GetMemoryRegionInfo(lldb::addr_t load_addr, 79053eb356SAaron Smith MemoryRegionInfo &range_info); 80053eb356SAaron Smith 81053eb356SAaron Smith Status ReadMemory(lldb::addr_t addr, void *buf, size_t size, 82053eb356SAaron Smith size_t &bytes_read); 83053eb356SAaron Smith 84053eb356SAaron Smith Status WriteMemory(lldb::addr_t addr, const void *buf, size_t size, 85053eb356SAaron Smith size_t &bytes_written); 86053eb356SAaron Smith 87053eb356SAaron Smith Status AllocateMemory(size_t size, uint32_t permissions, lldb::addr_t &addr); 88053eb356SAaron Smith 89053eb356SAaron Smith Status DeallocateMemory(lldb::addr_t addr); 90053eb356SAaron Smith 91053eb356SAaron Smith lldb::pid_t GetDebuggedProcessId() const; 92053eb356SAaron Smith 93053eb356SAaron Smith Status WaitForDebuggerConnection(DebuggerThreadSP debugger, 94053eb356SAaron Smith HostProcess &process); 95053eb356SAaron Smith 96053eb356SAaron Smith protected: 97053eb356SAaron Smith llvm::sys::Mutex m_mutex; 98053eb356SAaron Smith std::unique_ptr<ProcessWindowsData> m_session_data; 99053eb356SAaron Smith }; 100053eb356SAaron Smith 101053eb356SAaron Smith } // namespace lldb_private 102053eb356SAaron Smith 103053eb356SAaron Smith #endif // #ifndef liblldb_ProcessDebugger_h_ 104