blob: 44bab7b6fdfc7266fa91c2b37e15e361293310bc [file] [log] [blame]
Chris Lattner24943d22010-06-08 16:52:24 +00001//===-- 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 "CommandObjectTarget.h"
11
12// C Includes
13#include <errno.h>
Greg Clayton81040f42011-02-01 01:13:32 +000014
Chris Lattner24943d22010-06-08 16:52:24 +000015// C++ Includes
16// Other libraries and framework includes
17// Project includes
Jim Ingham84cdc152010-06-15 19:49:27 +000018#include "lldb/Interpreter/Args.h"
Chris Lattner24943d22010-06-08 16:52:24 +000019#include "lldb/Core/Debugger.h"
Jim Inghamd60d94a2011-03-11 03:53:59 +000020#include "lldb/Core/InputReader.h"
Greg Claytone1f50b92011-05-03 22:09:39 +000021#include "lldb/Core/Section.h"
Greg Claytonabe0fed2011-04-18 08:33:37 +000022#include "lldb/Core/State.h"
Chris Lattner24943d22010-06-08 16:52:24 +000023#include "lldb/Core/Timer.h"
Greg Clayton801417e2011-07-07 01:59:51 +000024#include "lldb/Core/ValueObjectVariable.h"
Chris Lattner24943d22010-06-08 16:52:24 +000025#include "lldb/Interpreter/CommandInterpreter.h"
26#include "lldb/Interpreter/CommandReturnObject.h"
Greg Claytone1f50b92011-05-03 22:09:39 +000027#include "lldb/Interpreter/Options.h"
Greg Claytonabe0fed2011-04-18 08:33:37 +000028#include "lldb/Interpreter/OptionGroupArchitecture.h"
Greg Clayton5beb99d2011-08-11 02:48:45 +000029#include "lldb/Interpreter/OptionGroupBoolean.h"
Greg Claytone1f50b92011-05-03 22:09:39 +000030#include "lldb/Interpreter/OptionGroupFile.h"
Greg Claytona42880a2011-10-25 06:44:01 +000031#include "lldb/Interpreter/OptionGroupFormat.h"
Greg Clayton368f8222011-07-07 04:38:25 +000032#include "lldb/Interpreter/OptionGroupVariable.h"
Greg Claytonabe0fed2011-04-18 08:33:37 +000033#include "lldb/Interpreter/OptionGroupPlatform.h"
Greg Claytone1f50b92011-05-03 22:09:39 +000034#include "lldb/Interpreter/OptionGroupUInt64.h"
35#include "lldb/Interpreter/OptionGroupUUID.h"
Greg Clayton801417e2011-07-07 01:59:51 +000036#include "lldb/Interpreter/OptionGroupValueObjectDisplay.h"
Greg Claytone1f50b92011-05-03 22:09:39 +000037#include "lldb/Symbol/LineTable.h"
38#include "lldb/Symbol/ObjectFile.h"
39#include "lldb/Symbol/SymbolFile.h"
40#include "lldb/Symbol/SymbolVendor.h"
Greg Clayton801417e2011-07-07 01:59:51 +000041#include "lldb/Symbol/VariableList.h"
Chris Lattner24943d22010-06-08 16:52:24 +000042#include "lldb/Target/Process.h"
43#include "lldb/Target/StackFrame.h"
44#include "lldb/Target/Thread.h"
Jim Inghamd60d94a2011-03-11 03:53:59 +000045#include "lldb/Target/ThreadSpec.h"
Chris Lattner24943d22010-06-08 16:52:24 +000046
47using namespace lldb;
48using namespace lldb_private;
49
Greg Claytonabe0fed2011-04-18 08:33:37 +000050
51
52static void
53DumpTargetInfo (uint32_t target_idx, Target *target, const char *prefix_cstr, bool show_stopped_process_status, Stream &strm)
54{
Greg Clayton52c8b6e2011-04-19 04:19:37 +000055 const ArchSpec &target_arch = target->GetArchitecture();
Greg Claytonabe0fed2011-04-18 08:33:37 +000056
Greg Clayton5beb99d2011-08-11 02:48:45 +000057 Module *exe_module = target->GetExecutableModulePointer();
Greg Claytonabe0fed2011-04-18 08:33:37 +000058 char exe_path[PATH_MAX];
59 bool exe_valid = false;
Greg Clayton5beb99d2011-08-11 02:48:45 +000060 if (exe_module)
61 exe_valid = exe_module->GetFileSpec().GetPath (exe_path, sizeof(exe_path));
Greg Claytonabe0fed2011-04-18 08:33:37 +000062
63 if (!exe_valid)
64 ::strcpy (exe_path, "<none>");
65
66 strm.Printf ("%starget #%u: %s", prefix_cstr ? prefix_cstr : "", target_idx, exe_path);
67
68 uint32_t properties = 0;
69 if (target_arch.IsValid())
70 {
71 strm.Printf ("%sarch=%s", properties++ > 0 ? ", " : " ( ", target_arch.GetTriple().str().c_str());
72 properties++;
73 }
74 PlatformSP platform_sp (target->GetPlatform());
75 if (platform_sp)
76 strm.Printf ("%splatform=%s", properties++ > 0 ? ", " : " ( ", platform_sp->GetName());
77
78 ProcessSP process_sp (target->GetProcessSP());
79 bool show_process_status = false;
80 if (process_sp)
81 {
82 lldb::pid_t pid = process_sp->GetID();
83 StateType state = process_sp->GetState();
84 if (show_stopped_process_status)
Greg Clayton20206082011-11-17 01:23:07 +000085 show_process_status = StateIsStoppedState(state, true);
Greg Claytonabe0fed2011-04-18 08:33:37 +000086 const char *state_cstr = StateAsCString (state);
87 if (pid != LLDB_INVALID_PROCESS_ID)
Greg Claytond9919d32011-12-01 23:28:38 +000088 strm.Printf ("%spid=%llu", properties++ > 0 ? ", " : " ( ", pid);
Greg Claytonabe0fed2011-04-18 08:33:37 +000089 strm.Printf ("%sstate=%s", properties++ > 0 ? ", " : " ( ", state_cstr);
90 }
91 if (properties > 0)
92 strm.PutCString (" )\n");
93 else
94 strm.EOL();
95 if (show_process_status)
96 {
97 const bool only_threads_with_stop_reason = true;
98 const uint32_t start_frame = 0;
99 const uint32_t num_frames = 1;
100 const uint32_t num_frames_with_source = 1;
101 process_sp->GetStatus (strm);
102 process_sp->GetThreadStatus (strm,
103 only_threads_with_stop_reason,
104 start_frame,
105 num_frames,
106 num_frames_with_source);
107
108 }
109}
110
111static uint32_t
112DumpTargetList (TargetList &target_list, bool show_stopped_process_status, Stream &strm)
113{
114 const uint32_t num_targets = target_list.GetNumTargets();
115 if (num_targets)
116 {
117 TargetSP selected_target_sp (target_list.GetSelectedTarget());
118 strm.PutCString ("Current targets:\n");
119 for (uint32_t i=0; i<num_targets; ++i)
120 {
121 TargetSP target_sp (target_list.GetTargetAtIndex (i));
122 if (target_sp)
123 {
124 bool is_selected = target_sp.get() == selected_target_sp.get();
125 DumpTargetInfo (i,
126 target_sp.get(),
127 is_selected ? "* " : " ",
128 show_stopped_process_status,
129 strm);
130 }
131 }
132 }
133 return num_targets;
134}
135#pragma mark CommandObjectTargetCreate
136
137//-------------------------------------------------------------------------
138// "target create"
139//-------------------------------------------------------------------------
140
141class CommandObjectTargetCreate : public CommandObject
142{
143public:
144 CommandObjectTargetCreate(CommandInterpreter &interpreter) :
145 CommandObject (interpreter,
146 "target create",
147 "Create a target using the argument as the main executable.",
148 NULL),
149 m_option_group (interpreter),
Greg Clayton801417e2011-07-07 01:59:51 +0000150 m_arch_option (),
Greg Claytonabe0fed2011-04-18 08:33:37 +0000151 m_platform_options(true) // Do include the "--platform" option in the platform settings by passing true
152 {
153 CommandArgumentEntry arg;
154 CommandArgumentData file_arg;
155
156 // Define the first (and only) variant of this arg.
157 file_arg.arg_type = eArgTypeFilename;
158 file_arg.arg_repetition = eArgRepeatPlain;
159
160 // There is only one variant this argument could be; put it into the argument entry.
161 arg.push_back (file_arg);
162
163 // Push the data for the first argument into the m_arguments vector.
164 m_arguments.push_back (arg);
165
Greg Clayton801417e2011-07-07 01:59:51 +0000166 m_option_group.Append (&m_arch_option, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
Greg Claytonabe0fed2011-04-18 08:33:37 +0000167 m_option_group.Append (&m_platform_options, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
168 m_option_group.Finalize();
169 }
170
171 ~CommandObjectTargetCreate ()
172 {
173 }
174
175 Options *
176 GetOptions ()
177 {
178 return &m_option_group;
179 }
180
181 bool
182 Execute (Args& command, CommandReturnObject &result)
183 {
184 const int argc = command.GetArgumentCount();
185 if (argc == 1)
186 {
187 const char *file_path = command.GetArgumentAtIndex(0);
188 Timer scoped_timer(__PRETTY_FUNCTION__, "(lldb) target create '%s'", file_path);
189 FileSpec file_spec (file_path, true);
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000190
Greg Claytonabe0fed2011-04-18 08:33:37 +0000191 TargetSP target_sp;
192 Debugger &debugger = m_interpreter.GetDebugger();
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000193 const char *arch_cstr = m_arch_option.GetArchitectureName();
194 const bool get_dependent_files = true;
195 Error error (debugger.GetTargetList().CreateTarget (debugger,
196 file_spec,
197 arch_cstr,
198 get_dependent_files,
199 &m_platform_options,
200 target_sp));
201
Greg Claytonabe0fed2011-04-18 08:33:37 +0000202 if (target_sp)
203 {
204 debugger.GetTargetList().SetSelectedTarget(target_sp.get());
205 result.AppendMessageWithFormat ("Current executable set to '%s' (%s).\n", file_path, target_sp->GetArchitecture().GetArchitectureName());
206 result.SetStatus (eReturnStatusSuccessFinishNoResult);
207 }
208 else
209 {
210 result.AppendError(error.AsCString());
211 result.SetStatus (eReturnStatusFailed);
212 }
213 }
214 else
215 {
216 result.AppendErrorWithFormat("'%s' takes exactly one executable path argument.\n", m_cmd_name.c_str());
217 result.SetStatus (eReturnStatusFailed);
218 }
219 return result.Succeeded();
220
221 }
222
223 int
224 HandleArgumentCompletion (Args &input,
225 int &cursor_index,
226 int &cursor_char_position,
227 OptionElementVector &opt_element_vector,
228 int match_start_point,
229 int max_return_elements,
230 bool &word_complete,
231 StringList &matches)
232 {
233 std::string completion_str (input.GetArgumentAtIndex(cursor_index));
234 completion_str.erase (cursor_char_position);
235
236 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
237 CommandCompletions::eDiskFileCompletion,
238 completion_str.c_str(),
239 match_start_point,
240 max_return_elements,
241 NULL,
242 word_complete,
243 matches);
244 return matches.GetSize();
245 }
246private:
247 OptionGroupOptions m_option_group;
Greg Clayton801417e2011-07-07 01:59:51 +0000248 OptionGroupArchitecture m_arch_option;
Greg Claytonabe0fed2011-04-18 08:33:37 +0000249 OptionGroupPlatform m_platform_options;
250
251};
252
253#pragma mark CommandObjectTargetList
254
255//----------------------------------------------------------------------
256// "target list"
257//----------------------------------------------------------------------
258
259class CommandObjectTargetList : public CommandObject
260{
261public:
262 CommandObjectTargetList (CommandInterpreter &interpreter) :
263 CommandObject (interpreter,
264 "target list",
265 "List all current targets in the current debug session.",
266 NULL,
267 0)
268 {
269 }
270
271 virtual
272 ~CommandObjectTargetList ()
273 {
274 }
275
276 virtual bool
277 Execute (Args& args, CommandReturnObject &result)
278 {
279 if (args.GetArgumentCount() == 0)
280 {
281 Stream &strm = result.GetOutputStream();
282
283 bool show_stopped_process_status = false;
284 if (DumpTargetList (m_interpreter.GetDebugger().GetTargetList(), show_stopped_process_status, strm) == 0)
285 {
286 strm.PutCString ("No targets.\n");
287 }
Johnny Chen44dc9d32011-04-18 21:08:05 +0000288 result.SetStatus (eReturnStatusSuccessFinishResult);
Greg Claytonabe0fed2011-04-18 08:33:37 +0000289 }
290 else
291 {
292 result.AppendError ("the 'target list' command takes no arguments\n");
293 result.SetStatus (eReturnStatusFailed);
294 }
295 return result.Succeeded();
296 }
297};
298
299
300#pragma mark CommandObjectTargetSelect
301
302//----------------------------------------------------------------------
303// "target select"
304//----------------------------------------------------------------------
305
306class CommandObjectTargetSelect : public CommandObject
307{
308public:
309 CommandObjectTargetSelect (CommandInterpreter &interpreter) :
310 CommandObject (interpreter,
311 "target select",
312 "Select a target as the current target by target index.",
313 NULL,
314 0)
315 {
316 }
317
318 virtual
319 ~CommandObjectTargetSelect ()
320 {
321 }
322
323 virtual bool
324 Execute (Args& args, CommandReturnObject &result)
325 {
326 if (args.GetArgumentCount() == 1)
327 {
328 bool success = false;
329 const char *target_idx_arg = args.GetArgumentAtIndex(0);
330 uint32_t target_idx = Args::StringToUInt32 (target_idx_arg, UINT32_MAX, 0, &success);
331 if (success)
332 {
333 TargetList &target_list = m_interpreter.GetDebugger().GetTargetList();
334 const uint32_t num_targets = target_list.GetNumTargets();
335 if (target_idx < num_targets)
336 {
337 TargetSP target_sp (target_list.GetTargetAtIndex (target_idx));
338 if (target_sp)
339 {
340 Stream &strm = result.GetOutputStream();
341 target_list.SetSelectedTarget (target_sp.get());
342 bool show_stopped_process_status = false;
343 DumpTargetList (target_list, show_stopped_process_status, strm);
Johnny Chen44dc9d32011-04-18 21:08:05 +0000344 result.SetStatus (eReturnStatusSuccessFinishResult);
Greg Claytonabe0fed2011-04-18 08:33:37 +0000345 }
346 else
347 {
348 result.AppendErrorWithFormat ("target #%u is NULL in target list\n", target_idx);
349 result.SetStatus (eReturnStatusFailed);
350 }
351 }
352 else
353 {
354 result.AppendErrorWithFormat ("index %u is out of range, valid target indexes are 0 - %u\n",
355 target_idx,
356 num_targets - 1);
357 result.SetStatus (eReturnStatusFailed);
358 }
359 }
360 else
361 {
362 result.AppendErrorWithFormat("invalid index string value '%s'\n", target_idx_arg);
363 result.SetStatus (eReturnStatusFailed);
364 }
365 }
366 else
367 {
368 result.AppendError ("'target select' takes a single argument: a target index\n");
369 result.SetStatus (eReturnStatusFailed);
370 }
371 return result.Succeeded();
372 }
373};
374
Greg Clayton153ccd72011-08-10 02:10:13 +0000375#pragma mark CommandObjectTargetSelect
376
377//----------------------------------------------------------------------
378// "target delete"
379//----------------------------------------------------------------------
380
381class CommandObjectTargetDelete : public CommandObject
382{
383public:
384 CommandObjectTargetDelete (CommandInterpreter &interpreter) :
Greg Clayton5beb99d2011-08-11 02:48:45 +0000385 CommandObject (interpreter,
386 "target delete",
387 "Delete one or more targets by target index.",
388 NULL,
389 0),
390 m_option_group (interpreter),
391 m_cleanup_option (LLDB_OPT_SET_1, false, "clean", 'c', 0, eArgTypeNone, "Perform extra cleanup to minimize memory consumption after deleting the target.", false)
Greg Clayton153ccd72011-08-10 02:10:13 +0000392 {
Greg Clayton5beb99d2011-08-11 02:48:45 +0000393 m_option_group.Append (&m_cleanup_option, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
394 m_option_group.Finalize();
Greg Clayton153ccd72011-08-10 02:10:13 +0000395 }
396
397 virtual
398 ~CommandObjectTargetDelete ()
399 {
400 }
401
402 virtual bool
403 Execute (Args& args, CommandReturnObject &result)
404 {
405 const size_t argc = args.GetArgumentCount();
406 std::vector<TargetSP> delete_target_list;
407 TargetList &target_list = m_interpreter.GetDebugger().GetTargetList();
408 bool success = true;
409 TargetSP target_sp;
410 if (argc > 0)
411 {
412 const uint32_t num_targets = target_list.GetNumTargets();
413 for (uint32_t arg_idx = 0; success && arg_idx < argc; ++arg_idx)
414 {
415 const char *target_idx_arg = args.GetArgumentAtIndex(arg_idx);
416 uint32_t target_idx = Args::StringToUInt32 (target_idx_arg, UINT32_MAX, 0, &success);
417 if (success)
418 {
419 if (target_idx < num_targets)
420 {
421 target_sp = target_list.GetTargetAtIndex (target_idx);
422 if (target_sp)
423 {
424 delete_target_list.push_back (target_sp);
425 continue;
426 }
427 }
428 result.AppendErrorWithFormat ("target index %u is out of range, valid target indexes are 0 - %u\n",
429 target_idx,
430 num_targets - 1);
431 result.SetStatus (eReturnStatusFailed);
432 success = false;
433 }
434 else
435 {
436 result.AppendErrorWithFormat("invalid target index '%s'\n", target_idx_arg);
437 result.SetStatus (eReturnStatusFailed);
438 success = false;
439 }
440 }
441
442 }
443 else
444 {
445 target_sp = target_list.GetSelectedTarget();
446 if (target_sp)
447 {
448 delete_target_list.push_back (target_sp);
449 }
450 else
451 {
452 result.AppendErrorWithFormat("no target is currently selected\n");
453 result.SetStatus (eReturnStatusFailed);
454 success = false;
455 }
456 }
457 if (success)
458 {
459 const size_t num_targets_to_delete = delete_target_list.size();
460 for (size_t idx = 0; idx < num_targets_to_delete; ++idx)
461 {
462 target_sp = delete_target_list[idx];
463 target_list.DeleteTarget(target_sp);
464 target_sp->Destroy();
465 }
Greg Clayton5beb99d2011-08-11 02:48:45 +0000466 // If "--clean" was specified, prune any orphaned shared modules from
467 // the global shared module list
468 if (m_cleanup_option.GetOptionValue ())
469 {
470 ModuleList::RemoveOrphanSharedModules();
471 }
Greg Clayton153ccd72011-08-10 02:10:13 +0000472 result.GetOutputStream().Printf("%u targets deleted.\n", (uint32_t)num_targets_to_delete);
473 result.SetStatus(eReturnStatusSuccessFinishResult);
474 }
475
476 return result.Succeeded();
477 }
Greg Clayton5beb99d2011-08-11 02:48:45 +0000478
479 Options *
480 GetOptions ()
481 {
482 return &m_option_group;
483 }
484
485protected:
486 OptionGroupOptions m_option_group;
487 OptionGroupBoolean m_cleanup_option;
Greg Clayton153ccd72011-08-10 02:10:13 +0000488};
489
Greg Claytonabe0fed2011-04-18 08:33:37 +0000490
Greg Clayton801417e2011-07-07 01:59:51 +0000491#pragma mark CommandObjectTargetVariable
492
493//----------------------------------------------------------------------
494// "target variable"
495//----------------------------------------------------------------------
496
497class CommandObjectTargetVariable : public CommandObject
498{
499public:
500 CommandObjectTargetVariable (CommandInterpreter &interpreter) :
501 CommandObject (interpreter,
Johnny Chen34bfa4f2011-07-12 22:34:30 +0000502 "target variable",
503 "Read global variable(s) prior to running your binary.",
Greg Clayton801417e2011-07-07 01:59:51 +0000504 NULL,
505 0),
506 m_option_group (interpreter),
Greg Clayton368f8222011-07-07 04:38:25 +0000507 m_option_variable (false), // Don't include frame options
Greg Claytona42880a2011-10-25 06:44:01 +0000508 m_option_format (eFormatDefault),
Greg Clayton801417e2011-07-07 01:59:51 +0000509 m_option_compile_units (LLDB_OPT_SET_1, false, "file", 'f', 0, eArgTypePath, "A basename or fullpath to a file that contains global variables. This option can be specified multiple times."),
510 m_option_shared_libraries (LLDB_OPT_SET_1, false, "shlib",'s', 0, eArgTypePath, "A basename or fullpath to a shared library to use in the search for global variables. This option can be specified multiple times."),
511 m_varobj_options()
512 {
Johnny Chen24b81e32011-08-22 22:22:00 +0000513 CommandArgumentEntry arg;
514 CommandArgumentData var_name_arg;
515
516 // Define the first (and only) variant of this arg.
517 var_name_arg.arg_type = eArgTypeVarName;
518 var_name_arg.arg_repetition = eArgRepeatPlus;
519
520 // There is only one variant this argument could be; put it into the argument entry.
521 arg.push_back (var_name_arg);
522
523 // Push the data for the first argument into the m_arguments vector.
524 m_arguments.push_back (arg);
525
Greg Clayton801417e2011-07-07 01:59:51 +0000526 m_option_group.Append (&m_varobj_options, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
Greg Clayton368f8222011-07-07 04:38:25 +0000527 m_option_group.Append (&m_option_variable, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
Greg Clayton24a6bd92011-10-27 17:55:14 +0000528 m_option_group.Append (&m_option_format, OptionGroupFormat::OPTION_GROUP_FORMAT | OptionGroupFormat::OPTION_GROUP_GDB_FMT, LLDB_OPT_SET_1);
Greg Clayton801417e2011-07-07 01:59:51 +0000529 m_option_group.Append (&m_option_compile_units, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
530 m_option_group.Append (&m_option_shared_libraries, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
531 m_option_group.Finalize();
532 }
533
534 virtual
535 ~CommandObjectTargetVariable ()
536 {
537 }
Greg Clayton5d81f492011-07-08 21:46:14 +0000538
539 void
540 DumpValueObject (Stream &s, VariableSP &var_sp, ValueObjectSP &valobj_sp, const char *root_name)
541 {
Enrico Granata19030d82011-08-15 18:01:31 +0000542 ValueObject::DumpValueObjectOptions options;
543
544 options.SetPointerDepth(m_varobj_options.ptr_depth)
545 .SetMaximumDepth(m_varobj_options.max_depth)
546 .SetShowTypes(m_varobj_options.show_types)
547 .SetShowLocation(m_varobj_options.show_location)
548 .SetUseObjectiveC(m_varobj_options.use_objc)
549 .SetUseDynamicType(m_varobj_options.use_dynamic)
550 .SetUseSyntheticValue((lldb::SyntheticValueType)m_varobj_options.use_synth)
551 .SetFlatOutput(m_varobj_options.flat_output)
552 .SetOmitSummaryDepth(m_varobj_options.no_summary_depth)
553 .SetIgnoreCap(m_varobj_options.ignore_cap);
554
Greg Clayton5d81f492011-07-08 21:46:14 +0000555 switch (var_sp->GetScope())
556 {
557 case eValueTypeVariableGlobal:
558 if (m_option_variable.show_scope)
559 s.PutCString("GLOBAL: ");
560 break;
561
562 case eValueTypeVariableStatic:
563 if (m_option_variable.show_scope)
564 s.PutCString("STATIC: ");
565 break;
566
567 case eValueTypeVariableArgument:
568 if (m_option_variable.show_scope)
569 s.PutCString(" ARG: ");
570 break;
571
572 case eValueTypeVariableLocal:
573 if (m_option_variable.show_scope)
574 s.PutCString(" LOCAL: ");
575 break;
576
577 default:
578 break;
579 }
580
Greg Claytonfb816422011-07-10 19:21:23 +0000581 if (m_option_variable.show_decl)
Greg Clayton5d81f492011-07-08 21:46:14 +0000582 {
Greg Claytonfb816422011-07-10 19:21:23 +0000583 bool show_fullpaths = false;
584 bool show_module = true;
585 if (var_sp->DumpDeclaration(&s, show_fullpaths, show_module))
586 s.PutCString (": ");
Greg Clayton5d81f492011-07-08 21:46:14 +0000587 }
588
Greg Claytona42880a2011-10-25 06:44:01 +0000589 const Format format = m_option_format.GetFormat();
Greg Clayton5d81f492011-07-08 21:46:14 +0000590 if (format != eFormatDefault)
591 valobj_sp->SetFormat (format);
592
593 ValueObject::DumpValueObject (s,
594 valobj_sp.get(),
595 root_name,
Enrico Granata19030d82011-08-15 18:01:31 +0000596 options);
Greg Clayton5d81f492011-07-08 21:46:14 +0000597
598 }
Greg Clayton801417e2011-07-07 01:59:51 +0000599
Greg Clayton5d81f492011-07-08 21:46:14 +0000600
601 static uint32_t GetVariableCallback (void *baton,
602 const char *name,
603 VariableList &variable_list)
604 {
605 Target *target = static_cast<Target *>(baton);
606 if (target)
607 {
608 return target->GetImages().FindGlobalVariables (ConstString(name),
609 true,
610 UINT32_MAX,
611 variable_list);
612 }
613 return 0;
614 }
615
616
617
Greg Clayton801417e2011-07-07 01:59:51 +0000618 virtual bool
619 Execute (Args& args, CommandReturnObject &result)
620 {
621 ExecutionContext exe_ctx (m_interpreter.GetExecutionContext());
Greg Clayton567e7f32011-09-22 04:58:26 +0000622 Target *target = exe_ctx.GetTargetPtr();
623 if (target)
Greg Clayton801417e2011-07-07 01:59:51 +0000624 {
625 const size_t argc = args.GetArgumentCount();
Greg Claytonfac93882011-10-05 22:17:32 +0000626 Stream &s = result.GetOutputStream();
Greg Clayton801417e2011-07-07 01:59:51 +0000627 if (argc > 0)
628 {
Greg Clayton5d81f492011-07-08 21:46:14 +0000629
Greg Clayton801417e2011-07-07 01:59:51 +0000630 for (size_t idx = 0; idx < argc; ++idx)
631 {
Greg Clayton5d81f492011-07-08 21:46:14 +0000632 VariableList variable_list;
633 ValueObjectList valobj_list;
634
Greg Clayton368f8222011-07-07 04:38:25 +0000635 const char *arg = args.GetArgumentAtIndex(idx);
636 uint32_t matches = 0;
Greg Claytonfb816422011-07-10 19:21:23 +0000637 bool use_var_name = false;
Greg Clayton368f8222011-07-07 04:38:25 +0000638 if (m_option_variable.use_regex)
Greg Clayton801417e2011-07-07 01:59:51 +0000639 {
Greg Clayton368f8222011-07-07 04:38:25 +0000640 RegularExpression regex(arg);
641 if (!regex.IsValid ())
642 {
643 result.GetErrorStream().Printf ("error: invalid regular expression: '%s'\n", arg);
644 result.SetStatus (eReturnStatusFailed);
645 return false;
646 }
Greg Claytonfb816422011-07-10 19:21:23 +0000647 use_var_name = true;
Greg Clayton567e7f32011-09-22 04:58:26 +0000648 matches = target->GetImages().FindGlobalVariables (regex,
649 true,
650 UINT32_MAX,
651 variable_list);
Greg Clayton801417e2011-07-07 01:59:51 +0000652 }
653 else
654 {
Greg Clayton5d81f492011-07-08 21:46:14 +0000655 Error error (Variable::GetValuesForVariableExpressionPath (arg,
Greg Clayton24b03102011-07-09 20:12:33 +0000656 exe_ctx.GetBestExecutionContextScope(),
Greg Clayton5d81f492011-07-08 21:46:14 +0000657 GetVariableCallback,
Greg Clayton567e7f32011-09-22 04:58:26 +0000658 target,
Greg Clayton5d81f492011-07-08 21:46:14 +0000659 variable_list,
660 valobj_list));
Greg Clayton5d81f492011-07-08 21:46:14 +0000661 matches = variable_list.GetSize();
Greg Clayton368f8222011-07-07 04:38:25 +0000662 }
663
664 if (matches == 0)
665 {
666 result.GetErrorStream().Printf ("error: can't find global variable '%s'\n", arg);
667 result.SetStatus (eReturnStatusFailed);
668 return false;
669 }
670 else
671 {
Greg Clayton801417e2011-07-07 01:59:51 +0000672 for (uint32_t global_idx=0; global_idx<matches; ++global_idx)
673 {
Greg Clayton5d81f492011-07-08 21:46:14 +0000674 VariableSP var_sp (variable_list.GetVariableAtIndex(global_idx));
Greg Clayton801417e2011-07-07 01:59:51 +0000675 if (var_sp)
676 {
Greg Clayton5d81f492011-07-08 21:46:14 +0000677 ValueObjectSP valobj_sp (valobj_list.GetValueObjectAtIndex(global_idx));
678 if (!valobj_sp)
Greg Claytonfb816422011-07-10 19:21:23 +0000679 valobj_sp = ValueObjectVariable::Create (exe_ctx.GetBestExecutionContextScope(), var_sp);
Greg Clayton801417e2011-07-07 01:59:51 +0000680
681 if (valobj_sp)
Greg Claytonb304a742011-10-13 18:31:02 +0000682 DumpValueObject (s, var_sp, valobj_sp, use_var_name ? var_sp->GetName().GetCString() : arg);
Greg Clayton801417e2011-07-07 01:59:51 +0000683 }
684 }
685 }
686 }
687 }
688 else
689 {
Greg Claytonfac93882011-10-05 22:17:32 +0000690 bool success = false;
691 StackFrame *frame = exe_ctx.GetFramePtr();
692 CompileUnit *comp_unit = NULL;
693 if (frame)
694 {
695 comp_unit = frame->GetSymbolContext (eSymbolContextCompUnit).comp_unit;
696 if (comp_unit)
697 {
698 const bool can_create = true;
699 VariableListSP comp_unit_varlist_sp (comp_unit->GetVariableList(can_create));
700 if (comp_unit_varlist_sp)
701 {
702 size_t count = comp_unit_varlist_sp->GetSize();
703 if (count > 0)
704 {
Greg Claytona1b9a902011-11-13 04:15:56 +0000705 s.Printf ("Global variables for %s/%s:\n",
Greg Claytonfac93882011-10-05 22:17:32 +0000706 comp_unit->GetDirectory().GetCString(),
707 comp_unit->GetFilename().GetCString());
708
709 success = true;
710 for (uint32_t i=0; i<count; ++i)
711 {
712 VariableSP var_sp (comp_unit_varlist_sp->GetVariableAtIndex(i));
713 if (var_sp)
714 {
715 ValueObjectSP valobj_sp (ValueObjectVariable::Create (exe_ctx.GetBestExecutionContextScope(), var_sp));
716
717 if (valobj_sp)
718 DumpValueObject (s, var_sp, valobj_sp, var_sp->GetName().GetCString());
719 }
720 }
721 }
722 }
723 }
724 }
725 if (!success)
726 {
727 if (frame)
728 {
729 if (comp_unit)
730 result.AppendErrorWithFormat ("no global variables in current compile unit: %s/%s\n",
731 comp_unit->GetDirectory().GetCString(),
732 comp_unit->GetFilename().GetCString());
733 else
734 result.AppendError ("no debug information for frame %u\n", frame->GetFrameIndex());
735 }
736 else
737 result.AppendError ("'target variable' takes one or more global variable names as arguments\n");
738 result.SetStatus (eReturnStatusFailed);
739 }
Greg Clayton801417e2011-07-07 01:59:51 +0000740 }
741 }
742 else
743 {
744 result.AppendError ("invalid target, create a debug target using the 'target create' command");
745 result.SetStatus (eReturnStatusFailed);
746 return false;
747 }
Enrico Granatadb64d952011-08-12 16:42:31 +0000748
749 if (m_interpreter.TruncationWarningNecessary())
750 {
751 result.GetOutputStream().Printf(m_interpreter.TruncationWarningText(),
752 m_cmd_name.c_str());
753 m_interpreter.TruncationWarningGiven();
754 }
755
Greg Clayton801417e2011-07-07 01:59:51 +0000756 return result.Succeeded();
757 }
758
759 Options *
760 GetOptions ()
761 {
762 return &m_option_group;
763 }
764
765protected:
766 OptionGroupOptions m_option_group;
Greg Clayton368f8222011-07-07 04:38:25 +0000767 OptionGroupVariable m_option_variable;
Greg Claytona42880a2011-10-25 06:44:01 +0000768 OptionGroupFormat m_option_format;
Greg Clayton801417e2011-07-07 01:59:51 +0000769 OptionGroupFileList m_option_compile_units;
770 OptionGroupFileList m_option_shared_libraries;
771 OptionGroupValueObjectDisplay m_varobj_options;
772
773};
774
775
Greg Claytone1f50b92011-05-03 22:09:39 +0000776#pragma mark CommandObjectTargetModulesSearchPathsAdd
Chris Lattner24943d22010-06-08 16:52:24 +0000777
Greg Claytone1f50b92011-05-03 22:09:39 +0000778class CommandObjectTargetModulesSearchPathsAdd : public CommandObject
Chris Lattner24943d22010-06-08 16:52:24 +0000779{
780public:
781
Greg Claytone1f50b92011-05-03 22:09:39 +0000782 CommandObjectTargetModulesSearchPathsAdd (CommandInterpreter &interpreter) :
Greg Clayton238c0a12010-09-18 01:14:36 +0000783 CommandObject (interpreter,
Greg Claytone1f50b92011-05-03 22:09:39 +0000784 "target modules search-paths add",
Chris Lattner24943d22010-06-08 16:52:24 +0000785 "Add new image search paths substitution pairs to the current target.",
Caroline Tice43b014a2010-10-04 22:28:36 +0000786 NULL)
Chris Lattner24943d22010-06-08 16:52:24 +0000787 {
Caroline Tice43b014a2010-10-04 22:28:36 +0000788 CommandArgumentEntry arg;
789 CommandArgumentData old_prefix_arg;
790 CommandArgumentData new_prefix_arg;
791
792 // Define the first variant of this arg pair.
793 old_prefix_arg.arg_type = eArgTypeOldPathPrefix;
794 old_prefix_arg.arg_repetition = eArgRepeatPairPlus;
795
796 // Define the first variant of this arg pair.
797 new_prefix_arg.arg_type = eArgTypeNewPathPrefix;
798 new_prefix_arg.arg_repetition = eArgRepeatPairPlus;
799
800 // There are two required arguments that must always occur together, i.e. an argument "pair". Because they
801 // must always occur together, they are treated as two variants of one argument rather than two independent
802 // arguments. Push them both into the first argument position for m_arguments...
803
804 arg.push_back (old_prefix_arg);
805 arg.push_back (new_prefix_arg);
806
807 m_arguments.push_back (arg);
Chris Lattner24943d22010-06-08 16:52:24 +0000808 }
809
Greg Claytone1f50b92011-05-03 22:09:39 +0000810 ~CommandObjectTargetModulesSearchPathsAdd ()
Chris Lattner24943d22010-06-08 16:52:24 +0000811 {
812 }
813
814 bool
Greg Clayton238c0a12010-09-18 01:14:36 +0000815 Execute (Args& command,
Chris Lattner24943d22010-06-08 16:52:24 +0000816 CommandReturnObject &result)
817 {
Greg Clayton238c0a12010-09-18 01:14:36 +0000818 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Chris Lattner24943d22010-06-08 16:52:24 +0000819 if (target)
820 {
821 uint32_t argc = command.GetArgumentCount();
822 if (argc & 1)
823 {
Greg Claytonabe0fed2011-04-18 08:33:37 +0000824 result.AppendError ("add requires an even number of arguments\n");
Chris Lattner24943d22010-06-08 16:52:24 +0000825 result.SetStatus (eReturnStatusFailed);
826 }
827 else
828 {
829 for (uint32_t i=0; i<argc; i+=2)
830 {
831 const char *from = command.GetArgumentAtIndex(i);
832 const char *to = command.GetArgumentAtIndex(i+1);
833
834 if (from[0] && to[0])
835 {
836 bool last_pair = ((argc - i) == 2);
Greg Clayton63094e02010-06-23 01:19:29 +0000837 target->GetImageSearchPathList().Append (ConstString(from),
838 ConstString(to),
839 last_pair); // Notify if this is the last pair
Johnny Chen4d661352011-02-03 00:30:19 +0000840 result.SetStatus (eReturnStatusSuccessFinishNoResult);
Chris Lattner24943d22010-06-08 16:52:24 +0000841 }
842 else
843 {
844 if (from[0])
Greg Claytonabe0fed2011-04-18 08:33:37 +0000845 result.AppendError ("<path-prefix> can't be empty\n");
Chris Lattner24943d22010-06-08 16:52:24 +0000846 else
Greg Claytonabe0fed2011-04-18 08:33:37 +0000847 result.AppendError ("<new-path-prefix> can't be empty\n");
Chris Lattner24943d22010-06-08 16:52:24 +0000848 result.SetStatus (eReturnStatusFailed);
849 }
850 }
851 }
852 }
853 else
854 {
Greg Claytonabe0fed2011-04-18 08:33:37 +0000855 result.AppendError ("invalid target\n");
Chris Lattner24943d22010-06-08 16:52:24 +0000856 result.SetStatus (eReturnStatusFailed);
857 }
858 return result.Succeeded();
859 }
860};
861
Greg Claytone1f50b92011-05-03 22:09:39 +0000862#pragma mark CommandObjectTargetModulesSearchPathsClear
863
864class CommandObjectTargetModulesSearchPathsClear : public CommandObject
Chris Lattner24943d22010-06-08 16:52:24 +0000865{
866public:
867
Greg Claytone1f50b92011-05-03 22:09:39 +0000868 CommandObjectTargetModulesSearchPathsClear (CommandInterpreter &interpreter) :
Greg Clayton238c0a12010-09-18 01:14:36 +0000869 CommandObject (interpreter,
Greg Claytone1f50b92011-05-03 22:09:39 +0000870 "target modules search-paths clear",
Caroline Ticeabb507a2010-09-08 21:06:11 +0000871 "Clear all current image search path substitution pairs from the current target.",
Greg Claytone1f50b92011-05-03 22:09:39 +0000872 "target modules search-paths clear")
Chris Lattner24943d22010-06-08 16:52:24 +0000873 {
874 }
875
Greg Claytone1f50b92011-05-03 22:09:39 +0000876 ~CommandObjectTargetModulesSearchPathsClear ()
Chris Lattner24943d22010-06-08 16:52:24 +0000877 {
878 }
879
880 bool
Greg Clayton238c0a12010-09-18 01:14:36 +0000881 Execute (Args& command,
Chris Lattner24943d22010-06-08 16:52:24 +0000882 CommandReturnObject &result)
883 {
Greg Clayton238c0a12010-09-18 01:14:36 +0000884 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Chris Lattner24943d22010-06-08 16:52:24 +0000885 if (target)
886 {
887 bool notify = true;
888 target->GetImageSearchPathList().Clear(notify);
Johnny Chen4d661352011-02-03 00:30:19 +0000889 result.SetStatus (eReturnStatusSuccessFinishNoResult);
Chris Lattner24943d22010-06-08 16:52:24 +0000890 }
891 else
892 {
Greg Claytonabe0fed2011-04-18 08:33:37 +0000893 result.AppendError ("invalid target\n");
Chris Lattner24943d22010-06-08 16:52:24 +0000894 result.SetStatus (eReturnStatusFailed);
895 }
896 return result.Succeeded();
897 }
898};
899
Greg Claytone1f50b92011-05-03 22:09:39 +0000900#pragma mark CommandObjectTargetModulesSearchPathsInsert
901
902class CommandObjectTargetModulesSearchPathsInsert : public CommandObject
Chris Lattner24943d22010-06-08 16:52:24 +0000903{
904public:
905
Greg Claytone1f50b92011-05-03 22:09:39 +0000906 CommandObjectTargetModulesSearchPathsInsert (CommandInterpreter &interpreter) :
Greg Clayton238c0a12010-09-18 01:14:36 +0000907 CommandObject (interpreter,
Greg Claytone1f50b92011-05-03 22:09:39 +0000908 "target modules search-paths insert",
Caroline Ticeabb507a2010-09-08 21:06:11 +0000909 "Insert a new image search path substitution pair into the current target at the specified index.",
Caroline Tice43b014a2010-10-04 22:28:36 +0000910 NULL)
Chris Lattner24943d22010-06-08 16:52:24 +0000911 {
Caroline Tice43b014a2010-10-04 22:28:36 +0000912 CommandArgumentEntry arg1;
913 CommandArgumentEntry arg2;
914 CommandArgumentData index_arg;
915 CommandArgumentData old_prefix_arg;
916 CommandArgumentData new_prefix_arg;
917
918 // Define the first and only variant of this arg.
919 index_arg.arg_type = eArgTypeIndex;
920 index_arg.arg_repetition = eArgRepeatPlain;
921
922 // Put the one and only variant into the first arg for m_arguments:
923 arg1.push_back (index_arg);
924
925 // Define the first variant of this arg pair.
926 old_prefix_arg.arg_type = eArgTypeOldPathPrefix;
927 old_prefix_arg.arg_repetition = eArgRepeatPairPlus;
928
929 // Define the first variant of this arg pair.
930 new_prefix_arg.arg_type = eArgTypeNewPathPrefix;
931 new_prefix_arg.arg_repetition = eArgRepeatPairPlus;
932
933 // There are two required arguments that must always occur together, i.e. an argument "pair". Because they
934 // must always occur together, they are treated as two variants of one argument rather than two independent
935 // arguments. Push them both into the same argument position for m_arguments...
936
937 arg2.push_back (old_prefix_arg);
938 arg2.push_back (new_prefix_arg);
939
940 // Add arguments to m_arguments.
941 m_arguments.push_back (arg1);
942 m_arguments.push_back (arg2);
Chris Lattner24943d22010-06-08 16:52:24 +0000943 }
944
Greg Claytone1f50b92011-05-03 22:09:39 +0000945 ~CommandObjectTargetModulesSearchPathsInsert ()
Chris Lattner24943d22010-06-08 16:52:24 +0000946 {
947 }
948
949 bool
Greg Clayton238c0a12010-09-18 01:14:36 +0000950 Execute (Args& command,
Chris Lattner24943d22010-06-08 16:52:24 +0000951 CommandReturnObject &result)
952 {
Greg Clayton238c0a12010-09-18 01:14:36 +0000953 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Chris Lattner24943d22010-06-08 16:52:24 +0000954 if (target)
955 {
956 uint32_t argc = command.GetArgumentCount();
957 // check for at least 3 arguments and an odd nubmer of parameters
958 if (argc >= 3 && argc & 1)
959 {
960 bool success = false;
961
962 uint32_t insert_idx = Args::StringToUInt32(command.GetArgumentAtIndex(0), UINT32_MAX, 0, &success);
963
964 if (!success)
965 {
966 result.AppendErrorWithFormat("<index> parameter is not an integer: '%s'.\n", command.GetArgumentAtIndex(0));
967 result.SetStatus (eReturnStatusFailed);
968 return result.Succeeded();
969 }
970
971 // shift off the index
972 command.Shift();
973 argc = command.GetArgumentCount();
974
975 for (uint32_t i=0; i<argc; i+=2, ++insert_idx)
976 {
977 const char *from = command.GetArgumentAtIndex(i);
978 const char *to = command.GetArgumentAtIndex(i+1);
979
980 if (from[0] && to[0])
981 {
982 bool last_pair = ((argc - i) == 2);
983 target->GetImageSearchPathList().Insert (ConstString(from),
984 ConstString(to),
985 insert_idx,
986 last_pair);
Johnny Chen4d661352011-02-03 00:30:19 +0000987 result.SetStatus (eReturnStatusSuccessFinishNoResult);
Chris Lattner24943d22010-06-08 16:52:24 +0000988 }
989 else
990 {
991 if (from[0])
Greg Claytonabe0fed2011-04-18 08:33:37 +0000992 result.AppendError ("<path-prefix> can't be empty\n");
Chris Lattner24943d22010-06-08 16:52:24 +0000993 else
Greg Claytonabe0fed2011-04-18 08:33:37 +0000994 result.AppendError ("<new-path-prefix> can't be empty\n");
Chris Lattner24943d22010-06-08 16:52:24 +0000995 result.SetStatus (eReturnStatusFailed);
996 return false;
997 }
998 }
999 }
1000 else
1001 {
Greg Claytonabe0fed2011-04-18 08:33:37 +00001002 result.AppendError ("insert requires at least three arguments\n");
Chris Lattner24943d22010-06-08 16:52:24 +00001003 result.SetStatus (eReturnStatusFailed);
1004 return result.Succeeded();
1005 }
1006
1007 }
1008 else
1009 {
Greg Claytonabe0fed2011-04-18 08:33:37 +00001010 result.AppendError ("invalid target\n");
Chris Lattner24943d22010-06-08 16:52:24 +00001011 result.SetStatus (eReturnStatusFailed);
1012 }
1013 return result.Succeeded();
1014 }
1015};
1016
Greg Claytone1f50b92011-05-03 22:09:39 +00001017
1018#pragma mark CommandObjectTargetModulesSearchPathsList
1019
1020
1021class CommandObjectTargetModulesSearchPathsList : public CommandObject
Chris Lattner24943d22010-06-08 16:52:24 +00001022{
1023public:
1024
Greg Claytone1f50b92011-05-03 22:09:39 +00001025 CommandObjectTargetModulesSearchPathsList (CommandInterpreter &interpreter) :
Greg Clayton238c0a12010-09-18 01:14:36 +00001026 CommandObject (interpreter,
Greg Claytone1f50b92011-05-03 22:09:39 +00001027 "target modules search-paths list",
Caroline Ticeabb507a2010-09-08 21:06:11 +00001028 "List all current image search path substitution pairs in the current target.",
Greg Claytone1f50b92011-05-03 22:09:39 +00001029 "target modules search-paths list")
Chris Lattner24943d22010-06-08 16:52:24 +00001030 {
1031 }
1032
Greg Claytone1f50b92011-05-03 22:09:39 +00001033 ~CommandObjectTargetModulesSearchPathsList ()
Chris Lattner24943d22010-06-08 16:52:24 +00001034 {
1035 }
1036
1037 bool
Greg Clayton238c0a12010-09-18 01:14:36 +00001038 Execute (Args& command,
Chris Lattner24943d22010-06-08 16:52:24 +00001039 CommandReturnObject &result)
1040 {
Greg Clayton238c0a12010-09-18 01:14:36 +00001041 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Chris Lattner24943d22010-06-08 16:52:24 +00001042 if (target)
1043 {
1044 if (command.GetArgumentCount() != 0)
1045 {
Greg Claytonabe0fed2011-04-18 08:33:37 +00001046 result.AppendError ("list takes no arguments\n");
Chris Lattner24943d22010-06-08 16:52:24 +00001047 result.SetStatus (eReturnStatusFailed);
1048 return result.Succeeded();
1049 }
1050
1051 target->GetImageSearchPathList().Dump(&result.GetOutputStream());
Johnny Chen4d661352011-02-03 00:30:19 +00001052 result.SetStatus (eReturnStatusSuccessFinishResult);
Chris Lattner24943d22010-06-08 16:52:24 +00001053 }
1054 else
1055 {
Greg Claytonabe0fed2011-04-18 08:33:37 +00001056 result.AppendError ("invalid target\n");
Chris Lattner24943d22010-06-08 16:52:24 +00001057 result.SetStatus (eReturnStatusFailed);
1058 }
1059 return result.Succeeded();
1060 }
1061};
1062
Greg Claytone1f50b92011-05-03 22:09:39 +00001063#pragma mark CommandObjectTargetModulesSearchPathsQuery
1064
1065class CommandObjectTargetModulesSearchPathsQuery : public CommandObject
Chris Lattner24943d22010-06-08 16:52:24 +00001066{
1067public:
1068
Greg Claytone1f50b92011-05-03 22:09:39 +00001069 CommandObjectTargetModulesSearchPathsQuery (CommandInterpreter &interpreter) :
Greg Clayton238c0a12010-09-18 01:14:36 +00001070 CommandObject (interpreter,
Greg Claytone1f50b92011-05-03 22:09:39 +00001071 "target modules search-paths query",
Caroline Ticeabb507a2010-09-08 21:06:11 +00001072 "Transform a path using the first applicable image search path.",
Caroline Tice43b014a2010-10-04 22:28:36 +00001073 NULL)
Chris Lattner24943d22010-06-08 16:52:24 +00001074 {
Caroline Tice43b014a2010-10-04 22:28:36 +00001075 CommandArgumentEntry arg;
1076 CommandArgumentData path_arg;
1077
1078 // Define the first (and only) variant of this arg.
1079 path_arg.arg_type = eArgTypePath;
1080 path_arg.arg_repetition = eArgRepeatPlain;
1081
1082 // There is only one variant this argument could be; put it into the argument entry.
1083 arg.push_back (path_arg);
1084
1085 // Push the data for the first argument into the m_arguments vector.
1086 m_arguments.push_back (arg);
Chris Lattner24943d22010-06-08 16:52:24 +00001087 }
1088
Greg Claytone1f50b92011-05-03 22:09:39 +00001089 ~CommandObjectTargetModulesSearchPathsQuery ()
Chris Lattner24943d22010-06-08 16:52:24 +00001090 {
1091 }
1092
1093 bool
Greg Clayton238c0a12010-09-18 01:14:36 +00001094 Execute (Args& command,
Chris Lattner24943d22010-06-08 16:52:24 +00001095 CommandReturnObject &result)
1096 {
Greg Clayton238c0a12010-09-18 01:14:36 +00001097 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Chris Lattner24943d22010-06-08 16:52:24 +00001098 if (target)
1099 {
1100 if (command.GetArgumentCount() != 1)
1101 {
Greg Claytonabe0fed2011-04-18 08:33:37 +00001102 result.AppendError ("query requires one argument\n");
Chris Lattner24943d22010-06-08 16:52:24 +00001103 result.SetStatus (eReturnStatusFailed);
1104 return result.Succeeded();
1105 }
1106
1107 ConstString orig(command.GetArgumentAtIndex(0));
1108 ConstString transformed;
1109 if (target->GetImageSearchPathList().RemapPath(orig, transformed))
1110 result.GetOutputStream().Printf("%s\n", transformed.GetCString());
1111 else
1112 result.GetOutputStream().Printf("%s\n", orig.GetCString());
Johnny Chen4d661352011-02-03 00:30:19 +00001113
1114 result.SetStatus (eReturnStatusSuccessFinishResult);
Chris Lattner24943d22010-06-08 16:52:24 +00001115 }
1116 else
1117 {
Greg Claytonabe0fed2011-04-18 08:33:37 +00001118 result.AppendError ("invalid target\n");
Chris Lattner24943d22010-06-08 16:52:24 +00001119 result.SetStatus (eReturnStatusFailed);
1120 }
1121 return result.Succeeded();
1122 }
1123};
1124
Greg Claytone1f50b92011-05-03 22:09:39 +00001125//----------------------------------------------------------------------
1126// Static Helper functions
1127//----------------------------------------------------------------------
1128static void
1129DumpModuleArchitecture (Stream &strm, Module *module, bool full_triple, uint32_t width)
1130{
1131 if (module)
1132 {
1133 const char *arch_cstr;
1134 if (full_triple)
1135 arch_cstr = module->GetArchitecture().GetTriple().str().c_str();
1136 else
1137 arch_cstr = module->GetArchitecture().GetArchitectureName();
1138 if (width)
1139 strm.Printf("%-*s", width, arch_cstr);
1140 else
1141 strm.PutCString(arch_cstr);
1142 }
1143}
1144
1145static void
1146DumpModuleUUID (Stream &strm, Module *module)
1147{
Greg Clayton153ccd72011-08-10 02:10:13 +00001148 if (module->GetUUID().IsValid())
1149 module->GetUUID().Dump (&strm);
1150 else
1151 strm.PutCString(" ");
Greg Claytone1f50b92011-05-03 22:09:39 +00001152}
1153
1154static uint32_t
1155DumpCompileUnitLineTable
1156(
1157 CommandInterpreter &interpreter,
1158 Stream &strm,
1159 Module *module,
1160 const FileSpec &file_spec,
1161 bool load_addresses
1162 )
1163{
1164 uint32_t num_matches = 0;
1165 if (module)
1166 {
1167 SymbolContextList sc_list;
1168 num_matches = module->ResolveSymbolContextsForFileSpec (file_spec,
1169 0,
1170 false,
1171 eSymbolContextCompUnit,
1172 sc_list);
1173
1174 for (uint32_t i=0; i<num_matches; ++i)
1175 {
1176 SymbolContext sc;
1177 if (sc_list.GetContextAtIndex(i, sc))
1178 {
1179 if (i > 0)
1180 strm << "\n\n";
1181
1182 strm << "Line table for " << *static_cast<FileSpec*> (sc.comp_unit) << " in `"
1183 << module->GetFileSpec().GetFilename() << "\n";
1184 LineTable *line_table = sc.comp_unit->GetLineTable();
1185 if (line_table)
1186 line_table->GetDescription (&strm,
Greg Clayton567e7f32011-09-22 04:58:26 +00001187 interpreter.GetExecutionContext().GetTargetPtr(),
Greg Claytone1f50b92011-05-03 22:09:39 +00001188 lldb::eDescriptionLevelBrief);
1189 else
1190 strm << "No line table";
1191 }
1192 }
1193 }
1194 return num_matches;
1195}
1196
1197static void
1198DumpFullpath (Stream &strm, const FileSpec *file_spec_ptr, uint32_t width)
1199{
1200 if (file_spec_ptr)
1201 {
1202 if (width > 0)
1203 {
1204 char fullpath[PATH_MAX];
1205 if (file_spec_ptr->GetPath(fullpath, sizeof(fullpath)))
1206 {
1207 strm.Printf("%-*s", width, fullpath);
1208 return;
1209 }
1210 }
1211 else
1212 {
1213 file_spec_ptr->Dump(&strm);
1214 return;
1215 }
1216 }
1217 // Keep the width spacing correct if things go wrong...
1218 if (width > 0)
1219 strm.Printf("%-*s", width, "");
1220}
1221
1222static void
1223DumpDirectory (Stream &strm, const FileSpec *file_spec_ptr, uint32_t width)
1224{
1225 if (file_spec_ptr)
1226 {
1227 if (width > 0)
1228 strm.Printf("%-*s", width, file_spec_ptr->GetDirectory().AsCString(""));
1229 else
1230 file_spec_ptr->GetDirectory().Dump(&strm);
1231 return;
1232 }
1233 // Keep the width spacing correct if things go wrong...
1234 if (width > 0)
1235 strm.Printf("%-*s", width, "");
1236}
1237
1238static void
1239DumpBasename (Stream &strm, const FileSpec *file_spec_ptr, uint32_t width)
1240{
1241 if (file_spec_ptr)
1242 {
1243 if (width > 0)
1244 strm.Printf("%-*s", width, file_spec_ptr->GetFilename().AsCString(""));
1245 else
1246 file_spec_ptr->GetFilename().Dump(&strm);
1247 return;
1248 }
1249 // Keep the width spacing correct if things go wrong...
1250 if (width > 0)
1251 strm.Printf("%-*s", width, "");
1252}
1253
1254
1255static void
1256DumpModuleSymtab (CommandInterpreter &interpreter, Stream &strm, Module *module, SortOrder sort_order)
1257{
1258 if (module)
1259 {
1260 ObjectFile *objfile = module->GetObjectFile ();
1261 if (objfile)
1262 {
1263 Symtab *symtab = objfile->GetSymtab();
1264 if (symtab)
Greg Clayton567e7f32011-09-22 04:58:26 +00001265 symtab->Dump(&strm, interpreter.GetExecutionContext().GetTargetPtr(), sort_order);
Greg Claytone1f50b92011-05-03 22:09:39 +00001266 }
1267 }
1268}
1269
1270static void
1271DumpModuleSections (CommandInterpreter &interpreter, Stream &strm, Module *module)
1272{
1273 if (module)
1274 {
1275 ObjectFile *objfile = module->GetObjectFile ();
1276 if (objfile)
1277 {
1278 SectionList *section_list = objfile->GetSectionList();
1279 if (section_list)
1280 {
1281 strm.PutCString ("Sections for '");
1282 strm << module->GetFileSpec();
1283 if (module->GetObjectName())
1284 strm << '(' << module->GetObjectName() << ')';
1285 strm.Printf ("' (%s):\n", module->GetArchitecture().GetArchitectureName());
1286 strm.IndentMore();
Greg Clayton567e7f32011-09-22 04:58:26 +00001287 section_list->Dump(&strm, interpreter.GetExecutionContext().GetTargetPtr(), true, UINT32_MAX);
Greg Claytone1f50b92011-05-03 22:09:39 +00001288 strm.IndentLess();
1289 }
1290 }
1291 }
1292}
1293
1294static bool
1295DumpModuleSymbolVendor (Stream &strm, Module *module)
1296{
1297 if (module)
1298 {
1299 SymbolVendor *symbol_vendor = module->GetSymbolVendor(true);
1300 if (symbol_vendor)
1301 {
1302 symbol_vendor->Dump(&strm);
1303 return true;
1304 }
1305 }
1306 return false;
1307}
1308
1309static bool
1310LookupAddressInModule
1311(
1312 CommandInterpreter &interpreter,
1313 Stream &strm,
1314 Module *module,
1315 uint32_t resolve_mask,
1316 lldb::addr_t raw_addr,
1317 lldb::addr_t offset,
1318 bool verbose
1319 )
1320{
1321 if (module)
1322 {
1323 lldb::addr_t addr = raw_addr - offset;
1324 Address so_addr;
1325 SymbolContext sc;
Greg Clayton567e7f32011-09-22 04:58:26 +00001326 Target *target = interpreter.GetExecutionContext().GetTargetPtr();
Greg Claytone1f50b92011-05-03 22:09:39 +00001327 if (target && !target->GetSectionLoadList().IsEmpty())
1328 {
1329 if (!target->GetSectionLoadList().ResolveLoadAddress (addr, so_addr))
1330 return false;
1331 else if (so_addr.GetModule() != module)
1332 return false;
1333 }
1334 else
1335 {
1336 if (!module->ResolveFileAddress (addr, so_addr))
1337 return false;
1338 }
1339
1340 // If an offset was given, print out the address we ended up looking up
1341 if (offset)
1342 strm.Printf("File Address: 0x%llx\n", addr);
1343
1344 ExecutionContextScope *exe_scope = interpreter.GetExecutionContext().GetBestExecutionContextScope();
1345 strm.IndentMore();
1346 strm.Indent (" Address: ");
1347 so_addr.Dump (&strm, exe_scope, Address::DumpStyleSectionNameOffset);
1348 strm.EOL();
1349 strm.Indent (" Summary: ");
1350 const uint32_t save_indent = strm.GetIndentLevel ();
Greg Clayton2f57db02011-10-01 00:45:15 +00001351 strm.SetIndentLevel (save_indent + 13);
Greg Claytone1f50b92011-05-03 22:09:39 +00001352 so_addr.Dump (&strm, exe_scope, Address::DumpStyleResolvedDescription);
1353 strm.SetIndentLevel (save_indent);
Greg Claytone1f50b92011-05-03 22:09:39 +00001354 // Print out detailed address information when verbose is enabled
1355 if (verbose)
1356 {
Greg Clayton2f57db02011-10-01 00:45:15 +00001357 strm.EOL();
Jason Molendafb66bb52011-09-23 00:27:44 +00001358 so_addr.Dump (&strm, exe_scope, Address::DumpStyleDetailedSymbolContext);
Greg Claytone1f50b92011-05-03 22:09:39 +00001359 }
1360 strm.IndentLess();
1361 return true;
1362 }
1363
1364 return false;
1365}
1366
1367static uint32_t
1368LookupSymbolInModule (CommandInterpreter &interpreter, Stream &strm, Module *module, const char *name, bool name_is_regex)
1369{
1370 if (module)
1371 {
1372 SymbolContext sc;
1373
1374 ObjectFile *objfile = module->GetObjectFile ();
1375 if (objfile)
1376 {
1377 Symtab *symtab = objfile->GetSymtab();
1378 if (symtab)
1379 {
1380 uint32_t i;
1381 std::vector<uint32_t> match_indexes;
1382 ConstString symbol_name (name);
1383 uint32_t num_matches = 0;
1384 if (name_is_regex)
1385 {
1386 RegularExpression name_regexp(name);
1387 num_matches = symtab->AppendSymbolIndexesMatchingRegExAndType (name_regexp,
1388 eSymbolTypeAny,
1389 match_indexes);
1390 }
1391 else
1392 {
1393 num_matches = symtab->AppendSymbolIndexesWithName (symbol_name, match_indexes);
1394 }
1395
1396
1397 if (num_matches > 0)
1398 {
1399 strm.Indent ();
1400 strm.Printf("%u symbols match %s'%s' in ", num_matches,
1401 name_is_regex ? "the regular expression " : "", name);
1402 DumpFullpath (strm, &module->GetFileSpec(), 0);
1403 strm.PutCString(":\n");
1404 strm.IndentMore ();
1405 Symtab::DumpSymbolHeader (&strm);
1406 for (i=0; i < num_matches; ++i)
1407 {
1408 Symbol *symbol = symtab->SymbolAtIndex(match_indexes[i]);
1409 strm.Indent ();
Greg Clayton567e7f32011-09-22 04:58:26 +00001410 symbol->Dump (&strm, interpreter.GetExecutionContext().GetTargetPtr(), i);
Greg Claytone1f50b92011-05-03 22:09:39 +00001411 }
1412 strm.IndentLess ();
1413 return num_matches;
1414 }
1415 }
1416 }
1417 }
1418 return 0;
1419}
1420
1421
1422static void
1423DumpSymbolContextList (CommandInterpreter &interpreter, Stream &strm, SymbolContextList &sc_list, bool prepend_addr, bool verbose)
1424{
1425 strm.IndentMore ();
1426 uint32_t i;
1427 const uint32_t num_matches = sc_list.GetSize();
1428
1429 for (i=0; i<num_matches; ++i)
1430 {
1431 SymbolContext sc;
1432 if (sc_list.GetContextAtIndex(i, sc))
1433 {
1434 strm.Indent();
1435 ExecutionContextScope *exe_scope = interpreter.GetExecutionContext().GetBestExecutionContextScope ();
1436
1437 if (prepend_addr)
1438 {
1439 if (sc.line_entry.range.GetBaseAddress().IsValid())
1440 {
1441 sc.line_entry.range.GetBaseAddress().Dump (&strm,
1442 exe_scope,
1443 Address::DumpStyleLoadAddress,
1444 Address::DumpStyleModuleWithFileAddress);
1445 strm.PutCString(" in ");
1446 }
1447 }
1448 sc.DumpStopContext(&strm,
1449 exe_scope,
1450 sc.line_entry.range.GetBaseAddress(),
1451 true,
1452 true,
1453 false);
1454 strm.EOL();
1455 if (verbose)
1456 {
1457 if (sc.line_entry.range.GetBaseAddress().IsValid())
1458 {
1459 if (sc.line_entry.range.GetBaseAddress().Dump (&strm,
1460 exe_scope,
1461 Address::DumpStyleDetailedSymbolContext))
1462 strm.PutCString("\n\n");
1463 }
1464 else if (sc.function->GetAddressRange().GetBaseAddress().IsValid())
1465 {
1466 if (sc.function->GetAddressRange().GetBaseAddress().Dump (&strm,
1467 exe_scope,
1468 Address::DumpStyleDetailedSymbolContext))
1469 strm.PutCString("\n\n");
1470 }
1471 }
1472 }
1473 }
1474 strm.IndentLess ();
1475}
1476
1477static uint32_t
1478LookupFunctionInModule (CommandInterpreter &interpreter, Stream &strm, Module *module, const char *name, bool name_is_regex, bool verbose)
1479{
1480 if (module && name && name[0])
1481 {
1482 SymbolContextList sc_list;
1483 const bool include_symbols = false;
1484 const bool append = true;
1485 uint32_t num_matches = 0;
1486 if (name_is_regex)
1487 {
1488 RegularExpression function_name_regex (name);
1489 num_matches = module->FindFunctions (function_name_regex,
1490 include_symbols,
1491 append,
1492 sc_list);
1493 }
1494 else
1495 {
1496 ConstString function_name (name);
Sean Callanan3e80cd92011-10-12 02:08:07 +00001497 num_matches = module->FindFunctions (function_name,
1498 NULL,
Greg Claytone1f50b92011-05-03 22:09:39 +00001499 eFunctionNameTypeBase | eFunctionNameTypeFull | eFunctionNameTypeMethod | eFunctionNameTypeSelector,
1500 include_symbols,
1501 append,
1502 sc_list);
1503 }
1504
1505 if (num_matches)
1506 {
1507 strm.Indent ();
1508 strm.Printf("%u match%s found in ", num_matches, num_matches > 1 ? "es" : "");
1509 DumpFullpath (strm, &module->GetFileSpec(), 0);
1510 strm.PutCString(":\n");
1511 DumpSymbolContextList (interpreter, strm, sc_list, true, verbose);
1512 }
1513 return num_matches;
1514 }
1515 return 0;
1516}
1517
1518static uint32_t
Greg Clayton801417e2011-07-07 01:59:51 +00001519LookupTypeInModule (CommandInterpreter &interpreter,
1520 Stream &strm,
1521 Module *module,
1522 const char *name_cstr,
1523 bool name_is_regex)
Greg Claytone1f50b92011-05-03 22:09:39 +00001524{
1525 if (module && name_cstr && name_cstr[0])
1526 {
Greg Clayton37bb8dd2011-12-08 02:13:16 +00001527 TypeList type_list;
1528 const uint32_t max_num_matches = 1;
1529 uint32_t num_matches = 0;
1530 SymbolContext sc;
1531
1532 ConstString name(name_cstr);
1533 num_matches = module->FindTypes(sc, name, NULL, true, max_num_matches, type_list);
Greg Claytone1f50b92011-05-03 22:09:39 +00001534
Greg Clayton37bb8dd2011-12-08 02:13:16 +00001535 if (num_matches)
1536 {
1537 strm.Indent ();
1538 strm.Printf("%u match%s found in ", num_matches, num_matches > 1 ? "es" : "");
1539 DumpFullpath (strm, &module->GetFileSpec(), 0);
1540 strm.PutCString(":\n");
1541 const uint32_t num_types = type_list.GetSize();
1542 for (uint32_t i=0; i<num_types; ++i)
Greg Claytone1f50b92011-05-03 22:09:39 +00001543 {
Greg Clayton37bb8dd2011-12-08 02:13:16 +00001544 TypeSP type_sp (type_list.GetTypeAtIndex(i));
1545 if (type_sp)
Greg Claytone1f50b92011-05-03 22:09:39 +00001546 {
Greg Clayton37bb8dd2011-12-08 02:13:16 +00001547 // Resolve the clang type so that any forward references
1548 // to types that haven't yet been parsed will get parsed.
1549 type_sp->GetClangFullType ();
1550 type_sp->GetDescription (&strm, eDescriptionLevelFull, true);
Greg Claytone1f50b92011-05-03 22:09:39 +00001551 }
Greg Clayton37bb8dd2011-12-08 02:13:16 +00001552 strm.EOL();
Greg Claytone1f50b92011-05-03 22:09:39 +00001553 }
Greg Clayton37bb8dd2011-12-08 02:13:16 +00001554 }
1555 return num_matches;
Greg Claytone1f50b92011-05-03 22:09:39 +00001556 }
1557 return 0;
1558}
1559
1560static uint32_t
1561LookupFileAndLineInModule (CommandInterpreter &interpreter,
1562 Stream &strm,
1563 Module *module,
1564 const FileSpec &file_spec,
1565 uint32_t line,
1566 bool check_inlines,
1567 bool verbose)
1568{
1569 if (module && file_spec)
1570 {
1571 SymbolContextList sc_list;
1572 const uint32_t num_matches = module->ResolveSymbolContextsForFileSpec(file_spec, line, check_inlines,
1573 eSymbolContextEverything, sc_list);
1574 if (num_matches > 0)
1575 {
1576 strm.Indent ();
1577 strm.Printf("%u match%s found in ", num_matches, num_matches > 1 ? "es" : "");
1578 strm << file_spec;
1579 if (line > 0)
1580 strm.Printf (":%u", line);
1581 strm << " in ";
1582 DumpFullpath (strm, &module->GetFileSpec(), 0);
1583 strm.PutCString(":\n");
1584 DumpSymbolContextList (interpreter, strm, sc_list, true, verbose);
1585 return num_matches;
1586 }
1587 }
1588 return 0;
1589
1590}
1591
Greg Clayton91048ef2011-11-10 01:18:58 +00001592
1593static size_t
1594FindModulesByName (Target *target,
1595 const char *module_name,
1596 ModuleList &module_list,
1597 bool check_global_list)
1598{
1599// Dump specified images (by basename or fullpath)
1600 FileSpec module_file_spec(module_name, false);
1601
1602 const size_t initial_size = module_list.GetSize ();
1603
1604 size_t num_matches = 0;
1605
1606 if (target)
1607 {
1608 num_matches = target->GetImages().FindModules (&module_file_spec,
1609 NULL,
1610 NULL,
1611 NULL,
1612 module_list);
1613
1614 // Not found in our module list for our target, check the main
1615 // shared module list in case it is a extra file used somewhere
1616 // else
1617 if (num_matches == 0)
1618 num_matches = ModuleList::FindSharedModules (module_file_spec,
1619 target->GetArchitecture(),
1620 NULL,
1621 NULL,
1622 module_list);
1623 }
1624 else
1625 {
1626 num_matches = ModuleList::FindSharedModules (module_file_spec,
1627 ArchSpec(),
1628 NULL,
1629 NULL,
1630 module_list);
1631 }
1632
1633 if (check_global_list && num_matches == 0)
1634 {
1635 // Check the global list
1636 Mutex::Locker locker(Module::GetAllocationModuleCollectionMutex().GetMutex());
1637 const uint32_t num_modules = Module::GetNumberAllocatedModules();
1638 ModuleSP module_sp;
1639 for (uint32_t image_idx = 0; image_idx<num_modules; ++image_idx)
1640 {
1641 Module *module = Module::GetAllocatedModuleAtIndex(image_idx);
1642
1643 if (module)
1644 {
1645 if (FileSpec::Equal(module->GetFileSpec(), module_file_spec, true))
1646 {
1647 module_sp = module;
1648 module_list.AppendIfNeeded(module_sp);
1649 }
1650 }
1651 }
1652 }
1653 return module_list.GetSize () - initial_size;
1654}
1655
Greg Claytone1f50b92011-05-03 22:09:39 +00001656#pragma mark CommandObjectTargetModulesModuleAutoComplete
1657
1658//----------------------------------------------------------------------
1659// A base command object class that can auto complete with module file
1660// paths
1661//----------------------------------------------------------------------
1662
1663class CommandObjectTargetModulesModuleAutoComplete : public CommandObject
1664{
1665public:
1666
1667 CommandObjectTargetModulesModuleAutoComplete (CommandInterpreter &interpreter,
1668 const char *name,
1669 const char *help,
1670 const char *syntax) :
1671 CommandObject (interpreter, name, help, syntax)
1672 {
1673 CommandArgumentEntry arg;
1674 CommandArgumentData file_arg;
1675
1676 // Define the first (and only) variant of this arg.
1677 file_arg.arg_type = eArgTypeFilename;
1678 file_arg.arg_repetition = eArgRepeatStar;
1679
1680 // There is only one variant this argument could be; put it into the argument entry.
1681 arg.push_back (file_arg);
1682
1683 // Push the data for the first argument into the m_arguments vector.
1684 m_arguments.push_back (arg);
1685 }
1686
1687 virtual
1688 ~CommandObjectTargetModulesModuleAutoComplete ()
1689 {
1690 }
1691
1692 virtual int
1693 HandleArgumentCompletion (Args &input,
1694 int &cursor_index,
1695 int &cursor_char_position,
1696 OptionElementVector &opt_element_vector,
1697 int match_start_point,
1698 int max_return_elements,
1699 bool &word_complete,
1700 StringList &matches)
1701 {
1702 // Arguments are the standard module completer.
1703 std::string completion_str (input.GetArgumentAtIndex(cursor_index));
1704 completion_str.erase (cursor_char_position);
1705
1706 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
1707 CommandCompletions::eModuleCompletion,
1708 completion_str.c_str(),
1709 match_start_point,
1710 max_return_elements,
1711 NULL,
1712 word_complete,
1713 matches);
1714 return matches.GetSize();
1715 }
1716};
1717
1718#pragma mark CommandObjectTargetModulesSourceFileAutoComplete
1719
1720//----------------------------------------------------------------------
1721// A base command object class that can auto complete with module source
1722// file paths
1723//----------------------------------------------------------------------
1724
1725class CommandObjectTargetModulesSourceFileAutoComplete : public CommandObject
1726{
1727public:
1728
1729 CommandObjectTargetModulesSourceFileAutoComplete (CommandInterpreter &interpreter,
1730 const char *name,
1731 const char *help,
1732 const char *syntax) :
1733 CommandObject (interpreter, name, help, syntax)
1734 {
1735 CommandArgumentEntry arg;
1736 CommandArgumentData source_file_arg;
1737
1738 // Define the first (and only) variant of this arg.
1739 source_file_arg.arg_type = eArgTypeSourceFile;
1740 source_file_arg.arg_repetition = eArgRepeatPlus;
1741
1742 // There is only one variant this argument could be; put it into the argument entry.
1743 arg.push_back (source_file_arg);
1744
1745 // Push the data for the first argument into the m_arguments vector.
1746 m_arguments.push_back (arg);
1747 }
1748
1749 virtual
1750 ~CommandObjectTargetModulesSourceFileAutoComplete ()
1751 {
1752 }
1753
1754 virtual int
1755 HandleArgumentCompletion (Args &input,
1756 int &cursor_index,
1757 int &cursor_char_position,
1758 OptionElementVector &opt_element_vector,
1759 int match_start_point,
1760 int max_return_elements,
1761 bool &word_complete,
1762 StringList &matches)
1763 {
1764 // Arguments are the standard source file completer.
1765 std::string completion_str (input.GetArgumentAtIndex(cursor_index));
1766 completion_str.erase (cursor_char_position);
1767
1768 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
1769 CommandCompletions::eSourceFileCompletion,
1770 completion_str.c_str(),
1771 match_start_point,
1772 max_return_elements,
1773 NULL,
1774 word_complete,
1775 matches);
1776 return matches.GetSize();
1777 }
1778};
1779
1780
1781#pragma mark CommandObjectTargetModulesDumpSymtab
1782
1783
1784class CommandObjectTargetModulesDumpSymtab : public CommandObjectTargetModulesModuleAutoComplete
1785{
1786public:
1787 CommandObjectTargetModulesDumpSymtab (CommandInterpreter &interpreter) :
1788 CommandObjectTargetModulesModuleAutoComplete (interpreter,
1789 "target modules dump symtab",
1790 "Dump the symbol table from one or more target modules.",
1791 NULL),
1792 m_options (interpreter)
1793 {
1794 }
1795
1796 virtual
1797 ~CommandObjectTargetModulesDumpSymtab ()
1798 {
1799 }
1800
1801 virtual bool
1802 Execute (Args& command,
1803 CommandReturnObject &result)
1804 {
1805 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
1806 if (target == NULL)
1807 {
1808 result.AppendError ("invalid target, create a debug target using the 'target create' command");
1809 result.SetStatus (eReturnStatusFailed);
1810 return false;
1811 }
1812 else
1813 {
1814 uint32_t num_dumped = 0;
1815
1816 uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize();
1817 result.GetOutputStream().SetAddressByteSize(addr_byte_size);
1818 result.GetErrorStream().SetAddressByteSize(addr_byte_size);
1819
1820 if (command.GetArgumentCount() == 0)
1821 {
1822 // Dump all sections for all modules images
1823 const uint32_t num_modules = target->GetImages().GetSize();
1824 if (num_modules > 0)
1825 {
1826 result.GetOutputStream().Printf("Dumping symbol table for %u modules.\n", num_modules);
1827 for (uint32_t image_idx = 0; image_idx<num_modules; ++image_idx)
1828 {
1829 if (num_dumped > 0)
1830 {
1831 result.GetOutputStream().EOL();
1832 result.GetOutputStream().EOL();
1833 }
1834 num_dumped++;
1835 DumpModuleSymtab (m_interpreter, result.GetOutputStream(), target->GetImages().GetModulePointerAtIndex(image_idx), m_options.m_sort_order);
1836 }
1837 }
1838 else
1839 {
1840 result.AppendError ("the target has no associated executable images");
1841 result.SetStatus (eReturnStatusFailed);
1842 return false;
1843 }
1844 }
1845 else
1846 {
1847 // Dump specified images (by basename or fullpath)
1848 const char *arg_cstr;
1849 for (int arg_idx = 0; (arg_cstr = command.GetArgumentAtIndex(arg_idx)) != NULL; ++arg_idx)
1850 {
Greg Clayton91048ef2011-11-10 01:18:58 +00001851 ModuleList module_list;
1852 const size_t num_matches = FindModulesByName (target, arg_cstr, module_list, true);
1853 if (num_matches > 0)
Greg Claytone1f50b92011-05-03 22:09:39 +00001854 {
Greg Clayton91048ef2011-11-10 01:18:58 +00001855 for (size_t i=0; i<num_matches; ++i)
Greg Claytone1f50b92011-05-03 22:09:39 +00001856 {
Greg Clayton91048ef2011-11-10 01:18:58 +00001857 Module *module = module_list.GetModulePointerAtIndex(i);
1858 if (module)
Greg Claytone1f50b92011-05-03 22:09:39 +00001859 {
1860 if (num_dumped > 0)
1861 {
1862 result.GetOutputStream().EOL();
1863 result.GetOutputStream().EOL();
1864 }
1865 num_dumped++;
Greg Clayton91048ef2011-11-10 01:18:58 +00001866 DumpModuleSymtab (m_interpreter, result.GetOutputStream(), module, m_options.m_sort_order);
Greg Claytone1f50b92011-05-03 22:09:39 +00001867 }
1868 }
1869 }
1870 else
1871 result.AppendWarningWithFormat("Unable to find an image that matches '%s'.\n", arg_cstr);
1872 }
1873 }
1874
1875 if (num_dumped > 0)
1876 result.SetStatus (eReturnStatusSuccessFinishResult);
1877 else
1878 {
1879 result.AppendError ("no matching executable images found");
1880 result.SetStatus (eReturnStatusFailed);
1881 }
1882 }
1883 return result.Succeeded();
1884 }
1885
1886 virtual Options *
1887 GetOptions ()
1888 {
1889 return &m_options;
1890 }
1891
1892 class CommandOptions : public Options
1893 {
1894 public:
1895
1896 CommandOptions (CommandInterpreter &interpreter) :
1897 Options(interpreter),
1898 m_sort_order (eSortOrderNone)
1899 {
1900 }
1901
1902 virtual
1903 ~CommandOptions ()
1904 {
1905 }
1906
1907 virtual Error
1908 SetOptionValue (uint32_t option_idx, const char *option_arg)
1909 {
1910 Error error;
1911 char short_option = (char) m_getopt_table[option_idx].val;
1912
1913 switch (short_option)
1914 {
1915 case 's':
Greg Claytone1f50b92011-05-03 22:09:39 +00001916 m_sort_order = (SortOrder) Args::StringToOptionEnum (option_arg,
1917 g_option_table[option_idx].enum_values,
1918 eSortOrderNone,
Greg Clayton61aca5d2011-10-07 18:58:12 +00001919 error);
Greg Claytone1f50b92011-05-03 22:09:39 +00001920 break;
1921
1922 default:
Greg Clayton9c236732011-10-26 00:56:27 +00001923 error.SetErrorStringWithFormat("invalid short option character '%c'", short_option);
Greg Claytone1f50b92011-05-03 22:09:39 +00001924 break;
1925
1926 }
1927 return error;
1928 }
1929
1930 void
1931 OptionParsingStarting ()
1932 {
1933 m_sort_order = eSortOrderNone;
1934 }
1935
1936 const OptionDefinition*
1937 GetDefinitions ()
1938 {
1939 return g_option_table;
1940 }
1941
1942 // Options table: Required for subclasses of Options.
1943 static OptionDefinition g_option_table[];
1944
1945 SortOrder m_sort_order;
1946 };
1947
1948protected:
1949
1950 CommandOptions m_options;
1951};
1952
1953static OptionEnumValueElement
1954g_sort_option_enumeration[4] =
1955{
1956 { eSortOrderNone, "none", "No sorting, use the original symbol table order."},
1957 { eSortOrderByAddress, "address", "Sort output by symbol address."},
1958 { eSortOrderByName, "name", "Sort output by symbol name."},
1959 { 0, NULL, NULL }
1960};
1961
1962
1963OptionDefinition
1964CommandObjectTargetModulesDumpSymtab::CommandOptions::g_option_table[] =
1965{
1966 { LLDB_OPT_SET_1, false, "sort", 's', required_argument, g_sort_option_enumeration, 0, eArgTypeSortOrder, "Supply a sort order when dumping the symbol table."},
1967 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
1968};
1969
1970#pragma mark CommandObjectTargetModulesDumpSections
1971
1972//----------------------------------------------------------------------
1973// Image section dumping command
1974//----------------------------------------------------------------------
1975
1976class CommandObjectTargetModulesDumpSections : public CommandObjectTargetModulesModuleAutoComplete
1977{
1978public:
1979 CommandObjectTargetModulesDumpSections (CommandInterpreter &interpreter) :
1980 CommandObjectTargetModulesModuleAutoComplete (interpreter,
1981 "target modules dump sections",
1982 "Dump the sections from one or more target modules.",
1983 //"target modules dump sections [<file1> ...]")
1984 NULL)
1985 {
1986 }
1987
1988 virtual
1989 ~CommandObjectTargetModulesDumpSections ()
1990 {
1991 }
1992
1993 virtual bool
1994 Execute (Args& command,
1995 CommandReturnObject &result)
1996 {
1997 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
1998 if (target == NULL)
1999 {
2000 result.AppendError ("invalid target, create a debug target using the 'target create' command");
2001 result.SetStatus (eReturnStatusFailed);
2002 return false;
2003 }
2004 else
2005 {
2006 uint32_t num_dumped = 0;
2007
2008 uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize();
2009 result.GetOutputStream().SetAddressByteSize(addr_byte_size);
2010 result.GetErrorStream().SetAddressByteSize(addr_byte_size);
2011
2012 if (command.GetArgumentCount() == 0)
2013 {
2014 // Dump all sections for all modules images
2015 const uint32_t num_modules = target->GetImages().GetSize();
2016 if (num_modules > 0)
2017 {
2018 result.GetOutputStream().Printf("Dumping sections for %u modules.\n", num_modules);
2019 for (uint32_t image_idx = 0; image_idx<num_modules; ++image_idx)
2020 {
2021 num_dumped++;
2022 DumpModuleSections (m_interpreter, result.GetOutputStream(), target->GetImages().GetModulePointerAtIndex(image_idx));
2023 }
2024 }
2025 else
2026 {
2027 result.AppendError ("the target has no associated executable images");
2028 result.SetStatus (eReturnStatusFailed);
2029 return false;
2030 }
2031 }
2032 else
2033 {
2034 // Dump specified images (by basename or fullpath)
2035 const char *arg_cstr;
2036 for (int arg_idx = 0; (arg_cstr = command.GetArgumentAtIndex(arg_idx)) != NULL; ++arg_idx)
2037 {
Greg Clayton91048ef2011-11-10 01:18:58 +00002038 ModuleList module_list;
2039 const size_t num_matches = FindModulesByName (target, arg_cstr, module_list, true);
2040 if (num_matches > 0)
Greg Claytone1f50b92011-05-03 22:09:39 +00002041 {
Greg Clayton91048ef2011-11-10 01:18:58 +00002042 for (size_t i=0; i<num_matches; ++i)
Greg Claytone1f50b92011-05-03 22:09:39 +00002043 {
Greg Clayton91048ef2011-11-10 01:18:58 +00002044 Module *module = module_list.GetModulePointerAtIndex(i);
2045 if (module)
Greg Claytone1f50b92011-05-03 22:09:39 +00002046 {
2047 num_dumped++;
Greg Clayton91048ef2011-11-10 01:18:58 +00002048 DumpModuleSections (m_interpreter, result.GetOutputStream(), module);
Greg Claytone1f50b92011-05-03 22:09:39 +00002049 }
2050 }
2051 }
2052 else
Greg Clayton91048ef2011-11-10 01:18:58 +00002053 {
2054 // Check the global list
2055 Mutex::Locker locker(Module::GetAllocationModuleCollectionMutex().GetMutex());
2056
Greg Claytone1f50b92011-05-03 22:09:39 +00002057 result.AppendWarningWithFormat("Unable to find an image that matches '%s'.\n", arg_cstr);
Greg Clayton91048ef2011-11-10 01:18:58 +00002058 }
Greg Claytone1f50b92011-05-03 22:09:39 +00002059 }
2060 }
2061
2062 if (num_dumped > 0)
2063 result.SetStatus (eReturnStatusSuccessFinishResult);
2064 else
2065 {
2066 result.AppendError ("no matching executable images found");
2067 result.SetStatus (eReturnStatusFailed);
2068 }
2069 }
2070 return result.Succeeded();
2071 }
2072};
2073
2074
2075#pragma mark CommandObjectTargetModulesDumpSymfile
2076
2077//----------------------------------------------------------------------
2078// Image debug symbol dumping command
2079//----------------------------------------------------------------------
2080
2081class CommandObjectTargetModulesDumpSymfile : public CommandObjectTargetModulesModuleAutoComplete
2082{
2083public:
2084 CommandObjectTargetModulesDumpSymfile (CommandInterpreter &interpreter) :
2085 CommandObjectTargetModulesModuleAutoComplete (interpreter,
2086 "target modules dump symfile",
2087 "Dump the debug symbol file for one or more target modules.",
2088 //"target modules dump symfile [<file1> ...]")
2089 NULL)
2090 {
2091 }
2092
2093 virtual
2094 ~CommandObjectTargetModulesDumpSymfile ()
2095 {
2096 }
2097
2098 virtual bool
2099 Execute (Args& command,
2100 CommandReturnObject &result)
2101 {
2102 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
2103 if (target == NULL)
2104 {
2105 result.AppendError ("invalid target, create a debug target using the 'target create' command");
2106 result.SetStatus (eReturnStatusFailed);
2107 return false;
2108 }
2109 else
2110 {
2111 uint32_t num_dumped = 0;
2112
2113 uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize();
2114 result.GetOutputStream().SetAddressByteSize(addr_byte_size);
2115 result.GetErrorStream().SetAddressByteSize(addr_byte_size);
2116
2117 if (command.GetArgumentCount() == 0)
2118 {
2119 // Dump all sections for all modules images
2120 const uint32_t num_modules = target->GetImages().GetSize();
2121 if (num_modules > 0)
2122 {
2123 result.GetOutputStream().Printf("Dumping debug symbols for %u modules.\n", num_modules);
2124 for (uint32_t image_idx = 0; image_idx<num_modules; ++image_idx)
2125 {
2126 if (DumpModuleSymbolVendor (result.GetOutputStream(), target->GetImages().GetModulePointerAtIndex(image_idx)))
2127 num_dumped++;
2128 }
2129 }
2130 else
2131 {
2132 result.AppendError ("the target has no associated executable images");
2133 result.SetStatus (eReturnStatusFailed);
2134 return false;
2135 }
2136 }
2137 else
2138 {
2139 // Dump specified images (by basename or fullpath)
2140 const char *arg_cstr;
2141 for (int arg_idx = 0; (arg_cstr = command.GetArgumentAtIndex(arg_idx)) != NULL; ++arg_idx)
2142 {
Greg Clayton91048ef2011-11-10 01:18:58 +00002143 ModuleList module_list;
2144 const size_t num_matches = FindModulesByName (target, arg_cstr, module_list, true);
2145 if (num_matches > 0)
Greg Claytone1f50b92011-05-03 22:09:39 +00002146 {
Greg Clayton91048ef2011-11-10 01:18:58 +00002147 for (size_t i=0; i<num_matches; ++i)
Greg Claytone1f50b92011-05-03 22:09:39 +00002148 {
Greg Clayton91048ef2011-11-10 01:18:58 +00002149 Module *module = module_list.GetModulePointerAtIndex(i);
2150 if (module)
Greg Claytone1f50b92011-05-03 22:09:39 +00002151 {
Greg Clayton91048ef2011-11-10 01:18:58 +00002152 if (DumpModuleSymbolVendor (result.GetOutputStream(), module))
Greg Claytone1f50b92011-05-03 22:09:39 +00002153 num_dumped++;
2154 }
2155 }
2156 }
2157 else
2158 result.AppendWarningWithFormat("Unable to find an image that matches '%s'.\n", arg_cstr);
2159 }
2160 }
2161
2162 if (num_dumped > 0)
2163 result.SetStatus (eReturnStatusSuccessFinishResult);
2164 else
2165 {
2166 result.AppendError ("no matching executable images found");
2167 result.SetStatus (eReturnStatusFailed);
2168 }
2169 }
2170 return result.Succeeded();
2171 }
2172};
2173
2174
2175#pragma mark CommandObjectTargetModulesDumpLineTable
2176
2177//----------------------------------------------------------------------
2178// Image debug line table dumping command
2179//----------------------------------------------------------------------
2180
2181class CommandObjectTargetModulesDumpLineTable : public CommandObjectTargetModulesSourceFileAutoComplete
2182{
2183public:
2184 CommandObjectTargetModulesDumpLineTable (CommandInterpreter &interpreter) :
2185 CommandObjectTargetModulesSourceFileAutoComplete (interpreter,
2186 "target modules dump line-table",
2187 "Dump the debug symbol file for one or more target modules.",
2188 NULL)
2189 {
2190 }
2191
2192 virtual
2193 ~CommandObjectTargetModulesDumpLineTable ()
2194 {
2195 }
2196
2197 virtual bool
2198 Execute (Args& command,
2199 CommandReturnObject &result)
2200 {
2201 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
2202 if (target == NULL)
2203 {
2204 result.AppendError ("invalid target, create a debug target using the 'target create' command");
2205 result.SetStatus (eReturnStatusFailed);
2206 return false;
2207 }
2208 else
2209 {
2210 ExecutionContext exe_ctx(m_interpreter.GetExecutionContext());
2211 uint32_t total_num_dumped = 0;
2212
2213 uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize();
2214 result.GetOutputStream().SetAddressByteSize(addr_byte_size);
2215 result.GetErrorStream().SetAddressByteSize(addr_byte_size);
2216
2217 if (command.GetArgumentCount() == 0)
2218 {
2219 result.AppendErrorWithFormat ("\nSyntax: %s\n", m_cmd_syntax.c_str());
2220 result.SetStatus (eReturnStatusFailed);
2221 }
2222 else
2223 {
2224 // Dump specified images (by basename or fullpath)
2225 const char *arg_cstr;
2226 for (int arg_idx = 0; (arg_cstr = command.GetArgumentAtIndex(arg_idx)) != NULL; ++arg_idx)
2227 {
2228 FileSpec file_spec(arg_cstr, false);
2229 const uint32_t num_modules = target->GetImages().GetSize();
2230 if (num_modules > 0)
2231 {
2232 uint32_t num_dumped = 0;
2233 for (uint32_t i = 0; i<num_modules; ++i)
2234 {
2235 if (DumpCompileUnitLineTable (m_interpreter,
2236 result.GetOutputStream(),
2237 target->GetImages().GetModulePointerAtIndex(i),
2238 file_spec,
Greg Clayton567e7f32011-09-22 04:58:26 +00002239 exe_ctx.GetProcessPtr() && exe_ctx.GetProcessRef().IsAlive()))
Greg Claytone1f50b92011-05-03 22:09:39 +00002240 num_dumped++;
2241 }
2242 if (num_dumped == 0)
2243 result.AppendWarningWithFormat ("No source filenames matched '%s'.\n", arg_cstr);
2244 else
2245 total_num_dumped += num_dumped;
2246 }
2247 }
2248 }
2249
2250 if (total_num_dumped > 0)
2251 result.SetStatus (eReturnStatusSuccessFinishResult);
2252 else
2253 {
2254 result.AppendError ("no source filenames matched any command arguments");
2255 result.SetStatus (eReturnStatusFailed);
2256 }
2257 }
2258 return result.Succeeded();
2259 }
2260};
2261
2262
2263#pragma mark CommandObjectTargetModulesDump
2264
2265//----------------------------------------------------------------------
2266// Dump multi-word command for target modules
2267//----------------------------------------------------------------------
2268
2269class CommandObjectTargetModulesDump : public CommandObjectMultiword
2270{
2271public:
2272
2273 //------------------------------------------------------------------
2274 // Constructors and Destructors
2275 //------------------------------------------------------------------
2276 CommandObjectTargetModulesDump(CommandInterpreter &interpreter) :
2277 CommandObjectMultiword (interpreter,
2278 "target modules dump",
2279 "A set of commands for dumping information about one or more target modules.",
2280 "target modules dump [symtab|sections|symfile|line-table] [<file1> <file2> ...]")
2281 {
2282 LoadSubCommand ("symtab", CommandObjectSP (new CommandObjectTargetModulesDumpSymtab (interpreter)));
2283 LoadSubCommand ("sections", CommandObjectSP (new CommandObjectTargetModulesDumpSections (interpreter)));
2284 LoadSubCommand ("symfile", CommandObjectSP (new CommandObjectTargetModulesDumpSymfile (interpreter)));
2285 LoadSubCommand ("line-table", CommandObjectSP (new CommandObjectTargetModulesDumpLineTable (interpreter)));
2286 }
2287
2288 virtual
2289 ~CommandObjectTargetModulesDump()
2290 {
2291 }
2292};
2293
2294class CommandObjectTargetModulesAdd : public CommandObject
2295{
2296public:
2297 CommandObjectTargetModulesAdd (CommandInterpreter &interpreter) :
2298 CommandObject (interpreter,
2299 "target modules add",
2300 "Add a new module to the current target's modules.",
2301 "target modules add [<module>]")
2302 {
2303 }
2304
2305 virtual
2306 ~CommandObjectTargetModulesAdd ()
2307 {
2308 }
2309
2310 virtual bool
2311 Execute (Args& args,
2312 CommandReturnObject &result)
2313 {
2314 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
2315 if (target == NULL)
2316 {
2317 result.AppendError ("invalid target, create a debug target using the 'target create' command");
2318 result.SetStatus (eReturnStatusFailed);
2319 return false;
2320 }
2321 else
2322 {
2323 const size_t argc = args.GetArgumentCount();
2324 if (argc == 0)
2325 {
2326 result.AppendError ("one or more executable image paths must be specified");
2327 result.SetStatus (eReturnStatusFailed);
2328 return false;
2329 }
2330 else
2331 {
2332 for (size_t i=0; i<argc; ++i)
2333 {
2334 const char *path = args.GetArgumentAtIndex(i);
2335 if (path)
2336 {
2337 FileSpec file_spec(path, true);
2338 ArchSpec arch;
2339 if (file_spec.Exists())
2340 {
2341 ModuleSP module_sp (target->GetSharedModule(file_spec, arch));
2342 if (!module_sp)
2343 {
2344 result.AppendError ("one or more executable image paths must be specified");
2345 result.SetStatus (eReturnStatusFailed);
2346 return false;
2347 }
Jason Molenda36f6fb92011-08-02 23:28:55 +00002348 result.SetStatus (eReturnStatusSuccessFinishResult);
Greg Claytone1f50b92011-05-03 22:09:39 +00002349 }
2350 else
2351 {
2352 char resolved_path[PATH_MAX];
2353 result.SetStatus (eReturnStatusFailed);
2354 if (file_spec.GetPath (resolved_path, sizeof(resolved_path)))
2355 {
2356 if (strcmp (resolved_path, path) != 0)
2357 {
2358 result.AppendErrorWithFormat ("invalid module path '%s' with resolved path '%s'\n", path, resolved_path);
2359 break;
2360 }
2361 }
2362 result.AppendErrorWithFormat ("invalid module path '%s'\n", path);
2363 break;
2364 }
2365 }
2366 }
2367 }
2368 }
2369 return result.Succeeded();
2370 }
2371
2372 int
2373 HandleArgumentCompletion (Args &input,
2374 int &cursor_index,
2375 int &cursor_char_position,
2376 OptionElementVector &opt_element_vector,
2377 int match_start_point,
2378 int max_return_elements,
2379 bool &word_complete,
2380 StringList &matches)
2381 {
2382 std::string completion_str (input.GetArgumentAtIndex(cursor_index));
2383 completion_str.erase (cursor_char_position);
2384
2385 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
2386 CommandCompletions::eDiskFileCompletion,
2387 completion_str.c_str(),
2388 match_start_point,
2389 max_return_elements,
2390 NULL,
2391 word_complete,
2392 matches);
2393 return matches.GetSize();
2394 }
2395
2396};
2397
2398class CommandObjectTargetModulesLoad : public CommandObjectTargetModulesModuleAutoComplete
2399{
2400public:
2401 CommandObjectTargetModulesLoad (CommandInterpreter &interpreter) :
2402 CommandObjectTargetModulesModuleAutoComplete (interpreter,
2403 "target modules load",
2404 "Set the load addresses for one or more sections in a target module.",
2405 "target modules load [--file <module> --uuid <uuid>] <sect-name> <address> [<sect-name> <address> ....]"),
2406 m_option_group (interpreter),
2407 m_file_option (LLDB_OPT_SET_1, false, "file", 'f', 0, eArgTypePath, "Fullpath or basename for module to load."),
2408 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)
2409 {
2410 m_option_group.Append (&m_uuid_option_group, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
2411 m_option_group.Append (&m_file_option, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
2412 m_option_group.Append (&m_slide_option, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
2413 m_option_group.Finalize();
2414 }
2415
2416 virtual
2417 ~CommandObjectTargetModulesLoad ()
2418 {
2419 }
2420
2421 virtual bool
2422 Execute (Args& args,
2423 CommandReturnObject &result)
2424 {
2425 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
2426 if (target == NULL)
2427 {
2428 result.AppendError ("invalid target, create a debug target using the 'target create' command");
2429 result.SetStatus (eReturnStatusFailed);
2430 return false;
2431 }
2432 else
2433 {
2434 const size_t argc = args.GetArgumentCount();
2435 const FileSpec *file_ptr = NULL;
2436 const UUID *uuid_ptr = NULL;
2437 if (m_file_option.GetOptionValue().OptionWasSet())
2438 file_ptr = &m_file_option.GetOptionValue().GetCurrentValue();
2439
2440 if (m_uuid_option_group.GetOptionValue().OptionWasSet())
2441 uuid_ptr = &m_uuid_option_group.GetOptionValue().GetCurrentValue();
2442
2443 if (file_ptr || uuid_ptr)
2444 {
2445
2446 ModuleList matching_modules;
2447 const size_t num_matches = target->GetImages().FindModules (file_ptr, // File spec to match (can be NULL to match by UUID only)
2448 NULL, // Architecture
2449 uuid_ptr, // UUID to match (can be NULL to not match on UUID)
2450 NULL, // Object name
2451 matching_modules);
2452
2453 char path[PATH_MAX];
2454 if (num_matches == 1)
2455 {
2456 Module *module = matching_modules.GetModulePointerAtIndex(0);
2457 if (module)
2458 {
2459 ObjectFile *objfile = module->GetObjectFile();
2460 if (objfile)
2461 {
2462 SectionList *section_list = objfile->GetSectionList();
2463 if (section_list)
2464 {
2465 if (argc == 0)
2466 {
2467 if (m_slide_option.GetOptionValue().OptionWasSet())
2468 {
2469 Module *module = matching_modules.GetModulePointerAtIndex(0);
2470 if (module)
2471 {
2472 ObjectFile *objfile = module->GetObjectFile();
2473 if (objfile)
2474 {
2475 SectionList *section_list = objfile->GetSectionList();
2476 if (section_list)
2477 {
2478 const size_t num_sections = section_list->GetSize();
2479 const addr_t slide = m_slide_option.GetOptionValue().GetCurrentValue();
2480 for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx)
2481 {
2482 SectionSP section_sp (section_list->GetSectionAtIndex(sect_idx));
2483 if (section_sp)
2484 target->GetSectionLoadList().SetSectionLoadAddress (section_sp.get(), section_sp->GetFileAddress() + slide);
2485 }
2486 }
2487 }
2488 }
2489 }
2490 else
2491 {
2492 result.AppendError ("one or more section name + load address pair must be specified");
2493 result.SetStatus (eReturnStatusFailed);
2494 return false;
2495 }
2496 }
2497 else
2498 {
2499 if (m_slide_option.GetOptionValue().OptionWasSet())
2500 {
2501 result.AppendError ("The \"--slide <offset>\" option can't be used in conjunction with setting section load addresses.\n");
2502 result.SetStatus (eReturnStatusFailed);
2503 return false;
2504 }
2505
2506 for (size_t i=0; i<argc; i += 2)
2507 {
2508 const char *sect_name = args.GetArgumentAtIndex(i);
2509 const char *load_addr_cstr = args.GetArgumentAtIndex(i+1);
2510 if (sect_name && load_addr_cstr)
2511 {
2512 ConstString const_sect_name(sect_name);
2513 bool success = false;
2514 addr_t load_addr = Args::StringToUInt64(load_addr_cstr, LLDB_INVALID_ADDRESS, 0, &success);
2515 if (success)
2516 {
2517 SectionSP section_sp (section_list->FindSectionByName(const_sect_name));
2518 if (section_sp)
2519 {
2520 target->GetSectionLoadList().SetSectionLoadAddress (section_sp.get(), load_addr);
2521 result.AppendMessageWithFormat("section '%s' loaded at 0x%llx\n", sect_name, load_addr);
2522 }
2523 else
2524 {
2525 result.AppendErrorWithFormat ("no section found that matches the section name '%s'\n", sect_name);
2526 result.SetStatus (eReturnStatusFailed);
2527 break;
2528 }
2529 }
2530 else
2531 {
2532 result.AppendErrorWithFormat ("invalid load address string '%s'\n", load_addr_cstr);
2533 result.SetStatus (eReturnStatusFailed);
2534 break;
2535 }
2536 }
2537 else
2538 {
2539 if (sect_name)
2540 result.AppendError ("section names must be followed by a load address.\n");
2541 else
2542 result.AppendError ("one or more section name + load address pair must be specified.\n");
2543 result.SetStatus (eReturnStatusFailed);
2544 break;
2545 }
2546 }
2547 }
2548 }
2549 else
2550 {
2551 module->GetFileSpec().GetPath (path, sizeof(path));
2552 result.AppendErrorWithFormat ("no sections in object file '%s'\n", path);
2553 result.SetStatus (eReturnStatusFailed);
2554 }
2555 }
2556 else
2557 {
2558 module->GetFileSpec().GetPath (path, sizeof(path));
2559 result.AppendErrorWithFormat ("no object file for module '%s'\n", path);
2560 result.SetStatus (eReturnStatusFailed);
2561 }
2562 }
2563 else
2564 {
2565 module->GetFileSpec().GetPath (path, sizeof(path));
2566 result.AppendErrorWithFormat ("invalid module '%s'.\n", path);
2567 result.SetStatus (eReturnStatusFailed);
2568 }
2569 }
2570 else
2571 {
2572 char uuid_cstr[64];
2573 if (file_ptr)
2574 file_ptr->GetPath (path, sizeof(path));
2575 else
2576 path[0] = '\0';
2577
2578 if (uuid_ptr)
2579 uuid_ptr->GetAsCString(uuid_cstr, sizeof(uuid_cstr));
2580 else
2581 uuid_cstr[0] = '\0';
2582 if (num_matches > 1)
2583 {
2584 result.AppendErrorWithFormat ("multiple modules match%s%s%s%s:\n",
2585 path[0] ? " file=" : "",
2586 path,
2587 uuid_cstr[0] ? " uuid=" : "",
2588 uuid_cstr);
2589 for (size_t i=0; i<num_matches; ++i)
2590 {
2591 if (matching_modules.GetModulePointerAtIndex(i)->GetFileSpec().GetPath (path, sizeof(path)))
2592 result.AppendMessageWithFormat("%s\n", path);
2593 }
2594 }
2595 else
2596 {
2597 result.AppendErrorWithFormat ("no modules were found that match%s%s%s%s.\n",
2598 path[0] ? " file=" : "",
2599 path,
2600 uuid_cstr[0] ? " uuid=" : "",
2601 uuid_cstr);
2602 }
2603 result.SetStatus (eReturnStatusFailed);
2604 }
2605 }
2606 else
2607 {
2608 result.AppendError ("either the \"--file <module>\" or the \"--uuid <uuid>\" option must be specified.\n");
2609 result.SetStatus (eReturnStatusFailed);
2610 return false;
2611 }
2612 }
2613 return result.Succeeded();
2614 }
2615
2616 virtual Options *
2617 GetOptions ()
2618 {
2619 return &m_option_group;
2620 }
2621
2622protected:
2623 OptionGroupOptions m_option_group;
2624 OptionGroupUUID m_uuid_option_group;
2625 OptionGroupFile m_file_option;
2626 OptionGroupUInt64 m_slide_option;
2627};
2628
2629//----------------------------------------------------------------------
2630// List images with associated information
2631//----------------------------------------------------------------------
2632class CommandObjectTargetModulesList : public CommandObject
2633{
2634public:
2635
2636 class CommandOptions : public Options
2637 {
2638 public:
2639
2640 CommandOptions (CommandInterpreter &interpreter) :
Greg Clayton899025f2011-08-09 00:01:09 +00002641 Options(interpreter),
Jim Ingham6bdea822011-10-24 18:36:33 +00002642 m_format_array(),
Daniel Dunbar97c89572011-10-31 22:50:49 +00002643 m_use_global_module_list (false),
Jim Ingham6bdea822011-10-24 18:36:33 +00002644 m_module_addr (LLDB_INVALID_ADDRESS)
Greg Claytone1f50b92011-05-03 22:09:39 +00002645 {
2646 }
2647
2648 virtual
2649 ~CommandOptions ()
2650 {
2651 }
2652
2653 virtual Error
2654 SetOptionValue (uint32_t option_idx, const char *option_arg)
2655 {
2656 char short_option = (char) m_getopt_table[option_idx].val;
Greg Clayton899025f2011-08-09 00:01:09 +00002657 if (short_option == 'g')
2658 {
2659 m_use_global_module_list = true;
2660 }
Jim Ingham6bdea822011-10-24 18:36:33 +00002661 else if (short_option == 'a')
2662 {
2663 bool success;
2664 m_module_addr = Args::StringToAddress(option_arg, LLDB_INVALID_ADDRESS, &success);
2665 if (!success)
2666 {
2667 Error error;
Greg Clayton9c236732011-10-26 00:56:27 +00002668 error.SetErrorStringWithFormat("invalid address: \"%s\"", option_arg);
Jim Ingham6bdea822011-10-24 18:36:33 +00002669 }
2670 }
Greg Clayton899025f2011-08-09 00:01:09 +00002671 else
2672 {
2673 uint32_t width = 0;
2674 if (option_arg)
2675 width = strtoul (option_arg, NULL, 0);
2676 m_format_array.push_back(std::make_pair(short_option, width));
2677 }
Greg Claytone1f50b92011-05-03 22:09:39 +00002678 Error error;
2679 return error;
2680 }
2681
2682 void
2683 OptionParsingStarting ()
2684 {
2685 m_format_array.clear();
Greg Clayton899025f2011-08-09 00:01:09 +00002686 m_use_global_module_list = false;
Jim Ingham6bdea822011-10-24 18:36:33 +00002687 m_module_addr = LLDB_INVALID_ADDRESS;
Greg Claytone1f50b92011-05-03 22:09:39 +00002688 }
2689
2690 const OptionDefinition*
2691 GetDefinitions ()
2692 {
2693 return g_option_table;
2694 }
2695
2696 // Options table: Required for subclasses of Options.
2697
2698 static OptionDefinition g_option_table[];
2699
2700 // Instance variables to hold the values for command options.
2701 typedef std::vector< std::pair<char, uint32_t> > FormatWidthCollection;
2702 FormatWidthCollection m_format_array;
Greg Clayton899025f2011-08-09 00:01:09 +00002703 bool m_use_global_module_list;
Jim Ingham6bdea822011-10-24 18:36:33 +00002704 lldb::addr_t m_module_addr;
Greg Claytone1f50b92011-05-03 22:09:39 +00002705 };
2706
2707 CommandObjectTargetModulesList (CommandInterpreter &interpreter) :
2708 CommandObject (interpreter,
2709 "target modules list",
2710 "List current executable and dependent shared library images.",
2711 "target modules list [<cmd-options>]"),
2712 m_options (interpreter)
2713 {
2714 }
2715
2716 virtual
2717 ~CommandObjectTargetModulesList ()
2718 {
2719 }
2720
2721 virtual
2722 Options *
2723 GetOptions ()
2724 {
2725 return &m_options;
2726 }
2727
2728 virtual bool
2729 Execute (Args& command,
2730 CommandReturnObject &result)
2731 {
2732 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Greg Clayton153ccd72011-08-10 02:10:13 +00002733 const bool use_global_module_list = m_options.m_use_global_module_list;
2734 if (target == NULL && use_global_module_list == false)
Greg Claytone1f50b92011-05-03 22:09:39 +00002735 {
2736 result.AppendError ("invalid target, create a debug target using the 'target create' command");
2737 result.SetStatus (eReturnStatusFailed);
2738 return false;
2739 }
2740 else
2741 {
Greg Clayton153ccd72011-08-10 02:10:13 +00002742 if (target)
2743 {
2744 uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize();
2745 result.GetOutputStream().SetAddressByteSize(addr_byte_size);
2746 result.GetErrorStream().SetAddressByteSize(addr_byte_size);
2747 }
Greg Claytone1f50b92011-05-03 22:09:39 +00002748 // Dump all sections for all modules images
Greg Clayton899025f2011-08-09 00:01:09 +00002749 uint32_t num_modules = 0;
2750 Mutex::Locker locker;
Jim Ingham6bdea822011-10-24 18:36:33 +00002751
2752 Stream &strm = result.GetOutputStream();
2753
2754 if (m_options.m_module_addr != LLDB_INVALID_ADDRESS)
2755 {
2756 if (target)
2757 {
2758 Address module_address;
2759 if (module_address.SetLoadAddress(m_options.m_module_addr, target))
2760 {
2761 Module *module = module_address.GetModule();
2762 if (module)
2763 {
2764 PrintModule (strm, module);
2765 result.SetStatus (eReturnStatusSuccessFinishResult);
2766 }
2767 else
2768 {
2769 result.AppendError ("Couldn't find module matching address: 0x%llx.", m_options.m_module_addr);
2770 result.SetStatus (eReturnStatusFailed);
2771 }
2772 }
2773 else
2774 {
2775 result.AppendError ("Couldn't find module containing address: 0x%llx.", m_options.m_module_addr);
2776 result.SetStatus (eReturnStatusFailed);
2777 }
2778 }
2779 else
2780 {
2781 result.AppendError ("Can only look up modules by address with a valid target.");
2782 result.SetStatus (eReturnStatusFailed);
2783 }
2784 return result.Succeeded();
2785 }
2786
Greg Clayton153ccd72011-08-10 02:10:13 +00002787 if (use_global_module_list)
Greg Clayton899025f2011-08-09 00:01:09 +00002788 {
2789 locker.Reset (Module::GetAllocationModuleCollectionMutex().GetMutex());
2790 num_modules = Module::GetNumberAllocatedModules();
2791 }
2792 else
2793 num_modules = target->GetImages().GetSize();
2794
Greg Claytone1f50b92011-05-03 22:09:39 +00002795 if (num_modules > 0)
Jim Ingham6bdea822011-10-24 18:36:33 +00002796 {
Greg Claytone1f50b92011-05-03 22:09:39 +00002797 for (uint32_t image_idx = 0; image_idx<num_modules; ++image_idx)
2798 {
Greg Clayton153ccd72011-08-10 02:10:13 +00002799 ModuleSP module_sp;
Greg Clayton899025f2011-08-09 00:01:09 +00002800 Module *module;
Greg Clayton153ccd72011-08-10 02:10:13 +00002801 if (use_global_module_list)
Greg Clayton899025f2011-08-09 00:01:09 +00002802 {
2803 module = Module::GetAllocatedModuleAtIndex(image_idx);
Greg Clayton02e210c2011-09-17 07:23:18 +00002804 module_sp = module;
Greg Clayton899025f2011-08-09 00:01:09 +00002805 }
2806 else
2807 {
Greg Clayton153ccd72011-08-10 02:10:13 +00002808 module_sp = target->GetImages().GetModuleAtIndex(image_idx);
2809 module = module_sp.get();
Greg Clayton899025f2011-08-09 00:01:09 +00002810 }
Jim Ingham6bdea822011-10-24 18:36:33 +00002811
Greg Clayton153ccd72011-08-10 02:10:13 +00002812 strm.Printf("[%3u] ", image_idx);
Jim Ingham6bdea822011-10-24 18:36:33 +00002813 PrintModule (strm, module);
Greg Clayton153ccd72011-08-10 02:10:13 +00002814
Greg Claytone1f50b92011-05-03 22:09:39 +00002815 }
2816 result.SetStatus (eReturnStatusSuccessFinishResult);
2817 }
2818 else
2819 {
Greg Clayton153ccd72011-08-10 02:10:13 +00002820 if (use_global_module_list)
2821 result.AppendError ("the global module list is empty");
2822 else
2823 result.AppendError ("the target has no associated executable images");
Greg Claytone1f50b92011-05-03 22:09:39 +00002824 result.SetStatus (eReturnStatusFailed);
2825 return false;
2826 }
2827 }
2828 return result.Succeeded();
2829 }
2830protected:
Jim Ingham6bdea822011-10-24 18:36:33 +00002831
2832 void
2833 PrintModule (Stream &strm, Module *module)
2834 {
2835
2836 bool dump_object_name = false;
2837 if (m_options.m_format_array.empty())
2838 {
2839 DumpFullpath(strm, &module->GetFileSpec(), 0);
2840 dump_object_name = true;
2841 }
2842 else
2843 {
2844 const size_t num_entries = m_options.m_format_array.size();
2845 for (size_t i=0; i<num_entries; ++i)
2846 {
2847 if (i > 0)
2848 strm.PutChar(' ');
2849 char format_char = m_options.m_format_array[i].first;
2850 uint32_t width = m_options.m_format_array[i].second;
2851 switch (format_char)
2852 {
2853 case 'A':
2854 DumpModuleArchitecture (strm, module, false, width);
2855 break;
2856
2857 case 't':
2858 DumpModuleArchitecture (strm, module, true, width);
2859 break;
2860
2861 case 'f':
2862 DumpFullpath (strm, &module->GetFileSpec(), width);
2863 dump_object_name = true;
2864 break;
2865
2866 case 'd':
2867 DumpDirectory (strm, &module->GetFileSpec(), width);
2868 break;
2869
2870 case 'b':
2871 DumpBasename (strm, &module->GetFileSpec(), width);
2872 dump_object_name = true;
2873 break;
2874
2875 case 'r':
2876 {
2877 uint32_t ref_count = 0;
2878 ModuleSP module_sp (module);
2879 if (module_sp)
2880 {
2881 // Take one away to make sure we don't count our local "module_sp"
2882 ref_count = module_sp.use_count() - 1;
2883 }
2884 if (width)
2885 strm.Printf("{%*u}", width, ref_count);
2886 else
2887 strm.Printf("{%u}", ref_count);
2888 }
2889 break;
2890
2891 case 's':
2892 case 'S':
2893 {
2894 SymbolVendor *symbol_vendor = module->GetSymbolVendor();
2895 if (symbol_vendor)
2896 {
2897 SymbolFile *symbol_file = symbol_vendor->GetSymbolFile();
2898 if (symbol_file)
2899 {
2900 if (format_char == 'S')
2901 DumpBasename(strm, &symbol_file->GetObjectFile()->GetFileSpec(), width);
2902 else
2903 DumpFullpath (strm, &symbol_file->GetObjectFile()->GetFileSpec(), width);
2904 dump_object_name = true;
2905 break;
2906 }
2907 }
2908 strm.Printf("%.*s", width, "<NONE>");
2909 }
2910 break;
2911
2912 case 'm':
2913 module->GetModificationTime().Dump(&strm, width);
2914 break;
2915
2916 case 'p':
2917 strm.Printf("%p", module);
2918 break;
2919
2920 case 'u':
2921 DumpModuleUUID(strm, module);
2922 break;
2923
2924 default:
2925 break;
2926 }
2927
2928 }
2929 if (dump_object_name)
2930 {
2931 const char *object_name = module->GetObjectName().GetCString();
2932 if (object_name)
2933 strm.Printf ("(%s)", object_name);
2934 }
2935 }
2936 strm.EOL();
2937 }
2938
Greg Claytone1f50b92011-05-03 22:09:39 +00002939 CommandOptions m_options;
2940};
2941
2942OptionDefinition
2943CommandObjectTargetModulesList::CommandOptions::g_option_table[] =
2944{
Jim Ingham6bdea822011-10-24 18:36:33 +00002945 { LLDB_OPT_SET_1, false, "address", 'a', required_argument, NULL, 0, eArgTypeAddress, "Display the image at this address."},
2946 { LLDB_OPT_SET_1, false, "arch", 'A', optional_argument, NULL, 0, eArgTypeWidth, "Display the architecture when listing images."},
Greg Claytone1f50b92011-05-03 22:09:39 +00002947 { LLDB_OPT_SET_1, false, "triple", 't', optional_argument, NULL, 0, eArgTypeWidth, "Display the triple when listing images."},
2948 { LLDB_OPT_SET_1, false, "uuid", 'u', no_argument, NULL, 0, eArgTypeNone, "Display the UUID when listing images."},
2949 { LLDB_OPT_SET_1, false, "fullpath", 'f', optional_argument, NULL, 0, eArgTypeWidth, "Display the fullpath to the image object file."},
2950 { LLDB_OPT_SET_1, false, "directory", 'd', optional_argument, NULL, 0, eArgTypeWidth, "Display the directory with optional width for the image object file."},
2951 { LLDB_OPT_SET_1, false, "basename", 'b', optional_argument, NULL, 0, eArgTypeWidth, "Display the basename with optional width for the image object file."},
2952 { LLDB_OPT_SET_1, false, "symfile", 's', optional_argument, NULL, 0, eArgTypeWidth, "Display the fullpath to the image symbol file with optional width."},
2953 { LLDB_OPT_SET_1, false, "symfile-basename", 'S', optional_argument, NULL, 0, eArgTypeWidth, "Display the basename to the image symbol file with optional width."},
Greg Clayton153ccd72011-08-10 02:10:13 +00002954 { LLDB_OPT_SET_1, false, "mod-time", 'm', optional_argument, NULL, 0, eArgTypeWidth, "Display the modification time with optional width of the module."},
2955 { 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."},
2956 { LLDB_OPT_SET_1, false, "pointer", 'p', optional_argument, NULL, 0, eArgTypeNone, "Display the module pointer."},
Greg Clayton899025f2011-08-09 00:01:09 +00002957 { 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."},
Greg Claytone1f50b92011-05-03 22:09:39 +00002958 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
2959};
2960
2961
2962
2963//----------------------------------------------------------------------
2964// Lookup information in images
2965//----------------------------------------------------------------------
2966class CommandObjectTargetModulesLookup : public CommandObject
2967{
2968public:
2969
2970 enum
2971 {
2972 eLookupTypeInvalid = -1,
2973 eLookupTypeAddress = 0,
2974 eLookupTypeSymbol,
2975 eLookupTypeFileLine, // Line is optional
2976 eLookupTypeFunction,
2977 eLookupTypeType,
2978 kNumLookupTypes
2979 };
2980
2981 class CommandOptions : public Options
2982 {
2983 public:
2984
2985 CommandOptions (CommandInterpreter &interpreter) :
2986 Options(interpreter)
2987 {
2988 OptionParsingStarting();
2989 }
2990
2991 virtual
2992 ~CommandOptions ()
2993 {
2994 }
2995
2996 virtual Error
2997 SetOptionValue (uint32_t option_idx, const char *option_arg)
2998 {
2999 Error error;
3000
3001 char short_option = (char) m_getopt_table[option_idx].val;
3002
3003 switch (short_option)
3004 {
3005 case 'a':
3006 m_type = eLookupTypeAddress;
3007 m_addr = Args::StringToUInt64(option_arg, LLDB_INVALID_ADDRESS);
3008 if (m_addr == LLDB_INVALID_ADDRESS)
Greg Clayton9c236732011-10-26 00:56:27 +00003009 error.SetErrorStringWithFormat ("invalid address string '%s'", option_arg);
Greg Claytone1f50b92011-05-03 22:09:39 +00003010 break;
3011
3012 case 'o':
3013 m_offset = Args::StringToUInt64(option_arg, LLDB_INVALID_ADDRESS);
3014 if (m_offset == LLDB_INVALID_ADDRESS)
Greg Clayton9c236732011-10-26 00:56:27 +00003015 error.SetErrorStringWithFormat ("invalid offset string '%s'", option_arg);
Greg Claytone1f50b92011-05-03 22:09:39 +00003016 break;
3017
3018 case 's':
3019 m_str = option_arg;
3020 m_type = eLookupTypeSymbol;
3021 break;
3022
3023 case 'f':
3024 m_file.SetFile (option_arg, false);
3025 m_type = eLookupTypeFileLine;
3026 break;
3027
3028 case 'i':
3029 m_check_inlines = false;
3030 break;
3031
3032 case 'l':
3033 m_line_number = Args::StringToUInt32(option_arg, UINT32_MAX);
3034 if (m_line_number == UINT32_MAX)
Greg Clayton9c236732011-10-26 00:56:27 +00003035 error.SetErrorStringWithFormat ("invalid line number string '%s'", option_arg);
Greg Claytone1f50b92011-05-03 22:09:39 +00003036 else if (m_line_number == 0)
Greg Clayton9c236732011-10-26 00:56:27 +00003037 error.SetErrorString ("zero is an invalid line number");
Greg Claytone1f50b92011-05-03 22:09:39 +00003038 m_type = eLookupTypeFileLine;
3039 break;
3040
3041 case 'n':
3042 m_str = option_arg;
3043 m_type = eLookupTypeFunction;
3044 break;
3045
3046 case 't':
3047 m_str = option_arg;
3048 m_type = eLookupTypeType;
3049 break;
3050
3051 case 'v':
3052 m_verbose = 1;
3053 break;
3054
3055 case 'r':
3056 m_use_regex = true;
3057 break;
3058 }
3059
3060 return error;
3061 }
3062
3063 void
3064 OptionParsingStarting ()
3065 {
3066 m_type = eLookupTypeInvalid;
3067 m_str.clear();
3068 m_file.Clear();
3069 m_addr = LLDB_INVALID_ADDRESS;
3070 m_offset = 0;
3071 m_line_number = 0;
3072 m_use_regex = false;
3073 m_check_inlines = true;
3074 m_verbose = false;
3075 }
3076
3077 const OptionDefinition*
3078 GetDefinitions ()
3079 {
3080 return g_option_table;
3081 }
3082
3083 // Options table: Required for subclasses of Options.
3084
3085 static OptionDefinition g_option_table[];
3086 int m_type; // Should be a eLookupTypeXXX enum after parsing options
3087 std::string m_str; // Holds name lookup
3088 FileSpec m_file; // Files for file lookups
3089 lldb::addr_t m_addr; // Holds the address to lookup
3090 lldb::addr_t m_offset; // Subtract this offset from m_addr before doing lookups.
3091 uint32_t m_line_number; // Line number for file+line lookups
3092 bool m_use_regex; // Name lookups in m_str are regular expressions.
3093 bool m_check_inlines;// Check for inline entries when looking up by file/line.
3094 bool m_verbose; // Enable verbose lookup info
3095
3096 };
3097
3098 CommandObjectTargetModulesLookup (CommandInterpreter &interpreter) :
3099 CommandObject (interpreter,
3100 "target modules lookup",
3101 "Look up information within executable and dependent shared library images.",
3102 NULL),
3103 m_options (interpreter)
3104 {
3105 CommandArgumentEntry arg;
3106 CommandArgumentData file_arg;
3107
3108 // Define the first (and only) variant of this arg.
3109 file_arg.arg_type = eArgTypeFilename;
3110 file_arg.arg_repetition = eArgRepeatStar;
3111
3112 // There is only one variant this argument could be; put it into the argument entry.
3113 arg.push_back (file_arg);
3114
3115 // Push the data for the first argument into the m_arguments vector.
3116 m_arguments.push_back (arg);
3117 }
3118
3119 virtual
3120 ~CommandObjectTargetModulesLookup ()
3121 {
3122 }
3123
3124 virtual Options *
3125 GetOptions ()
3126 {
3127 return &m_options;
3128 }
3129
3130
3131 bool
3132 LookupInModule (CommandInterpreter &interpreter, Module *module, CommandReturnObject &result, bool &syntax_error)
3133 {
3134 switch (m_options.m_type)
3135 {
3136 case eLookupTypeAddress:
3137 if (m_options.m_addr != LLDB_INVALID_ADDRESS)
3138 {
3139 if (LookupAddressInModule (m_interpreter,
3140 result.GetOutputStream(),
3141 module,
3142 eSymbolContextEverything,
3143 m_options.m_addr,
3144 m_options.m_offset,
3145 m_options.m_verbose))
3146 {
3147 result.SetStatus(eReturnStatusSuccessFinishResult);
3148 return true;
3149 }
3150 }
3151 break;
3152
3153 case eLookupTypeSymbol:
3154 if (!m_options.m_str.empty())
3155 {
3156 if (LookupSymbolInModule (m_interpreter, result.GetOutputStream(), module, m_options.m_str.c_str(), m_options.m_use_regex))
3157 {
3158 result.SetStatus(eReturnStatusSuccessFinishResult);
3159 return true;
3160 }
3161 }
3162 break;
3163
3164 case eLookupTypeFileLine:
3165 if (m_options.m_file)
3166 {
3167
3168 if (LookupFileAndLineInModule (m_interpreter,
3169 result.GetOutputStream(),
3170 module,
3171 m_options.m_file,
3172 m_options.m_line_number,
3173 m_options.m_check_inlines,
3174 m_options.m_verbose))
3175 {
3176 result.SetStatus(eReturnStatusSuccessFinishResult);
3177 return true;
3178 }
3179 }
3180 break;
3181
3182 case eLookupTypeFunction:
3183 if (!m_options.m_str.empty())
3184 {
3185 if (LookupFunctionInModule (m_interpreter,
3186 result.GetOutputStream(),
3187 module,
3188 m_options.m_str.c_str(),
3189 m_options.m_use_regex,
3190 m_options.m_verbose))
3191 {
3192 result.SetStatus(eReturnStatusSuccessFinishResult);
3193 return true;
3194 }
3195 }
3196 break;
3197
3198 case eLookupTypeType:
3199 if (!m_options.m_str.empty())
3200 {
3201 if (LookupTypeInModule (m_interpreter,
3202 result.GetOutputStream(),
3203 module,
3204 m_options.m_str.c_str(),
3205 m_options.m_use_regex))
3206 {
3207 result.SetStatus(eReturnStatusSuccessFinishResult);
3208 return true;
3209 }
3210 }
3211 break;
3212
3213 default:
3214 m_options.GenerateOptionUsage (result.GetErrorStream(), this);
3215 syntax_error = true;
3216 break;
3217 }
3218
3219 result.SetStatus (eReturnStatusFailed);
3220 return false;
3221 }
3222
3223 virtual bool
3224 Execute (Args& command,
3225 CommandReturnObject &result)
3226 {
3227 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
3228 if (target == NULL)
3229 {
3230 result.AppendError ("invalid target, create a debug target using the 'target create' command");
3231 result.SetStatus (eReturnStatusFailed);
3232 return false;
3233 }
3234 else
3235 {
3236 bool syntax_error = false;
3237 uint32_t i;
3238 uint32_t num_successful_lookups = 0;
3239 uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize();
3240 result.GetOutputStream().SetAddressByteSize(addr_byte_size);
3241 result.GetErrorStream().SetAddressByteSize(addr_byte_size);
3242 // Dump all sections for all modules images
3243
3244 if (command.GetArgumentCount() == 0)
3245 {
3246 // Dump all sections for all modules images
3247 const uint32_t num_modules = target->GetImages().GetSize();
3248 if (num_modules > 0)
3249 {
3250 for (i = 0; i<num_modules && syntax_error == false; ++i)
3251 {
3252 if (LookupInModule (m_interpreter, target->GetImages().GetModulePointerAtIndex(i), result, syntax_error))
3253 {
3254 result.GetOutputStream().EOL();
3255 num_successful_lookups++;
3256 }
3257 }
3258 }
3259 else
3260 {
3261 result.AppendError ("the target has no associated executable images");
3262 result.SetStatus (eReturnStatusFailed);
3263 return false;
3264 }
3265 }
3266 else
3267 {
3268 // Dump specified images (by basename or fullpath)
3269 const char *arg_cstr;
3270 for (i = 0; (arg_cstr = command.GetArgumentAtIndex(i)) != NULL && syntax_error == false; ++i)
3271 {
Greg Clayton91048ef2011-11-10 01:18:58 +00003272 ModuleList module_list;
3273 const size_t num_matches = FindModulesByName (target, arg_cstr, module_list, false);
3274 if (num_matches > 0)
Greg Claytone1f50b92011-05-03 22:09:39 +00003275 {
Greg Clayton91048ef2011-11-10 01:18:58 +00003276 for (size_t i=0; i<num_matches; ++i)
Greg Claytone1f50b92011-05-03 22:09:39 +00003277 {
Greg Clayton91048ef2011-11-10 01:18:58 +00003278 Module *module = module_list.GetModulePointerAtIndex(i);
3279 if (module)
Greg Claytone1f50b92011-05-03 22:09:39 +00003280 {
Greg Clayton91048ef2011-11-10 01:18:58 +00003281 if (LookupInModule (m_interpreter, module, result, syntax_error))
Greg Claytone1f50b92011-05-03 22:09:39 +00003282 {
3283 result.GetOutputStream().EOL();
3284 num_successful_lookups++;
3285 }
3286 }
3287 }
3288 }
3289 else
3290 result.AppendWarningWithFormat("Unable to find an image that matches '%s'.\n", arg_cstr);
3291 }
3292 }
3293
3294 if (num_successful_lookups > 0)
3295 result.SetStatus (eReturnStatusSuccessFinishResult);
3296 else
3297 result.SetStatus (eReturnStatusFailed);
3298 }
3299 return result.Succeeded();
3300 }
3301protected:
3302
3303 CommandOptions m_options;
3304};
3305
3306OptionDefinition
3307CommandObjectTargetModulesLookup::CommandOptions::g_option_table[] =
3308{
3309 { LLDB_OPT_SET_1, true, "address", 'a', required_argument, NULL, 0, eArgTypeAddress, "Lookup an address in one or more target modules."},
3310 { 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."},
Jim Inghame7a91c12011-06-20 23:38:11 +00003311 { LLDB_OPT_SET_2| LLDB_OPT_SET_4
3312 /* FIXME: re-enable this for types when the LookupTypeInModule actually uses the regex option: | LLDB_OPT_SET_5 */ ,
3313 false, "regex", 'r', no_argument, NULL, 0, eArgTypeNone, "The <name> argument for name lookups are regular expressions."},
Greg Claytone1f50b92011-05-03 22:09:39 +00003314 { 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."},
Greg Claytone1f50b92011-05-03 22:09:39 +00003315 { 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."},
3316 { 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)."},
3317 { LLDB_OPT_SET_3, false, "no-inlines", 'i', no_argument, NULL, 0, eArgTypeNone, "Check inline line entries (must be used in conjunction with --file)."},
3318 { LLDB_OPT_SET_4, true, "function", 'n', required_argument, NULL, 0, eArgTypeFunctionName, "Lookup a function by name in the debug symbols in one or more target modules."},
3319 { LLDB_OPT_SET_5, true, "type", 't', required_argument, NULL, 0, eArgTypeName, "Lookup a type by name in the debug symbols in one or more target modules."},
3320 { LLDB_OPT_SET_ALL, false, "verbose", 'v', no_argument, NULL, 0, eArgTypeNone, "Enable verbose lookup information."},
3321 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
3322};
Chris Lattner24943d22010-06-08 16:52:24 +00003323
3324
Jim Inghamd60d94a2011-03-11 03:53:59 +00003325#pragma mark CommandObjectMultiwordImageSearchPaths
Chris Lattner24943d22010-06-08 16:52:24 +00003326
3327//-------------------------------------------------------------------------
3328// CommandObjectMultiwordImageSearchPaths
3329//-------------------------------------------------------------------------
3330
Greg Claytone1f50b92011-05-03 22:09:39 +00003331class CommandObjectTargetModulesImageSearchPaths : public CommandObjectMultiword
Chris Lattner24943d22010-06-08 16:52:24 +00003332{
3333public:
Greg Claytone1f50b92011-05-03 22:09:39 +00003334
3335 CommandObjectTargetModulesImageSearchPaths (CommandInterpreter &interpreter) :
3336 CommandObjectMultiword (interpreter,
3337 "target modules search-paths",
3338 "A set of commands for operating on debugger target image search paths.",
3339 "target modules search-paths <subcommand> [<subcommand-options>]")
Chris Lattner24943d22010-06-08 16:52:24 +00003340 {
Greg Claytone1f50b92011-05-03 22:09:39 +00003341 LoadSubCommand ("add", CommandObjectSP (new CommandObjectTargetModulesSearchPathsAdd (interpreter)));
3342 LoadSubCommand ("clear", CommandObjectSP (new CommandObjectTargetModulesSearchPathsClear (interpreter)));
3343 LoadSubCommand ("insert", CommandObjectSP (new CommandObjectTargetModulesSearchPathsInsert (interpreter)));
3344 LoadSubCommand ("list", CommandObjectSP (new CommandObjectTargetModulesSearchPathsList (interpreter)));
3345 LoadSubCommand ("query", CommandObjectSP (new CommandObjectTargetModulesSearchPathsQuery (interpreter)));
Chris Lattner24943d22010-06-08 16:52:24 +00003346 }
Greg Claytone1f50b92011-05-03 22:09:39 +00003347
3348 ~CommandObjectTargetModulesImageSearchPaths()
Chris Lattner24943d22010-06-08 16:52:24 +00003349 {
3350 }
3351};
3352
Greg Claytone1f50b92011-05-03 22:09:39 +00003353
3354
3355#pragma mark CommandObjectTargetModules
3356
3357//-------------------------------------------------------------------------
3358// CommandObjectTargetModules
3359//-------------------------------------------------------------------------
3360
3361class CommandObjectTargetModules : public CommandObjectMultiword
3362{
3363public:
3364 //------------------------------------------------------------------
3365 // Constructors and Destructors
3366 //------------------------------------------------------------------
3367 CommandObjectTargetModules(CommandInterpreter &interpreter) :
3368 CommandObjectMultiword (interpreter,
3369 "target modules",
3370 "A set of commands for accessing information for one or more target modules.",
3371 "target modules <sub-command> ...")
3372 {
3373 LoadSubCommand ("add", CommandObjectSP (new CommandObjectTargetModulesAdd (interpreter)));
3374 LoadSubCommand ("load", CommandObjectSP (new CommandObjectTargetModulesLoad (interpreter)));
3375 //LoadSubCommand ("unload", CommandObjectSP (new CommandObjectTargetModulesUnload (interpreter)));
3376 LoadSubCommand ("dump", CommandObjectSP (new CommandObjectTargetModulesDump (interpreter)));
3377 LoadSubCommand ("list", CommandObjectSP (new CommandObjectTargetModulesList (interpreter)));
3378 LoadSubCommand ("lookup", CommandObjectSP (new CommandObjectTargetModulesLookup (interpreter)));
3379 LoadSubCommand ("search-paths", CommandObjectSP (new CommandObjectTargetModulesImageSearchPaths (interpreter)));
3380
3381 }
3382 virtual
3383 ~CommandObjectTargetModules()
3384 {
3385 }
3386
3387private:
3388 //------------------------------------------------------------------
3389 // For CommandObjectTargetModules only
3390 //------------------------------------------------------------------
3391 DISALLOW_COPY_AND_ASSIGN (CommandObjectTargetModules);
3392};
3393
3394
Jim Inghamd60d94a2011-03-11 03:53:59 +00003395#pragma mark CommandObjectTargetStopHookAdd
3396
3397//-------------------------------------------------------------------------
3398// CommandObjectTargetStopHookAdd
3399//-------------------------------------------------------------------------
3400
3401class CommandObjectTargetStopHookAdd : public CommandObject
3402{
3403public:
3404
3405 class CommandOptions : public Options
3406 {
3407 public:
Greg Claytonf15996e2011-04-07 22:46:35 +00003408 CommandOptions (CommandInterpreter &interpreter) :
3409 Options(interpreter),
Jim Inghamd60d94a2011-03-11 03:53:59 +00003410 m_line_start(0),
3411 m_line_end (UINT_MAX),
3412 m_func_name_type_mask (eFunctionNameTypeAuto),
3413 m_sym_ctx_specified (false),
Johnny Chen60fe60e2011-05-02 23:47:55 +00003414 m_thread_specified (false),
3415 m_use_one_liner (false),
3416 m_one_liner()
Jim Inghamd60d94a2011-03-11 03:53:59 +00003417 {
3418 }
3419
3420 ~CommandOptions () {}
3421
Greg Claytonb3448432011-03-24 21:19:54 +00003422 const OptionDefinition*
Jim Inghamd60d94a2011-03-11 03:53:59 +00003423 GetDefinitions ()
3424 {
3425 return g_option_table;
3426 }
3427
3428 virtual Error
Greg Clayton143fcc32011-04-13 00:18:08 +00003429 SetOptionValue (uint32_t option_idx, const char *option_arg)
Jim Inghamd60d94a2011-03-11 03:53:59 +00003430 {
3431 Error error;
3432 char short_option = (char) m_getopt_table[option_idx].val;
3433 bool success;
3434
3435 switch (short_option)
3436 {
3437 case 'c':
3438 m_class_name = option_arg;
3439 m_sym_ctx_specified = true;
3440 break;
3441
3442 case 'e':
3443 m_line_end = Args::StringToUInt32 (option_arg, UINT_MAX, 0, &success);
3444 if (!success)
3445 {
Greg Clayton9c236732011-10-26 00:56:27 +00003446 error.SetErrorStringWithFormat ("invalid end line number: \"%s\"", option_arg);
Jim Inghamd60d94a2011-03-11 03:53:59 +00003447 break;
3448 }
3449 m_sym_ctx_specified = true;
3450 break;
3451
3452 case 'l':
3453 m_line_start = Args::StringToUInt32 (option_arg, 0, 0, &success);
3454 if (!success)
3455 {
Greg Clayton9c236732011-10-26 00:56:27 +00003456 error.SetErrorStringWithFormat ("invalid start line number: \"%s\"", option_arg);
Jim Inghamd60d94a2011-03-11 03:53:59 +00003457 break;
3458 }
3459 m_sym_ctx_specified = true;
3460 break;
3461
3462 case 'n':
3463 m_function_name = option_arg;
3464 m_func_name_type_mask |= eFunctionNameTypeAuto;
3465 m_sym_ctx_specified = true;
3466 break;
3467
3468 case 'f':
3469 m_file_name = option_arg;
3470 m_sym_ctx_specified = true;
3471 break;
3472 case 's':
3473 m_module_name = option_arg;
3474 m_sym_ctx_specified = true;
3475 break;
3476 case 't' :
3477 {
Jim Ingham7a4c8ea2011-03-22 01:53:33 +00003478 m_thread_id = Args::StringToUInt64(option_arg, LLDB_INVALID_THREAD_ID, 0);
Jim Inghamd60d94a2011-03-11 03:53:59 +00003479 if (m_thread_id == LLDB_INVALID_THREAD_ID)
Greg Clayton9c236732011-10-26 00:56:27 +00003480 error.SetErrorStringWithFormat ("invalid thread id string '%s'", option_arg);
Jim Inghamd60d94a2011-03-11 03:53:59 +00003481 m_thread_specified = true;
3482 }
3483 break;
3484 case 'T':
3485 m_thread_name = option_arg;
3486 m_thread_specified = true;
3487 break;
3488 case 'q':
3489 m_queue_name = option_arg;
3490 m_thread_specified = true;
3491 break;
3492 case 'x':
3493 {
Jim Ingham7a4c8ea2011-03-22 01:53:33 +00003494 m_thread_index = Args::StringToUInt32(option_arg, UINT32_MAX, 0);
Jim Inghamd60d94a2011-03-11 03:53:59 +00003495 if (m_thread_id == UINT32_MAX)
Greg Clayton9c236732011-10-26 00:56:27 +00003496 error.SetErrorStringWithFormat ("invalid thread index string '%s'", option_arg);
Jim Inghamd60d94a2011-03-11 03:53:59 +00003497 m_thread_specified = true;
3498 }
3499 break;
Johnny Chen60fe60e2011-05-02 23:47:55 +00003500 case 'o':
3501 m_use_one_liner = true;
3502 m_one_liner = option_arg;
3503 break;
Jim Inghamd60d94a2011-03-11 03:53:59 +00003504 default:
Greg Clayton9c236732011-10-26 00:56:27 +00003505 error.SetErrorStringWithFormat ("unrecognized option %c.", short_option);
Jim Inghamd60d94a2011-03-11 03:53:59 +00003506 break;
3507 }
3508 return error;
3509 }
3510
3511 void
Greg Clayton143fcc32011-04-13 00:18:08 +00003512 OptionParsingStarting ()
Jim Inghamd60d94a2011-03-11 03:53:59 +00003513 {
3514 m_class_name.clear();
3515 m_function_name.clear();
3516 m_line_start = 0;
3517 m_line_end = UINT_MAX;
3518 m_file_name.clear();
3519 m_module_name.clear();
3520 m_func_name_type_mask = eFunctionNameTypeAuto;
3521 m_thread_id = LLDB_INVALID_THREAD_ID;
3522 m_thread_index = UINT32_MAX;
3523 m_thread_name.clear();
3524 m_queue_name.clear();
3525
3526 m_sym_ctx_specified = false;
3527 m_thread_specified = false;
Johnny Chen60fe60e2011-05-02 23:47:55 +00003528
3529 m_use_one_liner = false;
3530 m_one_liner.clear();
Jim Inghamd60d94a2011-03-11 03:53:59 +00003531 }
3532
3533
Greg Claytonb3448432011-03-24 21:19:54 +00003534 static OptionDefinition g_option_table[];
Jim Inghamd60d94a2011-03-11 03:53:59 +00003535
3536 std::string m_class_name;
3537 std::string m_function_name;
3538 uint32_t m_line_start;
3539 uint32_t m_line_end;
3540 std::string m_file_name;
3541 std::string m_module_name;
3542 uint32_t m_func_name_type_mask; // A pick from lldb::FunctionNameType.
3543 lldb::tid_t m_thread_id;
3544 uint32_t m_thread_index;
3545 std::string m_thread_name;
3546 std::string m_queue_name;
3547 bool m_sym_ctx_specified;
3548 bool m_thread_specified;
Johnny Chen60fe60e2011-05-02 23:47:55 +00003549 // Instance variables to hold the values for one_liner options.
3550 bool m_use_one_liner;
3551 std::string m_one_liner;
Jim Inghamd60d94a2011-03-11 03:53:59 +00003552 };
3553
3554 Options *
3555 GetOptions ()
3556 {
3557 return &m_options;
3558 }
3559
3560 CommandObjectTargetStopHookAdd (CommandInterpreter &interpreter) :
3561 CommandObject (interpreter,
3562 "target stop-hook add ",
3563 "Add a hook to be executed when the target stops.",
Greg Claytonf15996e2011-04-07 22:46:35 +00003564 "target stop-hook add"),
3565 m_options (interpreter)
Jim Inghamd60d94a2011-03-11 03:53:59 +00003566 {
3567 }
3568
3569 ~CommandObjectTargetStopHookAdd ()
3570 {
3571 }
3572
3573 static size_t
3574 ReadCommandsCallbackFunction (void *baton,
3575 InputReader &reader,
3576 lldb::InputReaderAction notification,
3577 const char *bytes,
3578 size_t bytes_len)
3579 {
Caroline Tice892fadd2011-06-16 16:27:19 +00003580 StreamSP out_stream = reader.GetDebugger().GetAsyncOutputStream();
Jim Inghamd60d94a2011-03-11 03:53:59 +00003581 Target::StopHook *new_stop_hook = ((Target::StopHook *) baton);
Jim Inghame15511a2011-05-05 01:03:36 +00003582 static bool got_interrupted;
Caroline Tice892fadd2011-06-16 16:27:19 +00003583 bool batch_mode = reader.GetDebugger().GetCommandInterpreter().GetBatchCommandMode();
Jim Inghamd60d94a2011-03-11 03:53:59 +00003584
3585 switch (notification)
3586 {
3587 case eInputReaderActivate:
Caroline Tice892fadd2011-06-16 16:27:19 +00003588 if (!batch_mode)
3589 {
3590 out_stream->Printf ("%s\n", "Enter your stop hook command(s). Type 'DONE' to end.");
3591 if (reader.GetPrompt())
3592 out_stream->Printf ("%s", reader.GetPrompt());
3593 out_stream->Flush();
3594 }
Jim Inghame15511a2011-05-05 01:03:36 +00003595 got_interrupted = false;
Jim Inghamd60d94a2011-03-11 03:53:59 +00003596 break;
3597
3598 case eInputReaderDeactivate:
3599 break;
3600
3601 case eInputReaderReactivate:
Caroline Tice892fadd2011-06-16 16:27:19 +00003602 if (reader.GetPrompt() && !batch_mode)
Jim Inghamd60d94a2011-03-11 03:53:59 +00003603 {
Caroline Tice892fadd2011-06-16 16:27:19 +00003604 out_stream->Printf ("%s", reader.GetPrompt());
3605 out_stream->Flush();
Jim Inghamd60d94a2011-03-11 03:53:59 +00003606 }
Jim Inghame15511a2011-05-05 01:03:36 +00003607 got_interrupted = false;
Jim Inghamd60d94a2011-03-11 03:53:59 +00003608 break;
3609
Caroline Tice4a348082011-05-02 20:41:46 +00003610 case eInputReaderAsynchronousOutputWritten:
3611 break;
3612
Jim Inghamd60d94a2011-03-11 03:53:59 +00003613 case eInputReaderGotToken:
3614 if (bytes && bytes_len && baton)
3615 {
3616 StringList *commands = new_stop_hook->GetCommandPointer();
3617 if (commands)
3618 {
3619 commands->AppendString (bytes, bytes_len);
3620 }
3621 }
Caroline Tice892fadd2011-06-16 16:27:19 +00003622 if (!reader.IsDone() && reader.GetPrompt() && !batch_mode)
Jim Inghamd60d94a2011-03-11 03:53:59 +00003623 {
Caroline Tice892fadd2011-06-16 16:27:19 +00003624 out_stream->Printf ("%s", reader.GetPrompt());
3625 out_stream->Flush();
Jim Inghamd60d94a2011-03-11 03:53:59 +00003626 }
3627 break;
3628
3629 case eInputReaderInterrupt:
3630 {
3631 // Finish, and cancel the stop hook.
3632 new_stop_hook->GetTarget()->RemoveStopHookByID(new_stop_hook->GetID());
Caroline Tice892fadd2011-06-16 16:27:19 +00003633 if (!batch_mode)
3634 {
3635 out_stream->Printf ("Stop hook cancelled.\n");
3636 out_stream->Flush();
3637 }
3638
Jim Inghamd60d94a2011-03-11 03:53:59 +00003639 reader.SetIsDone (true);
3640 }
Jim Inghame15511a2011-05-05 01:03:36 +00003641 got_interrupted = true;
Jim Inghamd60d94a2011-03-11 03:53:59 +00003642 break;
3643
3644 case eInputReaderEndOfFile:
3645 reader.SetIsDone (true);
3646 break;
3647
3648 case eInputReaderDone:
Caroline Tice892fadd2011-06-16 16:27:19 +00003649 if (!got_interrupted && !batch_mode)
3650 {
Greg Clayton444e35b2011-10-19 18:09:39 +00003651 out_stream->Printf ("Stop hook #%llu added.\n", new_stop_hook->GetID());
Caroline Tice892fadd2011-06-16 16:27:19 +00003652 out_stream->Flush();
3653 }
Jim Inghamd60d94a2011-03-11 03:53:59 +00003654 break;
3655 }
3656
3657 return bytes_len;
3658 }
3659
3660 bool
3661 Execute (Args& command,
3662 CommandReturnObject &result)
3663 {
3664 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
3665 if (target)
3666 {
3667 Target::StopHookSP new_hook_sp;
3668 target->AddStopHook (new_hook_sp);
3669
3670 // First step, make the specifier.
3671 std::auto_ptr<SymbolContextSpecifier> specifier_ap;
3672 if (m_options.m_sym_ctx_specified)
3673 {
3674 specifier_ap.reset(new SymbolContextSpecifier(m_interpreter.GetDebugger().GetSelectedTarget()));
3675
3676 if (!m_options.m_module_name.empty())
3677 {
3678 specifier_ap->AddSpecification (m_options.m_module_name.c_str(), SymbolContextSpecifier::eModuleSpecified);
3679 }
3680
3681 if (!m_options.m_class_name.empty())
3682 {
3683 specifier_ap->AddSpecification (m_options.m_class_name.c_str(), SymbolContextSpecifier::eClassOrNamespaceSpecified);
3684 }
3685
3686 if (!m_options.m_file_name.empty())
3687 {
3688 specifier_ap->AddSpecification (m_options.m_file_name.c_str(), SymbolContextSpecifier::eFileSpecified);
3689 }
3690
3691 if (m_options.m_line_start != 0)
3692 {
3693 specifier_ap->AddLineSpecification (m_options.m_line_start, SymbolContextSpecifier::eLineStartSpecified);
3694 }
3695
3696 if (m_options.m_line_end != UINT_MAX)
3697 {
3698 specifier_ap->AddLineSpecification (m_options.m_line_end, SymbolContextSpecifier::eLineEndSpecified);
3699 }
3700
3701 if (!m_options.m_function_name.empty())
3702 {
3703 specifier_ap->AddSpecification (m_options.m_function_name.c_str(), SymbolContextSpecifier::eFunctionSpecified);
3704 }
3705 }
3706
3707 if (specifier_ap.get())
3708 new_hook_sp->SetSpecifier (specifier_ap.release());
3709
3710 // Next see if any of the thread options have been entered:
3711
3712 if (m_options.m_thread_specified)
3713 {
3714 ThreadSpec *thread_spec = new ThreadSpec();
3715
3716 if (m_options.m_thread_id != LLDB_INVALID_THREAD_ID)
3717 {
3718 thread_spec->SetTID (m_options.m_thread_id);
3719 }
3720
3721 if (m_options.m_thread_index != UINT32_MAX)
3722 thread_spec->SetIndex (m_options.m_thread_index);
3723
3724 if (!m_options.m_thread_name.empty())
3725 thread_spec->SetName (m_options.m_thread_name.c_str());
3726
3727 if (!m_options.m_queue_name.empty())
3728 thread_spec->SetQueueName (m_options.m_queue_name.c_str());
3729
3730 new_hook_sp->SetThreadSpecifier (thread_spec);
3731
3732 }
Johnny Chen60fe60e2011-05-02 23:47:55 +00003733 if (m_options.m_use_one_liner)
Jim Inghamd60d94a2011-03-11 03:53:59 +00003734 {
Johnny Chen60fe60e2011-05-02 23:47:55 +00003735 // Use one-liner.
3736 new_hook_sp->GetCommandPointer()->AppendString (m_options.m_one_liner.c_str());
Greg Clayton444e35b2011-10-19 18:09:39 +00003737 result.AppendMessageWithFormat("Stop hook #%llu added.\n", new_hook_sp->GetID());
Jim Inghamd60d94a2011-03-11 03:53:59 +00003738 }
Johnny Chen60fe60e2011-05-02 23:47:55 +00003739 else
Jim Inghamd60d94a2011-03-11 03:53:59 +00003740 {
Johnny Chen60fe60e2011-05-02 23:47:55 +00003741 // Otherwise gather up the command list, we'll push an input reader and suck the data from that directly into
3742 // the new stop hook's command string.
3743 InputReaderSP reader_sp (new InputReader(m_interpreter.GetDebugger()));
3744 if (!reader_sp)
3745 {
3746 result.AppendError("out of memory\n");
3747 result.SetStatus (eReturnStatusFailed);
3748 target->RemoveStopHookByID (new_hook_sp->GetID());
3749 return false;
3750 }
3751
3752 Error err (reader_sp->Initialize (CommandObjectTargetStopHookAdd::ReadCommandsCallbackFunction,
3753 new_hook_sp.get(), // baton
3754 eInputReaderGranularityLine, // token size, to pass to callback function
3755 "DONE", // end token
3756 "> ", // prompt
3757 true)); // echo input
3758 if (!err.Success())
3759 {
3760 result.AppendError (err.AsCString());
3761 result.SetStatus (eReturnStatusFailed);
3762 target->RemoveStopHookByID (new_hook_sp->GetID());
3763 return false;
3764 }
3765 m_interpreter.GetDebugger().PushInputReader (reader_sp);
Jim Inghamd60d94a2011-03-11 03:53:59 +00003766 }
Jim Inghamd60d94a2011-03-11 03:53:59 +00003767 result.SetStatus (eReturnStatusSuccessFinishNoResult);
3768 }
3769 else
3770 {
Greg Claytonabe0fed2011-04-18 08:33:37 +00003771 result.AppendError ("invalid target\n");
Jim Inghamd60d94a2011-03-11 03:53:59 +00003772 result.SetStatus (eReturnStatusFailed);
3773 }
3774
3775 return result.Succeeded();
3776 }
3777private:
3778 CommandOptions m_options;
3779};
3780
Greg Claytonb3448432011-03-24 21:19:54 +00003781OptionDefinition
Jim Inghamd60d94a2011-03-11 03:53:59 +00003782CommandObjectTargetStopHookAdd::CommandOptions::g_option_table[] =
3783{
Johnny Chen60fe60e2011-05-02 23:47:55 +00003784 { LLDB_OPT_SET_ALL, false, "one-liner", 'o', required_argument, NULL, NULL, eArgTypeOneLiner,
3785 "Specify a one-line breakpoint command inline. Be sure to surround it with quotes." },
Jim Inghamd60d94a2011-03-11 03:53:59 +00003786 { LLDB_OPT_SET_ALL, false, "shlib", 's', required_argument, NULL, CommandCompletions::eModuleCompletion, eArgTypeShlibName,
3787 "Set the module within which the stop-hook is to be run."},
3788 { LLDB_OPT_SET_ALL, false, "thread-index", 'x', required_argument, NULL, NULL, eArgTypeThreadIndex,
3789 "The stop hook is run only for the thread whose index matches this argument."},
3790 { LLDB_OPT_SET_ALL, false, "thread-id", 't', required_argument, NULL, NULL, eArgTypeThreadID,
3791 "The stop hook is run only for the thread whose TID matches this argument."},
3792 { LLDB_OPT_SET_ALL, false, "thread-name", 'T', required_argument, NULL, NULL, eArgTypeThreadName,
3793 "The stop hook is run only for the thread whose thread name matches this argument."},
3794 { LLDB_OPT_SET_ALL, false, "queue-name", 'q', required_argument, NULL, NULL, eArgTypeQueueName,
3795 "The stop hook is run only for threads in the queue whose name is given by this argument."},
3796 { LLDB_OPT_SET_1, false, "file", 'f', required_argument, NULL, CommandCompletions::eSourceFileCompletion, eArgTypeFilename,
3797 "Specify the source file within which the stop-hook is to be run." },
3798 { LLDB_OPT_SET_1, false, "start-line", 'l', required_argument, NULL, 0, eArgTypeLineNum,
3799 "Set the start of the line range for which the stop-hook is to be run."},
3800 { LLDB_OPT_SET_1, false, "end-line", 'e', required_argument, NULL, 0, eArgTypeLineNum,
3801 "Set the end of the line range for which the stop-hook is to be run."},
3802 { LLDB_OPT_SET_2, false, "classname", 'c', required_argument, NULL, NULL, eArgTypeClassName,
3803 "Specify the class within which the stop-hook is to be run." },
3804 { LLDB_OPT_SET_3, false, "name", 'n', required_argument, NULL, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName,
3805 "Set the function name within which the stop hook will be run." },
3806 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
3807};
3808
3809#pragma mark CommandObjectTargetStopHookDelete
3810
3811//-------------------------------------------------------------------------
3812// CommandObjectTargetStopHookDelete
3813//-------------------------------------------------------------------------
3814
3815class CommandObjectTargetStopHookDelete : public CommandObject
3816{
3817public:
3818
3819 CommandObjectTargetStopHookDelete (CommandInterpreter &interpreter) :
3820 CommandObject (interpreter,
Jason Molenda3fccc902011-11-10 23:03:44 +00003821 "target stop-hook delete",
Jim Inghamd60d94a2011-03-11 03:53:59 +00003822 "Delete a stop-hook.",
Jason Molenda3fccc902011-11-10 23:03:44 +00003823 "target stop-hook delete [<idx>]")
Jim Inghamd60d94a2011-03-11 03:53:59 +00003824 {
3825 }
3826
3827 ~CommandObjectTargetStopHookDelete ()
3828 {
3829 }
3830
3831 bool
3832 Execute (Args& command,
3833 CommandReturnObject &result)
3834 {
3835 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
3836 if (target)
3837 {
3838 // FIXME: see if we can use the breakpoint id style parser?
3839 size_t num_args = command.GetArgumentCount();
3840 if (num_args == 0)
3841 {
3842 if (!m_interpreter.Confirm ("Delete all stop hooks?", true))
3843 {
3844 result.SetStatus (eReturnStatusFailed);
3845 return false;
3846 }
3847 else
3848 {
3849 target->RemoveAllStopHooks();
3850 }
3851 }
3852 else
3853 {
3854 bool success;
3855 for (size_t i = 0; i < num_args; i++)
3856 {
3857 lldb::user_id_t user_id = Args::StringToUInt32 (command.GetArgumentAtIndex(i), 0, 0, &success);
3858 if (!success)
3859 {
Greg Claytonabe0fed2011-04-18 08:33:37 +00003860 result.AppendErrorWithFormat ("invalid stop hook id: \"%s\".\n", command.GetArgumentAtIndex(i));
Jim Inghamd60d94a2011-03-11 03:53:59 +00003861 result.SetStatus(eReturnStatusFailed);
3862 return false;
3863 }
3864 success = target->RemoveStopHookByID (user_id);
3865 if (!success)
3866 {
Greg Claytonabe0fed2011-04-18 08:33:37 +00003867 result.AppendErrorWithFormat ("unknown stop hook id: \"%s\".\n", command.GetArgumentAtIndex(i));
Jim Inghamd60d94a2011-03-11 03:53:59 +00003868 result.SetStatus(eReturnStatusFailed);
3869 return false;
3870 }
3871 }
3872 }
3873 result.SetStatus (eReturnStatusSuccessFinishNoResult);
3874 }
3875 else
3876 {
Greg Claytonabe0fed2011-04-18 08:33:37 +00003877 result.AppendError ("invalid target\n");
Jim Inghamd60d94a2011-03-11 03:53:59 +00003878 result.SetStatus (eReturnStatusFailed);
3879 }
3880
3881 return result.Succeeded();
3882 }
3883};
3884#pragma mark CommandObjectTargetStopHookEnableDisable
3885
3886//-------------------------------------------------------------------------
3887// CommandObjectTargetStopHookEnableDisable
3888//-------------------------------------------------------------------------
3889
3890class CommandObjectTargetStopHookEnableDisable : public CommandObject
3891{
3892public:
3893
3894 CommandObjectTargetStopHookEnableDisable (CommandInterpreter &interpreter, bool enable, const char *name, const char *help, const char *syntax) :
3895 CommandObject (interpreter,
3896 name,
3897 help,
3898 syntax),
3899 m_enable (enable)
3900 {
3901 }
3902
3903 ~CommandObjectTargetStopHookEnableDisable ()
3904 {
3905 }
3906
3907 bool
3908 Execute (Args& command,
3909 CommandReturnObject &result)
3910 {
3911 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
3912 if (target)
3913 {
3914 // FIXME: see if we can use the breakpoint id style parser?
3915 size_t num_args = command.GetArgumentCount();
3916 bool success;
3917
3918 if (num_args == 0)
3919 {
3920 target->SetAllStopHooksActiveState (m_enable);
3921 }
3922 else
3923 {
3924 for (size_t i = 0; i < num_args; i++)
3925 {
3926 lldb::user_id_t user_id = Args::StringToUInt32 (command.GetArgumentAtIndex(i), 0, 0, &success);
3927 if (!success)
3928 {
Greg Claytonabe0fed2011-04-18 08:33:37 +00003929 result.AppendErrorWithFormat ("invalid stop hook id: \"%s\".\n", command.GetArgumentAtIndex(i));
Jim Inghamd60d94a2011-03-11 03:53:59 +00003930 result.SetStatus(eReturnStatusFailed);
3931 return false;
3932 }
3933 success = target->SetStopHookActiveStateByID (user_id, m_enable);
3934 if (!success)
3935 {
Greg Claytonabe0fed2011-04-18 08:33:37 +00003936 result.AppendErrorWithFormat ("unknown stop hook id: \"%s\".\n", command.GetArgumentAtIndex(i));
Jim Inghamd60d94a2011-03-11 03:53:59 +00003937 result.SetStatus(eReturnStatusFailed);
3938 return false;
3939 }
3940 }
3941 }
3942 result.SetStatus (eReturnStatusSuccessFinishNoResult);
3943 }
3944 else
3945 {
Greg Claytonabe0fed2011-04-18 08:33:37 +00003946 result.AppendError ("invalid target\n");
Jim Inghamd60d94a2011-03-11 03:53:59 +00003947 result.SetStatus (eReturnStatusFailed);
3948 }
3949 return result.Succeeded();
3950 }
3951private:
3952 bool m_enable;
3953};
3954
3955#pragma mark CommandObjectTargetStopHookList
3956
3957//-------------------------------------------------------------------------
3958// CommandObjectTargetStopHookList
3959//-------------------------------------------------------------------------
3960
3961class CommandObjectTargetStopHookList : public CommandObject
3962{
3963public:
3964
3965 CommandObjectTargetStopHookList (CommandInterpreter &interpreter) :
3966 CommandObject (interpreter,
Jason Molenda3fccc902011-11-10 23:03:44 +00003967 "target stop-hook list",
Jim Inghamd60d94a2011-03-11 03:53:59 +00003968 "List all stop-hooks.",
Jason Molenda3fccc902011-11-10 23:03:44 +00003969 "target stop-hook list [<type>]")
Jim Inghamd60d94a2011-03-11 03:53:59 +00003970 {
3971 }
3972
3973 ~CommandObjectTargetStopHookList ()
3974 {
3975 }
3976
3977 bool
3978 Execute (Args& command,
3979 CommandReturnObject &result)
3980 {
3981 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Johnny Chen9fc16922011-11-29 23:56:14 +00003982 if (!target)
Jim Inghamd60d94a2011-03-11 03:53:59 +00003983 {
Greg Claytonabe0fed2011-04-18 08:33:37 +00003984 result.AppendError ("invalid target\n");
Jim Inghamd60d94a2011-03-11 03:53:59 +00003985 result.SetStatus (eReturnStatusFailed);
Jason Molenda6e3a2412011-09-23 21:15:42 +00003986 return result.Succeeded();
Jim Inghamd60d94a2011-03-11 03:53:59 +00003987 }
3988
3989 size_t num_hooks = target->GetNumStopHooks ();
3990 if (num_hooks == 0)
3991 {
3992 result.GetOutputStream().PutCString ("No stop hooks.\n");
3993 }
3994 else
3995 {
3996 for (size_t i = 0; i < num_hooks; i++)
3997 {
3998 Target::StopHookSP this_hook = target->GetStopHookAtIndex (i);
3999 if (i > 0)
4000 result.GetOutputStream().PutCString ("\n");
4001 this_hook->GetDescription (&(result.GetOutputStream()), eDescriptionLevelFull);
4002 }
4003 }
Johnny Chen6c7c3902011-11-30 19:09:20 +00004004 result.SetStatus (eReturnStatusSuccessFinishResult);
Jim Inghamd60d94a2011-03-11 03:53:59 +00004005 return result.Succeeded();
4006 }
4007};
4008
4009#pragma mark CommandObjectMultiwordTargetStopHooks
4010//-------------------------------------------------------------------------
4011// CommandObjectMultiwordTargetStopHooks
4012//-------------------------------------------------------------------------
4013
4014class CommandObjectMultiwordTargetStopHooks : public CommandObjectMultiword
4015{
4016public:
4017
4018 CommandObjectMultiwordTargetStopHooks (CommandInterpreter &interpreter) :
4019 CommandObjectMultiword (interpreter,
4020 "target stop-hook",
4021 "A set of commands for operating on debugger target stop-hooks.",
4022 "target stop-hook <subcommand> [<subcommand-options>]")
4023 {
4024 LoadSubCommand ("add", CommandObjectSP (new CommandObjectTargetStopHookAdd (interpreter)));
4025 LoadSubCommand ("delete", CommandObjectSP (new CommandObjectTargetStopHookDelete (interpreter)));
4026 LoadSubCommand ("disable", CommandObjectSP (new CommandObjectTargetStopHookEnableDisable (interpreter,
4027 false,
4028 "target stop-hook disable [<id>]",
4029 "Disable a stop-hook.",
4030 "target stop-hook disable")));
4031 LoadSubCommand ("enable", CommandObjectSP (new CommandObjectTargetStopHookEnableDisable (interpreter,
4032 true,
4033 "target stop-hook enable [<id>]",
4034 "Enable a stop-hook.",
4035 "target stop-hook enable")));
4036 LoadSubCommand ("list", CommandObjectSP (new CommandObjectTargetStopHookList (interpreter)));
4037 }
4038
4039 ~CommandObjectMultiwordTargetStopHooks()
4040 {
4041 }
4042};
4043
4044
Chris Lattner24943d22010-06-08 16:52:24 +00004045
4046#pragma mark CommandObjectMultiwordTarget
4047
4048//-------------------------------------------------------------------------
4049// CommandObjectMultiwordTarget
4050//-------------------------------------------------------------------------
4051
Greg Clayton63094e02010-06-23 01:19:29 +00004052CommandObjectMultiwordTarget::CommandObjectMultiwordTarget (CommandInterpreter &interpreter) :
Greg Clayton238c0a12010-09-18 01:14:36 +00004053 CommandObjectMultiword (interpreter,
4054 "target",
Chris Lattner24943d22010-06-08 16:52:24 +00004055 "A set of commands for operating on debugger targets.",
4056 "target <subcommand> [<subcommand-options>]")
4057{
Greg Claytonabe0fed2011-04-18 08:33:37 +00004058
4059 LoadSubCommand ("create", CommandObjectSP (new CommandObjectTargetCreate (interpreter)));
Greg Clayton153ccd72011-08-10 02:10:13 +00004060 LoadSubCommand ("delete", CommandObjectSP (new CommandObjectTargetDelete (interpreter)));
Greg Claytonabe0fed2011-04-18 08:33:37 +00004061 LoadSubCommand ("list", CommandObjectSP (new CommandObjectTargetList (interpreter)));
4062 LoadSubCommand ("select", CommandObjectSP (new CommandObjectTargetSelect (interpreter)));
Jim Inghamd60d94a2011-03-11 03:53:59 +00004063 LoadSubCommand ("stop-hook", CommandObjectSP (new CommandObjectMultiwordTargetStopHooks (interpreter)));
Greg Claytone1f50b92011-05-03 22:09:39 +00004064 LoadSubCommand ("modules", CommandObjectSP (new CommandObjectTargetModules (interpreter)));
Greg Clayton801417e2011-07-07 01:59:51 +00004065 LoadSubCommand ("variable", CommandObjectSP (new CommandObjectTargetVariable (interpreter)));
Chris Lattner24943d22010-06-08 16:52:24 +00004066}
4067
4068CommandObjectMultiwordTarget::~CommandObjectMultiwordTarget ()
4069{
4070}
4071
Greg Claytonabe0fed2011-04-18 08:33:37 +00004072