1 //===-- CommandObjectTarget.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 #include "lldb/lldb-python.h"
11 
12 #include "CommandObjectTarget.h"
13 
14 // C Includes
15 #include <errno.h>
16 
17 // C++ Includes
18 // Other libraries and framework includes
19 // Project includes
20 #include "lldb/Interpreter/Args.h"
21 #include "lldb/Core/Debugger.h"
22 #include "lldb/Core/InputReader.h"
23 #include "lldb/Core/Module.h"
24 #include "lldb/Core/ModuleSpec.h"
25 #include "lldb/Core/Section.h"
26 #include "lldb/Core/State.h"
27 #include "lldb/Core/Timer.h"
28 #include "lldb/Core/ValueObjectVariable.h"
29 #include "lldb/Host/Symbols.h"
30 #include "lldb/Interpreter/CommandInterpreter.h"
31 #include "lldb/Interpreter/CommandReturnObject.h"
32 #include "lldb/Interpreter/Options.h"
33 #include "lldb/Interpreter/OptionGroupArchitecture.h"
34 #include "lldb/Interpreter/OptionGroupBoolean.h"
35 #include "lldb/Interpreter/OptionGroupFile.h"
36 #include "lldb/Interpreter/OptionGroupFormat.h"
37 #include "lldb/Interpreter/OptionGroupVariable.h"
38 #include "lldb/Interpreter/OptionGroupPlatform.h"
39 #include "lldb/Interpreter/OptionGroupUInt64.h"
40 #include "lldb/Interpreter/OptionGroupUUID.h"
41 #include "lldb/Interpreter/OptionGroupValueObjectDisplay.h"
42 #include "lldb/Symbol/CompileUnit.h"
43 #include "lldb/Symbol/FuncUnwinders.h"
44 #include "lldb/Symbol/LineTable.h"
45 #include "lldb/Symbol/ObjectFile.h"
46 #include "lldb/Symbol/SymbolFile.h"
47 #include "lldb/Symbol/SymbolVendor.h"
48 #include "lldb/Symbol/UnwindPlan.h"
49 #include "lldb/Symbol/VariableList.h"
50 #include "lldb/Target/Process.h"
51 #include "lldb/Target/StackFrame.h"
52 #include "lldb/Target/Thread.h"
53 #include "lldb/Target/ThreadSpec.h"
54 
55 using namespace lldb;
56 using namespace lldb_private;
57 
58 
59 
60 static void
61 DumpTargetInfo (uint32_t target_idx, Target *target, const char *prefix_cstr, bool show_stopped_process_status, Stream &strm)
62 {
63     const ArchSpec &target_arch = target->GetArchitecture();
64 
65     Module *exe_module = target->GetExecutableModulePointer();
66     char exe_path[PATH_MAX];
67     bool exe_valid = false;
68     if (exe_module)
69         exe_valid = exe_module->GetFileSpec().GetPath (exe_path, sizeof(exe_path));
70 
71     if (!exe_valid)
72         ::strcpy (exe_path, "<none>");
73 
74     strm.Printf ("%starget #%u: %s", prefix_cstr ? prefix_cstr : "", target_idx, exe_path);
75 
76     uint32_t properties = 0;
77     if (target_arch.IsValid())
78     {
79         strm.Printf ("%sarch=%s", properties++ > 0 ? ", " : " ( ", target_arch.GetTriple().str().c_str());
80         properties++;
81     }
82     PlatformSP platform_sp (target->GetPlatform());
83     if (platform_sp)
84         strm.Printf ("%splatform=%s", properties++ > 0 ? ", " : " ( ", platform_sp->GetName());
85 
86     ProcessSP process_sp (target->GetProcessSP());
87     bool show_process_status = false;
88     if (process_sp)
89     {
90         lldb::pid_t pid = process_sp->GetID();
91         StateType state = process_sp->GetState();
92         if (show_stopped_process_status)
93             show_process_status = StateIsStoppedState(state, true);
94         const char *state_cstr = StateAsCString (state);
95         if (pid != LLDB_INVALID_PROCESS_ID)
96             strm.Printf ("%spid=%" PRIu64, properties++ > 0 ? ", " : " ( ", pid);
97         strm.Printf ("%sstate=%s", properties++ > 0 ? ", " : " ( ", state_cstr);
98     }
99     if (properties > 0)
100         strm.PutCString (" )\n");
101     else
102         strm.EOL();
103     if (show_process_status)
104     {
105         const bool only_threads_with_stop_reason = true;
106         const uint32_t start_frame = 0;
107         const uint32_t num_frames = 1;
108         const uint32_t num_frames_with_source = 1;
109         process_sp->GetStatus (strm);
110         process_sp->GetThreadStatus (strm,
111                                      only_threads_with_stop_reason,
112                                      start_frame,
113                                      num_frames,
114                                      num_frames_with_source);
115 
116     }
117 }
118 
119 static uint32_t
120 DumpTargetList (TargetList &target_list, bool show_stopped_process_status, Stream &strm)
121 {
122     const uint32_t num_targets = target_list.GetNumTargets();
123     if (num_targets)
124     {
125         TargetSP selected_target_sp (target_list.GetSelectedTarget());
126         strm.PutCString ("Current targets:\n");
127         for (uint32_t i=0; i<num_targets; ++i)
128         {
129             TargetSP target_sp (target_list.GetTargetAtIndex (i));
130             if (target_sp)
131             {
132                 bool is_selected = target_sp.get() == selected_target_sp.get();
133                 DumpTargetInfo (i,
134                                 target_sp.get(),
135                                 is_selected ? "* " : "  ",
136                                 show_stopped_process_status,
137                                 strm);
138             }
139         }
140     }
141     return num_targets;
142 }
143 #pragma mark CommandObjectTargetCreate
144 
145 //-------------------------------------------------------------------------
146 // "target create"
147 //-------------------------------------------------------------------------
148 
149 class CommandObjectTargetCreate : public CommandObjectParsed
150 {
151 public:
152     CommandObjectTargetCreate(CommandInterpreter &interpreter) :
153         CommandObjectParsed (interpreter,
154                              "target create",
155                              "Create a target using the argument as the main executable.",
156                              NULL),
157         m_option_group (interpreter),
158         m_arch_option (),
159         m_platform_options(true), // Do include the "--platform" option in the platform settings by passing true
160         m_core_file (LLDB_OPT_SET_1, false, "core", 'c', 0, eArgTypeFilename, "Fullpath to a core file to use for this target."),
161         m_symbol_file (LLDB_OPT_SET_1, false, "symfile", 's', 0, eArgTypeFilename, "Fullpath to a stand alone debug symbols file for when debug symbols are not in the executable."),
162         m_add_dependents (LLDB_OPT_SET_1, false, "no-dependents", 'd', "Don't load dependent files when creating the target, just add the specified executable.", true, true)
163     {
164         CommandArgumentEntry arg;
165         CommandArgumentData file_arg;
166 
167         // Define the first (and only) variant of this arg.
168             file_arg.arg_type = eArgTypeFilename;
169         file_arg.arg_repetition = eArgRepeatPlain;
170 
171         // There is only one variant this argument could be; put it into the argument entry.
172         arg.push_back (file_arg);
173 
174         // Push the data for the first argument into the m_arguments vector.
175         m_arguments.push_back (arg);
176 
177         m_option_group.Append (&m_arch_option, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
178         m_option_group.Append (&m_platform_options, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
179         m_option_group.Append (&m_core_file, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
180         m_option_group.Append (&m_symbol_file, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
181         m_option_group.Append (&m_add_dependents, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
182         m_option_group.Finalize();
183     }
184 
185     ~CommandObjectTargetCreate ()
186     {
187     }
188 
189     Options *
190     GetOptions ()
191     {
192         return &m_option_group;
193     }
194 
195     virtual int
196     HandleArgumentCompletion (Args &input,
197                               int &cursor_index,
198                               int &cursor_char_position,
199                               OptionElementVector &opt_element_vector,
200                               int match_start_point,
201                               int max_return_elements,
202                               bool &word_complete,
203                               StringList &matches)
204     {
205         std::string completion_str (input.GetArgumentAtIndex(cursor_index));
206         completion_str.erase (cursor_char_position);
207 
208         CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
209                                                              CommandCompletions::eDiskFileCompletion,
210                                                              completion_str.c_str(),
211                                                              match_start_point,
212                                                              max_return_elements,
213                                                              NULL,
214                                                              word_complete,
215                                                              matches);
216         return matches.GetSize();
217     }
218 
219 protected:
220     bool
221     DoExecute (Args& command, CommandReturnObject &result)
222     {
223         const size_t argc = command.GetArgumentCount();
224         FileSpec core_file (m_core_file.GetOptionValue().GetCurrentValue());
225 
226         if (argc == 1 || core_file)
227         {
228             FileSpec symfile (m_symbol_file.GetOptionValue().GetCurrentValue());
229             if (symfile)
230             {
231                 if (!symfile.Exists())
232                 {
233                     char symfile_path[PATH_MAX];
234                     symfile.GetPath(symfile_path, sizeof(symfile_path));
235                     result.AppendErrorWithFormat("invalid symbol file path '%s'", symfile_path);
236                     result.SetStatus (eReturnStatusFailed);
237                     return false;
238                 }
239             }
240 
241             const char *file_path = command.GetArgumentAtIndex(0);
242             Timer scoped_timer(__PRETTY_FUNCTION__, "(lldb) target create '%s'", file_path);
243             TargetSP target_sp;
244             Debugger &debugger = m_interpreter.GetDebugger();
245             const char *arch_cstr = m_arch_option.GetArchitectureName();
246             const bool get_dependent_files = m_add_dependents.GetOptionValue().GetCurrentValue();
247             Error error (debugger.GetTargetList().CreateTarget (debugger,
248                                                                 file_path,
249                                                                 arch_cstr,
250                                                                 get_dependent_files,
251                                                                 &m_platform_options,
252                                                                 target_sp));
253 
254             if (target_sp)
255             {
256                 if (symfile)
257                 {
258                     ModuleSP module_sp (target_sp->GetExecutableModule());
259                     if (module_sp)
260                         module_sp->SetSymbolFileFileSpec(symfile);
261                 }
262 
263                 debugger.GetTargetList().SetSelectedTarget(target_sp.get());
264                 if (core_file)
265                 {
266                     char core_path[PATH_MAX];
267                     core_file.GetPath(core_path, sizeof(core_path));
268                     if (core_file.Exists())
269                     {
270                         FileSpec core_file_dir;
271                         core_file_dir.GetDirectory() = core_file.GetDirectory();
272                         target_sp->GetExecutableSearchPaths ().Append (core_file_dir);
273 
274                         ProcessSP process_sp (target_sp->CreateProcess (m_interpreter.GetDebugger().GetListener(), NULL, &core_file));
275 
276                         if (process_sp)
277                         {
278                             // Seems wierd that we Launch a core file, but that is
279                             // what we do!
280                             error = process_sp->LoadCore();
281 
282                             if (error.Fail())
283                             {
284                                 result.AppendError(error.AsCString("can't find plug-in for core file"));
285                                 result.SetStatus (eReturnStatusFailed);
286                                 return false;
287                             }
288                             else
289                             {
290                                 result.AppendMessageWithFormat ("Core file '%s' (%s) was loaded.\n", core_path, target_sp->GetArchitecture().GetArchitectureName());
291                                 result.SetStatus (eReturnStatusSuccessFinishNoResult);
292                             }
293                         }
294                         else
295                         {
296                             result.AppendErrorWithFormat ("Unable to find process plug-in for core file '%s'\n", core_path);
297                             result.SetStatus (eReturnStatusFailed);
298                         }
299                     }
300                     else
301                     {
302                         result.AppendErrorWithFormat ("Core file '%s' does not exist\n", core_path);
303                         result.SetStatus (eReturnStatusFailed);
304                     }
305                 }
306                 else
307                 {
308                     result.AppendMessageWithFormat ("Current executable set to '%s' (%s).\n", file_path, target_sp->GetArchitecture().GetArchitectureName());
309                     result.SetStatus (eReturnStatusSuccessFinishNoResult);
310                 }
311             }
312             else
313             {
314                 result.AppendError(error.AsCString());
315                 result.SetStatus (eReturnStatusFailed);
316             }
317         }
318         else
319         {
320             result.AppendErrorWithFormat("'%s' takes exactly one executable path argument, or use the --core-file option.\n", m_cmd_name.c_str());
321             result.SetStatus (eReturnStatusFailed);
322         }
323         return result.Succeeded();
324 
325     }
326 
327 private:
328     OptionGroupOptions m_option_group;
329     OptionGroupArchitecture m_arch_option;
330     OptionGroupPlatform m_platform_options;
331     OptionGroupFile m_core_file;
332     OptionGroupFile m_symbol_file;
333     OptionGroupBoolean m_add_dependents;
334 };
335 
336 #pragma mark CommandObjectTargetList
337 
338 //----------------------------------------------------------------------
339 // "target list"
340 //----------------------------------------------------------------------
341 
342 class CommandObjectTargetList : public CommandObjectParsed
343 {
344 public:
345     CommandObjectTargetList (CommandInterpreter &interpreter) :
346         CommandObjectParsed (interpreter,
347                              "target list",
348                              "List all current targets in the current debug session.",
349                              NULL,
350                              0)
351     {
352     }
353 
354     virtual
355     ~CommandObjectTargetList ()
356     {
357     }
358 
359 protected:
360     virtual bool
361     DoExecute (Args& args, CommandReturnObject &result)
362     {
363         if (args.GetArgumentCount() == 0)
364         {
365             Stream &strm = result.GetOutputStream();
366 
367             bool show_stopped_process_status = false;
368             if (DumpTargetList (m_interpreter.GetDebugger().GetTargetList(), show_stopped_process_status, strm) == 0)
369             {
370                 strm.PutCString ("No targets.\n");
371             }
372             result.SetStatus (eReturnStatusSuccessFinishResult);
373         }
374         else
375         {
376             result.AppendError ("the 'target list' command takes no arguments\n");
377             result.SetStatus (eReturnStatusFailed);
378         }
379         return result.Succeeded();
380     }
381 };
382 
383 
384 #pragma mark CommandObjectTargetSelect
385 
386 //----------------------------------------------------------------------
387 // "target select"
388 //----------------------------------------------------------------------
389 
390 class CommandObjectTargetSelect : public CommandObjectParsed
391 {
392 public:
393     CommandObjectTargetSelect (CommandInterpreter &interpreter) :
394         CommandObjectParsed (interpreter,
395                              "target select",
396                              "Select a target as the current target by target index.",
397                              NULL,
398                              0)
399     {
400     }
401 
402     virtual
403     ~CommandObjectTargetSelect ()
404     {
405     }
406 
407 protected:
408     virtual bool
409     DoExecute (Args& args, CommandReturnObject &result)
410     {
411         if (args.GetArgumentCount() == 1)
412         {
413             bool success = false;
414             const char *target_idx_arg = args.GetArgumentAtIndex(0);
415             uint32_t target_idx = Args::StringToUInt32 (target_idx_arg, UINT32_MAX, 0, &success);
416             if (success)
417             {
418                 TargetList &target_list = m_interpreter.GetDebugger().GetTargetList();
419                 const uint32_t num_targets = target_list.GetNumTargets();
420                 if (target_idx < num_targets)
421                 {
422                     TargetSP target_sp (target_list.GetTargetAtIndex (target_idx));
423                     if (target_sp)
424                     {
425                         Stream &strm = result.GetOutputStream();
426                         target_list.SetSelectedTarget (target_sp.get());
427                         bool show_stopped_process_status = false;
428                         DumpTargetList (target_list, show_stopped_process_status, strm);
429                         result.SetStatus (eReturnStatusSuccessFinishResult);
430                     }
431                     else
432                     {
433                         result.AppendErrorWithFormat ("target #%u is NULL in target list\n", target_idx);
434                         result.SetStatus (eReturnStatusFailed);
435                     }
436                 }
437                 else
438                 {
439                     result.AppendErrorWithFormat ("index %u is out of range, valid target indexes are 0 - %u\n",
440                                                   target_idx,
441                                                   num_targets - 1);
442                     result.SetStatus (eReturnStatusFailed);
443                 }
444             }
445             else
446             {
447                 result.AppendErrorWithFormat("invalid index string value '%s'\n", target_idx_arg);
448                 result.SetStatus (eReturnStatusFailed);
449             }
450         }
451         else
452         {
453             result.AppendError ("'target select' takes a single argument: a target index\n");
454             result.SetStatus (eReturnStatusFailed);
455         }
456         return result.Succeeded();
457     }
458 };
459 
460 #pragma mark CommandObjectTargetSelect
461 
462 //----------------------------------------------------------------------
463 // "target delete"
464 //----------------------------------------------------------------------
465 
466 class CommandObjectTargetDelete : public CommandObjectParsed
467 {
468 public:
469     CommandObjectTargetDelete (CommandInterpreter &interpreter) :
470         CommandObjectParsed (interpreter,
471                              "target delete",
472                              "Delete one or more targets by target index.",
473                              NULL,
474                              0),
475         m_option_group (interpreter),
476         m_cleanup_option (LLDB_OPT_SET_1, false, "clean", 'c', "Perform extra cleanup to minimize memory consumption after deleting the target.", false, false)
477     {
478         m_option_group.Append (&m_cleanup_option, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
479         m_option_group.Finalize();
480     }
481 
482     virtual
483     ~CommandObjectTargetDelete ()
484     {
485     }
486 
487     Options *
488     GetOptions ()
489     {
490         return &m_option_group;
491     }
492 
493 protected:
494     virtual bool
495     DoExecute (Args& args, CommandReturnObject &result)
496     {
497         const size_t argc = args.GetArgumentCount();
498         std::vector<TargetSP> delete_target_list;
499         TargetList &target_list = m_interpreter.GetDebugger().GetTargetList();
500         bool success = true;
501         TargetSP target_sp;
502         if (argc > 0)
503         {
504             const uint32_t num_targets = target_list.GetNumTargets();
505             // Bail out if don't have any targets.
506             if (num_targets == 0) {
507                 result.AppendError("no targets to delete");
508                 result.SetStatus(eReturnStatusFailed);
509                 success = false;
510             }
511 
512             for (uint32_t arg_idx = 0; success && arg_idx < argc; ++arg_idx)
513             {
514                 const char *target_idx_arg = args.GetArgumentAtIndex(arg_idx);
515                 uint32_t target_idx = Args::StringToUInt32 (target_idx_arg, UINT32_MAX, 0, &success);
516                 if (success)
517                 {
518                     if (target_idx < num_targets)
519                     {
520                         target_sp = target_list.GetTargetAtIndex (target_idx);
521                         if (target_sp)
522                         {
523                             delete_target_list.push_back (target_sp);
524                             continue;
525                         }
526                     }
527                     if (num_targets > 1)
528                         result.AppendErrorWithFormat ("target index %u is out of range, valid target indexes are 0 - %u\n",
529                                                       target_idx,
530                                                       num_targets - 1);
531                     else
532                         result.AppendErrorWithFormat("target index %u is out of range, the only valid index is 0\n",
533                                                     target_idx);
534 
535                     result.SetStatus (eReturnStatusFailed);
536                     success = false;
537                 }
538                 else
539                 {
540                     result.AppendErrorWithFormat("invalid target index '%s'\n", target_idx_arg);
541                     result.SetStatus (eReturnStatusFailed);
542                     success = false;
543                 }
544             }
545 
546         }
547         else
548         {
549             target_sp = target_list.GetSelectedTarget();
550             if (target_sp)
551             {
552                 delete_target_list.push_back (target_sp);
553             }
554             else
555             {
556                 result.AppendErrorWithFormat("no target is currently selected\n");
557                 result.SetStatus (eReturnStatusFailed);
558                 success = false;
559             }
560         }
561         if (success)
562         {
563             const size_t num_targets_to_delete = delete_target_list.size();
564             for (size_t idx = 0; idx < num_targets_to_delete; ++idx)
565             {
566                 target_sp = delete_target_list[idx];
567                 target_list.DeleteTarget(target_sp);
568                 target_sp->Destroy();
569             }
570             // If "--clean" was specified, prune any orphaned shared modules from
571             // the global shared module list
572             if (m_cleanup_option.GetOptionValue ())
573             {
574                 const bool mandatory = true;
575                 ModuleList::RemoveOrphanSharedModules(mandatory);
576             }
577             result.GetOutputStream().Printf("%u targets deleted.\n", (uint32_t)num_targets_to_delete);
578             result.SetStatus(eReturnStatusSuccessFinishResult);
579         }
580 
581         return result.Succeeded();
582     }
583 
584     OptionGroupOptions m_option_group;
585     OptionGroupBoolean m_cleanup_option;
586 };
587 
588 
589 #pragma mark CommandObjectTargetVariable
590 
591 //----------------------------------------------------------------------
592 // "target variable"
593 //----------------------------------------------------------------------
594 
595 class CommandObjectTargetVariable : public CommandObjectParsed
596 {
597 public:
598     CommandObjectTargetVariable (CommandInterpreter &interpreter) :
599         CommandObjectParsed (interpreter,
600                              "target variable",
601                              "Read global variable(s) prior to, or while running your binary.",
602                              NULL,
603                              eFlagRequiresTarget),
604         m_option_group (interpreter),
605         m_option_variable (false), // Don't include frame options
606         m_option_format (eFormatDefault),
607         m_option_compile_units    (LLDB_OPT_SET_1, false, "file", 'file', 0, eArgTypeFilename, "A basename or fullpath to a file that contains global variables. This option can be specified multiple times."),
608         m_option_shared_libraries (LLDB_OPT_SET_1, false, "shlib",'shlb', 0, eArgTypeFilename, "A basename or fullpath to a shared library to use in the search for global variables. This option can be specified multiple times."),
609         m_varobj_options()
610     {
611         CommandArgumentEntry arg;
612         CommandArgumentData var_name_arg;
613 
614         // Define the first (and only) variant of this arg.
615         var_name_arg.arg_type = eArgTypeVarName;
616         var_name_arg.arg_repetition = eArgRepeatPlus;
617 
618         // There is only one variant this argument could be; put it into the argument entry.
619         arg.push_back (var_name_arg);
620 
621         // Push the data for the first argument into the m_arguments vector.
622         m_arguments.push_back (arg);
623 
624         m_option_group.Append (&m_varobj_options, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
625         m_option_group.Append (&m_option_variable, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
626         m_option_group.Append (&m_option_format, OptionGroupFormat::OPTION_GROUP_FORMAT | OptionGroupFormat::OPTION_GROUP_GDB_FMT, LLDB_OPT_SET_1);
627         m_option_group.Append (&m_option_compile_units, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
628         m_option_group.Append (&m_option_shared_libraries, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
629         m_option_group.Finalize();
630     }
631 
632     virtual
633     ~CommandObjectTargetVariable ()
634     {
635     }
636 
637     void
638     DumpValueObject (Stream &s, VariableSP &var_sp, ValueObjectSP &valobj_sp, const char *root_name)
639     {
640         ValueObject::DumpValueObjectOptions options(m_varobj_options.GetAsDumpOptions());
641 
642         switch (var_sp->GetScope())
643         {
644             case eValueTypeVariableGlobal:
645                 if (m_option_variable.show_scope)
646                     s.PutCString("GLOBAL: ");
647                 break;
648 
649             case eValueTypeVariableStatic:
650                 if (m_option_variable.show_scope)
651                     s.PutCString("STATIC: ");
652                 break;
653 
654             case eValueTypeVariableArgument:
655                 if (m_option_variable.show_scope)
656                     s.PutCString("   ARG: ");
657                 break;
658 
659             case eValueTypeVariableLocal:
660                 if (m_option_variable.show_scope)
661                     s.PutCString(" LOCAL: ");
662                 break;
663 
664             default:
665                 break;
666         }
667 
668         if (m_option_variable.show_decl)
669         {
670             bool show_fullpaths = false;
671             bool show_module = true;
672             if (var_sp->DumpDeclaration(&s, show_fullpaths, show_module))
673                 s.PutCString (": ");
674         }
675 
676         const Format format = m_option_format.GetFormat();
677         if (format != eFormatDefault)
678             options.SetFormat(format);
679 
680         options.SetRootValueObjectName(root_name);
681 
682         ValueObject::DumpValueObject (s,
683                                       valobj_sp.get(),
684                                       options);
685 
686     }
687 
688 
689     static size_t GetVariableCallback (void *baton,
690                                        const char *name,
691                                        VariableList &variable_list)
692     {
693         Target *target = static_cast<Target *>(baton);
694         if (target)
695         {
696             return target->GetImages().FindGlobalVariables (ConstString(name),
697                                                             true,
698                                                             UINT32_MAX,
699                                                             variable_list);
700         }
701         return 0;
702     }
703 
704 
705 
706     Options *
707     GetOptions ()
708     {
709         return &m_option_group;
710     }
711 
712 protected:
713 
714     void
715     DumpGlobalVariableList(const ExecutionContext &exe_ctx, const SymbolContext &sc, const VariableList &variable_list, Stream &s)
716     {
717         size_t count = variable_list.GetSize();
718         if (count > 0)
719         {
720             if (sc.module_sp)
721             {
722                 if (sc.comp_unit)
723                 {
724                     s.Printf ("Global variables for %s in %s:\n",
725                               sc.comp_unit->GetPath().c_str(),
726                               sc.module_sp->GetFileSpec().GetPath().c_str());
727                 }
728                 else
729                 {
730                     s.Printf ("Global variables for %s\n",
731                               sc.module_sp->GetFileSpec().GetPath().c_str());
732                 }
733             }
734             else if (sc.comp_unit)
735             {
736                 s.Printf ("Global variables for %s\n",
737                           sc.comp_unit->GetPath().c_str());
738             }
739 
740             for (uint32_t i=0; i<count; ++i)
741             {
742                 VariableSP var_sp (variable_list.GetVariableAtIndex(i));
743                 if (var_sp)
744                 {
745                     ValueObjectSP valobj_sp (ValueObjectVariable::Create (exe_ctx.GetBestExecutionContextScope(), var_sp));
746 
747                     if (valobj_sp)
748                         DumpValueObject (s, var_sp, valobj_sp, var_sp->GetName().GetCString());
749                 }
750             }
751         }
752 
753     }
754     virtual bool
755     DoExecute (Args& args, CommandReturnObject &result)
756     {
757         Target *target = m_exe_ctx.GetTargetPtr();
758         const size_t argc = args.GetArgumentCount();
759         Stream &s = result.GetOutputStream();
760 
761         if (argc > 0)
762         {
763 
764             for (size_t idx = 0; idx < argc; ++idx)
765             {
766                 VariableList variable_list;
767                 ValueObjectList valobj_list;
768 
769                 const char *arg = args.GetArgumentAtIndex(idx);
770                 size_t matches = 0;
771                 bool use_var_name = false;
772                 if (m_option_variable.use_regex)
773                 {
774                     RegularExpression regex(arg);
775                     if (!regex.IsValid ())
776                     {
777                         result.GetErrorStream().Printf ("error: invalid regular expression: '%s'\n", arg);
778                         result.SetStatus (eReturnStatusFailed);
779                         return false;
780                     }
781                     use_var_name = true;
782                     matches = target->GetImages().FindGlobalVariables (regex,
783                                                                        true,
784                                                                        UINT32_MAX,
785                                                                        variable_list);
786                 }
787                 else
788                 {
789                     Error error (Variable::GetValuesForVariableExpressionPath (arg,
790                                                                                m_exe_ctx.GetBestExecutionContextScope(),
791                                                                                GetVariableCallback,
792                                                                                target,
793                                                                                variable_list,
794                                                                                valobj_list));
795                     matches = variable_list.GetSize();
796                 }
797 
798                 if (matches == 0)
799                 {
800                     result.GetErrorStream().Printf ("error: can't find global variable '%s'\n", arg);
801                     result.SetStatus (eReturnStatusFailed);
802                     return false;
803                 }
804                 else
805                 {
806                     for (uint32_t global_idx=0; global_idx<matches; ++global_idx)
807                     {
808                         VariableSP var_sp (variable_list.GetVariableAtIndex(global_idx));
809                         if (var_sp)
810                         {
811                             ValueObjectSP valobj_sp (valobj_list.GetValueObjectAtIndex(global_idx));
812                             if (!valobj_sp)
813                                 valobj_sp = ValueObjectVariable::Create (m_exe_ctx.GetBestExecutionContextScope(), var_sp);
814 
815                             if (valobj_sp)
816                                 DumpValueObject (s, var_sp, valobj_sp, use_var_name ? var_sp->GetName().GetCString() : arg);
817                         }
818                     }
819                 }
820             }
821         }
822         else
823         {
824             const FileSpecList &compile_units = m_option_compile_units.GetOptionValue().GetCurrentValue();
825             const FileSpecList &shlibs = m_option_shared_libraries.GetOptionValue().GetCurrentValue();
826             SymbolContextList sc_list;
827             const size_t num_compile_units = compile_units.GetSize();
828             const size_t num_shlibs = shlibs.GetSize();
829             if (num_compile_units == 0 && num_shlibs == 0)
830             {
831                 bool success = false;
832                 StackFrame *frame = m_exe_ctx.GetFramePtr();
833                 CompileUnit *comp_unit = NULL;
834                 if (frame)
835                 {
836                     SymbolContext sc = frame->GetSymbolContext (eSymbolContextCompUnit);
837                     if (sc.comp_unit)
838                     {
839                         const bool can_create = true;
840                         VariableListSP comp_unit_varlist_sp (sc.comp_unit->GetVariableList(can_create));
841                         if (comp_unit_varlist_sp)
842                         {
843                             size_t count = comp_unit_varlist_sp->GetSize();
844                             if (count > 0)
845                             {
846                                 DumpGlobalVariableList(m_exe_ctx, sc, *comp_unit_varlist_sp, s);
847                                 success = true;
848                             }
849                         }
850                     }
851                 }
852                 if (!success)
853                 {
854                     if (frame)
855                     {
856                         if (comp_unit)
857                             result.AppendErrorWithFormat ("no global variables in current compile unit: %s\n",
858                                                           comp_unit->GetPath().c_str());
859                         else
860                             result.AppendErrorWithFormat ("no debug information for frame %u\n", frame->GetFrameIndex());
861                     }
862                     else
863                         result.AppendError ("'target variable' takes one or more global variable names as arguments\n");
864                     result.SetStatus (eReturnStatusFailed);
865                 }
866             }
867             else
868             {
869                 SymbolContextList sc_list;
870                 const bool append = true;
871                 // We have one or more compile unit or shlib
872                 if (num_shlibs > 0)
873                 {
874                     for (size_t shlib_idx=0; shlib_idx<num_shlibs; ++shlib_idx)
875                     {
876                         const FileSpec module_file(shlibs.GetFileSpecAtIndex(shlib_idx));
877                         ModuleSpec module_spec (module_file);
878 
879                         ModuleSP module_sp (target->GetImages().FindFirstModule(module_spec));
880                         if (module_sp)
881                         {
882                             if (num_compile_units > 0)
883                             {
884                                 for (size_t cu_idx=0; cu_idx<num_compile_units; ++cu_idx)
885                                     module_sp->FindCompileUnits(compile_units.GetFileSpecAtIndex(cu_idx), append, sc_list);
886                             }
887                             else
888                             {
889                                 SymbolContext sc;
890                                 sc.module_sp = module_sp;
891                                 sc_list.Append(sc);
892                             }
893                         }
894                         else
895                         {
896                             // Didn't find matching shlib/module in target...
897                             result.AppendErrorWithFormat ("target doesn't contain the specified shared library: %s\n",
898                                                           module_file.GetPath().c_str());
899                         }
900                     }
901                 }
902                 else
903                 {
904                     // No shared libraries, we just want to find globals for the compile units files that were specified
905                     for (size_t cu_idx=0; cu_idx<num_compile_units; ++cu_idx)
906                         target->GetImages().FindCompileUnits(compile_units.GetFileSpecAtIndex(cu_idx), append, sc_list);
907                 }
908 
909                 const uint32_t num_scs = sc_list.GetSize();
910                 if (num_scs > 0)
911                 {
912                     SymbolContext sc;
913                     for (uint32_t sc_idx=0; sc_idx<num_scs; ++sc_idx)
914                     {
915                         if (sc_list.GetContextAtIndex(sc_idx, sc))
916                         {
917                             if (sc.comp_unit)
918                             {
919                                 const bool can_create = true;
920                                 VariableListSP comp_unit_varlist_sp (sc.comp_unit->GetVariableList(can_create));
921                                 if (comp_unit_varlist_sp)
922                                     DumpGlobalVariableList(m_exe_ctx, sc, *comp_unit_varlist_sp, s);
923                             }
924                             else if (sc.module_sp)
925                             {
926                                 // Get all global variables for this module
927                                 lldb_private::RegularExpression all_globals_regex("."); // Any global with at least one character
928                                 VariableList variable_list;
929                                 sc.module_sp->FindGlobalVariables(all_globals_regex, append, UINT32_MAX, variable_list);
930                                 DumpGlobalVariableList(m_exe_ctx, sc, variable_list, s);
931                             }
932                         }
933                     }
934                 }
935             }
936         }
937 
938         if (m_interpreter.TruncationWarningNecessary())
939         {
940             result.GetOutputStream().Printf(m_interpreter.TruncationWarningText(),
941                                             m_cmd_name.c_str());
942             m_interpreter.TruncationWarningGiven();
943         }
944 
945         return result.Succeeded();
946     }
947 
948     OptionGroupOptions m_option_group;
949     OptionGroupVariable m_option_variable;
950     OptionGroupFormat m_option_format;
951     OptionGroupFileList m_option_compile_units;
952     OptionGroupFileList m_option_shared_libraries;
953     OptionGroupValueObjectDisplay m_varobj_options;
954 
955 };
956 
957 
958 #pragma mark CommandObjectTargetModulesSearchPathsAdd
959 
960 class CommandObjectTargetModulesSearchPathsAdd : public CommandObjectParsed
961 {
962 public:
963 
964     CommandObjectTargetModulesSearchPathsAdd (CommandInterpreter &interpreter) :
965         CommandObjectParsed (interpreter,
966                              "target modules search-paths add",
967                              "Add new image search paths substitution pairs to the current target.",
968                              NULL)
969     {
970         CommandArgumentEntry arg;
971         CommandArgumentData old_prefix_arg;
972         CommandArgumentData new_prefix_arg;
973 
974         // Define the first variant of this arg pair.
975         old_prefix_arg.arg_type = eArgTypeOldPathPrefix;
976         old_prefix_arg.arg_repetition = eArgRepeatPairPlus;
977 
978         // Define the first variant of this arg pair.
979         new_prefix_arg.arg_type = eArgTypeNewPathPrefix;
980         new_prefix_arg.arg_repetition = eArgRepeatPairPlus;
981 
982         // There are two required arguments that must always occur together, i.e. an argument "pair".  Because they
983         // must always occur together, they are treated as two variants of one argument rather than two independent
984         // arguments.  Push them both into the first argument position for m_arguments...
985 
986         arg.push_back (old_prefix_arg);
987         arg.push_back (new_prefix_arg);
988 
989         m_arguments.push_back (arg);
990     }
991 
992     ~CommandObjectTargetModulesSearchPathsAdd ()
993     {
994     }
995 
996 protected:
997     bool
998     DoExecute (Args& command,
999              CommandReturnObject &result)
1000     {
1001         Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
1002         if (target)
1003         {
1004             const size_t argc = command.GetArgumentCount();
1005             if (argc & 1)
1006             {
1007                 result.AppendError ("add requires an even number of arguments\n");
1008                 result.SetStatus (eReturnStatusFailed);
1009             }
1010             else
1011             {
1012                 for (size_t i=0; i<argc; i+=2)
1013                 {
1014                     const char *from = command.GetArgumentAtIndex(i);
1015                     const char *to = command.GetArgumentAtIndex(i+1);
1016 
1017                     if (from[0] && to[0])
1018                     {
1019                         bool last_pair = ((argc - i) == 2);
1020                         target->GetImageSearchPathList().Append (ConstString(from),
1021                                                                  ConstString(to),
1022                                                                  last_pair); // Notify if this is the last pair
1023                         result.SetStatus (eReturnStatusSuccessFinishNoResult);
1024                     }
1025                     else
1026                     {
1027                         if (from[0])
1028                             result.AppendError ("<path-prefix> can't be empty\n");
1029                         else
1030                             result.AppendError ("<new-path-prefix> can't be empty\n");
1031                         result.SetStatus (eReturnStatusFailed);
1032                     }
1033                 }
1034             }
1035         }
1036         else
1037         {
1038             result.AppendError ("invalid target\n");
1039             result.SetStatus (eReturnStatusFailed);
1040         }
1041         return result.Succeeded();
1042     }
1043 };
1044 
1045 #pragma mark CommandObjectTargetModulesSearchPathsClear
1046 
1047 class CommandObjectTargetModulesSearchPathsClear : public CommandObjectParsed
1048 {
1049 public:
1050 
1051     CommandObjectTargetModulesSearchPathsClear (CommandInterpreter &interpreter) :
1052         CommandObjectParsed (interpreter,
1053                              "target modules search-paths clear",
1054                              "Clear all current image search path substitution pairs from the current target.",
1055                              "target modules search-paths clear")
1056     {
1057     }
1058 
1059     ~CommandObjectTargetModulesSearchPathsClear ()
1060     {
1061     }
1062 
1063 protected:
1064     bool
1065     DoExecute (Args& command,
1066              CommandReturnObject &result)
1067     {
1068         Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
1069         if (target)
1070         {
1071             bool notify = true;
1072             target->GetImageSearchPathList().Clear(notify);
1073             result.SetStatus (eReturnStatusSuccessFinishNoResult);
1074         }
1075         else
1076         {
1077             result.AppendError ("invalid target\n");
1078             result.SetStatus (eReturnStatusFailed);
1079         }
1080         return result.Succeeded();
1081     }
1082 };
1083 
1084 #pragma mark CommandObjectTargetModulesSearchPathsInsert
1085 
1086 class CommandObjectTargetModulesSearchPathsInsert : public CommandObjectParsed
1087 {
1088 public:
1089 
1090     CommandObjectTargetModulesSearchPathsInsert (CommandInterpreter &interpreter) :
1091         CommandObjectParsed (interpreter,
1092                              "target modules search-paths insert",
1093                              "Insert a new image search path substitution pair into the current target at the specified index.",
1094                              NULL)
1095     {
1096         CommandArgumentEntry arg1;
1097         CommandArgumentEntry arg2;
1098         CommandArgumentData index_arg;
1099         CommandArgumentData old_prefix_arg;
1100         CommandArgumentData new_prefix_arg;
1101 
1102         // Define the first and only variant of this arg.
1103         index_arg.arg_type = eArgTypeIndex;
1104         index_arg.arg_repetition = eArgRepeatPlain;
1105 
1106         // Put the one and only variant into the first arg for m_arguments:
1107         arg1.push_back (index_arg);
1108 
1109         // Define the first variant of this arg pair.
1110         old_prefix_arg.arg_type = eArgTypeOldPathPrefix;
1111         old_prefix_arg.arg_repetition = eArgRepeatPairPlus;
1112 
1113         // Define the first variant of this arg pair.
1114         new_prefix_arg.arg_type = eArgTypeNewPathPrefix;
1115         new_prefix_arg.arg_repetition = eArgRepeatPairPlus;
1116 
1117         // There are two required arguments that must always occur together, i.e. an argument "pair".  Because they
1118         // must always occur together, they are treated as two variants of one argument rather than two independent
1119         // arguments.  Push them both into the same argument position for m_arguments...
1120 
1121         arg2.push_back (old_prefix_arg);
1122         arg2.push_back (new_prefix_arg);
1123 
1124         // Add arguments to m_arguments.
1125         m_arguments.push_back (arg1);
1126         m_arguments.push_back (arg2);
1127     }
1128 
1129     ~CommandObjectTargetModulesSearchPathsInsert ()
1130     {
1131     }
1132 
1133 protected:
1134     bool
1135     DoExecute (Args& command,
1136              CommandReturnObject &result)
1137     {
1138         Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
1139         if (target)
1140         {
1141             size_t argc = command.GetArgumentCount();
1142             // check for at least 3 arguments and an odd nubmer of parameters
1143             if (argc >= 3 && argc & 1)
1144             {
1145                 bool success = false;
1146 
1147                 uint32_t insert_idx = Args::StringToUInt32(command.GetArgumentAtIndex(0), UINT32_MAX, 0, &success);
1148 
1149                 if (!success)
1150                 {
1151                     result.AppendErrorWithFormat("<index> parameter is not an integer: '%s'.\n", command.GetArgumentAtIndex(0));
1152                     result.SetStatus (eReturnStatusFailed);
1153                     return result.Succeeded();
1154                 }
1155 
1156                 // shift off the index
1157                 command.Shift();
1158                 argc = command.GetArgumentCount();
1159 
1160                 for (uint32_t i=0; i<argc; i+=2, ++insert_idx)
1161                 {
1162                     const char *from = command.GetArgumentAtIndex(i);
1163                     const char *to = command.GetArgumentAtIndex(i+1);
1164 
1165                     if (from[0] && to[0])
1166                     {
1167                         bool last_pair = ((argc - i) == 2);
1168                         target->GetImageSearchPathList().Insert (ConstString(from),
1169                                                                  ConstString(to),
1170                                                                  insert_idx,
1171                                                                  last_pair);
1172                         result.SetStatus (eReturnStatusSuccessFinishNoResult);
1173                     }
1174                     else
1175                     {
1176                         if (from[0])
1177                             result.AppendError ("<path-prefix> can't be empty\n");
1178                         else
1179                             result.AppendError ("<new-path-prefix> can't be empty\n");
1180                         result.SetStatus (eReturnStatusFailed);
1181                         return false;
1182                     }
1183                 }
1184             }
1185             else
1186             {
1187                 result.AppendError ("insert requires at least three arguments\n");
1188                 result.SetStatus (eReturnStatusFailed);
1189                 return result.Succeeded();
1190             }
1191 
1192         }
1193         else
1194         {
1195             result.AppendError ("invalid target\n");
1196             result.SetStatus (eReturnStatusFailed);
1197         }
1198         return result.Succeeded();
1199     }
1200 };
1201 
1202 
1203 #pragma mark CommandObjectTargetModulesSearchPathsList
1204 
1205 
1206 class CommandObjectTargetModulesSearchPathsList : public CommandObjectParsed
1207 {
1208 public:
1209 
1210     CommandObjectTargetModulesSearchPathsList (CommandInterpreter &interpreter) :
1211         CommandObjectParsed (interpreter,
1212                              "target modules search-paths list",
1213                              "List all current image search path substitution pairs in the current target.",
1214                              "target modules search-paths list")
1215     {
1216     }
1217 
1218     ~CommandObjectTargetModulesSearchPathsList ()
1219     {
1220     }
1221 
1222 protected:
1223     bool
1224     DoExecute (Args& command,
1225              CommandReturnObject &result)
1226     {
1227         Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
1228         if (target)
1229         {
1230             if (command.GetArgumentCount() != 0)
1231             {
1232                 result.AppendError ("list takes no arguments\n");
1233                 result.SetStatus (eReturnStatusFailed);
1234                 return result.Succeeded();
1235             }
1236 
1237             target->GetImageSearchPathList().Dump(&result.GetOutputStream());
1238             result.SetStatus (eReturnStatusSuccessFinishResult);
1239         }
1240         else
1241         {
1242             result.AppendError ("invalid target\n");
1243             result.SetStatus (eReturnStatusFailed);
1244         }
1245         return result.Succeeded();
1246     }
1247 };
1248 
1249 #pragma mark CommandObjectTargetModulesSearchPathsQuery
1250 
1251 class CommandObjectTargetModulesSearchPathsQuery : public CommandObjectParsed
1252 {
1253 public:
1254 
1255     CommandObjectTargetModulesSearchPathsQuery (CommandInterpreter &interpreter) :
1256         CommandObjectParsed (interpreter,
1257                              "target modules search-paths query",
1258                              "Transform a path using the first applicable image search path.",
1259                              NULL)
1260     {
1261         CommandArgumentEntry arg;
1262         CommandArgumentData path_arg;
1263 
1264         // Define the first (and only) variant of this arg.
1265         path_arg.arg_type = eArgTypeDirectoryName;
1266         path_arg.arg_repetition = eArgRepeatPlain;
1267 
1268         // There is only one variant this argument could be; put it into the argument entry.
1269         arg.push_back (path_arg);
1270 
1271         // Push the data for the first argument into the m_arguments vector.
1272         m_arguments.push_back (arg);
1273     }
1274 
1275     ~CommandObjectTargetModulesSearchPathsQuery ()
1276     {
1277     }
1278 
1279 protected:
1280     bool
1281     DoExecute (Args& command,
1282              CommandReturnObject &result)
1283     {
1284         Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
1285         if (target)
1286         {
1287             if (command.GetArgumentCount() != 1)
1288             {
1289                 result.AppendError ("query requires one argument\n");
1290                 result.SetStatus (eReturnStatusFailed);
1291                 return result.Succeeded();
1292             }
1293 
1294             ConstString orig(command.GetArgumentAtIndex(0));
1295             ConstString transformed;
1296             if (target->GetImageSearchPathList().RemapPath(orig, transformed))
1297                 result.GetOutputStream().Printf("%s\n", transformed.GetCString());
1298             else
1299                 result.GetOutputStream().Printf("%s\n", orig.GetCString());
1300 
1301             result.SetStatus (eReturnStatusSuccessFinishResult);
1302         }
1303         else
1304         {
1305             result.AppendError ("invalid target\n");
1306             result.SetStatus (eReturnStatusFailed);
1307         }
1308         return result.Succeeded();
1309     }
1310 };
1311 
1312 //----------------------------------------------------------------------
1313 // Static Helper functions
1314 //----------------------------------------------------------------------
1315 static void
1316 DumpModuleArchitecture (Stream &strm, Module *module, bool full_triple, uint32_t width)
1317 {
1318     if (module)
1319     {
1320         const char *arch_cstr;
1321         if (full_triple)
1322             arch_cstr = module->GetArchitecture().GetTriple().str().c_str();
1323         else
1324             arch_cstr = module->GetArchitecture().GetArchitectureName();
1325         if (width)
1326             strm.Printf("%-*s", width, arch_cstr);
1327         else
1328             strm.PutCString(arch_cstr);
1329     }
1330 }
1331 
1332 static void
1333 DumpModuleUUID (Stream &strm, Module *module)
1334 {
1335     if (module && module->GetUUID().IsValid())
1336         module->GetUUID().Dump (&strm);
1337     else
1338         strm.PutCString("                                    ");
1339 }
1340 
1341 static uint32_t
1342 DumpCompileUnitLineTable (CommandInterpreter &interpreter,
1343                           Stream &strm,
1344                           Module *module,
1345                           const FileSpec &file_spec,
1346                           bool load_addresses)
1347 {
1348     uint32_t num_matches = 0;
1349     if (module)
1350     {
1351         SymbolContextList sc_list;
1352         num_matches = module->ResolveSymbolContextsForFileSpec (file_spec,
1353                                                                 0,
1354                                                                 false,
1355                                                                 eSymbolContextCompUnit,
1356                                                                 sc_list);
1357 
1358         for (uint32_t i=0; i<num_matches; ++i)
1359         {
1360             SymbolContext sc;
1361             if (sc_list.GetContextAtIndex(i, sc))
1362             {
1363                 if (i > 0)
1364                     strm << "\n\n";
1365 
1366                 strm << "Line table for " << *static_cast<FileSpec*> (sc.comp_unit) << " in `"
1367                 << module->GetFileSpec().GetFilename() << "\n";
1368                 LineTable *line_table = sc.comp_unit->GetLineTable();
1369                 if (line_table)
1370                     line_table->GetDescription (&strm,
1371                                                 interpreter.GetExecutionContext().GetTargetPtr(),
1372                                                 lldb::eDescriptionLevelBrief);
1373                 else
1374                     strm << "No line table";
1375             }
1376         }
1377     }
1378     return num_matches;
1379 }
1380 
1381 static void
1382 DumpFullpath (Stream &strm, const FileSpec *file_spec_ptr, uint32_t width)
1383 {
1384     if (file_spec_ptr)
1385     {
1386         if (width > 0)
1387         {
1388             char fullpath[PATH_MAX];
1389             if (file_spec_ptr->GetPath(fullpath, sizeof(fullpath)))
1390             {
1391                 strm.Printf("%-*s", width, fullpath);
1392                 return;
1393             }
1394         }
1395         else
1396         {
1397             file_spec_ptr->Dump(&strm);
1398             return;
1399         }
1400     }
1401     // Keep the width spacing correct if things go wrong...
1402     if (width > 0)
1403         strm.Printf("%-*s", width, "");
1404 }
1405 
1406 static void
1407 DumpDirectory (Stream &strm, const FileSpec *file_spec_ptr, uint32_t width)
1408 {
1409     if (file_spec_ptr)
1410     {
1411         if (width > 0)
1412             strm.Printf("%-*s", width, file_spec_ptr->GetDirectory().AsCString(""));
1413         else
1414             file_spec_ptr->GetDirectory().Dump(&strm);
1415         return;
1416     }
1417     // Keep the width spacing correct if things go wrong...
1418     if (width > 0)
1419         strm.Printf("%-*s", width, "");
1420 }
1421 
1422 static void
1423 DumpBasename (Stream &strm, const FileSpec *file_spec_ptr, uint32_t width)
1424 {
1425     if (file_spec_ptr)
1426     {
1427         if (width > 0)
1428             strm.Printf("%-*s", width, file_spec_ptr->GetFilename().AsCString(""));
1429         else
1430             file_spec_ptr->GetFilename().Dump(&strm);
1431         return;
1432     }
1433     // Keep the width spacing correct if things go wrong...
1434     if (width > 0)
1435         strm.Printf("%-*s", width, "");
1436 }
1437 
1438 
1439 static void
1440 DumpModuleSymtab (CommandInterpreter &interpreter, Stream &strm, Module *module, SortOrder sort_order)
1441 {
1442     if (module)
1443     {
1444         ObjectFile *objfile = module->GetObjectFile ();
1445         if (objfile)
1446         {
1447             Symtab *symtab = objfile->GetSymtab();
1448             if (symtab)
1449                 symtab->Dump(&strm, interpreter.GetExecutionContext().GetTargetPtr(), sort_order);
1450         }
1451     }
1452 }
1453 
1454 static void
1455 DumpModuleSections (CommandInterpreter &interpreter, Stream &strm, Module *module)
1456 {
1457     if (module)
1458     {
1459         ObjectFile *objfile = module->GetObjectFile ();
1460         if (objfile)
1461         {
1462             SectionList *section_list = objfile->GetSectionList();
1463             if (section_list)
1464             {
1465                 strm.Printf ("Sections for '%s' (%s):\n",
1466                              module->GetSpecificationDescription().c_str(),
1467                              module->GetArchitecture().GetArchitectureName());
1468                 strm.IndentMore();
1469                 section_list->Dump(&strm, interpreter.GetExecutionContext().GetTargetPtr(), true, UINT32_MAX);
1470                 strm.IndentLess();
1471             }
1472         }
1473     }
1474 }
1475 
1476 static bool
1477 DumpModuleSymbolVendor (Stream &strm, Module *module)
1478 {
1479     if (module)
1480     {
1481         SymbolVendor *symbol_vendor = module->GetSymbolVendor(true);
1482         if (symbol_vendor)
1483         {
1484             symbol_vendor->Dump(&strm);
1485             return true;
1486         }
1487     }
1488     return false;
1489 }
1490 
1491 static void
1492 DumpAddress (ExecutionContextScope *exe_scope, const Address &so_addr, bool verbose, Stream &strm)
1493 {
1494     strm.IndentMore();
1495     strm.Indent ("    Address: ");
1496     so_addr.Dump (&strm, exe_scope, Address::DumpStyleModuleWithFileAddress);
1497     strm.PutCString (" (");
1498     so_addr.Dump (&strm, exe_scope, Address::DumpStyleSectionNameOffset);
1499     strm.PutCString (")\n");
1500     strm.Indent ("    Summary: ");
1501     const uint32_t save_indent = strm.GetIndentLevel ();
1502     strm.SetIndentLevel (save_indent + 13);
1503     so_addr.Dump (&strm, exe_scope, Address::DumpStyleResolvedDescription);
1504     strm.SetIndentLevel (save_indent);
1505     // Print out detailed address information when verbose is enabled
1506     if (verbose)
1507     {
1508         strm.EOL();
1509         so_addr.Dump (&strm, exe_scope, Address::DumpStyleDetailedSymbolContext);
1510     }
1511     strm.IndentLess();
1512 }
1513 
1514 static bool
1515 LookupAddressInModule (CommandInterpreter &interpreter,
1516                        Stream &strm,
1517                        Module *module,
1518                        uint32_t resolve_mask,
1519                        lldb::addr_t raw_addr,
1520                        lldb::addr_t offset,
1521                        bool verbose)
1522 {
1523     if (module)
1524     {
1525         lldb::addr_t addr = raw_addr - offset;
1526         Address so_addr;
1527         SymbolContext sc;
1528         Target *target = interpreter.GetExecutionContext().GetTargetPtr();
1529         if (target && !target->GetSectionLoadList().IsEmpty())
1530         {
1531             if (!target->GetSectionLoadList().ResolveLoadAddress (addr, so_addr))
1532                 return false;
1533             else if (so_addr.GetModule().get() != module)
1534                 return false;
1535         }
1536         else
1537         {
1538             if (!module->ResolveFileAddress (addr, so_addr))
1539                 return false;
1540         }
1541 
1542         ExecutionContextScope *exe_scope = interpreter.GetExecutionContext().GetBestExecutionContextScope();
1543         DumpAddress (exe_scope, so_addr, verbose, strm);
1544 //        strm.IndentMore();
1545 //        strm.Indent ("    Address: ");
1546 //        so_addr.Dump (&strm, exe_scope, Address::DumpStyleModuleWithFileAddress);
1547 //        strm.PutCString (" (");
1548 //        so_addr.Dump (&strm, exe_scope, Address::DumpStyleSectionNameOffset);
1549 //        strm.PutCString (")\n");
1550 //        strm.Indent ("    Summary: ");
1551 //        const uint32_t save_indent = strm.GetIndentLevel ();
1552 //        strm.SetIndentLevel (save_indent + 13);
1553 //        so_addr.Dump (&strm, exe_scope, Address::DumpStyleResolvedDescription);
1554 //        strm.SetIndentLevel (save_indent);
1555 //        // Print out detailed address information when verbose is enabled
1556 //        if (verbose)
1557 //        {
1558 //            strm.EOL();
1559 //            so_addr.Dump (&strm, exe_scope, Address::DumpStyleDetailedSymbolContext);
1560 //        }
1561 //        strm.IndentLess();
1562         return true;
1563     }
1564 
1565     return false;
1566 }
1567 
1568 static uint32_t
1569 LookupSymbolInModule (CommandInterpreter &interpreter, Stream &strm, Module *module, const char *name, bool name_is_regex, bool verbose)
1570 {
1571     if (module)
1572     {
1573         SymbolContext sc;
1574 
1575         ObjectFile *objfile = module->GetObjectFile ();
1576         if (objfile)
1577         {
1578             Symtab *symtab = objfile->GetSymtab();
1579             if (symtab)
1580             {
1581                 uint32_t i;
1582                 std::vector<uint32_t> match_indexes;
1583                 ConstString symbol_name (name);
1584                 uint32_t num_matches = 0;
1585                 if (name_is_regex)
1586                 {
1587                     RegularExpression name_regexp(name);
1588                     num_matches = symtab->AppendSymbolIndexesMatchingRegExAndType (name_regexp,
1589                                                                                    eSymbolTypeAny,
1590                                                                                    match_indexes);
1591                 }
1592                 else
1593                 {
1594                     num_matches = symtab->AppendSymbolIndexesWithName (symbol_name, match_indexes);
1595                 }
1596 
1597 
1598                 if (num_matches > 0)
1599                 {
1600                     strm.Indent ();
1601                     strm.Printf("%u symbols match %s'%s' in ", num_matches,
1602                                 name_is_regex ? "the regular expression " : "", name);
1603                     DumpFullpath (strm, &module->GetFileSpec(), 0);
1604                     strm.PutCString(":\n");
1605                     strm.IndentMore ();
1606                     //Symtab::DumpSymbolHeader (&strm);
1607                     for (i=0; i < num_matches; ++i)
1608                     {
1609                         Symbol *symbol = symtab->SymbolAtIndex(match_indexes[i]);
1610                         DumpAddress (interpreter.GetExecutionContext().GetBestExecutionContextScope(),
1611                                      symbol->GetAddress(),
1612                                      verbose,
1613                                      strm);
1614 
1615 //                        strm.Indent ();
1616 //                        symbol->Dump (&strm, interpreter.GetExecutionContext().GetTargetPtr(), i);
1617                     }
1618                     strm.IndentLess ();
1619                     return num_matches;
1620                 }
1621             }
1622         }
1623     }
1624     return 0;
1625 }
1626 
1627 
1628 static void
1629 DumpSymbolContextList (ExecutionContextScope *exe_scope, Stream &strm, SymbolContextList &sc_list, bool verbose)
1630 {
1631     strm.IndentMore ();
1632     uint32_t i;
1633     const uint32_t num_matches = sc_list.GetSize();
1634 
1635     for (i=0; i<num_matches; ++i)
1636     {
1637         SymbolContext sc;
1638         if (sc_list.GetContextAtIndex(i, sc))
1639         {
1640             AddressRange range;
1641 
1642             sc.GetAddressRange(eSymbolContextEverything,
1643                                0,
1644                                true,
1645                                range);
1646 
1647             DumpAddress (exe_scope, range.GetBaseAddress(), verbose, strm);
1648         }
1649     }
1650     strm.IndentLess ();
1651 }
1652 
1653 static size_t
1654 LookupFunctionInModule (CommandInterpreter &interpreter,
1655                         Stream &strm,
1656                         Module *module,
1657                         const char *name,
1658                         bool name_is_regex,
1659                         bool include_inlines,
1660                         bool include_symbols,
1661                         bool verbose)
1662 {
1663     if (module && name && name[0])
1664     {
1665         SymbolContextList sc_list;
1666         const bool append = true;
1667         size_t num_matches = 0;
1668         if (name_is_regex)
1669         {
1670             RegularExpression function_name_regex (name);
1671             num_matches = module->FindFunctions (function_name_regex,
1672                                                  include_symbols,
1673                                                  include_inlines,
1674                                                  append,
1675                                                  sc_list);
1676         }
1677         else
1678         {
1679             ConstString function_name (name);
1680             num_matches = module->FindFunctions (function_name,
1681                                                  NULL,
1682                                                  eFunctionNameTypeBase | eFunctionNameTypeFull | eFunctionNameTypeMethod | eFunctionNameTypeSelector,
1683                                                  include_symbols,
1684                                                  include_inlines,
1685                                                  append,
1686                                                  sc_list);
1687         }
1688 
1689         if (num_matches)
1690         {
1691             strm.Indent ();
1692             strm.Printf("%zu match%s found in ", num_matches, num_matches > 1 ? "es" : "");
1693             DumpFullpath (strm, &module->GetFileSpec(), 0);
1694             strm.PutCString(":\n");
1695             DumpSymbolContextList (interpreter.GetExecutionContext().GetBestExecutionContextScope(), strm, sc_list, verbose);
1696         }
1697         return num_matches;
1698     }
1699     return 0;
1700 }
1701 
1702 static size_t
1703 LookupTypeInModule (CommandInterpreter &interpreter,
1704                     Stream &strm,
1705                     Module *module,
1706                     const char *name_cstr,
1707                     bool name_is_regex)
1708 {
1709     if (module && name_cstr && name_cstr[0])
1710     {
1711         TypeList type_list;
1712         const uint32_t max_num_matches = UINT32_MAX;
1713         size_t num_matches = 0;
1714         bool name_is_fully_qualified = false;
1715         SymbolContext sc;
1716 
1717         ConstString name(name_cstr);
1718         num_matches = module->FindTypes(sc, name, name_is_fully_qualified, max_num_matches, type_list);
1719 
1720         if (num_matches)
1721         {
1722             strm.Indent ();
1723             strm.Printf("%zu match%s found in ", num_matches, num_matches > 1 ? "es" : "");
1724             DumpFullpath (strm, &module->GetFileSpec(), 0);
1725             strm.PutCString(":\n");
1726             const uint32_t num_types = type_list.GetSize();
1727             for (uint32_t i=0; i<num_types; ++i)
1728             {
1729                 TypeSP type_sp (type_list.GetTypeAtIndex(i));
1730                 if (type_sp)
1731                 {
1732                     // Resolve the clang type so that any forward references
1733                     // to types that haven't yet been parsed will get parsed.
1734                     type_sp->GetClangFullType ();
1735                     type_sp->GetDescription (&strm, eDescriptionLevelFull, true);
1736                     // Print all typedef chains
1737                     TypeSP typedef_type_sp (type_sp);
1738                     TypeSP typedefed_type_sp (typedef_type_sp->GetTypedefType());
1739                     while (typedefed_type_sp)
1740                     {
1741                         strm.EOL();
1742                         strm.Printf("     typedef '%s': ", typedef_type_sp->GetName().GetCString());
1743                         typedefed_type_sp->GetClangFullType ();
1744                         typedefed_type_sp->GetDescription (&strm, eDescriptionLevelFull, true);
1745                         typedef_type_sp = typedefed_type_sp;
1746                         typedefed_type_sp = typedef_type_sp->GetTypedefType();
1747                     }
1748                 }
1749                 strm.EOL();
1750             }
1751         }
1752         return num_matches;
1753     }
1754     return 0;
1755 }
1756 
1757 static size_t
1758 LookupTypeHere (CommandInterpreter &interpreter,
1759                 Stream &strm,
1760                 const SymbolContext &sym_ctx,
1761                 const char *name_cstr,
1762                 bool name_is_regex)
1763 {
1764     if (!sym_ctx.module_sp)
1765         return 0;
1766 
1767     TypeList type_list;
1768     const uint32_t max_num_matches = UINT32_MAX;
1769     size_t num_matches = 1;
1770     bool name_is_fully_qualified = false;
1771 
1772     ConstString name(name_cstr);
1773     num_matches = sym_ctx.module_sp->FindTypes(sym_ctx, name, name_is_fully_qualified, max_num_matches, type_list);
1774 
1775     if (num_matches)
1776     {
1777         strm.Indent ();
1778         strm.PutCString("Best match found in ");
1779         DumpFullpath (strm, &sym_ctx.module_sp->GetFileSpec(), 0);
1780         strm.PutCString(":\n");
1781 
1782         TypeSP type_sp (type_list.GetTypeAtIndex(0));
1783         if (type_sp)
1784         {
1785             // Resolve the clang type so that any forward references
1786             // to types that haven't yet been parsed will get parsed.
1787             type_sp->GetClangFullType ();
1788             type_sp->GetDescription (&strm, eDescriptionLevelFull, true);
1789             // Print all typedef chains
1790             TypeSP typedef_type_sp (type_sp);
1791             TypeSP typedefed_type_sp (typedef_type_sp->GetTypedefType());
1792             while (typedefed_type_sp)
1793             {
1794                 strm.EOL();
1795                 strm.Printf("     typedef '%s': ", typedef_type_sp->GetName().GetCString());
1796                 typedefed_type_sp->GetClangFullType ();
1797                 typedefed_type_sp->GetDescription (&strm, eDescriptionLevelFull, true);
1798                 typedef_type_sp = typedefed_type_sp;
1799                 typedefed_type_sp = typedef_type_sp->GetTypedefType();
1800             }
1801         }
1802         strm.EOL();
1803     }
1804     return num_matches;
1805 }
1806 
1807 static uint32_t
1808 LookupFileAndLineInModule (CommandInterpreter &interpreter,
1809                            Stream &strm,
1810                            Module *module,
1811                            const FileSpec &file_spec,
1812                            uint32_t line,
1813                            bool check_inlines,
1814                            bool verbose)
1815 {
1816     if (module && file_spec)
1817     {
1818         SymbolContextList sc_list;
1819         const uint32_t num_matches = module->ResolveSymbolContextsForFileSpec(file_spec, line, check_inlines,
1820                                                                               eSymbolContextEverything, sc_list);
1821         if (num_matches > 0)
1822         {
1823             strm.Indent ();
1824             strm.Printf("%u match%s found in ", num_matches, num_matches > 1 ? "es" : "");
1825             strm << file_spec;
1826             if (line > 0)
1827                 strm.Printf (":%u", line);
1828             strm << " in ";
1829             DumpFullpath (strm, &module->GetFileSpec(), 0);
1830             strm.PutCString(":\n");
1831             DumpSymbolContextList (interpreter.GetExecutionContext().GetBestExecutionContextScope(), strm, sc_list, verbose);
1832             return num_matches;
1833         }
1834     }
1835     return 0;
1836 
1837 }
1838 
1839 
1840 static size_t
1841 FindModulesByName (Target *target,
1842                    const char *module_name,
1843                    ModuleList &module_list,
1844                    bool check_global_list)
1845 {
1846 // Dump specified images (by basename or fullpath)
1847     FileSpec module_file_spec(module_name, false);
1848     ModuleSpec module_spec (module_file_spec);
1849 
1850     const size_t initial_size = module_list.GetSize ();
1851 
1852     if (check_global_list)
1853     {
1854         // Check the global list
1855         Mutex::Locker locker(Module::GetAllocationModuleCollectionMutex());
1856         const size_t num_modules = Module::GetNumberAllocatedModules();
1857         ModuleSP module_sp;
1858         for (size_t image_idx = 0; image_idx<num_modules; ++image_idx)
1859         {
1860             Module *module = Module::GetAllocatedModuleAtIndex(image_idx);
1861 
1862             if (module)
1863             {
1864                 if (module->MatchesModuleSpec (module_spec))
1865                 {
1866                     module_sp = module->shared_from_this();
1867                     module_list.AppendIfNeeded(module_sp);
1868                 }
1869             }
1870         }
1871     }
1872     else
1873     {
1874         if (target)
1875         {
1876             const size_t num_matches = target->GetImages().FindModules (module_spec, module_list);
1877 
1878             // Not found in our module list for our target, check the main
1879             // shared module list in case it is a extra file used somewhere
1880             // else
1881             if (num_matches == 0)
1882             {
1883                 module_spec.GetArchitecture() = target->GetArchitecture();
1884                 ModuleList::FindSharedModules (module_spec, module_list);
1885             }
1886         }
1887         else
1888         {
1889             ModuleList::FindSharedModules (module_spec,module_list);
1890         }
1891     }
1892 
1893     return module_list.GetSize () - initial_size;
1894 }
1895 
1896 #pragma mark CommandObjectTargetModulesModuleAutoComplete
1897 
1898 //----------------------------------------------------------------------
1899 // A base command object class that can auto complete with module file
1900 // paths
1901 //----------------------------------------------------------------------
1902 
1903 class CommandObjectTargetModulesModuleAutoComplete : public CommandObjectParsed
1904 {
1905 public:
1906 
1907     CommandObjectTargetModulesModuleAutoComplete (CommandInterpreter &interpreter,
1908                                       const char *name,
1909                                       const char *help,
1910                                       const char *syntax) :
1911         CommandObjectParsed (interpreter, name, help, syntax)
1912     {
1913         CommandArgumentEntry arg;
1914         CommandArgumentData file_arg;
1915 
1916         // Define the first (and only) variant of this arg.
1917         file_arg.arg_type = eArgTypeFilename;
1918         file_arg.arg_repetition = eArgRepeatStar;
1919 
1920         // There is only one variant this argument could be; put it into the argument entry.
1921         arg.push_back (file_arg);
1922 
1923         // Push the data for the first argument into the m_arguments vector.
1924         m_arguments.push_back (arg);
1925     }
1926 
1927     virtual
1928     ~CommandObjectTargetModulesModuleAutoComplete ()
1929     {
1930     }
1931 
1932     virtual int
1933     HandleArgumentCompletion (Args &input,
1934                               int &cursor_index,
1935                               int &cursor_char_position,
1936                               OptionElementVector &opt_element_vector,
1937                               int match_start_point,
1938                               int max_return_elements,
1939                               bool &word_complete,
1940                               StringList &matches)
1941     {
1942         // Arguments are the standard module completer.
1943         std::string completion_str (input.GetArgumentAtIndex(cursor_index));
1944         completion_str.erase (cursor_char_position);
1945 
1946         CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
1947                                                              CommandCompletions::eModuleCompletion,
1948                                                              completion_str.c_str(),
1949                                                              match_start_point,
1950                                                              max_return_elements,
1951                                                              NULL,
1952                                                              word_complete,
1953                                                              matches);
1954         return matches.GetSize();
1955     }
1956 };
1957 
1958 #pragma mark CommandObjectTargetModulesSourceFileAutoComplete
1959 
1960 //----------------------------------------------------------------------
1961 // A base command object class that can auto complete with module source
1962 // file paths
1963 //----------------------------------------------------------------------
1964 
1965 class CommandObjectTargetModulesSourceFileAutoComplete : public CommandObjectParsed
1966 {
1967 public:
1968 
1969     CommandObjectTargetModulesSourceFileAutoComplete (CommandInterpreter &interpreter,
1970                                                       const char *name,
1971                                                       const char *help,
1972                                                       const char *syntax,
1973                                                       uint32_t flags) :
1974         CommandObjectParsed (interpreter, name, help, syntax, flags)
1975     {
1976         CommandArgumentEntry arg;
1977         CommandArgumentData source_file_arg;
1978 
1979         // Define the first (and only) variant of this arg.
1980         source_file_arg.arg_type = eArgTypeSourceFile;
1981         source_file_arg.arg_repetition = eArgRepeatPlus;
1982 
1983         // There is only one variant this argument could be; put it into the argument entry.
1984         arg.push_back (source_file_arg);
1985 
1986         // Push the data for the first argument into the m_arguments vector.
1987         m_arguments.push_back (arg);
1988     }
1989 
1990     virtual
1991     ~CommandObjectTargetModulesSourceFileAutoComplete ()
1992     {
1993     }
1994 
1995     virtual int
1996     HandleArgumentCompletion (Args &input,
1997                               int &cursor_index,
1998                               int &cursor_char_position,
1999                               OptionElementVector &opt_element_vector,
2000                               int match_start_point,
2001                               int max_return_elements,
2002                               bool &word_complete,
2003                               StringList &matches)
2004     {
2005         // Arguments are the standard source file completer.
2006         std::string completion_str (input.GetArgumentAtIndex(cursor_index));
2007         completion_str.erase (cursor_char_position);
2008 
2009         CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
2010                                                              CommandCompletions::eSourceFileCompletion,
2011                                                              completion_str.c_str(),
2012                                                              match_start_point,
2013                                                              max_return_elements,
2014                                                              NULL,
2015                                                              word_complete,
2016                                                              matches);
2017         return matches.GetSize();
2018     }
2019 };
2020 
2021 
2022 #pragma mark CommandObjectTargetModulesDumpSymtab
2023 
2024 
2025 class CommandObjectTargetModulesDumpSymtab : public CommandObjectTargetModulesModuleAutoComplete
2026 {
2027 public:
2028     CommandObjectTargetModulesDumpSymtab (CommandInterpreter &interpreter) :
2029     CommandObjectTargetModulesModuleAutoComplete (interpreter,
2030                                       "target modules dump symtab",
2031                                       "Dump the symbol table from one or more target modules.",
2032                                       NULL),
2033     m_options (interpreter)
2034     {
2035     }
2036 
2037     virtual
2038     ~CommandObjectTargetModulesDumpSymtab ()
2039     {
2040     }
2041 
2042     virtual Options *
2043     GetOptions ()
2044     {
2045         return &m_options;
2046     }
2047 
2048     class CommandOptions : public Options
2049     {
2050     public:
2051 
2052         CommandOptions (CommandInterpreter &interpreter) :
2053         Options(interpreter),
2054         m_sort_order (eSortOrderNone)
2055         {
2056         }
2057 
2058         virtual
2059         ~CommandOptions ()
2060         {
2061         }
2062 
2063         virtual Error
2064         SetOptionValue (uint32_t option_idx, const char *option_arg)
2065         {
2066             Error error;
2067             const int short_option = m_getopt_table[option_idx].val;
2068 
2069             switch (short_option)
2070             {
2071                 case 's':
2072                     m_sort_order = (SortOrder) Args::StringToOptionEnum (option_arg,
2073                                                                          g_option_table[option_idx].enum_values,
2074                                                                          eSortOrderNone,
2075                                                                          error);
2076                     break;
2077 
2078                 default:
2079                     error.SetErrorStringWithFormat("invalid short option character '%c'", short_option);
2080                     break;
2081 
2082             }
2083             return error;
2084         }
2085 
2086         void
2087         OptionParsingStarting ()
2088         {
2089             m_sort_order = eSortOrderNone;
2090         }
2091 
2092         const OptionDefinition*
2093         GetDefinitions ()
2094         {
2095             return g_option_table;
2096         }
2097 
2098         // Options table: Required for subclasses of Options.
2099         static OptionDefinition g_option_table[];
2100 
2101         SortOrder m_sort_order;
2102     };
2103 
2104 protected:
2105     virtual bool
2106     DoExecute (Args& command,
2107              CommandReturnObject &result)
2108     {
2109         Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
2110         if (target == NULL)
2111         {
2112             result.AppendError ("invalid target, create a debug target using the 'target create' command");
2113             result.SetStatus (eReturnStatusFailed);
2114             return false;
2115         }
2116         else
2117         {
2118             uint32_t num_dumped = 0;
2119 
2120             uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize();
2121             result.GetOutputStream().SetAddressByteSize(addr_byte_size);
2122             result.GetErrorStream().SetAddressByteSize(addr_byte_size);
2123 
2124             if (command.GetArgumentCount() == 0)
2125             {
2126                 // Dump all sections for all modules images
2127                 Mutex::Locker modules_locker(target->GetImages().GetMutex());
2128                 const size_t num_modules = target->GetImages().GetSize();
2129                 if (num_modules > 0)
2130                 {
2131                     result.GetOutputStream().Printf("Dumping symbol table for %zu modules.\n", num_modules);
2132                     for (size_t image_idx = 0; image_idx<num_modules; ++image_idx)
2133                     {
2134                         if (num_dumped > 0)
2135                         {
2136                             result.GetOutputStream().EOL();
2137                             result.GetOutputStream().EOL();
2138                         }
2139                         num_dumped++;
2140                         DumpModuleSymtab (m_interpreter,
2141                                           result.GetOutputStream(),
2142                                           target->GetImages().GetModulePointerAtIndexUnlocked(image_idx),
2143                                           m_options.m_sort_order);
2144                     }
2145                 }
2146                 else
2147                 {
2148                     result.AppendError ("the target has no associated executable images");
2149                     result.SetStatus (eReturnStatusFailed);
2150                     return false;
2151                 }
2152             }
2153             else
2154             {
2155                 // Dump specified images (by basename or fullpath)
2156                 const char *arg_cstr;
2157                 for (int arg_idx = 0; (arg_cstr = command.GetArgumentAtIndex(arg_idx)) != NULL; ++arg_idx)
2158                 {
2159                     ModuleList module_list;
2160                     const size_t num_matches = FindModulesByName (target, arg_cstr, module_list, true);
2161                     if (num_matches > 0)
2162                     {
2163                         for (size_t i=0; i<num_matches; ++i)
2164                         {
2165                             Module *module = module_list.GetModulePointerAtIndex(i);
2166                             if (module)
2167                             {
2168                                 if (num_dumped > 0)
2169                                 {
2170                                     result.GetOutputStream().EOL();
2171                                     result.GetOutputStream().EOL();
2172                                 }
2173                                 num_dumped++;
2174                                 DumpModuleSymtab (m_interpreter, result.GetOutputStream(), module, m_options.m_sort_order);
2175                             }
2176                         }
2177                     }
2178                     else
2179                         result.AppendWarningWithFormat("Unable to find an image that matches '%s'.\n", arg_cstr);
2180                 }
2181             }
2182 
2183             if (num_dumped > 0)
2184                 result.SetStatus (eReturnStatusSuccessFinishResult);
2185             else
2186             {
2187                 result.AppendError ("no matching executable images found");
2188                 result.SetStatus (eReturnStatusFailed);
2189             }
2190         }
2191         return result.Succeeded();
2192     }
2193 
2194 
2195     CommandOptions m_options;
2196 };
2197 
2198 static OptionEnumValueElement
2199 g_sort_option_enumeration[4] =
2200 {
2201     { eSortOrderNone,       "none",     "No sorting, use the original symbol table order."},
2202     { eSortOrderByAddress,  "address",  "Sort output by symbol address."},
2203     { eSortOrderByName,     "name",     "Sort output by symbol name."},
2204     { 0,                    NULL,       NULL }
2205 };
2206 
2207 
2208 OptionDefinition
2209 CommandObjectTargetModulesDumpSymtab::CommandOptions::g_option_table[] =
2210 {
2211     { LLDB_OPT_SET_1, false, "sort", 's', required_argument, g_sort_option_enumeration, 0, eArgTypeSortOrder, "Supply a sort order when dumping the symbol table."},
2212     { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
2213 };
2214 
2215 #pragma mark CommandObjectTargetModulesDumpSections
2216 
2217 //----------------------------------------------------------------------
2218 // Image section dumping command
2219 //----------------------------------------------------------------------
2220 
2221 class CommandObjectTargetModulesDumpSections : public CommandObjectTargetModulesModuleAutoComplete
2222 {
2223 public:
2224     CommandObjectTargetModulesDumpSections (CommandInterpreter &interpreter) :
2225     CommandObjectTargetModulesModuleAutoComplete (interpreter,
2226                                       "target modules dump sections",
2227                                       "Dump the sections from one or more target modules.",
2228                                       //"target modules dump sections [<file1> ...]")
2229                                       NULL)
2230     {
2231     }
2232 
2233     virtual
2234     ~CommandObjectTargetModulesDumpSections ()
2235     {
2236     }
2237 
2238 protected:
2239     virtual bool
2240     DoExecute (Args& command,
2241              CommandReturnObject &result)
2242     {
2243         Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
2244         if (target == NULL)
2245         {
2246             result.AppendError ("invalid target, create a debug target using the 'target create' command");
2247             result.SetStatus (eReturnStatusFailed);
2248             return false;
2249         }
2250         else
2251         {
2252             uint32_t num_dumped = 0;
2253 
2254             uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize();
2255             result.GetOutputStream().SetAddressByteSize(addr_byte_size);
2256             result.GetErrorStream().SetAddressByteSize(addr_byte_size);
2257 
2258             if (command.GetArgumentCount() == 0)
2259             {
2260                 // Dump all sections for all modules images
2261                 const size_t num_modules = target->GetImages().GetSize();
2262                 if (num_modules > 0)
2263                 {
2264                     result.GetOutputStream().Printf("Dumping sections for %zu modules.\n", num_modules);
2265                     for (size_t image_idx = 0;  image_idx<num_modules; ++image_idx)
2266                     {
2267                         num_dumped++;
2268                         DumpModuleSections (m_interpreter, result.GetOutputStream(), target->GetImages().GetModulePointerAtIndex(image_idx));
2269                     }
2270                 }
2271                 else
2272                 {
2273                     result.AppendError ("the target has no associated executable images");
2274                     result.SetStatus (eReturnStatusFailed);
2275                     return false;
2276                 }
2277             }
2278             else
2279             {
2280                 // Dump specified images (by basename or fullpath)
2281                 const char *arg_cstr;
2282                 for (int arg_idx = 0; (arg_cstr = command.GetArgumentAtIndex(arg_idx)) != NULL; ++arg_idx)
2283                 {
2284                     ModuleList module_list;
2285                     const size_t num_matches = FindModulesByName (target, arg_cstr, module_list, true);
2286                     if (num_matches > 0)
2287                     {
2288                         for (size_t i=0; i<num_matches; ++i)
2289                         {
2290                             Module *module = module_list.GetModulePointerAtIndex(i);
2291                             if (module)
2292                             {
2293                                 num_dumped++;
2294                                 DumpModuleSections (m_interpreter, result.GetOutputStream(), module);
2295                             }
2296                         }
2297                     }
2298                     else
2299                     {
2300                         // Check the global list
2301                         Mutex::Locker locker(Module::GetAllocationModuleCollectionMutex());
2302 
2303                         result.AppendWarningWithFormat("Unable to find an image that matches '%s'.\n", arg_cstr);
2304                     }
2305                 }
2306             }
2307 
2308             if (num_dumped > 0)
2309                 result.SetStatus (eReturnStatusSuccessFinishResult);
2310             else
2311             {
2312                 result.AppendError ("no matching executable images found");
2313                 result.SetStatus (eReturnStatusFailed);
2314             }
2315         }
2316         return result.Succeeded();
2317     }
2318 };
2319 
2320 
2321 #pragma mark CommandObjectTargetModulesDumpSymfile
2322 
2323 //----------------------------------------------------------------------
2324 // Image debug symbol dumping command
2325 //----------------------------------------------------------------------
2326 
2327 class CommandObjectTargetModulesDumpSymfile : public CommandObjectTargetModulesModuleAutoComplete
2328 {
2329 public:
2330     CommandObjectTargetModulesDumpSymfile (CommandInterpreter &interpreter) :
2331     CommandObjectTargetModulesModuleAutoComplete (interpreter,
2332                                       "target modules dump symfile",
2333                                       "Dump the debug symbol file for one or more target modules.",
2334                                       //"target modules dump symfile [<file1> ...]")
2335                                       NULL)
2336     {
2337     }
2338 
2339     virtual
2340     ~CommandObjectTargetModulesDumpSymfile ()
2341     {
2342     }
2343 
2344 protected:
2345     virtual bool
2346     DoExecute (Args& command,
2347              CommandReturnObject &result)
2348     {
2349         Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
2350         if (target == NULL)
2351         {
2352             result.AppendError ("invalid target, create a debug target using the 'target create' command");
2353             result.SetStatus (eReturnStatusFailed);
2354             return false;
2355         }
2356         else
2357         {
2358             uint32_t num_dumped = 0;
2359 
2360             uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize();
2361             result.GetOutputStream().SetAddressByteSize(addr_byte_size);
2362             result.GetErrorStream().SetAddressByteSize(addr_byte_size);
2363 
2364             if (command.GetArgumentCount() == 0)
2365             {
2366                 // Dump all sections for all modules images
2367                 const ModuleList &target_modules = target->GetImages();
2368                 Mutex::Locker modules_locker (target_modules.GetMutex());
2369                 const size_t num_modules = target_modules.GetSize();
2370                 if (num_modules > 0)
2371                 {
2372                     result.GetOutputStream().Printf("Dumping debug symbols for %zu modules.\n", num_modules);
2373                     for (uint32_t image_idx = 0;  image_idx<num_modules; ++image_idx)
2374                     {
2375                         if (DumpModuleSymbolVendor (result.GetOutputStream(), target_modules.GetModulePointerAtIndexUnlocked(image_idx)))
2376                             num_dumped++;
2377                     }
2378                 }
2379                 else
2380                 {
2381                     result.AppendError ("the target has no associated executable images");
2382                     result.SetStatus (eReturnStatusFailed);
2383                     return false;
2384                 }
2385             }
2386             else
2387             {
2388                 // Dump specified images (by basename or fullpath)
2389                 const char *arg_cstr;
2390                 for (int arg_idx = 0; (arg_cstr = command.GetArgumentAtIndex(arg_idx)) != NULL; ++arg_idx)
2391                 {
2392                     ModuleList module_list;
2393                     const size_t num_matches = FindModulesByName (target, arg_cstr, module_list, true);
2394                     if (num_matches > 0)
2395                     {
2396                         for (size_t i=0; i<num_matches; ++i)
2397                         {
2398                             Module *module = module_list.GetModulePointerAtIndex(i);
2399                             if (module)
2400                             {
2401                                 if (DumpModuleSymbolVendor (result.GetOutputStream(), module))
2402                                     num_dumped++;
2403                             }
2404                         }
2405                     }
2406                     else
2407                         result.AppendWarningWithFormat("Unable to find an image that matches '%s'.\n", arg_cstr);
2408                 }
2409             }
2410 
2411             if (num_dumped > 0)
2412                 result.SetStatus (eReturnStatusSuccessFinishResult);
2413             else
2414             {
2415                 result.AppendError ("no matching executable images found");
2416                 result.SetStatus (eReturnStatusFailed);
2417             }
2418         }
2419         return result.Succeeded();
2420     }
2421 };
2422 
2423 
2424 #pragma mark CommandObjectTargetModulesDumpLineTable
2425 
2426 //----------------------------------------------------------------------
2427 // Image debug line table dumping command
2428 //----------------------------------------------------------------------
2429 
2430 class CommandObjectTargetModulesDumpLineTable : public CommandObjectTargetModulesSourceFileAutoComplete
2431 {
2432 public:
2433     CommandObjectTargetModulesDumpLineTable (CommandInterpreter &interpreter) :
2434     CommandObjectTargetModulesSourceFileAutoComplete (interpreter,
2435                                                       "target modules dump line-table",
2436                                                       "Dump the debug symbol file for one or more target modules.",
2437                                                       NULL,
2438                                                       eFlagRequiresTarget)
2439     {
2440     }
2441 
2442     virtual
2443     ~CommandObjectTargetModulesDumpLineTable ()
2444     {
2445     }
2446 
2447 protected:
2448     virtual bool
2449     DoExecute (Args& command,
2450              CommandReturnObject &result)
2451     {
2452         Target *target = m_exe_ctx.GetTargetPtr();
2453         uint32_t total_num_dumped = 0;
2454 
2455         uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize();
2456         result.GetOutputStream().SetAddressByteSize(addr_byte_size);
2457         result.GetErrorStream().SetAddressByteSize(addr_byte_size);
2458 
2459         if (command.GetArgumentCount() == 0)
2460         {
2461             result.AppendErrorWithFormat ("\nSyntax: %s\n", m_cmd_syntax.c_str());
2462             result.SetStatus (eReturnStatusFailed);
2463         }
2464         else
2465         {
2466             // Dump specified images (by basename or fullpath)
2467             const char *arg_cstr;
2468             for (int arg_idx = 0; (arg_cstr = command.GetArgumentAtIndex(arg_idx)) != NULL; ++arg_idx)
2469             {
2470                 FileSpec file_spec(arg_cstr, false);
2471 
2472                 const ModuleList &target_modules = target->GetImages();
2473                 Mutex::Locker modules_locker(target_modules.GetMutex());
2474                 const size_t num_modules = target_modules.GetSize();
2475                 if (num_modules > 0)
2476                 {
2477                     uint32_t num_dumped = 0;
2478                     for (uint32_t i = 0; i<num_modules; ++i)
2479                     {
2480                         if (DumpCompileUnitLineTable (m_interpreter,
2481                                                       result.GetOutputStream(),
2482                                                       target_modules.GetModulePointerAtIndexUnlocked(i),
2483                                                       file_spec,
2484                                                       m_exe_ctx.GetProcessPtr() && m_exe_ctx.GetProcessRef().IsAlive()))
2485                             num_dumped++;
2486                     }
2487                     if (num_dumped == 0)
2488                         result.AppendWarningWithFormat ("No source filenames matched '%s'.\n", arg_cstr);
2489                     else
2490                         total_num_dumped += num_dumped;
2491                 }
2492             }
2493         }
2494 
2495         if (total_num_dumped > 0)
2496             result.SetStatus (eReturnStatusSuccessFinishResult);
2497         else
2498         {
2499             result.AppendError ("no source filenames matched any command arguments");
2500             result.SetStatus (eReturnStatusFailed);
2501         }
2502         return result.Succeeded();
2503     }
2504 };
2505 
2506 
2507 #pragma mark CommandObjectTargetModulesDump
2508 
2509 //----------------------------------------------------------------------
2510 // Dump multi-word command for target modules
2511 //----------------------------------------------------------------------
2512 
2513 class CommandObjectTargetModulesDump : public CommandObjectMultiword
2514 {
2515 public:
2516 
2517     //------------------------------------------------------------------
2518     // Constructors and Destructors
2519     //------------------------------------------------------------------
2520     CommandObjectTargetModulesDump(CommandInterpreter &interpreter) :
2521     CommandObjectMultiword (interpreter,
2522                             "target modules dump",
2523                             "A set of commands for dumping information about one or more target modules.",
2524                             "target modules dump [symtab|sections|symfile|line-table] [<file1> <file2> ...]")
2525     {
2526         LoadSubCommand ("symtab",      CommandObjectSP (new CommandObjectTargetModulesDumpSymtab (interpreter)));
2527         LoadSubCommand ("sections",    CommandObjectSP (new CommandObjectTargetModulesDumpSections (interpreter)));
2528         LoadSubCommand ("symfile",     CommandObjectSP (new CommandObjectTargetModulesDumpSymfile (interpreter)));
2529         LoadSubCommand ("line-table",  CommandObjectSP (new CommandObjectTargetModulesDumpLineTable (interpreter)));
2530     }
2531 
2532     virtual
2533     ~CommandObjectTargetModulesDump()
2534     {
2535     }
2536 };
2537 
2538 class CommandObjectTargetModulesAdd : public CommandObjectParsed
2539 {
2540 public:
2541     CommandObjectTargetModulesAdd (CommandInterpreter &interpreter) :
2542         CommandObjectParsed (interpreter,
2543                              "target modules add",
2544                              "Add a new module to the current target's modules.",
2545                              "target modules add [<module>]"),
2546         m_option_group (interpreter),
2547         m_symbol_file (LLDB_OPT_SET_1, false, "symfile", 's', 0, eArgTypeFilename, "Fullpath to a stand alone debug symbols file for when debug symbols are not in the executable.")
2548     {
2549         m_option_group.Append (&m_uuid_option_group, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
2550         m_option_group.Append (&m_symbol_file, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
2551         m_option_group.Finalize();
2552     }
2553 
2554     virtual
2555     ~CommandObjectTargetModulesAdd ()
2556     {
2557     }
2558 
2559     virtual Options *
2560     GetOptions ()
2561     {
2562         return &m_option_group;
2563     }
2564 
2565     virtual int
2566     HandleArgumentCompletion (Args &input,
2567                               int &cursor_index,
2568                               int &cursor_char_position,
2569                               OptionElementVector &opt_element_vector,
2570                               int match_start_point,
2571                               int max_return_elements,
2572                               bool &word_complete,
2573                               StringList &matches)
2574     {
2575         std::string completion_str (input.GetArgumentAtIndex(cursor_index));
2576         completion_str.erase (cursor_char_position);
2577 
2578         CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
2579                                                              CommandCompletions::eDiskFileCompletion,
2580                                                              completion_str.c_str(),
2581                                                              match_start_point,
2582                                                              max_return_elements,
2583                                                              NULL,
2584                                                              word_complete,
2585                                                              matches);
2586         return matches.GetSize();
2587     }
2588 
2589 protected:
2590 
2591     OptionGroupOptions m_option_group;
2592     OptionGroupUUID m_uuid_option_group;
2593     OptionGroupFile m_symbol_file;
2594 
2595 
2596     virtual bool
2597     DoExecute (Args& args,
2598              CommandReturnObject &result)
2599     {
2600         Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
2601         if (target == NULL)
2602         {
2603             result.AppendError ("invalid target, create a debug target using the 'target create' command");
2604             result.SetStatus (eReturnStatusFailed);
2605             return false;
2606         }
2607         else
2608         {
2609             bool flush = false;
2610 
2611             const size_t argc = args.GetArgumentCount();
2612             if (argc == 0)
2613             {
2614                 if (m_uuid_option_group.GetOptionValue ().OptionWasSet())
2615                 {
2616                     // We are given a UUID only, go locate the file
2617                     ModuleSpec module_spec;
2618                     module_spec.GetUUID() = m_uuid_option_group.GetOptionValue ().GetCurrentValue();
2619                     if (m_symbol_file.GetOptionValue().OptionWasSet())
2620                         module_spec.GetSymbolFileSpec() = m_symbol_file.GetOptionValue().GetCurrentValue();
2621                     if (Symbols::DownloadObjectAndSymbolFile (module_spec))
2622                     {
2623                         ModuleSP module_sp (target->GetSharedModule (module_spec));
2624                         if (module_sp)
2625                         {
2626                             result.SetStatus (eReturnStatusSuccessFinishResult);
2627                             return true;
2628                         }
2629                         else
2630                         {
2631                             flush = true;
2632 
2633                             StreamString strm;
2634                             module_spec.GetUUID().Dump (&strm);
2635                             if (module_spec.GetFileSpec())
2636                             {
2637                                 if (module_spec.GetSymbolFileSpec())
2638                                 {
2639                                     result.AppendErrorWithFormat ("Unable to create the executable or symbol file with UUID %s with path %s and symbol file %s",
2640                                                                   strm.GetString().c_str(),
2641                                                                   module_spec.GetFileSpec().GetPath().c_str(),
2642                                                                   module_spec.GetSymbolFileSpec().GetPath().c_str());
2643                                 }
2644                                 else
2645                                 {
2646                                     result.AppendErrorWithFormat ("Unable to create the executable or symbol file with UUID %s with path %s",
2647                                                                   strm.GetString().c_str(),
2648                                                                   module_spec.GetFileSpec().GetPath().c_str());
2649                                 }
2650                             }
2651                             else
2652                             {
2653                                 result.AppendErrorWithFormat ("Unable to create the executable or symbol file with UUID %s",
2654                                                               strm.GetString().c_str());
2655                             }
2656                             result.SetStatus (eReturnStatusFailed);
2657                             return false;
2658                         }
2659                     }
2660                     else
2661                     {
2662                         StreamString strm;
2663                         module_spec.GetUUID().Dump (&strm);
2664                         result.AppendErrorWithFormat ("Unable to locate the executable or symbol file with UUID %s", strm.GetString().c_str());
2665                         result.SetStatus (eReturnStatusFailed);
2666                         return false;
2667                     }
2668                 }
2669                 else
2670                 {
2671                     result.AppendError ("one or more executable image paths must be specified");
2672                     result.SetStatus (eReturnStatusFailed);
2673                     return false;
2674                 }
2675             }
2676             else
2677             {
2678                 for (size_t i=0; i<argc; ++i)
2679                 {
2680                     const char *path = args.GetArgumentAtIndex(i);
2681                     if (path)
2682                     {
2683                         FileSpec file_spec(path, true);
2684                         if (file_spec.Exists())
2685                         {
2686                             ModuleSpec module_spec (file_spec);
2687                             if (m_uuid_option_group.GetOptionValue ().OptionWasSet())
2688                                 module_spec.GetUUID() = m_uuid_option_group.GetOptionValue ().GetCurrentValue();
2689                             if (m_symbol_file.GetOptionValue().OptionWasSet())
2690                                 module_spec.GetSymbolFileSpec() = m_symbol_file.GetOptionValue().GetCurrentValue();
2691                             Error error;
2692                             ModuleSP module_sp (target->GetSharedModule (module_spec, &error));
2693                             if (!module_sp)
2694                             {
2695                                 const char *error_cstr = error.AsCString();
2696                                 if (error_cstr)
2697                                     result.AppendError (error_cstr);
2698                                 else
2699                                     result.AppendErrorWithFormat ("unsupported module: %s", path);
2700                                 result.SetStatus (eReturnStatusFailed);
2701                                 return false;
2702                             }
2703                             else
2704                             {
2705                                 flush = true;
2706                             }
2707                             result.SetStatus (eReturnStatusSuccessFinishResult);
2708                         }
2709                         else
2710                         {
2711                             char resolved_path[PATH_MAX];
2712                             result.SetStatus (eReturnStatusFailed);
2713                             if (file_spec.GetPath (resolved_path, sizeof(resolved_path)))
2714                             {
2715                                 if (strcmp (resolved_path, path) != 0)
2716                                 {
2717                                     result.AppendErrorWithFormat ("invalid module path '%s' with resolved path '%s'\n", path, resolved_path);
2718                                     break;
2719                                 }
2720                             }
2721                             result.AppendErrorWithFormat ("invalid module path '%s'\n", path);
2722                             break;
2723                         }
2724                     }
2725                 }
2726             }
2727 
2728             if (flush)
2729             {
2730                 ProcessSP process = target->GetProcessSP();
2731                 if (process)
2732                     process->Flush();
2733             }
2734         }
2735 
2736         return result.Succeeded();
2737     }
2738 
2739 };
2740 
2741 class CommandObjectTargetModulesLoad : public CommandObjectTargetModulesModuleAutoComplete
2742 {
2743 public:
2744     CommandObjectTargetModulesLoad (CommandInterpreter &interpreter) :
2745         CommandObjectTargetModulesModuleAutoComplete (interpreter,
2746                                                       "target modules load",
2747                                                       "Set the load addresses for one or more sections in a target module.",
2748                                                       "target modules load [--file <module> --uuid <uuid>] <sect-name> <address> [<sect-name> <address> ....]"),
2749         m_option_group (interpreter),
2750         m_file_option (LLDB_OPT_SET_1, false, "file", 'f', 0, eArgTypeFilename, "Fullpath or basename for module to load."),
2751         m_slide_option(LLDB_OPT_SET_1, false, "slide", 's', 0, eArgTypeOffset, "Set the load address for all sections to be the virtual address in the file plus the offset.", 0)
2752     {
2753         m_option_group.Append (&m_uuid_option_group, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
2754         m_option_group.Append (&m_file_option, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
2755         m_option_group.Append (&m_slide_option, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
2756         m_option_group.Finalize();
2757     }
2758 
2759     virtual
2760     ~CommandObjectTargetModulesLoad ()
2761     {
2762     }
2763 
2764     virtual Options *
2765     GetOptions ()
2766     {
2767         return &m_option_group;
2768     }
2769 
2770 protected:
2771     virtual bool
2772     DoExecute (Args& args,
2773              CommandReturnObject &result)
2774     {
2775         Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
2776         if (target == NULL)
2777         {
2778             result.AppendError ("invalid target, create a debug target using the 'target create' command");
2779             result.SetStatus (eReturnStatusFailed);
2780             return false;
2781         }
2782         else
2783         {
2784             const size_t argc = args.GetArgumentCount();
2785             ModuleSpec module_spec;
2786             bool search_using_module_spec = false;
2787             if (m_file_option.GetOptionValue().OptionWasSet())
2788             {
2789                 search_using_module_spec = true;
2790                 module_spec.GetFileSpec() = m_file_option.GetOptionValue().GetCurrentValue();
2791             }
2792 
2793             if (m_uuid_option_group.GetOptionValue().OptionWasSet())
2794             {
2795                 search_using_module_spec = true;
2796                 module_spec.GetUUID() = m_uuid_option_group.GetOptionValue().GetCurrentValue();
2797             }
2798 
2799             if (search_using_module_spec)
2800             {
2801 
2802                 ModuleList matching_modules;
2803                 const size_t num_matches = target->GetImages().FindModules (module_spec, matching_modules);
2804 
2805                 char path[PATH_MAX];
2806                 if (num_matches == 1)
2807                 {
2808                     Module *module = matching_modules.GetModulePointerAtIndex(0);
2809                     if (module)
2810                     {
2811                         ObjectFile *objfile = module->GetObjectFile();
2812                         if (objfile)
2813                         {
2814                             SectionList *section_list = objfile->GetSectionList();
2815                             if (section_list)
2816                             {
2817                                 bool changed = false;
2818                                 if (argc == 0)
2819                                 {
2820                                     if (m_slide_option.GetOptionValue().OptionWasSet())
2821                                     {
2822                                         const addr_t slide = m_slide_option.GetOptionValue().GetCurrentValue();
2823                                         module->SetLoadAddress (*target, slide, changed);
2824                                     }
2825                                     else
2826                                     {
2827                                         result.AppendError ("one or more section name + load address pair must be specified");
2828                                         result.SetStatus (eReturnStatusFailed);
2829                                         return false;
2830                                     }
2831                                 }
2832                                 else
2833                                 {
2834                                     if (m_slide_option.GetOptionValue().OptionWasSet())
2835                                     {
2836                                         result.AppendError ("The \"--slide <offset>\" option can't be used in conjunction with setting section load addresses.\n");
2837                                         result.SetStatus (eReturnStatusFailed);
2838                                         return false;
2839                                     }
2840 
2841                                     for (size_t i=0; i<argc; i += 2)
2842                                     {
2843                                         const char *sect_name = args.GetArgumentAtIndex(i);
2844                                         const char *load_addr_cstr = args.GetArgumentAtIndex(i+1);
2845                                         if (sect_name && load_addr_cstr)
2846                                         {
2847                                             ConstString const_sect_name(sect_name);
2848                                             bool success = false;
2849                                             addr_t load_addr = Args::StringToUInt64(load_addr_cstr, LLDB_INVALID_ADDRESS, 0, &success);
2850                                             if (success)
2851                                             {
2852                                                 SectionSP section_sp (section_list->FindSectionByName(const_sect_name));
2853                                                 if (section_sp)
2854                                                 {
2855                                                     if (section_sp->IsThreadSpecific())
2856                                                     {
2857                                                         result.AppendErrorWithFormat ("thread specific sections are not yet supported (section '%s')\n", sect_name);
2858                                                         result.SetStatus (eReturnStatusFailed);
2859                                                         break;
2860                                                     }
2861                                                     else
2862                                                     {
2863                                                         if (target->GetSectionLoadList().SetSectionLoadAddress (section_sp, load_addr))
2864                                                             changed = true;
2865                                                         result.AppendMessageWithFormat("section '%s' loaded at 0x%" PRIx64 "\n", sect_name, load_addr);
2866                                                     }
2867                                                 }
2868                                                 else
2869                                                 {
2870                                                     result.AppendErrorWithFormat ("no section found that matches the section name '%s'\n", sect_name);
2871                                                     result.SetStatus (eReturnStatusFailed);
2872                                                     break;
2873                                                 }
2874                                             }
2875                                             else
2876                                             {
2877                                                 result.AppendErrorWithFormat ("invalid load address string '%s'\n", load_addr_cstr);
2878                                                 result.SetStatus (eReturnStatusFailed);
2879                                                 break;
2880                                             }
2881                                         }
2882                                         else
2883                                         {
2884                                             if (sect_name)
2885                                                 result.AppendError ("section names must be followed by a load address.\n");
2886                                             else
2887                                                 result.AppendError ("one or more section name + load address pair must be specified.\n");
2888                                             result.SetStatus (eReturnStatusFailed);
2889                                             break;
2890                                         }
2891                                     }
2892                                 }
2893 
2894                                 if (changed)
2895                                 {
2896                                     target->ModulesDidLoad (matching_modules);
2897                                     Process *process = m_exe_ctx.GetProcessPtr();
2898                                     if (process)
2899                                         process->Flush();
2900                                 }
2901                             }
2902                             else
2903                             {
2904                                 module->GetFileSpec().GetPath (path, sizeof(path));
2905                                 result.AppendErrorWithFormat ("no sections in object file '%s'\n", path);
2906                                 result.SetStatus (eReturnStatusFailed);
2907                             }
2908                         }
2909                         else
2910                         {
2911                             module->GetFileSpec().GetPath (path, sizeof(path));
2912                             result.AppendErrorWithFormat ("no object file for module '%s'\n", path);
2913                             result.SetStatus (eReturnStatusFailed);
2914                         }
2915                     }
2916                     else
2917                     {
2918                         FileSpec *module_spec_file = module_spec.GetFileSpecPtr();
2919                         if (module_spec_file)
2920                         {
2921                             module_spec_file->GetPath (path, sizeof(path));
2922                             result.AppendErrorWithFormat ("invalid module '%s'.\n", path);
2923                         }
2924                         else
2925                             result.AppendError ("no module spec");
2926                         result.SetStatus (eReturnStatusFailed);
2927                     }
2928                 }
2929                 else
2930                 {
2931                     char uuid_cstr[64];
2932 
2933                     if (module_spec.GetFileSpec())
2934                         module_spec.GetFileSpec().GetPath (path, sizeof(path));
2935                     else
2936                         path[0] = '\0';
2937 
2938                     if (module_spec.GetUUIDPtr())
2939                         module_spec.GetUUID().GetAsCString(uuid_cstr, sizeof(uuid_cstr));
2940                     else
2941                         uuid_cstr[0] = '\0';
2942                     if (num_matches > 1)
2943                     {
2944                         result.AppendErrorWithFormat ("multiple modules match%s%s%s%s:\n",
2945                                                       path[0] ? " file=" : "",
2946                                                       path,
2947                                                       uuid_cstr[0] ? " uuid=" : "",
2948                                                       uuid_cstr);
2949                         for (size_t i=0; i<num_matches; ++i)
2950                         {
2951                             if (matching_modules.GetModulePointerAtIndex(i)->GetFileSpec().GetPath (path, sizeof(path)))
2952                                 result.AppendMessageWithFormat("%s\n", path);
2953                         }
2954                     }
2955                     else
2956                     {
2957                         result.AppendErrorWithFormat ("no modules were found  that match%s%s%s%s.\n",
2958                                                       path[0] ? " file=" : "",
2959                                                       path,
2960                                                       uuid_cstr[0] ? " uuid=" : "",
2961                                                       uuid_cstr);
2962                     }
2963                     result.SetStatus (eReturnStatusFailed);
2964                 }
2965             }
2966             else
2967             {
2968                 result.AppendError ("either the \"--file <module>\" or the \"--uuid <uuid>\" option must be specified.\n");
2969                 result.SetStatus (eReturnStatusFailed);
2970                 return false;
2971             }
2972         }
2973         return result.Succeeded();
2974     }
2975 
2976     OptionGroupOptions m_option_group;
2977     OptionGroupUUID m_uuid_option_group;
2978     OptionGroupFile m_file_option;
2979     OptionGroupUInt64 m_slide_option;
2980 };
2981 
2982 //----------------------------------------------------------------------
2983 // List images with associated information
2984 //----------------------------------------------------------------------
2985 class CommandObjectTargetModulesList : public CommandObjectParsed
2986 {
2987 public:
2988 
2989     class CommandOptions : public Options
2990     {
2991     public:
2992 
2993         CommandOptions (CommandInterpreter &interpreter) :
2994             Options(interpreter),
2995             m_format_array(),
2996             m_use_global_module_list (false),
2997             m_module_addr (LLDB_INVALID_ADDRESS)
2998         {
2999         }
3000 
3001         virtual
3002         ~CommandOptions ()
3003         {
3004         }
3005 
3006         virtual Error
3007         SetOptionValue (uint32_t option_idx, const char *option_arg)
3008         {
3009             Error error;
3010 
3011             const int short_option = m_getopt_table[option_idx].val;
3012             if (short_option == 'g')
3013             {
3014                 m_use_global_module_list = true;
3015             }
3016             else if (short_option == 'a')
3017             {
3018                 ExecutionContext exe_ctx (m_interpreter.GetExecutionContext());
3019                 m_module_addr = Args::StringToAddress(&exe_ctx, option_arg, LLDB_INVALID_ADDRESS, &error);
3020             }
3021             else
3022             {
3023                 unsigned long width = 0;
3024                 if (option_arg)
3025                     width = strtoul (option_arg, NULL, 0);
3026                 m_format_array.push_back(std::make_pair(short_option, width));
3027             }
3028             return error;
3029         }
3030 
3031         void
3032         OptionParsingStarting ()
3033         {
3034             m_format_array.clear();
3035             m_use_global_module_list = false;
3036             m_module_addr = LLDB_INVALID_ADDRESS;
3037         }
3038 
3039         const OptionDefinition*
3040         GetDefinitions ()
3041         {
3042             return g_option_table;
3043         }
3044 
3045         // Options table: Required for subclasses of Options.
3046 
3047         static OptionDefinition g_option_table[];
3048 
3049         // Instance variables to hold the values for command options.
3050         typedef std::vector< std::pair<char, uint32_t> > FormatWidthCollection;
3051         FormatWidthCollection m_format_array;
3052         bool m_use_global_module_list;
3053         lldb::addr_t m_module_addr;
3054     };
3055 
3056     CommandObjectTargetModulesList (CommandInterpreter &interpreter) :
3057         CommandObjectParsed (interpreter,
3058                              "target modules list",
3059                              "List current executable and dependent shared library images.",
3060                              "target modules list [<cmd-options>]"),
3061         m_options (interpreter)
3062     {
3063     }
3064 
3065     virtual
3066     ~CommandObjectTargetModulesList ()
3067     {
3068     }
3069 
3070     virtual
3071     Options *
3072     GetOptions ()
3073     {
3074         return &m_options;
3075     }
3076 
3077 protected:
3078     virtual bool
3079     DoExecute (Args& command,
3080              CommandReturnObject &result)
3081     {
3082         Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
3083         const bool use_global_module_list = m_options.m_use_global_module_list;
3084         // Define a local module list here to ensure it lives longer than any "locker"
3085         // object which might lock its contents below (through the "module_list_ptr"
3086         // variable).
3087         ModuleList module_list;
3088         if (target == NULL && use_global_module_list == false)
3089         {
3090             result.AppendError ("invalid target, create a debug target using the 'target create' command");
3091             result.SetStatus (eReturnStatusFailed);
3092             return false;
3093         }
3094         else
3095         {
3096             if (target)
3097             {
3098                 uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize();
3099                 result.GetOutputStream().SetAddressByteSize(addr_byte_size);
3100                 result.GetErrorStream().SetAddressByteSize(addr_byte_size);
3101             }
3102             // Dump all sections for all modules images
3103             Stream &strm = result.GetOutputStream();
3104 
3105             if (m_options.m_module_addr != LLDB_INVALID_ADDRESS)
3106             {
3107                 if (target)
3108                 {
3109                     Address module_address;
3110                     if (module_address.SetLoadAddress(m_options.m_module_addr, target))
3111                     {
3112                         ModuleSP module_sp (module_address.GetModule());
3113                         if (module_sp)
3114                         {
3115                             PrintModule (target, module_sp.get(), 0, strm);
3116                             result.SetStatus (eReturnStatusSuccessFinishResult);
3117                         }
3118                         else
3119                         {
3120                             result.AppendErrorWithFormat ("Couldn't find module matching address: 0x%" PRIx64 ".", m_options.m_module_addr);
3121                             result.SetStatus (eReturnStatusFailed);
3122                         }
3123                     }
3124                     else
3125                     {
3126                         result.AppendErrorWithFormat ("Couldn't find module containing address: 0x%" PRIx64 ".", m_options.m_module_addr);
3127                         result.SetStatus (eReturnStatusFailed);
3128                     }
3129                 }
3130                 else
3131                 {
3132                     result.AppendError ("Can only look up modules by address with a valid target.");
3133                     result.SetStatus (eReturnStatusFailed);
3134                 }
3135                 return result.Succeeded();
3136             }
3137 
3138             size_t num_modules = 0;
3139             Mutex::Locker locker;      // This locker will be locked on the mutex in module_list_ptr if it is non-NULL.
3140                                        // Otherwise it will lock the AllocationModuleCollectionMutex when accessing
3141                                        // the global module list directly.
3142             const ModuleList *module_list_ptr = NULL;
3143             const size_t argc = command.GetArgumentCount();
3144             if (argc == 0)
3145             {
3146                 if (use_global_module_list)
3147                 {
3148                     locker.Lock (Module::GetAllocationModuleCollectionMutex());
3149                     num_modules = Module::GetNumberAllocatedModules();
3150                 }
3151                 else
3152                 {
3153                     module_list_ptr = &target->GetImages();
3154                 }
3155             }
3156             else
3157             {
3158                 for (size_t i=0; i<argc; ++i)
3159                 {
3160                     // Dump specified images (by basename or fullpath)
3161                     const char *arg_cstr = command.GetArgumentAtIndex(i);
3162                     const size_t num_matches = FindModulesByName (target, arg_cstr, module_list, use_global_module_list);
3163                     if (num_matches == 0)
3164                     {
3165                         if (argc == 1)
3166                         {
3167                             result.AppendErrorWithFormat ("no modules found that match '%s'", arg_cstr);
3168                             result.SetStatus (eReturnStatusFailed);
3169                             return false;
3170                         }
3171                     }
3172                 }
3173 
3174                 module_list_ptr = &module_list;
3175             }
3176 
3177             if (module_list_ptr != NULL)
3178             {
3179                 locker.Lock(module_list_ptr->GetMutex());
3180                 num_modules = module_list_ptr->GetSize();
3181             }
3182 
3183             if (num_modules > 0)
3184             {
3185                 for (uint32_t image_idx = 0; image_idx<num_modules; ++image_idx)
3186                 {
3187                     ModuleSP module_sp;
3188                     Module *module;
3189                     if (module_list_ptr)
3190                     {
3191                         module_sp = module_list_ptr->GetModuleAtIndexUnlocked(image_idx);
3192                         module = module_sp.get();
3193                     }
3194                     else
3195                     {
3196                         module = Module::GetAllocatedModuleAtIndex(image_idx);
3197                         module_sp = module->shared_from_this();
3198                     }
3199 
3200                     const size_t indent = strm.Printf("[%3u] ", image_idx);
3201                     PrintModule (target, module, indent, strm);
3202 
3203                 }
3204                 result.SetStatus (eReturnStatusSuccessFinishResult);
3205             }
3206             else
3207             {
3208                 if (argc)
3209                 {
3210                     if (use_global_module_list)
3211                         result.AppendError ("the global module list has no matching modules");
3212                     else
3213                         result.AppendError ("the target has no matching modules");
3214                 }
3215                 else
3216                 {
3217                     if (use_global_module_list)
3218                         result.AppendError ("the global module list is empty");
3219                     else
3220                         result.AppendError ("the target has no associated executable images");
3221                 }
3222                 result.SetStatus (eReturnStatusFailed);
3223                 return false;
3224             }
3225         }
3226         return result.Succeeded();
3227     }
3228 
3229     void
3230     PrintModule (Target *target, Module *module, int indent, Stream &strm)
3231     {
3232 
3233         if (module == NULL)
3234         {
3235             strm.PutCString("Null module");
3236             return;
3237         }
3238 
3239         bool dump_object_name = false;
3240         if (m_options.m_format_array.empty())
3241         {
3242             m_options.m_format_array.push_back(std::make_pair('u', 0));
3243             m_options.m_format_array.push_back(std::make_pair('h', 0));
3244             m_options.m_format_array.push_back(std::make_pair('f', 0));
3245             m_options.m_format_array.push_back(std::make_pair('S', 0));
3246         }
3247         const size_t num_entries = m_options.m_format_array.size();
3248         bool print_space = false;
3249         for (size_t i=0; i<num_entries; ++i)
3250         {
3251             if (print_space)
3252                 strm.PutChar(' ');
3253             print_space = true;
3254             const char format_char = m_options.m_format_array[i].first;
3255             uint32_t width = m_options.m_format_array[i].second;
3256             switch (format_char)
3257             {
3258                 case 'A':
3259                     DumpModuleArchitecture (strm, module, false, width);
3260                     break;
3261 
3262                 case 't':
3263                     DumpModuleArchitecture (strm, module, true, width);
3264                     break;
3265 
3266                 case 'f':
3267                     DumpFullpath (strm, &module->GetFileSpec(), width);
3268                     dump_object_name = true;
3269                     break;
3270 
3271                 case 'd':
3272                     DumpDirectory (strm, &module->GetFileSpec(), width);
3273                     break;
3274 
3275                 case 'b':
3276                     DumpBasename (strm, &module->GetFileSpec(), width);
3277                     dump_object_name = true;
3278                     break;
3279 
3280                 case 'h':
3281                 case 'o':
3282                     // Image header address
3283                     {
3284                         uint32_t addr_nibble_width = target ? (target->GetArchitecture().GetAddressByteSize() * 2) : 16;
3285 
3286                         ObjectFile *objfile = module->GetObjectFile ();
3287                         if (objfile)
3288                         {
3289                             Address header_addr(objfile->GetHeaderAddress());
3290                             if (header_addr.IsValid())
3291                             {
3292                                 if (target && !target->GetSectionLoadList().IsEmpty())
3293                                 {
3294                                     lldb::addr_t header_load_addr = header_addr.GetLoadAddress (target);
3295                                     if (header_load_addr == LLDB_INVALID_ADDRESS)
3296                                     {
3297                                         header_addr.Dump (&strm, target, Address::DumpStyleModuleWithFileAddress, Address::DumpStyleFileAddress);
3298                                     }
3299                                     else
3300                                     {
3301                                         if (format_char == 'o')
3302                                         {
3303                                             // Show the offset of slide for the image
3304                                             strm.Printf ("0x%*.*" PRIx64, addr_nibble_width, addr_nibble_width, header_load_addr - header_addr.GetFileAddress());
3305                                         }
3306                                         else
3307                                         {
3308                                             // Show the load address of the image
3309                                             strm.Printf ("0x%*.*" PRIx64, addr_nibble_width, addr_nibble_width, header_load_addr);
3310                                         }
3311                                     }
3312                                     break;
3313                                 }
3314                                 // The address was valid, but the image isn't loaded, output the address in an appropriate format
3315                                 header_addr.Dump (&strm, target, Address::DumpStyleFileAddress);
3316                                 break;
3317                             }
3318                         }
3319                         strm.Printf ("%*s", addr_nibble_width + 2, "");
3320                     }
3321                     break;
3322                 case 'r':
3323                     {
3324                         size_t ref_count = 0;
3325                         ModuleSP module_sp (module->shared_from_this());
3326                         if (module_sp)
3327                         {
3328                             // Take one away to make sure we don't count our local "module_sp"
3329                             ref_count = module_sp.use_count() - 1;
3330                         }
3331                         if (width)
3332                             strm.Printf("{%*zu}", width, ref_count);
3333                         else
3334                             strm.Printf("{%zu}", ref_count);
3335                     }
3336                     break;
3337 
3338                 case 's':
3339                 case 'S':
3340                     {
3341                         SymbolVendor *symbol_vendor = module->GetSymbolVendor();
3342                         if (symbol_vendor)
3343                         {
3344                             SymbolFile *symbol_file = symbol_vendor->GetSymbolFile();
3345                             if (symbol_file)
3346                             {
3347                                 if (format_char == 'S')
3348                                 {
3349                                     FileSpec &symfile_spec = symbol_file->GetObjectFile()->GetFileSpec();
3350                                     // Dump symbol file only if different from module file
3351                                     if (!symfile_spec || symfile_spec == module->GetFileSpec())
3352                                     {
3353                                         print_space = false;
3354                                         break;
3355                                     }
3356                                     // Add a newline and indent past the index
3357                                     strm.Printf ("\n%*s", indent, "");
3358                                 }
3359                                 DumpFullpath (strm, &symbol_file->GetObjectFile()->GetFileSpec(), width);
3360                                 dump_object_name = true;
3361                                 break;
3362                             }
3363                         }
3364                         strm.Printf("%.*s", width, "<NONE>");
3365                     }
3366                     break;
3367 
3368                 case 'm':
3369                     module->GetModificationTime().Dump(&strm, width);
3370                     break;
3371 
3372                 case 'p':
3373                     strm.Printf("%p", module);
3374                     break;
3375 
3376                 case 'u':
3377                     DumpModuleUUID(strm, module);
3378                     break;
3379 
3380                 default:
3381                     break;
3382             }
3383 
3384         }
3385         if (dump_object_name)
3386         {
3387             const char *object_name = module->GetObjectName().GetCString();
3388             if (object_name)
3389                 strm.Printf ("(%s)", object_name);
3390         }
3391         strm.EOL();
3392     }
3393 
3394     CommandOptions m_options;
3395 };
3396 
3397 OptionDefinition
3398 CommandObjectTargetModulesList::CommandOptions::g_option_table[] =
3399 {
3400     { LLDB_OPT_SET_1, false, "address",    'a', required_argument, NULL, 0, eArgTypeAddressOrExpression, "Display the image at this address."},
3401     { LLDB_OPT_SET_1, false, "arch",       'A', optional_argument, NULL, 0, eArgTypeWidth,   "Display the architecture when listing images."},
3402     { LLDB_OPT_SET_1, false, "triple",     't', optional_argument, NULL, 0, eArgTypeWidth,   "Display the triple when listing images."},
3403     { LLDB_OPT_SET_1, false, "header",     'h', no_argument,       NULL, 0, eArgTypeNone,    "Display the image header address as a load address if debugging, a file address otherwise."},
3404     { LLDB_OPT_SET_1, false, "offset",     'o', no_argument,       NULL, 0, eArgTypeNone,    "Display the image header address offset from the header file address (the slide amount)."},
3405     { LLDB_OPT_SET_1, false, "uuid",       'u', no_argument,       NULL, 0, eArgTypeNone,    "Display the UUID when listing images."},
3406     { LLDB_OPT_SET_1, false, "fullpath",   'f', optional_argument, NULL, 0, eArgTypeWidth,   "Display the fullpath to the image object file."},
3407     { LLDB_OPT_SET_1, false, "directory",  'd', optional_argument, NULL, 0, eArgTypeWidth,   "Display the directory with optional width for the image object file."},
3408     { LLDB_OPT_SET_1, false, "basename",   'b', optional_argument, NULL, 0, eArgTypeWidth,   "Display the basename with optional width for the image object file."},
3409     { LLDB_OPT_SET_1, false, "symfile",    's', optional_argument, NULL, 0, eArgTypeWidth,   "Display the fullpath to the image symbol file with optional width."},
3410     { LLDB_OPT_SET_1, false, "symfile-unique", 'S', optional_argument, NULL, 0, eArgTypeWidth,   "Display the symbol file with optional width only if it is different from the executable object file."},
3411     { LLDB_OPT_SET_1, false, "mod-time",   'm', optional_argument, NULL, 0, eArgTypeWidth,   "Display the modification time with optional width of the module."},
3412     { LLDB_OPT_SET_1, false, "ref-count",  'r', optional_argument, NULL, 0, eArgTypeWidth,   "Display the reference count if the module is still in the shared module cache."},
3413     { LLDB_OPT_SET_1, false, "pointer",    'p', optional_argument, NULL, 0, eArgTypeNone,    "Display the module pointer."},
3414     { LLDB_OPT_SET_1, false, "global",     'g', no_argument,       NULL, 0, eArgTypeNone,    "Display the modules from the global module list, not just the current target."},
3415     { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
3416 };
3417 
3418 #pragma mark CommandObjectTargetModulesShowUnwind
3419 
3420 //----------------------------------------------------------------------
3421 // Lookup unwind information in images
3422 //----------------------------------------------------------------------
3423 
3424 class CommandObjectTargetModulesShowUnwind : public CommandObjectParsed
3425 {
3426 public:
3427 
3428     enum
3429     {
3430         eLookupTypeInvalid = -1,
3431         eLookupTypeAddress = 0,
3432         eLookupTypeSymbol,
3433         eLookupTypeFunction,
3434         eLookupTypeFunctionOrSymbol,
3435         kNumLookupTypes
3436     };
3437 
3438     class CommandOptions : public Options
3439     {
3440     public:
3441 
3442         CommandOptions (CommandInterpreter &interpreter) :
3443             Options(interpreter),
3444             m_type(eLookupTypeInvalid),
3445             m_str(),
3446             m_addr(LLDB_INVALID_ADDRESS)
3447         {
3448         }
3449 
3450         virtual
3451         ~CommandOptions ()
3452         {
3453         }
3454 
3455         virtual Error
3456         SetOptionValue (uint32_t option_idx, const char *option_arg)
3457         {
3458             Error error;
3459 
3460             const int short_option = m_getopt_table[option_idx].val;
3461 
3462             switch (short_option)
3463             {
3464                 case 'a':
3465                 {
3466                     ExecutionContext exe_ctx (m_interpreter.GetExecutionContext());
3467                     m_type = eLookupTypeAddress;
3468                     m_addr = Args::StringToAddress(&exe_ctx, option_arg, LLDB_INVALID_ADDRESS, &error);
3469                     if (m_addr == LLDB_INVALID_ADDRESS)
3470                         error.SetErrorStringWithFormat ("invalid address string '%s'", option_arg);
3471                     break;
3472                 }
3473 
3474                 case 'n':
3475                 {
3476                     m_str = option_arg;
3477                     m_type = eLookupTypeFunctionOrSymbol;
3478                     break;
3479                 }
3480             }
3481 
3482             return error;
3483         }
3484 
3485         void
3486         OptionParsingStarting ()
3487         {
3488             m_type = eLookupTypeInvalid;
3489             m_str.clear();
3490             m_addr = LLDB_INVALID_ADDRESS;
3491         }
3492 
3493         const OptionDefinition*
3494         GetDefinitions ()
3495         {
3496             return g_option_table;
3497         }
3498 
3499         // Options table: Required for subclasses of Options.
3500 
3501         static OptionDefinition g_option_table[];
3502 
3503         // Instance variables to hold the values for command options.
3504 
3505         int             m_type;         // Should be a eLookupTypeXXX enum after parsing options
3506         std::string     m_str;          // Holds name lookup
3507         lldb::addr_t    m_addr;         // Holds the address to lookup
3508     };
3509 
3510     CommandObjectTargetModulesShowUnwind (CommandInterpreter &interpreter) :
3511         CommandObjectParsed (interpreter,
3512                              "target modules show-unwind",
3513                              "Show synthesized unwind instructions for a function.",
3514                              NULL,
3515                              eFlagRequiresTarget        |
3516                              eFlagRequiresProcess       |
3517                              eFlagProcessMustBeLaunched |
3518                              eFlagProcessMustBePaused   ),
3519         m_options (interpreter)
3520     {
3521     }
3522 
3523     virtual
3524     ~CommandObjectTargetModulesShowUnwind ()
3525     {
3526     }
3527 
3528     virtual
3529     Options *
3530     GetOptions ()
3531     {
3532         return &m_options;
3533     }
3534 
3535 protected:
3536     bool
3537     DoExecute (Args& command,
3538              CommandReturnObject &result)
3539     {
3540         Target *target = m_exe_ctx.GetTargetPtr();
3541         Process *process = m_exe_ctx.GetProcessPtr();
3542         ABI *abi = NULL;
3543         if (process)
3544           abi = process->GetABI().get();
3545 
3546         if (process == NULL)
3547         {
3548             result.AppendError ("You must have a process running to use this command.");
3549             result.SetStatus (eReturnStatusFailed);
3550             return false;
3551         }
3552 
3553         ThreadList threads(process->GetThreadList());
3554         if (threads.GetSize() == 0)
3555         {
3556             result.AppendError ("The process must be paused to use this command.");
3557             result.SetStatus (eReturnStatusFailed);
3558             return false;
3559         }
3560 
3561         ThreadSP thread(threads.GetThreadAtIndex(0));
3562         if (thread.get() == NULL)
3563         {
3564             result.AppendError ("The process must be paused to use this command.");
3565             result.SetStatus (eReturnStatusFailed);
3566             return false;
3567         }
3568 
3569         SymbolContextList sc_list;
3570 
3571         if (m_options.m_type == eLookupTypeFunctionOrSymbol)
3572         {
3573             ConstString function_name (m_options.m_str.c_str());
3574             target->GetImages().FindFunctions (function_name, eFunctionNameTypeAuto, true, false, true, sc_list);
3575         }
3576         else if (m_options.m_type == eLookupTypeAddress && target)
3577         {
3578             Address addr;
3579             if (target->GetSectionLoadList().ResolveLoadAddress (m_options.m_addr, addr))
3580             {
3581                 SymbolContext sc;
3582                 ModuleSP module_sp (addr.GetModule());
3583                 module_sp->ResolveSymbolContextForAddress (addr, eSymbolContextEverything, sc);
3584                 if (sc.function || sc.symbol)
3585                 {
3586                     sc_list.Append(sc);
3587                 }
3588             }
3589         }
3590 
3591         size_t num_matches = sc_list.GetSize();
3592         for (uint32_t idx = 0; idx < num_matches; idx++)
3593         {
3594             SymbolContext sc;
3595             sc_list.GetContextAtIndex(idx, sc);
3596             if (sc.symbol == NULL && sc.function == NULL)
3597                 continue;
3598             if (sc.module_sp.get() == NULL || sc.module_sp->GetObjectFile() == NULL)
3599                 continue;
3600             AddressRange range;
3601             if (!sc.GetAddressRange (eSymbolContextFunction | eSymbolContextSymbol, 0, false, range))
3602                 continue;
3603             if (!range.GetBaseAddress().IsValid())
3604                 continue;
3605             ConstString funcname(sc.GetFunctionName());
3606             if (funcname.IsEmpty())
3607                 continue;
3608             addr_t start_addr = range.GetBaseAddress().GetLoadAddress(target);
3609             if (abi)
3610                 start_addr = abi->FixCodeAddress(start_addr);
3611 
3612             FuncUnwindersSP func_unwinders_sp (sc.module_sp->GetObjectFile()->GetUnwindTable().GetUncachedFuncUnwindersContainingAddress(start_addr, sc));
3613             if (func_unwinders_sp.get() == NULL)
3614                 continue;
3615 
3616             Address first_non_prologue_insn (func_unwinders_sp->GetFirstNonPrologueInsn(*target));
3617             if (first_non_prologue_insn.IsValid())
3618             {
3619                 result.GetOutputStream().Printf("First non-prologue instruction is at address 0x%" PRIx64 " or offset %" PRId64 " into the function.\n", first_non_prologue_insn.GetLoadAddress(target), first_non_prologue_insn.GetLoadAddress(target) - start_addr);
3620                 result.GetOutputStream().Printf ("\n");
3621             }
3622 
3623             UnwindPlanSP non_callsite_unwind_plan = func_unwinders_sp->GetUnwindPlanAtNonCallSite(*thread.get());
3624             if (non_callsite_unwind_plan.get())
3625             {
3626                 result.GetOutputStream().Printf("Asynchronous (not restricted to call-sites) UnwindPlan for %s`%s (start addr 0x%" PRIx64 "):\n", sc.module_sp->GetPlatformFileSpec().GetFilename().AsCString(), funcname.AsCString(), start_addr);
3627                 non_callsite_unwind_plan->Dump(result.GetOutputStream(), thread.get(), LLDB_INVALID_ADDRESS);
3628                 result.GetOutputStream().Printf ("\n");
3629             }
3630 
3631             UnwindPlanSP callsite_unwind_plan = func_unwinders_sp->GetUnwindPlanAtCallSite(-1);
3632             if (callsite_unwind_plan.get())
3633             {
3634                 result.GetOutputStream().Printf("Synchronous (restricted to call-sites) UnwindPlan for %s`%s (start addr 0x%" PRIx64 "):\n", sc.module_sp->GetPlatformFileSpec().GetFilename().AsCString(), funcname.AsCString(), start_addr);
3635                 callsite_unwind_plan->Dump(result.GetOutputStream(), thread.get(), LLDB_INVALID_ADDRESS);
3636                 result.GetOutputStream().Printf ("\n");
3637             }
3638 
3639             UnwindPlanSP arch_default_unwind_plan = func_unwinders_sp->GetUnwindPlanArchitectureDefault(*thread.get());
3640             if (arch_default_unwind_plan.get())
3641             {
3642                 result.GetOutputStream().Printf("Architecture default UnwindPlan for %s`%s (start addr 0x%" PRIx64 "):\n", sc.module_sp->GetPlatformFileSpec().GetFilename().AsCString(), funcname.AsCString(), start_addr);
3643                 arch_default_unwind_plan->Dump(result.GetOutputStream(), thread.get(), LLDB_INVALID_ADDRESS);
3644                 result.GetOutputStream().Printf ("\n");
3645             }
3646 
3647             UnwindPlanSP fast_unwind_plan = func_unwinders_sp->GetUnwindPlanFastUnwind(*thread.get());
3648             if (fast_unwind_plan.get())
3649             {
3650                 result.GetOutputStream().Printf("Fast UnwindPlan for %s`%s (start addr 0x%" PRIx64 "):\n", sc.module_sp->GetPlatformFileSpec().GetFilename().AsCString(), funcname.AsCString(), start_addr);
3651                 fast_unwind_plan->Dump(result.GetOutputStream(), thread.get(), LLDB_INVALID_ADDRESS);
3652                 result.GetOutputStream().Printf ("\n");
3653             }
3654 
3655 
3656             result.GetOutputStream().Printf ("\n");
3657         }
3658         return result.Succeeded();
3659     }
3660 
3661     CommandOptions m_options;
3662 };
3663 
3664 OptionDefinition
3665 CommandObjectTargetModulesShowUnwind::CommandOptions::g_option_table[] =
3666 {
3667     { LLDB_OPT_SET_1,   false,  "name",       'n', required_argument, NULL, 0, eArgTypeFunctionName, "Show unwind instructions for a function or symbol name."},
3668     { LLDB_OPT_SET_2,   false,  "address",    'a', required_argument, NULL, 0, eArgTypeAddressOrExpression, "Show unwind instructions for a function or symbol containing an address"},
3669     { 0,                false, NULL,           0, 0,                 NULL, 0, eArgTypeNone, NULL }
3670 };
3671 
3672 //----------------------------------------------------------------------
3673 // Lookup information in images
3674 //----------------------------------------------------------------------
3675 class CommandObjectTargetModulesLookup : public CommandObjectParsed
3676 {
3677 public:
3678 
3679     enum
3680     {
3681         eLookupTypeInvalid = -1,
3682         eLookupTypeAddress = 0,
3683         eLookupTypeSymbol,
3684         eLookupTypeFileLine,    // Line is optional
3685         eLookupTypeFunction,
3686         eLookupTypeFunctionOrSymbol,
3687         eLookupTypeType,
3688         kNumLookupTypes
3689     };
3690 
3691     class CommandOptions : public Options
3692     {
3693     public:
3694 
3695         CommandOptions (CommandInterpreter &interpreter) :
3696         Options(interpreter)
3697         {
3698             OptionParsingStarting();
3699         }
3700 
3701         virtual
3702         ~CommandOptions ()
3703         {
3704         }
3705 
3706         virtual Error
3707         SetOptionValue (uint32_t option_idx, const char *option_arg)
3708         {
3709             Error error;
3710 
3711             const int short_option = m_getopt_table[option_idx].val;
3712 
3713             switch (short_option)
3714             {
3715                 case 'a':
3716                     {
3717                         m_type = eLookupTypeAddress;
3718                         ExecutionContext exe_ctx (m_interpreter.GetExecutionContext());
3719                         m_addr = Args::StringToAddress(&exe_ctx, option_arg, LLDB_INVALID_ADDRESS, &error);
3720                     }
3721                     break;
3722 
3723                 case 'o':
3724                     m_offset = Args::StringToUInt64(option_arg, LLDB_INVALID_ADDRESS);
3725                     if (m_offset == LLDB_INVALID_ADDRESS)
3726                         error.SetErrorStringWithFormat ("invalid offset string '%s'", option_arg);
3727                     break;
3728 
3729                 case 's':
3730                     m_str = option_arg;
3731                     m_type = eLookupTypeSymbol;
3732                     break;
3733 
3734                 case 'f':
3735                     m_file.SetFile (option_arg, false);
3736                     m_type = eLookupTypeFileLine;
3737                     break;
3738 
3739                 case 'i':
3740                     m_include_inlines = false;
3741                     break;
3742 
3743                 case 'l':
3744                     m_line_number = Args::StringToUInt32(option_arg, UINT32_MAX);
3745                     if (m_line_number == UINT32_MAX)
3746                         error.SetErrorStringWithFormat ("invalid line number string '%s'", option_arg);
3747                     else if (m_line_number == 0)
3748                         error.SetErrorString ("zero is an invalid line number");
3749                     m_type = eLookupTypeFileLine;
3750                     break;
3751 
3752                 case 'F':
3753                     m_str = option_arg;
3754                     m_type = eLookupTypeFunction;
3755                     break;
3756 
3757                 case 'n':
3758                     m_str = option_arg;
3759                     m_type = eLookupTypeFunctionOrSymbol;
3760                     break;
3761 
3762                 case 't':
3763                     m_str = option_arg;
3764                     m_type = eLookupTypeType;
3765                     break;
3766 
3767                 case 'v':
3768                     m_verbose = 1;
3769                     break;
3770 
3771                 case 'A':
3772                     m_print_all = true;
3773                     break;
3774 
3775                 case 'r':
3776                     m_use_regex = true;
3777                     break;
3778             }
3779 
3780             return error;
3781         }
3782 
3783         void
3784         OptionParsingStarting ()
3785         {
3786             m_type = eLookupTypeInvalid;
3787             m_str.clear();
3788             m_file.Clear();
3789             m_addr = LLDB_INVALID_ADDRESS;
3790             m_offset = 0;
3791             m_line_number = 0;
3792             m_use_regex = false;
3793             m_include_inlines = true;
3794             m_verbose = false;
3795             m_print_all = false;
3796         }
3797 
3798         const OptionDefinition*
3799         GetDefinitions ()
3800         {
3801             return g_option_table;
3802         }
3803 
3804         // Options table: Required for subclasses of Options.
3805 
3806         static OptionDefinition g_option_table[];
3807         int             m_type;         // Should be a eLookupTypeXXX enum after parsing options
3808         std::string     m_str;          // Holds name lookup
3809         FileSpec        m_file;         // Files for file lookups
3810         lldb::addr_t    m_addr;         // Holds the address to lookup
3811         lldb::addr_t    m_offset;       // Subtract this offset from m_addr before doing lookups.
3812         uint32_t        m_line_number;  // Line number for file+line lookups
3813         bool            m_use_regex;    // Name lookups in m_str are regular expressions.
3814         bool            m_include_inlines;// Check for inline entries when looking up by file/line.
3815         bool            m_verbose;      // Enable verbose lookup info
3816         bool            m_print_all;    // Print all matches, even in cases where there's a best match.
3817 
3818     };
3819 
3820     CommandObjectTargetModulesLookup (CommandInterpreter &interpreter) :
3821         CommandObjectParsed (interpreter,
3822                              "target modules lookup",
3823                              "Look up information within executable and dependent shared library images.",
3824                              NULL,
3825                              eFlagRequiresTarget),
3826         m_options (interpreter)
3827     {
3828         CommandArgumentEntry arg;
3829         CommandArgumentData file_arg;
3830 
3831         // Define the first (and only) variant of this arg.
3832         file_arg.arg_type = eArgTypeFilename;
3833         file_arg.arg_repetition = eArgRepeatStar;
3834 
3835         // There is only one variant this argument could be; put it into the argument entry.
3836         arg.push_back (file_arg);
3837 
3838         // Push the data for the first argument into the m_arguments vector.
3839         m_arguments.push_back (arg);
3840     }
3841 
3842     virtual
3843     ~CommandObjectTargetModulesLookup ()
3844     {
3845     }
3846 
3847     virtual Options *
3848     GetOptions ()
3849     {
3850         return &m_options;
3851     }
3852 
3853     bool
3854     LookupHere (CommandInterpreter &interpreter, CommandReturnObject &result, bool &syntax_error)
3855     {
3856         switch (m_options.m_type)
3857         {
3858             case eLookupTypeAddress:
3859             case eLookupTypeFileLine:
3860             case eLookupTypeFunction:
3861             case eLookupTypeFunctionOrSymbol:
3862             case eLookupTypeSymbol:
3863             default:
3864                 return false;
3865             case eLookupTypeType:
3866                 break;
3867         }
3868 
3869         StackFrameSP frame = m_exe_ctx.GetFrameSP();
3870 
3871         if (!frame)
3872             return false;
3873 
3874         const SymbolContext &sym_ctx(frame->GetSymbolContext(eSymbolContextModule));
3875 
3876         if (!sym_ctx.module_sp)
3877             return false;
3878 
3879         switch (m_options.m_type)
3880         {
3881         default:
3882             return false;
3883         case eLookupTypeType:
3884             if (!m_options.m_str.empty())
3885             {
3886                 if (LookupTypeHere (m_interpreter,
3887                                     result.GetOutputStream(),
3888                                     sym_ctx,
3889                                     m_options.m_str.c_str(),
3890                                     m_options.m_use_regex))
3891                 {
3892                     result.SetStatus(eReturnStatusSuccessFinishResult);
3893                     return true;
3894                 }
3895             }
3896             break;
3897         }
3898 
3899         return true;
3900     }
3901 
3902     bool
3903     LookupInModule (CommandInterpreter &interpreter, Module *module, CommandReturnObject &result, bool &syntax_error)
3904     {
3905         switch (m_options.m_type)
3906         {
3907             case eLookupTypeAddress:
3908                 if (m_options.m_addr != LLDB_INVALID_ADDRESS)
3909                 {
3910                     if (LookupAddressInModule (m_interpreter,
3911                                                result.GetOutputStream(),
3912                                                module,
3913                                                eSymbolContextEverything,
3914                                                m_options.m_addr,
3915                                                m_options.m_offset,
3916                                                m_options.m_verbose))
3917                     {
3918                         result.SetStatus(eReturnStatusSuccessFinishResult);
3919                         return true;
3920                     }
3921                 }
3922                 break;
3923 
3924             case eLookupTypeSymbol:
3925                 if (!m_options.m_str.empty())
3926                 {
3927                     if (LookupSymbolInModule (m_interpreter,
3928                                               result.GetOutputStream(),
3929                                               module,
3930                                               m_options.m_str.c_str(),
3931                                               m_options.m_use_regex,
3932                                               m_options.m_verbose))
3933                     {
3934                         result.SetStatus(eReturnStatusSuccessFinishResult);
3935                         return true;
3936                     }
3937                 }
3938                 break;
3939 
3940             case eLookupTypeFileLine:
3941                 if (m_options.m_file)
3942                 {
3943 
3944                     if (LookupFileAndLineInModule (m_interpreter,
3945                                                    result.GetOutputStream(),
3946                                                    module,
3947                                                    m_options.m_file,
3948                                                    m_options.m_line_number,
3949                                                    m_options.m_include_inlines,
3950                                                    m_options.m_verbose))
3951                     {
3952                         result.SetStatus(eReturnStatusSuccessFinishResult);
3953                         return true;
3954                     }
3955                 }
3956                 break;
3957 
3958             case eLookupTypeFunctionOrSymbol:
3959             case eLookupTypeFunction:
3960                 if (!m_options.m_str.empty())
3961                 {
3962                     if (LookupFunctionInModule (m_interpreter,
3963                                                 result.GetOutputStream(),
3964                                                 module,
3965                                                 m_options.m_str.c_str(),
3966                                                 m_options.m_use_regex,
3967                                                 m_options.m_include_inlines,
3968                                                 m_options.m_type == eLookupTypeFunctionOrSymbol, // include symbols
3969                                                 m_options.m_verbose))
3970                     {
3971                         result.SetStatus(eReturnStatusSuccessFinishResult);
3972                         return true;
3973                     }
3974                 }
3975                 break;
3976 
3977 
3978             case eLookupTypeType:
3979                 if (!m_options.m_str.empty())
3980                 {
3981                     if (LookupTypeInModule (m_interpreter,
3982                                             result.GetOutputStream(),
3983                                             module,
3984                                             m_options.m_str.c_str(),
3985                                             m_options.m_use_regex))
3986                     {
3987                         result.SetStatus(eReturnStatusSuccessFinishResult);
3988                         return true;
3989                     }
3990                 }
3991                 break;
3992 
3993             default:
3994                 m_options.GenerateOptionUsage (result.GetErrorStream(), this);
3995                 syntax_error = true;
3996                 break;
3997         }
3998 
3999         result.SetStatus (eReturnStatusFailed);
4000         return false;
4001     }
4002 
4003 protected:
4004     virtual bool
4005     DoExecute (Args& command,
4006              CommandReturnObject &result)
4007     {
4008         Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
4009         if (target == NULL)
4010         {
4011             result.AppendError ("invalid target, create a debug target using the 'target create' command");
4012             result.SetStatus (eReturnStatusFailed);
4013             return false;
4014         }
4015         else
4016         {
4017             bool syntax_error = false;
4018             uint32_t i;
4019             uint32_t num_successful_lookups = 0;
4020             uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize();
4021             result.GetOutputStream().SetAddressByteSize(addr_byte_size);
4022             result.GetErrorStream().SetAddressByteSize(addr_byte_size);
4023             // Dump all sections for all modules images
4024 
4025             if (command.GetArgumentCount() == 0)
4026             {
4027                 ModuleSP current_module;
4028 
4029                 // Where it is possible to look in the current symbol context
4030                 // first, try that.  If this search was successful and --all
4031                 // was not passed, don't print anything else.
4032                 if (LookupHere (m_interpreter, result, syntax_error))
4033                 {
4034                     result.GetOutputStream().EOL();
4035                     num_successful_lookups++;
4036                     if (!m_options.m_print_all)
4037                     {
4038                         result.SetStatus (eReturnStatusSuccessFinishResult);
4039                         return result.Succeeded();
4040                     }
4041                 }
4042 
4043                 // Dump all sections for all other modules
4044 
4045                 const ModuleList &target_modules = target->GetImages();
4046                 Mutex::Locker modules_locker(target_modules.GetMutex());
4047                 const size_t num_modules = target_modules.GetSize();
4048                 if (num_modules > 0)
4049                 {
4050                     for (i = 0; i<num_modules && syntax_error == false; ++i)
4051                     {
4052                         Module *module_pointer = target_modules.GetModulePointerAtIndexUnlocked(i);
4053 
4054                         if (module_pointer != current_module.get() &&
4055                             LookupInModule (m_interpreter, target_modules.GetModulePointerAtIndexUnlocked(i), result, syntax_error))
4056                         {
4057                             result.GetOutputStream().EOL();
4058                             num_successful_lookups++;
4059                         }
4060                     }
4061                 }
4062                 else
4063                 {
4064                     result.AppendError ("the target has no associated executable images");
4065                     result.SetStatus (eReturnStatusFailed);
4066                     return false;
4067                 }
4068             }
4069             else
4070             {
4071                 // Dump specified images (by basename or fullpath)
4072                 const char *arg_cstr;
4073                 for (i = 0; (arg_cstr = command.GetArgumentAtIndex(i)) != NULL && syntax_error == false; ++i)
4074                 {
4075                     ModuleList module_list;
4076                     const size_t num_matches = FindModulesByName (target, arg_cstr, module_list, false);
4077                     if (num_matches > 0)
4078                     {
4079                         for (size_t j=0; j<num_matches; ++j)
4080                         {
4081                             Module *module = module_list.GetModulePointerAtIndex(j);
4082                             if (module)
4083                             {
4084                                 if (LookupInModule (m_interpreter, module, result, syntax_error))
4085                                 {
4086                                     result.GetOutputStream().EOL();
4087                                     num_successful_lookups++;
4088                                 }
4089                             }
4090                         }
4091                     }
4092                     else
4093                         result.AppendWarningWithFormat("Unable to find an image that matches '%s'.\n", arg_cstr);
4094                 }
4095             }
4096 
4097             if (num_successful_lookups > 0)
4098                 result.SetStatus (eReturnStatusSuccessFinishResult);
4099             else
4100                 result.SetStatus (eReturnStatusFailed);
4101         }
4102         return result.Succeeded();
4103     }
4104 
4105     CommandOptions m_options;
4106 };
4107 
4108 OptionDefinition
4109 CommandObjectTargetModulesLookup::CommandOptions::g_option_table[] =
4110 {
4111     { LLDB_OPT_SET_1,   true,  "address",    'a', required_argument, NULL, 0, eArgTypeAddressOrExpression, "Lookup an address in one or more target modules."},
4112     { LLDB_OPT_SET_1,   false, "offset",     'o', required_argument, NULL, 0, eArgTypeOffset,           "When looking up an address subtract <offset> from any addresses before doing the lookup."},
4113     { LLDB_OPT_SET_2| LLDB_OPT_SET_4 | LLDB_OPT_SET_5
4114       /* FIXME: re-enable this for types when the LookupTypeInModule actually uses the regex option: | LLDB_OPT_SET_6 */ ,
4115                         false, "regex",      'r', no_argument,       NULL, 0, eArgTypeNone,             "The <name> argument for name lookups are regular expressions."},
4116     { LLDB_OPT_SET_2,   true,  "symbol",     's', required_argument, NULL, 0, eArgTypeSymbol,           "Lookup a symbol by name in the symbol tables in one or more target modules."},
4117     { LLDB_OPT_SET_3,   true,  "file",       'f', required_argument, NULL, 0, eArgTypeFilename,         "Lookup a file by fullpath or basename in one or more target modules."},
4118     { LLDB_OPT_SET_3,   false, "line",       'l', required_argument, NULL, 0, eArgTypeLineNum,          "Lookup a line number in a file (must be used in conjunction with --file)."},
4119     { LLDB_OPT_SET_FROM_TO(3,5),
4120                         false, "no-inlines", 'i', no_argument,       NULL, 0, eArgTypeNone,             "Ignore inline entries (must be used in conjunction with --file or --function)."},
4121     { LLDB_OPT_SET_4,   true,  "function",   'F', required_argument, NULL, 0, eArgTypeFunctionName,     "Lookup a function by name in the debug symbols in one or more target modules."},
4122     { LLDB_OPT_SET_5,   true,  "name",       'n', required_argument, NULL, 0, eArgTypeFunctionOrSymbol, "Lookup a function or symbol by name in one or more target modules."},
4123     { LLDB_OPT_SET_6,   true,  "type",       't', required_argument, NULL, 0, eArgTypeName,             "Lookup a type by name in the debug symbols in one or more target modules."},
4124     { LLDB_OPT_SET_ALL, false, "verbose",    'v', no_argument,       NULL, 0, eArgTypeNone,             "Enable verbose lookup information."},
4125     { LLDB_OPT_SET_ALL, false, "all",        'A', no_argument,       NULL, 0, eArgTypeNone,             "Print all matches, not just the best match, if a best match is available."},
4126     { 0,                false, NULL,           0, 0,                 NULL, 0, eArgTypeNone,             NULL }
4127 };
4128 
4129 
4130 #pragma mark CommandObjectMultiwordImageSearchPaths
4131 
4132 //-------------------------------------------------------------------------
4133 // CommandObjectMultiwordImageSearchPaths
4134 //-------------------------------------------------------------------------
4135 
4136 class CommandObjectTargetModulesImageSearchPaths : public CommandObjectMultiword
4137 {
4138 public:
4139 
4140     CommandObjectTargetModulesImageSearchPaths (CommandInterpreter &interpreter) :
4141     CommandObjectMultiword (interpreter,
4142                             "target modules search-paths",
4143                             "A set of commands for operating on debugger target image search paths.",
4144                             "target modules search-paths <subcommand> [<subcommand-options>]")
4145     {
4146         LoadSubCommand ("add",     CommandObjectSP (new CommandObjectTargetModulesSearchPathsAdd (interpreter)));
4147         LoadSubCommand ("clear",   CommandObjectSP (new CommandObjectTargetModulesSearchPathsClear (interpreter)));
4148         LoadSubCommand ("insert",  CommandObjectSP (new CommandObjectTargetModulesSearchPathsInsert (interpreter)));
4149         LoadSubCommand ("list",    CommandObjectSP (new CommandObjectTargetModulesSearchPathsList (interpreter)));
4150         LoadSubCommand ("query",   CommandObjectSP (new CommandObjectTargetModulesSearchPathsQuery (interpreter)));
4151     }
4152 
4153     ~CommandObjectTargetModulesImageSearchPaths()
4154     {
4155     }
4156 };
4157 
4158 
4159 
4160 #pragma mark CommandObjectTargetModules
4161 
4162 //-------------------------------------------------------------------------
4163 // CommandObjectTargetModules
4164 //-------------------------------------------------------------------------
4165 
4166 class CommandObjectTargetModules : public CommandObjectMultiword
4167 {
4168 public:
4169     //------------------------------------------------------------------
4170     // Constructors and Destructors
4171     //------------------------------------------------------------------
4172     CommandObjectTargetModules(CommandInterpreter &interpreter) :
4173         CommandObjectMultiword (interpreter,
4174                                 "target modules",
4175                                 "A set of commands for accessing information for one or more target modules.",
4176                                 "target modules <sub-command> ...")
4177     {
4178         LoadSubCommand ("add",          CommandObjectSP (new CommandObjectTargetModulesAdd (interpreter)));
4179         LoadSubCommand ("load",         CommandObjectSP (new CommandObjectTargetModulesLoad (interpreter)));
4180         LoadSubCommand ("dump",         CommandObjectSP (new CommandObjectTargetModulesDump (interpreter)));
4181         LoadSubCommand ("list",         CommandObjectSP (new CommandObjectTargetModulesList (interpreter)));
4182         LoadSubCommand ("lookup",       CommandObjectSP (new CommandObjectTargetModulesLookup (interpreter)));
4183         LoadSubCommand ("search-paths", CommandObjectSP (new CommandObjectTargetModulesImageSearchPaths (interpreter)));
4184         LoadSubCommand ("show-unwind",  CommandObjectSP (new CommandObjectTargetModulesShowUnwind (interpreter)));
4185 
4186     }
4187     virtual
4188     ~CommandObjectTargetModules()
4189     {
4190     }
4191 
4192 private:
4193     //------------------------------------------------------------------
4194     // For CommandObjectTargetModules only
4195     //------------------------------------------------------------------
4196     DISALLOW_COPY_AND_ASSIGN (CommandObjectTargetModules);
4197 };
4198 
4199 
4200 
4201 class CommandObjectTargetSymbolsAdd : public CommandObjectParsed
4202 {
4203 public:
4204     CommandObjectTargetSymbolsAdd (CommandInterpreter &interpreter) :
4205         CommandObjectParsed (interpreter,
4206                              "target symbols add",
4207                              "Add a debug symbol file to one of the target's current modules by specifying a path to a debug symbols file, or using the options to specify a module to download symbols for.",
4208                              "target symbols add [<symfile>]", eFlagRequiresTarget),
4209         m_option_group (interpreter),
4210         m_file_option (LLDB_OPT_SET_1, false, "shlib", 's', CommandCompletions::eModuleCompletion, eArgTypeShlibName, "Fullpath or basename for module to find debug symbols for."),
4211         m_current_frame_option (LLDB_OPT_SET_2, false, "frame", 'F', "Locate the debug symbols the currently selected frame.", false, true)
4212 
4213     {
4214         m_option_group.Append (&m_uuid_option_group, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
4215         m_option_group.Append (&m_file_option, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
4216         m_option_group.Append (&m_current_frame_option, LLDB_OPT_SET_2, LLDB_OPT_SET_2);
4217         m_option_group.Finalize();
4218     }
4219 
4220     virtual
4221     ~CommandObjectTargetSymbolsAdd ()
4222     {
4223     }
4224 
4225     virtual int
4226     HandleArgumentCompletion (Args &input,
4227                               int &cursor_index,
4228                               int &cursor_char_position,
4229                               OptionElementVector &opt_element_vector,
4230                               int match_start_point,
4231                               int max_return_elements,
4232                               bool &word_complete,
4233                               StringList &matches)
4234     {
4235         std::string completion_str (input.GetArgumentAtIndex(cursor_index));
4236         completion_str.erase (cursor_char_position);
4237 
4238         CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
4239                                                              CommandCompletions::eDiskFileCompletion,
4240                                                              completion_str.c_str(),
4241                                                              match_start_point,
4242                                                              max_return_elements,
4243                                                              NULL,
4244                                                              word_complete,
4245                                                              matches);
4246         return matches.GetSize();
4247     }
4248 
4249     virtual Options *
4250     GetOptions ()
4251     {
4252         return &m_option_group;
4253     }
4254 
4255 
4256 protected:
4257 
4258     bool
4259     AddModuleSymbols (Target *target,
4260                       ModuleSpec &module_spec,
4261                       bool &flush,
4262                       CommandReturnObject &result)
4263     {
4264         const FileSpec &symbol_fspec = module_spec.GetSymbolFileSpec();
4265         if (symbol_fspec)
4266         {
4267             char symfile_path[PATH_MAX];
4268             symbol_fspec.GetPath (symfile_path, sizeof(symfile_path));
4269 
4270             if (!module_spec.GetUUID().IsValid())
4271             {
4272                 if (!module_spec.GetFileSpec() && !module_spec.GetPlatformFileSpec())
4273                     module_spec.GetFileSpec().GetFilename() = symbol_fspec.GetFilename();
4274             }
4275             // We now have a module that represents a symbol file
4276             // that can be used for a module that might exist in the
4277             // current target, so we need to find that module in the
4278             // target
4279             ModuleList matching_module_list;
4280             size_t num_matches = target->GetImages().FindModules (module_spec, matching_module_list);
4281             while (num_matches == 0)
4282             {
4283                 ConstString filename_no_extension(module_spec.GetFileSpec().GetFileNameStrippingExtension());
4284                 // Empty string returned, lets bail
4285                 if (!filename_no_extension)
4286                     break;
4287 
4288                 // Check if there was no extension to strip and the basename is the same
4289                 if (filename_no_extension == module_spec.GetFileSpec().GetFilename())
4290                     break;
4291 
4292                 // Replace basename with one less extension
4293                 module_spec.GetFileSpec().GetFilename() = filename_no_extension;
4294 
4295                 num_matches = target->GetImages().FindModules (module_spec, matching_module_list);
4296             }
4297 
4298             if (num_matches > 1)
4299             {
4300                 result.AppendErrorWithFormat ("multiple modules match symbol file '%s', use the --uuid option to resolve the ambiguity.\n", symfile_path);
4301             }
4302             else if (num_matches == 1)
4303             {
4304                 ModuleSP module_sp (matching_module_list.GetModuleAtIndex(0));
4305 
4306                 // The module has not yet created its symbol vendor, we can just
4307                 // give the existing target module the symfile path to use for
4308                 // when it decides to create it!
4309                 module_sp->SetSymbolFileFileSpec (symbol_fspec);
4310 
4311                 SymbolVendor *symbol_vendor = module_sp->GetSymbolVendor(true, &result.GetErrorStream());
4312                 if (symbol_vendor)
4313                 {
4314                     SymbolFile *symbol_file = symbol_vendor->GetSymbolFile();
4315 
4316                     if (symbol_file)
4317                     {
4318                         ObjectFile *object_file = symbol_file->GetObjectFile();
4319 
4320                         if (object_file && object_file->GetFileSpec() == symbol_fspec)
4321                         {
4322                             // Provide feedback that the symfile has been successfully added.
4323                             const FileSpec &module_fs = module_sp->GetFileSpec();
4324                             result.AppendMessageWithFormat("symbol file '%s' has been added to '%s'\n",
4325                                                            symfile_path,
4326                                                            module_fs.GetPath().c_str());
4327 
4328                             // Let clients know something changed in the module
4329                             // if it is currently loaded
4330                             ModuleList module_list;
4331                             module_list.Append (module_sp);
4332                             target->SymbolsDidLoad (module_list);
4333 
4334                             // Make sure we load any scripting resources that may be embedded
4335                             // in the debug info files in case the platform supports that.
4336                             Error error;
4337                             module_sp->LoadScriptingResourceInTarget (target, error);
4338 
4339                             flush = true;
4340                             result.SetStatus (eReturnStatusSuccessFinishResult);
4341                             return true;
4342                         }
4343                     }
4344                 }
4345                 // Clear the symbol file spec if anything went wrong
4346                 module_sp->SetSymbolFileFileSpec (FileSpec());
4347             }
4348 
4349             if (module_spec.GetUUID().IsValid())
4350             {
4351                 StreamString ss_symfile_uuid;
4352                 module_spec.GetUUID().Dump(&ss_symfile_uuid);
4353                 result.AppendErrorWithFormat ("symbol file '%s' (%s) does not match any existing module%s\n",
4354                                               symfile_path,
4355                                               ss_symfile_uuid.GetData(),
4356                                               (symbol_fspec.GetFileType() != FileSpec::eFileTypeRegular)
4357                                                 ? "\n       please specify the full path to the symbol file"
4358                                                 : "");
4359             }
4360             else
4361             {
4362                 result.AppendErrorWithFormat ("symbol file '%s' does not match any existing module%s\n",
4363                                               symfile_path,
4364                                               (symbol_fspec.GetFileType() != FileSpec::eFileTypeRegular)
4365                                                 ? "\n       please specify the full path to the symbol file"
4366                                                 : "");
4367             }
4368         }
4369         else
4370         {
4371             result.AppendError ("one or more executable image paths must be specified");
4372         }
4373         result.SetStatus (eReturnStatusFailed);
4374         return false;
4375     }
4376 
4377     virtual bool
4378     DoExecute (Args& args,
4379              CommandReturnObject &result)
4380     {
4381         Target *target = m_exe_ctx.GetTargetPtr();
4382         result.SetStatus (eReturnStatusFailed);
4383         bool flush = false;
4384         ModuleSpec module_spec;
4385         const bool uuid_option_set = m_uuid_option_group.GetOptionValue().OptionWasSet();
4386         const bool file_option_set = m_file_option.GetOptionValue().OptionWasSet();
4387         const bool frame_option_set = m_current_frame_option.GetOptionValue().OptionWasSet();
4388 
4389         const size_t argc = args.GetArgumentCount();
4390         if (argc == 0)
4391         {
4392             if (uuid_option_set || file_option_set || frame_option_set)
4393             {
4394                 bool success = false;
4395                 bool error_set = false;
4396                 if (frame_option_set)
4397                 {
4398                     Process *process = m_exe_ctx.GetProcessPtr();
4399                     if (process)
4400                     {
4401                         const StateType process_state = process->GetState();
4402                         if (StateIsStoppedState (process_state, true))
4403                         {
4404                             StackFrame *frame = m_exe_ctx.GetFramePtr();
4405                             if (frame)
4406                             {
4407                                 ModuleSP frame_module_sp (frame->GetSymbolContext(eSymbolContextModule).module_sp);
4408                                 if (frame_module_sp)
4409                                 {
4410                                     if (frame_module_sp->GetPlatformFileSpec().Exists())
4411                                     {
4412                                         module_spec.GetArchitecture() = frame_module_sp->GetArchitecture();
4413                                         module_spec.GetFileSpec() = frame_module_sp->GetPlatformFileSpec();
4414                                     }
4415                                     module_spec.GetUUID() = frame_module_sp->GetUUID();
4416                                     success = module_spec.GetUUID().IsValid() || module_spec.GetFileSpec();
4417                                 }
4418                                 else
4419                                 {
4420                                     result.AppendError ("frame has no module");
4421                                     error_set = true;
4422                                 }
4423                             }
4424                             else
4425                             {
4426                                 result.AppendError ("invalid current frame");
4427                                 error_set = true;
4428                             }
4429                         }
4430                         else
4431                         {
4432                             result.AppendErrorWithFormat ("process is not stopped: %s", StateAsCString(process_state));
4433                             error_set = true;
4434                         }
4435                     }
4436                     else
4437                     {
4438                         result.AppendError ("a process must exist in order to use the --frame option");
4439                         error_set = true;
4440                     }
4441                 }
4442                 else
4443                 {
4444                     if (uuid_option_set)
4445                     {
4446                         module_spec.GetUUID() = m_uuid_option_group.GetOptionValue().GetCurrentValue();
4447                         success |= module_spec.GetUUID().IsValid();
4448                     }
4449                     else if (file_option_set)
4450                     {
4451                         module_spec.GetFileSpec() = m_file_option.GetOptionValue().GetCurrentValue();
4452                         ModuleSP module_sp (target->GetImages().FindFirstModule(module_spec));
4453                         if (module_sp)
4454                         {
4455                             module_spec.GetFileSpec() = module_sp->GetFileSpec();
4456                             module_spec.GetPlatformFileSpec() = module_sp->GetPlatformFileSpec();
4457                             module_spec.GetUUID() = module_sp->GetUUID();
4458                             module_spec.GetArchitecture() = module_sp->GetArchitecture();
4459                         }
4460                         else
4461                         {
4462                             module_spec.GetArchitecture() = target->GetArchitecture();
4463                         }
4464                         success |= module_spec.GetFileSpec().Exists();
4465                     }
4466                 }
4467 
4468                 if (success)
4469                 {
4470                     if (Symbols::DownloadObjectAndSymbolFile (module_spec))
4471                     {
4472                         if (module_spec.GetSymbolFileSpec())
4473                             success = AddModuleSymbols (target, module_spec, flush, result);
4474                     }
4475                 }
4476 
4477                 if (!success && !error_set)
4478                 {
4479                     StreamString error_strm;
4480                     if (uuid_option_set)
4481                     {
4482                         error_strm.PutCString("unable to find debug symbols for UUID ");
4483                         module_spec.GetUUID().Dump (&error_strm);
4484                     }
4485                     else if (file_option_set)
4486                     {
4487                         error_strm.PutCString("unable to find debug symbols for the executable file ");
4488                         error_strm << module_spec.GetFileSpec();
4489                     }
4490                     else if (frame_option_set)
4491                     {
4492                         error_strm.PutCString("unable to find debug symbols for the current frame");
4493                     }
4494                     result.AppendError (error_strm.GetData());
4495                 }
4496             }
4497             else
4498             {
4499                 result.AppendError ("one or more symbol file paths must be specified, or options must be specified");
4500             }
4501         }
4502         else
4503         {
4504             if (uuid_option_set)
4505             {
4506                 result.AppendError ("specify either one or more paths to symbol files or use the --uuid option without arguments");
4507             }
4508             else if (file_option_set)
4509             {
4510                 result.AppendError ("specify either one or more paths to symbol files or use the --file option without arguments");
4511             }
4512             else if (frame_option_set)
4513             {
4514                 result.AppendError ("specify either one or more paths to symbol files or use the --frame option without arguments");
4515             }
4516             else
4517             {
4518                 PlatformSP platform_sp (target->GetPlatform());
4519 
4520                 for (size_t i=0; i<argc; ++i)
4521                 {
4522                     const char *symfile_path = args.GetArgumentAtIndex(i);
4523                     if (symfile_path)
4524                     {
4525                         module_spec.GetSymbolFileSpec().SetFile(symfile_path, true);
4526                         if (platform_sp)
4527                         {
4528                             FileSpec symfile_spec;
4529                             if (platform_sp->ResolveSymbolFile(*target, module_spec, symfile_spec).Success())
4530                                 module_spec.GetSymbolFileSpec() = symfile_spec;
4531                         }
4532 
4533                         ArchSpec arch;
4534                         bool symfile_exists = module_spec.GetSymbolFileSpec().Exists();
4535 
4536                         if (symfile_exists)
4537                         {
4538                             if (!AddModuleSymbols (target, module_spec, flush, result))
4539                                 break;
4540                         }
4541                         else
4542                         {
4543                             char resolved_symfile_path[PATH_MAX];
4544                             if (module_spec.GetSymbolFileSpec().GetPath (resolved_symfile_path, sizeof(resolved_symfile_path)))
4545                             {
4546                                 if (strcmp (resolved_symfile_path, symfile_path) != 0)
4547                                 {
4548                                     result.AppendErrorWithFormat ("invalid module path '%s' with resolved path '%s'\n", symfile_path, resolved_symfile_path);
4549                                     break;
4550                                 }
4551                             }
4552                             result.AppendErrorWithFormat ("invalid module path '%s'\n", symfile_path);
4553                             break;
4554                         }
4555                     }
4556                 }
4557             }
4558         }
4559 
4560         if (flush)
4561         {
4562             Process *process = m_exe_ctx.GetProcessPtr();
4563             if (process)
4564                 process->Flush();
4565         }
4566         return result.Succeeded();
4567     }
4568 
4569     OptionGroupOptions m_option_group;
4570     OptionGroupUUID m_uuid_option_group;
4571     OptionGroupFile m_file_option;
4572     OptionGroupBoolean m_current_frame_option;
4573 
4574 
4575 };
4576 
4577 
4578 #pragma mark CommandObjectTargetSymbols
4579 
4580 //-------------------------------------------------------------------------
4581 // CommandObjectTargetSymbols
4582 //-------------------------------------------------------------------------
4583 
4584 class CommandObjectTargetSymbols : public CommandObjectMultiword
4585 {
4586 public:
4587     //------------------------------------------------------------------
4588     // Constructors and Destructors
4589     //------------------------------------------------------------------
4590     CommandObjectTargetSymbols(CommandInterpreter &interpreter) :
4591         CommandObjectMultiword (interpreter,
4592                             "target symbols",
4593                             "A set of commands for adding and managing debug symbol files.",
4594                             "target symbols <sub-command> ...")
4595     {
4596         LoadSubCommand ("add", CommandObjectSP (new CommandObjectTargetSymbolsAdd (interpreter)));
4597 
4598     }
4599     virtual
4600     ~CommandObjectTargetSymbols()
4601     {
4602     }
4603 
4604 private:
4605     //------------------------------------------------------------------
4606     // For CommandObjectTargetModules only
4607     //------------------------------------------------------------------
4608     DISALLOW_COPY_AND_ASSIGN (CommandObjectTargetSymbols);
4609 };
4610 
4611 
4612 #pragma mark CommandObjectTargetStopHookAdd
4613 
4614 //-------------------------------------------------------------------------
4615 // CommandObjectTargetStopHookAdd
4616 //-------------------------------------------------------------------------
4617 
4618 class CommandObjectTargetStopHookAdd : public CommandObjectParsed
4619 {
4620 public:
4621 
4622     class CommandOptions : public Options
4623     {
4624     public:
4625         CommandOptions (CommandInterpreter &interpreter) :
4626             Options(interpreter),
4627             m_line_start(0),
4628             m_line_end (UINT_MAX),
4629             m_func_name_type_mask (eFunctionNameTypeAuto),
4630             m_sym_ctx_specified (false),
4631             m_thread_specified (false),
4632             m_use_one_liner (false),
4633             m_one_liner()
4634         {
4635         }
4636 
4637         ~CommandOptions () {}
4638 
4639         const OptionDefinition*
4640         GetDefinitions ()
4641         {
4642             return g_option_table;
4643         }
4644 
4645         virtual Error
4646         SetOptionValue (uint32_t option_idx, const char *option_arg)
4647         {
4648             Error error;
4649             const int short_option = m_getopt_table[option_idx].val;
4650             bool success;
4651 
4652             switch (short_option)
4653             {
4654                 case 'c':
4655                     m_class_name = option_arg;
4656                     m_sym_ctx_specified = true;
4657                 break;
4658 
4659                 case 'e':
4660                     m_line_end = Args::StringToUInt32 (option_arg, UINT_MAX, 0, &success);
4661                     if (!success)
4662                     {
4663                         error.SetErrorStringWithFormat ("invalid end line number: \"%s\"", option_arg);
4664                         break;
4665                     }
4666                     m_sym_ctx_specified = true;
4667                 break;
4668 
4669                 case 'l':
4670                     m_line_start = Args::StringToUInt32 (option_arg, 0, 0, &success);
4671                     if (!success)
4672                     {
4673                         error.SetErrorStringWithFormat ("invalid start line number: \"%s\"", option_arg);
4674                         break;
4675                     }
4676                     m_sym_ctx_specified = true;
4677                 break;
4678 
4679                 case 'i':
4680                     m_no_inlines = true;
4681                 break;
4682 
4683                 case 'n':
4684                     m_function_name = option_arg;
4685                     m_func_name_type_mask |= eFunctionNameTypeAuto;
4686                     m_sym_ctx_specified = true;
4687                 break;
4688 
4689                 case 'f':
4690                     m_file_name = option_arg;
4691                     m_sym_ctx_specified = true;
4692                 break;
4693                 case 's':
4694                     m_module_name = option_arg;
4695                     m_sym_ctx_specified = true;
4696                 break;
4697                 case 't' :
4698                 {
4699                     m_thread_id = Args::StringToUInt64(option_arg, LLDB_INVALID_THREAD_ID, 0);
4700                     if (m_thread_id == LLDB_INVALID_THREAD_ID)
4701                        error.SetErrorStringWithFormat ("invalid thread id string '%s'", option_arg);
4702                     m_thread_specified = true;
4703                 }
4704                 break;
4705                 case 'T':
4706                     m_thread_name = option_arg;
4707                     m_thread_specified = true;
4708                 break;
4709                 case 'q':
4710                     m_queue_name = option_arg;
4711                     m_thread_specified = true;
4712                     break;
4713                 case 'x':
4714                 {
4715                     m_thread_index = Args::StringToUInt32(option_arg, UINT32_MAX, 0);
4716                     if (m_thread_id == UINT32_MAX)
4717                        error.SetErrorStringWithFormat ("invalid thread index string '%s'", option_arg);
4718                     m_thread_specified = true;
4719                 }
4720                 break;
4721                 case 'o':
4722                     m_use_one_liner = true;
4723                     m_one_liner = option_arg;
4724                 break;
4725                 default:
4726                     error.SetErrorStringWithFormat ("unrecognized option %c.", short_option);
4727                 break;
4728             }
4729             return error;
4730         }
4731 
4732         void
4733         OptionParsingStarting ()
4734         {
4735             m_class_name.clear();
4736             m_function_name.clear();
4737             m_line_start = 0;
4738             m_line_end = UINT_MAX;
4739             m_file_name.clear();
4740             m_module_name.clear();
4741             m_func_name_type_mask = eFunctionNameTypeAuto;
4742             m_thread_id = LLDB_INVALID_THREAD_ID;
4743             m_thread_index = UINT32_MAX;
4744             m_thread_name.clear();
4745             m_queue_name.clear();
4746 
4747             m_no_inlines = false;
4748             m_sym_ctx_specified = false;
4749             m_thread_specified = false;
4750 
4751             m_use_one_liner = false;
4752             m_one_liner.clear();
4753         }
4754 
4755 
4756         static OptionDefinition g_option_table[];
4757 
4758         std::string m_class_name;
4759         std::string m_function_name;
4760         uint32_t    m_line_start;
4761         uint32_t    m_line_end;
4762         std::string m_file_name;
4763         std::string m_module_name;
4764         uint32_t m_func_name_type_mask;  // A pick from lldb::FunctionNameType.
4765         lldb::tid_t m_thread_id;
4766         uint32_t m_thread_index;
4767         std::string m_thread_name;
4768         std::string m_queue_name;
4769         bool        m_sym_ctx_specified;
4770         bool        m_no_inlines;
4771         bool        m_thread_specified;
4772         // Instance variables to hold the values for one_liner options.
4773         bool m_use_one_liner;
4774         std::string m_one_liner;
4775     };
4776 
4777     Options *
4778     GetOptions ()
4779     {
4780         return &m_options;
4781     }
4782 
4783     CommandObjectTargetStopHookAdd (CommandInterpreter &interpreter) :
4784         CommandObjectParsed (interpreter,
4785                              "target stop-hook add ",
4786                              "Add a hook to be executed when the target stops.",
4787                              "target stop-hook add"),
4788         m_options (interpreter)
4789     {
4790     }
4791 
4792     ~CommandObjectTargetStopHookAdd ()
4793     {
4794     }
4795 
4796     static size_t
4797     ReadCommandsCallbackFunction (void *baton,
4798                                   InputReader &reader,
4799                                   lldb::InputReaderAction notification,
4800                                   const char *bytes,
4801                                   size_t bytes_len)
4802     {
4803         StreamSP out_stream = reader.GetDebugger().GetAsyncOutputStream();
4804         Target::StopHook *new_stop_hook = ((Target::StopHook *) baton);
4805         static bool got_interrupted;
4806         bool batch_mode = reader.GetDebugger().GetCommandInterpreter().GetBatchCommandMode();
4807 
4808         switch (notification)
4809         {
4810         case eInputReaderActivate:
4811             if (!batch_mode)
4812             {
4813                 out_stream->Printf ("%s\n", "Enter your stop hook command(s).  Type 'DONE' to end.");
4814                 if (reader.GetPrompt())
4815                     out_stream->Printf ("%s", reader.GetPrompt());
4816                 out_stream->Flush();
4817             }
4818             got_interrupted = false;
4819             break;
4820 
4821         case eInputReaderDeactivate:
4822             break;
4823 
4824         case eInputReaderReactivate:
4825             if (reader.GetPrompt() && !batch_mode)
4826             {
4827                 out_stream->Printf ("%s", reader.GetPrompt());
4828                 out_stream->Flush();
4829             }
4830             got_interrupted = false;
4831             break;
4832 
4833         case eInputReaderAsynchronousOutputWritten:
4834             break;
4835 
4836         case eInputReaderGotToken:
4837             if (bytes && bytes_len && baton)
4838             {
4839                 StringList *commands = new_stop_hook->GetCommandPointer();
4840                 if (commands)
4841                 {
4842                     commands->AppendString (bytes, bytes_len);
4843                 }
4844             }
4845             if (!reader.IsDone() && reader.GetPrompt() && !batch_mode)
4846             {
4847                 out_stream->Printf ("%s", reader.GetPrompt());
4848                 out_stream->Flush();
4849             }
4850             break;
4851 
4852         case eInputReaderInterrupt:
4853             {
4854                 // Finish, and cancel the stop hook.
4855                 new_stop_hook->GetTarget()->RemoveStopHookByID(new_stop_hook->GetID());
4856                 if (!batch_mode)
4857                 {
4858                     out_stream->Printf ("Stop hook cancelled.\n");
4859                     out_stream->Flush();
4860                 }
4861 
4862                 reader.SetIsDone (true);
4863             }
4864             got_interrupted = true;
4865             break;
4866 
4867         case eInputReaderEndOfFile:
4868             reader.SetIsDone (true);
4869             break;
4870 
4871         case eInputReaderDone:
4872             if (!got_interrupted && !batch_mode)
4873             {
4874                 out_stream->Printf ("Stop hook #%" PRIu64 " added.\n", new_stop_hook->GetID());
4875                 out_stream->Flush();
4876             }
4877             break;
4878         }
4879 
4880         return bytes_len;
4881     }
4882 
4883 protected:
4884     bool
4885     DoExecute (Args& command, CommandReturnObject &result)
4886     {
4887         Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
4888         if (target)
4889         {
4890             Target::StopHookSP new_hook_sp;
4891             target->AddStopHook (new_hook_sp);
4892 
4893             //  First step, make the specifier.
4894             std::unique_ptr<SymbolContextSpecifier> specifier_ap;
4895             if (m_options.m_sym_ctx_specified)
4896             {
4897                 specifier_ap.reset(new SymbolContextSpecifier(m_interpreter.GetDebugger().GetSelectedTarget()));
4898 
4899                 if (!m_options.m_module_name.empty())
4900                 {
4901                     specifier_ap->AddSpecification (m_options.m_module_name.c_str(), SymbolContextSpecifier::eModuleSpecified);
4902                 }
4903 
4904                 if (!m_options.m_class_name.empty())
4905                 {
4906                     specifier_ap->AddSpecification (m_options.m_class_name.c_str(), SymbolContextSpecifier::eClassOrNamespaceSpecified);
4907                 }
4908 
4909                 if (!m_options.m_file_name.empty())
4910                 {
4911                     specifier_ap->AddSpecification (m_options.m_file_name.c_str(), SymbolContextSpecifier::eFileSpecified);
4912                 }
4913 
4914                 if (m_options.m_line_start != 0)
4915                 {
4916                     specifier_ap->AddLineSpecification (m_options.m_line_start, SymbolContextSpecifier::eLineStartSpecified);
4917                 }
4918 
4919                 if (m_options.m_line_end != UINT_MAX)
4920                 {
4921                     specifier_ap->AddLineSpecification (m_options.m_line_end, SymbolContextSpecifier::eLineEndSpecified);
4922                 }
4923 
4924                 if (!m_options.m_function_name.empty())
4925                 {
4926                     specifier_ap->AddSpecification (m_options.m_function_name.c_str(), SymbolContextSpecifier::eFunctionSpecified);
4927                 }
4928             }
4929 
4930             if (specifier_ap.get())
4931                 new_hook_sp->SetSpecifier (specifier_ap.release());
4932 
4933             // Next see if any of the thread options have been entered:
4934 
4935             if (m_options.m_thread_specified)
4936             {
4937                 ThreadSpec *thread_spec = new ThreadSpec();
4938 
4939                 if (m_options.m_thread_id != LLDB_INVALID_THREAD_ID)
4940                 {
4941                     thread_spec->SetTID (m_options.m_thread_id);
4942                 }
4943 
4944                 if (m_options.m_thread_index != UINT32_MAX)
4945                     thread_spec->SetIndex (m_options.m_thread_index);
4946 
4947                 if (!m_options.m_thread_name.empty())
4948                     thread_spec->SetName (m_options.m_thread_name.c_str());
4949 
4950                 if (!m_options.m_queue_name.empty())
4951                     thread_spec->SetQueueName (m_options.m_queue_name.c_str());
4952 
4953                 new_hook_sp->SetThreadSpecifier (thread_spec);
4954 
4955             }
4956             if (m_options.m_use_one_liner)
4957             {
4958                 // Use one-liner.
4959                 new_hook_sp->GetCommandPointer()->AppendString (m_options.m_one_liner.c_str());
4960                 result.AppendMessageWithFormat("Stop hook #%" PRIu64 " added.\n", new_hook_sp->GetID());
4961             }
4962             else
4963             {
4964                 // Otherwise gather up the command list, we'll push an input reader and suck the data from that directly into
4965                 // the new stop hook's command string.
4966                 InputReaderSP reader_sp (new InputReader(m_interpreter.GetDebugger()));
4967                 if (!reader_sp)
4968                 {
4969                     result.AppendError("out of memory\n");
4970                     result.SetStatus (eReturnStatusFailed);
4971                     target->RemoveStopHookByID (new_hook_sp->GetID());
4972                     return false;
4973                 }
4974 
4975                 Error err (reader_sp->Initialize (CommandObjectTargetStopHookAdd::ReadCommandsCallbackFunction,
4976                                                   new_hook_sp.get(), // baton
4977                                                   eInputReaderGranularityLine,  // token size, to pass to callback function
4978                                                   "DONE",                       // end token
4979                                                   "> ",                         // prompt
4980                                                   true));                       // echo input
4981                 if (!err.Success())
4982                 {
4983                     result.AppendError (err.AsCString());
4984                     result.SetStatus (eReturnStatusFailed);
4985                     target->RemoveStopHookByID (new_hook_sp->GetID());
4986                     return false;
4987                 }
4988                 m_interpreter.GetDebugger().PushInputReader (reader_sp);
4989             }
4990             result.SetStatus (eReturnStatusSuccessFinishNoResult);
4991         }
4992         else
4993         {
4994             result.AppendError ("invalid target\n");
4995             result.SetStatus (eReturnStatusFailed);
4996         }
4997 
4998         return result.Succeeded();
4999     }
5000 private:
5001     CommandOptions m_options;
5002 };
5003 
5004 OptionDefinition
5005 CommandObjectTargetStopHookAdd::CommandOptions::g_option_table[] =
5006 {
5007     { LLDB_OPT_SET_ALL, false, "one-liner", 'o', required_argument, NULL, 0, eArgTypeOneLiner,
5008         "Specify a one-line breakpoint command inline. Be sure to surround it with quotes." },
5009     { LLDB_OPT_SET_ALL, false, "shlib", 's', required_argument, NULL, CommandCompletions::eModuleCompletion, eArgTypeShlibName,
5010         "Set the module within which the stop-hook is to be run."},
5011     { LLDB_OPT_SET_ALL, false, "thread-index", 'x', required_argument, NULL, 0, eArgTypeThreadIndex,
5012         "The stop hook is run only for the thread whose index matches this argument."},
5013     { LLDB_OPT_SET_ALL, false, "thread-id", 't', required_argument, NULL, 0, eArgTypeThreadID,
5014         "The stop hook is run only for the thread whose TID matches this argument."},
5015     { LLDB_OPT_SET_ALL, false, "thread-name", 'T', required_argument, NULL, 0, eArgTypeThreadName,
5016         "The stop hook is run only for the thread whose thread name matches this argument."},
5017     { LLDB_OPT_SET_ALL, false, "queue-name", 'q', required_argument, NULL, 0, eArgTypeQueueName,
5018         "The stop hook is run only for threads in the queue whose name is given by this argument."},
5019     { LLDB_OPT_SET_1, false, "file", 'f', required_argument, NULL, CommandCompletions::eSourceFileCompletion, eArgTypeFilename,
5020         "Specify the source file within which the stop-hook is to be run." },
5021     { LLDB_OPT_SET_1, false, "start-line", 'l', required_argument, NULL, 0, eArgTypeLineNum,
5022         "Set the start of the line range for which the stop-hook is to be run."},
5023     { LLDB_OPT_SET_1, false, "end-line", 'e', required_argument, NULL, 0, eArgTypeLineNum,
5024         "Set the end of the line range for which the stop-hook is to be run."},
5025     { LLDB_OPT_SET_2, false, "classname", 'c', required_argument, NULL, 0, eArgTypeClassName,
5026         "Specify the class within which the stop-hook is to be run." },
5027     { LLDB_OPT_SET_3, false, "name", 'n', required_argument, NULL, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName,
5028         "Set the function name within which the stop hook will be run." },
5029     { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
5030 };
5031 
5032 #pragma mark CommandObjectTargetStopHookDelete
5033 
5034 //-------------------------------------------------------------------------
5035 // CommandObjectTargetStopHookDelete
5036 //-------------------------------------------------------------------------
5037 
5038 class CommandObjectTargetStopHookDelete : public CommandObjectParsed
5039 {
5040 public:
5041 
5042     CommandObjectTargetStopHookDelete (CommandInterpreter &interpreter) :
5043         CommandObjectParsed (interpreter,
5044                              "target stop-hook delete",
5045                              "Delete a stop-hook.",
5046                              "target stop-hook delete [<idx>]")
5047     {
5048     }
5049 
5050     ~CommandObjectTargetStopHookDelete ()
5051     {
5052     }
5053 
5054 protected:
5055     bool
5056     DoExecute (Args& command, CommandReturnObject &result)
5057     {
5058         Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
5059         if (target)
5060         {
5061             // FIXME: see if we can use the breakpoint id style parser?
5062             size_t num_args = command.GetArgumentCount();
5063             if (num_args == 0)
5064             {
5065                 if (!m_interpreter.Confirm ("Delete all stop hooks?", true))
5066                 {
5067                     result.SetStatus (eReturnStatusFailed);
5068                     return false;
5069                 }
5070                 else
5071                 {
5072                     target->RemoveAllStopHooks();
5073                 }
5074             }
5075             else
5076             {
5077                 bool success;
5078                 for (size_t i = 0; i < num_args; i++)
5079                 {
5080                     lldb::user_id_t user_id = Args::StringToUInt32 (command.GetArgumentAtIndex(i), 0, 0, &success);
5081                     if (!success)
5082                     {
5083                         result.AppendErrorWithFormat ("invalid stop hook id: \"%s\".\n", command.GetArgumentAtIndex(i));
5084                         result.SetStatus(eReturnStatusFailed);
5085                         return false;
5086                     }
5087                     success = target->RemoveStopHookByID (user_id);
5088                     if (!success)
5089                     {
5090                         result.AppendErrorWithFormat ("unknown stop hook id: \"%s\".\n", command.GetArgumentAtIndex(i));
5091                         result.SetStatus(eReturnStatusFailed);
5092                         return false;
5093                     }
5094                 }
5095             }
5096             result.SetStatus (eReturnStatusSuccessFinishNoResult);
5097         }
5098         else
5099         {
5100             result.AppendError ("invalid target\n");
5101             result.SetStatus (eReturnStatusFailed);
5102         }
5103 
5104         return result.Succeeded();
5105     }
5106 };
5107 #pragma mark CommandObjectTargetStopHookEnableDisable
5108 
5109 //-------------------------------------------------------------------------
5110 // CommandObjectTargetStopHookEnableDisable
5111 //-------------------------------------------------------------------------
5112 
5113 class CommandObjectTargetStopHookEnableDisable : public CommandObjectParsed
5114 {
5115 public:
5116 
5117     CommandObjectTargetStopHookEnableDisable (CommandInterpreter &interpreter, bool enable, const char *name, const char *help, const char *syntax) :
5118         CommandObjectParsed (interpreter,
5119                              name,
5120                              help,
5121                              syntax),
5122         m_enable (enable)
5123     {
5124     }
5125 
5126     ~CommandObjectTargetStopHookEnableDisable ()
5127     {
5128     }
5129 
5130 protected:
5131     bool
5132     DoExecute (Args& command, CommandReturnObject &result)
5133     {
5134         Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
5135         if (target)
5136         {
5137             // FIXME: see if we can use the breakpoint id style parser?
5138             size_t num_args = command.GetArgumentCount();
5139             bool success;
5140 
5141             if (num_args == 0)
5142             {
5143                 target->SetAllStopHooksActiveState (m_enable);
5144             }
5145             else
5146             {
5147                 for (size_t i = 0; i < num_args; i++)
5148                 {
5149                     lldb::user_id_t user_id = Args::StringToUInt32 (command.GetArgumentAtIndex(i), 0, 0, &success);
5150                     if (!success)
5151                     {
5152                         result.AppendErrorWithFormat ("invalid stop hook id: \"%s\".\n", command.GetArgumentAtIndex(i));
5153                         result.SetStatus(eReturnStatusFailed);
5154                         return false;
5155                     }
5156                     success = target->SetStopHookActiveStateByID (user_id, m_enable);
5157                     if (!success)
5158                     {
5159                         result.AppendErrorWithFormat ("unknown stop hook id: \"%s\".\n", command.GetArgumentAtIndex(i));
5160                         result.SetStatus(eReturnStatusFailed);
5161                         return false;
5162                     }
5163                 }
5164             }
5165             result.SetStatus (eReturnStatusSuccessFinishNoResult);
5166         }
5167         else
5168         {
5169             result.AppendError ("invalid target\n");
5170             result.SetStatus (eReturnStatusFailed);
5171         }
5172         return result.Succeeded();
5173     }
5174 private:
5175     bool m_enable;
5176 };
5177 
5178 #pragma mark CommandObjectTargetStopHookList
5179 
5180 //-------------------------------------------------------------------------
5181 // CommandObjectTargetStopHookList
5182 //-------------------------------------------------------------------------
5183 
5184 class CommandObjectTargetStopHookList : public CommandObjectParsed
5185 {
5186 public:
5187 
5188     CommandObjectTargetStopHookList (CommandInterpreter &interpreter) :
5189         CommandObjectParsed (interpreter,
5190                              "target stop-hook list",
5191                              "List all stop-hooks.",
5192                              "target stop-hook list [<type>]")
5193     {
5194     }
5195 
5196     ~CommandObjectTargetStopHookList ()
5197     {
5198     }
5199 
5200 protected:
5201     bool
5202     DoExecute (Args& command, CommandReturnObject &result)
5203     {
5204         Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
5205         if (!target)
5206         {
5207             result.AppendError ("invalid target\n");
5208             result.SetStatus (eReturnStatusFailed);
5209             return result.Succeeded();
5210         }
5211 
5212         size_t num_hooks = target->GetNumStopHooks ();
5213         if (num_hooks == 0)
5214         {
5215             result.GetOutputStream().PutCString ("No stop hooks.\n");
5216         }
5217         else
5218         {
5219             for (size_t i = 0; i < num_hooks; i++)
5220             {
5221                 Target::StopHookSP this_hook = target->GetStopHookAtIndex (i);
5222                 if (i > 0)
5223                     result.GetOutputStream().PutCString ("\n");
5224                 this_hook->GetDescription (&(result.GetOutputStream()), eDescriptionLevelFull);
5225             }
5226         }
5227         result.SetStatus (eReturnStatusSuccessFinishResult);
5228         return result.Succeeded();
5229     }
5230 };
5231 
5232 #pragma mark CommandObjectMultiwordTargetStopHooks
5233 //-------------------------------------------------------------------------
5234 // CommandObjectMultiwordTargetStopHooks
5235 //-------------------------------------------------------------------------
5236 
5237 class CommandObjectMultiwordTargetStopHooks : public CommandObjectMultiword
5238 {
5239 public:
5240 
5241     CommandObjectMultiwordTargetStopHooks (CommandInterpreter &interpreter) :
5242         CommandObjectMultiword (interpreter,
5243                                 "target stop-hook",
5244                                 "A set of commands for operating on debugger target stop-hooks.",
5245                                 "target stop-hook <subcommand> [<subcommand-options>]")
5246     {
5247         LoadSubCommand ("add",      CommandObjectSP (new CommandObjectTargetStopHookAdd (interpreter)));
5248         LoadSubCommand ("delete",   CommandObjectSP (new CommandObjectTargetStopHookDelete (interpreter)));
5249         LoadSubCommand ("disable",  CommandObjectSP (new CommandObjectTargetStopHookEnableDisable (interpreter,
5250                                                                                                    false,
5251                                                                                                    "target stop-hook disable [<id>]",
5252                                                                                                    "Disable a stop-hook.",
5253                                                                                                    "target stop-hook disable")));
5254         LoadSubCommand ("enable",   CommandObjectSP (new CommandObjectTargetStopHookEnableDisable (interpreter,
5255                                                                                                    true,
5256                                                                                                    "target stop-hook enable [<id>]",
5257                                                                                                    "Enable a stop-hook.",
5258                                                                                                    "target stop-hook enable")));
5259         LoadSubCommand ("list",     CommandObjectSP (new CommandObjectTargetStopHookList (interpreter)));
5260     }
5261 
5262     ~CommandObjectMultiwordTargetStopHooks()
5263     {
5264     }
5265 };
5266 
5267 
5268 
5269 #pragma mark CommandObjectMultiwordTarget
5270 
5271 //-------------------------------------------------------------------------
5272 // CommandObjectMultiwordTarget
5273 //-------------------------------------------------------------------------
5274 
5275 CommandObjectMultiwordTarget::CommandObjectMultiwordTarget (CommandInterpreter &interpreter) :
5276     CommandObjectMultiword (interpreter,
5277                             "target",
5278                             "A set of commands for operating on debugger targets.",
5279                             "target <subcommand> [<subcommand-options>]")
5280 {
5281 
5282     LoadSubCommand ("create",    CommandObjectSP (new CommandObjectTargetCreate (interpreter)));
5283     LoadSubCommand ("delete",    CommandObjectSP (new CommandObjectTargetDelete (interpreter)));
5284     LoadSubCommand ("list",      CommandObjectSP (new CommandObjectTargetList   (interpreter)));
5285     LoadSubCommand ("select",    CommandObjectSP (new CommandObjectTargetSelect (interpreter)));
5286     LoadSubCommand ("stop-hook", CommandObjectSP (new CommandObjectMultiwordTargetStopHooks (interpreter)));
5287     LoadSubCommand ("modules",   CommandObjectSP (new CommandObjectTargetModules (interpreter)));
5288     LoadSubCommand ("symbols",   CommandObjectSP (new CommandObjectTargetSymbols (interpreter)));
5289     LoadSubCommand ("variable",  CommandObjectSP (new CommandObjectTargetVariable (interpreter)));
5290 }
5291 
5292 CommandObjectMultiwordTarget::~CommandObjectMultiwordTarget ()
5293 {
5294 }
5295 
5296 
5297