File indexing completed on 2026-05-10 08:42:46
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef LLDB_CORE_SECTION_H
0010 #define LLDB_CORE_SECTION_H
0011
0012 #include "lldb/Core/ModuleChild.h"
0013 #include "lldb/Utility/ConstString.h"
0014 #include "lldb/Utility/Flags.h"
0015 #include "lldb/Utility/UserID.h"
0016 #include "lldb/lldb-defines.h"
0017 #include "lldb/lldb-enumerations.h"
0018 #include "lldb/lldb-forward.h"
0019 #include "lldb/lldb-types.h"
0020 #include "llvm/Support/JSON.h"
0021
0022 #include <memory>
0023 #include <vector>
0024
0025 #include <cstddef>
0026 #include <cstdint>
0027
0028 namespace lldb_private {
0029 class Address;
0030 class DataExtractor;
0031 class ObjectFile;
0032 class Section;
0033 class Target;
0034
0035 class SectionList {
0036 public:
0037 typedef std::vector<lldb::SectionSP> collection;
0038 typedef collection::iterator iterator;
0039 typedef collection::const_iterator const_iterator;
0040
0041 const_iterator begin() const { return m_sections.begin(); }
0042 const_iterator end() const { return m_sections.end(); }
0043 const_iterator begin() { return m_sections.begin(); }
0044 const_iterator end() { return m_sections.end(); }
0045
0046
0047 SectionList() = default;
0048
0049 SectionList &operator=(const SectionList &rhs);
0050
0051 size_t AddSection(const lldb::SectionSP §ion_sp);
0052
0053 size_t AddUniqueSection(const lldb::SectionSP §ion_sp);
0054
0055 size_t FindSectionIndex(const Section *sect);
0056
0057 bool ContainsSection(lldb::user_id_t sect_id) const;
0058
0059 void Dump(llvm::raw_ostream &s, unsigned indent, Target *target,
0060 bool show_header, uint32_t depth) const;
0061
0062 lldb::SectionSP FindSectionByName(ConstString section_dstr) const;
0063
0064 lldb::SectionSP FindSectionByID(lldb::user_id_t sect_id) const;
0065
0066 lldb::SectionSP FindSectionByType(lldb::SectionType sect_type,
0067 bool check_children,
0068 size_t start_idx = 0) const;
0069
0070 lldb::SectionSP
0071 FindSectionContainingFileAddress(lldb::addr_t addr,
0072 uint32_t depth = UINT32_MAX) const;
0073
0074
0075 size_t GetSize() const { return m_sections.size(); }
0076
0077
0078 size_t GetNumSections(uint32_t depth) const;
0079
0080 bool ReplaceSection(lldb::user_id_t sect_id,
0081 const lldb::SectionSP §ion_sp,
0082 uint32_t depth = UINT32_MAX);
0083
0084
0085 bool DeleteSection(size_t idx);
0086
0087 lldb::SectionSP GetSectionAtIndex(size_t idx) const;
0088
0089 size_t Slide(lldb::addr_t slide_amount, bool slide_children);
0090
0091 void Clear() { m_sections.clear(); }
0092
0093
0094
0095
0096
0097 uint64_t GetDebugInfoSize() const;
0098
0099 protected:
0100 collection m_sections;
0101 };
0102
0103 struct JSONSection {
0104 std::string name;
0105 std::optional<lldb::SectionType> type;
0106 std::optional<uint64_t> address;
0107 std::optional<uint64_t> size;
0108 };
0109
0110 class Section : public std::enable_shared_from_this<Section>,
0111 public ModuleChild,
0112 public UserID,
0113 public Flags {
0114 public:
0115
0116 Section(const lldb::ModuleSP &module_sp, ObjectFile *obj_file,
0117 lldb::user_id_t sect_id, ConstString name,
0118 lldb::SectionType sect_type, lldb::addr_t file_vm_addr,
0119 lldb::addr_t vm_size, lldb::offset_t file_offset,
0120 lldb::offset_t file_size, uint32_t log2align, uint32_t flags,
0121 uint32_t target_byte_size = 1);
0122
0123
0124 Section(const lldb::SectionSP &parent_section_sp,
0125
0126
0127 const lldb::ModuleSP &module_sp, ObjectFile *obj_file,
0128 lldb::user_id_t sect_id, ConstString name,
0129 lldb::SectionType sect_type, lldb::addr_t file_vm_addr,
0130 lldb::addr_t vm_size, lldb::offset_t file_offset,
0131 lldb::offset_t file_size, uint32_t log2align, uint32_t flags,
0132 uint32_t target_byte_size = 1);
0133
0134 ~Section();
0135
0136 static int Compare(const Section &a, const Section &b);
0137
0138 bool ContainsFileAddress(lldb::addr_t vm_addr) const;
0139
0140 SectionList &GetChildren() { return m_children; }
0141
0142 const SectionList &GetChildren() const { return m_children; }
0143
0144 void Dump(llvm::raw_ostream &s, unsigned indent, Target *target,
0145 uint32_t depth) const;
0146
0147 void DumpName(llvm::raw_ostream &s) const;
0148
0149 lldb::addr_t GetLoadBaseAddress(Target *target) const;
0150
0151 bool ResolveContainedAddress(lldb::addr_t offset, Address &so_addr,
0152 bool allow_section_end = false) const;
0153
0154 lldb::offset_t GetFileOffset() const { return m_file_offset; }
0155
0156 void SetFileOffset(lldb::offset_t file_offset) {
0157 m_file_offset = file_offset;
0158 }
0159
0160 lldb::offset_t GetFileSize() const { return m_file_size; }
0161
0162 void SetFileSize(lldb::offset_t file_size) { m_file_size = file_size; }
0163
0164 lldb::addr_t GetFileAddress() const;
0165
0166 bool SetFileAddress(lldb::addr_t file_addr);
0167
0168 lldb::addr_t GetOffset() const;
0169
0170 lldb::addr_t GetByteSize() const { return m_byte_size; }
0171
0172 void SetByteSize(lldb::addr_t byte_size) { m_byte_size = byte_size; }
0173
0174 bool IsFake() const { return m_fake; }
0175
0176 void SetIsFake(bool fake) { m_fake = fake; }
0177
0178 bool IsEncrypted() const { return m_encrypted; }
0179
0180 void SetIsEncrypted(bool b) { m_encrypted = b; }
0181
0182 bool IsDescendant(const Section *section);
0183
0184 ConstString GetName() const { return m_name; }
0185
0186 bool Slide(lldb::addr_t slide_amount, bool slide_children);
0187
0188 lldb::SectionType GetType() const { return m_type; }
0189
0190 const char *GetTypeAsCString() const;
0191
0192 lldb::SectionSP GetParent() const { return m_parent_wp.lock(); }
0193
0194 bool IsThreadSpecific() const { return m_thread_specific; }
0195
0196 void SetIsThreadSpecific(bool b) { m_thread_specific = b; }
0197
0198
0199 uint32_t GetPermissions() const;
0200
0201
0202 void SetPermissions(uint32_t permissions);
0203
0204 ObjectFile *GetObjectFile() { return m_obj_file; }
0205 const ObjectFile *GetObjectFile() const { return m_obj_file; }
0206
0207
0208
0209
0210
0211
0212
0213
0214
0215
0216
0217
0218
0219
0220
0221
0222
0223
0224 lldb::offset_t GetSectionData(void *dst, lldb::offset_t dst_len,
0225 lldb::offset_t offset = 0);
0226
0227
0228
0229
0230
0231
0232
0233
0234
0235
0236
0237
0238
0239
0240 lldb::offset_t GetSectionData(DataExtractor &data);
0241
0242 uint32_t GetLog2Align() { return m_log2align; }
0243
0244 void SetLog2Align(uint32_t align) { m_log2align = align; }
0245
0246
0247 uint32_t GetTargetByteSize() const { return m_target_byte_size; }
0248
0249 bool IsRelocated() const { return m_relocated; }
0250
0251 void SetIsRelocated(bool b) { m_relocated = b; }
0252
0253
0254
0255
0256
0257
0258 bool ContainsOnlyDebugInfo() const;
0259
0260 protected:
0261 ObjectFile *m_obj_file;
0262
0263 lldb::SectionType m_type;
0264 lldb::SectionWP m_parent_wp;
0265 ConstString m_name;
0266 lldb::addr_t m_file_addr;
0267
0268
0269 lldb::addr_t m_byte_size;
0270
0271 lldb::offset_t m_file_offset;
0272 lldb::offset_t m_file_size;
0273
0274 uint32_t m_log2align;
0275
0276 SectionList m_children;
0277 bool m_fake : 1,
0278
0279
0280
0281
0282 m_encrypted : 1,
0283 m_thread_specific : 1,
0284 m_readable : 1,
0285 m_writable : 1,
0286 m_executable : 1,
0287 m_relocated : 1;
0288 uint32_t m_target_byte_size;
0289
0290
0291 private:
0292 Section(const Section &) = delete;
0293 const Section &operator=(const Section &) = delete;
0294 };
0295
0296 }
0297
0298 namespace llvm {
0299 namespace json {
0300
0301 bool fromJSON(const llvm::json::Value &value,
0302 lldb_private::JSONSection §ion, llvm::json::Path path);
0303
0304 bool fromJSON(const llvm::json::Value &value, lldb::SectionType &type,
0305 llvm::json::Path path);
0306
0307 }
0308 }
0309
0310 #endif