ModuleList.h revision 08205a649cf8a94477f7f9ab8e42dd95ebfc9626
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 append, 186 SymbolContextList &sc_list); 187 188 //------------------------------------------------------------------ 189 /// Find global and static variables by name. 190 /// 191 /// @param[in] name 192 /// The name of the global or static variable we are looking 193 /// for. 194 /// 195 /// @param[in] append 196 /// If \b true, any matches will be appended to \a 197 /// variable_list, else matches replace the contents of 198 /// \a variable_list. 199 /// 200 /// @param[in] max_matches 201 /// Allow the number of matches to be limited to \a 202 /// max_matches. Specify UINT32_MAX to get all possible matches. 203 /// 204 /// @param[in] variable_list 205 /// A list of variables that gets the matches appended to (if 206 /// \a append it \b true), or replace (if \a append is \b false). 207 /// 208 /// @return 209 /// The number of matches added to \a variable_list. 210 //------------------------------------------------------------------ 211 uint32_t 212 FindGlobalVariables (const ConstString &name, 213 bool append, 214 uint32_t max_matches, 215 VariableList& variable_list); 216 217 //------------------------------------------------------------------ 218 /// Find global and static variables by regular exression. 219 /// 220 /// @param[in] regex 221 /// A regular expression to use when matching the name. 222 /// 223 /// @param[in] append 224 /// If \b true, any matches will be appended to \a 225 /// variable_list, else matches replace the contents of 226 /// \a variable_list. 227 /// 228 /// @param[in] max_matches 229 /// Allow the number of matches to be limited to \a 230 /// max_matches. Specify UINT32_MAX to get all possible matches. 231 /// 232 /// @param[in] variable_list 233 /// A list of variables that gets the matches appended to (if 234 /// \a append it \b true), or replace (if \a append is \b false). 235 /// 236 /// @return 237 /// The number of matches added to \a variable_list. 238 //------------------------------------------------------------------ 239 uint32_t 240 FindGlobalVariables (const RegularExpression& regex, 241 bool append, 242 uint32_t max_matches, 243 VariableList& variable_list); 244 245 //------------------------------------------------------------------ 246 /// Finds the first module whose file specification matches \a 247 /// file_spec. 248 /// 249 /// @param[in] file_spec_ptr 250 /// A file specification object to match against the Module's 251 /// file specifications. If \a file_spec does not have 252 /// directory information, matches will occur by matching only 253 /// the basename of any modules in this list. If this value is 254 /// NULL, then file specifications won't be compared when 255 /// searching for matching modules. 256 /// 257 /// @param[in] arch_ptr 258 /// The architecture to search for if non-NULL. If this value 259 /// is NULL no architecture matching will be performed. 260 /// 261 /// @param[in] uuid_ptr 262 /// The uuid to search for if non-NULL. If this value is NULL 263 /// no uuid matching will be performed. 264 /// 265 /// @param[in] object_name 266 /// An optional object name that must match as well. This value 267 /// can be NULL. 268 /// 269 /// @param[out] matching_module_list 270 /// A module list that gets filled in with any modules that 271 /// match the search criteria. 272 /// 273 /// @return 274 /// The number of matching modules found by the search. 275 //------------------------------------------------------------------ 276 size_t 277 FindModules (const FileSpec *file_spec_ptr, 278 const ArchSpec *arch_ptr, 279 const lldb_private::UUID *uuid_ptr, 280 const ConstString *object_name, 281 ModuleList& matching_module_list) const; 282 283 lldb::ModuleSP 284 FindModule (const Module *module_ptr); 285 286 //------------------------------------------------------------------ 287 // Find a module by UUID 288 // 289 // The UUID value for a module is extracted from the ObjectFile and 290 // is the MD5 checksum, or a smarter object file equivalent, so 291 // finding modules by UUID values is very efficient and accurate. 292 //------------------------------------------------------------------ 293 lldb::ModuleSP 294 FindModule (const UUID &uuid); 295 296 lldb::ModuleSP 297 FindFirstModuleForFileSpec (const FileSpec &file_spec, 298 const ArchSpec *arch_ptr, 299 const ConstString *object_name); 300 301 lldb::ModuleSP 302 FindFirstModuleForPlatormFileSpec (const FileSpec &platform_file_spec, 303 const ArchSpec *arch_ptr, 304 const ConstString *object_name); 305 306 size_t 307 FindSymbolsWithNameAndType (const ConstString &name, 308 lldb::SymbolType symbol_type, 309 SymbolContextList &sc_list, 310 bool append = false); 311 312 size_t 313 FindSymbolsMatchingRegExAndType (const RegularExpression ®ex, 314 lldb::SymbolType symbol_type, 315 SymbolContextList &sc_list, 316 bool append = false); 317 318 //------------------------------------------------------------------ 319 /// Find types by name. 320 /// 321 /// @param[in] sc 322 /// A symbol context that scopes where to extract a type list 323 /// from. 324 /// 325 /// @param[in] name 326 /// The name of the type we are looking for. 327 /// 328 /// @param[in] append 329 /// If \b true, any matches will be appended to \a 330 /// variable_list, else matches replace the contents of 331 /// \a variable_list. 332 /// 333 /// @param[in] max_matches 334 /// Allow the number of matches to be limited to \a 335 /// max_matches. Specify UINT32_MAX to get all possible matches. 336 /// 337 /// @param[in] encoding 338 /// Limit the search to specific types, or get all types if 339 /// set to Type::invalid. 340 /// 341 /// @param[in] udt_name 342 /// If the encoding is a user defined type, specify the name 343 /// of the user defined type ("struct", "union", "class", etc). 344 /// 345 /// @param[out] type_list 346 /// A type list gets populated with any matches. 347 /// 348 /// @return 349 /// The number of matches added to \a type_list. 350 //------------------------------------------------------------------ 351 uint32_t 352 FindTypes (const SymbolContext& sc, 353 const ConstString &name, 354 bool append, 355 uint32_t max_matches, 356 TypeList& types); 357 358 bool 359 Remove (const lldb::ModuleSP &module_sp); 360 361 size_t 362 Remove (ModuleList &module_list); 363 364 size_t 365 RemoveOrphans (); 366 367 bool 368 ResolveFileAddress (lldb::addr_t vm_addr, 369 Address& so_addr); 370 371 //------------------------------------------------------------------ 372 /// @copydoc Module::ResolveSymbolContextForAddress (const Address &,uint32_t,SymbolContext&) 373 //------------------------------------------------------------------ 374 uint32_t 375 ResolveSymbolContextForAddress (const Address& so_addr, 376 uint32_t resolve_scope, 377 SymbolContext& sc); 378 379 //------------------------------------------------------------------ 380 /// @copydoc Module::ResolveSymbolContextForFilePath (const char *,uint32_t,bool,uint32_t,SymbolContextList&) 381 //------------------------------------------------------------------ 382 uint32_t 383 ResolveSymbolContextForFilePath (const char *file_path, 384 uint32_t line, 385 bool check_inlines, 386 uint32_t resolve_scope, 387 SymbolContextList& sc_list); 388 389 //------------------------------------------------------------------ 390 /// @copydoc Module::ResolveSymbolContextsForFileSpec (const FileSpec &,uint32_t,bool,uint32_t,SymbolContextList&) 391 //------------------------------------------------------------------ 392 uint32_t 393 ResolveSymbolContextsForFileSpec (const FileSpec &file_spec, 394 uint32_t line, 395 bool check_inlines, 396 uint32_t resolve_scope, 397 SymbolContextList& sc_list); 398 399 //------------------------------------------------------------------ 400 /// Gets the size of the module list. 401 /// 402 /// @return 403 /// The number of modules in the module list. 404 //------------------------------------------------------------------ 405 size_t 406 GetSize () const; 407 408 static bool 409 ModuleIsInCache (const Module *module_ptr); 410 411 static Error 412 GetSharedModule (const FileSpec& file_spec, 413 const ArchSpec& arch, 414 const lldb_private::UUID *uuid_ptr, 415 const ConstString *object_name, 416 off_t object_offset, 417 lldb::ModuleSP &module_sp, 418 lldb::ModuleSP *old_module_sp_ptr, 419 bool *did_create_ptr, 420 bool always_create = false); 421 422 static bool 423 RemoveSharedModule (lldb::ModuleSP &module_sp); 424 425 static size_t 426 FindSharedModules (const FileSpec& in_file_spec, 427 const ArchSpec& arch, 428 const lldb_private::UUID *uuid_ptr, 429 const ConstString *object_name_ptr, 430 ModuleList &matching_module_list); 431 432 static uint32_t 433 RemoveOrphanSharedModules (); 434 435protected: 436 //------------------------------------------------------------------ 437 // Class typedefs. 438 //------------------------------------------------------------------ 439 typedef std::vector<lldb::ModuleSP> collection; ///< The module collection type. 440 441 //------------------------------------------------------------------ 442 // Member variables. 443 //------------------------------------------------------------------ 444 collection m_modules; ///< The collection of modules. 445 mutable Mutex m_modules_mutex; 446 447}; 448 449} // namespace lldb_private 450 451#endif // liblldb_ModuleList_h_ 452