blob: cf8217c259cff0fa9550719c3c5a6e25feceffe5 [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 Clayton46c9a352012-02-09 06:16:32 +0000151 m_platform_options(true), // Do include the "--platform" option in the platform settings by passing true
152 m_core_file (LLDB_OPT_SET_1, false, "core-file", 'c', 0, eArgTypePath, "Fullpath to a core file to use for this target.")
Greg Claytonabe0fed2011-04-18 08:33:37 +0000153 {
154 CommandArgumentEntry arg;
155 CommandArgumentData file_arg;
156
157 // Define the first (and only) variant of this arg.
158 file_arg.arg_type = eArgTypeFilename;
159 file_arg.arg_repetition = eArgRepeatPlain;
160
161 // There is only one variant this argument could be; put it into the argument entry.
162 arg.push_back (file_arg);
163
164 // Push the data for the first argument into the m_arguments vector.
165 m_arguments.push_back (arg);
166
Greg Clayton801417e2011-07-07 01:59:51 +0000167 m_option_group.Append (&m_arch_option, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
Greg Claytonabe0fed2011-04-18 08:33:37 +0000168 m_option_group.Append (&m_platform_options, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
Greg Clayton46c9a352012-02-09 06:16:32 +0000169 m_option_group.Append (&m_core_file, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
Greg Claytonabe0fed2011-04-18 08:33:37 +0000170 m_option_group.Finalize();
171 }
172
173 ~CommandObjectTargetCreate ()
174 {
175 }
176
177 Options *
178 GetOptions ()
179 {
180 return &m_option_group;
181 }
182
183 bool
184 Execute (Args& command, CommandReturnObject &result)
185 {
186 const int argc = command.GetArgumentCount();
Greg Clayton46c9a352012-02-09 06:16:32 +0000187 FileSpec core_file (m_core_file.GetOptionValue().GetCurrentValue());
188
189 if (argc == 1 || core_file)
Greg Claytonabe0fed2011-04-18 08:33:37 +0000190 {
191 const char *file_path = command.GetArgumentAtIndex(0);
192 Timer scoped_timer(__PRETTY_FUNCTION__, "(lldb) target create '%s'", file_path);
Greg Clayton46c9a352012-02-09 06:16:32 +0000193 FileSpec file_spec;
194
195 if (file_path)
196 file_spec.SetFile (file_path, true);
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000197
Greg Claytonabe0fed2011-04-18 08:33:37 +0000198 TargetSP target_sp;
199 Debugger &debugger = m_interpreter.GetDebugger();
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000200 const char *arch_cstr = m_arch_option.GetArchitectureName();
201 const bool get_dependent_files = true;
202 Error error (debugger.GetTargetList().CreateTarget (debugger,
203 file_spec,
204 arch_cstr,
205 get_dependent_files,
206 &m_platform_options,
207 target_sp));
208
Greg Claytonabe0fed2011-04-18 08:33:37 +0000209 if (target_sp)
210 {
211 debugger.GetTargetList().SetSelectedTarget(target_sp.get());
Greg Clayton46c9a352012-02-09 06:16:32 +0000212 if (core_file)
213 {
Greg Clayton46c9a352012-02-09 06:16:32 +0000214 char core_path[PATH_MAX];
215 core_file.GetPath(core_path, sizeof(core_path));
Greg Clayton9ce95382012-02-13 23:10:39 +0000216 if (core_file.Exists())
Greg Clayton46c9a352012-02-09 06:16:32 +0000217 {
Greg Clayton9ce95382012-02-13 23:10:39 +0000218 FileSpec core_file_dir;
219 core_file_dir.GetDirectory() = core_file.GetDirectory();
220 target_sp->GetExecutableSearchPaths ().Append (core_file_dir);
Greg Clayton46c9a352012-02-09 06:16:32 +0000221
Greg Clayton9ce95382012-02-13 23:10:39 +0000222 ProcessSP process_sp (target_sp->CreateProcess (m_interpreter.GetDebugger().GetListener(), NULL, &core_file));
223
224 if (process_sp)
Greg Clayton46c9a352012-02-09 06:16:32 +0000225 {
Greg Clayton9ce95382012-02-13 23:10:39 +0000226 // Seems wierd that we Launch a core file, but that is
227 // what we do!
228 error = process_sp->LoadCore();
229
230 if (error.Fail())
231 {
232 result.AppendError(error.AsCString("can't find plug-in for core file"));
233 result.SetStatus (eReturnStatusFailed);
234 return false;
235 }
236 else
237 {
238 result.AppendMessageWithFormat ("Core file '%s' (%s) was loaded.\n", core_path, target_sp->GetArchitecture().GetArchitectureName());
239 result.SetStatus (eReturnStatusSuccessFinishNoResult);
240 }
Greg Clayton46c9a352012-02-09 06:16:32 +0000241 }
242 else
243 {
Greg Clayton9ce95382012-02-13 23:10:39 +0000244 result.AppendErrorWithFormat ("Unable to find process plug-in for core file '%s'\n", core_path);
245 result.SetStatus (eReturnStatusFailed);
Greg Clayton46c9a352012-02-09 06:16:32 +0000246 }
247 }
248 else
249 {
Greg Clayton9ce95382012-02-13 23:10:39 +0000250 result.AppendErrorWithFormat ("Core file '%s' does not exist\n", core_path);
Greg Clayton46c9a352012-02-09 06:16:32 +0000251 result.SetStatus (eReturnStatusFailed);
252 }
253 }
254 else
255 {
256 result.AppendMessageWithFormat ("Current executable set to '%s' (%s).\n", file_path, target_sp->GetArchitecture().GetArchitectureName());
257 result.SetStatus (eReturnStatusSuccessFinishNoResult);
258 }
Greg Claytonabe0fed2011-04-18 08:33:37 +0000259 }
260 else
261 {
262 result.AppendError(error.AsCString());
263 result.SetStatus (eReturnStatusFailed);
264 }
265 }
266 else
267 {
Greg Clayton46c9a352012-02-09 06:16:32 +0000268 result.AppendErrorWithFormat("'%s' takes exactly one executable path argument, or use the --core-file option.\n", m_cmd_name.c_str());
Greg Claytonabe0fed2011-04-18 08:33:37 +0000269 result.SetStatus (eReturnStatusFailed);
270 }
271 return result.Succeeded();
272
273 }
274
275 int
276 HandleArgumentCompletion (Args &input,
277 int &cursor_index,
278 int &cursor_char_position,
279 OptionElementVector &opt_element_vector,
280 int match_start_point,
281 int max_return_elements,
282 bool &word_complete,
283 StringList &matches)
284 {
285 std::string completion_str (input.GetArgumentAtIndex(cursor_index));
286 completion_str.erase (cursor_char_position);
287
288 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
289 CommandCompletions::eDiskFileCompletion,
290 completion_str.c_str(),
291 match_start_point,
292 max_return_elements,
293 NULL,
294 word_complete,
295 matches);
296 return matches.GetSize();
297 }
298private:
299 OptionGroupOptions m_option_group;
Greg Clayton801417e2011-07-07 01:59:51 +0000300 OptionGroupArchitecture m_arch_option;
Greg Claytonabe0fed2011-04-18 08:33:37 +0000301 OptionGroupPlatform m_platform_options;
Greg Clayton46c9a352012-02-09 06:16:32 +0000302 OptionGroupFile m_core_file;
Greg Claytonabe0fed2011-04-18 08:33:37 +0000303
304};
305
306#pragma mark CommandObjectTargetList
307
308//----------------------------------------------------------------------
309// "target list"
310//----------------------------------------------------------------------
311
312class CommandObjectTargetList : public CommandObject
313{
314public:
315 CommandObjectTargetList (CommandInterpreter &interpreter) :
316 CommandObject (interpreter,
317 "target list",
318 "List all current targets in the current debug session.",
319 NULL,
320 0)
321 {
322 }
323
324 virtual
325 ~CommandObjectTargetList ()
326 {
327 }
328
329 virtual bool
330 Execute (Args& args, CommandReturnObject &result)
331 {
332 if (args.GetArgumentCount() == 0)
333 {
334 Stream &strm = result.GetOutputStream();
335
336 bool show_stopped_process_status = false;
337 if (DumpTargetList (m_interpreter.GetDebugger().GetTargetList(), show_stopped_process_status, strm) == 0)
338 {
339 strm.PutCString ("No targets.\n");
340 }
Johnny Chen44dc9d32011-04-18 21:08:05 +0000341 result.SetStatus (eReturnStatusSuccessFinishResult);
Greg Claytonabe0fed2011-04-18 08:33:37 +0000342 }
343 else
344 {
345 result.AppendError ("the 'target list' command takes no arguments\n");
346 result.SetStatus (eReturnStatusFailed);
347 }
348 return result.Succeeded();
349 }
350};
351
352
353#pragma mark CommandObjectTargetSelect
354
355//----------------------------------------------------------------------
356// "target select"
357//----------------------------------------------------------------------
358
359class CommandObjectTargetSelect : public CommandObject
360{
361public:
362 CommandObjectTargetSelect (CommandInterpreter &interpreter) :
363 CommandObject (interpreter,
364 "target select",
365 "Select a target as the current target by target index.",
366 NULL,
367 0)
368 {
369 }
370
371 virtual
372 ~CommandObjectTargetSelect ()
373 {
374 }
375
376 virtual bool
377 Execute (Args& args, CommandReturnObject &result)
378 {
379 if (args.GetArgumentCount() == 1)
380 {
381 bool success = false;
382 const char *target_idx_arg = args.GetArgumentAtIndex(0);
383 uint32_t target_idx = Args::StringToUInt32 (target_idx_arg, UINT32_MAX, 0, &success);
384 if (success)
385 {
386 TargetList &target_list = m_interpreter.GetDebugger().GetTargetList();
387 const uint32_t num_targets = target_list.GetNumTargets();
388 if (target_idx < num_targets)
389 {
390 TargetSP target_sp (target_list.GetTargetAtIndex (target_idx));
391 if (target_sp)
392 {
393 Stream &strm = result.GetOutputStream();
394 target_list.SetSelectedTarget (target_sp.get());
395 bool show_stopped_process_status = false;
396 DumpTargetList (target_list, show_stopped_process_status, strm);
Johnny Chen44dc9d32011-04-18 21:08:05 +0000397 result.SetStatus (eReturnStatusSuccessFinishResult);
Greg Claytonabe0fed2011-04-18 08:33:37 +0000398 }
399 else
400 {
401 result.AppendErrorWithFormat ("target #%u is NULL in target list\n", target_idx);
402 result.SetStatus (eReturnStatusFailed);
403 }
404 }
405 else
406 {
407 result.AppendErrorWithFormat ("index %u is out of range, valid target indexes are 0 - %u\n",
408 target_idx,
409 num_targets - 1);
410 result.SetStatus (eReturnStatusFailed);
411 }
412 }
413 else
414 {
415 result.AppendErrorWithFormat("invalid index string value '%s'\n", target_idx_arg);
416 result.SetStatus (eReturnStatusFailed);
417 }
418 }
419 else
420 {
421 result.AppendError ("'target select' takes a single argument: a target index\n");
422 result.SetStatus (eReturnStatusFailed);
423 }
424 return result.Succeeded();
425 }
426};
427
Greg Clayton153ccd72011-08-10 02:10:13 +0000428#pragma mark CommandObjectTargetSelect
429
430//----------------------------------------------------------------------
431// "target delete"
432//----------------------------------------------------------------------
433
434class CommandObjectTargetDelete : public CommandObject
435{
436public:
437 CommandObjectTargetDelete (CommandInterpreter &interpreter) :
Greg Clayton5beb99d2011-08-11 02:48:45 +0000438 CommandObject (interpreter,
439 "target delete",
440 "Delete one or more targets by target index.",
441 NULL,
442 0),
443 m_option_group (interpreter),
444 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 +0000445 {
Greg Clayton5beb99d2011-08-11 02:48:45 +0000446 m_option_group.Append (&m_cleanup_option, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
447 m_option_group.Finalize();
Greg Clayton153ccd72011-08-10 02:10:13 +0000448 }
449
450 virtual
451 ~CommandObjectTargetDelete ()
452 {
453 }
454
455 virtual bool
456 Execute (Args& args, CommandReturnObject &result)
457 {
458 const size_t argc = args.GetArgumentCount();
459 std::vector<TargetSP> delete_target_list;
460 TargetList &target_list = m_interpreter.GetDebugger().GetTargetList();
461 bool success = true;
462 TargetSP target_sp;
463 if (argc > 0)
464 {
465 const uint32_t num_targets = target_list.GetNumTargets();
466 for (uint32_t arg_idx = 0; success && arg_idx < argc; ++arg_idx)
467 {
468 const char *target_idx_arg = args.GetArgumentAtIndex(arg_idx);
469 uint32_t target_idx = Args::StringToUInt32 (target_idx_arg, UINT32_MAX, 0, &success);
470 if (success)
471 {
472 if (target_idx < num_targets)
473 {
474 target_sp = target_list.GetTargetAtIndex (target_idx);
475 if (target_sp)
476 {
477 delete_target_list.push_back (target_sp);
478 continue;
479 }
480 }
481 result.AppendErrorWithFormat ("target index %u is out of range, valid target indexes are 0 - %u\n",
482 target_idx,
483 num_targets - 1);
484 result.SetStatus (eReturnStatusFailed);
485 success = false;
486 }
487 else
488 {
489 result.AppendErrorWithFormat("invalid target index '%s'\n", target_idx_arg);
490 result.SetStatus (eReturnStatusFailed);
491 success = false;
492 }
493 }
494
495 }
496 else
497 {
498 target_sp = target_list.GetSelectedTarget();
499 if (target_sp)
500 {
501 delete_target_list.push_back (target_sp);
502 }
503 else
504 {
505 result.AppendErrorWithFormat("no target is currently selected\n");
506 result.SetStatus (eReturnStatusFailed);
507 success = false;
508 }
509 }
510 if (success)
511 {
512 const size_t num_targets_to_delete = delete_target_list.size();
513 for (size_t idx = 0; idx < num_targets_to_delete; ++idx)
514 {
515 target_sp = delete_target_list[idx];
516 target_list.DeleteTarget(target_sp);
517 target_sp->Destroy();
518 }
Greg Clayton5beb99d2011-08-11 02:48:45 +0000519 // If "--clean" was specified, prune any orphaned shared modules from
520 // the global shared module list
521 if (m_cleanup_option.GetOptionValue ())
522 {
Greg Clayton860b9ea2012-04-09 20:22:01 +0000523 const bool mandatory = true;
524 ModuleList::RemoveOrphanSharedModules(mandatory);
Greg Clayton5beb99d2011-08-11 02:48:45 +0000525 }
Greg Clayton153ccd72011-08-10 02:10:13 +0000526 result.GetOutputStream().Printf("%u targets deleted.\n", (uint32_t)num_targets_to_delete);
527 result.SetStatus(eReturnStatusSuccessFinishResult);
528 }
529
530 return result.Succeeded();
531 }
Greg Clayton5beb99d2011-08-11 02:48:45 +0000532
533 Options *
534 GetOptions ()
535 {
536 return &m_option_group;
537 }
538
539protected:
540 OptionGroupOptions m_option_group;
541 OptionGroupBoolean m_cleanup_option;
Greg Clayton153ccd72011-08-10 02:10:13 +0000542};
543
Greg Claytonabe0fed2011-04-18 08:33:37 +0000544
Greg Clayton801417e2011-07-07 01:59:51 +0000545#pragma mark CommandObjectTargetVariable
546
547//----------------------------------------------------------------------
548// "target variable"
549//----------------------------------------------------------------------
550
551class CommandObjectTargetVariable : public CommandObject
552{
553public:
554 CommandObjectTargetVariable (CommandInterpreter &interpreter) :
555 CommandObject (interpreter,
Johnny Chen34bfa4f2011-07-12 22:34:30 +0000556 "target variable",
557 "Read global variable(s) prior to running your binary.",
Greg Clayton801417e2011-07-07 01:59:51 +0000558 NULL,
559 0),
560 m_option_group (interpreter),
Greg Clayton368f8222011-07-07 04:38:25 +0000561 m_option_variable (false), // Don't include frame options
Greg Claytona42880a2011-10-25 06:44:01 +0000562 m_option_format (eFormatDefault),
Greg Clayton801417e2011-07-07 01:59:51 +0000563 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."),
564 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."),
565 m_varobj_options()
566 {
Johnny Chen24b81e32011-08-22 22:22:00 +0000567 CommandArgumentEntry arg;
568 CommandArgumentData var_name_arg;
569
570 // Define the first (and only) variant of this arg.
571 var_name_arg.arg_type = eArgTypeVarName;
572 var_name_arg.arg_repetition = eArgRepeatPlus;
573
574 // There is only one variant this argument could be; put it into the argument entry.
575 arg.push_back (var_name_arg);
576
577 // Push the data for the first argument into the m_arguments vector.
578 m_arguments.push_back (arg);
579
Greg Clayton801417e2011-07-07 01:59:51 +0000580 m_option_group.Append (&m_varobj_options, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
Greg Clayton368f8222011-07-07 04:38:25 +0000581 m_option_group.Append (&m_option_variable, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
Greg Clayton24a6bd92011-10-27 17:55:14 +0000582 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 +0000583 m_option_group.Append (&m_option_compile_units, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
584 m_option_group.Append (&m_option_shared_libraries, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
585 m_option_group.Finalize();
586 }
587
588 virtual
589 ~CommandObjectTargetVariable ()
590 {
591 }
Greg Clayton5d81f492011-07-08 21:46:14 +0000592
593 void
594 DumpValueObject (Stream &s, VariableSP &var_sp, ValueObjectSP &valobj_sp, const char *root_name)
595 {
Enrico Granata19030d82011-08-15 18:01:31 +0000596 ValueObject::DumpValueObjectOptions options;
597
Enrico Granata3069c622012-03-01 04:24:26 +0000598 options.SetMaximumPointerDepth(m_varobj_options.ptr_depth)
Enrico Granata19030d82011-08-15 18:01:31 +0000599 .SetMaximumDepth(m_varobj_options.max_depth)
600 .SetShowTypes(m_varobj_options.show_types)
601 .SetShowLocation(m_varobj_options.show_location)
602 .SetUseObjectiveC(m_varobj_options.use_objc)
603 .SetUseDynamicType(m_varobj_options.use_dynamic)
Enrico Granatacf09f882012-03-19 22:58:49 +0000604 .SetUseSyntheticValue(m_varobj_options.use_synth)
Enrico Granata19030d82011-08-15 18:01:31 +0000605 .SetFlatOutput(m_varobj_options.flat_output)
606 .SetOmitSummaryDepth(m_varobj_options.no_summary_depth)
607 .SetIgnoreCap(m_varobj_options.ignore_cap);
608
Greg Clayton5d81f492011-07-08 21:46:14 +0000609 switch (var_sp->GetScope())
610 {
611 case eValueTypeVariableGlobal:
612 if (m_option_variable.show_scope)
613 s.PutCString("GLOBAL: ");
614 break;
615
616 case eValueTypeVariableStatic:
617 if (m_option_variable.show_scope)
618 s.PutCString("STATIC: ");
619 break;
620
621 case eValueTypeVariableArgument:
622 if (m_option_variable.show_scope)
623 s.PutCString(" ARG: ");
624 break;
625
626 case eValueTypeVariableLocal:
627 if (m_option_variable.show_scope)
628 s.PutCString(" LOCAL: ");
629 break;
630
631 default:
632 break;
633 }
634
Greg Claytonfb816422011-07-10 19:21:23 +0000635 if (m_option_variable.show_decl)
Greg Clayton5d81f492011-07-08 21:46:14 +0000636 {
Greg Claytonfb816422011-07-10 19:21:23 +0000637 bool show_fullpaths = false;
638 bool show_module = true;
639 if (var_sp->DumpDeclaration(&s, show_fullpaths, show_module))
640 s.PutCString (": ");
Greg Clayton5d81f492011-07-08 21:46:14 +0000641 }
642
Greg Claytona42880a2011-10-25 06:44:01 +0000643 const Format format = m_option_format.GetFormat();
Greg Clayton5d81f492011-07-08 21:46:14 +0000644 if (format != eFormatDefault)
Enrico Granata3069c622012-03-01 04:24:26 +0000645 options.SetFormat(format);
646
647 options.SetRootValueObjectName(root_name);
Greg Clayton5d81f492011-07-08 21:46:14 +0000648
649 ValueObject::DumpValueObject (s,
650 valobj_sp.get(),
Enrico Granata3069c622012-03-01 04:24:26 +0000651 options);
Greg Clayton5d81f492011-07-08 21:46:14 +0000652
653 }
Greg Clayton801417e2011-07-07 01:59:51 +0000654
Greg Clayton5d81f492011-07-08 21:46:14 +0000655
656 static uint32_t GetVariableCallback (void *baton,
657 const char *name,
658 VariableList &variable_list)
659 {
660 Target *target = static_cast<Target *>(baton);
661 if (target)
662 {
663 return target->GetImages().FindGlobalVariables (ConstString(name),
664 true,
665 UINT32_MAX,
666 variable_list);
667 }
668 return 0;
669 }
670
671
672
Greg Clayton801417e2011-07-07 01:59:51 +0000673 virtual bool
674 Execute (Args& args, CommandReturnObject &result)
675 {
676 ExecutionContext exe_ctx (m_interpreter.GetExecutionContext());
Greg Clayton567e7f32011-09-22 04:58:26 +0000677 Target *target = exe_ctx.GetTargetPtr();
678 if (target)
Greg Clayton801417e2011-07-07 01:59:51 +0000679 {
680 const size_t argc = args.GetArgumentCount();
Greg Claytonfac93882011-10-05 22:17:32 +0000681 Stream &s = result.GetOutputStream();
Greg Clayton801417e2011-07-07 01:59:51 +0000682 if (argc > 0)
683 {
Greg Clayton5d81f492011-07-08 21:46:14 +0000684
Greg Clayton801417e2011-07-07 01:59:51 +0000685 for (size_t idx = 0; idx < argc; ++idx)
686 {
Greg Clayton5d81f492011-07-08 21:46:14 +0000687 VariableList variable_list;
688 ValueObjectList valobj_list;
689
Greg Clayton368f8222011-07-07 04:38:25 +0000690 const char *arg = args.GetArgumentAtIndex(idx);
691 uint32_t matches = 0;
Greg Claytonfb816422011-07-10 19:21:23 +0000692 bool use_var_name = false;
Greg Clayton368f8222011-07-07 04:38:25 +0000693 if (m_option_variable.use_regex)
Greg Clayton801417e2011-07-07 01:59:51 +0000694 {
Greg Clayton368f8222011-07-07 04:38:25 +0000695 RegularExpression regex(arg);
696 if (!regex.IsValid ())
697 {
698 result.GetErrorStream().Printf ("error: invalid regular expression: '%s'\n", arg);
699 result.SetStatus (eReturnStatusFailed);
700 return false;
701 }
Greg Claytonfb816422011-07-10 19:21:23 +0000702 use_var_name = true;
Greg Clayton567e7f32011-09-22 04:58:26 +0000703 matches = target->GetImages().FindGlobalVariables (regex,
704 true,
705 UINT32_MAX,
706 variable_list);
Greg Clayton801417e2011-07-07 01:59:51 +0000707 }
708 else
709 {
Greg Clayton5d81f492011-07-08 21:46:14 +0000710 Error error (Variable::GetValuesForVariableExpressionPath (arg,
Greg Clayton24b03102011-07-09 20:12:33 +0000711 exe_ctx.GetBestExecutionContextScope(),
Greg Clayton5d81f492011-07-08 21:46:14 +0000712 GetVariableCallback,
Greg Clayton567e7f32011-09-22 04:58:26 +0000713 target,
Greg Clayton5d81f492011-07-08 21:46:14 +0000714 variable_list,
715 valobj_list));
Greg Clayton5d81f492011-07-08 21:46:14 +0000716 matches = variable_list.GetSize();
Greg Clayton368f8222011-07-07 04:38:25 +0000717 }
718
719 if (matches == 0)
720 {
721 result.GetErrorStream().Printf ("error: can't find global variable '%s'\n", arg);
722 result.SetStatus (eReturnStatusFailed);
723 return false;
724 }
725 else
726 {
Greg Clayton801417e2011-07-07 01:59:51 +0000727 for (uint32_t global_idx=0; global_idx<matches; ++global_idx)
728 {
Greg Clayton5d81f492011-07-08 21:46:14 +0000729 VariableSP var_sp (variable_list.GetVariableAtIndex(global_idx));
Greg Clayton801417e2011-07-07 01:59:51 +0000730 if (var_sp)
731 {
Greg Clayton5d81f492011-07-08 21:46:14 +0000732 ValueObjectSP valobj_sp (valobj_list.GetValueObjectAtIndex(global_idx));
733 if (!valobj_sp)
Greg Claytonfb816422011-07-10 19:21:23 +0000734 valobj_sp = ValueObjectVariable::Create (exe_ctx.GetBestExecutionContextScope(), var_sp);
Greg Clayton801417e2011-07-07 01:59:51 +0000735
736 if (valobj_sp)
Greg Claytonb304a742011-10-13 18:31:02 +0000737 DumpValueObject (s, var_sp, valobj_sp, use_var_name ? var_sp->GetName().GetCString() : arg);
Greg Clayton801417e2011-07-07 01:59:51 +0000738 }
739 }
740 }
741 }
742 }
743 else
744 {
Greg Claytonfac93882011-10-05 22:17:32 +0000745 bool success = false;
746 StackFrame *frame = exe_ctx.GetFramePtr();
747 CompileUnit *comp_unit = NULL;
748 if (frame)
749 {
750 comp_unit = frame->GetSymbolContext (eSymbolContextCompUnit).comp_unit;
751 if (comp_unit)
752 {
753 const bool can_create = true;
754 VariableListSP comp_unit_varlist_sp (comp_unit->GetVariableList(can_create));
755 if (comp_unit_varlist_sp)
756 {
757 size_t count = comp_unit_varlist_sp->GetSize();
758 if (count > 0)
759 {
Greg Claytona1b9a902011-11-13 04:15:56 +0000760 s.Printf ("Global variables for %s/%s:\n",
Greg Claytonfac93882011-10-05 22:17:32 +0000761 comp_unit->GetDirectory().GetCString(),
762 comp_unit->GetFilename().GetCString());
763
764 success = true;
765 for (uint32_t i=0; i<count; ++i)
766 {
767 VariableSP var_sp (comp_unit_varlist_sp->GetVariableAtIndex(i));
768 if (var_sp)
769 {
770 ValueObjectSP valobj_sp (ValueObjectVariable::Create (exe_ctx.GetBestExecutionContextScope(), var_sp));
771
772 if (valobj_sp)
773 DumpValueObject (s, var_sp, valobj_sp, var_sp->GetName().GetCString());
774 }
775 }
776 }
777 }
778 }
779 }
780 if (!success)
781 {
782 if (frame)
783 {
784 if (comp_unit)
785 result.AppendErrorWithFormat ("no global variables in current compile unit: %s/%s\n",
786 comp_unit->GetDirectory().GetCString(),
787 comp_unit->GetFilename().GetCString());
788 else
789 result.AppendError ("no debug information for frame %u\n", frame->GetFrameIndex());
790 }
791 else
792 result.AppendError ("'target variable' takes one or more global variable names as arguments\n");
793 result.SetStatus (eReturnStatusFailed);
794 }
Greg Clayton801417e2011-07-07 01:59:51 +0000795 }
796 }
797 else
798 {
799 result.AppendError ("invalid target, create a debug target using the 'target create' command");
800 result.SetStatus (eReturnStatusFailed);
801 return false;
802 }
Enrico Granatadb64d952011-08-12 16:42:31 +0000803
804 if (m_interpreter.TruncationWarningNecessary())
805 {
806 result.GetOutputStream().Printf(m_interpreter.TruncationWarningText(),
807 m_cmd_name.c_str());
808 m_interpreter.TruncationWarningGiven();
809 }
810
Greg Clayton801417e2011-07-07 01:59:51 +0000811 return result.Succeeded();
812 }
813
814 Options *
815 GetOptions ()
816 {
817 return &m_option_group;
818 }
819
820protected:
821 OptionGroupOptions m_option_group;
Greg Clayton368f8222011-07-07 04:38:25 +0000822 OptionGroupVariable m_option_variable;
Greg Claytona42880a2011-10-25 06:44:01 +0000823 OptionGroupFormat m_option_format;
Greg Clayton801417e2011-07-07 01:59:51 +0000824 OptionGroupFileList m_option_compile_units;
825 OptionGroupFileList m_option_shared_libraries;
826 OptionGroupValueObjectDisplay m_varobj_options;
827
828};
829
830
Greg Claytone1f50b92011-05-03 22:09:39 +0000831#pragma mark CommandObjectTargetModulesSearchPathsAdd
Chris Lattner24943d22010-06-08 16:52:24 +0000832
Greg Claytone1f50b92011-05-03 22:09:39 +0000833class CommandObjectTargetModulesSearchPathsAdd : public CommandObject
Chris Lattner24943d22010-06-08 16:52:24 +0000834{
835public:
836
Greg Claytone1f50b92011-05-03 22:09:39 +0000837 CommandObjectTargetModulesSearchPathsAdd (CommandInterpreter &interpreter) :
Greg Clayton238c0a12010-09-18 01:14:36 +0000838 CommandObject (interpreter,
Greg Claytone1f50b92011-05-03 22:09:39 +0000839 "target modules search-paths add",
Chris Lattner24943d22010-06-08 16:52:24 +0000840 "Add new image search paths substitution pairs to the current target.",
Caroline Tice43b014a2010-10-04 22:28:36 +0000841 NULL)
Chris Lattner24943d22010-06-08 16:52:24 +0000842 {
Caroline Tice43b014a2010-10-04 22:28:36 +0000843 CommandArgumentEntry arg;
844 CommandArgumentData old_prefix_arg;
845 CommandArgumentData new_prefix_arg;
846
847 // Define the first variant of this arg pair.
848 old_prefix_arg.arg_type = eArgTypeOldPathPrefix;
849 old_prefix_arg.arg_repetition = eArgRepeatPairPlus;
850
851 // Define the first variant of this arg pair.
852 new_prefix_arg.arg_type = eArgTypeNewPathPrefix;
853 new_prefix_arg.arg_repetition = eArgRepeatPairPlus;
854
855 // There are two required arguments that must always occur together, i.e. an argument "pair". Because they
856 // must always occur together, they are treated as two variants of one argument rather than two independent
857 // arguments. Push them both into the first argument position for m_arguments...
858
859 arg.push_back (old_prefix_arg);
860 arg.push_back (new_prefix_arg);
861
862 m_arguments.push_back (arg);
Chris Lattner24943d22010-06-08 16:52:24 +0000863 }
864
Greg Claytone1f50b92011-05-03 22:09:39 +0000865 ~CommandObjectTargetModulesSearchPathsAdd ()
Chris Lattner24943d22010-06-08 16:52:24 +0000866 {
867 }
868
869 bool
Greg Clayton238c0a12010-09-18 01:14:36 +0000870 Execute (Args& command,
Chris Lattner24943d22010-06-08 16:52:24 +0000871 CommandReturnObject &result)
872 {
Greg Clayton238c0a12010-09-18 01:14:36 +0000873 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Chris Lattner24943d22010-06-08 16:52:24 +0000874 if (target)
875 {
876 uint32_t argc = command.GetArgumentCount();
877 if (argc & 1)
878 {
Greg Claytonabe0fed2011-04-18 08:33:37 +0000879 result.AppendError ("add requires an even number of arguments\n");
Chris Lattner24943d22010-06-08 16:52:24 +0000880 result.SetStatus (eReturnStatusFailed);
881 }
882 else
883 {
884 for (uint32_t i=0; i<argc; i+=2)
885 {
886 const char *from = command.GetArgumentAtIndex(i);
887 const char *to = command.GetArgumentAtIndex(i+1);
888
889 if (from[0] && to[0])
890 {
891 bool last_pair = ((argc - i) == 2);
Greg Clayton63094e02010-06-23 01:19:29 +0000892 target->GetImageSearchPathList().Append (ConstString(from),
893 ConstString(to),
894 last_pair); // Notify if this is the last pair
Johnny Chen4d661352011-02-03 00:30:19 +0000895 result.SetStatus (eReturnStatusSuccessFinishNoResult);
Chris Lattner24943d22010-06-08 16:52:24 +0000896 }
897 else
898 {
899 if (from[0])
Greg Claytonabe0fed2011-04-18 08:33:37 +0000900 result.AppendError ("<path-prefix> can't be empty\n");
Chris Lattner24943d22010-06-08 16:52:24 +0000901 else
Greg Claytonabe0fed2011-04-18 08:33:37 +0000902 result.AppendError ("<new-path-prefix> can't be empty\n");
Chris Lattner24943d22010-06-08 16:52:24 +0000903 result.SetStatus (eReturnStatusFailed);
904 }
905 }
906 }
907 }
908 else
909 {
Greg Claytonabe0fed2011-04-18 08:33:37 +0000910 result.AppendError ("invalid target\n");
Chris Lattner24943d22010-06-08 16:52:24 +0000911 result.SetStatus (eReturnStatusFailed);
912 }
913 return result.Succeeded();
914 }
915};
916
Greg Claytone1f50b92011-05-03 22:09:39 +0000917#pragma mark CommandObjectTargetModulesSearchPathsClear
918
919class CommandObjectTargetModulesSearchPathsClear : public CommandObject
Chris Lattner24943d22010-06-08 16:52:24 +0000920{
921public:
922
Greg Claytone1f50b92011-05-03 22:09:39 +0000923 CommandObjectTargetModulesSearchPathsClear (CommandInterpreter &interpreter) :
Greg Clayton238c0a12010-09-18 01:14:36 +0000924 CommandObject (interpreter,
Greg Claytone1f50b92011-05-03 22:09:39 +0000925 "target modules search-paths clear",
Caroline Ticeabb507a2010-09-08 21:06:11 +0000926 "Clear all current image search path substitution pairs from the current target.",
Greg Claytone1f50b92011-05-03 22:09:39 +0000927 "target modules search-paths clear")
Chris Lattner24943d22010-06-08 16:52:24 +0000928 {
929 }
930
Greg Claytone1f50b92011-05-03 22:09:39 +0000931 ~CommandObjectTargetModulesSearchPathsClear ()
Chris Lattner24943d22010-06-08 16:52:24 +0000932 {
933 }
934
935 bool
Greg Clayton238c0a12010-09-18 01:14:36 +0000936 Execute (Args& command,
Chris Lattner24943d22010-06-08 16:52:24 +0000937 CommandReturnObject &result)
938 {
Greg Clayton238c0a12010-09-18 01:14:36 +0000939 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Chris Lattner24943d22010-06-08 16:52:24 +0000940 if (target)
941 {
942 bool notify = true;
943 target->GetImageSearchPathList().Clear(notify);
Johnny Chen4d661352011-02-03 00:30:19 +0000944 result.SetStatus (eReturnStatusSuccessFinishNoResult);
Chris Lattner24943d22010-06-08 16:52:24 +0000945 }
946 else
947 {
Greg Claytonabe0fed2011-04-18 08:33:37 +0000948 result.AppendError ("invalid target\n");
Chris Lattner24943d22010-06-08 16:52:24 +0000949 result.SetStatus (eReturnStatusFailed);
950 }
951 return result.Succeeded();
952 }
953};
954
Greg Claytone1f50b92011-05-03 22:09:39 +0000955#pragma mark CommandObjectTargetModulesSearchPathsInsert
956
957class CommandObjectTargetModulesSearchPathsInsert : public CommandObject
Chris Lattner24943d22010-06-08 16:52:24 +0000958{
959public:
960
Greg Claytone1f50b92011-05-03 22:09:39 +0000961 CommandObjectTargetModulesSearchPathsInsert (CommandInterpreter &interpreter) :
Greg Clayton238c0a12010-09-18 01:14:36 +0000962 CommandObject (interpreter,
Greg Claytone1f50b92011-05-03 22:09:39 +0000963 "target modules search-paths insert",
Caroline Ticeabb507a2010-09-08 21:06:11 +0000964 "Insert a new image search path substitution pair into the current target at the specified index.",
Caroline Tice43b014a2010-10-04 22:28:36 +0000965 NULL)
Chris Lattner24943d22010-06-08 16:52:24 +0000966 {
Caroline Tice43b014a2010-10-04 22:28:36 +0000967 CommandArgumentEntry arg1;
968 CommandArgumentEntry arg2;
969 CommandArgumentData index_arg;
970 CommandArgumentData old_prefix_arg;
971 CommandArgumentData new_prefix_arg;
972
973 // Define the first and only variant of this arg.
974 index_arg.arg_type = eArgTypeIndex;
975 index_arg.arg_repetition = eArgRepeatPlain;
976
977 // Put the one and only variant into the first arg for m_arguments:
978 arg1.push_back (index_arg);
979
980 // Define the first variant of this arg pair.
981 old_prefix_arg.arg_type = eArgTypeOldPathPrefix;
982 old_prefix_arg.arg_repetition = eArgRepeatPairPlus;
983
984 // Define the first variant of this arg pair.
985 new_prefix_arg.arg_type = eArgTypeNewPathPrefix;
986 new_prefix_arg.arg_repetition = eArgRepeatPairPlus;
987
988 // There are two required arguments that must always occur together, i.e. an argument "pair". Because they
989 // must always occur together, they are treated as two variants of one argument rather than two independent
990 // arguments. Push them both into the same argument position for m_arguments...
991
992 arg2.push_back (old_prefix_arg);
993 arg2.push_back (new_prefix_arg);
994
995 // Add arguments to m_arguments.
996 m_arguments.push_back (arg1);
997 m_arguments.push_back (arg2);
Chris Lattner24943d22010-06-08 16:52:24 +0000998 }
999
Greg Claytone1f50b92011-05-03 22:09:39 +00001000 ~CommandObjectTargetModulesSearchPathsInsert ()
Chris Lattner24943d22010-06-08 16:52:24 +00001001 {
1002 }
1003
1004 bool
Greg Clayton238c0a12010-09-18 01:14:36 +00001005 Execute (Args& command,
Chris Lattner24943d22010-06-08 16:52:24 +00001006 CommandReturnObject &result)
1007 {
Greg Clayton238c0a12010-09-18 01:14:36 +00001008 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Chris Lattner24943d22010-06-08 16:52:24 +00001009 if (target)
1010 {
1011 uint32_t argc = command.GetArgumentCount();
1012 // check for at least 3 arguments and an odd nubmer of parameters
1013 if (argc >= 3 && argc & 1)
1014 {
1015 bool success = false;
1016
1017 uint32_t insert_idx = Args::StringToUInt32(command.GetArgumentAtIndex(0), UINT32_MAX, 0, &success);
1018
1019 if (!success)
1020 {
1021 result.AppendErrorWithFormat("<index> parameter is not an integer: '%s'.\n", command.GetArgumentAtIndex(0));
1022 result.SetStatus (eReturnStatusFailed);
1023 return result.Succeeded();
1024 }
1025
1026 // shift off the index
1027 command.Shift();
1028 argc = command.GetArgumentCount();
1029
1030 for (uint32_t i=0; i<argc; i+=2, ++insert_idx)
1031 {
1032 const char *from = command.GetArgumentAtIndex(i);
1033 const char *to = command.GetArgumentAtIndex(i+1);
1034
1035 if (from[0] && to[0])
1036 {
1037 bool last_pair = ((argc - i) == 2);
1038 target->GetImageSearchPathList().Insert (ConstString(from),
1039 ConstString(to),
1040 insert_idx,
1041 last_pair);
Johnny Chen4d661352011-02-03 00:30:19 +00001042 result.SetStatus (eReturnStatusSuccessFinishNoResult);
Chris Lattner24943d22010-06-08 16:52:24 +00001043 }
1044 else
1045 {
1046 if (from[0])
Greg Claytonabe0fed2011-04-18 08:33:37 +00001047 result.AppendError ("<path-prefix> can't be empty\n");
Chris Lattner24943d22010-06-08 16:52:24 +00001048 else
Greg Claytonabe0fed2011-04-18 08:33:37 +00001049 result.AppendError ("<new-path-prefix> can't be empty\n");
Chris Lattner24943d22010-06-08 16:52:24 +00001050 result.SetStatus (eReturnStatusFailed);
1051 return false;
1052 }
1053 }
1054 }
1055 else
1056 {
Greg Claytonabe0fed2011-04-18 08:33:37 +00001057 result.AppendError ("insert requires at least three arguments\n");
Chris Lattner24943d22010-06-08 16:52:24 +00001058 result.SetStatus (eReturnStatusFailed);
1059 return result.Succeeded();
1060 }
1061
1062 }
1063 else
1064 {
Greg Claytonabe0fed2011-04-18 08:33:37 +00001065 result.AppendError ("invalid target\n");
Chris Lattner24943d22010-06-08 16:52:24 +00001066 result.SetStatus (eReturnStatusFailed);
1067 }
1068 return result.Succeeded();
1069 }
1070};
1071
Greg Claytone1f50b92011-05-03 22:09:39 +00001072
1073#pragma mark CommandObjectTargetModulesSearchPathsList
1074
1075
1076class CommandObjectTargetModulesSearchPathsList : public CommandObject
Chris Lattner24943d22010-06-08 16:52:24 +00001077{
1078public:
1079
Greg Claytone1f50b92011-05-03 22:09:39 +00001080 CommandObjectTargetModulesSearchPathsList (CommandInterpreter &interpreter) :
Greg Clayton238c0a12010-09-18 01:14:36 +00001081 CommandObject (interpreter,
Greg Claytone1f50b92011-05-03 22:09:39 +00001082 "target modules search-paths list",
Caroline Ticeabb507a2010-09-08 21:06:11 +00001083 "List all current image search path substitution pairs in the current target.",
Greg Claytone1f50b92011-05-03 22:09:39 +00001084 "target modules search-paths list")
Chris Lattner24943d22010-06-08 16:52:24 +00001085 {
1086 }
1087
Greg Claytone1f50b92011-05-03 22:09:39 +00001088 ~CommandObjectTargetModulesSearchPathsList ()
Chris Lattner24943d22010-06-08 16:52:24 +00001089 {
1090 }
1091
1092 bool
Greg Clayton238c0a12010-09-18 01:14:36 +00001093 Execute (Args& command,
Chris Lattner24943d22010-06-08 16:52:24 +00001094 CommandReturnObject &result)
1095 {
Greg Clayton238c0a12010-09-18 01:14:36 +00001096 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Chris Lattner24943d22010-06-08 16:52:24 +00001097 if (target)
1098 {
1099 if (command.GetArgumentCount() != 0)
1100 {
Greg Claytonabe0fed2011-04-18 08:33:37 +00001101 result.AppendError ("list takes no arguments\n");
Chris Lattner24943d22010-06-08 16:52:24 +00001102 result.SetStatus (eReturnStatusFailed);
1103 return result.Succeeded();
1104 }
1105
1106 target->GetImageSearchPathList().Dump(&result.GetOutputStream());
Johnny Chen4d661352011-02-03 00:30:19 +00001107 result.SetStatus (eReturnStatusSuccessFinishResult);
Chris Lattner24943d22010-06-08 16:52:24 +00001108 }
1109 else
1110 {
Greg Claytonabe0fed2011-04-18 08:33:37 +00001111 result.AppendError ("invalid target\n");
Chris Lattner24943d22010-06-08 16:52:24 +00001112 result.SetStatus (eReturnStatusFailed);
1113 }
1114 return result.Succeeded();
1115 }
1116};
1117
Greg Claytone1f50b92011-05-03 22:09:39 +00001118#pragma mark CommandObjectTargetModulesSearchPathsQuery
1119
1120class CommandObjectTargetModulesSearchPathsQuery : public CommandObject
Chris Lattner24943d22010-06-08 16:52:24 +00001121{
1122public:
1123
Greg Claytone1f50b92011-05-03 22:09:39 +00001124 CommandObjectTargetModulesSearchPathsQuery (CommandInterpreter &interpreter) :
Greg Clayton238c0a12010-09-18 01:14:36 +00001125 CommandObject (interpreter,
Greg Claytone1f50b92011-05-03 22:09:39 +00001126 "target modules search-paths query",
Caroline Ticeabb507a2010-09-08 21:06:11 +00001127 "Transform a path using the first applicable image search path.",
Caroline Tice43b014a2010-10-04 22:28:36 +00001128 NULL)
Chris Lattner24943d22010-06-08 16:52:24 +00001129 {
Caroline Tice43b014a2010-10-04 22:28:36 +00001130 CommandArgumentEntry arg;
1131 CommandArgumentData path_arg;
1132
1133 // Define the first (and only) variant of this arg.
1134 path_arg.arg_type = eArgTypePath;
1135 path_arg.arg_repetition = eArgRepeatPlain;
1136
1137 // There is only one variant this argument could be; put it into the argument entry.
1138 arg.push_back (path_arg);
1139
1140 // Push the data for the first argument into the m_arguments vector.
1141 m_arguments.push_back (arg);
Chris Lattner24943d22010-06-08 16:52:24 +00001142 }
1143
Greg Claytone1f50b92011-05-03 22:09:39 +00001144 ~CommandObjectTargetModulesSearchPathsQuery ()
Chris Lattner24943d22010-06-08 16:52:24 +00001145 {
1146 }
1147
1148 bool
Greg Clayton238c0a12010-09-18 01:14:36 +00001149 Execute (Args& command,
Chris Lattner24943d22010-06-08 16:52:24 +00001150 CommandReturnObject &result)
1151 {
Greg Clayton238c0a12010-09-18 01:14:36 +00001152 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Chris Lattner24943d22010-06-08 16:52:24 +00001153 if (target)
1154 {
1155 if (command.GetArgumentCount() != 1)
1156 {
Greg Claytonabe0fed2011-04-18 08:33:37 +00001157 result.AppendError ("query requires one argument\n");
Chris Lattner24943d22010-06-08 16:52:24 +00001158 result.SetStatus (eReturnStatusFailed);
1159 return result.Succeeded();
1160 }
1161
1162 ConstString orig(command.GetArgumentAtIndex(0));
1163 ConstString transformed;
1164 if (target->GetImageSearchPathList().RemapPath(orig, transformed))
1165 result.GetOutputStream().Printf("%s\n", transformed.GetCString());
1166 else
1167 result.GetOutputStream().Printf("%s\n", orig.GetCString());
Johnny Chen4d661352011-02-03 00:30:19 +00001168
1169 result.SetStatus (eReturnStatusSuccessFinishResult);
Chris Lattner24943d22010-06-08 16:52:24 +00001170 }
1171 else
1172 {
Greg Claytonabe0fed2011-04-18 08:33:37 +00001173 result.AppendError ("invalid target\n");
Chris Lattner24943d22010-06-08 16:52:24 +00001174 result.SetStatus (eReturnStatusFailed);
1175 }
1176 return result.Succeeded();
1177 }
1178};
1179
Greg Claytone1f50b92011-05-03 22:09:39 +00001180//----------------------------------------------------------------------
1181// Static Helper functions
1182//----------------------------------------------------------------------
1183static void
1184DumpModuleArchitecture (Stream &strm, Module *module, bool full_triple, uint32_t width)
1185{
1186 if (module)
1187 {
1188 const char *arch_cstr;
1189 if (full_triple)
1190 arch_cstr = module->GetArchitecture().GetTriple().str().c_str();
1191 else
1192 arch_cstr = module->GetArchitecture().GetArchitectureName();
1193 if (width)
1194 strm.Printf("%-*s", width, arch_cstr);
1195 else
1196 strm.PutCString(arch_cstr);
1197 }
1198}
1199
1200static void
1201DumpModuleUUID (Stream &strm, Module *module)
1202{
Greg Clayton153ccd72011-08-10 02:10:13 +00001203 if (module->GetUUID().IsValid())
1204 module->GetUUID().Dump (&strm);
1205 else
1206 strm.PutCString(" ");
Greg Claytone1f50b92011-05-03 22:09:39 +00001207}
1208
1209static uint32_t
1210DumpCompileUnitLineTable
1211(
1212 CommandInterpreter &interpreter,
1213 Stream &strm,
1214 Module *module,
1215 const FileSpec &file_spec,
1216 bool load_addresses
1217 )
1218{
1219 uint32_t num_matches = 0;
1220 if (module)
1221 {
1222 SymbolContextList sc_list;
1223 num_matches = module->ResolveSymbolContextsForFileSpec (file_spec,
1224 0,
1225 false,
1226 eSymbolContextCompUnit,
1227 sc_list);
1228
1229 for (uint32_t i=0; i<num_matches; ++i)
1230 {
1231 SymbolContext sc;
1232 if (sc_list.GetContextAtIndex(i, sc))
1233 {
1234 if (i > 0)
1235 strm << "\n\n";
1236
1237 strm << "Line table for " << *static_cast<FileSpec*> (sc.comp_unit) << " in `"
1238 << module->GetFileSpec().GetFilename() << "\n";
1239 LineTable *line_table = sc.comp_unit->GetLineTable();
1240 if (line_table)
1241 line_table->GetDescription (&strm,
Greg Clayton567e7f32011-09-22 04:58:26 +00001242 interpreter.GetExecutionContext().GetTargetPtr(),
Greg Claytone1f50b92011-05-03 22:09:39 +00001243 lldb::eDescriptionLevelBrief);
1244 else
1245 strm << "No line table";
1246 }
1247 }
1248 }
1249 return num_matches;
1250}
1251
1252static void
1253DumpFullpath (Stream &strm, const FileSpec *file_spec_ptr, uint32_t width)
1254{
1255 if (file_spec_ptr)
1256 {
1257 if (width > 0)
1258 {
1259 char fullpath[PATH_MAX];
1260 if (file_spec_ptr->GetPath(fullpath, sizeof(fullpath)))
1261 {
1262 strm.Printf("%-*s", width, fullpath);
1263 return;
1264 }
1265 }
1266 else
1267 {
1268 file_spec_ptr->Dump(&strm);
1269 return;
1270 }
1271 }
1272 // Keep the width spacing correct if things go wrong...
1273 if (width > 0)
1274 strm.Printf("%-*s", width, "");
1275}
1276
1277static void
1278DumpDirectory (Stream &strm, const FileSpec *file_spec_ptr, uint32_t width)
1279{
1280 if (file_spec_ptr)
1281 {
1282 if (width > 0)
1283 strm.Printf("%-*s", width, file_spec_ptr->GetDirectory().AsCString(""));
1284 else
1285 file_spec_ptr->GetDirectory().Dump(&strm);
1286 return;
1287 }
1288 // Keep the width spacing correct if things go wrong...
1289 if (width > 0)
1290 strm.Printf("%-*s", width, "");
1291}
1292
1293static void
1294DumpBasename (Stream &strm, const FileSpec *file_spec_ptr, uint32_t width)
1295{
1296 if (file_spec_ptr)
1297 {
1298 if (width > 0)
1299 strm.Printf("%-*s", width, file_spec_ptr->GetFilename().AsCString(""));
1300 else
1301 file_spec_ptr->GetFilename().Dump(&strm);
1302 return;
1303 }
1304 // Keep the width spacing correct if things go wrong...
1305 if (width > 0)
1306 strm.Printf("%-*s", width, "");
1307}
1308
1309
1310static void
1311DumpModuleSymtab (CommandInterpreter &interpreter, Stream &strm, Module *module, SortOrder sort_order)
1312{
1313 if (module)
1314 {
1315 ObjectFile *objfile = module->GetObjectFile ();
1316 if (objfile)
1317 {
1318 Symtab *symtab = objfile->GetSymtab();
1319 if (symtab)
Greg Clayton567e7f32011-09-22 04:58:26 +00001320 symtab->Dump(&strm, interpreter.GetExecutionContext().GetTargetPtr(), sort_order);
Greg Claytone1f50b92011-05-03 22:09:39 +00001321 }
1322 }
1323}
1324
1325static void
1326DumpModuleSections (CommandInterpreter &interpreter, Stream &strm, Module *module)
1327{
1328 if (module)
1329 {
1330 ObjectFile *objfile = module->GetObjectFile ();
1331 if (objfile)
1332 {
1333 SectionList *section_list = objfile->GetSectionList();
1334 if (section_list)
1335 {
1336 strm.PutCString ("Sections for '");
1337 strm << module->GetFileSpec();
1338 if (module->GetObjectName())
1339 strm << '(' << module->GetObjectName() << ')';
1340 strm.Printf ("' (%s):\n", module->GetArchitecture().GetArchitectureName());
1341 strm.IndentMore();
Greg Clayton567e7f32011-09-22 04:58:26 +00001342 section_list->Dump(&strm, interpreter.GetExecutionContext().GetTargetPtr(), true, UINT32_MAX);
Greg Claytone1f50b92011-05-03 22:09:39 +00001343 strm.IndentLess();
1344 }
1345 }
1346 }
1347}
1348
1349static bool
1350DumpModuleSymbolVendor (Stream &strm, Module *module)
1351{
1352 if (module)
1353 {
1354 SymbolVendor *symbol_vendor = module->GetSymbolVendor(true);
1355 if (symbol_vendor)
1356 {
1357 symbol_vendor->Dump(&strm);
1358 return true;
1359 }
1360 }
1361 return false;
1362}
1363
Greg Clayton2ad894b2012-05-15 18:43:44 +00001364static void
1365DumpAddress (ExecutionContextScope *exe_scope, const Address &so_addr, bool verbose, Stream &strm)
1366{
1367 strm.IndentMore();
1368 strm.Indent (" Address: ");
1369 so_addr.Dump (&strm, exe_scope, Address::DumpStyleModuleWithFileAddress);
1370 strm.PutCString (" (");
1371 so_addr.Dump (&strm, exe_scope, Address::DumpStyleSectionNameOffset);
1372 strm.PutCString (")\n");
1373 strm.Indent (" Summary: ");
1374 const uint32_t save_indent = strm.GetIndentLevel ();
1375 strm.SetIndentLevel (save_indent + 13);
1376 so_addr.Dump (&strm, exe_scope, Address::DumpStyleResolvedDescription);
1377 strm.SetIndentLevel (save_indent);
1378 // Print out detailed address information when verbose is enabled
1379 if (verbose)
1380 {
1381 strm.EOL();
1382 so_addr.Dump (&strm, exe_scope, Address::DumpStyleDetailedSymbolContext);
1383 }
1384 strm.IndentLess();
1385}
1386
Greg Claytone1f50b92011-05-03 22:09:39 +00001387static bool
Greg Clayton3508c382012-02-24 01:59:29 +00001388LookupAddressInModule (CommandInterpreter &interpreter,
1389 Stream &strm,
1390 Module *module,
1391 uint32_t resolve_mask,
1392 lldb::addr_t raw_addr,
1393 lldb::addr_t offset,
1394 bool verbose)
Greg Claytone1f50b92011-05-03 22:09:39 +00001395{
1396 if (module)
1397 {
1398 lldb::addr_t addr = raw_addr - offset;
1399 Address so_addr;
1400 SymbolContext sc;
Greg Clayton567e7f32011-09-22 04:58:26 +00001401 Target *target = interpreter.GetExecutionContext().GetTargetPtr();
Greg Claytone1f50b92011-05-03 22:09:39 +00001402 if (target && !target->GetSectionLoadList().IsEmpty())
1403 {
1404 if (!target->GetSectionLoadList().ResolveLoadAddress (addr, so_addr))
1405 return false;
Greg Clayton3508c382012-02-24 01:59:29 +00001406 else if (so_addr.GetModule().get() != module)
Greg Claytone1f50b92011-05-03 22:09:39 +00001407 return false;
1408 }
1409 else
1410 {
1411 if (!module->ResolveFileAddress (addr, so_addr))
1412 return false;
1413 }
1414
Greg Claytone1f50b92011-05-03 22:09:39 +00001415 ExecutionContextScope *exe_scope = interpreter.GetExecutionContext().GetBestExecutionContextScope();
Greg Clayton2ad894b2012-05-15 18:43:44 +00001416 DumpAddress (exe_scope, so_addr, verbose, strm);
1417// strm.IndentMore();
1418// strm.Indent (" Address: ");
1419// so_addr.Dump (&strm, exe_scope, Address::DumpStyleModuleWithFileAddress);
1420// strm.PutCString (" (");
1421// so_addr.Dump (&strm, exe_scope, Address::DumpStyleSectionNameOffset);
1422// strm.PutCString (")\n");
1423// strm.Indent (" Summary: ");
1424// const uint32_t save_indent = strm.GetIndentLevel ();
1425// strm.SetIndentLevel (save_indent + 13);
1426// so_addr.Dump (&strm, exe_scope, Address::DumpStyleResolvedDescription);
1427// strm.SetIndentLevel (save_indent);
1428// // Print out detailed address information when verbose is enabled
1429// if (verbose)
1430// {
1431// strm.EOL();
1432// so_addr.Dump (&strm, exe_scope, Address::DumpStyleDetailedSymbolContext);
1433// }
1434// strm.IndentLess();
Greg Claytone1f50b92011-05-03 22:09:39 +00001435 return true;
1436 }
1437
1438 return false;
1439}
1440
1441static uint32_t
Greg Clayton2ad894b2012-05-15 18:43:44 +00001442LookupSymbolInModule (CommandInterpreter &interpreter, Stream &strm, Module *module, const char *name, bool name_is_regex, bool verbose)
Greg Claytone1f50b92011-05-03 22:09:39 +00001443{
1444 if (module)
1445 {
1446 SymbolContext sc;
1447
1448 ObjectFile *objfile = module->GetObjectFile ();
1449 if (objfile)
1450 {
1451 Symtab *symtab = objfile->GetSymtab();
1452 if (symtab)
1453 {
1454 uint32_t i;
1455 std::vector<uint32_t> match_indexes;
1456 ConstString symbol_name (name);
1457 uint32_t num_matches = 0;
1458 if (name_is_regex)
1459 {
1460 RegularExpression name_regexp(name);
1461 num_matches = symtab->AppendSymbolIndexesMatchingRegExAndType (name_regexp,
1462 eSymbolTypeAny,
1463 match_indexes);
1464 }
1465 else
1466 {
1467 num_matches = symtab->AppendSymbolIndexesWithName (symbol_name, match_indexes);
1468 }
1469
1470
1471 if (num_matches > 0)
1472 {
1473 strm.Indent ();
1474 strm.Printf("%u symbols match %s'%s' in ", num_matches,
1475 name_is_regex ? "the regular expression " : "", name);
1476 DumpFullpath (strm, &module->GetFileSpec(), 0);
1477 strm.PutCString(":\n");
1478 strm.IndentMore ();
Greg Clayton2ad894b2012-05-15 18:43:44 +00001479 //Symtab::DumpSymbolHeader (&strm);
Greg Claytone1f50b92011-05-03 22:09:39 +00001480 for (i=0; i < num_matches; ++i)
1481 {
1482 Symbol *symbol = symtab->SymbolAtIndex(match_indexes[i]);
Greg Clayton2ad894b2012-05-15 18:43:44 +00001483 DumpAddress (interpreter.GetExecutionContext().GetBestExecutionContextScope(),
1484 symbol->GetAddress(),
1485 verbose,
1486 strm);
1487
1488// strm.Indent ();
1489// symbol->Dump (&strm, interpreter.GetExecutionContext().GetTargetPtr(), i);
Greg Claytone1f50b92011-05-03 22:09:39 +00001490 }
1491 strm.IndentLess ();
1492 return num_matches;
1493 }
1494 }
1495 }
1496 }
1497 return 0;
1498}
1499
1500
1501static void
Greg Clayton2ad894b2012-05-15 18:43:44 +00001502DumpSymbolContextList (ExecutionContextScope *exe_scope, Stream &strm, SymbolContextList &sc_list, bool verbose)
Greg Claytone1f50b92011-05-03 22:09:39 +00001503{
1504 strm.IndentMore ();
1505 uint32_t i;
1506 const uint32_t num_matches = sc_list.GetSize();
1507
1508 for (i=0; i<num_matches; ++i)
1509 {
1510 SymbolContext sc;
1511 if (sc_list.GetContextAtIndex(i, sc))
1512 {
Sean Callanand7793d22012-02-11 00:24:04 +00001513 AddressRange range;
1514
1515 sc.GetAddressRange(eSymbolContextEverything,
1516 0,
1517 true,
1518 range);
1519
Greg Clayton2ad894b2012-05-15 18:43:44 +00001520 DumpAddress (exe_scope, range.GetBaseAddress(), verbose, strm);
Greg Claytone1f50b92011-05-03 22:09:39 +00001521 }
1522 }
1523 strm.IndentLess ();
1524}
1525
1526static uint32_t
Greg Clayton2ad894b2012-05-15 18:43:44 +00001527LookupFunctionInModule (CommandInterpreter &interpreter,
1528 Stream &strm,
1529 Module *module,
1530 const char *name,
1531 bool name_is_regex,
1532 bool include_inlines,
1533 bool include_symbols,
1534 bool verbose)
Greg Claytone1f50b92011-05-03 22:09:39 +00001535{
1536 if (module && name && name[0])
1537 {
1538 SymbolContextList sc_list;
Greg Claytone1f50b92011-05-03 22:09:39 +00001539 const bool append = true;
1540 uint32_t num_matches = 0;
1541 if (name_is_regex)
1542 {
1543 RegularExpression function_name_regex (name);
1544 num_matches = module->FindFunctions (function_name_regex,
1545 include_symbols,
Sean Callanan302d78c2012-02-10 22:52:19 +00001546 include_inlines,
Greg Claytone1f50b92011-05-03 22:09:39 +00001547 append,
1548 sc_list);
1549 }
1550 else
1551 {
1552 ConstString function_name (name);
Sean Callanan3e80cd92011-10-12 02:08:07 +00001553 num_matches = module->FindFunctions (function_name,
1554 NULL,
Greg Claytone1f50b92011-05-03 22:09:39 +00001555 eFunctionNameTypeBase | eFunctionNameTypeFull | eFunctionNameTypeMethod | eFunctionNameTypeSelector,
1556 include_symbols,
Sean Callanan302d78c2012-02-10 22:52:19 +00001557 include_inlines,
Greg Claytone1f50b92011-05-03 22:09:39 +00001558 append,
1559 sc_list);
1560 }
1561
1562 if (num_matches)
1563 {
1564 strm.Indent ();
1565 strm.Printf("%u match%s found in ", num_matches, num_matches > 1 ? "es" : "");
1566 DumpFullpath (strm, &module->GetFileSpec(), 0);
1567 strm.PutCString(":\n");
Greg Clayton2ad894b2012-05-15 18:43:44 +00001568 DumpSymbolContextList (interpreter.GetExecutionContext().GetBestExecutionContextScope(), strm, sc_list, verbose);
Greg Claytone1f50b92011-05-03 22:09:39 +00001569 }
1570 return num_matches;
1571 }
1572 return 0;
1573}
1574
1575static uint32_t
Greg Clayton0cbaacd2012-05-15 19:26:12 +00001576LookupTypeInModule (CommandInterpreter &interpreter,
Greg Clayton801417e2011-07-07 01:59:51 +00001577 Stream &strm,
1578 Module *module,
1579 const char *name_cstr,
1580 bool name_is_regex)
Greg Claytone1f50b92011-05-03 22:09:39 +00001581{
1582 if (module && name_cstr && name_cstr[0])
1583 {
Greg Clayton37bb8dd2011-12-08 02:13:16 +00001584 TypeList type_list;
Greg Claytondc0a38c2012-03-26 23:03:23 +00001585 const uint32_t max_num_matches = UINT32_MAX;
Greg Clayton37bb8dd2011-12-08 02:13:16 +00001586 uint32_t num_matches = 0;
Greg Claytondc0a38c2012-03-26 23:03:23 +00001587 bool name_is_fully_qualified = false;
Greg Clayton37bb8dd2011-12-08 02:13:16 +00001588 SymbolContext sc;
1589
1590 ConstString name(name_cstr);
Greg Claytondc0a38c2012-03-26 23:03:23 +00001591 num_matches = module->FindTypes(sc, name, name_is_fully_qualified, max_num_matches, type_list);
Greg Claytone1f50b92011-05-03 22:09:39 +00001592
Greg Clayton37bb8dd2011-12-08 02:13:16 +00001593 if (num_matches)
1594 {
1595 strm.Indent ();
1596 strm.Printf("%u match%s found in ", num_matches, num_matches > 1 ? "es" : "");
1597 DumpFullpath (strm, &module->GetFileSpec(), 0);
1598 strm.PutCString(":\n");
1599 const uint32_t num_types = type_list.GetSize();
1600 for (uint32_t i=0; i<num_types; ++i)
Greg Claytone1f50b92011-05-03 22:09:39 +00001601 {
Greg Clayton37bb8dd2011-12-08 02:13:16 +00001602 TypeSP type_sp (type_list.GetTypeAtIndex(i));
1603 if (type_sp)
Greg Claytone1f50b92011-05-03 22:09:39 +00001604 {
Greg Clayton37bb8dd2011-12-08 02:13:16 +00001605 // Resolve the clang type so that any forward references
1606 // to types that haven't yet been parsed will get parsed.
1607 type_sp->GetClangFullType ();
1608 type_sp->GetDescription (&strm, eDescriptionLevelFull, true);
Greg Clayton0cbaacd2012-05-15 19:26:12 +00001609 // Print all typedef chains
1610 TypeSP typedef_type_sp (type_sp);
1611 TypeSP typedefed_type_sp (typedef_type_sp->GetTypedefType());
1612 while (typedefed_type_sp)
1613 {
1614 strm.EOL();
1615 strm.Printf(" typedef '%s': ", typedef_type_sp->GetName().GetCString());
1616 typedefed_type_sp->GetClangFullType ();
1617 typedefed_type_sp->GetDescription (&strm, eDescriptionLevelFull, true);
1618 typedef_type_sp = typedefed_type_sp;
1619 typedefed_type_sp = typedef_type_sp->GetTypedefType();
1620 }
Greg Claytone1f50b92011-05-03 22:09:39 +00001621 }
Greg Clayton37bb8dd2011-12-08 02:13:16 +00001622 strm.EOL();
Greg Claytone1f50b92011-05-03 22:09:39 +00001623 }
Greg Clayton37bb8dd2011-12-08 02:13:16 +00001624 }
1625 return num_matches;
Greg Claytone1f50b92011-05-03 22:09:39 +00001626 }
1627 return 0;
1628}
1629
1630static uint32_t
1631LookupFileAndLineInModule (CommandInterpreter &interpreter,
1632 Stream &strm,
1633 Module *module,
1634 const FileSpec &file_spec,
1635 uint32_t line,
1636 bool check_inlines,
1637 bool verbose)
1638{
1639 if (module && file_spec)
1640 {
1641 SymbolContextList sc_list;
1642 const uint32_t num_matches = module->ResolveSymbolContextsForFileSpec(file_spec, line, check_inlines,
1643 eSymbolContextEverything, sc_list);
1644 if (num_matches > 0)
1645 {
1646 strm.Indent ();
1647 strm.Printf("%u match%s found in ", num_matches, num_matches > 1 ? "es" : "");
1648 strm << file_spec;
1649 if (line > 0)
1650 strm.Printf (":%u", line);
1651 strm << " in ";
1652 DumpFullpath (strm, &module->GetFileSpec(), 0);
1653 strm.PutCString(":\n");
Greg Clayton2ad894b2012-05-15 18:43:44 +00001654 DumpSymbolContextList (interpreter.GetExecutionContext().GetBestExecutionContextScope(), strm, sc_list, verbose);
Greg Claytone1f50b92011-05-03 22:09:39 +00001655 return num_matches;
1656 }
1657 }
1658 return 0;
1659
1660}
1661
Greg Clayton91048ef2011-11-10 01:18:58 +00001662
1663static size_t
1664FindModulesByName (Target *target,
1665 const char *module_name,
1666 ModuleList &module_list,
1667 bool check_global_list)
1668{
1669// Dump specified images (by basename or fullpath)
1670 FileSpec module_file_spec(module_name, false);
Greg Clayton444fe992012-02-26 05:51:37 +00001671 ModuleSpec module_spec (module_file_spec);
Greg Clayton91048ef2011-11-10 01:18:58 +00001672
1673 const size_t initial_size = module_list.GetSize ();
1674
1675 size_t num_matches = 0;
1676
1677 if (target)
1678 {
Greg Clayton444fe992012-02-26 05:51:37 +00001679 num_matches = target->GetImages().FindModules (module_spec, module_list);
Greg Clayton91048ef2011-11-10 01:18:58 +00001680
1681 // Not found in our module list for our target, check the main
1682 // shared module list in case it is a extra file used somewhere
1683 // else
1684 if (num_matches == 0)
Greg Clayton444fe992012-02-26 05:51:37 +00001685 {
1686 module_spec.GetArchitecture() = target->GetArchitecture();
1687 num_matches = ModuleList::FindSharedModules (module_spec, module_list);
1688 }
Greg Clayton91048ef2011-11-10 01:18:58 +00001689 }
1690 else
1691 {
Greg Clayton444fe992012-02-26 05:51:37 +00001692 num_matches = ModuleList::FindSharedModules (module_spec,module_list);
Greg Clayton91048ef2011-11-10 01:18:58 +00001693 }
1694
1695 if (check_global_list && num_matches == 0)
1696 {
1697 // Check the global list
Greg Claytonc149c8b2012-01-27 18:08:35 +00001698 Mutex::Locker locker(Module::GetAllocationModuleCollectionMutex());
Greg Clayton91048ef2011-11-10 01:18:58 +00001699 const uint32_t num_modules = Module::GetNumberAllocatedModules();
1700 ModuleSP module_sp;
1701 for (uint32_t image_idx = 0; image_idx<num_modules; ++image_idx)
1702 {
1703 Module *module = Module::GetAllocatedModuleAtIndex(image_idx);
1704
1705 if (module)
1706 {
Greg Clayton444fe992012-02-26 05:51:37 +00001707 if (module->MatchesModuleSpec (module_spec))
Greg Clayton91048ef2011-11-10 01:18:58 +00001708 {
Greg Clayton13d24fb2012-01-29 20:56:30 +00001709 module_sp = module->shared_from_this();
Greg Clayton91048ef2011-11-10 01:18:58 +00001710 module_list.AppendIfNeeded(module_sp);
1711 }
1712 }
1713 }
1714 }
1715 return module_list.GetSize () - initial_size;
1716}
1717
Greg Claytone1f50b92011-05-03 22:09:39 +00001718#pragma mark CommandObjectTargetModulesModuleAutoComplete
1719
1720//----------------------------------------------------------------------
1721// A base command object class that can auto complete with module file
1722// paths
1723//----------------------------------------------------------------------
1724
1725class CommandObjectTargetModulesModuleAutoComplete : public CommandObject
1726{
1727public:
1728
1729 CommandObjectTargetModulesModuleAutoComplete (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 file_arg;
1737
1738 // Define the first (and only) variant of this arg.
1739 file_arg.arg_type = eArgTypeFilename;
1740 file_arg.arg_repetition = eArgRepeatStar;
1741
1742 // There is only one variant this argument could be; put it into the argument entry.
1743 arg.push_back (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 ~CommandObjectTargetModulesModuleAutoComplete ()
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 module 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::eModuleCompletion,
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#pragma mark CommandObjectTargetModulesSourceFileAutoComplete
1781
1782//----------------------------------------------------------------------
1783// A base command object class that can auto complete with module source
1784// file paths
1785//----------------------------------------------------------------------
1786
1787class CommandObjectTargetModulesSourceFileAutoComplete : public CommandObject
1788{
1789public:
1790
1791 CommandObjectTargetModulesSourceFileAutoComplete (CommandInterpreter &interpreter,
1792 const char *name,
1793 const char *help,
1794 const char *syntax) :
1795 CommandObject (interpreter, name, help, syntax)
1796 {
1797 CommandArgumentEntry arg;
1798 CommandArgumentData source_file_arg;
1799
1800 // Define the first (and only) variant of this arg.
1801 source_file_arg.arg_type = eArgTypeSourceFile;
1802 source_file_arg.arg_repetition = eArgRepeatPlus;
1803
1804 // There is only one variant this argument could be; put it into the argument entry.
1805 arg.push_back (source_file_arg);
1806
1807 // Push the data for the first argument into the m_arguments vector.
1808 m_arguments.push_back (arg);
1809 }
1810
1811 virtual
1812 ~CommandObjectTargetModulesSourceFileAutoComplete ()
1813 {
1814 }
1815
1816 virtual int
1817 HandleArgumentCompletion (Args &input,
1818 int &cursor_index,
1819 int &cursor_char_position,
1820 OptionElementVector &opt_element_vector,
1821 int match_start_point,
1822 int max_return_elements,
1823 bool &word_complete,
1824 StringList &matches)
1825 {
1826 // Arguments are the standard source file completer.
1827 std::string completion_str (input.GetArgumentAtIndex(cursor_index));
1828 completion_str.erase (cursor_char_position);
1829
1830 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
1831 CommandCompletions::eSourceFileCompletion,
1832 completion_str.c_str(),
1833 match_start_point,
1834 max_return_elements,
1835 NULL,
1836 word_complete,
1837 matches);
1838 return matches.GetSize();
1839 }
1840};
1841
1842
1843#pragma mark CommandObjectTargetModulesDumpSymtab
1844
1845
1846class CommandObjectTargetModulesDumpSymtab : public CommandObjectTargetModulesModuleAutoComplete
1847{
1848public:
1849 CommandObjectTargetModulesDumpSymtab (CommandInterpreter &interpreter) :
1850 CommandObjectTargetModulesModuleAutoComplete (interpreter,
1851 "target modules dump symtab",
1852 "Dump the symbol table from one or more target modules.",
1853 NULL),
1854 m_options (interpreter)
1855 {
1856 }
1857
1858 virtual
1859 ~CommandObjectTargetModulesDumpSymtab ()
1860 {
1861 }
1862
1863 virtual bool
1864 Execute (Args& command,
1865 CommandReturnObject &result)
1866 {
1867 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
1868 if (target == NULL)
1869 {
1870 result.AppendError ("invalid target, create a debug target using the 'target create' command");
1871 result.SetStatus (eReturnStatusFailed);
1872 return false;
1873 }
1874 else
1875 {
1876 uint32_t num_dumped = 0;
1877
1878 uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize();
1879 result.GetOutputStream().SetAddressByteSize(addr_byte_size);
1880 result.GetErrorStream().SetAddressByteSize(addr_byte_size);
1881
1882 if (command.GetArgumentCount() == 0)
1883 {
1884 // Dump all sections for all modules images
Jim Ingham93367902012-05-30 02:19:25 +00001885 Mutex::Locker modules_locker(target->GetImages().GetMutex());
Greg Claytone1f50b92011-05-03 22:09:39 +00001886 const uint32_t num_modules = target->GetImages().GetSize();
1887 if (num_modules > 0)
1888 {
1889 result.GetOutputStream().Printf("Dumping symbol table for %u modules.\n", num_modules);
1890 for (uint32_t image_idx = 0; image_idx<num_modules; ++image_idx)
1891 {
1892 if (num_dumped > 0)
1893 {
1894 result.GetOutputStream().EOL();
1895 result.GetOutputStream().EOL();
1896 }
1897 num_dumped++;
Jim Ingham93367902012-05-30 02:19:25 +00001898 DumpModuleSymtab (m_interpreter,
1899 result.GetOutputStream(),
1900 target->GetImages().GetModulePointerAtIndexUnlocked(image_idx),
1901 m_options.m_sort_order);
Greg Claytone1f50b92011-05-03 22:09:39 +00001902 }
1903 }
1904 else
1905 {
1906 result.AppendError ("the target has no associated executable images");
1907 result.SetStatus (eReturnStatusFailed);
1908 return false;
1909 }
1910 }
1911 else
1912 {
1913 // Dump specified images (by basename or fullpath)
1914 const char *arg_cstr;
1915 for (int arg_idx = 0; (arg_cstr = command.GetArgumentAtIndex(arg_idx)) != NULL; ++arg_idx)
1916 {
Greg Clayton91048ef2011-11-10 01:18:58 +00001917 ModuleList module_list;
1918 const size_t num_matches = FindModulesByName (target, arg_cstr, module_list, true);
1919 if (num_matches > 0)
Greg Claytone1f50b92011-05-03 22:09:39 +00001920 {
Greg Clayton91048ef2011-11-10 01:18:58 +00001921 for (size_t i=0; i<num_matches; ++i)
Greg Claytone1f50b92011-05-03 22:09:39 +00001922 {
Greg Clayton91048ef2011-11-10 01:18:58 +00001923 Module *module = module_list.GetModulePointerAtIndex(i);
1924 if (module)
Greg Claytone1f50b92011-05-03 22:09:39 +00001925 {
1926 if (num_dumped > 0)
1927 {
1928 result.GetOutputStream().EOL();
1929 result.GetOutputStream().EOL();
1930 }
1931 num_dumped++;
Greg Clayton91048ef2011-11-10 01:18:58 +00001932 DumpModuleSymtab (m_interpreter, result.GetOutputStream(), module, m_options.m_sort_order);
Greg Claytone1f50b92011-05-03 22:09:39 +00001933 }
1934 }
1935 }
1936 else
1937 result.AppendWarningWithFormat("Unable to find an image that matches '%s'.\n", arg_cstr);
1938 }
1939 }
1940
1941 if (num_dumped > 0)
1942 result.SetStatus (eReturnStatusSuccessFinishResult);
1943 else
1944 {
1945 result.AppendError ("no matching executable images found");
1946 result.SetStatus (eReturnStatusFailed);
1947 }
1948 }
1949 return result.Succeeded();
1950 }
1951
1952 virtual Options *
1953 GetOptions ()
1954 {
1955 return &m_options;
1956 }
1957
1958 class CommandOptions : public Options
1959 {
1960 public:
1961
1962 CommandOptions (CommandInterpreter &interpreter) :
1963 Options(interpreter),
1964 m_sort_order (eSortOrderNone)
1965 {
1966 }
1967
1968 virtual
1969 ~CommandOptions ()
1970 {
1971 }
1972
1973 virtual Error
1974 SetOptionValue (uint32_t option_idx, const char *option_arg)
1975 {
1976 Error error;
1977 char short_option = (char) m_getopt_table[option_idx].val;
1978
1979 switch (short_option)
1980 {
1981 case 's':
Greg Claytone1f50b92011-05-03 22:09:39 +00001982 m_sort_order = (SortOrder) Args::StringToOptionEnum (option_arg,
1983 g_option_table[option_idx].enum_values,
1984 eSortOrderNone,
Greg Clayton61aca5d2011-10-07 18:58:12 +00001985 error);
Greg Claytone1f50b92011-05-03 22:09:39 +00001986 break;
1987
1988 default:
Greg Clayton9c236732011-10-26 00:56:27 +00001989 error.SetErrorStringWithFormat("invalid short option character '%c'", short_option);
Greg Claytone1f50b92011-05-03 22:09:39 +00001990 break;
1991
1992 }
1993 return error;
1994 }
1995
1996 void
1997 OptionParsingStarting ()
1998 {
1999 m_sort_order = eSortOrderNone;
2000 }
2001
2002 const OptionDefinition*
2003 GetDefinitions ()
2004 {
2005 return g_option_table;
2006 }
2007
2008 // Options table: Required for subclasses of Options.
2009 static OptionDefinition g_option_table[];
2010
2011 SortOrder m_sort_order;
2012 };
2013
2014protected:
2015
2016 CommandOptions m_options;
2017};
2018
2019static OptionEnumValueElement
2020g_sort_option_enumeration[4] =
2021{
2022 { eSortOrderNone, "none", "No sorting, use the original symbol table order."},
2023 { eSortOrderByAddress, "address", "Sort output by symbol address."},
2024 { eSortOrderByName, "name", "Sort output by symbol name."},
2025 { 0, NULL, NULL }
2026};
2027
2028
2029OptionDefinition
2030CommandObjectTargetModulesDumpSymtab::CommandOptions::g_option_table[] =
2031{
2032 { LLDB_OPT_SET_1, false, "sort", 's', required_argument, g_sort_option_enumeration, 0, eArgTypeSortOrder, "Supply a sort order when dumping the symbol table."},
2033 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
2034};
2035
2036#pragma mark CommandObjectTargetModulesDumpSections
2037
2038//----------------------------------------------------------------------
2039// Image section dumping command
2040//----------------------------------------------------------------------
2041
2042class CommandObjectTargetModulesDumpSections : public CommandObjectTargetModulesModuleAutoComplete
2043{
2044public:
2045 CommandObjectTargetModulesDumpSections (CommandInterpreter &interpreter) :
2046 CommandObjectTargetModulesModuleAutoComplete (interpreter,
2047 "target modules dump sections",
2048 "Dump the sections from one or more target modules.",
2049 //"target modules dump sections [<file1> ...]")
2050 NULL)
2051 {
2052 }
2053
2054 virtual
2055 ~CommandObjectTargetModulesDumpSections ()
2056 {
2057 }
2058
2059 virtual bool
2060 Execute (Args& command,
2061 CommandReturnObject &result)
2062 {
2063 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
2064 if (target == NULL)
2065 {
2066 result.AppendError ("invalid target, create a debug target using the 'target create' command");
2067 result.SetStatus (eReturnStatusFailed);
2068 return false;
2069 }
2070 else
2071 {
2072 uint32_t num_dumped = 0;
2073
2074 uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize();
2075 result.GetOutputStream().SetAddressByteSize(addr_byte_size);
2076 result.GetErrorStream().SetAddressByteSize(addr_byte_size);
2077
2078 if (command.GetArgumentCount() == 0)
2079 {
2080 // Dump all sections for all modules images
2081 const uint32_t num_modules = target->GetImages().GetSize();
2082 if (num_modules > 0)
2083 {
2084 result.GetOutputStream().Printf("Dumping sections for %u modules.\n", num_modules);
2085 for (uint32_t image_idx = 0; image_idx<num_modules; ++image_idx)
2086 {
2087 num_dumped++;
2088 DumpModuleSections (m_interpreter, result.GetOutputStream(), target->GetImages().GetModulePointerAtIndex(image_idx));
2089 }
2090 }
2091 else
2092 {
2093 result.AppendError ("the target has no associated executable images");
2094 result.SetStatus (eReturnStatusFailed);
2095 return false;
2096 }
2097 }
2098 else
2099 {
2100 // Dump specified images (by basename or fullpath)
2101 const char *arg_cstr;
2102 for (int arg_idx = 0; (arg_cstr = command.GetArgumentAtIndex(arg_idx)) != NULL; ++arg_idx)
2103 {
Greg Clayton91048ef2011-11-10 01:18:58 +00002104 ModuleList module_list;
2105 const size_t num_matches = FindModulesByName (target, arg_cstr, module_list, true);
2106 if (num_matches > 0)
Greg Claytone1f50b92011-05-03 22:09:39 +00002107 {
Greg Clayton91048ef2011-11-10 01:18:58 +00002108 for (size_t i=0; i<num_matches; ++i)
Greg Claytone1f50b92011-05-03 22:09:39 +00002109 {
Greg Clayton91048ef2011-11-10 01:18:58 +00002110 Module *module = module_list.GetModulePointerAtIndex(i);
2111 if (module)
Greg Claytone1f50b92011-05-03 22:09:39 +00002112 {
2113 num_dumped++;
Greg Clayton91048ef2011-11-10 01:18:58 +00002114 DumpModuleSections (m_interpreter, result.GetOutputStream(), module);
Greg Claytone1f50b92011-05-03 22:09:39 +00002115 }
2116 }
2117 }
2118 else
Greg Clayton91048ef2011-11-10 01:18:58 +00002119 {
2120 // Check the global list
Greg Claytonc149c8b2012-01-27 18:08:35 +00002121 Mutex::Locker locker(Module::GetAllocationModuleCollectionMutex());
Greg Clayton91048ef2011-11-10 01:18:58 +00002122
Greg Claytone1f50b92011-05-03 22:09:39 +00002123 result.AppendWarningWithFormat("Unable to find an image that matches '%s'.\n", arg_cstr);
Greg Clayton91048ef2011-11-10 01:18:58 +00002124 }
Greg Claytone1f50b92011-05-03 22:09:39 +00002125 }
2126 }
2127
2128 if (num_dumped > 0)
2129 result.SetStatus (eReturnStatusSuccessFinishResult);
2130 else
2131 {
2132 result.AppendError ("no matching executable images found");
2133 result.SetStatus (eReturnStatusFailed);
2134 }
2135 }
2136 return result.Succeeded();
2137 }
2138};
2139
2140
2141#pragma mark CommandObjectTargetModulesDumpSymfile
2142
2143//----------------------------------------------------------------------
2144// Image debug symbol dumping command
2145//----------------------------------------------------------------------
2146
2147class CommandObjectTargetModulesDumpSymfile : public CommandObjectTargetModulesModuleAutoComplete
2148{
2149public:
2150 CommandObjectTargetModulesDumpSymfile (CommandInterpreter &interpreter) :
2151 CommandObjectTargetModulesModuleAutoComplete (interpreter,
2152 "target modules dump symfile",
2153 "Dump the debug symbol file for one or more target modules.",
2154 //"target modules dump symfile [<file1> ...]")
2155 NULL)
2156 {
2157 }
2158
2159 virtual
2160 ~CommandObjectTargetModulesDumpSymfile ()
2161 {
2162 }
2163
2164 virtual bool
2165 Execute (Args& command,
2166 CommandReturnObject &result)
2167 {
2168 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
2169 if (target == NULL)
2170 {
2171 result.AppendError ("invalid target, create a debug target using the 'target create' command");
2172 result.SetStatus (eReturnStatusFailed);
2173 return false;
2174 }
2175 else
2176 {
2177 uint32_t num_dumped = 0;
2178
2179 uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize();
2180 result.GetOutputStream().SetAddressByteSize(addr_byte_size);
2181 result.GetErrorStream().SetAddressByteSize(addr_byte_size);
2182
2183 if (command.GetArgumentCount() == 0)
2184 {
2185 // Dump all sections for all modules images
Jim Ingham93367902012-05-30 02:19:25 +00002186 ModuleList &target_modules = target->GetImages();
2187 Mutex::Locker modules_locker (target_modules.GetMutex());
2188 const uint32_t num_modules = target_modules.GetSize();
Greg Claytone1f50b92011-05-03 22:09:39 +00002189 if (num_modules > 0)
2190 {
2191 result.GetOutputStream().Printf("Dumping debug symbols for %u modules.\n", num_modules);
2192 for (uint32_t image_idx = 0; image_idx<num_modules; ++image_idx)
2193 {
Jim Ingham93367902012-05-30 02:19:25 +00002194 if (DumpModuleSymbolVendor (result.GetOutputStream(), target_modules.GetModulePointerAtIndexUnlocked(image_idx)))
Greg Claytone1f50b92011-05-03 22:09:39 +00002195 num_dumped++;
2196 }
2197 }
2198 else
2199 {
2200 result.AppendError ("the target has no associated executable images");
2201 result.SetStatus (eReturnStatusFailed);
2202 return false;
2203 }
2204 }
2205 else
2206 {
2207 // Dump specified images (by basename or fullpath)
2208 const char *arg_cstr;
2209 for (int arg_idx = 0; (arg_cstr = command.GetArgumentAtIndex(arg_idx)) != NULL; ++arg_idx)
2210 {
Greg Clayton91048ef2011-11-10 01:18:58 +00002211 ModuleList module_list;
2212 const size_t num_matches = FindModulesByName (target, arg_cstr, module_list, true);
2213 if (num_matches > 0)
Greg Claytone1f50b92011-05-03 22:09:39 +00002214 {
Greg Clayton91048ef2011-11-10 01:18:58 +00002215 for (size_t i=0; i<num_matches; ++i)
Greg Claytone1f50b92011-05-03 22:09:39 +00002216 {
Greg Clayton91048ef2011-11-10 01:18:58 +00002217 Module *module = module_list.GetModulePointerAtIndex(i);
2218 if (module)
Greg Claytone1f50b92011-05-03 22:09:39 +00002219 {
Greg Clayton91048ef2011-11-10 01:18:58 +00002220 if (DumpModuleSymbolVendor (result.GetOutputStream(), module))
Greg Claytone1f50b92011-05-03 22:09:39 +00002221 num_dumped++;
2222 }
2223 }
2224 }
2225 else
2226 result.AppendWarningWithFormat("Unable to find an image that matches '%s'.\n", arg_cstr);
2227 }
2228 }
2229
2230 if (num_dumped > 0)
2231 result.SetStatus (eReturnStatusSuccessFinishResult);
2232 else
2233 {
2234 result.AppendError ("no matching executable images found");
2235 result.SetStatus (eReturnStatusFailed);
2236 }
2237 }
2238 return result.Succeeded();
2239 }
2240};
2241
2242
2243#pragma mark CommandObjectTargetModulesDumpLineTable
2244
2245//----------------------------------------------------------------------
2246// Image debug line table dumping command
2247//----------------------------------------------------------------------
2248
2249class CommandObjectTargetModulesDumpLineTable : public CommandObjectTargetModulesSourceFileAutoComplete
2250{
2251public:
2252 CommandObjectTargetModulesDumpLineTable (CommandInterpreter &interpreter) :
2253 CommandObjectTargetModulesSourceFileAutoComplete (interpreter,
2254 "target modules dump line-table",
2255 "Dump the debug symbol file for one or more target modules.",
2256 NULL)
2257 {
2258 }
2259
2260 virtual
2261 ~CommandObjectTargetModulesDumpLineTable ()
2262 {
2263 }
2264
2265 virtual bool
2266 Execute (Args& command,
2267 CommandReturnObject &result)
2268 {
2269 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
2270 if (target == NULL)
2271 {
2272 result.AppendError ("invalid target, create a debug target using the 'target create' command");
2273 result.SetStatus (eReturnStatusFailed);
2274 return false;
2275 }
2276 else
2277 {
2278 ExecutionContext exe_ctx(m_interpreter.GetExecutionContext());
2279 uint32_t total_num_dumped = 0;
2280
2281 uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize();
2282 result.GetOutputStream().SetAddressByteSize(addr_byte_size);
2283 result.GetErrorStream().SetAddressByteSize(addr_byte_size);
2284
2285 if (command.GetArgumentCount() == 0)
2286 {
2287 result.AppendErrorWithFormat ("\nSyntax: %s\n", m_cmd_syntax.c_str());
2288 result.SetStatus (eReturnStatusFailed);
2289 }
2290 else
2291 {
2292 // Dump specified images (by basename or fullpath)
2293 const char *arg_cstr;
2294 for (int arg_idx = 0; (arg_cstr = command.GetArgumentAtIndex(arg_idx)) != NULL; ++arg_idx)
2295 {
2296 FileSpec file_spec(arg_cstr, false);
Jim Ingham93367902012-05-30 02:19:25 +00002297
2298 ModuleList &target_modules = target->GetImages();
2299 Mutex::Locker modules_locker(target_modules.GetMutex());
2300 const uint32_t num_modules = target_modules.GetSize();
Greg Claytone1f50b92011-05-03 22:09:39 +00002301 if (num_modules > 0)
2302 {
2303 uint32_t num_dumped = 0;
2304 for (uint32_t i = 0; i<num_modules; ++i)
2305 {
2306 if (DumpCompileUnitLineTable (m_interpreter,
2307 result.GetOutputStream(),
Jim Ingham93367902012-05-30 02:19:25 +00002308 target_modules.GetModulePointerAtIndexUnlocked(i),
Greg Claytone1f50b92011-05-03 22:09:39 +00002309 file_spec,
Greg Clayton567e7f32011-09-22 04:58:26 +00002310 exe_ctx.GetProcessPtr() && exe_ctx.GetProcessRef().IsAlive()))
Greg Claytone1f50b92011-05-03 22:09:39 +00002311 num_dumped++;
2312 }
2313 if (num_dumped == 0)
2314 result.AppendWarningWithFormat ("No source filenames matched '%s'.\n", arg_cstr);
2315 else
2316 total_num_dumped += num_dumped;
2317 }
2318 }
2319 }
2320
2321 if (total_num_dumped > 0)
2322 result.SetStatus (eReturnStatusSuccessFinishResult);
2323 else
2324 {
2325 result.AppendError ("no source filenames matched any command arguments");
2326 result.SetStatus (eReturnStatusFailed);
2327 }
2328 }
2329 return result.Succeeded();
2330 }
2331};
2332
2333
2334#pragma mark CommandObjectTargetModulesDump
2335
2336//----------------------------------------------------------------------
2337// Dump multi-word command for target modules
2338//----------------------------------------------------------------------
2339
2340class CommandObjectTargetModulesDump : public CommandObjectMultiword
2341{
2342public:
2343
2344 //------------------------------------------------------------------
2345 // Constructors and Destructors
2346 //------------------------------------------------------------------
2347 CommandObjectTargetModulesDump(CommandInterpreter &interpreter) :
2348 CommandObjectMultiword (interpreter,
2349 "target modules dump",
2350 "A set of commands for dumping information about one or more target modules.",
2351 "target modules dump [symtab|sections|symfile|line-table] [<file1> <file2> ...]")
2352 {
2353 LoadSubCommand ("symtab", CommandObjectSP (new CommandObjectTargetModulesDumpSymtab (interpreter)));
2354 LoadSubCommand ("sections", CommandObjectSP (new CommandObjectTargetModulesDumpSections (interpreter)));
2355 LoadSubCommand ("symfile", CommandObjectSP (new CommandObjectTargetModulesDumpSymfile (interpreter)));
2356 LoadSubCommand ("line-table", CommandObjectSP (new CommandObjectTargetModulesDumpLineTable (interpreter)));
2357 }
2358
2359 virtual
2360 ~CommandObjectTargetModulesDump()
2361 {
2362 }
2363};
2364
2365class CommandObjectTargetModulesAdd : public CommandObject
2366{
2367public:
2368 CommandObjectTargetModulesAdd (CommandInterpreter &interpreter) :
2369 CommandObject (interpreter,
2370 "target modules add",
2371 "Add a new module to the current target's modules.",
2372 "target modules add [<module>]")
2373 {
2374 }
2375
2376 virtual
2377 ~CommandObjectTargetModulesAdd ()
2378 {
2379 }
2380
2381 virtual bool
2382 Execute (Args& args,
2383 CommandReturnObject &result)
2384 {
2385 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
2386 if (target == NULL)
2387 {
2388 result.AppendError ("invalid target, create a debug target using the 'target create' command");
2389 result.SetStatus (eReturnStatusFailed);
2390 return false;
2391 }
2392 else
2393 {
2394 const size_t argc = args.GetArgumentCount();
2395 if (argc == 0)
2396 {
2397 result.AppendError ("one or more executable image paths must be specified");
2398 result.SetStatus (eReturnStatusFailed);
2399 return false;
2400 }
2401 else
2402 {
2403 for (size_t i=0; i<argc; ++i)
2404 {
2405 const char *path = args.GetArgumentAtIndex(i);
2406 if (path)
2407 {
2408 FileSpec file_spec(path, true);
Greg Claytone1f50b92011-05-03 22:09:39 +00002409 if (file_spec.Exists())
2410 {
Greg Clayton444fe992012-02-26 05:51:37 +00002411 ModuleSpec module_spec (file_spec);
2412 ModuleSP module_sp (target->GetSharedModule (module_spec));
Greg Claytone1f50b92011-05-03 22:09:39 +00002413 if (!module_sp)
2414 {
2415 result.AppendError ("one or more executable image paths must be specified");
2416 result.SetStatus (eReturnStatusFailed);
2417 return false;
2418 }
Jason Molenda36f6fb92011-08-02 23:28:55 +00002419 result.SetStatus (eReturnStatusSuccessFinishResult);
Greg Claytone1f50b92011-05-03 22:09:39 +00002420 }
2421 else
2422 {
2423 char resolved_path[PATH_MAX];
2424 result.SetStatus (eReturnStatusFailed);
2425 if (file_spec.GetPath (resolved_path, sizeof(resolved_path)))
2426 {
2427 if (strcmp (resolved_path, path) != 0)
2428 {
2429 result.AppendErrorWithFormat ("invalid module path '%s' with resolved path '%s'\n", path, resolved_path);
2430 break;
2431 }
2432 }
2433 result.AppendErrorWithFormat ("invalid module path '%s'\n", path);
2434 break;
2435 }
2436 }
2437 }
2438 }
2439 }
2440 return result.Succeeded();
2441 }
2442
2443 int
2444 HandleArgumentCompletion (Args &input,
2445 int &cursor_index,
2446 int &cursor_char_position,
2447 OptionElementVector &opt_element_vector,
2448 int match_start_point,
2449 int max_return_elements,
2450 bool &word_complete,
2451 StringList &matches)
2452 {
2453 std::string completion_str (input.GetArgumentAtIndex(cursor_index));
2454 completion_str.erase (cursor_char_position);
2455
2456 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
2457 CommandCompletions::eDiskFileCompletion,
2458 completion_str.c_str(),
2459 match_start_point,
2460 max_return_elements,
2461 NULL,
2462 word_complete,
2463 matches);
2464 return matches.GetSize();
2465 }
2466
2467};
2468
2469class CommandObjectTargetModulesLoad : public CommandObjectTargetModulesModuleAutoComplete
2470{
2471public:
2472 CommandObjectTargetModulesLoad (CommandInterpreter &interpreter) :
2473 CommandObjectTargetModulesModuleAutoComplete (interpreter,
2474 "target modules load",
2475 "Set the load addresses for one or more sections in a target module.",
2476 "target modules load [--file <module> --uuid <uuid>] <sect-name> <address> [<sect-name> <address> ....]"),
2477 m_option_group (interpreter),
2478 m_file_option (LLDB_OPT_SET_1, false, "file", 'f', 0, eArgTypePath, "Fullpath or basename for module to load."),
2479 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)
2480 {
2481 m_option_group.Append (&m_uuid_option_group, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
2482 m_option_group.Append (&m_file_option, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
2483 m_option_group.Append (&m_slide_option, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
2484 m_option_group.Finalize();
2485 }
2486
2487 virtual
2488 ~CommandObjectTargetModulesLoad ()
2489 {
2490 }
2491
2492 virtual bool
2493 Execute (Args& args,
2494 CommandReturnObject &result)
2495 {
2496 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
2497 if (target == NULL)
2498 {
2499 result.AppendError ("invalid target, create a debug target using the 'target create' command");
2500 result.SetStatus (eReturnStatusFailed);
2501 return false;
2502 }
2503 else
2504 {
2505 const size_t argc = args.GetArgumentCount();
Greg Clayton444fe992012-02-26 05:51:37 +00002506 ModuleSpec module_spec;
2507 bool search_using_module_spec = false;
Greg Claytone1f50b92011-05-03 22:09:39 +00002508 if (m_file_option.GetOptionValue().OptionWasSet())
Greg Clayton444fe992012-02-26 05:51:37 +00002509 {
2510 search_using_module_spec = true;
2511 module_spec.GetFileSpec() = m_file_option.GetOptionValue().GetCurrentValue();
2512 }
Greg Claytone1f50b92011-05-03 22:09:39 +00002513
2514 if (m_uuid_option_group.GetOptionValue().OptionWasSet())
Greg Clayton444fe992012-02-26 05:51:37 +00002515 {
2516 search_using_module_spec = true;
2517 module_spec.GetUUID() = m_uuid_option_group.GetOptionValue().GetCurrentValue();
2518 }
Greg Claytone1f50b92011-05-03 22:09:39 +00002519
Greg Clayton444fe992012-02-26 05:51:37 +00002520 if (search_using_module_spec)
Greg Claytone1f50b92011-05-03 22:09:39 +00002521 {
2522
2523 ModuleList matching_modules;
Greg Clayton444fe992012-02-26 05:51:37 +00002524 const size_t num_matches = target->GetImages().FindModules (module_spec, matching_modules);
Greg Claytone1f50b92011-05-03 22:09:39 +00002525
2526 char path[PATH_MAX];
2527 if (num_matches == 1)
2528 {
2529 Module *module = matching_modules.GetModulePointerAtIndex(0);
2530 if (module)
2531 {
2532 ObjectFile *objfile = module->GetObjectFile();
2533 if (objfile)
2534 {
2535 SectionList *section_list = objfile->GetSectionList();
2536 if (section_list)
2537 {
Greg Clayton9ab696e2012-03-27 21:10:07 +00002538 bool changed = false;
Greg Claytone1f50b92011-05-03 22:09:39 +00002539 if (argc == 0)
2540 {
2541 if (m_slide_option.GetOptionValue().OptionWasSet())
2542 {
Greg Clayton9ab696e2012-03-27 21:10:07 +00002543 const addr_t slide = m_slide_option.GetOptionValue().GetCurrentValue();
2544 module->SetLoadAddress (*target, slide, changed);
Greg Claytone1f50b92011-05-03 22:09:39 +00002545 }
2546 else
2547 {
2548 result.AppendError ("one or more section name + load address pair must be specified");
2549 result.SetStatus (eReturnStatusFailed);
2550 return false;
2551 }
2552 }
2553 else
2554 {
2555 if (m_slide_option.GetOptionValue().OptionWasSet())
2556 {
2557 result.AppendError ("The \"--slide <offset>\" option can't be used in conjunction with setting section load addresses.\n");
2558 result.SetStatus (eReturnStatusFailed);
2559 return false;
2560 }
2561
2562 for (size_t i=0; i<argc; i += 2)
2563 {
2564 const char *sect_name = args.GetArgumentAtIndex(i);
2565 const char *load_addr_cstr = args.GetArgumentAtIndex(i+1);
2566 if (sect_name && load_addr_cstr)
2567 {
2568 ConstString const_sect_name(sect_name);
2569 bool success = false;
2570 addr_t load_addr = Args::StringToUInt64(load_addr_cstr, LLDB_INVALID_ADDRESS, 0, &success);
2571 if (success)
2572 {
2573 SectionSP section_sp (section_list->FindSectionByName(const_sect_name));
2574 if (section_sp)
2575 {
Greg Clayton9ab696e2012-03-27 21:10:07 +00002576 if (section_sp->IsThreadSpecific())
2577 {
2578 result.AppendErrorWithFormat ("thread specific sections are not yet supported (section '%s')\n", sect_name);
2579 result.SetStatus (eReturnStatusFailed);
2580 break;
2581 }
2582 else
2583 {
2584 if (target->GetSectionLoadList().SetSectionLoadAddress (section_sp.get(), load_addr))
2585 changed = true;
2586 result.AppendMessageWithFormat("section '%s' loaded at 0x%llx\n", sect_name, load_addr);
2587 }
Greg Claytone1f50b92011-05-03 22:09:39 +00002588 }
2589 else
2590 {
2591 result.AppendErrorWithFormat ("no section found that matches the section name '%s'\n", sect_name);
2592 result.SetStatus (eReturnStatusFailed);
2593 break;
2594 }
2595 }
2596 else
2597 {
2598 result.AppendErrorWithFormat ("invalid load address string '%s'\n", load_addr_cstr);
2599 result.SetStatus (eReturnStatusFailed);
2600 break;
2601 }
2602 }
2603 else
2604 {
2605 if (sect_name)
2606 result.AppendError ("section names must be followed by a load address.\n");
2607 else
2608 result.AppendError ("one or more section name + load address pair must be specified.\n");
2609 result.SetStatus (eReturnStatusFailed);
2610 break;
2611 }
2612 }
2613 }
Greg Clayton9ab696e2012-03-27 21:10:07 +00002614
2615 if (changed)
2616 target->ModulesDidLoad (matching_modules);
Greg Claytone1f50b92011-05-03 22:09:39 +00002617 }
2618 else
2619 {
2620 module->GetFileSpec().GetPath (path, sizeof(path));
2621 result.AppendErrorWithFormat ("no sections in object file '%s'\n", path);
2622 result.SetStatus (eReturnStatusFailed);
2623 }
2624 }
2625 else
2626 {
2627 module->GetFileSpec().GetPath (path, sizeof(path));
2628 result.AppendErrorWithFormat ("no object file for module '%s'\n", path);
2629 result.SetStatus (eReturnStatusFailed);
2630 }
2631 }
2632 else
2633 {
2634 module->GetFileSpec().GetPath (path, sizeof(path));
2635 result.AppendErrorWithFormat ("invalid module '%s'.\n", path);
2636 result.SetStatus (eReturnStatusFailed);
2637 }
2638 }
2639 else
2640 {
2641 char uuid_cstr[64];
Greg Clayton444fe992012-02-26 05:51:37 +00002642
2643 if (module_spec.GetFileSpec())
2644 module_spec.GetFileSpec().GetPath (path, sizeof(path));
Greg Claytone1f50b92011-05-03 22:09:39 +00002645 else
2646 path[0] = '\0';
2647
Greg Clayton444fe992012-02-26 05:51:37 +00002648 if (module_spec.GetUUIDPtr())
2649 module_spec.GetUUID().GetAsCString(uuid_cstr, sizeof(uuid_cstr));
Greg Claytone1f50b92011-05-03 22:09:39 +00002650 else
2651 uuid_cstr[0] = '\0';
2652 if (num_matches > 1)
2653 {
2654 result.AppendErrorWithFormat ("multiple modules match%s%s%s%s:\n",
2655 path[0] ? " file=" : "",
2656 path,
2657 uuid_cstr[0] ? " uuid=" : "",
2658 uuid_cstr);
2659 for (size_t i=0; i<num_matches; ++i)
2660 {
2661 if (matching_modules.GetModulePointerAtIndex(i)->GetFileSpec().GetPath (path, sizeof(path)))
2662 result.AppendMessageWithFormat("%s\n", path);
2663 }
2664 }
2665 else
2666 {
2667 result.AppendErrorWithFormat ("no modules were found that match%s%s%s%s.\n",
2668 path[0] ? " file=" : "",
2669 path,
2670 uuid_cstr[0] ? " uuid=" : "",
2671 uuid_cstr);
2672 }
2673 result.SetStatus (eReturnStatusFailed);
2674 }
2675 }
2676 else
2677 {
2678 result.AppendError ("either the \"--file <module>\" or the \"--uuid <uuid>\" option must be specified.\n");
2679 result.SetStatus (eReturnStatusFailed);
2680 return false;
2681 }
2682 }
2683 return result.Succeeded();
2684 }
2685
2686 virtual Options *
2687 GetOptions ()
2688 {
2689 return &m_option_group;
2690 }
2691
2692protected:
2693 OptionGroupOptions m_option_group;
2694 OptionGroupUUID m_uuid_option_group;
2695 OptionGroupFile m_file_option;
2696 OptionGroupUInt64 m_slide_option;
2697};
2698
2699//----------------------------------------------------------------------
2700// List images with associated information
2701//----------------------------------------------------------------------
2702class CommandObjectTargetModulesList : public CommandObject
2703{
2704public:
2705
2706 class CommandOptions : public Options
2707 {
2708 public:
2709
2710 CommandOptions (CommandInterpreter &interpreter) :
Greg Clayton899025f2011-08-09 00:01:09 +00002711 Options(interpreter),
Jim Ingham6bdea822011-10-24 18:36:33 +00002712 m_format_array(),
Daniel Dunbar97c89572011-10-31 22:50:49 +00002713 m_use_global_module_list (false),
Jim Ingham6bdea822011-10-24 18:36:33 +00002714 m_module_addr (LLDB_INVALID_ADDRESS)
Greg Claytone1f50b92011-05-03 22:09:39 +00002715 {
2716 }
2717
2718 virtual
2719 ~CommandOptions ()
2720 {
2721 }
2722
2723 virtual Error
2724 SetOptionValue (uint32_t option_idx, const char *option_arg)
2725 {
2726 char short_option = (char) m_getopt_table[option_idx].val;
Greg Clayton899025f2011-08-09 00:01:09 +00002727 if (short_option == 'g')
2728 {
2729 m_use_global_module_list = true;
2730 }
Jim Ingham6bdea822011-10-24 18:36:33 +00002731 else if (short_option == 'a')
2732 {
2733 bool success;
2734 m_module_addr = Args::StringToAddress(option_arg, LLDB_INVALID_ADDRESS, &success);
2735 if (!success)
2736 {
2737 Error error;
Greg Clayton9c236732011-10-26 00:56:27 +00002738 error.SetErrorStringWithFormat("invalid address: \"%s\"", option_arg);
Jim Ingham6bdea822011-10-24 18:36:33 +00002739 }
2740 }
Greg Clayton899025f2011-08-09 00:01:09 +00002741 else
2742 {
2743 uint32_t width = 0;
2744 if (option_arg)
2745 width = strtoul (option_arg, NULL, 0);
2746 m_format_array.push_back(std::make_pair(short_option, width));
2747 }
Greg Claytone1f50b92011-05-03 22:09:39 +00002748 Error error;
2749 return error;
2750 }
2751
2752 void
2753 OptionParsingStarting ()
2754 {
2755 m_format_array.clear();
Greg Clayton899025f2011-08-09 00:01:09 +00002756 m_use_global_module_list = false;
Jim Ingham6bdea822011-10-24 18:36:33 +00002757 m_module_addr = LLDB_INVALID_ADDRESS;
Greg Claytone1f50b92011-05-03 22:09:39 +00002758 }
2759
2760 const OptionDefinition*
2761 GetDefinitions ()
2762 {
2763 return g_option_table;
2764 }
2765
2766 // Options table: Required for subclasses of Options.
2767
2768 static OptionDefinition g_option_table[];
2769
2770 // Instance variables to hold the values for command options.
2771 typedef std::vector< std::pair<char, uint32_t> > FormatWidthCollection;
2772 FormatWidthCollection m_format_array;
Greg Clayton899025f2011-08-09 00:01:09 +00002773 bool m_use_global_module_list;
Jim Ingham6bdea822011-10-24 18:36:33 +00002774 lldb::addr_t m_module_addr;
Greg Claytone1f50b92011-05-03 22:09:39 +00002775 };
2776
2777 CommandObjectTargetModulesList (CommandInterpreter &interpreter) :
2778 CommandObject (interpreter,
2779 "target modules list",
2780 "List current executable and dependent shared library images.",
2781 "target modules list [<cmd-options>]"),
2782 m_options (interpreter)
2783 {
2784 }
2785
2786 virtual
2787 ~CommandObjectTargetModulesList ()
2788 {
2789 }
2790
2791 virtual
2792 Options *
2793 GetOptions ()
2794 {
2795 return &m_options;
2796 }
2797
2798 virtual bool
2799 Execute (Args& command,
2800 CommandReturnObject &result)
2801 {
2802 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Greg Clayton153ccd72011-08-10 02:10:13 +00002803 const bool use_global_module_list = m_options.m_use_global_module_list;
2804 if (target == NULL && use_global_module_list == false)
Greg Claytone1f50b92011-05-03 22:09:39 +00002805 {
2806 result.AppendError ("invalid target, create a debug target using the 'target create' command");
2807 result.SetStatus (eReturnStatusFailed);
2808 return false;
2809 }
2810 else
2811 {
Greg Clayton153ccd72011-08-10 02:10:13 +00002812 if (target)
2813 {
2814 uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize();
2815 result.GetOutputStream().SetAddressByteSize(addr_byte_size);
2816 result.GetErrorStream().SetAddressByteSize(addr_byte_size);
2817 }
Greg Claytone1f50b92011-05-03 22:09:39 +00002818 // Dump all sections for all modules images
Jim Ingham6bdea822011-10-24 18:36:33 +00002819 Stream &strm = result.GetOutputStream();
2820
2821 if (m_options.m_module_addr != LLDB_INVALID_ADDRESS)
2822 {
2823 if (target)
2824 {
2825 Address module_address;
2826 if (module_address.SetLoadAddress(m_options.m_module_addr, target))
2827 {
Greg Clayton3508c382012-02-24 01:59:29 +00002828 ModuleSP module_sp (module_address.GetModule());
2829 if (module_sp)
Jim Ingham6bdea822011-10-24 18:36:33 +00002830 {
Greg Clayton3508c382012-02-24 01:59:29 +00002831 PrintModule (target, module_sp.get(), UINT32_MAX, 0, strm);
Jim Ingham6bdea822011-10-24 18:36:33 +00002832 result.SetStatus (eReturnStatusSuccessFinishResult);
2833 }
2834 else
2835 {
2836 result.AppendError ("Couldn't find module matching address: 0x%llx.", m_options.m_module_addr);
2837 result.SetStatus (eReturnStatusFailed);
2838 }
2839 }
2840 else
2841 {
2842 result.AppendError ("Couldn't find module containing address: 0x%llx.", m_options.m_module_addr);
2843 result.SetStatus (eReturnStatusFailed);
2844 }
2845 }
2846 else
2847 {
2848 result.AppendError ("Can only look up modules by address with a valid target.");
2849 result.SetStatus (eReturnStatusFailed);
2850 }
2851 return result.Succeeded();
2852 }
2853
Jim Ingham93367902012-05-30 02:19:25 +00002854 uint32_t num_modules = 0;
2855 Mutex::Locker locker; // This locker will be locked on the mutex in module_list_ptr if it is non-NULL.
2856 // Otherwise it will lock the AllocationModuleCollectionMutex when accessing
2857 // the global module list directly.
2858
Greg Clayton2ad894b2012-05-15 18:43:44 +00002859 ModuleList module_list;
2860 ModuleList *module_list_ptr = NULL;
2861 const size_t argc = command.GetArgumentCount();
2862 if (argc == 0)
Greg Clayton899025f2011-08-09 00:01:09 +00002863 {
Greg Clayton2ad894b2012-05-15 18:43:44 +00002864 if (use_global_module_list)
2865 {
2866 locker.Lock (Module::GetAllocationModuleCollectionMutex());
2867 num_modules = Module::GetNumberAllocatedModules();
2868 }
2869 else
2870 {
2871 module_list_ptr = &target->GetImages();
Greg Clayton2ad894b2012-05-15 18:43:44 +00002872 }
Greg Clayton899025f2011-08-09 00:01:09 +00002873 }
2874 else
Greg Clayton2ad894b2012-05-15 18:43:44 +00002875 {
2876 for (size_t i=0; i<argc; ++i)
2877 {
2878 // Dump specified images (by basename or fullpath)
2879 const char *arg_cstr = command.GetArgumentAtIndex(i);
2880 const size_t num_matches = FindModulesByName (target, arg_cstr, module_list, use_global_module_list);
2881 if (num_matches == 0)
2882 {
2883 if (argc == 1)
2884 {
2885 result.AppendErrorWithFormat ("no modules found that match '%s'", arg_cstr);
2886 result.SetStatus (eReturnStatusFailed);
2887 return false;
2888 }
2889 }
2890 }
2891
Greg Clayton2ad894b2012-05-15 18:43:44 +00002892 module_list_ptr = &module_list;
2893 }
Jim Ingham93367902012-05-30 02:19:25 +00002894
2895 if (module_list_ptr != NULL)
2896 {
2897 locker.Lock(module_list_ptr->GetMutex());
2898 num_modules = module_list_ptr->GetSize();
2899 }
Greg Clayton899025f2011-08-09 00:01:09 +00002900
Greg Claytone1f50b92011-05-03 22:09:39 +00002901 if (num_modules > 0)
Jim Ingham6bdea822011-10-24 18:36:33 +00002902 {
Greg Claytone1f50b92011-05-03 22:09:39 +00002903 for (uint32_t image_idx = 0; image_idx<num_modules; ++image_idx)
2904 {
Greg Clayton153ccd72011-08-10 02:10:13 +00002905 ModuleSP module_sp;
Greg Clayton899025f2011-08-09 00:01:09 +00002906 Module *module;
Greg Clayton2ad894b2012-05-15 18:43:44 +00002907 if (module_list_ptr)
Greg Clayton899025f2011-08-09 00:01:09 +00002908 {
Jim Ingham93367902012-05-30 02:19:25 +00002909 module_sp = module_list_ptr->GetModuleAtIndexUnlocked(image_idx);
Greg Clayton2ad894b2012-05-15 18:43:44 +00002910 module = module_sp.get();
Greg Clayton899025f2011-08-09 00:01:09 +00002911 }
2912 else
2913 {
Greg Clayton2ad894b2012-05-15 18:43:44 +00002914 module = Module::GetAllocatedModuleAtIndex(image_idx);
2915 module_sp = module->shared_from_this();
Greg Clayton899025f2011-08-09 00:01:09 +00002916 }
Jim Ingham6bdea822011-10-24 18:36:33 +00002917
Greg Claytonb5a8f142012-02-05 02:38:54 +00002918 int indent = strm.Printf("[%3u] ", image_idx);
2919 PrintModule (target, module, image_idx, indent, strm);
Greg Clayton153ccd72011-08-10 02:10:13 +00002920
Greg Claytone1f50b92011-05-03 22:09:39 +00002921 }
2922 result.SetStatus (eReturnStatusSuccessFinishResult);
2923 }
2924 else
2925 {
Greg Clayton2ad894b2012-05-15 18:43:44 +00002926 if (argc)
2927 {
2928 if (use_global_module_list)
2929 result.AppendError ("the global module list has no matching modules");
2930 else
2931 result.AppendError ("the target has no matching modules");
2932 }
Greg Clayton153ccd72011-08-10 02:10:13 +00002933 else
Greg Clayton2ad894b2012-05-15 18:43:44 +00002934 {
2935 if (use_global_module_list)
2936 result.AppendError ("the global module list is empty");
2937 else
2938 result.AppendError ("the target has no associated executable images");
2939 }
Greg Claytone1f50b92011-05-03 22:09:39 +00002940 result.SetStatus (eReturnStatusFailed);
2941 return false;
2942 }
2943 }
2944 return result.Succeeded();
2945 }
2946protected:
Jim Ingham6bdea822011-10-24 18:36:33 +00002947
2948 void
Greg Claytonb5a8f142012-02-05 02:38:54 +00002949 PrintModule (Target *target, Module *module, uint32_t idx, int indent, Stream &strm)
Jim Ingham6bdea822011-10-24 18:36:33 +00002950 {
2951
2952 bool dump_object_name = false;
2953 if (m_options.m_format_array.empty())
2954 {
Greg Claytonb5a8f142012-02-05 02:38:54 +00002955 m_options.m_format_array.push_back(std::make_pair('u', 0));
2956 m_options.m_format_array.push_back(std::make_pair('h', 0));
2957 m_options.m_format_array.push_back(std::make_pair('f', 0));
2958 m_options.m_format_array.push_back(std::make_pair('S', 0));
Jim Ingham6bdea822011-10-24 18:36:33 +00002959 }
Greg Claytonb5a8f142012-02-05 02:38:54 +00002960 const size_t num_entries = m_options.m_format_array.size();
2961 bool print_space = false;
2962 for (size_t i=0; i<num_entries; ++i)
Jim Ingham6bdea822011-10-24 18:36:33 +00002963 {
Greg Claytonb5a8f142012-02-05 02:38:54 +00002964 if (print_space)
2965 strm.PutChar(' ');
2966 print_space = true;
2967 const char format_char = m_options.m_format_array[i].first;
2968 uint32_t width = m_options.m_format_array[i].second;
2969 switch (format_char)
Jim Ingham6bdea822011-10-24 18:36:33 +00002970 {
Greg Claytonb5a8f142012-02-05 02:38:54 +00002971 case 'A':
2972 DumpModuleArchitecture (strm, module, false, width);
2973 break;
2974
2975 case 't':
2976 DumpModuleArchitecture (strm, module, true, width);
2977 break;
2978
2979 case 'f':
2980 DumpFullpath (strm, &module->GetFileSpec(), width);
2981 dump_object_name = true;
2982 break;
2983
2984 case 'd':
2985 DumpDirectory (strm, &module->GetFileSpec(), width);
2986 break;
2987
2988 case 'b':
2989 DumpBasename (strm, &module->GetFileSpec(), width);
2990 dump_object_name = true;
2991 break;
2992
2993 case 'h':
2994 case 'o':
2995 // Image header address
2996 {
2997 uint32_t addr_nibble_width = target ? (target->GetArchitecture().GetAddressByteSize() * 2) : 16;
Jim Ingham6bdea822011-10-24 18:36:33 +00002998
Greg Claytonb5a8f142012-02-05 02:38:54 +00002999 ObjectFile *objfile = module->GetObjectFile ();
3000 if (objfile)
Jim Ingham6bdea822011-10-24 18:36:33 +00003001 {
Greg Claytonb5a8f142012-02-05 02:38:54 +00003002 Address header_addr(objfile->GetHeaderAddress());
3003 if (header_addr.IsValid())
Jim Ingham6bdea822011-10-24 18:36:33 +00003004 {
Greg Claytonb5a8f142012-02-05 02:38:54 +00003005 if (target && !target->GetSectionLoadList().IsEmpty())
Jim Ingham6bdea822011-10-24 18:36:33 +00003006 {
Greg Claytonb5a8f142012-02-05 02:38:54 +00003007 lldb::addr_t header_load_addr = header_addr.GetLoadAddress (target);
3008 if (header_load_addr == LLDB_INVALID_ADDRESS)
3009 {
3010 header_addr.Dump (&strm, target, Address::DumpStyleModuleWithFileAddress, Address::DumpStyleFileAddress);
3011 }
Jim Ingham6bdea822011-10-24 18:36:33 +00003012 else
Greg Claytonb5a8f142012-02-05 02:38:54 +00003013 {
3014 if (format_char == 'o')
3015 {
3016 // Show the offset of slide for the image
3017 strm.Printf ("0x%*.*llx", addr_nibble_width, addr_nibble_width, header_load_addr - header_addr.GetFileAddress());
3018 }
3019 else
3020 {
3021 // Show the load address of the image
3022 strm.Printf ("0x%*.*llx", addr_nibble_width, addr_nibble_width, header_load_addr);
3023 }
3024 }
Jim Ingham6bdea822011-10-24 18:36:33 +00003025 break;
3026 }
Greg Claytonb5a8f142012-02-05 02:38:54 +00003027 // The address was valid, but the image isn't loaded, output the address in an appropriate format
3028 header_addr.Dump (&strm, target, Address::DumpStyleFileAddress);
3029 break;
Jim Ingham6bdea822011-10-24 18:36:33 +00003030 }
Jim Ingham6bdea822011-10-24 18:36:33 +00003031 }
Greg Claytonb5a8f142012-02-05 02:38:54 +00003032 strm.Printf ("%*s", addr_nibble_width + 2, "");
3033 }
3034 break;
3035 case 'r':
3036 {
3037 uint32_t ref_count = 0;
3038 ModuleSP module_sp (module->shared_from_this());
3039 if (module_sp)
3040 {
3041 // Take one away to make sure we don't count our local "module_sp"
3042 ref_count = module_sp.use_count() - 1;
3043 }
3044 if (width)
3045 strm.Printf("{%*u}", width, ref_count);
3046 else
3047 strm.Printf("{%u}", ref_count);
3048 }
3049 break;
Jim Ingham6bdea822011-10-24 18:36:33 +00003050
Greg Claytonb5a8f142012-02-05 02:38:54 +00003051 case 's':
3052 case 'S':
3053 {
3054 SymbolVendor *symbol_vendor = module->GetSymbolVendor();
3055 if (symbol_vendor)
3056 {
3057 SymbolFile *symbol_file = symbol_vendor->GetSymbolFile();
3058 if (symbol_file)
3059 {
3060 if (format_char == 'S')
3061 {
3062 FileSpec &symfile_spec = symbol_file->GetObjectFile()->GetFileSpec();
3063 // Dump symbol file only if different from module file
3064 if (!symfile_spec || symfile_spec == module->GetFileSpec())
3065 {
3066 print_space = false;
3067 break;
3068 }
3069 // Add a newline and indent past the index
3070 strm.Printf ("\n%*s", indent, "");
3071 }
3072 DumpFullpath (strm, &symbol_file->GetObjectFile()->GetFileSpec(), width);
3073 dump_object_name = true;
3074 break;
3075 }
3076 }
3077 strm.Printf("%.*s", width, "<NONE>");
3078 }
3079 break;
3080
3081 case 'm':
3082 module->GetModificationTime().Dump(&strm, width);
3083 break;
Jim Ingham6bdea822011-10-24 18:36:33 +00003084
Greg Claytonb5a8f142012-02-05 02:38:54 +00003085 case 'p':
3086 strm.Printf("%p", module);
3087 break;
3088
3089 case 'u':
3090 DumpModuleUUID(strm, module);
3091 break;
3092
3093 default:
3094 break;
Jim Ingham6bdea822011-10-24 18:36:33 +00003095 }
Greg Claytonb5a8f142012-02-05 02:38:54 +00003096
3097 }
3098 if (dump_object_name)
3099 {
3100 const char *object_name = module->GetObjectName().GetCString();
3101 if (object_name)
3102 strm.Printf ("(%s)", object_name);
Jim Ingham6bdea822011-10-24 18:36:33 +00003103 }
3104 strm.EOL();
3105 }
3106
Greg Claytone1f50b92011-05-03 22:09:39 +00003107 CommandOptions m_options;
3108};
3109
3110OptionDefinition
3111CommandObjectTargetModulesList::CommandOptions::g_option_table[] =
3112{
Jim Ingham6bdea822011-10-24 18:36:33 +00003113 { LLDB_OPT_SET_1, false, "address", 'a', required_argument, NULL, 0, eArgTypeAddress, "Display the image at this address."},
3114 { 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 +00003115 { LLDB_OPT_SET_1, false, "triple", 't', optional_argument, NULL, 0, eArgTypeWidth, "Display the triple when listing images."},
Greg Claytonb5a8f142012-02-05 02:38:54 +00003116 { LLDB_OPT_SET_1, false, "header", 'h', no_argument, NULL, 0, eArgTypeNone, "Display the image header address as a load address if debugging, a file address otherwise."},
3117 { LLDB_OPT_SET_1, false, "offset", 'o', no_argument, NULL, 0, eArgTypeNone, "Display the image header address offset from the header file address (the slide amount)."},
Greg Claytone1f50b92011-05-03 22:09:39 +00003118 { LLDB_OPT_SET_1, false, "uuid", 'u', no_argument, NULL, 0, eArgTypeNone, "Display the UUID when listing images."},
3119 { LLDB_OPT_SET_1, false, "fullpath", 'f', optional_argument, NULL, 0, eArgTypeWidth, "Display the fullpath to the image object file."},
3120 { LLDB_OPT_SET_1, false, "directory", 'd', optional_argument, NULL, 0, eArgTypeWidth, "Display the directory with optional width for the image object file."},
3121 { LLDB_OPT_SET_1, false, "basename", 'b', optional_argument, NULL, 0, eArgTypeWidth, "Display the basename with optional width for the image object file."},
3122 { LLDB_OPT_SET_1, false, "symfile", 's', optional_argument, NULL, 0, eArgTypeWidth, "Display the fullpath to the image symbol file with optional width."},
Greg Claytonb5a8f142012-02-05 02:38:54 +00003123 { LLDB_OPT_SET_1, false, "symfile-unique", 'S', optional_argument, NULL, 0, eArgTypeWidth, "Display the symbol file with optional width only if it is different from the executable object file."},
Greg Clayton153ccd72011-08-10 02:10:13 +00003124 { LLDB_OPT_SET_1, false, "mod-time", 'm', optional_argument, NULL, 0, eArgTypeWidth, "Display the modification time with optional width of the module."},
3125 { 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."},
3126 { LLDB_OPT_SET_1, false, "pointer", 'p', optional_argument, NULL, 0, eArgTypeNone, "Display the module pointer."},
Greg Clayton899025f2011-08-09 00:01:09 +00003127 { 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 +00003128 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
3129};
3130
3131
3132
3133//----------------------------------------------------------------------
3134// Lookup information in images
3135//----------------------------------------------------------------------
3136class CommandObjectTargetModulesLookup : public CommandObject
3137{
3138public:
3139
3140 enum
3141 {
3142 eLookupTypeInvalid = -1,
3143 eLookupTypeAddress = 0,
3144 eLookupTypeSymbol,
3145 eLookupTypeFileLine, // Line is optional
3146 eLookupTypeFunction,
Greg Clayton2ad894b2012-05-15 18:43:44 +00003147 eLookupTypeFunctionOrSymbol,
Greg Claytone1f50b92011-05-03 22:09:39 +00003148 eLookupTypeType,
3149 kNumLookupTypes
3150 };
3151
3152 class CommandOptions : public Options
3153 {
3154 public:
3155
3156 CommandOptions (CommandInterpreter &interpreter) :
3157 Options(interpreter)
3158 {
3159 OptionParsingStarting();
3160 }
3161
3162 virtual
3163 ~CommandOptions ()
3164 {
3165 }
3166
3167 virtual Error
3168 SetOptionValue (uint32_t option_idx, const char *option_arg)
3169 {
3170 Error error;
3171
3172 char short_option = (char) m_getopt_table[option_idx].val;
3173
3174 switch (short_option)
3175 {
3176 case 'a':
3177 m_type = eLookupTypeAddress;
3178 m_addr = Args::StringToUInt64(option_arg, LLDB_INVALID_ADDRESS);
3179 if (m_addr == LLDB_INVALID_ADDRESS)
Greg Clayton9c236732011-10-26 00:56:27 +00003180 error.SetErrorStringWithFormat ("invalid address string '%s'", option_arg);
Greg Claytone1f50b92011-05-03 22:09:39 +00003181 break;
3182
3183 case 'o':
3184 m_offset = Args::StringToUInt64(option_arg, LLDB_INVALID_ADDRESS);
3185 if (m_offset == LLDB_INVALID_ADDRESS)
Greg Clayton9c236732011-10-26 00:56:27 +00003186 error.SetErrorStringWithFormat ("invalid offset string '%s'", option_arg);
Greg Claytone1f50b92011-05-03 22:09:39 +00003187 break;
3188
3189 case 's':
3190 m_str = option_arg;
3191 m_type = eLookupTypeSymbol;
3192 break;
3193
3194 case 'f':
3195 m_file.SetFile (option_arg, false);
3196 m_type = eLookupTypeFileLine;
3197 break;
3198
3199 case 'i':
Sean Callanan9ad19532012-02-11 01:22:21 +00003200 m_include_inlines = false;
Greg Claytone1f50b92011-05-03 22:09:39 +00003201 break;
3202
3203 case 'l':
3204 m_line_number = Args::StringToUInt32(option_arg, UINT32_MAX);
3205 if (m_line_number == UINT32_MAX)
Greg Clayton9c236732011-10-26 00:56:27 +00003206 error.SetErrorStringWithFormat ("invalid line number string '%s'", option_arg);
Greg Claytone1f50b92011-05-03 22:09:39 +00003207 else if (m_line_number == 0)
Greg Clayton9c236732011-10-26 00:56:27 +00003208 error.SetErrorString ("zero is an invalid line number");
Greg Claytone1f50b92011-05-03 22:09:39 +00003209 m_type = eLookupTypeFileLine;
3210 break;
3211
Greg Clayton2ad894b2012-05-15 18:43:44 +00003212 case 'F':
Greg Claytone1f50b92011-05-03 22:09:39 +00003213 m_str = option_arg;
3214 m_type = eLookupTypeFunction;
3215 break;
Greg Clayton2ad894b2012-05-15 18:43:44 +00003216
3217 case 'n':
3218 m_str = option_arg;
3219 m_type = eLookupTypeFunctionOrSymbol;
3220 break;
3221
Greg Claytone1f50b92011-05-03 22:09:39 +00003222 case 't':
3223 m_str = option_arg;
3224 m_type = eLookupTypeType;
3225 break;
3226
3227 case 'v':
3228 m_verbose = 1;
3229 break;
3230
3231 case 'r':
3232 m_use_regex = true;
3233 break;
3234 }
3235
3236 return error;
3237 }
3238
3239 void
3240 OptionParsingStarting ()
3241 {
3242 m_type = eLookupTypeInvalid;
3243 m_str.clear();
3244 m_file.Clear();
3245 m_addr = LLDB_INVALID_ADDRESS;
3246 m_offset = 0;
3247 m_line_number = 0;
3248 m_use_regex = false;
Sean Callanan9ad19532012-02-11 01:22:21 +00003249 m_include_inlines = true;
Greg Claytone1f50b92011-05-03 22:09:39 +00003250 m_verbose = false;
3251 }
3252
3253 const OptionDefinition*
3254 GetDefinitions ()
3255 {
3256 return g_option_table;
3257 }
3258
3259 // Options table: Required for subclasses of Options.
3260
3261 static OptionDefinition g_option_table[];
3262 int m_type; // Should be a eLookupTypeXXX enum after parsing options
3263 std::string m_str; // Holds name lookup
3264 FileSpec m_file; // Files for file lookups
3265 lldb::addr_t m_addr; // Holds the address to lookup
3266 lldb::addr_t m_offset; // Subtract this offset from m_addr before doing lookups.
3267 uint32_t m_line_number; // Line number for file+line lookups
3268 bool m_use_regex; // Name lookups in m_str are regular expressions.
Sean Callanan9ad19532012-02-11 01:22:21 +00003269 bool m_include_inlines;// Check for inline entries when looking up by file/line.
Greg Claytone1f50b92011-05-03 22:09:39 +00003270 bool m_verbose; // Enable verbose lookup info
3271
3272 };
3273
3274 CommandObjectTargetModulesLookup (CommandInterpreter &interpreter) :
3275 CommandObject (interpreter,
3276 "target modules lookup",
3277 "Look up information within executable and dependent shared library images.",
3278 NULL),
3279 m_options (interpreter)
3280 {
3281 CommandArgumentEntry arg;
3282 CommandArgumentData file_arg;
3283
3284 // Define the first (and only) variant of this arg.
3285 file_arg.arg_type = eArgTypeFilename;
3286 file_arg.arg_repetition = eArgRepeatStar;
3287
3288 // There is only one variant this argument could be; put it into the argument entry.
3289 arg.push_back (file_arg);
3290
3291 // Push the data for the first argument into the m_arguments vector.
3292 m_arguments.push_back (arg);
3293 }
3294
3295 virtual
3296 ~CommandObjectTargetModulesLookup ()
3297 {
3298 }
3299
3300 virtual Options *
3301 GetOptions ()
3302 {
3303 return &m_options;
3304 }
3305
3306
3307 bool
3308 LookupInModule (CommandInterpreter &interpreter, Module *module, CommandReturnObject &result, bool &syntax_error)
3309 {
3310 switch (m_options.m_type)
3311 {
3312 case eLookupTypeAddress:
3313 if (m_options.m_addr != LLDB_INVALID_ADDRESS)
3314 {
3315 if (LookupAddressInModule (m_interpreter,
3316 result.GetOutputStream(),
3317 module,
3318 eSymbolContextEverything,
3319 m_options.m_addr,
3320 m_options.m_offset,
3321 m_options.m_verbose))
3322 {
3323 result.SetStatus(eReturnStatusSuccessFinishResult);
3324 return true;
3325 }
3326 }
3327 break;
3328
3329 case eLookupTypeSymbol:
3330 if (!m_options.m_str.empty())
3331 {
Greg Clayton2ad894b2012-05-15 18:43:44 +00003332 if (LookupSymbolInModule (m_interpreter,
3333 result.GetOutputStream(),
3334 module,
3335 m_options.m_str.c_str(),
3336 m_options.m_use_regex,
3337 m_options.m_verbose))
Greg Claytone1f50b92011-05-03 22:09:39 +00003338 {
3339 result.SetStatus(eReturnStatusSuccessFinishResult);
3340 return true;
3341 }
3342 }
3343 break;
3344
3345 case eLookupTypeFileLine:
3346 if (m_options.m_file)
3347 {
3348
3349 if (LookupFileAndLineInModule (m_interpreter,
3350 result.GetOutputStream(),
3351 module,
3352 m_options.m_file,
3353 m_options.m_line_number,
Sean Callanan9ad19532012-02-11 01:22:21 +00003354 m_options.m_include_inlines,
Greg Claytone1f50b92011-05-03 22:09:39 +00003355 m_options.m_verbose))
3356 {
3357 result.SetStatus(eReturnStatusSuccessFinishResult);
3358 return true;
3359 }
3360 }
3361 break;
Greg Clayton2ad894b2012-05-15 18:43:44 +00003362
3363 case eLookupTypeFunctionOrSymbol:
Greg Claytone1f50b92011-05-03 22:09:39 +00003364 case eLookupTypeFunction:
3365 if (!m_options.m_str.empty())
3366 {
3367 if (LookupFunctionInModule (m_interpreter,
3368 result.GetOutputStream(),
3369 module,
3370 m_options.m_str.c_str(),
3371 m_options.m_use_regex,
Sean Callanan9ad19532012-02-11 01:22:21 +00003372 m_options.m_include_inlines,
Greg Clayton2ad894b2012-05-15 18:43:44 +00003373 m_options.m_type == eLookupTypeFunctionOrSymbol, // include symbols
Greg Claytone1f50b92011-05-03 22:09:39 +00003374 m_options.m_verbose))
3375 {
3376 result.SetStatus(eReturnStatusSuccessFinishResult);
3377 return true;
3378 }
3379 }
3380 break;
3381
Greg Clayton2ad894b2012-05-15 18:43:44 +00003382
Greg Claytone1f50b92011-05-03 22:09:39 +00003383 case eLookupTypeType:
3384 if (!m_options.m_str.empty())
3385 {
3386 if (LookupTypeInModule (m_interpreter,
3387 result.GetOutputStream(),
3388 module,
3389 m_options.m_str.c_str(),
3390 m_options.m_use_regex))
3391 {
3392 result.SetStatus(eReturnStatusSuccessFinishResult);
3393 return true;
3394 }
3395 }
3396 break;
3397
3398 default:
3399 m_options.GenerateOptionUsage (result.GetErrorStream(), this);
3400 syntax_error = true;
3401 break;
3402 }
3403
3404 result.SetStatus (eReturnStatusFailed);
3405 return false;
3406 }
3407
3408 virtual bool
3409 Execute (Args& command,
3410 CommandReturnObject &result)
3411 {
3412 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
3413 if (target == NULL)
3414 {
3415 result.AppendError ("invalid target, create a debug target using the 'target create' command");
3416 result.SetStatus (eReturnStatusFailed);
3417 return false;
3418 }
3419 else
3420 {
3421 bool syntax_error = false;
3422 uint32_t i;
3423 uint32_t num_successful_lookups = 0;
3424 uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize();
3425 result.GetOutputStream().SetAddressByteSize(addr_byte_size);
3426 result.GetErrorStream().SetAddressByteSize(addr_byte_size);
3427 // Dump all sections for all modules images
3428
3429 if (command.GetArgumentCount() == 0)
3430 {
3431 // Dump all sections for all modules images
Jim Ingham93367902012-05-30 02:19:25 +00003432 ModuleList &target_modules = target->GetImages();
3433 Mutex::Locker modules_locker(target_modules.GetMutex());
3434 const uint32_t num_modules = target_modules.GetSize();
Greg Claytone1f50b92011-05-03 22:09:39 +00003435 if (num_modules > 0)
3436 {
3437 for (i = 0; i<num_modules && syntax_error == false; ++i)
3438 {
Jim Ingham93367902012-05-30 02:19:25 +00003439 if (LookupInModule (m_interpreter, target_modules.GetModulePointerAtIndexUnlocked(i), result, syntax_error))
Greg Claytone1f50b92011-05-03 22:09:39 +00003440 {
3441 result.GetOutputStream().EOL();
3442 num_successful_lookups++;
3443 }
3444 }
3445 }
3446 else
3447 {
3448 result.AppendError ("the target has no associated executable images");
3449 result.SetStatus (eReturnStatusFailed);
3450 return false;
3451 }
3452 }
3453 else
3454 {
3455 // Dump specified images (by basename or fullpath)
3456 const char *arg_cstr;
3457 for (i = 0; (arg_cstr = command.GetArgumentAtIndex(i)) != NULL && syntax_error == false; ++i)
3458 {
Greg Clayton91048ef2011-11-10 01:18:58 +00003459 ModuleList module_list;
3460 const size_t num_matches = FindModulesByName (target, arg_cstr, module_list, false);
3461 if (num_matches > 0)
Greg Claytone1f50b92011-05-03 22:09:39 +00003462 {
Greg Clayton91048ef2011-11-10 01:18:58 +00003463 for (size_t i=0; i<num_matches; ++i)
Greg Claytone1f50b92011-05-03 22:09:39 +00003464 {
Greg Clayton91048ef2011-11-10 01:18:58 +00003465 Module *module = module_list.GetModulePointerAtIndex(i);
3466 if (module)
Greg Claytone1f50b92011-05-03 22:09:39 +00003467 {
Greg Clayton91048ef2011-11-10 01:18:58 +00003468 if (LookupInModule (m_interpreter, module, result, syntax_error))
Greg Claytone1f50b92011-05-03 22:09:39 +00003469 {
3470 result.GetOutputStream().EOL();
3471 num_successful_lookups++;
3472 }
3473 }
3474 }
3475 }
3476 else
3477 result.AppendWarningWithFormat("Unable to find an image that matches '%s'.\n", arg_cstr);
3478 }
3479 }
3480
3481 if (num_successful_lookups > 0)
3482 result.SetStatus (eReturnStatusSuccessFinishResult);
3483 else
3484 result.SetStatus (eReturnStatusFailed);
3485 }
3486 return result.Succeeded();
3487 }
3488protected:
3489
3490 CommandOptions m_options;
3491};
3492
3493OptionDefinition
3494CommandObjectTargetModulesLookup::CommandOptions::g_option_table[] =
3495{
3496 { LLDB_OPT_SET_1, true, "address", 'a', required_argument, NULL, 0, eArgTypeAddress, "Lookup an address in one or more target modules."},
3497 { 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."},
Greg Clayton2ad894b2012-05-15 18:43:44 +00003498 { LLDB_OPT_SET_2| LLDB_OPT_SET_4 | LLDB_OPT_SET_5
3499 /* FIXME: re-enable this for types when the LookupTypeInModule actually uses the regex option: | LLDB_OPT_SET_6 */ ,
Jim Inghame7a91c12011-06-20 23:38:11 +00003500 false, "regex", 'r', no_argument, NULL, 0, eArgTypeNone, "The <name> argument for name lookups are regular expressions."},
Greg Claytone1f50b92011-05-03 22:09:39 +00003501 { 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 +00003502 { 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."},
3503 { 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)."},
Jim Inghamf081dab2012-06-04 22:47:34 +00003504 { LLDB_OPT_SET_FROM_TO(3,5),
3505 false, "no-inlines", 'i', no_argument, NULL, 0, eArgTypeNone, "Ignore inline entries (must be used in conjunction with --file or --function)."},
Greg Clayton2ad894b2012-05-15 18:43:44 +00003506 { LLDB_OPT_SET_4, true, "function", 'F', required_argument, NULL, 0, eArgTypeFunctionName, "Lookup a function by name in the debug symbols in one or more target modules."},
3507 { LLDB_OPT_SET_5, true, "name", 'n', required_argument, NULL, 0, eArgTypeFunctionName, "Lookup a function or symbol by name in one or more target modules."},
3508 { LLDB_OPT_SET_6, true, "type", 't', required_argument, NULL, 0, eArgTypeName, "Lookup a type by name in the debug symbols in one or more target modules."},
Greg Claytone1f50b92011-05-03 22:09:39 +00003509 { LLDB_OPT_SET_ALL, false, "verbose", 'v', no_argument, NULL, 0, eArgTypeNone, "Enable verbose lookup information."},
Greg Clayton2ad894b2012-05-15 18:43:44 +00003510 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
Greg Claytone1f50b92011-05-03 22:09:39 +00003511};
Chris Lattner24943d22010-06-08 16:52:24 +00003512
3513
Jim Inghamd60d94a2011-03-11 03:53:59 +00003514#pragma mark CommandObjectMultiwordImageSearchPaths
Chris Lattner24943d22010-06-08 16:52:24 +00003515
3516//-------------------------------------------------------------------------
3517// CommandObjectMultiwordImageSearchPaths
3518//-------------------------------------------------------------------------
3519
Greg Claytone1f50b92011-05-03 22:09:39 +00003520class CommandObjectTargetModulesImageSearchPaths : public CommandObjectMultiword
Chris Lattner24943d22010-06-08 16:52:24 +00003521{
3522public:
Greg Claytone1f50b92011-05-03 22:09:39 +00003523
3524 CommandObjectTargetModulesImageSearchPaths (CommandInterpreter &interpreter) :
3525 CommandObjectMultiword (interpreter,
3526 "target modules search-paths",
3527 "A set of commands for operating on debugger target image search paths.",
3528 "target modules search-paths <subcommand> [<subcommand-options>]")
Chris Lattner24943d22010-06-08 16:52:24 +00003529 {
Greg Claytone1f50b92011-05-03 22:09:39 +00003530 LoadSubCommand ("add", CommandObjectSP (new CommandObjectTargetModulesSearchPathsAdd (interpreter)));
3531 LoadSubCommand ("clear", CommandObjectSP (new CommandObjectTargetModulesSearchPathsClear (interpreter)));
3532 LoadSubCommand ("insert", CommandObjectSP (new CommandObjectTargetModulesSearchPathsInsert (interpreter)));
3533 LoadSubCommand ("list", CommandObjectSP (new CommandObjectTargetModulesSearchPathsList (interpreter)));
3534 LoadSubCommand ("query", CommandObjectSP (new CommandObjectTargetModulesSearchPathsQuery (interpreter)));
Chris Lattner24943d22010-06-08 16:52:24 +00003535 }
Greg Claytone1f50b92011-05-03 22:09:39 +00003536
3537 ~CommandObjectTargetModulesImageSearchPaths()
Chris Lattner24943d22010-06-08 16:52:24 +00003538 {
3539 }
3540};
3541
Greg Claytone1f50b92011-05-03 22:09:39 +00003542
3543
3544#pragma mark CommandObjectTargetModules
3545
3546//-------------------------------------------------------------------------
3547// CommandObjectTargetModules
3548//-------------------------------------------------------------------------
3549
3550class CommandObjectTargetModules : public CommandObjectMultiword
3551{
3552public:
3553 //------------------------------------------------------------------
3554 // Constructors and Destructors
3555 //------------------------------------------------------------------
3556 CommandObjectTargetModules(CommandInterpreter &interpreter) :
3557 CommandObjectMultiword (interpreter,
3558 "target modules",
3559 "A set of commands for accessing information for one or more target modules.",
3560 "target modules <sub-command> ...")
3561 {
3562 LoadSubCommand ("add", CommandObjectSP (new CommandObjectTargetModulesAdd (interpreter)));
3563 LoadSubCommand ("load", CommandObjectSP (new CommandObjectTargetModulesLoad (interpreter)));
3564 //LoadSubCommand ("unload", CommandObjectSP (new CommandObjectTargetModulesUnload (interpreter)));
3565 LoadSubCommand ("dump", CommandObjectSP (new CommandObjectTargetModulesDump (interpreter)));
3566 LoadSubCommand ("list", CommandObjectSP (new CommandObjectTargetModulesList (interpreter)));
3567 LoadSubCommand ("lookup", CommandObjectSP (new CommandObjectTargetModulesLookup (interpreter)));
3568 LoadSubCommand ("search-paths", CommandObjectSP (new CommandObjectTargetModulesImageSearchPaths (interpreter)));
3569
3570 }
3571 virtual
3572 ~CommandObjectTargetModules()
3573 {
3574 }
3575
3576private:
3577 //------------------------------------------------------------------
3578 // For CommandObjectTargetModules only
3579 //------------------------------------------------------------------
3580 DISALLOW_COPY_AND_ASSIGN (CommandObjectTargetModules);
3581};
3582
3583
Greg Clayton3508c382012-02-24 01:59:29 +00003584
3585class CommandObjectTargetSymbolsAdd : public CommandObject
3586{
3587public:
3588 CommandObjectTargetSymbolsAdd (CommandInterpreter &interpreter) :
3589 CommandObject (interpreter,
3590 "target symbols add",
3591 "Add a debug symbol file to one of the target's current modules.",
3592 "target symbols add [<symfile>]")
3593 {
3594 }
3595
3596 virtual
3597 ~CommandObjectTargetSymbolsAdd ()
3598 {
3599 }
3600
3601 virtual bool
3602 Execute (Args& args,
3603 CommandReturnObject &result)
3604 {
Greg Claytoncf5927e2012-05-18 02:38:05 +00003605 ExecutionContext exe_ctx (m_interpreter.GetExecutionContext());
3606 Target *target = exe_ctx.GetTargetPtr();
Greg Clayton3508c382012-02-24 01:59:29 +00003607 if (target == NULL)
3608 {
3609 result.AppendError ("invalid target, create a debug target using the 'target create' command");
3610 result.SetStatus (eReturnStatusFailed);
Greg Clayton3508c382012-02-24 01:59:29 +00003611 }
3612 else
3613 {
Greg Claytoncf5927e2012-05-18 02:38:05 +00003614 bool flush = false;
Greg Clayton3508c382012-02-24 01:59:29 +00003615 const size_t argc = args.GetArgumentCount();
3616 if (argc == 0)
3617 {
3618 result.AppendError ("one or more symbol file paths must be specified");
3619 result.SetStatus (eReturnStatusFailed);
Greg Clayton3508c382012-02-24 01:59:29 +00003620 }
3621 else
3622 {
3623 for (size_t i=0; i<argc; ++i)
3624 {
3625 const char *symfile_path = args.GetArgumentAtIndex(i);
3626 if (symfile_path)
3627 {
3628 FileSpec symfile_spec(symfile_path, true);
3629 ArchSpec arch;
3630 if (symfile_spec.Exists())
3631 {
3632 ModuleSP symfile_module_sp (new Module (symfile_spec, target->GetArchitecture()));
3633 if (symfile_module_sp)
3634 {
3635 // We now have a module that represents a symbol file
3636 // that can be used for a module that might exist in the
3637 // current target, so we need to find that module in the
3638 // target
3639
3640 ModuleSP old_module_sp (target->GetImages().FindModule (symfile_module_sp->GetUUID()));
3641 if (old_module_sp)
3642 {
Greg Claytond4f16c82012-03-29 21:43:25 +00003643 // The module has not yet created its symbol vendor, we can just
3644 // give the existing target module the symfile path to use for
3645 // when it decides to create it!
3646 old_module_sp->SetSymbolFileFileSpec (symfile_module_sp->GetFileSpec());
Greg Clayton3508c382012-02-24 01:59:29 +00003647
Greg Claytond4f16c82012-03-29 21:43:25 +00003648 // Let clients know something changed in the module
3649 // if it is currently loaded
3650 ModuleList module_list;
3651 module_list.Append (old_module_sp);
3652 target->ModulesDidLoad (module_list);
Greg Claytoncf5927e2012-05-18 02:38:05 +00003653 flush = true;
Greg Clayton3508c382012-02-24 01:59:29 +00003654 }
3655 }
3656 else
3657 {
3658 result.AppendError ("one or more executable image paths must be specified");
3659 result.SetStatus (eReturnStatusFailed);
Greg Claytoncf5927e2012-05-18 02:38:05 +00003660 break;
Greg Clayton3508c382012-02-24 01:59:29 +00003661 }
3662 result.SetStatus (eReturnStatusSuccessFinishResult);
3663 }
3664 else
3665 {
3666 char resolved_symfile_path[PATH_MAX];
3667 result.SetStatus (eReturnStatusFailed);
3668 if (symfile_spec.GetPath (resolved_symfile_path, sizeof(resolved_symfile_path)))
3669 {
3670 if (strcmp (resolved_symfile_path, symfile_path) != 0)
3671 {
3672 result.AppendErrorWithFormat ("invalid module path '%s' with resolved path '%s'\n", symfile_path, resolved_symfile_path);
3673 break;
3674 }
3675 }
3676 result.AppendErrorWithFormat ("invalid module path '%s'\n", symfile_path);
3677 break;
3678 }
3679 }
3680 }
3681 }
Greg Claytoncf5927e2012-05-18 02:38:05 +00003682
3683 if (flush)
3684 {
3685 Process *process = exe_ctx.GetProcessPtr();
3686 if (process)
3687 process->Flush();
3688 }
Greg Clayton3508c382012-02-24 01:59:29 +00003689 }
3690 return result.Succeeded();
3691 }
3692
3693 int
3694 HandleArgumentCompletion (Args &input,
3695 int &cursor_index,
3696 int &cursor_char_position,
3697 OptionElementVector &opt_element_vector,
3698 int match_start_point,
3699 int max_return_elements,
3700 bool &word_complete,
3701 StringList &matches)
3702 {
3703 std::string completion_str (input.GetArgumentAtIndex(cursor_index));
3704 completion_str.erase (cursor_char_position);
3705
3706 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
3707 CommandCompletions::eDiskFileCompletion,
3708 completion_str.c_str(),
3709 match_start_point,
3710 max_return_elements,
3711 NULL,
3712 word_complete,
3713 matches);
3714 return matches.GetSize();
3715 }
3716
3717};
3718
3719
3720#pragma mark CommandObjectTargetSymbols
3721
3722//-------------------------------------------------------------------------
3723// CommandObjectTargetSymbols
3724//-------------------------------------------------------------------------
3725
3726class CommandObjectTargetSymbols : public CommandObjectMultiword
3727{
3728public:
3729 //------------------------------------------------------------------
3730 // Constructors and Destructors
3731 //------------------------------------------------------------------
3732 CommandObjectTargetSymbols(CommandInterpreter &interpreter) :
3733 CommandObjectMultiword (interpreter,
3734 "target symbols",
3735 "A set of commands for adding and managing debug symbol files.",
3736 "target symbols <sub-command> ...")
3737 {
3738 LoadSubCommand ("add", CommandObjectSP (new CommandObjectTargetSymbolsAdd (interpreter)));
3739
3740 }
3741 virtual
3742 ~CommandObjectTargetSymbols()
3743 {
3744 }
3745
3746private:
3747 //------------------------------------------------------------------
3748 // For CommandObjectTargetModules only
3749 //------------------------------------------------------------------
3750 DISALLOW_COPY_AND_ASSIGN (CommandObjectTargetSymbols);
3751};
3752
3753
Jim Inghamd60d94a2011-03-11 03:53:59 +00003754#pragma mark CommandObjectTargetStopHookAdd
3755
3756//-------------------------------------------------------------------------
3757// CommandObjectTargetStopHookAdd
3758//-------------------------------------------------------------------------
3759
3760class CommandObjectTargetStopHookAdd : public CommandObject
3761{
3762public:
3763
3764 class CommandOptions : public Options
3765 {
3766 public:
Greg Claytonf15996e2011-04-07 22:46:35 +00003767 CommandOptions (CommandInterpreter &interpreter) :
3768 Options(interpreter),
Jim Inghamd60d94a2011-03-11 03:53:59 +00003769 m_line_start(0),
3770 m_line_end (UINT_MAX),
3771 m_func_name_type_mask (eFunctionNameTypeAuto),
3772 m_sym_ctx_specified (false),
Johnny Chen60fe60e2011-05-02 23:47:55 +00003773 m_thread_specified (false),
3774 m_use_one_liner (false),
3775 m_one_liner()
Jim Inghamd60d94a2011-03-11 03:53:59 +00003776 {
3777 }
3778
3779 ~CommandOptions () {}
3780
Greg Claytonb3448432011-03-24 21:19:54 +00003781 const OptionDefinition*
Jim Inghamd60d94a2011-03-11 03:53:59 +00003782 GetDefinitions ()
3783 {
3784 return g_option_table;
3785 }
3786
3787 virtual Error
Greg Clayton143fcc32011-04-13 00:18:08 +00003788 SetOptionValue (uint32_t option_idx, const char *option_arg)
Jim Inghamd60d94a2011-03-11 03:53:59 +00003789 {
3790 Error error;
3791 char short_option = (char) m_getopt_table[option_idx].val;
3792 bool success;
3793
3794 switch (short_option)
3795 {
3796 case 'c':
3797 m_class_name = option_arg;
3798 m_sym_ctx_specified = true;
3799 break;
3800
3801 case 'e':
3802 m_line_end = Args::StringToUInt32 (option_arg, UINT_MAX, 0, &success);
3803 if (!success)
3804 {
Greg Clayton9c236732011-10-26 00:56:27 +00003805 error.SetErrorStringWithFormat ("invalid end line number: \"%s\"", option_arg);
Jim Inghamd60d94a2011-03-11 03:53:59 +00003806 break;
3807 }
3808 m_sym_ctx_specified = true;
3809 break;
3810
3811 case 'l':
3812 m_line_start = Args::StringToUInt32 (option_arg, 0, 0, &success);
3813 if (!success)
3814 {
Greg Clayton9c236732011-10-26 00:56:27 +00003815 error.SetErrorStringWithFormat ("invalid start line number: \"%s\"", option_arg);
Jim Inghamd60d94a2011-03-11 03:53:59 +00003816 break;
3817 }
3818 m_sym_ctx_specified = true;
3819 break;
Sean Callanan9ad19532012-02-11 01:22:21 +00003820
3821 case 'i':
3822 m_no_inlines = true;
3823 break;
Jim Inghamd60d94a2011-03-11 03:53:59 +00003824
3825 case 'n':
3826 m_function_name = option_arg;
3827 m_func_name_type_mask |= eFunctionNameTypeAuto;
3828 m_sym_ctx_specified = true;
3829 break;
3830
3831 case 'f':
3832 m_file_name = option_arg;
3833 m_sym_ctx_specified = true;
3834 break;
3835 case 's':
3836 m_module_name = option_arg;
3837 m_sym_ctx_specified = true;
3838 break;
3839 case 't' :
3840 {
Jim Ingham7a4c8ea2011-03-22 01:53:33 +00003841 m_thread_id = Args::StringToUInt64(option_arg, LLDB_INVALID_THREAD_ID, 0);
Jim Inghamd60d94a2011-03-11 03:53:59 +00003842 if (m_thread_id == LLDB_INVALID_THREAD_ID)
Greg Clayton9c236732011-10-26 00:56:27 +00003843 error.SetErrorStringWithFormat ("invalid thread id string '%s'", option_arg);
Jim Inghamd60d94a2011-03-11 03:53:59 +00003844 m_thread_specified = true;
3845 }
3846 break;
3847 case 'T':
3848 m_thread_name = option_arg;
3849 m_thread_specified = true;
3850 break;
3851 case 'q':
3852 m_queue_name = option_arg;
3853 m_thread_specified = true;
3854 break;
3855 case 'x':
3856 {
Jim Ingham7a4c8ea2011-03-22 01:53:33 +00003857 m_thread_index = Args::StringToUInt32(option_arg, UINT32_MAX, 0);
Jim Inghamd60d94a2011-03-11 03:53:59 +00003858 if (m_thread_id == UINT32_MAX)
Greg Clayton9c236732011-10-26 00:56:27 +00003859 error.SetErrorStringWithFormat ("invalid thread index string '%s'", option_arg);
Jim Inghamd60d94a2011-03-11 03:53:59 +00003860 m_thread_specified = true;
3861 }
3862 break;
Johnny Chen60fe60e2011-05-02 23:47:55 +00003863 case 'o':
3864 m_use_one_liner = true;
3865 m_one_liner = option_arg;
3866 break;
Jim Inghamd60d94a2011-03-11 03:53:59 +00003867 default:
Greg Clayton9c236732011-10-26 00:56:27 +00003868 error.SetErrorStringWithFormat ("unrecognized option %c.", short_option);
Jim Inghamd60d94a2011-03-11 03:53:59 +00003869 break;
3870 }
3871 return error;
3872 }
3873
3874 void
Greg Clayton143fcc32011-04-13 00:18:08 +00003875 OptionParsingStarting ()
Jim Inghamd60d94a2011-03-11 03:53:59 +00003876 {
3877 m_class_name.clear();
3878 m_function_name.clear();
3879 m_line_start = 0;
3880 m_line_end = UINT_MAX;
3881 m_file_name.clear();
3882 m_module_name.clear();
3883 m_func_name_type_mask = eFunctionNameTypeAuto;
3884 m_thread_id = LLDB_INVALID_THREAD_ID;
3885 m_thread_index = UINT32_MAX;
3886 m_thread_name.clear();
3887 m_queue_name.clear();
Sean Callanan9ad19532012-02-11 01:22:21 +00003888
3889 m_no_inlines = false;
Jim Inghamd60d94a2011-03-11 03:53:59 +00003890 m_sym_ctx_specified = false;
3891 m_thread_specified = false;
Johnny Chen60fe60e2011-05-02 23:47:55 +00003892
3893 m_use_one_liner = false;
3894 m_one_liner.clear();
Jim Inghamd60d94a2011-03-11 03:53:59 +00003895 }
3896
3897
Greg Claytonb3448432011-03-24 21:19:54 +00003898 static OptionDefinition g_option_table[];
Jim Inghamd60d94a2011-03-11 03:53:59 +00003899
3900 std::string m_class_name;
3901 std::string m_function_name;
3902 uint32_t m_line_start;
3903 uint32_t m_line_end;
3904 std::string m_file_name;
3905 std::string m_module_name;
3906 uint32_t m_func_name_type_mask; // A pick from lldb::FunctionNameType.
3907 lldb::tid_t m_thread_id;
3908 uint32_t m_thread_index;
3909 std::string m_thread_name;
3910 std::string m_queue_name;
3911 bool m_sym_ctx_specified;
Sean Callanan9ad19532012-02-11 01:22:21 +00003912 bool m_no_inlines;
Jim Inghamd60d94a2011-03-11 03:53:59 +00003913 bool m_thread_specified;
Johnny Chen60fe60e2011-05-02 23:47:55 +00003914 // Instance variables to hold the values for one_liner options.
3915 bool m_use_one_liner;
3916 std::string m_one_liner;
Jim Inghamd60d94a2011-03-11 03:53:59 +00003917 };
3918
3919 Options *
3920 GetOptions ()
3921 {
3922 return &m_options;
3923 }
3924
3925 CommandObjectTargetStopHookAdd (CommandInterpreter &interpreter) :
3926 CommandObject (interpreter,
3927 "target stop-hook add ",
3928 "Add a hook to be executed when the target stops.",
Greg Claytonf15996e2011-04-07 22:46:35 +00003929 "target stop-hook add"),
3930 m_options (interpreter)
Jim Inghamd60d94a2011-03-11 03:53:59 +00003931 {
3932 }
3933
3934 ~CommandObjectTargetStopHookAdd ()
3935 {
3936 }
3937
3938 static size_t
3939 ReadCommandsCallbackFunction (void *baton,
3940 InputReader &reader,
3941 lldb::InputReaderAction notification,
3942 const char *bytes,
3943 size_t bytes_len)
3944 {
Caroline Tice892fadd2011-06-16 16:27:19 +00003945 StreamSP out_stream = reader.GetDebugger().GetAsyncOutputStream();
Jim Inghamd60d94a2011-03-11 03:53:59 +00003946 Target::StopHook *new_stop_hook = ((Target::StopHook *) baton);
Jim Inghame15511a2011-05-05 01:03:36 +00003947 static bool got_interrupted;
Caroline Tice892fadd2011-06-16 16:27:19 +00003948 bool batch_mode = reader.GetDebugger().GetCommandInterpreter().GetBatchCommandMode();
Jim Inghamd60d94a2011-03-11 03:53:59 +00003949
3950 switch (notification)
3951 {
3952 case eInputReaderActivate:
Caroline Tice892fadd2011-06-16 16:27:19 +00003953 if (!batch_mode)
3954 {
3955 out_stream->Printf ("%s\n", "Enter your stop hook command(s). Type 'DONE' to end.");
3956 if (reader.GetPrompt())
3957 out_stream->Printf ("%s", reader.GetPrompt());
3958 out_stream->Flush();
3959 }
Jim Inghame15511a2011-05-05 01:03:36 +00003960 got_interrupted = false;
Jim Inghamd60d94a2011-03-11 03:53:59 +00003961 break;
3962
3963 case eInputReaderDeactivate:
3964 break;
3965
3966 case eInputReaderReactivate:
Caroline Tice892fadd2011-06-16 16:27:19 +00003967 if (reader.GetPrompt() && !batch_mode)
Jim Inghamd60d94a2011-03-11 03:53:59 +00003968 {
Caroline Tice892fadd2011-06-16 16:27:19 +00003969 out_stream->Printf ("%s", reader.GetPrompt());
3970 out_stream->Flush();
Jim Inghamd60d94a2011-03-11 03:53:59 +00003971 }
Jim Inghame15511a2011-05-05 01:03:36 +00003972 got_interrupted = false;
Jim Inghamd60d94a2011-03-11 03:53:59 +00003973 break;
3974
Caroline Tice4a348082011-05-02 20:41:46 +00003975 case eInputReaderAsynchronousOutputWritten:
3976 break;
3977
Jim Inghamd60d94a2011-03-11 03:53:59 +00003978 case eInputReaderGotToken:
3979 if (bytes && bytes_len && baton)
3980 {
3981 StringList *commands = new_stop_hook->GetCommandPointer();
3982 if (commands)
3983 {
3984 commands->AppendString (bytes, bytes_len);
3985 }
3986 }
Caroline Tice892fadd2011-06-16 16:27:19 +00003987 if (!reader.IsDone() && reader.GetPrompt() && !batch_mode)
Jim Inghamd60d94a2011-03-11 03:53:59 +00003988 {
Caroline Tice892fadd2011-06-16 16:27:19 +00003989 out_stream->Printf ("%s", reader.GetPrompt());
3990 out_stream->Flush();
Jim Inghamd60d94a2011-03-11 03:53:59 +00003991 }
3992 break;
3993
3994 case eInputReaderInterrupt:
3995 {
3996 // Finish, and cancel the stop hook.
3997 new_stop_hook->GetTarget()->RemoveStopHookByID(new_stop_hook->GetID());
Caroline Tice892fadd2011-06-16 16:27:19 +00003998 if (!batch_mode)
3999 {
4000 out_stream->Printf ("Stop hook cancelled.\n");
4001 out_stream->Flush();
4002 }
4003
Jim Inghamd60d94a2011-03-11 03:53:59 +00004004 reader.SetIsDone (true);
4005 }
Jim Inghame15511a2011-05-05 01:03:36 +00004006 got_interrupted = true;
Jim Inghamd60d94a2011-03-11 03:53:59 +00004007 break;
4008
4009 case eInputReaderEndOfFile:
4010 reader.SetIsDone (true);
4011 break;
4012
4013 case eInputReaderDone:
Caroline Tice892fadd2011-06-16 16:27:19 +00004014 if (!got_interrupted && !batch_mode)
4015 {
Greg Clayton444e35b2011-10-19 18:09:39 +00004016 out_stream->Printf ("Stop hook #%llu added.\n", new_stop_hook->GetID());
Caroline Tice892fadd2011-06-16 16:27:19 +00004017 out_stream->Flush();
4018 }
Jim Inghamd60d94a2011-03-11 03:53:59 +00004019 break;
4020 }
4021
4022 return bytes_len;
4023 }
4024
4025 bool
4026 Execute (Args& command,
4027 CommandReturnObject &result)
4028 {
4029 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
4030 if (target)
4031 {
4032 Target::StopHookSP new_hook_sp;
4033 target->AddStopHook (new_hook_sp);
4034
4035 // First step, make the specifier.
4036 std::auto_ptr<SymbolContextSpecifier> specifier_ap;
4037 if (m_options.m_sym_ctx_specified)
4038 {
4039 specifier_ap.reset(new SymbolContextSpecifier(m_interpreter.GetDebugger().GetSelectedTarget()));
4040
4041 if (!m_options.m_module_name.empty())
4042 {
4043 specifier_ap->AddSpecification (m_options.m_module_name.c_str(), SymbolContextSpecifier::eModuleSpecified);
4044 }
4045
4046 if (!m_options.m_class_name.empty())
4047 {
4048 specifier_ap->AddSpecification (m_options.m_class_name.c_str(), SymbolContextSpecifier::eClassOrNamespaceSpecified);
4049 }
4050
4051 if (!m_options.m_file_name.empty())
4052 {
4053 specifier_ap->AddSpecification (m_options.m_file_name.c_str(), SymbolContextSpecifier::eFileSpecified);
4054 }
4055
4056 if (m_options.m_line_start != 0)
4057 {
4058 specifier_ap->AddLineSpecification (m_options.m_line_start, SymbolContextSpecifier::eLineStartSpecified);
4059 }
4060
4061 if (m_options.m_line_end != UINT_MAX)
4062 {
4063 specifier_ap->AddLineSpecification (m_options.m_line_end, SymbolContextSpecifier::eLineEndSpecified);
4064 }
4065
4066 if (!m_options.m_function_name.empty())
4067 {
4068 specifier_ap->AddSpecification (m_options.m_function_name.c_str(), SymbolContextSpecifier::eFunctionSpecified);
4069 }
4070 }
4071
4072 if (specifier_ap.get())
4073 new_hook_sp->SetSpecifier (specifier_ap.release());
4074
4075 // Next see if any of the thread options have been entered:
4076
4077 if (m_options.m_thread_specified)
4078 {
4079 ThreadSpec *thread_spec = new ThreadSpec();
4080
4081 if (m_options.m_thread_id != LLDB_INVALID_THREAD_ID)
4082 {
4083 thread_spec->SetTID (m_options.m_thread_id);
4084 }
4085
4086 if (m_options.m_thread_index != UINT32_MAX)
4087 thread_spec->SetIndex (m_options.m_thread_index);
4088
4089 if (!m_options.m_thread_name.empty())
4090 thread_spec->SetName (m_options.m_thread_name.c_str());
4091
4092 if (!m_options.m_queue_name.empty())
4093 thread_spec->SetQueueName (m_options.m_queue_name.c_str());
4094
4095 new_hook_sp->SetThreadSpecifier (thread_spec);
4096
4097 }
Johnny Chen60fe60e2011-05-02 23:47:55 +00004098 if (m_options.m_use_one_liner)
Jim Inghamd60d94a2011-03-11 03:53:59 +00004099 {
Johnny Chen60fe60e2011-05-02 23:47:55 +00004100 // Use one-liner.
4101 new_hook_sp->GetCommandPointer()->AppendString (m_options.m_one_liner.c_str());
Greg Clayton444e35b2011-10-19 18:09:39 +00004102 result.AppendMessageWithFormat("Stop hook #%llu added.\n", new_hook_sp->GetID());
Jim Inghamd60d94a2011-03-11 03:53:59 +00004103 }
Johnny Chen60fe60e2011-05-02 23:47:55 +00004104 else
Jim Inghamd60d94a2011-03-11 03:53:59 +00004105 {
Johnny Chen60fe60e2011-05-02 23:47:55 +00004106 // Otherwise gather up the command list, we'll push an input reader and suck the data from that directly into
4107 // the new stop hook's command string.
4108 InputReaderSP reader_sp (new InputReader(m_interpreter.GetDebugger()));
4109 if (!reader_sp)
4110 {
4111 result.AppendError("out of memory\n");
4112 result.SetStatus (eReturnStatusFailed);
4113 target->RemoveStopHookByID (new_hook_sp->GetID());
4114 return false;
4115 }
4116
4117 Error err (reader_sp->Initialize (CommandObjectTargetStopHookAdd::ReadCommandsCallbackFunction,
4118 new_hook_sp.get(), // baton
4119 eInputReaderGranularityLine, // token size, to pass to callback function
4120 "DONE", // end token
4121 "> ", // prompt
4122 true)); // echo input
4123 if (!err.Success())
4124 {
4125 result.AppendError (err.AsCString());
4126 result.SetStatus (eReturnStatusFailed);
4127 target->RemoveStopHookByID (new_hook_sp->GetID());
4128 return false;
4129 }
4130 m_interpreter.GetDebugger().PushInputReader (reader_sp);
Jim Inghamd60d94a2011-03-11 03:53:59 +00004131 }
Jim Inghamd60d94a2011-03-11 03:53:59 +00004132 result.SetStatus (eReturnStatusSuccessFinishNoResult);
4133 }
4134 else
4135 {
Greg Claytonabe0fed2011-04-18 08:33:37 +00004136 result.AppendError ("invalid target\n");
Jim Inghamd60d94a2011-03-11 03:53:59 +00004137 result.SetStatus (eReturnStatusFailed);
4138 }
4139
4140 return result.Succeeded();
4141 }
4142private:
4143 CommandOptions m_options;
4144};
4145
Greg Claytonb3448432011-03-24 21:19:54 +00004146OptionDefinition
Jim Inghamd60d94a2011-03-11 03:53:59 +00004147CommandObjectTargetStopHookAdd::CommandOptions::g_option_table[] =
4148{
Johnny Chen60fe60e2011-05-02 23:47:55 +00004149 { LLDB_OPT_SET_ALL, false, "one-liner", 'o', required_argument, NULL, NULL, eArgTypeOneLiner,
4150 "Specify a one-line breakpoint command inline. Be sure to surround it with quotes." },
Jim Inghamd60d94a2011-03-11 03:53:59 +00004151 { LLDB_OPT_SET_ALL, false, "shlib", 's', required_argument, NULL, CommandCompletions::eModuleCompletion, eArgTypeShlibName,
4152 "Set the module within which the stop-hook is to be run."},
4153 { LLDB_OPT_SET_ALL, false, "thread-index", 'x', required_argument, NULL, NULL, eArgTypeThreadIndex,
4154 "The stop hook is run only for the thread whose index matches this argument."},
4155 { LLDB_OPT_SET_ALL, false, "thread-id", 't', required_argument, NULL, NULL, eArgTypeThreadID,
4156 "The stop hook is run only for the thread whose TID matches this argument."},
4157 { LLDB_OPT_SET_ALL, false, "thread-name", 'T', required_argument, NULL, NULL, eArgTypeThreadName,
4158 "The stop hook is run only for the thread whose thread name matches this argument."},
4159 { LLDB_OPT_SET_ALL, false, "queue-name", 'q', required_argument, NULL, NULL, eArgTypeQueueName,
4160 "The stop hook is run only for threads in the queue whose name is given by this argument."},
4161 { LLDB_OPT_SET_1, false, "file", 'f', required_argument, NULL, CommandCompletions::eSourceFileCompletion, eArgTypeFilename,
4162 "Specify the source file within which the stop-hook is to be run." },
4163 { LLDB_OPT_SET_1, false, "start-line", 'l', required_argument, NULL, 0, eArgTypeLineNum,
4164 "Set the start of the line range for which the stop-hook is to be run."},
4165 { LLDB_OPT_SET_1, false, "end-line", 'e', required_argument, NULL, 0, eArgTypeLineNum,
4166 "Set the end of the line range for which the stop-hook is to be run."},
4167 { LLDB_OPT_SET_2, false, "classname", 'c', required_argument, NULL, NULL, eArgTypeClassName,
4168 "Specify the class within which the stop-hook is to be run." },
4169 { LLDB_OPT_SET_3, false, "name", 'n', required_argument, NULL, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName,
4170 "Set the function name within which the stop hook will be run." },
4171 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
4172};
4173
4174#pragma mark CommandObjectTargetStopHookDelete
4175
4176//-------------------------------------------------------------------------
4177// CommandObjectTargetStopHookDelete
4178//-------------------------------------------------------------------------
4179
4180class CommandObjectTargetStopHookDelete : public CommandObject
4181{
4182public:
4183
4184 CommandObjectTargetStopHookDelete (CommandInterpreter &interpreter) :
4185 CommandObject (interpreter,
Jason Molenda3fccc902011-11-10 23:03:44 +00004186 "target stop-hook delete",
Jim Inghamd60d94a2011-03-11 03:53:59 +00004187 "Delete a stop-hook.",
Jason Molenda3fccc902011-11-10 23:03:44 +00004188 "target stop-hook delete [<idx>]")
Jim Inghamd60d94a2011-03-11 03:53:59 +00004189 {
4190 }
4191
4192 ~CommandObjectTargetStopHookDelete ()
4193 {
4194 }
4195
4196 bool
4197 Execute (Args& command,
4198 CommandReturnObject &result)
4199 {
4200 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
4201 if (target)
4202 {
4203 // FIXME: see if we can use the breakpoint id style parser?
4204 size_t num_args = command.GetArgumentCount();
4205 if (num_args == 0)
4206 {
4207 if (!m_interpreter.Confirm ("Delete all stop hooks?", true))
4208 {
4209 result.SetStatus (eReturnStatusFailed);
4210 return false;
4211 }
4212 else
4213 {
4214 target->RemoveAllStopHooks();
4215 }
4216 }
4217 else
4218 {
4219 bool success;
4220 for (size_t i = 0; i < num_args; i++)
4221 {
4222 lldb::user_id_t user_id = Args::StringToUInt32 (command.GetArgumentAtIndex(i), 0, 0, &success);
4223 if (!success)
4224 {
Greg Claytonabe0fed2011-04-18 08:33:37 +00004225 result.AppendErrorWithFormat ("invalid stop hook id: \"%s\".\n", command.GetArgumentAtIndex(i));
Jim Inghamd60d94a2011-03-11 03:53:59 +00004226 result.SetStatus(eReturnStatusFailed);
4227 return false;
4228 }
4229 success = target->RemoveStopHookByID (user_id);
4230 if (!success)
4231 {
Greg Claytonabe0fed2011-04-18 08:33:37 +00004232 result.AppendErrorWithFormat ("unknown stop hook id: \"%s\".\n", command.GetArgumentAtIndex(i));
Jim Inghamd60d94a2011-03-11 03:53:59 +00004233 result.SetStatus(eReturnStatusFailed);
4234 return false;
4235 }
4236 }
4237 }
4238 result.SetStatus (eReturnStatusSuccessFinishNoResult);
4239 }
4240 else
4241 {
Greg Claytonabe0fed2011-04-18 08:33:37 +00004242 result.AppendError ("invalid target\n");
Jim Inghamd60d94a2011-03-11 03:53:59 +00004243 result.SetStatus (eReturnStatusFailed);
4244 }
4245
4246 return result.Succeeded();
4247 }
4248};
4249#pragma mark CommandObjectTargetStopHookEnableDisable
4250
4251//-------------------------------------------------------------------------
4252// CommandObjectTargetStopHookEnableDisable
4253//-------------------------------------------------------------------------
4254
4255class CommandObjectTargetStopHookEnableDisable : public CommandObject
4256{
4257public:
4258
4259 CommandObjectTargetStopHookEnableDisable (CommandInterpreter &interpreter, bool enable, const char *name, const char *help, const char *syntax) :
4260 CommandObject (interpreter,
4261 name,
4262 help,
4263 syntax),
4264 m_enable (enable)
4265 {
4266 }
4267
4268 ~CommandObjectTargetStopHookEnableDisable ()
4269 {
4270 }
4271
4272 bool
4273 Execute (Args& command,
4274 CommandReturnObject &result)
4275 {
4276 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
4277 if (target)
4278 {
4279 // FIXME: see if we can use the breakpoint id style parser?
4280 size_t num_args = command.GetArgumentCount();
4281 bool success;
4282
4283 if (num_args == 0)
4284 {
4285 target->SetAllStopHooksActiveState (m_enable);
4286 }
4287 else
4288 {
4289 for (size_t i = 0; i < num_args; i++)
4290 {
4291 lldb::user_id_t user_id = Args::StringToUInt32 (command.GetArgumentAtIndex(i), 0, 0, &success);
4292 if (!success)
4293 {
Greg Claytonabe0fed2011-04-18 08:33:37 +00004294 result.AppendErrorWithFormat ("invalid stop hook id: \"%s\".\n", command.GetArgumentAtIndex(i));
Jim Inghamd60d94a2011-03-11 03:53:59 +00004295 result.SetStatus(eReturnStatusFailed);
4296 return false;
4297 }
4298 success = target->SetStopHookActiveStateByID (user_id, m_enable);
4299 if (!success)
4300 {
Greg Claytonabe0fed2011-04-18 08:33:37 +00004301 result.AppendErrorWithFormat ("unknown stop hook id: \"%s\".\n", command.GetArgumentAtIndex(i));
Jim Inghamd60d94a2011-03-11 03:53:59 +00004302 result.SetStatus(eReturnStatusFailed);
4303 return false;
4304 }
4305 }
4306 }
4307 result.SetStatus (eReturnStatusSuccessFinishNoResult);
4308 }
4309 else
4310 {
Greg Claytonabe0fed2011-04-18 08:33:37 +00004311 result.AppendError ("invalid target\n");
Jim Inghamd60d94a2011-03-11 03:53:59 +00004312 result.SetStatus (eReturnStatusFailed);
4313 }
4314 return result.Succeeded();
4315 }
4316private:
4317 bool m_enable;
4318};
4319
4320#pragma mark CommandObjectTargetStopHookList
4321
4322//-------------------------------------------------------------------------
4323// CommandObjectTargetStopHookList
4324//-------------------------------------------------------------------------
4325
4326class CommandObjectTargetStopHookList : public CommandObject
4327{
4328public:
4329
4330 CommandObjectTargetStopHookList (CommandInterpreter &interpreter) :
4331 CommandObject (interpreter,
Jason Molenda3fccc902011-11-10 23:03:44 +00004332 "target stop-hook list",
Jim Inghamd60d94a2011-03-11 03:53:59 +00004333 "List all stop-hooks.",
Jason Molenda3fccc902011-11-10 23:03:44 +00004334 "target stop-hook list [<type>]")
Jim Inghamd60d94a2011-03-11 03:53:59 +00004335 {
4336 }
4337
4338 ~CommandObjectTargetStopHookList ()
4339 {
4340 }
4341
4342 bool
4343 Execute (Args& command,
4344 CommandReturnObject &result)
4345 {
4346 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Johnny Chen9fc16922011-11-29 23:56:14 +00004347 if (!target)
Jim Inghamd60d94a2011-03-11 03:53:59 +00004348 {
Greg Claytonabe0fed2011-04-18 08:33:37 +00004349 result.AppendError ("invalid target\n");
Jim Inghamd60d94a2011-03-11 03:53:59 +00004350 result.SetStatus (eReturnStatusFailed);
Jason Molenda6e3a2412011-09-23 21:15:42 +00004351 return result.Succeeded();
Jim Inghamd60d94a2011-03-11 03:53:59 +00004352 }
4353
4354 size_t num_hooks = target->GetNumStopHooks ();
4355 if (num_hooks == 0)
4356 {
4357 result.GetOutputStream().PutCString ("No stop hooks.\n");
4358 }
4359 else
4360 {
4361 for (size_t i = 0; i < num_hooks; i++)
4362 {
4363 Target::StopHookSP this_hook = target->GetStopHookAtIndex (i);
4364 if (i > 0)
4365 result.GetOutputStream().PutCString ("\n");
4366 this_hook->GetDescription (&(result.GetOutputStream()), eDescriptionLevelFull);
4367 }
4368 }
Johnny Chen6c7c3902011-11-30 19:09:20 +00004369 result.SetStatus (eReturnStatusSuccessFinishResult);
Jim Inghamd60d94a2011-03-11 03:53:59 +00004370 return result.Succeeded();
4371 }
4372};
4373
4374#pragma mark CommandObjectMultiwordTargetStopHooks
4375//-------------------------------------------------------------------------
4376// CommandObjectMultiwordTargetStopHooks
4377//-------------------------------------------------------------------------
4378
4379class CommandObjectMultiwordTargetStopHooks : public CommandObjectMultiword
4380{
4381public:
4382
4383 CommandObjectMultiwordTargetStopHooks (CommandInterpreter &interpreter) :
4384 CommandObjectMultiword (interpreter,
4385 "target stop-hook",
4386 "A set of commands for operating on debugger target stop-hooks.",
4387 "target stop-hook <subcommand> [<subcommand-options>]")
4388 {
4389 LoadSubCommand ("add", CommandObjectSP (new CommandObjectTargetStopHookAdd (interpreter)));
4390 LoadSubCommand ("delete", CommandObjectSP (new CommandObjectTargetStopHookDelete (interpreter)));
4391 LoadSubCommand ("disable", CommandObjectSP (new CommandObjectTargetStopHookEnableDisable (interpreter,
4392 false,
4393 "target stop-hook disable [<id>]",
4394 "Disable a stop-hook.",
4395 "target stop-hook disable")));
4396 LoadSubCommand ("enable", CommandObjectSP (new CommandObjectTargetStopHookEnableDisable (interpreter,
4397 true,
4398 "target stop-hook enable [<id>]",
4399 "Enable a stop-hook.",
4400 "target stop-hook enable")));
4401 LoadSubCommand ("list", CommandObjectSP (new CommandObjectTargetStopHookList (interpreter)));
4402 }
4403
4404 ~CommandObjectMultiwordTargetStopHooks()
4405 {
4406 }
4407};
4408
4409
Chris Lattner24943d22010-06-08 16:52:24 +00004410
4411#pragma mark CommandObjectMultiwordTarget
4412
4413//-------------------------------------------------------------------------
4414// CommandObjectMultiwordTarget
4415//-------------------------------------------------------------------------
4416
Greg Clayton63094e02010-06-23 01:19:29 +00004417CommandObjectMultiwordTarget::CommandObjectMultiwordTarget (CommandInterpreter &interpreter) :
Greg Clayton238c0a12010-09-18 01:14:36 +00004418 CommandObjectMultiword (interpreter,
4419 "target",
Chris Lattner24943d22010-06-08 16:52:24 +00004420 "A set of commands for operating on debugger targets.",
4421 "target <subcommand> [<subcommand-options>]")
4422{
Greg Claytonabe0fed2011-04-18 08:33:37 +00004423
4424 LoadSubCommand ("create", CommandObjectSP (new CommandObjectTargetCreate (interpreter)));
Greg Clayton153ccd72011-08-10 02:10:13 +00004425 LoadSubCommand ("delete", CommandObjectSP (new CommandObjectTargetDelete (interpreter)));
Greg Claytonabe0fed2011-04-18 08:33:37 +00004426 LoadSubCommand ("list", CommandObjectSP (new CommandObjectTargetList (interpreter)));
4427 LoadSubCommand ("select", CommandObjectSP (new CommandObjectTargetSelect (interpreter)));
Jim Inghamd60d94a2011-03-11 03:53:59 +00004428 LoadSubCommand ("stop-hook", CommandObjectSP (new CommandObjectMultiwordTargetStopHooks (interpreter)));
Greg Claytone1f50b92011-05-03 22:09:39 +00004429 LoadSubCommand ("modules", CommandObjectSP (new CommandObjectTargetModules (interpreter)));
Greg Clayton3508c382012-02-24 01:59:29 +00004430 LoadSubCommand ("symbols", CommandObjectSP (new CommandObjectTargetSymbols (interpreter)));
Greg Clayton801417e2011-07-07 01:59:51 +00004431 LoadSubCommand ("variable", CommandObjectSP (new CommandObjectTargetVariable (interpreter)));
Chris Lattner24943d22010-06-08 16:52:24 +00004432}
4433
4434CommandObjectMultiwordTarget::~CommandObjectMultiwordTarget ()
4435{
4436}
4437
Greg Claytonabe0fed2011-04-18 08:33:37 +00004438