Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- SearchFilter.cpp ----------------------------------------*- 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 | // C Includes |
| 11 | // C++ Includes |
| 12 | // Other libraries and framework includes |
| 13 | // Project includes |
| 14 | |
| 15 | #include "lldb/lldb-private.h" |
| 16 | #include "lldb/Core/SearchFilter.h" |
Greg Clayton | 49ce896 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 17 | #include "lldb/Core/Module.h" |
| 18 | #include "lldb/Symbol/CompileUnit.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 19 | #include "lldb/Target/Target.h" |
| 20 | |
| 21 | using namespace lldb; |
| 22 | using namespace lldb_private; |
| 23 | |
| 24 | //---------------------------------------------------------------------- |
| 25 | // SearchFilter constructor |
| 26 | //---------------------------------------------------------------------- |
| 27 | Searcher::Searcher () |
| 28 | { |
| 29 | |
| 30 | } |
| 31 | |
| 32 | Searcher::~Searcher () |
| 33 | { |
| 34 | |
| 35 | } |
| 36 | |
| 37 | void |
| 38 | Searcher::GetDescription (Stream *s) |
| 39 | { |
| 40 | } |
| 41 | |
| 42 | //---------------------------------------------------------------------- |
| 43 | // SearchFilter constructor |
| 44 | //---------------------------------------------------------------------- |
Greg Clayton | 52c8b6e | 2011-04-19 04:19:37 +0000 | [diff] [blame] | 45 | SearchFilter::SearchFilter(const TargetSP &target_sp) : |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 46 | m_target_sp (target_sp) |
| 47 | { |
| 48 | } |
| 49 | |
| 50 | //---------------------------------------------------------------------- |
| 51 | // SearchFilter copy constructor |
| 52 | //---------------------------------------------------------------------- |
| 53 | SearchFilter::SearchFilter(const SearchFilter& rhs) : |
| 54 | m_target_sp (rhs.m_target_sp) |
| 55 | { |
| 56 | } |
| 57 | |
| 58 | //---------------------------------------------------------------------- |
| 59 | // SearchFilter assignment operator |
| 60 | //---------------------------------------------------------------------- |
| 61 | const SearchFilter& |
| 62 | SearchFilter::operator=(const SearchFilter& rhs) |
| 63 | { |
| 64 | m_target_sp = rhs.m_target_sp; |
| 65 | return *this; |
| 66 | } |
| 67 | |
| 68 | //---------------------------------------------------------------------- |
| 69 | // Destructor |
| 70 | //---------------------------------------------------------------------- |
| 71 | SearchFilter::~SearchFilter() |
| 72 | { |
| 73 | } |
| 74 | |
| 75 | bool |
| 76 | SearchFilter::ModulePasses (const FileSpec &spec) |
| 77 | { |
| 78 | return true; |
| 79 | } |
| 80 | |
| 81 | bool |
| 82 | SearchFilter::ModulePasses (const ModuleSP &module_sp) |
| 83 | { |
| 84 | return true; |
| 85 | } |
| 86 | |
| 87 | bool |
| 88 | SearchFilter::SymbolContextPasses |
| 89 | ( |
| 90 | const SymbolContext &context, |
| 91 | lldb::SymbolContextItem scope |
| 92 | ) |
| 93 | { |
| 94 | return true; |
| 95 | } |
| 96 | |
| 97 | bool |
| 98 | SearchFilter::AddressPasses (Address &address) |
| 99 | { |
| 100 | return true; |
| 101 | } |
| 102 | |
| 103 | bool |
| 104 | SearchFilter::CompUnitPasses (FileSpec &fileSpec) |
| 105 | { |
| 106 | return true; |
| 107 | } |
| 108 | |
| 109 | bool |
| 110 | SearchFilter::CompUnitPasses (CompileUnit &compUnit) |
| 111 | { |
| 112 | return true; |
| 113 | } |
| 114 | |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 115 | uint32_t |
| 116 | SearchFilter::GetFilterRequiredItems() |
| 117 | { |
| 118 | return (lldb::SymbolContextItem) 0; |
| 119 | } |
| 120 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 121 | void |
| 122 | SearchFilter::GetDescription (Stream *s) |
| 123 | { |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | void |
| 127 | SearchFilter::Dump (Stream *s) const |
| 128 | { |
| 129 | |
| 130 | } |
| 131 | |
| 132 | //---------------------------------------------------------------------- |
| 133 | // UTILITY Functions to help iterate down through the elements of the |
| 134 | // SymbolContext. |
| 135 | //---------------------------------------------------------------------- |
| 136 | |
| 137 | void |
| 138 | SearchFilter::Search (Searcher &searcher) |
| 139 | { |
| 140 | SymbolContext empty_sc; |
| 141 | |
Greg Clayton | 987c7eb | 2011-09-17 08:33:22 +0000 | [diff] [blame] | 142 | if (!m_target_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 143 | return; |
| 144 | empty_sc.target_sp = m_target_sp; |
| 145 | |
| 146 | if (searcher.GetDepth() == Searcher::eDepthTarget) |
| 147 | searcher.SearchCallback (*this, empty_sc, NULL, false); |
| 148 | else |
| 149 | DoModuleIteration(empty_sc, searcher); |
| 150 | } |
| 151 | |
| 152 | void |
| 153 | SearchFilter::SearchInModuleList (Searcher &searcher, ModuleList &modules) |
| 154 | { |
| 155 | SymbolContext empty_sc; |
| 156 | |
Greg Clayton | 987c7eb | 2011-09-17 08:33:22 +0000 | [diff] [blame] | 157 | if (!m_target_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 158 | return; |
| 159 | empty_sc.target_sp = m_target_sp; |
| 160 | |
| 161 | if (searcher.GetDepth() == Searcher::eDepthTarget) |
| 162 | searcher.SearchCallback (*this, empty_sc, NULL, false); |
| 163 | else |
| 164 | { |
Jim Ingham | 9336790 | 2012-05-30 02:19:25 +0000 | [diff] [blame] | 165 | Mutex::Locker modules_locker(modules.GetMutex()); |
Greg Clayton | 54e7afa | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 166 | const size_t numModules = modules.GetSize(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 167 | |
Greg Clayton | 54e7afa | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 168 | for (size_t i = 0; i < numModules; i++) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 169 | { |
Jim Ingham | 9336790 | 2012-05-30 02:19:25 +0000 | [diff] [blame] | 170 | ModuleSP module_sp(modules.GetModuleAtIndexUnlocked(i)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 171 | if (ModulePasses(module_sp)) |
| 172 | { |
| 173 | if (DoModuleIteration(module_sp, searcher) == Searcher::eCallbackReturnStop) |
| 174 | return; |
| 175 | } |
| 176 | } |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | |
| 181 | Searcher::CallbackReturn |
| 182 | SearchFilter::DoModuleIteration (const lldb::ModuleSP& module_sp, Searcher &searcher) |
| 183 | { |
| 184 | SymbolContext matchingContext (m_target_sp, module_sp); |
| 185 | return DoModuleIteration(matchingContext, searcher); |
| 186 | } |
| 187 | |
| 188 | Searcher::CallbackReturn |
| 189 | SearchFilter::DoModuleIteration (const SymbolContext &context, Searcher &searcher) |
| 190 | { |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 191 | if (searcher.GetDepth () >= Searcher::eDepthModule) |
| 192 | { |
Greg Clayton | 4a379b1 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 193 | if (context.module_sp) |
| 194 | { |
| 195 | if (searcher.GetDepth () == Searcher::eDepthModule) |
| 196 | { |
| 197 | SymbolContext matchingContext(context.module_sp.get()); |
| 198 | searcher.SearchCallback (*this, matchingContext, NULL, false); |
| 199 | } |
| 200 | else |
| 201 | { |
| 202 | return DoCUIteration(context.module_sp, context, searcher); |
| 203 | } |
| 204 | } |
| 205 | else |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 206 | { |
Enrico Granata | 146d952 | 2012-11-08 02:22:02 +0000 | [diff] [blame] | 207 | const ModuleList &target_images = m_target_sp->GetImages(); |
Jim Ingham | 9336790 | 2012-05-30 02:19:25 +0000 | [diff] [blame] | 208 | Mutex::Locker modules_locker(target_images.GetMutex()); |
| 209 | |
| 210 | size_t n_modules = target_images.GetSize(); |
Greg Clayton | 54e7afa | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 211 | for (size_t i = 0; i < n_modules; i++) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 212 | { |
| 213 | // If this is the last level supplied, then call the callback directly, |
| 214 | // otherwise descend. |
Jim Ingham | 9336790 | 2012-05-30 02:19:25 +0000 | [diff] [blame] | 215 | ModuleSP module_sp(target_images.GetModuleAtIndexUnlocked (i)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 216 | if (!ModulePasses (module_sp)) |
| 217 | continue; |
| 218 | |
| 219 | if (searcher.GetDepth () == Searcher::eDepthModule) |
| 220 | { |
| 221 | SymbolContext matchingContext(m_target_sp, module_sp); |
| 222 | |
Greg Clayton | 4a379b1 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 223 | Searcher::CallbackReturn shouldContinue = searcher.SearchCallback (*this, matchingContext, NULL, false); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 224 | if (shouldContinue == Searcher::eCallbackReturnStop |
| 225 | || shouldContinue == Searcher::eCallbackReturnPop) |
| 226 | return shouldContinue; |
| 227 | } |
| 228 | else |
| 229 | { |
Greg Clayton | 4a379b1 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 230 | Searcher::CallbackReturn shouldContinue = DoCUIteration(module_sp, context, searcher); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 231 | if (shouldContinue == Searcher::eCallbackReturnStop) |
| 232 | return shouldContinue; |
| 233 | else if (shouldContinue == Searcher::eCallbackReturnPop) |
| 234 | continue; |
| 235 | } |
| 236 | } |
| 237 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 238 | } |
| 239 | return Searcher::eCallbackReturnContinue; |
| 240 | } |
| 241 | |
| 242 | Searcher::CallbackReturn |
| 243 | SearchFilter::DoCUIteration (const ModuleSP &module_sp, const SymbolContext &context, Searcher &searcher) |
| 244 | { |
| 245 | Searcher::CallbackReturn shouldContinue; |
| 246 | if (context.comp_unit == NULL) |
| 247 | { |
| 248 | uint32_t num_comp_units = module_sp->GetNumCompileUnits(); |
| 249 | for (uint32_t i = 0; i < num_comp_units; i++) |
| 250 | { |
| 251 | CompUnitSP cu_sp (module_sp->GetCompileUnitAtIndex (i)); |
Greg Clayton | c705730 | 2012-04-23 22:00:21 +0000 | [diff] [blame] | 252 | if (cu_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 253 | { |
Greg Clayton | c705730 | 2012-04-23 22:00:21 +0000 | [diff] [blame] | 254 | if (!CompUnitPasses (*(cu_sp.get()))) |
| 255 | continue; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 256 | |
Greg Clayton | c705730 | 2012-04-23 22:00:21 +0000 | [diff] [blame] | 257 | if (searcher.GetDepth () == Searcher::eDepthCompUnit) |
| 258 | { |
| 259 | SymbolContext matchingContext(m_target_sp, module_sp, cu_sp.get()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 260 | |
Greg Clayton | c705730 | 2012-04-23 22:00:21 +0000 | [diff] [blame] | 261 | shouldContinue = searcher.SearchCallback (*this, matchingContext, NULL, false); |
| 262 | |
| 263 | if (shouldContinue == Searcher::eCallbackReturnPop) |
| 264 | return Searcher::eCallbackReturnContinue; |
| 265 | else if (shouldContinue == Searcher::eCallbackReturnStop) |
| 266 | return shouldContinue; |
| 267 | } |
| 268 | else |
| 269 | { |
| 270 | // FIXME Descend to block. |
| 271 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 272 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 273 | } |
| 274 | } |
| 275 | else |
| 276 | { |
| 277 | if (CompUnitPasses(*context.comp_unit)) |
| 278 | { |
| 279 | SymbolContext matchingContext (m_target_sp, module_sp, context.comp_unit); |
| 280 | return searcher.SearchCallback (*this, matchingContext, NULL, false); |
| 281 | } |
| 282 | } |
| 283 | return Searcher::eCallbackReturnContinue; |
| 284 | } |
| 285 | |
| 286 | Searcher::CallbackReturn |
| 287 | SearchFilter::DoFunctionIteration (Function *function, const SymbolContext &context, Searcher &searcher) |
| 288 | { |
| 289 | // FIXME: Implement... |
| 290 | return Searcher::eCallbackReturnContinue; |
| 291 | } |
| 292 | |
| 293 | //---------------------------------------------------------------------- |
Jim Ingham | 7089d8a | 2011-10-28 23:14:11 +0000 | [diff] [blame] | 294 | // SearchFilterForNonModuleSpecificSearches: |
| 295 | // Selects a shared library matching a given file spec, consulting the targets "black list". |
| 296 | //---------------------------------------------------------------------- |
| 297 | |
| 298 | bool |
| 299 | SearchFilterForNonModuleSpecificSearches::ModulePasses (const FileSpec &module_spec) |
| 300 | { |
| 301 | if (m_target_sp->ModuleIsExcludedForNonModuleSpecificSearches (module_spec)) |
| 302 | return false; |
| 303 | else |
| 304 | return true; |
| 305 | } |
| 306 | |
| 307 | bool |
| 308 | SearchFilterForNonModuleSpecificSearches::ModulePasses (const lldb::ModuleSP &module_sp) |
| 309 | { |
Jim Ingham | 49170d4 | 2012-05-29 23:48:51 +0000 | [diff] [blame] | 310 | if (!module_sp) |
| 311 | return true; |
| 312 | else if (m_target_sp->ModuleIsExcludedForNonModuleSpecificSearches (module_sp)) |
Jim Ingham | 7089d8a | 2011-10-28 23:14:11 +0000 | [diff] [blame] | 313 | return false; |
| 314 | else |
| 315 | return true; |
| 316 | } |
| 317 | |
| 318 | //---------------------------------------------------------------------- |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 319 | // SearchFilterByModule: |
| 320 | // Selects a shared library matching a given file spec |
| 321 | //---------------------------------------------------------------------- |
| 322 | |
| 323 | //---------------------------------------------------------------------- |
| 324 | // SearchFilterByModule constructors |
| 325 | //---------------------------------------------------------------------- |
| 326 | |
Greg Clayton | 13d24fb | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 327 | SearchFilterByModule::SearchFilterByModule (const lldb::TargetSP &target_sp, const FileSpec &module) : |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 328 | SearchFilter (target_sp), |
| 329 | m_module_spec (module) |
| 330 | { |
| 331 | } |
| 332 | |
| 333 | |
| 334 | //---------------------------------------------------------------------- |
| 335 | // SearchFilterByModule copy constructor |
| 336 | //---------------------------------------------------------------------- |
| 337 | SearchFilterByModule::SearchFilterByModule(const SearchFilterByModule& rhs) : |
| 338 | SearchFilter (rhs), |
| 339 | m_module_spec (rhs.m_module_spec) |
| 340 | { |
| 341 | } |
| 342 | |
| 343 | //---------------------------------------------------------------------- |
| 344 | // SearchFilterByModule assignment operator |
| 345 | //---------------------------------------------------------------------- |
| 346 | const SearchFilterByModule& |
| 347 | SearchFilterByModule::operator=(const SearchFilterByModule& rhs) |
| 348 | { |
| 349 | m_target_sp = rhs.m_target_sp; |
| 350 | m_module_spec = rhs.m_module_spec; |
| 351 | return *this; |
| 352 | } |
| 353 | |
| 354 | //---------------------------------------------------------------------- |
| 355 | // Destructor |
| 356 | //---------------------------------------------------------------------- |
| 357 | SearchFilterByModule::~SearchFilterByModule() |
| 358 | { |
| 359 | } |
| 360 | |
| 361 | bool |
| 362 | SearchFilterByModule::ModulePasses (const ModuleSP &module_sp) |
| 363 | { |
Greg Clayton | 801417e | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 364 | if (module_sp && FileSpec::Equal(module_sp->GetFileSpec(), m_module_spec, false)) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 365 | return true; |
| 366 | else |
| 367 | return false; |
| 368 | } |
| 369 | |
| 370 | bool |
| 371 | SearchFilterByModule::ModulePasses (const FileSpec &spec) |
| 372 | { |
Greg Clayton | 49ce896 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 373 | // Do a full match only if "spec" has a directory |
| 374 | const bool full_match = spec.GetDirectory(); |
| 375 | return FileSpec::Equal(spec, m_module_spec, full_match); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | bool |
Greg Clayton | 49ce896 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 379 | SearchFilterByModule::SymbolContextPasses (const SymbolContext &sc, |
| 380 | lldb::SymbolContextItem scope) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 381 | { |
Greg Clayton | 49ce896 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 382 | if (scope & eSymbolContextModule) |
| 383 | { |
| 384 | if (sc.module_sp) |
| 385 | { |
| 386 | // Match the full path only if "m_module_spec" has a directory |
| 387 | const bool full_match = m_module_spec.GetDirectory(); |
| 388 | return FileSpec::Equal (sc.module_sp->GetFileSpec(), m_module_spec, full_match); |
| 389 | } |
| 390 | } |
| 391 | return false; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | bool |
| 395 | SearchFilterByModule::AddressPasses (Address &address) |
| 396 | { |
| 397 | // FIXME: Not yet implemented |
| 398 | return true; |
| 399 | } |
| 400 | |
| 401 | |
| 402 | bool |
| 403 | SearchFilterByModule::CompUnitPasses (FileSpec &fileSpec) |
| 404 | { |
| 405 | return true; |
| 406 | } |
| 407 | |
| 408 | bool |
| 409 | SearchFilterByModule::CompUnitPasses (CompileUnit &compUnit) |
| 410 | { |
| 411 | return true; |
| 412 | } |
| 413 | |
| 414 | void |
| 415 | SearchFilterByModule::Search (Searcher &searcher) |
| 416 | { |
| 417 | if (!m_target_sp) |
| 418 | return; |
| 419 | |
| 420 | if (searcher.GetDepth() == Searcher::eDepthTarget) |
| 421 | { |
| 422 | SymbolContext empty_sc; |
| 423 | empty_sc.target_sp = m_target_sp; |
| 424 | searcher.SearchCallback (*this, empty_sc, NULL, false); |
| 425 | } |
| 426 | |
| 427 | // If the module file spec is a full path, then we can just find the one |
| 428 | // filespec that passes. Otherwise, we need to go through all modules and |
| 429 | // find the ones that match the file name. |
| 430 | |
Enrico Granata | 146d952 | 2012-11-08 02:22:02 +0000 | [diff] [blame] | 431 | const ModuleList &target_modules = m_target_sp->GetImages(); |
Jim Ingham | 9336790 | 2012-05-30 02:19:25 +0000 | [diff] [blame] | 432 | Mutex::Locker modules_locker (target_modules.GetMutex()); |
| 433 | |
| 434 | const size_t num_modules = target_modules.GetSize (); |
Greg Clayton | 54e7afa | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 435 | for (size_t i = 0; i < num_modules; i++) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 436 | { |
Jim Ingham | 9336790 | 2012-05-30 02:19:25 +0000 | [diff] [blame] | 437 | Module* module = target_modules.GetModulePointerAtIndexUnlocked(i); |
Greg Clayton | 49ce896 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 438 | const bool full_match = m_module_spec.GetDirectory(); |
| 439 | if (FileSpec::Equal (m_module_spec, module->GetFileSpec(), full_match)) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 440 | { |
Greg Clayton | 13d24fb | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 441 | SymbolContext matchingContext(m_target_sp, module->shared_from_this()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 442 | Searcher::CallbackReturn shouldContinue; |
| 443 | |
| 444 | shouldContinue = DoModuleIteration(matchingContext, searcher); |
| 445 | if (shouldContinue == Searcher::eCallbackReturnStop) |
| 446 | return; |
| 447 | } |
| 448 | } |
| 449 | } |
| 450 | |
| 451 | void |
| 452 | SearchFilterByModule::GetDescription (Stream *s) |
| 453 | { |
Greg Clayton | 12bec71 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 454 | s->PutCString(", module = "); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 455 | if (s->GetVerbose()) |
| 456 | { |
| 457 | char buffer[2048]; |
| 458 | m_module_spec.GetPath(buffer, 2047); |
| 459 | s->PutCString(buffer); |
| 460 | } |
| 461 | else |
| 462 | { |
| 463 | s->PutCString(m_module_spec.GetFilename().AsCString("<unknown>")); |
| 464 | } |
| 465 | } |
| 466 | |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 467 | uint32_t |
| 468 | SearchFilterByModule::GetFilterRequiredItems() |
| 469 | { |
| 470 | return eSymbolContextModule; |
| 471 | } |
| 472 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 473 | void |
| 474 | SearchFilterByModule::Dump (Stream *s) const |
| 475 | { |
| 476 | |
| 477 | } |
Jim Ingham | 03c8ee5 | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 478 | //---------------------------------------------------------------------- |
| 479 | // SearchFilterByModuleList: |
| 480 | // Selects a shared library matching a given file spec |
| 481 | //---------------------------------------------------------------------- |
| 482 | |
| 483 | //---------------------------------------------------------------------- |
| 484 | // SearchFilterByModuleList constructors |
| 485 | //---------------------------------------------------------------------- |
| 486 | |
Greg Clayton | 13d24fb | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 487 | SearchFilterByModuleList::SearchFilterByModuleList (const lldb::TargetSP &target_sp, const FileSpecList &module_list) : |
Jim Ingham | 03c8ee5 | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 488 | SearchFilter (target_sp), |
| 489 | m_module_spec_list (module_list) |
| 490 | { |
| 491 | } |
| 492 | |
| 493 | |
| 494 | //---------------------------------------------------------------------- |
| 495 | // SearchFilterByModuleList copy constructor |
| 496 | //---------------------------------------------------------------------- |
| 497 | SearchFilterByModuleList::SearchFilterByModuleList(const SearchFilterByModuleList& rhs) : |
| 498 | SearchFilter (rhs), |
| 499 | m_module_spec_list (rhs.m_module_spec_list) |
| 500 | { |
| 501 | } |
| 502 | |
| 503 | //---------------------------------------------------------------------- |
| 504 | // SearchFilterByModuleList assignment operator |
| 505 | //---------------------------------------------------------------------- |
| 506 | const SearchFilterByModuleList& |
| 507 | SearchFilterByModuleList::operator=(const SearchFilterByModuleList& rhs) |
| 508 | { |
| 509 | m_target_sp = rhs.m_target_sp; |
| 510 | m_module_spec_list = rhs.m_module_spec_list; |
| 511 | return *this; |
| 512 | } |
| 513 | |
| 514 | //---------------------------------------------------------------------- |
| 515 | // Destructor |
| 516 | //---------------------------------------------------------------------- |
| 517 | SearchFilterByModuleList::~SearchFilterByModuleList() |
| 518 | { |
| 519 | } |
| 520 | |
| 521 | bool |
| 522 | SearchFilterByModuleList::ModulePasses (const ModuleSP &module_sp) |
| 523 | { |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 524 | if (m_module_spec_list.GetSize() == 0) |
| 525 | return true; |
| 526 | |
| 527 | if (module_sp && m_module_spec_list.FindFileIndex(0, module_sp->GetFileSpec(), false) != UINT32_MAX) |
Jim Ingham | 03c8ee5 | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 528 | return true; |
| 529 | else |
| 530 | return false; |
| 531 | } |
| 532 | |
| 533 | bool |
| 534 | SearchFilterByModuleList::ModulePasses (const FileSpec &spec) |
| 535 | { |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 536 | if (m_module_spec_list.GetSize() == 0) |
| 537 | return true; |
| 538 | |
| 539 | if (m_module_spec_list.FindFileIndex(0, spec, true) != UINT32_MAX) |
Jim Ingham | 03c8ee5 | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 540 | return true; |
| 541 | else |
| 542 | return false; |
| 543 | } |
| 544 | |
| 545 | bool |
| 546 | SearchFilterByModuleList::SymbolContextPasses |
| 547 | ( |
| 548 | const SymbolContext &context, |
| 549 | lldb::SymbolContextItem scope |
| 550 | ) |
| 551 | { |
| 552 | if (!(scope & eSymbolContextModule)) |
| 553 | return false; |
| 554 | |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 555 | if (context.module_sp && m_module_spec_list.FindFileIndex(0, context.module_sp->GetFileSpec(), true) != UINT32_MAX) |
Jim Ingham | 03c8ee5 | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 556 | return true; |
| 557 | else |
| 558 | return false; |
| 559 | } |
| 560 | |
| 561 | bool |
| 562 | SearchFilterByModuleList::AddressPasses (Address &address) |
| 563 | { |
| 564 | // FIXME: Not yet implemented |
| 565 | return true; |
| 566 | } |
| 567 | |
| 568 | |
| 569 | bool |
| 570 | SearchFilterByModuleList::CompUnitPasses (FileSpec &fileSpec) |
| 571 | { |
| 572 | return true; |
| 573 | } |
| 574 | |
| 575 | bool |
| 576 | SearchFilterByModuleList::CompUnitPasses (CompileUnit &compUnit) |
| 577 | { |
| 578 | return true; |
| 579 | } |
| 580 | |
| 581 | void |
| 582 | SearchFilterByModuleList::Search (Searcher &searcher) |
| 583 | { |
| 584 | if (!m_target_sp) |
| 585 | return; |
| 586 | |
| 587 | if (searcher.GetDepth() == Searcher::eDepthTarget) |
| 588 | { |
| 589 | SymbolContext empty_sc; |
| 590 | empty_sc.target_sp = m_target_sp; |
| 591 | searcher.SearchCallback (*this, empty_sc, NULL, false); |
| 592 | } |
| 593 | |
| 594 | // If the module file spec is a full path, then we can just find the one |
| 595 | // filespec that passes. Otherwise, we need to go through all modules and |
| 596 | // find the ones that match the file name. |
| 597 | |
Enrico Granata | 146d952 | 2012-11-08 02:22:02 +0000 | [diff] [blame] | 598 | const ModuleList &target_modules = m_target_sp->GetImages(); |
Jim Ingham | 9336790 | 2012-05-30 02:19:25 +0000 | [diff] [blame] | 599 | Mutex::Locker modules_locker (target_modules.GetMutex()); |
| 600 | |
| 601 | const size_t num_modules = target_modules.GetSize (); |
Jim Ingham | 03c8ee5 | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 602 | for (size_t i = 0; i < num_modules; i++) |
| 603 | { |
Jim Ingham | 9336790 | 2012-05-30 02:19:25 +0000 | [diff] [blame] | 604 | Module* module = target_modules.GetModulePointerAtIndexUnlocked(i); |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 605 | if (m_module_spec_list.FindFileIndex(0, module->GetFileSpec(), false) != UINT32_MAX) |
Jim Ingham | 03c8ee5 | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 606 | { |
Greg Clayton | 13d24fb | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 607 | SymbolContext matchingContext(m_target_sp, module->shared_from_this()); |
Jim Ingham | 03c8ee5 | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 608 | Searcher::CallbackReturn shouldContinue; |
| 609 | |
| 610 | shouldContinue = DoModuleIteration(matchingContext, searcher); |
| 611 | if (shouldContinue == Searcher::eCallbackReturnStop) |
| 612 | return; |
| 613 | } |
| 614 | } |
| 615 | } |
| 616 | |
| 617 | void |
| 618 | SearchFilterByModuleList::GetDescription (Stream *s) |
| 619 | { |
| 620 | uint32_t num_modules = m_module_spec_list.GetSize(); |
| 621 | if (num_modules == 1) |
| 622 | { |
Jason Molenda | 16ccbfd | 2011-09-22 02:24:49 +0000 | [diff] [blame] | 623 | s->Printf (", module = "); |
Jim Ingham | 03c8ee5 | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 624 | if (s->GetVerbose()) |
| 625 | { |
| 626 | char buffer[2048]; |
| 627 | m_module_spec_list.GetFileSpecAtIndex(0).GetPath(buffer, 2047); |
| 628 | s->PutCString(buffer); |
| 629 | } |
| 630 | else |
| 631 | { |
| 632 | s->PutCString(m_module_spec_list.GetFileSpecAtIndex(0).GetFilename().AsCString("<unknown>")); |
| 633 | } |
| 634 | } |
| 635 | else |
| 636 | { |
Greg Clayton | 567e7f3 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 637 | s->Printf (", modules(%u) = ", num_modules); |
Jim Ingham | 03c8ee5 | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 638 | for (uint32_t i = 0; i < num_modules; i++) |
| 639 | { |
| 640 | if (s->GetVerbose()) |
| 641 | { |
| 642 | char buffer[2048]; |
| 643 | m_module_spec_list.GetFileSpecAtIndex(i).GetPath(buffer, 2047); |
| 644 | s->PutCString(buffer); |
| 645 | } |
| 646 | else |
| 647 | { |
| 648 | s->PutCString(m_module_spec_list.GetFileSpecAtIndex(i).GetFilename().AsCString("<unknown>")); |
| 649 | } |
| 650 | if (i != num_modules - 1) |
| 651 | s->PutCString (", "); |
| 652 | } |
| 653 | } |
| 654 | } |
| 655 | |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 656 | uint32_t |
| 657 | SearchFilterByModuleList::GetFilterRequiredItems() |
| 658 | { |
| 659 | return eSymbolContextModule; |
| 660 | } |
| 661 | |
Jim Ingham | 03c8ee5 | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 662 | void |
| 663 | SearchFilterByModuleList::Dump (Stream *s) const |
| 664 | { |
| 665 | |
| 666 | } |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 667 | |
| 668 | //---------------------------------------------------------------------- |
| 669 | // SearchFilterByModuleListAndCU: |
| 670 | // Selects a shared library matching a given file spec |
| 671 | //---------------------------------------------------------------------- |
| 672 | |
| 673 | //---------------------------------------------------------------------- |
| 674 | // SearchFilterByModuleListAndCU constructors |
| 675 | //---------------------------------------------------------------------- |
| 676 | |
Greg Clayton | 13d24fb | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 677 | SearchFilterByModuleListAndCU::SearchFilterByModuleListAndCU (const lldb::TargetSP &target_sp, |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 678 | const FileSpecList &module_list, |
| 679 | const FileSpecList &cu_list) : |
| 680 | SearchFilterByModuleList (target_sp, module_list), |
| 681 | m_cu_spec_list (cu_list) |
| 682 | { |
| 683 | } |
| 684 | |
| 685 | |
| 686 | //---------------------------------------------------------------------- |
| 687 | // SearchFilterByModuleListAndCU copy constructor |
| 688 | //---------------------------------------------------------------------- |
| 689 | SearchFilterByModuleListAndCU::SearchFilterByModuleListAndCU(const SearchFilterByModuleListAndCU& rhs) : |
| 690 | SearchFilterByModuleList (rhs), |
| 691 | m_cu_spec_list (rhs.m_cu_spec_list) |
| 692 | { |
| 693 | } |
| 694 | |
| 695 | //---------------------------------------------------------------------- |
| 696 | // SearchFilterByModuleListAndCU assignment operator |
| 697 | //---------------------------------------------------------------------- |
| 698 | const SearchFilterByModuleListAndCU& |
| 699 | SearchFilterByModuleListAndCU::operator=(const SearchFilterByModuleListAndCU& rhs) |
| 700 | { |
| 701 | if (&rhs != this) |
| 702 | { |
| 703 | m_target_sp = rhs.m_target_sp; |
| 704 | m_module_spec_list = rhs.m_module_spec_list; |
| 705 | m_cu_spec_list = rhs.m_cu_spec_list; |
| 706 | } |
| 707 | return *this; |
| 708 | } |
| 709 | |
| 710 | //---------------------------------------------------------------------- |
| 711 | // Destructor |
| 712 | //---------------------------------------------------------------------- |
| 713 | SearchFilterByModuleListAndCU::~SearchFilterByModuleListAndCU() |
| 714 | { |
| 715 | } |
| 716 | |
| 717 | bool |
| 718 | SearchFilterByModuleListAndCU::SymbolContextPasses |
| 719 | ( |
| 720 | const SymbolContext &context, |
| 721 | lldb::SymbolContextItem scope |
| 722 | ) |
| 723 | { |
| 724 | if (!SearchFilterByModuleList::SymbolContextPasses(context, scope)) |
| 725 | return false; |
| 726 | if (!(scope & eSymbolContextCompUnit)) |
| 727 | return false; |
Greg Clayton | 49ce896 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 728 | if (context.comp_unit && m_cu_spec_list.FindFileIndex(0, context.comp_unit, false) == UINT32_MAX) |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 729 | return false; |
| 730 | return true; |
| 731 | } |
| 732 | |
| 733 | bool |
| 734 | SearchFilterByModuleListAndCU::AddressPasses (Address &address) |
| 735 | { |
| 736 | // FIXME: Not yet implemented |
| 737 | return true; |
| 738 | } |
| 739 | |
| 740 | |
| 741 | bool |
| 742 | SearchFilterByModuleListAndCU::CompUnitPasses (FileSpec &fileSpec) |
| 743 | { |
| 744 | return m_cu_spec_list.FindFileIndex(0, fileSpec, false) != UINT32_MAX; |
| 745 | } |
| 746 | |
| 747 | bool |
| 748 | SearchFilterByModuleListAndCU::CompUnitPasses (CompileUnit &compUnit) |
| 749 | { |
Greg Clayton | 49ce896 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 750 | return m_cu_spec_list.FindFileIndex(0, compUnit, false) != UINT32_MAX; |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 751 | } |
| 752 | |
| 753 | void |
| 754 | SearchFilterByModuleListAndCU::Search (Searcher &searcher) |
| 755 | { |
| 756 | if (!m_target_sp) |
| 757 | return; |
| 758 | |
| 759 | if (searcher.GetDepth() == Searcher::eDepthTarget) |
| 760 | { |
| 761 | SymbolContext empty_sc; |
| 762 | empty_sc.target_sp = m_target_sp; |
| 763 | searcher.SearchCallback (*this, empty_sc, NULL, false); |
| 764 | } |
| 765 | |
| 766 | // If the module file spec is a full path, then we can just find the one |
| 767 | // filespec that passes. Otherwise, we need to go through all modules and |
| 768 | // find the ones that match the file name. |
| 769 | |
| 770 | ModuleList matching_modules; |
Enrico Granata | 146d952 | 2012-11-08 02:22:02 +0000 | [diff] [blame] | 771 | const ModuleList &target_images = m_target_sp->GetImages(); |
Jim Ingham | 9336790 | 2012-05-30 02:19:25 +0000 | [diff] [blame] | 772 | Mutex::Locker modules_locker(target_images.GetMutex()); |
| 773 | |
| 774 | const size_t num_modules = target_images.GetSize (); |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 775 | bool no_modules_in_filter = m_module_spec_list.GetSize() == 0; |
| 776 | for (size_t i = 0; i < num_modules; i++) |
| 777 | { |
Jim Ingham | 9336790 | 2012-05-30 02:19:25 +0000 | [diff] [blame] | 778 | lldb::ModuleSP module_sp = target_images.GetModuleAtIndexUnlocked(i); |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 779 | if (no_modules_in_filter || m_module_spec_list.FindFileIndex(0, module_sp->GetFileSpec(), false) != UINT32_MAX) |
| 780 | { |
| 781 | SymbolContext matchingContext(m_target_sp, module_sp); |
| 782 | Searcher::CallbackReturn shouldContinue; |
| 783 | |
| 784 | if (searcher.GetDepth() == Searcher::eDepthModule) |
| 785 | { |
| 786 | shouldContinue = DoModuleIteration(matchingContext, searcher); |
| 787 | if (shouldContinue == Searcher::eCallbackReturnStop) |
| 788 | return; |
| 789 | } |
| 790 | else |
| 791 | { |
| 792 | const size_t num_cu = module_sp->GetNumCompileUnits(); |
| 793 | for (size_t cu_idx = 0; cu_idx < num_cu; cu_idx++) |
| 794 | { |
| 795 | CompUnitSP cu_sp = module_sp->GetCompileUnitAtIndex(cu_idx); |
| 796 | matchingContext.comp_unit = cu_sp.get(); |
Greg Clayton | c705730 | 2012-04-23 22:00:21 +0000 | [diff] [blame] | 797 | if (matchingContext.comp_unit) |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 798 | { |
Greg Clayton | c705730 | 2012-04-23 22:00:21 +0000 | [diff] [blame] | 799 | if (m_cu_spec_list.FindFileIndex(0, *matchingContext.comp_unit, false) != UINT32_MAX) |
| 800 | { |
| 801 | shouldContinue = DoCUIteration(module_sp, matchingContext, searcher); |
| 802 | if (shouldContinue == Searcher::eCallbackReturnStop) |
| 803 | return; |
| 804 | } |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 805 | } |
| 806 | } |
| 807 | } |
| 808 | } |
| 809 | } |
| 810 | } |
| 811 | |
| 812 | void |
| 813 | SearchFilterByModuleListAndCU::GetDescription (Stream *s) |
| 814 | { |
| 815 | uint32_t num_modules = m_module_spec_list.GetSize(); |
| 816 | if (num_modules == 1) |
| 817 | { |
| 818 | s->Printf (", module = "); |
| 819 | if (s->GetVerbose()) |
| 820 | { |
| 821 | char buffer[2048]; |
| 822 | m_module_spec_list.GetFileSpecAtIndex(0).GetPath(buffer, 2047); |
| 823 | s->PutCString(buffer); |
| 824 | } |
| 825 | else |
| 826 | { |
| 827 | s->PutCString(m_module_spec_list.GetFileSpecAtIndex(0).GetFilename().AsCString("<unknown>")); |
| 828 | } |
| 829 | } |
| 830 | else if (num_modules > 0) |
| 831 | { |
| 832 | s->Printf (", modules(%d) = ", num_modules); |
| 833 | for (uint32_t i = 0; i < num_modules; i++) |
| 834 | { |
| 835 | if (s->GetVerbose()) |
| 836 | { |
| 837 | char buffer[2048]; |
| 838 | m_module_spec_list.GetFileSpecAtIndex(i).GetPath(buffer, 2047); |
| 839 | s->PutCString(buffer); |
| 840 | } |
| 841 | else |
| 842 | { |
| 843 | s->PutCString(m_module_spec_list.GetFileSpecAtIndex(i).GetFilename().AsCString("<unknown>")); |
| 844 | } |
| 845 | if (i != num_modules - 1) |
| 846 | s->PutCString (", "); |
| 847 | } |
| 848 | } |
| 849 | } |
| 850 | |
| 851 | uint32_t |
| 852 | SearchFilterByModuleListAndCU::GetFilterRequiredItems() |
| 853 | { |
| 854 | return eSymbolContextModule | eSymbolContextCompUnit; |
| 855 | } |
| 856 | |
| 857 | void |
| 858 | SearchFilterByModuleListAndCU::Dump (Stream *s) const |
| 859 | { |
| 860 | |
| 861 | } |
| 862 | |