ModuleList.h revision 9ce953807eb814a93b449dc243de4f7bf32c3115
1//===-- ModuleList.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//===----------------------------------------------------------------------===// 9 10#ifndef liblldb_ModuleList_h_ 11#define liblldb_ModuleList_h_ 12 13#include <vector> 14 15#include "lldb/lldb-private.h" 16#include "lldb/Host/Mutex.h" 17 18namespace lldb_private { 19 20//---------------------------------------------------------------------- 21/// @class ModuleList ModuleList.h "lldb/Core/ModuleList.h" 22/// @brief A collection class for Module objects. 23/// 24/// Modules in the module collection class are stored as reference 25/// counted shared pointers to Module objects. 26//---------------------------------------------------------------------- 27class ModuleList 28{ 29public: 30 //------------------------------------------------------------------ 31 /// Default constructor. 32 /// 33 /// Creates an empty list of Module objects. 34 //------------------------------------------------------------------ 35 ModuleList (); 36 37 //------------------------------------------------------------------ 38 /// Copy Constructor. 39 /// 40 /// Creates a new module list object with a copy of the modules from 41 /// \a rhs. 42 /// 43 /// @param[in] rhs 44 /// Another module list object. 45 //------------------------------------------------------------------ 46 ModuleList (const ModuleList& rhs); 47 48 //------------------------------------------------------------------ 49 /// Destructor. 50 //------------------------------------------------------------------ 51 ~ModuleList (); 52 53 //------------------------------------------------------------------ 54 /// Assignment operator. 55 /// 56 /// Copies the module list from \a rhs into this list. 57 /// 58 /// @param[in] rhs 59 /// Another module list object. 60 /// 61 /// @return 62 /// A const reference to this object. 63 //------------------------------------------------------------------ 64 const ModuleList& 65 operator= (const ModuleList& rhs); 66 67 //------------------------------------------------------------------ 68 /// Append a module to the module list. 69 /// 70 /// Appends the module to the collection. 71 /// 72 /// @param[in] module_sp 73 /// A shared pointer to a module to add to this collection. 74 //------------------------------------------------------------------ 75 void 76 Append (const lldb::ModuleSP &module_sp); 77 78 bool 79 AppendIfNeeded (const lldb::ModuleSP &module_sp); 80 81 //------------------------------------------------------------------ 82 /// Clear the object's state. 83 /// 84 /// Clears the list of modules and releases a reference to each 85 /// module object and if the reference count goes to zero, the 86 /// module will be deleted. 87 //------------------------------------------------------------------ 88 void 89 Clear (); 90 91 //------------------------------------------------------------------ 92 /// Clear the object's state. 93 /// 94 /// Clears the list of modules and releases a reference to each 95 /// module object and if the reference count goes to zero, the 96 /// module will be deleted. Also relese all memory that might be 97 /// held by any collection classes (like std::vector) 98 //------------------------------------------------------------------ 99 void 100 Destroy(); 101 //------------------------------------------------------------------ 102 /// Dump the description of each module contained in this list. 103 /// 104 /// Dump the description of each module contained in this list to 105 /// the supplied stream \a s. 106 /// 107 /// @param[in] s 108 /// The stream to which to dump the object descripton. 109 /// 110 /// @see Module::Dump(Stream *) const 111 //------------------------------------------------------------------ 112 void 113 Dump (Stream *s) const; 114 115 void 116 LogUUIDAndPaths (lldb::LogSP &log_sp, 117 const char *prefix_cstr); 118 119 uint32_t 120 GetIndexForModule (const Module *module) const; 121 122 //------------------------------------------------------------------ 123 /// Get the module shared pointer for the module at index \a idx. 124 /// 125 /// @param[in] idx 126 /// An index into this module collection. 127 /// 128 /// @return 129 /// A shared pointer to a Module which can contain NULL if 130 /// \a idx is out of range. 131 /// 132 /// @see ModuleList::GetSize() 133 //------------------------------------------------------------------ 134 lldb::ModuleSP 135 GetModuleAtIndex (uint32_t idx); 136 137 //------------------------------------------------------------------ 138 /// Get the module pointer for the module at index \a idx. 139 /// 140 /// @param[in] idx 141 /// An index into this module collection. 142 /// 143 /// @return 144 /// A pointer to a Module which can by NULL if \a idx is out 145 /// of range. 146 /// 147 /// @see ModuleList::GetSize() 148 //------------------------------------------------------------------ 149 Module* 150 GetModulePointerAtIndex (uint32_t idx) const; 151 152 //------------------------------------------------------------------ 153 /// Find compile units by partial or full path. 154 /// 155 /// Finds all compile units that match \a path in all of the modules 156 /// and returns the results in \a sc_list. 157 /// 158 /// @param[in] path 159 /// The name of the compile unit we are looking for. 160 /// 161 /// @param[in] append 162 /// If \b true, then append any compile units that were found 163 /// to \a sc_list. If \b false, then the \a sc_list is cleared 164 /// and the contents of \a sc_list are replaced. 165 /// 166 /// @param[out] sc_list 167 /// A symbol context list that gets filled in with all of the 168 /// matches. 169 /// 170 /// @return 171 /// The number of matches added to \a sc_list. 172 //------------------------------------------------------------------ 173 uint32_t 174 FindCompileUnits (const FileSpec &path, 175 bool append, 176 SymbolContextList &sc_list); 177 178 //------------------------------------------------------------------ 179 /// @see Module::FindFunctions () 180 //------------------------------------------------------------------ 181 uint32_t 182 FindFunctions (const ConstString &name, 183 uint32_t name_type_mask, 184 bool include_symbols, 185 bool include_inlines, 186 bool append, 187 SymbolContextList &sc_list); 188 189 //------------------------------------------------------------------ 190 /// Find global and static variables by name. 191 /// 192 /// @param[in] name 193 /// The name of the global or static variable we are looking 194 /// for. 195 /// 196 /// @param[in] append 197 /// If \b true, any matches will be appended to \a 198 /// variable_list, else matches replace the contents of 199 /// \a variable_list. 200 /// 201 /// @param[in] max_matches 202 /// Allow the number of matches to be limited to \a 203 /// max_matches. Specify UINT32_MAX to get all possible matches. 204 /// 205 /// @param[in] variable_list 206 /// A list of variables that gets the matches appended to (if 207 /// \a append it \b true), or replace (if \a append is \b false). 208 /// 209 /// @return 210 /// The number of matches added to \a variable_list. 211 //------------------------------------------------------------------ 212 uint32_t 213 FindGlobalVariables (const ConstString &name, 214 bool append, 215 uint32_t max_matches, 216 VariableList& variable_list); 217 218 //------------------------------------------------------------------ 219 /// Find global and static variables by regular exression. 220 /// 221 /// @param[in] regex 222 /// A regular expression to use when matching the name. 223 /// 224 /// @param[in] append 225 /// If \b true, any matches will be appended to \a 226 /// variable_list, else matches replace the contents of 227 /// \a variable_list. 228 /// 229 /// @param[in] max_matches 230 /// Allow the number of matches to be limited to \a 231 /// max_matches. Specify UINT32_MAX to get all possible matches. 232 /// 233 /// @param[in] variable_list 234 /// A list of variables that gets the matches appended to (if 235 /// \a append it \b true), or replace (if \a append is \b false). 236 /// 237 /// @return 238 /// The number of matches added to \a variable_list. 239 //------------------------------------------------------------------ 240 uint32_t 241 FindGlobalVariables (const RegularExpression& regex, 242 bool append, 243 uint32_t max_matches, 244 VariableList& variable_list); 245 246 //------------------------------------------------------------------ 247 /// Finds the first module whose file specification matches \a 248 /// file_spec. 249 /// 250 /// @param[in] file_spec_ptr 251 /// A file specification object to match against the Module's 252 /// file specifications. If \a file_spec does not have 253 /// directory information, matches will occur by matching only 254 /// the basename of any modules in this list. If this value is 255 /// NULL, then file specifications won't be compared when 256 /// searching for matching modules. 257 /// 258 /// @param[in] arch_ptr 259 /// The architecture to search for if non-NULL. If this value 260 /// is NULL no architecture matching will be performed. 261 /// 262 /// @param[in] uuid_ptr 263 /// The uuid to search for if non-NULL. If this value is NULL 264 /// no uuid matching will be performed. 265 /// 266 /// @param[in] object_name 267 /// An optional object name that must match as well. This value 268 /// can be NULL. 269 /// 270 /// @param[out] matching_module_list 271 /// A module list that gets filled in with any modules that 272 /// match the search criteria. 273 /// 274 /// @return 275 /// The number of matching modules found by the search. 276 //------------------------------------------------------------------ 277 size_t 278 FindModules (const FileSpec *file_spec_ptr, 279 const ArchSpec *arch_ptr, 280 const lldb_private::UUID *uuid_ptr, 281 const ConstString *object_name, 282 ModuleList& matching_module_list) const; 283 284 lldb::ModuleSP 285 FindModule (const Module *module_ptr); 286 287 //------------------------------------------------------------------ 288 // Find a module by UUID 289 // 290 // The UUID value for a module is extracted from the ObjectFile and 291 // is the MD5 checksum, or a smarter object file equivalent, so 292 // finding modules by UUID values is very efficient and accurate. 293 //------------------------------------------------------------------ 294 lldb::ModuleSP 295 FindModule (const UUID &uuid); 296 297 lldb::ModuleSP 298 FindFirstModuleForFileSpec (const FileSpec &file_spec, 299 const ArchSpec *arch_ptr, 300 const ConstString *object_name); 301 302 lldb::ModuleSP 303 FindFirstModuleForPlatormFileSpec (const FileSpec &platform_file_spec, 304 const ArchSpec *arch_ptr, 305 const ConstString *object_name); 306 307 size_t 308 FindSymbolsWithNameAndType (const ConstString &name, 309 lldb::SymbolType symbol_type, 310 SymbolContextList &sc_list, 311 bool append = false); 312 313 size_t 314 FindSymbolsMatchingRegExAndType (const RegularExpression ®ex, 315 lldb::SymbolType symbol_type, 316 SymbolContextList &sc_list, 317 bool append = false); 318 319 //------------------------------------------------------------------ 320 /// Find types by name. 321 /// 322 /// @param[in] sc 323 /// A symbol context that scopes where to extract a type list 324 /// from. 325 /// 326 /// @param[in] name 327 /// The name of the type we are looking for. 328 /// 329 /// @param[in] append 330 /// If \b true, any matches will be appended to \a 331 /// variable_list, else matches replace the contents of 332 /// \a variable_list. 333 /// 334 /// @param[in] max_matches 335 /// Allow the number of matches to be limited to \a 336 /// max_matches. Specify UINT32_MAX to get all possible matches. 337 /// 338 /// @param[in] encoding 339 /// Limit the search to specific types, or get all types if 340 /// set to Type::invalid. 341 /// 342 /// @param[in] udt_name 343 /// If the encoding is a user defined type, specify the name 344 /// of the user defined type ("struct", "union", "class", etc). 345 /// 346 /// @param[out] type_list 347 /// A type list gets populated with any matches. 348 /// 349 /// @return 350 /// The number of matches added to \a type_list. 351 //------------------------------------------------------------------ 352 uint32_t 353 FindTypes (const SymbolContext& sc, 354 const ConstString &name, 355 bool append, 356 uint32_t max_matches, 357 TypeList& types); 358 359 bool 360 Remove (const lldb::ModuleSP &module_sp); 361 362 size_t 363 Remove (ModuleList &module_list); 364 365 size_t 366 RemoveOrphans (); 367 368 bool 369 ResolveFileAddress (lldb::addr_t vm_addr, 370 Address& so_addr); 371 372 //------------------------------------------------------------------ 373 /// @copydoc Module::ResolveSymbolContextForAddress (const Address &,uint32_t,SymbolContext&) 374 //------------------------------------------------------------------ 375 uint32_t 376 ResolveSymbolContextForAddress (const Address& so_addr, 377 uint32_t resolve_scope, 378 SymbolContext& sc); 379 380 //------------------------------------------------------------------ 381 /// @copydoc Module::ResolveSymbolContextForFilePath (const char *,uint32_t,bool,uint32_t,SymbolContextList&) 382 //------------------------------------------------------------------ 383 uint32_t 384 ResolveSymbolContextForFilePath (const char *file_path, 385 uint32_t line, 386 bool check_inlines, 387 uint32_t resolve_scope, 388 SymbolContextList& sc_list); 389 390 //------------------------------------------------------------------ 391 /// @copydoc Module::ResolveSymbolContextsForFileSpec (const FileSpec &,uint32_t,bool,uint32_t,SymbolContextList&) 392 //------------------------------------------------------------------ 393 uint32_t 394 ResolveSymbolContextsForFileSpec (const FileSpec &file_spec, 395 uint32_t line, 396 bool check_inlines, 397 uint32_t resolve_scope, 398 SymbolContextList& sc_list); 399 400 //------------------------------------------------------------------ 401 /// Gets the size of the module list. 402 /// 403 /// @return 404 /// The number of modules in the module list. 405 //------------------------------------------------------------------ 406 size_t 407 GetSize () const; 408 409 static bool 410 ModuleIsInCache (const Module *module_ptr); 411 412 static Error 413 GetSharedModule (const FileSpec& file_spec, 414 const ArchSpec& arch, 415 const lldb_private::UUID *uuid_ptr, 416 const ConstString *object_name, 417 off_t object_offset, 418 lldb::ModuleSP &module_sp, 419 const FileSpecList *module_search_paths_ptr, 420 lldb::ModuleSP *old_module_sp_ptr, 421 bool *did_create_ptr, 422 bool always_create = false); 423 424 static bool 425 RemoveSharedModule (lldb::ModuleSP &module_sp); 426 427 static size_t 428 FindSharedModules (const FileSpec& in_file_spec, 429 const ArchSpec& arch, 430 const lldb_private::UUID *uuid_ptr, 431 const ConstString *object_name_ptr, 432 ModuleList &matching_module_list); 433 434 static uint32_t 435 RemoveOrphanSharedModules (); 436 437protected: 438 //------------------------------------------------------------------ 439 // Class typedefs. 440 //------------------------------------------------------------------ 441 typedef std::vector<lldb::ModuleSP> collection; ///< The module collection type. 442 443 //------------------------------------------------------------------ 444 // Member variables. 445 //------------------------------------------------------------------ 446 collection m_modules; ///< The collection of modules. 447 mutable Mutex m_modules_mutex; 448 449}; 450 451} // namespace lldb_private 452 453#endif // liblldb_ModuleList_h_ 454