1 //===-- ProcessElfCore.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 // Notes about Linux Process core dumps: 9 // 1) Linux core dump is stored as ELF file. 10 // 2) The ELF file's PT_NOTE and PT_LOAD segments describes the program's 11 // address space and thread contexts. 12 // 3) PT_NOTE segment contains note entries which describes a thread context. 13 // 4) PT_LOAD segment describes a valid contigous range of process address 14 // space. 15 //===----------------------------------------------------------------------===// 16 17 #ifndef liblldb_ProcessElfCore_h_ 18 #define liblldb_ProcessElfCore_h_ 19 20 // C++ Includes 21 #include <list> 22 #include <vector> 23 24 // Other libraries and framework includes 25 #include "lldb/Core/ConstString.h" 26 #include "lldb/Core/Error.h" 27 #include "lldb/Target/Process.h" 28 29 #include "Plugins/ObjectFile/ELF/ELFHeader.h" 30 31 struct ThreadData; 32 33 class ProcessElfCore : public lldb_private::Process 34 { 35 public: 36 //------------------------------------------------------------------ 37 // Constructors and Destructors 38 //------------------------------------------------------------------ 39 static lldb::ProcessSP 40 CreateInstance (lldb_private::Target& target, 41 lldb_private::Listener &listener, 42 const lldb_private::FileSpec *crash_file_path); 43 44 static void 45 Initialize(); 46 47 static void 48 Terminate(); 49 50 static lldb_private::ConstString 51 GetPluginNameStatic(); 52 53 static const char * 54 GetPluginDescriptionStatic(); 55 56 //------------------------------------------------------------------ 57 // Constructors and Destructors 58 //------------------------------------------------------------------ 59 ProcessElfCore(lldb_private::Target& target, 60 lldb_private::Listener &listener, 61 const lldb_private::FileSpec &core_file); 62 63 virtual 64 ~ProcessElfCore(); 65 66 //------------------------------------------------------------------ 67 // Check if a given Process 68 //------------------------------------------------------------------ 69 virtual bool 70 CanDebug (lldb_private::Target &target, 71 bool plugin_specified_by_name); 72 73 //------------------------------------------------------------------ 74 // Creating a new process, or attaching to an existing one 75 //------------------------------------------------------------------ 76 virtual lldb_private::Error 77 DoLoadCore (); 78 79 virtual lldb_private::DynamicLoader * 80 GetDynamicLoader (); 81 82 //------------------------------------------------------------------ 83 // PluginInterface protocol 84 //------------------------------------------------------------------ 85 virtual lldb_private::ConstString 86 GetPluginName(); 87 88 virtual uint32_t 89 GetPluginVersion(); 90 91 //------------------------------------------------------------------ 92 // Process Control 93 //------------------------------------------------------------------ 94 virtual lldb_private::Error 95 DoDestroy (); 96 97 virtual void 98 RefreshStateAfterStop(); 99 100 //------------------------------------------------------------------ 101 // Process Queries 102 //------------------------------------------------------------------ 103 virtual bool 104 IsAlive (); 105 106 //------------------------------------------------------------------ 107 // Process Signals 108 //------------------------------------------------------------------ 109 virtual lldb_private::UnixSignals & 110 GetUnixSignals() 111 { 112 if (m_signals_sp) 113 return *m_signals_sp; 114 else 115 return Process::GetUnixSignals(); 116 } 117 118 //------------------------------------------------------------------ 119 // Process Memory 120 //------------------------------------------------------------------ 121 virtual size_t 122 ReadMemory (lldb::addr_t addr, void *buf, size_t size, lldb_private::Error &error); 123 124 virtual size_t 125 DoReadMemory (lldb::addr_t addr, void *buf, size_t size, lldb_private::Error &error); 126 127 virtual lldb::addr_t 128 GetImageInfoAddress (); 129 130 lldb_private::ArchSpec 131 GetArchitecture(); 132 133 // Returns AUXV structure found in the core file 134 const lldb::DataBufferSP 135 GetAuxvData(); 136 137 protected: 138 void 139 Clear ( ); 140 141 virtual bool 142 UpdateThreadList (lldb_private::ThreadList &old_thread_list, 143 lldb_private::ThreadList &new_thread_list); 144 145 private: 146 //------------------------------------------------------------------ 147 // For ProcessElfCore only 148 //------------------------------------------------------------------ 149 typedef lldb_private::Range<lldb::addr_t, lldb::addr_t> FileRange; 150 typedef lldb_private::RangeDataArray<lldb::addr_t, lldb::addr_t, FileRange, 1> VMRangeToFileOffset; 151 152 lldb::ModuleSP m_core_module_sp; 153 lldb_private::FileSpec m_core_file; 154 std::string m_dyld_plugin_name; 155 DISALLOW_COPY_AND_ASSIGN (ProcessElfCore); 156 157 llvm::Triple::OSType m_os; 158 std::shared_ptr<lldb_private::UnixSignals> m_signals_sp; 159 160 // True if m_thread_contexts contains valid entries 161 bool m_thread_data_valid; 162 163 // Contain thread data read from NOTE segments 164 std::vector<ThreadData> m_thread_data; 165 166 // AUXV structure found from the NOTE segment 167 lldb_private::DataExtractor m_auxv; 168 169 // Address ranges found in the core 170 VMRangeToFileOffset m_core_aranges; 171 172 // Parse thread(s) data structures(prstatus, prpsinfo) from given NOTE segment 173 void 174 ParseThreadContextsFromNoteSegment (const elf::ELFProgramHeader *segment_header, 175 lldb_private::DataExtractor segment_data); 176 177 // Returns number of thread contexts stored in the core file 178 uint32_t 179 GetNumThreadContexts(); 180 181 // Parse a contiguous address range of the process from LOAD segment 182 lldb::addr_t 183 AddAddressRangeFromLoadSegment(const elf::ELFProgramHeader *header); 184 }; 185 186 #endif // liblldb_ProcessElffCore_h_ 187