File indexing completed on 2026-05-10 08:42:52
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef LLDB_SYMBOL_SYMBOL_H
0010 #define LLDB_SYMBOL_SYMBOL_H
0011
0012 #include "lldb/Core/AddressRange.h"
0013 #include "lldb/Core/Mangled.h"
0014 #include "lldb/Core/Section.h"
0015 #include "lldb/Symbol/SymbolContextScope.h"
0016 #include "lldb/Utility/Stream.h"
0017 #include "lldb/Utility/UserID.h"
0018 #include "lldb/lldb-private.h"
0019 #include "llvm/Support/JSON.h"
0020
0021 namespace lldb_private {
0022
0023 struct JSONSymbol {
0024 std::optional<uint64_t> address;
0025 std::optional<uint64_t> value;
0026 std::optional<uint64_t> size;
0027 std::optional<uint64_t> id;
0028 std::optional<lldb::SymbolType> type;
0029 std::string name;
0030 };
0031
0032 class Symbol : public SymbolContextScope {
0033 public:
0034
0035
0036
0037 Symbol();
0038
0039 Symbol(uint32_t symID, llvm::StringRef name, lldb::SymbolType type,
0040 bool external, bool is_debug, bool is_trampoline, bool is_artificial,
0041 const lldb::SectionSP §ion_sp, lldb::addr_t value,
0042 lldb::addr_t size, bool size_is_valid,
0043 bool contains_linker_annotations, uint32_t flags);
0044
0045 Symbol(uint32_t symID, const Mangled &mangled, lldb::SymbolType type,
0046 bool external, bool is_debug, bool is_trampoline, bool is_artificial,
0047 const AddressRange &range, bool size_is_valid,
0048 bool contains_linker_annotations, uint32_t flags);
0049
0050 Symbol(const Symbol &rhs);
0051
0052 const Symbol &operator=(const Symbol &rhs);
0053
0054 static llvm::Expected<Symbol> FromJSON(const JSONSymbol &symbol,
0055 SectionList *section_list);
0056
0057 void Clear();
0058
0059 bool Compare(ConstString name, lldb::SymbolType type) const;
0060
0061 void Dump(Stream *s, Target *target, uint32_t index,
0062 Mangled::NamePreference name_preference =
0063 Mangled::ePreferDemangled) const;
0064
0065 bool ValueIsAddress() const;
0066
0067
0068
0069
0070
0071
0072 Address &GetAddressRef() { return m_addr_range.GetBaseAddress(); }
0073
0074 const Address &GetAddressRef() const { return m_addr_range.GetBaseAddress(); }
0075
0076
0077
0078 lldb::addr_t GetFileAddress() const;
0079
0080
0081
0082
0083 lldb::addr_t GetLoadAddress(Target *target) const;
0084
0085
0086
0087
0088 Address GetAddress() const {
0089
0090
0091
0092
0093
0094
0095
0096
0097 if (ValueIsAddress())
0098 return m_addr_range.GetBaseAddress();
0099 else
0100 return Address();
0101 }
0102
0103
0104
0105
0106
0107
0108
0109 uint64_t GetRawValue() const {
0110 return m_addr_range.GetBaseAddress().GetFileAddress();
0111 }
0112
0113
0114
0115
0116
0117 uint64_t GetIntegerValue(uint64_t fail_value = 0) const {
0118 if (ValueIsAddress()) {
0119
0120
0121 return fail_value;
0122 } else {
0123
0124 return m_addr_range.GetBaseAddress().GetOffset();
0125 }
0126 }
0127
0128 lldb::addr_t ResolveCallableAddress(Target &target) const;
0129
0130 ConstString GetName() const;
0131
0132 ConstString GetNameNoArguments() const;
0133
0134 ConstString GetDisplayName() const;
0135
0136 uint32_t GetID() const { return m_uid; }
0137
0138 lldb::LanguageType GetLanguage() const {
0139
0140
0141 return GetMangled().GuessLanguage();
0142 }
0143
0144 void SetID(uint32_t uid) { m_uid = uid; }
0145
0146 Mangled &GetMangled() {
0147 SynthesizeNameIfNeeded();
0148 return m_mangled;
0149 }
0150
0151 const Mangled &GetMangled() const {
0152 SynthesizeNameIfNeeded();
0153 return m_mangled;
0154 }
0155
0156 ConstString GetReExportedSymbolName() const;
0157
0158 FileSpec GetReExportedSymbolSharedLibrary() const;
0159
0160 void SetReExportedSymbolName(ConstString name);
0161
0162 bool SetReExportedSymbolSharedLibrary(const FileSpec &fspec);
0163
0164 Symbol *ResolveReExportedSymbol(Target &target) const;
0165
0166 uint32_t GetSiblingIndex() const;
0167
0168 lldb::SymbolType GetType() const { return (lldb::SymbolType)m_type; }
0169
0170 void SetType(lldb::SymbolType type) { m_type = (lldb::SymbolType)type; }
0171
0172 const char *GetTypeAsString() const;
0173
0174 uint32_t GetFlags() const { return m_flags; }
0175
0176 void SetFlags(uint32_t flags) { m_flags = flags; }
0177
0178 void GetDescription(
0179 Stream *s, lldb::DescriptionLevel level, Target *target,
0180 std::optional<Stream::HighlightSettings> settings = std::nullopt) const;
0181
0182 bool IsSynthetic() const { return m_is_synthetic; }
0183
0184 bool IsSyntheticWithAutoGeneratedName() const;
0185
0186 void SetIsSynthetic(bool b) { m_is_synthetic = b; }
0187
0188 bool GetSizeIsSynthesized() const { return m_size_is_synthesized; }
0189
0190 void SetSizeIsSynthesized(bool b) { m_size_is_synthesized = b; }
0191
0192 bool IsDebug() const { return m_is_debug; }
0193
0194 void SetDebug(bool b) { m_is_debug = b; }
0195
0196 bool IsExternal() const { return m_is_external; }
0197
0198 void SetExternal(bool b) { m_is_external = b; }
0199
0200 bool IsTrampoline() const;
0201
0202 bool IsIndirect() const;
0203
0204 bool IsWeak() const { return m_is_weak; }
0205
0206 void SetIsWeak(bool b) { m_is_weak = b; }
0207
0208 bool GetByteSizeIsValid() const { return m_size_is_valid; }
0209
0210 lldb::addr_t GetByteSize() const;
0211
0212 void SetByteSize(lldb::addr_t size) {
0213 m_size_is_valid = size > 0;
0214 m_addr_range.SetByteSize(size);
0215 }
0216
0217 bool GetSizeIsSibling() const { return m_size_is_sibling; }
0218
0219 void SetSizeIsSibling(bool b) { m_size_is_sibling = b; }
0220
0221
0222
0223 uint32_t GetPrologueByteSize();
0224
0225 bool GetDemangledNameIsSynthesized() const {
0226 return m_demangled_is_synthesized;
0227 }
0228
0229 void SetDemangledNameIsSynthesized(bool b) { m_demangled_is_synthesized = b; }
0230
0231 bool ContainsLinkerAnnotations() const {
0232 return m_contains_linker_annotations;
0233 }
0234 void SetContainsLinkerAnnotations(bool b) {
0235 m_contains_linker_annotations = b;
0236 }
0237
0238
0239
0240 void CalculateSymbolContext(SymbolContext *sc) override;
0241
0242 lldb::ModuleSP CalculateSymbolContextModule() override;
0243
0244 Symbol *CalculateSymbolContextSymbol() override;
0245
0246
0247
0248
0249 void DumpSymbolContext(Stream *s) override;
0250
0251 lldb::DisassemblerSP GetInstructions(const ExecutionContext &exe_ctx,
0252 const char *flavor,
0253 bool prefer_file_cache);
0254
0255 bool GetDisassembly(const ExecutionContext &exe_ctx, const char *flavor,
0256 bool prefer_file_cache, Stream &strm);
0257
0258 bool ContainsFileAddress(lldb::addr_t file_addr) const;
0259
0260 static llvm::StringRef GetSyntheticSymbolPrefix() {
0261 return "___lldb_unnamed_symbol";
0262 }
0263
0264
0265
0266
0267
0268
0269
0270
0271
0272
0273
0274
0275
0276
0277
0278
0279
0280
0281
0282
0283
0284
0285
0286 bool Decode(const DataExtractor &data, lldb::offset_t *offset_ptr,
0287 const SectionList *section_list, const StringTableReader &strtab);
0288
0289
0290
0291
0292
0293
0294
0295
0296
0297
0298
0299
0300 void Encode(DataEncoder &encoder, ConstStringTable &strtab) const;
0301
0302 bool operator==(const Symbol &rhs) const;
0303
0304 protected:
0305
0306
0307
0308
0309 Symbol *ResolveReExportedSymbolInModuleSpec(
0310 Target &target, ConstString &reexport_name,
0311 lldb_private::ModuleSpec &module_spec,
0312 lldb_private::ModuleList &seen_modules) const;
0313
0314 void SynthesizeNameIfNeeded() const;
0315
0316 uint32_t m_uid =
0317 UINT32_MAX;
0318 uint16_t m_type_data = 0;
0319 uint16_t m_type_data_resolved : 1,
0320
0321 m_is_synthetic : 1,
0322
0323
0324 m_is_debug : 1,
0325
0326 m_is_external : 1,
0327 m_size_is_sibling : 1,
0328
0329 m_size_is_synthesized : 1,
0330
0331
0332 m_size_is_valid : 1,
0333 m_demangled_is_synthesized : 1,
0334
0335
0336 m_contains_linker_annotations : 1,
0337
0338
0339 m_is_weak : 1,
0340 m_type : 6;
0341 mutable Mangled m_mangled;
0342 AddressRange m_addr_range;
0343
0344
0345 uint32_t m_flags = 0;
0346
0347 };
0348
0349 }
0350
0351 namespace llvm {
0352 namespace json {
0353
0354 bool fromJSON(const llvm::json::Value &value, lldb_private::JSONSymbol &symbol,
0355 llvm::json::Path path);
0356
0357 bool fromJSON(const llvm::json::Value &value, lldb::SymbolType &type,
0358 llvm::json::Path path);
0359
0360 }
0361 }
0362
0363 #endif