File indexing completed on 2026-05-10 08:42:45
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef LLDB_CORE_MODULELIST_H
0010 #define LLDB_CORE_MODULELIST_H
0011
0012 #include "lldb/Core/Address.h"
0013 #include "lldb/Core/ModuleSpec.h"
0014 #include "lldb/Core/UserSettingsController.h"
0015 #include "lldb/Utility/FileSpec.h"
0016 #include "lldb/Utility/Iterable.h"
0017 #include "lldb/Utility/Status.h"
0018 #include "lldb/lldb-enumerations.h"
0019 #include "lldb/lldb-forward.h"
0020 #include "lldb/lldb-types.h"
0021
0022 #include "llvm/ADT/DenseSet.h"
0023 #include "llvm/Support/RWMutex.h"
0024
0025 #include <functional>
0026 #include <list>
0027 #include <mutex>
0028 #include <vector>
0029
0030 #include <cstddef>
0031 #include <cstdint>
0032
0033 namespace lldb_private {
0034 class ConstString;
0035 class FileSpecList;
0036 class Function;
0037 class Log;
0038 class Module;
0039 class RegularExpression;
0040 class Stream;
0041 class SymbolContext;
0042 class SymbolContextList;
0043 class SymbolFile;
0044 class Target;
0045 class TypeList;
0046 class UUID;
0047 class VariableList;
0048 struct ModuleFunctionSearchOptions;
0049
0050 static constexpr OptionEnumValueElement g_auto_download_enum_values[] = {
0051 {
0052 lldb::eSymbolDownloadOff,
0053 "off",
0054 "Disable automatically downloading symbols.",
0055 },
0056 {
0057 lldb::eSymbolDownloadBackground,
0058 "background",
0059 "Download symbols in the background for images as they appear in the "
0060 "backtrace.",
0061 },
0062 {
0063 lldb::eSymbolDownloadForeground,
0064 "foreground",
0065 "Download symbols in the foreground for images as they appear in the "
0066 "backtrace.",
0067 },
0068 };
0069
0070 class ModuleListProperties : public Properties {
0071 mutable llvm::sys::RWMutex m_symlink_paths_mutex;
0072 PathMappingList m_symlink_paths;
0073
0074 void UpdateSymlinkMappings();
0075
0076 public:
0077 ModuleListProperties();
0078
0079 FileSpec GetClangModulesCachePath() const;
0080 bool SetClangModulesCachePath(const FileSpec &path);
0081 bool GetEnableExternalLookup() const;
0082 bool SetEnableExternalLookup(bool new_value);
0083 bool GetEnableLLDBIndexCache() const;
0084 bool SetEnableLLDBIndexCache(bool new_value);
0085 uint64_t GetLLDBIndexCacheMaxByteSize();
0086 uint64_t GetLLDBIndexCacheMaxPercent();
0087 uint64_t GetLLDBIndexCacheExpirationDays();
0088 FileSpec GetLLDBIndexCachePath() const;
0089 bool SetLLDBIndexCachePath(const FileSpec &path);
0090
0091 bool GetLoadSymbolOnDemand();
0092
0093 lldb::SymbolDownload GetSymbolAutoDownload() const;
0094
0095 PathMappingList GetSymlinkMappings() const;
0096 };
0097
0098
0099
0100
0101
0102
0103 class ModuleList {
0104 public:
0105 class Notifier {
0106 public:
0107 virtual ~Notifier() = default;
0108
0109 virtual void NotifyModuleAdded(const ModuleList &module_list,
0110 const lldb::ModuleSP &module_sp) = 0;
0111 virtual void NotifyModuleRemoved(const ModuleList &module_list,
0112 const lldb::ModuleSP &module_sp) = 0;
0113 virtual void NotifyModuleUpdated(const ModuleList &module_list,
0114 const lldb::ModuleSP &old_module_sp,
0115 const lldb::ModuleSP &new_module_sp) = 0;
0116 virtual void NotifyWillClearList(const ModuleList &module_list) = 0;
0117
0118 virtual void NotifyModulesRemoved(lldb_private::ModuleList &module_list) = 0;
0119 };
0120
0121
0122
0123
0124 ModuleList();
0125
0126
0127
0128
0129
0130
0131
0132 ModuleList(const ModuleList &rhs);
0133
0134 ModuleList(ModuleList::Notifier *notifier);
0135
0136
0137 ~ModuleList();
0138
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148 const ModuleList &operator=(const ModuleList &rhs);
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164 void Append(const lldb::ModuleSP &module_sp, bool notify = true);
0165
0166
0167
0168
0169
0170
0171
0172
0173
0174
0175
0176
0177
0178 void ReplaceEquivalent(
0179 const lldb::ModuleSP &module_sp,
0180 llvm::SmallVectorImpl<lldb::ModuleSP> *old_modules = nullptr);
0181
0182
0183
0184
0185
0186
0187
0188
0189
0190
0191
0192
0193 bool AppendIfNeeded(const lldb::ModuleSP &new_module, bool notify = true);
0194
0195 void Append(const ModuleList &module_list);
0196
0197 bool AppendIfNeeded(const ModuleList &module_list);
0198
0199 bool ReplaceModule(const lldb::ModuleSP &old_module_sp,
0200 const lldb::ModuleSP &new_module_sp);
0201
0202
0203
0204
0205
0206
0207 void Clear();
0208
0209
0210
0211
0212
0213
0214
0215 void Destroy();
0216
0217
0218
0219
0220
0221
0222
0223
0224
0225
0226 void Dump(Stream *s) const;
0227
0228 void LogUUIDAndPaths(Log *log, const char *prefix_cstr);
0229
0230 std::recursive_mutex &GetMutex() const { return m_modules_mutex; }
0231
0232 size_t GetIndexForModule(const Module *module) const;
0233
0234
0235
0236
0237
0238
0239
0240
0241
0242
0243
0244 lldb::ModuleSP GetModuleAtIndex(size_t idx) const;
0245
0246
0247
0248
0249
0250
0251
0252
0253
0254
0255
0256
0257
0258 lldb::ModuleSP GetModuleAtIndexUnlocked(size_t idx) const;
0259
0260
0261
0262
0263
0264
0265
0266
0267
0268
0269
0270 Module *GetModulePointerAtIndex(size_t idx) const;
0271
0272
0273
0274
0275
0276
0277
0278
0279
0280
0281
0282
0283 void FindCompileUnits(const FileSpec &path, SymbolContextList &sc_list) const;
0284
0285
0286 void FindFunctions(ConstString name, lldb::FunctionNameType name_type_mask,
0287 const ModuleFunctionSearchOptions &options,
0288 SymbolContextList &sc_list) const;
0289
0290
0291 void FindFunctionSymbols(ConstString name,
0292 lldb::FunctionNameType name_type_mask,
0293 SymbolContextList &sc_list);
0294
0295
0296 void FindFunctions(const RegularExpression &name,
0297 const ModuleFunctionSearchOptions &options,
0298 SymbolContextList &sc_list);
0299
0300
0301
0302
0303
0304
0305
0306
0307
0308
0309
0310
0311
0312 void FindGlobalVariables(ConstString name, size_t max_matches,
0313 VariableList &variable_list) const;
0314
0315
0316
0317
0318
0319
0320
0321
0322
0323
0324
0325
0326 void FindGlobalVariables(const RegularExpression ®ex, size_t max_matches,
0327 VariableList &variable_list) const;
0328
0329
0330
0331
0332
0333
0334
0335
0336
0337
0338
0339
0340
0341
0342 void FindModules(const ModuleSpec &module_spec,
0343 ModuleList &matching_module_list) const;
0344
0345 lldb::ModuleSP FindModule(const Module *module_ptr) const;
0346
0347
0348
0349
0350
0351
0352 lldb::ModuleSP FindModule(const UUID &uuid) const;
0353
0354 lldb::ModuleSP FindFirstModule(const ModuleSpec &module_spec) const;
0355
0356 void FindSymbolsWithNameAndType(ConstString name,
0357 lldb::SymbolType symbol_type,
0358 SymbolContextList &sc_list) const;
0359
0360 void FindSymbolsMatchingRegExAndType(const RegularExpression ®ex,
0361 lldb::SymbolType symbol_type,
0362 SymbolContextList &sc_list) const;
0363
0364
0365
0366
0367
0368
0369
0370
0371
0372
0373
0374
0375
0376
0377
0378 void FindTypes(Module *search_first, const TypeQuery &query,
0379 lldb_private::TypeResults &results) const;
0380
0381 bool FindSourceFile(const FileSpec &orig_spec, FileSpec &new_spec) const;
0382
0383
0384
0385
0386
0387
0388
0389
0390
0391
0392
0393
0394
0395
0396
0397
0398
0399
0400
0401
0402
0403
0404 void FindAddressesForLine(const lldb::TargetSP target_sp,
0405 const FileSpec &file, uint32_t line,
0406 Function *function,
0407 std::vector<Address> &output_local,
0408 std::vector<Address> &output_extern);
0409
0410
0411
0412
0413
0414
0415
0416
0417
0418
0419
0420
0421
0422
0423
0424 bool Remove(const lldb::ModuleSP &module_sp, bool notify = true);
0425
0426 size_t Remove(ModuleList &module_list);
0427
0428 bool RemoveIfOrphaned(const Module *module_ptr);
0429
0430 size_t RemoveOrphans(bool mandatory);
0431
0432 bool ResolveFileAddress(lldb::addr_t vm_addr, Address &so_addr) const;
0433
0434
0435
0436 uint32_t ResolveSymbolContextForAddress(const Address &so_addr,
0437 lldb::SymbolContextItem resolve_scope,
0438 SymbolContext &sc) const;
0439
0440
0441
0442 uint32_t ResolveSymbolContextForFilePath(
0443 const char *file_path, uint32_t line, bool check_inlines,
0444 lldb::SymbolContextItem resolve_scope, SymbolContextList &sc_list) const;
0445
0446
0447
0448 uint32_t ResolveSymbolContextsForFileSpec(
0449 const FileSpec &file_spec, uint32_t line, bool check_inlines,
0450 lldb::SymbolContextItem resolve_scope, SymbolContextList &sc_list) const;
0451
0452
0453
0454
0455
0456 size_t GetSize() const;
0457 bool IsEmpty() const { return !GetSize(); }
0458
0459 bool LoadScriptingResourcesInTarget(Target *target, std::list<Status> &errors,
0460 Stream &feedback_stream,
0461 bool continue_on_error = true);
0462
0463 static ModuleListProperties &GetGlobalModuleListProperties();
0464
0465 static bool ModuleIsInCache(const Module *module_ptr);
0466
0467 static Status
0468 GetSharedModule(const ModuleSpec &module_spec, lldb::ModuleSP &module_sp,
0469 const FileSpecList *module_search_paths_ptr,
0470 llvm::SmallVectorImpl<lldb::ModuleSP> *old_modules,
0471 bool *did_create_ptr, bool always_create = false);
0472
0473 static bool RemoveSharedModule(lldb::ModuleSP &module_sp);
0474
0475 static void FindSharedModules(const ModuleSpec &module_spec,
0476 ModuleList &matching_module_list);
0477
0478 static lldb::ModuleSP FindSharedModule(const UUID &uuid);
0479
0480 static size_t RemoveOrphanSharedModules(bool mandatory);
0481
0482 static bool RemoveSharedModuleIfOrphaned(const Module *module_ptr);
0483
0484
0485
0486
0487
0488
0489
0490 void ForEach(std::function<bool(const lldb::ModuleSP &module_sp)> const
0491 &callback) const;
0492
0493
0494
0495
0496
0497 bool AnyOf(
0498 std::function<bool(lldb_private::Module &module)> const &callback) const;
0499
0500
0501 void Swap(ModuleList &other);
0502
0503 protected:
0504
0505 typedef std::vector<lldb::ModuleSP>
0506 collection;
0507
0508 void AppendImpl(const lldb::ModuleSP &module_sp, bool use_notifier = true);
0509
0510 bool RemoveImpl(const lldb::ModuleSP &module_sp, bool use_notifier = true);
0511
0512 collection::iterator RemoveImpl(collection::iterator pos,
0513 bool use_notifier = true);
0514
0515 void ClearImpl(bool use_notifier = true);
0516
0517
0518 collection m_modules;
0519 mutable std::recursive_mutex m_modules_mutex;
0520
0521 Notifier *m_notifier = nullptr;
0522
0523 public:
0524 typedef LockingAdaptedIterable<collection, lldb::ModuleSP, vector_adapter,
0525 std::recursive_mutex>
0526 ModuleIterable;
0527 ModuleIterable Modules() const {
0528 return ModuleIterable(m_modules, GetMutex());
0529 }
0530
0531 typedef AdaptedIterable<collection, lldb::ModuleSP, vector_adapter>
0532 ModuleIterableNoLocking;
0533 ModuleIterableNoLocking ModulesNoLocking() const {
0534 return ModuleIterableNoLocking(m_modules);
0535 }
0536 };
0537
0538 }
0539
0540 #endif