1 //===-- ProcessMachCore.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 LLDB_SOURCE_PLUGINS_PROCESS_MACH_CORE_PROCESSMACHCORE_H 10 #define LLDB_SOURCE_PLUGINS_PROCESS_MACH_CORE_PROCESSMACHCORE_H 11 12 #include <list> 13 #include <vector> 14 15 #include "lldb/Target/PostMortemProcess.h" 16 #include "lldb/Utility/ConstString.h" 17 #include "lldb/Utility/Status.h" 18 19 class ThreadKDP; 20 21 class ProcessMachCore : public lldb_private::PostMortemProcess { 22 public: 23 // Constructors and Destructors 24 ProcessMachCore(lldb::TargetSP target_sp, lldb::ListenerSP listener, 25 const lldb_private::FileSpec &core_file); 26 27 ~ProcessMachCore() override; 28 29 static lldb::ProcessSP 30 CreateInstance(lldb::TargetSP target_sp, lldb::ListenerSP listener, 31 const lldb_private::FileSpec *crash_file_path, 32 bool can_connect); 33 34 static void Initialize(); 35 36 static void Terminate(); 37 38 static lldb_private::ConstString GetPluginNameStatic(); 39 40 static const char *GetPluginDescriptionStatic(); 41 42 // Check if a given Process 43 bool CanDebug(lldb::TargetSP target_sp, 44 bool plugin_specified_by_name) override; 45 46 // Creating a new process, or attaching to an existing one 47 lldb_private::Status DoLoadCore() override; 48 49 lldb_private::DynamicLoader *GetDynamicLoader() override; 50 51 // PluginInterface protocol 52 lldb_private::ConstString GetPluginName() override; 53 54 uint32_t GetPluginVersion() override; 55 56 // Process Control 57 lldb_private::Status DoDestroy() override; 58 59 void RefreshStateAfterStop() override; 60 61 // Process Queries 62 bool IsAlive() override; 63 64 bool WarnBeforeDetach() const override; 65 66 // Process Memory 67 size_t ReadMemory(lldb::addr_t addr, void *buf, size_t size, 68 lldb_private::Status &error) override; 69 70 size_t DoReadMemory(lldb::addr_t addr, void *buf, size_t size, 71 lldb_private::Status &error) override; 72 73 lldb_private::Status 74 GetMemoryRegionInfo(lldb::addr_t load_addr, 75 lldb_private::MemoryRegionInfo ®ion_info) override; 76 77 lldb::addr_t GetImageInfoAddress() override; 78 79 protected: 80 friend class ThreadMachCore; 81 82 void Clear(); 83 84 bool DoUpdateThreadList(lldb_private::ThreadList &old_thread_list, 85 lldb_private::ThreadList &new_thread_list) override; 86 87 lldb_private::ObjectFile *GetCoreObjectFile(); 88 89 private: 90 bool GetDynamicLoaderAddress(lldb::addr_t addr); 91 92 enum CorefilePreference { eUserProcessCorefile, eKernelCorefile }; 93 94 /// If a core file can be interpreted multiple ways, this establishes 95 /// which style wins. 96 /// 97 /// If a core file contains both a kernel binary and a user-process 98 /// dynamic loader, lldb needs to pick one over the other. This could 99 /// be a kernel corefile that happens to have a copy of dyld in its 100 /// memory. Or it could be a user process coredump of lldb while doing 101 /// kernel debugging - so a copy of the kernel is in its heap. This 102 /// should become a setting so it can be over-ridden when necessary. 103 CorefilePreference GetCorefilePreference() { 104 // For now, if both user process and kernel binaries a present, 105 // assume this is a kernel coredump which has a copy of a user 106 // process dyld in one of its pages. 107 return eKernelCorefile; 108 } 109 110 // For ProcessMachCore only 111 typedef lldb_private::Range<lldb::addr_t, lldb::addr_t> FileRange; 112 typedef lldb_private::RangeDataVector<lldb::addr_t, lldb::addr_t, FileRange> 113 VMRangeToFileOffset; 114 typedef lldb_private::RangeDataVector<lldb::addr_t, lldb::addr_t, uint32_t> 115 VMRangeToPermissions; 116 117 VMRangeToFileOffset m_core_aranges; 118 VMRangeToPermissions m_core_range_infos; 119 lldb::ModuleSP m_core_module_sp; 120 lldb_private::FileSpec m_core_file; 121 lldb::addr_t m_dyld_addr; 122 lldb::addr_t m_mach_kernel_addr; 123 lldb_private::ConstString m_dyld_plugin_name; 124 }; 125 126 #endif // LLDB_SOURCE_PLUGINS_PROCESS_MACH_CORE_PROCESSMACHCORE_H 127