blob: 92076d75bc5db1d3354e346b33370f708513f6af [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"
Jason Molenda5b0afcc2012-07-12 00:20:07 +000037#include "lldb/Symbol/FuncUnwinders.h"
Greg Claytone1f50b92011-05-03 22:09:39 +000038#include "lldb/Symbol/LineTable.h"
39#include "lldb/Symbol/ObjectFile.h"
40#include "lldb/Symbol/SymbolFile.h"
41#include "lldb/Symbol/SymbolVendor.h"
Jason Molenda5b0afcc2012-07-12 00:20:07 +000042#include "lldb/Symbol/UnwindPlan.h"
Greg Clayton801417e2011-07-07 01:59:51 +000043#include "lldb/Symbol/VariableList.h"
Chris Lattner24943d22010-06-08 16:52:24 +000044#include "lldb/Target/Process.h"
45#include "lldb/Target/StackFrame.h"
46#include "lldb/Target/Thread.h"
Jim Inghamd60d94a2011-03-11 03:53:59 +000047#include "lldb/Target/ThreadSpec.h"
Chris Lattner24943d22010-06-08 16:52:24 +000048
49using namespace lldb;
50using namespace lldb_private;
51
Greg Claytonabe0fed2011-04-18 08:33:37 +000052
53
54static void
55DumpTargetInfo (uint32_t target_idx, Target *target, const char *prefix_cstr, bool show_stopped_process_status, Stream &strm)
56{
Greg Clayton52c8b6e2011-04-19 04:19:37 +000057 const ArchSpec &target_arch = target->GetArchitecture();
Greg Claytonabe0fed2011-04-18 08:33:37 +000058
Greg Clayton5beb99d2011-08-11 02:48:45 +000059 Module *exe_module = target->GetExecutableModulePointer();
Greg Claytonabe0fed2011-04-18 08:33:37 +000060 char exe_path[PATH_MAX];
61 bool exe_valid = false;
Greg Clayton5beb99d2011-08-11 02:48:45 +000062 if (exe_module)
63 exe_valid = exe_module->GetFileSpec().GetPath (exe_path, sizeof(exe_path));
Greg Claytonabe0fed2011-04-18 08:33:37 +000064
65 if (!exe_valid)
66 ::strcpy (exe_path, "<none>");
67
68 strm.Printf ("%starget #%u: %s", prefix_cstr ? prefix_cstr : "", target_idx, exe_path);
69
70 uint32_t properties = 0;
71 if (target_arch.IsValid())
72 {
73 strm.Printf ("%sarch=%s", properties++ > 0 ? ", " : " ( ", target_arch.GetTriple().str().c_str());
74 properties++;
75 }
76 PlatformSP platform_sp (target->GetPlatform());
77 if (platform_sp)
78 strm.Printf ("%splatform=%s", properties++ > 0 ? ", " : " ( ", platform_sp->GetName());
79
80 ProcessSP process_sp (target->GetProcessSP());
81 bool show_process_status = false;
82 if (process_sp)
83 {
84 lldb::pid_t pid = process_sp->GetID();
85 StateType state = process_sp->GetState();
86 if (show_stopped_process_status)
Greg Clayton20206082011-11-17 01:23:07 +000087 show_process_status = StateIsStoppedState(state, true);
Greg Claytonabe0fed2011-04-18 08:33:37 +000088 const char *state_cstr = StateAsCString (state);
89 if (pid != LLDB_INVALID_PROCESS_ID)
Greg Claytond9919d32011-12-01 23:28:38 +000090 strm.Printf ("%spid=%llu", properties++ > 0 ? ", " : " ( ", pid);
Greg Claytonabe0fed2011-04-18 08:33:37 +000091 strm.Printf ("%sstate=%s", properties++ > 0 ? ", " : " ( ", state_cstr);
92 }
93 if (properties > 0)
94 strm.PutCString (" )\n");
95 else
96 strm.EOL();
97 if (show_process_status)
98 {
99 const bool only_threads_with_stop_reason = true;
100 const uint32_t start_frame = 0;
101 const uint32_t num_frames = 1;
102 const uint32_t num_frames_with_source = 1;
103 process_sp->GetStatus (strm);
104 process_sp->GetThreadStatus (strm,
105 only_threads_with_stop_reason,
106 start_frame,
107 num_frames,
108 num_frames_with_source);
109
110 }
111}
112
113static uint32_t
114DumpTargetList (TargetList &target_list, bool show_stopped_process_status, Stream &strm)
115{
116 const uint32_t num_targets = target_list.GetNumTargets();
117 if (num_targets)
118 {
119 TargetSP selected_target_sp (target_list.GetSelectedTarget());
120 strm.PutCString ("Current targets:\n");
121 for (uint32_t i=0; i<num_targets; ++i)
122 {
123 TargetSP target_sp (target_list.GetTargetAtIndex (i));
124 if (target_sp)
125 {
126 bool is_selected = target_sp.get() == selected_target_sp.get();
127 DumpTargetInfo (i,
128 target_sp.get(),
129 is_selected ? "* " : " ",
130 show_stopped_process_status,
131 strm);
132 }
133 }
134 }
135 return num_targets;
136}
137#pragma mark CommandObjectTargetCreate
138
139//-------------------------------------------------------------------------
140// "target create"
141//-------------------------------------------------------------------------
142
Jim Inghamda26bd22012-06-08 21:56:10 +0000143class CommandObjectTargetCreate : public CommandObjectParsed
Greg Claytonabe0fed2011-04-18 08:33:37 +0000144{
145public:
146 CommandObjectTargetCreate(CommandInterpreter &interpreter) :
Jim Inghamda26bd22012-06-08 21:56:10 +0000147 CommandObjectParsed (interpreter,
148 "target create",
149 "Create a target using the argument as the main executable.",
150 NULL),
Greg Claytonabe0fed2011-04-18 08:33:37 +0000151 m_option_group (interpreter),
Greg Clayton801417e2011-07-07 01:59:51 +0000152 m_arch_option (),
Greg Clayton46c9a352012-02-09 06:16:32 +0000153 m_platform_options(true), // Do include the "--platform" option in the platform settings by passing true
Johnny Chen6c061be2012-08-15 22:10:42 +0000154 m_core_file (LLDB_OPT_SET_1, false, "core", 'c', 0, eArgTypePath, "Fullpath to a core file to use for this target.")
Greg Claytonabe0fed2011-04-18 08:33:37 +0000155 {
156 CommandArgumentEntry arg;
157 CommandArgumentData file_arg;
158
159 // Define the first (and only) variant of this arg.
160 file_arg.arg_type = eArgTypeFilename;
161 file_arg.arg_repetition = eArgRepeatPlain;
162
163 // There is only one variant this argument could be; put it into the argument entry.
164 arg.push_back (file_arg);
165
166 // Push the data for the first argument into the m_arguments vector.
167 m_arguments.push_back (arg);
168
Greg Clayton801417e2011-07-07 01:59:51 +0000169 m_option_group.Append (&m_arch_option, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
Greg Claytonabe0fed2011-04-18 08:33:37 +0000170 m_option_group.Append (&m_platform_options, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
Greg Clayton46c9a352012-02-09 06:16:32 +0000171 m_option_group.Append (&m_core_file, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
Greg Claytonabe0fed2011-04-18 08:33:37 +0000172 m_option_group.Finalize();
173 }
174
175 ~CommandObjectTargetCreate ()
176 {
177 }
178
179 Options *
180 GetOptions ()
181 {
182 return &m_option_group;
183 }
184
Jim Inghamda26bd22012-06-08 21:56:10 +0000185 int
186 HandleArgumentCompletion (Args &input,
187 int &cursor_index,
188 int &cursor_char_position,
189 OptionElementVector &opt_element_vector,
190 int match_start_point,
191 int max_return_elements,
192 bool &word_complete,
193 StringList &matches)
194 {
195 std::string completion_str (input.GetArgumentAtIndex(cursor_index));
196 completion_str.erase (cursor_char_position);
197
198 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
199 CommandCompletions::eDiskFileCompletion,
200 completion_str.c_str(),
201 match_start_point,
202 max_return_elements,
203 NULL,
204 word_complete,
205 matches);
206 return matches.GetSize();
207 }
208
209protected:
Greg Claytonabe0fed2011-04-18 08:33:37 +0000210 bool
Jim Inghamda26bd22012-06-08 21:56:10 +0000211 DoExecute (Args& command, CommandReturnObject &result)
Greg Claytonabe0fed2011-04-18 08:33:37 +0000212 {
213 const int argc = command.GetArgumentCount();
Greg Clayton46c9a352012-02-09 06:16:32 +0000214 FileSpec core_file (m_core_file.GetOptionValue().GetCurrentValue());
215
216 if (argc == 1 || core_file)
Greg Claytonabe0fed2011-04-18 08:33:37 +0000217 {
218 const char *file_path = command.GetArgumentAtIndex(0);
219 Timer scoped_timer(__PRETTY_FUNCTION__, "(lldb) target create '%s'", file_path);
Greg Clayton46c9a352012-02-09 06:16:32 +0000220 FileSpec file_spec;
221
222 if (file_path)
223 file_spec.SetFile (file_path, true);
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000224
Greg Claytonabe0fed2011-04-18 08:33:37 +0000225 TargetSP target_sp;
226 Debugger &debugger = m_interpreter.GetDebugger();
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000227 const char *arch_cstr = m_arch_option.GetArchitectureName();
228 const bool get_dependent_files = true;
229 Error error (debugger.GetTargetList().CreateTarget (debugger,
230 file_spec,
231 arch_cstr,
232 get_dependent_files,
233 &m_platform_options,
234 target_sp));
235
Greg Claytonabe0fed2011-04-18 08:33:37 +0000236 if (target_sp)
237 {
238 debugger.GetTargetList().SetSelectedTarget(target_sp.get());
Greg Clayton46c9a352012-02-09 06:16:32 +0000239 if (core_file)
240 {
Greg Clayton46c9a352012-02-09 06:16:32 +0000241 char core_path[PATH_MAX];
242 core_file.GetPath(core_path, sizeof(core_path));
Greg Clayton9ce95382012-02-13 23:10:39 +0000243 if (core_file.Exists())
Greg Clayton46c9a352012-02-09 06:16:32 +0000244 {
Greg Clayton9ce95382012-02-13 23:10:39 +0000245 FileSpec core_file_dir;
246 core_file_dir.GetDirectory() = core_file.GetDirectory();
247 target_sp->GetExecutableSearchPaths ().Append (core_file_dir);
Greg Clayton46c9a352012-02-09 06:16:32 +0000248
Greg Clayton9ce95382012-02-13 23:10:39 +0000249 ProcessSP process_sp (target_sp->CreateProcess (m_interpreter.GetDebugger().GetListener(), NULL, &core_file));
250
251 if (process_sp)
Greg Clayton46c9a352012-02-09 06:16:32 +0000252 {
Greg Clayton9ce95382012-02-13 23:10:39 +0000253 // Seems wierd that we Launch a core file, but that is
254 // what we do!
255 error = process_sp->LoadCore();
256
257 if (error.Fail())
258 {
259 result.AppendError(error.AsCString("can't find plug-in for core file"));
260 result.SetStatus (eReturnStatusFailed);
261 return false;
262 }
263 else
264 {
265 result.AppendMessageWithFormat ("Core file '%s' (%s) was loaded.\n", core_path, target_sp->GetArchitecture().GetArchitectureName());
266 result.SetStatus (eReturnStatusSuccessFinishNoResult);
267 }
Greg Clayton46c9a352012-02-09 06:16:32 +0000268 }
269 else
270 {
Greg Clayton9ce95382012-02-13 23:10:39 +0000271 result.AppendErrorWithFormat ("Unable to find process plug-in for core file '%s'\n", core_path);
272 result.SetStatus (eReturnStatusFailed);
Greg Clayton46c9a352012-02-09 06:16:32 +0000273 }
274 }
275 else
276 {
Greg Clayton9ce95382012-02-13 23:10:39 +0000277 result.AppendErrorWithFormat ("Core file '%s' does not exist\n", core_path);
Greg Clayton46c9a352012-02-09 06:16:32 +0000278 result.SetStatus (eReturnStatusFailed);
279 }
280 }
281 else
282 {
283 result.AppendMessageWithFormat ("Current executable set to '%s' (%s).\n", file_path, target_sp->GetArchitecture().GetArchitectureName());
284 result.SetStatus (eReturnStatusSuccessFinishNoResult);
285 }
Greg Claytonabe0fed2011-04-18 08:33:37 +0000286 }
287 else
288 {
289 result.AppendError(error.AsCString());
290 result.SetStatus (eReturnStatusFailed);
291 }
292 }
293 else
294 {
Greg Clayton46c9a352012-02-09 06:16:32 +0000295 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 +0000296 result.SetStatus (eReturnStatusFailed);
297 }
298 return result.Succeeded();
299
300 }
301
Greg Claytonabe0fed2011-04-18 08:33:37 +0000302private:
303 OptionGroupOptions m_option_group;
Greg Clayton801417e2011-07-07 01:59:51 +0000304 OptionGroupArchitecture m_arch_option;
Greg Claytonabe0fed2011-04-18 08:33:37 +0000305 OptionGroupPlatform m_platform_options;
Greg Clayton46c9a352012-02-09 06:16:32 +0000306 OptionGroupFile m_core_file;
Greg Claytonabe0fed2011-04-18 08:33:37 +0000307
308};
309
310#pragma mark CommandObjectTargetList
311
312//----------------------------------------------------------------------
313// "target list"
314//----------------------------------------------------------------------
315
Jim Inghamda26bd22012-06-08 21:56:10 +0000316class CommandObjectTargetList : public CommandObjectParsed
Greg Claytonabe0fed2011-04-18 08:33:37 +0000317{
318public:
319 CommandObjectTargetList (CommandInterpreter &interpreter) :
Jim Inghamda26bd22012-06-08 21:56:10 +0000320 CommandObjectParsed (interpreter,
321 "target list",
322 "List all current targets in the current debug session.",
323 NULL,
324 0)
Greg Claytonabe0fed2011-04-18 08:33:37 +0000325 {
326 }
327
328 virtual
329 ~CommandObjectTargetList ()
330 {
331 }
332
Jim Inghamda26bd22012-06-08 21:56:10 +0000333protected:
Greg Claytonabe0fed2011-04-18 08:33:37 +0000334 virtual bool
Jim Inghamda26bd22012-06-08 21:56:10 +0000335 DoExecute (Args& args, CommandReturnObject &result)
Greg Claytonabe0fed2011-04-18 08:33:37 +0000336 {
337 if (args.GetArgumentCount() == 0)
338 {
339 Stream &strm = result.GetOutputStream();
340
341 bool show_stopped_process_status = false;
342 if (DumpTargetList (m_interpreter.GetDebugger().GetTargetList(), show_stopped_process_status, strm) == 0)
343 {
344 strm.PutCString ("No targets.\n");
345 }
Johnny Chen44dc9d32011-04-18 21:08:05 +0000346 result.SetStatus (eReturnStatusSuccessFinishResult);
Greg Claytonabe0fed2011-04-18 08:33:37 +0000347 }
348 else
349 {
350 result.AppendError ("the 'target list' command takes no arguments\n");
351 result.SetStatus (eReturnStatusFailed);
352 }
353 return result.Succeeded();
354 }
355};
356
357
358#pragma mark CommandObjectTargetSelect
359
360//----------------------------------------------------------------------
361// "target select"
362//----------------------------------------------------------------------
363
Jim Inghamda26bd22012-06-08 21:56:10 +0000364class CommandObjectTargetSelect : public CommandObjectParsed
Greg Claytonabe0fed2011-04-18 08:33:37 +0000365{
366public:
367 CommandObjectTargetSelect (CommandInterpreter &interpreter) :
Jim Inghamda26bd22012-06-08 21:56:10 +0000368 CommandObjectParsed (interpreter,
369 "target select",
370 "Select a target as the current target by target index.",
371 NULL,
372 0)
Greg Claytonabe0fed2011-04-18 08:33:37 +0000373 {
374 }
375
376 virtual
377 ~CommandObjectTargetSelect ()
378 {
379 }
380
Jim Inghamda26bd22012-06-08 21:56:10 +0000381protected:
Greg Claytonabe0fed2011-04-18 08:33:37 +0000382 virtual bool
Jim Inghamda26bd22012-06-08 21:56:10 +0000383 DoExecute (Args& args, CommandReturnObject &result)
Greg Claytonabe0fed2011-04-18 08:33:37 +0000384 {
385 if (args.GetArgumentCount() == 1)
386 {
387 bool success = false;
388 const char *target_idx_arg = args.GetArgumentAtIndex(0);
389 uint32_t target_idx = Args::StringToUInt32 (target_idx_arg, UINT32_MAX, 0, &success);
390 if (success)
391 {
392 TargetList &target_list = m_interpreter.GetDebugger().GetTargetList();
393 const uint32_t num_targets = target_list.GetNumTargets();
394 if (target_idx < num_targets)
395 {
396 TargetSP target_sp (target_list.GetTargetAtIndex (target_idx));
397 if (target_sp)
398 {
399 Stream &strm = result.GetOutputStream();
400 target_list.SetSelectedTarget (target_sp.get());
401 bool show_stopped_process_status = false;
402 DumpTargetList (target_list, show_stopped_process_status, strm);
Johnny Chen44dc9d32011-04-18 21:08:05 +0000403 result.SetStatus (eReturnStatusSuccessFinishResult);
Greg Claytonabe0fed2011-04-18 08:33:37 +0000404 }
405 else
406 {
407 result.AppendErrorWithFormat ("target #%u is NULL in target list\n", target_idx);
408 result.SetStatus (eReturnStatusFailed);
409 }
410 }
411 else
412 {
413 result.AppendErrorWithFormat ("index %u is out of range, valid target indexes are 0 - %u\n",
414 target_idx,
415 num_targets - 1);
416 result.SetStatus (eReturnStatusFailed);
417 }
418 }
419 else
420 {
421 result.AppendErrorWithFormat("invalid index string value '%s'\n", target_idx_arg);
422 result.SetStatus (eReturnStatusFailed);
423 }
424 }
425 else
426 {
427 result.AppendError ("'target select' takes a single argument: a target index\n");
428 result.SetStatus (eReturnStatusFailed);
429 }
430 return result.Succeeded();
431 }
432};
433
Greg Clayton153ccd72011-08-10 02:10:13 +0000434#pragma mark CommandObjectTargetSelect
435
436//----------------------------------------------------------------------
437// "target delete"
438//----------------------------------------------------------------------
439
Jim Inghamda26bd22012-06-08 21:56:10 +0000440class CommandObjectTargetDelete : public CommandObjectParsed
Greg Clayton153ccd72011-08-10 02:10:13 +0000441{
442public:
443 CommandObjectTargetDelete (CommandInterpreter &interpreter) :
Jim Inghamda26bd22012-06-08 21:56:10 +0000444 CommandObjectParsed (interpreter,
445 "target delete",
446 "Delete one or more targets by target index.",
447 NULL,
448 0),
Greg Clayton5beb99d2011-08-11 02:48:45 +0000449 m_option_group (interpreter),
450 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 +0000451 {
Greg Clayton5beb99d2011-08-11 02:48:45 +0000452 m_option_group.Append (&m_cleanup_option, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
453 m_option_group.Finalize();
Greg Clayton153ccd72011-08-10 02:10:13 +0000454 }
455
456 virtual
457 ~CommandObjectTargetDelete ()
458 {
459 }
460
Jim Inghamda26bd22012-06-08 21:56:10 +0000461 Options *
462 GetOptions ()
463 {
464 return &m_option_group;
465 }
466
467protected:
Greg Clayton153ccd72011-08-10 02:10:13 +0000468 virtual bool
Jim Inghamda26bd22012-06-08 21:56:10 +0000469 DoExecute (Args& args, CommandReturnObject &result)
Greg Clayton153ccd72011-08-10 02:10:13 +0000470 {
471 const size_t argc = args.GetArgumentCount();
472 std::vector<TargetSP> delete_target_list;
473 TargetList &target_list = m_interpreter.GetDebugger().GetTargetList();
474 bool success = true;
475 TargetSP target_sp;
476 if (argc > 0)
477 {
478 const uint32_t num_targets = target_list.GetNumTargets();
Filipe Cabecinhasaa3d89e2012-07-09 13:02:17 +0000479 // Bail out if don't have any targets.
480 if (num_targets == 0) {
481 result.AppendError("no targets to delete");
482 result.SetStatus(eReturnStatusFailed);
483 success = false;
484 }
485
Greg Clayton153ccd72011-08-10 02:10:13 +0000486 for (uint32_t arg_idx = 0; success && arg_idx < argc; ++arg_idx)
487 {
488 const char *target_idx_arg = args.GetArgumentAtIndex(arg_idx);
489 uint32_t target_idx = Args::StringToUInt32 (target_idx_arg, UINT32_MAX, 0, &success);
490 if (success)
491 {
492 if (target_idx < num_targets)
493 {
494 target_sp = target_list.GetTargetAtIndex (target_idx);
495 if (target_sp)
496 {
497 delete_target_list.push_back (target_sp);
498 continue;
499 }
500 }
Filipe Cabecinhasaa3d89e2012-07-09 13:02:17 +0000501 if (num_targets > 1)
502 result.AppendErrorWithFormat ("target index %u is out of range, valid target indexes are 0 - %u\n",
503 target_idx,
504 num_targets - 1);
505 else
506 result.AppendErrorWithFormat("target index %u is out of range, the only valid index is 0\n",
507 target_idx);
508
Greg Clayton153ccd72011-08-10 02:10:13 +0000509 result.SetStatus (eReturnStatusFailed);
510 success = false;
511 }
512 else
513 {
514 result.AppendErrorWithFormat("invalid target index '%s'\n", target_idx_arg);
515 result.SetStatus (eReturnStatusFailed);
516 success = false;
517 }
518 }
519
520 }
521 else
522 {
523 target_sp = target_list.GetSelectedTarget();
524 if (target_sp)
525 {
526 delete_target_list.push_back (target_sp);
527 }
528 else
529 {
530 result.AppendErrorWithFormat("no target is currently selected\n");
531 result.SetStatus (eReturnStatusFailed);
532 success = false;
533 }
534 }
535 if (success)
536 {
537 const size_t num_targets_to_delete = delete_target_list.size();
538 for (size_t idx = 0; idx < num_targets_to_delete; ++idx)
539 {
540 target_sp = delete_target_list[idx];
541 target_list.DeleteTarget(target_sp);
542 target_sp->Destroy();
543 }
Greg Clayton5beb99d2011-08-11 02:48:45 +0000544 // If "--clean" was specified, prune any orphaned shared modules from
545 // the global shared module list
546 if (m_cleanup_option.GetOptionValue ())
547 {
Greg Clayton860b9ea2012-04-09 20:22:01 +0000548 const bool mandatory = true;
549 ModuleList::RemoveOrphanSharedModules(mandatory);
Greg Clayton5beb99d2011-08-11 02:48:45 +0000550 }
Greg Clayton153ccd72011-08-10 02:10:13 +0000551 result.GetOutputStream().Printf("%u targets deleted.\n", (uint32_t)num_targets_to_delete);
552 result.SetStatus(eReturnStatusSuccessFinishResult);
553 }
554
555 return result.Succeeded();
556 }
Greg Clayton5beb99d2011-08-11 02:48:45 +0000557
Greg Clayton5beb99d2011-08-11 02:48:45 +0000558 OptionGroupOptions m_option_group;
559 OptionGroupBoolean m_cleanup_option;
Greg Clayton153ccd72011-08-10 02:10:13 +0000560};
561
Greg Claytonabe0fed2011-04-18 08:33:37 +0000562
Greg Clayton801417e2011-07-07 01:59:51 +0000563#pragma mark CommandObjectTargetVariable
564
565//----------------------------------------------------------------------
566// "target variable"
567//----------------------------------------------------------------------
568
Jim Inghamda26bd22012-06-08 21:56:10 +0000569class CommandObjectTargetVariable : public CommandObjectParsed
Greg Clayton801417e2011-07-07 01:59:51 +0000570{
571public:
572 CommandObjectTargetVariable (CommandInterpreter &interpreter) :
Jim Inghamda26bd22012-06-08 21:56:10 +0000573 CommandObjectParsed (interpreter,
574 "target variable",
575 "Read global variable(s) prior to running your binary.",
576 NULL,
577 0),
Greg Clayton801417e2011-07-07 01:59:51 +0000578 m_option_group (interpreter),
Greg Clayton368f8222011-07-07 04:38:25 +0000579 m_option_variable (false), // Don't include frame options
Greg Claytona42880a2011-10-25 06:44:01 +0000580 m_option_format (eFormatDefault),
Greg Clayton801417e2011-07-07 01:59:51 +0000581 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."),
582 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."),
583 m_varobj_options()
584 {
Johnny Chen24b81e32011-08-22 22:22:00 +0000585 CommandArgumentEntry arg;
586 CommandArgumentData var_name_arg;
587
588 // Define the first (and only) variant of this arg.
589 var_name_arg.arg_type = eArgTypeVarName;
590 var_name_arg.arg_repetition = eArgRepeatPlus;
591
592 // There is only one variant this argument could be; put it into the argument entry.
593 arg.push_back (var_name_arg);
594
595 // Push the data for the first argument into the m_arguments vector.
596 m_arguments.push_back (arg);
597
Greg Clayton801417e2011-07-07 01:59:51 +0000598 m_option_group.Append (&m_varobj_options, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
Greg Clayton368f8222011-07-07 04:38:25 +0000599 m_option_group.Append (&m_option_variable, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
Greg Clayton24a6bd92011-10-27 17:55:14 +0000600 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 +0000601 m_option_group.Append (&m_option_compile_units, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
602 m_option_group.Append (&m_option_shared_libraries, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
603 m_option_group.Finalize();
604 }
605
606 virtual
607 ~CommandObjectTargetVariable ()
608 {
609 }
Greg Clayton5d81f492011-07-08 21:46:14 +0000610
611 void
612 DumpValueObject (Stream &s, VariableSP &var_sp, ValueObjectSP &valobj_sp, const char *root_name)
613 {
Enrico Granata19030d82011-08-15 18:01:31 +0000614 ValueObject::DumpValueObjectOptions options;
615
Enrico Granata3069c622012-03-01 04:24:26 +0000616 options.SetMaximumPointerDepth(m_varobj_options.ptr_depth)
Enrico Granata19030d82011-08-15 18:01:31 +0000617 .SetMaximumDepth(m_varobj_options.max_depth)
618 .SetShowTypes(m_varobj_options.show_types)
619 .SetShowLocation(m_varobj_options.show_location)
620 .SetUseObjectiveC(m_varobj_options.use_objc)
621 .SetUseDynamicType(m_varobj_options.use_dynamic)
Enrico Granatacf09f882012-03-19 22:58:49 +0000622 .SetUseSyntheticValue(m_varobj_options.use_synth)
Enrico Granata19030d82011-08-15 18:01:31 +0000623 .SetFlatOutput(m_varobj_options.flat_output)
624 .SetOmitSummaryDepth(m_varobj_options.no_summary_depth)
625 .SetIgnoreCap(m_varobj_options.ignore_cap);
626
Greg Clayton5d81f492011-07-08 21:46:14 +0000627 switch (var_sp->GetScope())
628 {
629 case eValueTypeVariableGlobal:
630 if (m_option_variable.show_scope)
631 s.PutCString("GLOBAL: ");
632 break;
633
634 case eValueTypeVariableStatic:
635 if (m_option_variable.show_scope)
636 s.PutCString("STATIC: ");
637 break;
638
639 case eValueTypeVariableArgument:
640 if (m_option_variable.show_scope)
641 s.PutCString(" ARG: ");
642 break;
643
644 case eValueTypeVariableLocal:
645 if (m_option_variable.show_scope)
646 s.PutCString(" LOCAL: ");
647 break;
648
649 default:
650 break;
651 }
652
Greg Claytonfb816422011-07-10 19:21:23 +0000653 if (m_option_variable.show_decl)
Greg Clayton5d81f492011-07-08 21:46:14 +0000654 {
Greg Claytonfb816422011-07-10 19:21:23 +0000655 bool show_fullpaths = false;
656 bool show_module = true;
657 if (var_sp->DumpDeclaration(&s, show_fullpaths, show_module))
658 s.PutCString (": ");
Greg Clayton5d81f492011-07-08 21:46:14 +0000659 }
660
Greg Claytona42880a2011-10-25 06:44:01 +0000661 const Format format = m_option_format.GetFormat();
Greg Clayton5d81f492011-07-08 21:46:14 +0000662 if (format != eFormatDefault)
Enrico Granata3069c622012-03-01 04:24:26 +0000663 options.SetFormat(format);
664
665 options.SetRootValueObjectName(root_name);
Greg Clayton5d81f492011-07-08 21:46:14 +0000666
667 ValueObject::DumpValueObject (s,
668 valobj_sp.get(),
Enrico Granata3069c622012-03-01 04:24:26 +0000669 options);
Greg Clayton5d81f492011-07-08 21:46:14 +0000670
671 }
Greg Clayton801417e2011-07-07 01:59:51 +0000672
Greg Clayton5d81f492011-07-08 21:46:14 +0000673
674 static uint32_t GetVariableCallback (void *baton,
675 const char *name,
676 VariableList &variable_list)
677 {
678 Target *target = static_cast<Target *>(baton);
679 if (target)
680 {
681 return target->GetImages().FindGlobalVariables (ConstString(name),
682 true,
683 UINT32_MAX,
684 variable_list);
685 }
686 return 0;
687 }
688
689
690
Jim Inghamda26bd22012-06-08 21:56:10 +0000691 Options *
692 GetOptions ()
693 {
694 return &m_option_group;
695 }
696
697protected:
Greg Clayton801417e2011-07-07 01:59:51 +0000698 virtual bool
Jim Inghamda26bd22012-06-08 21:56:10 +0000699 DoExecute (Args& args, CommandReturnObject &result)
Greg Clayton801417e2011-07-07 01:59:51 +0000700 {
701 ExecutionContext exe_ctx (m_interpreter.GetExecutionContext());
Greg Clayton567e7f32011-09-22 04:58:26 +0000702 Target *target = exe_ctx.GetTargetPtr();
703 if (target)
Greg Clayton801417e2011-07-07 01:59:51 +0000704 {
705 const size_t argc = args.GetArgumentCount();
Greg Claytonfac93882011-10-05 22:17:32 +0000706 Stream &s = result.GetOutputStream();
Greg Clayton801417e2011-07-07 01:59:51 +0000707 if (argc > 0)
708 {
Greg Clayton5d81f492011-07-08 21:46:14 +0000709
Greg Clayton801417e2011-07-07 01:59:51 +0000710 for (size_t idx = 0; idx < argc; ++idx)
711 {
Greg Clayton5d81f492011-07-08 21:46:14 +0000712 VariableList variable_list;
713 ValueObjectList valobj_list;
714
Greg Clayton368f8222011-07-07 04:38:25 +0000715 const char *arg = args.GetArgumentAtIndex(idx);
716 uint32_t matches = 0;
Greg Claytonfb816422011-07-10 19:21:23 +0000717 bool use_var_name = false;
Greg Clayton368f8222011-07-07 04:38:25 +0000718 if (m_option_variable.use_regex)
Greg Clayton801417e2011-07-07 01:59:51 +0000719 {
Greg Clayton368f8222011-07-07 04:38:25 +0000720 RegularExpression regex(arg);
721 if (!regex.IsValid ())
722 {
723 result.GetErrorStream().Printf ("error: invalid regular expression: '%s'\n", arg);
724 result.SetStatus (eReturnStatusFailed);
725 return false;
726 }
Greg Claytonfb816422011-07-10 19:21:23 +0000727 use_var_name = true;
Greg Clayton567e7f32011-09-22 04:58:26 +0000728 matches = target->GetImages().FindGlobalVariables (regex,
729 true,
730 UINT32_MAX,
731 variable_list);
Greg Clayton801417e2011-07-07 01:59:51 +0000732 }
733 else
734 {
Greg Clayton5d81f492011-07-08 21:46:14 +0000735 Error error (Variable::GetValuesForVariableExpressionPath (arg,
Greg Clayton24b03102011-07-09 20:12:33 +0000736 exe_ctx.GetBestExecutionContextScope(),
Greg Clayton5d81f492011-07-08 21:46:14 +0000737 GetVariableCallback,
Greg Clayton567e7f32011-09-22 04:58:26 +0000738 target,
Greg Clayton5d81f492011-07-08 21:46:14 +0000739 variable_list,
740 valobj_list));
Greg Clayton5d81f492011-07-08 21:46:14 +0000741 matches = variable_list.GetSize();
Greg Clayton368f8222011-07-07 04:38:25 +0000742 }
743
744 if (matches == 0)
745 {
746 result.GetErrorStream().Printf ("error: can't find global variable '%s'\n", arg);
747 result.SetStatus (eReturnStatusFailed);
748 return false;
749 }
750 else
751 {
Greg Clayton801417e2011-07-07 01:59:51 +0000752 for (uint32_t global_idx=0; global_idx<matches; ++global_idx)
753 {
Greg Clayton5d81f492011-07-08 21:46:14 +0000754 VariableSP var_sp (variable_list.GetVariableAtIndex(global_idx));
Greg Clayton801417e2011-07-07 01:59:51 +0000755 if (var_sp)
756 {
Greg Clayton5d81f492011-07-08 21:46:14 +0000757 ValueObjectSP valobj_sp (valobj_list.GetValueObjectAtIndex(global_idx));
758 if (!valobj_sp)
Greg Claytonfb816422011-07-10 19:21:23 +0000759 valobj_sp = ValueObjectVariable::Create (exe_ctx.GetBestExecutionContextScope(), var_sp);
Greg Clayton801417e2011-07-07 01:59:51 +0000760
761 if (valobj_sp)
Greg Claytonb304a742011-10-13 18:31:02 +0000762 DumpValueObject (s, var_sp, valobj_sp, use_var_name ? var_sp->GetName().GetCString() : arg);
Greg Clayton801417e2011-07-07 01:59:51 +0000763 }
764 }
765 }
766 }
767 }
768 else
769 {
Greg Claytonfac93882011-10-05 22:17:32 +0000770 bool success = false;
771 StackFrame *frame = exe_ctx.GetFramePtr();
772 CompileUnit *comp_unit = NULL;
773 if (frame)
774 {
775 comp_unit = frame->GetSymbolContext (eSymbolContextCompUnit).comp_unit;
776 if (comp_unit)
777 {
778 const bool can_create = true;
779 VariableListSP comp_unit_varlist_sp (comp_unit->GetVariableList(can_create));
780 if (comp_unit_varlist_sp)
781 {
782 size_t count = comp_unit_varlist_sp->GetSize();
783 if (count > 0)
784 {
Greg Claytona1b9a902011-11-13 04:15:56 +0000785 s.Printf ("Global variables for %s/%s:\n",
Greg Claytonfac93882011-10-05 22:17:32 +0000786 comp_unit->GetDirectory().GetCString(),
787 comp_unit->GetFilename().GetCString());
788
789 success = true;
790 for (uint32_t i=0; i<count; ++i)
791 {
792 VariableSP var_sp (comp_unit_varlist_sp->GetVariableAtIndex(i));
793 if (var_sp)
794 {
795 ValueObjectSP valobj_sp (ValueObjectVariable::Create (exe_ctx.GetBestExecutionContextScope(), var_sp));
796
797 if (valobj_sp)
798 DumpValueObject (s, var_sp, valobj_sp, var_sp->GetName().GetCString());
799 }
800 }
801 }
802 }
803 }
804 }
805 if (!success)
806 {
807 if (frame)
808 {
809 if (comp_unit)
810 result.AppendErrorWithFormat ("no global variables in current compile unit: %s/%s\n",
811 comp_unit->GetDirectory().GetCString(),
812 comp_unit->GetFilename().GetCString());
813 else
814 result.AppendError ("no debug information for frame %u\n", frame->GetFrameIndex());
815 }
816 else
817 result.AppendError ("'target variable' takes one or more global variable names as arguments\n");
818 result.SetStatus (eReturnStatusFailed);
819 }
Greg Clayton801417e2011-07-07 01:59:51 +0000820 }
821 }
822 else
823 {
824 result.AppendError ("invalid target, create a debug target using the 'target create' command");
825 result.SetStatus (eReturnStatusFailed);
826 return false;
827 }
Enrico Granatadb64d952011-08-12 16:42:31 +0000828
829 if (m_interpreter.TruncationWarningNecessary())
830 {
831 result.GetOutputStream().Printf(m_interpreter.TruncationWarningText(),
832 m_cmd_name.c_str());
833 m_interpreter.TruncationWarningGiven();
834 }
835
Greg Clayton801417e2011-07-07 01:59:51 +0000836 return result.Succeeded();
837 }
838
Greg Clayton801417e2011-07-07 01:59:51 +0000839 OptionGroupOptions m_option_group;
Greg Clayton368f8222011-07-07 04:38:25 +0000840 OptionGroupVariable m_option_variable;
Greg Claytona42880a2011-10-25 06:44:01 +0000841 OptionGroupFormat m_option_format;
Greg Clayton801417e2011-07-07 01:59:51 +0000842 OptionGroupFileList m_option_compile_units;
843 OptionGroupFileList m_option_shared_libraries;
844 OptionGroupValueObjectDisplay m_varobj_options;
845
846};
847
848
Greg Claytone1f50b92011-05-03 22:09:39 +0000849#pragma mark CommandObjectTargetModulesSearchPathsAdd
Chris Lattner24943d22010-06-08 16:52:24 +0000850
Jim Inghamda26bd22012-06-08 21:56:10 +0000851class CommandObjectTargetModulesSearchPathsAdd : public CommandObjectParsed
Chris Lattner24943d22010-06-08 16:52:24 +0000852{
853public:
854
Greg Claytone1f50b92011-05-03 22:09:39 +0000855 CommandObjectTargetModulesSearchPathsAdd (CommandInterpreter &interpreter) :
Jim Inghamda26bd22012-06-08 21:56:10 +0000856 CommandObjectParsed (interpreter,
857 "target modules search-paths add",
858 "Add new image search paths substitution pairs to the current target.",
859 NULL)
Chris Lattner24943d22010-06-08 16:52:24 +0000860 {
Caroline Tice43b014a2010-10-04 22:28:36 +0000861 CommandArgumentEntry arg;
862 CommandArgumentData old_prefix_arg;
863 CommandArgumentData new_prefix_arg;
864
865 // Define the first variant of this arg pair.
866 old_prefix_arg.arg_type = eArgTypeOldPathPrefix;
867 old_prefix_arg.arg_repetition = eArgRepeatPairPlus;
868
869 // Define the first variant of this arg pair.
870 new_prefix_arg.arg_type = eArgTypeNewPathPrefix;
871 new_prefix_arg.arg_repetition = eArgRepeatPairPlus;
872
873 // There are two required arguments that must always occur together, i.e. an argument "pair". Because they
874 // must always occur together, they are treated as two variants of one argument rather than two independent
875 // arguments. Push them both into the first argument position for m_arguments...
876
877 arg.push_back (old_prefix_arg);
878 arg.push_back (new_prefix_arg);
879
880 m_arguments.push_back (arg);
Chris Lattner24943d22010-06-08 16:52:24 +0000881 }
882
Greg Claytone1f50b92011-05-03 22:09:39 +0000883 ~CommandObjectTargetModulesSearchPathsAdd ()
Chris Lattner24943d22010-06-08 16:52:24 +0000884 {
885 }
886
Jim Inghamda26bd22012-06-08 21:56:10 +0000887protected:
Chris Lattner24943d22010-06-08 16:52:24 +0000888 bool
Jim Inghamda26bd22012-06-08 21:56:10 +0000889 DoExecute (Args& command,
Chris Lattner24943d22010-06-08 16:52:24 +0000890 CommandReturnObject &result)
891 {
Greg Clayton238c0a12010-09-18 01:14:36 +0000892 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Chris Lattner24943d22010-06-08 16:52:24 +0000893 if (target)
894 {
895 uint32_t argc = command.GetArgumentCount();
896 if (argc & 1)
897 {
Greg Claytonabe0fed2011-04-18 08:33:37 +0000898 result.AppendError ("add requires an even number of arguments\n");
Chris Lattner24943d22010-06-08 16:52:24 +0000899 result.SetStatus (eReturnStatusFailed);
900 }
901 else
902 {
903 for (uint32_t i=0; i<argc; i+=2)
904 {
905 const char *from = command.GetArgumentAtIndex(i);
906 const char *to = command.GetArgumentAtIndex(i+1);
907
908 if (from[0] && to[0])
909 {
910 bool last_pair = ((argc - i) == 2);
Greg Clayton63094e02010-06-23 01:19:29 +0000911 target->GetImageSearchPathList().Append (ConstString(from),
912 ConstString(to),
913 last_pair); // Notify if this is the last pair
Johnny Chen4d661352011-02-03 00:30:19 +0000914 result.SetStatus (eReturnStatusSuccessFinishNoResult);
Chris Lattner24943d22010-06-08 16:52:24 +0000915 }
916 else
917 {
918 if (from[0])
Greg Claytonabe0fed2011-04-18 08:33:37 +0000919 result.AppendError ("<path-prefix> can't be empty\n");
Chris Lattner24943d22010-06-08 16:52:24 +0000920 else
Greg Claytonabe0fed2011-04-18 08:33:37 +0000921 result.AppendError ("<new-path-prefix> can't be empty\n");
Chris Lattner24943d22010-06-08 16:52:24 +0000922 result.SetStatus (eReturnStatusFailed);
923 }
924 }
925 }
926 }
927 else
928 {
Greg Claytonabe0fed2011-04-18 08:33:37 +0000929 result.AppendError ("invalid target\n");
Chris Lattner24943d22010-06-08 16:52:24 +0000930 result.SetStatus (eReturnStatusFailed);
931 }
932 return result.Succeeded();
933 }
934};
935
Greg Claytone1f50b92011-05-03 22:09:39 +0000936#pragma mark CommandObjectTargetModulesSearchPathsClear
937
Jim Inghamda26bd22012-06-08 21:56:10 +0000938class CommandObjectTargetModulesSearchPathsClear : public CommandObjectParsed
Chris Lattner24943d22010-06-08 16:52:24 +0000939{
940public:
941
Greg Claytone1f50b92011-05-03 22:09:39 +0000942 CommandObjectTargetModulesSearchPathsClear (CommandInterpreter &interpreter) :
Jim Inghamda26bd22012-06-08 21:56:10 +0000943 CommandObjectParsed (interpreter,
944 "target modules search-paths clear",
945 "Clear all current image search path substitution pairs from the current target.",
946 "target modules search-paths clear")
Chris Lattner24943d22010-06-08 16:52:24 +0000947 {
948 }
949
Greg Claytone1f50b92011-05-03 22:09:39 +0000950 ~CommandObjectTargetModulesSearchPathsClear ()
Chris Lattner24943d22010-06-08 16:52:24 +0000951 {
952 }
953
Jim Inghamda26bd22012-06-08 21:56:10 +0000954protected:
Chris Lattner24943d22010-06-08 16:52:24 +0000955 bool
Jim Inghamda26bd22012-06-08 21:56:10 +0000956 DoExecute (Args& command,
Chris Lattner24943d22010-06-08 16:52:24 +0000957 CommandReturnObject &result)
958 {
Greg Clayton238c0a12010-09-18 01:14:36 +0000959 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Chris Lattner24943d22010-06-08 16:52:24 +0000960 if (target)
961 {
962 bool notify = true;
963 target->GetImageSearchPathList().Clear(notify);
Johnny Chen4d661352011-02-03 00:30:19 +0000964 result.SetStatus (eReturnStatusSuccessFinishNoResult);
Chris Lattner24943d22010-06-08 16:52:24 +0000965 }
966 else
967 {
Greg Claytonabe0fed2011-04-18 08:33:37 +0000968 result.AppendError ("invalid target\n");
Chris Lattner24943d22010-06-08 16:52:24 +0000969 result.SetStatus (eReturnStatusFailed);
970 }
971 return result.Succeeded();
972 }
973};
974
Greg Claytone1f50b92011-05-03 22:09:39 +0000975#pragma mark CommandObjectTargetModulesSearchPathsInsert
976
Jim Inghamda26bd22012-06-08 21:56:10 +0000977class CommandObjectTargetModulesSearchPathsInsert : public CommandObjectParsed
Chris Lattner24943d22010-06-08 16:52:24 +0000978{
979public:
980
Greg Claytone1f50b92011-05-03 22:09:39 +0000981 CommandObjectTargetModulesSearchPathsInsert (CommandInterpreter &interpreter) :
Jim Inghamda26bd22012-06-08 21:56:10 +0000982 CommandObjectParsed (interpreter,
983 "target modules search-paths insert",
984 "Insert a new image search path substitution pair into the current target at the specified index.",
985 NULL)
Chris Lattner24943d22010-06-08 16:52:24 +0000986 {
Caroline Tice43b014a2010-10-04 22:28:36 +0000987 CommandArgumentEntry arg1;
988 CommandArgumentEntry arg2;
989 CommandArgumentData index_arg;
990 CommandArgumentData old_prefix_arg;
991 CommandArgumentData new_prefix_arg;
992
993 // Define the first and only variant of this arg.
994 index_arg.arg_type = eArgTypeIndex;
995 index_arg.arg_repetition = eArgRepeatPlain;
996
997 // Put the one and only variant into the first arg for m_arguments:
998 arg1.push_back (index_arg);
999
1000 // Define the first variant of this arg pair.
1001 old_prefix_arg.arg_type = eArgTypeOldPathPrefix;
1002 old_prefix_arg.arg_repetition = eArgRepeatPairPlus;
1003
1004 // Define the first variant of this arg pair.
1005 new_prefix_arg.arg_type = eArgTypeNewPathPrefix;
1006 new_prefix_arg.arg_repetition = eArgRepeatPairPlus;
1007
1008 // There are two required arguments that must always occur together, i.e. an argument "pair". Because they
1009 // must always occur together, they are treated as two variants of one argument rather than two independent
1010 // arguments. Push them both into the same argument position for m_arguments...
1011
1012 arg2.push_back (old_prefix_arg);
1013 arg2.push_back (new_prefix_arg);
1014
1015 // Add arguments to m_arguments.
1016 m_arguments.push_back (arg1);
1017 m_arguments.push_back (arg2);
Chris Lattner24943d22010-06-08 16:52:24 +00001018 }
1019
Greg Claytone1f50b92011-05-03 22:09:39 +00001020 ~CommandObjectTargetModulesSearchPathsInsert ()
Chris Lattner24943d22010-06-08 16:52:24 +00001021 {
1022 }
1023
Jim Inghamda26bd22012-06-08 21:56:10 +00001024protected:
Chris Lattner24943d22010-06-08 16:52:24 +00001025 bool
Jim Inghamda26bd22012-06-08 21:56:10 +00001026 DoExecute (Args& command,
Chris Lattner24943d22010-06-08 16:52:24 +00001027 CommandReturnObject &result)
1028 {
Greg Clayton238c0a12010-09-18 01:14:36 +00001029 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Chris Lattner24943d22010-06-08 16:52:24 +00001030 if (target)
1031 {
1032 uint32_t argc = command.GetArgumentCount();
1033 // check for at least 3 arguments and an odd nubmer of parameters
1034 if (argc >= 3 && argc & 1)
1035 {
1036 bool success = false;
1037
1038 uint32_t insert_idx = Args::StringToUInt32(command.GetArgumentAtIndex(0), UINT32_MAX, 0, &success);
1039
1040 if (!success)
1041 {
1042 result.AppendErrorWithFormat("<index> parameter is not an integer: '%s'.\n", command.GetArgumentAtIndex(0));
1043 result.SetStatus (eReturnStatusFailed);
1044 return result.Succeeded();
1045 }
1046
1047 // shift off the index
1048 command.Shift();
1049 argc = command.GetArgumentCount();
1050
1051 for (uint32_t i=0; i<argc; i+=2, ++insert_idx)
1052 {
1053 const char *from = command.GetArgumentAtIndex(i);
1054 const char *to = command.GetArgumentAtIndex(i+1);
1055
1056 if (from[0] && to[0])
1057 {
1058 bool last_pair = ((argc - i) == 2);
1059 target->GetImageSearchPathList().Insert (ConstString(from),
1060 ConstString(to),
1061 insert_idx,
1062 last_pair);
Johnny Chen4d661352011-02-03 00:30:19 +00001063 result.SetStatus (eReturnStatusSuccessFinishNoResult);
Chris Lattner24943d22010-06-08 16:52:24 +00001064 }
1065 else
1066 {
1067 if (from[0])
Greg Claytonabe0fed2011-04-18 08:33:37 +00001068 result.AppendError ("<path-prefix> can't be empty\n");
Chris Lattner24943d22010-06-08 16:52:24 +00001069 else
Greg Claytonabe0fed2011-04-18 08:33:37 +00001070 result.AppendError ("<new-path-prefix> can't be empty\n");
Chris Lattner24943d22010-06-08 16:52:24 +00001071 result.SetStatus (eReturnStatusFailed);
1072 return false;
1073 }
1074 }
1075 }
1076 else
1077 {
Greg Claytonabe0fed2011-04-18 08:33:37 +00001078 result.AppendError ("insert requires at least three arguments\n");
Chris Lattner24943d22010-06-08 16:52:24 +00001079 result.SetStatus (eReturnStatusFailed);
1080 return result.Succeeded();
1081 }
1082
1083 }
1084 else
1085 {
Greg Claytonabe0fed2011-04-18 08:33:37 +00001086 result.AppendError ("invalid target\n");
Chris Lattner24943d22010-06-08 16:52:24 +00001087 result.SetStatus (eReturnStatusFailed);
1088 }
1089 return result.Succeeded();
1090 }
1091};
1092
Greg Claytone1f50b92011-05-03 22:09:39 +00001093
1094#pragma mark CommandObjectTargetModulesSearchPathsList
1095
1096
Jim Inghamda26bd22012-06-08 21:56:10 +00001097class CommandObjectTargetModulesSearchPathsList : public CommandObjectParsed
Chris Lattner24943d22010-06-08 16:52:24 +00001098{
1099public:
1100
Greg Claytone1f50b92011-05-03 22:09:39 +00001101 CommandObjectTargetModulesSearchPathsList (CommandInterpreter &interpreter) :
Jim Inghamda26bd22012-06-08 21:56:10 +00001102 CommandObjectParsed (interpreter,
1103 "target modules search-paths list",
1104 "List all current image search path substitution pairs in the current target.",
1105 "target modules search-paths list")
Chris Lattner24943d22010-06-08 16:52:24 +00001106 {
1107 }
1108
Greg Claytone1f50b92011-05-03 22:09:39 +00001109 ~CommandObjectTargetModulesSearchPathsList ()
Chris Lattner24943d22010-06-08 16:52:24 +00001110 {
1111 }
1112
Jim Inghamda26bd22012-06-08 21:56:10 +00001113protected:
Chris Lattner24943d22010-06-08 16:52:24 +00001114 bool
Jim Inghamda26bd22012-06-08 21:56:10 +00001115 DoExecute (Args& command,
Chris Lattner24943d22010-06-08 16:52:24 +00001116 CommandReturnObject &result)
1117 {
Greg Clayton238c0a12010-09-18 01:14:36 +00001118 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Chris Lattner24943d22010-06-08 16:52:24 +00001119 if (target)
1120 {
1121 if (command.GetArgumentCount() != 0)
1122 {
Greg Claytonabe0fed2011-04-18 08:33:37 +00001123 result.AppendError ("list takes no arguments\n");
Chris Lattner24943d22010-06-08 16:52:24 +00001124 result.SetStatus (eReturnStatusFailed);
1125 return result.Succeeded();
1126 }
1127
1128 target->GetImageSearchPathList().Dump(&result.GetOutputStream());
Johnny Chen4d661352011-02-03 00:30:19 +00001129 result.SetStatus (eReturnStatusSuccessFinishResult);
Chris Lattner24943d22010-06-08 16:52:24 +00001130 }
1131 else
1132 {
Greg Claytonabe0fed2011-04-18 08:33:37 +00001133 result.AppendError ("invalid target\n");
Chris Lattner24943d22010-06-08 16:52:24 +00001134 result.SetStatus (eReturnStatusFailed);
1135 }
1136 return result.Succeeded();
1137 }
1138};
1139
Greg Claytone1f50b92011-05-03 22:09:39 +00001140#pragma mark CommandObjectTargetModulesSearchPathsQuery
1141
Jim Inghamda26bd22012-06-08 21:56:10 +00001142class CommandObjectTargetModulesSearchPathsQuery : public CommandObjectParsed
Chris Lattner24943d22010-06-08 16:52:24 +00001143{
1144public:
1145
Greg Claytone1f50b92011-05-03 22:09:39 +00001146 CommandObjectTargetModulesSearchPathsQuery (CommandInterpreter &interpreter) :
Jim Inghamda26bd22012-06-08 21:56:10 +00001147 CommandObjectParsed (interpreter,
1148 "target modules search-paths query",
1149 "Transform a path using the first applicable image search path.",
1150 NULL)
Chris Lattner24943d22010-06-08 16:52:24 +00001151 {
Caroline Tice43b014a2010-10-04 22:28:36 +00001152 CommandArgumentEntry arg;
1153 CommandArgumentData path_arg;
1154
1155 // Define the first (and only) variant of this arg.
1156 path_arg.arg_type = eArgTypePath;
1157 path_arg.arg_repetition = eArgRepeatPlain;
1158
1159 // There is only one variant this argument could be; put it into the argument entry.
1160 arg.push_back (path_arg);
1161
1162 // Push the data for the first argument into the m_arguments vector.
1163 m_arguments.push_back (arg);
Chris Lattner24943d22010-06-08 16:52:24 +00001164 }
1165
Greg Claytone1f50b92011-05-03 22:09:39 +00001166 ~CommandObjectTargetModulesSearchPathsQuery ()
Chris Lattner24943d22010-06-08 16:52:24 +00001167 {
1168 }
1169
Jim Inghamda26bd22012-06-08 21:56:10 +00001170protected:
Chris Lattner24943d22010-06-08 16:52:24 +00001171 bool
Jim Inghamda26bd22012-06-08 21:56:10 +00001172 DoExecute (Args& command,
Chris Lattner24943d22010-06-08 16:52:24 +00001173 CommandReturnObject &result)
1174 {
Greg Clayton238c0a12010-09-18 01:14:36 +00001175 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Chris Lattner24943d22010-06-08 16:52:24 +00001176 if (target)
1177 {
1178 if (command.GetArgumentCount() != 1)
1179 {
Greg Claytonabe0fed2011-04-18 08:33:37 +00001180 result.AppendError ("query requires one argument\n");
Chris Lattner24943d22010-06-08 16:52:24 +00001181 result.SetStatus (eReturnStatusFailed);
1182 return result.Succeeded();
1183 }
1184
1185 ConstString orig(command.GetArgumentAtIndex(0));
1186 ConstString transformed;
1187 if (target->GetImageSearchPathList().RemapPath(orig, transformed))
1188 result.GetOutputStream().Printf("%s\n", transformed.GetCString());
1189 else
1190 result.GetOutputStream().Printf("%s\n", orig.GetCString());
Johnny Chen4d661352011-02-03 00:30:19 +00001191
1192 result.SetStatus (eReturnStatusSuccessFinishResult);
Chris Lattner24943d22010-06-08 16:52:24 +00001193 }
1194 else
1195 {
Greg Claytonabe0fed2011-04-18 08:33:37 +00001196 result.AppendError ("invalid target\n");
Chris Lattner24943d22010-06-08 16:52:24 +00001197 result.SetStatus (eReturnStatusFailed);
1198 }
1199 return result.Succeeded();
1200 }
1201};
1202
Greg Claytone1f50b92011-05-03 22:09:39 +00001203//----------------------------------------------------------------------
1204// Static Helper functions
1205//----------------------------------------------------------------------
1206static void
1207DumpModuleArchitecture (Stream &strm, Module *module, bool full_triple, uint32_t width)
1208{
1209 if (module)
1210 {
1211 const char *arch_cstr;
1212 if (full_triple)
1213 arch_cstr = module->GetArchitecture().GetTriple().str().c_str();
1214 else
1215 arch_cstr = module->GetArchitecture().GetArchitectureName();
1216 if (width)
1217 strm.Printf("%-*s", width, arch_cstr);
1218 else
1219 strm.PutCString(arch_cstr);
1220 }
1221}
1222
1223static void
1224DumpModuleUUID (Stream &strm, Module *module)
1225{
Greg Clayton153ccd72011-08-10 02:10:13 +00001226 if (module->GetUUID().IsValid())
1227 module->GetUUID().Dump (&strm);
1228 else
1229 strm.PutCString(" ");
Greg Claytone1f50b92011-05-03 22:09:39 +00001230}
1231
1232static uint32_t
1233DumpCompileUnitLineTable
1234(
1235 CommandInterpreter &interpreter,
1236 Stream &strm,
1237 Module *module,
1238 const FileSpec &file_spec,
1239 bool load_addresses
1240 )
1241{
1242 uint32_t num_matches = 0;
1243 if (module)
1244 {
1245 SymbolContextList sc_list;
1246 num_matches = module->ResolveSymbolContextsForFileSpec (file_spec,
1247 0,
1248 false,
1249 eSymbolContextCompUnit,
1250 sc_list);
1251
1252 for (uint32_t i=0; i<num_matches; ++i)
1253 {
1254 SymbolContext sc;
1255 if (sc_list.GetContextAtIndex(i, sc))
1256 {
1257 if (i > 0)
1258 strm << "\n\n";
1259
1260 strm << "Line table for " << *static_cast<FileSpec*> (sc.comp_unit) << " in `"
1261 << module->GetFileSpec().GetFilename() << "\n";
1262 LineTable *line_table = sc.comp_unit->GetLineTable();
1263 if (line_table)
1264 line_table->GetDescription (&strm,
Greg Clayton567e7f32011-09-22 04:58:26 +00001265 interpreter.GetExecutionContext().GetTargetPtr(),
Greg Claytone1f50b92011-05-03 22:09:39 +00001266 lldb::eDescriptionLevelBrief);
1267 else
1268 strm << "No line table";
1269 }
1270 }
1271 }
1272 return num_matches;
1273}
1274
1275static void
1276DumpFullpath (Stream &strm, const FileSpec *file_spec_ptr, uint32_t width)
1277{
1278 if (file_spec_ptr)
1279 {
1280 if (width > 0)
1281 {
1282 char fullpath[PATH_MAX];
1283 if (file_spec_ptr->GetPath(fullpath, sizeof(fullpath)))
1284 {
1285 strm.Printf("%-*s", width, fullpath);
1286 return;
1287 }
1288 }
1289 else
1290 {
1291 file_spec_ptr->Dump(&strm);
1292 return;
1293 }
1294 }
1295 // Keep the width spacing correct if things go wrong...
1296 if (width > 0)
1297 strm.Printf("%-*s", width, "");
1298}
1299
1300static void
1301DumpDirectory (Stream &strm, const FileSpec *file_spec_ptr, uint32_t width)
1302{
1303 if (file_spec_ptr)
1304 {
1305 if (width > 0)
1306 strm.Printf("%-*s", width, file_spec_ptr->GetDirectory().AsCString(""));
1307 else
1308 file_spec_ptr->GetDirectory().Dump(&strm);
1309 return;
1310 }
1311 // Keep the width spacing correct if things go wrong...
1312 if (width > 0)
1313 strm.Printf("%-*s", width, "");
1314}
1315
1316static void
1317DumpBasename (Stream &strm, const FileSpec *file_spec_ptr, uint32_t width)
1318{
1319 if (file_spec_ptr)
1320 {
1321 if (width > 0)
1322 strm.Printf("%-*s", width, file_spec_ptr->GetFilename().AsCString(""));
1323 else
1324 file_spec_ptr->GetFilename().Dump(&strm);
1325 return;
1326 }
1327 // Keep the width spacing correct if things go wrong...
1328 if (width > 0)
1329 strm.Printf("%-*s", width, "");
1330}
1331
1332
1333static void
1334DumpModuleSymtab (CommandInterpreter &interpreter, Stream &strm, Module *module, SortOrder sort_order)
1335{
1336 if (module)
1337 {
1338 ObjectFile *objfile = module->GetObjectFile ();
1339 if (objfile)
1340 {
1341 Symtab *symtab = objfile->GetSymtab();
1342 if (symtab)
Greg Clayton567e7f32011-09-22 04:58:26 +00001343 symtab->Dump(&strm, interpreter.GetExecutionContext().GetTargetPtr(), sort_order);
Greg Claytone1f50b92011-05-03 22:09:39 +00001344 }
1345 }
1346}
1347
1348static void
1349DumpModuleSections (CommandInterpreter &interpreter, Stream &strm, Module *module)
1350{
1351 if (module)
1352 {
1353 ObjectFile *objfile = module->GetObjectFile ();
1354 if (objfile)
1355 {
1356 SectionList *section_list = objfile->GetSectionList();
1357 if (section_list)
1358 {
1359 strm.PutCString ("Sections for '");
1360 strm << module->GetFileSpec();
1361 if (module->GetObjectName())
1362 strm << '(' << module->GetObjectName() << ')';
1363 strm.Printf ("' (%s):\n", module->GetArchitecture().GetArchitectureName());
1364 strm.IndentMore();
Greg Clayton567e7f32011-09-22 04:58:26 +00001365 section_list->Dump(&strm, interpreter.GetExecutionContext().GetTargetPtr(), true, UINT32_MAX);
Greg Claytone1f50b92011-05-03 22:09:39 +00001366 strm.IndentLess();
1367 }
1368 }
1369 }
1370}
1371
1372static bool
1373DumpModuleSymbolVendor (Stream &strm, Module *module)
1374{
1375 if (module)
1376 {
1377 SymbolVendor *symbol_vendor = module->GetSymbolVendor(true);
1378 if (symbol_vendor)
1379 {
1380 symbol_vendor->Dump(&strm);
1381 return true;
1382 }
1383 }
1384 return false;
1385}
1386
Greg Clayton2ad894b2012-05-15 18:43:44 +00001387static void
1388DumpAddress (ExecutionContextScope *exe_scope, const Address &so_addr, bool verbose, Stream &strm)
1389{
1390 strm.IndentMore();
1391 strm.Indent (" Address: ");
1392 so_addr.Dump (&strm, exe_scope, Address::DumpStyleModuleWithFileAddress);
1393 strm.PutCString (" (");
1394 so_addr.Dump (&strm, exe_scope, Address::DumpStyleSectionNameOffset);
1395 strm.PutCString (")\n");
1396 strm.Indent (" Summary: ");
1397 const uint32_t save_indent = strm.GetIndentLevel ();
1398 strm.SetIndentLevel (save_indent + 13);
1399 so_addr.Dump (&strm, exe_scope, Address::DumpStyleResolvedDescription);
1400 strm.SetIndentLevel (save_indent);
1401 // Print out detailed address information when verbose is enabled
1402 if (verbose)
1403 {
1404 strm.EOL();
1405 so_addr.Dump (&strm, exe_scope, Address::DumpStyleDetailedSymbolContext);
1406 }
1407 strm.IndentLess();
1408}
1409
Greg Claytone1f50b92011-05-03 22:09:39 +00001410static bool
Greg Clayton3508c382012-02-24 01:59:29 +00001411LookupAddressInModule (CommandInterpreter &interpreter,
1412 Stream &strm,
1413 Module *module,
1414 uint32_t resolve_mask,
1415 lldb::addr_t raw_addr,
1416 lldb::addr_t offset,
1417 bool verbose)
Greg Claytone1f50b92011-05-03 22:09:39 +00001418{
1419 if (module)
1420 {
1421 lldb::addr_t addr = raw_addr - offset;
1422 Address so_addr;
1423 SymbolContext sc;
Greg Clayton567e7f32011-09-22 04:58:26 +00001424 Target *target = interpreter.GetExecutionContext().GetTargetPtr();
Greg Claytone1f50b92011-05-03 22:09:39 +00001425 if (target && !target->GetSectionLoadList().IsEmpty())
1426 {
1427 if (!target->GetSectionLoadList().ResolveLoadAddress (addr, so_addr))
1428 return false;
Greg Clayton3508c382012-02-24 01:59:29 +00001429 else if (so_addr.GetModule().get() != module)
Greg Claytone1f50b92011-05-03 22:09:39 +00001430 return false;
1431 }
1432 else
1433 {
1434 if (!module->ResolveFileAddress (addr, so_addr))
1435 return false;
1436 }
1437
Greg Claytone1f50b92011-05-03 22:09:39 +00001438 ExecutionContextScope *exe_scope = interpreter.GetExecutionContext().GetBestExecutionContextScope();
Greg Clayton2ad894b2012-05-15 18:43:44 +00001439 DumpAddress (exe_scope, so_addr, verbose, strm);
1440// strm.IndentMore();
1441// strm.Indent (" Address: ");
1442// so_addr.Dump (&strm, exe_scope, Address::DumpStyleModuleWithFileAddress);
1443// strm.PutCString (" (");
1444// so_addr.Dump (&strm, exe_scope, Address::DumpStyleSectionNameOffset);
1445// strm.PutCString (")\n");
1446// strm.Indent (" Summary: ");
1447// const uint32_t save_indent = strm.GetIndentLevel ();
1448// strm.SetIndentLevel (save_indent + 13);
1449// so_addr.Dump (&strm, exe_scope, Address::DumpStyleResolvedDescription);
1450// strm.SetIndentLevel (save_indent);
1451// // Print out detailed address information when verbose is enabled
1452// if (verbose)
1453// {
1454// strm.EOL();
1455// so_addr.Dump (&strm, exe_scope, Address::DumpStyleDetailedSymbolContext);
1456// }
1457// strm.IndentLess();
Greg Claytone1f50b92011-05-03 22:09:39 +00001458 return true;
1459 }
1460
1461 return false;
1462}
1463
1464static uint32_t
Greg Clayton2ad894b2012-05-15 18:43:44 +00001465LookupSymbolInModule (CommandInterpreter &interpreter, Stream &strm, Module *module, const char *name, bool name_is_regex, bool verbose)
Greg Claytone1f50b92011-05-03 22:09:39 +00001466{
1467 if (module)
1468 {
1469 SymbolContext sc;
1470
1471 ObjectFile *objfile = module->GetObjectFile ();
1472 if (objfile)
1473 {
1474 Symtab *symtab = objfile->GetSymtab();
1475 if (symtab)
1476 {
1477 uint32_t i;
1478 std::vector<uint32_t> match_indexes;
1479 ConstString symbol_name (name);
1480 uint32_t num_matches = 0;
1481 if (name_is_regex)
1482 {
1483 RegularExpression name_regexp(name);
1484 num_matches = symtab->AppendSymbolIndexesMatchingRegExAndType (name_regexp,
1485 eSymbolTypeAny,
1486 match_indexes);
1487 }
1488 else
1489 {
1490 num_matches = symtab->AppendSymbolIndexesWithName (symbol_name, match_indexes);
1491 }
1492
1493
1494 if (num_matches > 0)
1495 {
1496 strm.Indent ();
1497 strm.Printf("%u symbols match %s'%s' in ", num_matches,
1498 name_is_regex ? "the regular expression " : "", name);
1499 DumpFullpath (strm, &module->GetFileSpec(), 0);
1500 strm.PutCString(":\n");
1501 strm.IndentMore ();
Greg Clayton2ad894b2012-05-15 18:43:44 +00001502 //Symtab::DumpSymbolHeader (&strm);
Greg Claytone1f50b92011-05-03 22:09:39 +00001503 for (i=0; i < num_matches; ++i)
1504 {
1505 Symbol *symbol = symtab->SymbolAtIndex(match_indexes[i]);
Greg Clayton2ad894b2012-05-15 18:43:44 +00001506 DumpAddress (interpreter.GetExecutionContext().GetBestExecutionContextScope(),
1507 symbol->GetAddress(),
1508 verbose,
1509 strm);
1510
1511// strm.Indent ();
1512// symbol->Dump (&strm, interpreter.GetExecutionContext().GetTargetPtr(), i);
Greg Claytone1f50b92011-05-03 22:09:39 +00001513 }
1514 strm.IndentLess ();
1515 return num_matches;
1516 }
1517 }
1518 }
1519 }
1520 return 0;
1521}
1522
1523
1524static void
Greg Clayton2ad894b2012-05-15 18:43:44 +00001525DumpSymbolContextList (ExecutionContextScope *exe_scope, Stream &strm, SymbolContextList &sc_list, bool verbose)
Greg Claytone1f50b92011-05-03 22:09:39 +00001526{
1527 strm.IndentMore ();
1528 uint32_t i;
1529 const uint32_t num_matches = sc_list.GetSize();
1530
1531 for (i=0; i<num_matches; ++i)
1532 {
1533 SymbolContext sc;
1534 if (sc_list.GetContextAtIndex(i, sc))
1535 {
Sean Callanand7793d22012-02-11 00:24:04 +00001536 AddressRange range;
1537
1538 sc.GetAddressRange(eSymbolContextEverything,
1539 0,
1540 true,
1541 range);
1542
Greg Clayton2ad894b2012-05-15 18:43:44 +00001543 DumpAddress (exe_scope, range.GetBaseAddress(), verbose, strm);
Greg Claytone1f50b92011-05-03 22:09:39 +00001544 }
1545 }
1546 strm.IndentLess ();
1547}
1548
1549static uint32_t
Greg Clayton2ad894b2012-05-15 18:43:44 +00001550LookupFunctionInModule (CommandInterpreter &interpreter,
1551 Stream &strm,
1552 Module *module,
1553 const char *name,
1554 bool name_is_regex,
1555 bool include_inlines,
1556 bool include_symbols,
1557 bool verbose)
Greg Claytone1f50b92011-05-03 22:09:39 +00001558{
1559 if (module && name && name[0])
1560 {
1561 SymbolContextList sc_list;
Greg Claytone1f50b92011-05-03 22:09:39 +00001562 const bool append = true;
1563 uint32_t num_matches = 0;
1564 if (name_is_regex)
1565 {
1566 RegularExpression function_name_regex (name);
1567 num_matches = module->FindFunctions (function_name_regex,
1568 include_symbols,
Sean Callanan302d78c2012-02-10 22:52:19 +00001569 include_inlines,
Greg Claytone1f50b92011-05-03 22:09:39 +00001570 append,
1571 sc_list);
1572 }
1573 else
1574 {
1575 ConstString function_name (name);
Sean Callanan3e80cd92011-10-12 02:08:07 +00001576 num_matches = module->FindFunctions (function_name,
1577 NULL,
Greg Claytone1f50b92011-05-03 22:09:39 +00001578 eFunctionNameTypeBase | eFunctionNameTypeFull | eFunctionNameTypeMethod | eFunctionNameTypeSelector,
1579 include_symbols,
Sean Callanan302d78c2012-02-10 22:52:19 +00001580 include_inlines,
Greg Claytone1f50b92011-05-03 22:09:39 +00001581 append,
1582 sc_list);
1583 }
1584
1585 if (num_matches)
1586 {
1587 strm.Indent ();
1588 strm.Printf("%u match%s found in ", num_matches, num_matches > 1 ? "es" : "");
1589 DumpFullpath (strm, &module->GetFileSpec(), 0);
1590 strm.PutCString(":\n");
Greg Clayton2ad894b2012-05-15 18:43:44 +00001591 DumpSymbolContextList (interpreter.GetExecutionContext().GetBestExecutionContextScope(), strm, sc_list, verbose);
Greg Claytone1f50b92011-05-03 22:09:39 +00001592 }
1593 return num_matches;
1594 }
1595 return 0;
1596}
1597
1598static uint32_t
Greg Clayton0cbaacd2012-05-15 19:26:12 +00001599LookupTypeInModule (CommandInterpreter &interpreter,
Greg Clayton801417e2011-07-07 01:59:51 +00001600 Stream &strm,
1601 Module *module,
1602 const char *name_cstr,
1603 bool name_is_regex)
Greg Claytone1f50b92011-05-03 22:09:39 +00001604{
1605 if (module && name_cstr && name_cstr[0])
1606 {
Greg Clayton37bb8dd2011-12-08 02:13:16 +00001607 TypeList type_list;
Greg Claytondc0a38c2012-03-26 23:03:23 +00001608 const uint32_t max_num_matches = UINT32_MAX;
Greg Clayton37bb8dd2011-12-08 02:13:16 +00001609 uint32_t num_matches = 0;
Greg Claytondc0a38c2012-03-26 23:03:23 +00001610 bool name_is_fully_qualified = false;
Greg Clayton37bb8dd2011-12-08 02:13:16 +00001611 SymbolContext sc;
1612
1613 ConstString name(name_cstr);
Greg Claytondc0a38c2012-03-26 23:03:23 +00001614 num_matches = module->FindTypes(sc, name, name_is_fully_qualified, max_num_matches, type_list);
Greg Claytone1f50b92011-05-03 22:09:39 +00001615
Greg Clayton37bb8dd2011-12-08 02:13:16 +00001616 if (num_matches)
1617 {
1618 strm.Indent ();
1619 strm.Printf("%u match%s found in ", num_matches, num_matches > 1 ? "es" : "");
1620 DumpFullpath (strm, &module->GetFileSpec(), 0);
1621 strm.PutCString(":\n");
1622 const uint32_t num_types = type_list.GetSize();
1623 for (uint32_t i=0; i<num_types; ++i)
Greg Claytone1f50b92011-05-03 22:09:39 +00001624 {
Greg Clayton37bb8dd2011-12-08 02:13:16 +00001625 TypeSP type_sp (type_list.GetTypeAtIndex(i));
1626 if (type_sp)
Greg Claytone1f50b92011-05-03 22:09:39 +00001627 {
Greg Clayton37bb8dd2011-12-08 02:13:16 +00001628 // Resolve the clang type so that any forward references
1629 // to types that haven't yet been parsed will get parsed.
1630 type_sp->GetClangFullType ();
1631 type_sp->GetDescription (&strm, eDescriptionLevelFull, true);
Greg Clayton0cbaacd2012-05-15 19:26:12 +00001632 // Print all typedef chains
1633 TypeSP typedef_type_sp (type_sp);
1634 TypeSP typedefed_type_sp (typedef_type_sp->GetTypedefType());
1635 while (typedefed_type_sp)
1636 {
1637 strm.EOL();
1638 strm.Printf(" typedef '%s': ", typedef_type_sp->GetName().GetCString());
1639 typedefed_type_sp->GetClangFullType ();
1640 typedefed_type_sp->GetDescription (&strm, eDescriptionLevelFull, true);
1641 typedef_type_sp = typedefed_type_sp;
1642 typedefed_type_sp = typedef_type_sp->GetTypedefType();
1643 }
Greg Claytone1f50b92011-05-03 22:09:39 +00001644 }
Greg Clayton37bb8dd2011-12-08 02:13:16 +00001645 strm.EOL();
Greg Claytone1f50b92011-05-03 22:09:39 +00001646 }
Greg Clayton37bb8dd2011-12-08 02:13:16 +00001647 }
1648 return num_matches;
Greg Claytone1f50b92011-05-03 22:09:39 +00001649 }
1650 return 0;
1651}
1652
1653static uint32_t
Sean Callanan56d31ec2012-06-06 20:49:55 +00001654LookupTypeHere (CommandInterpreter &interpreter,
1655 Stream &strm,
1656 const SymbolContext &sym_ctx,
1657 const char *name_cstr,
1658 bool name_is_regex)
1659{
1660 if (!sym_ctx.module_sp)
1661 return 0;
1662
1663 TypeList type_list;
1664 const uint32_t max_num_matches = UINT32_MAX;
1665 uint32_t num_matches = 1;
1666 bool name_is_fully_qualified = false;
1667
1668 ConstString name(name_cstr);
1669 num_matches = sym_ctx.module_sp->FindTypes(sym_ctx, name, name_is_fully_qualified, max_num_matches, type_list);
1670
1671 if (num_matches)
1672 {
1673 strm.Indent ();
1674 strm.PutCString("Best match found in ");
1675 DumpFullpath (strm, &sym_ctx.module_sp->GetFileSpec(), 0);
1676 strm.PutCString(":\n");
1677
1678 TypeSP type_sp (type_list.GetTypeAtIndex(0));
1679 if (type_sp)
1680 {
1681 // Resolve the clang type so that any forward references
1682 // to types that haven't yet been parsed will get parsed.
1683 type_sp->GetClangFullType ();
1684 type_sp->GetDescription (&strm, eDescriptionLevelFull, true);
1685 // Print all typedef chains
1686 TypeSP typedef_type_sp (type_sp);
1687 TypeSP typedefed_type_sp (typedef_type_sp->GetTypedefType());
1688 while (typedefed_type_sp)
1689 {
1690 strm.EOL();
1691 strm.Printf(" typedef '%s': ", typedef_type_sp->GetName().GetCString());
1692 typedefed_type_sp->GetClangFullType ();
1693 typedefed_type_sp->GetDescription (&strm, eDescriptionLevelFull, true);
1694 typedef_type_sp = typedefed_type_sp;
1695 typedefed_type_sp = typedef_type_sp->GetTypedefType();
1696 }
1697 }
1698 strm.EOL();
1699 }
1700 return num_matches;
1701}
1702
1703static uint32_t
Greg Claytone1f50b92011-05-03 22:09:39 +00001704LookupFileAndLineInModule (CommandInterpreter &interpreter,
Sean Callanan56d31ec2012-06-06 20:49:55 +00001705 Stream &strm,
Greg Claytone1f50b92011-05-03 22:09:39 +00001706 Module *module,
1707 const FileSpec &file_spec,
1708 uint32_t line,
1709 bool check_inlines,
1710 bool verbose)
1711{
1712 if (module && file_spec)
1713 {
1714 SymbolContextList sc_list;
1715 const uint32_t num_matches = module->ResolveSymbolContextsForFileSpec(file_spec, line, check_inlines,
1716 eSymbolContextEverything, sc_list);
1717 if (num_matches > 0)
1718 {
1719 strm.Indent ();
1720 strm.Printf("%u match%s found in ", num_matches, num_matches > 1 ? "es" : "");
1721 strm << file_spec;
1722 if (line > 0)
1723 strm.Printf (":%u", line);
1724 strm << " in ";
1725 DumpFullpath (strm, &module->GetFileSpec(), 0);
1726 strm.PutCString(":\n");
Greg Clayton2ad894b2012-05-15 18:43:44 +00001727 DumpSymbolContextList (interpreter.GetExecutionContext().GetBestExecutionContextScope(), strm, sc_list, verbose);
Greg Claytone1f50b92011-05-03 22:09:39 +00001728 return num_matches;
1729 }
1730 }
1731 return 0;
1732
1733}
1734
Greg Clayton91048ef2011-11-10 01:18:58 +00001735
1736static size_t
1737FindModulesByName (Target *target,
1738 const char *module_name,
1739 ModuleList &module_list,
1740 bool check_global_list)
1741{
1742// Dump specified images (by basename or fullpath)
1743 FileSpec module_file_spec(module_name, false);
Greg Clayton444fe992012-02-26 05:51:37 +00001744 ModuleSpec module_spec (module_file_spec);
Greg Clayton91048ef2011-11-10 01:18:58 +00001745
1746 const size_t initial_size = module_list.GetSize ();
1747
Greg Clayton316f57f2012-07-11 20:46:47 +00001748 if (check_global_list)
Greg Clayton91048ef2011-11-10 01:18:58 +00001749 {
1750 // Check the global list
Greg Claytonc149c8b2012-01-27 18:08:35 +00001751 Mutex::Locker locker(Module::GetAllocationModuleCollectionMutex());
Greg Clayton91048ef2011-11-10 01:18:58 +00001752 const uint32_t num_modules = Module::GetNumberAllocatedModules();
1753 ModuleSP module_sp;
1754 for (uint32_t image_idx = 0; image_idx<num_modules; ++image_idx)
1755 {
1756 Module *module = Module::GetAllocatedModuleAtIndex(image_idx);
1757
1758 if (module)
1759 {
Greg Clayton444fe992012-02-26 05:51:37 +00001760 if (module->MatchesModuleSpec (module_spec))
Greg Clayton91048ef2011-11-10 01:18:58 +00001761 {
Greg Clayton13d24fb2012-01-29 20:56:30 +00001762 module_sp = module->shared_from_this();
Greg Clayton91048ef2011-11-10 01:18:58 +00001763 module_list.AppendIfNeeded(module_sp);
1764 }
1765 }
1766 }
1767 }
Greg Clayton316f57f2012-07-11 20:46:47 +00001768 else
1769 {
1770 if (target)
1771 {
1772 const size_t num_matches = target->GetImages().FindModules (module_spec, module_list);
1773
1774 // Not found in our module list for our target, check the main
1775 // shared module list in case it is a extra file used somewhere
1776 // else
1777 if (num_matches == 0)
1778 {
1779 module_spec.GetArchitecture() = target->GetArchitecture();
1780 ModuleList::FindSharedModules (module_spec, module_list);
1781 }
1782 }
1783 else
1784 {
1785 ModuleList::FindSharedModules (module_spec,module_list);
1786 }
1787 }
1788
Greg Clayton91048ef2011-11-10 01:18:58 +00001789 return module_list.GetSize () - initial_size;
1790}
1791
Greg Claytone1f50b92011-05-03 22:09:39 +00001792#pragma mark CommandObjectTargetModulesModuleAutoComplete
1793
1794//----------------------------------------------------------------------
1795// A base command object class that can auto complete with module file
1796// paths
1797//----------------------------------------------------------------------
1798
Jim Inghamda26bd22012-06-08 21:56:10 +00001799class CommandObjectTargetModulesModuleAutoComplete : public CommandObjectParsed
Greg Claytone1f50b92011-05-03 22:09:39 +00001800{
1801public:
1802
1803 CommandObjectTargetModulesModuleAutoComplete (CommandInterpreter &interpreter,
1804 const char *name,
1805 const char *help,
1806 const char *syntax) :
Jim Inghamda26bd22012-06-08 21:56:10 +00001807 CommandObjectParsed (interpreter, name, help, syntax)
Greg Claytone1f50b92011-05-03 22:09:39 +00001808 {
1809 CommandArgumentEntry arg;
1810 CommandArgumentData file_arg;
1811
1812 // Define the first (and only) variant of this arg.
1813 file_arg.arg_type = eArgTypeFilename;
1814 file_arg.arg_repetition = eArgRepeatStar;
1815
1816 // There is only one variant this argument could be; put it into the argument entry.
1817 arg.push_back (file_arg);
1818
1819 // Push the data for the first argument into the m_arguments vector.
1820 m_arguments.push_back (arg);
1821 }
1822
1823 virtual
1824 ~CommandObjectTargetModulesModuleAutoComplete ()
1825 {
1826 }
1827
1828 virtual int
1829 HandleArgumentCompletion (Args &input,
1830 int &cursor_index,
1831 int &cursor_char_position,
1832 OptionElementVector &opt_element_vector,
1833 int match_start_point,
1834 int max_return_elements,
1835 bool &word_complete,
1836 StringList &matches)
1837 {
1838 // Arguments are the standard module completer.
1839 std::string completion_str (input.GetArgumentAtIndex(cursor_index));
1840 completion_str.erase (cursor_char_position);
1841
1842 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
1843 CommandCompletions::eModuleCompletion,
1844 completion_str.c_str(),
1845 match_start_point,
1846 max_return_elements,
1847 NULL,
1848 word_complete,
1849 matches);
1850 return matches.GetSize();
1851 }
1852};
1853
1854#pragma mark CommandObjectTargetModulesSourceFileAutoComplete
1855
1856//----------------------------------------------------------------------
1857// A base command object class that can auto complete with module source
1858// file paths
1859//----------------------------------------------------------------------
1860
Jim Inghamda26bd22012-06-08 21:56:10 +00001861class CommandObjectTargetModulesSourceFileAutoComplete : public CommandObjectParsed
Greg Claytone1f50b92011-05-03 22:09:39 +00001862{
1863public:
1864
1865 CommandObjectTargetModulesSourceFileAutoComplete (CommandInterpreter &interpreter,
1866 const char *name,
1867 const char *help,
1868 const char *syntax) :
Jim Inghamda26bd22012-06-08 21:56:10 +00001869 CommandObjectParsed (interpreter, name, help, syntax)
Greg Claytone1f50b92011-05-03 22:09:39 +00001870 {
1871 CommandArgumentEntry arg;
1872 CommandArgumentData source_file_arg;
1873
1874 // Define the first (and only) variant of this arg.
1875 source_file_arg.arg_type = eArgTypeSourceFile;
1876 source_file_arg.arg_repetition = eArgRepeatPlus;
1877
1878 // There is only one variant this argument could be; put it into the argument entry.
1879 arg.push_back (source_file_arg);
1880
1881 // Push the data for the first argument into the m_arguments vector.
1882 m_arguments.push_back (arg);
1883 }
1884
1885 virtual
1886 ~CommandObjectTargetModulesSourceFileAutoComplete ()
1887 {
1888 }
1889
1890 virtual int
1891 HandleArgumentCompletion (Args &input,
1892 int &cursor_index,
1893 int &cursor_char_position,
1894 OptionElementVector &opt_element_vector,
1895 int match_start_point,
1896 int max_return_elements,
1897 bool &word_complete,
1898 StringList &matches)
1899 {
1900 // Arguments are the standard source file completer.
1901 std::string completion_str (input.GetArgumentAtIndex(cursor_index));
1902 completion_str.erase (cursor_char_position);
1903
1904 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
1905 CommandCompletions::eSourceFileCompletion,
1906 completion_str.c_str(),
1907 match_start_point,
1908 max_return_elements,
1909 NULL,
1910 word_complete,
1911 matches);
1912 return matches.GetSize();
1913 }
1914};
1915
1916
1917#pragma mark CommandObjectTargetModulesDumpSymtab
1918
1919
1920class CommandObjectTargetModulesDumpSymtab : public CommandObjectTargetModulesModuleAutoComplete
1921{
1922public:
1923 CommandObjectTargetModulesDumpSymtab (CommandInterpreter &interpreter) :
1924 CommandObjectTargetModulesModuleAutoComplete (interpreter,
1925 "target modules dump symtab",
1926 "Dump the symbol table from one or more target modules.",
1927 NULL),
1928 m_options (interpreter)
1929 {
1930 }
1931
1932 virtual
1933 ~CommandObjectTargetModulesDumpSymtab ()
1934 {
1935 }
1936
Jim Inghamda26bd22012-06-08 21:56:10 +00001937 virtual Options *
1938 GetOptions ()
1939 {
1940 return &m_options;
1941 }
1942
1943 class CommandOptions : public Options
1944 {
1945 public:
1946
1947 CommandOptions (CommandInterpreter &interpreter) :
1948 Options(interpreter),
1949 m_sort_order (eSortOrderNone)
1950 {
1951 }
1952
1953 virtual
1954 ~CommandOptions ()
1955 {
1956 }
1957
1958 virtual Error
1959 SetOptionValue (uint32_t option_idx, const char *option_arg)
1960 {
1961 Error error;
1962 char short_option = (char) m_getopt_table[option_idx].val;
1963
1964 switch (short_option)
1965 {
1966 case 's':
1967 m_sort_order = (SortOrder) Args::StringToOptionEnum (option_arg,
1968 g_option_table[option_idx].enum_values,
1969 eSortOrderNone,
1970 error);
1971 break;
1972
1973 default:
1974 error.SetErrorStringWithFormat("invalid short option character '%c'", short_option);
1975 break;
1976
1977 }
1978 return error;
1979 }
1980
1981 void
1982 OptionParsingStarting ()
1983 {
1984 m_sort_order = eSortOrderNone;
1985 }
1986
1987 const OptionDefinition*
1988 GetDefinitions ()
1989 {
1990 return g_option_table;
1991 }
1992
1993 // Options table: Required for subclasses of Options.
1994 static OptionDefinition g_option_table[];
1995
1996 SortOrder m_sort_order;
1997 };
1998
1999protected:
Greg Claytone1f50b92011-05-03 22:09:39 +00002000 virtual bool
Jim Inghamda26bd22012-06-08 21:56:10 +00002001 DoExecute (Args& command,
Greg Claytone1f50b92011-05-03 22:09:39 +00002002 CommandReturnObject &result)
2003 {
2004 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
2005 if (target == NULL)
2006 {
2007 result.AppendError ("invalid target, create a debug target using the 'target create' command");
2008 result.SetStatus (eReturnStatusFailed);
2009 return false;
2010 }
2011 else
2012 {
2013 uint32_t num_dumped = 0;
2014
2015 uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize();
2016 result.GetOutputStream().SetAddressByteSize(addr_byte_size);
2017 result.GetErrorStream().SetAddressByteSize(addr_byte_size);
2018
2019 if (command.GetArgumentCount() == 0)
2020 {
2021 // Dump all sections for all modules images
Jim Ingham93367902012-05-30 02:19:25 +00002022 Mutex::Locker modules_locker(target->GetImages().GetMutex());
Greg Claytone1f50b92011-05-03 22:09:39 +00002023 const uint32_t num_modules = target->GetImages().GetSize();
2024 if (num_modules > 0)
2025 {
2026 result.GetOutputStream().Printf("Dumping symbol table for %u modules.\n", num_modules);
2027 for (uint32_t image_idx = 0; image_idx<num_modules; ++image_idx)
2028 {
2029 if (num_dumped > 0)
2030 {
2031 result.GetOutputStream().EOL();
2032 result.GetOutputStream().EOL();
2033 }
2034 num_dumped++;
Jim Ingham93367902012-05-30 02:19:25 +00002035 DumpModuleSymtab (m_interpreter,
2036 result.GetOutputStream(),
2037 target->GetImages().GetModulePointerAtIndexUnlocked(image_idx),
2038 m_options.m_sort_order);
Greg Claytone1f50b92011-05-03 22:09:39 +00002039 }
2040 }
2041 else
2042 {
2043 result.AppendError ("the target has no associated executable images");
2044 result.SetStatus (eReturnStatusFailed);
2045 return false;
2046 }
2047 }
2048 else
2049 {
2050 // Dump specified images (by basename or fullpath)
2051 const char *arg_cstr;
2052 for (int arg_idx = 0; (arg_cstr = command.GetArgumentAtIndex(arg_idx)) != NULL; ++arg_idx)
2053 {
Greg Clayton91048ef2011-11-10 01:18:58 +00002054 ModuleList module_list;
2055 const size_t num_matches = FindModulesByName (target, arg_cstr, module_list, true);
2056 if (num_matches > 0)
Greg Claytone1f50b92011-05-03 22:09:39 +00002057 {
Greg Clayton91048ef2011-11-10 01:18:58 +00002058 for (size_t i=0; i<num_matches; ++i)
Greg Claytone1f50b92011-05-03 22:09:39 +00002059 {
Greg Clayton91048ef2011-11-10 01:18:58 +00002060 Module *module = module_list.GetModulePointerAtIndex(i);
2061 if (module)
Greg Claytone1f50b92011-05-03 22:09:39 +00002062 {
2063 if (num_dumped > 0)
2064 {
2065 result.GetOutputStream().EOL();
2066 result.GetOutputStream().EOL();
2067 }
2068 num_dumped++;
Greg Clayton91048ef2011-11-10 01:18:58 +00002069 DumpModuleSymtab (m_interpreter, result.GetOutputStream(), module, m_options.m_sort_order);
Greg Claytone1f50b92011-05-03 22:09:39 +00002070 }
2071 }
2072 }
2073 else
2074 result.AppendWarningWithFormat("Unable to find an image that matches '%s'.\n", arg_cstr);
2075 }
2076 }
2077
2078 if (num_dumped > 0)
2079 result.SetStatus (eReturnStatusSuccessFinishResult);
2080 else
2081 {
2082 result.AppendError ("no matching executable images found");
2083 result.SetStatus (eReturnStatusFailed);
2084 }
2085 }
2086 return result.Succeeded();
2087 }
2088
Greg Claytone1f50b92011-05-03 22:09:39 +00002089
2090 CommandOptions m_options;
2091};
2092
2093static OptionEnumValueElement
2094g_sort_option_enumeration[4] =
2095{
2096 { eSortOrderNone, "none", "No sorting, use the original symbol table order."},
2097 { eSortOrderByAddress, "address", "Sort output by symbol address."},
2098 { eSortOrderByName, "name", "Sort output by symbol name."},
2099 { 0, NULL, NULL }
2100};
2101
2102
2103OptionDefinition
2104CommandObjectTargetModulesDumpSymtab::CommandOptions::g_option_table[] =
2105{
2106 { LLDB_OPT_SET_1, false, "sort", 's', required_argument, g_sort_option_enumeration, 0, eArgTypeSortOrder, "Supply a sort order when dumping the symbol table."},
2107 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
2108};
2109
2110#pragma mark CommandObjectTargetModulesDumpSections
2111
2112//----------------------------------------------------------------------
2113// Image section dumping command
2114//----------------------------------------------------------------------
2115
2116class CommandObjectTargetModulesDumpSections : public CommandObjectTargetModulesModuleAutoComplete
2117{
2118public:
2119 CommandObjectTargetModulesDumpSections (CommandInterpreter &interpreter) :
2120 CommandObjectTargetModulesModuleAutoComplete (interpreter,
2121 "target modules dump sections",
2122 "Dump the sections from one or more target modules.",
2123 //"target modules dump sections [<file1> ...]")
2124 NULL)
2125 {
2126 }
2127
2128 virtual
2129 ~CommandObjectTargetModulesDumpSections ()
2130 {
2131 }
2132
Jim Inghamda26bd22012-06-08 21:56:10 +00002133protected:
Greg Claytone1f50b92011-05-03 22:09:39 +00002134 virtual bool
Jim Inghamda26bd22012-06-08 21:56:10 +00002135 DoExecute (Args& command,
Greg Claytone1f50b92011-05-03 22:09:39 +00002136 CommandReturnObject &result)
2137 {
2138 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
2139 if (target == NULL)
2140 {
2141 result.AppendError ("invalid target, create a debug target using the 'target create' command");
2142 result.SetStatus (eReturnStatusFailed);
2143 return false;
2144 }
2145 else
2146 {
2147 uint32_t num_dumped = 0;
2148
2149 uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize();
2150 result.GetOutputStream().SetAddressByteSize(addr_byte_size);
2151 result.GetErrorStream().SetAddressByteSize(addr_byte_size);
2152
2153 if (command.GetArgumentCount() == 0)
2154 {
2155 // Dump all sections for all modules images
2156 const uint32_t num_modules = target->GetImages().GetSize();
2157 if (num_modules > 0)
2158 {
2159 result.GetOutputStream().Printf("Dumping sections for %u modules.\n", num_modules);
2160 for (uint32_t image_idx = 0; image_idx<num_modules; ++image_idx)
2161 {
2162 num_dumped++;
2163 DumpModuleSections (m_interpreter, result.GetOutputStream(), target->GetImages().GetModulePointerAtIndex(image_idx));
2164 }
2165 }
2166 else
2167 {
2168 result.AppendError ("the target has no associated executable images");
2169 result.SetStatus (eReturnStatusFailed);
2170 return false;
2171 }
2172 }
2173 else
2174 {
2175 // Dump specified images (by basename or fullpath)
2176 const char *arg_cstr;
2177 for (int arg_idx = 0; (arg_cstr = command.GetArgumentAtIndex(arg_idx)) != NULL; ++arg_idx)
2178 {
Greg Clayton91048ef2011-11-10 01:18:58 +00002179 ModuleList module_list;
2180 const size_t num_matches = FindModulesByName (target, arg_cstr, module_list, true);
2181 if (num_matches > 0)
Greg Claytone1f50b92011-05-03 22:09:39 +00002182 {
Greg Clayton91048ef2011-11-10 01:18:58 +00002183 for (size_t i=0; i<num_matches; ++i)
Greg Claytone1f50b92011-05-03 22:09:39 +00002184 {
Greg Clayton91048ef2011-11-10 01:18:58 +00002185 Module *module = module_list.GetModulePointerAtIndex(i);
2186 if (module)
Greg Claytone1f50b92011-05-03 22:09:39 +00002187 {
2188 num_dumped++;
Greg Clayton91048ef2011-11-10 01:18:58 +00002189 DumpModuleSections (m_interpreter, result.GetOutputStream(), module);
Greg Claytone1f50b92011-05-03 22:09:39 +00002190 }
2191 }
2192 }
2193 else
Greg Clayton91048ef2011-11-10 01:18:58 +00002194 {
2195 // Check the global list
Greg Claytonc149c8b2012-01-27 18:08:35 +00002196 Mutex::Locker locker(Module::GetAllocationModuleCollectionMutex());
Greg Clayton91048ef2011-11-10 01:18:58 +00002197
Greg Claytone1f50b92011-05-03 22:09:39 +00002198 result.AppendWarningWithFormat("Unable to find an image that matches '%s'.\n", arg_cstr);
Greg Clayton91048ef2011-11-10 01:18:58 +00002199 }
Greg Claytone1f50b92011-05-03 22:09:39 +00002200 }
2201 }
2202
2203 if (num_dumped > 0)
2204 result.SetStatus (eReturnStatusSuccessFinishResult);
2205 else
2206 {
2207 result.AppendError ("no matching executable images found");
2208 result.SetStatus (eReturnStatusFailed);
2209 }
2210 }
2211 return result.Succeeded();
2212 }
2213};
2214
2215
2216#pragma mark CommandObjectTargetModulesDumpSymfile
2217
2218//----------------------------------------------------------------------
2219// Image debug symbol dumping command
2220//----------------------------------------------------------------------
2221
2222class CommandObjectTargetModulesDumpSymfile : public CommandObjectTargetModulesModuleAutoComplete
2223{
2224public:
2225 CommandObjectTargetModulesDumpSymfile (CommandInterpreter &interpreter) :
2226 CommandObjectTargetModulesModuleAutoComplete (interpreter,
2227 "target modules dump symfile",
2228 "Dump the debug symbol file for one or more target modules.",
2229 //"target modules dump symfile [<file1> ...]")
2230 NULL)
2231 {
2232 }
2233
2234 virtual
2235 ~CommandObjectTargetModulesDumpSymfile ()
2236 {
2237 }
2238
Jim Inghamda26bd22012-06-08 21:56:10 +00002239protected:
Greg Claytone1f50b92011-05-03 22:09:39 +00002240 virtual bool
Jim Inghamda26bd22012-06-08 21:56:10 +00002241 DoExecute (Args& command,
Greg Claytone1f50b92011-05-03 22:09:39 +00002242 CommandReturnObject &result)
2243 {
2244 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
2245 if (target == NULL)
2246 {
2247 result.AppendError ("invalid target, create a debug target using the 'target create' command");
2248 result.SetStatus (eReturnStatusFailed);
2249 return false;
2250 }
2251 else
2252 {
2253 uint32_t num_dumped = 0;
2254
2255 uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize();
2256 result.GetOutputStream().SetAddressByteSize(addr_byte_size);
2257 result.GetErrorStream().SetAddressByteSize(addr_byte_size);
2258
2259 if (command.GetArgumentCount() == 0)
2260 {
2261 // Dump all sections for all modules images
Jim Ingham93367902012-05-30 02:19:25 +00002262 ModuleList &target_modules = target->GetImages();
2263 Mutex::Locker modules_locker (target_modules.GetMutex());
2264 const uint32_t num_modules = target_modules.GetSize();
Greg Claytone1f50b92011-05-03 22:09:39 +00002265 if (num_modules > 0)
2266 {
2267 result.GetOutputStream().Printf("Dumping debug symbols for %u modules.\n", num_modules);
2268 for (uint32_t image_idx = 0; image_idx<num_modules; ++image_idx)
2269 {
Jim Ingham93367902012-05-30 02:19:25 +00002270 if (DumpModuleSymbolVendor (result.GetOutputStream(), target_modules.GetModulePointerAtIndexUnlocked(image_idx)))
Greg Claytone1f50b92011-05-03 22:09:39 +00002271 num_dumped++;
2272 }
2273 }
2274 else
2275 {
2276 result.AppendError ("the target has no associated executable images");
2277 result.SetStatus (eReturnStatusFailed);
2278 return false;
2279 }
2280 }
2281 else
2282 {
2283 // Dump specified images (by basename or fullpath)
2284 const char *arg_cstr;
2285 for (int arg_idx = 0; (arg_cstr = command.GetArgumentAtIndex(arg_idx)) != NULL; ++arg_idx)
2286 {
Greg Clayton91048ef2011-11-10 01:18:58 +00002287 ModuleList module_list;
2288 const size_t num_matches = FindModulesByName (target, arg_cstr, module_list, true);
2289 if (num_matches > 0)
Greg Claytone1f50b92011-05-03 22:09:39 +00002290 {
Greg Clayton91048ef2011-11-10 01:18:58 +00002291 for (size_t i=0; i<num_matches; ++i)
Greg Claytone1f50b92011-05-03 22:09:39 +00002292 {
Greg Clayton91048ef2011-11-10 01:18:58 +00002293 Module *module = module_list.GetModulePointerAtIndex(i);
2294 if (module)
Greg Claytone1f50b92011-05-03 22:09:39 +00002295 {
Greg Clayton91048ef2011-11-10 01:18:58 +00002296 if (DumpModuleSymbolVendor (result.GetOutputStream(), module))
Greg Claytone1f50b92011-05-03 22:09:39 +00002297 num_dumped++;
2298 }
2299 }
2300 }
2301 else
2302 result.AppendWarningWithFormat("Unable to find an image that matches '%s'.\n", arg_cstr);
2303 }
2304 }
2305
2306 if (num_dumped > 0)
2307 result.SetStatus (eReturnStatusSuccessFinishResult);
2308 else
2309 {
2310 result.AppendError ("no matching executable images found");
2311 result.SetStatus (eReturnStatusFailed);
2312 }
2313 }
2314 return result.Succeeded();
2315 }
2316};
2317
2318
2319#pragma mark CommandObjectTargetModulesDumpLineTable
2320
2321//----------------------------------------------------------------------
2322// Image debug line table dumping command
2323//----------------------------------------------------------------------
2324
2325class CommandObjectTargetModulesDumpLineTable : public CommandObjectTargetModulesSourceFileAutoComplete
2326{
2327public:
2328 CommandObjectTargetModulesDumpLineTable (CommandInterpreter &interpreter) :
2329 CommandObjectTargetModulesSourceFileAutoComplete (interpreter,
2330 "target modules dump line-table",
2331 "Dump the debug symbol file for one or more target modules.",
2332 NULL)
2333 {
2334 }
2335
2336 virtual
2337 ~CommandObjectTargetModulesDumpLineTable ()
2338 {
2339 }
2340
Jim Inghamda26bd22012-06-08 21:56:10 +00002341protected:
Greg Claytone1f50b92011-05-03 22:09:39 +00002342 virtual bool
Jim Inghamda26bd22012-06-08 21:56:10 +00002343 DoExecute (Args& command,
Greg Claytone1f50b92011-05-03 22:09:39 +00002344 CommandReturnObject &result)
2345 {
2346 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
2347 if (target == NULL)
2348 {
2349 result.AppendError ("invalid target, create a debug target using the 'target create' command");
2350 result.SetStatus (eReturnStatusFailed);
2351 return false;
2352 }
2353 else
2354 {
2355 ExecutionContext exe_ctx(m_interpreter.GetExecutionContext());
2356 uint32_t total_num_dumped = 0;
2357
2358 uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize();
2359 result.GetOutputStream().SetAddressByteSize(addr_byte_size);
2360 result.GetErrorStream().SetAddressByteSize(addr_byte_size);
2361
2362 if (command.GetArgumentCount() == 0)
2363 {
2364 result.AppendErrorWithFormat ("\nSyntax: %s\n", m_cmd_syntax.c_str());
2365 result.SetStatus (eReturnStatusFailed);
2366 }
2367 else
2368 {
2369 // Dump specified images (by basename or fullpath)
2370 const char *arg_cstr;
2371 for (int arg_idx = 0; (arg_cstr = command.GetArgumentAtIndex(arg_idx)) != NULL; ++arg_idx)
2372 {
2373 FileSpec file_spec(arg_cstr, false);
Jim Ingham93367902012-05-30 02:19:25 +00002374
2375 ModuleList &target_modules = target->GetImages();
2376 Mutex::Locker modules_locker(target_modules.GetMutex());
2377 const uint32_t num_modules = target_modules.GetSize();
Greg Claytone1f50b92011-05-03 22:09:39 +00002378 if (num_modules > 0)
2379 {
2380 uint32_t num_dumped = 0;
2381 for (uint32_t i = 0; i<num_modules; ++i)
2382 {
2383 if (DumpCompileUnitLineTable (m_interpreter,
2384 result.GetOutputStream(),
Jim Ingham93367902012-05-30 02:19:25 +00002385 target_modules.GetModulePointerAtIndexUnlocked(i),
Greg Claytone1f50b92011-05-03 22:09:39 +00002386 file_spec,
Greg Clayton567e7f32011-09-22 04:58:26 +00002387 exe_ctx.GetProcessPtr() && exe_ctx.GetProcessRef().IsAlive()))
Greg Claytone1f50b92011-05-03 22:09:39 +00002388 num_dumped++;
2389 }
2390 if (num_dumped == 0)
2391 result.AppendWarningWithFormat ("No source filenames matched '%s'.\n", arg_cstr);
2392 else
2393 total_num_dumped += num_dumped;
2394 }
2395 }
2396 }
2397
2398 if (total_num_dumped > 0)
2399 result.SetStatus (eReturnStatusSuccessFinishResult);
2400 else
2401 {
2402 result.AppendError ("no source filenames matched any command arguments");
2403 result.SetStatus (eReturnStatusFailed);
2404 }
2405 }
2406 return result.Succeeded();
2407 }
2408};
2409
2410
2411#pragma mark CommandObjectTargetModulesDump
2412
2413//----------------------------------------------------------------------
2414// Dump multi-word command for target modules
2415//----------------------------------------------------------------------
2416
2417class CommandObjectTargetModulesDump : public CommandObjectMultiword
2418{
2419public:
2420
2421 //------------------------------------------------------------------
2422 // Constructors and Destructors
2423 //------------------------------------------------------------------
2424 CommandObjectTargetModulesDump(CommandInterpreter &interpreter) :
2425 CommandObjectMultiword (interpreter,
2426 "target modules dump",
2427 "A set of commands for dumping information about one or more target modules.",
2428 "target modules dump [symtab|sections|symfile|line-table] [<file1> <file2> ...]")
2429 {
2430 LoadSubCommand ("symtab", CommandObjectSP (new CommandObjectTargetModulesDumpSymtab (interpreter)));
2431 LoadSubCommand ("sections", CommandObjectSP (new CommandObjectTargetModulesDumpSections (interpreter)));
2432 LoadSubCommand ("symfile", CommandObjectSP (new CommandObjectTargetModulesDumpSymfile (interpreter)));
2433 LoadSubCommand ("line-table", CommandObjectSP (new CommandObjectTargetModulesDumpLineTable (interpreter)));
2434 }
2435
2436 virtual
2437 ~CommandObjectTargetModulesDump()
2438 {
2439 }
2440};
2441
Jim Inghamda26bd22012-06-08 21:56:10 +00002442class CommandObjectTargetModulesAdd : public CommandObjectParsed
Greg Claytone1f50b92011-05-03 22:09:39 +00002443{
2444public:
2445 CommandObjectTargetModulesAdd (CommandInterpreter &interpreter) :
Jim Inghamda26bd22012-06-08 21:56:10 +00002446 CommandObjectParsed (interpreter,
2447 "target modules add",
2448 "Add a new module to the current target's modules.",
2449 "target modules add [<module>]")
Greg Claytone1f50b92011-05-03 22:09:39 +00002450 {
2451 }
2452
2453 virtual
2454 ~CommandObjectTargetModulesAdd ()
2455 {
2456 }
2457
Jim Inghamda26bd22012-06-08 21:56:10 +00002458 int
2459 HandleArgumentCompletion (Args &input,
2460 int &cursor_index,
2461 int &cursor_char_position,
2462 OptionElementVector &opt_element_vector,
2463 int match_start_point,
2464 int max_return_elements,
2465 bool &word_complete,
2466 StringList &matches)
2467 {
2468 std::string completion_str (input.GetArgumentAtIndex(cursor_index));
2469 completion_str.erase (cursor_char_position);
2470
2471 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
2472 CommandCompletions::eDiskFileCompletion,
2473 completion_str.c_str(),
2474 match_start_point,
2475 max_return_elements,
2476 NULL,
2477 word_complete,
2478 matches);
2479 return matches.GetSize();
2480 }
2481
2482protected:
Greg Claytone1f50b92011-05-03 22:09:39 +00002483 virtual bool
Jim Inghamda26bd22012-06-08 21:56:10 +00002484 DoExecute (Args& args,
Greg Claytone1f50b92011-05-03 22:09:39 +00002485 CommandReturnObject &result)
2486 {
2487 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
2488 if (target == NULL)
2489 {
2490 result.AppendError ("invalid target, create a debug target using the 'target create' command");
2491 result.SetStatus (eReturnStatusFailed);
2492 return false;
2493 }
2494 else
2495 {
2496 const size_t argc = args.GetArgumentCount();
2497 if (argc == 0)
2498 {
2499 result.AppendError ("one or more executable image paths must be specified");
2500 result.SetStatus (eReturnStatusFailed);
2501 return false;
2502 }
2503 else
2504 {
2505 for (size_t i=0; i<argc; ++i)
2506 {
2507 const char *path = args.GetArgumentAtIndex(i);
2508 if (path)
2509 {
2510 FileSpec file_spec(path, true);
Greg Claytone1f50b92011-05-03 22:09:39 +00002511 if (file_spec.Exists())
2512 {
Greg Clayton444fe992012-02-26 05:51:37 +00002513 ModuleSpec module_spec (file_spec);
2514 ModuleSP module_sp (target->GetSharedModule (module_spec));
Greg Claytone1f50b92011-05-03 22:09:39 +00002515 if (!module_sp)
2516 {
2517 result.AppendError ("one or more executable image paths must be specified");
2518 result.SetStatus (eReturnStatusFailed);
2519 return false;
2520 }
Jason Molenda36f6fb92011-08-02 23:28:55 +00002521 result.SetStatus (eReturnStatusSuccessFinishResult);
Greg Claytone1f50b92011-05-03 22:09:39 +00002522 }
2523 else
2524 {
2525 char resolved_path[PATH_MAX];
2526 result.SetStatus (eReturnStatusFailed);
2527 if (file_spec.GetPath (resolved_path, sizeof(resolved_path)))
2528 {
2529 if (strcmp (resolved_path, path) != 0)
2530 {
2531 result.AppendErrorWithFormat ("invalid module path '%s' with resolved path '%s'\n", path, resolved_path);
2532 break;
2533 }
2534 }
2535 result.AppendErrorWithFormat ("invalid module path '%s'\n", path);
2536 break;
2537 }
2538 }
2539 }
2540 }
2541 }
2542 return result.Succeeded();
2543 }
2544
Greg Claytone1f50b92011-05-03 22:09:39 +00002545};
2546
2547class CommandObjectTargetModulesLoad : public CommandObjectTargetModulesModuleAutoComplete
2548{
2549public:
2550 CommandObjectTargetModulesLoad (CommandInterpreter &interpreter) :
2551 CommandObjectTargetModulesModuleAutoComplete (interpreter,
2552 "target modules load",
2553 "Set the load addresses for one or more sections in a target module.",
2554 "target modules load [--file <module> --uuid <uuid>] <sect-name> <address> [<sect-name> <address> ....]"),
2555 m_option_group (interpreter),
2556 m_file_option (LLDB_OPT_SET_1, false, "file", 'f', 0, eArgTypePath, "Fullpath or basename for module to load."),
2557 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)
2558 {
2559 m_option_group.Append (&m_uuid_option_group, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
2560 m_option_group.Append (&m_file_option, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
2561 m_option_group.Append (&m_slide_option, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
2562 m_option_group.Finalize();
2563 }
2564
2565 virtual
2566 ~CommandObjectTargetModulesLoad ()
2567 {
2568 }
2569
Jim Inghamda26bd22012-06-08 21:56:10 +00002570 virtual Options *
2571 GetOptions ()
2572 {
2573 return &m_option_group;
2574 }
2575
2576protected:
Greg Claytone1f50b92011-05-03 22:09:39 +00002577 virtual bool
Jim Inghamda26bd22012-06-08 21:56:10 +00002578 DoExecute (Args& args,
Greg Claytone1f50b92011-05-03 22:09:39 +00002579 CommandReturnObject &result)
2580 {
2581 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
2582 if (target == NULL)
2583 {
2584 result.AppendError ("invalid target, create a debug target using the 'target create' command");
2585 result.SetStatus (eReturnStatusFailed);
2586 return false;
2587 }
2588 else
2589 {
2590 const size_t argc = args.GetArgumentCount();
Greg Clayton444fe992012-02-26 05:51:37 +00002591 ModuleSpec module_spec;
2592 bool search_using_module_spec = false;
Greg Claytone1f50b92011-05-03 22:09:39 +00002593 if (m_file_option.GetOptionValue().OptionWasSet())
Greg Clayton444fe992012-02-26 05:51:37 +00002594 {
2595 search_using_module_spec = true;
2596 module_spec.GetFileSpec() = m_file_option.GetOptionValue().GetCurrentValue();
2597 }
Greg Claytone1f50b92011-05-03 22:09:39 +00002598
2599 if (m_uuid_option_group.GetOptionValue().OptionWasSet())
Greg Clayton444fe992012-02-26 05:51:37 +00002600 {
2601 search_using_module_spec = true;
2602 module_spec.GetUUID() = m_uuid_option_group.GetOptionValue().GetCurrentValue();
2603 }
Greg Claytone1f50b92011-05-03 22:09:39 +00002604
Greg Clayton444fe992012-02-26 05:51:37 +00002605 if (search_using_module_spec)
Greg Claytone1f50b92011-05-03 22:09:39 +00002606 {
2607
2608 ModuleList matching_modules;
Greg Clayton444fe992012-02-26 05:51:37 +00002609 const size_t num_matches = target->GetImages().FindModules (module_spec, matching_modules);
Greg Claytone1f50b92011-05-03 22:09:39 +00002610
2611 char path[PATH_MAX];
2612 if (num_matches == 1)
2613 {
2614 Module *module = matching_modules.GetModulePointerAtIndex(0);
2615 if (module)
2616 {
2617 ObjectFile *objfile = module->GetObjectFile();
2618 if (objfile)
2619 {
2620 SectionList *section_list = objfile->GetSectionList();
2621 if (section_list)
2622 {
Greg Clayton9ab696e2012-03-27 21:10:07 +00002623 bool changed = false;
Greg Claytone1f50b92011-05-03 22:09:39 +00002624 if (argc == 0)
2625 {
2626 if (m_slide_option.GetOptionValue().OptionWasSet())
2627 {
Greg Clayton9ab696e2012-03-27 21:10:07 +00002628 const addr_t slide = m_slide_option.GetOptionValue().GetCurrentValue();
2629 module->SetLoadAddress (*target, slide, changed);
Greg Claytone1f50b92011-05-03 22:09:39 +00002630 }
2631 else
2632 {
2633 result.AppendError ("one or more section name + load address pair must be specified");
2634 result.SetStatus (eReturnStatusFailed);
2635 return false;
2636 }
2637 }
2638 else
2639 {
2640 if (m_slide_option.GetOptionValue().OptionWasSet())
2641 {
2642 result.AppendError ("The \"--slide <offset>\" option can't be used in conjunction with setting section load addresses.\n");
2643 result.SetStatus (eReturnStatusFailed);
2644 return false;
2645 }
2646
2647 for (size_t i=0; i<argc; i += 2)
2648 {
2649 const char *sect_name = args.GetArgumentAtIndex(i);
2650 const char *load_addr_cstr = args.GetArgumentAtIndex(i+1);
2651 if (sect_name && load_addr_cstr)
2652 {
2653 ConstString const_sect_name(sect_name);
2654 bool success = false;
2655 addr_t load_addr = Args::StringToUInt64(load_addr_cstr, LLDB_INVALID_ADDRESS, 0, &success);
2656 if (success)
2657 {
2658 SectionSP section_sp (section_list->FindSectionByName(const_sect_name));
2659 if (section_sp)
2660 {
Greg Clayton9ab696e2012-03-27 21:10:07 +00002661 if (section_sp->IsThreadSpecific())
2662 {
2663 result.AppendErrorWithFormat ("thread specific sections are not yet supported (section '%s')\n", sect_name);
2664 result.SetStatus (eReturnStatusFailed);
2665 break;
2666 }
2667 else
2668 {
Greg Clayton545762f2012-07-07 01:24:12 +00002669 if (target->GetSectionLoadList().SetSectionLoadAddress (section_sp, load_addr))
Greg Clayton9ab696e2012-03-27 21:10:07 +00002670 changed = true;
2671 result.AppendMessageWithFormat("section '%s' loaded at 0x%llx\n", sect_name, load_addr);
2672 }
Greg Claytone1f50b92011-05-03 22:09:39 +00002673 }
2674 else
2675 {
2676 result.AppendErrorWithFormat ("no section found that matches the section name '%s'\n", sect_name);
2677 result.SetStatus (eReturnStatusFailed);
2678 break;
2679 }
2680 }
2681 else
2682 {
2683 result.AppendErrorWithFormat ("invalid load address string '%s'\n", load_addr_cstr);
2684 result.SetStatus (eReturnStatusFailed);
2685 break;
2686 }
2687 }
2688 else
2689 {
2690 if (sect_name)
2691 result.AppendError ("section names must be followed by a load address.\n");
2692 else
2693 result.AppendError ("one or more section name + load address pair must be specified.\n");
2694 result.SetStatus (eReturnStatusFailed);
2695 break;
2696 }
2697 }
2698 }
Greg Clayton9ab696e2012-03-27 21:10:07 +00002699
2700 if (changed)
2701 target->ModulesDidLoad (matching_modules);
Greg Claytone1f50b92011-05-03 22:09:39 +00002702 }
2703 else
2704 {
2705 module->GetFileSpec().GetPath (path, sizeof(path));
2706 result.AppendErrorWithFormat ("no sections in object file '%s'\n", path);
2707 result.SetStatus (eReturnStatusFailed);
2708 }
2709 }
2710 else
2711 {
2712 module->GetFileSpec().GetPath (path, sizeof(path));
2713 result.AppendErrorWithFormat ("no object file for module '%s'\n", path);
2714 result.SetStatus (eReturnStatusFailed);
2715 }
2716 }
2717 else
2718 {
2719 module->GetFileSpec().GetPath (path, sizeof(path));
2720 result.AppendErrorWithFormat ("invalid module '%s'.\n", path);
2721 result.SetStatus (eReturnStatusFailed);
2722 }
2723 }
2724 else
2725 {
2726 char uuid_cstr[64];
Greg Clayton444fe992012-02-26 05:51:37 +00002727
2728 if (module_spec.GetFileSpec())
2729 module_spec.GetFileSpec().GetPath (path, sizeof(path));
Greg Claytone1f50b92011-05-03 22:09:39 +00002730 else
2731 path[0] = '\0';
2732
Greg Clayton444fe992012-02-26 05:51:37 +00002733 if (module_spec.GetUUIDPtr())
2734 module_spec.GetUUID().GetAsCString(uuid_cstr, sizeof(uuid_cstr));
Greg Claytone1f50b92011-05-03 22:09:39 +00002735 else
2736 uuid_cstr[0] = '\0';
2737 if (num_matches > 1)
2738 {
2739 result.AppendErrorWithFormat ("multiple modules match%s%s%s%s:\n",
2740 path[0] ? " file=" : "",
2741 path,
2742 uuid_cstr[0] ? " uuid=" : "",
2743 uuid_cstr);
2744 for (size_t i=0; i<num_matches; ++i)
2745 {
2746 if (matching_modules.GetModulePointerAtIndex(i)->GetFileSpec().GetPath (path, sizeof(path)))
2747 result.AppendMessageWithFormat("%s\n", path);
2748 }
2749 }
2750 else
2751 {
2752 result.AppendErrorWithFormat ("no modules were found that match%s%s%s%s.\n",
2753 path[0] ? " file=" : "",
2754 path,
2755 uuid_cstr[0] ? " uuid=" : "",
2756 uuid_cstr);
2757 }
2758 result.SetStatus (eReturnStatusFailed);
2759 }
2760 }
2761 else
2762 {
2763 result.AppendError ("either the \"--file <module>\" or the \"--uuid <uuid>\" option must be specified.\n");
2764 result.SetStatus (eReturnStatusFailed);
2765 return false;
2766 }
2767 }
2768 return result.Succeeded();
2769 }
2770
Greg Claytone1f50b92011-05-03 22:09:39 +00002771 OptionGroupOptions m_option_group;
2772 OptionGroupUUID m_uuid_option_group;
2773 OptionGroupFile m_file_option;
2774 OptionGroupUInt64 m_slide_option;
2775};
2776
2777//----------------------------------------------------------------------
2778// List images with associated information
2779//----------------------------------------------------------------------
Jim Inghamda26bd22012-06-08 21:56:10 +00002780class CommandObjectTargetModulesList : public CommandObjectParsed
Greg Claytone1f50b92011-05-03 22:09:39 +00002781{
2782public:
2783
2784 class CommandOptions : public Options
2785 {
2786 public:
2787
2788 CommandOptions (CommandInterpreter &interpreter) :
Greg Clayton899025f2011-08-09 00:01:09 +00002789 Options(interpreter),
Jim Ingham6bdea822011-10-24 18:36:33 +00002790 m_format_array(),
Daniel Dunbar97c89572011-10-31 22:50:49 +00002791 m_use_global_module_list (false),
Jim Ingham6bdea822011-10-24 18:36:33 +00002792 m_module_addr (LLDB_INVALID_ADDRESS)
Greg Claytone1f50b92011-05-03 22:09:39 +00002793 {
2794 }
2795
2796 virtual
2797 ~CommandOptions ()
2798 {
2799 }
2800
2801 virtual Error
2802 SetOptionValue (uint32_t option_idx, const char *option_arg)
2803 {
2804 char short_option = (char) m_getopt_table[option_idx].val;
Greg Clayton899025f2011-08-09 00:01:09 +00002805 if (short_option == 'g')
2806 {
2807 m_use_global_module_list = true;
2808 }
Jim Ingham6bdea822011-10-24 18:36:33 +00002809 else if (short_option == 'a')
2810 {
2811 bool success;
2812 m_module_addr = Args::StringToAddress(option_arg, LLDB_INVALID_ADDRESS, &success);
2813 if (!success)
2814 {
2815 Error error;
Greg Clayton9c236732011-10-26 00:56:27 +00002816 error.SetErrorStringWithFormat("invalid address: \"%s\"", option_arg);
Jim Ingham6bdea822011-10-24 18:36:33 +00002817 }
2818 }
Greg Clayton899025f2011-08-09 00:01:09 +00002819 else
2820 {
2821 uint32_t width = 0;
2822 if (option_arg)
2823 width = strtoul (option_arg, NULL, 0);
2824 m_format_array.push_back(std::make_pair(short_option, width));
2825 }
Greg Claytone1f50b92011-05-03 22:09:39 +00002826 Error error;
2827 return error;
2828 }
2829
2830 void
2831 OptionParsingStarting ()
2832 {
2833 m_format_array.clear();
Greg Clayton899025f2011-08-09 00:01:09 +00002834 m_use_global_module_list = false;
Jim Ingham6bdea822011-10-24 18:36:33 +00002835 m_module_addr = LLDB_INVALID_ADDRESS;
Greg Claytone1f50b92011-05-03 22:09:39 +00002836 }
2837
2838 const OptionDefinition*
2839 GetDefinitions ()
2840 {
2841 return g_option_table;
2842 }
2843
2844 // Options table: Required for subclasses of Options.
2845
2846 static OptionDefinition g_option_table[];
2847
2848 // Instance variables to hold the values for command options.
2849 typedef std::vector< std::pair<char, uint32_t> > FormatWidthCollection;
2850 FormatWidthCollection m_format_array;
Greg Clayton899025f2011-08-09 00:01:09 +00002851 bool m_use_global_module_list;
Jim Ingham6bdea822011-10-24 18:36:33 +00002852 lldb::addr_t m_module_addr;
Greg Claytone1f50b92011-05-03 22:09:39 +00002853 };
2854
2855 CommandObjectTargetModulesList (CommandInterpreter &interpreter) :
Jim Inghamda26bd22012-06-08 21:56:10 +00002856 CommandObjectParsed (interpreter,
2857 "target modules list",
2858 "List current executable and dependent shared library images.",
2859 "target modules list [<cmd-options>]"),
Greg Claytone1f50b92011-05-03 22:09:39 +00002860 m_options (interpreter)
2861 {
2862 }
2863
2864 virtual
2865 ~CommandObjectTargetModulesList ()
2866 {
2867 }
2868
2869 virtual
2870 Options *
2871 GetOptions ()
2872 {
2873 return &m_options;
2874 }
2875
Jim Inghamda26bd22012-06-08 21:56:10 +00002876protected:
Greg Claytone1f50b92011-05-03 22:09:39 +00002877 virtual bool
Jim Inghamda26bd22012-06-08 21:56:10 +00002878 DoExecute (Args& command,
Greg Claytone1f50b92011-05-03 22:09:39 +00002879 CommandReturnObject &result)
2880 {
2881 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Greg Clayton153ccd72011-08-10 02:10:13 +00002882 const bool use_global_module_list = m_options.m_use_global_module_list;
Greg Clayton11fb9212012-06-27 20:26:19 +00002883 // Define a local module list here to ensure it lives longer than any "locker"
2884 // object which might lock its contents below (through the "module_list_ptr"
2885 // variable).
2886 ModuleList module_list;
Greg Clayton153ccd72011-08-10 02:10:13 +00002887 if (target == NULL && use_global_module_list == false)
Greg Claytone1f50b92011-05-03 22:09:39 +00002888 {
2889 result.AppendError ("invalid target, create a debug target using the 'target create' command");
2890 result.SetStatus (eReturnStatusFailed);
2891 return false;
2892 }
2893 else
2894 {
Greg Clayton153ccd72011-08-10 02:10:13 +00002895 if (target)
2896 {
2897 uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize();
2898 result.GetOutputStream().SetAddressByteSize(addr_byte_size);
2899 result.GetErrorStream().SetAddressByteSize(addr_byte_size);
2900 }
Greg Claytone1f50b92011-05-03 22:09:39 +00002901 // Dump all sections for all modules images
Jim Ingham6bdea822011-10-24 18:36:33 +00002902 Stream &strm = result.GetOutputStream();
2903
2904 if (m_options.m_module_addr != LLDB_INVALID_ADDRESS)
2905 {
2906 if (target)
2907 {
2908 Address module_address;
2909 if (module_address.SetLoadAddress(m_options.m_module_addr, target))
2910 {
Greg Clayton3508c382012-02-24 01:59:29 +00002911 ModuleSP module_sp (module_address.GetModule());
2912 if (module_sp)
Jim Ingham6bdea822011-10-24 18:36:33 +00002913 {
Greg Clayton3508c382012-02-24 01:59:29 +00002914 PrintModule (target, module_sp.get(), UINT32_MAX, 0, strm);
Jim Ingham6bdea822011-10-24 18:36:33 +00002915 result.SetStatus (eReturnStatusSuccessFinishResult);
2916 }
2917 else
2918 {
2919 result.AppendError ("Couldn't find module matching address: 0x%llx.", m_options.m_module_addr);
2920 result.SetStatus (eReturnStatusFailed);
2921 }
2922 }
2923 else
2924 {
2925 result.AppendError ("Couldn't find module containing address: 0x%llx.", m_options.m_module_addr);
2926 result.SetStatus (eReturnStatusFailed);
2927 }
2928 }
2929 else
2930 {
2931 result.AppendError ("Can only look up modules by address with a valid target.");
2932 result.SetStatus (eReturnStatusFailed);
2933 }
2934 return result.Succeeded();
2935 }
2936
Jim Ingham93367902012-05-30 02:19:25 +00002937 uint32_t num_modules = 0;
2938 Mutex::Locker locker; // This locker will be locked on the mutex in module_list_ptr if it is non-NULL.
2939 // Otherwise it will lock the AllocationModuleCollectionMutex when accessing
2940 // the global module list directly.
Greg Clayton2ad894b2012-05-15 18:43:44 +00002941 ModuleList *module_list_ptr = NULL;
2942 const size_t argc = command.GetArgumentCount();
2943 if (argc == 0)
Greg Clayton899025f2011-08-09 00:01:09 +00002944 {
Greg Clayton2ad894b2012-05-15 18:43:44 +00002945 if (use_global_module_list)
2946 {
2947 locker.Lock (Module::GetAllocationModuleCollectionMutex());
2948 num_modules = Module::GetNumberAllocatedModules();
2949 }
2950 else
2951 {
2952 module_list_ptr = &target->GetImages();
Greg Clayton2ad894b2012-05-15 18:43:44 +00002953 }
Greg Clayton899025f2011-08-09 00:01:09 +00002954 }
2955 else
Greg Clayton2ad894b2012-05-15 18:43:44 +00002956 {
2957 for (size_t i=0; i<argc; ++i)
2958 {
2959 // Dump specified images (by basename or fullpath)
2960 const char *arg_cstr = command.GetArgumentAtIndex(i);
2961 const size_t num_matches = FindModulesByName (target, arg_cstr, module_list, use_global_module_list);
2962 if (num_matches == 0)
2963 {
2964 if (argc == 1)
2965 {
2966 result.AppendErrorWithFormat ("no modules found that match '%s'", arg_cstr);
2967 result.SetStatus (eReturnStatusFailed);
2968 return false;
2969 }
2970 }
2971 }
2972
Greg Clayton2ad894b2012-05-15 18:43:44 +00002973 module_list_ptr = &module_list;
2974 }
Jim Ingham93367902012-05-30 02:19:25 +00002975
2976 if (module_list_ptr != NULL)
2977 {
2978 locker.Lock(module_list_ptr->GetMutex());
2979 num_modules = module_list_ptr->GetSize();
2980 }
Greg Clayton899025f2011-08-09 00:01:09 +00002981
Greg Claytone1f50b92011-05-03 22:09:39 +00002982 if (num_modules > 0)
Jim Ingham6bdea822011-10-24 18:36:33 +00002983 {
Greg Claytone1f50b92011-05-03 22:09:39 +00002984 for (uint32_t image_idx = 0; image_idx<num_modules; ++image_idx)
2985 {
Greg Clayton153ccd72011-08-10 02:10:13 +00002986 ModuleSP module_sp;
Greg Clayton899025f2011-08-09 00:01:09 +00002987 Module *module;
Greg Clayton2ad894b2012-05-15 18:43:44 +00002988 if (module_list_ptr)
Greg Clayton899025f2011-08-09 00:01:09 +00002989 {
Jim Ingham93367902012-05-30 02:19:25 +00002990 module_sp = module_list_ptr->GetModuleAtIndexUnlocked(image_idx);
Greg Clayton2ad894b2012-05-15 18:43:44 +00002991 module = module_sp.get();
Greg Clayton899025f2011-08-09 00:01:09 +00002992 }
2993 else
2994 {
Greg Clayton2ad894b2012-05-15 18:43:44 +00002995 module = Module::GetAllocatedModuleAtIndex(image_idx);
2996 module_sp = module->shared_from_this();
Greg Clayton899025f2011-08-09 00:01:09 +00002997 }
Jim Ingham6bdea822011-10-24 18:36:33 +00002998
Greg Claytonb5a8f142012-02-05 02:38:54 +00002999 int indent = strm.Printf("[%3u] ", image_idx);
3000 PrintModule (target, module, image_idx, indent, strm);
Greg Clayton153ccd72011-08-10 02:10:13 +00003001
Greg Claytone1f50b92011-05-03 22:09:39 +00003002 }
3003 result.SetStatus (eReturnStatusSuccessFinishResult);
3004 }
3005 else
3006 {
Greg Clayton2ad894b2012-05-15 18:43:44 +00003007 if (argc)
3008 {
3009 if (use_global_module_list)
3010 result.AppendError ("the global module list has no matching modules");
3011 else
3012 result.AppendError ("the target has no matching modules");
3013 }
Greg Clayton153ccd72011-08-10 02:10:13 +00003014 else
Greg Clayton2ad894b2012-05-15 18:43:44 +00003015 {
3016 if (use_global_module_list)
3017 result.AppendError ("the global module list is empty");
3018 else
3019 result.AppendError ("the target has no associated executable images");
3020 }
Greg Claytone1f50b92011-05-03 22:09:39 +00003021 result.SetStatus (eReturnStatusFailed);
3022 return false;
3023 }
3024 }
3025 return result.Succeeded();
3026 }
Jim Ingham6bdea822011-10-24 18:36:33 +00003027
3028 void
Greg Claytonb5a8f142012-02-05 02:38:54 +00003029 PrintModule (Target *target, Module *module, uint32_t idx, int indent, Stream &strm)
Jim Ingham6bdea822011-10-24 18:36:33 +00003030 {
3031
3032 bool dump_object_name = false;
3033 if (m_options.m_format_array.empty())
3034 {
Greg Claytonb5a8f142012-02-05 02:38:54 +00003035 m_options.m_format_array.push_back(std::make_pair('u', 0));
3036 m_options.m_format_array.push_back(std::make_pair('h', 0));
3037 m_options.m_format_array.push_back(std::make_pair('f', 0));
3038 m_options.m_format_array.push_back(std::make_pair('S', 0));
Jim Ingham6bdea822011-10-24 18:36:33 +00003039 }
Greg Claytonb5a8f142012-02-05 02:38:54 +00003040 const size_t num_entries = m_options.m_format_array.size();
3041 bool print_space = false;
3042 for (size_t i=0; i<num_entries; ++i)
Jim Ingham6bdea822011-10-24 18:36:33 +00003043 {
Greg Claytonb5a8f142012-02-05 02:38:54 +00003044 if (print_space)
3045 strm.PutChar(' ');
3046 print_space = true;
3047 const char format_char = m_options.m_format_array[i].first;
3048 uint32_t width = m_options.m_format_array[i].second;
3049 switch (format_char)
Jim Ingham6bdea822011-10-24 18:36:33 +00003050 {
Greg Claytonb5a8f142012-02-05 02:38:54 +00003051 case 'A':
3052 DumpModuleArchitecture (strm, module, false, width);
3053 break;
3054
3055 case 't':
3056 DumpModuleArchitecture (strm, module, true, width);
3057 break;
3058
3059 case 'f':
3060 DumpFullpath (strm, &module->GetFileSpec(), width);
3061 dump_object_name = true;
3062 break;
3063
3064 case 'd':
3065 DumpDirectory (strm, &module->GetFileSpec(), width);
3066 break;
3067
3068 case 'b':
3069 DumpBasename (strm, &module->GetFileSpec(), width);
3070 dump_object_name = true;
3071 break;
3072
3073 case 'h':
3074 case 'o':
3075 // Image header address
3076 {
3077 uint32_t addr_nibble_width = target ? (target->GetArchitecture().GetAddressByteSize() * 2) : 16;
Jim Ingham6bdea822011-10-24 18:36:33 +00003078
Greg Claytonb5a8f142012-02-05 02:38:54 +00003079 ObjectFile *objfile = module->GetObjectFile ();
3080 if (objfile)
Jim Ingham6bdea822011-10-24 18:36:33 +00003081 {
Greg Claytonb5a8f142012-02-05 02:38:54 +00003082 Address header_addr(objfile->GetHeaderAddress());
3083 if (header_addr.IsValid())
Jim Ingham6bdea822011-10-24 18:36:33 +00003084 {
Greg Claytonb5a8f142012-02-05 02:38:54 +00003085 if (target && !target->GetSectionLoadList().IsEmpty())
Jim Ingham6bdea822011-10-24 18:36:33 +00003086 {
Greg Claytonb5a8f142012-02-05 02:38:54 +00003087 lldb::addr_t header_load_addr = header_addr.GetLoadAddress (target);
3088 if (header_load_addr == LLDB_INVALID_ADDRESS)
3089 {
3090 header_addr.Dump (&strm, target, Address::DumpStyleModuleWithFileAddress, Address::DumpStyleFileAddress);
3091 }
Jim Ingham6bdea822011-10-24 18:36:33 +00003092 else
Greg Claytonb5a8f142012-02-05 02:38:54 +00003093 {
3094 if (format_char == 'o')
3095 {
3096 // Show the offset of slide for the image
3097 strm.Printf ("0x%*.*llx", addr_nibble_width, addr_nibble_width, header_load_addr - header_addr.GetFileAddress());
3098 }
3099 else
3100 {
3101 // Show the load address of the image
3102 strm.Printf ("0x%*.*llx", addr_nibble_width, addr_nibble_width, header_load_addr);
3103 }
3104 }
Jim Ingham6bdea822011-10-24 18:36:33 +00003105 break;
3106 }
Greg Claytonb5a8f142012-02-05 02:38:54 +00003107 // The address was valid, but the image isn't loaded, output the address in an appropriate format
3108 header_addr.Dump (&strm, target, Address::DumpStyleFileAddress);
3109 break;
Jim Ingham6bdea822011-10-24 18:36:33 +00003110 }
Jim Ingham6bdea822011-10-24 18:36:33 +00003111 }
Greg Claytonb5a8f142012-02-05 02:38:54 +00003112 strm.Printf ("%*s", addr_nibble_width + 2, "");
3113 }
3114 break;
3115 case 'r':
3116 {
3117 uint32_t ref_count = 0;
3118 ModuleSP module_sp (module->shared_from_this());
3119 if (module_sp)
3120 {
3121 // Take one away to make sure we don't count our local "module_sp"
3122 ref_count = module_sp.use_count() - 1;
3123 }
3124 if (width)
3125 strm.Printf("{%*u}", width, ref_count);
3126 else
3127 strm.Printf("{%u}", ref_count);
3128 }
3129 break;
Jim Ingham6bdea822011-10-24 18:36:33 +00003130
Greg Claytonb5a8f142012-02-05 02:38:54 +00003131 case 's':
3132 case 'S':
3133 {
3134 SymbolVendor *symbol_vendor = module->GetSymbolVendor();
3135 if (symbol_vendor)
3136 {
3137 SymbolFile *symbol_file = symbol_vendor->GetSymbolFile();
3138 if (symbol_file)
3139 {
3140 if (format_char == 'S')
3141 {
3142 FileSpec &symfile_spec = symbol_file->GetObjectFile()->GetFileSpec();
3143 // Dump symbol file only if different from module file
3144 if (!symfile_spec || symfile_spec == module->GetFileSpec())
3145 {
3146 print_space = false;
3147 break;
3148 }
3149 // Add a newline and indent past the index
3150 strm.Printf ("\n%*s", indent, "");
3151 }
3152 DumpFullpath (strm, &symbol_file->GetObjectFile()->GetFileSpec(), width);
3153 dump_object_name = true;
3154 break;
3155 }
3156 }
3157 strm.Printf("%.*s", width, "<NONE>");
3158 }
3159 break;
3160
3161 case 'm':
3162 module->GetModificationTime().Dump(&strm, width);
3163 break;
Jim Ingham6bdea822011-10-24 18:36:33 +00003164
Greg Claytonb5a8f142012-02-05 02:38:54 +00003165 case 'p':
3166 strm.Printf("%p", module);
3167 break;
3168
3169 case 'u':
3170 DumpModuleUUID(strm, module);
3171 break;
3172
3173 default:
3174 break;
Jim Ingham6bdea822011-10-24 18:36:33 +00003175 }
Greg Claytonb5a8f142012-02-05 02:38:54 +00003176
3177 }
3178 if (dump_object_name)
3179 {
3180 const char *object_name = module->GetObjectName().GetCString();
3181 if (object_name)
3182 strm.Printf ("(%s)", object_name);
Jim Ingham6bdea822011-10-24 18:36:33 +00003183 }
3184 strm.EOL();
3185 }
3186
Greg Claytone1f50b92011-05-03 22:09:39 +00003187 CommandOptions m_options;
3188};
3189
3190OptionDefinition
3191CommandObjectTargetModulesList::CommandOptions::g_option_table[] =
3192{
Jim Ingham6bdea822011-10-24 18:36:33 +00003193 { LLDB_OPT_SET_1, false, "address", 'a', required_argument, NULL, 0, eArgTypeAddress, "Display the image at this address."},
3194 { 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 +00003195 { 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 +00003196 { 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."},
3197 { 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 +00003198 { LLDB_OPT_SET_1, false, "uuid", 'u', no_argument, NULL, 0, eArgTypeNone, "Display the UUID when listing images."},
3199 { LLDB_OPT_SET_1, false, "fullpath", 'f', optional_argument, NULL, 0, eArgTypeWidth, "Display the fullpath to the image object file."},
3200 { LLDB_OPT_SET_1, false, "directory", 'd', optional_argument, NULL, 0, eArgTypeWidth, "Display the directory with optional width for the image object file."},
3201 { LLDB_OPT_SET_1, false, "basename", 'b', optional_argument, NULL, 0, eArgTypeWidth, "Display the basename with optional width for the image object file."},
3202 { 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 +00003203 { 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 +00003204 { LLDB_OPT_SET_1, false, "mod-time", 'm', optional_argument, NULL, 0, eArgTypeWidth, "Display the modification time with optional width of the module."},
3205 { 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."},
3206 { LLDB_OPT_SET_1, false, "pointer", 'p', optional_argument, NULL, 0, eArgTypeNone, "Display the module pointer."},
Greg Clayton899025f2011-08-09 00:01:09 +00003207 { 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 +00003208 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
3209};
3210
Jason Molenda5b0afcc2012-07-12 00:20:07 +00003211#pragma mark CommandObjectTargetModulesShowUnwind
Greg Claytone1f50b92011-05-03 22:09:39 +00003212
Jason Molenda5b0afcc2012-07-12 00:20:07 +00003213//----------------------------------------------------------------------
3214// Lookup unwind information in images
3215//----------------------------------------------------------------------
3216
3217class CommandObjectTargetModulesShowUnwind : public CommandObjectParsed
3218{
3219public:
3220
3221 enum
3222 {
3223 eLookupTypeInvalid = -1,
3224 eLookupTypeAddress = 0,
3225 eLookupTypeSymbol,
3226 eLookupTypeFunction,
3227 eLookupTypeFunctionOrSymbol,
3228 kNumLookupTypes
3229 };
3230
3231 class CommandOptions : public Options
3232 {
3233 public:
3234
3235 CommandOptions (CommandInterpreter &interpreter) :
3236 Options(interpreter),
3237 m_type(eLookupTypeInvalid),
3238 m_str(),
3239 m_addr(LLDB_INVALID_ADDRESS)
3240 {
3241 }
3242
3243 virtual
3244 ~CommandOptions ()
3245 {
3246 }
3247
3248 virtual Error
3249 SetOptionValue (uint32_t option_idx, const char *option_arg)
3250 {
3251 Error error;
3252
3253 char short_option = (char) m_getopt_table[option_idx].val;
3254
3255 switch (short_option)
3256 {
3257 case 'a':
3258 m_type = eLookupTypeAddress;
3259 m_addr = Args::StringToUInt64(option_arg, LLDB_INVALID_ADDRESS);
3260 if (m_addr == LLDB_INVALID_ADDRESS)
3261 error.SetErrorStringWithFormat ("invalid address string '%s'", option_arg);
3262 break;
3263
3264 case 'n':
3265 m_str = option_arg;
3266 m_type = eLookupTypeFunctionOrSymbol;
3267 break;
3268 }
3269
3270 return error;
3271 }
3272
3273 void
3274 OptionParsingStarting ()
3275 {
3276 m_type = eLookupTypeInvalid;
3277 m_str.clear();
3278 m_addr = LLDB_INVALID_ADDRESS;
3279 }
3280
3281 const OptionDefinition*
3282 GetDefinitions ()
3283 {
3284 return g_option_table;
3285 }
3286
3287 // Options table: Required for subclasses of Options.
3288
3289 static OptionDefinition g_option_table[];
3290
3291 // Instance variables to hold the values for command options.
3292
3293 int m_type; // Should be a eLookupTypeXXX enum after parsing options
3294 std::string m_str; // Holds name lookup
3295 lldb::addr_t m_addr; // Holds the address to lookup
3296 };
3297
3298 CommandObjectTargetModulesShowUnwind (CommandInterpreter &interpreter) :
3299 CommandObjectParsed (interpreter,
3300 "target modules show-unwind",
3301 "Show synthesized unwind instructions for a function.",
3302 NULL),
3303 m_options (interpreter)
3304 {
3305 }
3306
3307 virtual
3308 ~CommandObjectTargetModulesShowUnwind ()
3309 {
3310 }
3311
3312 virtual
3313 Options *
3314 GetOptions ()
3315 {
3316 return &m_options;
3317 }
3318
3319protected:
3320 bool
3321 DoExecute (Args& command,
3322 CommandReturnObject &result)
3323 {
3324 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
3325 if (!target)
3326 {
3327 result.AppendError ("invalid target, create a debug target using the 'target create' command");
3328 result.SetStatus (eReturnStatusFailed);
3329 return false;
3330 }
3331
3332 ExecutionContext exe_ctx = m_interpreter.GetDebugger().GetSelectedExecutionContext();
3333 Process *process = exe_ctx.GetProcessPtr();
3334 ABI *abi = NULL;
3335 if (process)
3336 abi = process->GetABI().get();
3337
3338 if (process == NULL)
3339 {
3340 result.AppendError ("You must have a process running to use this command.");
3341 result.SetStatus (eReturnStatusFailed);
3342 return false;
3343 }
3344
3345 ThreadList threads(process->GetThreadList());
3346 if (threads.GetSize() == 0)
3347 {
3348 result.AppendError ("The process must be paused to use this command.");
3349 result.SetStatus (eReturnStatusFailed);
3350 return false;
3351 }
3352
3353 ThreadSP thread(threads.GetThreadAtIndex(0));
3354 if (thread.get() == NULL)
3355 {
3356 result.AppendError ("The process must be paused to use this command.");
3357 result.SetStatus (eReturnStatusFailed);
3358 return false;
3359 }
3360
3361 if (m_options.m_type == eLookupTypeFunctionOrSymbol)
3362 {
3363 SymbolContextList sc_list;
3364 uint32_t num_matches;
3365 ConstString function_name (m_options.m_str.c_str());
3366 num_matches = target->GetImages().FindFunctions (function_name, eFunctionNameTypeAuto, true, false, true, sc_list);
3367 for (uint32_t idx = 0; idx < num_matches; idx++)
3368 {
3369 SymbolContext sc;
3370 sc_list.GetContextAtIndex(idx, sc);
3371 if (sc.symbol == NULL && sc.function == NULL)
3372 continue;
3373 if (sc.module_sp.get() == NULL || sc.module_sp->GetObjectFile() == NULL)
3374 continue;
3375 AddressRange range;
3376 if (!sc.GetAddressRange (eSymbolContextFunction | eSymbolContextSymbol, 0, false, range))
3377 continue;
3378 if (!range.GetBaseAddress().IsValid())
3379 continue;
3380 ConstString funcname(sc.GetFunctionName());
3381 if (funcname.IsEmpty())
3382 continue;
3383 addr_t start_addr = range.GetBaseAddress().GetLoadAddress(target);
3384 if (abi)
3385 start_addr = abi->FixCodeAddress(start_addr);
3386
3387 FuncUnwindersSP func_unwinders_sp (sc.module_sp->GetObjectFile()->GetUnwindTable().GetUncachedFuncUnwindersContainingAddress(start_addr, sc));
3388 if (func_unwinders_sp.get() == NULL)
3389 continue;
3390
3391 Address first_non_prologue_insn (func_unwinders_sp->GetFirstNonPrologueInsn(*target));
3392 if (first_non_prologue_insn.IsValid())
3393 {
3394 result.GetOutputStream().Printf("First non-prologue instruction is at address 0x%llx or offset %lld into the function.\n", first_non_prologue_insn.GetLoadAddress(target), first_non_prologue_insn.GetLoadAddress(target) - start_addr);
3395 result.GetOutputStream().Printf ("\n");
3396 }
3397
3398 UnwindPlanSP non_callsite_unwind_plan = func_unwinders_sp->GetUnwindPlanAtNonCallSite(*thread.get());
3399 if (non_callsite_unwind_plan.get())
3400 {
3401 result.GetOutputStream().Printf("Asynchronous (not restricted to call-sites) UnwindPlan for %s`%s (start addr 0x%llx):\n", sc.module_sp->GetPlatformFileSpec().GetFilename().AsCString(), funcname.AsCString(), start_addr);
3402 non_callsite_unwind_plan->Dump(result.GetOutputStream(), thread.get(), LLDB_INVALID_ADDRESS);
3403 result.GetOutputStream().Printf ("\n");
3404 }
3405
3406 UnwindPlanSP callsite_unwind_plan = func_unwinders_sp->GetUnwindPlanAtCallSite(-1);
3407 if (callsite_unwind_plan.get())
3408 {
3409 result.GetOutputStream().Printf("Synchronous (restricted to call-sites) UnwindPlan for %s`%s (start addr 0x%llx):\n", sc.module_sp->GetPlatformFileSpec().GetFilename().AsCString(), funcname.AsCString(), start_addr);
3410 callsite_unwind_plan->Dump(result.GetOutputStream(), thread.get(), LLDB_INVALID_ADDRESS);
3411 result.GetOutputStream().Printf ("\n");
3412 }
3413
3414 UnwindPlanSP arch_default_unwind_plan = func_unwinders_sp->GetUnwindPlanArchitectureDefault(*thread.get());
3415 if (arch_default_unwind_plan.get())
3416 {
3417 result.GetOutputStream().Printf("Architecture default UnwindPlan for %s`%s (start addr 0x%llx):\n", sc.module_sp->GetPlatformFileSpec().GetFilename().AsCString(), funcname.AsCString(), start_addr);
3418 arch_default_unwind_plan->Dump(result.GetOutputStream(), thread.get(), LLDB_INVALID_ADDRESS);
3419 result.GetOutputStream().Printf ("\n");
3420 }
3421
3422 UnwindPlanSP fast_unwind_plan = func_unwinders_sp->GetUnwindPlanFastUnwind(*thread.get());
3423 if (fast_unwind_plan.get())
3424 {
3425 result.GetOutputStream().Printf("Fast UnwindPlan for %s`%s (start addr 0x%llx):\n", sc.module_sp->GetPlatformFileSpec().GetFilename().AsCString(), funcname.AsCString(), start_addr);
3426 fast_unwind_plan->Dump(result.GetOutputStream(), thread.get(), LLDB_INVALID_ADDRESS);
3427 result.GetOutputStream().Printf ("\n");
3428 }
3429
3430
3431 result.GetOutputStream().Printf ("\n");
3432 }
3433 }
3434 return result.Succeeded();
3435 }
3436
3437 CommandOptions m_options;
3438};
3439
3440OptionDefinition
3441CommandObjectTargetModulesShowUnwind::CommandOptions::g_option_table[] =
3442{
3443 { LLDB_OPT_SET_1, true, "name", 'n', required_argument, NULL, 0, eArgTypeFunctionName, "Lookup a function or symbol by name in one or more target modules."},
3444 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
3445};
Greg Claytone1f50b92011-05-03 22:09:39 +00003446
3447//----------------------------------------------------------------------
3448// Lookup information in images
3449//----------------------------------------------------------------------
Jim Inghamda26bd22012-06-08 21:56:10 +00003450class CommandObjectTargetModulesLookup : public CommandObjectParsed
Greg Claytone1f50b92011-05-03 22:09:39 +00003451{
3452public:
3453
3454 enum
3455 {
3456 eLookupTypeInvalid = -1,
3457 eLookupTypeAddress = 0,
3458 eLookupTypeSymbol,
3459 eLookupTypeFileLine, // Line is optional
3460 eLookupTypeFunction,
Greg Clayton2ad894b2012-05-15 18:43:44 +00003461 eLookupTypeFunctionOrSymbol,
Greg Claytone1f50b92011-05-03 22:09:39 +00003462 eLookupTypeType,
3463 kNumLookupTypes
3464 };
3465
3466 class CommandOptions : public Options
3467 {
3468 public:
3469
3470 CommandOptions (CommandInterpreter &interpreter) :
3471 Options(interpreter)
3472 {
3473 OptionParsingStarting();
3474 }
3475
3476 virtual
3477 ~CommandOptions ()
3478 {
3479 }
3480
3481 virtual Error
3482 SetOptionValue (uint32_t option_idx, const char *option_arg)
3483 {
3484 Error error;
3485
3486 char short_option = (char) m_getopt_table[option_idx].val;
3487
3488 switch (short_option)
3489 {
3490 case 'a':
3491 m_type = eLookupTypeAddress;
3492 m_addr = Args::StringToUInt64(option_arg, LLDB_INVALID_ADDRESS);
3493 if (m_addr == LLDB_INVALID_ADDRESS)
Greg Clayton9c236732011-10-26 00:56:27 +00003494 error.SetErrorStringWithFormat ("invalid address string '%s'", option_arg);
Greg Claytone1f50b92011-05-03 22:09:39 +00003495 break;
3496
3497 case 'o':
3498 m_offset = Args::StringToUInt64(option_arg, LLDB_INVALID_ADDRESS);
3499 if (m_offset == LLDB_INVALID_ADDRESS)
Greg Clayton9c236732011-10-26 00:56:27 +00003500 error.SetErrorStringWithFormat ("invalid offset string '%s'", option_arg);
Greg Claytone1f50b92011-05-03 22:09:39 +00003501 break;
3502
3503 case 's':
3504 m_str = option_arg;
3505 m_type = eLookupTypeSymbol;
3506 break;
3507
3508 case 'f':
3509 m_file.SetFile (option_arg, false);
3510 m_type = eLookupTypeFileLine;
3511 break;
3512
3513 case 'i':
Sean Callanan9ad19532012-02-11 01:22:21 +00003514 m_include_inlines = false;
Greg Claytone1f50b92011-05-03 22:09:39 +00003515 break;
3516
3517 case 'l':
3518 m_line_number = Args::StringToUInt32(option_arg, UINT32_MAX);
3519 if (m_line_number == UINT32_MAX)
Greg Clayton9c236732011-10-26 00:56:27 +00003520 error.SetErrorStringWithFormat ("invalid line number string '%s'", option_arg);
Greg Claytone1f50b92011-05-03 22:09:39 +00003521 else if (m_line_number == 0)
Greg Clayton9c236732011-10-26 00:56:27 +00003522 error.SetErrorString ("zero is an invalid line number");
Greg Claytone1f50b92011-05-03 22:09:39 +00003523 m_type = eLookupTypeFileLine;
3524 break;
3525
Greg Clayton2ad894b2012-05-15 18:43:44 +00003526 case 'F':
Greg Claytone1f50b92011-05-03 22:09:39 +00003527 m_str = option_arg;
3528 m_type = eLookupTypeFunction;
3529 break;
Greg Clayton2ad894b2012-05-15 18:43:44 +00003530
3531 case 'n':
3532 m_str = option_arg;
3533 m_type = eLookupTypeFunctionOrSymbol;
3534 break;
3535
Greg Claytone1f50b92011-05-03 22:09:39 +00003536 case 't':
3537 m_str = option_arg;
3538 m_type = eLookupTypeType;
3539 break;
3540
3541 case 'v':
3542 m_verbose = 1;
3543 break;
Sean Callanan56d31ec2012-06-06 20:49:55 +00003544
3545 case 'A':
3546 m_print_all = true;
3547 break;
Greg Claytone1f50b92011-05-03 22:09:39 +00003548
3549 case 'r':
3550 m_use_regex = true;
3551 break;
3552 }
3553
3554 return error;
3555 }
3556
3557 void
3558 OptionParsingStarting ()
3559 {
3560 m_type = eLookupTypeInvalid;
3561 m_str.clear();
3562 m_file.Clear();
3563 m_addr = LLDB_INVALID_ADDRESS;
3564 m_offset = 0;
3565 m_line_number = 0;
3566 m_use_regex = false;
Sean Callanan9ad19532012-02-11 01:22:21 +00003567 m_include_inlines = true;
Greg Claytone1f50b92011-05-03 22:09:39 +00003568 m_verbose = false;
Sean Callanan56d31ec2012-06-06 20:49:55 +00003569 m_print_all = false;
Greg Claytone1f50b92011-05-03 22:09:39 +00003570 }
3571
3572 const OptionDefinition*
3573 GetDefinitions ()
3574 {
3575 return g_option_table;
3576 }
3577
3578 // Options table: Required for subclasses of Options.
3579
3580 static OptionDefinition g_option_table[];
3581 int m_type; // Should be a eLookupTypeXXX enum after parsing options
3582 std::string m_str; // Holds name lookup
3583 FileSpec m_file; // Files for file lookups
3584 lldb::addr_t m_addr; // Holds the address to lookup
3585 lldb::addr_t m_offset; // Subtract this offset from m_addr before doing lookups.
3586 uint32_t m_line_number; // Line number for file+line lookups
3587 bool m_use_regex; // Name lookups in m_str are regular expressions.
Sean Callanan9ad19532012-02-11 01:22:21 +00003588 bool m_include_inlines;// Check for inline entries when looking up by file/line.
Greg Claytone1f50b92011-05-03 22:09:39 +00003589 bool m_verbose; // Enable verbose lookup info
Sean Callanan56d31ec2012-06-06 20:49:55 +00003590 bool m_print_all; // Print all matches, even in cases where there's a best match.
Greg Claytone1f50b92011-05-03 22:09:39 +00003591
3592 };
3593
3594 CommandObjectTargetModulesLookup (CommandInterpreter &interpreter) :
Jim Inghamda26bd22012-06-08 21:56:10 +00003595 CommandObjectParsed (interpreter,
3596 "target modules lookup",
3597 "Look up information within executable and dependent shared library images.",
3598 NULL),
3599 m_options (interpreter)
Greg Claytone1f50b92011-05-03 22:09:39 +00003600 {
3601 CommandArgumentEntry arg;
3602 CommandArgumentData file_arg;
3603
3604 // Define the first (and only) variant of this arg.
3605 file_arg.arg_type = eArgTypeFilename;
3606 file_arg.arg_repetition = eArgRepeatStar;
3607
3608 // There is only one variant this argument could be; put it into the argument entry.
3609 arg.push_back (file_arg);
3610
3611 // Push the data for the first argument into the m_arguments vector.
3612 m_arguments.push_back (arg);
3613 }
3614
3615 virtual
3616 ~CommandObjectTargetModulesLookup ()
3617 {
3618 }
3619
3620 virtual Options *
3621 GetOptions ()
3622 {
3623 return &m_options;
3624 }
3625
Sean Callanan56d31ec2012-06-06 20:49:55 +00003626 bool
3627 LookupHere (CommandInterpreter &interpreter, CommandReturnObject &result, bool &syntax_error)
3628 {
3629 switch (m_options.m_type)
3630 {
3631 case eLookupTypeAddress:
3632 case eLookupTypeFileLine:
3633 case eLookupTypeFunction:
3634 case eLookupTypeFunctionOrSymbol:
3635 case eLookupTypeSymbol:
3636 default:
3637 return false;
3638 case eLookupTypeType:
3639 break;
3640 }
3641
3642 ExecutionContext exe_ctx = interpreter.GetDebugger().GetSelectedExecutionContext();
3643
3644 StackFrameSP frame = exe_ctx.GetFrameSP();
3645
3646 if (!frame)
3647 return false;
3648
3649 const SymbolContext &sym_ctx(frame->GetSymbolContext(eSymbolContextModule));
3650
3651 if (!sym_ctx.module_sp)
3652 return false;
3653
3654 switch (m_options.m_type)
3655 {
3656 default:
3657 return false;
3658 case eLookupTypeType:
3659 if (!m_options.m_str.empty())
3660 {
3661 if (LookupTypeHere (m_interpreter,
3662 result.GetOutputStream(),
3663 sym_ctx,
3664 m_options.m_str.c_str(),
3665 m_options.m_use_regex))
3666 {
3667 result.SetStatus(eReturnStatusSuccessFinishResult);
3668 return true;
3669 }
3670 }
3671 break;
3672 }
3673
3674 return true;
3675 }
Greg Claytone1f50b92011-05-03 22:09:39 +00003676
3677 bool
3678 LookupInModule (CommandInterpreter &interpreter, Module *module, CommandReturnObject &result, bool &syntax_error)
3679 {
3680 switch (m_options.m_type)
3681 {
3682 case eLookupTypeAddress:
3683 if (m_options.m_addr != LLDB_INVALID_ADDRESS)
3684 {
3685 if (LookupAddressInModule (m_interpreter,
3686 result.GetOutputStream(),
3687 module,
3688 eSymbolContextEverything,
3689 m_options.m_addr,
3690 m_options.m_offset,
3691 m_options.m_verbose))
3692 {
3693 result.SetStatus(eReturnStatusSuccessFinishResult);
3694 return true;
3695 }
3696 }
3697 break;
3698
3699 case eLookupTypeSymbol:
3700 if (!m_options.m_str.empty())
3701 {
Greg Clayton2ad894b2012-05-15 18:43:44 +00003702 if (LookupSymbolInModule (m_interpreter,
3703 result.GetOutputStream(),
3704 module,
3705 m_options.m_str.c_str(),
3706 m_options.m_use_regex,
3707 m_options.m_verbose))
Greg Claytone1f50b92011-05-03 22:09:39 +00003708 {
3709 result.SetStatus(eReturnStatusSuccessFinishResult);
3710 return true;
3711 }
3712 }
3713 break;
3714
3715 case eLookupTypeFileLine:
3716 if (m_options.m_file)
3717 {
3718
3719 if (LookupFileAndLineInModule (m_interpreter,
3720 result.GetOutputStream(),
3721 module,
3722 m_options.m_file,
3723 m_options.m_line_number,
Sean Callanan9ad19532012-02-11 01:22:21 +00003724 m_options.m_include_inlines,
Greg Claytone1f50b92011-05-03 22:09:39 +00003725 m_options.m_verbose))
3726 {
3727 result.SetStatus(eReturnStatusSuccessFinishResult);
3728 return true;
3729 }
3730 }
3731 break;
Greg Clayton2ad894b2012-05-15 18:43:44 +00003732
3733 case eLookupTypeFunctionOrSymbol:
Greg Claytone1f50b92011-05-03 22:09:39 +00003734 case eLookupTypeFunction:
3735 if (!m_options.m_str.empty())
3736 {
3737 if (LookupFunctionInModule (m_interpreter,
3738 result.GetOutputStream(),
3739 module,
3740 m_options.m_str.c_str(),
3741 m_options.m_use_regex,
Sean Callanan9ad19532012-02-11 01:22:21 +00003742 m_options.m_include_inlines,
Greg Clayton2ad894b2012-05-15 18:43:44 +00003743 m_options.m_type == eLookupTypeFunctionOrSymbol, // include symbols
Greg Claytone1f50b92011-05-03 22:09:39 +00003744 m_options.m_verbose))
3745 {
3746 result.SetStatus(eReturnStatusSuccessFinishResult);
3747 return true;
3748 }
3749 }
3750 break;
3751
Greg Clayton2ad894b2012-05-15 18:43:44 +00003752
Greg Claytone1f50b92011-05-03 22:09:39 +00003753 case eLookupTypeType:
3754 if (!m_options.m_str.empty())
3755 {
3756 if (LookupTypeInModule (m_interpreter,
3757 result.GetOutputStream(),
3758 module,
3759 m_options.m_str.c_str(),
3760 m_options.m_use_regex))
3761 {
3762 result.SetStatus(eReturnStatusSuccessFinishResult);
3763 return true;
3764 }
3765 }
3766 break;
3767
3768 default:
3769 m_options.GenerateOptionUsage (result.GetErrorStream(), this);
3770 syntax_error = true;
3771 break;
3772 }
3773
3774 result.SetStatus (eReturnStatusFailed);
3775 return false;
3776 }
3777
Jim Inghamda26bd22012-06-08 21:56:10 +00003778protected:
Greg Claytone1f50b92011-05-03 22:09:39 +00003779 virtual bool
Jim Inghamda26bd22012-06-08 21:56:10 +00003780 DoExecute (Args& command,
Greg Claytone1f50b92011-05-03 22:09:39 +00003781 CommandReturnObject &result)
3782 {
3783 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
3784 if (target == NULL)
3785 {
3786 result.AppendError ("invalid target, create a debug target using the 'target create' command");
3787 result.SetStatus (eReturnStatusFailed);
3788 return false;
3789 }
3790 else
3791 {
3792 bool syntax_error = false;
3793 uint32_t i;
3794 uint32_t num_successful_lookups = 0;
3795 uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize();
3796 result.GetOutputStream().SetAddressByteSize(addr_byte_size);
3797 result.GetErrorStream().SetAddressByteSize(addr_byte_size);
3798 // Dump all sections for all modules images
3799
3800 if (command.GetArgumentCount() == 0)
3801 {
Sean Callanan56d31ec2012-06-06 20:49:55 +00003802 ModuleSP current_module;
3803
3804 // Where it is possible to look in the current symbol context
3805 // first, try that. If this search was successful and --all
3806 // was not passed, don't print anything else.
3807 if (LookupHere (m_interpreter, result, syntax_error))
3808 {
3809 result.GetOutputStream().EOL();
3810 num_successful_lookups++;
3811 if (!m_options.m_print_all)
3812 {
3813 result.SetStatus (eReturnStatusSuccessFinishResult);
3814 return result.Succeeded();
3815 }
3816 }
3817
3818 // Dump all sections for all other modules
3819
Jim Ingham93367902012-05-30 02:19:25 +00003820 ModuleList &target_modules = target->GetImages();
3821 Mutex::Locker modules_locker(target_modules.GetMutex());
3822 const uint32_t num_modules = target_modules.GetSize();
Greg Claytone1f50b92011-05-03 22:09:39 +00003823 if (num_modules > 0)
3824 {
3825 for (i = 0; i<num_modules && syntax_error == false; ++i)
3826 {
Sean Callanan56d31ec2012-06-06 20:49:55 +00003827 Module *module_pointer = target_modules.GetModulePointerAtIndexUnlocked(i);
3828
3829 if (module_pointer != current_module.get() &&
3830 LookupInModule (m_interpreter, target_modules.GetModulePointerAtIndexUnlocked(i), result, syntax_error))
Greg Claytone1f50b92011-05-03 22:09:39 +00003831 {
3832 result.GetOutputStream().EOL();
3833 num_successful_lookups++;
3834 }
3835 }
3836 }
3837 else
3838 {
3839 result.AppendError ("the target has no associated executable images");
3840 result.SetStatus (eReturnStatusFailed);
3841 return false;
3842 }
3843 }
3844 else
3845 {
3846 // Dump specified images (by basename or fullpath)
3847 const char *arg_cstr;
3848 for (i = 0; (arg_cstr = command.GetArgumentAtIndex(i)) != NULL && syntax_error == false; ++i)
3849 {
Greg Clayton91048ef2011-11-10 01:18:58 +00003850 ModuleList module_list;
3851 const size_t num_matches = FindModulesByName (target, arg_cstr, module_list, false);
3852 if (num_matches > 0)
Greg Claytone1f50b92011-05-03 22:09:39 +00003853 {
Greg Clayton91048ef2011-11-10 01:18:58 +00003854 for (size_t i=0; i<num_matches; ++i)
Greg Claytone1f50b92011-05-03 22:09:39 +00003855 {
Greg Clayton91048ef2011-11-10 01:18:58 +00003856 Module *module = module_list.GetModulePointerAtIndex(i);
3857 if (module)
Greg Claytone1f50b92011-05-03 22:09:39 +00003858 {
Greg Clayton91048ef2011-11-10 01:18:58 +00003859 if (LookupInModule (m_interpreter, module, result, syntax_error))
Greg Claytone1f50b92011-05-03 22:09:39 +00003860 {
3861 result.GetOutputStream().EOL();
3862 num_successful_lookups++;
3863 }
3864 }
3865 }
3866 }
3867 else
3868 result.AppendWarningWithFormat("Unable to find an image that matches '%s'.\n", arg_cstr);
3869 }
3870 }
3871
3872 if (num_successful_lookups > 0)
3873 result.SetStatus (eReturnStatusSuccessFinishResult);
3874 else
3875 result.SetStatus (eReturnStatusFailed);
3876 }
3877 return result.Succeeded();
3878 }
Greg Claytone1f50b92011-05-03 22:09:39 +00003879
3880 CommandOptions m_options;
3881};
3882
3883OptionDefinition
3884CommandObjectTargetModulesLookup::CommandOptions::g_option_table[] =
3885{
3886 { LLDB_OPT_SET_1, true, "address", 'a', required_argument, NULL, 0, eArgTypeAddress, "Lookup an address in one or more target modules."},
3887 { 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 +00003888 { LLDB_OPT_SET_2| LLDB_OPT_SET_4 | LLDB_OPT_SET_5
3889 /* 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 +00003890 false, "regex", 'r', no_argument, NULL, 0, eArgTypeNone, "The <name> argument for name lookups are regular expressions."},
Greg Claytone1f50b92011-05-03 22:09:39 +00003891 { 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 +00003892 { 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."},
3893 { 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 +00003894 { LLDB_OPT_SET_FROM_TO(3,5),
3895 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 +00003896 { 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."},
3897 { 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."},
3898 { 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 +00003899 { LLDB_OPT_SET_ALL, false, "verbose", 'v', no_argument, NULL, 0, eArgTypeNone, "Enable verbose lookup information."},
Sean Callanan56d31ec2012-06-06 20:49:55 +00003900 { LLDB_OPT_SET_ALL, false, "all", 'A', no_argument, NULL, 0, eArgTypeNone, "Print all matches, not just the best match, if a best match is available."},
Greg Clayton2ad894b2012-05-15 18:43:44 +00003901 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
Greg Claytone1f50b92011-05-03 22:09:39 +00003902};
Chris Lattner24943d22010-06-08 16:52:24 +00003903
3904
Jim Inghamd60d94a2011-03-11 03:53:59 +00003905#pragma mark CommandObjectMultiwordImageSearchPaths
Chris Lattner24943d22010-06-08 16:52:24 +00003906
3907//-------------------------------------------------------------------------
3908// CommandObjectMultiwordImageSearchPaths
3909//-------------------------------------------------------------------------
3910
Greg Claytone1f50b92011-05-03 22:09:39 +00003911class CommandObjectTargetModulesImageSearchPaths : public CommandObjectMultiword
Chris Lattner24943d22010-06-08 16:52:24 +00003912{
3913public:
Greg Claytone1f50b92011-05-03 22:09:39 +00003914
3915 CommandObjectTargetModulesImageSearchPaths (CommandInterpreter &interpreter) :
3916 CommandObjectMultiword (interpreter,
3917 "target modules search-paths",
3918 "A set of commands for operating on debugger target image search paths.",
3919 "target modules search-paths <subcommand> [<subcommand-options>]")
Chris Lattner24943d22010-06-08 16:52:24 +00003920 {
Greg Claytone1f50b92011-05-03 22:09:39 +00003921 LoadSubCommand ("add", CommandObjectSP (new CommandObjectTargetModulesSearchPathsAdd (interpreter)));
3922 LoadSubCommand ("clear", CommandObjectSP (new CommandObjectTargetModulesSearchPathsClear (interpreter)));
3923 LoadSubCommand ("insert", CommandObjectSP (new CommandObjectTargetModulesSearchPathsInsert (interpreter)));
3924 LoadSubCommand ("list", CommandObjectSP (new CommandObjectTargetModulesSearchPathsList (interpreter)));
3925 LoadSubCommand ("query", CommandObjectSP (new CommandObjectTargetModulesSearchPathsQuery (interpreter)));
Chris Lattner24943d22010-06-08 16:52:24 +00003926 }
Greg Claytone1f50b92011-05-03 22:09:39 +00003927
3928 ~CommandObjectTargetModulesImageSearchPaths()
Chris Lattner24943d22010-06-08 16:52:24 +00003929 {
3930 }
3931};
3932
Greg Claytone1f50b92011-05-03 22:09:39 +00003933
3934
3935#pragma mark CommandObjectTargetModules
3936
3937//-------------------------------------------------------------------------
3938// CommandObjectTargetModules
3939//-------------------------------------------------------------------------
3940
3941class CommandObjectTargetModules : public CommandObjectMultiword
3942{
3943public:
3944 //------------------------------------------------------------------
3945 // Constructors and Destructors
3946 //------------------------------------------------------------------
3947 CommandObjectTargetModules(CommandInterpreter &interpreter) :
3948 CommandObjectMultiword (interpreter,
3949 "target modules",
3950 "A set of commands for accessing information for one or more target modules.",
3951 "target modules <sub-command> ...")
3952 {
3953 LoadSubCommand ("add", CommandObjectSP (new CommandObjectTargetModulesAdd (interpreter)));
3954 LoadSubCommand ("load", CommandObjectSP (new CommandObjectTargetModulesLoad (interpreter)));
3955 //LoadSubCommand ("unload", CommandObjectSP (new CommandObjectTargetModulesUnload (interpreter)));
3956 LoadSubCommand ("dump", CommandObjectSP (new CommandObjectTargetModulesDump (interpreter)));
3957 LoadSubCommand ("list", CommandObjectSP (new CommandObjectTargetModulesList (interpreter)));
3958 LoadSubCommand ("lookup", CommandObjectSP (new CommandObjectTargetModulesLookup (interpreter)));
3959 LoadSubCommand ("search-paths", CommandObjectSP (new CommandObjectTargetModulesImageSearchPaths (interpreter)));
Jason Molenda5b0afcc2012-07-12 00:20:07 +00003960 LoadSubCommand ("show-unwind", CommandObjectSP (new CommandObjectTargetModulesShowUnwind (interpreter)));
Greg Claytone1f50b92011-05-03 22:09:39 +00003961
3962 }
3963 virtual
3964 ~CommandObjectTargetModules()
3965 {
3966 }
3967
3968private:
3969 //------------------------------------------------------------------
3970 // For CommandObjectTargetModules only
3971 //------------------------------------------------------------------
3972 DISALLOW_COPY_AND_ASSIGN (CommandObjectTargetModules);
3973};
3974
3975
Greg Clayton3508c382012-02-24 01:59:29 +00003976
Jim Inghamda26bd22012-06-08 21:56:10 +00003977class CommandObjectTargetSymbolsAdd : public CommandObjectParsed
Greg Clayton3508c382012-02-24 01:59:29 +00003978{
3979public:
3980 CommandObjectTargetSymbolsAdd (CommandInterpreter &interpreter) :
Jim Inghamda26bd22012-06-08 21:56:10 +00003981 CommandObjectParsed (interpreter,
3982 "target symbols add",
3983 "Add a debug symbol file to one of the target's current modules.",
3984 "target symbols add [<symfile>]")
Greg Clayton3508c382012-02-24 01:59:29 +00003985 {
3986 }
3987
3988 virtual
3989 ~CommandObjectTargetSymbolsAdd ()
3990 {
3991 }
3992
Jim Inghamda26bd22012-06-08 21:56:10 +00003993 int
3994 HandleArgumentCompletion (Args &input,
3995 int &cursor_index,
3996 int &cursor_char_position,
3997 OptionElementVector &opt_element_vector,
3998 int match_start_point,
3999 int max_return_elements,
4000 bool &word_complete,
4001 StringList &matches)
4002 {
4003 std::string completion_str (input.GetArgumentAtIndex(cursor_index));
4004 completion_str.erase (cursor_char_position);
4005
4006 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
4007 CommandCompletions::eDiskFileCompletion,
4008 completion_str.c_str(),
4009 match_start_point,
4010 max_return_elements,
4011 NULL,
4012 word_complete,
4013 matches);
4014 return matches.GetSize();
4015 }
4016
4017protected:
Greg Clayton3508c382012-02-24 01:59:29 +00004018 virtual bool
Jim Inghamda26bd22012-06-08 21:56:10 +00004019 DoExecute (Args& args,
Greg Clayton3508c382012-02-24 01:59:29 +00004020 CommandReturnObject &result)
4021 {
Greg Claytoncf5927e2012-05-18 02:38:05 +00004022 ExecutionContext exe_ctx (m_interpreter.GetExecutionContext());
4023 Target *target = exe_ctx.GetTargetPtr();
Greg Clayton3508c382012-02-24 01:59:29 +00004024 if (target == NULL)
4025 {
4026 result.AppendError ("invalid target, create a debug target using the 'target create' command");
4027 result.SetStatus (eReturnStatusFailed);
Greg Clayton3508c382012-02-24 01:59:29 +00004028 }
4029 else
4030 {
Greg Claytoncf5927e2012-05-18 02:38:05 +00004031 bool flush = false;
Greg Clayton3508c382012-02-24 01:59:29 +00004032 const size_t argc = args.GetArgumentCount();
4033 if (argc == 0)
4034 {
4035 result.AppendError ("one or more symbol file paths must be specified");
4036 result.SetStatus (eReturnStatusFailed);
Greg Clayton3508c382012-02-24 01:59:29 +00004037 }
4038 else
4039 {
4040 for (size_t i=0; i<argc; ++i)
4041 {
4042 const char *symfile_path = args.GetArgumentAtIndex(i);
4043 if (symfile_path)
4044 {
4045 FileSpec symfile_spec(symfile_path, true);
4046 ArchSpec arch;
4047 if (symfile_spec.Exists())
4048 {
4049 ModuleSP symfile_module_sp (new Module (symfile_spec, target->GetArchitecture()));
Johnny Chen9262cd52012-08-22 00:18:43 +00004050 const UUID &symfile_uuid = symfile_module_sp->GetUUID();
4051 StreamString ss_symfile_uuid;
4052 symfile_module_sp->GetUUID().Dump(&ss_symfile_uuid);
4053
Greg Clayton3508c382012-02-24 01:59:29 +00004054 if (symfile_module_sp)
4055 {
4056 // We now have a module that represents a symbol file
4057 // that can be used for a module that might exist in the
4058 // current target, so we need to find that module in the
4059 // target
4060
Johnny Chen9262cd52012-08-22 00:18:43 +00004061 ModuleSP old_module_sp (target->GetImages().FindModule (symfile_uuid));
Greg Clayton3508c382012-02-24 01:59:29 +00004062 if (old_module_sp)
4063 {
Greg Claytond4f16c82012-03-29 21:43:25 +00004064 // The module has not yet created its symbol vendor, we can just
4065 // give the existing target module the symfile path to use for
4066 // when it decides to create it!
4067 old_module_sp->SetSymbolFileFileSpec (symfile_module_sp->GetFileSpec());
Greg Clayton3508c382012-02-24 01:59:29 +00004068
Johnny Chen9262cd52012-08-22 00:18:43 +00004069 // Provide feedback that the symfile has been successfully added.
4070 const FileSpec &module_fs = old_module_sp->GetFileSpec();
4071 result.AppendMessageWithFormat("symbol file '%s' with UUID %s has been successfully added to the '%s/%s' module\n",
4072 symfile_path, ss_symfile_uuid.GetData(),
4073 module_fs.GetDirectory().AsCString(), module_fs.GetFilename().AsCString());
4074
Greg Claytond4f16c82012-03-29 21:43:25 +00004075 // Let clients know something changed in the module
4076 // if it is currently loaded
4077 ModuleList module_list;
4078 module_list.Append (old_module_sp);
4079 target->ModulesDidLoad (module_list);
Greg Claytoncf5927e2012-05-18 02:38:05 +00004080 flush = true;
Greg Clayton3508c382012-02-24 01:59:29 +00004081 }
Johnny Chen9262cd52012-08-22 00:18:43 +00004082 else
4083 {
4084 result.AppendErrorWithFormat ("symbol file '%s' with UUID %s does not match any existing module%s\n",
4085 symfile_path, ss_symfile_uuid.GetData(),
4086 (symfile_spec.GetFileType() != FileSpec::eFileTypeRegular)
4087 ? "\n please specify the full path to the symbol file"
4088 : "");
4089 break;
4090 }
Greg Clayton3508c382012-02-24 01:59:29 +00004091 }
4092 else
4093 {
4094 result.AppendError ("one or more executable image paths must be specified");
4095 result.SetStatus (eReturnStatusFailed);
Greg Claytoncf5927e2012-05-18 02:38:05 +00004096 break;
Greg Clayton3508c382012-02-24 01:59:29 +00004097 }
4098 result.SetStatus (eReturnStatusSuccessFinishResult);
4099 }
4100 else
4101 {
4102 char resolved_symfile_path[PATH_MAX];
4103 result.SetStatus (eReturnStatusFailed);
4104 if (symfile_spec.GetPath (resolved_symfile_path, sizeof(resolved_symfile_path)))
4105 {
4106 if (strcmp (resolved_symfile_path, symfile_path) != 0)
4107 {
4108 result.AppendErrorWithFormat ("invalid module path '%s' with resolved path '%s'\n", symfile_path, resolved_symfile_path);
4109 break;
4110 }
4111 }
4112 result.AppendErrorWithFormat ("invalid module path '%s'\n", symfile_path);
4113 break;
4114 }
4115 }
4116 }
4117 }
Greg Claytoncf5927e2012-05-18 02:38:05 +00004118
4119 if (flush)
4120 {
4121 Process *process = exe_ctx.GetProcessPtr();
4122 if (process)
4123 process->Flush();
4124 }
Greg Clayton3508c382012-02-24 01:59:29 +00004125 }
4126 return result.Succeeded();
4127 }
4128
Greg Clayton3508c382012-02-24 01:59:29 +00004129};
4130
4131
4132#pragma mark CommandObjectTargetSymbols
4133
4134//-------------------------------------------------------------------------
4135// CommandObjectTargetSymbols
4136//-------------------------------------------------------------------------
4137
4138class CommandObjectTargetSymbols : public CommandObjectMultiword
4139{
4140public:
4141 //------------------------------------------------------------------
4142 // Constructors and Destructors
4143 //------------------------------------------------------------------
4144 CommandObjectTargetSymbols(CommandInterpreter &interpreter) :
4145 CommandObjectMultiword (interpreter,
4146 "target symbols",
4147 "A set of commands for adding and managing debug symbol files.",
4148 "target symbols <sub-command> ...")
4149 {
4150 LoadSubCommand ("add", CommandObjectSP (new CommandObjectTargetSymbolsAdd (interpreter)));
4151
4152 }
4153 virtual
4154 ~CommandObjectTargetSymbols()
4155 {
4156 }
4157
4158private:
4159 //------------------------------------------------------------------
4160 // For CommandObjectTargetModules only
4161 //------------------------------------------------------------------
4162 DISALLOW_COPY_AND_ASSIGN (CommandObjectTargetSymbols);
4163};
4164
4165
Jim Inghamd60d94a2011-03-11 03:53:59 +00004166#pragma mark CommandObjectTargetStopHookAdd
4167
4168//-------------------------------------------------------------------------
4169// CommandObjectTargetStopHookAdd
4170//-------------------------------------------------------------------------
4171
Jim Inghamda26bd22012-06-08 21:56:10 +00004172class CommandObjectTargetStopHookAdd : public CommandObjectParsed
Jim Inghamd60d94a2011-03-11 03:53:59 +00004173{
4174public:
4175
4176 class CommandOptions : public Options
4177 {
4178 public:
Greg Claytonf15996e2011-04-07 22:46:35 +00004179 CommandOptions (CommandInterpreter &interpreter) :
4180 Options(interpreter),
Jim Inghamd60d94a2011-03-11 03:53:59 +00004181 m_line_start(0),
4182 m_line_end (UINT_MAX),
4183 m_func_name_type_mask (eFunctionNameTypeAuto),
4184 m_sym_ctx_specified (false),
Johnny Chen60fe60e2011-05-02 23:47:55 +00004185 m_thread_specified (false),
4186 m_use_one_liner (false),
4187 m_one_liner()
Jim Inghamd60d94a2011-03-11 03:53:59 +00004188 {
4189 }
4190
4191 ~CommandOptions () {}
4192
Greg Claytonb3448432011-03-24 21:19:54 +00004193 const OptionDefinition*
Jim Inghamd60d94a2011-03-11 03:53:59 +00004194 GetDefinitions ()
4195 {
4196 return g_option_table;
4197 }
4198
4199 virtual Error
Greg Clayton143fcc32011-04-13 00:18:08 +00004200 SetOptionValue (uint32_t option_idx, const char *option_arg)
Jim Inghamd60d94a2011-03-11 03:53:59 +00004201 {
4202 Error error;
4203 char short_option = (char) m_getopt_table[option_idx].val;
4204 bool success;
4205
4206 switch (short_option)
4207 {
4208 case 'c':
4209 m_class_name = option_arg;
4210 m_sym_ctx_specified = true;
4211 break;
4212
4213 case 'e':
4214 m_line_end = Args::StringToUInt32 (option_arg, UINT_MAX, 0, &success);
4215 if (!success)
4216 {
Greg Clayton9c236732011-10-26 00:56:27 +00004217 error.SetErrorStringWithFormat ("invalid end line number: \"%s\"", option_arg);
Jim Inghamd60d94a2011-03-11 03:53:59 +00004218 break;
4219 }
4220 m_sym_ctx_specified = true;
4221 break;
4222
4223 case 'l':
4224 m_line_start = Args::StringToUInt32 (option_arg, 0, 0, &success);
4225 if (!success)
4226 {
Greg Clayton9c236732011-10-26 00:56:27 +00004227 error.SetErrorStringWithFormat ("invalid start line number: \"%s\"", option_arg);
Jim Inghamd60d94a2011-03-11 03:53:59 +00004228 break;
4229 }
4230 m_sym_ctx_specified = true;
4231 break;
Sean Callanan9ad19532012-02-11 01:22:21 +00004232
4233 case 'i':
4234 m_no_inlines = true;
4235 break;
Jim Inghamd60d94a2011-03-11 03:53:59 +00004236
4237 case 'n':
4238 m_function_name = option_arg;
4239 m_func_name_type_mask |= eFunctionNameTypeAuto;
4240 m_sym_ctx_specified = true;
4241 break;
4242
4243 case 'f':
4244 m_file_name = option_arg;
4245 m_sym_ctx_specified = true;
4246 break;
4247 case 's':
4248 m_module_name = option_arg;
4249 m_sym_ctx_specified = true;
4250 break;
4251 case 't' :
4252 {
Jim Ingham7a4c8ea2011-03-22 01:53:33 +00004253 m_thread_id = Args::StringToUInt64(option_arg, LLDB_INVALID_THREAD_ID, 0);
Jim Inghamd60d94a2011-03-11 03:53:59 +00004254 if (m_thread_id == LLDB_INVALID_THREAD_ID)
Greg Clayton9c236732011-10-26 00:56:27 +00004255 error.SetErrorStringWithFormat ("invalid thread id string '%s'", option_arg);
Jim Inghamd60d94a2011-03-11 03:53:59 +00004256 m_thread_specified = true;
4257 }
4258 break;
4259 case 'T':
4260 m_thread_name = option_arg;
4261 m_thread_specified = true;
4262 break;
4263 case 'q':
4264 m_queue_name = option_arg;
4265 m_thread_specified = true;
4266 break;
4267 case 'x':
4268 {
Jim Ingham7a4c8ea2011-03-22 01:53:33 +00004269 m_thread_index = Args::StringToUInt32(option_arg, UINT32_MAX, 0);
Jim Inghamd60d94a2011-03-11 03:53:59 +00004270 if (m_thread_id == UINT32_MAX)
Greg Clayton9c236732011-10-26 00:56:27 +00004271 error.SetErrorStringWithFormat ("invalid thread index string '%s'", option_arg);
Jim Inghamd60d94a2011-03-11 03:53:59 +00004272 m_thread_specified = true;
4273 }
4274 break;
Johnny Chen60fe60e2011-05-02 23:47:55 +00004275 case 'o':
4276 m_use_one_liner = true;
4277 m_one_liner = option_arg;
4278 break;
Jim Inghamd60d94a2011-03-11 03:53:59 +00004279 default:
Greg Clayton9c236732011-10-26 00:56:27 +00004280 error.SetErrorStringWithFormat ("unrecognized option %c.", short_option);
Jim Inghamd60d94a2011-03-11 03:53:59 +00004281 break;
4282 }
4283 return error;
4284 }
4285
4286 void
Greg Clayton143fcc32011-04-13 00:18:08 +00004287 OptionParsingStarting ()
Jim Inghamd60d94a2011-03-11 03:53:59 +00004288 {
4289 m_class_name.clear();
4290 m_function_name.clear();
4291 m_line_start = 0;
4292 m_line_end = UINT_MAX;
4293 m_file_name.clear();
4294 m_module_name.clear();
4295 m_func_name_type_mask = eFunctionNameTypeAuto;
4296 m_thread_id = LLDB_INVALID_THREAD_ID;
4297 m_thread_index = UINT32_MAX;
4298 m_thread_name.clear();
4299 m_queue_name.clear();
Sean Callanan9ad19532012-02-11 01:22:21 +00004300
4301 m_no_inlines = false;
Jim Inghamd60d94a2011-03-11 03:53:59 +00004302 m_sym_ctx_specified = false;
4303 m_thread_specified = false;
Johnny Chen60fe60e2011-05-02 23:47:55 +00004304
4305 m_use_one_liner = false;
4306 m_one_liner.clear();
Jim Inghamd60d94a2011-03-11 03:53:59 +00004307 }
4308
4309
Greg Claytonb3448432011-03-24 21:19:54 +00004310 static OptionDefinition g_option_table[];
Jim Inghamd60d94a2011-03-11 03:53:59 +00004311
4312 std::string m_class_name;
4313 std::string m_function_name;
4314 uint32_t m_line_start;
4315 uint32_t m_line_end;
4316 std::string m_file_name;
4317 std::string m_module_name;
4318 uint32_t m_func_name_type_mask; // A pick from lldb::FunctionNameType.
4319 lldb::tid_t m_thread_id;
4320 uint32_t m_thread_index;
4321 std::string m_thread_name;
4322 std::string m_queue_name;
4323 bool m_sym_ctx_specified;
Sean Callanan9ad19532012-02-11 01:22:21 +00004324 bool m_no_inlines;
Jim Inghamd60d94a2011-03-11 03:53:59 +00004325 bool m_thread_specified;
Johnny Chen60fe60e2011-05-02 23:47:55 +00004326 // Instance variables to hold the values for one_liner options.
4327 bool m_use_one_liner;
4328 std::string m_one_liner;
Jim Inghamd60d94a2011-03-11 03:53:59 +00004329 };
4330
4331 Options *
4332 GetOptions ()
4333 {
4334 return &m_options;
4335 }
4336
4337 CommandObjectTargetStopHookAdd (CommandInterpreter &interpreter) :
Jim Inghamda26bd22012-06-08 21:56:10 +00004338 CommandObjectParsed (interpreter,
4339 "target stop-hook add ",
4340 "Add a hook to be executed when the target stops.",
4341 "target stop-hook add"),
Greg Claytonf15996e2011-04-07 22:46:35 +00004342 m_options (interpreter)
Jim Inghamd60d94a2011-03-11 03:53:59 +00004343 {
4344 }
4345
4346 ~CommandObjectTargetStopHookAdd ()
4347 {
4348 }
4349
4350 static size_t
4351 ReadCommandsCallbackFunction (void *baton,
4352 InputReader &reader,
4353 lldb::InputReaderAction notification,
4354 const char *bytes,
4355 size_t bytes_len)
4356 {
Caroline Tice892fadd2011-06-16 16:27:19 +00004357 StreamSP out_stream = reader.GetDebugger().GetAsyncOutputStream();
Jim Inghamd60d94a2011-03-11 03:53:59 +00004358 Target::StopHook *new_stop_hook = ((Target::StopHook *) baton);
Jim Inghame15511a2011-05-05 01:03:36 +00004359 static bool got_interrupted;
Caroline Tice892fadd2011-06-16 16:27:19 +00004360 bool batch_mode = reader.GetDebugger().GetCommandInterpreter().GetBatchCommandMode();
Jim Inghamd60d94a2011-03-11 03:53:59 +00004361
4362 switch (notification)
4363 {
4364 case eInputReaderActivate:
Caroline Tice892fadd2011-06-16 16:27:19 +00004365 if (!batch_mode)
4366 {
4367 out_stream->Printf ("%s\n", "Enter your stop hook command(s). Type 'DONE' to end.");
4368 if (reader.GetPrompt())
4369 out_stream->Printf ("%s", reader.GetPrompt());
4370 out_stream->Flush();
4371 }
Jim Inghame15511a2011-05-05 01:03:36 +00004372 got_interrupted = false;
Jim Inghamd60d94a2011-03-11 03:53:59 +00004373 break;
4374
4375 case eInputReaderDeactivate:
4376 break;
4377
4378 case eInputReaderReactivate:
Caroline Tice892fadd2011-06-16 16:27:19 +00004379 if (reader.GetPrompt() && !batch_mode)
Jim Inghamd60d94a2011-03-11 03:53:59 +00004380 {
Caroline Tice892fadd2011-06-16 16:27:19 +00004381 out_stream->Printf ("%s", reader.GetPrompt());
4382 out_stream->Flush();
Jim Inghamd60d94a2011-03-11 03:53:59 +00004383 }
Jim Inghame15511a2011-05-05 01:03:36 +00004384 got_interrupted = false;
Jim Inghamd60d94a2011-03-11 03:53:59 +00004385 break;
4386
Caroline Tice4a348082011-05-02 20:41:46 +00004387 case eInputReaderAsynchronousOutputWritten:
4388 break;
4389
Jim Inghamd60d94a2011-03-11 03:53:59 +00004390 case eInputReaderGotToken:
4391 if (bytes && bytes_len && baton)
4392 {
4393 StringList *commands = new_stop_hook->GetCommandPointer();
4394 if (commands)
4395 {
4396 commands->AppendString (bytes, bytes_len);
4397 }
4398 }
Caroline Tice892fadd2011-06-16 16:27:19 +00004399 if (!reader.IsDone() && reader.GetPrompt() && !batch_mode)
Jim Inghamd60d94a2011-03-11 03:53:59 +00004400 {
Caroline Tice892fadd2011-06-16 16:27:19 +00004401 out_stream->Printf ("%s", reader.GetPrompt());
4402 out_stream->Flush();
Jim Inghamd60d94a2011-03-11 03:53:59 +00004403 }
4404 break;
4405
4406 case eInputReaderInterrupt:
4407 {
4408 // Finish, and cancel the stop hook.
4409 new_stop_hook->GetTarget()->RemoveStopHookByID(new_stop_hook->GetID());
Caroline Tice892fadd2011-06-16 16:27:19 +00004410 if (!batch_mode)
4411 {
4412 out_stream->Printf ("Stop hook cancelled.\n");
4413 out_stream->Flush();
4414 }
4415
Jim Inghamd60d94a2011-03-11 03:53:59 +00004416 reader.SetIsDone (true);
4417 }
Jim Inghame15511a2011-05-05 01:03:36 +00004418 got_interrupted = true;
Jim Inghamd60d94a2011-03-11 03:53:59 +00004419 break;
4420
4421 case eInputReaderEndOfFile:
4422 reader.SetIsDone (true);
4423 break;
4424
4425 case eInputReaderDone:
Caroline Tice892fadd2011-06-16 16:27:19 +00004426 if (!got_interrupted && !batch_mode)
4427 {
Greg Clayton444e35b2011-10-19 18:09:39 +00004428 out_stream->Printf ("Stop hook #%llu added.\n", new_stop_hook->GetID());
Caroline Tice892fadd2011-06-16 16:27:19 +00004429 out_stream->Flush();
4430 }
Jim Inghamd60d94a2011-03-11 03:53:59 +00004431 break;
4432 }
4433
4434 return bytes_len;
4435 }
4436
Jim Inghamda26bd22012-06-08 21:56:10 +00004437protected:
Jim Inghamd60d94a2011-03-11 03:53:59 +00004438 bool
Jim Inghamda26bd22012-06-08 21:56:10 +00004439 DoExecute (Args& command, CommandReturnObject &result)
Jim Inghamd60d94a2011-03-11 03:53:59 +00004440 {
4441 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
4442 if (target)
4443 {
4444 Target::StopHookSP new_hook_sp;
4445 target->AddStopHook (new_hook_sp);
4446
4447 // First step, make the specifier.
4448 std::auto_ptr<SymbolContextSpecifier> specifier_ap;
4449 if (m_options.m_sym_ctx_specified)
4450 {
4451 specifier_ap.reset(new SymbolContextSpecifier(m_interpreter.GetDebugger().GetSelectedTarget()));
4452
4453 if (!m_options.m_module_name.empty())
4454 {
4455 specifier_ap->AddSpecification (m_options.m_module_name.c_str(), SymbolContextSpecifier::eModuleSpecified);
4456 }
4457
4458 if (!m_options.m_class_name.empty())
4459 {
4460 specifier_ap->AddSpecification (m_options.m_class_name.c_str(), SymbolContextSpecifier::eClassOrNamespaceSpecified);
4461 }
4462
4463 if (!m_options.m_file_name.empty())
4464 {
4465 specifier_ap->AddSpecification (m_options.m_file_name.c_str(), SymbolContextSpecifier::eFileSpecified);
4466 }
4467
4468 if (m_options.m_line_start != 0)
4469 {
4470 specifier_ap->AddLineSpecification (m_options.m_line_start, SymbolContextSpecifier::eLineStartSpecified);
4471 }
4472
4473 if (m_options.m_line_end != UINT_MAX)
4474 {
4475 specifier_ap->AddLineSpecification (m_options.m_line_end, SymbolContextSpecifier::eLineEndSpecified);
4476 }
4477
4478 if (!m_options.m_function_name.empty())
4479 {
4480 specifier_ap->AddSpecification (m_options.m_function_name.c_str(), SymbolContextSpecifier::eFunctionSpecified);
4481 }
4482 }
4483
4484 if (specifier_ap.get())
4485 new_hook_sp->SetSpecifier (specifier_ap.release());
4486
4487 // Next see if any of the thread options have been entered:
4488
4489 if (m_options.m_thread_specified)
4490 {
4491 ThreadSpec *thread_spec = new ThreadSpec();
4492
4493 if (m_options.m_thread_id != LLDB_INVALID_THREAD_ID)
4494 {
4495 thread_spec->SetTID (m_options.m_thread_id);
4496 }
4497
4498 if (m_options.m_thread_index != UINT32_MAX)
4499 thread_spec->SetIndex (m_options.m_thread_index);
4500
4501 if (!m_options.m_thread_name.empty())
4502 thread_spec->SetName (m_options.m_thread_name.c_str());
4503
4504 if (!m_options.m_queue_name.empty())
4505 thread_spec->SetQueueName (m_options.m_queue_name.c_str());
4506
4507 new_hook_sp->SetThreadSpecifier (thread_spec);
4508
4509 }
Johnny Chen60fe60e2011-05-02 23:47:55 +00004510 if (m_options.m_use_one_liner)
Jim Inghamd60d94a2011-03-11 03:53:59 +00004511 {
Johnny Chen60fe60e2011-05-02 23:47:55 +00004512 // Use one-liner.
4513 new_hook_sp->GetCommandPointer()->AppendString (m_options.m_one_liner.c_str());
Greg Clayton444e35b2011-10-19 18:09:39 +00004514 result.AppendMessageWithFormat("Stop hook #%llu added.\n", new_hook_sp->GetID());
Jim Inghamd60d94a2011-03-11 03:53:59 +00004515 }
Johnny Chen60fe60e2011-05-02 23:47:55 +00004516 else
Jim Inghamd60d94a2011-03-11 03:53:59 +00004517 {
Johnny Chen60fe60e2011-05-02 23:47:55 +00004518 // Otherwise gather up the command list, we'll push an input reader and suck the data from that directly into
4519 // the new stop hook's command string.
4520 InputReaderSP reader_sp (new InputReader(m_interpreter.GetDebugger()));
4521 if (!reader_sp)
4522 {
4523 result.AppendError("out of memory\n");
4524 result.SetStatus (eReturnStatusFailed);
4525 target->RemoveStopHookByID (new_hook_sp->GetID());
4526 return false;
4527 }
4528
4529 Error err (reader_sp->Initialize (CommandObjectTargetStopHookAdd::ReadCommandsCallbackFunction,
4530 new_hook_sp.get(), // baton
4531 eInputReaderGranularityLine, // token size, to pass to callback function
4532 "DONE", // end token
4533 "> ", // prompt
4534 true)); // echo input
4535 if (!err.Success())
4536 {
4537 result.AppendError (err.AsCString());
4538 result.SetStatus (eReturnStatusFailed);
4539 target->RemoveStopHookByID (new_hook_sp->GetID());
4540 return false;
4541 }
4542 m_interpreter.GetDebugger().PushInputReader (reader_sp);
Jim Inghamd60d94a2011-03-11 03:53:59 +00004543 }
Jim Inghamd60d94a2011-03-11 03:53:59 +00004544 result.SetStatus (eReturnStatusSuccessFinishNoResult);
4545 }
4546 else
4547 {
Greg Claytonabe0fed2011-04-18 08:33:37 +00004548 result.AppendError ("invalid target\n");
Jim Inghamd60d94a2011-03-11 03:53:59 +00004549 result.SetStatus (eReturnStatusFailed);
4550 }
4551
4552 return result.Succeeded();
4553 }
4554private:
4555 CommandOptions m_options;
4556};
4557
Greg Claytonb3448432011-03-24 21:19:54 +00004558OptionDefinition
Jim Inghamd60d94a2011-03-11 03:53:59 +00004559CommandObjectTargetStopHookAdd::CommandOptions::g_option_table[] =
4560{
Johnny Chen60fe60e2011-05-02 23:47:55 +00004561 { LLDB_OPT_SET_ALL, false, "one-liner", 'o', required_argument, NULL, NULL, eArgTypeOneLiner,
4562 "Specify a one-line breakpoint command inline. Be sure to surround it with quotes." },
Jim Inghamd60d94a2011-03-11 03:53:59 +00004563 { LLDB_OPT_SET_ALL, false, "shlib", 's', required_argument, NULL, CommandCompletions::eModuleCompletion, eArgTypeShlibName,
4564 "Set the module within which the stop-hook is to be run."},
4565 { LLDB_OPT_SET_ALL, false, "thread-index", 'x', required_argument, NULL, NULL, eArgTypeThreadIndex,
4566 "The stop hook is run only for the thread whose index matches this argument."},
4567 { LLDB_OPT_SET_ALL, false, "thread-id", 't', required_argument, NULL, NULL, eArgTypeThreadID,
4568 "The stop hook is run only for the thread whose TID matches this argument."},
4569 { LLDB_OPT_SET_ALL, false, "thread-name", 'T', required_argument, NULL, NULL, eArgTypeThreadName,
4570 "The stop hook is run only for the thread whose thread name matches this argument."},
4571 { LLDB_OPT_SET_ALL, false, "queue-name", 'q', required_argument, NULL, NULL, eArgTypeQueueName,
4572 "The stop hook is run only for threads in the queue whose name is given by this argument."},
4573 { LLDB_OPT_SET_1, false, "file", 'f', required_argument, NULL, CommandCompletions::eSourceFileCompletion, eArgTypeFilename,
4574 "Specify the source file within which the stop-hook is to be run." },
4575 { LLDB_OPT_SET_1, false, "start-line", 'l', required_argument, NULL, 0, eArgTypeLineNum,
4576 "Set the start of the line range for which the stop-hook is to be run."},
4577 { LLDB_OPT_SET_1, false, "end-line", 'e', required_argument, NULL, 0, eArgTypeLineNum,
4578 "Set the end of the line range for which the stop-hook is to be run."},
4579 { LLDB_OPT_SET_2, false, "classname", 'c', required_argument, NULL, NULL, eArgTypeClassName,
4580 "Specify the class within which the stop-hook is to be run." },
4581 { LLDB_OPT_SET_3, false, "name", 'n', required_argument, NULL, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName,
4582 "Set the function name within which the stop hook will be run." },
4583 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
4584};
4585
4586#pragma mark CommandObjectTargetStopHookDelete
4587
4588//-------------------------------------------------------------------------
4589// CommandObjectTargetStopHookDelete
4590//-------------------------------------------------------------------------
4591
Jim Inghamda26bd22012-06-08 21:56:10 +00004592class CommandObjectTargetStopHookDelete : public CommandObjectParsed
Jim Inghamd60d94a2011-03-11 03:53:59 +00004593{
4594public:
4595
4596 CommandObjectTargetStopHookDelete (CommandInterpreter &interpreter) :
Jim Inghamda26bd22012-06-08 21:56:10 +00004597 CommandObjectParsed (interpreter,
4598 "target stop-hook delete",
4599 "Delete a stop-hook.",
4600 "target stop-hook delete [<idx>]")
Jim Inghamd60d94a2011-03-11 03:53:59 +00004601 {
4602 }
4603
4604 ~CommandObjectTargetStopHookDelete ()
4605 {
4606 }
4607
Jim Inghamda26bd22012-06-08 21:56:10 +00004608protected:
Jim Inghamd60d94a2011-03-11 03:53:59 +00004609 bool
Jim Inghamda26bd22012-06-08 21:56:10 +00004610 DoExecute (Args& command, CommandReturnObject &result)
Jim Inghamd60d94a2011-03-11 03:53:59 +00004611 {
4612 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
4613 if (target)
4614 {
4615 // FIXME: see if we can use the breakpoint id style parser?
4616 size_t num_args = command.GetArgumentCount();
4617 if (num_args == 0)
4618 {
4619 if (!m_interpreter.Confirm ("Delete all stop hooks?", true))
4620 {
4621 result.SetStatus (eReturnStatusFailed);
4622 return false;
4623 }
4624 else
4625 {
4626 target->RemoveAllStopHooks();
4627 }
4628 }
4629 else
4630 {
4631 bool success;
4632 for (size_t i = 0; i < num_args; i++)
4633 {
4634 lldb::user_id_t user_id = Args::StringToUInt32 (command.GetArgumentAtIndex(i), 0, 0, &success);
4635 if (!success)
4636 {
Greg Claytonabe0fed2011-04-18 08:33:37 +00004637 result.AppendErrorWithFormat ("invalid stop hook id: \"%s\".\n", command.GetArgumentAtIndex(i));
Jim Inghamd60d94a2011-03-11 03:53:59 +00004638 result.SetStatus(eReturnStatusFailed);
4639 return false;
4640 }
4641 success = target->RemoveStopHookByID (user_id);
4642 if (!success)
4643 {
Greg Claytonabe0fed2011-04-18 08:33:37 +00004644 result.AppendErrorWithFormat ("unknown stop hook id: \"%s\".\n", command.GetArgumentAtIndex(i));
Jim Inghamd60d94a2011-03-11 03:53:59 +00004645 result.SetStatus(eReturnStatusFailed);
4646 return false;
4647 }
4648 }
4649 }
4650 result.SetStatus (eReturnStatusSuccessFinishNoResult);
4651 }
4652 else
4653 {
Greg Claytonabe0fed2011-04-18 08:33:37 +00004654 result.AppendError ("invalid target\n");
Jim Inghamd60d94a2011-03-11 03:53:59 +00004655 result.SetStatus (eReturnStatusFailed);
4656 }
4657
4658 return result.Succeeded();
4659 }
4660};
4661#pragma mark CommandObjectTargetStopHookEnableDisable
4662
4663//-------------------------------------------------------------------------
4664// CommandObjectTargetStopHookEnableDisable
4665//-------------------------------------------------------------------------
4666
Jim Inghamda26bd22012-06-08 21:56:10 +00004667class CommandObjectTargetStopHookEnableDisable : public CommandObjectParsed
Jim Inghamd60d94a2011-03-11 03:53:59 +00004668{
4669public:
4670
4671 CommandObjectTargetStopHookEnableDisable (CommandInterpreter &interpreter, bool enable, const char *name, const char *help, const char *syntax) :
Jim Inghamda26bd22012-06-08 21:56:10 +00004672 CommandObjectParsed (interpreter,
4673 name,
4674 help,
4675 syntax),
Jim Inghamd60d94a2011-03-11 03:53:59 +00004676 m_enable (enable)
4677 {
4678 }
4679
4680 ~CommandObjectTargetStopHookEnableDisable ()
4681 {
4682 }
4683
Jim Inghamda26bd22012-06-08 21:56:10 +00004684protected:
Jim Inghamd60d94a2011-03-11 03:53:59 +00004685 bool
Jim Inghamda26bd22012-06-08 21:56:10 +00004686 DoExecute (Args& command, CommandReturnObject &result)
Jim Inghamd60d94a2011-03-11 03:53:59 +00004687 {
4688 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
4689 if (target)
4690 {
4691 // FIXME: see if we can use the breakpoint id style parser?
4692 size_t num_args = command.GetArgumentCount();
4693 bool success;
4694
4695 if (num_args == 0)
4696 {
4697 target->SetAllStopHooksActiveState (m_enable);
4698 }
4699 else
4700 {
4701 for (size_t i = 0; i < num_args; i++)
4702 {
4703 lldb::user_id_t user_id = Args::StringToUInt32 (command.GetArgumentAtIndex(i), 0, 0, &success);
4704 if (!success)
4705 {
Greg Claytonabe0fed2011-04-18 08:33:37 +00004706 result.AppendErrorWithFormat ("invalid stop hook id: \"%s\".\n", command.GetArgumentAtIndex(i));
Jim Inghamd60d94a2011-03-11 03:53:59 +00004707 result.SetStatus(eReturnStatusFailed);
4708 return false;
4709 }
4710 success = target->SetStopHookActiveStateByID (user_id, m_enable);
4711 if (!success)
4712 {
Greg Claytonabe0fed2011-04-18 08:33:37 +00004713 result.AppendErrorWithFormat ("unknown stop hook id: \"%s\".\n", command.GetArgumentAtIndex(i));
Jim Inghamd60d94a2011-03-11 03:53:59 +00004714 result.SetStatus(eReturnStatusFailed);
4715 return false;
4716 }
4717 }
4718 }
4719 result.SetStatus (eReturnStatusSuccessFinishNoResult);
4720 }
4721 else
4722 {
Greg Claytonabe0fed2011-04-18 08:33:37 +00004723 result.AppendError ("invalid target\n");
Jim Inghamd60d94a2011-03-11 03:53:59 +00004724 result.SetStatus (eReturnStatusFailed);
4725 }
4726 return result.Succeeded();
4727 }
4728private:
4729 bool m_enable;
4730};
4731
4732#pragma mark CommandObjectTargetStopHookList
4733
4734//-------------------------------------------------------------------------
4735// CommandObjectTargetStopHookList
4736//-------------------------------------------------------------------------
4737
Jim Inghamda26bd22012-06-08 21:56:10 +00004738class CommandObjectTargetStopHookList : public CommandObjectParsed
Jim Inghamd60d94a2011-03-11 03:53:59 +00004739{
4740public:
4741
4742 CommandObjectTargetStopHookList (CommandInterpreter &interpreter) :
Jim Inghamda26bd22012-06-08 21:56:10 +00004743 CommandObjectParsed (interpreter,
4744 "target stop-hook list",
4745 "List all stop-hooks.",
4746 "target stop-hook list [<type>]")
Jim Inghamd60d94a2011-03-11 03:53:59 +00004747 {
4748 }
4749
4750 ~CommandObjectTargetStopHookList ()
4751 {
4752 }
4753
Jim Inghamda26bd22012-06-08 21:56:10 +00004754protected:
Jim Inghamd60d94a2011-03-11 03:53:59 +00004755 bool
Jim Inghamda26bd22012-06-08 21:56:10 +00004756 DoExecute (Args& command, CommandReturnObject &result)
Jim Inghamd60d94a2011-03-11 03:53:59 +00004757 {
4758 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Johnny Chen9fc16922011-11-29 23:56:14 +00004759 if (!target)
Jim Inghamd60d94a2011-03-11 03:53:59 +00004760 {
Greg Claytonabe0fed2011-04-18 08:33:37 +00004761 result.AppendError ("invalid target\n");
Jim Inghamd60d94a2011-03-11 03:53:59 +00004762 result.SetStatus (eReturnStatusFailed);
Jason Molenda6e3a2412011-09-23 21:15:42 +00004763 return result.Succeeded();
Jim Inghamd60d94a2011-03-11 03:53:59 +00004764 }
4765
4766 size_t num_hooks = target->GetNumStopHooks ();
4767 if (num_hooks == 0)
4768 {
4769 result.GetOutputStream().PutCString ("No stop hooks.\n");
4770 }
4771 else
4772 {
4773 for (size_t i = 0; i < num_hooks; i++)
4774 {
4775 Target::StopHookSP this_hook = target->GetStopHookAtIndex (i);
4776 if (i > 0)
4777 result.GetOutputStream().PutCString ("\n");
4778 this_hook->GetDescription (&(result.GetOutputStream()), eDescriptionLevelFull);
4779 }
4780 }
Johnny Chen6c7c3902011-11-30 19:09:20 +00004781 result.SetStatus (eReturnStatusSuccessFinishResult);
Jim Inghamd60d94a2011-03-11 03:53:59 +00004782 return result.Succeeded();
4783 }
4784};
4785
4786#pragma mark CommandObjectMultiwordTargetStopHooks
4787//-------------------------------------------------------------------------
4788// CommandObjectMultiwordTargetStopHooks
4789//-------------------------------------------------------------------------
4790
4791class CommandObjectMultiwordTargetStopHooks : public CommandObjectMultiword
4792{
4793public:
4794
4795 CommandObjectMultiwordTargetStopHooks (CommandInterpreter &interpreter) :
4796 CommandObjectMultiword (interpreter,
4797 "target stop-hook",
4798 "A set of commands for operating on debugger target stop-hooks.",
4799 "target stop-hook <subcommand> [<subcommand-options>]")
4800 {
4801 LoadSubCommand ("add", CommandObjectSP (new CommandObjectTargetStopHookAdd (interpreter)));
4802 LoadSubCommand ("delete", CommandObjectSP (new CommandObjectTargetStopHookDelete (interpreter)));
4803 LoadSubCommand ("disable", CommandObjectSP (new CommandObjectTargetStopHookEnableDisable (interpreter,
4804 false,
4805 "target stop-hook disable [<id>]",
4806 "Disable a stop-hook.",
4807 "target stop-hook disable")));
4808 LoadSubCommand ("enable", CommandObjectSP (new CommandObjectTargetStopHookEnableDisable (interpreter,
4809 true,
4810 "target stop-hook enable [<id>]",
4811 "Enable a stop-hook.",
4812 "target stop-hook enable")));
4813 LoadSubCommand ("list", CommandObjectSP (new CommandObjectTargetStopHookList (interpreter)));
4814 }
4815
4816 ~CommandObjectMultiwordTargetStopHooks()
4817 {
4818 }
4819};
4820
4821
Chris Lattner24943d22010-06-08 16:52:24 +00004822
4823#pragma mark CommandObjectMultiwordTarget
4824
4825//-------------------------------------------------------------------------
4826// CommandObjectMultiwordTarget
4827//-------------------------------------------------------------------------
4828
Greg Clayton63094e02010-06-23 01:19:29 +00004829CommandObjectMultiwordTarget::CommandObjectMultiwordTarget (CommandInterpreter &interpreter) :
Greg Clayton238c0a12010-09-18 01:14:36 +00004830 CommandObjectMultiword (interpreter,
4831 "target",
Chris Lattner24943d22010-06-08 16:52:24 +00004832 "A set of commands for operating on debugger targets.",
4833 "target <subcommand> [<subcommand-options>]")
4834{
Greg Claytonabe0fed2011-04-18 08:33:37 +00004835
4836 LoadSubCommand ("create", CommandObjectSP (new CommandObjectTargetCreate (interpreter)));
Greg Clayton153ccd72011-08-10 02:10:13 +00004837 LoadSubCommand ("delete", CommandObjectSP (new CommandObjectTargetDelete (interpreter)));
Greg Claytonabe0fed2011-04-18 08:33:37 +00004838 LoadSubCommand ("list", CommandObjectSP (new CommandObjectTargetList (interpreter)));
4839 LoadSubCommand ("select", CommandObjectSP (new CommandObjectTargetSelect (interpreter)));
Jim Inghamd60d94a2011-03-11 03:53:59 +00004840 LoadSubCommand ("stop-hook", CommandObjectSP (new CommandObjectMultiwordTargetStopHooks (interpreter)));
Greg Claytone1f50b92011-05-03 22:09:39 +00004841 LoadSubCommand ("modules", CommandObjectSP (new CommandObjectTargetModules (interpreter)));
Greg Clayton3508c382012-02-24 01:59:29 +00004842 LoadSubCommand ("symbols", CommandObjectSP (new CommandObjectTargetSymbols (interpreter)));
Greg Clayton801417e2011-07-07 01:59:51 +00004843 LoadSubCommand ("variable", CommandObjectSP (new CommandObjectTargetVariable (interpreter)));
Chris Lattner24943d22010-06-08 16:52:24 +00004844}
4845
4846CommandObjectMultiwordTarget::~CommandObjectMultiwordTarget ()
4847{
4848}
4849
Greg Claytonabe0fed2011-04-18 08:33:37 +00004850