1 //===-- ProcessElfCore.h ---------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
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
15 //===----------------------------------------------------------------------===//
17 #ifndef liblldb_ProcessElfCore_h_
18 #define liblldb_ProcessElfCore_h_
24 // Other libraries and framework includes
25 #include "lldb/Core/ConstString.h"
26 #include "lldb/Core/Error.h"
27 #include "lldb/Target/Process.h"
29 #include "Plugins/ObjectFile/ELF/ELFHeader.h"
33 class ProcessElfCore : public lldb_private::Process
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);
50 static lldb_private::ConstString
51 GetPluginNameStatic();
54 GetPluginDescriptionStatic();
56 //------------------------------------------------------------------
57 // Constructors and Destructors
58 //------------------------------------------------------------------
59 ProcessElfCore(lldb_private::Target& target,
60 lldb_private::Listener &listener,
61 const lldb_private::FileSpec &core_file);
66 //------------------------------------------------------------------
67 // Check if a given Process
68 //------------------------------------------------------------------
69 bool CanDebug(lldb_private::Target &target, bool plugin_specified_by_name) override;
71 //------------------------------------------------------------------
72 // Creating a new process, or attaching to an existing one
73 //------------------------------------------------------------------
74 lldb_private::Error DoLoadCore() override;
76 lldb_private::DynamicLoader *GetDynamicLoader() override;
78 //------------------------------------------------------------------
79 // PluginInterface protocol
80 //------------------------------------------------------------------
81 lldb_private::ConstString GetPluginName() override;
83 uint32_t GetPluginVersion() override;
85 //------------------------------------------------------------------
87 //------------------------------------------------------------------
88 lldb_private::Error DoDestroy() override;
90 void RefreshStateAfterStop() override;
92 //------------------------------------------------------------------
94 //------------------------------------------------------------------
95 bool IsAlive() override;
97 //------------------------------------------------------------------
99 //------------------------------------------------------------------
100 size_t ReadMemory(lldb::addr_t addr, void *buf, size_t size, lldb_private::Error &error) override;
102 size_t DoReadMemory(lldb::addr_t addr, void *buf, size_t size, lldb_private::Error &error) override;
104 lldb::addr_t GetImageInfoAddress() override;
106 lldb_private::ArchSpec
109 // Returns AUXV structure found in the core file
110 const lldb::DataBufferSP
111 GetAuxvData() override;
117 bool UpdateThreadList(lldb_private::ThreadList &old_thread_list,
118 lldb_private::ThreadList &new_thread_list) override;
121 //------------------------------------------------------------------
122 // For ProcessElfCore only
123 //------------------------------------------------------------------
124 typedef lldb_private::Range<lldb::addr_t, lldb::addr_t> FileRange;
125 typedef lldb_private::RangeDataArray<lldb::addr_t, lldb::addr_t, FileRange, 1> VMRangeToFileOffset;
127 lldb::ModuleSP m_core_module_sp;
128 lldb_private::FileSpec m_core_file;
129 std::string m_dyld_plugin_name;
130 DISALLOW_COPY_AND_ASSIGN (ProcessElfCore);
132 llvm::Triple::OSType m_os;
134 // True if m_thread_contexts contains valid entries
135 bool m_thread_data_valid;
137 // Contain thread data read from NOTE segments
138 std::vector<ThreadData> m_thread_data;
140 // AUXV structure found from the NOTE segment
141 lldb_private::DataExtractor m_auxv;
143 // Address ranges found in the core
144 VMRangeToFileOffset m_core_aranges;
146 // Parse thread(s) data structures(prstatus, prpsinfo) from given NOTE segment
148 ParseThreadContextsFromNoteSegment (const elf::ELFProgramHeader *segment_header,
149 lldb_private::DataExtractor segment_data);
151 // Returns number of thread contexts stored in the core file
153 GetNumThreadContexts();
155 // Parse a contiguous address range of the process from LOAD segment
157 AddAddressRangeFromLoadSegment(const elf::ELFProgramHeader *header);
160 #endif // liblldb_ProcessElffCore_h_