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