1254721Semaste//===-- SearchFilter.cpp ----------------------------------------*- C++ -*-===//
2254721Semaste//
3254721Semaste//                     The LLVM Compiler Infrastructure
4254721Semaste//
5254721Semaste// This file is distributed under the University of Illinois Open Source
6254721Semaste// License. See LICENSE.TXT for details.
7254721Semaste//
8254721Semaste//===----------------------------------------------------------------------===//
9254721Semaste
10254721Semaste// C Includes
11254721Semaste// C++ Includes
12254721Semaste// Other libraries and framework includes
13254721Semaste// Project includes
14254721Semaste
15254721Semaste#include "lldb/lldb-private.h"
16254721Semaste#include "lldb/Core/SearchFilter.h"
17254721Semaste#include "lldb/Core/Module.h"
18254721Semaste#include "lldb/Symbol/CompileUnit.h"
19254721Semaste#include "lldb/Target/Target.h"
20254721Semaste
21254721Semasteusing namespace lldb;
22254721Semasteusing namespace lldb_private;
23254721Semaste
24254721Semaste//----------------------------------------------------------------------
25254721Semaste// SearchFilter constructor
26254721Semaste//----------------------------------------------------------------------
27254721SemasteSearcher::Searcher ()
28254721Semaste{
29254721Semaste
30254721Semaste}
31254721Semaste
32254721SemasteSearcher::~Searcher ()
33254721Semaste{
34254721Semaste
35254721Semaste}
36254721Semaste
37254721Semastevoid
38254721SemasteSearcher::GetDescription (Stream *s)
39254721Semaste{
40254721Semaste}
41254721Semaste
42254721Semaste//----------------------------------------------------------------------
43254721Semaste// SearchFilter constructor
44254721Semaste//----------------------------------------------------------------------
45254721SemasteSearchFilter::SearchFilter(const TargetSP &target_sp) :
46254721Semaste    m_target_sp (target_sp)
47254721Semaste{
48254721Semaste}
49254721Semaste
50254721Semaste//----------------------------------------------------------------------
51254721Semaste// SearchFilter copy constructor
52254721Semaste//----------------------------------------------------------------------
53254721SemasteSearchFilter::SearchFilter(const SearchFilter& rhs) :
54254721Semaste    m_target_sp (rhs.m_target_sp)
55254721Semaste{
56254721Semaste}
57254721Semaste
58254721Semaste//----------------------------------------------------------------------
59254721Semaste// SearchFilter assignment operator
60254721Semaste//----------------------------------------------------------------------
61254721Semasteconst SearchFilter&
62254721SemasteSearchFilter::operator=(const SearchFilter& rhs)
63254721Semaste{
64254721Semaste    m_target_sp = rhs.m_target_sp;
65254721Semaste    return *this;
66254721Semaste}
67254721Semaste
68254721Semaste//----------------------------------------------------------------------
69254721Semaste// Destructor
70254721Semaste//----------------------------------------------------------------------
71254721SemasteSearchFilter::~SearchFilter()
72254721Semaste{
73254721Semaste}
74254721Semaste
75254721Semastebool
76254721SemasteSearchFilter::ModulePasses (const FileSpec &spec)
77254721Semaste{
78254721Semaste    return true;
79254721Semaste}
80254721Semaste
81254721Semastebool
82254721SemasteSearchFilter::ModulePasses (const ModuleSP &module_sp)
83254721Semaste{
84254721Semaste    return true;
85254721Semaste}
86254721Semaste
87254721Semastebool
88254721SemasteSearchFilter::AddressPasses (Address &address)
89254721Semaste{
90254721Semaste    return true;
91254721Semaste}
92254721Semaste
93254721Semastebool
94254721SemasteSearchFilter::CompUnitPasses (FileSpec &fileSpec)
95254721Semaste{
96254721Semaste    return true;
97254721Semaste}
98254721Semaste
99254721Semastebool
100254721SemasteSearchFilter::CompUnitPasses (CompileUnit &compUnit)
101254721Semaste{
102254721Semaste    return true;
103254721Semaste}
104254721Semaste
105254721Semasteuint32_t
106254721SemasteSearchFilter::GetFilterRequiredItems()
107254721Semaste{
108254721Semaste    return (lldb::SymbolContextItem) 0;
109254721Semaste}
110254721Semaste
111254721Semastevoid
112254721SemasteSearchFilter::GetDescription (Stream *s)
113254721Semaste{
114254721Semaste}
115254721Semaste
116254721Semastevoid
117254721SemasteSearchFilter::Dump (Stream *s) const
118254721Semaste{
119254721Semaste
120254721Semaste}
121254721Semaste
122254721Semaste//----------------------------------------------------------------------
123254721Semaste// UTILITY Functions to help iterate down through the elements of the
124254721Semaste// SymbolContext.
125254721Semaste//----------------------------------------------------------------------
126254721Semaste
127254721Semastevoid
128254721SemasteSearchFilter::Search (Searcher &searcher)
129254721Semaste{
130254721Semaste    SymbolContext empty_sc;
131254721Semaste
132254721Semaste    if (!m_target_sp)
133254721Semaste        return;
134254721Semaste    empty_sc.target_sp = m_target_sp;
135254721Semaste
136254721Semaste    if (searcher.GetDepth() == Searcher::eDepthTarget)
137254721Semaste        searcher.SearchCallback (*this, empty_sc, NULL, false);
138254721Semaste    else
139254721Semaste        DoModuleIteration(empty_sc, searcher);
140254721Semaste}
141254721Semaste
142254721Semastevoid
143254721SemasteSearchFilter::SearchInModuleList (Searcher &searcher, ModuleList &modules)
144254721Semaste{
145254721Semaste    SymbolContext empty_sc;
146254721Semaste
147254721Semaste    if (!m_target_sp)
148254721Semaste        return;
149254721Semaste    empty_sc.target_sp = m_target_sp;
150254721Semaste
151254721Semaste    if (searcher.GetDepth() == Searcher::eDepthTarget)
152254721Semaste        searcher.SearchCallback (*this, empty_sc, NULL, false);
153254721Semaste    else
154254721Semaste    {
155254721Semaste        Mutex::Locker modules_locker(modules.GetMutex());
156254721Semaste        const size_t numModules = modules.GetSize();
157254721Semaste
158254721Semaste        for (size_t i = 0; i < numModules; i++)
159254721Semaste        {
160254721Semaste            ModuleSP module_sp(modules.GetModuleAtIndexUnlocked(i));
161254721Semaste            if (ModulePasses(module_sp))
162254721Semaste            {
163254721Semaste                if (DoModuleIteration(module_sp, searcher) == Searcher::eCallbackReturnStop)
164254721Semaste                    return;
165254721Semaste            }
166254721Semaste        }
167254721Semaste    }
168254721Semaste}
169254721Semaste
170254721Semaste
171254721SemasteSearcher::CallbackReturn
172254721SemasteSearchFilter::DoModuleIteration (const lldb::ModuleSP& module_sp, Searcher &searcher)
173254721Semaste{
174254721Semaste    SymbolContext matchingContext (m_target_sp, module_sp);
175254721Semaste    return DoModuleIteration(matchingContext, searcher);
176254721Semaste}
177254721Semaste
178254721SemasteSearcher::CallbackReturn
179254721SemasteSearchFilter::DoModuleIteration (const SymbolContext &context, Searcher &searcher)
180254721Semaste{
181254721Semaste    if (searcher.GetDepth () >= Searcher::eDepthModule)
182254721Semaste    {
183254721Semaste        if (context.module_sp)
184254721Semaste        {
185254721Semaste            if (searcher.GetDepth () == Searcher::eDepthModule)
186254721Semaste            {
187254721Semaste                SymbolContext matchingContext(context.module_sp.get());
188254721Semaste                searcher.SearchCallback (*this, matchingContext, NULL, false);
189254721Semaste            }
190254721Semaste            else
191254721Semaste            {
192254721Semaste                return DoCUIteration(context.module_sp, context, searcher);
193254721Semaste            }
194254721Semaste        }
195254721Semaste        else
196254721Semaste        {
197254721Semaste            const ModuleList &target_images = m_target_sp->GetImages();
198254721Semaste            Mutex::Locker modules_locker(target_images.GetMutex());
199254721Semaste
200254721Semaste            size_t n_modules = target_images.GetSize();
201254721Semaste            for (size_t i = 0; i < n_modules; i++)
202254721Semaste            {
203254721Semaste                // If this is the last level supplied, then call the callback directly,
204254721Semaste                // otherwise descend.
205254721Semaste                ModuleSP module_sp(target_images.GetModuleAtIndexUnlocked (i));
206254721Semaste                if (!ModulePasses (module_sp))
207254721Semaste                    continue;
208254721Semaste
209254721Semaste                if (searcher.GetDepth () == Searcher::eDepthModule)
210254721Semaste                {
211254721Semaste                    SymbolContext matchingContext(m_target_sp, module_sp);
212254721Semaste
213254721Semaste                    Searcher::CallbackReturn shouldContinue = searcher.SearchCallback (*this, matchingContext, NULL, false);
214254721Semaste                    if (shouldContinue == Searcher::eCallbackReturnStop
215254721Semaste                        || shouldContinue == Searcher::eCallbackReturnPop)
216254721Semaste                        return shouldContinue;
217254721Semaste                }
218254721Semaste                else
219254721Semaste                {
220254721Semaste                    Searcher::CallbackReturn shouldContinue = DoCUIteration(module_sp, context, searcher);
221254721Semaste                    if (shouldContinue == Searcher::eCallbackReturnStop)
222254721Semaste                        return shouldContinue;
223254721Semaste                    else if (shouldContinue == Searcher::eCallbackReturnPop)
224254721Semaste                        continue;
225254721Semaste                }
226254721Semaste            }
227254721Semaste        }
228254721Semaste    }
229254721Semaste    return Searcher::eCallbackReturnContinue;
230254721Semaste}
231254721Semaste
232254721SemasteSearcher::CallbackReturn
233254721SemasteSearchFilter::DoCUIteration (const ModuleSP &module_sp, const SymbolContext &context, Searcher &searcher)
234254721Semaste{
235254721Semaste    Searcher::CallbackReturn shouldContinue;
236254721Semaste    if (context.comp_unit == NULL)
237254721Semaste    {
238254721Semaste        const size_t num_comp_units = module_sp->GetNumCompileUnits();
239254721Semaste        for (size_t i = 0; i < num_comp_units; i++)
240254721Semaste        {
241254721Semaste            CompUnitSP cu_sp (module_sp->GetCompileUnitAtIndex (i));
242254721Semaste            if (cu_sp)
243254721Semaste            {
244254721Semaste                if (!CompUnitPasses (*(cu_sp.get())))
245254721Semaste                    continue;
246254721Semaste
247254721Semaste                if (searcher.GetDepth () == Searcher::eDepthCompUnit)
248254721Semaste                {
249254721Semaste                    SymbolContext matchingContext(m_target_sp, module_sp, cu_sp.get());
250254721Semaste
251254721Semaste                    shouldContinue = searcher.SearchCallback (*this, matchingContext, NULL, false);
252254721Semaste
253254721Semaste                    if (shouldContinue == Searcher::eCallbackReturnPop)
254254721Semaste                        return Searcher::eCallbackReturnContinue;
255254721Semaste                    else if (shouldContinue == Searcher::eCallbackReturnStop)
256254721Semaste                        return shouldContinue;
257254721Semaste                }
258254721Semaste                else
259254721Semaste                {
260254721Semaste                    // FIXME Descend to block.
261254721Semaste                }
262254721Semaste            }
263254721Semaste        }
264254721Semaste    }
265254721Semaste    else
266254721Semaste    {
267254721Semaste        if (CompUnitPasses(*context.comp_unit))
268254721Semaste        {
269254721Semaste            SymbolContext matchingContext (m_target_sp, module_sp, context.comp_unit);
270254721Semaste            return searcher.SearchCallback (*this, matchingContext, NULL, false);
271254721Semaste        }
272254721Semaste    }
273254721Semaste    return Searcher::eCallbackReturnContinue;
274254721Semaste}
275254721Semaste
276254721SemasteSearcher::CallbackReturn
277254721SemasteSearchFilter::DoFunctionIteration (Function *function, const SymbolContext &context, Searcher &searcher)
278254721Semaste{
279254721Semaste    // FIXME: Implement...
280254721Semaste    return Searcher::eCallbackReturnContinue;
281254721Semaste}
282254721Semaste
283254721Semaste//----------------------------------------------------------------------
284254721Semaste//  SearchFilterForNonModuleSpecificSearches:
285254721Semaste//  Selects a shared library matching a given file spec, consulting the targets "black list".
286254721Semaste//----------------------------------------------------------------------
287254721Semaste
288254721Semaste    bool
289254721Semaste    SearchFilterForNonModuleSpecificSearches::ModulePasses (const FileSpec &module_spec)
290254721Semaste    {
291254721Semaste        if (m_target_sp->ModuleIsExcludedForNonModuleSpecificSearches (module_spec))
292254721Semaste            return false;
293254721Semaste        else
294254721Semaste            return true;
295254721Semaste    }
296254721Semaste
297254721Semaste    bool
298254721Semaste    SearchFilterForNonModuleSpecificSearches::ModulePasses (const lldb::ModuleSP &module_sp)
299254721Semaste    {
300254721Semaste        if (!module_sp)
301254721Semaste            return true;
302254721Semaste        else if (m_target_sp->ModuleIsExcludedForNonModuleSpecificSearches (module_sp))
303254721Semaste            return false;
304254721Semaste        else
305254721Semaste            return true;
306254721Semaste    }
307254721Semaste
308254721Semaste//----------------------------------------------------------------------
309254721Semaste//  SearchFilterByModule:
310254721Semaste//  Selects a shared library matching a given file spec
311254721Semaste//----------------------------------------------------------------------
312254721Semaste
313254721Semaste//----------------------------------------------------------------------
314254721Semaste// SearchFilterByModule constructors
315254721Semaste//----------------------------------------------------------------------
316254721Semaste
317254721SemasteSearchFilterByModule::SearchFilterByModule (const lldb::TargetSP &target_sp, const FileSpec &module) :
318254721Semaste    SearchFilter (target_sp),
319254721Semaste    m_module_spec (module)
320254721Semaste{
321254721Semaste}
322254721Semaste
323254721Semaste
324254721Semaste//----------------------------------------------------------------------
325254721Semaste// SearchFilterByModule copy constructor
326254721Semaste//----------------------------------------------------------------------
327254721SemasteSearchFilterByModule::SearchFilterByModule(const SearchFilterByModule& rhs) :
328254721Semaste    SearchFilter (rhs),
329254721Semaste    m_module_spec (rhs.m_module_spec)
330254721Semaste{
331254721Semaste}
332254721Semaste
333254721Semaste//----------------------------------------------------------------------
334254721Semaste// SearchFilterByModule assignment operator
335254721Semaste//----------------------------------------------------------------------
336254721Semasteconst SearchFilterByModule&
337254721SemasteSearchFilterByModule::operator=(const SearchFilterByModule& rhs)
338254721Semaste{
339254721Semaste    m_target_sp = rhs.m_target_sp;
340254721Semaste    m_module_spec = rhs.m_module_spec;
341254721Semaste    return *this;
342254721Semaste}
343254721Semaste
344254721Semaste//----------------------------------------------------------------------
345254721Semaste// Destructor
346254721Semaste//----------------------------------------------------------------------
347254721SemasteSearchFilterByModule::~SearchFilterByModule()
348254721Semaste{
349254721Semaste}
350254721Semaste
351254721Semastebool
352254721SemasteSearchFilterByModule::ModulePasses (const ModuleSP &module_sp)
353254721Semaste{
354254721Semaste    if (module_sp && FileSpec::Equal(module_sp->GetFileSpec(), m_module_spec, false))
355254721Semaste        return true;
356254721Semaste    else
357254721Semaste        return false;
358254721Semaste}
359254721Semaste
360254721Semastebool
361254721SemasteSearchFilterByModule::ModulePasses (const FileSpec &spec)
362254721Semaste{
363254721Semaste    // Do a full match only if "spec" has a directory
364254721Semaste    const bool full_match = spec.GetDirectory();
365254721Semaste    return FileSpec::Equal(spec, m_module_spec, full_match);
366254721Semaste}
367254721Semaste
368254721Semastebool
369254721SemasteSearchFilterByModule::AddressPasses (Address &address)
370254721Semaste{
371254721Semaste    // FIXME: Not yet implemented
372254721Semaste    return true;
373254721Semaste}
374254721Semaste
375254721Semaste
376254721Semastebool
377254721SemasteSearchFilterByModule::CompUnitPasses (FileSpec &fileSpec)
378254721Semaste{
379254721Semaste    return true;
380254721Semaste}
381254721Semaste
382254721Semastebool
383254721SemasteSearchFilterByModule::CompUnitPasses (CompileUnit &compUnit)
384254721Semaste{
385254721Semaste    return true;
386254721Semaste}
387254721Semaste
388254721Semastevoid
389254721SemasteSearchFilterByModule::Search (Searcher &searcher)
390254721Semaste{
391254721Semaste    if (!m_target_sp)
392254721Semaste        return;
393254721Semaste
394254721Semaste    if (searcher.GetDepth() == Searcher::eDepthTarget)
395254721Semaste    {
396254721Semaste        SymbolContext empty_sc;
397254721Semaste        empty_sc.target_sp = m_target_sp;
398254721Semaste        searcher.SearchCallback (*this, empty_sc, NULL, false);
399254721Semaste    }
400254721Semaste
401254721Semaste    // If the module file spec is a full path, then we can just find the one
402254721Semaste    // filespec that passes.  Otherwise, we need to go through all modules and
403254721Semaste    // find the ones that match the file name.
404254721Semaste
405254721Semaste    const ModuleList &target_modules = m_target_sp->GetImages();
406254721Semaste    Mutex::Locker modules_locker (target_modules.GetMutex());
407254721Semaste
408254721Semaste    const size_t num_modules = target_modules.GetSize ();
409254721Semaste    for (size_t i = 0; i < num_modules; i++)
410254721Semaste    {
411254721Semaste        Module* module = target_modules.GetModulePointerAtIndexUnlocked(i);
412254721Semaste        const bool full_match = m_module_spec.GetDirectory();
413254721Semaste        if (FileSpec::Equal (m_module_spec, module->GetFileSpec(), full_match))
414254721Semaste        {
415254721Semaste            SymbolContext matchingContext(m_target_sp, module->shared_from_this());
416254721Semaste            Searcher::CallbackReturn shouldContinue;
417254721Semaste
418254721Semaste            shouldContinue = DoModuleIteration(matchingContext, searcher);
419254721Semaste            if (shouldContinue == Searcher::eCallbackReturnStop)
420254721Semaste                return;
421254721Semaste        }
422254721Semaste    }
423254721Semaste}
424254721Semaste
425254721Semastevoid
426254721SemasteSearchFilterByModule::GetDescription (Stream *s)
427254721Semaste{
428254721Semaste    s->PutCString(", module = ");
429254721Semaste    if (s->GetVerbose())
430254721Semaste    {
431254721Semaste        char buffer[2048];
432254721Semaste        m_module_spec.GetPath(buffer, 2047);
433254721Semaste        s->PutCString(buffer);
434254721Semaste    }
435254721Semaste    else
436254721Semaste    {
437254721Semaste        s->PutCString(m_module_spec.GetFilename().AsCString("<unknown>"));
438254721Semaste    }
439254721Semaste}
440254721Semaste
441254721Semasteuint32_t
442254721SemasteSearchFilterByModule::GetFilterRequiredItems()
443254721Semaste{
444254721Semaste    return eSymbolContextModule;
445254721Semaste}
446254721Semaste
447254721Semastevoid
448254721SemasteSearchFilterByModule::Dump (Stream *s) const
449254721Semaste{
450254721Semaste
451254721Semaste}
452254721Semaste//----------------------------------------------------------------------
453254721Semaste//  SearchFilterByModuleList:
454254721Semaste//  Selects a shared library matching a given file spec
455254721Semaste//----------------------------------------------------------------------
456254721Semaste
457254721Semaste//----------------------------------------------------------------------
458254721Semaste// SearchFilterByModuleList constructors
459254721Semaste//----------------------------------------------------------------------
460254721Semaste
461254721SemasteSearchFilterByModuleList::SearchFilterByModuleList (const lldb::TargetSP &target_sp, const FileSpecList &module_list) :
462254721Semaste    SearchFilter (target_sp),
463254721Semaste    m_module_spec_list (module_list)
464254721Semaste{
465254721Semaste}
466254721Semaste
467254721Semaste
468254721Semaste//----------------------------------------------------------------------
469254721Semaste// SearchFilterByModuleList copy constructor
470254721Semaste//----------------------------------------------------------------------
471254721SemasteSearchFilterByModuleList::SearchFilterByModuleList(const SearchFilterByModuleList& rhs) :
472254721Semaste    SearchFilter (rhs),
473254721Semaste    m_module_spec_list (rhs.m_module_spec_list)
474254721Semaste{
475254721Semaste}
476254721Semaste
477254721Semaste//----------------------------------------------------------------------
478254721Semaste// SearchFilterByModuleList assignment operator
479254721Semaste//----------------------------------------------------------------------
480254721Semasteconst SearchFilterByModuleList&
481254721SemasteSearchFilterByModuleList::operator=(const SearchFilterByModuleList& rhs)
482254721Semaste{
483254721Semaste    m_target_sp = rhs.m_target_sp;
484254721Semaste    m_module_spec_list = rhs.m_module_spec_list;
485254721Semaste    return *this;
486254721Semaste}
487254721Semaste
488254721Semaste//----------------------------------------------------------------------
489254721Semaste// Destructor
490254721Semaste//----------------------------------------------------------------------
491254721SemasteSearchFilterByModuleList::~SearchFilterByModuleList()
492254721Semaste{
493254721Semaste}
494254721Semaste
495254721Semastebool
496254721SemasteSearchFilterByModuleList::ModulePasses (const ModuleSP &module_sp)
497254721Semaste{
498254721Semaste    if (m_module_spec_list.GetSize() == 0)
499254721Semaste        return true;
500254721Semaste
501254721Semaste    if (module_sp && m_module_spec_list.FindFileIndex(0, module_sp->GetFileSpec(), false) != UINT32_MAX)
502254721Semaste        return true;
503254721Semaste    else
504254721Semaste        return false;
505254721Semaste}
506254721Semaste
507254721Semastebool
508254721SemasteSearchFilterByModuleList::ModulePasses (const FileSpec &spec)
509254721Semaste{
510254721Semaste    if (m_module_spec_list.GetSize() == 0)
511254721Semaste        return true;
512254721Semaste
513254721Semaste    if (m_module_spec_list.FindFileIndex(0, spec, true) != UINT32_MAX)
514254721Semaste        return true;
515254721Semaste    else
516254721Semaste        return false;
517254721Semaste}
518254721Semaste
519254721Semastebool
520254721SemasteSearchFilterByModuleList::AddressPasses (Address &address)
521254721Semaste{
522254721Semaste    // FIXME: Not yet implemented
523254721Semaste    return true;
524254721Semaste}
525254721Semaste
526254721Semaste
527254721Semastebool
528254721SemasteSearchFilterByModuleList::CompUnitPasses (FileSpec &fileSpec)
529254721Semaste{
530254721Semaste    return true;
531254721Semaste}
532254721Semaste
533254721Semastebool
534254721SemasteSearchFilterByModuleList::CompUnitPasses (CompileUnit &compUnit)
535254721Semaste{
536254721Semaste    return true;
537254721Semaste}
538254721Semaste
539254721Semastevoid
540254721SemasteSearchFilterByModuleList::Search (Searcher &searcher)
541254721Semaste{
542254721Semaste    if (!m_target_sp)
543254721Semaste        return;
544254721Semaste
545254721Semaste    if (searcher.GetDepth() == Searcher::eDepthTarget)
546254721Semaste    {
547254721Semaste        SymbolContext empty_sc;
548254721Semaste        empty_sc.target_sp = m_target_sp;
549254721Semaste        searcher.SearchCallback (*this, empty_sc, NULL, false);
550254721Semaste    }
551254721Semaste
552254721Semaste    // If the module file spec is a full path, then we can just find the one
553254721Semaste    // filespec that passes.  Otherwise, we need to go through all modules and
554254721Semaste    // find the ones that match the file name.
555254721Semaste
556254721Semaste    const ModuleList &target_modules = m_target_sp->GetImages();
557254721Semaste    Mutex::Locker modules_locker (target_modules.GetMutex());
558254721Semaste
559254721Semaste    const size_t num_modules = target_modules.GetSize ();
560254721Semaste    for (size_t i = 0; i < num_modules; i++)
561254721Semaste    {
562254721Semaste        Module* module = target_modules.GetModulePointerAtIndexUnlocked(i);
563254721Semaste        if (m_module_spec_list.FindFileIndex(0, module->GetFileSpec(), false) != UINT32_MAX)
564254721Semaste        {
565254721Semaste            SymbolContext matchingContext(m_target_sp, module->shared_from_this());
566254721Semaste            Searcher::CallbackReturn shouldContinue;
567254721Semaste
568254721Semaste            shouldContinue = DoModuleIteration(matchingContext, searcher);
569254721Semaste            if (shouldContinue == Searcher::eCallbackReturnStop)
570254721Semaste                return;
571254721Semaste        }
572254721Semaste    }
573254721Semaste}
574254721Semaste
575254721Semastevoid
576254721SemasteSearchFilterByModuleList::GetDescription (Stream *s)
577254721Semaste{
578254721Semaste    size_t num_modules = m_module_spec_list.GetSize();
579254721Semaste    if (num_modules == 1)
580254721Semaste    {
581254721Semaste        s->Printf (", module = ");
582254721Semaste        if (s->GetVerbose())
583254721Semaste        {
584254721Semaste            char buffer[2048];
585254721Semaste            m_module_spec_list.GetFileSpecAtIndex(0).GetPath(buffer, 2047);
586254721Semaste            s->PutCString(buffer);
587254721Semaste        }
588254721Semaste        else
589254721Semaste        {
590254721Semaste            s->PutCString(m_module_spec_list.GetFileSpecAtIndex(0).GetFilename().AsCString("<unknown>"));
591254721Semaste        }
592254721Semaste    }
593254721Semaste    else
594254721Semaste    {
595254721Semaste        s->Printf (", modules(%zu) = ", num_modules);
596254721Semaste        for (size_t i = 0; i < num_modules; i++)
597254721Semaste        {
598254721Semaste            if (s->GetVerbose())
599254721Semaste            {
600254721Semaste                char buffer[2048];
601254721Semaste                m_module_spec_list.GetFileSpecAtIndex(i).GetPath(buffer, 2047);
602254721Semaste                s->PutCString(buffer);
603254721Semaste            }
604254721Semaste            else
605254721Semaste            {
606254721Semaste                s->PutCString(m_module_spec_list.GetFileSpecAtIndex(i).GetFilename().AsCString("<unknown>"));
607254721Semaste            }
608254721Semaste            if (i != num_modules - 1)
609254721Semaste                s->PutCString (", ");
610254721Semaste        }
611254721Semaste    }
612254721Semaste}
613254721Semaste
614254721Semasteuint32_t
615254721SemasteSearchFilterByModuleList::GetFilterRequiredItems()
616254721Semaste{
617254721Semaste    return eSymbolContextModule;
618254721Semaste}
619254721Semaste
620254721Semastevoid
621254721SemasteSearchFilterByModuleList::Dump (Stream *s) const
622254721Semaste{
623254721Semaste
624254721Semaste}
625254721Semaste
626254721Semaste//----------------------------------------------------------------------
627254721Semaste//  SearchFilterByModuleListAndCU:
628254721Semaste//  Selects a shared library matching a given file spec
629254721Semaste//----------------------------------------------------------------------
630254721Semaste
631254721Semaste//----------------------------------------------------------------------
632254721Semaste// SearchFilterByModuleListAndCU constructors
633254721Semaste//----------------------------------------------------------------------
634254721Semaste
635254721SemasteSearchFilterByModuleListAndCU::SearchFilterByModuleListAndCU (const lldb::TargetSP &target_sp,
636254721Semaste                                                              const FileSpecList &module_list,
637254721Semaste                                                              const FileSpecList &cu_list) :
638254721Semaste    SearchFilterByModuleList (target_sp, module_list),
639254721Semaste    m_cu_spec_list (cu_list)
640254721Semaste{
641254721Semaste}
642254721Semaste
643254721Semaste
644254721Semaste//----------------------------------------------------------------------
645254721Semaste// SearchFilterByModuleListAndCU copy constructor
646254721Semaste//----------------------------------------------------------------------
647254721SemasteSearchFilterByModuleListAndCU::SearchFilterByModuleListAndCU(const SearchFilterByModuleListAndCU& rhs) :
648254721Semaste    SearchFilterByModuleList (rhs),
649254721Semaste    m_cu_spec_list (rhs.m_cu_spec_list)
650254721Semaste{
651254721Semaste}
652254721Semaste
653254721Semaste//----------------------------------------------------------------------
654254721Semaste// SearchFilterByModuleListAndCU assignment operator
655254721Semaste//----------------------------------------------------------------------
656254721Semasteconst SearchFilterByModuleListAndCU&
657254721SemasteSearchFilterByModuleListAndCU::operator=(const SearchFilterByModuleListAndCU& rhs)
658254721Semaste{
659254721Semaste    if (&rhs != this)
660254721Semaste    {
661254721Semaste        m_target_sp = rhs.m_target_sp;
662254721Semaste        m_module_spec_list = rhs.m_module_spec_list;
663254721Semaste        m_cu_spec_list = rhs.m_cu_spec_list;
664254721Semaste    }
665254721Semaste    return *this;
666254721Semaste}
667254721Semaste
668254721Semaste//----------------------------------------------------------------------
669254721Semaste// Destructor
670254721Semaste//----------------------------------------------------------------------
671254721SemasteSearchFilterByModuleListAndCU::~SearchFilterByModuleListAndCU()
672254721Semaste{
673254721Semaste}
674254721Semaste
675254721Semastebool
676254721SemasteSearchFilterByModuleListAndCU::AddressPasses (Address &address)
677254721Semaste{
678254721Semaste    return true;
679254721Semaste}
680254721Semaste
681254721Semaste
682254721Semastebool
683254721SemasteSearchFilterByModuleListAndCU::CompUnitPasses (FileSpec &fileSpec)
684254721Semaste{
685254721Semaste    return m_cu_spec_list.FindFileIndex(0, fileSpec, false) != UINT32_MAX;
686254721Semaste}
687254721Semaste
688254721Semastebool
689254721SemasteSearchFilterByModuleListAndCU::CompUnitPasses (CompileUnit &compUnit)
690254721Semaste{
691254721Semaste    bool in_cu_list = m_cu_spec_list.FindFileIndex(0, compUnit, false) != UINT32_MAX;
692254721Semaste    if (in_cu_list)
693254721Semaste    {
694254721Semaste        ModuleSP module_sp(compUnit.GetModule());
695254721Semaste        if (module_sp)
696254721Semaste        {
697254721Semaste            bool module_passes = SearchFilterByModuleList::ModulePasses(module_sp);
698254721Semaste            return module_passes;
699254721Semaste        }
700254721Semaste        else
701254721Semaste            return true;
702254721Semaste    }
703254721Semaste    else
704254721Semaste        return false;
705254721Semaste}
706254721Semaste
707254721Semastevoid
708254721SemasteSearchFilterByModuleListAndCU::Search (Searcher &searcher)
709254721Semaste{
710254721Semaste    if (!m_target_sp)
711254721Semaste        return;
712254721Semaste
713254721Semaste    if (searcher.GetDepth() == Searcher::eDepthTarget)
714254721Semaste    {
715254721Semaste        SymbolContext empty_sc;
716254721Semaste        empty_sc.target_sp = m_target_sp;
717254721Semaste        searcher.SearchCallback (*this, empty_sc, NULL, false);
718254721Semaste    }
719254721Semaste
720254721Semaste    // If the module file spec is a full path, then we can just find the one
721254721Semaste    // filespec that passes.  Otherwise, we need to go through all modules and
722254721Semaste    // find the ones that match the file name.
723254721Semaste
724254721Semaste    ModuleList matching_modules;
725254721Semaste    const ModuleList &target_images = m_target_sp->GetImages();
726254721Semaste    Mutex::Locker modules_locker(target_images.GetMutex());
727254721Semaste
728254721Semaste    const size_t num_modules = target_images.GetSize ();
729254721Semaste    bool no_modules_in_filter = m_module_spec_list.GetSize() == 0;
730254721Semaste    for (size_t i = 0; i < num_modules; i++)
731254721Semaste    {
732254721Semaste        lldb::ModuleSP module_sp = target_images.GetModuleAtIndexUnlocked(i);
733254721Semaste        if (no_modules_in_filter || m_module_spec_list.FindFileIndex(0, module_sp->GetFileSpec(), false) != UINT32_MAX)
734254721Semaste        {
735254721Semaste            SymbolContext matchingContext(m_target_sp, module_sp);
736254721Semaste            Searcher::CallbackReturn shouldContinue;
737254721Semaste
738254721Semaste            if (searcher.GetDepth() == Searcher::eDepthModule)
739254721Semaste            {
740254721Semaste                shouldContinue = DoModuleIteration(matchingContext, searcher);
741254721Semaste                if (shouldContinue == Searcher::eCallbackReturnStop)
742254721Semaste                    return;
743254721Semaste            }
744254721Semaste            else
745254721Semaste            {
746254721Semaste                const size_t num_cu = module_sp->GetNumCompileUnits();
747254721Semaste                for (size_t cu_idx = 0; cu_idx < num_cu; cu_idx++)
748254721Semaste                {
749254721Semaste                    CompUnitSP cu_sp = module_sp->GetCompileUnitAtIndex(cu_idx);
750254721Semaste                    matchingContext.comp_unit = cu_sp.get();
751254721Semaste                    if (matchingContext.comp_unit)
752254721Semaste                    {
753254721Semaste                        if (m_cu_spec_list.FindFileIndex(0, *matchingContext.comp_unit, false) != UINT32_MAX)
754254721Semaste                        {
755254721Semaste                            shouldContinue = DoCUIteration(module_sp, matchingContext, searcher);
756254721Semaste                            if (shouldContinue == Searcher::eCallbackReturnStop)
757254721Semaste                                return;
758254721Semaste                        }
759254721Semaste                    }
760254721Semaste                }
761254721Semaste            }
762254721Semaste        }
763254721Semaste    }
764254721Semaste}
765254721Semaste
766254721Semastevoid
767254721SemasteSearchFilterByModuleListAndCU::GetDescription (Stream *s)
768254721Semaste{
769254721Semaste    size_t num_modules = m_module_spec_list.GetSize();
770254721Semaste    if (num_modules == 1)
771254721Semaste    {
772254721Semaste        s->Printf (", module = ");
773254721Semaste        if (s->GetVerbose())
774254721Semaste        {
775254721Semaste            char buffer[2048];
776254721Semaste            m_module_spec_list.GetFileSpecAtIndex(0).GetPath(buffer, 2047);
777254721Semaste            s->PutCString(buffer);
778254721Semaste        }
779254721Semaste        else
780254721Semaste        {
781254721Semaste            s->PutCString(m_module_spec_list.GetFileSpecAtIndex(0).GetFilename().AsCString("<unknown>"));
782254721Semaste        }
783254721Semaste    }
784254721Semaste    else if (num_modules > 0)
785254721Semaste    {
786254721Semaste        s->Printf (", modules(%zd) = ", num_modules);
787254721Semaste        for (size_t i = 0; i < num_modules; i++)
788254721Semaste        {
789254721Semaste            if (s->GetVerbose())
790254721Semaste            {
791254721Semaste                char buffer[2048];
792254721Semaste                m_module_spec_list.GetFileSpecAtIndex(i).GetPath(buffer, 2047);
793254721Semaste                s->PutCString(buffer);
794254721Semaste            }
795254721Semaste            else
796254721Semaste            {
797254721Semaste                s->PutCString(m_module_spec_list.GetFileSpecAtIndex(i).GetFilename().AsCString("<unknown>"));
798254721Semaste            }
799254721Semaste            if (i != num_modules - 1)
800254721Semaste                s->PutCString (", ");
801254721Semaste        }
802254721Semaste    }
803254721Semaste}
804254721Semaste
805254721Semasteuint32_t
806254721SemasteSearchFilterByModuleListAndCU::GetFilterRequiredItems()
807254721Semaste{
808254721Semaste    return eSymbolContextModule | eSymbolContextCompUnit;
809254721Semaste}
810254721Semaste
811254721Semastevoid
812254721SemasteSearchFilterByModuleListAndCU::Dump (Stream *s) const
813254721Semaste{
814254721Semaste
815254721Semaste}
816254721Semaste
817