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