blob: 16ce7ee32d8215bd2eed521d2ca740e3d9039c15 [file] [log] [blame]
Chris Lattner30fdc8d2010-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
Daniel Malea93a64302012-12-05 00:20:57 +000010#include "lldb/lldb-python.h"
11
Chris Lattner30fdc8d2010-06-08 16:52:24 +000012#include "CommandObjectTarget.h"
13
14// C Includes
15#include <errno.h>
Greg Claytonc4a99bc2011-02-01 01:13:32 +000016
Chris Lattner30fdc8d2010-06-08 16:52:24 +000017// C++ Includes
18// Other libraries and framework includes
19// Project includes
Jim Ingham40af72e2010-06-15 19:49:27 +000020#include "lldb/Interpreter/Args.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000021#include "lldb/Core/Debugger.h"
Greg Clayton44d93782014-01-27 23:43:24 +000022#include "lldb/Core/IOHandler.h"
Greg Clayton1f746072012-08-29 21:13:06 +000023#include "lldb/Core/Module.h"
24#include "lldb/Core/ModuleSpec.h"
Greg Claytoneffe5c92011-05-03 22:09:39 +000025#include "lldb/Core/Section.h"
Greg Clayton7260f622011-04-18 08:33:37 +000026#include "lldb/Core/State.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000027#include "lldb/Core/Timer.h"
Greg Clayton644247c2011-07-07 01:59:51 +000028#include "lldb/Core/ValueObjectVariable.h"
Enrico Granata4d93b8c2013-09-30 19:11:51 +000029#include "lldb/DataFormatters/ValueObjectPrinter.h"
Greg Claytonc8f814d2012-09-27 03:13:55 +000030#include "lldb/Host/Symbols.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000031#include "lldb/Interpreter/CommandInterpreter.h"
32#include "lldb/Interpreter/CommandReturnObject.h"
Greg Claytoneffe5c92011-05-03 22:09:39 +000033#include "lldb/Interpreter/Options.h"
Greg Clayton7260f622011-04-18 08:33:37 +000034#include "lldb/Interpreter/OptionGroupArchitecture.h"
Greg Claytonaa149cb2011-08-11 02:48:45 +000035#include "lldb/Interpreter/OptionGroupBoolean.h"
Greg Claytoneffe5c92011-05-03 22:09:39 +000036#include "lldb/Interpreter/OptionGroupFile.h"
Greg Clayton1deb7962011-10-25 06:44:01 +000037#include "lldb/Interpreter/OptionGroupFormat.h"
Greg Clayton715c2362011-07-07 04:38:25 +000038#include "lldb/Interpreter/OptionGroupVariable.h"
Greg Clayton7260f622011-04-18 08:33:37 +000039#include "lldb/Interpreter/OptionGroupPlatform.h"
Greg Claytoneffe5c92011-05-03 22:09:39 +000040#include "lldb/Interpreter/OptionGroupUInt64.h"
41#include "lldb/Interpreter/OptionGroupUUID.h"
Greg Clayton644247c2011-07-07 01:59:51 +000042#include "lldb/Interpreter/OptionGroupValueObjectDisplay.h"
Greg Clayton1f746072012-08-29 21:13:06 +000043#include "lldb/Symbol/CompileUnit.h"
Jason Molenda380241a2012-07-12 00:20:07 +000044#include "lldb/Symbol/FuncUnwinders.h"
Greg Claytoneffe5c92011-05-03 22:09:39 +000045#include "lldb/Symbol/LineTable.h"
46#include "lldb/Symbol/ObjectFile.h"
47#include "lldb/Symbol/SymbolFile.h"
48#include "lldb/Symbol/SymbolVendor.h"
Jason Molenda380241a2012-07-12 00:20:07 +000049#include "lldb/Symbol/UnwindPlan.h"
Greg Clayton644247c2011-07-07 01:59:51 +000050#include "lldb/Symbol/VariableList.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000051#include "lldb/Target/Process.h"
Greg Claytond5944cd2013-12-06 01:12:00 +000052#include "lldb/Target/SectionLoadList.h"
Jason Molendab57e4a12013-11-04 09:33:30 +000053#include "lldb/Target/StackFrame.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000054#include "lldb/Target/Thread.h"
Jim Ingham9575d842011-03-11 03:53:59 +000055#include "lldb/Target/ThreadSpec.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000056
57using namespace lldb;
58using namespace lldb_private;
59
Greg Clayton7260f622011-04-18 08:33:37 +000060
61
62static void
63DumpTargetInfo (uint32_t target_idx, Target *target, const char *prefix_cstr, bool show_stopped_process_status, Stream &strm)
64{
Greg Clayton176761e2011-04-19 04:19:37 +000065 const ArchSpec &target_arch = target->GetArchitecture();
Greg Clayton7260f622011-04-18 08:33:37 +000066
Greg Claytonaa149cb2011-08-11 02:48:45 +000067 Module *exe_module = target->GetExecutableModulePointer();
Greg Clayton7260f622011-04-18 08:33:37 +000068 char exe_path[PATH_MAX];
69 bool exe_valid = false;
Greg Claytonaa149cb2011-08-11 02:48:45 +000070 if (exe_module)
71 exe_valid = exe_module->GetFileSpec().GetPath (exe_path, sizeof(exe_path));
Greg Clayton7260f622011-04-18 08:33:37 +000072
73 if (!exe_valid)
74 ::strcpy (exe_path, "<none>");
75
76 strm.Printf ("%starget #%u: %s", prefix_cstr ? prefix_cstr : "", target_idx, exe_path);
77
78 uint32_t properties = 0;
79 if (target_arch.IsValid())
80 {
81 strm.Printf ("%sarch=%s", properties++ > 0 ? ", " : " ( ", target_arch.GetTriple().str().c_str());
82 properties++;
83 }
84 PlatformSP platform_sp (target->GetPlatform());
85 if (platform_sp)
Greg Clayton57abc5d2013-05-10 21:47:16 +000086 strm.Printf ("%splatform=%s", properties++ > 0 ? ", " : " ( ", platform_sp->GetName().GetCString());
Greg Clayton7260f622011-04-18 08:33:37 +000087
88 ProcessSP process_sp (target->GetProcessSP());
89 bool show_process_status = false;
90 if (process_sp)
91 {
92 lldb::pid_t pid = process_sp->GetID();
93 StateType state = process_sp->GetState();
94 if (show_stopped_process_status)
Greg Clayton2637f822011-11-17 01:23:07 +000095 show_process_status = StateIsStoppedState(state, true);
Greg Clayton7260f622011-04-18 08:33:37 +000096 const char *state_cstr = StateAsCString (state);
97 if (pid != LLDB_INVALID_PROCESS_ID)
Daniel Malead01b2952012-11-29 21:49:15 +000098 strm.Printf ("%spid=%" PRIu64, properties++ > 0 ? ", " : " ( ", pid);
Greg Clayton7260f622011-04-18 08:33:37 +000099 strm.Printf ("%sstate=%s", properties++ > 0 ? ", " : " ( ", state_cstr);
100 }
101 if (properties > 0)
102 strm.PutCString (" )\n");
103 else
104 strm.EOL();
105 if (show_process_status)
106 {
107 const bool only_threads_with_stop_reason = true;
108 const uint32_t start_frame = 0;
109 const uint32_t num_frames = 1;
110 const uint32_t num_frames_with_source = 1;
111 process_sp->GetStatus (strm);
112 process_sp->GetThreadStatus (strm,
113 only_threads_with_stop_reason,
114 start_frame,
115 num_frames,
116 num_frames_with_source);
117
118 }
119}
120
121static uint32_t
122DumpTargetList (TargetList &target_list, bool show_stopped_process_status, Stream &strm)
123{
124 const uint32_t num_targets = target_list.GetNumTargets();
125 if (num_targets)
126 {
127 TargetSP selected_target_sp (target_list.GetSelectedTarget());
128 strm.PutCString ("Current targets:\n");
129 for (uint32_t i=0; i<num_targets; ++i)
130 {
131 TargetSP target_sp (target_list.GetTargetAtIndex (i));
132 if (target_sp)
133 {
134 bool is_selected = target_sp.get() == selected_target_sp.get();
135 DumpTargetInfo (i,
136 target_sp.get(),
137 is_selected ? "* " : " ",
138 show_stopped_process_status,
139 strm);
140 }
141 }
142 }
143 return num_targets;
144}
145#pragma mark CommandObjectTargetCreate
146
147//-------------------------------------------------------------------------
148// "target create"
149//-------------------------------------------------------------------------
150
Jim Ingham5a988412012-06-08 21:56:10 +0000151class CommandObjectTargetCreate : public CommandObjectParsed
Greg Clayton7260f622011-04-18 08:33:37 +0000152{
153public:
154 CommandObjectTargetCreate(CommandInterpreter &interpreter) :
Jim Ingham5a988412012-06-08 21:56:10 +0000155 CommandObjectParsed (interpreter,
156 "target create",
157 "Create a target using the argument as the main executable.",
158 NULL),
Greg Clayton7260f622011-04-18 08:33:37 +0000159 m_option_group (interpreter),
Greg Clayton644247c2011-07-07 01:59:51 +0000160 m_arch_option (),
Greg Claytonc3776bf2012-02-09 06:16:32 +0000161 m_platform_options(true), // Do include the "--platform" option in the platform settings by passing true
Greg Clayton1c5f1862012-11-30 19:05:35 +0000162 m_core_file (LLDB_OPT_SET_1, false, "core", 'c', 0, eArgTypeFilename, "Fullpath to a core file to use for this target."),
Daniel Maleae0f8f572013-08-26 23:57:52 +0000163 m_platform_path (LLDB_OPT_SET_1, false, "platform-path", 'P', 0, eArgTypePath, "Path to the remote file to use for this target."),
Greg Clayton1c5f1862012-11-30 19:05:35 +0000164 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."),
Jim Inghambf22b962013-07-11 01:47:46 +0000165 m_remote_file (LLDB_OPT_SET_1, false, "remote-file", 'r', 0, eArgTypeFilename, "Fullpath to the file on the remote host if debugging remotely."),
Greg Clayton1c5f1862012-11-30 19:05:35 +0000166 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 Clayton7260f622011-04-18 08:33:37 +0000167 {
168 CommandArgumentEntry arg;
169 CommandArgumentData file_arg;
170
171 // Define the first (and only) variant of this arg.
172 file_arg.arg_type = eArgTypeFilename;
173 file_arg.arg_repetition = eArgRepeatPlain;
174
175 // There is only one variant this argument could be; put it into the argument entry.
176 arg.push_back (file_arg);
177
178 // Push the data for the first argument into the m_arguments vector.
179 m_arguments.push_back (arg);
180
Greg Clayton644247c2011-07-07 01:59:51 +0000181 m_option_group.Append (&m_arch_option, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
Greg Clayton7260f622011-04-18 08:33:37 +0000182 m_option_group.Append (&m_platform_options, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
Greg Claytonc3776bf2012-02-09 06:16:32 +0000183 m_option_group.Append (&m_core_file, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000184 m_option_group.Append (&m_platform_path, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
Greg Clayton1c5f1862012-11-30 19:05:35 +0000185 m_option_group.Append (&m_symbol_file, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
Jim Inghambf22b962013-07-11 01:47:46 +0000186 m_option_group.Append (&m_remote_file, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
Greg Clayton1c5f1862012-11-30 19:05:35 +0000187 m_option_group.Append (&m_add_dependents, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
Greg Clayton7260f622011-04-18 08:33:37 +0000188 m_option_group.Finalize();
189 }
190
191 ~CommandObjectTargetCreate ()
192 {
193 }
194
195 Options *
196 GetOptions ()
197 {
198 return &m_option_group;
199 }
200
Greg Claytonc7bece562013-01-25 18:06:21 +0000201 virtual int
Jim Ingham5a988412012-06-08 21:56:10 +0000202 HandleArgumentCompletion (Args &input,
203 int &cursor_index,
204 int &cursor_char_position,
205 OptionElementVector &opt_element_vector,
206 int match_start_point,
207 int max_return_elements,
208 bool &word_complete,
209 StringList &matches)
210 {
211 std::string completion_str (input.GetArgumentAtIndex(cursor_index));
212 completion_str.erase (cursor_char_position);
213
214 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
215 CommandCompletions::eDiskFileCompletion,
216 completion_str.c_str(),
217 match_start_point,
218 max_return_elements,
219 NULL,
220 word_complete,
221 matches);
222 return matches.GetSize();
223 }
224
225protected:
Greg Clayton7260f622011-04-18 08:33:37 +0000226 bool
Jim Ingham5a988412012-06-08 21:56:10 +0000227 DoExecute (Args& command, CommandReturnObject &result)
Greg Clayton7260f622011-04-18 08:33:37 +0000228 {
Greg Claytonc7bece562013-01-25 18:06:21 +0000229 const size_t argc = command.GetArgumentCount();
Greg Claytonc3776bf2012-02-09 06:16:32 +0000230 FileSpec core_file (m_core_file.GetOptionValue().GetCurrentValue());
Jim Inghambf22b962013-07-11 01:47:46 +0000231 FileSpec remote_file (m_remote_file.GetOptionValue().GetCurrentValue());
Greg Claytonc3776bf2012-02-09 06:16:32 +0000232
Daniel Maleae0f8f572013-08-26 23:57:52 +0000233 if (argc == 1 || core_file || remote_file)
Greg Clayton7260f622011-04-18 08:33:37 +0000234 {
Greg Clayton1c5f1862012-11-30 19:05:35 +0000235 FileSpec symfile (m_symbol_file.GetOptionValue().GetCurrentValue());
236 if (symfile)
237 {
238 if (!symfile.Exists())
239 {
240 char symfile_path[PATH_MAX];
241 symfile.GetPath(symfile_path, sizeof(symfile_path));
242 result.AppendErrorWithFormat("invalid symbol file path '%s'", symfile_path);
243 result.SetStatus (eReturnStatusFailed);
244 return false;
245 }
246 }
247
Greg Clayton7260f622011-04-18 08:33:37 +0000248 const char *file_path = command.GetArgumentAtIndex(0);
249 Timer scoped_timer(__PRETTY_FUNCTION__, "(lldb) target create '%s'", file_path);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000250 FileSpec file_spec;
251
252 if (file_path)
253 file_spec.SetFile (file_path, true);
254
255 bool must_set_platform_path = false;
256
Greg Clayton7260f622011-04-18 08:33:37 +0000257 Debugger &debugger = m_interpreter.GetDebugger();
Daniel Maleae0f8f572013-08-26 23:57:52 +0000258 PlatformSP platform_sp(debugger.GetPlatformList().GetSelectedPlatform ());
259
260 if (remote_file)
261 {
262 // I have a remote file.. two possible cases
263 if (file_spec && file_spec.Exists())
264 {
265 // if the remote file does not exist, push it there
266 if (!platform_sp->GetFileExists (remote_file))
267 {
268 Error err = platform_sp->PutFile(file_spec, remote_file);
269 if (err.Fail())
270 {
271 result.AppendError(err.AsCString());
272 result.SetStatus (eReturnStatusFailed);
273 return false;
274 }
275 }
276 }
277 else
278 {
279 // there is no local file and we need one
280 // in order to make the remote ---> local transfer we need a platform
281 // TODO: if the user has passed in a --platform argument, use it to fetch the right platform
282 if (!platform_sp)
283 {
284 result.AppendError("unable to perform remote debugging without a platform");
285 result.SetStatus (eReturnStatusFailed);
286 return false;
287 }
288 if (file_path)
289 {
290 // copy the remote file to the local file
291 Error err = platform_sp->GetFile(remote_file, file_spec);
292 if (err.Fail())
293 {
294 result.AppendError(err.AsCString());
295 result.SetStatus (eReturnStatusFailed);
296 return false;
297 }
298 }
299 else
300 {
301 // make up a local file
302 result.AppendError("remote --> local transfer without local path is not implemented yet");
303 result.SetStatus (eReturnStatusFailed);
304 return false;
305 }
306 }
307 }
308
309 TargetSP target_sp;
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000310 const char *arch_cstr = m_arch_option.GetArchitectureName();
Greg Clayton1c5f1862012-11-30 19:05:35 +0000311 const bool get_dependent_files = m_add_dependents.GetOptionValue().GetCurrentValue();
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000312 Error error (debugger.GetTargetList().CreateTarget (debugger,
Daniel Maleae0f8f572013-08-26 23:57:52 +0000313// remote_file ? remote_file : file_spec,
Greg Claytona0ca6602012-10-18 16:33:33 +0000314 file_path,
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000315 arch_cstr,
316 get_dependent_files,
317 &m_platform_options,
318 target_sp));
319
Greg Clayton7260f622011-04-18 08:33:37 +0000320 if (target_sp)
321 {
Jim Inghambf22b962013-07-11 01:47:46 +0000322 if (symfile || remote_file)
Greg Clayton1c5f1862012-11-30 19:05:35 +0000323 {
324 ModuleSP module_sp (target_sp->GetExecutableModule());
325 if (module_sp)
Jim Inghambf22b962013-07-11 01:47:46 +0000326 {
327 if (symfile)
328 module_sp->SetSymbolFileFileSpec(symfile);
329 if (remote_file)
330 {
331 std::string remote_path = remote_file.GetPath();
332 target_sp->SetArg0(remote_path.c_str());
333 module_sp->SetPlatformFileSpec(remote_file);
334 }
335 }
Greg Clayton1c5f1862012-11-30 19:05:35 +0000336 }
337
Greg Clayton7260f622011-04-18 08:33:37 +0000338 debugger.GetTargetList().SetSelectedTarget(target_sp.get());
Daniel Maleae0f8f572013-08-26 23:57:52 +0000339 if (must_set_platform_path)
340 {
341 ModuleSpec main_module_spec(file_spec);
342 ModuleSP module_sp = target_sp->GetSharedModule(main_module_spec);
343 if (module_sp)
344 module_sp->SetPlatformFileSpec(remote_file);
345 }
Greg Claytonc3776bf2012-02-09 06:16:32 +0000346 if (core_file)
347 {
Greg Claytonc3776bf2012-02-09 06:16:32 +0000348 char core_path[PATH_MAX];
349 core_file.GetPath(core_path, sizeof(core_path));
Greg Claytonc859e2d2012-02-13 23:10:39 +0000350 if (core_file.Exists())
Greg Claytonc3776bf2012-02-09 06:16:32 +0000351 {
Greg Claytonc859e2d2012-02-13 23:10:39 +0000352 FileSpec core_file_dir;
353 core_file_dir.GetDirectory() = core_file.GetDirectory();
354 target_sp->GetExecutableSearchPaths ().Append (core_file_dir);
Greg Claytonc3776bf2012-02-09 06:16:32 +0000355
Greg Claytonc859e2d2012-02-13 23:10:39 +0000356 ProcessSP process_sp (target_sp->CreateProcess (m_interpreter.GetDebugger().GetListener(), NULL, &core_file));
357
358 if (process_sp)
Greg Claytonc3776bf2012-02-09 06:16:32 +0000359 {
Greg Claytonc859e2d2012-02-13 23:10:39 +0000360 // Seems wierd that we Launch a core file, but that is
361 // what we do!
362 error = process_sp->LoadCore();
363
364 if (error.Fail())
365 {
366 result.AppendError(error.AsCString("can't find plug-in for core file"));
367 result.SetStatus (eReturnStatusFailed);
368 return false;
369 }
370 else
371 {
372 result.AppendMessageWithFormat ("Core file '%s' (%s) was loaded.\n", core_path, target_sp->GetArchitecture().GetArchitectureName());
373 result.SetStatus (eReturnStatusSuccessFinishNoResult);
374 }
Greg Claytonc3776bf2012-02-09 06:16:32 +0000375 }
376 else
377 {
Greg Claytonc859e2d2012-02-13 23:10:39 +0000378 result.AppendErrorWithFormat ("Unable to find process plug-in for core file '%s'\n", core_path);
379 result.SetStatus (eReturnStatusFailed);
Greg Claytonc3776bf2012-02-09 06:16:32 +0000380 }
381 }
382 else
383 {
Greg Claytonc859e2d2012-02-13 23:10:39 +0000384 result.AppendErrorWithFormat ("Core file '%s' does not exist\n", core_path);
Greg Claytonc3776bf2012-02-09 06:16:32 +0000385 result.SetStatus (eReturnStatusFailed);
386 }
387 }
388 else
389 {
390 result.AppendMessageWithFormat ("Current executable set to '%s' (%s).\n", file_path, target_sp->GetArchitecture().GetArchitectureName());
391 result.SetStatus (eReturnStatusSuccessFinishNoResult);
392 }
Greg Clayton7260f622011-04-18 08:33:37 +0000393 }
394 else
395 {
396 result.AppendError(error.AsCString());
397 result.SetStatus (eReturnStatusFailed);
398 }
399 }
400 else
401 {
Greg Claytonc3776bf2012-02-09 06:16:32 +0000402 result.AppendErrorWithFormat("'%s' takes exactly one executable path argument, or use the --core-file option.\n", m_cmd_name.c_str());
Greg Clayton7260f622011-04-18 08:33:37 +0000403 result.SetStatus (eReturnStatusFailed);
404 }
405 return result.Succeeded();
406
407 }
408
Greg Clayton7260f622011-04-18 08:33:37 +0000409private:
410 OptionGroupOptions m_option_group;
Greg Clayton644247c2011-07-07 01:59:51 +0000411 OptionGroupArchitecture m_arch_option;
Greg Clayton7260f622011-04-18 08:33:37 +0000412 OptionGroupPlatform m_platform_options;
Greg Claytonc3776bf2012-02-09 06:16:32 +0000413 OptionGroupFile m_core_file;
Daniel Maleae0f8f572013-08-26 23:57:52 +0000414 OptionGroupFile m_platform_path;
Greg Clayton1c5f1862012-11-30 19:05:35 +0000415 OptionGroupFile m_symbol_file;
Jim Inghambf22b962013-07-11 01:47:46 +0000416 OptionGroupFile m_remote_file;
Greg Clayton1c5f1862012-11-30 19:05:35 +0000417 OptionGroupBoolean m_add_dependents;
Greg Clayton7260f622011-04-18 08:33:37 +0000418};
419
420#pragma mark CommandObjectTargetList
421
422//----------------------------------------------------------------------
423// "target list"
424//----------------------------------------------------------------------
425
Jim Ingham5a988412012-06-08 21:56:10 +0000426class CommandObjectTargetList : public CommandObjectParsed
Greg Clayton7260f622011-04-18 08:33:37 +0000427{
428public:
429 CommandObjectTargetList (CommandInterpreter &interpreter) :
Jim Ingham5a988412012-06-08 21:56:10 +0000430 CommandObjectParsed (interpreter,
431 "target list",
432 "List all current targets in the current debug session.",
433 NULL,
434 0)
Greg Clayton7260f622011-04-18 08:33:37 +0000435 {
436 }
437
438 virtual
439 ~CommandObjectTargetList ()
440 {
441 }
442
Jim Ingham5a988412012-06-08 21:56:10 +0000443protected:
Greg Clayton7260f622011-04-18 08:33:37 +0000444 virtual bool
Jim Ingham5a988412012-06-08 21:56:10 +0000445 DoExecute (Args& args, CommandReturnObject &result)
Greg Clayton7260f622011-04-18 08:33:37 +0000446 {
447 if (args.GetArgumentCount() == 0)
448 {
449 Stream &strm = result.GetOutputStream();
450
451 bool show_stopped_process_status = false;
452 if (DumpTargetList (m_interpreter.GetDebugger().GetTargetList(), show_stopped_process_status, strm) == 0)
453 {
454 strm.PutCString ("No targets.\n");
455 }
Johnny Chen1ee61a72011-04-18 21:08:05 +0000456 result.SetStatus (eReturnStatusSuccessFinishResult);
Greg Clayton7260f622011-04-18 08:33:37 +0000457 }
458 else
459 {
460 result.AppendError ("the 'target list' command takes no arguments\n");
461 result.SetStatus (eReturnStatusFailed);
462 }
463 return result.Succeeded();
464 }
465};
466
467
468#pragma mark CommandObjectTargetSelect
469
470//----------------------------------------------------------------------
471// "target select"
472//----------------------------------------------------------------------
473
Jim Ingham5a988412012-06-08 21:56:10 +0000474class CommandObjectTargetSelect : public CommandObjectParsed
Greg Clayton7260f622011-04-18 08:33:37 +0000475{
476public:
477 CommandObjectTargetSelect (CommandInterpreter &interpreter) :
Jim Ingham5a988412012-06-08 21:56:10 +0000478 CommandObjectParsed (interpreter,
479 "target select",
480 "Select a target as the current target by target index.",
481 NULL,
482 0)
Greg Clayton7260f622011-04-18 08:33:37 +0000483 {
484 }
485
486 virtual
487 ~CommandObjectTargetSelect ()
488 {
489 }
490
Jim Ingham5a988412012-06-08 21:56:10 +0000491protected:
Greg Clayton7260f622011-04-18 08:33:37 +0000492 virtual bool
Jim Ingham5a988412012-06-08 21:56:10 +0000493 DoExecute (Args& args, CommandReturnObject &result)
Greg Clayton7260f622011-04-18 08:33:37 +0000494 {
495 if (args.GetArgumentCount() == 1)
496 {
497 bool success = false;
498 const char *target_idx_arg = args.GetArgumentAtIndex(0);
499 uint32_t target_idx = Args::StringToUInt32 (target_idx_arg, UINT32_MAX, 0, &success);
500 if (success)
501 {
502 TargetList &target_list = m_interpreter.GetDebugger().GetTargetList();
503 const uint32_t num_targets = target_list.GetNumTargets();
504 if (target_idx < num_targets)
505 {
506 TargetSP target_sp (target_list.GetTargetAtIndex (target_idx));
507 if (target_sp)
508 {
509 Stream &strm = result.GetOutputStream();
510 target_list.SetSelectedTarget (target_sp.get());
511 bool show_stopped_process_status = false;
512 DumpTargetList (target_list, show_stopped_process_status, strm);
Johnny Chen1ee61a72011-04-18 21:08:05 +0000513 result.SetStatus (eReturnStatusSuccessFinishResult);
Greg Clayton7260f622011-04-18 08:33:37 +0000514 }
515 else
516 {
517 result.AppendErrorWithFormat ("target #%u is NULL in target list\n", target_idx);
518 result.SetStatus (eReturnStatusFailed);
519 }
520 }
521 else
522 {
523 result.AppendErrorWithFormat ("index %u is out of range, valid target indexes are 0 - %u\n",
524 target_idx,
525 num_targets - 1);
526 result.SetStatus (eReturnStatusFailed);
527 }
528 }
529 else
530 {
531 result.AppendErrorWithFormat("invalid index string value '%s'\n", target_idx_arg);
532 result.SetStatus (eReturnStatusFailed);
533 }
534 }
535 else
536 {
537 result.AppendError ("'target select' takes a single argument: a target index\n");
538 result.SetStatus (eReturnStatusFailed);
539 }
540 return result.Succeeded();
541 }
542};
543
Greg Clayton3418c852011-08-10 02:10:13 +0000544#pragma mark CommandObjectTargetSelect
545
546//----------------------------------------------------------------------
547// "target delete"
548//----------------------------------------------------------------------
549
Jim Ingham5a988412012-06-08 21:56:10 +0000550class CommandObjectTargetDelete : public CommandObjectParsed
Greg Clayton3418c852011-08-10 02:10:13 +0000551{
552public:
553 CommandObjectTargetDelete (CommandInterpreter &interpreter) :
Jim Ingham5a988412012-06-08 21:56:10 +0000554 CommandObjectParsed (interpreter,
555 "target delete",
556 "Delete one or more targets by target index.",
557 NULL,
558 0),
Greg Claytonaa149cb2011-08-11 02:48:45 +0000559 m_option_group (interpreter),
Greg Claytonb5f0fea2012-09-27 22:26:11 +0000560 m_cleanup_option (LLDB_OPT_SET_1, false, "clean", 'c', "Perform extra cleanup to minimize memory consumption after deleting the target.", false, false)
Greg Clayton3418c852011-08-10 02:10:13 +0000561 {
Greg Claytonaa149cb2011-08-11 02:48:45 +0000562 m_option_group.Append (&m_cleanup_option, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
563 m_option_group.Finalize();
Greg Clayton3418c852011-08-10 02:10:13 +0000564 }
565
566 virtual
567 ~CommandObjectTargetDelete ()
568 {
569 }
570
Jim Ingham5a988412012-06-08 21:56:10 +0000571 Options *
572 GetOptions ()
573 {
574 return &m_option_group;
575 }
576
577protected:
Greg Clayton3418c852011-08-10 02:10:13 +0000578 virtual bool
Jim Ingham5a988412012-06-08 21:56:10 +0000579 DoExecute (Args& args, CommandReturnObject &result)
Greg Clayton3418c852011-08-10 02:10:13 +0000580 {
581 const size_t argc = args.GetArgumentCount();
582 std::vector<TargetSP> delete_target_list;
583 TargetList &target_list = m_interpreter.GetDebugger().GetTargetList();
584 bool success = true;
585 TargetSP target_sp;
586 if (argc > 0)
587 {
588 const uint32_t num_targets = target_list.GetNumTargets();
Filipe Cabecinhasf065fdc2012-07-09 13:02:17 +0000589 // Bail out if don't have any targets.
590 if (num_targets == 0) {
591 result.AppendError("no targets to delete");
592 result.SetStatus(eReturnStatusFailed);
593 success = false;
594 }
595
Greg Clayton3418c852011-08-10 02:10:13 +0000596 for (uint32_t arg_idx = 0; success && arg_idx < argc; ++arg_idx)
597 {
598 const char *target_idx_arg = args.GetArgumentAtIndex(arg_idx);
599 uint32_t target_idx = Args::StringToUInt32 (target_idx_arg, UINT32_MAX, 0, &success);
600 if (success)
601 {
602 if (target_idx < num_targets)
603 {
604 target_sp = target_list.GetTargetAtIndex (target_idx);
605 if (target_sp)
606 {
607 delete_target_list.push_back (target_sp);
608 continue;
609 }
610 }
Filipe Cabecinhasf065fdc2012-07-09 13:02:17 +0000611 if (num_targets > 1)
612 result.AppendErrorWithFormat ("target index %u is out of range, valid target indexes are 0 - %u\n",
613 target_idx,
614 num_targets - 1);
615 else
616 result.AppendErrorWithFormat("target index %u is out of range, the only valid index is 0\n",
617 target_idx);
618
Greg Clayton3418c852011-08-10 02:10:13 +0000619 result.SetStatus (eReturnStatusFailed);
620 success = false;
621 }
622 else
623 {
624 result.AppendErrorWithFormat("invalid target index '%s'\n", target_idx_arg);
625 result.SetStatus (eReturnStatusFailed);
626 success = false;
627 }
628 }
629
630 }
631 else
632 {
633 target_sp = target_list.GetSelectedTarget();
634 if (target_sp)
635 {
636 delete_target_list.push_back (target_sp);
637 }
638 else
639 {
640 result.AppendErrorWithFormat("no target is currently selected\n");
641 result.SetStatus (eReturnStatusFailed);
642 success = false;
643 }
644 }
645 if (success)
646 {
647 const size_t num_targets_to_delete = delete_target_list.size();
648 for (size_t idx = 0; idx < num_targets_to_delete; ++idx)
649 {
650 target_sp = delete_target_list[idx];
651 target_list.DeleteTarget(target_sp);
652 target_sp->Destroy();
653 }
Greg Claytonaa149cb2011-08-11 02:48:45 +0000654 // If "--clean" was specified, prune any orphaned shared modules from
655 // the global shared module list
656 if (m_cleanup_option.GetOptionValue ())
657 {
Greg Clayton0cd70862012-04-09 20:22:01 +0000658 const bool mandatory = true;
659 ModuleList::RemoveOrphanSharedModules(mandatory);
Greg Claytonaa149cb2011-08-11 02:48:45 +0000660 }
Greg Clayton3418c852011-08-10 02:10:13 +0000661 result.GetOutputStream().Printf("%u targets deleted.\n", (uint32_t)num_targets_to_delete);
662 result.SetStatus(eReturnStatusSuccessFinishResult);
663 }
664
665 return result.Succeeded();
666 }
Greg Claytonaa149cb2011-08-11 02:48:45 +0000667
Greg Claytonaa149cb2011-08-11 02:48:45 +0000668 OptionGroupOptions m_option_group;
669 OptionGroupBoolean m_cleanup_option;
Greg Clayton3418c852011-08-10 02:10:13 +0000670};
671
Greg Clayton7260f622011-04-18 08:33:37 +0000672
Greg Clayton644247c2011-07-07 01:59:51 +0000673#pragma mark CommandObjectTargetVariable
674
675//----------------------------------------------------------------------
676// "target variable"
677//----------------------------------------------------------------------
678
Jim Ingham5a988412012-06-08 21:56:10 +0000679class CommandObjectTargetVariable : public CommandObjectParsed
Greg Clayton644247c2011-07-07 01:59:51 +0000680{
681public:
682 CommandObjectTargetVariable (CommandInterpreter &interpreter) :
Jim Ingham5a988412012-06-08 21:56:10 +0000683 CommandObjectParsed (interpreter,
684 "target variable",
Greg Claytondfdd1eb2012-11-03 00:10:22 +0000685 "Read global variable(s) prior to, or while running your binary.",
Jim Ingham5a988412012-06-08 21:56:10 +0000686 NULL,
Greg Claytonf9fc6092013-01-09 19:44:40 +0000687 eFlagRequiresTarget),
Greg Clayton644247c2011-07-07 01:59:51 +0000688 m_option_group (interpreter),
Greg Clayton715c2362011-07-07 04:38:25 +0000689 m_option_variable (false), // Don't include frame options
Greg Clayton1deb7962011-10-25 06:44:01 +0000690 m_option_format (eFormatDefault),
Greg Clayton3bcdfc02012-12-04 00:32:51 +0000691 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."),
692 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 Clayton644247c2011-07-07 01:59:51 +0000693 m_varobj_options()
694 {
Johnny Chen81ab3f52011-08-22 22:22:00 +0000695 CommandArgumentEntry arg;
696 CommandArgumentData var_name_arg;
697
698 // Define the first (and only) variant of this arg.
699 var_name_arg.arg_type = eArgTypeVarName;
700 var_name_arg.arg_repetition = eArgRepeatPlus;
701
702 // There is only one variant this argument could be; put it into the argument entry.
703 arg.push_back (var_name_arg);
704
705 // Push the data for the first argument into the m_arguments vector.
706 m_arguments.push_back (arg);
707
Greg Clayton644247c2011-07-07 01:59:51 +0000708 m_option_group.Append (&m_varobj_options, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
Greg Clayton715c2362011-07-07 04:38:25 +0000709 m_option_group.Append (&m_option_variable, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
Greg Clayton5009f9d2011-10-27 17:55:14 +0000710 m_option_group.Append (&m_option_format, OptionGroupFormat::OPTION_GROUP_FORMAT | OptionGroupFormat::OPTION_GROUP_GDB_FMT, LLDB_OPT_SET_1);
Greg Clayton644247c2011-07-07 01:59:51 +0000711 m_option_group.Append (&m_option_compile_units, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
712 m_option_group.Append (&m_option_shared_libraries, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
713 m_option_group.Finalize();
714 }
715
716 virtual
717 ~CommandObjectTargetVariable ()
718 {
719 }
Greg Clayton884fb692011-07-08 21:46:14 +0000720
721 void
722 DumpValueObject (Stream &s, VariableSP &var_sp, ValueObjectSP &valobj_sp, const char *root_name)
723 {
Enrico Granata4d93b8c2013-09-30 19:11:51 +0000724 DumpValueObjectOptions options(m_varobj_options.GetAsDumpOptions());
Enrico Granata379447a2011-08-15 18:01:31 +0000725
Greg Clayton884fb692011-07-08 21:46:14 +0000726 switch (var_sp->GetScope())
727 {
728 case eValueTypeVariableGlobal:
729 if (m_option_variable.show_scope)
730 s.PutCString("GLOBAL: ");
731 break;
732
733 case eValueTypeVariableStatic:
734 if (m_option_variable.show_scope)
735 s.PutCString("STATIC: ");
736 break;
737
738 case eValueTypeVariableArgument:
739 if (m_option_variable.show_scope)
740 s.PutCString(" ARG: ");
741 break;
742
743 case eValueTypeVariableLocal:
744 if (m_option_variable.show_scope)
745 s.PutCString(" LOCAL: ");
746 break;
747
748 default:
749 break;
750 }
751
Greg Clayton45ba8542011-07-10 19:21:23 +0000752 if (m_option_variable.show_decl)
Greg Clayton884fb692011-07-08 21:46:14 +0000753 {
Greg Clayton45ba8542011-07-10 19:21:23 +0000754 bool show_fullpaths = false;
755 bool show_module = true;
756 if (var_sp->DumpDeclaration(&s, show_fullpaths, show_module))
757 s.PutCString (": ");
Greg Clayton884fb692011-07-08 21:46:14 +0000758 }
759
Greg Clayton1deb7962011-10-25 06:44:01 +0000760 const Format format = m_option_format.GetFormat();
Greg Clayton884fb692011-07-08 21:46:14 +0000761 if (format != eFormatDefault)
Enrico Granata0c489f52012-03-01 04:24:26 +0000762 options.SetFormat(format);
763
764 options.SetRootValueObjectName(root_name);
Greg Clayton884fb692011-07-08 21:46:14 +0000765
Enrico Granata4d93b8c2013-09-30 19:11:51 +0000766 valobj_sp->Dump(s,options);
Greg Clayton884fb692011-07-08 21:46:14 +0000767 }
Greg Clayton644247c2011-07-07 01:59:51 +0000768
Greg Clayton884fb692011-07-08 21:46:14 +0000769
Greg Claytonc7bece562013-01-25 18:06:21 +0000770 static size_t GetVariableCallback (void *baton,
771 const char *name,
772 VariableList &variable_list)
Greg Clayton884fb692011-07-08 21:46:14 +0000773 {
774 Target *target = static_cast<Target *>(baton);
775 if (target)
776 {
777 return target->GetImages().FindGlobalVariables (ConstString(name),
778 true,
779 UINT32_MAX,
780 variable_list);
781 }
782 return 0;
783 }
784
785
786
Jim Ingham5a988412012-06-08 21:56:10 +0000787 Options *
788 GetOptions ()
789 {
790 return &m_option_group;
791 }
792
793protected:
Greg Clayton3bcdfc02012-12-04 00:32:51 +0000794
795 void
796 DumpGlobalVariableList(const ExecutionContext &exe_ctx, const SymbolContext &sc, const VariableList &variable_list, Stream &s)
797 {
798 size_t count = variable_list.GetSize();
799 if (count > 0)
800 {
801 if (sc.module_sp)
802 {
803 if (sc.comp_unit)
804 {
Greg Claytonb5ad4ec2013-04-29 17:25:54 +0000805 s.Printf ("Global variables for %s in %s:\n",
806 sc.comp_unit->GetPath().c_str(),
807 sc.module_sp->GetFileSpec().GetPath().c_str());
Greg Clayton3bcdfc02012-12-04 00:32:51 +0000808 }
809 else
810 {
Greg Claytonb5ad4ec2013-04-29 17:25:54 +0000811 s.Printf ("Global variables for %s\n",
812 sc.module_sp->GetFileSpec().GetPath().c_str());
Greg Clayton3bcdfc02012-12-04 00:32:51 +0000813 }
814 }
815 else if (sc.comp_unit)
816 {
Greg Claytonb5ad4ec2013-04-29 17:25:54 +0000817 s.Printf ("Global variables for %s\n",
818 sc.comp_unit->GetPath().c_str());
Greg Clayton3bcdfc02012-12-04 00:32:51 +0000819 }
820
821 for (uint32_t i=0; i<count; ++i)
822 {
823 VariableSP var_sp (variable_list.GetVariableAtIndex(i));
824 if (var_sp)
825 {
826 ValueObjectSP valobj_sp (ValueObjectVariable::Create (exe_ctx.GetBestExecutionContextScope(), var_sp));
827
828 if (valobj_sp)
829 DumpValueObject (s, var_sp, valobj_sp, var_sp->GetName().GetCString());
830 }
831 }
832 }
833
834 }
Greg Clayton644247c2011-07-07 01:59:51 +0000835 virtual bool
Jim Ingham5a988412012-06-08 21:56:10 +0000836 DoExecute (Args& args, CommandReturnObject &result)
Greg Clayton644247c2011-07-07 01:59:51 +0000837 {
Greg Claytonf9fc6092013-01-09 19:44:40 +0000838 Target *target = m_exe_ctx.GetTargetPtr();
839 const size_t argc = args.GetArgumentCount();
840 Stream &s = result.GetOutputStream();
841
842 if (argc > 0)
Greg Clayton644247c2011-07-07 01:59:51 +0000843 {
Greg Claytonf9fc6092013-01-09 19:44:40 +0000844
845 for (size_t idx = 0; idx < argc; ++idx)
Greg Clayton644247c2011-07-07 01:59:51 +0000846 {
Greg Claytonf9fc6092013-01-09 19:44:40 +0000847 VariableList variable_list;
848 ValueObjectList valobj_list;
Greg Clayton884fb692011-07-08 21:46:14 +0000849
Greg Claytonf9fc6092013-01-09 19:44:40 +0000850 const char *arg = args.GetArgumentAtIndex(idx);
Greg Claytonc7bece562013-01-25 18:06:21 +0000851 size_t matches = 0;
Greg Claytonf9fc6092013-01-09 19:44:40 +0000852 bool use_var_name = false;
853 if (m_option_variable.use_regex)
Greg Clayton644247c2011-07-07 01:59:51 +0000854 {
Greg Claytonf9fc6092013-01-09 19:44:40 +0000855 RegularExpression regex(arg);
856 if (!regex.IsValid ())
Greg Clayton644247c2011-07-07 01:59:51 +0000857 {
Greg Claytonf9fc6092013-01-09 19:44:40 +0000858 result.GetErrorStream().Printf ("error: invalid regular expression: '%s'\n", arg);
Greg Clayton715c2362011-07-07 04:38:25 +0000859 result.SetStatus (eReturnStatusFailed);
860 return false;
861 }
Greg Claytonf9fc6092013-01-09 19:44:40 +0000862 use_var_name = true;
863 matches = target->GetImages().FindGlobalVariables (regex,
864 true,
865 UINT32_MAX,
866 variable_list);
Greg Clayton3bcdfc02012-12-04 00:32:51 +0000867 }
868 else
869 {
Greg Claytonf9fc6092013-01-09 19:44:40 +0000870 Error error (Variable::GetValuesForVariableExpressionPath (arg,
871 m_exe_ctx.GetBestExecutionContextScope(),
872 GetVariableCallback,
873 target,
874 variable_list,
875 valobj_list));
876 matches = variable_list.GetSize();
877 }
878
879 if (matches == 0)
880 {
881 result.GetErrorStream().Printf ("error: can't find global variable '%s'\n", arg);
882 result.SetStatus (eReturnStatusFailed);
883 return false;
884 }
885 else
886 {
887 for (uint32_t global_idx=0; global_idx<matches; ++global_idx)
Greg Clayton3bcdfc02012-12-04 00:32:51 +0000888 {
Greg Claytonf9fc6092013-01-09 19:44:40 +0000889 VariableSP var_sp (variable_list.GetVariableAtIndex(global_idx));
890 if (var_sp)
Greg Clayton3bcdfc02012-12-04 00:32:51 +0000891 {
Greg Claytonf9fc6092013-01-09 19:44:40 +0000892 ValueObjectSP valobj_sp (valobj_list.GetValueObjectAtIndex(global_idx));
893 if (!valobj_sp)
894 valobj_sp = ValueObjectVariable::Create (m_exe_ctx.GetBestExecutionContextScope(), var_sp);
Greg Clayton3bcdfc02012-12-04 00:32:51 +0000895
Greg Claytonf9fc6092013-01-09 19:44:40 +0000896 if (valobj_sp)
897 DumpValueObject (s, var_sp, valobj_sp, use_var_name ? var_sp->GetName().GetCString() : arg);
Greg Clayton3bcdfc02012-12-04 00:32:51 +0000898 }
899 }
Greg Clayton9a5a9342011-10-05 22:17:32 +0000900 }
Greg Clayton644247c2011-07-07 01:59:51 +0000901 }
902 }
903 else
904 {
Greg Claytonf9fc6092013-01-09 19:44:40 +0000905 const FileSpecList &compile_units = m_option_compile_units.GetOptionValue().GetCurrentValue();
906 const FileSpecList &shlibs = m_option_shared_libraries.GetOptionValue().GetCurrentValue();
907 SymbolContextList sc_list;
908 const size_t num_compile_units = compile_units.GetSize();
909 const size_t num_shlibs = shlibs.GetSize();
910 if (num_compile_units == 0 && num_shlibs == 0)
911 {
912 bool success = false;
Jason Molendab57e4a12013-11-04 09:33:30 +0000913 StackFrame *frame = m_exe_ctx.GetFramePtr();
Greg Claytonf9fc6092013-01-09 19:44:40 +0000914 CompileUnit *comp_unit = NULL;
915 if (frame)
916 {
917 SymbolContext sc = frame->GetSymbolContext (eSymbolContextCompUnit);
918 if (sc.comp_unit)
919 {
920 const bool can_create = true;
921 VariableListSP comp_unit_varlist_sp (sc.comp_unit->GetVariableList(can_create));
922 if (comp_unit_varlist_sp)
923 {
924 size_t count = comp_unit_varlist_sp->GetSize();
925 if (count > 0)
926 {
927 DumpGlobalVariableList(m_exe_ctx, sc, *comp_unit_varlist_sp, s);
928 success = true;
929 }
930 }
931 }
932 }
933 if (!success)
934 {
935 if (frame)
936 {
937 if (comp_unit)
Greg Claytonb5ad4ec2013-04-29 17:25:54 +0000938 result.AppendErrorWithFormat ("no global variables in current compile unit: %s\n",
939 comp_unit->GetPath().c_str());
Greg Claytonf9fc6092013-01-09 19:44:40 +0000940 else
941 result.AppendErrorWithFormat ("no debug information for frame %u\n", frame->GetFrameIndex());
942 }
943 else
944 result.AppendError ("'target variable' takes one or more global variable names as arguments\n");
945 result.SetStatus (eReturnStatusFailed);
946 }
947 }
948 else
949 {
950 SymbolContextList sc_list;
951 const bool append = true;
952 // We have one or more compile unit or shlib
953 if (num_shlibs > 0)
954 {
955 for (size_t shlib_idx=0; shlib_idx<num_shlibs; ++shlib_idx)
956 {
957 const FileSpec module_file(shlibs.GetFileSpecAtIndex(shlib_idx));
958 ModuleSpec module_spec (module_file);
959
960 ModuleSP module_sp (target->GetImages().FindFirstModule(module_spec));
961 if (module_sp)
962 {
963 if (num_compile_units > 0)
964 {
965 for (size_t cu_idx=0; cu_idx<num_compile_units; ++cu_idx)
966 module_sp->FindCompileUnits(compile_units.GetFileSpecAtIndex(cu_idx), append, sc_list);
967 }
968 else
969 {
970 SymbolContext sc;
971 sc.module_sp = module_sp;
972 sc_list.Append(sc);
973 }
974 }
975 else
976 {
977 // Didn't find matching shlib/module in target...
Greg Claytonb5ad4ec2013-04-29 17:25:54 +0000978 result.AppendErrorWithFormat ("target doesn't contain the specified shared library: %s\n",
979 module_file.GetPath().c_str());
Greg Claytonf9fc6092013-01-09 19:44:40 +0000980 }
981 }
982 }
983 else
984 {
985 // No shared libraries, we just want to find globals for the compile units files that were specified
986 for (size_t cu_idx=0; cu_idx<num_compile_units; ++cu_idx)
987 target->GetImages().FindCompileUnits(compile_units.GetFileSpecAtIndex(cu_idx), append, sc_list);
988 }
989
990 const uint32_t num_scs = sc_list.GetSize();
991 if (num_scs > 0)
992 {
993 SymbolContext sc;
994 for (uint32_t sc_idx=0; sc_idx<num_scs; ++sc_idx)
995 {
996 if (sc_list.GetContextAtIndex(sc_idx, sc))
997 {
998 if (sc.comp_unit)
999 {
1000 const bool can_create = true;
1001 VariableListSP comp_unit_varlist_sp (sc.comp_unit->GetVariableList(can_create));
1002 if (comp_unit_varlist_sp)
1003 DumpGlobalVariableList(m_exe_ctx, sc, *comp_unit_varlist_sp, s);
1004 }
1005 else if (sc.module_sp)
1006 {
1007 // Get all global variables for this module
1008 lldb_private::RegularExpression all_globals_regex("."); // Any global with at least one character
1009 VariableList variable_list;
1010 sc.module_sp->FindGlobalVariables(all_globals_regex, append, UINT32_MAX, variable_list);
1011 DumpGlobalVariableList(m_exe_ctx, sc, variable_list, s);
1012 }
1013 }
1014 }
1015 }
1016 }
Greg Clayton644247c2011-07-07 01:59:51 +00001017 }
Greg Claytonf9fc6092013-01-09 19:44:40 +00001018
Enrico Granata61a80ba2011-08-12 16:42:31 +00001019 if (m_interpreter.TruncationWarningNecessary())
1020 {
1021 result.GetOutputStream().Printf(m_interpreter.TruncationWarningText(),
1022 m_cmd_name.c_str());
1023 m_interpreter.TruncationWarningGiven();
1024 }
1025
Greg Clayton644247c2011-07-07 01:59:51 +00001026 return result.Succeeded();
1027 }
1028
Greg Clayton644247c2011-07-07 01:59:51 +00001029 OptionGroupOptions m_option_group;
Greg Clayton715c2362011-07-07 04:38:25 +00001030 OptionGroupVariable m_option_variable;
Greg Clayton1deb7962011-10-25 06:44:01 +00001031 OptionGroupFormat m_option_format;
Greg Clayton644247c2011-07-07 01:59:51 +00001032 OptionGroupFileList m_option_compile_units;
1033 OptionGroupFileList m_option_shared_libraries;
1034 OptionGroupValueObjectDisplay m_varobj_options;
1035
1036};
1037
1038
Greg Claytoneffe5c92011-05-03 22:09:39 +00001039#pragma mark CommandObjectTargetModulesSearchPathsAdd
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001040
Jim Ingham5a988412012-06-08 21:56:10 +00001041class CommandObjectTargetModulesSearchPathsAdd : public CommandObjectParsed
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001042{
1043public:
1044
Greg Claytoneffe5c92011-05-03 22:09:39 +00001045 CommandObjectTargetModulesSearchPathsAdd (CommandInterpreter &interpreter) :
Jim Ingham5a988412012-06-08 21:56:10 +00001046 CommandObjectParsed (interpreter,
1047 "target modules search-paths add",
1048 "Add new image search paths substitution pairs to the current target.",
1049 NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001050 {
Caroline Tice405fe672010-10-04 22:28:36 +00001051 CommandArgumentEntry arg;
1052 CommandArgumentData old_prefix_arg;
1053 CommandArgumentData new_prefix_arg;
1054
1055 // Define the first variant of this arg pair.
1056 old_prefix_arg.arg_type = eArgTypeOldPathPrefix;
1057 old_prefix_arg.arg_repetition = eArgRepeatPairPlus;
1058
1059 // Define the first variant of this arg pair.
1060 new_prefix_arg.arg_type = eArgTypeNewPathPrefix;
1061 new_prefix_arg.arg_repetition = eArgRepeatPairPlus;
1062
1063 // There are two required arguments that must always occur together, i.e. an argument "pair". Because they
1064 // must always occur together, they are treated as two variants of one argument rather than two independent
1065 // arguments. Push them both into the first argument position for m_arguments...
1066
1067 arg.push_back (old_prefix_arg);
1068 arg.push_back (new_prefix_arg);
1069
1070 m_arguments.push_back (arg);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001071 }
1072
Greg Claytoneffe5c92011-05-03 22:09:39 +00001073 ~CommandObjectTargetModulesSearchPathsAdd ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001074 {
1075 }
1076
Jim Ingham5a988412012-06-08 21:56:10 +00001077protected:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001078 bool
Jim Ingham5a988412012-06-08 21:56:10 +00001079 DoExecute (Args& command,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001080 CommandReturnObject &result)
1081 {
Greg Claytona7015092010-09-18 01:14:36 +00001082 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001083 if (target)
1084 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001085 const size_t argc = command.GetArgumentCount();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001086 if (argc & 1)
1087 {
Greg Clayton7260f622011-04-18 08:33:37 +00001088 result.AppendError ("add requires an even number of arguments\n");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001089 result.SetStatus (eReturnStatusFailed);
1090 }
1091 else
1092 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001093 for (size_t i=0; i<argc; i+=2)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001094 {
1095 const char *from = command.GetArgumentAtIndex(i);
1096 const char *to = command.GetArgumentAtIndex(i+1);
1097
1098 if (from[0] && to[0])
1099 {
1100 bool last_pair = ((argc - i) == 2);
Greg Clayton66111032010-06-23 01:19:29 +00001101 target->GetImageSearchPathList().Append (ConstString(from),
1102 ConstString(to),
1103 last_pair); // Notify if this is the last pair
Johnny Chen7791b332011-02-03 00:30:19 +00001104 result.SetStatus (eReturnStatusSuccessFinishNoResult);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001105 }
1106 else
1107 {
1108 if (from[0])
Greg Clayton7260f622011-04-18 08:33:37 +00001109 result.AppendError ("<path-prefix> can't be empty\n");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001110 else
Greg Clayton7260f622011-04-18 08:33:37 +00001111 result.AppendError ("<new-path-prefix> can't be empty\n");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001112 result.SetStatus (eReturnStatusFailed);
1113 }
1114 }
1115 }
1116 }
1117 else
1118 {
Greg Clayton7260f622011-04-18 08:33:37 +00001119 result.AppendError ("invalid target\n");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001120 result.SetStatus (eReturnStatusFailed);
1121 }
1122 return result.Succeeded();
1123 }
1124};
1125
Greg Claytoneffe5c92011-05-03 22:09:39 +00001126#pragma mark CommandObjectTargetModulesSearchPathsClear
1127
Jim Ingham5a988412012-06-08 21:56:10 +00001128class CommandObjectTargetModulesSearchPathsClear : public CommandObjectParsed
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001129{
1130public:
1131
Greg Claytoneffe5c92011-05-03 22:09:39 +00001132 CommandObjectTargetModulesSearchPathsClear (CommandInterpreter &interpreter) :
Jim Ingham5a988412012-06-08 21:56:10 +00001133 CommandObjectParsed (interpreter,
1134 "target modules search-paths clear",
1135 "Clear all current image search path substitution pairs from the current target.",
1136 "target modules search-paths clear")
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001137 {
1138 }
1139
Greg Claytoneffe5c92011-05-03 22:09:39 +00001140 ~CommandObjectTargetModulesSearchPathsClear ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001141 {
1142 }
1143
Jim Ingham5a988412012-06-08 21:56:10 +00001144protected:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001145 bool
Jim Ingham5a988412012-06-08 21:56:10 +00001146 DoExecute (Args& command,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001147 CommandReturnObject &result)
1148 {
Greg Claytona7015092010-09-18 01:14:36 +00001149 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001150 if (target)
1151 {
1152 bool notify = true;
1153 target->GetImageSearchPathList().Clear(notify);
Johnny Chen7791b332011-02-03 00:30:19 +00001154 result.SetStatus (eReturnStatusSuccessFinishNoResult);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001155 }
1156 else
1157 {
Greg Clayton7260f622011-04-18 08:33:37 +00001158 result.AppendError ("invalid target\n");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001159 result.SetStatus (eReturnStatusFailed);
1160 }
1161 return result.Succeeded();
1162 }
1163};
1164
Greg Claytoneffe5c92011-05-03 22:09:39 +00001165#pragma mark CommandObjectTargetModulesSearchPathsInsert
1166
Jim Ingham5a988412012-06-08 21:56:10 +00001167class CommandObjectTargetModulesSearchPathsInsert : public CommandObjectParsed
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001168{
1169public:
1170
Greg Claytoneffe5c92011-05-03 22:09:39 +00001171 CommandObjectTargetModulesSearchPathsInsert (CommandInterpreter &interpreter) :
Jim Ingham5a988412012-06-08 21:56:10 +00001172 CommandObjectParsed (interpreter,
1173 "target modules search-paths insert",
1174 "Insert a new image search path substitution pair into the current target at the specified index.",
1175 NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001176 {
Caroline Tice405fe672010-10-04 22:28:36 +00001177 CommandArgumentEntry arg1;
1178 CommandArgumentEntry arg2;
1179 CommandArgumentData index_arg;
1180 CommandArgumentData old_prefix_arg;
1181 CommandArgumentData new_prefix_arg;
1182
1183 // Define the first and only variant of this arg.
1184 index_arg.arg_type = eArgTypeIndex;
1185 index_arg.arg_repetition = eArgRepeatPlain;
1186
1187 // Put the one and only variant into the first arg for m_arguments:
1188 arg1.push_back (index_arg);
1189
1190 // Define the first variant of this arg pair.
1191 old_prefix_arg.arg_type = eArgTypeOldPathPrefix;
1192 old_prefix_arg.arg_repetition = eArgRepeatPairPlus;
1193
1194 // Define the first variant of this arg pair.
1195 new_prefix_arg.arg_type = eArgTypeNewPathPrefix;
1196 new_prefix_arg.arg_repetition = eArgRepeatPairPlus;
1197
1198 // There are two required arguments that must always occur together, i.e. an argument "pair". Because they
1199 // must always occur together, they are treated as two variants of one argument rather than two independent
1200 // arguments. Push them both into the same argument position for m_arguments...
1201
1202 arg2.push_back (old_prefix_arg);
1203 arg2.push_back (new_prefix_arg);
1204
1205 // Add arguments to m_arguments.
1206 m_arguments.push_back (arg1);
1207 m_arguments.push_back (arg2);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001208 }
1209
Greg Claytoneffe5c92011-05-03 22:09:39 +00001210 ~CommandObjectTargetModulesSearchPathsInsert ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001211 {
1212 }
1213
Jim Ingham5a988412012-06-08 21:56:10 +00001214protected:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001215 bool
Jim Ingham5a988412012-06-08 21:56:10 +00001216 DoExecute (Args& command,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001217 CommandReturnObject &result)
1218 {
Greg Claytona7015092010-09-18 01:14:36 +00001219 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001220 if (target)
1221 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001222 size_t argc = command.GetArgumentCount();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001223 // check for at least 3 arguments and an odd nubmer of parameters
1224 if (argc >= 3 && argc & 1)
1225 {
1226 bool success = false;
1227
1228 uint32_t insert_idx = Args::StringToUInt32(command.GetArgumentAtIndex(0), UINT32_MAX, 0, &success);
1229
1230 if (!success)
1231 {
1232 result.AppendErrorWithFormat("<index> parameter is not an integer: '%s'.\n", command.GetArgumentAtIndex(0));
1233 result.SetStatus (eReturnStatusFailed);
1234 return result.Succeeded();
1235 }
1236
1237 // shift off the index
1238 command.Shift();
1239 argc = command.GetArgumentCount();
1240
1241 for (uint32_t i=0; i<argc; i+=2, ++insert_idx)
1242 {
1243 const char *from = command.GetArgumentAtIndex(i);
1244 const char *to = command.GetArgumentAtIndex(i+1);
1245
1246 if (from[0] && to[0])
1247 {
1248 bool last_pair = ((argc - i) == 2);
1249 target->GetImageSearchPathList().Insert (ConstString(from),
1250 ConstString(to),
1251 insert_idx,
1252 last_pair);
Johnny Chen7791b332011-02-03 00:30:19 +00001253 result.SetStatus (eReturnStatusSuccessFinishNoResult);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001254 }
1255 else
1256 {
1257 if (from[0])
Greg Clayton7260f622011-04-18 08:33:37 +00001258 result.AppendError ("<path-prefix> can't be empty\n");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001259 else
Greg Clayton7260f622011-04-18 08:33:37 +00001260 result.AppendError ("<new-path-prefix> can't be empty\n");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001261 result.SetStatus (eReturnStatusFailed);
1262 return false;
1263 }
1264 }
1265 }
1266 else
1267 {
Greg Clayton7260f622011-04-18 08:33:37 +00001268 result.AppendError ("insert requires at least three arguments\n");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001269 result.SetStatus (eReturnStatusFailed);
1270 return result.Succeeded();
1271 }
1272
1273 }
1274 else
1275 {
Greg Clayton7260f622011-04-18 08:33:37 +00001276 result.AppendError ("invalid target\n");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001277 result.SetStatus (eReturnStatusFailed);
1278 }
1279 return result.Succeeded();
1280 }
1281};
1282
Greg Claytoneffe5c92011-05-03 22:09:39 +00001283
1284#pragma mark CommandObjectTargetModulesSearchPathsList
1285
1286
Jim Ingham5a988412012-06-08 21:56:10 +00001287class CommandObjectTargetModulesSearchPathsList : public CommandObjectParsed
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001288{
1289public:
1290
Greg Claytoneffe5c92011-05-03 22:09:39 +00001291 CommandObjectTargetModulesSearchPathsList (CommandInterpreter &interpreter) :
Jim Ingham5a988412012-06-08 21:56:10 +00001292 CommandObjectParsed (interpreter,
1293 "target modules search-paths list",
1294 "List all current image search path substitution pairs in the current target.",
1295 "target modules search-paths list")
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001296 {
1297 }
1298
Greg Claytoneffe5c92011-05-03 22:09:39 +00001299 ~CommandObjectTargetModulesSearchPathsList ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001300 {
1301 }
1302
Jim Ingham5a988412012-06-08 21:56:10 +00001303protected:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001304 bool
Jim Ingham5a988412012-06-08 21:56:10 +00001305 DoExecute (Args& command,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001306 CommandReturnObject &result)
1307 {
Greg Claytona7015092010-09-18 01:14:36 +00001308 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001309 if (target)
1310 {
1311 if (command.GetArgumentCount() != 0)
1312 {
Greg Clayton7260f622011-04-18 08:33:37 +00001313 result.AppendError ("list takes no arguments\n");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001314 result.SetStatus (eReturnStatusFailed);
1315 return result.Succeeded();
1316 }
1317
1318 target->GetImageSearchPathList().Dump(&result.GetOutputStream());
Johnny Chen7791b332011-02-03 00:30:19 +00001319 result.SetStatus (eReturnStatusSuccessFinishResult);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001320 }
1321 else
1322 {
Greg Clayton7260f622011-04-18 08:33:37 +00001323 result.AppendError ("invalid target\n");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001324 result.SetStatus (eReturnStatusFailed);
1325 }
1326 return result.Succeeded();
1327 }
1328};
1329
Greg Claytoneffe5c92011-05-03 22:09:39 +00001330#pragma mark CommandObjectTargetModulesSearchPathsQuery
1331
Jim Ingham5a988412012-06-08 21:56:10 +00001332class CommandObjectTargetModulesSearchPathsQuery : public CommandObjectParsed
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001333{
1334public:
1335
Greg Claytoneffe5c92011-05-03 22:09:39 +00001336 CommandObjectTargetModulesSearchPathsQuery (CommandInterpreter &interpreter) :
Jim Ingham5a988412012-06-08 21:56:10 +00001337 CommandObjectParsed (interpreter,
1338 "target modules search-paths query",
1339 "Transform a path using the first applicable image search path.",
1340 NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001341 {
Caroline Tice405fe672010-10-04 22:28:36 +00001342 CommandArgumentEntry arg;
1343 CommandArgumentData path_arg;
1344
1345 // Define the first (and only) variant of this arg.
Sean Callanan31542552012-10-24 01:12:14 +00001346 path_arg.arg_type = eArgTypeDirectoryName;
Caroline Tice405fe672010-10-04 22:28:36 +00001347 path_arg.arg_repetition = eArgRepeatPlain;
1348
1349 // There is only one variant this argument could be; put it into the argument entry.
1350 arg.push_back (path_arg);
1351
1352 // Push the data for the first argument into the m_arguments vector.
1353 m_arguments.push_back (arg);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001354 }
1355
Greg Claytoneffe5c92011-05-03 22:09:39 +00001356 ~CommandObjectTargetModulesSearchPathsQuery ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001357 {
1358 }
1359
Jim Ingham5a988412012-06-08 21:56:10 +00001360protected:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001361 bool
Jim Ingham5a988412012-06-08 21:56:10 +00001362 DoExecute (Args& command,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001363 CommandReturnObject &result)
1364 {
Greg Claytona7015092010-09-18 01:14:36 +00001365 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001366 if (target)
1367 {
1368 if (command.GetArgumentCount() != 1)
1369 {
Greg Clayton7260f622011-04-18 08:33:37 +00001370 result.AppendError ("query requires one argument\n");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001371 result.SetStatus (eReturnStatusFailed);
1372 return result.Succeeded();
1373 }
1374
1375 ConstString orig(command.GetArgumentAtIndex(0));
1376 ConstString transformed;
1377 if (target->GetImageSearchPathList().RemapPath(orig, transformed))
1378 result.GetOutputStream().Printf("%s\n", transformed.GetCString());
1379 else
1380 result.GetOutputStream().Printf("%s\n", orig.GetCString());
Johnny Chen7791b332011-02-03 00:30:19 +00001381
1382 result.SetStatus (eReturnStatusSuccessFinishResult);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001383 }
1384 else
1385 {
Greg Clayton7260f622011-04-18 08:33:37 +00001386 result.AppendError ("invalid target\n");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001387 result.SetStatus (eReturnStatusFailed);
1388 }
1389 return result.Succeeded();
1390 }
1391};
1392
Greg Claytoneffe5c92011-05-03 22:09:39 +00001393//----------------------------------------------------------------------
1394// Static Helper functions
1395//----------------------------------------------------------------------
1396static void
1397DumpModuleArchitecture (Stream &strm, Module *module, bool full_triple, uint32_t width)
1398{
1399 if (module)
1400 {
1401 const char *arch_cstr;
1402 if (full_triple)
1403 arch_cstr = module->GetArchitecture().GetTriple().str().c_str();
1404 else
1405 arch_cstr = module->GetArchitecture().GetArchitectureName();
1406 if (width)
1407 strm.Printf("%-*s", width, arch_cstr);
1408 else
1409 strm.PutCString(arch_cstr);
1410 }
1411}
1412
1413static void
1414DumpModuleUUID (Stream &strm, Module *module)
1415{
Jim Ingham28eb5712012-10-12 17:34:26 +00001416 if (module && module->GetUUID().IsValid())
Greg Clayton3418c852011-08-10 02:10:13 +00001417 module->GetUUID().Dump (&strm);
1418 else
1419 strm.PutCString(" ");
Greg Claytoneffe5c92011-05-03 22:09:39 +00001420}
1421
1422static uint32_t
Greg Claytona0ca6602012-10-18 16:33:33 +00001423DumpCompileUnitLineTable (CommandInterpreter &interpreter,
1424 Stream &strm,
1425 Module *module,
1426 const FileSpec &file_spec,
1427 bool load_addresses)
Greg Claytoneffe5c92011-05-03 22:09:39 +00001428{
1429 uint32_t num_matches = 0;
1430 if (module)
1431 {
1432 SymbolContextList sc_list;
1433 num_matches = module->ResolveSymbolContextsForFileSpec (file_spec,
1434 0,
1435 false,
1436 eSymbolContextCompUnit,
1437 sc_list);
1438
1439 for (uint32_t i=0; i<num_matches; ++i)
1440 {
1441 SymbolContext sc;
1442 if (sc_list.GetContextAtIndex(i, sc))
1443 {
1444 if (i > 0)
1445 strm << "\n\n";
1446
1447 strm << "Line table for " << *static_cast<FileSpec*> (sc.comp_unit) << " in `"
1448 << module->GetFileSpec().GetFilename() << "\n";
1449 LineTable *line_table = sc.comp_unit->GetLineTable();
1450 if (line_table)
1451 line_table->GetDescription (&strm,
Greg Claytonc14ee322011-09-22 04:58:26 +00001452 interpreter.GetExecutionContext().GetTargetPtr(),
Greg Claytoneffe5c92011-05-03 22:09:39 +00001453 lldb::eDescriptionLevelBrief);
1454 else
1455 strm << "No line table";
1456 }
1457 }
1458 }
1459 return num_matches;
1460}
1461
1462static void
1463DumpFullpath (Stream &strm, const FileSpec *file_spec_ptr, uint32_t width)
1464{
1465 if (file_spec_ptr)
1466 {
1467 if (width > 0)
1468 {
Jason Molendadb7d11c2013-05-06 10:21:11 +00001469 std::string fullpath = file_spec_ptr->GetPath();
1470 strm.Printf("%-*s", width, fullpath.c_str());
1471 return;
Greg Claytoneffe5c92011-05-03 22:09:39 +00001472 }
1473 else
1474 {
1475 file_spec_ptr->Dump(&strm);
1476 return;
1477 }
1478 }
1479 // Keep the width spacing correct if things go wrong...
1480 if (width > 0)
1481 strm.Printf("%-*s", width, "");
1482}
1483
1484static void
1485DumpDirectory (Stream &strm, const FileSpec *file_spec_ptr, uint32_t width)
1486{
1487 if (file_spec_ptr)
1488 {
1489 if (width > 0)
1490 strm.Printf("%-*s", width, file_spec_ptr->GetDirectory().AsCString(""));
1491 else
1492 file_spec_ptr->GetDirectory().Dump(&strm);
1493 return;
1494 }
1495 // Keep the width spacing correct if things go wrong...
1496 if (width > 0)
1497 strm.Printf("%-*s", width, "");
1498}
1499
1500static void
1501DumpBasename (Stream &strm, const FileSpec *file_spec_ptr, uint32_t width)
1502{
1503 if (file_spec_ptr)
1504 {
1505 if (width > 0)
1506 strm.Printf("%-*s", width, file_spec_ptr->GetFilename().AsCString(""));
1507 else
1508 file_spec_ptr->GetFilename().Dump(&strm);
1509 return;
1510 }
1511 // Keep the width spacing correct if things go wrong...
1512 if (width > 0)
1513 strm.Printf("%-*s", width, "");
1514}
1515
1516
1517static void
1518DumpModuleSymtab (CommandInterpreter &interpreter, Stream &strm, Module *module, SortOrder sort_order)
1519{
1520 if (module)
1521 {
Michael Sartaina7499c92013-07-01 19:45:50 +00001522 SymbolVendor *sym_vendor = module->GetSymbolVendor ();
1523 if (sym_vendor)
Greg Claytoneffe5c92011-05-03 22:09:39 +00001524 {
Michael Sartaina7499c92013-07-01 19:45:50 +00001525 Symtab *symtab = sym_vendor->GetSymtab();
Greg Claytoneffe5c92011-05-03 22:09:39 +00001526 if (symtab)
Greg Claytonc14ee322011-09-22 04:58:26 +00001527 symtab->Dump(&strm, interpreter.GetExecutionContext().GetTargetPtr(), sort_order);
Greg Claytoneffe5c92011-05-03 22:09:39 +00001528 }
1529 }
1530}
1531
1532static void
1533DumpModuleSections (CommandInterpreter &interpreter, Stream &strm, Module *module)
1534{
1535 if (module)
1536 {
Greg Clayton3046e662013-07-10 01:23:25 +00001537 SectionList *section_list = module->GetSectionList();
Michael Sartaina7499c92013-07-01 19:45:50 +00001538 if (section_list)
Greg Claytoneffe5c92011-05-03 22:09:39 +00001539 {
Michael Sartaina7499c92013-07-01 19:45:50 +00001540 strm.Printf ("Sections for '%s' (%s):\n",
1541 module->GetSpecificationDescription().c_str(),
1542 module->GetArchitecture().GetArchitectureName());
1543 strm.IndentMore();
1544 section_list->Dump(&strm, interpreter.GetExecutionContext().GetTargetPtr(), true, UINT32_MAX);
1545 strm.IndentLess();
Greg Claytoneffe5c92011-05-03 22:09:39 +00001546 }
1547 }
1548}
1549
1550static bool
1551DumpModuleSymbolVendor (Stream &strm, Module *module)
1552{
1553 if (module)
1554 {
1555 SymbolVendor *symbol_vendor = module->GetSymbolVendor(true);
1556 if (symbol_vendor)
1557 {
1558 symbol_vendor->Dump(&strm);
1559 return true;
1560 }
1561 }
1562 return false;
1563}
1564
Greg Claytonc4a8a762012-05-15 18:43:44 +00001565static void
1566DumpAddress (ExecutionContextScope *exe_scope, const Address &so_addr, bool verbose, Stream &strm)
1567{
1568 strm.IndentMore();
1569 strm.Indent (" Address: ");
1570 so_addr.Dump (&strm, exe_scope, Address::DumpStyleModuleWithFileAddress);
1571 strm.PutCString (" (");
1572 so_addr.Dump (&strm, exe_scope, Address::DumpStyleSectionNameOffset);
1573 strm.PutCString (")\n");
1574 strm.Indent (" Summary: ");
1575 const uint32_t save_indent = strm.GetIndentLevel ();
1576 strm.SetIndentLevel (save_indent + 13);
1577 so_addr.Dump (&strm, exe_scope, Address::DumpStyleResolvedDescription);
1578 strm.SetIndentLevel (save_indent);
1579 // Print out detailed address information when verbose is enabled
1580 if (verbose)
1581 {
1582 strm.EOL();
1583 so_addr.Dump (&strm, exe_scope, Address::DumpStyleDetailedSymbolContext);
1584 }
1585 strm.IndentLess();
1586}
1587
Greg Claytoneffe5c92011-05-03 22:09:39 +00001588static bool
Greg Claytone72dfb32012-02-24 01:59:29 +00001589LookupAddressInModule (CommandInterpreter &interpreter,
1590 Stream &strm,
1591 Module *module,
1592 uint32_t resolve_mask,
1593 lldb::addr_t raw_addr,
1594 lldb::addr_t offset,
1595 bool verbose)
Greg Claytoneffe5c92011-05-03 22:09:39 +00001596{
1597 if (module)
1598 {
1599 lldb::addr_t addr = raw_addr - offset;
1600 Address so_addr;
1601 SymbolContext sc;
Greg Claytonc14ee322011-09-22 04:58:26 +00001602 Target *target = interpreter.GetExecutionContext().GetTargetPtr();
Greg Claytoneffe5c92011-05-03 22:09:39 +00001603 if (target && !target->GetSectionLoadList().IsEmpty())
1604 {
1605 if (!target->GetSectionLoadList().ResolveLoadAddress (addr, so_addr))
1606 return false;
Greg Claytone72dfb32012-02-24 01:59:29 +00001607 else if (so_addr.GetModule().get() != module)
Greg Claytoneffe5c92011-05-03 22:09:39 +00001608 return false;
1609 }
1610 else
1611 {
1612 if (!module->ResolveFileAddress (addr, so_addr))
1613 return false;
1614 }
1615
Greg Claytoneffe5c92011-05-03 22:09:39 +00001616 ExecutionContextScope *exe_scope = interpreter.GetExecutionContext().GetBestExecutionContextScope();
Greg Claytonc4a8a762012-05-15 18:43:44 +00001617 DumpAddress (exe_scope, so_addr, verbose, strm);
1618// strm.IndentMore();
1619// strm.Indent (" Address: ");
1620// so_addr.Dump (&strm, exe_scope, Address::DumpStyleModuleWithFileAddress);
1621// strm.PutCString (" (");
1622// so_addr.Dump (&strm, exe_scope, Address::DumpStyleSectionNameOffset);
1623// strm.PutCString (")\n");
1624// strm.Indent (" Summary: ");
1625// const uint32_t save_indent = strm.GetIndentLevel ();
1626// strm.SetIndentLevel (save_indent + 13);
1627// so_addr.Dump (&strm, exe_scope, Address::DumpStyleResolvedDescription);
1628// strm.SetIndentLevel (save_indent);
1629// // Print out detailed address information when verbose is enabled
1630// if (verbose)
1631// {
1632// strm.EOL();
1633// so_addr.Dump (&strm, exe_scope, Address::DumpStyleDetailedSymbolContext);
1634// }
1635// strm.IndentLess();
Greg Claytoneffe5c92011-05-03 22:09:39 +00001636 return true;
1637 }
1638
1639 return false;
1640}
1641
1642static uint32_t
Greg Claytonc4a8a762012-05-15 18:43:44 +00001643LookupSymbolInModule (CommandInterpreter &interpreter, Stream &strm, Module *module, const char *name, bool name_is_regex, bool verbose)
Greg Claytoneffe5c92011-05-03 22:09:39 +00001644{
1645 if (module)
1646 {
1647 SymbolContext sc;
1648
Michael Sartaina7499c92013-07-01 19:45:50 +00001649 SymbolVendor *sym_vendor = module->GetSymbolVendor ();
1650 if (sym_vendor)
Greg Claytoneffe5c92011-05-03 22:09:39 +00001651 {
Michael Sartaina7499c92013-07-01 19:45:50 +00001652 Symtab *symtab = sym_vendor->GetSymtab();
Greg Claytoneffe5c92011-05-03 22:09:39 +00001653 if (symtab)
1654 {
1655 uint32_t i;
1656 std::vector<uint32_t> match_indexes;
1657 ConstString symbol_name (name);
1658 uint32_t num_matches = 0;
1659 if (name_is_regex)
1660 {
1661 RegularExpression name_regexp(name);
1662 num_matches = symtab->AppendSymbolIndexesMatchingRegExAndType (name_regexp,
1663 eSymbolTypeAny,
1664 match_indexes);
1665 }
1666 else
1667 {
1668 num_matches = symtab->AppendSymbolIndexesWithName (symbol_name, match_indexes);
1669 }
1670
1671
1672 if (num_matches > 0)
1673 {
1674 strm.Indent ();
1675 strm.Printf("%u symbols match %s'%s' in ", num_matches,
1676 name_is_regex ? "the regular expression " : "", name);
1677 DumpFullpath (strm, &module->GetFileSpec(), 0);
1678 strm.PutCString(":\n");
1679 strm.IndentMore ();
Greg Claytonc4a8a762012-05-15 18:43:44 +00001680 //Symtab::DumpSymbolHeader (&strm);
Greg Claytoneffe5c92011-05-03 22:09:39 +00001681 for (i=0; i < num_matches; ++i)
1682 {
1683 Symbol *symbol = symtab->SymbolAtIndex(match_indexes[i]);
Greg Claytonc4a8a762012-05-15 18:43:44 +00001684 DumpAddress (interpreter.GetExecutionContext().GetBestExecutionContextScope(),
1685 symbol->GetAddress(),
1686 verbose,
1687 strm);
1688
1689// strm.Indent ();
1690// symbol->Dump (&strm, interpreter.GetExecutionContext().GetTargetPtr(), i);
Greg Claytoneffe5c92011-05-03 22:09:39 +00001691 }
1692 strm.IndentLess ();
1693 return num_matches;
1694 }
1695 }
1696 }
1697 }
1698 return 0;
1699}
1700
1701
1702static void
Greg Claytonc4a8a762012-05-15 18:43:44 +00001703DumpSymbolContextList (ExecutionContextScope *exe_scope, Stream &strm, SymbolContextList &sc_list, bool verbose)
Greg Claytoneffe5c92011-05-03 22:09:39 +00001704{
1705 strm.IndentMore ();
1706 uint32_t i;
1707 const uint32_t num_matches = sc_list.GetSize();
1708
1709 for (i=0; i<num_matches; ++i)
1710 {
1711 SymbolContext sc;
1712 if (sc_list.GetContextAtIndex(i, sc))
1713 {
Sean Callananf6172c22012-02-11 00:24:04 +00001714 AddressRange range;
1715
1716 sc.GetAddressRange(eSymbolContextEverything,
1717 0,
1718 true,
1719 range);
1720
Greg Claytonc4a8a762012-05-15 18:43:44 +00001721 DumpAddress (exe_scope, range.GetBaseAddress(), verbose, strm);
Greg Claytoneffe5c92011-05-03 22:09:39 +00001722 }
1723 }
1724 strm.IndentLess ();
1725}
1726
Greg Claytonc7bece562013-01-25 18:06:21 +00001727static size_t
Greg Claytonc4a8a762012-05-15 18:43:44 +00001728LookupFunctionInModule (CommandInterpreter &interpreter,
1729 Stream &strm,
1730 Module *module,
1731 const char *name,
1732 bool name_is_regex,
1733 bool include_inlines,
1734 bool include_symbols,
1735 bool verbose)
Greg Claytoneffe5c92011-05-03 22:09:39 +00001736{
1737 if (module && name && name[0])
1738 {
1739 SymbolContextList sc_list;
Greg Claytoneffe5c92011-05-03 22:09:39 +00001740 const bool append = true;
Greg Claytonc7bece562013-01-25 18:06:21 +00001741 size_t num_matches = 0;
Greg Claytoneffe5c92011-05-03 22:09:39 +00001742 if (name_is_regex)
1743 {
1744 RegularExpression function_name_regex (name);
1745 num_matches = module->FindFunctions (function_name_regex,
1746 include_symbols,
Sean Callanan9df05fb2012-02-10 22:52:19 +00001747 include_inlines,
Greg Claytoneffe5c92011-05-03 22:09:39 +00001748 append,
1749 sc_list);
1750 }
1751 else
1752 {
1753 ConstString function_name (name);
Sean Callananb6d70eb2011-10-12 02:08:07 +00001754 num_matches = module->FindFunctions (function_name,
1755 NULL,
Greg Clayton6ecb2322013-05-18 00:11:21 +00001756 eFunctionNameTypeAuto,
Greg Claytoneffe5c92011-05-03 22:09:39 +00001757 include_symbols,
Sean Callanan9df05fb2012-02-10 22:52:19 +00001758 include_inlines,
Greg Claytoneffe5c92011-05-03 22:09:39 +00001759 append,
1760 sc_list);
1761 }
1762
1763 if (num_matches)
1764 {
1765 strm.Indent ();
Deepak Panickal99fbc072014-03-03 15:39:47 +00001766 strm.Printf("%" PRIu64 " match%s found in ", (uint64_t)num_matches, num_matches > 1 ? "es" : "");
Greg Claytoneffe5c92011-05-03 22:09:39 +00001767 DumpFullpath (strm, &module->GetFileSpec(), 0);
1768 strm.PutCString(":\n");
Greg Claytonc4a8a762012-05-15 18:43:44 +00001769 DumpSymbolContextList (interpreter.GetExecutionContext().GetBestExecutionContextScope(), strm, sc_list, verbose);
Greg Claytoneffe5c92011-05-03 22:09:39 +00001770 }
1771 return num_matches;
1772 }
1773 return 0;
1774}
1775
Greg Claytonc7bece562013-01-25 18:06:21 +00001776static size_t
Greg Claytonaafa5c92012-05-15 19:26:12 +00001777LookupTypeInModule (CommandInterpreter &interpreter,
Greg Clayton644247c2011-07-07 01:59:51 +00001778 Stream &strm,
1779 Module *module,
1780 const char *name_cstr,
1781 bool name_is_regex)
Greg Claytoneffe5c92011-05-03 22:09:39 +00001782{
1783 if (module && name_cstr && name_cstr[0])
1784 {
Greg Claytond1767f02011-12-08 02:13:16 +00001785 TypeList type_list;
Greg Clayton84db9102012-03-26 23:03:23 +00001786 const uint32_t max_num_matches = UINT32_MAX;
Greg Claytonc7bece562013-01-25 18:06:21 +00001787 size_t num_matches = 0;
Greg Clayton84db9102012-03-26 23:03:23 +00001788 bool name_is_fully_qualified = false;
Greg Claytond1767f02011-12-08 02:13:16 +00001789 SymbolContext sc;
1790
1791 ConstString name(name_cstr);
Greg Clayton84db9102012-03-26 23:03:23 +00001792 num_matches = module->FindTypes(sc, name, name_is_fully_qualified, max_num_matches, type_list);
Greg Claytoneffe5c92011-05-03 22:09:39 +00001793
Greg Claytond1767f02011-12-08 02:13:16 +00001794 if (num_matches)
1795 {
1796 strm.Indent ();
Deepak Panickal99fbc072014-03-03 15:39:47 +00001797 strm.Printf("%" PRIu64 " match%s found in ", (uint64_t)num_matches, num_matches > 1 ? "es" : "");
Greg Claytond1767f02011-12-08 02:13:16 +00001798 DumpFullpath (strm, &module->GetFileSpec(), 0);
1799 strm.PutCString(":\n");
Sean Callanan5c19eac2013-11-06 19:28:40 +00001800 for (TypeSP type_sp : type_list.Types())
Greg Claytoneffe5c92011-05-03 22:09:39 +00001801 {
Greg Claytond1767f02011-12-08 02:13:16 +00001802 if (type_sp)
Greg Claytoneffe5c92011-05-03 22:09:39 +00001803 {
Greg Claytond1767f02011-12-08 02:13:16 +00001804 // Resolve the clang type so that any forward references
1805 // to types that haven't yet been parsed will get parsed.
1806 type_sp->GetClangFullType ();
1807 type_sp->GetDescription (&strm, eDescriptionLevelFull, true);
Greg Claytonaafa5c92012-05-15 19:26:12 +00001808 // Print all typedef chains
1809 TypeSP typedef_type_sp (type_sp);
1810 TypeSP typedefed_type_sp (typedef_type_sp->GetTypedefType());
1811 while (typedefed_type_sp)
1812 {
1813 strm.EOL();
1814 strm.Printf(" typedef '%s': ", typedef_type_sp->GetName().GetCString());
1815 typedefed_type_sp->GetClangFullType ();
1816 typedefed_type_sp->GetDescription (&strm, eDescriptionLevelFull, true);
1817 typedef_type_sp = typedefed_type_sp;
1818 typedefed_type_sp = typedef_type_sp->GetTypedefType();
1819 }
Greg Claytoneffe5c92011-05-03 22:09:39 +00001820 }
Greg Claytond1767f02011-12-08 02:13:16 +00001821 strm.EOL();
Greg Claytoneffe5c92011-05-03 22:09:39 +00001822 }
Greg Claytond1767f02011-12-08 02:13:16 +00001823 }
1824 return num_matches;
Greg Claytoneffe5c92011-05-03 22:09:39 +00001825 }
1826 return 0;
1827}
1828
Greg Claytonc7bece562013-01-25 18:06:21 +00001829static size_t
Sean Callanand38b4a92012-06-06 20:49:55 +00001830LookupTypeHere (CommandInterpreter &interpreter,
1831 Stream &strm,
1832 const SymbolContext &sym_ctx,
1833 const char *name_cstr,
1834 bool name_is_regex)
1835{
1836 if (!sym_ctx.module_sp)
1837 return 0;
1838
1839 TypeList type_list;
1840 const uint32_t max_num_matches = UINT32_MAX;
Greg Claytonc7bece562013-01-25 18:06:21 +00001841 size_t num_matches = 1;
Sean Callanand38b4a92012-06-06 20:49:55 +00001842 bool name_is_fully_qualified = false;
1843
1844 ConstString name(name_cstr);
1845 num_matches = sym_ctx.module_sp->FindTypes(sym_ctx, name, name_is_fully_qualified, max_num_matches, type_list);
1846
1847 if (num_matches)
1848 {
1849 strm.Indent ();
1850 strm.PutCString("Best match found in ");
1851 DumpFullpath (strm, &sym_ctx.module_sp->GetFileSpec(), 0);
1852 strm.PutCString(":\n");
1853
1854 TypeSP type_sp (type_list.GetTypeAtIndex(0));
1855 if (type_sp)
1856 {
1857 // Resolve the clang type so that any forward references
1858 // to types that haven't yet been parsed will get parsed.
1859 type_sp->GetClangFullType ();
1860 type_sp->GetDescription (&strm, eDescriptionLevelFull, true);
1861 // Print all typedef chains
1862 TypeSP typedef_type_sp (type_sp);
1863 TypeSP typedefed_type_sp (typedef_type_sp->GetTypedefType());
1864 while (typedefed_type_sp)
1865 {
1866 strm.EOL();
1867 strm.Printf(" typedef '%s': ", typedef_type_sp->GetName().GetCString());
1868 typedefed_type_sp->GetClangFullType ();
1869 typedefed_type_sp->GetDescription (&strm, eDescriptionLevelFull, true);
1870 typedef_type_sp = typedefed_type_sp;
1871 typedefed_type_sp = typedef_type_sp->GetTypedefType();
1872 }
1873 }
1874 strm.EOL();
1875 }
1876 return num_matches;
1877}
1878
1879static uint32_t
Greg Claytoneffe5c92011-05-03 22:09:39 +00001880LookupFileAndLineInModule (CommandInterpreter &interpreter,
Sean Callanand38b4a92012-06-06 20:49:55 +00001881 Stream &strm,
Greg Claytoneffe5c92011-05-03 22:09:39 +00001882 Module *module,
1883 const FileSpec &file_spec,
1884 uint32_t line,
1885 bool check_inlines,
1886 bool verbose)
1887{
1888 if (module && file_spec)
1889 {
1890 SymbolContextList sc_list;
1891 const uint32_t num_matches = module->ResolveSymbolContextsForFileSpec(file_spec, line, check_inlines,
1892 eSymbolContextEverything, sc_list);
1893 if (num_matches > 0)
1894 {
1895 strm.Indent ();
1896 strm.Printf("%u match%s found in ", num_matches, num_matches > 1 ? "es" : "");
1897 strm << file_spec;
1898 if (line > 0)
1899 strm.Printf (":%u", line);
1900 strm << " in ";
1901 DumpFullpath (strm, &module->GetFileSpec(), 0);
1902 strm.PutCString(":\n");
Greg Claytonc4a8a762012-05-15 18:43:44 +00001903 DumpSymbolContextList (interpreter.GetExecutionContext().GetBestExecutionContextScope(), strm, sc_list, verbose);
Greg Claytoneffe5c92011-05-03 22:09:39 +00001904 return num_matches;
1905 }
1906 }
1907 return 0;
1908
1909}
1910
Greg Clayton8ee64382011-11-10 01:18:58 +00001911
1912static size_t
1913FindModulesByName (Target *target,
1914 const char *module_name,
1915 ModuleList &module_list,
1916 bool check_global_list)
1917{
1918// Dump specified images (by basename or fullpath)
1919 FileSpec module_file_spec(module_name, false);
Greg Claytonb9a01b32012-02-26 05:51:37 +00001920 ModuleSpec module_spec (module_file_spec);
Greg Clayton8ee64382011-11-10 01:18:58 +00001921
1922 const size_t initial_size = module_list.GetSize ();
1923
Greg Claytonf3156262012-07-11 20:46:47 +00001924 if (check_global_list)
Greg Clayton8ee64382011-11-10 01:18:58 +00001925 {
1926 // Check the global list
Greg Claytonb26e6be2012-01-27 18:08:35 +00001927 Mutex::Locker locker(Module::GetAllocationModuleCollectionMutex());
Greg Claytonc7bece562013-01-25 18:06:21 +00001928 const size_t num_modules = Module::GetNumberAllocatedModules();
Greg Clayton8ee64382011-11-10 01:18:58 +00001929 ModuleSP module_sp;
Greg Claytonc7bece562013-01-25 18:06:21 +00001930 for (size_t image_idx = 0; image_idx<num_modules; ++image_idx)
Greg Clayton8ee64382011-11-10 01:18:58 +00001931 {
1932 Module *module = Module::GetAllocatedModuleAtIndex(image_idx);
1933
1934 if (module)
1935 {
Greg Claytonb9a01b32012-02-26 05:51:37 +00001936 if (module->MatchesModuleSpec (module_spec))
Greg Clayton8ee64382011-11-10 01:18:58 +00001937 {
Greg Claytone1cd1be2012-01-29 20:56:30 +00001938 module_sp = module->shared_from_this();
Greg Clayton8ee64382011-11-10 01:18:58 +00001939 module_list.AppendIfNeeded(module_sp);
1940 }
1941 }
1942 }
1943 }
Greg Claytonf3156262012-07-11 20:46:47 +00001944 else
1945 {
1946 if (target)
1947 {
1948 const size_t num_matches = target->GetImages().FindModules (module_spec, module_list);
1949
1950 // Not found in our module list for our target, check the main
1951 // shared module list in case it is a extra file used somewhere
1952 // else
1953 if (num_matches == 0)
1954 {
1955 module_spec.GetArchitecture() = target->GetArchitecture();
1956 ModuleList::FindSharedModules (module_spec, module_list);
1957 }
1958 }
1959 else
1960 {
1961 ModuleList::FindSharedModules (module_spec,module_list);
1962 }
1963 }
1964
Greg Clayton8ee64382011-11-10 01:18:58 +00001965 return module_list.GetSize () - initial_size;
1966}
1967
Greg Claytoneffe5c92011-05-03 22:09:39 +00001968#pragma mark CommandObjectTargetModulesModuleAutoComplete
1969
1970//----------------------------------------------------------------------
1971// A base command object class that can auto complete with module file
1972// paths
1973//----------------------------------------------------------------------
1974
Jim Ingham5a988412012-06-08 21:56:10 +00001975class CommandObjectTargetModulesModuleAutoComplete : public CommandObjectParsed
Greg Claytoneffe5c92011-05-03 22:09:39 +00001976{
1977public:
1978
1979 CommandObjectTargetModulesModuleAutoComplete (CommandInterpreter &interpreter,
1980 const char *name,
1981 const char *help,
1982 const char *syntax) :
Jim Ingham5a988412012-06-08 21:56:10 +00001983 CommandObjectParsed (interpreter, name, help, syntax)
Greg Claytoneffe5c92011-05-03 22:09:39 +00001984 {
1985 CommandArgumentEntry arg;
1986 CommandArgumentData file_arg;
1987
1988 // Define the first (and only) variant of this arg.
1989 file_arg.arg_type = eArgTypeFilename;
1990 file_arg.arg_repetition = eArgRepeatStar;
1991
1992 // There is only one variant this argument could be; put it into the argument entry.
1993 arg.push_back (file_arg);
1994
1995 // Push the data for the first argument into the m_arguments vector.
1996 m_arguments.push_back (arg);
1997 }
1998
1999 virtual
2000 ~CommandObjectTargetModulesModuleAutoComplete ()
2001 {
2002 }
2003
2004 virtual int
2005 HandleArgumentCompletion (Args &input,
2006 int &cursor_index,
2007 int &cursor_char_position,
2008 OptionElementVector &opt_element_vector,
2009 int match_start_point,
2010 int max_return_elements,
2011 bool &word_complete,
2012 StringList &matches)
2013 {
2014 // Arguments are the standard module completer.
2015 std::string completion_str (input.GetArgumentAtIndex(cursor_index));
2016 completion_str.erase (cursor_char_position);
2017
2018 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
2019 CommandCompletions::eModuleCompletion,
2020 completion_str.c_str(),
2021 match_start_point,
2022 max_return_elements,
2023 NULL,
2024 word_complete,
2025 matches);
2026 return matches.GetSize();
2027 }
2028};
2029
2030#pragma mark CommandObjectTargetModulesSourceFileAutoComplete
2031
2032//----------------------------------------------------------------------
2033// A base command object class that can auto complete with module source
2034// file paths
2035//----------------------------------------------------------------------
2036
Jim Ingham5a988412012-06-08 21:56:10 +00002037class CommandObjectTargetModulesSourceFileAutoComplete : public CommandObjectParsed
Greg Claytoneffe5c92011-05-03 22:09:39 +00002038{
2039public:
2040
2041 CommandObjectTargetModulesSourceFileAutoComplete (CommandInterpreter &interpreter,
Greg Claytonf9fc6092013-01-09 19:44:40 +00002042 const char *name,
2043 const char *help,
2044 const char *syntax,
2045 uint32_t flags) :
2046 CommandObjectParsed (interpreter, name, help, syntax, flags)
Greg Claytoneffe5c92011-05-03 22:09:39 +00002047 {
2048 CommandArgumentEntry arg;
2049 CommandArgumentData source_file_arg;
2050
2051 // Define the first (and only) variant of this arg.
2052 source_file_arg.arg_type = eArgTypeSourceFile;
2053 source_file_arg.arg_repetition = eArgRepeatPlus;
2054
2055 // There is only one variant this argument could be; put it into the argument entry.
2056 arg.push_back (source_file_arg);
2057
2058 // Push the data for the first argument into the m_arguments vector.
2059 m_arguments.push_back (arg);
2060 }
2061
2062 virtual
2063 ~CommandObjectTargetModulesSourceFileAutoComplete ()
2064 {
2065 }
2066
2067 virtual int
2068 HandleArgumentCompletion (Args &input,
2069 int &cursor_index,
2070 int &cursor_char_position,
2071 OptionElementVector &opt_element_vector,
2072 int match_start_point,
2073 int max_return_elements,
2074 bool &word_complete,
2075 StringList &matches)
2076 {
2077 // Arguments are the standard source file completer.
2078 std::string completion_str (input.GetArgumentAtIndex(cursor_index));
2079 completion_str.erase (cursor_char_position);
2080
2081 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
2082 CommandCompletions::eSourceFileCompletion,
2083 completion_str.c_str(),
2084 match_start_point,
2085 max_return_elements,
2086 NULL,
2087 word_complete,
2088 matches);
2089 return matches.GetSize();
2090 }
2091};
2092
2093
2094#pragma mark CommandObjectTargetModulesDumpSymtab
2095
2096
2097class CommandObjectTargetModulesDumpSymtab : public CommandObjectTargetModulesModuleAutoComplete
2098{
2099public:
2100 CommandObjectTargetModulesDumpSymtab (CommandInterpreter &interpreter) :
2101 CommandObjectTargetModulesModuleAutoComplete (interpreter,
2102 "target modules dump symtab",
2103 "Dump the symbol table from one or more target modules.",
2104 NULL),
2105 m_options (interpreter)
2106 {
2107 }
2108
2109 virtual
2110 ~CommandObjectTargetModulesDumpSymtab ()
2111 {
2112 }
2113
Jim Ingham5a988412012-06-08 21:56:10 +00002114 virtual Options *
2115 GetOptions ()
2116 {
2117 return &m_options;
2118 }
2119
2120 class CommandOptions : public Options
2121 {
2122 public:
2123
2124 CommandOptions (CommandInterpreter &interpreter) :
2125 Options(interpreter),
2126 m_sort_order (eSortOrderNone)
2127 {
2128 }
2129
2130 virtual
2131 ~CommandOptions ()
2132 {
2133 }
2134
2135 virtual Error
2136 SetOptionValue (uint32_t option_idx, const char *option_arg)
2137 {
2138 Error error;
Greg Clayton3bcdfc02012-12-04 00:32:51 +00002139 const int short_option = m_getopt_table[option_idx].val;
Jim Ingham5a988412012-06-08 21:56:10 +00002140
2141 switch (short_option)
2142 {
2143 case 's':
2144 m_sort_order = (SortOrder) Args::StringToOptionEnum (option_arg,
2145 g_option_table[option_idx].enum_values,
2146 eSortOrderNone,
2147 error);
2148 break;
2149
2150 default:
2151 error.SetErrorStringWithFormat("invalid short option character '%c'", short_option);
2152 break;
2153
2154 }
2155 return error;
2156 }
2157
2158 void
2159 OptionParsingStarting ()
2160 {
2161 m_sort_order = eSortOrderNone;
2162 }
2163
2164 const OptionDefinition*
2165 GetDefinitions ()
2166 {
2167 return g_option_table;
2168 }
2169
2170 // Options table: Required for subclasses of Options.
2171 static OptionDefinition g_option_table[];
2172
2173 SortOrder m_sort_order;
2174 };
2175
2176protected:
Greg Claytoneffe5c92011-05-03 22:09:39 +00002177 virtual bool
Jim Ingham5a988412012-06-08 21:56:10 +00002178 DoExecute (Args& command,
Greg Claytoneffe5c92011-05-03 22:09:39 +00002179 CommandReturnObject &result)
2180 {
2181 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
2182 if (target == NULL)
2183 {
2184 result.AppendError ("invalid target, create a debug target using the 'target create' command");
2185 result.SetStatus (eReturnStatusFailed);
2186 return false;
2187 }
2188 else
2189 {
2190 uint32_t num_dumped = 0;
2191
2192 uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize();
2193 result.GetOutputStream().SetAddressByteSize(addr_byte_size);
2194 result.GetErrorStream().SetAddressByteSize(addr_byte_size);
2195
2196 if (command.GetArgumentCount() == 0)
2197 {
2198 // Dump all sections for all modules images
Jim Ingham3ee12ef2012-05-30 02:19:25 +00002199 Mutex::Locker modules_locker(target->GetImages().GetMutex());
Greg Claytonc7bece562013-01-25 18:06:21 +00002200 const size_t num_modules = target->GetImages().GetSize();
Greg Claytoneffe5c92011-05-03 22:09:39 +00002201 if (num_modules > 0)
2202 {
Deepak Panickal99fbc072014-03-03 15:39:47 +00002203 result.GetOutputStream().Printf("Dumping symbol table for %" PRIu64 " modules.\n", (uint64_t)num_modules);
Greg Claytonc7bece562013-01-25 18:06:21 +00002204 for (size_t image_idx = 0; image_idx<num_modules; ++image_idx)
Greg Claytoneffe5c92011-05-03 22:09:39 +00002205 {
2206 if (num_dumped > 0)
2207 {
2208 result.GetOutputStream().EOL();
2209 result.GetOutputStream().EOL();
2210 }
2211 num_dumped++;
Jim Ingham3ee12ef2012-05-30 02:19:25 +00002212 DumpModuleSymtab (m_interpreter,
2213 result.GetOutputStream(),
2214 target->GetImages().GetModulePointerAtIndexUnlocked(image_idx),
2215 m_options.m_sort_order);
Greg Claytoneffe5c92011-05-03 22:09:39 +00002216 }
2217 }
2218 else
2219 {
2220 result.AppendError ("the target has no associated executable images");
2221 result.SetStatus (eReturnStatusFailed);
2222 return false;
2223 }
2224 }
2225 else
2226 {
2227 // Dump specified images (by basename or fullpath)
2228 const char *arg_cstr;
2229 for (int arg_idx = 0; (arg_cstr = command.GetArgumentAtIndex(arg_idx)) != NULL; ++arg_idx)
2230 {
Greg Clayton8ee64382011-11-10 01:18:58 +00002231 ModuleList module_list;
2232 const size_t num_matches = FindModulesByName (target, arg_cstr, module_list, true);
2233 if (num_matches > 0)
Greg Claytoneffe5c92011-05-03 22:09:39 +00002234 {
Greg Clayton8ee64382011-11-10 01:18:58 +00002235 for (size_t i=0; i<num_matches; ++i)
Greg Claytoneffe5c92011-05-03 22:09:39 +00002236 {
Greg Clayton8ee64382011-11-10 01:18:58 +00002237 Module *module = module_list.GetModulePointerAtIndex(i);
2238 if (module)
Greg Claytoneffe5c92011-05-03 22:09:39 +00002239 {
2240 if (num_dumped > 0)
2241 {
2242 result.GetOutputStream().EOL();
2243 result.GetOutputStream().EOL();
2244 }
2245 num_dumped++;
Greg Clayton8ee64382011-11-10 01:18:58 +00002246 DumpModuleSymtab (m_interpreter, result.GetOutputStream(), module, m_options.m_sort_order);
Greg Claytoneffe5c92011-05-03 22:09:39 +00002247 }
2248 }
2249 }
2250 else
2251 result.AppendWarningWithFormat("Unable to find an image that matches '%s'.\n", arg_cstr);
2252 }
2253 }
2254
2255 if (num_dumped > 0)
2256 result.SetStatus (eReturnStatusSuccessFinishResult);
2257 else
2258 {
2259 result.AppendError ("no matching executable images found");
2260 result.SetStatus (eReturnStatusFailed);
2261 }
2262 }
2263 return result.Succeeded();
2264 }
2265
Greg Claytoneffe5c92011-05-03 22:09:39 +00002266
2267 CommandOptions m_options;
2268};
2269
2270static OptionEnumValueElement
2271g_sort_option_enumeration[4] =
2272{
2273 { eSortOrderNone, "none", "No sorting, use the original symbol table order."},
2274 { eSortOrderByAddress, "address", "Sort output by symbol address."},
2275 { eSortOrderByName, "name", "Sort output by symbol name."},
2276 { 0, NULL, NULL }
2277};
2278
2279
2280OptionDefinition
2281CommandObjectTargetModulesDumpSymtab::CommandOptions::g_option_table[] =
2282{
Virgile Belloe2607b52013-09-05 16:42:23 +00002283 { LLDB_OPT_SET_1, false, "sort", 's', OptionParser::eRequiredArgument, g_sort_option_enumeration, 0, eArgTypeSortOrder, "Supply a sort order when dumping the symbol table."},
Greg Claytoneffe5c92011-05-03 22:09:39 +00002284 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
2285};
2286
2287#pragma mark CommandObjectTargetModulesDumpSections
2288
2289//----------------------------------------------------------------------
2290// Image section dumping command
2291//----------------------------------------------------------------------
2292
2293class CommandObjectTargetModulesDumpSections : public CommandObjectTargetModulesModuleAutoComplete
2294{
2295public:
2296 CommandObjectTargetModulesDumpSections (CommandInterpreter &interpreter) :
2297 CommandObjectTargetModulesModuleAutoComplete (interpreter,
2298 "target modules dump sections",
2299 "Dump the sections from one or more target modules.",
2300 //"target modules dump sections [<file1> ...]")
2301 NULL)
2302 {
2303 }
2304
2305 virtual
2306 ~CommandObjectTargetModulesDumpSections ()
2307 {
2308 }
2309
Jim Ingham5a988412012-06-08 21:56:10 +00002310protected:
Greg Claytoneffe5c92011-05-03 22:09:39 +00002311 virtual bool
Jim Ingham5a988412012-06-08 21:56:10 +00002312 DoExecute (Args& command,
Greg Claytoneffe5c92011-05-03 22:09:39 +00002313 CommandReturnObject &result)
2314 {
2315 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
2316 if (target == NULL)
2317 {
2318 result.AppendError ("invalid target, create a debug target using the 'target create' command");
2319 result.SetStatus (eReturnStatusFailed);
2320 return false;
2321 }
2322 else
2323 {
2324 uint32_t num_dumped = 0;
2325
2326 uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize();
2327 result.GetOutputStream().SetAddressByteSize(addr_byte_size);
2328 result.GetErrorStream().SetAddressByteSize(addr_byte_size);
2329
2330 if (command.GetArgumentCount() == 0)
2331 {
2332 // Dump all sections for all modules images
Greg Claytonc7bece562013-01-25 18:06:21 +00002333 const size_t num_modules = target->GetImages().GetSize();
Greg Claytoneffe5c92011-05-03 22:09:39 +00002334 if (num_modules > 0)
2335 {
Deepak Panickal99fbc072014-03-03 15:39:47 +00002336 result.GetOutputStream().Printf("Dumping sections for %" PRIu64 " modules.\n", (uint64_t)num_modules);
Greg Claytonc7bece562013-01-25 18:06:21 +00002337 for (size_t image_idx = 0; image_idx<num_modules; ++image_idx)
Greg Claytoneffe5c92011-05-03 22:09:39 +00002338 {
2339 num_dumped++;
2340 DumpModuleSections (m_interpreter, result.GetOutputStream(), target->GetImages().GetModulePointerAtIndex(image_idx));
2341 }
2342 }
2343 else
2344 {
2345 result.AppendError ("the target has no associated executable images");
2346 result.SetStatus (eReturnStatusFailed);
2347 return false;
2348 }
2349 }
2350 else
2351 {
2352 // Dump specified images (by basename or fullpath)
2353 const char *arg_cstr;
2354 for (int arg_idx = 0; (arg_cstr = command.GetArgumentAtIndex(arg_idx)) != NULL; ++arg_idx)
2355 {
Greg Clayton8ee64382011-11-10 01:18:58 +00002356 ModuleList module_list;
2357 const size_t num_matches = FindModulesByName (target, arg_cstr, module_list, true);
2358 if (num_matches > 0)
Greg Claytoneffe5c92011-05-03 22:09:39 +00002359 {
Greg Clayton8ee64382011-11-10 01:18:58 +00002360 for (size_t i=0; i<num_matches; ++i)
Greg Claytoneffe5c92011-05-03 22:09:39 +00002361 {
Greg Clayton8ee64382011-11-10 01:18:58 +00002362 Module *module = module_list.GetModulePointerAtIndex(i);
2363 if (module)
Greg Claytoneffe5c92011-05-03 22:09:39 +00002364 {
2365 num_dumped++;
Greg Clayton8ee64382011-11-10 01:18:58 +00002366 DumpModuleSections (m_interpreter, result.GetOutputStream(), module);
Greg Claytoneffe5c92011-05-03 22:09:39 +00002367 }
2368 }
2369 }
2370 else
Greg Clayton8ee64382011-11-10 01:18:58 +00002371 {
2372 // Check the global list
Greg Claytonb26e6be2012-01-27 18:08:35 +00002373 Mutex::Locker locker(Module::GetAllocationModuleCollectionMutex());
Greg Clayton8ee64382011-11-10 01:18:58 +00002374
Greg Claytoneffe5c92011-05-03 22:09:39 +00002375 result.AppendWarningWithFormat("Unable to find an image that matches '%s'.\n", arg_cstr);
Greg Clayton8ee64382011-11-10 01:18:58 +00002376 }
Greg Claytoneffe5c92011-05-03 22:09:39 +00002377 }
2378 }
2379
2380 if (num_dumped > 0)
2381 result.SetStatus (eReturnStatusSuccessFinishResult);
2382 else
2383 {
2384 result.AppendError ("no matching executable images found");
2385 result.SetStatus (eReturnStatusFailed);
2386 }
2387 }
2388 return result.Succeeded();
2389 }
2390};
2391
2392
2393#pragma mark CommandObjectTargetModulesDumpSymfile
2394
2395//----------------------------------------------------------------------
2396// Image debug symbol dumping command
2397//----------------------------------------------------------------------
2398
2399class CommandObjectTargetModulesDumpSymfile : public CommandObjectTargetModulesModuleAutoComplete
2400{
2401public:
2402 CommandObjectTargetModulesDumpSymfile (CommandInterpreter &interpreter) :
2403 CommandObjectTargetModulesModuleAutoComplete (interpreter,
2404 "target modules dump symfile",
2405 "Dump the debug symbol file for one or more target modules.",
2406 //"target modules dump symfile [<file1> ...]")
2407 NULL)
2408 {
2409 }
2410
2411 virtual
2412 ~CommandObjectTargetModulesDumpSymfile ()
2413 {
2414 }
2415
Jim Ingham5a988412012-06-08 21:56:10 +00002416protected:
Greg Claytoneffe5c92011-05-03 22:09:39 +00002417 virtual bool
Jim Ingham5a988412012-06-08 21:56:10 +00002418 DoExecute (Args& command,
Greg Claytoneffe5c92011-05-03 22:09:39 +00002419 CommandReturnObject &result)
2420 {
2421 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
2422 if (target == NULL)
2423 {
2424 result.AppendError ("invalid target, create a debug target using the 'target create' command");
2425 result.SetStatus (eReturnStatusFailed);
2426 return false;
2427 }
2428 else
2429 {
2430 uint32_t num_dumped = 0;
2431
2432 uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize();
2433 result.GetOutputStream().SetAddressByteSize(addr_byte_size);
2434 result.GetErrorStream().SetAddressByteSize(addr_byte_size);
2435
2436 if (command.GetArgumentCount() == 0)
2437 {
2438 // Dump all sections for all modules images
Enrico Granata17598482012-11-08 02:22:02 +00002439 const ModuleList &target_modules = target->GetImages();
Jim Ingham3ee12ef2012-05-30 02:19:25 +00002440 Mutex::Locker modules_locker (target_modules.GetMutex());
Greg Claytonc7bece562013-01-25 18:06:21 +00002441 const size_t num_modules = target_modules.GetSize();
Greg Claytoneffe5c92011-05-03 22:09:39 +00002442 if (num_modules > 0)
2443 {
Deepak Panickal99fbc072014-03-03 15:39:47 +00002444 result.GetOutputStream().Printf("Dumping debug symbols for %" PRIu64 " modules.\n", (uint64_t)num_modules);
Greg Claytoneffe5c92011-05-03 22:09:39 +00002445 for (uint32_t image_idx = 0; image_idx<num_modules; ++image_idx)
2446 {
Jim Ingham3ee12ef2012-05-30 02:19:25 +00002447 if (DumpModuleSymbolVendor (result.GetOutputStream(), target_modules.GetModulePointerAtIndexUnlocked(image_idx)))
Greg Claytoneffe5c92011-05-03 22:09:39 +00002448 num_dumped++;
2449 }
2450 }
2451 else
2452 {
2453 result.AppendError ("the target has no associated executable images");
2454 result.SetStatus (eReturnStatusFailed);
2455 return false;
2456 }
2457 }
2458 else
2459 {
2460 // Dump specified images (by basename or fullpath)
2461 const char *arg_cstr;
2462 for (int arg_idx = 0; (arg_cstr = command.GetArgumentAtIndex(arg_idx)) != NULL; ++arg_idx)
2463 {
Greg Clayton8ee64382011-11-10 01:18:58 +00002464 ModuleList module_list;
2465 const size_t num_matches = FindModulesByName (target, arg_cstr, module_list, true);
2466 if (num_matches > 0)
Greg Claytoneffe5c92011-05-03 22:09:39 +00002467 {
Greg Clayton8ee64382011-11-10 01:18:58 +00002468 for (size_t i=0; i<num_matches; ++i)
Greg Claytoneffe5c92011-05-03 22:09:39 +00002469 {
Greg Clayton8ee64382011-11-10 01:18:58 +00002470 Module *module = module_list.GetModulePointerAtIndex(i);
2471 if (module)
Greg Claytoneffe5c92011-05-03 22:09:39 +00002472 {
Greg Clayton8ee64382011-11-10 01:18:58 +00002473 if (DumpModuleSymbolVendor (result.GetOutputStream(), module))
Greg Claytoneffe5c92011-05-03 22:09:39 +00002474 num_dumped++;
2475 }
2476 }
2477 }
2478 else
2479 result.AppendWarningWithFormat("Unable to find an image that matches '%s'.\n", arg_cstr);
2480 }
2481 }
2482
2483 if (num_dumped > 0)
2484 result.SetStatus (eReturnStatusSuccessFinishResult);
2485 else
2486 {
2487 result.AppendError ("no matching executable images found");
2488 result.SetStatus (eReturnStatusFailed);
2489 }
2490 }
2491 return result.Succeeded();
2492 }
2493};
2494
2495
2496#pragma mark CommandObjectTargetModulesDumpLineTable
2497
2498//----------------------------------------------------------------------
2499// Image debug line table dumping command
2500//----------------------------------------------------------------------
2501
2502class CommandObjectTargetModulesDumpLineTable : public CommandObjectTargetModulesSourceFileAutoComplete
2503{
2504public:
2505 CommandObjectTargetModulesDumpLineTable (CommandInterpreter &interpreter) :
2506 CommandObjectTargetModulesSourceFileAutoComplete (interpreter,
Greg Claytonf9fc6092013-01-09 19:44:40 +00002507 "target modules dump line-table",
Jim Inghamcc0273d2013-06-18 20:27:11 +00002508 "Dump the line table for one or more compilation units.",
Greg Claytonf9fc6092013-01-09 19:44:40 +00002509 NULL,
2510 eFlagRequiresTarget)
Greg Claytoneffe5c92011-05-03 22:09:39 +00002511 {
2512 }
2513
2514 virtual
2515 ~CommandObjectTargetModulesDumpLineTable ()
2516 {
2517 }
2518
Jim Ingham5a988412012-06-08 21:56:10 +00002519protected:
Greg Claytoneffe5c92011-05-03 22:09:39 +00002520 virtual bool
Jim Ingham5a988412012-06-08 21:56:10 +00002521 DoExecute (Args& command,
Greg Claytoneffe5c92011-05-03 22:09:39 +00002522 CommandReturnObject &result)
2523 {
Greg Claytonf9fc6092013-01-09 19:44:40 +00002524 Target *target = m_exe_ctx.GetTargetPtr();
2525 uint32_t total_num_dumped = 0;
2526
2527 uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize();
2528 result.GetOutputStream().SetAddressByteSize(addr_byte_size);
2529 result.GetErrorStream().SetAddressByteSize(addr_byte_size);
2530
2531 if (command.GetArgumentCount() == 0)
Greg Claytoneffe5c92011-05-03 22:09:39 +00002532 {
Greg Claytonf9fc6092013-01-09 19:44:40 +00002533 result.AppendErrorWithFormat ("\nSyntax: %s\n", m_cmd_syntax.c_str());
Greg Claytoneffe5c92011-05-03 22:09:39 +00002534 result.SetStatus (eReturnStatusFailed);
Greg Claytoneffe5c92011-05-03 22:09:39 +00002535 }
2536 else
2537 {
Greg Claytonf9fc6092013-01-09 19:44:40 +00002538 // Dump specified images (by basename or fullpath)
2539 const char *arg_cstr;
2540 for (int arg_idx = 0; (arg_cstr = command.GetArgumentAtIndex(arg_idx)) != NULL; ++arg_idx)
Greg Claytoneffe5c92011-05-03 22:09:39 +00002541 {
Greg Claytonf9fc6092013-01-09 19:44:40 +00002542 FileSpec file_spec(arg_cstr, false);
2543
2544 const ModuleList &target_modules = target->GetImages();
2545 Mutex::Locker modules_locker(target_modules.GetMutex());
Greg Claytonc7bece562013-01-25 18:06:21 +00002546 const size_t num_modules = target_modules.GetSize();
Greg Claytonf9fc6092013-01-09 19:44:40 +00002547 if (num_modules > 0)
Greg Claytoneffe5c92011-05-03 22:09:39 +00002548 {
Greg Claytonf9fc6092013-01-09 19:44:40 +00002549 uint32_t num_dumped = 0;
2550 for (uint32_t i = 0; i<num_modules; ++i)
Greg Claytoneffe5c92011-05-03 22:09:39 +00002551 {
Greg Claytonf9fc6092013-01-09 19:44:40 +00002552 if (DumpCompileUnitLineTable (m_interpreter,
2553 result.GetOutputStream(),
2554 target_modules.GetModulePointerAtIndexUnlocked(i),
2555 file_spec,
2556 m_exe_ctx.GetProcessPtr() && m_exe_ctx.GetProcessRef().IsAlive()))
2557 num_dumped++;
Greg Claytoneffe5c92011-05-03 22:09:39 +00002558 }
Greg Claytonf9fc6092013-01-09 19:44:40 +00002559 if (num_dumped == 0)
2560 result.AppendWarningWithFormat ("No source filenames matched '%s'.\n", arg_cstr);
2561 else
2562 total_num_dumped += num_dumped;
Greg Claytoneffe5c92011-05-03 22:09:39 +00002563 }
2564 }
Greg Claytonf9fc6092013-01-09 19:44:40 +00002565 }
2566
2567 if (total_num_dumped > 0)
2568 result.SetStatus (eReturnStatusSuccessFinishResult);
2569 else
2570 {
2571 result.AppendError ("no source filenames matched any command arguments");
2572 result.SetStatus (eReturnStatusFailed);
Greg Claytoneffe5c92011-05-03 22:09:39 +00002573 }
2574 return result.Succeeded();
2575 }
2576};
2577
2578
2579#pragma mark CommandObjectTargetModulesDump
2580
2581//----------------------------------------------------------------------
2582// Dump multi-word command for target modules
2583//----------------------------------------------------------------------
2584
2585class CommandObjectTargetModulesDump : public CommandObjectMultiword
2586{
2587public:
2588
2589 //------------------------------------------------------------------
2590 // Constructors and Destructors
2591 //------------------------------------------------------------------
2592 CommandObjectTargetModulesDump(CommandInterpreter &interpreter) :
2593 CommandObjectMultiword (interpreter,
2594 "target modules dump",
2595 "A set of commands for dumping information about one or more target modules.",
2596 "target modules dump [symtab|sections|symfile|line-table] [<file1> <file2> ...]")
2597 {
2598 LoadSubCommand ("symtab", CommandObjectSP (new CommandObjectTargetModulesDumpSymtab (interpreter)));
2599 LoadSubCommand ("sections", CommandObjectSP (new CommandObjectTargetModulesDumpSections (interpreter)));
2600 LoadSubCommand ("symfile", CommandObjectSP (new CommandObjectTargetModulesDumpSymfile (interpreter)));
2601 LoadSubCommand ("line-table", CommandObjectSP (new CommandObjectTargetModulesDumpLineTable (interpreter)));
2602 }
2603
2604 virtual
2605 ~CommandObjectTargetModulesDump()
2606 {
2607 }
2608};
2609
Jim Ingham5a988412012-06-08 21:56:10 +00002610class CommandObjectTargetModulesAdd : public CommandObjectParsed
Greg Claytoneffe5c92011-05-03 22:09:39 +00002611{
2612public:
2613 CommandObjectTargetModulesAdd (CommandInterpreter &interpreter) :
Jim Ingham5a988412012-06-08 21:56:10 +00002614 CommandObjectParsed (interpreter,
2615 "target modules add",
2616 "Add a new module to the current target's modules.",
Greg Clayton50a24bd2012-11-29 22:16:27 +00002617 "target modules add [<module>]"),
Greg Clayton1c5f1862012-11-30 19:05:35 +00002618 m_option_group (interpreter),
2619 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 Claytoneffe5c92011-05-03 22:09:39 +00002620 {
Greg Clayton50a24bd2012-11-29 22:16:27 +00002621 m_option_group.Append (&m_uuid_option_group, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
Greg Clayton1c5f1862012-11-30 19:05:35 +00002622 m_option_group.Append (&m_symbol_file, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
Greg Clayton50a24bd2012-11-29 22:16:27 +00002623 m_option_group.Finalize();
Greg Claytoneffe5c92011-05-03 22:09:39 +00002624 }
2625
2626 virtual
2627 ~CommandObjectTargetModulesAdd ()
2628 {
2629 }
Greg Clayton50a24bd2012-11-29 22:16:27 +00002630
2631 virtual Options *
2632 GetOptions ()
2633 {
2634 return &m_option_group;
2635 }
Greg Claytoneffe5c92011-05-03 22:09:39 +00002636
Greg Claytonc7bece562013-01-25 18:06:21 +00002637 virtual int
Jim Ingham5a988412012-06-08 21:56:10 +00002638 HandleArgumentCompletion (Args &input,
2639 int &cursor_index,
2640 int &cursor_char_position,
2641 OptionElementVector &opt_element_vector,
2642 int match_start_point,
2643 int max_return_elements,
2644 bool &word_complete,
2645 StringList &matches)
2646 {
2647 std::string completion_str (input.GetArgumentAtIndex(cursor_index));
2648 completion_str.erase (cursor_char_position);
2649
2650 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
2651 CommandCompletions::eDiskFileCompletion,
2652 completion_str.c_str(),
2653 match_start_point,
2654 max_return_elements,
2655 NULL,
2656 word_complete,
2657 matches);
2658 return matches.GetSize();
2659 }
2660
2661protected:
Greg Clayton50a24bd2012-11-29 22:16:27 +00002662
2663 OptionGroupOptions m_option_group;
2664 OptionGroupUUID m_uuid_option_group;
Greg Clayton1c5f1862012-11-30 19:05:35 +00002665 OptionGroupFile m_symbol_file;
Greg Clayton50a24bd2012-11-29 22:16:27 +00002666
2667
Greg Claytoneffe5c92011-05-03 22:09:39 +00002668 virtual bool
Jim Ingham5a988412012-06-08 21:56:10 +00002669 DoExecute (Args& args,
Greg Claytoneffe5c92011-05-03 22:09:39 +00002670 CommandReturnObject &result)
2671 {
2672 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
2673 if (target == NULL)
2674 {
2675 result.AppendError ("invalid target, create a debug target using the 'target create' command");
2676 result.SetStatus (eReturnStatusFailed);
2677 return false;
2678 }
2679 else
2680 {
Sean Callananb36c6c02012-12-13 01:39:39 +00002681 bool flush = false;
2682
Greg Claytoneffe5c92011-05-03 22:09:39 +00002683 const size_t argc = args.GetArgumentCount();
2684 if (argc == 0)
2685 {
Greg Clayton50a24bd2012-11-29 22:16:27 +00002686 if (m_uuid_option_group.GetOptionValue ().OptionWasSet())
2687 {
2688 // We are given a UUID only, go locate the file
2689 ModuleSpec module_spec;
2690 module_spec.GetUUID() = m_uuid_option_group.GetOptionValue ().GetCurrentValue();
Greg Clayton1c5f1862012-11-30 19:05:35 +00002691 if (m_symbol_file.GetOptionValue().OptionWasSet())
2692 module_spec.GetSymbolFileSpec() = m_symbol_file.GetOptionValue().GetCurrentValue();
Greg Clayton50a24bd2012-11-29 22:16:27 +00002693 if (Symbols::DownloadObjectAndSymbolFile (module_spec))
2694 {
2695 ModuleSP module_sp (target->GetSharedModule (module_spec));
2696 if (module_sp)
2697 {
2698 result.SetStatus (eReturnStatusSuccessFinishResult);
2699 return true;
2700 }
2701 else
2702 {
Sean Callananb36c6c02012-12-13 01:39:39 +00002703 flush = true;
2704
Greg Clayton50a24bd2012-11-29 22:16:27 +00002705 StreamString strm;
2706 module_spec.GetUUID().Dump (&strm);
2707 if (module_spec.GetFileSpec())
2708 {
2709 if (module_spec.GetSymbolFileSpec())
2710 {
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00002711 result.AppendErrorWithFormat ("Unable to create the executable or symbol file with UUID %s with path %s and symbol file %s",
Greg Clayton50a24bd2012-11-29 22:16:27 +00002712 strm.GetString().c_str(),
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00002713 module_spec.GetFileSpec().GetPath().c_str(),
2714 module_spec.GetSymbolFileSpec().GetPath().c_str());
Greg Clayton50a24bd2012-11-29 22:16:27 +00002715 }
2716 else
2717 {
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00002718 result.AppendErrorWithFormat ("Unable to create the executable or symbol file with UUID %s with path %s",
Greg Clayton50a24bd2012-11-29 22:16:27 +00002719 strm.GetString().c_str(),
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00002720 module_spec.GetFileSpec().GetPath().c_str());
Greg Clayton50a24bd2012-11-29 22:16:27 +00002721 }
2722 }
2723 else
2724 {
2725 result.AppendErrorWithFormat ("Unable to create the executable or symbol file with UUID %s",
2726 strm.GetString().c_str());
2727 }
2728 result.SetStatus (eReturnStatusFailed);
2729 return false;
2730 }
2731 }
2732 else
2733 {
2734 StreamString strm;
2735 module_spec.GetUUID().Dump (&strm);
2736 result.AppendErrorWithFormat ("Unable to locate the executable or symbol file with UUID %s", strm.GetString().c_str());
2737 result.SetStatus (eReturnStatusFailed);
2738 return false;
2739 }
2740 }
2741 else
2742 {
2743 result.AppendError ("one or more executable image paths must be specified");
2744 result.SetStatus (eReturnStatusFailed);
2745 return false;
2746 }
Greg Claytoneffe5c92011-05-03 22:09:39 +00002747 }
2748 else
2749 {
2750 for (size_t i=0; i<argc; ++i)
2751 {
2752 const char *path = args.GetArgumentAtIndex(i);
2753 if (path)
2754 {
2755 FileSpec file_spec(path, true);
Greg Claytoneffe5c92011-05-03 22:09:39 +00002756 if (file_spec.Exists())
2757 {
Greg Claytonb9a01b32012-02-26 05:51:37 +00002758 ModuleSpec module_spec (file_spec);
Greg Clayton50a24bd2012-11-29 22:16:27 +00002759 if (m_uuid_option_group.GetOptionValue ().OptionWasSet())
2760 module_spec.GetUUID() = m_uuid_option_group.GetOptionValue ().GetCurrentValue();
Greg Clayton1c5f1862012-11-30 19:05:35 +00002761 if (m_symbol_file.GetOptionValue().OptionWasSet())
2762 module_spec.GetSymbolFileSpec() = m_symbol_file.GetOptionValue().GetCurrentValue();
Jason Molendab019cd92013-09-11 21:25:46 +00002763 if (!module_spec.GetArchitecture().IsValid())
2764 module_spec.GetArchitecture() = target->GetArchitecture();
Greg Clayton50a24bd2012-11-29 22:16:27 +00002765 Error error;
2766 ModuleSP module_sp (target->GetSharedModule (module_spec, &error));
Greg Claytoneffe5c92011-05-03 22:09:39 +00002767 if (!module_sp)
2768 {
Greg Clayton50a24bd2012-11-29 22:16:27 +00002769 const char *error_cstr = error.AsCString();
2770 if (error_cstr)
2771 result.AppendError (error_cstr);
2772 else
2773 result.AppendErrorWithFormat ("unsupported module: %s", path);
Greg Claytoneffe5c92011-05-03 22:09:39 +00002774 result.SetStatus (eReturnStatusFailed);
2775 return false;
2776 }
Sean Callananb36c6c02012-12-13 01:39:39 +00002777 else
2778 {
2779 flush = true;
2780 }
Jason Molenda2f7af6a2011-08-02 23:28:55 +00002781 result.SetStatus (eReturnStatusSuccessFinishResult);
Greg Claytoneffe5c92011-05-03 22:09:39 +00002782 }
2783 else
2784 {
2785 char resolved_path[PATH_MAX];
2786 result.SetStatus (eReturnStatusFailed);
2787 if (file_spec.GetPath (resolved_path, sizeof(resolved_path)))
2788 {
2789 if (strcmp (resolved_path, path) != 0)
2790 {
2791 result.AppendErrorWithFormat ("invalid module path '%s' with resolved path '%s'\n", path, resolved_path);
2792 break;
2793 }
2794 }
2795 result.AppendErrorWithFormat ("invalid module path '%s'\n", path);
2796 break;
2797 }
2798 }
2799 }
2800 }
Sean Callananb36c6c02012-12-13 01:39:39 +00002801
2802 if (flush)
2803 {
2804 ProcessSP process = target->GetProcessSP();
2805 if (process)
2806 process->Flush();
2807 }
Greg Claytoneffe5c92011-05-03 22:09:39 +00002808 }
Sean Callananb36c6c02012-12-13 01:39:39 +00002809
Greg Claytoneffe5c92011-05-03 22:09:39 +00002810 return result.Succeeded();
2811 }
2812
Greg Claytoneffe5c92011-05-03 22:09:39 +00002813};
2814
2815class CommandObjectTargetModulesLoad : public CommandObjectTargetModulesModuleAutoComplete
2816{
2817public:
2818 CommandObjectTargetModulesLoad (CommandInterpreter &interpreter) :
2819 CommandObjectTargetModulesModuleAutoComplete (interpreter,
2820 "target modules load",
2821 "Set the load addresses for one or more sections in a target module.",
2822 "target modules load [--file <module> --uuid <uuid>] <sect-name> <address> [<sect-name> <address> ....]"),
2823 m_option_group (interpreter),
Sean Callanan31542552012-10-24 01:12:14 +00002824 m_file_option (LLDB_OPT_SET_1, false, "file", 'f', 0, eArgTypeFilename, "Fullpath or basename for module to load."),
Greg Claytoneffe5c92011-05-03 22:09:39 +00002825 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)
2826 {
2827 m_option_group.Append (&m_uuid_option_group, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
2828 m_option_group.Append (&m_file_option, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
2829 m_option_group.Append (&m_slide_option, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
2830 m_option_group.Finalize();
2831 }
2832
2833 virtual
2834 ~CommandObjectTargetModulesLoad ()
2835 {
2836 }
2837
Jim Ingham5a988412012-06-08 21:56:10 +00002838 virtual Options *
2839 GetOptions ()
2840 {
2841 return &m_option_group;
2842 }
2843
2844protected:
Greg Claytoneffe5c92011-05-03 22:09:39 +00002845 virtual bool
Jim Ingham5a988412012-06-08 21:56:10 +00002846 DoExecute (Args& args,
Greg Claytoneffe5c92011-05-03 22:09:39 +00002847 CommandReturnObject &result)
2848 {
2849 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
2850 if (target == NULL)
2851 {
2852 result.AppendError ("invalid target, create a debug target using the 'target create' command");
2853 result.SetStatus (eReturnStatusFailed);
2854 return false;
2855 }
2856 else
2857 {
2858 const size_t argc = args.GetArgumentCount();
Greg Claytonb9a01b32012-02-26 05:51:37 +00002859 ModuleSpec module_spec;
2860 bool search_using_module_spec = false;
Greg Claytoneffe5c92011-05-03 22:09:39 +00002861 if (m_file_option.GetOptionValue().OptionWasSet())
Greg Claytonb9a01b32012-02-26 05:51:37 +00002862 {
2863 search_using_module_spec = true;
2864 module_spec.GetFileSpec() = m_file_option.GetOptionValue().GetCurrentValue();
2865 }
Greg Claytoneffe5c92011-05-03 22:09:39 +00002866
2867 if (m_uuid_option_group.GetOptionValue().OptionWasSet())
Greg Claytonb9a01b32012-02-26 05:51:37 +00002868 {
2869 search_using_module_spec = true;
2870 module_spec.GetUUID() = m_uuid_option_group.GetOptionValue().GetCurrentValue();
2871 }
Greg Claytoneffe5c92011-05-03 22:09:39 +00002872
Greg Claytonb9a01b32012-02-26 05:51:37 +00002873 if (search_using_module_spec)
Greg Claytoneffe5c92011-05-03 22:09:39 +00002874 {
2875
2876 ModuleList matching_modules;
Greg Claytonb9a01b32012-02-26 05:51:37 +00002877 const size_t num_matches = target->GetImages().FindModules (module_spec, matching_modules);
Greg Claytoneffe5c92011-05-03 22:09:39 +00002878
2879 char path[PATH_MAX];
2880 if (num_matches == 1)
2881 {
2882 Module *module = matching_modules.GetModulePointerAtIndex(0);
2883 if (module)
2884 {
2885 ObjectFile *objfile = module->GetObjectFile();
2886 if (objfile)
2887 {
Greg Clayton3046e662013-07-10 01:23:25 +00002888 SectionList *section_list = module->GetSectionList();
Greg Claytoneffe5c92011-05-03 22:09:39 +00002889 if (section_list)
2890 {
Greg Clayton741f3f92012-03-27 21:10:07 +00002891 bool changed = false;
Greg Claytoneffe5c92011-05-03 22:09:39 +00002892 if (argc == 0)
2893 {
2894 if (m_slide_option.GetOptionValue().OptionWasSet())
2895 {
Greg Clayton741f3f92012-03-27 21:10:07 +00002896 const addr_t slide = m_slide_option.GetOptionValue().GetCurrentValue();
Greg Clayton751caf62014-02-07 22:54:47 +00002897 const bool slide_is_offset = true;
2898 module->SetLoadAddress (*target, slide, slide_is_offset, changed);
Greg Claytoneffe5c92011-05-03 22:09:39 +00002899 }
2900 else
2901 {
2902 result.AppendError ("one or more section name + load address pair must be specified");
2903 result.SetStatus (eReturnStatusFailed);
2904 return false;
2905 }
2906 }
2907 else
2908 {
2909 if (m_slide_option.GetOptionValue().OptionWasSet())
2910 {
2911 result.AppendError ("The \"--slide <offset>\" option can't be used in conjunction with setting section load addresses.\n");
2912 result.SetStatus (eReturnStatusFailed);
2913 return false;
2914 }
2915
2916 for (size_t i=0; i<argc; i += 2)
2917 {
2918 const char *sect_name = args.GetArgumentAtIndex(i);
2919 const char *load_addr_cstr = args.GetArgumentAtIndex(i+1);
2920 if (sect_name && load_addr_cstr)
2921 {
2922 ConstString const_sect_name(sect_name);
2923 bool success = false;
2924 addr_t load_addr = Args::StringToUInt64(load_addr_cstr, LLDB_INVALID_ADDRESS, 0, &success);
2925 if (success)
2926 {
2927 SectionSP section_sp (section_list->FindSectionByName(const_sect_name));
2928 if (section_sp)
2929 {
Greg Clayton741f3f92012-03-27 21:10:07 +00002930 if (section_sp->IsThreadSpecific())
2931 {
2932 result.AppendErrorWithFormat ("thread specific sections are not yet supported (section '%s')\n", sect_name);
2933 result.SetStatus (eReturnStatusFailed);
2934 break;
2935 }
2936 else
2937 {
Greg Clayton7820bd12012-07-07 01:24:12 +00002938 if (target->GetSectionLoadList().SetSectionLoadAddress (section_sp, load_addr))
Greg Clayton741f3f92012-03-27 21:10:07 +00002939 changed = true;
Daniel Malead01b2952012-11-29 21:49:15 +00002940 result.AppendMessageWithFormat("section '%s' loaded at 0x%" PRIx64 "\n", sect_name, load_addr);
Greg Clayton741f3f92012-03-27 21:10:07 +00002941 }
Greg Claytoneffe5c92011-05-03 22:09:39 +00002942 }
2943 else
2944 {
2945 result.AppendErrorWithFormat ("no section found that matches the section name '%s'\n", sect_name);
2946 result.SetStatus (eReturnStatusFailed);
2947 break;
2948 }
2949 }
2950 else
2951 {
2952 result.AppendErrorWithFormat ("invalid load address string '%s'\n", load_addr_cstr);
2953 result.SetStatus (eReturnStatusFailed);
2954 break;
2955 }
2956 }
2957 else
2958 {
2959 if (sect_name)
2960 result.AppendError ("section names must be followed by a load address.\n");
2961 else
2962 result.AppendError ("one or more section name + load address pair must be specified.\n");
2963 result.SetStatus (eReturnStatusFailed);
2964 break;
2965 }
2966 }
2967 }
Greg Clayton741f3f92012-03-27 21:10:07 +00002968
2969 if (changed)
Greg Clayton3c947372013-01-29 01:17:09 +00002970 {
Greg Clayton741f3f92012-03-27 21:10:07 +00002971 target->ModulesDidLoad (matching_modules);
Greg Clayton3c947372013-01-29 01:17:09 +00002972 Process *process = m_exe_ctx.GetProcessPtr();
2973 if (process)
2974 process->Flush();
2975 }
Greg Claytoneffe5c92011-05-03 22:09:39 +00002976 }
2977 else
2978 {
2979 module->GetFileSpec().GetPath (path, sizeof(path));
2980 result.AppendErrorWithFormat ("no sections in object file '%s'\n", path);
2981 result.SetStatus (eReturnStatusFailed);
2982 }
2983 }
2984 else
2985 {
2986 module->GetFileSpec().GetPath (path, sizeof(path));
2987 result.AppendErrorWithFormat ("no object file for module '%s'\n", path);
2988 result.SetStatus (eReturnStatusFailed);
2989 }
2990 }
2991 else
2992 {
Jim Ingham28eb5712012-10-12 17:34:26 +00002993 FileSpec *module_spec_file = module_spec.GetFileSpecPtr();
2994 if (module_spec_file)
2995 {
2996 module_spec_file->GetPath (path, sizeof(path));
2997 result.AppendErrorWithFormat ("invalid module '%s'.\n", path);
2998 }
2999 else
3000 result.AppendError ("no module spec");
Greg Claytoneffe5c92011-05-03 22:09:39 +00003001 result.SetStatus (eReturnStatusFailed);
3002 }
3003 }
3004 else
3005 {
Jason Molendac16b4af2013-05-03 23:56:12 +00003006 std::string uuid_str;
Greg Claytonb9a01b32012-02-26 05:51:37 +00003007
3008 if (module_spec.GetFileSpec())
3009 module_spec.GetFileSpec().GetPath (path, sizeof(path));
Greg Claytoneffe5c92011-05-03 22:09:39 +00003010 else
3011 path[0] = '\0';
3012
Greg Claytonb9a01b32012-02-26 05:51:37 +00003013 if (module_spec.GetUUIDPtr())
Jason Molendac16b4af2013-05-03 23:56:12 +00003014 uuid_str = module_spec.GetUUID().GetAsString();
Greg Claytoneffe5c92011-05-03 22:09:39 +00003015 if (num_matches > 1)
3016 {
3017 result.AppendErrorWithFormat ("multiple modules match%s%s%s%s:\n",
3018 path[0] ? " file=" : "",
3019 path,
Jason Molendac16b4af2013-05-03 23:56:12 +00003020 !uuid_str.empty() ? " uuid=" : "",
3021 uuid_str.c_str());
Greg Claytoneffe5c92011-05-03 22:09:39 +00003022 for (size_t i=0; i<num_matches; ++i)
3023 {
3024 if (matching_modules.GetModulePointerAtIndex(i)->GetFileSpec().GetPath (path, sizeof(path)))
3025 result.AppendMessageWithFormat("%s\n", path);
3026 }
3027 }
3028 else
3029 {
3030 result.AppendErrorWithFormat ("no modules were found that match%s%s%s%s.\n",
3031 path[0] ? " file=" : "",
3032 path,
Jason Molendac16b4af2013-05-03 23:56:12 +00003033 !uuid_str.empty() ? " uuid=" : "",
3034 uuid_str.c_str());
Greg Claytoneffe5c92011-05-03 22:09:39 +00003035 }
3036 result.SetStatus (eReturnStatusFailed);
3037 }
3038 }
3039 else
3040 {
3041 result.AppendError ("either the \"--file <module>\" or the \"--uuid <uuid>\" option must be specified.\n");
3042 result.SetStatus (eReturnStatusFailed);
3043 return false;
3044 }
3045 }
3046 return result.Succeeded();
3047 }
3048
Greg Claytoneffe5c92011-05-03 22:09:39 +00003049 OptionGroupOptions m_option_group;
3050 OptionGroupUUID m_uuid_option_group;
3051 OptionGroupFile m_file_option;
3052 OptionGroupUInt64 m_slide_option;
3053};
3054
3055//----------------------------------------------------------------------
3056// List images with associated information
3057//----------------------------------------------------------------------
Jim Ingham5a988412012-06-08 21:56:10 +00003058class CommandObjectTargetModulesList : public CommandObjectParsed
Greg Claytoneffe5c92011-05-03 22:09:39 +00003059{
3060public:
3061
3062 class CommandOptions : public Options
3063 {
3064 public:
3065
3066 CommandOptions (CommandInterpreter &interpreter) :
Greg Clayton65a03992011-08-09 00:01:09 +00003067 Options(interpreter),
Jim Inghamc10312c2011-10-24 18:36:33 +00003068 m_format_array(),
Daniel Dunbara08823f2011-10-31 22:50:49 +00003069 m_use_global_module_list (false),
Jim Inghamc10312c2011-10-24 18:36:33 +00003070 m_module_addr (LLDB_INVALID_ADDRESS)
Greg Claytoneffe5c92011-05-03 22:09:39 +00003071 {
3072 }
3073
3074 virtual
3075 ~CommandOptions ()
3076 {
3077 }
3078
3079 virtual Error
3080 SetOptionValue (uint32_t option_idx, const char *option_arg)
3081 {
Greg Claytonb9d5df52012-12-06 22:49:16 +00003082 Error error;
3083
Greg Clayton3bcdfc02012-12-04 00:32:51 +00003084 const int short_option = m_getopt_table[option_idx].val;
Greg Clayton65a03992011-08-09 00:01:09 +00003085 if (short_option == 'g')
3086 {
3087 m_use_global_module_list = true;
3088 }
Jim Inghamc10312c2011-10-24 18:36:33 +00003089 else if (short_option == 'a')
3090 {
Jim Inghame7b849e2013-03-15 23:09:19 +00003091 ExecutionContext exe_ctx (m_interpreter.GetExecutionContext());
3092 m_module_addr = Args::StringToAddress(&exe_ctx, option_arg, LLDB_INVALID_ADDRESS, &error);
Jim Inghamc10312c2011-10-24 18:36:33 +00003093 }
Greg Clayton65a03992011-08-09 00:01:09 +00003094 else
3095 {
Greg Claytonc7bece562013-01-25 18:06:21 +00003096 unsigned long width = 0;
Greg Clayton65a03992011-08-09 00:01:09 +00003097 if (option_arg)
3098 width = strtoul (option_arg, NULL, 0);
3099 m_format_array.push_back(std::make_pair(short_option, width));
3100 }
Greg Claytoneffe5c92011-05-03 22:09:39 +00003101 return error;
3102 }
3103
3104 void
3105 OptionParsingStarting ()
3106 {
3107 m_format_array.clear();
Greg Clayton65a03992011-08-09 00:01:09 +00003108 m_use_global_module_list = false;
Jim Inghamc10312c2011-10-24 18:36:33 +00003109 m_module_addr = LLDB_INVALID_ADDRESS;
Greg Claytoneffe5c92011-05-03 22:09:39 +00003110 }
3111
3112 const OptionDefinition*
3113 GetDefinitions ()
3114 {
3115 return g_option_table;
3116 }
3117
3118 // Options table: Required for subclasses of Options.
3119
3120 static OptionDefinition g_option_table[];
3121
3122 // Instance variables to hold the values for command options.
3123 typedef std::vector< std::pair<char, uint32_t> > FormatWidthCollection;
3124 FormatWidthCollection m_format_array;
Greg Clayton65a03992011-08-09 00:01:09 +00003125 bool m_use_global_module_list;
Jim Inghamc10312c2011-10-24 18:36:33 +00003126 lldb::addr_t m_module_addr;
Greg Claytoneffe5c92011-05-03 22:09:39 +00003127 };
3128
3129 CommandObjectTargetModulesList (CommandInterpreter &interpreter) :
Jim Ingham5a988412012-06-08 21:56:10 +00003130 CommandObjectParsed (interpreter,
3131 "target modules list",
3132 "List current executable and dependent shared library images.",
3133 "target modules list [<cmd-options>]"),
Greg Claytoneffe5c92011-05-03 22:09:39 +00003134 m_options (interpreter)
3135 {
3136 }
3137
3138 virtual
3139 ~CommandObjectTargetModulesList ()
3140 {
3141 }
3142
3143 virtual
3144 Options *
3145 GetOptions ()
3146 {
3147 return &m_options;
3148 }
3149
Jim Ingham5a988412012-06-08 21:56:10 +00003150protected:
Greg Claytoneffe5c92011-05-03 22:09:39 +00003151 virtual bool
Jim Ingham5a988412012-06-08 21:56:10 +00003152 DoExecute (Args& command,
Greg Claytoneffe5c92011-05-03 22:09:39 +00003153 CommandReturnObject &result)
3154 {
3155 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Greg Clayton3418c852011-08-10 02:10:13 +00003156 const bool use_global_module_list = m_options.m_use_global_module_list;
Greg Clayton234076c2012-06-27 20:26:19 +00003157 // Define a local module list here to ensure it lives longer than any "locker"
3158 // object which might lock its contents below (through the "module_list_ptr"
3159 // variable).
3160 ModuleList module_list;
Greg Clayton3418c852011-08-10 02:10:13 +00003161 if (target == NULL && use_global_module_list == false)
Greg Claytoneffe5c92011-05-03 22:09:39 +00003162 {
3163 result.AppendError ("invalid target, create a debug target using the 'target create' command");
3164 result.SetStatus (eReturnStatusFailed);
3165 return false;
3166 }
3167 else
3168 {
Greg Clayton3418c852011-08-10 02:10:13 +00003169 if (target)
3170 {
3171 uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize();
3172 result.GetOutputStream().SetAddressByteSize(addr_byte_size);
3173 result.GetErrorStream().SetAddressByteSize(addr_byte_size);
3174 }
Greg Claytoneffe5c92011-05-03 22:09:39 +00003175 // Dump all sections for all modules images
Jim Inghamc10312c2011-10-24 18:36:33 +00003176 Stream &strm = result.GetOutputStream();
3177
3178 if (m_options.m_module_addr != LLDB_INVALID_ADDRESS)
3179 {
3180 if (target)
3181 {
3182 Address module_address;
3183 if (module_address.SetLoadAddress(m_options.m_module_addr, target))
3184 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003185 ModuleSP module_sp (module_address.GetModule());
3186 if (module_sp)
Jim Inghamc10312c2011-10-24 18:36:33 +00003187 {
Greg Claytonc7bece562013-01-25 18:06:21 +00003188 PrintModule (target, module_sp.get(), 0, strm);
Jim Inghamc10312c2011-10-24 18:36:33 +00003189 result.SetStatus (eReturnStatusSuccessFinishResult);
3190 }
3191 else
3192 {
Jim Ingham17fafa12012-12-15 02:40:54 +00003193 result.AppendErrorWithFormat ("Couldn't find module matching address: 0x%" PRIx64 ".", m_options.m_module_addr);
Jim Inghamc10312c2011-10-24 18:36:33 +00003194 result.SetStatus (eReturnStatusFailed);
3195 }
3196 }
3197 else
3198 {
Jim Ingham17fafa12012-12-15 02:40:54 +00003199 result.AppendErrorWithFormat ("Couldn't find module containing address: 0x%" PRIx64 ".", m_options.m_module_addr);
Jim Inghamc10312c2011-10-24 18:36:33 +00003200 result.SetStatus (eReturnStatusFailed);
3201 }
3202 }
3203 else
3204 {
3205 result.AppendError ("Can only look up modules by address with a valid target.");
3206 result.SetStatus (eReturnStatusFailed);
3207 }
3208 return result.Succeeded();
3209 }
3210
Greg Claytonc7bece562013-01-25 18:06:21 +00003211 size_t num_modules = 0;
Jim Ingham3ee12ef2012-05-30 02:19:25 +00003212 Mutex::Locker locker; // This locker will be locked on the mutex in module_list_ptr if it is non-NULL.
3213 // Otherwise it will lock the AllocationModuleCollectionMutex when accessing
3214 // the global module list directly.
Enrico Granata17598482012-11-08 02:22:02 +00003215 const ModuleList *module_list_ptr = NULL;
Greg Claytonc4a8a762012-05-15 18:43:44 +00003216 const size_t argc = command.GetArgumentCount();
3217 if (argc == 0)
Greg Clayton65a03992011-08-09 00:01:09 +00003218 {
Greg Claytonc4a8a762012-05-15 18:43:44 +00003219 if (use_global_module_list)
3220 {
3221 locker.Lock (Module::GetAllocationModuleCollectionMutex());
3222 num_modules = Module::GetNumberAllocatedModules();
3223 }
3224 else
3225 {
3226 module_list_ptr = &target->GetImages();
Greg Claytonc4a8a762012-05-15 18:43:44 +00003227 }
Greg Clayton65a03992011-08-09 00:01:09 +00003228 }
3229 else
Greg Claytonc4a8a762012-05-15 18:43:44 +00003230 {
3231 for (size_t i=0; i<argc; ++i)
3232 {
3233 // Dump specified images (by basename or fullpath)
3234 const char *arg_cstr = command.GetArgumentAtIndex(i);
3235 const size_t num_matches = FindModulesByName (target, arg_cstr, module_list, use_global_module_list);
3236 if (num_matches == 0)
3237 {
3238 if (argc == 1)
3239 {
3240 result.AppendErrorWithFormat ("no modules found that match '%s'", arg_cstr);
3241 result.SetStatus (eReturnStatusFailed);
3242 return false;
3243 }
3244 }
3245 }
3246
Greg Claytonc4a8a762012-05-15 18:43:44 +00003247 module_list_ptr = &module_list;
3248 }
Jim Ingham3ee12ef2012-05-30 02:19:25 +00003249
3250 if (module_list_ptr != NULL)
3251 {
3252 locker.Lock(module_list_ptr->GetMutex());
3253 num_modules = module_list_ptr->GetSize();
3254 }
Greg Clayton65a03992011-08-09 00:01:09 +00003255
Greg Claytoneffe5c92011-05-03 22:09:39 +00003256 if (num_modules > 0)
Jim Inghamc10312c2011-10-24 18:36:33 +00003257 {
Greg Claytoneffe5c92011-05-03 22:09:39 +00003258 for (uint32_t image_idx = 0; image_idx<num_modules; ++image_idx)
3259 {
Greg Clayton3418c852011-08-10 02:10:13 +00003260 ModuleSP module_sp;
Greg Clayton65a03992011-08-09 00:01:09 +00003261 Module *module;
Greg Claytonc4a8a762012-05-15 18:43:44 +00003262 if (module_list_ptr)
Greg Clayton65a03992011-08-09 00:01:09 +00003263 {
Jim Ingham3ee12ef2012-05-30 02:19:25 +00003264 module_sp = module_list_ptr->GetModuleAtIndexUnlocked(image_idx);
Greg Claytonc4a8a762012-05-15 18:43:44 +00003265 module = module_sp.get();
Greg Clayton65a03992011-08-09 00:01:09 +00003266 }
3267 else
3268 {
Greg Claytonc4a8a762012-05-15 18:43:44 +00003269 module = Module::GetAllocatedModuleAtIndex(image_idx);
3270 module_sp = module->shared_from_this();
Greg Clayton65a03992011-08-09 00:01:09 +00003271 }
Jim Inghamc10312c2011-10-24 18:36:33 +00003272
Greg Claytonc7bece562013-01-25 18:06:21 +00003273 const size_t indent = strm.Printf("[%3u] ", image_idx);
3274 PrintModule (target, module, indent, strm);
Greg Clayton3418c852011-08-10 02:10:13 +00003275
Greg Claytoneffe5c92011-05-03 22:09:39 +00003276 }
3277 result.SetStatus (eReturnStatusSuccessFinishResult);
3278 }
3279 else
3280 {
Greg Claytonc4a8a762012-05-15 18:43:44 +00003281 if (argc)
3282 {
3283 if (use_global_module_list)
3284 result.AppendError ("the global module list has no matching modules");
3285 else
3286 result.AppendError ("the target has no matching modules");
3287 }
Greg Clayton3418c852011-08-10 02:10:13 +00003288 else
Greg Claytonc4a8a762012-05-15 18:43:44 +00003289 {
3290 if (use_global_module_list)
3291 result.AppendError ("the global module list is empty");
3292 else
3293 result.AppendError ("the target has no associated executable images");
3294 }
Greg Claytoneffe5c92011-05-03 22:09:39 +00003295 result.SetStatus (eReturnStatusFailed);
3296 return false;
3297 }
3298 }
3299 return result.Succeeded();
3300 }
Jim Inghamc10312c2011-10-24 18:36:33 +00003301
3302 void
Greg Claytonc7bece562013-01-25 18:06:21 +00003303 PrintModule (Target *target, Module *module, int indent, Stream &strm)
Jim Inghamc10312c2011-10-24 18:36:33 +00003304 {
3305
Jim Ingham28eb5712012-10-12 17:34:26 +00003306 if (module == NULL)
3307 {
3308 strm.PutCString("Null module");
3309 return;
3310 }
3311
Jim Inghamc10312c2011-10-24 18:36:33 +00003312 bool dump_object_name = false;
3313 if (m_options.m_format_array.empty())
3314 {
Greg Claytonc9660542012-02-05 02:38:54 +00003315 m_options.m_format_array.push_back(std::make_pair('u', 0));
3316 m_options.m_format_array.push_back(std::make_pair('h', 0));
3317 m_options.m_format_array.push_back(std::make_pair('f', 0));
3318 m_options.m_format_array.push_back(std::make_pair('S', 0));
Jim Inghamc10312c2011-10-24 18:36:33 +00003319 }
Greg Claytonc9660542012-02-05 02:38:54 +00003320 const size_t num_entries = m_options.m_format_array.size();
3321 bool print_space = false;
3322 for (size_t i=0; i<num_entries; ++i)
Jim Inghamc10312c2011-10-24 18:36:33 +00003323 {
Greg Claytonc9660542012-02-05 02:38:54 +00003324 if (print_space)
3325 strm.PutChar(' ');
3326 print_space = true;
3327 const char format_char = m_options.m_format_array[i].first;
3328 uint32_t width = m_options.m_format_array[i].second;
3329 switch (format_char)
Jim Inghamc10312c2011-10-24 18:36:33 +00003330 {
Greg Claytonc9660542012-02-05 02:38:54 +00003331 case 'A':
3332 DumpModuleArchitecture (strm, module, false, width);
3333 break;
3334
3335 case 't':
3336 DumpModuleArchitecture (strm, module, true, width);
3337 break;
3338
3339 case 'f':
3340 DumpFullpath (strm, &module->GetFileSpec(), width);
3341 dump_object_name = true;
3342 break;
3343
3344 case 'd':
3345 DumpDirectory (strm, &module->GetFileSpec(), width);
3346 break;
3347
3348 case 'b':
3349 DumpBasename (strm, &module->GetFileSpec(), width);
3350 dump_object_name = true;
3351 break;
3352
3353 case 'h':
3354 case 'o':
3355 // Image header address
3356 {
3357 uint32_t addr_nibble_width = target ? (target->GetArchitecture().GetAddressByteSize() * 2) : 16;
Jim Inghamc10312c2011-10-24 18:36:33 +00003358
Greg Claytonc9660542012-02-05 02:38:54 +00003359 ObjectFile *objfile = module->GetObjectFile ();
3360 if (objfile)
Jim Inghamc10312c2011-10-24 18:36:33 +00003361 {
Greg Claytonc9660542012-02-05 02:38:54 +00003362 Address header_addr(objfile->GetHeaderAddress());
3363 if (header_addr.IsValid())
Jim Inghamc10312c2011-10-24 18:36:33 +00003364 {
Greg Claytonc9660542012-02-05 02:38:54 +00003365 if (target && !target->GetSectionLoadList().IsEmpty())
Jim Inghamc10312c2011-10-24 18:36:33 +00003366 {
Greg Claytonc9660542012-02-05 02:38:54 +00003367 lldb::addr_t header_load_addr = header_addr.GetLoadAddress (target);
3368 if (header_load_addr == LLDB_INVALID_ADDRESS)
3369 {
3370 header_addr.Dump (&strm, target, Address::DumpStyleModuleWithFileAddress, Address::DumpStyleFileAddress);
3371 }
Jim Inghamc10312c2011-10-24 18:36:33 +00003372 else
Greg Claytonc9660542012-02-05 02:38:54 +00003373 {
3374 if (format_char == 'o')
3375 {
3376 // Show the offset of slide for the image
Daniel Malead01b2952012-11-29 21:49:15 +00003377 strm.Printf ("0x%*.*" PRIx64, addr_nibble_width, addr_nibble_width, header_load_addr - header_addr.GetFileAddress());
Greg Claytonc9660542012-02-05 02:38:54 +00003378 }
3379 else
3380 {
3381 // Show the load address of the image
Daniel Malead01b2952012-11-29 21:49:15 +00003382 strm.Printf ("0x%*.*" PRIx64, addr_nibble_width, addr_nibble_width, header_load_addr);
Greg Claytonc9660542012-02-05 02:38:54 +00003383 }
3384 }
Jim Inghamc10312c2011-10-24 18:36:33 +00003385 break;
3386 }
Greg Claytonc9660542012-02-05 02:38:54 +00003387 // The address was valid, but the image isn't loaded, output the address in an appropriate format
3388 header_addr.Dump (&strm, target, Address::DumpStyleFileAddress);
3389 break;
Jim Inghamc10312c2011-10-24 18:36:33 +00003390 }
Jim Inghamc10312c2011-10-24 18:36:33 +00003391 }
Greg Claytonc9660542012-02-05 02:38:54 +00003392 strm.Printf ("%*s", addr_nibble_width + 2, "");
3393 }
3394 break;
3395 case 'r':
3396 {
Greg Claytonc7bece562013-01-25 18:06:21 +00003397 size_t ref_count = 0;
Greg Claytonc9660542012-02-05 02:38:54 +00003398 ModuleSP module_sp (module->shared_from_this());
3399 if (module_sp)
3400 {
3401 // Take one away to make sure we don't count our local "module_sp"
3402 ref_count = module_sp.use_count() - 1;
3403 }
3404 if (width)
Greg Clayton6fea17e2014-03-03 19:15:20 +00003405 strm.Printf("{%*" PRIu64 "}", width, (uint64_t)ref_count);
Greg Claytonc9660542012-02-05 02:38:54 +00003406 else
Deepak Panickal99fbc072014-03-03 15:39:47 +00003407 strm.Printf("{%" PRIu64 "}", (uint64_t)ref_count);
Greg Claytonc9660542012-02-05 02:38:54 +00003408 }
3409 break;
Jim Inghamc10312c2011-10-24 18:36:33 +00003410
Greg Claytonc9660542012-02-05 02:38:54 +00003411 case 's':
3412 case 'S':
3413 {
3414 SymbolVendor *symbol_vendor = module->GetSymbolVendor();
3415 if (symbol_vendor)
3416 {
3417 SymbolFile *symbol_file = symbol_vendor->GetSymbolFile();
3418 if (symbol_file)
3419 {
3420 if (format_char == 'S')
3421 {
3422 FileSpec &symfile_spec = symbol_file->GetObjectFile()->GetFileSpec();
3423 // Dump symbol file only if different from module file
3424 if (!symfile_spec || symfile_spec == module->GetFileSpec())
3425 {
3426 print_space = false;
3427 break;
3428 }
3429 // Add a newline and indent past the index
3430 strm.Printf ("\n%*s", indent, "");
3431 }
3432 DumpFullpath (strm, &symbol_file->GetObjectFile()->GetFileSpec(), width);
3433 dump_object_name = true;
3434 break;
3435 }
3436 }
3437 strm.Printf("%.*s", width, "<NONE>");
3438 }
3439 break;
3440
3441 case 'm':
3442 module->GetModificationTime().Dump(&strm, width);
3443 break;
Jim Inghamc10312c2011-10-24 18:36:33 +00003444
Greg Claytonc9660542012-02-05 02:38:54 +00003445 case 'p':
3446 strm.Printf("%p", module);
3447 break;
3448
3449 case 'u':
3450 DumpModuleUUID(strm, module);
3451 break;
3452
3453 default:
3454 break;
Jim Inghamc10312c2011-10-24 18:36:33 +00003455 }
Greg Claytonc9660542012-02-05 02:38:54 +00003456
3457 }
3458 if (dump_object_name)
3459 {
3460 const char *object_name = module->GetObjectName().GetCString();
3461 if (object_name)
3462 strm.Printf ("(%s)", object_name);
Jim Inghamc10312c2011-10-24 18:36:33 +00003463 }
3464 strm.EOL();
3465 }
3466
Greg Claytoneffe5c92011-05-03 22:09:39 +00003467 CommandOptions m_options;
3468};
3469
3470OptionDefinition
3471CommandObjectTargetModulesList::CommandOptions::g_option_table[] =
3472{
Virgile Belloe2607b52013-09-05 16:42:23 +00003473 { LLDB_OPT_SET_1, false, "address", 'a', OptionParser::eRequiredArgument, NULL, 0, eArgTypeAddressOrExpression, "Display the image at this address."},
3474 { LLDB_OPT_SET_1, false, "arch", 'A', OptionParser::eOptionalArgument, NULL, 0, eArgTypeWidth, "Display the architecture when listing images."},
3475 { LLDB_OPT_SET_1, false, "triple", 't', OptionParser::eOptionalArgument, NULL, 0, eArgTypeWidth, "Display the triple when listing images."},
3476 { LLDB_OPT_SET_1, false, "header", 'h', OptionParser::eNoArgument, NULL, 0, eArgTypeNone, "Display the image header address as a load address if debugging, a file address otherwise."},
3477 { LLDB_OPT_SET_1, false, "offset", 'o', OptionParser::eNoArgument, NULL, 0, eArgTypeNone, "Display the image header address offset from the header file address (the slide amount)."},
3478 { LLDB_OPT_SET_1, false, "uuid", 'u', OptionParser::eNoArgument, NULL, 0, eArgTypeNone, "Display the UUID when listing images."},
3479 { LLDB_OPT_SET_1, false, "fullpath", 'f', OptionParser::eOptionalArgument, NULL, 0, eArgTypeWidth, "Display the fullpath to the image object file."},
3480 { LLDB_OPT_SET_1, false, "directory", 'd', OptionParser::eOptionalArgument, NULL, 0, eArgTypeWidth, "Display the directory with optional width for the image object file."},
3481 { LLDB_OPT_SET_1, false, "basename", 'b', OptionParser::eOptionalArgument, NULL, 0, eArgTypeWidth, "Display the basename with optional width for the image object file."},
3482 { LLDB_OPT_SET_1, false, "symfile", 's', OptionParser::eOptionalArgument, NULL, 0, eArgTypeWidth, "Display the fullpath to the image symbol file with optional width."},
3483 { LLDB_OPT_SET_1, false, "symfile-unique", 'S', OptionParser::eOptionalArgument, NULL, 0, eArgTypeWidth, "Display the symbol file with optional width only if it is different from the executable object file."},
3484 { LLDB_OPT_SET_1, false, "mod-time", 'm', OptionParser::eOptionalArgument, NULL, 0, eArgTypeWidth, "Display the modification time with optional width of the module."},
3485 { LLDB_OPT_SET_1, false, "ref-count", 'r', OptionParser::eOptionalArgument, NULL, 0, eArgTypeWidth, "Display the reference count if the module is still in the shared module cache."},
3486 { LLDB_OPT_SET_1, false, "pointer", 'p', OptionParser::eOptionalArgument, NULL, 0, eArgTypeNone, "Display the module pointer."},
3487 { LLDB_OPT_SET_1, false, "global", 'g', OptionParser::eNoArgument, NULL, 0, eArgTypeNone, "Display the modules from the global module list, not just the current target."},
Greg Claytoneffe5c92011-05-03 22:09:39 +00003488 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
3489};
3490
Jason Molenda380241a2012-07-12 00:20:07 +00003491#pragma mark CommandObjectTargetModulesShowUnwind
Greg Claytoneffe5c92011-05-03 22:09:39 +00003492
Jason Molenda380241a2012-07-12 00:20:07 +00003493//----------------------------------------------------------------------
3494// Lookup unwind information in images
3495//----------------------------------------------------------------------
3496
3497class CommandObjectTargetModulesShowUnwind : public CommandObjectParsed
3498{
3499public:
3500
3501 enum
3502 {
3503 eLookupTypeInvalid = -1,
3504 eLookupTypeAddress = 0,
3505 eLookupTypeSymbol,
3506 eLookupTypeFunction,
3507 eLookupTypeFunctionOrSymbol,
3508 kNumLookupTypes
3509 };
3510
3511 class CommandOptions : public Options
3512 {
3513 public:
3514
3515 CommandOptions (CommandInterpreter &interpreter) :
Greg Claytonf9fc6092013-01-09 19:44:40 +00003516 Options(interpreter),
3517 m_type(eLookupTypeInvalid),
3518 m_str(),
3519 m_addr(LLDB_INVALID_ADDRESS)
Jason Molenda380241a2012-07-12 00:20:07 +00003520 {
3521 }
3522
3523 virtual
3524 ~CommandOptions ()
3525 {
3526 }
3527
3528 virtual Error
3529 SetOptionValue (uint32_t option_idx, const char *option_arg)
3530 {
3531 Error error;
3532
Greg Clayton3bcdfc02012-12-04 00:32:51 +00003533 const int short_option = m_getopt_table[option_idx].val;
Jason Molenda380241a2012-07-12 00:20:07 +00003534
3535 switch (short_option)
3536 {
3537 case 'a':
Jason Molenda535ab862013-04-23 04:30:57 +00003538 {
3539 ExecutionContext exe_ctx (m_interpreter.GetExecutionContext());
Michael Sartainb1e15922013-08-22 20:42:30 +00003540 m_str = option_arg;
Jason Molenda380241a2012-07-12 00:20:07 +00003541 m_type = eLookupTypeAddress;
Jason Molenda535ab862013-04-23 04:30:57 +00003542 m_addr = Args::StringToAddress(&exe_ctx, option_arg, LLDB_INVALID_ADDRESS, &error);
Jason Molenda380241a2012-07-12 00:20:07 +00003543 if (m_addr == LLDB_INVALID_ADDRESS)
3544 error.SetErrorStringWithFormat ("invalid address string '%s'", option_arg);
3545 break;
Jason Molenda535ab862013-04-23 04:30:57 +00003546 }
Jason Molenda380241a2012-07-12 00:20:07 +00003547
3548 case 'n':
Jason Molenda535ab862013-04-23 04:30:57 +00003549 {
Jason Molenda380241a2012-07-12 00:20:07 +00003550 m_str = option_arg;
3551 m_type = eLookupTypeFunctionOrSymbol;
3552 break;
Jason Molenda535ab862013-04-23 04:30:57 +00003553 }
Michael Sartainb1e15922013-08-22 20:42:30 +00003554
3555 default:
3556 error.SetErrorStringWithFormat ("unrecognized option %c.", short_option);
3557 break;
Jason Molenda380241a2012-07-12 00:20:07 +00003558 }
3559
3560 return error;
3561 }
3562
3563 void
3564 OptionParsingStarting ()
3565 {
3566 m_type = eLookupTypeInvalid;
3567 m_str.clear();
3568 m_addr = LLDB_INVALID_ADDRESS;
3569 }
3570
3571 const OptionDefinition*
3572 GetDefinitions ()
3573 {
3574 return g_option_table;
3575 }
3576
3577 // Options table: Required for subclasses of Options.
3578
3579 static OptionDefinition g_option_table[];
3580
3581 // Instance variables to hold the values for command options.
3582
3583 int m_type; // Should be a eLookupTypeXXX enum after parsing options
3584 std::string m_str; // Holds name lookup
3585 lldb::addr_t m_addr; // Holds the address to lookup
3586 };
3587
3588 CommandObjectTargetModulesShowUnwind (CommandInterpreter &interpreter) :
3589 CommandObjectParsed (interpreter,
3590 "target modules show-unwind",
3591 "Show synthesized unwind instructions for a function.",
Greg Claytonf9fc6092013-01-09 19:44:40 +00003592 NULL,
3593 eFlagRequiresTarget |
3594 eFlagRequiresProcess |
3595 eFlagProcessMustBeLaunched |
3596 eFlagProcessMustBePaused ),
Jason Molenda380241a2012-07-12 00:20:07 +00003597 m_options (interpreter)
3598 {
3599 }
3600
3601 virtual
3602 ~CommandObjectTargetModulesShowUnwind ()
3603 {
3604 }
3605
3606 virtual
3607 Options *
3608 GetOptions ()
3609 {
3610 return &m_options;
3611 }
3612
3613protected:
3614 bool
3615 DoExecute (Args& command,
3616 CommandReturnObject &result)
3617 {
Greg Claytonf9fc6092013-01-09 19:44:40 +00003618 Target *target = m_exe_ctx.GetTargetPtr();
3619 Process *process = m_exe_ctx.GetProcessPtr();
Jason Molenda380241a2012-07-12 00:20:07 +00003620 ABI *abi = NULL;
3621 if (process)
3622 abi = process->GetABI().get();
3623
3624 if (process == NULL)
3625 {
3626 result.AppendError ("You must have a process running to use this command.");
3627 result.SetStatus (eReturnStatusFailed);
3628 return false;
3629 }
3630
3631 ThreadList threads(process->GetThreadList());
3632 if (threads.GetSize() == 0)
3633 {
3634 result.AppendError ("The process must be paused to use this command.");
3635 result.SetStatus (eReturnStatusFailed);
3636 return false;
3637 }
3638
3639 ThreadSP thread(threads.GetThreadAtIndex(0));
3640 if (thread.get() == NULL)
3641 {
3642 result.AppendError ("The process must be paused to use this command.");
3643 result.SetStatus (eReturnStatusFailed);
3644 return false;
3645 }
3646
Jason Molenda535ab862013-04-23 04:30:57 +00003647 SymbolContextList sc_list;
3648
Jason Molenda380241a2012-07-12 00:20:07 +00003649 if (m_options.m_type == eLookupTypeFunctionOrSymbol)
3650 {
Jason Molenda380241a2012-07-12 00:20:07 +00003651 ConstString function_name (m_options.m_str.c_str());
Jason Molenda535ab862013-04-23 04:30:57 +00003652 target->GetImages().FindFunctions (function_name, eFunctionNameTypeAuto, true, false, true, sc_list);
3653 }
3654 else if (m_options.m_type == eLookupTypeAddress && target)
3655 {
3656 Address addr;
3657 if (target->GetSectionLoadList().ResolveLoadAddress (m_options.m_addr, addr))
Jason Molenda380241a2012-07-12 00:20:07 +00003658 {
3659 SymbolContext sc;
Jason Molenda535ab862013-04-23 04:30:57 +00003660 ModuleSP module_sp (addr.GetModule());
3661 module_sp->ResolveSymbolContextForAddress (addr, eSymbolContextEverything, sc);
3662 if (sc.function || sc.symbol)
Jason Molenda380241a2012-07-12 00:20:07 +00003663 {
Jason Molenda535ab862013-04-23 04:30:57 +00003664 sc_list.Append(sc);
Jason Molenda380241a2012-07-12 00:20:07 +00003665 }
Jason Molenda535ab862013-04-23 04:30:57 +00003666 }
3667 }
Michael Sartainb1e15922013-08-22 20:42:30 +00003668 else
3669 {
3670 result.AppendError ("address-expression or function name option must be specified.");
3671 result.SetStatus (eReturnStatusFailed);
3672 return false;
3673 }
Jason Molenda380241a2012-07-12 00:20:07 +00003674
Jason Molenda535ab862013-04-23 04:30:57 +00003675 size_t num_matches = sc_list.GetSize();
Michael Sartainb1e15922013-08-22 20:42:30 +00003676 if (num_matches == 0)
3677 {
3678 result.AppendErrorWithFormat ("no unwind data found that matches '%s'.", m_options.m_str.c_str());
3679 result.SetStatus (eReturnStatusFailed);
3680 return false;
3681 }
3682
Jason Molenda535ab862013-04-23 04:30:57 +00003683 for (uint32_t idx = 0; idx < num_matches; idx++)
3684 {
3685 SymbolContext sc;
3686 sc_list.GetContextAtIndex(idx, sc);
3687 if (sc.symbol == NULL && sc.function == NULL)
3688 continue;
3689 if (sc.module_sp.get() == NULL || sc.module_sp->GetObjectFile() == NULL)
3690 continue;
3691 AddressRange range;
3692 if (!sc.GetAddressRange (eSymbolContextFunction | eSymbolContextSymbol, 0, false, range))
3693 continue;
3694 if (!range.GetBaseAddress().IsValid())
3695 continue;
3696 ConstString funcname(sc.GetFunctionName());
3697 if (funcname.IsEmpty())
3698 continue;
3699 addr_t start_addr = range.GetBaseAddress().GetLoadAddress(target);
3700 if (abi)
3701 start_addr = abi->FixCodeAddress(start_addr);
Jason Molenda380241a2012-07-12 00:20:07 +00003702
Jason Molenda535ab862013-04-23 04:30:57 +00003703 FuncUnwindersSP func_unwinders_sp (sc.module_sp->GetObjectFile()->GetUnwindTable().GetUncachedFuncUnwindersContainingAddress(start_addr, sc));
3704 if (func_unwinders_sp.get() == NULL)
3705 continue;
Jason Molenda380241a2012-07-12 00:20:07 +00003706
Jason Molenda535ab862013-04-23 04:30:57 +00003707 Address first_non_prologue_insn (func_unwinders_sp->GetFirstNonPrologueInsn(*target));
3708 if (first_non_prologue_insn.IsValid())
3709 {
3710 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 Molenda380241a2012-07-12 00:20:07 +00003711 result.GetOutputStream().Printf ("\n");
3712 }
Jason Molenda535ab862013-04-23 04:30:57 +00003713
3714 UnwindPlanSP non_callsite_unwind_plan = func_unwinders_sp->GetUnwindPlanAtNonCallSite(*thread.get());
3715 if (non_callsite_unwind_plan.get())
3716 {
3717 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);
3718 non_callsite_unwind_plan->Dump(result.GetOutputStream(), thread.get(), LLDB_INVALID_ADDRESS);
3719 result.GetOutputStream().Printf ("\n");
3720 }
3721
3722 UnwindPlanSP callsite_unwind_plan = func_unwinders_sp->GetUnwindPlanAtCallSite(-1);
3723 if (callsite_unwind_plan.get())
3724 {
3725 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);
3726 callsite_unwind_plan->Dump(result.GetOutputStream(), thread.get(), LLDB_INVALID_ADDRESS);
3727 result.GetOutputStream().Printf ("\n");
3728 }
3729
3730 UnwindPlanSP arch_default_unwind_plan = func_unwinders_sp->GetUnwindPlanArchitectureDefault(*thread.get());
3731 if (arch_default_unwind_plan.get())
3732 {
3733 result.GetOutputStream().Printf("Architecture default UnwindPlan for %s`%s (start addr 0x%" PRIx64 "):\n", sc.module_sp->GetPlatformFileSpec().GetFilename().AsCString(), funcname.AsCString(), start_addr);
3734 arch_default_unwind_plan->Dump(result.GetOutputStream(), thread.get(), LLDB_INVALID_ADDRESS);
3735 result.GetOutputStream().Printf ("\n");
3736 }
3737
3738 UnwindPlanSP fast_unwind_plan = func_unwinders_sp->GetUnwindPlanFastUnwind(*thread.get());
3739 if (fast_unwind_plan.get())
3740 {
3741 result.GetOutputStream().Printf("Fast UnwindPlan for %s`%s (start addr 0x%" PRIx64 "):\n", sc.module_sp->GetPlatformFileSpec().GetFilename().AsCString(), funcname.AsCString(), start_addr);
3742 fast_unwind_plan->Dump(result.GetOutputStream(), thread.get(), LLDB_INVALID_ADDRESS);
3743 result.GetOutputStream().Printf ("\n");
3744 }
3745
3746
3747 result.GetOutputStream().Printf ("\n");
Jason Molenda380241a2012-07-12 00:20:07 +00003748 }
3749 return result.Succeeded();
3750 }
3751
3752 CommandOptions m_options;
3753};
3754
3755OptionDefinition
3756CommandObjectTargetModulesShowUnwind::CommandOptions::g_option_table[] =
3757{
Virgile Belloe2607b52013-09-05 16:42:23 +00003758 { LLDB_OPT_SET_1, false, "name", 'n', OptionParser::eRequiredArgument, NULL, 0, eArgTypeFunctionName, "Show unwind instructions for a function or symbol name."},
3759 { LLDB_OPT_SET_2, false, "address", 'a', OptionParser::eRequiredArgument, NULL, 0, eArgTypeAddressOrExpression, "Show unwind instructions for a function or symbol containing an address"},
Jason Molenda380241a2012-07-12 00:20:07 +00003760 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
3761};
Greg Claytoneffe5c92011-05-03 22:09:39 +00003762
3763//----------------------------------------------------------------------
3764// Lookup information in images
3765//----------------------------------------------------------------------
Jim Ingham5a988412012-06-08 21:56:10 +00003766class CommandObjectTargetModulesLookup : public CommandObjectParsed
Greg Claytoneffe5c92011-05-03 22:09:39 +00003767{
3768public:
3769
3770 enum
3771 {
3772 eLookupTypeInvalid = -1,
3773 eLookupTypeAddress = 0,
3774 eLookupTypeSymbol,
3775 eLookupTypeFileLine, // Line is optional
3776 eLookupTypeFunction,
Greg Claytonc4a8a762012-05-15 18:43:44 +00003777 eLookupTypeFunctionOrSymbol,
Greg Claytoneffe5c92011-05-03 22:09:39 +00003778 eLookupTypeType,
3779 kNumLookupTypes
3780 };
3781
3782 class CommandOptions : public Options
3783 {
3784 public:
3785
3786 CommandOptions (CommandInterpreter &interpreter) :
3787 Options(interpreter)
3788 {
3789 OptionParsingStarting();
3790 }
3791
3792 virtual
3793 ~CommandOptions ()
3794 {
3795 }
3796
3797 virtual Error
3798 SetOptionValue (uint32_t option_idx, const char *option_arg)
3799 {
3800 Error error;
3801
Greg Clayton3bcdfc02012-12-04 00:32:51 +00003802 const int short_option = m_getopt_table[option_idx].val;
Greg Claytoneffe5c92011-05-03 22:09:39 +00003803
3804 switch (short_option)
3805 {
3806 case 'a':
Jim Inghame7b849e2013-03-15 23:09:19 +00003807 {
3808 m_type = eLookupTypeAddress;
3809 ExecutionContext exe_ctx (m_interpreter.GetExecutionContext());
3810 m_addr = Args::StringToAddress(&exe_ctx, option_arg, LLDB_INVALID_ADDRESS, &error);
3811 }
Greg Claytoneffe5c92011-05-03 22:09:39 +00003812 break;
3813
3814 case 'o':
3815 m_offset = Args::StringToUInt64(option_arg, LLDB_INVALID_ADDRESS);
3816 if (m_offset == LLDB_INVALID_ADDRESS)
Greg Clayton86edbf42011-10-26 00:56:27 +00003817 error.SetErrorStringWithFormat ("invalid offset string '%s'", option_arg);
Greg Claytoneffe5c92011-05-03 22:09:39 +00003818 break;
3819
3820 case 's':
3821 m_str = option_arg;
3822 m_type = eLookupTypeSymbol;
3823 break;
3824
3825 case 'f':
3826 m_file.SetFile (option_arg, false);
3827 m_type = eLookupTypeFileLine;
3828 break;
3829
3830 case 'i':
Sean Callanand4a7c122012-02-11 01:22:21 +00003831 m_include_inlines = false;
Greg Claytoneffe5c92011-05-03 22:09:39 +00003832 break;
3833
3834 case 'l':
3835 m_line_number = Args::StringToUInt32(option_arg, UINT32_MAX);
3836 if (m_line_number == UINT32_MAX)
Greg Clayton86edbf42011-10-26 00:56:27 +00003837 error.SetErrorStringWithFormat ("invalid line number string '%s'", option_arg);
Greg Claytoneffe5c92011-05-03 22:09:39 +00003838 else if (m_line_number == 0)
Greg Clayton86edbf42011-10-26 00:56:27 +00003839 error.SetErrorString ("zero is an invalid line number");
Greg Claytoneffe5c92011-05-03 22:09:39 +00003840 m_type = eLookupTypeFileLine;
3841 break;
3842
Greg Claytonc4a8a762012-05-15 18:43:44 +00003843 case 'F':
Greg Claytoneffe5c92011-05-03 22:09:39 +00003844 m_str = option_arg;
3845 m_type = eLookupTypeFunction;
3846 break;
Greg Claytonc4a8a762012-05-15 18:43:44 +00003847
3848 case 'n':
3849 m_str = option_arg;
3850 m_type = eLookupTypeFunctionOrSymbol;
3851 break;
3852
Greg Claytoneffe5c92011-05-03 22:09:39 +00003853 case 't':
3854 m_str = option_arg;
3855 m_type = eLookupTypeType;
3856 break;
3857
3858 case 'v':
3859 m_verbose = 1;
3860 break;
Sean Callanand38b4a92012-06-06 20:49:55 +00003861
3862 case 'A':
3863 m_print_all = true;
3864 break;
Greg Claytoneffe5c92011-05-03 22:09:39 +00003865
3866 case 'r':
3867 m_use_regex = true;
3868 break;
3869 }
3870
3871 return error;
3872 }
3873
3874 void
3875 OptionParsingStarting ()
3876 {
3877 m_type = eLookupTypeInvalid;
3878 m_str.clear();
3879 m_file.Clear();
3880 m_addr = LLDB_INVALID_ADDRESS;
3881 m_offset = 0;
3882 m_line_number = 0;
3883 m_use_regex = false;
Sean Callanand4a7c122012-02-11 01:22:21 +00003884 m_include_inlines = true;
Greg Claytoneffe5c92011-05-03 22:09:39 +00003885 m_verbose = false;
Sean Callanand38b4a92012-06-06 20:49:55 +00003886 m_print_all = false;
Greg Claytoneffe5c92011-05-03 22:09:39 +00003887 }
3888
3889 const OptionDefinition*
3890 GetDefinitions ()
3891 {
3892 return g_option_table;
3893 }
3894
3895 // Options table: Required for subclasses of Options.
3896
3897 static OptionDefinition g_option_table[];
3898 int m_type; // Should be a eLookupTypeXXX enum after parsing options
3899 std::string m_str; // Holds name lookup
3900 FileSpec m_file; // Files for file lookups
3901 lldb::addr_t m_addr; // Holds the address to lookup
3902 lldb::addr_t m_offset; // Subtract this offset from m_addr before doing lookups.
3903 uint32_t m_line_number; // Line number for file+line lookups
3904 bool m_use_regex; // Name lookups in m_str are regular expressions.
Sean Callanand4a7c122012-02-11 01:22:21 +00003905 bool m_include_inlines;// Check for inline entries when looking up by file/line.
Greg Claytoneffe5c92011-05-03 22:09:39 +00003906 bool m_verbose; // Enable verbose lookup info
Sean Callanand38b4a92012-06-06 20:49:55 +00003907 bool m_print_all; // Print all matches, even in cases where there's a best match.
Greg Claytoneffe5c92011-05-03 22:09:39 +00003908
3909 };
3910
3911 CommandObjectTargetModulesLookup (CommandInterpreter &interpreter) :
Jim Ingham5a988412012-06-08 21:56:10 +00003912 CommandObjectParsed (interpreter,
3913 "target modules lookup",
3914 "Look up information within executable and dependent shared library images.",
Greg Claytonf9fc6092013-01-09 19:44:40 +00003915 NULL,
3916 eFlagRequiresTarget),
Jim Ingham5a988412012-06-08 21:56:10 +00003917 m_options (interpreter)
Greg Claytoneffe5c92011-05-03 22:09:39 +00003918 {
3919 CommandArgumentEntry arg;
3920 CommandArgumentData file_arg;
3921
3922 // Define the first (and only) variant of this arg.
3923 file_arg.arg_type = eArgTypeFilename;
3924 file_arg.arg_repetition = eArgRepeatStar;
3925
3926 // There is only one variant this argument could be; put it into the argument entry.
3927 arg.push_back (file_arg);
3928
3929 // Push the data for the first argument into the m_arguments vector.
3930 m_arguments.push_back (arg);
3931 }
3932
3933 virtual
3934 ~CommandObjectTargetModulesLookup ()
3935 {
3936 }
3937
3938 virtual Options *
3939 GetOptions ()
3940 {
3941 return &m_options;
3942 }
3943
Sean Callanand38b4a92012-06-06 20:49:55 +00003944 bool
3945 LookupHere (CommandInterpreter &interpreter, CommandReturnObject &result, bool &syntax_error)
3946 {
3947 switch (m_options.m_type)
3948 {
3949 case eLookupTypeAddress:
3950 case eLookupTypeFileLine:
3951 case eLookupTypeFunction:
3952 case eLookupTypeFunctionOrSymbol:
3953 case eLookupTypeSymbol:
3954 default:
3955 return false;
3956 case eLookupTypeType:
3957 break;
3958 }
3959
Jason Molendab57e4a12013-11-04 09:33:30 +00003960 StackFrameSP frame = m_exe_ctx.GetFrameSP();
Sean Callanand38b4a92012-06-06 20:49:55 +00003961
3962 if (!frame)
3963 return false;
3964
3965 const SymbolContext &sym_ctx(frame->GetSymbolContext(eSymbolContextModule));
3966
3967 if (!sym_ctx.module_sp)
3968 return false;
3969
3970 switch (m_options.m_type)
3971 {
3972 default:
3973 return false;
3974 case eLookupTypeType:
3975 if (!m_options.m_str.empty())
3976 {
3977 if (LookupTypeHere (m_interpreter,
3978 result.GetOutputStream(),
3979 sym_ctx,
3980 m_options.m_str.c_str(),
3981 m_options.m_use_regex))
3982 {
3983 result.SetStatus(eReturnStatusSuccessFinishResult);
3984 return true;
3985 }
3986 }
3987 break;
3988 }
3989
3990 return true;
3991 }
Greg Claytoneffe5c92011-05-03 22:09:39 +00003992
3993 bool
3994 LookupInModule (CommandInterpreter &interpreter, Module *module, CommandReturnObject &result, bool &syntax_error)
3995 {
3996 switch (m_options.m_type)
3997 {
3998 case eLookupTypeAddress:
3999 if (m_options.m_addr != LLDB_INVALID_ADDRESS)
4000 {
4001 if (LookupAddressInModule (m_interpreter,
4002 result.GetOutputStream(),
4003 module,
4004 eSymbolContextEverything,
4005 m_options.m_addr,
4006 m_options.m_offset,
4007 m_options.m_verbose))
4008 {
4009 result.SetStatus(eReturnStatusSuccessFinishResult);
4010 return true;
4011 }
4012 }
4013 break;
4014
4015 case eLookupTypeSymbol:
4016 if (!m_options.m_str.empty())
4017 {
Greg Claytonc4a8a762012-05-15 18:43:44 +00004018 if (LookupSymbolInModule (m_interpreter,
4019 result.GetOutputStream(),
4020 module,
4021 m_options.m_str.c_str(),
4022 m_options.m_use_regex,
4023 m_options.m_verbose))
Greg Claytoneffe5c92011-05-03 22:09:39 +00004024 {
4025 result.SetStatus(eReturnStatusSuccessFinishResult);
4026 return true;
4027 }
4028 }
4029 break;
4030
4031 case eLookupTypeFileLine:
4032 if (m_options.m_file)
4033 {
4034
4035 if (LookupFileAndLineInModule (m_interpreter,
4036 result.GetOutputStream(),
4037 module,
4038 m_options.m_file,
4039 m_options.m_line_number,
Sean Callanand4a7c122012-02-11 01:22:21 +00004040 m_options.m_include_inlines,
Greg Claytoneffe5c92011-05-03 22:09:39 +00004041 m_options.m_verbose))
4042 {
4043 result.SetStatus(eReturnStatusSuccessFinishResult);
4044 return true;
4045 }
4046 }
4047 break;
Greg Claytonc4a8a762012-05-15 18:43:44 +00004048
4049 case eLookupTypeFunctionOrSymbol:
Greg Claytoneffe5c92011-05-03 22:09:39 +00004050 case eLookupTypeFunction:
4051 if (!m_options.m_str.empty())
4052 {
4053 if (LookupFunctionInModule (m_interpreter,
4054 result.GetOutputStream(),
4055 module,
4056 m_options.m_str.c_str(),
4057 m_options.m_use_regex,
Sean Callanand4a7c122012-02-11 01:22:21 +00004058 m_options.m_include_inlines,
Greg Claytonc4a8a762012-05-15 18:43:44 +00004059 m_options.m_type == eLookupTypeFunctionOrSymbol, // include symbols
Greg Claytoneffe5c92011-05-03 22:09:39 +00004060 m_options.m_verbose))
4061 {
4062 result.SetStatus(eReturnStatusSuccessFinishResult);
4063 return true;
4064 }
4065 }
4066 break;
4067
Greg Claytonc4a8a762012-05-15 18:43:44 +00004068
Greg Claytoneffe5c92011-05-03 22:09:39 +00004069 case eLookupTypeType:
4070 if (!m_options.m_str.empty())
4071 {
4072 if (LookupTypeInModule (m_interpreter,
4073 result.GetOutputStream(),
4074 module,
4075 m_options.m_str.c_str(),
4076 m_options.m_use_regex))
4077 {
4078 result.SetStatus(eReturnStatusSuccessFinishResult);
4079 return true;
4080 }
4081 }
4082 break;
4083
4084 default:
4085 m_options.GenerateOptionUsage (result.GetErrorStream(), this);
4086 syntax_error = true;
4087 break;
4088 }
4089
4090 result.SetStatus (eReturnStatusFailed);
4091 return false;
4092 }
4093
Jim Ingham5a988412012-06-08 21:56:10 +00004094protected:
Greg Claytoneffe5c92011-05-03 22:09:39 +00004095 virtual bool
Jim Ingham5a988412012-06-08 21:56:10 +00004096 DoExecute (Args& command,
Greg Claytoneffe5c92011-05-03 22:09:39 +00004097 CommandReturnObject &result)
4098 {
4099 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
4100 if (target == NULL)
4101 {
4102 result.AppendError ("invalid target, create a debug target using the 'target create' command");
4103 result.SetStatus (eReturnStatusFailed);
4104 return false;
4105 }
4106 else
4107 {
4108 bool syntax_error = false;
4109 uint32_t i;
4110 uint32_t num_successful_lookups = 0;
4111 uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize();
4112 result.GetOutputStream().SetAddressByteSize(addr_byte_size);
4113 result.GetErrorStream().SetAddressByteSize(addr_byte_size);
4114 // Dump all sections for all modules images
4115
4116 if (command.GetArgumentCount() == 0)
4117 {
Sean Callanand38b4a92012-06-06 20:49:55 +00004118 ModuleSP current_module;
4119
4120 // Where it is possible to look in the current symbol context
4121 // first, try that. If this search was successful and --all
4122 // was not passed, don't print anything else.
4123 if (LookupHere (m_interpreter, result, syntax_error))
4124 {
4125 result.GetOutputStream().EOL();
4126 num_successful_lookups++;
4127 if (!m_options.m_print_all)
4128 {
4129 result.SetStatus (eReturnStatusSuccessFinishResult);
4130 return result.Succeeded();
4131 }
4132 }
4133
4134 // Dump all sections for all other modules
4135
Enrico Granata17598482012-11-08 02:22:02 +00004136 const ModuleList &target_modules = target->GetImages();
Jim Ingham3ee12ef2012-05-30 02:19:25 +00004137 Mutex::Locker modules_locker(target_modules.GetMutex());
Greg Claytonc7bece562013-01-25 18:06:21 +00004138 const size_t num_modules = target_modules.GetSize();
Greg Claytoneffe5c92011-05-03 22:09:39 +00004139 if (num_modules > 0)
4140 {
4141 for (i = 0; i<num_modules && syntax_error == false; ++i)
4142 {
Sean Callanand38b4a92012-06-06 20:49:55 +00004143 Module *module_pointer = target_modules.GetModulePointerAtIndexUnlocked(i);
4144
4145 if (module_pointer != current_module.get() &&
4146 LookupInModule (m_interpreter, target_modules.GetModulePointerAtIndexUnlocked(i), result, syntax_error))
Greg Claytoneffe5c92011-05-03 22:09:39 +00004147 {
4148 result.GetOutputStream().EOL();
4149 num_successful_lookups++;
4150 }
4151 }
4152 }
4153 else
4154 {
4155 result.AppendError ("the target has no associated executable images");
4156 result.SetStatus (eReturnStatusFailed);
4157 return false;
4158 }
4159 }
4160 else
4161 {
4162 // Dump specified images (by basename or fullpath)
4163 const char *arg_cstr;
4164 for (i = 0; (arg_cstr = command.GetArgumentAtIndex(i)) != NULL && syntax_error == false; ++i)
4165 {
Greg Clayton8ee64382011-11-10 01:18:58 +00004166 ModuleList module_list;
4167 const size_t num_matches = FindModulesByName (target, arg_cstr, module_list, false);
4168 if (num_matches > 0)
Greg Claytoneffe5c92011-05-03 22:09:39 +00004169 {
Jason Molendaccd41e52012-10-04 22:47:07 +00004170 for (size_t j=0; j<num_matches; ++j)
Greg Claytoneffe5c92011-05-03 22:09:39 +00004171 {
Jason Molendaccd41e52012-10-04 22:47:07 +00004172 Module *module = module_list.GetModulePointerAtIndex(j);
Greg Clayton8ee64382011-11-10 01:18:58 +00004173 if (module)
Greg Claytoneffe5c92011-05-03 22:09:39 +00004174 {
Greg Clayton8ee64382011-11-10 01:18:58 +00004175 if (LookupInModule (m_interpreter, module, result, syntax_error))
Greg Claytoneffe5c92011-05-03 22:09:39 +00004176 {
4177 result.GetOutputStream().EOL();
4178 num_successful_lookups++;
4179 }
4180 }
4181 }
4182 }
4183 else
4184 result.AppendWarningWithFormat("Unable to find an image that matches '%s'.\n", arg_cstr);
4185 }
4186 }
4187
4188 if (num_successful_lookups > 0)
4189 result.SetStatus (eReturnStatusSuccessFinishResult);
4190 else
4191 result.SetStatus (eReturnStatusFailed);
4192 }
4193 return result.Succeeded();
4194 }
Greg Claytoneffe5c92011-05-03 22:09:39 +00004195
4196 CommandOptions m_options;
4197};
4198
4199OptionDefinition
4200CommandObjectTargetModulesLookup::CommandOptions::g_option_table[] =
4201{
Virgile Belloe2607b52013-09-05 16:42:23 +00004202 { LLDB_OPT_SET_1, true, "address", 'a', OptionParser::eRequiredArgument, NULL, 0, eArgTypeAddressOrExpression, "Lookup an address in one or more target modules."},
4203 { LLDB_OPT_SET_1, false, "offset", 'o', OptionParser::eRequiredArgument, NULL, 0, eArgTypeOffset, "When looking up an address subtract <offset> from any addresses before doing the lookup."},
Greg Claytonc4a8a762012-05-15 18:43:44 +00004204 { LLDB_OPT_SET_2| LLDB_OPT_SET_4 | LLDB_OPT_SET_5
4205 /* FIXME: re-enable this for types when the LookupTypeInModule actually uses the regex option: | LLDB_OPT_SET_6 */ ,
Virgile Belloe2607b52013-09-05 16:42:23 +00004206 false, "regex", 'r', OptionParser::eNoArgument, NULL, 0, eArgTypeNone, "The <name> argument for name lookups are regular expressions."},
4207 { LLDB_OPT_SET_2, true, "symbol", 's', OptionParser::eRequiredArgument, NULL, 0, eArgTypeSymbol, "Lookup a symbol by name in the symbol tables in one or more target modules."},
4208 { LLDB_OPT_SET_3, true, "file", 'f', OptionParser::eRequiredArgument, NULL, 0, eArgTypeFilename, "Lookup a file by fullpath or basename in one or more target modules."},
4209 { LLDB_OPT_SET_3, false, "line", 'l', OptionParser::eRequiredArgument, NULL, 0, eArgTypeLineNum, "Lookup a line number in a file (must be used in conjunction with --file)."},
Jim Inghama8f55662012-06-04 22:47:34 +00004210 { LLDB_OPT_SET_FROM_TO(3,5),
Virgile Belloe2607b52013-09-05 16:42:23 +00004211 false, "no-inlines", 'i', OptionParser::eNoArgument, NULL, 0, eArgTypeNone, "Ignore inline entries (must be used in conjunction with --file or --function)."},
4212 { LLDB_OPT_SET_4, true, "function", 'F', OptionParser::eRequiredArgument, NULL, 0, eArgTypeFunctionName, "Lookup a function by name in the debug symbols in one or more target modules."},
4213 { LLDB_OPT_SET_5, true, "name", 'n', OptionParser::eRequiredArgument, NULL, 0, eArgTypeFunctionOrSymbol, "Lookup a function or symbol by name in one or more target modules."},
4214 { LLDB_OPT_SET_6, true, "type", 't', OptionParser::eRequiredArgument, NULL, 0, eArgTypeName, "Lookup a type by name in the debug symbols in one or more target modules."},
4215 { LLDB_OPT_SET_ALL, false, "verbose", 'v', OptionParser::eNoArgument, NULL, 0, eArgTypeNone, "Enable verbose lookup information."},
4216 { LLDB_OPT_SET_ALL, false, "all", 'A', OptionParser::eNoArgument, NULL, 0, eArgTypeNone, "Print all matches, not just the best match, if a best match is available."},
Sean Callanancd8b7cd2012-09-13 21:11:40 +00004217 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
Greg Claytoneffe5c92011-05-03 22:09:39 +00004218};
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004219
4220
Jim Ingham9575d842011-03-11 03:53:59 +00004221#pragma mark CommandObjectMultiwordImageSearchPaths
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004222
4223//-------------------------------------------------------------------------
4224// CommandObjectMultiwordImageSearchPaths
4225//-------------------------------------------------------------------------
4226
Greg Claytoneffe5c92011-05-03 22:09:39 +00004227class CommandObjectTargetModulesImageSearchPaths : public CommandObjectMultiword
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004228{
4229public:
Greg Claytoneffe5c92011-05-03 22:09:39 +00004230
4231 CommandObjectTargetModulesImageSearchPaths (CommandInterpreter &interpreter) :
4232 CommandObjectMultiword (interpreter,
4233 "target modules search-paths",
4234 "A set of commands for operating on debugger target image search paths.",
4235 "target modules search-paths <subcommand> [<subcommand-options>]")
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004236 {
Greg Claytoneffe5c92011-05-03 22:09:39 +00004237 LoadSubCommand ("add", CommandObjectSP (new CommandObjectTargetModulesSearchPathsAdd (interpreter)));
4238 LoadSubCommand ("clear", CommandObjectSP (new CommandObjectTargetModulesSearchPathsClear (interpreter)));
4239 LoadSubCommand ("insert", CommandObjectSP (new CommandObjectTargetModulesSearchPathsInsert (interpreter)));
4240 LoadSubCommand ("list", CommandObjectSP (new CommandObjectTargetModulesSearchPathsList (interpreter)));
4241 LoadSubCommand ("query", CommandObjectSP (new CommandObjectTargetModulesSearchPathsQuery (interpreter)));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004242 }
Greg Claytoneffe5c92011-05-03 22:09:39 +00004243
4244 ~CommandObjectTargetModulesImageSearchPaths()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004245 {
4246 }
4247};
4248
Greg Claytoneffe5c92011-05-03 22:09:39 +00004249
4250
4251#pragma mark CommandObjectTargetModules
4252
4253//-------------------------------------------------------------------------
4254// CommandObjectTargetModules
4255//-------------------------------------------------------------------------
4256
4257class CommandObjectTargetModules : public CommandObjectMultiword
4258{
4259public:
4260 //------------------------------------------------------------------
4261 // Constructors and Destructors
4262 //------------------------------------------------------------------
4263 CommandObjectTargetModules(CommandInterpreter &interpreter) :
4264 CommandObjectMultiword (interpreter,
4265 "target modules",
4266 "A set of commands for accessing information for one or more target modules.",
4267 "target modules <sub-command> ...")
4268 {
4269 LoadSubCommand ("add", CommandObjectSP (new CommandObjectTargetModulesAdd (interpreter)));
4270 LoadSubCommand ("load", CommandObjectSP (new CommandObjectTargetModulesLoad (interpreter)));
Greg Claytoneffe5c92011-05-03 22:09:39 +00004271 LoadSubCommand ("dump", CommandObjectSP (new CommandObjectTargetModulesDump (interpreter)));
4272 LoadSubCommand ("list", CommandObjectSP (new CommandObjectTargetModulesList (interpreter)));
4273 LoadSubCommand ("lookup", CommandObjectSP (new CommandObjectTargetModulesLookup (interpreter)));
4274 LoadSubCommand ("search-paths", CommandObjectSP (new CommandObjectTargetModulesImageSearchPaths (interpreter)));
Jason Molenda380241a2012-07-12 00:20:07 +00004275 LoadSubCommand ("show-unwind", CommandObjectSP (new CommandObjectTargetModulesShowUnwind (interpreter)));
Greg Claytoneffe5c92011-05-03 22:09:39 +00004276
4277 }
4278 virtual
4279 ~CommandObjectTargetModules()
4280 {
4281 }
4282
4283private:
4284 //------------------------------------------------------------------
4285 // For CommandObjectTargetModules only
4286 //------------------------------------------------------------------
4287 DISALLOW_COPY_AND_ASSIGN (CommandObjectTargetModules);
4288};
4289
4290
Greg Claytone72dfb32012-02-24 01:59:29 +00004291
Jim Ingham5a988412012-06-08 21:56:10 +00004292class CommandObjectTargetSymbolsAdd : public CommandObjectParsed
Greg Claytone72dfb32012-02-24 01:59:29 +00004293{
4294public:
4295 CommandObjectTargetSymbolsAdd (CommandInterpreter &interpreter) :
Jim Ingham5a988412012-06-08 21:56:10 +00004296 CommandObjectParsed (interpreter,
4297 "target symbols add",
Greg Claytonb5f0fea2012-09-27 22:26:11 +00004298 "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.",
Jason Molendab9c9f9b2013-02-02 06:00:36 +00004299 "target symbols add [<symfile>]", eFlagRequiresTarget),
Greg Claytonb5f0fea2012-09-27 22:26:11 +00004300 m_option_group (interpreter),
4301 m_file_option (LLDB_OPT_SET_1, false, "shlib", 's', CommandCompletions::eModuleCompletion, eArgTypeShlibName, "Fullpath or basename for module to find debug symbols for."),
4302 m_current_frame_option (LLDB_OPT_SET_2, false, "frame", 'F', "Locate the debug symbols the currently selected frame.", false, true)
4303
Greg Claytone72dfb32012-02-24 01:59:29 +00004304 {
Greg Claytonb5f0fea2012-09-27 22:26:11 +00004305 m_option_group.Append (&m_uuid_option_group, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
4306 m_option_group.Append (&m_file_option, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
4307 m_option_group.Append (&m_current_frame_option, LLDB_OPT_SET_2, LLDB_OPT_SET_2);
4308 m_option_group.Finalize();
Greg Claytone72dfb32012-02-24 01:59:29 +00004309 }
4310
4311 virtual
4312 ~CommandObjectTargetSymbolsAdd ()
4313 {
4314 }
4315
Greg Claytonc7bece562013-01-25 18:06:21 +00004316 virtual int
Jim Ingham5a988412012-06-08 21:56:10 +00004317 HandleArgumentCompletion (Args &input,
4318 int &cursor_index,
4319 int &cursor_char_position,
4320 OptionElementVector &opt_element_vector,
4321 int match_start_point,
4322 int max_return_elements,
4323 bool &word_complete,
4324 StringList &matches)
4325 {
4326 std::string completion_str (input.GetArgumentAtIndex(cursor_index));
4327 completion_str.erase (cursor_char_position);
4328
4329 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
4330 CommandCompletions::eDiskFileCompletion,
4331 completion_str.c_str(),
4332 match_start_point,
4333 max_return_elements,
4334 NULL,
4335 word_complete,
4336 matches);
4337 return matches.GetSize();
4338 }
4339
Greg Claytonb5f0fea2012-09-27 22:26:11 +00004340 virtual Options *
4341 GetOptions ()
4342 {
4343 return &m_option_group;
4344 }
4345
4346
Jim Ingham5a988412012-06-08 21:56:10 +00004347protected:
Greg Claytonb5f0fea2012-09-27 22:26:11 +00004348
4349 bool
4350 AddModuleSymbols (Target *target,
Greg Clayton89deb062012-12-12 01:15:30 +00004351 ModuleSpec &module_spec,
Greg Claytonb5f0fea2012-09-27 22:26:11 +00004352 bool &flush,
4353 CommandReturnObject &result)
4354 {
Greg Clayton89deb062012-12-12 01:15:30 +00004355 const FileSpec &symbol_fspec = module_spec.GetSymbolFileSpec();
4356 if (symbol_fspec)
Greg Claytonb5f0fea2012-09-27 22:26:11 +00004357 {
4358 char symfile_path[PATH_MAX];
Greg Clayton89deb062012-12-12 01:15:30 +00004359 symbol_fspec.GetPath (symfile_path, sizeof(symfile_path));
4360
4361 if (!module_spec.GetUUID().IsValid())
4362 {
4363 if (!module_spec.GetFileSpec() && !module_spec.GetPlatformFileSpec())
4364 module_spec.GetFileSpec().GetFilename() = symbol_fspec.GetFilename();
4365 }
Greg Claytonb5f0fea2012-09-27 22:26:11 +00004366 // We now have a module that represents a symbol file
4367 // that can be used for a module that might exist in the
4368 // current target, so we need to find that module in the
4369 // target
Greg Clayton89deb062012-12-12 01:15:30 +00004370 ModuleList matching_module_list;
Greg Clayton9aae0a12013-05-15 19:52:08 +00004371
4372 size_t num_matches = 0;
4373 // First extract all module specs from the symbol file
4374 lldb_private::ModuleSpecList symfile_module_specs;
Greg Clayton2540a8a2013-07-12 22:07:46 +00004375 if (ObjectFile::GetModuleSpecifications(module_spec.GetSymbolFileSpec(), 0, 0, symfile_module_specs))
Greg Clayton9aae0a12013-05-15 19:52:08 +00004376 {
4377 // Now extract the module spec that matches the target architecture
4378 ModuleSpec target_arch_module_spec;
4379 ModuleSpec symfile_module_spec;
4380 target_arch_module_spec.GetArchitecture() = target->GetArchitecture();
4381 if (symfile_module_specs.FindMatchingModuleSpec(target_arch_module_spec, symfile_module_spec))
4382 {
4383 // See if it has a UUID?
4384 if (symfile_module_spec.GetUUID().IsValid())
4385 {
4386 // It has a UUID, look for this UUID in the target modules
4387 ModuleSpec symfile_uuid_module_spec;
4388 symfile_uuid_module_spec.GetUUID() = symfile_module_spec.GetUUID();
4389 num_matches = target->GetImages().FindModules (symfile_uuid_module_spec, matching_module_list);
4390 }
4391 }
4392
4393 if (num_matches == 0)
4394 {
4395 // No matches yet, iterate through the module specs to find a UUID value that
4396 // we can match up to an image in our target
4397 const size_t num_symfile_module_specs = symfile_module_specs.GetSize();
4398 for (size_t i=0; i<num_symfile_module_specs && num_matches == 0; ++i)
4399 {
4400 if (symfile_module_specs.GetModuleSpecAtIndex(i, symfile_module_spec))
4401 {
4402 if (symfile_module_spec.GetUUID().IsValid())
4403 {
4404 // It has a UUID, look for this UUID in the target modules
4405 ModuleSpec symfile_uuid_module_spec;
4406 symfile_uuid_module_spec.GetUUID() = symfile_module_spec.GetUUID();
4407 num_matches = target->GetImages().FindModules (symfile_uuid_module_spec, matching_module_list);
4408 }
4409 }
4410 }
4411 }
4412 }
4413
4414 // Just try to match up the file by basename if we have no matches at this point
4415 if (num_matches == 0)
4416 num_matches = target->GetImages().FindModules (module_spec, matching_module_list);
4417
Greg Clayton91c0e742013-01-11 23:44:27 +00004418 while (num_matches == 0)
4419 {
4420 ConstString filename_no_extension(module_spec.GetFileSpec().GetFileNameStrippingExtension());
4421 // Empty string returned, lets bail
4422 if (!filename_no_extension)
4423 break;
4424
4425 // Check if there was no extension to strip and the basename is the same
4426 if (filename_no_extension == module_spec.GetFileSpec().GetFilename())
4427 break;
4428
4429 // Replace basename with one less extension
4430 module_spec.GetFileSpec().GetFilename() = filename_no_extension;
4431
4432 num_matches = target->GetImages().FindModules (module_spec, matching_module_list);
Greg Clayton9aae0a12013-05-15 19:52:08 +00004433
Greg Clayton91c0e742013-01-11 23:44:27 +00004434 }
4435
Greg Clayton89deb062012-12-12 01:15:30 +00004436 if (num_matches > 1)
Greg Claytonb5f0fea2012-09-27 22:26:11 +00004437 {
Greg Clayton89deb062012-12-12 01:15:30 +00004438 result.AppendErrorWithFormat ("multiple modules match symbol file '%s', use the --uuid option to resolve the ambiguity.\n", symfile_path);
4439 }
4440 else if (num_matches == 1)
4441 {
4442 ModuleSP module_sp (matching_module_list.GetModuleAtIndex(0));
4443
Greg Claytonb5f0fea2012-09-27 22:26:11 +00004444 // The module has not yet created its symbol vendor, we can just
4445 // give the existing target module the symfile path to use for
4446 // when it decides to create it!
Greg Clayton89deb062012-12-12 01:15:30 +00004447 module_sp->SetSymbolFileFileSpec (symbol_fspec);
Greg Claytonb5f0fea2012-09-27 22:26:11 +00004448
Greg Clayton136dff82012-12-14 02:15:00 +00004449 SymbolVendor *symbol_vendor = module_sp->GetSymbolVendor(true, &result.GetErrorStream());
Greg Clayton89deb062012-12-12 01:15:30 +00004450 if (symbol_vendor)
4451 {
4452 SymbolFile *symbol_file = symbol_vendor->GetSymbolFile();
4453
4454 if (symbol_file)
4455 {
4456 ObjectFile *object_file = symbol_file->GetObjectFile();
4457
4458 if (object_file && object_file->GetFileSpec() == symbol_fspec)
4459 {
4460 // Provide feedback that the symfile has been successfully added.
4461 const FileSpec &module_fs = module_sp->GetFileSpec();
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00004462 result.AppendMessageWithFormat("symbol file '%s' has been added to '%s'\n",
Greg Clayton89deb062012-12-12 01:15:30 +00004463 symfile_path,
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00004464 module_fs.GetPath().c_str());
Greg Clayton89deb062012-12-12 01:15:30 +00004465
4466 // Let clients know something changed in the module
4467 // if it is currently loaded
4468 ModuleList module_list;
4469 module_list.Append (module_sp);
Enrico Granataf15ee4e2013-04-05 18:49:06 +00004470 target->SymbolsDidLoad (module_list);
Greg Clayton91c0e742013-01-11 23:44:27 +00004471
4472 // Make sure we load any scripting resources that may be embedded
4473 // in the debug info files in case the platform supports that.
4474 Error error;
Enrico Granata97303392013-05-21 00:00:30 +00004475 StreamString feedback_stream;
4476 module_sp->LoadScriptingResourceInTarget (target, error,&feedback_stream);
Enrico Granatacaa84cb2013-05-20 22:40:54 +00004477 if (error.Fail() && error.AsCString())
Enrico Granata2ea43cd2013-05-13 17:03:52 +00004478 result.AppendWarningWithFormat("unable to load scripting data for module %s - error reported was %s",
4479 module_sp->GetFileSpec().GetFileNameStrippingExtension().GetCString(),
4480 error.AsCString());
Enrico Granata97303392013-05-21 00:00:30 +00004481 else if (feedback_stream.GetSize())
4482 result.AppendWarningWithFormat("%s",feedback_stream.GetData());
Greg Clayton91c0e742013-01-11 23:44:27 +00004483
Greg Clayton89deb062012-12-12 01:15:30 +00004484 flush = true;
4485 result.SetStatus (eReturnStatusSuccessFinishResult);
4486 return true;
4487 }
4488 }
4489 }
4490 // Clear the symbol file spec if anything went wrong
4491 module_sp->SetSymbolFileFileSpec (FileSpec());
Greg Clayton89deb062012-12-12 01:15:30 +00004492 }
4493
4494 if (module_spec.GetUUID().IsValid())
4495 {
4496 StreamString ss_symfile_uuid;
4497 module_spec.GetUUID().Dump(&ss_symfile_uuid);
4498 result.AppendErrorWithFormat ("symbol file '%s' (%s) does not match any existing module%s\n",
4499 symfile_path,
4500 ss_symfile_uuid.GetData(),
4501 (symbol_fspec.GetFileType() != FileSpec::eFileTypeRegular)
4502 ? "\n please specify the full path to the symbol file"
4503 : "");
Greg Claytonb5f0fea2012-09-27 22:26:11 +00004504 }
4505 else
4506 {
Greg Clayton89deb062012-12-12 01:15:30 +00004507 result.AppendErrorWithFormat ("symbol file '%s' does not match any existing module%s\n",
4508 symfile_path,
4509 (symbol_fspec.GetFileType() != FileSpec::eFileTypeRegular)
4510 ? "\n please specify the full path to the symbol file"
4511 : "");
Greg Claytonb5f0fea2012-09-27 22:26:11 +00004512 }
4513 }
4514 else
4515 {
4516 result.AppendError ("one or more executable image paths must be specified");
Greg Claytonb5f0fea2012-09-27 22:26:11 +00004517 }
Greg Clayton89deb062012-12-12 01:15:30 +00004518 result.SetStatus (eReturnStatusFailed);
4519 return false;
Greg Claytonb5f0fea2012-09-27 22:26:11 +00004520 }
4521
Greg Claytone72dfb32012-02-24 01:59:29 +00004522 virtual bool
Jim Ingham5a988412012-06-08 21:56:10 +00004523 DoExecute (Args& args,
Greg Claytone72dfb32012-02-24 01:59:29 +00004524 CommandReturnObject &result)
4525 {
Greg Claytonf9fc6092013-01-09 19:44:40 +00004526 Target *target = m_exe_ctx.GetTargetPtr();
Greg Claytonb5f0fea2012-09-27 22:26:11 +00004527 result.SetStatus (eReturnStatusFailed);
Greg Claytonf9fc6092013-01-09 19:44:40 +00004528 bool flush = false;
4529 ModuleSpec module_spec;
4530 const bool uuid_option_set = m_uuid_option_group.GetOptionValue().OptionWasSet();
4531 const bool file_option_set = m_file_option.GetOptionValue().OptionWasSet();
4532 const bool frame_option_set = m_current_frame_option.GetOptionValue().OptionWasSet();
Greg Claytonb5f0fea2012-09-27 22:26:11 +00004533
Greg Claytonf9fc6092013-01-09 19:44:40 +00004534 const size_t argc = args.GetArgumentCount();
4535 if (argc == 0)
4536 {
4537 if (uuid_option_set || file_option_set || frame_option_set)
Greg Claytone72dfb32012-02-24 01:59:29 +00004538 {
Greg Claytonf9fc6092013-01-09 19:44:40 +00004539 bool success = false;
4540 bool error_set = false;
4541 if (frame_option_set)
Greg Claytone72dfb32012-02-24 01:59:29 +00004542 {
Greg Claytonf9fc6092013-01-09 19:44:40 +00004543 Process *process = m_exe_ctx.GetProcessPtr();
4544 if (process)
Greg Claytone72dfb32012-02-24 01:59:29 +00004545 {
Greg Claytonf9fc6092013-01-09 19:44:40 +00004546 const StateType process_state = process->GetState();
4547 if (StateIsStoppedState (process_state, true))
Greg Claytone72dfb32012-02-24 01:59:29 +00004548 {
Jason Molendab57e4a12013-11-04 09:33:30 +00004549 StackFrame *frame = m_exe_ctx.GetFramePtr();
Greg Claytonf9fc6092013-01-09 19:44:40 +00004550 if (frame)
Greg Claytone72dfb32012-02-24 01:59:29 +00004551 {
Greg Claytonf9fc6092013-01-09 19:44:40 +00004552 ModuleSP frame_module_sp (frame->GetSymbolContext(eSymbolContextModule).module_sp);
4553 if (frame_module_sp)
Greg Claytone72dfb32012-02-24 01:59:29 +00004554 {
Greg Claytonf9fc6092013-01-09 19:44:40 +00004555 if (frame_module_sp->GetPlatformFileSpec().Exists())
Greg Claytonb5f0fea2012-09-27 22:26:11 +00004556 {
Greg Claytonf9fc6092013-01-09 19:44:40 +00004557 module_spec.GetArchitecture() = frame_module_sp->GetArchitecture();
4558 module_spec.GetFileSpec() = frame_module_sp->GetPlatformFileSpec();
Greg Claytonb5f0fea2012-09-27 22:26:11 +00004559 }
Greg Claytonf9fc6092013-01-09 19:44:40 +00004560 module_spec.GetUUID() = frame_module_sp->GetUUID();
4561 success = module_spec.GetUUID().IsValid() || module_spec.GetFileSpec();
Greg Claytone72dfb32012-02-24 01:59:29 +00004562 }
Johnny Chen82e5a262012-08-22 00:18:43 +00004563 else
4564 {
Greg Claytonf9fc6092013-01-09 19:44:40 +00004565 result.AppendError ("frame has no module");
Greg Claytonb5f0fea2012-09-27 22:26:11 +00004566 error_set = true;
Johnny Chen82e5a262012-08-22 00:18:43 +00004567 }
Greg Claytone72dfb32012-02-24 01:59:29 +00004568 }
4569 else
4570 {
Greg Claytonf9fc6092013-01-09 19:44:40 +00004571 result.AppendError ("invalid current frame");
Greg Claytonb5f0fea2012-09-27 22:26:11 +00004572 error_set = true;
Greg Claytone72dfb32012-02-24 01:59:29 +00004573 }
Greg Claytone72dfb32012-02-24 01:59:29 +00004574 }
4575 else
4576 {
Greg Claytonf9fc6092013-01-09 19:44:40 +00004577 result.AppendErrorWithFormat ("process is not stopped: %s", StateAsCString(process_state));
Greg Claytonb5f0fea2012-09-27 22:26:11 +00004578 error_set = true;
4579 }
4580 }
4581 else
4582 {
Greg Claytonf9fc6092013-01-09 19:44:40 +00004583 result.AppendError ("a process must exist in order to use the --frame option");
4584 error_set = true;
Greg Claytonb5f0fea2012-09-27 22:26:11 +00004585 }
4586 }
4587 else
4588 {
Greg Claytonf9fc6092013-01-09 19:44:40 +00004589 if (uuid_option_set)
4590 {
4591 module_spec.GetUUID() = m_uuid_option_group.GetOptionValue().GetCurrentValue();
4592 success |= module_spec.GetUUID().IsValid();
4593 }
4594 else if (file_option_set)
4595 {
4596 module_spec.GetFileSpec() = m_file_option.GetOptionValue().GetCurrentValue();
4597 ModuleSP module_sp (target->GetImages().FindFirstModule(module_spec));
4598 if (module_sp)
4599 {
4600 module_spec.GetFileSpec() = module_sp->GetFileSpec();
4601 module_spec.GetPlatformFileSpec() = module_sp->GetPlatformFileSpec();
4602 module_spec.GetUUID() = module_sp->GetUUID();
4603 module_spec.GetArchitecture() = module_sp->GetArchitecture();
4604 }
4605 else
4606 {
4607 module_spec.GetArchitecture() = target->GetArchitecture();
4608 }
4609 success |= module_spec.GetFileSpec().Exists();
4610 }
4611 }
4612
4613 if (success)
4614 {
4615 if (Symbols::DownloadObjectAndSymbolFile (module_spec))
4616 {
4617 if (module_spec.GetSymbolFileSpec())
4618 success = AddModuleSymbols (target, module_spec, flush, result);
4619 }
4620 }
4621
4622 if (!success && !error_set)
4623 {
4624 StreamString error_strm;
4625 if (uuid_option_set)
4626 {
4627 error_strm.PutCString("unable to find debug symbols for UUID ");
4628 module_spec.GetUUID().Dump (&error_strm);
4629 }
4630 else if (file_option_set)
4631 {
4632 error_strm.PutCString("unable to find debug symbols for the executable file ");
4633 error_strm << module_spec.GetFileSpec();
4634 }
4635 else if (frame_option_set)
4636 {
4637 error_strm.PutCString("unable to find debug symbols for the current frame");
4638 }
4639 result.AppendError (error_strm.GetData());
Greg Claytonb5f0fea2012-09-27 22:26:11 +00004640 }
4641 }
4642 else
4643 {
Greg Claytonf9fc6092013-01-09 19:44:40 +00004644 result.AppendError ("one or more symbol file paths must be specified, or options must be specified");
4645 }
4646 }
4647 else
4648 {
4649 if (uuid_option_set)
4650 {
4651 result.AppendError ("specify either one or more paths to symbol files or use the --uuid option without arguments");
4652 }
4653 else if (file_option_set)
4654 {
4655 result.AppendError ("specify either one or more paths to symbol files or use the --file option without arguments");
4656 }
4657 else if (frame_option_set)
4658 {
4659 result.AppendError ("specify either one or more paths to symbol files or use the --frame option without arguments");
4660 }
4661 else
4662 {
4663 PlatformSP platform_sp (target->GetPlatform());
Greg Claytonb5f0fea2012-09-27 22:26:11 +00004664
Greg Claytonf9fc6092013-01-09 19:44:40 +00004665 for (size_t i=0; i<argc; ++i)
4666 {
4667 const char *symfile_path = args.GetArgumentAtIndex(i);
4668 if (symfile_path)
Greg Claytonb5f0fea2012-09-27 22:26:11 +00004669 {
Greg Claytonf9fc6092013-01-09 19:44:40 +00004670 module_spec.GetSymbolFileSpec().SetFile(symfile_path, true);
4671 if (platform_sp)
Greg Claytonb5f0fea2012-09-27 22:26:11 +00004672 {
Greg Claytonf9fc6092013-01-09 19:44:40 +00004673 FileSpec symfile_spec;
4674 if (platform_sp->ResolveSymbolFile(*target, module_spec, symfile_spec).Success())
4675 module_spec.GetSymbolFileSpec() = symfile_spec;
4676 }
4677
4678 ArchSpec arch;
4679 bool symfile_exists = module_spec.GetSymbolFileSpec().Exists();
Greg Claytonb5f0fea2012-09-27 22:26:11 +00004680
Greg Claytonf9fc6092013-01-09 19:44:40 +00004681 if (symfile_exists)
4682 {
4683 if (!AddModuleSymbols (target, module_spec, flush, result))
Greg Claytonb5f0fea2012-09-27 22:26:11 +00004684 break;
Greg Claytonf9fc6092013-01-09 19:44:40 +00004685 }
4686 else
4687 {
4688 char resolved_symfile_path[PATH_MAX];
4689 if (module_spec.GetSymbolFileSpec().GetPath (resolved_symfile_path, sizeof(resolved_symfile_path)))
4690 {
4691 if (strcmp (resolved_symfile_path, symfile_path) != 0)
4692 {
4693 result.AppendErrorWithFormat ("invalid module path '%s' with resolved path '%s'\n", symfile_path, resolved_symfile_path);
4694 break;
4695 }
Greg Claytonb5f0fea2012-09-27 22:26:11 +00004696 }
Greg Claytonf9fc6092013-01-09 19:44:40 +00004697 result.AppendErrorWithFormat ("invalid module path '%s'\n", symfile_path);
4698 break;
Greg Claytone72dfb32012-02-24 01:59:29 +00004699 }
4700 }
4701 }
4702 }
Greg Claytonf9fc6092013-01-09 19:44:40 +00004703 }
Greg Claytonfa559e52012-05-18 02:38:05 +00004704
Greg Claytonf9fc6092013-01-09 19:44:40 +00004705 if (flush)
4706 {
4707 Process *process = m_exe_ctx.GetProcessPtr();
4708 if (process)
4709 process->Flush();
Greg Claytone72dfb32012-02-24 01:59:29 +00004710 }
4711 return result.Succeeded();
4712 }
4713
Greg Claytonb5f0fea2012-09-27 22:26:11 +00004714 OptionGroupOptions m_option_group;
4715 OptionGroupUUID m_uuid_option_group;
4716 OptionGroupFile m_file_option;
4717 OptionGroupBoolean m_current_frame_option;
4718
4719
Greg Claytone72dfb32012-02-24 01:59:29 +00004720};
4721
4722
4723#pragma mark CommandObjectTargetSymbols
4724
4725//-------------------------------------------------------------------------
4726// CommandObjectTargetSymbols
4727//-------------------------------------------------------------------------
4728
4729class CommandObjectTargetSymbols : public CommandObjectMultiword
4730{
4731public:
4732 //------------------------------------------------------------------
4733 // Constructors and Destructors
4734 //------------------------------------------------------------------
4735 CommandObjectTargetSymbols(CommandInterpreter &interpreter) :
4736 CommandObjectMultiword (interpreter,
4737 "target symbols",
4738 "A set of commands for adding and managing debug symbol files.",
4739 "target symbols <sub-command> ...")
4740 {
4741 LoadSubCommand ("add", CommandObjectSP (new CommandObjectTargetSymbolsAdd (interpreter)));
4742
4743 }
4744 virtual
4745 ~CommandObjectTargetSymbols()
4746 {
4747 }
4748
4749private:
4750 //------------------------------------------------------------------
4751 // For CommandObjectTargetModules only
4752 //------------------------------------------------------------------
4753 DISALLOW_COPY_AND_ASSIGN (CommandObjectTargetSymbols);
4754};
4755
4756
Jim Ingham9575d842011-03-11 03:53:59 +00004757#pragma mark CommandObjectTargetStopHookAdd
4758
4759//-------------------------------------------------------------------------
4760// CommandObjectTargetStopHookAdd
4761//-------------------------------------------------------------------------
4762
Greg Clayton44d93782014-01-27 23:43:24 +00004763class CommandObjectTargetStopHookAdd :
4764 public CommandObjectParsed,
4765 public IOHandlerDelegateMultiline
Jim Ingham9575d842011-03-11 03:53:59 +00004766{
4767public:
4768
4769 class CommandOptions : public Options
4770 {
4771 public:
Greg Claytoneb0103f2011-04-07 22:46:35 +00004772 CommandOptions (CommandInterpreter &interpreter) :
4773 Options(interpreter),
Jim Ingham9575d842011-03-11 03:53:59 +00004774 m_line_start(0),
4775 m_line_end (UINT_MAX),
4776 m_func_name_type_mask (eFunctionNameTypeAuto),
4777 m_sym_ctx_specified (false),
Johnny Chenb1372c02011-05-02 23:47:55 +00004778 m_thread_specified (false),
4779 m_use_one_liner (false),
4780 m_one_liner()
Jim Ingham9575d842011-03-11 03:53:59 +00004781 {
4782 }
4783
4784 ~CommandOptions () {}
4785
Greg Claytone0d378b2011-03-24 21:19:54 +00004786 const OptionDefinition*
Jim Ingham9575d842011-03-11 03:53:59 +00004787 GetDefinitions ()
4788 {
4789 return g_option_table;
4790 }
4791
4792 virtual Error
Greg Claytonf6b8b582011-04-13 00:18:08 +00004793 SetOptionValue (uint32_t option_idx, const char *option_arg)
Jim Ingham9575d842011-03-11 03:53:59 +00004794 {
4795 Error error;
Greg Clayton3bcdfc02012-12-04 00:32:51 +00004796 const int short_option = m_getopt_table[option_idx].val;
Jim Ingham9575d842011-03-11 03:53:59 +00004797 bool success;
4798
4799 switch (short_option)
4800 {
4801 case 'c':
4802 m_class_name = option_arg;
4803 m_sym_ctx_specified = true;
4804 break;
4805
4806 case 'e':
4807 m_line_end = Args::StringToUInt32 (option_arg, UINT_MAX, 0, &success);
4808 if (!success)
4809 {
Greg Clayton86edbf42011-10-26 00:56:27 +00004810 error.SetErrorStringWithFormat ("invalid end line number: \"%s\"", option_arg);
Jim Ingham9575d842011-03-11 03:53:59 +00004811 break;
4812 }
4813 m_sym_ctx_specified = true;
4814 break;
4815
4816 case 'l':
4817 m_line_start = Args::StringToUInt32 (option_arg, 0, 0, &success);
4818 if (!success)
4819 {
Greg Clayton86edbf42011-10-26 00:56:27 +00004820 error.SetErrorStringWithFormat ("invalid start line number: \"%s\"", option_arg);
Jim Ingham9575d842011-03-11 03:53:59 +00004821 break;
4822 }
4823 m_sym_ctx_specified = true;
4824 break;
Sean Callanand4a7c122012-02-11 01:22:21 +00004825
4826 case 'i':
4827 m_no_inlines = true;
4828 break;
Jim Ingham9575d842011-03-11 03:53:59 +00004829
4830 case 'n':
4831 m_function_name = option_arg;
4832 m_func_name_type_mask |= eFunctionNameTypeAuto;
4833 m_sym_ctx_specified = true;
4834 break;
4835
4836 case 'f':
4837 m_file_name = option_arg;
4838 m_sym_ctx_specified = true;
4839 break;
4840 case 's':
4841 m_module_name = option_arg;
4842 m_sym_ctx_specified = true;
4843 break;
4844 case 't' :
4845 {
Jim Ingham0292f4a2011-03-22 01:53:33 +00004846 m_thread_id = Args::StringToUInt64(option_arg, LLDB_INVALID_THREAD_ID, 0);
Jim Ingham9575d842011-03-11 03:53:59 +00004847 if (m_thread_id == LLDB_INVALID_THREAD_ID)
Greg Clayton86edbf42011-10-26 00:56:27 +00004848 error.SetErrorStringWithFormat ("invalid thread id string '%s'", option_arg);
Jim Ingham9575d842011-03-11 03:53:59 +00004849 m_thread_specified = true;
4850 }
4851 break;
4852 case 'T':
4853 m_thread_name = option_arg;
4854 m_thread_specified = true;
4855 break;
4856 case 'q':
4857 m_queue_name = option_arg;
4858 m_thread_specified = true;
4859 break;
4860 case 'x':
4861 {
Jim Ingham0292f4a2011-03-22 01:53:33 +00004862 m_thread_index = Args::StringToUInt32(option_arg, UINT32_MAX, 0);
Jim Ingham9575d842011-03-11 03:53:59 +00004863 if (m_thread_id == UINT32_MAX)
Greg Clayton86edbf42011-10-26 00:56:27 +00004864 error.SetErrorStringWithFormat ("invalid thread index string '%s'", option_arg);
Jim Ingham9575d842011-03-11 03:53:59 +00004865 m_thread_specified = true;
4866 }
4867 break;
Johnny Chenb1372c02011-05-02 23:47:55 +00004868 case 'o':
4869 m_use_one_liner = true;
4870 m_one_liner = option_arg;
4871 break;
Jim Ingham9575d842011-03-11 03:53:59 +00004872 default:
Greg Clayton86edbf42011-10-26 00:56:27 +00004873 error.SetErrorStringWithFormat ("unrecognized option %c.", short_option);
Jim Ingham9575d842011-03-11 03:53:59 +00004874 break;
4875 }
4876 return error;
4877 }
4878
4879 void
Greg Claytonf6b8b582011-04-13 00:18:08 +00004880 OptionParsingStarting ()
Jim Ingham9575d842011-03-11 03:53:59 +00004881 {
4882 m_class_name.clear();
4883 m_function_name.clear();
4884 m_line_start = 0;
4885 m_line_end = UINT_MAX;
4886 m_file_name.clear();
4887 m_module_name.clear();
4888 m_func_name_type_mask = eFunctionNameTypeAuto;
4889 m_thread_id = LLDB_INVALID_THREAD_ID;
4890 m_thread_index = UINT32_MAX;
4891 m_thread_name.clear();
4892 m_queue_name.clear();
Sean Callanand4a7c122012-02-11 01:22:21 +00004893
4894 m_no_inlines = false;
Jim Ingham9575d842011-03-11 03:53:59 +00004895 m_sym_ctx_specified = false;
4896 m_thread_specified = false;
Johnny Chenb1372c02011-05-02 23:47:55 +00004897
4898 m_use_one_liner = false;
4899 m_one_liner.clear();
Jim Ingham9575d842011-03-11 03:53:59 +00004900 }
4901
4902
Greg Claytone0d378b2011-03-24 21:19:54 +00004903 static OptionDefinition g_option_table[];
Jim Ingham9575d842011-03-11 03:53:59 +00004904
4905 std::string m_class_name;
4906 std::string m_function_name;
4907 uint32_t m_line_start;
4908 uint32_t m_line_end;
4909 std::string m_file_name;
4910 std::string m_module_name;
4911 uint32_t m_func_name_type_mask; // A pick from lldb::FunctionNameType.
4912 lldb::tid_t m_thread_id;
4913 uint32_t m_thread_index;
4914 std::string m_thread_name;
4915 std::string m_queue_name;
4916 bool m_sym_ctx_specified;
Sean Callanand4a7c122012-02-11 01:22:21 +00004917 bool m_no_inlines;
Jim Ingham9575d842011-03-11 03:53:59 +00004918 bool m_thread_specified;
Johnny Chenb1372c02011-05-02 23:47:55 +00004919 // Instance variables to hold the values for one_liner options.
4920 bool m_use_one_liner;
4921 std::string m_one_liner;
Jim Ingham9575d842011-03-11 03:53:59 +00004922 };
4923
4924 Options *
4925 GetOptions ()
4926 {
4927 return &m_options;
4928 }
4929
4930 CommandObjectTargetStopHookAdd (CommandInterpreter &interpreter) :
Jim Ingham5a988412012-06-08 21:56:10 +00004931 CommandObjectParsed (interpreter,
Greg Clayton44d93782014-01-27 23:43:24 +00004932 "target stop-hook add",
Jim Ingham5a988412012-06-08 21:56:10 +00004933 "Add a hook to be executed when the target stops.",
4934 "target stop-hook add"),
Greg Clayton44d93782014-01-27 23:43:24 +00004935 IOHandlerDelegateMultiline ("DONE", IOHandlerDelegate::Completion::LLDBCommand),
Greg Claytoneb0103f2011-04-07 22:46:35 +00004936 m_options (interpreter)
Jim Ingham9575d842011-03-11 03:53:59 +00004937 {
4938 }
4939
4940 ~CommandObjectTargetStopHookAdd ()
4941 {
4942 }
4943
Jim Ingham5a988412012-06-08 21:56:10 +00004944protected:
Greg Clayton44d93782014-01-27 23:43:24 +00004945
4946 virtual void
4947 IOHandlerActivated (IOHandler &io_handler)
4948 {
4949 StreamFileSP output_sp(io_handler.GetOutputStreamFile());
4950 if (output_sp)
4951 {
4952 output_sp->PutCString("Enter your stop hook command(s). Type 'DONE' to end.\n");
4953 output_sp->Flush();
4954 }
4955 }
4956
4957
4958 virtual void
4959 IOHandlerInputComplete (IOHandler &io_handler, std::string &line)
4960 {
4961 if (m_stop_hook_sp)
4962 {
4963 if (line.empty())
4964 {
4965 StreamFileSP error_sp(io_handler.GetErrorStreamFile());
4966 if (error_sp)
4967 {
4968 error_sp->Printf("error: stop hook #%" PRIu64 " aborted, no commands.\n", m_stop_hook_sp->GetID());
4969 error_sp->Flush();
4970 }
4971 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
4972 if (target)
4973 target->RemoveStopHookByID(m_stop_hook_sp->GetID());
4974 }
4975 else
4976 {
4977 m_stop_hook_sp->GetCommandPointer()->SplitIntoLines(line);
4978 StreamFileSP output_sp(io_handler.GetOutputStreamFile());
4979 if (output_sp)
4980 {
4981 output_sp->Printf("Stop hook #%" PRIu64 " added.\n", m_stop_hook_sp->GetID());
4982 output_sp->Flush();
4983 }
4984 }
4985 m_stop_hook_sp.reset();
4986 }
4987 io_handler.SetIsDone(true);
4988 }
4989
Jim Ingham9575d842011-03-11 03:53:59 +00004990 bool
Jim Ingham5a988412012-06-08 21:56:10 +00004991 DoExecute (Args& command, CommandReturnObject &result)
Jim Ingham9575d842011-03-11 03:53:59 +00004992 {
Greg Clayton44d93782014-01-27 23:43:24 +00004993 m_stop_hook_sp.reset();
4994
Jim Ingham9575d842011-03-11 03:53:59 +00004995 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
4996 if (target)
4997 {
Greg Clayton44d93782014-01-27 23:43:24 +00004998 Target::StopHookSP new_hook_sp = target->CreateStopHook();
Jim Ingham9575d842011-03-11 03:53:59 +00004999
5000 // First step, make the specifier.
Greg Clayton7b0992d2013-04-18 22:45:39 +00005001 std::unique_ptr<SymbolContextSpecifier> specifier_ap;
Jim Ingham9575d842011-03-11 03:53:59 +00005002 if (m_options.m_sym_ctx_specified)
5003 {
5004 specifier_ap.reset(new SymbolContextSpecifier(m_interpreter.GetDebugger().GetSelectedTarget()));
5005
5006 if (!m_options.m_module_name.empty())
5007 {
5008 specifier_ap->AddSpecification (m_options.m_module_name.c_str(), SymbolContextSpecifier::eModuleSpecified);
5009 }
5010
5011 if (!m_options.m_class_name.empty())
5012 {
5013 specifier_ap->AddSpecification (m_options.m_class_name.c_str(), SymbolContextSpecifier::eClassOrNamespaceSpecified);
5014 }
5015
5016 if (!m_options.m_file_name.empty())
5017 {
5018 specifier_ap->AddSpecification (m_options.m_file_name.c_str(), SymbolContextSpecifier::eFileSpecified);
5019 }
5020
5021 if (m_options.m_line_start != 0)
5022 {
5023 specifier_ap->AddLineSpecification (m_options.m_line_start, SymbolContextSpecifier::eLineStartSpecified);
5024 }
5025
5026 if (m_options.m_line_end != UINT_MAX)
5027 {
5028 specifier_ap->AddLineSpecification (m_options.m_line_end, SymbolContextSpecifier::eLineEndSpecified);
5029 }
5030
5031 if (!m_options.m_function_name.empty())
5032 {
5033 specifier_ap->AddSpecification (m_options.m_function_name.c_str(), SymbolContextSpecifier::eFunctionSpecified);
5034 }
5035 }
5036
5037 if (specifier_ap.get())
5038 new_hook_sp->SetSpecifier (specifier_ap.release());
5039
5040 // Next see if any of the thread options have been entered:
5041
5042 if (m_options.m_thread_specified)
5043 {
5044 ThreadSpec *thread_spec = new ThreadSpec();
5045
5046 if (m_options.m_thread_id != LLDB_INVALID_THREAD_ID)
5047 {
5048 thread_spec->SetTID (m_options.m_thread_id);
5049 }
5050
5051 if (m_options.m_thread_index != UINT32_MAX)
5052 thread_spec->SetIndex (m_options.m_thread_index);
5053
5054 if (!m_options.m_thread_name.empty())
5055 thread_spec->SetName (m_options.m_thread_name.c_str());
5056
5057 if (!m_options.m_queue_name.empty())
5058 thread_spec->SetQueueName (m_options.m_queue_name.c_str());
5059
5060 new_hook_sp->SetThreadSpecifier (thread_spec);
5061
5062 }
Johnny Chenb1372c02011-05-02 23:47:55 +00005063 if (m_options.m_use_one_liner)
Jim Ingham9575d842011-03-11 03:53:59 +00005064 {
Johnny Chenb1372c02011-05-02 23:47:55 +00005065 // Use one-liner.
5066 new_hook_sp->GetCommandPointer()->AppendString (m_options.m_one_liner.c_str());
Daniel Malead01b2952012-11-29 21:49:15 +00005067 result.AppendMessageWithFormat("Stop hook #%" PRIu64 " added.\n", new_hook_sp->GetID());
Jim Ingham9575d842011-03-11 03:53:59 +00005068 }
Johnny Chenb1372c02011-05-02 23:47:55 +00005069 else
Jim Ingham9575d842011-03-11 03:53:59 +00005070 {
Greg Clayton44d93782014-01-27 23:43:24 +00005071 m_stop_hook_sp = new_hook_sp;
5072 m_interpreter.GetLLDBCommandsFromIOHandler ("> ", // Prompt
5073 *this, // IOHandlerDelegate
5074 true, // Run IOHandler in async mode
5075 NULL); // Baton for the "io_handler" that will be passed back into our IOHandlerDelegate functions
5076
Jim Ingham9575d842011-03-11 03:53:59 +00005077 }
Jim Ingham9575d842011-03-11 03:53:59 +00005078 result.SetStatus (eReturnStatusSuccessFinishNoResult);
5079 }
5080 else
5081 {
Greg Clayton7260f622011-04-18 08:33:37 +00005082 result.AppendError ("invalid target\n");
Jim Ingham9575d842011-03-11 03:53:59 +00005083 result.SetStatus (eReturnStatusFailed);
5084 }
5085
5086 return result.Succeeded();
5087 }
5088private:
5089 CommandOptions m_options;
Greg Clayton44d93782014-01-27 23:43:24 +00005090 Target::StopHookSP m_stop_hook_sp;
Jim Ingham9575d842011-03-11 03:53:59 +00005091};
5092
Greg Claytone0d378b2011-03-24 21:19:54 +00005093OptionDefinition
Jim Ingham9575d842011-03-11 03:53:59 +00005094CommandObjectTargetStopHookAdd::CommandOptions::g_option_table[] =
5095{
Virgile Belloe2607b52013-09-05 16:42:23 +00005096 { LLDB_OPT_SET_ALL, false, "one-liner", 'o', OptionParser::eRequiredArgument, NULL, 0, eArgTypeOneLiner,
Johnny Chenb1372c02011-05-02 23:47:55 +00005097 "Specify a one-line breakpoint command inline. Be sure to surround it with quotes." },
Virgile Belloe2607b52013-09-05 16:42:23 +00005098 { LLDB_OPT_SET_ALL, false, "shlib", 's', OptionParser::eRequiredArgument, NULL, CommandCompletions::eModuleCompletion, eArgTypeShlibName,
Jim Ingham9575d842011-03-11 03:53:59 +00005099 "Set the module within which the stop-hook is to be run."},
Virgile Belloe2607b52013-09-05 16:42:23 +00005100 { LLDB_OPT_SET_ALL, false, "thread-index", 'x', OptionParser::eRequiredArgument, NULL, 0, eArgTypeThreadIndex,
Jim Ingham9575d842011-03-11 03:53:59 +00005101 "The stop hook is run only for the thread whose index matches this argument."},
Virgile Belloe2607b52013-09-05 16:42:23 +00005102 { LLDB_OPT_SET_ALL, false, "thread-id", 't', OptionParser::eRequiredArgument, NULL, 0, eArgTypeThreadID,
Jim Ingham9575d842011-03-11 03:53:59 +00005103 "The stop hook is run only for the thread whose TID matches this argument."},
Virgile Belloe2607b52013-09-05 16:42:23 +00005104 { LLDB_OPT_SET_ALL, false, "thread-name", 'T', OptionParser::eRequiredArgument, NULL, 0, eArgTypeThreadName,
Jim Ingham9575d842011-03-11 03:53:59 +00005105 "The stop hook is run only for the thread whose thread name matches this argument."},
Virgile Belloe2607b52013-09-05 16:42:23 +00005106 { LLDB_OPT_SET_ALL, false, "queue-name", 'q', OptionParser::eRequiredArgument, NULL, 0, eArgTypeQueueName,
Jim Ingham9575d842011-03-11 03:53:59 +00005107 "The stop hook is run only for threads in the queue whose name is given by this argument."},
Virgile Belloe2607b52013-09-05 16:42:23 +00005108 { LLDB_OPT_SET_1, false, "file", 'f', OptionParser::eRequiredArgument, NULL, CommandCompletions::eSourceFileCompletion, eArgTypeFilename,
Jim Ingham9575d842011-03-11 03:53:59 +00005109 "Specify the source file within which the stop-hook is to be run." },
Virgile Belloe2607b52013-09-05 16:42:23 +00005110 { LLDB_OPT_SET_1, false, "start-line", 'l', OptionParser::eRequiredArgument, NULL, 0, eArgTypeLineNum,
Jim Ingham9575d842011-03-11 03:53:59 +00005111 "Set the start of the line range for which the stop-hook is to be run."},
Virgile Belloe2607b52013-09-05 16:42:23 +00005112 { LLDB_OPT_SET_1, false, "end-line", 'e', OptionParser::eRequiredArgument, NULL, 0, eArgTypeLineNum,
Jim Ingham9575d842011-03-11 03:53:59 +00005113 "Set the end of the line range for which the stop-hook is to be run."},
Virgile Belloe2607b52013-09-05 16:42:23 +00005114 { LLDB_OPT_SET_2, false, "classname", 'c', OptionParser::eRequiredArgument, NULL, 0, eArgTypeClassName,
Jim Ingham9575d842011-03-11 03:53:59 +00005115 "Specify the class within which the stop-hook is to be run." },
Virgile Belloe2607b52013-09-05 16:42:23 +00005116 { LLDB_OPT_SET_3, false, "name", 'n', OptionParser::eRequiredArgument, NULL, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName,
Jim Ingham9575d842011-03-11 03:53:59 +00005117 "Set the function name within which the stop hook will be run." },
5118 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
5119};
5120
5121#pragma mark CommandObjectTargetStopHookDelete
5122
5123//-------------------------------------------------------------------------
5124// CommandObjectTargetStopHookDelete
5125//-------------------------------------------------------------------------
5126
Jim Ingham5a988412012-06-08 21:56:10 +00005127class CommandObjectTargetStopHookDelete : public CommandObjectParsed
Jim Ingham9575d842011-03-11 03:53:59 +00005128{
5129public:
5130
5131 CommandObjectTargetStopHookDelete (CommandInterpreter &interpreter) :
Jim Ingham5a988412012-06-08 21:56:10 +00005132 CommandObjectParsed (interpreter,
5133 "target stop-hook delete",
5134 "Delete a stop-hook.",
5135 "target stop-hook delete [<idx>]")
Jim Ingham9575d842011-03-11 03:53:59 +00005136 {
5137 }
5138
5139 ~CommandObjectTargetStopHookDelete ()
5140 {
5141 }
5142
Jim Ingham5a988412012-06-08 21:56:10 +00005143protected:
Jim Ingham9575d842011-03-11 03:53:59 +00005144 bool
Jim Ingham5a988412012-06-08 21:56:10 +00005145 DoExecute (Args& command, CommandReturnObject &result)
Jim Ingham9575d842011-03-11 03:53:59 +00005146 {
5147 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
5148 if (target)
5149 {
5150 // FIXME: see if we can use the breakpoint id style parser?
5151 size_t num_args = command.GetArgumentCount();
5152 if (num_args == 0)
5153 {
5154 if (!m_interpreter.Confirm ("Delete all stop hooks?", true))
5155 {
5156 result.SetStatus (eReturnStatusFailed);
5157 return false;
5158 }
5159 else
5160 {
5161 target->RemoveAllStopHooks();
5162 }
5163 }
5164 else
5165 {
5166 bool success;
5167 for (size_t i = 0; i < num_args; i++)
5168 {
5169 lldb::user_id_t user_id = Args::StringToUInt32 (command.GetArgumentAtIndex(i), 0, 0, &success);
5170 if (!success)
5171 {
Greg Clayton7260f622011-04-18 08:33:37 +00005172 result.AppendErrorWithFormat ("invalid stop hook id: \"%s\".\n", command.GetArgumentAtIndex(i));
Jim Ingham9575d842011-03-11 03:53:59 +00005173 result.SetStatus(eReturnStatusFailed);
5174 return false;
5175 }
5176 success = target->RemoveStopHookByID (user_id);
5177 if (!success)
5178 {
Greg Clayton7260f622011-04-18 08:33:37 +00005179 result.AppendErrorWithFormat ("unknown stop hook id: \"%s\".\n", command.GetArgumentAtIndex(i));
Jim Ingham9575d842011-03-11 03:53:59 +00005180 result.SetStatus(eReturnStatusFailed);
5181 return false;
5182 }
5183 }
5184 }
5185 result.SetStatus (eReturnStatusSuccessFinishNoResult);
5186 }
5187 else
5188 {
Greg Clayton7260f622011-04-18 08:33:37 +00005189 result.AppendError ("invalid target\n");
Jim Ingham9575d842011-03-11 03:53:59 +00005190 result.SetStatus (eReturnStatusFailed);
5191 }
5192
5193 return result.Succeeded();
5194 }
5195};
5196#pragma mark CommandObjectTargetStopHookEnableDisable
5197
5198//-------------------------------------------------------------------------
5199// CommandObjectTargetStopHookEnableDisable
5200//-------------------------------------------------------------------------
5201
Jim Ingham5a988412012-06-08 21:56:10 +00005202class CommandObjectTargetStopHookEnableDisable : public CommandObjectParsed
Jim Ingham9575d842011-03-11 03:53:59 +00005203{
5204public:
5205
5206 CommandObjectTargetStopHookEnableDisable (CommandInterpreter &interpreter, bool enable, const char *name, const char *help, const char *syntax) :
Jim Ingham5a988412012-06-08 21:56:10 +00005207 CommandObjectParsed (interpreter,
5208 name,
5209 help,
5210 syntax),
Jim Ingham9575d842011-03-11 03:53:59 +00005211 m_enable (enable)
5212 {
5213 }
5214
5215 ~CommandObjectTargetStopHookEnableDisable ()
5216 {
5217 }
5218
Jim Ingham5a988412012-06-08 21:56:10 +00005219protected:
Jim Ingham9575d842011-03-11 03:53:59 +00005220 bool
Jim Ingham5a988412012-06-08 21:56:10 +00005221 DoExecute (Args& command, CommandReturnObject &result)
Jim Ingham9575d842011-03-11 03:53:59 +00005222 {
5223 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
5224 if (target)
5225 {
5226 // FIXME: see if we can use the breakpoint id style parser?
5227 size_t num_args = command.GetArgumentCount();
5228 bool success;
5229
5230 if (num_args == 0)
5231 {
5232 target->SetAllStopHooksActiveState (m_enable);
5233 }
5234 else
5235 {
5236 for (size_t i = 0; i < num_args; i++)
5237 {
5238 lldb::user_id_t user_id = Args::StringToUInt32 (command.GetArgumentAtIndex(i), 0, 0, &success);
5239 if (!success)
5240 {
Greg Clayton7260f622011-04-18 08:33:37 +00005241 result.AppendErrorWithFormat ("invalid stop hook id: \"%s\".\n", command.GetArgumentAtIndex(i));
Jim Ingham9575d842011-03-11 03:53:59 +00005242 result.SetStatus(eReturnStatusFailed);
5243 return false;
5244 }
5245 success = target->SetStopHookActiveStateByID (user_id, m_enable);
5246 if (!success)
5247 {
Greg Clayton7260f622011-04-18 08:33:37 +00005248 result.AppendErrorWithFormat ("unknown stop hook id: \"%s\".\n", command.GetArgumentAtIndex(i));
Jim Ingham9575d842011-03-11 03:53:59 +00005249 result.SetStatus(eReturnStatusFailed);
5250 return false;
5251 }
5252 }
5253 }
5254 result.SetStatus (eReturnStatusSuccessFinishNoResult);
5255 }
5256 else
5257 {
Greg Clayton7260f622011-04-18 08:33:37 +00005258 result.AppendError ("invalid target\n");
Jim Ingham9575d842011-03-11 03:53:59 +00005259 result.SetStatus (eReturnStatusFailed);
5260 }
5261 return result.Succeeded();
5262 }
5263private:
5264 bool m_enable;
5265};
5266
5267#pragma mark CommandObjectTargetStopHookList
5268
5269//-------------------------------------------------------------------------
5270// CommandObjectTargetStopHookList
5271//-------------------------------------------------------------------------
5272
Jim Ingham5a988412012-06-08 21:56:10 +00005273class CommandObjectTargetStopHookList : public CommandObjectParsed
Jim Ingham9575d842011-03-11 03:53:59 +00005274{
5275public:
5276
5277 CommandObjectTargetStopHookList (CommandInterpreter &interpreter) :
Jim Ingham5a988412012-06-08 21:56:10 +00005278 CommandObjectParsed (interpreter,
5279 "target stop-hook list",
5280 "List all stop-hooks.",
5281 "target stop-hook list [<type>]")
Jim Ingham9575d842011-03-11 03:53:59 +00005282 {
5283 }
5284
5285 ~CommandObjectTargetStopHookList ()
5286 {
5287 }
5288
Jim Ingham5a988412012-06-08 21:56:10 +00005289protected:
Jim Ingham9575d842011-03-11 03:53:59 +00005290 bool
Jim Ingham5a988412012-06-08 21:56:10 +00005291 DoExecute (Args& command, CommandReturnObject &result)
Jim Ingham9575d842011-03-11 03:53:59 +00005292 {
5293 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Johnny Chenfaa5c132011-11-29 23:56:14 +00005294 if (!target)
Jim Ingham9575d842011-03-11 03:53:59 +00005295 {
Greg Clayton7260f622011-04-18 08:33:37 +00005296 result.AppendError ("invalid target\n");
Jim Ingham9575d842011-03-11 03:53:59 +00005297 result.SetStatus (eReturnStatusFailed);
Jason Molendaeffcd2a2011-09-23 21:15:42 +00005298 return result.Succeeded();
Jim Ingham9575d842011-03-11 03:53:59 +00005299 }
5300
5301 size_t num_hooks = target->GetNumStopHooks ();
5302 if (num_hooks == 0)
5303 {
5304 result.GetOutputStream().PutCString ("No stop hooks.\n");
5305 }
5306 else
5307 {
5308 for (size_t i = 0; i < num_hooks; i++)
5309 {
5310 Target::StopHookSP this_hook = target->GetStopHookAtIndex (i);
5311 if (i > 0)
5312 result.GetOutputStream().PutCString ("\n");
5313 this_hook->GetDescription (&(result.GetOutputStream()), eDescriptionLevelFull);
5314 }
5315 }
Johnny Chend0cff1e2011-11-30 19:09:20 +00005316 result.SetStatus (eReturnStatusSuccessFinishResult);
Jim Ingham9575d842011-03-11 03:53:59 +00005317 return result.Succeeded();
5318 }
5319};
5320
5321#pragma mark CommandObjectMultiwordTargetStopHooks
5322//-------------------------------------------------------------------------
5323// CommandObjectMultiwordTargetStopHooks
5324//-------------------------------------------------------------------------
5325
5326class CommandObjectMultiwordTargetStopHooks : public CommandObjectMultiword
5327{
5328public:
5329
5330 CommandObjectMultiwordTargetStopHooks (CommandInterpreter &interpreter) :
5331 CommandObjectMultiword (interpreter,
5332 "target stop-hook",
5333 "A set of commands for operating on debugger target stop-hooks.",
5334 "target stop-hook <subcommand> [<subcommand-options>]")
5335 {
5336 LoadSubCommand ("add", CommandObjectSP (new CommandObjectTargetStopHookAdd (interpreter)));
5337 LoadSubCommand ("delete", CommandObjectSP (new CommandObjectTargetStopHookDelete (interpreter)));
5338 LoadSubCommand ("disable", CommandObjectSP (new CommandObjectTargetStopHookEnableDisable (interpreter,
5339 false,
5340 "target stop-hook disable [<id>]",
5341 "Disable a stop-hook.",
5342 "target stop-hook disable")));
5343 LoadSubCommand ("enable", CommandObjectSP (new CommandObjectTargetStopHookEnableDisable (interpreter,
5344 true,
5345 "target stop-hook enable [<id>]",
5346 "Enable a stop-hook.",
5347 "target stop-hook enable")));
5348 LoadSubCommand ("list", CommandObjectSP (new CommandObjectTargetStopHookList (interpreter)));
5349 }
5350
5351 ~CommandObjectMultiwordTargetStopHooks()
5352 {
5353 }
5354};
5355
5356
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005357
5358#pragma mark CommandObjectMultiwordTarget
5359
5360//-------------------------------------------------------------------------
5361// CommandObjectMultiwordTarget
5362//-------------------------------------------------------------------------
5363
Greg Clayton66111032010-06-23 01:19:29 +00005364CommandObjectMultiwordTarget::CommandObjectMultiwordTarget (CommandInterpreter &interpreter) :
Greg Claytona7015092010-09-18 01:14:36 +00005365 CommandObjectMultiword (interpreter,
5366 "target",
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005367 "A set of commands for operating on debugger targets.",
5368 "target <subcommand> [<subcommand-options>]")
5369{
Greg Clayton7260f622011-04-18 08:33:37 +00005370
5371 LoadSubCommand ("create", CommandObjectSP (new CommandObjectTargetCreate (interpreter)));
Greg Clayton3418c852011-08-10 02:10:13 +00005372 LoadSubCommand ("delete", CommandObjectSP (new CommandObjectTargetDelete (interpreter)));
Greg Clayton7260f622011-04-18 08:33:37 +00005373 LoadSubCommand ("list", CommandObjectSP (new CommandObjectTargetList (interpreter)));
5374 LoadSubCommand ("select", CommandObjectSP (new CommandObjectTargetSelect (interpreter)));
Jim Ingham9575d842011-03-11 03:53:59 +00005375 LoadSubCommand ("stop-hook", CommandObjectSP (new CommandObjectMultiwordTargetStopHooks (interpreter)));
Greg Claytoneffe5c92011-05-03 22:09:39 +00005376 LoadSubCommand ("modules", CommandObjectSP (new CommandObjectTargetModules (interpreter)));
Greg Claytone72dfb32012-02-24 01:59:29 +00005377 LoadSubCommand ("symbols", CommandObjectSP (new CommandObjectTargetSymbols (interpreter)));
Greg Clayton644247c2011-07-07 01:59:51 +00005378 LoadSubCommand ("variable", CommandObjectSP (new CommandObjectTargetVariable (interpreter)));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005379}
5380
5381CommandObjectMultiwordTarget::~CommandObjectMultiwordTarget ()
5382{
5383}
5384
Greg Clayton7260f622011-04-18 08:33:37 +00005385