1c9af18a5SGreg Clayton //===-- CommandCompletions.cpp ----------------------------------*- C++ -*-===//
2c9af18a5SGreg Clayton //
3c9af18a5SGreg Clayton //                     The LLVM Compiler Infrastructure
4c9af18a5SGreg Clayton //
5c9af18a5SGreg Clayton // This file is distributed under the University of Illinois Open Source
6c9af18a5SGreg Clayton // License. See LICENSE.TXT for details.
7c9af18a5SGreg Clayton //
8c9af18a5SGreg Clayton //===----------------------------------------------------------------------===//
9c9af18a5SGreg Clayton 
10c9af18a5SGreg Clayton 
11c9af18a5SGreg Clayton // C Includes
12c9af18a5SGreg Clayton // C++ Includes
13c9af18a5SGreg Clayton // Other libraries and framework includes
14c9af18a5SGreg Clayton // Project includes
1540af72e1SJim Ingham #include "lldb/Interpreter/Args.h"
16c9af18a5SGreg Clayton #include "lldb/Interpreter/CommandInterpreter.h"
17c9af18a5SGreg Clayton #include "lldb/Core/FileSpecList.h"
18c9af18a5SGreg Clayton #include "lldb/Target/Target.h"
19c9af18a5SGreg Clayton #include "lldb/Interpreter/CommandCompletions.h"
20c9af18a5SGreg Clayton 
21c9af18a5SGreg Clayton 
22c9af18a5SGreg Clayton using namespace lldb_private;
23c9af18a5SGreg Clayton 
24c9af18a5SGreg Clayton CommandCompletions::CommonCompletionElement
25c9af18a5SGreg Clayton CommandCompletions::g_common_completions[] =
26c9af18a5SGreg Clayton {
27c9af18a5SGreg Clayton     {eCustomCompletion,     NULL},
28c9af18a5SGreg Clayton     {eSourceFileCompletion, CommandCompletions::SourceFiles},
29c9af18a5SGreg Clayton     {eDiskFileCompletion,   NULL},
30c9af18a5SGreg Clayton     {eSymbolCompletion,     CommandCompletions::Symbols},
31c9af18a5SGreg Clayton     {eModuleCompletion,     CommandCompletions::Modules},
32c9af18a5SGreg Clayton     {eNoCompletion,         NULL}      // This one has to be last in the list.
33c9af18a5SGreg Clayton };
34c9af18a5SGreg Clayton 
35c9af18a5SGreg Clayton bool
36*6611103cSGreg Clayton CommandCompletions::InvokeCommonCompletionCallbacks
37*6611103cSGreg Clayton (
38*6611103cSGreg Clayton     CommandInterpreter &interpreter,
39*6611103cSGreg Clayton     uint32_t completion_mask,
40c9af18a5SGreg Clayton     const char *completion_str,
41c9af18a5SGreg Clayton     int match_start_point,
42c9af18a5SGreg Clayton     int max_return_elements,
43c9af18a5SGreg Clayton     SearchFilter *searcher,
44*6611103cSGreg Clayton     StringList &matches
45*6611103cSGreg Clayton )
46c9af18a5SGreg Clayton {
47c9af18a5SGreg Clayton     bool handled = false;
48c9af18a5SGreg Clayton 
49c9af18a5SGreg Clayton     if (completion_mask & eCustomCompletion)
50c9af18a5SGreg Clayton         return false;
51c9af18a5SGreg Clayton 
52c9af18a5SGreg Clayton     for (int i = 0; ; i++)
53c9af18a5SGreg Clayton     {
54c9af18a5SGreg Clayton         if (g_common_completions[i].type == eNoCompletion)
55c9af18a5SGreg Clayton             break;
56c9af18a5SGreg Clayton          else if ((g_common_completions[i].type & completion_mask) == g_common_completions[i].type
57c9af18a5SGreg Clayton                    && g_common_completions[i].callback != NULL)
58c9af18a5SGreg Clayton          {
59c9af18a5SGreg Clayton             handled = true;
60*6611103cSGreg Clayton             g_common_completions[i].callback (interpreter,
61*6611103cSGreg Clayton                                               completion_str,
62c9af18a5SGreg Clayton                                               match_start_point,
63c9af18a5SGreg Clayton                                               max_return_elements,
64c9af18a5SGreg Clayton                                               searcher,
65c9af18a5SGreg Clayton                                               matches);
66c9af18a5SGreg Clayton         }
67c9af18a5SGreg Clayton     }
68c9af18a5SGreg Clayton     return handled;
69c9af18a5SGreg Clayton }
70c9af18a5SGreg Clayton 
71c9af18a5SGreg Clayton int
72*6611103cSGreg Clayton CommandCompletions::SourceFiles
73*6611103cSGreg Clayton (
74*6611103cSGreg Clayton     CommandInterpreter &interpreter,
75*6611103cSGreg Clayton     const char *partial_file_name,
76c9af18a5SGreg Clayton     int match_start_point,
77c9af18a5SGreg Clayton     int max_return_elements,
78c9af18a5SGreg Clayton     SearchFilter *searcher,
79*6611103cSGreg Clayton     StringList &matches
80*6611103cSGreg Clayton )
81c9af18a5SGreg Clayton {
82c9af18a5SGreg Clayton     // Find some way to switch "include support files..."
83*6611103cSGreg Clayton     SourceFileCompleter completer (interpreter,
84*6611103cSGreg Clayton                                    false,
85*6611103cSGreg Clayton                                    partial_file_name,
86*6611103cSGreg Clayton                                    match_start_point,
87*6611103cSGreg Clayton                                    max_return_elements,
88c9af18a5SGreg Clayton                                    matches);
89c9af18a5SGreg Clayton 
90c9af18a5SGreg Clayton     if (searcher == NULL)
91c9af18a5SGreg Clayton     {
92*6611103cSGreg Clayton         lldb::TargetSP target_sp = interpreter.GetDebugger().GetCurrentTarget();
93c9af18a5SGreg Clayton         SearchFilter null_searcher (target_sp);
94c9af18a5SGreg Clayton         completer.DoCompletion (&null_searcher);
95c9af18a5SGreg Clayton     }
96c9af18a5SGreg Clayton     else
97c9af18a5SGreg Clayton     {
98c9af18a5SGreg Clayton         completer.DoCompletion (searcher);
99c9af18a5SGreg Clayton     }
100c9af18a5SGreg Clayton     return matches.GetSize();
101c9af18a5SGreg Clayton }
102c9af18a5SGreg Clayton 
103c9af18a5SGreg Clayton int
104*6611103cSGreg Clayton CommandCompletions::Modules
105*6611103cSGreg Clayton (
106*6611103cSGreg Clayton     CommandInterpreter &interpreter,
107*6611103cSGreg Clayton     const char *partial_file_name,
108c9af18a5SGreg Clayton     int match_start_point,
109c9af18a5SGreg Clayton     int max_return_elements,
110c9af18a5SGreg Clayton     SearchFilter *searcher,
111*6611103cSGreg Clayton     StringList &matches
112*6611103cSGreg Clayton )
113c9af18a5SGreg Clayton {
114*6611103cSGreg Clayton     ModuleCompleter completer (interpreter,
115*6611103cSGreg Clayton                                partial_file_name,
116*6611103cSGreg Clayton                                match_start_point,
117*6611103cSGreg Clayton                                max_return_elements,
118*6611103cSGreg Clayton                                matches);
119c9af18a5SGreg Clayton 
120c9af18a5SGreg Clayton     if (searcher == NULL)
121c9af18a5SGreg Clayton     {
122*6611103cSGreg Clayton         lldb::TargetSP target_sp = interpreter.GetDebugger().GetCurrentTarget();
123c9af18a5SGreg Clayton         SearchFilter null_searcher (target_sp);
124c9af18a5SGreg Clayton         completer.DoCompletion (&null_searcher);
125c9af18a5SGreg Clayton     }
126c9af18a5SGreg Clayton     else
127c9af18a5SGreg Clayton     {
128c9af18a5SGreg Clayton         completer.DoCompletion (searcher);
129c9af18a5SGreg Clayton     }
130c9af18a5SGreg Clayton     return matches.GetSize();
131c9af18a5SGreg Clayton }
132c9af18a5SGreg Clayton 
133c9af18a5SGreg Clayton int
134*6611103cSGreg Clayton CommandCompletions::Symbols
135*6611103cSGreg Clayton (
136*6611103cSGreg Clayton     CommandInterpreter &interpreter,
137*6611103cSGreg Clayton     const char *partial_file_name,
138c9af18a5SGreg Clayton     int match_start_point,
139c9af18a5SGreg Clayton     int max_return_elements,
140c9af18a5SGreg Clayton     SearchFilter *searcher,
141*6611103cSGreg Clayton     StringList &matches)
142c9af18a5SGreg Clayton {
143*6611103cSGreg Clayton     SymbolCompleter completer (interpreter,
144*6611103cSGreg Clayton                                partial_file_name,
145*6611103cSGreg Clayton                                match_start_point,
146*6611103cSGreg Clayton                                max_return_elements,
147*6611103cSGreg Clayton                                matches);
148c9af18a5SGreg Clayton 
149c9af18a5SGreg Clayton     if (searcher == NULL)
150c9af18a5SGreg Clayton     {
151*6611103cSGreg Clayton         lldb::TargetSP target_sp = interpreter.GetDebugger().GetCurrentTarget();
152c9af18a5SGreg Clayton         SearchFilter null_searcher (target_sp);
153c9af18a5SGreg Clayton         completer.DoCompletion (&null_searcher);
154c9af18a5SGreg Clayton     }
155c9af18a5SGreg Clayton     else
156c9af18a5SGreg Clayton     {
157c9af18a5SGreg Clayton         completer.DoCompletion (searcher);
158c9af18a5SGreg Clayton     }
159c9af18a5SGreg Clayton     return matches.GetSize();
160c9af18a5SGreg Clayton }
161c9af18a5SGreg Clayton 
162*6611103cSGreg Clayton CommandCompletions::Completer::Completer
163*6611103cSGreg Clayton (
164*6611103cSGreg Clayton     CommandInterpreter &interpreter,
165c9af18a5SGreg Clayton     const char *completion_str,
166c9af18a5SGreg Clayton     int match_start_point,
167c9af18a5SGreg Clayton     int max_return_elements,
168c9af18a5SGreg Clayton     StringList &matches
169c9af18a5SGreg Clayton ) :
170*6611103cSGreg Clayton     m_interpreter (interpreter),
171c9af18a5SGreg Clayton     m_completion_str (completion_str),
172c9af18a5SGreg Clayton     m_match_start_point (match_start_point),
173c9af18a5SGreg Clayton     m_max_return_elements (max_return_elements),
174c9af18a5SGreg Clayton     m_matches (matches)
175c9af18a5SGreg Clayton {
176c9af18a5SGreg Clayton }
177c9af18a5SGreg Clayton 
178c9af18a5SGreg Clayton CommandCompletions::Completer::~Completer ()
179c9af18a5SGreg Clayton {
180c9af18a5SGreg Clayton 
181c9af18a5SGreg Clayton }
182c9af18a5SGreg Clayton 
183c9af18a5SGreg Clayton //----------------------------------------------------------------------
184c9af18a5SGreg Clayton // SourceFileCompleter
185c9af18a5SGreg Clayton //----------------------------------------------------------------------
186c9af18a5SGreg Clayton 
187*6611103cSGreg Clayton CommandCompletions::SourceFileCompleter::SourceFileCompleter
188*6611103cSGreg Clayton (
189*6611103cSGreg Clayton     CommandInterpreter &interpreter,
190c9af18a5SGreg Clayton     bool include_support_files,
191c9af18a5SGreg Clayton     const char *completion_str,
192c9af18a5SGreg Clayton     int match_start_point,
193c9af18a5SGreg Clayton     int max_return_elements,
194c9af18a5SGreg Clayton     StringList &matches
195c9af18a5SGreg Clayton ) :
196*6611103cSGreg Clayton     CommandCompletions::Completer (interpreter, completion_str, match_start_point, max_return_elements, matches),
197c9af18a5SGreg Clayton     m_include_support_files (include_support_files),
198c9af18a5SGreg Clayton     m_matching_files()
199c9af18a5SGreg Clayton {
200c9af18a5SGreg Clayton     FileSpec partial_spec (m_completion_str.c_str());
201c9af18a5SGreg Clayton     m_file_name = partial_spec.GetFilename().GetCString();
202c9af18a5SGreg Clayton     m_dir_name = partial_spec.GetDirectory().GetCString();
203c9af18a5SGreg Clayton }
204c9af18a5SGreg Clayton 
205c9af18a5SGreg Clayton Searcher::Depth
206c9af18a5SGreg Clayton CommandCompletions::SourceFileCompleter::GetDepth()
207c9af18a5SGreg Clayton {
208c9af18a5SGreg Clayton     return eDepthCompUnit;
209c9af18a5SGreg Clayton }
210c9af18a5SGreg Clayton 
211c9af18a5SGreg Clayton Searcher::CallbackReturn
212c9af18a5SGreg Clayton CommandCompletions::SourceFileCompleter::SearchCallback (
213c9af18a5SGreg Clayton     SearchFilter &filter,
214c9af18a5SGreg Clayton     SymbolContext &context,
215c9af18a5SGreg Clayton     Address *addr,
216c9af18a5SGreg Clayton     bool complete
217c9af18a5SGreg Clayton )
218c9af18a5SGreg Clayton {
219c9af18a5SGreg Clayton     if (context.comp_unit != NULL)
220c9af18a5SGreg Clayton     {
221c9af18a5SGreg Clayton         if (m_include_support_files)
222c9af18a5SGreg Clayton         {
223c9af18a5SGreg Clayton             FileSpecList supporting_files = context.comp_unit->GetSupportFiles();
224c9af18a5SGreg Clayton             for (size_t sfiles = 0; sfiles < supporting_files.GetSize(); sfiles++)
225c9af18a5SGreg Clayton             {
226c9af18a5SGreg Clayton                 const FileSpec &sfile_spec = supporting_files.GetFileSpecAtIndex(sfiles);
227c9af18a5SGreg Clayton                 const char *sfile_file_name = sfile_spec.GetFilename().GetCString();
228c9af18a5SGreg Clayton                 const char *sfile_dir_name = sfile_spec.GetFilename().GetCString();
229c9af18a5SGreg Clayton                 bool match = false;
230c9af18a5SGreg Clayton                 if (m_file_name && sfile_file_name
231c9af18a5SGreg Clayton                     && strstr (sfile_file_name, m_file_name) == sfile_file_name)
232c9af18a5SGreg Clayton                     match = true;
233c9af18a5SGreg Clayton                 if (match && m_dir_name && sfile_dir_name
234c9af18a5SGreg Clayton                     && strstr (sfile_dir_name, m_dir_name) != sfile_dir_name)
235c9af18a5SGreg Clayton                     match = false;
236c9af18a5SGreg Clayton 
237c9af18a5SGreg Clayton                 if (match)
238c9af18a5SGreg Clayton                 {
239c9af18a5SGreg Clayton                     m_matching_files.AppendIfUnique(sfile_spec);
240c9af18a5SGreg Clayton                 }
241c9af18a5SGreg Clayton             }
242c9af18a5SGreg Clayton 
243c9af18a5SGreg Clayton         }
244c9af18a5SGreg Clayton         else
245c9af18a5SGreg Clayton         {
246c9af18a5SGreg Clayton             const char *cur_file_name = context.comp_unit->GetFilename().GetCString();
247c9af18a5SGreg Clayton             const char *cur_dir_name = context.comp_unit->GetDirectory().GetCString();
248c9af18a5SGreg Clayton 
249c9af18a5SGreg Clayton             bool match = false;
250c9af18a5SGreg Clayton             if (m_file_name && cur_file_name
251c9af18a5SGreg Clayton                 && strstr (cur_file_name, m_file_name) == cur_file_name)
252c9af18a5SGreg Clayton                 match = true;
253c9af18a5SGreg Clayton 
254c9af18a5SGreg Clayton             if (match && m_dir_name && cur_dir_name
255c9af18a5SGreg Clayton                 && strstr (cur_dir_name, m_dir_name) != cur_dir_name)
256c9af18a5SGreg Clayton                 match = false;
257c9af18a5SGreg Clayton 
258c9af18a5SGreg Clayton             if (match)
259c9af18a5SGreg Clayton             {
260c9af18a5SGreg Clayton                 m_matching_files.AppendIfUnique(context.comp_unit);
261c9af18a5SGreg Clayton             }
262c9af18a5SGreg Clayton         }
263c9af18a5SGreg Clayton     }
264c9af18a5SGreg Clayton     return Searcher::eCallbackReturnContinue;
265c9af18a5SGreg Clayton }
266c9af18a5SGreg Clayton 
267c9af18a5SGreg Clayton size_t
268c9af18a5SGreg Clayton CommandCompletions::SourceFileCompleter::DoCompletion (SearchFilter *filter)
269c9af18a5SGreg Clayton {
270c9af18a5SGreg Clayton     filter->Search (*this);
271c9af18a5SGreg Clayton     // Now convert the filelist to completions:
272c9af18a5SGreg Clayton     for (size_t i = 0; i < m_matching_files.GetSize(); i++)
273c9af18a5SGreg Clayton     {
274c9af18a5SGreg Clayton         m_matches.AppendString (m_matching_files.GetFileSpecAtIndex(i).GetFilename().GetCString());
275c9af18a5SGreg Clayton     }
276c9af18a5SGreg Clayton     return m_matches.GetSize();
277c9af18a5SGreg Clayton 
278c9af18a5SGreg Clayton }
279c9af18a5SGreg Clayton 
280c9af18a5SGreg Clayton //----------------------------------------------------------------------
281c9af18a5SGreg Clayton // SymbolCompleter
282c9af18a5SGreg Clayton //----------------------------------------------------------------------
283c9af18a5SGreg Clayton 
284c9af18a5SGreg Clayton static bool
285c9af18a5SGreg Clayton regex_chars (const char comp)
286c9af18a5SGreg Clayton {
287c9af18a5SGreg Clayton     if (comp == '[' || comp == ']' || comp == '(' || comp == ')')
288c9af18a5SGreg Clayton         return true;
289c9af18a5SGreg Clayton     else
290c9af18a5SGreg Clayton         return false;
291c9af18a5SGreg Clayton }
292*6611103cSGreg Clayton CommandCompletions::SymbolCompleter::SymbolCompleter
293*6611103cSGreg Clayton (
294*6611103cSGreg Clayton     CommandInterpreter &interpreter,
295c9af18a5SGreg Clayton     const char *completion_str,
296c9af18a5SGreg Clayton     int match_start_point,
297c9af18a5SGreg Clayton     int max_return_elements,
298c9af18a5SGreg Clayton     StringList &matches
299c9af18a5SGreg Clayton ) :
300*6611103cSGreg Clayton     CommandCompletions::Completer (interpreter, completion_str, match_start_point, max_return_elements, matches)
301c9af18a5SGreg Clayton {
302c9af18a5SGreg Clayton     std::string regex_str ("^");
303c9af18a5SGreg Clayton     regex_str.append(completion_str);
304c9af18a5SGreg Clayton     regex_str.append(".*");
305c9af18a5SGreg Clayton     std::string::iterator pos;
306c9af18a5SGreg Clayton 
307c9af18a5SGreg Clayton     pos = find_if(regex_str.begin(), regex_str.end(), regex_chars);
308c9af18a5SGreg Clayton     while (pos < regex_str.end()) {
309c9af18a5SGreg Clayton         pos = regex_str.insert(pos, '\\');
310c9af18a5SGreg Clayton         pos += 2;
311c9af18a5SGreg Clayton         pos = find_if(pos, regex_str.end(), regex_chars);
312c9af18a5SGreg Clayton     }
313c9af18a5SGreg Clayton     m_regex.Compile(regex_str.c_str());
314c9af18a5SGreg Clayton }
315c9af18a5SGreg Clayton 
316c9af18a5SGreg Clayton Searcher::Depth
317c9af18a5SGreg Clayton CommandCompletions::SymbolCompleter::GetDepth()
318c9af18a5SGreg Clayton {
319c9af18a5SGreg Clayton     return eDepthModule;
320c9af18a5SGreg Clayton }
321c9af18a5SGreg Clayton 
322c9af18a5SGreg Clayton Searcher::CallbackReturn
323c9af18a5SGreg Clayton CommandCompletions::SymbolCompleter::SearchCallback (
324c9af18a5SGreg Clayton     SearchFilter &filter,
325c9af18a5SGreg Clayton     SymbolContext &context,
326c9af18a5SGreg Clayton     Address *addr,
327c9af18a5SGreg Clayton     bool complete
328c9af18a5SGreg Clayton )
329c9af18a5SGreg Clayton {
330c9af18a5SGreg Clayton     SymbolContextList func_list;
331c9af18a5SGreg Clayton     SymbolContextList sym_list;
332c9af18a5SGreg Clayton 
333c9af18a5SGreg Clayton     if (context.module_sp != NULL)
334c9af18a5SGreg Clayton     {
335c9af18a5SGreg Clayton         if (context.module_sp)
336c9af18a5SGreg Clayton         {
337c9af18a5SGreg Clayton             context.module_sp->FindSymbolsMatchingRegExAndType (m_regex, lldb::eSymbolTypeCode, sym_list);
338c9af18a5SGreg Clayton             context.module_sp->FindFunctions (m_regex, true, func_list);
339c9af18a5SGreg Clayton         }
340c9af18a5SGreg Clayton 
341c9af18a5SGreg Clayton         SymbolContext sc;
342c9af18a5SGreg Clayton         // Now add the functions & symbols to the list - only add if unique:
343c9af18a5SGreg Clayton         for (int i = 0; i < func_list.GetSize(); i++)
344c9af18a5SGreg Clayton         {
345c9af18a5SGreg Clayton             if (func_list.GetContextAtIndex(i, sc))
346c9af18a5SGreg Clayton             {
347c9af18a5SGreg Clayton                 if (sc.function)
348c9af18a5SGreg Clayton                 {
349c9af18a5SGreg Clayton                     m_match_set.insert (sc.function->GetMangled().GetDemangledName());
350c9af18a5SGreg Clayton                 }
351c9af18a5SGreg Clayton             }
352c9af18a5SGreg Clayton         }
353c9af18a5SGreg Clayton 
354c9af18a5SGreg Clayton         for (int i = 0; i < sym_list.GetSize(); i++)
355c9af18a5SGreg Clayton         {
356c9af18a5SGreg Clayton             if (sym_list.GetContextAtIndex(i, sc))
357c9af18a5SGreg Clayton             {
358c9af18a5SGreg Clayton                 if (sc.symbol && sc.symbol->GetAddressRangePtr())
359c9af18a5SGreg Clayton                 {
360c9af18a5SGreg Clayton                     m_match_set.insert (sc.symbol->GetMangled().GetDemangledName());
361c9af18a5SGreg Clayton                 }
362c9af18a5SGreg Clayton             }
363c9af18a5SGreg Clayton         }
364c9af18a5SGreg Clayton     }
365c9af18a5SGreg Clayton     return Searcher::eCallbackReturnContinue;
366c9af18a5SGreg Clayton }
367c9af18a5SGreg Clayton 
368c9af18a5SGreg Clayton size_t
369c9af18a5SGreg Clayton CommandCompletions::SymbolCompleter::DoCompletion (SearchFilter *filter)
370c9af18a5SGreg Clayton {
371c9af18a5SGreg Clayton     filter->Search (*this);
372c9af18a5SGreg Clayton     collection::iterator pos = m_match_set.begin(), end = m_match_set.end();
373c9af18a5SGreg Clayton     for (pos = m_match_set.begin(); pos != end; pos++)
374c9af18a5SGreg Clayton         m_matches.AppendString((*pos).GetCString());
375c9af18a5SGreg Clayton 
376c9af18a5SGreg Clayton     return m_matches.GetSize();
377c9af18a5SGreg Clayton }
378c9af18a5SGreg Clayton 
379c9af18a5SGreg Clayton //----------------------------------------------------------------------
380c9af18a5SGreg Clayton // ModuleCompleter
381c9af18a5SGreg Clayton //----------------------------------------------------------------------
382*6611103cSGreg Clayton CommandCompletions::ModuleCompleter::ModuleCompleter
383*6611103cSGreg Clayton (
384*6611103cSGreg Clayton     CommandInterpreter &interpreter,
385c9af18a5SGreg Clayton     const char *completion_str,
386c9af18a5SGreg Clayton     int match_start_point,
387c9af18a5SGreg Clayton     int max_return_elements,
388c9af18a5SGreg Clayton     StringList &matches
389c9af18a5SGreg Clayton ) :
390*6611103cSGreg Clayton     CommandCompletions::Completer (interpreter, completion_str, match_start_point, max_return_elements, matches)
391c9af18a5SGreg Clayton {
392c9af18a5SGreg Clayton     FileSpec partial_spec (m_completion_str.c_str());
393c9af18a5SGreg Clayton     m_file_name = partial_spec.GetFilename().GetCString();
394c9af18a5SGreg Clayton     m_dir_name = partial_spec.GetDirectory().GetCString();
395c9af18a5SGreg Clayton }
396c9af18a5SGreg Clayton 
397c9af18a5SGreg Clayton Searcher::Depth
398c9af18a5SGreg Clayton CommandCompletions::ModuleCompleter::GetDepth()
399c9af18a5SGreg Clayton {
400c9af18a5SGreg Clayton     return eDepthModule;
401c9af18a5SGreg Clayton }
402c9af18a5SGreg Clayton 
403c9af18a5SGreg Clayton Searcher::CallbackReturn
404c9af18a5SGreg Clayton CommandCompletions::ModuleCompleter::SearchCallback (
405c9af18a5SGreg Clayton     SearchFilter &filter,
406c9af18a5SGreg Clayton     SymbolContext &context,
407c9af18a5SGreg Clayton     Address *addr,
408c9af18a5SGreg Clayton     bool complete
409c9af18a5SGreg Clayton )
410c9af18a5SGreg Clayton {
411c9af18a5SGreg Clayton     if (context.module_sp != NULL)
412c9af18a5SGreg Clayton     {
413c9af18a5SGreg Clayton         const char *cur_file_name = context.module_sp->GetFileSpec().GetFilename().GetCString();
414c9af18a5SGreg Clayton         const char *cur_dir_name = context.module_sp->GetFileSpec().GetDirectory().GetCString();
415c9af18a5SGreg Clayton 
416c9af18a5SGreg Clayton         bool match = false;
417c9af18a5SGreg Clayton         if (m_file_name && cur_file_name
418c9af18a5SGreg Clayton             && strstr (cur_file_name, m_file_name) == cur_file_name)
419c9af18a5SGreg Clayton             match = true;
420c9af18a5SGreg Clayton 
421c9af18a5SGreg Clayton         if (match && m_dir_name && cur_dir_name
422c9af18a5SGreg Clayton             && strstr (cur_dir_name, m_dir_name) != cur_dir_name)
423c9af18a5SGreg Clayton             match = false;
424c9af18a5SGreg Clayton 
425c9af18a5SGreg Clayton         if (match)
426c9af18a5SGreg Clayton         {
427c9af18a5SGreg Clayton             m_matches.AppendString (cur_file_name);
428c9af18a5SGreg Clayton         }
429c9af18a5SGreg Clayton     }
430c9af18a5SGreg Clayton     return Searcher::eCallbackReturnContinue;
431c9af18a5SGreg Clayton }
432c9af18a5SGreg Clayton 
433c9af18a5SGreg Clayton size_t
434c9af18a5SGreg Clayton CommandCompletions::ModuleCompleter::DoCompletion (SearchFilter *filter)
435c9af18a5SGreg Clayton {
436c9af18a5SGreg Clayton     filter->Search (*this);
437c9af18a5SGreg Clayton     return m_matches.GetSize();
438c9af18a5SGreg Clayton }
439c9af18a5SGreg Clayton 
440c9af18a5SGreg Clayton 
441c9af18a5SGreg Clayton 
442