blob: 2a5b6c6d4c452f6dc6b5bd8d59268b77a0d94f16 [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 Clayton49ce8962012-08-29 21:13:06 +000021#include "lldb/Core/Module.h"
22#include "lldb/Core/ModuleSpec.h"
Greg Claytone1f50b92011-05-03 22:09:39 +000023#include "lldb/Core/Section.h"
Greg Claytonabe0fed2011-04-18 08:33:37 +000024#include "lldb/Core/State.h"
Chris Lattner24943d22010-06-08 16:52:24 +000025#include "lldb/Core/Timer.h"
Greg Clayton801417e2011-07-07 01:59:51 +000026#include "lldb/Core/ValueObjectVariable.h"
Greg Claytonb924eb62012-09-27 03:13:55 +000027#include "lldb/Host/Symbols.h"
Chris Lattner24943d22010-06-08 16:52:24 +000028#include "lldb/Interpreter/CommandInterpreter.h"
29#include "lldb/Interpreter/CommandReturnObject.h"
Greg Claytone1f50b92011-05-03 22:09:39 +000030#include "lldb/Interpreter/Options.h"
Greg Claytonabe0fed2011-04-18 08:33:37 +000031#include "lldb/Interpreter/OptionGroupArchitecture.h"
Greg Clayton5beb99d2011-08-11 02:48:45 +000032#include "lldb/Interpreter/OptionGroupBoolean.h"
Greg Claytone1f50b92011-05-03 22:09:39 +000033#include "lldb/Interpreter/OptionGroupFile.h"
Greg Claytona42880a2011-10-25 06:44:01 +000034#include "lldb/Interpreter/OptionGroupFormat.h"
Greg Clayton368f8222011-07-07 04:38:25 +000035#include "lldb/Interpreter/OptionGroupVariable.h"
Greg Claytonabe0fed2011-04-18 08:33:37 +000036#include "lldb/Interpreter/OptionGroupPlatform.h"
Greg Claytone1f50b92011-05-03 22:09:39 +000037#include "lldb/Interpreter/OptionGroupUInt64.h"
38#include "lldb/Interpreter/OptionGroupUUID.h"
Greg Clayton801417e2011-07-07 01:59:51 +000039#include "lldb/Interpreter/OptionGroupValueObjectDisplay.h"
Greg Clayton49ce8962012-08-29 21:13:06 +000040#include "lldb/Symbol/CompileUnit.h"
Jason Molenda5b0afcc2012-07-12 00:20:07 +000041#include "lldb/Symbol/FuncUnwinders.h"
Greg Claytone1f50b92011-05-03 22:09:39 +000042#include "lldb/Symbol/LineTable.h"
43#include "lldb/Symbol/ObjectFile.h"
44#include "lldb/Symbol/SymbolFile.h"
45#include "lldb/Symbol/SymbolVendor.h"
Jason Molenda5b0afcc2012-07-12 00:20:07 +000046#include "lldb/Symbol/UnwindPlan.h"
Greg Clayton801417e2011-07-07 01:59:51 +000047#include "lldb/Symbol/VariableList.h"
Chris Lattner24943d22010-06-08 16:52:24 +000048#include "lldb/Target/Process.h"
49#include "lldb/Target/StackFrame.h"
50#include "lldb/Target/Thread.h"
Jim Inghamd60d94a2011-03-11 03:53:59 +000051#include "lldb/Target/ThreadSpec.h"
Chris Lattner24943d22010-06-08 16:52:24 +000052
53using namespace lldb;
54using namespace lldb_private;
55
Greg Claytonabe0fed2011-04-18 08:33:37 +000056
57
58static void
59DumpTargetInfo (uint32_t target_idx, Target *target, const char *prefix_cstr, bool show_stopped_process_status, Stream &strm)
60{
Greg Clayton52c8b6e2011-04-19 04:19:37 +000061 const ArchSpec &target_arch = target->GetArchitecture();
Greg Claytonabe0fed2011-04-18 08:33:37 +000062
Greg Clayton5beb99d2011-08-11 02:48:45 +000063 Module *exe_module = target->GetExecutableModulePointer();
Greg Claytonabe0fed2011-04-18 08:33:37 +000064 char exe_path[PATH_MAX];
65 bool exe_valid = false;
Greg Clayton5beb99d2011-08-11 02:48:45 +000066 if (exe_module)
67 exe_valid = exe_module->GetFileSpec().GetPath (exe_path, sizeof(exe_path));
Greg Claytonabe0fed2011-04-18 08:33:37 +000068
69 if (!exe_valid)
70 ::strcpy (exe_path, "<none>");
71
72 strm.Printf ("%starget #%u: %s", prefix_cstr ? prefix_cstr : "", target_idx, exe_path);
73
74 uint32_t properties = 0;
75 if (target_arch.IsValid())
76 {
77 strm.Printf ("%sarch=%s", properties++ > 0 ? ", " : " ( ", target_arch.GetTriple().str().c_str());
78 properties++;
79 }
80 PlatformSP platform_sp (target->GetPlatform());
81 if (platform_sp)
82 strm.Printf ("%splatform=%s", properties++ > 0 ? ", " : " ( ", platform_sp->GetName());
83
84 ProcessSP process_sp (target->GetProcessSP());
85 bool show_process_status = false;
86 if (process_sp)
87 {
88 lldb::pid_t pid = process_sp->GetID();
89 StateType state = process_sp->GetState();
90 if (show_stopped_process_status)
Greg Clayton20206082011-11-17 01:23:07 +000091 show_process_status = StateIsStoppedState(state, true);
Greg Claytonabe0fed2011-04-18 08:33:37 +000092 const char *state_cstr = StateAsCString (state);
93 if (pid != LLDB_INVALID_PROCESS_ID)
Daniel Malea5f35a4b2012-11-29 21:49:15 +000094 strm.Printf ("%spid=%" PRIu64, properties++ > 0 ? ", " : " ( ", pid);
Greg Claytonabe0fed2011-04-18 08:33:37 +000095 strm.Printf ("%sstate=%s", properties++ > 0 ? ", " : " ( ", state_cstr);
96 }
97 if (properties > 0)
98 strm.PutCString (" )\n");
99 else
100 strm.EOL();
101 if (show_process_status)
102 {
103 const bool only_threads_with_stop_reason = true;
104 const uint32_t start_frame = 0;
105 const uint32_t num_frames = 1;
106 const uint32_t num_frames_with_source = 1;
107 process_sp->GetStatus (strm);
108 process_sp->GetThreadStatus (strm,
109 only_threads_with_stop_reason,
110 start_frame,
111 num_frames,
112 num_frames_with_source);
113
114 }
115}
116
117static uint32_t
118DumpTargetList (TargetList &target_list, bool show_stopped_process_status, Stream &strm)
119{
120 const uint32_t num_targets = target_list.GetNumTargets();
121 if (num_targets)
122 {
123 TargetSP selected_target_sp (target_list.GetSelectedTarget());
124 strm.PutCString ("Current targets:\n");
125 for (uint32_t i=0; i<num_targets; ++i)
126 {
127 TargetSP target_sp (target_list.GetTargetAtIndex (i));
128 if (target_sp)
129 {
130 bool is_selected = target_sp.get() == selected_target_sp.get();
131 DumpTargetInfo (i,
132 target_sp.get(),
133 is_selected ? "* " : " ",
134 show_stopped_process_status,
135 strm);
136 }
137 }
138 }
139 return num_targets;
140}
141#pragma mark CommandObjectTargetCreate
142
143//-------------------------------------------------------------------------
144// "target create"
145//-------------------------------------------------------------------------
146
Jim Inghamda26bd22012-06-08 21:56:10 +0000147class CommandObjectTargetCreate : public CommandObjectParsed
Greg Claytonabe0fed2011-04-18 08:33:37 +0000148{
149public:
150 CommandObjectTargetCreate(CommandInterpreter &interpreter) :
Jim Inghamda26bd22012-06-08 21:56:10 +0000151 CommandObjectParsed (interpreter,
152 "target create",
153 "Create a target using the argument as the main executable.",
154 NULL),
Greg Claytonabe0fed2011-04-18 08:33:37 +0000155 m_option_group (interpreter),
Greg Clayton801417e2011-07-07 01:59:51 +0000156 m_arch_option (),
Greg Clayton46c9a352012-02-09 06:16:32 +0000157 m_platform_options(true), // Do include the "--platform" option in the platform settings by passing true
Greg Claytonec9c2d22012-11-30 19:05:35 +0000158 m_core_file (LLDB_OPT_SET_1, false, "core", 'c', 0, eArgTypeFilename, "Fullpath to a core file to use for this target."),
159 m_symbol_file (LLDB_OPT_SET_1, false, "symfile", 's', 0, eArgTypeFilename, "Fullpath to a stand alone debug symbols file for when debug symbols are not in the executable."),
160 m_add_dependents (LLDB_OPT_SET_1, false, "no-dependents", 'd', "Don't load dependent files when creating the target, just add the specified executable.", true, true)
Greg Claytonabe0fed2011-04-18 08:33:37 +0000161 {
162 CommandArgumentEntry arg;
163 CommandArgumentData file_arg;
164
165 // Define the first (and only) variant of this arg.
166 file_arg.arg_type = eArgTypeFilename;
167 file_arg.arg_repetition = eArgRepeatPlain;
168
169 // There is only one variant this argument could be; put it into the argument entry.
170 arg.push_back (file_arg);
171
172 // Push the data for the first argument into the m_arguments vector.
173 m_arguments.push_back (arg);
174
Greg Clayton801417e2011-07-07 01:59:51 +0000175 m_option_group.Append (&m_arch_option, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
Greg Claytonabe0fed2011-04-18 08:33:37 +0000176 m_option_group.Append (&m_platform_options, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
Greg Clayton46c9a352012-02-09 06:16:32 +0000177 m_option_group.Append (&m_core_file, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
Greg Claytonec9c2d22012-11-30 19:05:35 +0000178 m_option_group.Append (&m_symbol_file, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
179 m_option_group.Append (&m_add_dependents, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
Greg Claytonabe0fed2011-04-18 08:33:37 +0000180 m_option_group.Finalize();
181 }
182
183 ~CommandObjectTargetCreate ()
184 {
185 }
186
187 Options *
188 GetOptions ()
189 {
190 return &m_option_group;
191 }
192
Jim Inghamda26bd22012-06-08 21:56:10 +0000193 int
194 HandleArgumentCompletion (Args &input,
195 int &cursor_index,
196 int &cursor_char_position,
197 OptionElementVector &opt_element_vector,
198 int match_start_point,
199 int max_return_elements,
200 bool &word_complete,
201 StringList &matches)
202 {
203 std::string completion_str (input.GetArgumentAtIndex(cursor_index));
204 completion_str.erase (cursor_char_position);
205
206 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
207 CommandCompletions::eDiskFileCompletion,
208 completion_str.c_str(),
209 match_start_point,
210 max_return_elements,
211 NULL,
212 word_complete,
213 matches);
214 return matches.GetSize();
215 }
216
217protected:
Greg Claytonabe0fed2011-04-18 08:33:37 +0000218 bool
Jim Inghamda26bd22012-06-08 21:56:10 +0000219 DoExecute (Args& command, CommandReturnObject &result)
Greg Claytonabe0fed2011-04-18 08:33:37 +0000220 {
221 const int argc = command.GetArgumentCount();
Greg Clayton46c9a352012-02-09 06:16:32 +0000222 FileSpec core_file (m_core_file.GetOptionValue().GetCurrentValue());
223
224 if (argc == 1 || core_file)
Greg Claytonabe0fed2011-04-18 08:33:37 +0000225 {
Greg Claytonec9c2d22012-11-30 19:05:35 +0000226 FileSpec symfile (m_symbol_file.GetOptionValue().GetCurrentValue());
227 if (symfile)
228 {
229 if (!symfile.Exists())
230 {
231 char symfile_path[PATH_MAX];
232 symfile.GetPath(symfile_path, sizeof(symfile_path));
233 result.AppendErrorWithFormat("invalid symbol file path '%s'", symfile_path);
234 result.SetStatus (eReturnStatusFailed);
235 return false;
236 }
237 }
238
Greg Claytonabe0fed2011-04-18 08:33:37 +0000239 const char *file_path = command.GetArgumentAtIndex(0);
240 Timer scoped_timer(__PRETTY_FUNCTION__, "(lldb) target create '%s'", file_path);
Greg Claytonabe0fed2011-04-18 08:33:37 +0000241 TargetSP target_sp;
242 Debugger &debugger = m_interpreter.GetDebugger();
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000243 const char *arch_cstr = m_arch_option.GetArchitectureName();
Greg Claytonec9c2d22012-11-30 19:05:35 +0000244 const bool get_dependent_files = m_add_dependents.GetOptionValue().GetCurrentValue();
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000245 Error error (debugger.GetTargetList().CreateTarget (debugger,
Greg Claytoned0a0fb2012-10-18 16:33:33 +0000246 file_path,
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000247 arch_cstr,
248 get_dependent_files,
249 &m_platform_options,
250 target_sp));
251
Greg Claytonabe0fed2011-04-18 08:33:37 +0000252 if (target_sp)
253 {
Greg Claytonec9c2d22012-11-30 19:05:35 +0000254 if (symfile)
255 {
256 ModuleSP module_sp (target_sp->GetExecutableModule());
257 if (module_sp)
258 module_sp->SetSymbolFileFileSpec(symfile);
259 }
260
Greg Claytonabe0fed2011-04-18 08:33:37 +0000261 debugger.GetTargetList().SetSelectedTarget(target_sp.get());
Greg Clayton46c9a352012-02-09 06:16:32 +0000262 if (core_file)
263 {
Greg Clayton46c9a352012-02-09 06:16:32 +0000264 char core_path[PATH_MAX];
265 core_file.GetPath(core_path, sizeof(core_path));
Greg Clayton9ce95382012-02-13 23:10:39 +0000266 if (core_file.Exists())
Greg Clayton46c9a352012-02-09 06:16:32 +0000267 {
Greg Clayton9ce95382012-02-13 23:10:39 +0000268 FileSpec core_file_dir;
269 core_file_dir.GetDirectory() = core_file.GetDirectory();
270 target_sp->GetExecutableSearchPaths ().Append (core_file_dir);
Greg Clayton46c9a352012-02-09 06:16:32 +0000271
Greg Clayton9ce95382012-02-13 23:10:39 +0000272 ProcessSP process_sp (target_sp->CreateProcess (m_interpreter.GetDebugger().GetListener(), NULL, &core_file));
273
274 if (process_sp)
Greg Clayton46c9a352012-02-09 06:16:32 +0000275 {
Greg Clayton9ce95382012-02-13 23:10:39 +0000276 // Seems wierd that we Launch a core file, but that is
277 // what we do!
278 error = process_sp->LoadCore();
279
280 if (error.Fail())
281 {
282 result.AppendError(error.AsCString("can't find plug-in for core file"));
283 result.SetStatus (eReturnStatusFailed);
284 return false;
285 }
286 else
287 {
288 result.AppendMessageWithFormat ("Core file '%s' (%s) was loaded.\n", core_path, target_sp->GetArchitecture().GetArchitectureName());
289 result.SetStatus (eReturnStatusSuccessFinishNoResult);
290 }
Greg Clayton46c9a352012-02-09 06:16:32 +0000291 }
292 else
293 {
Greg Clayton9ce95382012-02-13 23:10:39 +0000294 result.AppendErrorWithFormat ("Unable to find process plug-in for core file '%s'\n", core_path);
295 result.SetStatus (eReturnStatusFailed);
Greg Clayton46c9a352012-02-09 06:16:32 +0000296 }
297 }
298 else
299 {
Greg Clayton9ce95382012-02-13 23:10:39 +0000300 result.AppendErrorWithFormat ("Core file '%s' does not exist\n", core_path);
Greg Clayton46c9a352012-02-09 06:16:32 +0000301 result.SetStatus (eReturnStatusFailed);
302 }
303 }
304 else
305 {
306 result.AppendMessageWithFormat ("Current executable set to '%s' (%s).\n", file_path, target_sp->GetArchitecture().GetArchitectureName());
307 result.SetStatus (eReturnStatusSuccessFinishNoResult);
308 }
Greg Claytonabe0fed2011-04-18 08:33:37 +0000309 }
310 else
311 {
312 result.AppendError(error.AsCString());
313 result.SetStatus (eReturnStatusFailed);
314 }
315 }
316 else
317 {
Greg Clayton46c9a352012-02-09 06:16:32 +0000318 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 +0000319 result.SetStatus (eReturnStatusFailed);
320 }
321 return result.Succeeded();
322
323 }
324
Greg Claytonabe0fed2011-04-18 08:33:37 +0000325private:
326 OptionGroupOptions m_option_group;
Greg Clayton801417e2011-07-07 01:59:51 +0000327 OptionGroupArchitecture m_arch_option;
Greg Claytonabe0fed2011-04-18 08:33:37 +0000328 OptionGroupPlatform m_platform_options;
Greg Clayton46c9a352012-02-09 06:16:32 +0000329 OptionGroupFile m_core_file;
Greg Claytonec9c2d22012-11-30 19:05:35 +0000330 OptionGroupFile m_symbol_file;
331 OptionGroupBoolean m_add_dependents;
Greg Claytonabe0fed2011-04-18 08:33:37 +0000332};
333
334#pragma mark CommandObjectTargetList
335
336//----------------------------------------------------------------------
337// "target list"
338//----------------------------------------------------------------------
339
Jim Inghamda26bd22012-06-08 21:56:10 +0000340class CommandObjectTargetList : public CommandObjectParsed
Greg Claytonabe0fed2011-04-18 08:33:37 +0000341{
342public:
343 CommandObjectTargetList (CommandInterpreter &interpreter) :
Jim Inghamda26bd22012-06-08 21:56:10 +0000344 CommandObjectParsed (interpreter,
345 "target list",
346 "List all current targets in the current debug session.",
347 NULL,
348 0)
Greg Claytonabe0fed2011-04-18 08:33:37 +0000349 {
350 }
351
352 virtual
353 ~CommandObjectTargetList ()
354 {
355 }
356
Jim Inghamda26bd22012-06-08 21:56:10 +0000357protected:
Greg Claytonabe0fed2011-04-18 08:33:37 +0000358 virtual bool
Jim Inghamda26bd22012-06-08 21:56:10 +0000359 DoExecute (Args& args, CommandReturnObject &result)
Greg Claytonabe0fed2011-04-18 08:33:37 +0000360 {
361 if (args.GetArgumentCount() == 0)
362 {
363 Stream &strm = result.GetOutputStream();
364
365 bool show_stopped_process_status = false;
366 if (DumpTargetList (m_interpreter.GetDebugger().GetTargetList(), show_stopped_process_status, strm) == 0)
367 {
368 strm.PutCString ("No targets.\n");
369 }
Johnny Chen44dc9d32011-04-18 21:08:05 +0000370 result.SetStatus (eReturnStatusSuccessFinishResult);
Greg Claytonabe0fed2011-04-18 08:33:37 +0000371 }
372 else
373 {
374 result.AppendError ("the 'target list' command takes no arguments\n");
375 result.SetStatus (eReturnStatusFailed);
376 }
377 return result.Succeeded();
378 }
379};
380
381
382#pragma mark CommandObjectTargetSelect
383
384//----------------------------------------------------------------------
385// "target select"
386//----------------------------------------------------------------------
387
Jim Inghamda26bd22012-06-08 21:56:10 +0000388class CommandObjectTargetSelect : public CommandObjectParsed
Greg Claytonabe0fed2011-04-18 08:33:37 +0000389{
390public:
391 CommandObjectTargetSelect (CommandInterpreter &interpreter) :
Jim Inghamda26bd22012-06-08 21:56:10 +0000392 CommandObjectParsed (interpreter,
393 "target select",
394 "Select a target as the current target by target index.",
395 NULL,
396 0)
Greg Claytonabe0fed2011-04-18 08:33:37 +0000397 {
398 }
399
400 virtual
401 ~CommandObjectTargetSelect ()
402 {
403 }
404
Jim Inghamda26bd22012-06-08 21:56:10 +0000405protected:
Greg Claytonabe0fed2011-04-18 08:33:37 +0000406 virtual bool
Jim Inghamda26bd22012-06-08 21:56:10 +0000407 DoExecute (Args& args, CommandReturnObject &result)
Greg Claytonabe0fed2011-04-18 08:33:37 +0000408 {
409 if (args.GetArgumentCount() == 1)
410 {
411 bool success = false;
412 const char *target_idx_arg = args.GetArgumentAtIndex(0);
413 uint32_t target_idx = Args::StringToUInt32 (target_idx_arg, UINT32_MAX, 0, &success);
414 if (success)
415 {
416 TargetList &target_list = m_interpreter.GetDebugger().GetTargetList();
417 const uint32_t num_targets = target_list.GetNumTargets();
418 if (target_idx < num_targets)
419 {
420 TargetSP target_sp (target_list.GetTargetAtIndex (target_idx));
421 if (target_sp)
422 {
423 Stream &strm = result.GetOutputStream();
424 target_list.SetSelectedTarget (target_sp.get());
425 bool show_stopped_process_status = false;
426 DumpTargetList (target_list, show_stopped_process_status, strm);
Johnny Chen44dc9d32011-04-18 21:08:05 +0000427 result.SetStatus (eReturnStatusSuccessFinishResult);
Greg Claytonabe0fed2011-04-18 08:33:37 +0000428 }
429 else
430 {
431 result.AppendErrorWithFormat ("target #%u is NULL in target list\n", target_idx);
432 result.SetStatus (eReturnStatusFailed);
433 }
434 }
435 else
436 {
437 result.AppendErrorWithFormat ("index %u is out of range, valid target indexes are 0 - %u\n",
438 target_idx,
439 num_targets - 1);
440 result.SetStatus (eReturnStatusFailed);
441 }
442 }
443 else
444 {
445 result.AppendErrorWithFormat("invalid index string value '%s'\n", target_idx_arg);
446 result.SetStatus (eReturnStatusFailed);
447 }
448 }
449 else
450 {
451 result.AppendError ("'target select' takes a single argument: a target index\n");
452 result.SetStatus (eReturnStatusFailed);
453 }
454 return result.Succeeded();
455 }
456};
457
Greg Clayton153ccd72011-08-10 02:10:13 +0000458#pragma mark CommandObjectTargetSelect
459
460//----------------------------------------------------------------------
461// "target delete"
462//----------------------------------------------------------------------
463
Jim Inghamda26bd22012-06-08 21:56:10 +0000464class CommandObjectTargetDelete : public CommandObjectParsed
Greg Clayton153ccd72011-08-10 02:10:13 +0000465{
466public:
467 CommandObjectTargetDelete (CommandInterpreter &interpreter) :
Jim Inghamda26bd22012-06-08 21:56:10 +0000468 CommandObjectParsed (interpreter,
469 "target delete",
470 "Delete one or more targets by target index.",
471 NULL,
472 0),
Greg Clayton5beb99d2011-08-11 02:48:45 +0000473 m_option_group (interpreter),
Greg Clayton437b5bc2012-09-27 22:26:11 +0000474 m_cleanup_option (LLDB_OPT_SET_1, false, "clean", 'c', "Perform extra cleanup to minimize memory consumption after deleting the target.", false, false)
Greg Clayton153ccd72011-08-10 02:10:13 +0000475 {
Greg Clayton5beb99d2011-08-11 02:48:45 +0000476 m_option_group.Append (&m_cleanup_option, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
477 m_option_group.Finalize();
Greg Clayton153ccd72011-08-10 02:10:13 +0000478 }
479
480 virtual
481 ~CommandObjectTargetDelete ()
482 {
483 }
484
Jim Inghamda26bd22012-06-08 21:56:10 +0000485 Options *
486 GetOptions ()
487 {
488 return &m_option_group;
489 }
490
491protected:
Greg Clayton153ccd72011-08-10 02:10:13 +0000492 virtual bool
Jim Inghamda26bd22012-06-08 21:56:10 +0000493 DoExecute (Args& args, CommandReturnObject &result)
Greg Clayton153ccd72011-08-10 02:10:13 +0000494 {
495 const size_t argc = args.GetArgumentCount();
496 std::vector<TargetSP> delete_target_list;
497 TargetList &target_list = m_interpreter.GetDebugger().GetTargetList();
498 bool success = true;
499 TargetSP target_sp;
500 if (argc > 0)
501 {
502 const uint32_t num_targets = target_list.GetNumTargets();
Filipe Cabecinhasaa3d89e2012-07-09 13:02:17 +0000503 // Bail out if don't have any targets.
504 if (num_targets == 0) {
505 result.AppendError("no targets to delete");
506 result.SetStatus(eReturnStatusFailed);
507 success = false;
508 }
509
Greg Clayton153ccd72011-08-10 02:10:13 +0000510 for (uint32_t arg_idx = 0; success && arg_idx < argc; ++arg_idx)
511 {
512 const char *target_idx_arg = args.GetArgumentAtIndex(arg_idx);
513 uint32_t target_idx = Args::StringToUInt32 (target_idx_arg, UINT32_MAX, 0, &success);
514 if (success)
515 {
516 if (target_idx < num_targets)
517 {
518 target_sp = target_list.GetTargetAtIndex (target_idx);
519 if (target_sp)
520 {
521 delete_target_list.push_back (target_sp);
522 continue;
523 }
524 }
Filipe Cabecinhasaa3d89e2012-07-09 13:02:17 +0000525 if (num_targets > 1)
526 result.AppendErrorWithFormat ("target index %u is out of range, valid target indexes are 0 - %u\n",
527 target_idx,
528 num_targets - 1);
529 else
530 result.AppendErrorWithFormat("target index %u is out of range, the only valid index is 0\n",
531 target_idx);
532
Greg Clayton153ccd72011-08-10 02:10:13 +0000533 result.SetStatus (eReturnStatusFailed);
534 success = false;
535 }
536 else
537 {
538 result.AppendErrorWithFormat("invalid target index '%s'\n", target_idx_arg);
539 result.SetStatus (eReturnStatusFailed);
540 success = false;
541 }
542 }
543
544 }
545 else
546 {
547 target_sp = target_list.GetSelectedTarget();
548 if (target_sp)
549 {
550 delete_target_list.push_back (target_sp);
551 }
552 else
553 {
554 result.AppendErrorWithFormat("no target is currently selected\n");
555 result.SetStatus (eReturnStatusFailed);
556 success = false;
557 }
558 }
559 if (success)
560 {
561 const size_t num_targets_to_delete = delete_target_list.size();
562 for (size_t idx = 0; idx < num_targets_to_delete; ++idx)
563 {
564 target_sp = delete_target_list[idx];
565 target_list.DeleteTarget(target_sp);
566 target_sp->Destroy();
567 }
Greg Clayton5beb99d2011-08-11 02:48:45 +0000568 // If "--clean" was specified, prune any orphaned shared modules from
569 // the global shared module list
570 if (m_cleanup_option.GetOptionValue ())
571 {
Greg Clayton860b9ea2012-04-09 20:22:01 +0000572 const bool mandatory = true;
573 ModuleList::RemoveOrphanSharedModules(mandatory);
Greg Clayton5beb99d2011-08-11 02:48:45 +0000574 }
Greg Clayton153ccd72011-08-10 02:10:13 +0000575 result.GetOutputStream().Printf("%u targets deleted.\n", (uint32_t)num_targets_to_delete);
576 result.SetStatus(eReturnStatusSuccessFinishResult);
577 }
578
579 return result.Succeeded();
580 }
Greg Clayton5beb99d2011-08-11 02:48:45 +0000581
Greg Clayton5beb99d2011-08-11 02:48:45 +0000582 OptionGroupOptions m_option_group;
583 OptionGroupBoolean m_cleanup_option;
Greg Clayton153ccd72011-08-10 02:10:13 +0000584};
585
Greg Claytonabe0fed2011-04-18 08:33:37 +0000586
Greg Clayton801417e2011-07-07 01:59:51 +0000587#pragma mark CommandObjectTargetVariable
588
589//----------------------------------------------------------------------
590// "target variable"
591//----------------------------------------------------------------------
592
Jim Inghamda26bd22012-06-08 21:56:10 +0000593class CommandObjectTargetVariable : public CommandObjectParsed
Greg Clayton801417e2011-07-07 01:59:51 +0000594{
595public:
596 CommandObjectTargetVariable (CommandInterpreter &interpreter) :
Jim Inghamda26bd22012-06-08 21:56:10 +0000597 CommandObjectParsed (interpreter,
598 "target variable",
Greg Claytonf72bd8b2012-11-03 00:10:22 +0000599 "Read global variable(s) prior to, or while running your binary.",
Jim Inghamda26bd22012-06-08 21:56:10 +0000600 NULL,
601 0),
Greg Clayton801417e2011-07-07 01:59:51 +0000602 m_option_group (interpreter),
Greg Clayton368f8222011-07-07 04:38:25 +0000603 m_option_variable (false), // Don't include frame options
Greg Claytona42880a2011-10-25 06:44:01 +0000604 m_option_format (eFormatDefault),
Greg Clayton6475c422012-12-04 00:32:51 +0000605 m_option_compile_units (LLDB_OPT_SET_1, false, "file", 'file', 0, eArgTypeFilename, "A basename or fullpath to a file that contains global variables. This option can be specified multiple times."),
606 m_option_shared_libraries (LLDB_OPT_SET_1, false, "shlib",'shlb', 0, eArgTypeFilename, "A basename or fullpath to a shared library to use in the search for global variables. This option can be specified multiple times."),
Greg Clayton801417e2011-07-07 01:59:51 +0000607 m_varobj_options()
608 {
Johnny Chen24b81e32011-08-22 22:22:00 +0000609 CommandArgumentEntry arg;
610 CommandArgumentData var_name_arg;
611
612 // Define the first (and only) variant of this arg.
613 var_name_arg.arg_type = eArgTypeVarName;
614 var_name_arg.arg_repetition = eArgRepeatPlus;
615
616 // There is only one variant this argument could be; put it into the argument entry.
617 arg.push_back (var_name_arg);
618
619 // Push the data for the first argument into the m_arguments vector.
620 m_arguments.push_back (arg);
621
Greg Clayton801417e2011-07-07 01:59:51 +0000622 m_option_group.Append (&m_varobj_options, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
Greg Clayton368f8222011-07-07 04:38:25 +0000623 m_option_group.Append (&m_option_variable, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
Greg Clayton24a6bd92011-10-27 17:55:14 +0000624 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 +0000625 m_option_group.Append (&m_option_compile_units, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
626 m_option_group.Append (&m_option_shared_libraries, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
627 m_option_group.Finalize();
628 }
629
630 virtual
631 ~CommandObjectTargetVariable ()
632 {
633 }
Greg Clayton5d81f492011-07-08 21:46:14 +0000634
635 void
636 DumpValueObject (Stream &s, VariableSP &var_sp, ValueObjectSP &valobj_sp, const char *root_name)
637 {
Enrico Granata19030d82011-08-15 18:01:31 +0000638 ValueObject::DumpValueObjectOptions options;
639
Enrico Granata3069c622012-03-01 04:24:26 +0000640 options.SetMaximumPointerDepth(m_varobj_options.ptr_depth)
Enrico Granata19030d82011-08-15 18:01:31 +0000641 .SetMaximumDepth(m_varobj_options.max_depth)
642 .SetShowTypes(m_varobj_options.show_types)
643 .SetShowLocation(m_varobj_options.show_location)
644 .SetUseObjectiveC(m_varobj_options.use_objc)
645 .SetUseDynamicType(m_varobj_options.use_dynamic)
Enrico Granatacf09f882012-03-19 22:58:49 +0000646 .SetUseSyntheticValue(m_varobj_options.use_synth)
Enrico Granata19030d82011-08-15 18:01:31 +0000647 .SetFlatOutput(m_varobj_options.flat_output)
648 .SetOmitSummaryDepth(m_varobj_options.no_summary_depth)
649 .SetIgnoreCap(m_varobj_options.ignore_cap);
650
Greg Clayton5d81f492011-07-08 21:46:14 +0000651 switch (var_sp->GetScope())
652 {
653 case eValueTypeVariableGlobal:
654 if (m_option_variable.show_scope)
655 s.PutCString("GLOBAL: ");
656 break;
657
658 case eValueTypeVariableStatic:
659 if (m_option_variable.show_scope)
660 s.PutCString("STATIC: ");
661 break;
662
663 case eValueTypeVariableArgument:
664 if (m_option_variable.show_scope)
665 s.PutCString(" ARG: ");
666 break;
667
668 case eValueTypeVariableLocal:
669 if (m_option_variable.show_scope)
670 s.PutCString(" LOCAL: ");
671 break;
672
673 default:
674 break;
675 }
676
Greg Claytonfb816422011-07-10 19:21:23 +0000677 if (m_option_variable.show_decl)
Greg Clayton5d81f492011-07-08 21:46:14 +0000678 {
Greg Claytonfb816422011-07-10 19:21:23 +0000679 bool show_fullpaths = false;
680 bool show_module = true;
681 if (var_sp->DumpDeclaration(&s, show_fullpaths, show_module))
682 s.PutCString (": ");
Greg Clayton5d81f492011-07-08 21:46:14 +0000683 }
684
Greg Claytona42880a2011-10-25 06:44:01 +0000685 const Format format = m_option_format.GetFormat();
Greg Clayton5d81f492011-07-08 21:46:14 +0000686 if (format != eFormatDefault)
Enrico Granata3069c622012-03-01 04:24:26 +0000687 options.SetFormat(format);
688
689 options.SetRootValueObjectName(root_name);
Greg Clayton5d81f492011-07-08 21:46:14 +0000690
691 ValueObject::DumpValueObject (s,
692 valobj_sp.get(),
Enrico Granata3069c622012-03-01 04:24:26 +0000693 options);
Greg Clayton5d81f492011-07-08 21:46:14 +0000694
695 }
Greg Clayton801417e2011-07-07 01:59:51 +0000696
Greg Clayton5d81f492011-07-08 21:46:14 +0000697
698 static uint32_t GetVariableCallback (void *baton,
699 const char *name,
700 VariableList &variable_list)
701 {
702 Target *target = static_cast<Target *>(baton);
703 if (target)
704 {
705 return target->GetImages().FindGlobalVariables (ConstString(name),
706 true,
707 UINT32_MAX,
708 variable_list);
709 }
710 return 0;
711 }
712
713
714
Jim Inghamda26bd22012-06-08 21:56:10 +0000715 Options *
716 GetOptions ()
717 {
718 return &m_option_group;
719 }
720
721protected:
Greg Clayton6475c422012-12-04 00:32:51 +0000722
723 void
724 DumpGlobalVariableList(const ExecutionContext &exe_ctx, const SymbolContext &sc, const VariableList &variable_list, Stream &s)
725 {
726 size_t count = variable_list.GetSize();
727 if (count > 0)
728 {
729 if (sc.module_sp)
730 {
731 if (sc.comp_unit)
732 {
733 s.Printf ("Global variables for %s/%s in %s/%s:\n",
734 sc.comp_unit->GetDirectory().GetCString(),
735 sc.comp_unit->GetFilename().GetCString(),
736 sc.module_sp->GetFileSpec().GetDirectory().GetCString(),
737 sc.module_sp->GetFileSpec().GetFilename().GetCString());
738 }
739 else
740 {
741 s.Printf ("Global variables for %s/%s\n",
742 sc.module_sp->GetFileSpec().GetDirectory().GetCString(),
743 sc.module_sp->GetFileSpec().GetFilename().GetCString());
744 }
745 }
746 else if (sc.comp_unit)
747 {
748 s.Printf ("Global variables for %s/%s\n",
749 sc.comp_unit->GetDirectory().GetCString(),
750 sc.comp_unit->GetFilename().GetCString());
751 }
752
753 for (uint32_t i=0; i<count; ++i)
754 {
755 VariableSP var_sp (variable_list.GetVariableAtIndex(i));
756 if (var_sp)
757 {
758 ValueObjectSP valobj_sp (ValueObjectVariable::Create (exe_ctx.GetBestExecutionContextScope(), var_sp));
759
760 if (valobj_sp)
761 DumpValueObject (s, var_sp, valobj_sp, var_sp->GetName().GetCString());
762 }
763 }
764 }
765
766 }
Greg Clayton801417e2011-07-07 01:59:51 +0000767 virtual bool
Jim Inghamda26bd22012-06-08 21:56:10 +0000768 DoExecute (Args& args, CommandReturnObject &result)
Greg Clayton801417e2011-07-07 01:59:51 +0000769 {
770 ExecutionContext exe_ctx (m_interpreter.GetExecutionContext());
Greg Clayton567e7f32011-09-22 04:58:26 +0000771 Target *target = exe_ctx.GetTargetPtr();
772 if (target)
Greg Clayton801417e2011-07-07 01:59:51 +0000773 {
774 const size_t argc = args.GetArgumentCount();
Greg Claytonfac93882011-10-05 22:17:32 +0000775 Stream &s = result.GetOutputStream();
Greg Clayton6475c422012-12-04 00:32:51 +0000776
Greg Clayton801417e2011-07-07 01:59:51 +0000777 if (argc > 0)
778 {
Greg Clayton5d81f492011-07-08 21:46:14 +0000779
Greg Clayton801417e2011-07-07 01:59:51 +0000780 for (size_t idx = 0; idx < argc; ++idx)
781 {
Greg Clayton5d81f492011-07-08 21:46:14 +0000782 VariableList variable_list;
783 ValueObjectList valobj_list;
784
Greg Clayton368f8222011-07-07 04:38:25 +0000785 const char *arg = args.GetArgumentAtIndex(idx);
786 uint32_t matches = 0;
Greg Claytonfb816422011-07-10 19:21:23 +0000787 bool use_var_name = false;
Greg Clayton368f8222011-07-07 04:38:25 +0000788 if (m_option_variable.use_regex)
Greg Clayton801417e2011-07-07 01:59:51 +0000789 {
Greg Clayton368f8222011-07-07 04:38:25 +0000790 RegularExpression regex(arg);
791 if (!regex.IsValid ())
792 {
793 result.GetErrorStream().Printf ("error: invalid regular expression: '%s'\n", arg);
794 result.SetStatus (eReturnStatusFailed);
795 return false;
796 }
Greg Claytonfb816422011-07-10 19:21:23 +0000797 use_var_name = true;
Greg Clayton567e7f32011-09-22 04:58:26 +0000798 matches = target->GetImages().FindGlobalVariables (regex,
799 true,
800 UINT32_MAX,
801 variable_list);
Greg Clayton801417e2011-07-07 01:59:51 +0000802 }
803 else
804 {
Greg Clayton5d81f492011-07-08 21:46:14 +0000805 Error error (Variable::GetValuesForVariableExpressionPath (arg,
Greg Clayton24b03102011-07-09 20:12:33 +0000806 exe_ctx.GetBestExecutionContextScope(),
Greg Clayton5d81f492011-07-08 21:46:14 +0000807 GetVariableCallback,
Greg Clayton567e7f32011-09-22 04:58:26 +0000808 target,
Greg Clayton5d81f492011-07-08 21:46:14 +0000809 variable_list,
810 valobj_list));
Greg Clayton5d81f492011-07-08 21:46:14 +0000811 matches = variable_list.GetSize();
Greg Clayton368f8222011-07-07 04:38:25 +0000812 }
813
814 if (matches == 0)
815 {
816 result.GetErrorStream().Printf ("error: can't find global variable '%s'\n", arg);
817 result.SetStatus (eReturnStatusFailed);
818 return false;
819 }
820 else
821 {
Greg Clayton801417e2011-07-07 01:59:51 +0000822 for (uint32_t global_idx=0; global_idx<matches; ++global_idx)
823 {
Greg Clayton5d81f492011-07-08 21:46:14 +0000824 VariableSP var_sp (variable_list.GetVariableAtIndex(global_idx));
Greg Clayton801417e2011-07-07 01:59:51 +0000825 if (var_sp)
826 {
Greg Clayton5d81f492011-07-08 21:46:14 +0000827 ValueObjectSP valobj_sp (valobj_list.GetValueObjectAtIndex(global_idx));
828 if (!valobj_sp)
Greg Claytonfb816422011-07-10 19:21:23 +0000829 valobj_sp = ValueObjectVariable::Create (exe_ctx.GetBestExecutionContextScope(), var_sp);
Greg Clayton801417e2011-07-07 01:59:51 +0000830
831 if (valobj_sp)
Greg Claytonb304a742011-10-13 18:31:02 +0000832 DumpValueObject (s, var_sp, valobj_sp, use_var_name ? var_sp->GetName().GetCString() : arg);
Greg Clayton801417e2011-07-07 01:59:51 +0000833 }
834 }
835 }
836 }
837 }
838 else
839 {
Greg Clayton6475c422012-12-04 00:32:51 +0000840 const FileSpecList &compile_units = m_option_compile_units.GetOptionValue().GetCurrentValue();
841 const FileSpecList &shlibs = m_option_shared_libraries.GetOptionValue().GetCurrentValue();
842 SymbolContextList sc_list;
843 const size_t num_compile_units = compile_units.GetSize();
844 const size_t num_shlibs = shlibs.GetSize();
845 if (num_compile_units == 0 && num_shlibs == 0)
Greg Claytonfac93882011-10-05 22:17:32 +0000846 {
Greg Clayton6475c422012-12-04 00:32:51 +0000847 bool success = false;
848 StackFrame *frame = exe_ctx.GetFramePtr();
849 CompileUnit *comp_unit = NULL;
850 if (frame)
Greg Claytonfac93882011-10-05 22:17:32 +0000851 {
Greg Clayton6475c422012-12-04 00:32:51 +0000852 SymbolContext sc = frame->GetSymbolContext (eSymbolContextCompUnit);
853 if (sc.comp_unit)
Greg Claytonfac93882011-10-05 22:17:32 +0000854 {
Greg Clayton6475c422012-12-04 00:32:51 +0000855 const bool can_create = true;
856 VariableListSP comp_unit_varlist_sp (sc.comp_unit->GetVariableList(can_create));
857 if (comp_unit_varlist_sp)
Greg Claytonfac93882011-10-05 22:17:32 +0000858 {
Greg Clayton6475c422012-12-04 00:32:51 +0000859 size_t count = comp_unit_varlist_sp->GetSize();
860 if (count > 0)
Greg Claytonfac93882011-10-05 22:17:32 +0000861 {
Greg Clayton6475c422012-12-04 00:32:51 +0000862 DumpGlobalVariableList(exe_ctx, sc, *comp_unit_varlist_sp, s);
863 success = true;
Greg Claytonfac93882011-10-05 22:17:32 +0000864 }
865 }
866 }
867 }
Greg Clayton6475c422012-12-04 00:32:51 +0000868 if (!success)
Greg Claytonfac93882011-10-05 22:17:32 +0000869 {
Greg Clayton6475c422012-12-04 00:32:51 +0000870 if (frame)
871 {
872 if (comp_unit)
873 result.AppendErrorWithFormat ("no global variables in current compile unit: %s/%s\n",
874 comp_unit->GetDirectory().GetCString(),
875 comp_unit->GetFilename().GetCString());
876 else
877 result.AppendError ("no debug information for frame %u\n", frame->GetFrameIndex());
878 }
Greg Claytonfac93882011-10-05 22:17:32 +0000879 else
Greg Clayton6475c422012-12-04 00:32:51 +0000880 result.AppendError ("'target variable' takes one or more global variable names as arguments\n");
881 result.SetStatus (eReturnStatusFailed);
882 }
883 }
884 else
885 {
886 SymbolContextList sc_list;
887 const bool append = true;
888 // We have one or more compile unit or shlib
889 if (num_shlibs > 0)
890 {
891 for (size_t shlib_idx=0; shlib_idx<num_shlibs; ++shlib_idx)
892 {
893 const FileSpec module_file(shlibs.GetFileSpecAtIndex(shlib_idx));
894 ModuleSpec module_spec (module_file);
895
896 ModuleSP module_sp (target->GetImages().FindFirstModule(module_spec));
897 if (module_sp)
898 {
899 if (num_compile_units > 0)
900 {
901 for (size_t cu_idx=0; cu_idx<num_compile_units; ++cu_idx)
902 module_sp->FindCompileUnits(compile_units.GetFileSpecAtIndex(cu_idx), append, sc_list);
903 }
904 else
905 {
906 SymbolContext sc;
907 sc.module_sp = module_sp;
908 sc_list.Append(sc);
909 }
910 }
911 else
912 {
913 // Didn't find matching shlib/module in target...
914 result.AppendErrorWithFormat ("target doesn't contain the specified shared library: %s%s%s\n",
915 module_file.GetDirectory().GetCString(),
916 module_file.GetDirectory() ? "/" : "",
917 module_file.GetFilename().GetCString());
918 }
919 }
920 }
Greg Claytonfac93882011-10-05 22:17:32 +0000921 else
Greg Clayton6475c422012-12-04 00:32:51 +0000922 {
923 // No shared libraries, we just want to find globals for the compile units files that were specified
924 for (size_t cu_idx=0; cu_idx<num_compile_units; ++cu_idx)
925 target->GetImages().FindCompileUnits(compile_units.GetFileSpecAtIndex(cu_idx), append, sc_list);
926 }
927
928 const uint32_t num_scs = sc_list.GetSize();
929 if (num_scs > 0)
930 {
931 SymbolContext sc;
932 for (uint32_t sc_idx=0; sc_idx<num_scs; ++sc_idx)
933 {
934 if (sc_list.GetContextAtIndex(sc_idx, sc))
935 {
936 if (sc.comp_unit)
937 {
938 const bool can_create = true;
939 VariableListSP comp_unit_varlist_sp (sc.comp_unit->GetVariableList(can_create));
940 if (comp_unit_varlist_sp)
941 DumpGlobalVariableList(exe_ctx, sc, *comp_unit_varlist_sp, s);
942 }
943 else if (sc.module_sp)
944 {
945 // Get all global variables for this module
946 lldb_private::RegularExpression all_globals_regex("."); // Any global with at least one character
947 VariableList variable_list;
948 sc.module_sp->FindGlobalVariables(all_globals_regex, append, UINT32_MAX, variable_list);
949 DumpGlobalVariableList(exe_ctx, sc, variable_list, s);
950 }
951 }
952 }
953 }
Greg Claytonfac93882011-10-05 22:17:32 +0000954 }
Greg Clayton801417e2011-07-07 01:59:51 +0000955 }
956 }
957 else
958 {
959 result.AppendError ("invalid target, create a debug target using the 'target create' command");
960 result.SetStatus (eReturnStatusFailed);
961 return false;
962 }
Enrico Granatadb64d952011-08-12 16:42:31 +0000963
964 if (m_interpreter.TruncationWarningNecessary())
965 {
966 result.GetOutputStream().Printf(m_interpreter.TruncationWarningText(),
967 m_cmd_name.c_str());
968 m_interpreter.TruncationWarningGiven();
969 }
970
Greg Clayton801417e2011-07-07 01:59:51 +0000971 return result.Succeeded();
972 }
973
Greg Clayton801417e2011-07-07 01:59:51 +0000974 OptionGroupOptions m_option_group;
Greg Clayton368f8222011-07-07 04:38:25 +0000975 OptionGroupVariable m_option_variable;
Greg Claytona42880a2011-10-25 06:44:01 +0000976 OptionGroupFormat m_option_format;
Greg Clayton801417e2011-07-07 01:59:51 +0000977 OptionGroupFileList m_option_compile_units;
978 OptionGroupFileList m_option_shared_libraries;
979 OptionGroupValueObjectDisplay m_varobj_options;
980
981};
982
983
Greg Claytone1f50b92011-05-03 22:09:39 +0000984#pragma mark CommandObjectTargetModulesSearchPathsAdd
Chris Lattner24943d22010-06-08 16:52:24 +0000985
Jim Inghamda26bd22012-06-08 21:56:10 +0000986class CommandObjectTargetModulesSearchPathsAdd : public CommandObjectParsed
Chris Lattner24943d22010-06-08 16:52:24 +0000987{
988public:
989
Greg Claytone1f50b92011-05-03 22:09:39 +0000990 CommandObjectTargetModulesSearchPathsAdd (CommandInterpreter &interpreter) :
Jim Inghamda26bd22012-06-08 21:56:10 +0000991 CommandObjectParsed (interpreter,
992 "target modules search-paths add",
993 "Add new image search paths substitution pairs to the current target.",
994 NULL)
Chris Lattner24943d22010-06-08 16:52:24 +0000995 {
Caroline Tice43b014a2010-10-04 22:28:36 +0000996 CommandArgumentEntry arg;
997 CommandArgumentData old_prefix_arg;
998 CommandArgumentData new_prefix_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 first argument position for m_arguments...
1011
1012 arg.push_back (old_prefix_arg);
1013 arg.push_back (new_prefix_arg);
1014
1015 m_arguments.push_back (arg);
Chris Lattner24943d22010-06-08 16:52:24 +00001016 }
1017
Greg Claytone1f50b92011-05-03 22:09:39 +00001018 ~CommandObjectTargetModulesSearchPathsAdd ()
Chris Lattner24943d22010-06-08 16:52:24 +00001019 {
1020 }
1021
Jim Inghamda26bd22012-06-08 21:56:10 +00001022protected:
Chris Lattner24943d22010-06-08 16:52:24 +00001023 bool
Jim Inghamda26bd22012-06-08 21:56:10 +00001024 DoExecute (Args& command,
Chris Lattner24943d22010-06-08 16:52:24 +00001025 CommandReturnObject &result)
1026 {
Greg Clayton238c0a12010-09-18 01:14:36 +00001027 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Chris Lattner24943d22010-06-08 16:52:24 +00001028 if (target)
1029 {
1030 uint32_t argc = command.GetArgumentCount();
1031 if (argc & 1)
1032 {
Greg Claytonabe0fed2011-04-18 08:33:37 +00001033 result.AppendError ("add requires an even number of arguments\n");
Chris Lattner24943d22010-06-08 16:52:24 +00001034 result.SetStatus (eReturnStatusFailed);
1035 }
1036 else
1037 {
1038 for (uint32_t i=0; i<argc; i+=2)
1039 {
1040 const char *from = command.GetArgumentAtIndex(i);
1041 const char *to = command.GetArgumentAtIndex(i+1);
1042
1043 if (from[0] && to[0])
1044 {
1045 bool last_pair = ((argc - i) == 2);
Greg Clayton63094e02010-06-23 01:19:29 +00001046 target->GetImageSearchPathList().Append (ConstString(from),
1047 ConstString(to),
1048 last_pair); // Notify if this is the last pair
Johnny Chen4d661352011-02-03 00:30:19 +00001049 result.SetStatus (eReturnStatusSuccessFinishNoResult);
Chris Lattner24943d22010-06-08 16:52:24 +00001050 }
1051 else
1052 {
1053 if (from[0])
Greg Claytonabe0fed2011-04-18 08:33:37 +00001054 result.AppendError ("<path-prefix> can't be empty\n");
Chris Lattner24943d22010-06-08 16:52:24 +00001055 else
Greg Claytonabe0fed2011-04-18 08:33:37 +00001056 result.AppendError ("<new-path-prefix> can't be empty\n");
Chris Lattner24943d22010-06-08 16:52:24 +00001057 result.SetStatus (eReturnStatusFailed);
1058 }
1059 }
1060 }
1061 }
1062 else
1063 {
Greg Claytonabe0fed2011-04-18 08:33:37 +00001064 result.AppendError ("invalid target\n");
Chris Lattner24943d22010-06-08 16:52:24 +00001065 result.SetStatus (eReturnStatusFailed);
1066 }
1067 return result.Succeeded();
1068 }
1069};
1070
Greg Claytone1f50b92011-05-03 22:09:39 +00001071#pragma mark CommandObjectTargetModulesSearchPathsClear
1072
Jim Inghamda26bd22012-06-08 21:56:10 +00001073class CommandObjectTargetModulesSearchPathsClear : public CommandObjectParsed
Chris Lattner24943d22010-06-08 16:52:24 +00001074{
1075public:
1076
Greg Claytone1f50b92011-05-03 22:09:39 +00001077 CommandObjectTargetModulesSearchPathsClear (CommandInterpreter &interpreter) :
Jim Inghamda26bd22012-06-08 21:56:10 +00001078 CommandObjectParsed (interpreter,
1079 "target modules search-paths clear",
1080 "Clear all current image search path substitution pairs from the current target.",
1081 "target modules search-paths clear")
Chris Lattner24943d22010-06-08 16:52:24 +00001082 {
1083 }
1084
Greg Claytone1f50b92011-05-03 22:09:39 +00001085 ~CommandObjectTargetModulesSearchPathsClear ()
Chris Lattner24943d22010-06-08 16:52:24 +00001086 {
1087 }
1088
Jim Inghamda26bd22012-06-08 21:56:10 +00001089protected:
Chris Lattner24943d22010-06-08 16:52:24 +00001090 bool
Jim Inghamda26bd22012-06-08 21:56:10 +00001091 DoExecute (Args& command,
Chris Lattner24943d22010-06-08 16:52:24 +00001092 CommandReturnObject &result)
1093 {
Greg Clayton238c0a12010-09-18 01:14:36 +00001094 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Chris Lattner24943d22010-06-08 16:52:24 +00001095 if (target)
1096 {
1097 bool notify = true;
1098 target->GetImageSearchPathList().Clear(notify);
Johnny Chen4d661352011-02-03 00:30:19 +00001099 result.SetStatus (eReturnStatusSuccessFinishNoResult);
Chris Lattner24943d22010-06-08 16:52:24 +00001100 }
1101 else
1102 {
Greg Claytonabe0fed2011-04-18 08:33:37 +00001103 result.AppendError ("invalid target\n");
Chris Lattner24943d22010-06-08 16:52:24 +00001104 result.SetStatus (eReturnStatusFailed);
1105 }
1106 return result.Succeeded();
1107 }
1108};
1109
Greg Claytone1f50b92011-05-03 22:09:39 +00001110#pragma mark CommandObjectTargetModulesSearchPathsInsert
1111
Jim Inghamda26bd22012-06-08 21:56:10 +00001112class CommandObjectTargetModulesSearchPathsInsert : public CommandObjectParsed
Chris Lattner24943d22010-06-08 16:52:24 +00001113{
1114public:
1115
Greg Claytone1f50b92011-05-03 22:09:39 +00001116 CommandObjectTargetModulesSearchPathsInsert (CommandInterpreter &interpreter) :
Jim Inghamda26bd22012-06-08 21:56:10 +00001117 CommandObjectParsed (interpreter,
1118 "target modules search-paths insert",
1119 "Insert a new image search path substitution pair into the current target at the specified index.",
1120 NULL)
Chris Lattner24943d22010-06-08 16:52:24 +00001121 {
Caroline Tice43b014a2010-10-04 22:28:36 +00001122 CommandArgumentEntry arg1;
1123 CommandArgumentEntry arg2;
1124 CommandArgumentData index_arg;
1125 CommandArgumentData old_prefix_arg;
1126 CommandArgumentData new_prefix_arg;
1127
1128 // Define the first and only variant of this arg.
1129 index_arg.arg_type = eArgTypeIndex;
1130 index_arg.arg_repetition = eArgRepeatPlain;
1131
1132 // Put the one and only variant into the first arg for m_arguments:
1133 arg1.push_back (index_arg);
1134
1135 // Define the first variant of this arg pair.
1136 old_prefix_arg.arg_type = eArgTypeOldPathPrefix;
1137 old_prefix_arg.arg_repetition = eArgRepeatPairPlus;
1138
1139 // Define the first variant of this arg pair.
1140 new_prefix_arg.arg_type = eArgTypeNewPathPrefix;
1141 new_prefix_arg.arg_repetition = eArgRepeatPairPlus;
1142
1143 // There are two required arguments that must always occur together, i.e. an argument "pair". Because they
1144 // must always occur together, they are treated as two variants of one argument rather than two independent
1145 // arguments. Push them both into the same argument position for m_arguments...
1146
1147 arg2.push_back (old_prefix_arg);
1148 arg2.push_back (new_prefix_arg);
1149
1150 // Add arguments to m_arguments.
1151 m_arguments.push_back (arg1);
1152 m_arguments.push_back (arg2);
Chris Lattner24943d22010-06-08 16:52:24 +00001153 }
1154
Greg Claytone1f50b92011-05-03 22:09:39 +00001155 ~CommandObjectTargetModulesSearchPathsInsert ()
Chris Lattner24943d22010-06-08 16:52:24 +00001156 {
1157 }
1158
Jim Inghamda26bd22012-06-08 21:56:10 +00001159protected:
Chris Lattner24943d22010-06-08 16:52:24 +00001160 bool
Jim Inghamda26bd22012-06-08 21:56:10 +00001161 DoExecute (Args& command,
Chris Lattner24943d22010-06-08 16:52:24 +00001162 CommandReturnObject &result)
1163 {
Greg Clayton238c0a12010-09-18 01:14:36 +00001164 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Chris Lattner24943d22010-06-08 16:52:24 +00001165 if (target)
1166 {
1167 uint32_t argc = command.GetArgumentCount();
1168 // check for at least 3 arguments and an odd nubmer of parameters
1169 if (argc >= 3 && argc & 1)
1170 {
1171 bool success = false;
1172
1173 uint32_t insert_idx = Args::StringToUInt32(command.GetArgumentAtIndex(0), UINT32_MAX, 0, &success);
1174
1175 if (!success)
1176 {
1177 result.AppendErrorWithFormat("<index> parameter is not an integer: '%s'.\n", command.GetArgumentAtIndex(0));
1178 result.SetStatus (eReturnStatusFailed);
1179 return result.Succeeded();
1180 }
1181
1182 // shift off the index
1183 command.Shift();
1184 argc = command.GetArgumentCount();
1185
1186 for (uint32_t i=0; i<argc; i+=2, ++insert_idx)
1187 {
1188 const char *from = command.GetArgumentAtIndex(i);
1189 const char *to = command.GetArgumentAtIndex(i+1);
1190
1191 if (from[0] && to[0])
1192 {
1193 bool last_pair = ((argc - i) == 2);
1194 target->GetImageSearchPathList().Insert (ConstString(from),
1195 ConstString(to),
1196 insert_idx,
1197 last_pair);
Johnny Chen4d661352011-02-03 00:30:19 +00001198 result.SetStatus (eReturnStatusSuccessFinishNoResult);
Chris Lattner24943d22010-06-08 16:52:24 +00001199 }
1200 else
1201 {
1202 if (from[0])
Greg Claytonabe0fed2011-04-18 08:33:37 +00001203 result.AppendError ("<path-prefix> can't be empty\n");
Chris Lattner24943d22010-06-08 16:52:24 +00001204 else
Greg Claytonabe0fed2011-04-18 08:33:37 +00001205 result.AppendError ("<new-path-prefix> can't be empty\n");
Chris Lattner24943d22010-06-08 16:52:24 +00001206 result.SetStatus (eReturnStatusFailed);
1207 return false;
1208 }
1209 }
1210 }
1211 else
1212 {
Greg Claytonabe0fed2011-04-18 08:33:37 +00001213 result.AppendError ("insert requires at least three arguments\n");
Chris Lattner24943d22010-06-08 16:52:24 +00001214 result.SetStatus (eReturnStatusFailed);
1215 return result.Succeeded();
1216 }
1217
1218 }
1219 else
1220 {
Greg Claytonabe0fed2011-04-18 08:33:37 +00001221 result.AppendError ("invalid target\n");
Chris Lattner24943d22010-06-08 16:52:24 +00001222 result.SetStatus (eReturnStatusFailed);
1223 }
1224 return result.Succeeded();
1225 }
1226};
1227
Greg Claytone1f50b92011-05-03 22:09:39 +00001228
1229#pragma mark CommandObjectTargetModulesSearchPathsList
1230
1231
Jim Inghamda26bd22012-06-08 21:56:10 +00001232class CommandObjectTargetModulesSearchPathsList : public CommandObjectParsed
Chris Lattner24943d22010-06-08 16:52:24 +00001233{
1234public:
1235
Greg Claytone1f50b92011-05-03 22:09:39 +00001236 CommandObjectTargetModulesSearchPathsList (CommandInterpreter &interpreter) :
Jim Inghamda26bd22012-06-08 21:56:10 +00001237 CommandObjectParsed (interpreter,
1238 "target modules search-paths list",
1239 "List all current image search path substitution pairs in the current target.",
1240 "target modules search-paths list")
Chris Lattner24943d22010-06-08 16:52:24 +00001241 {
1242 }
1243
Greg Claytone1f50b92011-05-03 22:09:39 +00001244 ~CommandObjectTargetModulesSearchPathsList ()
Chris Lattner24943d22010-06-08 16:52:24 +00001245 {
1246 }
1247
Jim Inghamda26bd22012-06-08 21:56:10 +00001248protected:
Chris Lattner24943d22010-06-08 16:52:24 +00001249 bool
Jim Inghamda26bd22012-06-08 21:56:10 +00001250 DoExecute (Args& command,
Chris Lattner24943d22010-06-08 16:52:24 +00001251 CommandReturnObject &result)
1252 {
Greg Clayton238c0a12010-09-18 01:14:36 +00001253 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Chris Lattner24943d22010-06-08 16:52:24 +00001254 if (target)
1255 {
1256 if (command.GetArgumentCount() != 0)
1257 {
Greg Claytonabe0fed2011-04-18 08:33:37 +00001258 result.AppendError ("list takes no arguments\n");
Chris Lattner24943d22010-06-08 16:52:24 +00001259 result.SetStatus (eReturnStatusFailed);
1260 return result.Succeeded();
1261 }
1262
1263 target->GetImageSearchPathList().Dump(&result.GetOutputStream());
Johnny Chen4d661352011-02-03 00:30:19 +00001264 result.SetStatus (eReturnStatusSuccessFinishResult);
Chris Lattner24943d22010-06-08 16:52:24 +00001265 }
1266 else
1267 {
Greg Claytonabe0fed2011-04-18 08:33:37 +00001268 result.AppendError ("invalid target\n");
Chris Lattner24943d22010-06-08 16:52:24 +00001269 result.SetStatus (eReturnStatusFailed);
1270 }
1271 return result.Succeeded();
1272 }
1273};
1274
Greg Claytone1f50b92011-05-03 22:09:39 +00001275#pragma mark CommandObjectTargetModulesSearchPathsQuery
1276
Jim Inghamda26bd22012-06-08 21:56:10 +00001277class CommandObjectTargetModulesSearchPathsQuery : public CommandObjectParsed
Chris Lattner24943d22010-06-08 16:52:24 +00001278{
1279public:
1280
Greg Claytone1f50b92011-05-03 22:09:39 +00001281 CommandObjectTargetModulesSearchPathsQuery (CommandInterpreter &interpreter) :
Jim Inghamda26bd22012-06-08 21:56:10 +00001282 CommandObjectParsed (interpreter,
1283 "target modules search-paths query",
1284 "Transform a path using the first applicable image search path.",
1285 NULL)
Chris Lattner24943d22010-06-08 16:52:24 +00001286 {
Caroline Tice43b014a2010-10-04 22:28:36 +00001287 CommandArgumentEntry arg;
1288 CommandArgumentData path_arg;
1289
1290 // Define the first (and only) variant of this arg.
Sean Callanan9a91ef62012-10-24 01:12:14 +00001291 path_arg.arg_type = eArgTypeDirectoryName;
Caroline Tice43b014a2010-10-04 22:28:36 +00001292 path_arg.arg_repetition = eArgRepeatPlain;
1293
1294 // There is only one variant this argument could be; put it into the argument entry.
1295 arg.push_back (path_arg);
1296
1297 // Push the data for the first argument into the m_arguments vector.
1298 m_arguments.push_back (arg);
Chris Lattner24943d22010-06-08 16:52:24 +00001299 }
1300
Greg Claytone1f50b92011-05-03 22:09:39 +00001301 ~CommandObjectTargetModulesSearchPathsQuery ()
Chris Lattner24943d22010-06-08 16:52:24 +00001302 {
1303 }
1304
Jim Inghamda26bd22012-06-08 21:56:10 +00001305protected:
Chris Lattner24943d22010-06-08 16:52:24 +00001306 bool
Jim Inghamda26bd22012-06-08 21:56:10 +00001307 DoExecute (Args& command,
Chris Lattner24943d22010-06-08 16:52:24 +00001308 CommandReturnObject &result)
1309 {
Greg Clayton238c0a12010-09-18 01:14:36 +00001310 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Chris Lattner24943d22010-06-08 16:52:24 +00001311 if (target)
1312 {
1313 if (command.GetArgumentCount() != 1)
1314 {
Greg Claytonabe0fed2011-04-18 08:33:37 +00001315 result.AppendError ("query requires one argument\n");
Chris Lattner24943d22010-06-08 16:52:24 +00001316 result.SetStatus (eReturnStatusFailed);
1317 return result.Succeeded();
1318 }
1319
1320 ConstString orig(command.GetArgumentAtIndex(0));
1321 ConstString transformed;
1322 if (target->GetImageSearchPathList().RemapPath(orig, transformed))
1323 result.GetOutputStream().Printf("%s\n", transformed.GetCString());
1324 else
1325 result.GetOutputStream().Printf("%s\n", orig.GetCString());
Johnny Chen4d661352011-02-03 00:30:19 +00001326
1327 result.SetStatus (eReturnStatusSuccessFinishResult);
Chris Lattner24943d22010-06-08 16:52:24 +00001328 }
1329 else
1330 {
Greg Claytonabe0fed2011-04-18 08:33:37 +00001331 result.AppendError ("invalid target\n");
Chris Lattner24943d22010-06-08 16:52:24 +00001332 result.SetStatus (eReturnStatusFailed);
1333 }
1334 return result.Succeeded();
1335 }
1336};
1337
Greg Claytone1f50b92011-05-03 22:09:39 +00001338//----------------------------------------------------------------------
1339// Static Helper functions
1340//----------------------------------------------------------------------
1341static void
1342DumpModuleArchitecture (Stream &strm, Module *module, bool full_triple, uint32_t width)
1343{
1344 if (module)
1345 {
1346 const char *arch_cstr;
1347 if (full_triple)
1348 arch_cstr = module->GetArchitecture().GetTriple().str().c_str();
1349 else
1350 arch_cstr = module->GetArchitecture().GetArchitectureName();
1351 if (width)
1352 strm.Printf("%-*s", width, arch_cstr);
1353 else
1354 strm.PutCString(arch_cstr);
1355 }
1356}
1357
1358static void
1359DumpModuleUUID (Stream &strm, Module *module)
1360{
Jim Ingham6f01c932012-10-12 17:34:26 +00001361 if (module && module->GetUUID().IsValid())
Greg Clayton153ccd72011-08-10 02:10:13 +00001362 module->GetUUID().Dump (&strm);
1363 else
1364 strm.PutCString(" ");
Greg Claytone1f50b92011-05-03 22:09:39 +00001365}
1366
1367static uint32_t
Greg Claytoned0a0fb2012-10-18 16:33:33 +00001368DumpCompileUnitLineTable (CommandInterpreter &interpreter,
1369 Stream &strm,
1370 Module *module,
1371 const FileSpec &file_spec,
1372 bool load_addresses)
Greg Claytone1f50b92011-05-03 22:09:39 +00001373{
1374 uint32_t num_matches = 0;
1375 if (module)
1376 {
1377 SymbolContextList sc_list;
1378 num_matches = module->ResolveSymbolContextsForFileSpec (file_spec,
1379 0,
1380 false,
1381 eSymbolContextCompUnit,
1382 sc_list);
1383
1384 for (uint32_t i=0; i<num_matches; ++i)
1385 {
1386 SymbolContext sc;
1387 if (sc_list.GetContextAtIndex(i, sc))
1388 {
1389 if (i > 0)
1390 strm << "\n\n";
1391
1392 strm << "Line table for " << *static_cast<FileSpec*> (sc.comp_unit) << " in `"
1393 << module->GetFileSpec().GetFilename() << "\n";
1394 LineTable *line_table = sc.comp_unit->GetLineTable();
1395 if (line_table)
1396 line_table->GetDescription (&strm,
Greg Clayton567e7f32011-09-22 04:58:26 +00001397 interpreter.GetExecutionContext().GetTargetPtr(),
Greg Claytone1f50b92011-05-03 22:09:39 +00001398 lldb::eDescriptionLevelBrief);
1399 else
1400 strm << "No line table";
1401 }
1402 }
1403 }
1404 return num_matches;
1405}
1406
1407static void
1408DumpFullpath (Stream &strm, const FileSpec *file_spec_ptr, uint32_t width)
1409{
1410 if (file_spec_ptr)
1411 {
1412 if (width > 0)
1413 {
1414 char fullpath[PATH_MAX];
1415 if (file_spec_ptr->GetPath(fullpath, sizeof(fullpath)))
1416 {
1417 strm.Printf("%-*s", width, fullpath);
1418 return;
1419 }
1420 }
1421 else
1422 {
1423 file_spec_ptr->Dump(&strm);
1424 return;
1425 }
1426 }
1427 // Keep the width spacing correct if things go wrong...
1428 if (width > 0)
1429 strm.Printf("%-*s", width, "");
1430}
1431
1432static void
1433DumpDirectory (Stream &strm, const FileSpec *file_spec_ptr, uint32_t width)
1434{
1435 if (file_spec_ptr)
1436 {
1437 if (width > 0)
1438 strm.Printf("%-*s", width, file_spec_ptr->GetDirectory().AsCString(""));
1439 else
1440 file_spec_ptr->GetDirectory().Dump(&strm);
1441 return;
1442 }
1443 // Keep the width spacing correct if things go wrong...
1444 if (width > 0)
1445 strm.Printf("%-*s", width, "");
1446}
1447
1448static void
1449DumpBasename (Stream &strm, const FileSpec *file_spec_ptr, uint32_t width)
1450{
1451 if (file_spec_ptr)
1452 {
1453 if (width > 0)
1454 strm.Printf("%-*s", width, file_spec_ptr->GetFilename().AsCString(""));
1455 else
1456 file_spec_ptr->GetFilename().Dump(&strm);
1457 return;
1458 }
1459 // Keep the width spacing correct if things go wrong...
1460 if (width > 0)
1461 strm.Printf("%-*s", width, "");
1462}
1463
1464
1465static void
1466DumpModuleSymtab (CommandInterpreter &interpreter, Stream &strm, Module *module, SortOrder sort_order)
1467{
1468 if (module)
1469 {
1470 ObjectFile *objfile = module->GetObjectFile ();
1471 if (objfile)
1472 {
1473 Symtab *symtab = objfile->GetSymtab();
1474 if (symtab)
Greg Clayton567e7f32011-09-22 04:58:26 +00001475 symtab->Dump(&strm, interpreter.GetExecutionContext().GetTargetPtr(), sort_order);
Greg Claytone1f50b92011-05-03 22:09:39 +00001476 }
1477 }
1478}
1479
1480static void
1481DumpModuleSections (CommandInterpreter &interpreter, Stream &strm, Module *module)
1482{
1483 if (module)
1484 {
1485 ObjectFile *objfile = module->GetObjectFile ();
1486 if (objfile)
1487 {
1488 SectionList *section_list = objfile->GetSectionList();
1489 if (section_list)
1490 {
1491 strm.PutCString ("Sections for '");
1492 strm << module->GetFileSpec();
1493 if (module->GetObjectName())
1494 strm << '(' << module->GetObjectName() << ')';
1495 strm.Printf ("' (%s):\n", module->GetArchitecture().GetArchitectureName());
1496 strm.IndentMore();
Greg Clayton567e7f32011-09-22 04:58:26 +00001497 section_list->Dump(&strm, interpreter.GetExecutionContext().GetTargetPtr(), true, UINT32_MAX);
Greg Claytone1f50b92011-05-03 22:09:39 +00001498 strm.IndentLess();
1499 }
1500 }
1501 }
1502}
1503
1504static bool
1505DumpModuleSymbolVendor (Stream &strm, Module *module)
1506{
1507 if (module)
1508 {
1509 SymbolVendor *symbol_vendor = module->GetSymbolVendor(true);
1510 if (symbol_vendor)
1511 {
1512 symbol_vendor->Dump(&strm);
1513 return true;
1514 }
1515 }
1516 return false;
1517}
1518
Greg Clayton2ad894b2012-05-15 18:43:44 +00001519static void
1520DumpAddress (ExecutionContextScope *exe_scope, const Address &so_addr, bool verbose, Stream &strm)
1521{
1522 strm.IndentMore();
1523 strm.Indent (" Address: ");
1524 so_addr.Dump (&strm, exe_scope, Address::DumpStyleModuleWithFileAddress);
1525 strm.PutCString (" (");
1526 so_addr.Dump (&strm, exe_scope, Address::DumpStyleSectionNameOffset);
1527 strm.PutCString (")\n");
1528 strm.Indent (" Summary: ");
1529 const uint32_t save_indent = strm.GetIndentLevel ();
1530 strm.SetIndentLevel (save_indent + 13);
1531 so_addr.Dump (&strm, exe_scope, Address::DumpStyleResolvedDescription);
1532 strm.SetIndentLevel (save_indent);
1533 // Print out detailed address information when verbose is enabled
1534 if (verbose)
1535 {
1536 strm.EOL();
1537 so_addr.Dump (&strm, exe_scope, Address::DumpStyleDetailedSymbolContext);
1538 }
1539 strm.IndentLess();
1540}
1541
Greg Claytone1f50b92011-05-03 22:09:39 +00001542static bool
Greg Clayton3508c382012-02-24 01:59:29 +00001543LookupAddressInModule (CommandInterpreter &interpreter,
1544 Stream &strm,
1545 Module *module,
1546 uint32_t resolve_mask,
1547 lldb::addr_t raw_addr,
1548 lldb::addr_t offset,
1549 bool verbose)
Greg Claytone1f50b92011-05-03 22:09:39 +00001550{
1551 if (module)
1552 {
1553 lldb::addr_t addr = raw_addr - offset;
1554 Address so_addr;
1555 SymbolContext sc;
Greg Clayton567e7f32011-09-22 04:58:26 +00001556 Target *target = interpreter.GetExecutionContext().GetTargetPtr();
Greg Claytone1f50b92011-05-03 22:09:39 +00001557 if (target && !target->GetSectionLoadList().IsEmpty())
1558 {
1559 if (!target->GetSectionLoadList().ResolveLoadAddress (addr, so_addr))
1560 return false;
Greg Clayton3508c382012-02-24 01:59:29 +00001561 else if (so_addr.GetModule().get() != module)
Greg Claytone1f50b92011-05-03 22:09:39 +00001562 return false;
1563 }
1564 else
1565 {
1566 if (!module->ResolveFileAddress (addr, so_addr))
1567 return false;
1568 }
1569
Greg Claytone1f50b92011-05-03 22:09:39 +00001570 ExecutionContextScope *exe_scope = interpreter.GetExecutionContext().GetBestExecutionContextScope();
Greg Clayton2ad894b2012-05-15 18:43:44 +00001571 DumpAddress (exe_scope, so_addr, verbose, strm);
1572// strm.IndentMore();
1573// strm.Indent (" Address: ");
1574// so_addr.Dump (&strm, exe_scope, Address::DumpStyleModuleWithFileAddress);
1575// strm.PutCString (" (");
1576// so_addr.Dump (&strm, exe_scope, Address::DumpStyleSectionNameOffset);
1577// strm.PutCString (")\n");
1578// strm.Indent (" Summary: ");
1579// const uint32_t save_indent = strm.GetIndentLevel ();
1580// strm.SetIndentLevel (save_indent + 13);
1581// so_addr.Dump (&strm, exe_scope, Address::DumpStyleResolvedDescription);
1582// strm.SetIndentLevel (save_indent);
1583// // Print out detailed address information when verbose is enabled
1584// if (verbose)
1585// {
1586// strm.EOL();
1587// so_addr.Dump (&strm, exe_scope, Address::DumpStyleDetailedSymbolContext);
1588// }
1589// strm.IndentLess();
Greg Claytone1f50b92011-05-03 22:09:39 +00001590 return true;
1591 }
1592
1593 return false;
1594}
1595
1596static uint32_t
Greg Clayton2ad894b2012-05-15 18:43:44 +00001597LookupSymbolInModule (CommandInterpreter &interpreter, Stream &strm, Module *module, const char *name, bool name_is_regex, bool verbose)
Greg Claytone1f50b92011-05-03 22:09:39 +00001598{
1599 if (module)
1600 {
1601 SymbolContext sc;
1602
1603 ObjectFile *objfile = module->GetObjectFile ();
1604 if (objfile)
1605 {
1606 Symtab *symtab = objfile->GetSymtab();
1607 if (symtab)
1608 {
1609 uint32_t i;
1610 std::vector<uint32_t> match_indexes;
1611 ConstString symbol_name (name);
1612 uint32_t num_matches = 0;
1613 if (name_is_regex)
1614 {
1615 RegularExpression name_regexp(name);
1616 num_matches = symtab->AppendSymbolIndexesMatchingRegExAndType (name_regexp,
1617 eSymbolTypeAny,
1618 match_indexes);
1619 }
1620 else
1621 {
1622 num_matches = symtab->AppendSymbolIndexesWithName (symbol_name, match_indexes);
1623 }
1624
1625
1626 if (num_matches > 0)
1627 {
1628 strm.Indent ();
1629 strm.Printf("%u symbols match %s'%s' in ", num_matches,
1630 name_is_regex ? "the regular expression " : "", name);
1631 DumpFullpath (strm, &module->GetFileSpec(), 0);
1632 strm.PutCString(":\n");
1633 strm.IndentMore ();
Greg Clayton2ad894b2012-05-15 18:43:44 +00001634 //Symtab::DumpSymbolHeader (&strm);
Greg Claytone1f50b92011-05-03 22:09:39 +00001635 for (i=0; i < num_matches; ++i)
1636 {
1637 Symbol *symbol = symtab->SymbolAtIndex(match_indexes[i]);
Greg Clayton2ad894b2012-05-15 18:43:44 +00001638 DumpAddress (interpreter.GetExecutionContext().GetBestExecutionContextScope(),
1639 symbol->GetAddress(),
1640 verbose,
1641 strm);
1642
1643// strm.Indent ();
1644// symbol->Dump (&strm, interpreter.GetExecutionContext().GetTargetPtr(), i);
Greg Claytone1f50b92011-05-03 22:09:39 +00001645 }
1646 strm.IndentLess ();
1647 return num_matches;
1648 }
1649 }
1650 }
1651 }
1652 return 0;
1653}
1654
1655
1656static void
Greg Clayton2ad894b2012-05-15 18:43:44 +00001657DumpSymbolContextList (ExecutionContextScope *exe_scope, Stream &strm, SymbolContextList &sc_list, bool verbose)
Greg Claytone1f50b92011-05-03 22:09:39 +00001658{
1659 strm.IndentMore ();
1660 uint32_t i;
1661 const uint32_t num_matches = sc_list.GetSize();
1662
1663 for (i=0; i<num_matches; ++i)
1664 {
1665 SymbolContext sc;
1666 if (sc_list.GetContextAtIndex(i, sc))
1667 {
Sean Callanand7793d22012-02-11 00:24:04 +00001668 AddressRange range;
1669
1670 sc.GetAddressRange(eSymbolContextEverything,
1671 0,
1672 true,
1673 range);
1674
Greg Clayton2ad894b2012-05-15 18:43:44 +00001675 DumpAddress (exe_scope, range.GetBaseAddress(), verbose, strm);
Greg Claytone1f50b92011-05-03 22:09:39 +00001676 }
1677 }
1678 strm.IndentLess ();
1679}
1680
1681static uint32_t
Greg Clayton2ad894b2012-05-15 18:43:44 +00001682LookupFunctionInModule (CommandInterpreter &interpreter,
1683 Stream &strm,
1684 Module *module,
1685 const char *name,
1686 bool name_is_regex,
1687 bool include_inlines,
1688 bool include_symbols,
1689 bool verbose)
Greg Claytone1f50b92011-05-03 22:09:39 +00001690{
1691 if (module && name && name[0])
1692 {
1693 SymbolContextList sc_list;
Greg Claytone1f50b92011-05-03 22:09:39 +00001694 const bool append = true;
1695 uint32_t num_matches = 0;
1696 if (name_is_regex)
1697 {
1698 RegularExpression function_name_regex (name);
1699 num_matches = module->FindFunctions (function_name_regex,
1700 include_symbols,
Sean Callanan302d78c2012-02-10 22:52:19 +00001701 include_inlines,
Greg Claytone1f50b92011-05-03 22:09:39 +00001702 append,
1703 sc_list);
1704 }
1705 else
1706 {
1707 ConstString function_name (name);
Sean Callanan3e80cd92011-10-12 02:08:07 +00001708 num_matches = module->FindFunctions (function_name,
1709 NULL,
Greg Claytone1f50b92011-05-03 22:09:39 +00001710 eFunctionNameTypeBase | eFunctionNameTypeFull | eFunctionNameTypeMethod | eFunctionNameTypeSelector,
1711 include_symbols,
Sean Callanan302d78c2012-02-10 22:52:19 +00001712 include_inlines,
Greg Claytone1f50b92011-05-03 22:09:39 +00001713 append,
1714 sc_list);
1715 }
1716
1717 if (num_matches)
1718 {
1719 strm.Indent ();
1720 strm.Printf("%u match%s found in ", num_matches, num_matches > 1 ? "es" : "");
1721 DumpFullpath (strm, &module->GetFileSpec(), 0);
1722 strm.PutCString(":\n");
Greg Clayton2ad894b2012-05-15 18:43:44 +00001723 DumpSymbolContextList (interpreter.GetExecutionContext().GetBestExecutionContextScope(), strm, sc_list, verbose);
Greg Claytone1f50b92011-05-03 22:09:39 +00001724 }
1725 return num_matches;
1726 }
1727 return 0;
1728}
1729
1730static uint32_t
Greg Clayton0cbaacd2012-05-15 19:26:12 +00001731LookupTypeInModule (CommandInterpreter &interpreter,
Greg Clayton801417e2011-07-07 01:59:51 +00001732 Stream &strm,
1733 Module *module,
1734 const char *name_cstr,
1735 bool name_is_regex)
Greg Claytone1f50b92011-05-03 22:09:39 +00001736{
1737 if (module && name_cstr && name_cstr[0])
1738 {
Greg Clayton37bb8dd2011-12-08 02:13:16 +00001739 TypeList type_list;
Greg Claytondc0a38c2012-03-26 23:03:23 +00001740 const uint32_t max_num_matches = UINT32_MAX;
Greg Clayton37bb8dd2011-12-08 02:13:16 +00001741 uint32_t num_matches = 0;
Greg Claytondc0a38c2012-03-26 23:03:23 +00001742 bool name_is_fully_qualified = false;
Greg Clayton37bb8dd2011-12-08 02:13:16 +00001743 SymbolContext sc;
1744
1745 ConstString name(name_cstr);
Greg Claytondc0a38c2012-03-26 23:03:23 +00001746 num_matches = module->FindTypes(sc, name, name_is_fully_qualified, max_num_matches, type_list);
Greg Claytone1f50b92011-05-03 22:09:39 +00001747
Greg Clayton37bb8dd2011-12-08 02:13:16 +00001748 if (num_matches)
1749 {
1750 strm.Indent ();
1751 strm.Printf("%u match%s found in ", num_matches, num_matches > 1 ? "es" : "");
1752 DumpFullpath (strm, &module->GetFileSpec(), 0);
1753 strm.PutCString(":\n");
1754 const uint32_t num_types = type_list.GetSize();
1755 for (uint32_t i=0; i<num_types; ++i)
Greg Claytone1f50b92011-05-03 22:09:39 +00001756 {
Greg Clayton37bb8dd2011-12-08 02:13:16 +00001757 TypeSP type_sp (type_list.GetTypeAtIndex(i));
1758 if (type_sp)
Greg Claytone1f50b92011-05-03 22:09:39 +00001759 {
Greg Clayton37bb8dd2011-12-08 02:13:16 +00001760 // Resolve the clang type so that any forward references
1761 // to types that haven't yet been parsed will get parsed.
1762 type_sp->GetClangFullType ();
1763 type_sp->GetDescription (&strm, eDescriptionLevelFull, true);
Greg Clayton0cbaacd2012-05-15 19:26:12 +00001764 // Print all typedef chains
1765 TypeSP typedef_type_sp (type_sp);
1766 TypeSP typedefed_type_sp (typedef_type_sp->GetTypedefType());
1767 while (typedefed_type_sp)
1768 {
1769 strm.EOL();
1770 strm.Printf(" typedef '%s': ", typedef_type_sp->GetName().GetCString());
1771 typedefed_type_sp->GetClangFullType ();
1772 typedefed_type_sp->GetDescription (&strm, eDescriptionLevelFull, true);
1773 typedef_type_sp = typedefed_type_sp;
1774 typedefed_type_sp = typedef_type_sp->GetTypedefType();
1775 }
Greg Claytone1f50b92011-05-03 22:09:39 +00001776 }
Greg Clayton37bb8dd2011-12-08 02:13:16 +00001777 strm.EOL();
Greg Claytone1f50b92011-05-03 22:09:39 +00001778 }
Greg Clayton37bb8dd2011-12-08 02:13:16 +00001779 }
1780 return num_matches;
Greg Claytone1f50b92011-05-03 22:09:39 +00001781 }
1782 return 0;
1783}
1784
1785static uint32_t
Sean Callanan56d31ec2012-06-06 20:49:55 +00001786LookupTypeHere (CommandInterpreter &interpreter,
1787 Stream &strm,
1788 const SymbolContext &sym_ctx,
1789 const char *name_cstr,
1790 bool name_is_regex)
1791{
1792 if (!sym_ctx.module_sp)
1793 return 0;
1794
1795 TypeList type_list;
1796 const uint32_t max_num_matches = UINT32_MAX;
1797 uint32_t num_matches = 1;
1798 bool name_is_fully_qualified = false;
1799
1800 ConstString name(name_cstr);
1801 num_matches = sym_ctx.module_sp->FindTypes(sym_ctx, name, name_is_fully_qualified, max_num_matches, type_list);
1802
1803 if (num_matches)
1804 {
1805 strm.Indent ();
1806 strm.PutCString("Best match found in ");
1807 DumpFullpath (strm, &sym_ctx.module_sp->GetFileSpec(), 0);
1808 strm.PutCString(":\n");
1809
1810 TypeSP type_sp (type_list.GetTypeAtIndex(0));
1811 if (type_sp)
1812 {
1813 // Resolve the clang type so that any forward references
1814 // to types that haven't yet been parsed will get parsed.
1815 type_sp->GetClangFullType ();
1816 type_sp->GetDescription (&strm, eDescriptionLevelFull, true);
1817 // Print all typedef chains
1818 TypeSP typedef_type_sp (type_sp);
1819 TypeSP typedefed_type_sp (typedef_type_sp->GetTypedefType());
1820 while (typedefed_type_sp)
1821 {
1822 strm.EOL();
1823 strm.Printf(" typedef '%s': ", typedef_type_sp->GetName().GetCString());
1824 typedefed_type_sp->GetClangFullType ();
1825 typedefed_type_sp->GetDescription (&strm, eDescriptionLevelFull, true);
1826 typedef_type_sp = typedefed_type_sp;
1827 typedefed_type_sp = typedef_type_sp->GetTypedefType();
1828 }
1829 }
1830 strm.EOL();
1831 }
1832 return num_matches;
1833}
1834
1835static uint32_t
Greg Claytone1f50b92011-05-03 22:09:39 +00001836LookupFileAndLineInModule (CommandInterpreter &interpreter,
Sean Callanan56d31ec2012-06-06 20:49:55 +00001837 Stream &strm,
Greg Claytone1f50b92011-05-03 22:09:39 +00001838 Module *module,
1839 const FileSpec &file_spec,
1840 uint32_t line,
1841 bool check_inlines,
1842 bool verbose)
1843{
1844 if (module && file_spec)
1845 {
1846 SymbolContextList sc_list;
1847 const uint32_t num_matches = module->ResolveSymbolContextsForFileSpec(file_spec, line, check_inlines,
1848 eSymbolContextEverything, sc_list);
1849 if (num_matches > 0)
1850 {
1851 strm.Indent ();
1852 strm.Printf("%u match%s found in ", num_matches, num_matches > 1 ? "es" : "");
1853 strm << file_spec;
1854 if (line > 0)
1855 strm.Printf (":%u", line);
1856 strm << " in ";
1857 DumpFullpath (strm, &module->GetFileSpec(), 0);
1858 strm.PutCString(":\n");
Greg Clayton2ad894b2012-05-15 18:43:44 +00001859 DumpSymbolContextList (interpreter.GetExecutionContext().GetBestExecutionContextScope(), strm, sc_list, verbose);
Greg Claytone1f50b92011-05-03 22:09:39 +00001860 return num_matches;
1861 }
1862 }
1863 return 0;
1864
1865}
1866
Greg Clayton91048ef2011-11-10 01:18:58 +00001867
1868static size_t
1869FindModulesByName (Target *target,
1870 const char *module_name,
1871 ModuleList &module_list,
1872 bool check_global_list)
1873{
1874// Dump specified images (by basename or fullpath)
1875 FileSpec module_file_spec(module_name, false);
Greg Clayton444fe992012-02-26 05:51:37 +00001876 ModuleSpec module_spec (module_file_spec);
Greg Clayton91048ef2011-11-10 01:18:58 +00001877
1878 const size_t initial_size = module_list.GetSize ();
1879
Greg Clayton316f57f2012-07-11 20:46:47 +00001880 if (check_global_list)
Greg Clayton91048ef2011-11-10 01:18:58 +00001881 {
1882 // Check the global list
Greg Claytonc149c8b2012-01-27 18:08:35 +00001883 Mutex::Locker locker(Module::GetAllocationModuleCollectionMutex());
Greg Clayton91048ef2011-11-10 01:18:58 +00001884 const uint32_t num_modules = Module::GetNumberAllocatedModules();
1885 ModuleSP module_sp;
1886 for (uint32_t image_idx = 0; image_idx<num_modules; ++image_idx)
1887 {
1888 Module *module = Module::GetAllocatedModuleAtIndex(image_idx);
1889
1890 if (module)
1891 {
Greg Clayton444fe992012-02-26 05:51:37 +00001892 if (module->MatchesModuleSpec (module_spec))
Greg Clayton91048ef2011-11-10 01:18:58 +00001893 {
Greg Clayton13d24fb2012-01-29 20:56:30 +00001894 module_sp = module->shared_from_this();
Greg Clayton91048ef2011-11-10 01:18:58 +00001895 module_list.AppendIfNeeded(module_sp);
1896 }
1897 }
1898 }
1899 }
Greg Clayton316f57f2012-07-11 20:46:47 +00001900 else
1901 {
1902 if (target)
1903 {
1904 const size_t num_matches = target->GetImages().FindModules (module_spec, module_list);
1905
1906 // Not found in our module list for our target, check the main
1907 // shared module list in case it is a extra file used somewhere
1908 // else
1909 if (num_matches == 0)
1910 {
1911 module_spec.GetArchitecture() = target->GetArchitecture();
1912 ModuleList::FindSharedModules (module_spec, module_list);
1913 }
1914 }
1915 else
1916 {
1917 ModuleList::FindSharedModules (module_spec,module_list);
1918 }
1919 }
1920
Greg Clayton91048ef2011-11-10 01:18:58 +00001921 return module_list.GetSize () - initial_size;
1922}
1923
Greg Claytone1f50b92011-05-03 22:09:39 +00001924#pragma mark CommandObjectTargetModulesModuleAutoComplete
1925
1926//----------------------------------------------------------------------
1927// A base command object class that can auto complete with module file
1928// paths
1929//----------------------------------------------------------------------
1930
Jim Inghamda26bd22012-06-08 21:56:10 +00001931class CommandObjectTargetModulesModuleAutoComplete : public CommandObjectParsed
Greg Claytone1f50b92011-05-03 22:09:39 +00001932{
1933public:
1934
1935 CommandObjectTargetModulesModuleAutoComplete (CommandInterpreter &interpreter,
1936 const char *name,
1937 const char *help,
1938 const char *syntax) :
Jim Inghamda26bd22012-06-08 21:56:10 +00001939 CommandObjectParsed (interpreter, name, help, syntax)
Greg Claytone1f50b92011-05-03 22:09:39 +00001940 {
1941 CommandArgumentEntry arg;
1942 CommandArgumentData file_arg;
1943
1944 // Define the first (and only) variant of this arg.
1945 file_arg.arg_type = eArgTypeFilename;
1946 file_arg.arg_repetition = eArgRepeatStar;
1947
1948 // There is only one variant this argument could be; put it into the argument entry.
1949 arg.push_back (file_arg);
1950
1951 // Push the data for the first argument into the m_arguments vector.
1952 m_arguments.push_back (arg);
1953 }
1954
1955 virtual
1956 ~CommandObjectTargetModulesModuleAutoComplete ()
1957 {
1958 }
1959
1960 virtual int
1961 HandleArgumentCompletion (Args &input,
1962 int &cursor_index,
1963 int &cursor_char_position,
1964 OptionElementVector &opt_element_vector,
1965 int match_start_point,
1966 int max_return_elements,
1967 bool &word_complete,
1968 StringList &matches)
1969 {
1970 // Arguments are the standard module completer.
1971 std::string completion_str (input.GetArgumentAtIndex(cursor_index));
1972 completion_str.erase (cursor_char_position);
1973
1974 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
1975 CommandCompletions::eModuleCompletion,
1976 completion_str.c_str(),
1977 match_start_point,
1978 max_return_elements,
1979 NULL,
1980 word_complete,
1981 matches);
1982 return matches.GetSize();
1983 }
1984};
1985
1986#pragma mark CommandObjectTargetModulesSourceFileAutoComplete
1987
1988//----------------------------------------------------------------------
1989// A base command object class that can auto complete with module source
1990// file paths
1991//----------------------------------------------------------------------
1992
Jim Inghamda26bd22012-06-08 21:56:10 +00001993class CommandObjectTargetModulesSourceFileAutoComplete : public CommandObjectParsed
Greg Claytone1f50b92011-05-03 22:09:39 +00001994{
1995public:
1996
1997 CommandObjectTargetModulesSourceFileAutoComplete (CommandInterpreter &interpreter,
1998 const char *name,
1999 const char *help,
2000 const char *syntax) :
Jim Inghamda26bd22012-06-08 21:56:10 +00002001 CommandObjectParsed (interpreter, name, help, syntax)
Greg Claytone1f50b92011-05-03 22:09:39 +00002002 {
2003 CommandArgumentEntry arg;
2004 CommandArgumentData source_file_arg;
2005
2006 // Define the first (and only) variant of this arg.
2007 source_file_arg.arg_type = eArgTypeSourceFile;
2008 source_file_arg.arg_repetition = eArgRepeatPlus;
2009
2010 // There is only one variant this argument could be; put it into the argument entry.
2011 arg.push_back (source_file_arg);
2012
2013 // Push the data for the first argument into the m_arguments vector.
2014 m_arguments.push_back (arg);
2015 }
2016
2017 virtual
2018 ~CommandObjectTargetModulesSourceFileAutoComplete ()
2019 {
2020 }
2021
2022 virtual int
2023 HandleArgumentCompletion (Args &input,
2024 int &cursor_index,
2025 int &cursor_char_position,
2026 OptionElementVector &opt_element_vector,
2027 int match_start_point,
2028 int max_return_elements,
2029 bool &word_complete,
2030 StringList &matches)
2031 {
2032 // Arguments are the standard source file completer.
2033 std::string completion_str (input.GetArgumentAtIndex(cursor_index));
2034 completion_str.erase (cursor_char_position);
2035
2036 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
2037 CommandCompletions::eSourceFileCompletion,
2038 completion_str.c_str(),
2039 match_start_point,
2040 max_return_elements,
2041 NULL,
2042 word_complete,
2043 matches);
2044 return matches.GetSize();
2045 }
2046};
2047
2048
2049#pragma mark CommandObjectTargetModulesDumpSymtab
2050
2051
2052class CommandObjectTargetModulesDumpSymtab : public CommandObjectTargetModulesModuleAutoComplete
2053{
2054public:
2055 CommandObjectTargetModulesDumpSymtab (CommandInterpreter &interpreter) :
2056 CommandObjectTargetModulesModuleAutoComplete (interpreter,
2057 "target modules dump symtab",
2058 "Dump the symbol table from one or more target modules.",
2059 NULL),
2060 m_options (interpreter)
2061 {
2062 }
2063
2064 virtual
2065 ~CommandObjectTargetModulesDumpSymtab ()
2066 {
2067 }
2068
Jim Inghamda26bd22012-06-08 21:56:10 +00002069 virtual Options *
2070 GetOptions ()
2071 {
2072 return &m_options;
2073 }
2074
2075 class CommandOptions : public Options
2076 {
2077 public:
2078
2079 CommandOptions (CommandInterpreter &interpreter) :
2080 Options(interpreter),
2081 m_sort_order (eSortOrderNone)
2082 {
2083 }
2084
2085 virtual
2086 ~CommandOptions ()
2087 {
2088 }
2089
2090 virtual Error
2091 SetOptionValue (uint32_t option_idx, const char *option_arg)
2092 {
2093 Error error;
Greg Clayton6475c422012-12-04 00:32:51 +00002094 const int short_option = m_getopt_table[option_idx].val;
Jim Inghamda26bd22012-06-08 21:56:10 +00002095
2096 switch (short_option)
2097 {
2098 case 's':
2099 m_sort_order = (SortOrder) Args::StringToOptionEnum (option_arg,
2100 g_option_table[option_idx].enum_values,
2101 eSortOrderNone,
2102 error);
2103 break;
2104
2105 default:
2106 error.SetErrorStringWithFormat("invalid short option character '%c'", short_option);
2107 break;
2108
2109 }
2110 return error;
2111 }
2112
2113 void
2114 OptionParsingStarting ()
2115 {
2116 m_sort_order = eSortOrderNone;
2117 }
2118
2119 const OptionDefinition*
2120 GetDefinitions ()
2121 {
2122 return g_option_table;
2123 }
2124
2125 // Options table: Required for subclasses of Options.
2126 static OptionDefinition g_option_table[];
2127
2128 SortOrder m_sort_order;
2129 };
2130
2131protected:
Greg Claytone1f50b92011-05-03 22:09:39 +00002132 virtual bool
Jim Inghamda26bd22012-06-08 21:56:10 +00002133 DoExecute (Args& command,
Greg Claytone1f50b92011-05-03 22:09:39 +00002134 CommandReturnObject &result)
2135 {
2136 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
2137 if (target == NULL)
2138 {
2139 result.AppendError ("invalid target, create a debug target using the 'target create' command");
2140 result.SetStatus (eReturnStatusFailed);
2141 return false;
2142 }
2143 else
2144 {
2145 uint32_t num_dumped = 0;
2146
2147 uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize();
2148 result.GetOutputStream().SetAddressByteSize(addr_byte_size);
2149 result.GetErrorStream().SetAddressByteSize(addr_byte_size);
2150
2151 if (command.GetArgumentCount() == 0)
2152 {
2153 // Dump all sections for all modules images
Jim Ingham93367902012-05-30 02:19:25 +00002154 Mutex::Locker modules_locker(target->GetImages().GetMutex());
Greg Claytone1f50b92011-05-03 22:09:39 +00002155 const uint32_t num_modules = target->GetImages().GetSize();
2156 if (num_modules > 0)
2157 {
2158 result.GetOutputStream().Printf("Dumping symbol table for %u modules.\n", num_modules);
2159 for (uint32_t image_idx = 0; image_idx<num_modules; ++image_idx)
2160 {
2161 if (num_dumped > 0)
2162 {
2163 result.GetOutputStream().EOL();
2164 result.GetOutputStream().EOL();
2165 }
2166 num_dumped++;
Jim Ingham93367902012-05-30 02:19:25 +00002167 DumpModuleSymtab (m_interpreter,
2168 result.GetOutputStream(),
2169 target->GetImages().GetModulePointerAtIndexUnlocked(image_idx),
2170 m_options.m_sort_order);
Greg Claytone1f50b92011-05-03 22:09:39 +00002171 }
2172 }
2173 else
2174 {
2175 result.AppendError ("the target has no associated executable images");
2176 result.SetStatus (eReturnStatusFailed);
2177 return false;
2178 }
2179 }
2180 else
2181 {
2182 // Dump specified images (by basename or fullpath)
2183 const char *arg_cstr;
2184 for (int arg_idx = 0; (arg_cstr = command.GetArgumentAtIndex(arg_idx)) != NULL; ++arg_idx)
2185 {
Greg Clayton91048ef2011-11-10 01:18:58 +00002186 ModuleList module_list;
2187 const size_t num_matches = FindModulesByName (target, arg_cstr, module_list, true);
2188 if (num_matches > 0)
Greg Claytone1f50b92011-05-03 22:09:39 +00002189 {
Greg Clayton91048ef2011-11-10 01:18:58 +00002190 for (size_t i=0; i<num_matches; ++i)
Greg Claytone1f50b92011-05-03 22:09:39 +00002191 {
Greg Clayton91048ef2011-11-10 01:18:58 +00002192 Module *module = module_list.GetModulePointerAtIndex(i);
2193 if (module)
Greg Claytone1f50b92011-05-03 22:09:39 +00002194 {
2195 if (num_dumped > 0)
2196 {
2197 result.GetOutputStream().EOL();
2198 result.GetOutputStream().EOL();
2199 }
2200 num_dumped++;
Greg Clayton91048ef2011-11-10 01:18:58 +00002201 DumpModuleSymtab (m_interpreter, result.GetOutputStream(), module, m_options.m_sort_order);
Greg Claytone1f50b92011-05-03 22:09:39 +00002202 }
2203 }
2204 }
2205 else
2206 result.AppendWarningWithFormat("Unable to find an image that matches '%s'.\n", arg_cstr);
2207 }
2208 }
2209
2210 if (num_dumped > 0)
2211 result.SetStatus (eReturnStatusSuccessFinishResult);
2212 else
2213 {
2214 result.AppendError ("no matching executable images found");
2215 result.SetStatus (eReturnStatusFailed);
2216 }
2217 }
2218 return result.Succeeded();
2219 }
2220
Greg Claytone1f50b92011-05-03 22:09:39 +00002221
2222 CommandOptions m_options;
2223};
2224
2225static OptionEnumValueElement
2226g_sort_option_enumeration[4] =
2227{
2228 { eSortOrderNone, "none", "No sorting, use the original symbol table order."},
2229 { eSortOrderByAddress, "address", "Sort output by symbol address."},
2230 { eSortOrderByName, "name", "Sort output by symbol name."},
2231 { 0, NULL, NULL }
2232};
2233
2234
2235OptionDefinition
2236CommandObjectTargetModulesDumpSymtab::CommandOptions::g_option_table[] =
2237{
2238 { LLDB_OPT_SET_1, false, "sort", 's', required_argument, g_sort_option_enumeration, 0, eArgTypeSortOrder, "Supply a sort order when dumping the symbol table."},
2239 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
2240};
2241
2242#pragma mark CommandObjectTargetModulesDumpSections
2243
2244//----------------------------------------------------------------------
2245// Image section dumping command
2246//----------------------------------------------------------------------
2247
2248class CommandObjectTargetModulesDumpSections : public CommandObjectTargetModulesModuleAutoComplete
2249{
2250public:
2251 CommandObjectTargetModulesDumpSections (CommandInterpreter &interpreter) :
2252 CommandObjectTargetModulesModuleAutoComplete (interpreter,
2253 "target modules dump sections",
2254 "Dump the sections from one or more target modules.",
2255 //"target modules dump sections [<file1> ...]")
2256 NULL)
2257 {
2258 }
2259
2260 virtual
2261 ~CommandObjectTargetModulesDumpSections ()
2262 {
2263 }
2264
Jim Inghamda26bd22012-06-08 21:56:10 +00002265protected:
Greg Claytone1f50b92011-05-03 22:09:39 +00002266 virtual bool
Jim Inghamda26bd22012-06-08 21:56:10 +00002267 DoExecute (Args& command,
Greg Claytone1f50b92011-05-03 22:09:39 +00002268 CommandReturnObject &result)
2269 {
2270 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
2271 if (target == NULL)
2272 {
2273 result.AppendError ("invalid target, create a debug target using the 'target create' command");
2274 result.SetStatus (eReturnStatusFailed);
2275 return false;
2276 }
2277 else
2278 {
2279 uint32_t num_dumped = 0;
2280
2281 uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize();
2282 result.GetOutputStream().SetAddressByteSize(addr_byte_size);
2283 result.GetErrorStream().SetAddressByteSize(addr_byte_size);
2284
2285 if (command.GetArgumentCount() == 0)
2286 {
2287 // Dump all sections for all modules images
2288 const uint32_t num_modules = target->GetImages().GetSize();
2289 if (num_modules > 0)
2290 {
2291 result.GetOutputStream().Printf("Dumping sections for %u modules.\n", num_modules);
2292 for (uint32_t image_idx = 0; image_idx<num_modules; ++image_idx)
2293 {
2294 num_dumped++;
2295 DumpModuleSections (m_interpreter, result.GetOutputStream(), target->GetImages().GetModulePointerAtIndex(image_idx));
2296 }
2297 }
2298 else
2299 {
2300 result.AppendError ("the target has no associated executable images");
2301 result.SetStatus (eReturnStatusFailed);
2302 return false;
2303 }
2304 }
2305 else
2306 {
2307 // Dump specified images (by basename or fullpath)
2308 const char *arg_cstr;
2309 for (int arg_idx = 0; (arg_cstr = command.GetArgumentAtIndex(arg_idx)) != NULL; ++arg_idx)
2310 {
Greg Clayton91048ef2011-11-10 01:18:58 +00002311 ModuleList module_list;
2312 const size_t num_matches = FindModulesByName (target, arg_cstr, module_list, true);
2313 if (num_matches > 0)
Greg Claytone1f50b92011-05-03 22:09:39 +00002314 {
Greg Clayton91048ef2011-11-10 01:18:58 +00002315 for (size_t i=0; i<num_matches; ++i)
Greg Claytone1f50b92011-05-03 22:09:39 +00002316 {
Greg Clayton91048ef2011-11-10 01:18:58 +00002317 Module *module = module_list.GetModulePointerAtIndex(i);
2318 if (module)
Greg Claytone1f50b92011-05-03 22:09:39 +00002319 {
2320 num_dumped++;
Greg Clayton91048ef2011-11-10 01:18:58 +00002321 DumpModuleSections (m_interpreter, result.GetOutputStream(), module);
Greg Claytone1f50b92011-05-03 22:09:39 +00002322 }
2323 }
2324 }
2325 else
Greg Clayton91048ef2011-11-10 01:18:58 +00002326 {
2327 // Check the global list
Greg Claytonc149c8b2012-01-27 18:08:35 +00002328 Mutex::Locker locker(Module::GetAllocationModuleCollectionMutex());
Greg Clayton91048ef2011-11-10 01:18:58 +00002329
Greg Claytone1f50b92011-05-03 22:09:39 +00002330 result.AppendWarningWithFormat("Unable to find an image that matches '%s'.\n", arg_cstr);
Greg Clayton91048ef2011-11-10 01:18:58 +00002331 }
Greg Claytone1f50b92011-05-03 22:09:39 +00002332 }
2333 }
2334
2335 if (num_dumped > 0)
2336 result.SetStatus (eReturnStatusSuccessFinishResult);
2337 else
2338 {
2339 result.AppendError ("no matching executable images found");
2340 result.SetStatus (eReturnStatusFailed);
2341 }
2342 }
2343 return result.Succeeded();
2344 }
2345};
2346
2347
2348#pragma mark CommandObjectTargetModulesDumpSymfile
2349
2350//----------------------------------------------------------------------
2351// Image debug symbol dumping command
2352//----------------------------------------------------------------------
2353
2354class CommandObjectTargetModulesDumpSymfile : public CommandObjectTargetModulesModuleAutoComplete
2355{
2356public:
2357 CommandObjectTargetModulesDumpSymfile (CommandInterpreter &interpreter) :
2358 CommandObjectTargetModulesModuleAutoComplete (interpreter,
2359 "target modules dump symfile",
2360 "Dump the debug symbol file for one or more target modules.",
2361 //"target modules dump symfile [<file1> ...]")
2362 NULL)
2363 {
2364 }
2365
2366 virtual
2367 ~CommandObjectTargetModulesDumpSymfile ()
2368 {
2369 }
2370
Jim Inghamda26bd22012-06-08 21:56:10 +00002371protected:
Greg Claytone1f50b92011-05-03 22:09:39 +00002372 virtual bool
Jim Inghamda26bd22012-06-08 21:56:10 +00002373 DoExecute (Args& command,
Greg Claytone1f50b92011-05-03 22:09:39 +00002374 CommandReturnObject &result)
2375 {
2376 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
2377 if (target == NULL)
2378 {
2379 result.AppendError ("invalid target, create a debug target using the 'target create' command");
2380 result.SetStatus (eReturnStatusFailed);
2381 return false;
2382 }
2383 else
2384 {
2385 uint32_t num_dumped = 0;
2386
2387 uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize();
2388 result.GetOutputStream().SetAddressByteSize(addr_byte_size);
2389 result.GetErrorStream().SetAddressByteSize(addr_byte_size);
2390
2391 if (command.GetArgumentCount() == 0)
2392 {
2393 // Dump all sections for all modules images
Enrico Granata146d9522012-11-08 02:22:02 +00002394 const ModuleList &target_modules = target->GetImages();
Jim Ingham93367902012-05-30 02:19:25 +00002395 Mutex::Locker modules_locker (target_modules.GetMutex());
2396 const uint32_t num_modules = target_modules.GetSize();
Greg Claytone1f50b92011-05-03 22:09:39 +00002397 if (num_modules > 0)
2398 {
2399 result.GetOutputStream().Printf("Dumping debug symbols for %u modules.\n", num_modules);
2400 for (uint32_t image_idx = 0; image_idx<num_modules; ++image_idx)
2401 {
Jim Ingham93367902012-05-30 02:19:25 +00002402 if (DumpModuleSymbolVendor (result.GetOutputStream(), target_modules.GetModulePointerAtIndexUnlocked(image_idx)))
Greg Claytone1f50b92011-05-03 22:09:39 +00002403 num_dumped++;
2404 }
2405 }
2406 else
2407 {
2408 result.AppendError ("the target has no associated executable images");
2409 result.SetStatus (eReturnStatusFailed);
2410 return false;
2411 }
2412 }
2413 else
2414 {
2415 // Dump specified images (by basename or fullpath)
2416 const char *arg_cstr;
2417 for (int arg_idx = 0; (arg_cstr = command.GetArgumentAtIndex(arg_idx)) != NULL; ++arg_idx)
2418 {
Greg Clayton91048ef2011-11-10 01:18:58 +00002419 ModuleList module_list;
2420 const size_t num_matches = FindModulesByName (target, arg_cstr, module_list, true);
2421 if (num_matches > 0)
Greg Claytone1f50b92011-05-03 22:09:39 +00002422 {
Greg Clayton91048ef2011-11-10 01:18:58 +00002423 for (size_t i=0; i<num_matches; ++i)
Greg Claytone1f50b92011-05-03 22:09:39 +00002424 {
Greg Clayton91048ef2011-11-10 01:18:58 +00002425 Module *module = module_list.GetModulePointerAtIndex(i);
2426 if (module)
Greg Claytone1f50b92011-05-03 22:09:39 +00002427 {
Greg Clayton91048ef2011-11-10 01:18:58 +00002428 if (DumpModuleSymbolVendor (result.GetOutputStream(), module))
Greg Claytone1f50b92011-05-03 22:09:39 +00002429 num_dumped++;
2430 }
2431 }
2432 }
2433 else
2434 result.AppendWarningWithFormat("Unable to find an image that matches '%s'.\n", arg_cstr);
2435 }
2436 }
2437
2438 if (num_dumped > 0)
2439 result.SetStatus (eReturnStatusSuccessFinishResult);
2440 else
2441 {
2442 result.AppendError ("no matching executable images found");
2443 result.SetStatus (eReturnStatusFailed);
2444 }
2445 }
2446 return result.Succeeded();
2447 }
2448};
2449
2450
2451#pragma mark CommandObjectTargetModulesDumpLineTable
2452
2453//----------------------------------------------------------------------
2454// Image debug line table dumping command
2455//----------------------------------------------------------------------
2456
2457class CommandObjectTargetModulesDumpLineTable : public CommandObjectTargetModulesSourceFileAutoComplete
2458{
2459public:
2460 CommandObjectTargetModulesDumpLineTable (CommandInterpreter &interpreter) :
2461 CommandObjectTargetModulesSourceFileAutoComplete (interpreter,
2462 "target modules dump line-table",
2463 "Dump the debug symbol file for one or more target modules.",
2464 NULL)
2465 {
2466 }
2467
2468 virtual
2469 ~CommandObjectTargetModulesDumpLineTable ()
2470 {
2471 }
2472
Jim Inghamda26bd22012-06-08 21:56:10 +00002473protected:
Greg Claytone1f50b92011-05-03 22:09:39 +00002474 virtual bool
Jim Inghamda26bd22012-06-08 21:56:10 +00002475 DoExecute (Args& command,
Greg Claytone1f50b92011-05-03 22:09:39 +00002476 CommandReturnObject &result)
2477 {
2478 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
2479 if (target == NULL)
2480 {
2481 result.AppendError ("invalid target, create a debug target using the 'target create' command");
2482 result.SetStatus (eReturnStatusFailed);
2483 return false;
2484 }
2485 else
2486 {
2487 ExecutionContext exe_ctx(m_interpreter.GetExecutionContext());
2488 uint32_t total_num_dumped = 0;
2489
2490 uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize();
2491 result.GetOutputStream().SetAddressByteSize(addr_byte_size);
2492 result.GetErrorStream().SetAddressByteSize(addr_byte_size);
2493
2494 if (command.GetArgumentCount() == 0)
2495 {
2496 result.AppendErrorWithFormat ("\nSyntax: %s\n", m_cmd_syntax.c_str());
2497 result.SetStatus (eReturnStatusFailed);
2498 }
2499 else
2500 {
2501 // Dump specified images (by basename or fullpath)
2502 const char *arg_cstr;
2503 for (int arg_idx = 0; (arg_cstr = command.GetArgumentAtIndex(arg_idx)) != NULL; ++arg_idx)
2504 {
2505 FileSpec file_spec(arg_cstr, false);
Jim Ingham93367902012-05-30 02:19:25 +00002506
Enrico Granata146d9522012-11-08 02:22:02 +00002507 const ModuleList &target_modules = target->GetImages();
Jim Ingham93367902012-05-30 02:19:25 +00002508 Mutex::Locker modules_locker(target_modules.GetMutex());
2509 const uint32_t num_modules = target_modules.GetSize();
Greg Claytone1f50b92011-05-03 22:09:39 +00002510 if (num_modules > 0)
2511 {
2512 uint32_t num_dumped = 0;
2513 for (uint32_t i = 0; i<num_modules; ++i)
2514 {
2515 if (DumpCompileUnitLineTable (m_interpreter,
2516 result.GetOutputStream(),
Jim Ingham93367902012-05-30 02:19:25 +00002517 target_modules.GetModulePointerAtIndexUnlocked(i),
Greg Claytone1f50b92011-05-03 22:09:39 +00002518 file_spec,
Greg Clayton567e7f32011-09-22 04:58:26 +00002519 exe_ctx.GetProcessPtr() && exe_ctx.GetProcessRef().IsAlive()))
Greg Claytone1f50b92011-05-03 22:09:39 +00002520 num_dumped++;
2521 }
2522 if (num_dumped == 0)
2523 result.AppendWarningWithFormat ("No source filenames matched '%s'.\n", arg_cstr);
2524 else
2525 total_num_dumped += num_dumped;
2526 }
2527 }
2528 }
2529
2530 if (total_num_dumped > 0)
2531 result.SetStatus (eReturnStatusSuccessFinishResult);
2532 else
2533 {
2534 result.AppendError ("no source filenames matched any command arguments");
2535 result.SetStatus (eReturnStatusFailed);
2536 }
2537 }
2538 return result.Succeeded();
2539 }
2540};
2541
2542
2543#pragma mark CommandObjectTargetModulesDump
2544
2545//----------------------------------------------------------------------
2546// Dump multi-word command for target modules
2547//----------------------------------------------------------------------
2548
2549class CommandObjectTargetModulesDump : public CommandObjectMultiword
2550{
2551public:
2552
2553 //------------------------------------------------------------------
2554 // Constructors and Destructors
2555 //------------------------------------------------------------------
2556 CommandObjectTargetModulesDump(CommandInterpreter &interpreter) :
2557 CommandObjectMultiword (interpreter,
2558 "target modules dump",
2559 "A set of commands for dumping information about one or more target modules.",
2560 "target modules dump [symtab|sections|symfile|line-table] [<file1> <file2> ...]")
2561 {
2562 LoadSubCommand ("symtab", CommandObjectSP (new CommandObjectTargetModulesDumpSymtab (interpreter)));
2563 LoadSubCommand ("sections", CommandObjectSP (new CommandObjectTargetModulesDumpSections (interpreter)));
2564 LoadSubCommand ("symfile", CommandObjectSP (new CommandObjectTargetModulesDumpSymfile (interpreter)));
2565 LoadSubCommand ("line-table", CommandObjectSP (new CommandObjectTargetModulesDumpLineTable (interpreter)));
2566 }
2567
2568 virtual
2569 ~CommandObjectTargetModulesDump()
2570 {
2571 }
2572};
2573
Jim Inghamda26bd22012-06-08 21:56:10 +00002574class CommandObjectTargetModulesAdd : public CommandObjectParsed
Greg Claytone1f50b92011-05-03 22:09:39 +00002575{
2576public:
2577 CommandObjectTargetModulesAdd (CommandInterpreter &interpreter) :
Jim Inghamda26bd22012-06-08 21:56:10 +00002578 CommandObjectParsed (interpreter,
2579 "target modules add",
2580 "Add a new module to the current target's modules.",
Greg Clayton1649a722012-11-29 22:16:27 +00002581 "target modules add [<module>]"),
Greg Claytonec9c2d22012-11-30 19:05:35 +00002582 m_option_group (interpreter),
2583 m_symbol_file (LLDB_OPT_SET_1, false, "symfile", 's', 0, eArgTypeFilename, "Fullpath to a stand alone debug symbols file for when debug symbols are not in the executable.")
Greg Claytone1f50b92011-05-03 22:09:39 +00002584 {
Greg Clayton1649a722012-11-29 22:16:27 +00002585 m_option_group.Append (&m_uuid_option_group, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
Greg Claytonec9c2d22012-11-30 19:05:35 +00002586 m_option_group.Append (&m_symbol_file, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
Greg Clayton1649a722012-11-29 22:16:27 +00002587 m_option_group.Finalize();
Greg Claytone1f50b92011-05-03 22:09:39 +00002588 }
2589
2590 virtual
2591 ~CommandObjectTargetModulesAdd ()
2592 {
2593 }
Greg Clayton1649a722012-11-29 22:16:27 +00002594
2595 virtual Options *
2596 GetOptions ()
2597 {
2598 return &m_option_group;
2599 }
Greg Claytone1f50b92011-05-03 22:09:39 +00002600
Jim Inghamda26bd22012-06-08 21:56:10 +00002601 int
2602 HandleArgumentCompletion (Args &input,
2603 int &cursor_index,
2604 int &cursor_char_position,
2605 OptionElementVector &opt_element_vector,
2606 int match_start_point,
2607 int max_return_elements,
2608 bool &word_complete,
2609 StringList &matches)
2610 {
2611 std::string completion_str (input.GetArgumentAtIndex(cursor_index));
2612 completion_str.erase (cursor_char_position);
2613
2614 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
2615 CommandCompletions::eDiskFileCompletion,
2616 completion_str.c_str(),
2617 match_start_point,
2618 max_return_elements,
2619 NULL,
2620 word_complete,
2621 matches);
2622 return matches.GetSize();
2623 }
2624
2625protected:
Greg Clayton1649a722012-11-29 22:16:27 +00002626
2627 OptionGroupOptions m_option_group;
2628 OptionGroupUUID m_uuid_option_group;
Greg Claytonec9c2d22012-11-30 19:05:35 +00002629 OptionGroupFile m_symbol_file;
Greg Clayton1649a722012-11-29 22:16:27 +00002630
2631
Greg Claytone1f50b92011-05-03 22:09:39 +00002632 virtual bool
Jim Inghamda26bd22012-06-08 21:56:10 +00002633 DoExecute (Args& args,
Greg Claytone1f50b92011-05-03 22:09:39 +00002634 CommandReturnObject &result)
2635 {
2636 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
2637 if (target == NULL)
2638 {
2639 result.AppendError ("invalid target, create a debug target using the 'target create' command");
2640 result.SetStatus (eReturnStatusFailed);
2641 return false;
2642 }
2643 else
2644 {
2645 const size_t argc = args.GetArgumentCount();
2646 if (argc == 0)
2647 {
Greg Clayton1649a722012-11-29 22:16:27 +00002648 if (m_uuid_option_group.GetOptionValue ().OptionWasSet())
2649 {
2650 // We are given a UUID only, go locate the file
2651 ModuleSpec module_spec;
2652 module_spec.GetUUID() = m_uuid_option_group.GetOptionValue ().GetCurrentValue();
Greg Claytonec9c2d22012-11-30 19:05:35 +00002653 if (m_symbol_file.GetOptionValue().OptionWasSet())
2654 module_spec.GetSymbolFileSpec() = m_symbol_file.GetOptionValue().GetCurrentValue();
Greg Clayton1649a722012-11-29 22:16:27 +00002655 if (Symbols::DownloadObjectAndSymbolFile (module_spec))
2656 {
2657 ModuleSP module_sp (target->GetSharedModule (module_spec));
2658 if (module_sp)
2659 {
2660 result.SetStatus (eReturnStatusSuccessFinishResult);
2661 return true;
2662 }
2663 else
2664 {
2665 StreamString strm;
2666 module_spec.GetUUID().Dump (&strm);
2667 if (module_spec.GetFileSpec())
2668 {
2669 if (module_spec.GetSymbolFileSpec())
2670 {
2671 result.AppendErrorWithFormat ("Unable to create the executable or symbol file with UUID %s with path %s/%s and symbol file %s/%s",
2672 strm.GetString().c_str(),
2673 module_spec.GetFileSpec().GetDirectory().GetCString(),
2674 module_spec.GetFileSpec().GetFilename().GetCString(),
2675 module_spec.GetSymbolFileSpec().GetDirectory().GetCString(),
2676 module_spec.GetSymbolFileSpec().GetFilename().GetCString());
2677 }
2678 else
2679 {
2680 result.AppendErrorWithFormat ("Unable to create the executable or symbol file with UUID %s with path %s/%s",
2681 strm.GetString().c_str(),
2682 module_spec.GetFileSpec().GetDirectory().GetCString(),
2683 module_spec.GetFileSpec().GetFilename().GetCString());
2684 }
2685 }
2686 else
2687 {
2688 result.AppendErrorWithFormat ("Unable to create the executable or symbol file with UUID %s",
2689 strm.GetString().c_str());
2690 }
2691 result.SetStatus (eReturnStatusFailed);
2692 return false;
2693 }
2694 }
2695 else
2696 {
2697 StreamString strm;
2698 module_spec.GetUUID().Dump (&strm);
2699 result.AppendErrorWithFormat ("Unable to locate the executable or symbol file with UUID %s", strm.GetString().c_str());
2700 result.SetStatus (eReturnStatusFailed);
2701 return false;
2702 }
2703 }
2704 else
2705 {
2706 result.AppendError ("one or more executable image paths must be specified");
2707 result.SetStatus (eReturnStatusFailed);
2708 return false;
2709 }
Greg Claytone1f50b92011-05-03 22:09:39 +00002710 }
2711 else
2712 {
2713 for (size_t i=0; i<argc; ++i)
2714 {
2715 const char *path = args.GetArgumentAtIndex(i);
2716 if (path)
2717 {
2718 FileSpec file_spec(path, true);
Greg Claytone1f50b92011-05-03 22:09:39 +00002719 if (file_spec.Exists())
2720 {
Greg Clayton444fe992012-02-26 05:51:37 +00002721 ModuleSpec module_spec (file_spec);
Greg Clayton1649a722012-11-29 22:16:27 +00002722 if (m_uuid_option_group.GetOptionValue ().OptionWasSet())
2723 module_spec.GetUUID() = m_uuid_option_group.GetOptionValue ().GetCurrentValue();
Greg Claytonec9c2d22012-11-30 19:05:35 +00002724 if (m_symbol_file.GetOptionValue().OptionWasSet())
2725 module_spec.GetSymbolFileSpec() = m_symbol_file.GetOptionValue().GetCurrentValue();
Greg Clayton1649a722012-11-29 22:16:27 +00002726 Error error;
2727 ModuleSP module_sp (target->GetSharedModule (module_spec, &error));
Greg Claytone1f50b92011-05-03 22:09:39 +00002728 if (!module_sp)
2729 {
Greg Clayton1649a722012-11-29 22:16:27 +00002730 const char *error_cstr = error.AsCString();
2731 if (error_cstr)
2732 result.AppendError (error_cstr);
2733 else
2734 result.AppendErrorWithFormat ("unsupported module: %s", path);
Greg Claytone1f50b92011-05-03 22:09:39 +00002735 result.SetStatus (eReturnStatusFailed);
2736 return false;
2737 }
Jason Molenda36f6fb92011-08-02 23:28:55 +00002738 result.SetStatus (eReturnStatusSuccessFinishResult);
Greg Claytone1f50b92011-05-03 22:09:39 +00002739 }
2740 else
2741 {
2742 char resolved_path[PATH_MAX];
2743 result.SetStatus (eReturnStatusFailed);
2744 if (file_spec.GetPath (resolved_path, sizeof(resolved_path)))
2745 {
2746 if (strcmp (resolved_path, path) != 0)
2747 {
2748 result.AppendErrorWithFormat ("invalid module path '%s' with resolved path '%s'\n", path, resolved_path);
2749 break;
2750 }
2751 }
2752 result.AppendErrorWithFormat ("invalid module path '%s'\n", path);
2753 break;
2754 }
2755 }
2756 }
2757 }
2758 }
2759 return result.Succeeded();
2760 }
2761
Greg Claytone1f50b92011-05-03 22:09:39 +00002762};
2763
2764class CommandObjectTargetModulesLoad : public CommandObjectTargetModulesModuleAutoComplete
2765{
2766public:
2767 CommandObjectTargetModulesLoad (CommandInterpreter &interpreter) :
2768 CommandObjectTargetModulesModuleAutoComplete (interpreter,
2769 "target modules load",
2770 "Set the load addresses for one or more sections in a target module.",
2771 "target modules load [--file <module> --uuid <uuid>] <sect-name> <address> [<sect-name> <address> ....]"),
2772 m_option_group (interpreter),
Sean Callanan9a91ef62012-10-24 01:12:14 +00002773 m_file_option (LLDB_OPT_SET_1, false, "file", 'f', 0, eArgTypeFilename, "Fullpath or basename for module to load."),
Greg Claytone1f50b92011-05-03 22:09:39 +00002774 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)
2775 {
2776 m_option_group.Append (&m_uuid_option_group, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
2777 m_option_group.Append (&m_file_option, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
2778 m_option_group.Append (&m_slide_option, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
2779 m_option_group.Finalize();
2780 }
2781
2782 virtual
2783 ~CommandObjectTargetModulesLoad ()
2784 {
2785 }
2786
Jim Inghamda26bd22012-06-08 21:56:10 +00002787 virtual Options *
2788 GetOptions ()
2789 {
2790 return &m_option_group;
2791 }
2792
2793protected:
Greg Claytone1f50b92011-05-03 22:09:39 +00002794 virtual bool
Jim Inghamda26bd22012-06-08 21:56:10 +00002795 DoExecute (Args& args,
Greg Claytone1f50b92011-05-03 22:09:39 +00002796 CommandReturnObject &result)
2797 {
2798 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
2799 if (target == NULL)
2800 {
2801 result.AppendError ("invalid target, create a debug target using the 'target create' command");
2802 result.SetStatus (eReturnStatusFailed);
2803 return false;
2804 }
2805 else
2806 {
2807 const size_t argc = args.GetArgumentCount();
Greg Clayton444fe992012-02-26 05:51:37 +00002808 ModuleSpec module_spec;
2809 bool search_using_module_spec = false;
Greg Claytone1f50b92011-05-03 22:09:39 +00002810 if (m_file_option.GetOptionValue().OptionWasSet())
Greg Clayton444fe992012-02-26 05:51:37 +00002811 {
2812 search_using_module_spec = true;
2813 module_spec.GetFileSpec() = m_file_option.GetOptionValue().GetCurrentValue();
2814 }
Greg Claytone1f50b92011-05-03 22:09:39 +00002815
2816 if (m_uuid_option_group.GetOptionValue().OptionWasSet())
Greg Clayton444fe992012-02-26 05:51:37 +00002817 {
2818 search_using_module_spec = true;
2819 module_spec.GetUUID() = m_uuid_option_group.GetOptionValue().GetCurrentValue();
2820 }
Greg Claytone1f50b92011-05-03 22:09:39 +00002821
Greg Clayton444fe992012-02-26 05:51:37 +00002822 if (search_using_module_spec)
Greg Claytone1f50b92011-05-03 22:09:39 +00002823 {
2824
2825 ModuleList matching_modules;
Greg Clayton444fe992012-02-26 05:51:37 +00002826 const size_t num_matches = target->GetImages().FindModules (module_spec, matching_modules);
Greg Claytone1f50b92011-05-03 22:09:39 +00002827
2828 char path[PATH_MAX];
2829 if (num_matches == 1)
2830 {
2831 Module *module = matching_modules.GetModulePointerAtIndex(0);
2832 if (module)
2833 {
2834 ObjectFile *objfile = module->GetObjectFile();
2835 if (objfile)
2836 {
2837 SectionList *section_list = objfile->GetSectionList();
2838 if (section_list)
2839 {
Greg Clayton9ab696e2012-03-27 21:10:07 +00002840 bool changed = false;
Greg Claytone1f50b92011-05-03 22:09:39 +00002841 if (argc == 0)
2842 {
2843 if (m_slide_option.GetOptionValue().OptionWasSet())
2844 {
Greg Clayton9ab696e2012-03-27 21:10:07 +00002845 const addr_t slide = m_slide_option.GetOptionValue().GetCurrentValue();
2846 module->SetLoadAddress (*target, slide, changed);
Greg Claytone1f50b92011-05-03 22:09:39 +00002847 }
2848 else
2849 {
2850 result.AppendError ("one or more section name + load address pair must be specified");
2851 result.SetStatus (eReturnStatusFailed);
2852 return false;
2853 }
2854 }
2855 else
2856 {
2857 if (m_slide_option.GetOptionValue().OptionWasSet())
2858 {
2859 result.AppendError ("The \"--slide <offset>\" option can't be used in conjunction with setting section load addresses.\n");
2860 result.SetStatus (eReturnStatusFailed);
2861 return false;
2862 }
2863
2864 for (size_t i=0; i<argc; i += 2)
2865 {
2866 const char *sect_name = args.GetArgumentAtIndex(i);
2867 const char *load_addr_cstr = args.GetArgumentAtIndex(i+1);
2868 if (sect_name && load_addr_cstr)
2869 {
2870 ConstString const_sect_name(sect_name);
2871 bool success = false;
2872 addr_t load_addr = Args::StringToUInt64(load_addr_cstr, LLDB_INVALID_ADDRESS, 0, &success);
2873 if (success)
2874 {
2875 SectionSP section_sp (section_list->FindSectionByName(const_sect_name));
2876 if (section_sp)
2877 {
Greg Clayton9ab696e2012-03-27 21:10:07 +00002878 if (section_sp->IsThreadSpecific())
2879 {
2880 result.AppendErrorWithFormat ("thread specific sections are not yet supported (section '%s')\n", sect_name);
2881 result.SetStatus (eReturnStatusFailed);
2882 break;
2883 }
2884 else
2885 {
Greg Clayton545762f2012-07-07 01:24:12 +00002886 if (target->GetSectionLoadList().SetSectionLoadAddress (section_sp, load_addr))
Greg Clayton9ab696e2012-03-27 21:10:07 +00002887 changed = true;
Daniel Malea5f35a4b2012-11-29 21:49:15 +00002888 result.AppendMessageWithFormat("section '%s' loaded at 0x%" PRIx64 "\n", sect_name, load_addr);
Greg Clayton9ab696e2012-03-27 21:10:07 +00002889 }
Greg Claytone1f50b92011-05-03 22:09:39 +00002890 }
2891 else
2892 {
2893 result.AppendErrorWithFormat ("no section found that matches the section name '%s'\n", sect_name);
2894 result.SetStatus (eReturnStatusFailed);
2895 break;
2896 }
2897 }
2898 else
2899 {
2900 result.AppendErrorWithFormat ("invalid load address string '%s'\n", load_addr_cstr);
2901 result.SetStatus (eReturnStatusFailed);
2902 break;
2903 }
2904 }
2905 else
2906 {
2907 if (sect_name)
2908 result.AppendError ("section names must be followed by a load address.\n");
2909 else
2910 result.AppendError ("one or more section name + load address pair must be specified.\n");
2911 result.SetStatus (eReturnStatusFailed);
2912 break;
2913 }
2914 }
2915 }
Greg Clayton9ab696e2012-03-27 21:10:07 +00002916
2917 if (changed)
2918 target->ModulesDidLoad (matching_modules);
Greg Claytone1f50b92011-05-03 22:09:39 +00002919 }
2920 else
2921 {
2922 module->GetFileSpec().GetPath (path, sizeof(path));
2923 result.AppendErrorWithFormat ("no sections in object file '%s'\n", path);
2924 result.SetStatus (eReturnStatusFailed);
2925 }
2926 }
2927 else
2928 {
2929 module->GetFileSpec().GetPath (path, sizeof(path));
2930 result.AppendErrorWithFormat ("no object file for module '%s'\n", path);
2931 result.SetStatus (eReturnStatusFailed);
2932 }
2933 }
2934 else
2935 {
Jim Ingham6f01c932012-10-12 17:34:26 +00002936 FileSpec *module_spec_file = module_spec.GetFileSpecPtr();
2937 if (module_spec_file)
2938 {
2939 module_spec_file->GetPath (path, sizeof(path));
2940 result.AppendErrorWithFormat ("invalid module '%s'.\n", path);
2941 }
2942 else
2943 result.AppendError ("no module spec");
Greg Claytone1f50b92011-05-03 22:09:39 +00002944 result.SetStatus (eReturnStatusFailed);
2945 }
2946 }
2947 else
2948 {
2949 char uuid_cstr[64];
Greg Clayton444fe992012-02-26 05:51:37 +00002950
2951 if (module_spec.GetFileSpec())
2952 module_spec.GetFileSpec().GetPath (path, sizeof(path));
Greg Claytone1f50b92011-05-03 22:09:39 +00002953 else
2954 path[0] = '\0';
2955
Greg Clayton444fe992012-02-26 05:51:37 +00002956 if (module_spec.GetUUIDPtr())
2957 module_spec.GetUUID().GetAsCString(uuid_cstr, sizeof(uuid_cstr));
Greg Claytone1f50b92011-05-03 22:09:39 +00002958 else
2959 uuid_cstr[0] = '\0';
2960 if (num_matches > 1)
2961 {
2962 result.AppendErrorWithFormat ("multiple modules match%s%s%s%s:\n",
2963 path[0] ? " file=" : "",
2964 path,
2965 uuid_cstr[0] ? " uuid=" : "",
2966 uuid_cstr);
2967 for (size_t i=0; i<num_matches; ++i)
2968 {
2969 if (matching_modules.GetModulePointerAtIndex(i)->GetFileSpec().GetPath (path, sizeof(path)))
2970 result.AppendMessageWithFormat("%s\n", path);
2971 }
2972 }
2973 else
2974 {
2975 result.AppendErrorWithFormat ("no modules were found that match%s%s%s%s.\n",
2976 path[0] ? " file=" : "",
2977 path,
2978 uuid_cstr[0] ? " uuid=" : "",
2979 uuid_cstr);
2980 }
2981 result.SetStatus (eReturnStatusFailed);
2982 }
2983 }
2984 else
2985 {
2986 result.AppendError ("either the \"--file <module>\" or the \"--uuid <uuid>\" option must be specified.\n");
2987 result.SetStatus (eReturnStatusFailed);
2988 return false;
2989 }
2990 }
2991 return result.Succeeded();
2992 }
2993
Greg Claytone1f50b92011-05-03 22:09:39 +00002994 OptionGroupOptions m_option_group;
2995 OptionGroupUUID m_uuid_option_group;
2996 OptionGroupFile m_file_option;
2997 OptionGroupUInt64 m_slide_option;
2998};
2999
3000//----------------------------------------------------------------------
3001// List images with associated information
3002//----------------------------------------------------------------------
Jim Inghamda26bd22012-06-08 21:56:10 +00003003class CommandObjectTargetModulesList : public CommandObjectParsed
Greg Claytone1f50b92011-05-03 22:09:39 +00003004{
3005public:
3006
3007 class CommandOptions : public Options
3008 {
3009 public:
3010
3011 CommandOptions (CommandInterpreter &interpreter) :
Greg Clayton899025f2011-08-09 00:01:09 +00003012 Options(interpreter),
Jim Ingham6bdea822011-10-24 18:36:33 +00003013 m_format_array(),
Daniel Dunbar97c89572011-10-31 22:50:49 +00003014 m_use_global_module_list (false),
Jim Ingham6bdea822011-10-24 18:36:33 +00003015 m_module_addr (LLDB_INVALID_ADDRESS)
Greg Claytone1f50b92011-05-03 22:09:39 +00003016 {
3017 }
3018
3019 virtual
3020 ~CommandOptions ()
3021 {
3022 }
3023
3024 virtual Error
3025 SetOptionValue (uint32_t option_idx, const char *option_arg)
3026 {
Greg Clayton6475c422012-12-04 00:32:51 +00003027 const int short_option = m_getopt_table[option_idx].val;
Greg Clayton899025f2011-08-09 00:01:09 +00003028 if (short_option == 'g')
3029 {
3030 m_use_global_module_list = true;
3031 }
Jim Ingham6bdea822011-10-24 18:36:33 +00003032 else if (short_option == 'a')
3033 {
3034 bool success;
3035 m_module_addr = Args::StringToAddress(option_arg, LLDB_INVALID_ADDRESS, &success);
3036 if (!success)
3037 {
3038 Error error;
Greg Clayton9c236732011-10-26 00:56:27 +00003039 error.SetErrorStringWithFormat("invalid address: \"%s\"", option_arg);
Jim Ingham6bdea822011-10-24 18:36:33 +00003040 }
3041 }
Greg Clayton899025f2011-08-09 00:01:09 +00003042 else
3043 {
3044 uint32_t width = 0;
3045 if (option_arg)
3046 width = strtoul (option_arg, NULL, 0);
3047 m_format_array.push_back(std::make_pair(short_option, width));
3048 }
Greg Claytone1f50b92011-05-03 22:09:39 +00003049 Error error;
3050 return error;
3051 }
3052
3053 void
3054 OptionParsingStarting ()
3055 {
3056 m_format_array.clear();
Greg Clayton899025f2011-08-09 00:01:09 +00003057 m_use_global_module_list = false;
Jim Ingham6bdea822011-10-24 18:36:33 +00003058 m_module_addr = LLDB_INVALID_ADDRESS;
Greg Claytone1f50b92011-05-03 22:09:39 +00003059 }
3060
3061 const OptionDefinition*
3062 GetDefinitions ()
3063 {
3064 return g_option_table;
3065 }
3066
3067 // Options table: Required for subclasses of Options.
3068
3069 static OptionDefinition g_option_table[];
3070
3071 // Instance variables to hold the values for command options.
3072 typedef std::vector< std::pair<char, uint32_t> > FormatWidthCollection;
3073 FormatWidthCollection m_format_array;
Greg Clayton899025f2011-08-09 00:01:09 +00003074 bool m_use_global_module_list;
Jim Ingham6bdea822011-10-24 18:36:33 +00003075 lldb::addr_t m_module_addr;
Greg Claytone1f50b92011-05-03 22:09:39 +00003076 };
3077
3078 CommandObjectTargetModulesList (CommandInterpreter &interpreter) :
Jim Inghamda26bd22012-06-08 21:56:10 +00003079 CommandObjectParsed (interpreter,
3080 "target modules list",
3081 "List current executable and dependent shared library images.",
3082 "target modules list [<cmd-options>]"),
Greg Claytone1f50b92011-05-03 22:09:39 +00003083 m_options (interpreter)
3084 {
3085 }
3086
3087 virtual
3088 ~CommandObjectTargetModulesList ()
3089 {
3090 }
3091
3092 virtual
3093 Options *
3094 GetOptions ()
3095 {
3096 return &m_options;
3097 }
3098
Jim Inghamda26bd22012-06-08 21:56:10 +00003099protected:
Greg Claytone1f50b92011-05-03 22:09:39 +00003100 virtual bool
Jim Inghamda26bd22012-06-08 21:56:10 +00003101 DoExecute (Args& command,
Greg Claytone1f50b92011-05-03 22:09:39 +00003102 CommandReturnObject &result)
3103 {
3104 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Greg Clayton153ccd72011-08-10 02:10:13 +00003105 const bool use_global_module_list = m_options.m_use_global_module_list;
Greg Clayton11fb9212012-06-27 20:26:19 +00003106 // Define a local module list here to ensure it lives longer than any "locker"
3107 // object which might lock its contents below (through the "module_list_ptr"
3108 // variable).
3109 ModuleList module_list;
Greg Clayton153ccd72011-08-10 02:10:13 +00003110 if (target == NULL && use_global_module_list == false)
Greg Claytone1f50b92011-05-03 22:09:39 +00003111 {
3112 result.AppendError ("invalid target, create a debug target using the 'target create' command");
3113 result.SetStatus (eReturnStatusFailed);
3114 return false;
3115 }
3116 else
3117 {
Greg Clayton153ccd72011-08-10 02:10:13 +00003118 if (target)
3119 {
3120 uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize();
3121 result.GetOutputStream().SetAddressByteSize(addr_byte_size);
3122 result.GetErrorStream().SetAddressByteSize(addr_byte_size);
3123 }
Greg Claytone1f50b92011-05-03 22:09:39 +00003124 // Dump all sections for all modules images
Jim Ingham6bdea822011-10-24 18:36:33 +00003125 Stream &strm = result.GetOutputStream();
3126
3127 if (m_options.m_module_addr != LLDB_INVALID_ADDRESS)
3128 {
3129 if (target)
3130 {
3131 Address module_address;
3132 if (module_address.SetLoadAddress(m_options.m_module_addr, target))
3133 {
Greg Clayton3508c382012-02-24 01:59:29 +00003134 ModuleSP module_sp (module_address.GetModule());
3135 if (module_sp)
Jim Ingham6bdea822011-10-24 18:36:33 +00003136 {
Greg Clayton3508c382012-02-24 01:59:29 +00003137 PrintModule (target, module_sp.get(), UINT32_MAX, 0, strm);
Jim Ingham6bdea822011-10-24 18:36:33 +00003138 result.SetStatus (eReturnStatusSuccessFinishResult);
3139 }
3140 else
3141 {
Daniel Malea5f35a4b2012-11-29 21:49:15 +00003142 result.AppendError ("Couldn't find module matching address: 0x%" PRIx64 ".", m_options.m_module_addr);
Jim Ingham6bdea822011-10-24 18:36:33 +00003143 result.SetStatus (eReturnStatusFailed);
3144 }
3145 }
3146 else
3147 {
Daniel Malea5f35a4b2012-11-29 21:49:15 +00003148 result.AppendError ("Couldn't find module containing address: 0x%" PRIx64 ".", m_options.m_module_addr);
Jim Ingham6bdea822011-10-24 18:36:33 +00003149 result.SetStatus (eReturnStatusFailed);
3150 }
3151 }
3152 else
3153 {
3154 result.AppendError ("Can only look up modules by address with a valid target.");
3155 result.SetStatus (eReturnStatusFailed);
3156 }
3157 return result.Succeeded();
3158 }
3159
Jim Ingham93367902012-05-30 02:19:25 +00003160 uint32_t num_modules = 0;
3161 Mutex::Locker locker; // This locker will be locked on the mutex in module_list_ptr if it is non-NULL.
3162 // Otherwise it will lock the AllocationModuleCollectionMutex when accessing
3163 // the global module list directly.
Enrico Granata146d9522012-11-08 02:22:02 +00003164 const ModuleList *module_list_ptr = NULL;
Greg Clayton2ad894b2012-05-15 18:43:44 +00003165 const size_t argc = command.GetArgumentCount();
3166 if (argc == 0)
Greg Clayton899025f2011-08-09 00:01:09 +00003167 {
Greg Clayton2ad894b2012-05-15 18:43:44 +00003168 if (use_global_module_list)
3169 {
3170 locker.Lock (Module::GetAllocationModuleCollectionMutex());
3171 num_modules = Module::GetNumberAllocatedModules();
3172 }
3173 else
3174 {
3175 module_list_ptr = &target->GetImages();
Greg Clayton2ad894b2012-05-15 18:43:44 +00003176 }
Greg Clayton899025f2011-08-09 00:01:09 +00003177 }
3178 else
Greg Clayton2ad894b2012-05-15 18:43:44 +00003179 {
3180 for (size_t i=0; i<argc; ++i)
3181 {
3182 // Dump specified images (by basename or fullpath)
3183 const char *arg_cstr = command.GetArgumentAtIndex(i);
3184 const size_t num_matches = FindModulesByName (target, arg_cstr, module_list, use_global_module_list);
3185 if (num_matches == 0)
3186 {
3187 if (argc == 1)
3188 {
3189 result.AppendErrorWithFormat ("no modules found that match '%s'", arg_cstr);
3190 result.SetStatus (eReturnStatusFailed);
3191 return false;
3192 }
3193 }
3194 }
3195
Greg Clayton2ad894b2012-05-15 18:43:44 +00003196 module_list_ptr = &module_list;
3197 }
Jim Ingham93367902012-05-30 02:19:25 +00003198
3199 if (module_list_ptr != NULL)
3200 {
3201 locker.Lock(module_list_ptr->GetMutex());
3202 num_modules = module_list_ptr->GetSize();
3203 }
Greg Clayton899025f2011-08-09 00:01:09 +00003204
Greg Claytone1f50b92011-05-03 22:09:39 +00003205 if (num_modules > 0)
Jim Ingham6bdea822011-10-24 18:36:33 +00003206 {
Greg Claytone1f50b92011-05-03 22:09:39 +00003207 for (uint32_t image_idx = 0; image_idx<num_modules; ++image_idx)
3208 {
Greg Clayton153ccd72011-08-10 02:10:13 +00003209 ModuleSP module_sp;
Greg Clayton899025f2011-08-09 00:01:09 +00003210 Module *module;
Greg Clayton2ad894b2012-05-15 18:43:44 +00003211 if (module_list_ptr)
Greg Clayton899025f2011-08-09 00:01:09 +00003212 {
Jim Ingham93367902012-05-30 02:19:25 +00003213 module_sp = module_list_ptr->GetModuleAtIndexUnlocked(image_idx);
Greg Clayton2ad894b2012-05-15 18:43:44 +00003214 module = module_sp.get();
Greg Clayton899025f2011-08-09 00:01:09 +00003215 }
3216 else
3217 {
Greg Clayton2ad894b2012-05-15 18:43:44 +00003218 module = Module::GetAllocatedModuleAtIndex(image_idx);
3219 module_sp = module->shared_from_this();
Greg Clayton899025f2011-08-09 00:01:09 +00003220 }
Jim Ingham6bdea822011-10-24 18:36:33 +00003221
Greg Claytonb5a8f142012-02-05 02:38:54 +00003222 int indent = strm.Printf("[%3u] ", image_idx);
3223 PrintModule (target, module, image_idx, indent, strm);
Greg Clayton153ccd72011-08-10 02:10:13 +00003224
Greg Claytone1f50b92011-05-03 22:09:39 +00003225 }
3226 result.SetStatus (eReturnStatusSuccessFinishResult);
3227 }
3228 else
3229 {
Greg Clayton2ad894b2012-05-15 18:43:44 +00003230 if (argc)
3231 {
3232 if (use_global_module_list)
3233 result.AppendError ("the global module list has no matching modules");
3234 else
3235 result.AppendError ("the target has no matching modules");
3236 }
Greg Clayton153ccd72011-08-10 02:10:13 +00003237 else
Greg Clayton2ad894b2012-05-15 18:43:44 +00003238 {
3239 if (use_global_module_list)
3240 result.AppendError ("the global module list is empty");
3241 else
3242 result.AppendError ("the target has no associated executable images");
3243 }
Greg Claytone1f50b92011-05-03 22:09:39 +00003244 result.SetStatus (eReturnStatusFailed);
3245 return false;
3246 }
3247 }
3248 return result.Succeeded();
3249 }
Jim Ingham6bdea822011-10-24 18:36:33 +00003250
3251 void
Greg Claytonb5a8f142012-02-05 02:38:54 +00003252 PrintModule (Target *target, Module *module, uint32_t idx, int indent, Stream &strm)
Jim Ingham6bdea822011-10-24 18:36:33 +00003253 {
3254
Jim Ingham6f01c932012-10-12 17:34:26 +00003255 if (module == NULL)
3256 {
3257 strm.PutCString("Null module");
3258 return;
3259 }
3260
Jim Ingham6bdea822011-10-24 18:36:33 +00003261 bool dump_object_name = false;
3262 if (m_options.m_format_array.empty())
3263 {
Greg Claytonb5a8f142012-02-05 02:38:54 +00003264 m_options.m_format_array.push_back(std::make_pair('u', 0));
3265 m_options.m_format_array.push_back(std::make_pair('h', 0));
3266 m_options.m_format_array.push_back(std::make_pair('f', 0));
3267 m_options.m_format_array.push_back(std::make_pair('S', 0));
Jim Ingham6bdea822011-10-24 18:36:33 +00003268 }
Greg Claytonb5a8f142012-02-05 02:38:54 +00003269 const size_t num_entries = m_options.m_format_array.size();
3270 bool print_space = false;
3271 for (size_t i=0; i<num_entries; ++i)
Jim Ingham6bdea822011-10-24 18:36:33 +00003272 {
Greg Claytonb5a8f142012-02-05 02:38:54 +00003273 if (print_space)
3274 strm.PutChar(' ');
3275 print_space = true;
3276 const char format_char = m_options.m_format_array[i].first;
3277 uint32_t width = m_options.m_format_array[i].second;
3278 switch (format_char)
Jim Ingham6bdea822011-10-24 18:36:33 +00003279 {
Greg Claytonb5a8f142012-02-05 02:38:54 +00003280 case 'A':
3281 DumpModuleArchitecture (strm, module, false, width);
3282 break;
3283
3284 case 't':
3285 DumpModuleArchitecture (strm, module, true, width);
3286 break;
3287
3288 case 'f':
3289 DumpFullpath (strm, &module->GetFileSpec(), width);
3290 dump_object_name = true;
3291 break;
3292
3293 case 'd':
3294 DumpDirectory (strm, &module->GetFileSpec(), width);
3295 break;
3296
3297 case 'b':
3298 DumpBasename (strm, &module->GetFileSpec(), width);
3299 dump_object_name = true;
3300 break;
3301
3302 case 'h':
3303 case 'o':
3304 // Image header address
3305 {
3306 uint32_t addr_nibble_width = target ? (target->GetArchitecture().GetAddressByteSize() * 2) : 16;
Jim Ingham6bdea822011-10-24 18:36:33 +00003307
Greg Claytonb5a8f142012-02-05 02:38:54 +00003308 ObjectFile *objfile = module->GetObjectFile ();
3309 if (objfile)
Jim Ingham6bdea822011-10-24 18:36:33 +00003310 {
Greg Claytonb5a8f142012-02-05 02:38:54 +00003311 Address header_addr(objfile->GetHeaderAddress());
3312 if (header_addr.IsValid())
Jim Ingham6bdea822011-10-24 18:36:33 +00003313 {
Greg Claytonb5a8f142012-02-05 02:38:54 +00003314 if (target && !target->GetSectionLoadList().IsEmpty())
Jim Ingham6bdea822011-10-24 18:36:33 +00003315 {
Greg Claytonb5a8f142012-02-05 02:38:54 +00003316 lldb::addr_t header_load_addr = header_addr.GetLoadAddress (target);
3317 if (header_load_addr == LLDB_INVALID_ADDRESS)
3318 {
3319 header_addr.Dump (&strm, target, Address::DumpStyleModuleWithFileAddress, Address::DumpStyleFileAddress);
3320 }
Jim Ingham6bdea822011-10-24 18:36:33 +00003321 else
Greg Claytonb5a8f142012-02-05 02:38:54 +00003322 {
3323 if (format_char == 'o')
3324 {
3325 // Show the offset of slide for the image
Daniel Malea5f35a4b2012-11-29 21:49:15 +00003326 strm.Printf ("0x%*.*" PRIx64, addr_nibble_width, addr_nibble_width, header_load_addr - header_addr.GetFileAddress());
Greg Claytonb5a8f142012-02-05 02:38:54 +00003327 }
3328 else
3329 {
3330 // Show the load address of the image
Daniel Malea5f35a4b2012-11-29 21:49:15 +00003331 strm.Printf ("0x%*.*" PRIx64, addr_nibble_width, addr_nibble_width, header_load_addr);
Greg Claytonb5a8f142012-02-05 02:38:54 +00003332 }
3333 }
Jim Ingham6bdea822011-10-24 18:36:33 +00003334 break;
3335 }
Greg Claytonb5a8f142012-02-05 02:38:54 +00003336 // The address was valid, but the image isn't loaded, output the address in an appropriate format
3337 header_addr.Dump (&strm, target, Address::DumpStyleFileAddress);
3338 break;
Jim Ingham6bdea822011-10-24 18:36:33 +00003339 }
Jim Ingham6bdea822011-10-24 18:36:33 +00003340 }
Greg Claytonb5a8f142012-02-05 02:38:54 +00003341 strm.Printf ("%*s", addr_nibble_width + 2, "");
3342 }
3343 break;
3344 case 'r':
3345 {
3346 uint32_t ref_count = 0;
3347 ModuleSP module_sp (module->shared_from_this());
3348 if (module_sp)
3349 {
3350 // Take one away to make sure we don't count our local "module_sp"
3351 ref_count = module_sp.use_count() - 1;
3352 }
3353 if (width)
3354 strm.Printf("{%*u}", width, ref_count);
3355 else
3356 strm.Printf("{%u}", ref_count);
3357 }
3358 break;
Jim Ingham6bdea822011-10-24 18:36:33 +00003359
Greg Claytonb5a8f142012-02-05 02:38:54 +00003360 case 's':
3361 case 'S':
3362 {
3363 SymbolVendor *symbol_vendor = module->GetSymbolVendor();
3364 if (symbol_vendor)
3365 {
3366 SymbolFile *symbol_file = symbol_vendor->GetSymbolFile();
3367 if (symbol_file)
3368 {
3369 if (format_char == 'S')
3370 {
3371 FileSpec &symfile_spec = symbol_file->GetObjectFile()->GetFileSpec();
3372 // Dump symbol file only if different from module file
3373 if (!symfile_spec || symfile_spec == module->GetFileSpec())
3374 {
3375 print_space = false;
3376 break;
3377 }
3378 // Add a newline and indent past the index
3379 strm.Printf ("\n%*s", indent, "");
3380 }
3381 DumpFullpath (strm, &symbol_file->GetObjectFile()->GetFileSpec(), width);
3382 dump_object_name = true;
3383 break;
3384 }
3385 }
3386 strm.Printf("%.*s", width, "<NONE>");
3387 }
3388 break;
3389
3390 case 'm':
3391 module->GetModificationTime().Dump(&strm, width);
3392 break;
Jim Ingham6bdea822011-10-24 18:36:33 +00003393
Greg Claytonb5a8f142012-02-05 02:38:54 +00003394 case 'p':
3395 strm.Printf("%p", module);
3396 break;
3397
3398 case 'u':
3399 DumpModuleUUID(strm, module);
3400 break;
3401
3402 default:
3403 break;
Jim Ingham6bdea822011-10-24 18:36:33 +00003404 }
Greg Claytonb5a8f142012-02-05 02:38:54 +00003405
3406 }
3407 if (dump_object_name)
3408 {
3409 const char *object_name = module->GetObjectName().GetCString();
3410 if (object_name)
3411 strm.Printf ("(%s)", object_name);
Jim Ingham6bdea822011-10-24 18:36:33 +00003412 }
3413 strm.EOL();
3414 }
3415
Greg Claytone1f50b92011-05-03 22:09:39 +00003416 CommandOptions m_options;
3417};
3418
3419OptionDefinition
3420CommandObjectTargetModulesList::CommandOptions::g_option_table[] =
3421{
Jim Ingham6bdea822011-10-24 18:36:33 +00003422 { LLDB_OPT_SET_1, false, "address", 'a', required_argument, NULL, 0, eArgTypeAddress, "Display the image at this address."},
3423 { 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 +00003424 { 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 +00003425 { 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."},
3426 { 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 +00003427 { LLDB_OPT_SET_1, false, "uuid", 'u', no_argument, NULL, 0, eArgTypeNone, "Display the UUID when listing images."},
3428 { LLDB_OPT_SET_1, false, "fullpath", 'f', optional_argument, NULL, 0, eArgTypeWidth, "Display the fullpath to the image object file."},
3429 { LLDB_OPT_SET_1, false, "directory", 'd', optional_argument, NULL, 0, eArgTypeWidth, "Display the directory with optional width for the image object file."},
3430 { LLDB_OPT_SET_1, false, "basename", 'b', optional_argument, NULL, 0, eArgTypeWidth, "Display the basename with optional width for the image object file."},
3431 { 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 +00003432 { 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 +00003433 { LLDB_OPT_SET_1, false, "mod-time", 'm', optional_argument, NULL, 0, eArgTypeWidth, "Display the modification time with optional width of the module."},
3434 { 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."},
3435 { LLDB_OPT_SET_1, false, "pointer", 'p', optional_argument, NULL, 0, eArgTypeNone, "Display the module pointer."},
Greg Clayton899025f2011-08-09 00:01:09 +00003436 { 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 +00003437 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
3438};
3439
Jason Molenda5b0afcc2012-07-12 00:20:07 +00003440#pragma mark CommandObjectTargetModulesShowUnwind
Greg Claytone1f50b92011-05-03 22:09:39 +00003441
Jason Molenda5b0afcc2012-07-12 00:20:07 +00003442//----------------------------------------------------------------------
3443// Lookup unwind information in images
3444//----------------------------------------------------------------------
3445
3446class CommandObjectTargetModulesShowUnwind : public CommandObjectParsed
3447{
3448public:
3449
3450 enum
3451 {
3452 eLookupTypeInvalid = -1,
3453 eLookupTypeAddress = 0,
3454 eLookupTypeSymbol,
3455 eLookupTypeFunction,
3456 eLookupTypeFunctionOrSymbol,
3457 kNumLookupTypes
3458 };
3459
3460 class CommandOptions : public Options
3461 {
3462 public:
3463
3464 CommandOptions (CommandInterpreter &interpreter) :
3465 Options(interpreter),
3466 m_type(eLookupTypeInvalid),
3467 m_str(),
3468 m_addr(LLDB_INVALID_ADDRESS)
3469 {
3470 }
3471
3472 virtual
3473 ~CommandOptions ()
3474 {
3475 }
3476
3477 virtual Error
3478 SetOptionValue (uint32_t option_idx, const char *option_arg)
3479 {
3480 Error error;
3481
Greg Clayton6475c422012-12-04 00:32:51 +00003482 const int short_option = m_getopt_table[option_idx].val;
Jason Molenda5b0afcc2012-07-12 00:20:07 +00003483
3484 switch (short_option)
3485 {
3486 case 'a':
3487 m_type = eLookupTypeAddress;
3488 m_addr = Args::StringToUInt64(option_arg, LLDB_INVALID_ADDRESS);
3489 if (m_addr == LLDB_INVALID_ADDRESS)
3490 error.SetErrorStringWithFormat ("invalid address string '%s'", option_arg);
3491 break;
3492
3493 case 'n':
3494 m_str = option_arg;
3495 m_type = eLookupTypeFunctionOrSymbol;
3496 break;
3497 }
3498
3499 return error;
3500 }
3501
3502 void
3503 OptionParsingStarting ()
3504 {
3505 m_type = eLookupTypeInvalid;
3506 m_str.clear();
3507 m_addr = LLDB_INVALID_ADDRESS;
3508 }
3509
3510 const OptionDefinition*
3511 GetDefinitions ()
3512 {
3513 return g_option_table;
3514 }
3515
3516 // Options table: Required for subclasses of Options.
3517
3518 static OptionDefinition g_option_table[];
3519
3520 // Instance variables to hold the values for command options.
3521
3522 int m_type; // Should be a eLookupTypeXXX enum after parsing options
3523 std::string m_str; // Holds name lookup
3524 lldb::addr_t m_addr; // Holds the address to lookup
3525 };
3526
3527 CommandObjectTargetModulesShowUnwind (CommandInterpreter &interpreter) :
3528 CommandObjectParsed (interpreter,
3529 "target modules show-unwind",
3530 "Show synthesized unwind instructions for a function.",
3531 NULL),
3532 m_options (interpreter)
3533 {
3534 }
3535
3536 virtual
3537 ~CommandObjectTargetModulesShowUnwind ()
3538 {
3539 }
3540
3541 virtual
3542 Options *
3543 GetOptions ()
3544 {
3545 return &m_options;
3546 }
3547
3548protected:
3549 bool
3550 DoExecute (Args& command,
3551 CommandReturnObject &result)
3552 {
3553 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
3554 if (!target)
3555 {
3556 result.AppendError ("invalid target, create a debug target using the 'target create' command");
3557 result.SetStatus (eReturnStatusFailed);
3558 return false;
3559 }
3560
3561 ExecutionContext exe_ctx = m_interpreter.GetDebugger().GetSelectedExecutionContext();
3562 Process *process = exe_ctx.GetProcessPtr();
3563 ABI *abi = NULL;
3564 if (process)
3565 abi = process->GetABI().get();
3566
3567 if (process == NULL)
3568 {
3569 result.AppendError ("You must have a process running to use this command.");
3570 result.SetStatus (eReturnStatusFailed);
3571 return false;
3572 }
3573
3574 ThreadList threads(process->GetThreadList());
3575 if (threads.GetSize() == 0)
3576 {
3577 result.AppendError ("The process must be paused to use this command.");
3578 result.SetStatus (eReturnStatusFailed);
3579 return false;
3580 }
3581
3582 ThreadSP thread(threads.GetThreadAtIndex(0));
3583 if (thread.get() == NULL)
3584 {
3585 result.AppendError ("The process must be paused to use this command.");
3586 result.SetStatus (eReturnStatusFailed);
3587 return false;
3588 }
3589
3590 if (m_options.m_type == eLookupTypeFunctionOrSymbol)
3591 {
3592 SymbolContextList sc_list;
3593 uint32_t num_matches;
3594 ConstString function_name (m_options.m_str.c_str());
3595 num_matches = target->GetImages().FindFunctions (function_name, eFunctionNameTypeAuto, true, false, true, sc_list);
3596 for (uint32_t idx = 0; idx < num_matches; idx++)
3597 {
3598 SymbolContext sc;
3599 sc_list.GetContextAtIndex(idx, sc);
3600 if (sc.symbol == NULL && sc.function == NULL)
3601 continue;
3602 if (sc.module_sp.get() == NULL || sc.module_sp->GetObjectFile() == NULL)
3603 continue;
3604 AddressRange range;
3605 if (!sc.GetAddressRange (eSymbolContextFunction | eSymbolContextSymbol, 0, false, range))
3606 continue;
3607 if (!range.GetBaseAddress().IsValid())
3608 continue;
3609 ConstString funcname(sc.GetFunctionName());
3610 if (funcname.IsEmpty())
3611 continue;
3612 addr_t start_addr = range.GetBaseAddress().GetLoadAddress(target);
3613 if (abi)
3614 start_addr = abi->FixCodeAddress(start_addr);
3615
3616 FuncUnwindersSP func_unwinders_sp (sc.module_sp->GetObjectFile()->GetUnwindTable().GetUncachedFuncUnwindersContainingAddress(start_addr, sc));
3617 if (func_unwinders_sp.get() == NULL)
3618 continue;
3619
3620 Address first_non_prologue_insn (func_unwinders_sp->GetFirstNonPrologueInsn(*target));
3621 if (first_non_prologue_insn.IsValid())
3622 {
Daniel Malea5f35a4b2012-11-29 21:49:15 +00003623 result.GetOutputStream().Printf("First non-prologue instruction is at address 0x%" PRIx64 " or offset %" PRId64 " into the function.\n", first_non_prologue_insn.GetLoadAddress(target), first_non_prologue_insn.GetLoadAddress(target) - start_addr);
Jason Molenda5b0afcc2012-07-12 00:20:07 +00003624 result.GetOutputStream().Printf ("\n");
3625 }
3626
3627 UnwindPlanSP non_callsite_unwind_plan = func_unwinders_sp->GetUnwindPlanAtNonCallSite(*thread.get());
3628 if (non_callsite_unwind_plan.get())
3629 {
Daniel Malea5f35a4b2012-11-29 21:49:15 +00003630 result.GetOutputStream().Printf("Asynchronous (not restricted to call-sites) UnwindPlan for %s`%s (start addr 0x%" PRIx64 "):\n", sc.module_sp->GetPlatformFileSpec().GetFilename().AsCString(), funcname.AsCString(), start_addr);
Jason Molenda5b0afcc2012-07-12 00:20:07 +00003631 non_callsite_unwind_plan->Dump(result.GetOutputStream(), thread.get(), LLDB_INVALID_ADDRESS);
3632 result.GetOutputStream().Printf ("\n");
3633 }
3634
3635 UnwindPlanSP callsite_unwind_plan = func_unwinders_sp->GetUnwindPlanAtCallSite(-1);
3636 if (callsite_unwind_plan.get())
3637 {
Daniel Malea5f35a4b2012-11-29 21:49:15 +00003638 result.GetOutputStream().Printf("Synchronous (restricted to call-sites) UnwindPlan for %s`%s (start addr 0x%" PRIx64 "):\n", sc.module_sp->GetPlatformFileSpec().GetFilename().AsCString(), funcname.AsCString(), start_addr);
Jason Molenda5b0afcc2012-07-12 00:20:07 +00003639 callsite_unwind_plan->Dump(result.GetOutputStream(), thread.get(), LLDB_INVALID_ADDRESS);
3640 result.GetOutputStream().Printf ("\n");
3641 }
3642
3643 UnwindPlanSP arch_default_unwind_plan = func_unwinders_sp->GetUnwindPlanArchitectureDefault(*thread.get());
3644 if (arch_default_unwind_plan.get())
3645 {
Daniel Malea5f35a4b2012-11-29 21:49:15 +00003646 result.GetOutputStream().Printf("Architecture default UnwindPlan for %s`%s (start addr 0x%" PRIx64 "):\n", sc.module_sp->GetPlatformFileSpec().GetFilename().AsCString(), funcname.AsCString(), start_addr);
Jason Molenda5b0afcc2012-07-12 00:20:07 +00003647 arch_default_unwind_plan->Dump(result.GetOutputStream(), thread.get(), LLDB_INVALID_ADDRESS);
3648 result.GetOutputStream().Printf ("\n");
3649 }
3650
3651 UnwindPlanSP fast_unwind_plan = func_unwinders_sp->GetUnwindPlanFastUnwind(*thread.get());
3652 if (fast_unwind_plan.get())
3653 {
Daniel Malea5f35a4b2012-11-29 21:49:15 +00003654 result.GetOutputStream().Printf("Fast UnwindPlan for %s`%s (start addr 0x%" PRIx64 "):\n", sc.module_sp->GetPlatformFileSpec().GetFilename().AsCString(), funcname.AsCString(), start_addr);
Jason Molenda5b0afcc2012-07-12 00:20:07 +00003655 fast_unwind_plan->Dump(result.GetOutputStream(), thread.get(), LLDB_INVALID_ADDRESS);
3656 result.GetOutputStream().Printf ("\n");
3657 }
3658
3659
3660 result.GetOutputStream().Printf ("\n");
3661 }
3662 }
3663 return result.Succeeded();
3664 }
3665
3666 CommandOptions m_options;
3667};
3668
3669OptionDefinition
3670CommandObjectTargetModulesShowUnwind::CommandOptions::g_option_table[] =
3671{
3672 { 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."},
3673 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
3674};
Greg Claytone1f50b92011-05-03 22:09:39 +00003675
3676//----------------------------------------------------------------------
3677// Lookup information in images
3678//----------------------------------------------------------------------
Jim Inghamda26bd22012-06-08 21:56:10 +00003679class CommandObjectTargetModulesLookup : public CommandObjectParsed
Greg Claytone1f50b92011-05-03 22:09:39 +00003680{
3681public:
3682
3683 enum
3684 {
3685 eLookupTypeInvalid = -1,
3686 eLookupTypeAddress = 0,
3687 eLookupTypeSymbol,
3688 eLookupTypeFileLine, // Line is optional
3689 eLookupTypeFunction,
Greg Clayton2ad894b2012-05-15 18:43:44 +00003690 eLookupTypeFunctionOrSymbol,
Greg Claytone1f50b92011-05-03 22:09:39 +00003691 eLookupTypeType,
3692 kNumLookupTypes
3693 };
3694
3695 class CommandOptions : public Options
3696 {
3697 public:
3698
3699 CommandOptions (CommandInterpreter &interpreter) :
3700 Options(interpreter)
3701 {
3702 OptionParsingStarting();
3703 }
3704
3705 virtual
3706 ~CommandOptions ()
3707 {
3708 }
3709
3710 virtual Error
3711 SetOptionValue (uint32_t option_idx, const char *option_arg)
3712 {
3713 Error error;
3714
Greg Clayton6475c422012-12-04 00:32:51 +00003715 const int short_option = m_getopt_table[option_idx].val;
Greg Claytone1f50b92011-05-03 22:09:39 +00003716
3717 switch (short_option)
3718 {
3719 case 'a':
3720 m_type = eLookupTypeAddress;
3721 m_addr = Args::StringToUInt64(option_arg, LLDB_INVALID_ADDRESS);
3722 if (m_addr == LLDB_INVALID_ADDRESS)
Greg Clayton9c236732011-10-26 00:56:27 +00003723 error.SetErrorStringWithFormat ("invalid address string '%s'", option_arg);
Greg Claytone1f50b92011-05-03 22:09:39 +00003724 break;
3725
3726 case 'o':
3727 m_offset = Args::StringToUInt64(option_arg, LLDB_INVALID_ADDRESS);
3728 if (m_offset == LLDB_INVALID_ADDRESS)
Greg Clayton9c236732011-10-26 00:56:27 +00003729 error.SetErrorStringWithFormat ("invalid offset string '%s'", option_arg);
Greg Claytone1f50b92011-05-03 22:09:39 +00003730 break;
3731
3732 case 's':
3733 m_str = option_arg;
3734 m_type = eLookupTypeSymbol;
3735 break;
3736
3737 case 'f':
3738 m_file.SetFile (option_arg, false);
3739 m_type = eLookupTypeFileLine;
3740 break;
3741
3742 case 'i':
Sean Callanan9ad19532012-02-11 01:22:21 +00003743 m_include_inlines = false;
Greg Claytone1f50b92011-05-03 22:09:39 +00003744 break;
3745
3746 case 'l':
3747 m_line_number = Args::StringToUInt32(option_arg, UINT32_MAX);
3748 if (m_line_number == UINT32_MAX)
Greg Clayton9c236732011-10-26 00:56:27 +00003749 error.SetErrorStringWithFormat ("invalid line number string '%s'", option_arg);
Greg Claytone1f50b92011-05-03 22:09:39 +00003750 else if (m_line_number == 0)
Greg Clayton9c236732011-10-26 00:56:27 +00003751 error.SetErrorString ("zero is an invalid line number");
Greg Claytone1f50b92011-05-03 22:09:39 +00003752 m_type = eLookupTypeFileLine;
3753 break;
3754
Greg Clayton2ad894b2012-05-15 18:43:44 +00003755 case 'F':
Greg Claytone1f50b92011-05-03 22:09:39 +00003756 m_str = option_arg;
3757 m_type = eLookupTypeFunction;
3758 break;
Greg Clayton2ad894b2012-05-15 18:43:44 +00003759
3760 case 'n':
3761 m_str = option_arg;
3762 m_type = eLookupTypeFunctionOrSymbol;
3763 break;
3764
Greg Claytone1f50b92011-05-03 22:09:39 +00003765 case 't':
3766 m_str = option_arg;
3767 m_type = eLookupTypeType;
3768 break;
3769
3770 case 'v':
3771 m_verbose = 1;
3772 break;
Sean Callanan56d31ec2012-06-06 20:49:55 +00003773
3774 case 'A':
3775 m_print_all = true;
3776 break;
Greg Claytone1f50b92011-05-03 22:09:39 +00003777
3778 case 'r':
3779 m_use_regex = true;
3780 break;
3781 }
3782
3783 return error;
3784 }
3785
3786 void
3787 OptionParsingStarting ()
3788 {
3789 m_type = eLookupTypeInvalid;
3790 m_str.clear();
3791 m_file.Clear();
3792 m_addr = LLDB_INVALID_ADDRESS;
3793 m_offset = 0;
3794 m_line_number = 0;
3795 m_use_regex = false;
Sean Callanan9ad19532012-02-11 01:22:21 +00003796 m_include_inlines = true;
Greg Claytone1f50b92011-05-03 22:09:39 +00003797 m_verbose = false;
Sean Callanan56d31ec2012-06-06 20:49:55 +00003798 m_print_all = false;
Greg Claytone1f50b92011-05-03 22:09:39 +00003799 }
3800
3801 const OptionDefinition*
3802 GetDefinitions ()
3803 {
3804 return g_option_table;
3805 }
3806
3807 // Options table: Required for subclasses of Options.
3808
3809 static OptionDefinition g_option_table[];
3810 int m_type; // Should be a eLookupTypeXXX enum after parsing options
3811 std::string m_str; // Holds name lookup
3812 FileSpec m_file; // Files for file lookups
3813 lldb::addr_t m_addr; // Holds the address to lookup
3814 lldb::addr_t m_offset; // Subtract this offset from m_addr before doing lookups.
3815 uint32_t m_line_number; // Line number for file+line lookups
3816 bool m_use_regex; // Name lookups in m_str are regular expressions.
Sean Callanan9ad19532012-02-11 01:22:21 +00003817 bool m_include_inlines;// Check for inline entries when looking up by file/line.
Greg Claytone1f50b92011-05-03 22:09:39 +00003818 bool m_verbose; // Enable verbose lookup info
Sean Callanan56d31ec2012-06-06 20:49:55 +00003819 bool m_print_all; // Print all matches, even in cases where there's a best match.
Greg Claytone1f50b92011-05-03 22:09:39 +00003820
3821 };
3822
3823 CommandObjectTargetModulesLookup (CommandInterpreter &interpreter) :
Jim Inghamda26bd22012-06-08 21:56:10 +00003824 CommandObjectParsed (interpreter,
3825 "target modules lookup",
3826 "Look up information within executable and dependent shared library images.",
3827 NULL),
3828 m_options (interpreter)
Greg Claytone1f50b92011-05-03 22:09:39 +00003829 {
3830 CommandArgumentEntry arg;
3831 CommandArgumentData file_arg;
3832
3833 // Define the first (and only) variant of this arg.
3834 file_arg.arg_type = eArgTypeFilename;
3835 file_arg.arg_repetition = eArgRepeatStar;
3836
3837 // There is only one variant this argument could be; put it into the argument entry.
3838 arg.push_back (file_arg);
3839
3840 // Push the data for the first argument into the m_arguments vector.
3841 m_arguments.push_back (arg);
3842 }
3843
3844 virtual
3845 ~CommandObjectTargetModulesLookup ()
3846 {
3847 }
3848
3849 virtual Options *
3850 GetOptions ()
3851 {
3852 return &m_options;
3853 }
3854
Sean Callanan56d31ec2012-06-06 20:49:55 +00003855 bool
3856 LookupHere (CommandInterpreter &interpreter, CommandReturnObject &result, bool &syntax_error)
3857 {
3858 switch (m_options.m_type)
3859 {
3860 case eLookupTypeAddress:
3861 case eLookupTypeFileLine:
3862 case eLookupTypeFunction:
3863 case eLookupTypeFunctionOrSymbol:
3864 case eLookupTypeSymbol:
3865 default:
3866 return false;
3867 case eLookupTypeType:
3868 break;
3869 }
3870
3871 ExecutionContext exe_ctx = interpreter.GetDebugger().GetSelectedExecutionContext();
3872
3873 StackFrameSP frame = exe_ctx.GetFrameSP();
3874
3875 if (!frame)
3876 return false;
3877
3878 const SymbolContext &sym_ctx(frame->GetSymbolContext(eSymbolContextModule));
3879
3880 if (!sym_ctx.module_sp)
3881 return false;
3882
3883 switch (m_options.m_type)
3884 {
3885 default:
3886 return false;
3887 case eLookupTypeType:
3888 if (!m_options.m_str.empty())
3889 {
3890 if (LookupTypeHere (m_interpreter,
3891 result.GetOutputStream(),
3892 sym_ctx,
3893 m_options.m_str.c_str(),
3894 m_options.m_use_regex))
3895 {
3896 result.SetStatus(eReturnStatusSuccessFinishResult);
3897 return true;
3898 }
3899 }
3900 break;
3901 }
3902
3903 return true;
3904 }
Greg Claytone1f50b92011-05-03 22:09:39 +00003905
3906 bool
3907 LookupInModule (CommandInterpreter &interpreter, Module *module, CommandReturnObject &result, bool &syntax_error)
3908 {
3909 switch (m_options.m_type)
3910 {
3911 case eLookupTypeAddress:
3912 if (m_options.m_addr != LLDB_INVALID_ADDRESS)
3913 {
3914 if (LookupAddressInModule (m_interpreter,
3915 result.GetOutputStream(),
3916 module,
3917 eSymbolContextEverything,
3918 m_options.m_addr,
3919 m_options.m_offset,
3920 m_options.m_verbose))
3921 {
3922 result.SetStatus(eReturnStatusSuccessFinishResult);
3923 return true;
3924 }
3925 }
3926 break;
3927
3928 case eLookupTypeSymbol:
3929 if (!m_options.m_str.empty())
3930 {
Greg Clayton2ad894b2012-05-15 18:43:44 +00003931 if (LookupSymbolInModule (m_interpreter,
3932 result.GetOutputStream(),
3933 module,
3934 m_options.m_str.c_str(),
3935 m_options.m_use_regex,
3936 m_options.m_verbose))
Greg Claytone1f50b92011-05-03 22:09:39 +00003937 {
3938 result.SetStatus(eReturnStatusSuccessFinishResult);
3939 return true;
3940 }
3941 }
3942 break;
3943
3944 case eLookupTypeFileLine:
3945 if (m_options.m_file)
3946 {
3947
3948 if (LookupFileAndLineInModule (m_interpreter,
3949 result.GetOutputStream(),
3950 module,
3951 m_options.m_file,
3952 m_options.m_line_number,
Sean Callanan9ad19532012-02-11 01:22:21 +00003953 m_options.m_include_inlines,
Greg Claytone1f50b92011-05-03 22:09:39 +00003954 m_options.m_verbose))
3955 {
3956 result.SetStatus(eReturnStatusSuccessFinishResult);
3957 return true;
3958 }
3959 }
3960 break;
Greg Clayton2ad894b2012-05-15 18:43:44 +00003961
3962 case eLookupTypeFunctionOrSymbol:
Greg Claytone1f50b92011-05-03 22:09:39 +00003963 case eLookupTypeFunction:
3964 if (!m_options.m_str.empty())
3965 {
3966 if (LookupFunctionInModule (m_interpreter,
3967 result.GetOutputStream(),
3968 module,
3969 m_options.m_str.c_str(),
3970 m_options.m_use_regex,
Sean Callanan9ad19532012-02-11 01:22:21 +00003971 m_options.m_include_inlines,
Greg Clayton2ad894b2012-05-15 18:43:44 +00003972 m_options.m_type == eLookupTypeFunctionOrSymbol, // include symbols
Greg Claytone1f50b92011-05-03 22:09:39 +00003973 m_options.m_verbose))
3974 {
3975 result.SetStatus(eReturnStatusSuccessFinishResult);
3976 return true;
3977 }
3978 }
3979 break;
3980
Greg Clayton2ad894b2012-05-15 18:43:44 +00003981
Greg Claytone1f50b92011-05-03 22:09:39 +00003982 case eLookupTypeType:
3983 if (!m_options.m_str.empty())
3984 {
3985 if (LookupTypeInModule (m_interpreter,
3986 result.GetOutputStream(),
3987 module,
3988 m_options.m_str.c_str(),
3989 m_options.m_use_regex))
3990 {
3991 result.SetStatus(eReturnStatusSuccessFinishResult);
3992 return true;
3993 }
3994 }
3995 break;
3996
3997 default:
3998 m_options.GenerateOptionUsage (result.GetErrorStream(), this);
3999 syntax_error = true;
4000 break;
4001 }
4002
4003 result.SetStatus (eReturnStatusFailed);
4004 return false;
4005 }
4006
Jim Inghamda26bd22012-06-08 21:56:10 +00004007protected:
Greg Claytone1f50b92011-05-03 22:09:39 +00004008 virtual bool
Jim Inghamda26bd22012-06-08 21:56:10 +00004009 DoExecute (Args& command,
Greg Claytone1f50b92011-05-03 22:09:39 +00004010 CommandReturnObject &result)
4011 {
4012 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
4013 if (target == NULL)
4014 {
4015 result.AppendError ("invalid target, create a debug target using the 'target create' command");
4016 result.SetStatus (eReturnStatusFailed);
4017 return false;
4018 }
4019 else
4020 {
4021 bool syntax_error = false;
4022 uint32_t i;
4023 uint32_t num_successful_lookups = 0;
4024 uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize();
4025 result.GetOutputStream().SetAddressByteSize(addr_byte_size);
4026 result.GetErrorStream().SetAddressByteSize(addr_byte_size);
4027 // Dump all sections for all modules images
4028
4029 if (command.GetArgumentCount() == 0)
4030 {
Sean Callanan56d31ec2012-06-06 20:49:55 +00004031 ModuleSP current_module;
4032
4033 // Where it is possible to look in the current symbol context
4034 // first, try that. If this search was successful and --all
4035 // was not passed, don't print anything else.
4036 if (LookupHere (m_interpreter, result, syntax_error))
4037 {
4038 result.GetOutputStream().EOL();
4039 num_successful_lookups++;
4040 if (!m_options.m_print_all)
4041 {
4042 result.SetStatus (eReturnStatusSuccessFinishResult);
4043 return result.Succeeded();
4044 }
4045 }
4046
4047 // Dump all sections for all other modules
4048
Enrico Granata146d9522012-11-08 02:22:02 +00004049 const ModuleList &target_modules = target->GetImages();
Jim Ingham93367902012-05-30 02:19:25 +00004050 Mutex::Locker modules_locker(target_modules.GetMutex());
4051 const uint32_t num_modules = target_modules.GetSize();
Greg Claytone1f50b92011-05-03 22:09:39 +00004052 if (num_modules > 0)
4053 {
4054 for (i = 0; i<num_modules && syntax_error == false; ++i)
4055 {
Sean Callanan56d31ec2012-06-06 20:49:55 +00004056 Module *module_pointer = target_modules.GetModulePointerAtIndexUnlocked(i);
4057
4058 if (module_pointer != current_module.get() &&
4059 LookupInModule (m_interpreter, target_modules.GetModulePointerAtIndexUnlocked(i), result, syntax_error))
Greg Claytone1f50b92011-05-03 22:09:39 +00004060 {
4061 result.GetOutputStream().EOL();
4062 num_successful_lookups++;
4063 }
4064 }
4065 }
4066 else
4067 {
4068 result.AppendError ("the target has no associated executable images");
4069 result.SetStatus (eReturnStatusFailed);
4070 return false;
4071 }
4072 }
4073 else
4074 {
4075 // Dump specified images (by basename or fullpath)
4076 const char *arg_cstr;
4077 for (i = 0; (arg_cstr = command.GetArgumentAtIndex(i)) != NULL && syntax_error == false; ++i)
4078 {
Greg Clayton91048ef2011-11-10 01:18:58 +00004079 ModuleList module_list;
4080 const size_t num_matches = FindModulesByName (target, arg_cstr, module_list, false);
4081 if (num_matches > 0)
Greg Claytone1f50b92011-05-03 22:09:39 +00004082 {
Jason Molendabf41e192012-10-04 22:47:07 +00004083 for (size_t j=0; j<num_matches; ++j)
Greg Claytone1f50b92011-05-03 22:09:39 +00004084 {
Jason Molendabf41e192012-10-04 22:47:07 +00004085 Module *module = module_list.GetModulePointerAtIndex(j);
Greg Clayton91048ef2011-11-10 01:18:58 +00004086 if (module)
Greg Claytone1f50b92011-05-03 22:09:39 +00004087 {
Greg Clayton91048ef2011-11-10 01:18:58 +00004088 if (LookupInModule (m_interpreter, module, result, syntax_error))
Greg Claytone1f50b92011-05-03 22:09:39 +00004089 {
4090 result.GetOutputStream().EOL();
4091 num_successful_lookups++;
4092 }
4093 }
4094 }
4095 }
4096 else
4097 result.AppendWarningWithFormat("Unable to find an image that matches '%s'.\n", arg_cstr);
4098 }
4099 }
4100
4101 if (num_successful_lookups > 0)
4102 result.SetStatus (eReturnStatusSuccessFinishResult);
4103 else
4104 result.SetStatus (eReturnStatusFailed);
4105 }
4106 return result.Succeeded();
4107 }
Greg Claytone1f50b92011-05-03 22:09:39 +00004108
4109 CommandOptions m_options;
4110};
4111
4112OptionDefinition
4113CommandObjectTargetModulesLookup::CommandOptions::g_option_table[] =
4114{
Sean Callanan3bfaad62012-09-13 21:11:40 +00004115 { LLDB_OPT_SET_1, true, "address", 'a', required_argument, NULL, 0, eArgTypeAddress, "Lookup an address in one or more target modules."},
4116 { 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 +00004117 { LLDB_OPT_SET_2| LLDB_OPT_SET_4 | LLDB_OPT_SET_5
4118 /* FIXME: re-enable this for types when the LookupTypeInModule actually uses the regex option: | LLDB_OPT_SET_6 */ ,
Sean Callanan3bfaad62012-09-13 21:11:40 +00004119 false, "regex", 'r', no_argument, NULL, 0, eArgTypeNone, "The <name> argument for name lookups are regular expressions."},
4120 { 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."},
4121 { 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."},
4122 { 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 +00004123 { LLDB_OPT_SET_FROM_TO(3,5),
Sean Callanan3bfaad62012-09-13 21:11:40 +00004124 false, "no-inlines", 'i', no_argument, NULL, 0, eArgTypeNone, "Ignore inline entries (must be used in conjunction with --file or --function)."},
4125 { 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."},
4126 { LLDB_OPT_SET_5, true, "name", 'n', required_argument, NULL, 0, eArgTypeFunctionOrSymbol, "Lookup a function or symbol by name in one or more target modules."},
4127 { 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."},
4128 { LLDB_OPT_SET_ALL, false, "verbose", 'v', no_argument, NULL, 0, eArgTypeNone, "Enable verbose lookup information."},
4129 { 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."},
4130 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
Greg Claytone1f50b92011-05-03 22:09:39 +00004131};
Chris Lattner24943d22010-06-08 16:52:24 +00004132
4133
Jim Inghamd60d94a2011-03-11 03:53:59 +00004134#pragma mark CommandObjectMultiwordImageSearchPaths
Chris Lattner24943d22010-06-08 16:52:24 +00004135
4136//-------------------------------------------------------------------------
4137// CommandObjectMultiwordImageSearchPaths
4138//-------------------------------------------------------------------------
4139
Greg Claytone1f50b92011-05-03 22:09:39 +00004140class CommandObjectTargetModulesImageSearchPaths : public CommandObjectMultiword
Chris Lattner24943d22010-06-08 16:52:24 +00004141{
4142public:
Greg Claytone1f50b92011-05-03 22:09:39 +00004143
4144 CommandObjectTargetModulesImageSearchPaths (CommandInterpreter &interpreter) :
4145 CommandObjectMultiword (interpreter,
4146 "target modules search-paths",
4147 "A set of commands for operating on debugger target image search paths.",
4148 "target modules search-paths <subcommand> [<subcommand-options>]")
Chris Lattner24943d22010-06-08 16:52:24 +00004149 {
Greg Claytone1f50b92011-05-03 22:09:39 +00004150 LoadSubCommand ("add", CommandObjectSP (new CommandObjectTargetModulesSearchPathsAdd (interpreter)));
4151 LoadSubCommand ("clear", CommandObjectSP (new CommandObjectTargetModulesSearchPathsClear (interpreter)));
4152 LoadSubCommand ("insert", CommandObjectSP (new CommandObjectTargetModulesSearchPathsInsert (interpreter)));
4153 LoadSubCommand ("list", CommandObjectSP (new CommandObjectTargetModulesSearchPathsList (interpreter)));
4154 LoadSubCommand ("query", CommandObjectSP (new CommandObjectTargetModulesSearchPathsQuery (interpreter)));
Chris Lattner24943d22010-06-08 16:52:24 +00004155 }
Greg Claytone1f50b92011-05-03 22:09:39 +00004156
4157 ~CommandObjectTargetModulesImageSearchPaths()
Chris Lattner24943d22010-06-08 16:52:24 +00004158 {
4159 }
4160};
4161
Greg Claytone1f50b92011-05-03 22:09:39 +00004162
4163
4164#pragma mark CommandObjectTargetModules
4165
4166//-------------------------------------------------------------------------
4167// CommandObjectTargetModules
4168//-------------------------------------------------------------------------
4169
4170class CommandObjectTargetModules : public CommandObjectMultiword
4171{
4172public:
4173 //------------------------------------------------------------------
4174 // Constructors and Destructors
4175 //------------------------------------------------------------------
4176 CommandObjectTargetModules(CommandInterpreter &interpreter) :
4177 CommandObjectMultiword (interpreter,
4178 "target modules",
4179 "A set of commands for accessing information for one or more target modules.",
4180 "target modules <sub-command> ...")
4181 {
4182 LoadSubCommand ("add", CommandObjectSP (new CommandObjectTargetModulesAdd (interpreter)));
4183 LoadSubCommand ("load", CommandObjectSP (new CommandObjectTargetModulesLoad (interpreter)));
4184 //LoadSubCommand ("unload", CommandObjectSP (new CommandObjectTargetModulesUnload (interpreter)));
4185 LoadSubCommand ("dump", CommandObjectSP (new CommandObjectTargetModulesDump (interpreter)));
4186 LoadSubCommand ("list", CommandObjectSP (new CommandObjectTargetModulesList (interpreter)));
4187 LoadSubCommand ("lookup", CommandObjectSP (new CommandObjectTargetModulesLookup (interpreter)));
4188 LoadSubCommand ("search-paths", CommandObjectSP (new CommandObjectTargetModulesImageSearchPaths (interpreter)));
Jason Molenda5b0afcc2012-07-12 00:20:07 +00004189 LoadSubCommand ("show-unwind", CommandObjectSP (new CommandObjectTargetModulesShowUnwind (interpreter)));
Greg Claytone1f50b92011-05-03 22:09:39 +00004190
4191 }
4192 virtual
4193 ~CommandObjectTargetModules()
4194 {
4195 }
4196
4197private:
4198 //------------------------------------------------------------------
4199 // For CommandObjectTargetModules only
4200 //------------------------------------------------------------------
4201 DISALLOW_COPY_AND_ASSIGN (CommandObjectTargetModules);
4202};
4203
4204
Greg Clayton3508c382012-02-24 01:59:29 +00004205
Jim Inghamda26bd22012-06-08 21:56:10 +00004206class CommandObjectTargetSymbolsAdd : public CommandObjectParsed
Greg Clayton3508c382012-02-24 01:59:29 +00004207{
4208public:
4209 CommandObjectTargetSymbolsAdd (CommandInterpreter &interpreter) :
Jim Inghamda26bd22012-06-08 21:56:10 +00004210 CommandObjectParsed (interpreter,
4211 "target symbols add",
Greg Clayton437b5bc2012-09-27 22:26:11 +00004212 "Add a debug symbol file to one of the target's current modules by specifying a path to a debug symbols file, or using the options to specify a module to download symbols for.",
4213 "target symbols add [<symfile>]"),
4214 m_option_group (interpreter),
4215 m_file_option (LLDB_OPT_SET_1, false, "shlib", 's', CommandCompletions::eModuleCompletion, eArgTypeShlibName, "Fullpath or basename for module to find debug symbols for."),
4216 m_current_frame_option (LLDB_OPT_SET_2, false, "frame", 'F', "Locate the debug symbols the currently selected frame.", false, true)
4217
Greg Clayton3508c382012-02-24 01:59:29 +00004218 {
Greg Clayton437b5bc2012-09-27 22:26:11 +00004219 m_option_group.Append (&m_uuid_option_group, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
4220 m_option_group.Append (&m_file_option, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
4221 m_option_group.Append (&m_current_frame_option, LLDB_OPT_SET_2, LLDB_OPT_SET_2);
4222 m_option_group.Finalize();
Greg Clayton3508c382012-02-24 01:59:29 +00004223 }
4224
4225 virtual
4226 ~CommandObjectTargetSymbolsAdd ()
4227 {
4228 }
4229
Jim Inghamda26bd22012-06-08 21:56:10 +00004230 int
4231 HandleArgumentCompletion (Args &input,
4232 int &cursor_index,
4233 int &cursor_char_position,
4234 OptionElementVector &opt_element_vector,
4235 int match_start_point,
4236 int max_return_elements,
4237 bool &word_complete,
4238 StringList &matches)
4239 {
4240 std::string completion_str (input.GetArgumentAtIndex(cursor_index));
4241 completion_str.erase (cursor_char_position);
4242
4243 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
4244 CommandCompletions::eDiskFileCompletion,
4245 completion_str.c_str(),
4246 match_start_point,
4247 max_return_elements,
4248 NULL,
4249 word_complete,
4250 matches);
4251 return matches.GetSize();
4252 }
4253
Greg Clayton437b5bc2012-09-27 22:26:11 +00004254 virtual Options *
4255 GetOptions ()
4256 {
4257 return &m_option_group;
4258 }
4259
4260
Jim Inghamda26bd22012-06-08 21:56:10 +00004261protected:
Greg Clayton437b5bc2012-09-27 22:26:11 +00004262
4263 bool
4264 AddModuleSymbols (Target *target,
4265 const FileSpec &symfile_spec,
4266 bool &flush,
4267 CommandReturnObject &result)
4268 {
4269 ModuleSP symfile_module_sp (new Module (symfile_spec, target->GetArchitecture()));
4270 const UUID &symfile_uuid = symfile_module_sp->GetUUID();
4271 StreamString ss_symfile_uuid;
4272 symfile_uuid.Dump(&ss_symfile_uuid);
4273
4274 if (symfile_module_sp)
4275 {
4276 char symfile_path[PATH_MAX];
4277 symfile_spec.GetPath (symfile_path, sizeof(symfile_path));
4278 // We now have a module that represents a symbol file
4279 // that can be used for a module that might exist in the
4280 // current target, so we need to find that module in the
4281 // target
4282
4283 ModuleSP old_module_sp (target->GetImages().FindModule (symfile_uuid));
4284 if (old_module_sp)
4285 {
4286 // The module has not yet created its symbol vendor, we can just
4287 // give the existing target module the symfile path to use for
4288 // when it decides to create it!
4289 old_module_sp->SetSymbolFileFileSpec (symfile_module_sp->GetFileSpec());
4290
4291 // Provide feedback that the symfile has been successfully added.
4292 const FileSpec &module_fs = old_module_sp->GetFileSpec();
4293 result.AppendMessageWithFormat("symbol file '%s' with UUID %s has been successfully added to the '%s/%s' module\n",
4294 symfile_path, ss_symfile_uuid.GetData(),
4295 module_fs.GetDirectory().AsCString(), module_fs.GetFilename().AsCString());
4296
4297 // Let clients know something changed in the module
4298 // if it is currently loaded
4299 ModuleList module_list;
4300 module_list.Append (old_module_sp);
4301 target->ModulesDidLoad (module_list);
4302 flush = true;
4303 }
4304 else
4305 {
4306 result.AppendErrorWithFormat ("symbol file '%s' with UUID %s does not match any existing module%s\n",
4307 symfile_path, ss_symfile_uuid.GetData(),
4308 (symfile_spec.GetFileType() != FileSpec::eFileTypeRegular)
4309 ? "\n please specify the full path to the symbol file"
4310 : "");
4311 return false;
4312 }
4313 }
4314 else
4315 {
4316 result.AppendError ("one or more executable image paths must be specified");
4317 result.SetStatus (eReturnStatusFailed);
4318 return false;
4319 }
4320 result.SetStatus (eReturnStatusSuccessFinishResult);
4321 return true;
4322 }
4323
Greg Clayton3508c382012-02-24 01:59:29 +00004324 virtual bool
Jim Inghamda26bd22012-06-08 21:56:10 +00004325 DoExecute (Args& args,
Greg Clayton3508c382012-02-24 01:59:29 +00004326 CommandReturnObject &result)
4327 {
Greg Claytoncf5927e2012-05-18 02:38:05 +00004328 ExecutionContext exe_ctx (m_interpreter.GetExecutionContext());
4329 Target *target = exe_ctx.GetTargetPtr();
Greg Clayton437b5bc2012-09-27 22:26:11 +00004330 result.SetStatus (eReturnStatusFailed);
Greg Clayton3508c382012-02-24 01:59:29 +00004331 if (target == NULL)
4332 {
4333 result.AppendError ("invalid target, create a debug target using the 'target create' command");
Greg Clayton3508c382012-02-24 01:59:29 +00004334 }
4335 else
4336 {
Greg Claytoncf5927e2012-05-18 02:38:05 +00004337 bool flush = false;
Greg Clayton437b5bc2012-09-27 22:26:11 +00004338 ModuleSpec sym_spec;
4339 const bool uuid_option_set = m_uuid_option_group.GetOptionValue().OptionWasSet();
4340 const bool file_option_set = m_file_option.GetOptionValue().OptionWasSet();
4341 const bool frame_option_set = m_current_frame_option.GetOptionValue().OptionWasSet();
4342
Greg Clayton3508c382012-02-24 01:59:29 +00004343 const size_t argc = args.GetArgumentCount();
4344 if (argc == 0)
4345 {
Greg Clayton437b5bc2012-09-27 22:26:11 +00004346 if (uuid_option_set || file_option_set || frame_option_set)
Greg Clayton3508c382012-02-24 01:59:29 +00004347 {
Greg Clayton437b5bc2012-09-27 22:26:11 +00004348 bool success = false;
4349 bool error_set = false;
4350 if (frame_option_set)
Greg Clayton3508c382012-02-24 01:59:29 +00004351 {
Greg Clayton437b5bc2012-09-27 22:26:11 +00004352 Process *process = exe_ctx.GetProcessPtr();
4353 if (process)
Greg Clayton3508c382012-02-24 01:59:29 +00004354 {
Greg Clayton437b5bc2012-09-27 22:26:11 +00004355 const StateType process_state = process->GetState();
4356 if (StateIsStoppedState (process_state, true))
Greg Clayton3508c382012-02-24 01:59:29 +00004357 {
Greg Clayton437b5bc2012-09-27 22:26:11 +00004358 StackFrame *frame = exe_ctx.GetFramePtr();
4359 if (frame)
Greg Clayton3508c382012-02-24 01:59:29 +00004360 {
Greg Clayton437b5bc2012-09-27 22:26:11 +00004361 ModuleSP frame_module_sp (frame->GetSymbolContext(eSymbolContextModule).module_sp);
4362 if (frame_module_sp)
4363 {
4364 if (frame_module_sp->GetPlatformFileSpec().Exists())
4365 {
4366 sym_spec.GetArchitecture() = frame_module_sp->GetArchitecture();
4367 sym_spec.GetFileSpec() = frame_module_sp->GetPlatformFileSpec();
4368 }
4369 sym_spec.GetUUID() = frame_module_sp->GetUUID();
4370 success = sym_spec.GetUUID().IsValid() || sym_spec.GetFileSpec();
4371 }
4372 else
4373 {
4374 result.AppendError ("frame has no module");
4375 error_set = true;
4376 }
Greg Clayton3508c382012-02-24 01:59:29 +00004377 }
Johnny Chen9262cd52012-08-22 00:18:43 +00004378 else
4379 {
Greg Clayton437b5bc2012-09-27 22:26:11 +00004380 result.AppendError ("invalid current frame");
4381 error_set = true;
Johnny Chen9262cd52012-08-22 00:18:43 +00004382 }
Greg Clayton3508c382012-02-24 01:59:29 +00004383 }
4384 else
4385 {
Greg Clayton437b5bc2012-09-27 22:26:11 +00004386 result.AppendErrorWithFormat ("process is not stopped: %s", StateAsCString(process_state));
4387 error_set = true;
Greg Clayton3508c382012-02-24 01:59:29 +00004388 }
Greg Clayton3508c382012-02-24 01:59:29 +00004389 }
4390 else
4391 {
Greg Clayton437b5bc2012-09-27 22:26:11 +00004392 result.AppendError ("a process must exist in order to use the --frame option");
4393 error_set = true;
4394 }
4395 }
4396 else
4397 {
4398 if (uuid_option_set)
4399 {
4400 sym_spec.GetUUID() = m_uuid_option_group.GetOptionValue().GetCurrentValue();
4401 success |= sym_spec.GetUUID().IsValid();
4402 }
4403 else if (file_option_set)
4404 {
4405 sym_spec.GetFileSpec() = m_file_option.GetOptionValue().GetCurrentValue();
4406 ModuleSP module_sp (target->GetImages().FindFirstModule(sym_spec));
4407 if (module_sp)
Greg Clayton3508c382012-02-24 01:59:29 +00004408 {
Greg Clayton437b5bc2012-09-27 22:26:11 +00004409 sym_spec.GetFileSpec() = module_sp->GetFileSpec();
4410 sym_spec.GetPlatformFileSpec() = module_sp->GetPlatformFileSpec();
4411 sym_spec.GetUUID() = module_sp->GetUUID();
4412 sym_spec.GetArchitecture() = module_sp->GetArchitecture();
Greg Clayton3508c382012-02-24 01:59:29 +00004413 }
Greg Clayton437b5bc2012-09-27 22:26:11 +00004414 else
4415 {
4416 sym_spec.GetArchitecture() = target->GetArchitecture();
4417 }
4418 success |= sym_spec.GetFileSpec().Exists();
4419 }
4420 }
4421
4422 if (success)
4423 {
4424 if (Symbols::DownloadObjectAndSymbolFile (sym_spec))
4425 {
4426 if (sym_spec.GetSymbolFileSpec())
4427 success = AddModuleSymbols (target, sym_spec.GetSymbolFileSpec(), flush, result);
4428 }
4429 }
4430
4431 if (!success && !error_set)
4432 {
4433 StreamString error_strm;
4434 if (uuid_option_set)
4435 {
4436 error_strm.PutCString("unable to find debug symbols for UUID ");
4437 sym_spec.GetUUID().Dump (&error_strm);
4438 }
4439 else if (file_option_set)
4440 {
4441 error_strm.PutCString("unable to find debug symbols for the executable file ");
4442 error_strm << sym_spec.GetFileSpec();
4443 }
4444 else if (frame_option_set)
4445 {
4446 error_strm.PutCString("unable to find debug symbols for the current frame");
4447 }
4448 result.AppendError (error_strm.GetData());
4449 }
4450 }
4451 else
4452 {
4453 result.AppendError ("one or more symbol file paths must be specified, or options must be specified");
4454 }
4455 }
4456 else
4457 {
4458 if (uuid_option_set)
4459 {
4460 result.AppendError ("specify either one or more paths to symbol files or use the --uuid option without arguments");
4461 }
4462 else if (file_option_set)
4463 {
4464 result.AppendError ("specify either one or more paths to symbol files or use the --file option without arguments");
4465 }
4466 else if (frame_option_set)
4467 {
4468 result.AppendError ("specify either one or more paths to symbol files or use the --frame option without arguments");
4469 }
4470 else
4471 {
4472 PlatformSP platform_sp (target->GetPlatform());
4473
4474 for (size_t i=0; i<argc; ++i)
4475 {
4476 const char *symfile_path = args.GetArgumentAtIndex(i);
4477 if (symfile_path)
4478 {
4479 FileSpec symfile_spec;
4480 sym_spec.GetSymbolFileSpec().SetFile(symfile_path, true);
4481 if (platform_sp)
4482 platform_sp->ResolveSymbolFile(*target, sym_spec, symfile_spec);
4483 else
4484 symfile_spec.SetFile(symfile_path, true);
4485
4486 ArchSpec arch;
4487 bool symfile_exists = symfile_spec.Exists();
4488
4489 if (symfile_exists)
4490 {
4491 if (!AddModuleSymbols (target, symfile_spec, flush, result))
4492 break;
4493 }
4494 else
4495 {
4496 char resolved_symfile_path[PATH_MAX];
4497 if (symfile_spec.GetPath (resolved_symfile_path, sizeof(resolved_symfile_path)))
4498 {
4499 if (strcmp (resolved_symfile_path, symfile_path) != 0)
4500 {
4501 result.AppendErrorWithFormat ("invalid module path '%s' with resolved path '%s'\n", symfile_path, resolved_symfile_path);
4502 break;
4503 }
4504 }
4505 result.AppendErrorWithFormat ("invalid module path '%s'\n", symfile_path);
4506 break;
4507 }
Greg Clayton3508c382012-02-24 01:59:29 +00004508 }
4509 }
4510 }
4511 }
Greg Claytoncf5927e2012-05-18 02:38:05 +00004512
4513 if (flush)
4514 {
4515 Process *process = exe_ctx.GetProcessPtr();
4516 if (process)
4517 process->Flush();
4518 }
Greg Clayton3508c382012-02-24 01:59:29 +00004519 }
4520 return result.Succeeded();
4521 }
4522
Greg Clayton437b5bc2012-09-27 22:26:11 +00004523 OptionGroupOptions m_option_group;
4524 OptionGroupUUID m_uuid_option_group;
4525 OptionGroupFile m_file_option;
4526 OptionGroupBoolean m_current_frame_option;
4527
4528
Greg Clayton3508c382012-02-24 01:59:29 +00004529};
4530
4531
4532#pragma mark CommandObjectTargetSymbols
4533
4534//-------------------------------------------------------------------------
4535// CommandObjectTargetSymbols
4536//-------------------------------------------------------------------------
4537
4538class CommandObjectTargetSymbols : public CommandObjectMultiword
4539{
4540public:
4541 //------------------------------------------------------------------
4542 // Constructors and Destructors
4543 //------------------------------------------------------------------
4544 CommandObjectTargetSymbols(CommandInterpreter &interpreter) :
4545 CommandObjectMultiword (interpreter,
4546 "target symbols",
4547 "A set of commands for adding and managing debug symbol files.",
4548 "target symbols <sub-command> ...")
4549 {
4550 LoadSubCommand ("add", CommandObjectSP (new CommandObjectTargetSymbolsAdd (interpreter)));
4551
4552 }
4553 virtual
4554 ~CommandObjectTargetSymbols()
4555 {
4556 }
4557
4558private:
4559 //------------------------------------------------------------------
4560 // For CommandObjectTargetModules only
4561 //------------------------------------------------------------------
4562 DISALLOW_COPY_AND_ASSIGN (CommandObjectTargetSymbols);
4563};
4564
4565
Jim Inghamd60d94a2011-03-11 03:53:59 +00004566#pragma mark CommandObjectTargetStopHookAdd
4567
4568//-------------------------------------------------------------------------
4569// CommandObjectTargetStopHookAdd
4570//-------------------------------------------------------------------------
4571
Jim Inghamda26bd22012-06-08 21:56:10 +00004572class CommandObjectTargetStopHookAdd : public CommandObjectParsed
Jim Inghamd60d94a2011-03-11 03:53:59 +00004573{
4574public:
4575
4576 class CommandOptions : public Options
4577 {
4578 public:
Greg Claytonf15996e2011-04-07 22:46:35 +00004579 CommandOptions (CommandInterpreter &interpreter) :
4580 Options(interpreter),
Jim Inghamd60d94a2011-03-11 03:53:59 +00004581 m_line_start(0),
4582 m_line_end (UINT_MAX),
4583 m_func_name_type_mask (eFunctionNameTypeAuto),
4584 m_sym_ctx_specified (false),
Johnny Chen60fe60e2011-05-02 23:47:55 +00004585 m_thread_specified (false),
4586 m_use_one_liner (false),
4587 m_one_liner()
Jim Inghamd60d94a2011-03-11 03:53:59 +00004588 {
4589 }
4590
4591 ~CommandOptions () {}
4592
Greg Claytonb3448432011-03-24 21:19:54 +00004593 const OptionDefinition*
Jim Inghamd60d94a2011-03-11 03:53:59 +00004594 GetDefinitions ()
4595 {
4596 return g_option_table;
4597 }
4598
4599 virtual Error
Greg Clayton143fcc32011-04-13 00:18:08 +00004600 SetOptionValue (uint32_t option_idx, const char *option_arg)
Jim Inghamd60d94a2011-03-11 03:53:59 +00004601 {
4602 Error error;
Greg Clayton6475c422012-12-04 00:32:51 +00004603 const int short_option = m_getopt_table[option_idx].val;
Jim Inghamd60d94a2011-03-11 03:53:59 +00004604 bool success;
4605
4606 switch (short_option)
4607 {
4608 case 'c':
4609 m_class_name = option_arg;
4610 m_sym_ctx_specified = true;
4611 break;
4612
4613 case 'e':
4614 m_line_end = Args::StringToUInt32 (option_arg, UINT_MAX, 0, &success);
4615 if (!success)
4616 {
Greg Clayton9c236732011-10-26 00:56:27 +00004617 error.SetErrorStringWithFormat ("invalid end line number: \"%s\"", option_arg);
Jim Inghamd60d94a2011-03-11 03:53:59 +00004618 break;
4619 }
4620 m_sym_ctx_specified = true;
4621 break;
4622
4623 case 'l':
4624 m_line_start = Args::StringToUInt32 (option_arg, 0, 0, &success);
4625 if (!success)
4626 {
Greg Clayton9c236732011-10-26 00:56:27 +00004627 error.SetErrorStringWithFormat ("invalid start line number: \"%s\"", option_arg);
Jim Inghamd60d94a2011-03-11 03:53:59 +00004628 break;
4629 }
4630 m_sym_ctx_specified = true;
4631 break;
Sean Callanan9ad19532012-02-11 01:22:21 +00004632
4633 case 'i':
4634 m_no_inlines = true;
4635 break;
Jim Inghamd60d94a2011-03-11 03:53:59 +00004636
4637 case 'n':
4638 m_function_name = option_arg;
4639 m_func_name_type_mask |= eFunctionNameTypeAuto;
4640 m_sym_ctx_specified = true;
4641 break;
4642
4643 case 'f':
4644 m_file_name = option_arg;
4645 m_sym_ctx_specified = true;
4646 break;
4647 case 's':
4648 m_module_name = option_arg;
4649 m_sym_ctx_specified = true;
4650 break;
4651 case 't' :
4652 {
Jim Ingham7a4c8ea2011-03-22 01:53:33 +00004653 m_thread_id = Args::StringToUInt64(option_arg, LLDB_INVALID_THREAD_ID, 0);
Jim Inghamd60d94a2011-03-11 03:53:59 +00004654 if (m_thread_id == LLDB_INVALID_THREAD_ID)
Greg Clayton9c236732011-10-26 00:56:27 +00004655 error.SetErrorStringWithFormat ("invalid thread id string '%s'", option_arg);
Jim Inghamd60d94a2011-03-11 03:53:59 +00004656 m_thread_specified = true;
4657 }
4658 break;
4659 case 'T':
4660 m_thread_name = option_arg;
4661 m_thread_specified = true;
4662 break;
4663 case 'q':
4664 m_queue_name = option_arg;
4665 m_thread_specified = true;
4666 break;
4667 case 'x':
4668 {
Jim Ingham7a4c8ea2011-03-22 01:53:33 +00004669 m_thread_index = Args::StringToUInt32(option_arg, UINT32_MAX, 0);
Jim Inghamd60d94a2011-03-11 03:53:59 +00004670 if (m_thread_id == UINT32_MAX)
Greg Clayton9c236732011-10-26 00:56:27 +00004671 error.SetErrorStringWithFormat ("invalid thread index string '%s'", option_arg);
Jim Inghamd60d94a2011-03-11 03:53:59 +00004672 m_thread_specified = true;
4673 }
4674 break;
Johnny Chen60fe60e2011-05-02 23:47:55 +00004675 case 'o':
4676 m_use_one_liner = true;
4677 m_one_liner = option_arg;
4678 break;
Jim Inghamd60d94a2011-03-11 03:53:59 +00004679 default:
Greg Clayton9c236732011-10-26 00:56:27 +00004680 error.SetErrorStringWithFormat ("unrecognized option %c.", short_option);
Jim Inghamd60d94a2011-03-11 03:53:59 +00004681 break;
4682 }
4683 return error;
4684 }
4685
4686 void
Greg Clayton143fcc32011-04-13 00:18:08 +00004687 OptionParsingStarting ()
Jim Inghamd60d94a2011-03-11 03:53:59 +00004688 {
4689 m_class_name.clear();
4690 m_function_name.clear();
4691 m_line_start = 0;
4692 m_line_end = UINT_MAX;
4693 m_file_name.clear();
4694 m_module_name.clear();
4695 m_func_name_type_mask = eFunctionNameTypeAuto;
4696 m_thread_id = LLDB_INVALID_THREAD_ID;
4697 m_thread_index = UINT32_MAX;
4698 m_thread_name.clear();
4699 m_queue_name.clear();
Sean Callanan9ad19532012-02-11 01:22:21 +00004700
4701 m_no_inlines = false;
Jim Inghamd60d94a2011-03-11 03:53:59 +00004702 m_sym_ctx_specified = false;
4703 m_thread_specified = false;
Johnny Chen60fe60e2011-05-02 23:47:55 +00004704
4705 m_use_one_liner = false;
4706 m_one_liner.clear();
Jim Inghamd60d94a2011-03-11 03:53:59 +00004707 }
4708
4709
Greg Claytonb3448432011-03-24 21:19:54 +00004710 static OptionDefinition g_option_table[];
Jim Inghamd60d94a2011-03-11 03:53:59 +00004711
4712 std::string m_class_name;
4713 std::string m_function_name;
4714 uint32_t m_line_start;
4715 uint32_t m_line_end;
4716 std::string m_file_name;
4717 std::string m_module_name;
4718 uint32_t m_func_name_type_mask; // A pick from lldb::FunctionNameType.
4719 lldb::tid_t m_thread_id;
4720 uint32_t m_thread_index;
4721 std::string m_thread_name;
4722 std::string m_queue_name;
4723 bool m_sym_ctx_specified;
Sean Callanan9ad19532012-02-11 01:22:21 +00004724 bool m_no_inlines;
Jim Inghamd60d94a2011-03-11 03:53:59 +00004725 bool m_thread_specified;
Johnny Chen60fe60e2011-05-02 23:47:55 +00004726 // Instance variables to hold the values for one_liner options.
4727 bool m_use_one_liner;
4728 std::string m_one_liner;
Jim Inghamd60d94a2011-03-11 03:53:59 +00004729 };
4730
4731 Options *
4732 GetOptions ()
4733 {
4734 return &m_options;
4735 }
4736
4737 CommandObjectTargetStopHookAdd (CommandInterpreter &interpreter) :
Jim Inghamda26bd22012-06-08 21:56:10 +00004738 CommandObjectParsed (interpreter,
4739 "target stop-hook add ",
4740 "Add a hook to be executed when the target stops.",
4741 "target stop-hook add"),
Greg Claytonf15996e2011-04-07 22:46:35 +00004742 m_options (interpreter)
Jim Inghamd60d94a2011-03-11 03:53:59 +00004743 {
4744 }
4745
4746 ~CommandObjectTargetStopHookAdd ()
4747 {
4748 }
4749
4750 static size_t
4751 ReadCommandsCallbackFunction (void *baton,
4752 InputReader &reader,
4753 lldb::InputReaderAction notification,
4754 const char *bytes,
4755 size_t bytes_len)
4756 {
Caroline Tice892fadd2011-06-16 16:27:19 +00004757 StreamSP out_stream = reader.GetDebugger().GetAsyncOutputStream();
Jim Inghamd60d94a2011-03-11 03:53:59 +00004758 Target::StopHook *new_stop_hook = ((Target::StopHook *) baton);
Jim Inghame15511a2011-05-05 01:03:36 +00004759 static bool got_interrupted;
Caroline Tice892fadd2011-06-16 16:27:19 +00004760 bool batch_mode = reader.GetDebugger().GetCommandInterpreter().GetBatchCommandMode();
Jim Inghamd60d94a2011-03-11 03:53:59 +00004761
4762 switch (notification)
4763 {
4764 case eInputReaderActivate:
Caroline Tice892fadd2011-06-16 16:27:19 +00004765 if (!batch_mode)
4766 {
4767 out_stream->Printf ("%s\n", "Enter your stop hook command(s). Type 'DONE' to end.");
4768 if (reader.GetPrompt())
4769 out_stream->Printf ("%s", reader.GetPrompt());
4770 out_stream->Flush();
4771 }
Jim Inghame15511a2011-05-05 01:03:36 +00004772 got_interrupted = false;
Jim Inghamd60d94a2011-03-11 03:53:59 +00004773 break;
4774
4775 case eInputReaderDeactivate:
4776 break;
4777
4778 case eInputReaderReactivate:
Caroline Tice892fadd2011-06-16 16:27:19 +00004779 if (reader.GetPrompt() && !batch_mode)
Jim Inghamd60d94a2011-03-11 03:53:59 +00004780 {
Caroline Tice892fadd2011-06-16 16:27:19 +00004781 out_stream->Printf ("%s", reader.GetPrompt());
4782 out_stream->Flush();
Jim Inghamd60d94a2011-03-11 03:53:59 +00004783 }
Jim Inghame15511a2011-05-05 01:03:36 +00004784 got_interrupted = false;
Jim Inghamd60d94a2011-03-11 03:53:59 +00004785 break;
4786
Caroline Tice4a348082011-05-02 20:41:46 +00004787 case eInputReaderAsynchronousOutputWritten:
4788 break;
4789
Jim Inghamd60d94a2011-03-11 03:53:59 +00004790 case eInputReaderGotToken:
4791 if (bytes && bytes_len && baton)
4792 {
4793 StringList *commands = new_stop_hook->GetCommandPointer();
4794 if (commands)
4795 {
4796 commands->AppendString (bytes, bytes_len);
4797 }
4798 }
Caroline Tice892fadd2011-06-16 16:27:19 +00004799 if (!reader.IsDone() && reader.GetPrompt() && !batch_mode)
Jim Inghamd60d94a2011-03-11 03:53:59 +00004800 {
Caroline Tice892fadd2011-06-16 16:27:19 +00004801 out_stream->Printf ("%s", reader.GetPrompt());
4802 out_stream->Flush();
Jim Inghamd60d94a2011-03-11 03:53:59 +00004803 }
4804 break;
4805
4806 case eInputReaderInterrupt:
4807 {
4808 // Finish, and cancel the stop hook.
4809 new_stop_hook->GetTarget()->RemoveStopHookByID(new_stop_hook->GetID());
Caroline Tice892fadd2011-06-16 16:27:19 +00004810 if (!batch_mode)
4811 {
4812 out_stream->Printf ("Stop hook cancelled.\n");
4813 out_stream->Flush();
4814 }
4815
Jim Inghamd60d94a2011-03-11 03:53:59 +00004816 reader.SetIsDone (true);
4817 }
Jim Inghame15511a2011-05-05 01:03:36 +00004818 got_interrupted = true;
Jim Inghamd60d94a2011-03-11 03:53:59 +00004819 break;
4820
4821 case eInputReaderEndOfFile:
4822 reader.SetIsDone (true);
4823 break;
4824
4825 case eInputReaderDone:
Caroline Tice892fadd2011-06-16 16:27:19 +00004826 if (!got_interrupted && !batch_mode)
4827 {
Daniel Malea5f35a4b2012-11-29 21:49:15 +00004828 out_stream->Printf ("Stop hook #%" PRIu64 " added.\n", new_stop_hook->GetID());
Caroline Tice892fadd2011-06-16 16:27:19 +00004829 out_stream->Flush();
4830 }
Jim Inghamd60d94a2011-03-11 03:53:59 +00004831 break;
4832 }
4833
4834 return bytes_len;
4835 }
4836
Jim Inghamda26bd22012-06-08 21:56:10 +00004837protected:
Jim Inghamd60d94a2011-03-11 03:53:59 +00004838 bool
Jim Inghamda26bd22012-06-08 21:56:10 +00004839 DoExecute (Args& command, CommandReturnObject &result)
Jim Inghamd60d94a2011-03-11 03:53:59 +00004840 {
4841 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
4842 if (target)
4843 {
4844 Target::StopHookSP new_hook_sp;
4845 target->AddStopHook (new_hook_sp);
4846
4847 // First step, make the specifier.
4848 std::auto_ptr<SymbolContextSpecifier> specifier_ap;
4849 if (m_options.m_sym_ctx_specified)
4850 {
4851 specifier_ap.reset(new SymbolContextSpecifier(m_interpreter.GetDebugger().GetSelectedTarget()));
4852
4853 if (!m_options.m_module_name.empty())
4854 {
4855 specifier_ap->AddSpecification (m_options.m_module_name.c_str(), SymbolContextSpecifier::eModuleSpecified);
4856 }
4857
4858 if (!m_options.m_class_name.empty())
4859 {
4860 specifier_ap->AddSpecification (m_options.m_class_name.c_str(), SymbolContextSpecifier::eClassOrNamespaceSpecified);
4861 }
4862
4863 if (!m_options.m_file_name.empty())
4864 {
4865 specifier_ap->AddSpecification (m_options.m_file_name.c_str(), SymbolContextSpecifier::eFileSpecified);
4866 }
4867
4868 if (m_options.m_line_start != 0)
4869 {
4870 specifier_ap->AddLineSpecification (m_options.m_line_start, SymbolContextSpecifier::eLineStartSpecified);
4871 }
4872
4873 if (m_options.m_line_end != UINT_MAX)
4874 {
4875 specifier_ap->AddLineSpecification (m_options.m_line_end, SymbolContextSpecifier::eLineEndSpecified);
4876 }
4877
4878 if (!m_options.m_function_name.empty())
4879 {
4880 specifier_ap->AddSpecification (m_options.m_function_name.c_str(), SymbolContextSpecifier::eFunctionSpecified);
4881 }
4882 }
4883
4884 if (specifier_ap.get())
4885 new_hook_sp->SetSpecifier (specifier_ap.release());
4886
4887 // Next see if any of the thread options have been entered:
4888
4889 if (m_options.m_thread_specified)
4890 {
4891 ThreadSpec *thread_spec = new ThreadSpec();
4892
4893 if (m_options.m_thread_id != LLDB_INVALID_THREAD_ID)
4894 {
4895 thread_spec->SetTID (m_options.m_thread_id);
4896 }
4897
4898 if (m_options.m_thread_index != UINT32_MAX)
4899 thread_spec->SetIndex (m_options.m_thread_index);
4900
4901 if (!m_options.m_thread_name.empty())
4902 thread_spec->SetName (m_options.m_thread_name.c_str());
4903
4904 if (!m_options.m_queue_name.empty())
4905 thread_spec->SetQueueName (m_options.m_queue_name.c_str());
4906
4907 new_hook_sp->SetThreadSpecifier (thread_spec);
4908
4909 }
Johnny Chen60fe60e2011-05-02 23:47:55 +00004910 if (m_options.m_use_one_liner)
Jim Inghamd60d94a2011-03-11 03:53:59 +00004911 {
Johnny Chen60fe60e2011-05-02 23:47:55 +00004912 // Use one-liner.
4913 new_hook_sp->GetCommandPointer()->AppendString (m_options.m_one_liner.c_str());
Daniel Malea5f35a4b2012-11-29 21:49:15 +00004914 result.AppendMessageWithFormat("Stop hook #%" PRIu64 " added.\n", new_hook_sp->GetID());
Jim Inghamd60d94a2011-03-11 03:53:59 +00004915 }
Johnny Chen60fe60e2011-05-02 23:47:55 +00004916 else
Jim Inghamd60d94a2011-03-11 03:53:59 +00004917 {
Johnny Chen60fe60e2011-05-02 23:47:55 +00004918 // Otherwise gather up the command list, we'll push an input reader and suck the data from that directly into
4919 // the new stop hook's command string.
4920 InputReaderSP reader_sp (new InputReader(m_interpreter.GetDebugger()));
4921 if (!reader_sp)
4922 {
4923 result.AppendError("out of memory\n");
4924 result.SetStatus (eReturnStatusFailed);
4925 target->RemoveStopHookByID (new_hook_sp->GetID());
4926 return false;
4927 }
4928
4929 Error err (reader_sp->Initialize (CommandObjectTargetStopHookAdd::ReadCommandsCallbackFunction,
4930 new_hook_sp.get(), // baton
4931 eInputReaderGranularityLine, // token size, to pass to callback function
4932 "DONE", // end token
4933 "> ", // prompt
4934 true)); // echo input
4935 if (!err.Success())
4936 {
4937 result.AppendError (err.AsCString());
4938 result.SetStatus (eReturnStatusFailed);
4939 target->RemoveStopHookByID (new_hook_sp->GetID());
4940 return false;
4941 }
4942 m_interpreter.GetDebugger().PushInputReader (reader_sp);
Jim Inghamd60d94a2011-03-11 03:53:59 +00004943 }
Jim Inghamd60d94a2011-03-11 03:53:59 +00004944 result.SetStatus (eReturnStatusSuccessFinishNoResult);
4945 }
4946 else
4947 {
Greg Claytonabe0fed2011-04-18 08:33:37 +00004948 result.AppendError ("invalid target\n");
Jim Inghamd60d94a2011-03-11 03:53:59 +00004949 result.SetStatus (eReturnStatusFailed);
4950 }
4951
4952 return result.Succeeded();
4953 }
4954private:
4955 CommandOptions m_options;
4956};
4957
Greg Claytonb3448432011-03-24 21:19:54 +00004958OptionDefinition
Jim Inghamd60d94a2011-03-11 03:53:59 +00004959CommandObjectTargetStopHookAdd::CommandOptions::g_option_table[] =
4960{
Filipe Cabecinhas560c5142012-09-11 16:09:27 +00004961 { LLDB_OPT_SET_ALL, false, "one-liner", 'o', required_argument, NULL, 0, eArgTypeOneLiner,
Johnny Chen60fe60e2011-05-02 23:47:55 +00004962 "Specify a one-line breakpoint command inline. Be sure to surround it with quotes." },
Jim Inghamd60d94a2011-03-11 03:53:59 +00004963 { LLDB_OPT_SET_ALL, false, "shlib", 's', required_argument, NULL, CommandCompletions::eModuleCompletion, eArgTypeShlibName,
4964 "Set the module within which the stop-hook is to be run."},
Filipe Cabecinhas560c5142012-09-11 16:09:27 +00004965 { LLDB_OPT_SET_ALL, false, "thread-index", 'x', required_argument, NULL, 0, eArgTypeThreadIndex,
Jim Inghamd60d94a2011-03-11 03:53:59 +00004966 "The stop hook is run only for the thread whose index matches this argument."},
Filipe Cabecinhas560c5142012-09-11 16:09:27 +00004967 { LLDB_OPT_SET_ALL, false, "thread-id", 't', required_argument, NULL, 0, eArgTypeThreadID,
Jim Inghamd60d94a2011-03-11 03:53:59 +00004968 "The stop hook is run only for the thread whose TID matches this argument."},
Filipe Cabecinhas560c5142012-09-11 16:09:27 +00004969 { LLDB_OPT_SET_ALL, false, "thread-name", 'T', required_argument, NULL, 0, eArgTypeThreadName,
Jim Inghamd60d94a2011-03-11 03:53:59 +00004970 "The stop hook is run only for the thread whose thread name matches this argument."},
Filipe Cabecinhas560c5142012-09-11 16:09:27 +00004971 { LLDB_OPT_SET_ALL, false, "queue-name", 'q', required_argument, NULL, 0, eArgTypeQueueName,
Jim Inghamd60d94a2011-03-11 03:53:59 +00004972 "The stop hook is run only for threads in the queue whose name is given by this argument."},
4973 { LLDB_OPT_SET_1, false, "file", 'f', required_argument, NULL, CommandCompletions::eSourceFileCompletion, eArgTypeFilename,
4974 "Specify the source file within which the stop-hook is to be run." },
4975 { LLDB_OPT_SET_1, false, "start-line", 'l', required_argument, NULL, 0, eArgTypeLineNum,
4976 "Set the start of the line range for which the stop-hook is to be run."},
4977 { LLDB_OPT_SET_1, false, "end-line", 'e', required_argument, NULL, 0, eArgTypeLineNum,
4978 "Set the end of the line range for which the stop-hook is to be run."},
Filipe Cabecinhas560c5142012-09-11 16:09:27 +00004979 { LLDB_OPT_SET_2, false, "classname", 'c', required_argument, NULL, 0, eArgTypeClassName,
Jim Inghamd60d94a2011-03-11 03:53:59 +00004980 "Specify the class within which the stop-hook is to be run." },
4981 { LLDB_OPT_SET_3, false, "name", 'n', required_argument, NULL, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName,
4982 "Set the function name within which the stop hook will be run." },
4983 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
4984};
4985
4986#pragma mark CommandObjectTargetStopHookDelete
4987
4988//-------------------------------------------------------------------------
4989// CommandObjectTargetStopHookDelete
4990//-------------------------------------------------------------------------
4991
Jim Inghamda26bd22012-06-08 21:56:10 +00004992class CommandObjectTargetStopHookDelete : public CommandObjectParsed
Jim Inghamd60d94a2011-03-11 03:53:59 +00004993{
4994public:
4995
4996 CommandObjectTargetStopHookDelete (CommandInterpreter &interpreter) :
Jim Inghamda26bd22012-06-08 21:56:10 +00004997 CommandObjectParsed (interpreter,
4998 "target stop-hook delete",
4999 "Delete a stop-hook.",
5000 "target stop-hook delete [<idx>]")
Jim Inghamd60d94a2011-03-11 03:53:59 +00005001 {
5002 }
5003
5004 ~CommandObjectTargetStopHookDelete ()
5005 {
5006 }
5007
Jim Inghamda26bd22012-06-08 21:56:10 +00005008protected:
Jim Inghamd60d94a2011-03-11 03:53:59 +00005009 bool
Jim Inghamda26bd22012-06-08 21:56:10 +00005010 DoExecute (Args& command, CommandReturnObject &result)
Jim Inghamd60d94a2011-03-11 03:53:59 +00005011 {
5012 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
5013 if (target)
5014 {
5015 // FIXME: see if we can use the breakpoint id style parser?
5016 size_t num_args = command.GetArgumentCount();
5017 if (num_args == 0)
5018 {
5019 if (!m_interpreter.Confirm ("Delete all stop hooks?", true))
5020 {
5021 result.SetStatus (eReturnStatusFailed);
5022 return false;
5023 }
5024 else
5025 {
5026 target->RemoveAllStopHooks();
5027 }
5028 }
5029 else
5030 {
5031 bool success;
5032 for (size_t i = 0; i < num_args; i++)
5033 {
5034 lldb::user_id_t user_id = Args::StringToUInt32 (command.GetArgumentAtIndex(i), 0, 0, &success);
5035 if (!success)
5036 {
Greg Claytonabe0fed2011-04-18 08:33:37 +00005037 result.AppendErrorWithFormat ("invalid stop hook id: \"%s\".\n", command.GetArgumentAtIndex(i));
Jim Inghamd60d94a2011-03-11 03:53:59 +00005038 result.SetStatus(eReturnStatusFailed);
5039 return false;
5040 }
5041 success = target->RemoveStopHookByID (user_id);
5042 if (!success)
5043 {
Greg Claytonabe0fed2011-04-18 08:33:37 +00005044 result.AppendErrorWithFormat ("unknown stop hook id: \"%s\".\n", command.GetArgumentAtIndex(i));
Jim Inghamd60d94a2011-03-11 03:53:59 +00005045 result.SetStatus(eReturnStatusFailed);
5046 return false;
5047 }
5048 }
5049 }
5050 result.SetStatus (eReturnStatusSuccessFinishNoResult);
5051 }
5052 else
5053 {
Greg Claytonabe0fed2011-04-18 08:33:37 +00005054 result.AppendError ("invalid target\n");
Jim Inghamd60d94a2011-03-11 03:53:59 +00005055 result.SetStatus (eReturnStatusFailed);
5056 }
5057
5058 return result.Succeeded();
5059 }
5060};
5061#pragma mark CommandObjectTargetStopHookEnableDisable
5062
5063//-------------------------------------------------------------------------
5064// CommandObjectTargetStopHookEnableDisable
5065//-------------------------------------------------------------------------
5066
Jim Inghamda26bd22012-06-08 21:56:10 +00005067class CommandObjectTargetStopHookEnableDisable : public CommandObjectParsed
Jim Inghamd60d94a2011-03-11 03:53:59 +00005068{
5069public:
5070
5071 CommandObjectTargetStopHookEnableDisable (CommandInterpreter &interpreter, bool enable, const char *name, const char *help, const char *syntax) :
Jim Inghamda26bd22012-06-08 21:56:10 +00005072 CommandObjectParsed (interpreter,
5073 name,
5074 help,
5075 syntax),
Jim Inghamd60d94a2011-03-11 03:53:59 +00005076 m_enable (enable)
5077 {
5078 }
5079
5080 ~CommandObjectTargetStopHookEnableDisable ()
5081 {
5082 }
5083
Jim Inghamda26bd22012-06-08 21:56:10 +00005084protected:
Jim Inghamd60d94a2011-03-11 03:53:59 +00005085 bool
Jim Inghamda26bd22012-06-08 21:56:10 +00005086 DoExecute (Args& command, CommandReturnObject &result)
Jim Inghamd60d94a2011-03-11 03:53:59 +00005087 {
5088 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
5089 if (target)
5090 {
5091 // FIXME: see if we can use the breakpoint id style parser?
5092 size_t num_args = command.GetArgumentCount();
5093 bool success;
5094
5095 if (num_args == 0)
5096 {
5097 target->SetAllStopHooksActiveState (m_enable);
5098 }
5099 else
5100 {
5101 for (size_t i = 0; i < num_args; i++)
5102 {
5103 lldb::user_id_t user_id = Args::StringToUInt32 (command.GetArgumentAtIndex(i), 0, 0, &success);
5104 if (!success)
5105 {
Greg Claytonabe0fed2011-04-18 08:33:37 +00005106 result.AppendErrorWithFormat ("invalid stop hook id: \"%s\".\n", command.GetArgumentAtIndex(i));
Jim Inghamd60d94a2011-03-11 03:53:59 +00005107 result.SetStatus(eReturnStatusFailed);
5108 return false;
5109 }
5110 success = target->SetStopHookActiveStateByID (user_id, m_enable);
5111 if (!success)
5112 {
Greg Claytonabe0fed2011-04-18 08:33:37 +00005113 result.AppendErrorWithFormat ("unknown stop hook id: \"%s\".\n", command.GetArgumentAtIndex(i));
Jim Inghamd60d94a2011-03-11 03:53:59 +00005114 result.SetStatus(eReturnStatusFailed);
5115 return false;
5116 }
5117 }
5118 }
5119 result.SetStatus (eReturnStatusSuccessFinishNoResult);
5120 }
5121 else
5122 {
Greg Claytonabe0fed2011-04-18 08:33:37 +00005123 result.AppendError ("invalid target\n");
Jim Inghamd60d94a2011-03-11 03:53:59 +00005124 result.SetStatus (eReturnStatusFailed);
5125 }
5126 return result.Succeeded();
5127 }
5128private:
5129 bool m_enable;
5130};
5131
5132#pragma mark CommandObjectTargetStopHookList
5133
5134//-------------------------------------------------------------------------
5135// CommandObjectTargetStopHookList
5136//-------------------------------------------------------------------------
5137
Jim Inghamda26bd22012-06-08 21:56:10 +00005138class CommandObjectTargetStopHookList : public CommandObjectParsed
Jim Inghamd60d94a2011-03-11 03:53:59 +00005139{
5140public:
5141
5142 CommandObjectTargetStopHookList (CommandInterpreter &interpreter) :
Jim Inghamda26bd22012-06-08 21:56:10 +00005143 CommandObjectParsed (interpreter,
5144 "target stop-hook list",
5145 "List all stop-hooks.",
5146 "target stop-hook list [<type>]")
Jim Inghamd60d94a2011-03-11 03:53:59 +00005147 {
5148 }
5149
5150 ~CommandObjectTargetStopHookList ()
5151 {
5152 }
5153
Jim Inghamda26bd22012-06-08 21:56:10 +00005154protected:
Jim Inghamd60d94a2011-03-11 03:53:59 +00005155 bool
Jim Inghamda26bd22012-06-08 21:56:10 +00005156 DoExecute (Args& command, CommandReturnObject &result)
Jim Inghamd60d94a2011-03-11 03:53:59 +00005157 {
5158 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Johnny Chen9fc16922011-11-29 23:56:14 +00005159 if (!target)
Jim Inghamd60d94a2011-03-11 03:53:59 +00005160 {
Greg Claytonabe0fed2011-04-18 08:33:37 +00005161 result.AppendError ("invalid target\n");
Jim Inghamd60d94a2011-03-11 03:53:59 +00005162 result.SetStatus (eReturnStatusFailed);
Jason Molenda6e3a2412011-09-23 21:15:42 +00005163 return result.Succeeded();
Jim Inghamd60d94a2011-03-11 03:53:59 +00005164 }
5165
5166 size_t num_hooks = target->GetNumStopHooks ();
5167 if (num_hooks == 0)
5168 {
5169 result.GetOutputStream().PutCString ("No stop hooks.\n");
5170 }
5171 else
5172 {
5173 for (size_t i = 0; i < num_hooks; i++)
5174 {
5175 Target::StopHookSP this_hook = target->GetStopHookAtIndex (i);
5176 if (i > 0)
5177 result.GetOutputStream().PutCString ("\n");
5178 this_hook->GetDescription (&(result.GetOutputStream()), eDescriptionLevelFull);
5179 }
5180 }
Johnny Chen6c7c3902011-11-30 19:09:20 +00005181 result.SetStatus (eReturnStatusSuccessFinishResult);
Jim Inghamd60d94a2011-03-11 03:53:59 +00005182 return result.Succeeded();
5183 }
5184};
5185
5186#pragma mark CommandObjectMultiwordTargetStopHooks
5187//-------------------------------------------------------------------------
5188// CommandObjectMultiwordTargetStopHooks
5189//-------------------------------------------------------------------------
5190
5191class CommandObjectMultiwordTargetStopHooks : public CommandObjectMultiword
5192{
5193public:
5194
5195 CommandObjectMultiwordTargetStopHooks (CommandInterpreter &interpreter) :
5196 CommandObjectMultiword (interpreter,
5197 "target stop-hook",
5198 "A set of commands for operating on debugger target stop-hooks.",
5199 "target stop-hook <subcommand> [<subcommand-options>]")
5200 {
5201 LoadSubCommand ("add", CommandObjectSP (new CommandObjectTargetStopHookAdd (interpreter)));
5202 LoadSubCommand ("delete", CommandObjectSP (new CommandObjectTargetStopHookDelete (interpreter)));
5203 LoadSubCommand ("disable", CommandObjectSP (new CommandObjectTargetStopHookEnableDisable (interpreter,
5204 false,
5205 "target stop-hook disable [<id>]",
5206 "Disable a stop-hook.",
5207 "target stop-hook disable")));
5208 LoadSubCommand ("enable", CommandObjectSP (new CommandObjectTargetStopHookEnableDisable (interpreter,
5209 true,
5210 "target stop-hook enable [<id>]",
5211 "Enable a stop-hook.",
5212 "target stop-hook enable")));
5213 LoadSubCommand ("list", CommandObjectSP (new CommandObjectTargetStopHookList (interpreter)));
5214 }
5215
5216 ~CommandObjectMultiwordTargetStopHooks()
5217 {
5218 }
5219};
5220
5221
Chris Lattner24943d22010-06-08 16:52:24 +00005222
5223#pragma mark CommandObjectMultiwordTarget
5224
5225//-------------------------------------------------------------------------
5226// CommandObjectMultiwordTarget
5227//-------------------------------------------------------------------------
5228
Greg Clayton63094e02010-06-23 01:19:29 +00005229CommandObjectMultiwordTarget::CommandObjectMultiwordTarget (CommandInterpreter &interpreter) :
Greg Clayton238c0a12010-09-18 01:14:36 +00005230 CommandObjectMultiword (interpreter,
5231 "target",
Chris Lattner24943d22010-06-08 16:52:24 +00005232 "A set of commands for operating on debugger targets.",
5233 "target <subcommand> [<subcommand-options>]")
5234{
Greg Claytonabe0fed2011-04-18 08:33:37 +00005235
5236 LoadSubCommand ("create", CommandObjectSP (new CommandObjectTargetCreate (interpreter)));
Greg Clayton153ccd72011-08-10 02:10:13 +00005237 LoadSubCommand ("delete", CommandObjectSP (new CommandObjectTargetDelete (interpreter)));
Greg Claytonabe0fed2011-04-18 08:33:37 +00005238 LoadSubCommand ("list", CommandObjectSP (new CommandObjectTargetList (interpreter)));
5239 LoadSubCommand ("select", CommandObjectSP (new CommandObjectTargetSelect (interpreter)));
Jim Inghamd60d94a2011-03-11 03:53:59 +00005240 LoadSubCommand ("stop-hook", CommandObjectSP (new CommandObjectMultiwordTargetStopHooks (interpreter)));
Greg Claytone1f50b92011-05-03 22:09:39 +00005241 LoadSubCommand ("modules", CommandObjectSP (new CommandObjectTargetModules (interpreter)));
Greg Clayton3508c382012-02-24 01:59:29 +00005242 LoadSubCommand ("symbols", CommandObjectSP (new CommandObjectTargetSymbols (interpreter)));
Greg Clayton801417e2011-07-07 01:59:51 +00005243 LoadSubCommand ("variable", CommandObjectSP (new CommandObjectTargetVariable (interpreter)));
Chris Lattner24943d22010-06-08 16:52:24 +00005244}
5245
5246CommandObjectMultiwordTarget::~CommandObjectMultiwordTarget ()
5247{
5248}
5249
Greg Claytonabe0fed2011-04-18 08:33:37 +00005250