blob: 9fdd51bf74042f35cb47fd9e7a460c0a138a85c5 [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();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +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));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +000072
Greg Clayton7260f622011-04-18 08:33:37 +000073 if (!exe_valid)
74 ::strcpy (exe_path, "<none>");
Saleem Abdulrasool324a1032014-04-04 04:06:10 +000075
Greg Clayton7260f622011-04-18 08:33:37 +000076 strm.Printf ("%starget #%u: %s", prefix_cstr ? prefix_cstr : "", target_idx, exe_path);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +000077
Greg Clayton7260f622011-04-18 08:33:37 +000078 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());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +000087
Greg Clayton7260f622011-04-18 08:33:37 +000088 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)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000126 {
Greg Clayton7260f622011-04-18 08:33:37 +0000127 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;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000170
Greg Clayton7260f622011-04-18 08:33:37 +0000171 // Define the first (and only) variant of this arg.
172 file_arg.arg_type = eArgTypeFilename;
173 file_arg.arg_repetition = eArgRepeatPlain;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000174
Greg Clayton7260f622011-04-18 08:33:37 +0000175 // There is only one variant this argument could be; put it into the argument entry.
176 arg.push_back (file_arg);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000177
Greg Clayton7260f622011-04-18 08:33:37 +0000178 // Push the data for the first argument into the m_arguments vector.
179 m_arguments.push_back (arg);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000180
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);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000213
Jim Ingham5a988412012-06-08 21:56:10 +0000214 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;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000251
Daniel Maleae0f8f572013-08-26 23:57:52 +0000252 if (file_path)
253 file_spec.SetFile (file_path, true);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000254
Daniel Maleae0f8f572013-08-26 23:57:52 +0000255 bool must_set_platform_path = false;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000256
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 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000337
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);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +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();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000363
Greg Claytonc859e2d2012-02-13 23:10:39 +0000364 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();
Greg Clayton7260f622011-04-18 08:33:37 +0000406 }
407
Greg Clayton7260f622011-04-18 08:33:37 +0000408private:
409 OptionGroupOptions m_option_group;
Greg Clayton644247c2011-07-07 01:59:51 +0000410 OptionGroupArchitecture m_arch_option;
Greg Clayton7260f622011-04-18 08:33:37 +0000411 OptionGroupPlatform m_platform_options;
Greg Claytonc3776bf2012-02-09 06:16:32 +0000412 OptionGroupFile m_core_file;
Daniel Maleae0f8f572013-08-26 23:57:52 +0000413 OptionGroupFile m_platform_path;
Greg Clayton1c5f1862012-11-30 19:05:35 +0000414 OptionGroupFile m_symbol_file;
Jim Inghambf22b962013-07-11 01:47:46 +0000415 OptionGroupFile m_remote_file;
Greg Clayton1c5f1862012-11-30 19:05:35 +0000416 OptionGroupBoolean m_add_dependents;
Greg Clayton7260f622011-04-18 08:33:37 +0000417};
418
419#pragma mark CommandObjectTargetList
420
421//----------------------------------------------------------------------
422// "target list"
423//----------------------------------------------------------------------
424
Jim Ingham5a988412012-06-08 21:56:10 +0000425class CommandObjectTargetList : public CommandObjectParsed
Greg Clayton7260f622011-04-18 08:33:37 +0000426{
427public:
428 CommandObjectTargetList (CommandInterpreter &interpreter) :
Jim Ingham5a988412012-06-08 21:56:10 +0000429 CommandObjectParsed (interpreter,
430 "target list",
431 "List all current targets in the current debug session.",
432 NULL,
433 0)
Greg Clayton7260f622011-04-18 08:33:37 +0000434 {
435 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000436
Greg Clayton7260f622011-04-18 08:33:37 +0000437 virtual
438 ~CommandObjectTargetList ()
439 {
440 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000441
Jim Ingham5a988412012-06-08 21:56:10 +0000442protected:
Greg Clayton7260f622011-04-18 08:33:37 +0000443 virtual bool
Jim Ingham5a988412012-06-08 21:56:10 +0000444 DoExecute (Args& args, CommandReturnObject &result)
Greg Clayton7260f622011-04-18 08:33:37 +0000445 {
446 if (args.GetArgumentCount() == 0)
447 {
448 Stream &strm = result.GetOutputStream();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000449
Greg Clayton7260f622011-04-18 08:33:37 +0000450 bool show_stopped_process_status = false;
451 if (DumpTargetList (m_interpreter.GetDebugger().GetTargetList(), show_stopped_process_status, strm) == 0)
452 {
453 strm.PutCString ("No targets.\n");
454 }
Johnny Chen1ee61a72011-04-18 21:08:05 +0000455 result.SetStatus (eReturnStatusSuccessFinishResult);
Greg Clayton7260f622011-04-18 08:33:37 +0000456 }
457 else
458 {
459 result.AppendError ("the 'target list' command takes no arguments\n");
460 result.SetStatus (eReturnStatusFailed);
461 }
462 return result.Succeeded();
463 }
464};
465
466
467#pragma mark CommandObjectTargetSelect
468
469//----------------------------------------------------------------------
470// "target select"
471//----------------------------------------------------------------------
472
Jim Ingham5a988412012-06-08 21:56:10 +0000473class CommandObjectTargetSelect : public CommandObjectParsed
Greg Clayton7260f622011-04-18 08:33:37 +0000474{
475public:
476 CommandObjectTargetSelect (CommandInterpreter &interpreter) :
Jim Ingham5a988412012-06-08 21:56:10 +0000477 CommandObjectParsed (interpreter,
478 "target select",
479 "Select a target as the current target by target index.",
480 NULL,
481 0)
Greg Clayton7260f622011-04-18 08:33:37 +0000482 {
483 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000484
Greg Clayton7260f622011-04-18 08:33:37 +0000485 virtual
486 ~CommandObjectTargetSelect ()
487 {
488 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000489
Jim Ingham5a988412012-06-08 21:56:10 +0000490protected:
Greg Clayton7260f622011-04-18 08:33:37 +0000491 virtual bool
Jim Ingham5a988412012-06-08 21:56:10 +0000492 DoExecute (Args& args, CommandReturnObject &result)
Greg Clayton7260f622011-04-18 08:33:37 +0000493 {
494 if (args.GetArgumentCount() == 1)
495 {
496 bool success = false;
497 const char *target_idx_arg = args.GetArgumentAtIndex(0);
498 uint32_t target_idx = Args::StringToUInt32 (target_idx_arg, UINT32_MAX, 0, &success);
499 if (success)
500 {
501 TargetList &target_list = m_interpreter.GetDebugger().GetTargetList();
502 const uint32_t num_targets = target_list.GetNumTargets();
503 if (target_idx < num_targets)
504 {
505 TargetSP target_sp (target_list.GetTargetAtIndex (target_idx));
506 if (target_sp)
507 {
508 Stream &strm = result.GetOutputStream();
509 target_list.SetSelectedTarget (target_sp.get());
510 bool show_stopped_process_status = false;
511 DumpTargetList (target_list, show_stopped_process_status, strm);
Johnny Chen1ee61a72011-04-18 21:08:05 +0000512 result.SetStatus (eReturnStatusSuccessFinishResult);
Greg Clayton7260f622011-04-18 08:33:37 +0000513 }
514 else
515 {
516 result.AppendErrorWithFormat ("target #%u is NULL in target list\n", target_idx);
517 result.SetStatus (eReturnStatusFailed);
518 }
519 }
520 else
521 {
522 result.AppendErrorWithFormat ("index %u is out of range, valid target indexes are 0 - %u\n",
523 target_idx,
524 num_targets - 1);
525 result.SetStatus (eReturnStatusFailed);
526 }
527 }
528 else
529 {
530 result.AppendErrorWithFormat("invalid index string value '%s'\n", target_idx_arg);
531 result.SetStatus (eReturnStatusFailed);
532 }
533 }
534 else
535 {
536 result.AppendError ("'target select' takes a single argument: a target index\n");
537 result.SetStatus (eReturnStatusFailed);
538 }
539 return result.Succeeded();
540 }
541};
542
Greg Clayton3418c852011-08-10 02:10:13 +0000543#pragma mark CommandObjectTargetSelect
544
545//----------------------------------------------------------------------
546// "target delete"
547//----------------------------------------------------------------------
548
Jim Ingham5a988412012-06-08 21:56:10 +0000549class CommandObjectTargetDelete : public CommandObjectParsed
Greg Clayton3418c852011-08-10 02:10:13 +0000550{
551public:
552 CommandObjectTargetDelete (CommandInterpreter &interpreter) :
Jim Ingham5a988412012-06-08 21:56:10 +0000553 CommandObjectParsed (interpreter,
554 "target delete",
555 "Delete one or more targets by target index.",
556 NULL,
557 0),
Greg Claytonaa149cb2011-08-11 02:48:45 +0000558 m_option_group (interpreter),
Greg Claytonb5f0fea2012-09-27 22:26:11 +0000559 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 +0000560 {
Greg Claytonaa149cb2011-08-11 02:48:45 +0000561 m_option_group.Append (&m_cleanup_option, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
562 m_option_group.Finalize();
Greg Clayton3418c852011-08-10 02:10:13 +0000563 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000564
Greg Clayton3418c852011-08-10 02:10:13 +0000565 virtual
566 ~CommandObjectTargetDelete ()
567 {
568 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000569
Jim Ingham5a988412012-06-08 21:56:10 +0000570 Options *
571 GetOptions ()
572 {
573 return &m_option_group;
574 }
575
576protected:
Greg Clayton3418c852011-08-10 02:10:13 +0000577 virtual bool
Jim Ingham5a988412012-06-08 21:56:10 +0000578 DoExecute (Args& args, CommandReturnObject &result)
Greg Clayton3418c852011-08-10 02:10:13 +0000579 {
580 const size_t argc = args.GetArgumentCount();
581 std::vector<TargetSP> delete_target_list;
582 TargetList &target_list = m_interpreter.GetDebugger().GetTargetList();
583 bool success = true;
584 TargetSP target_sp;
585 if (argc > 0)
586 {
587 const uint32_t num_targets = target_list.GetNumTargets();
Filipe Cabecinhasf065fdc2012-07-09 13:02:17 +0000588 // Bail out if don't have any targets.
589 if (num_targets == 0) {
590 result.AppendError("no targets to delete");
591 result.SetStatus(eReturnStatusFailed);
592 success = false;
593 }
594
Greg Clayton3418c852011-08-10 02:10:13 +0000595 for (uint32_t arg_idx = 0; success && arg_idx < argc; ++arg_idx)
596 {
597 const char *target_idx_arg = args.GetArgumentAtIndex(arg_idx);
598 uint32_t target_idx = Args::StringToUInt32 (target_idx_arg, UINT32_MAX, 0, &success);
599 if (success)
600 {
601 if (target_idx < num_targets)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000602 {
Greg Clayton3418c852011-08-10 02:10:13 +0000603 target_sp = target_list.GetTargetAtIndex (target_idx);
604 if (target_sp)
605 {
606 delete_target_list.push_back (target_sp);
607 continue;
608 }
609 }
Filipe Cabecinhasf065fdc2012-07-09 13:02:17 +0000610 if (num_targets > 1)
611 result.AppendErrorWithFormat ("target index %u is out of range, valid target indexes are 0 - %u\n",
612 target_idx,
613 num_targets - 1);
614 else
615 result.AppendErrorWithFormat("target index %u is out of range, the only valid index is 0\n",
616 target_idx);
617
Greg Clayton3418c852011-08-10 02:10:13 +0000618 result.SetStatus (eReturnStatusFailed);
619 success = false;
620 }
621 else
622 {
623 result.AppendErrorWithFormat("invalid target index '%s'\n", target_idx_arg);
624 result.SetStatus (eReturnStatusFailed);
625 success = false;
626 }
627 }
Greg Clayton3418c852011-08-10 02:10:13 +0000628 }
629 else
630 {
631 target_sp = target_list.GetSelectedTarget();
632 if (target_sp)
633 {
634 delete_target_list.push_back (target_sp);
635 }
636 else
637 {
638 result.AppendErrorWithFormat("no target is currently selected\n");
639 result.SetStatus (eReturnStatusFailed);
640 success = false;
641 }
642 }
643 if (success)
644 {
645 const size_t num_targets_to_delete = delete_target_list.size();
646 for (size_t idx = 0; idx < num_targets_to_delete; ++idx)
647 {
648 target_sp = delete_target_list[idx];
649 target_list.DeleteTarget(target_sp);
650 target_sp->Destroy();
651 }
Greg Claytonaa149cb2011-08-11 02:48:45 +0000652 // If "--clean" was specified, prune any orphaned shared modules from
653 // the global shared module list
654 if (m_cleanup_option.GetOptionValue ())
655 {
Greg Clayton0cd70862012-04-09 20:22:01 +0000656 const bool mandatory = true;
657 ModuleList::RemoveOrphanSharedModules(mandatory);
Greg Claytonaa149cb2011-08-11 02:48:45 +0000658 }
Greg Clayton3418c852011-08-10 02:10:13 +0000659 result.GetOutputStream().Printf("%u targets deleted.\n", (uint32_t)num_targets_to_delete);
660 result.SetStatus(eReturnStatusSuccessFinishResult);
661 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000662
Greg Clayton3418c852011-08-10 02:10:13 +0000663 return result.Succeeded();
664 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000665
Greg Claytonaa149cb2011-08-11 02:48:45 +0000666 OptionGroupOptions m_option_group;
667 OptionGroupBoolean m_cleanup_option;
Greg Clayton3418c852011-08-10 02:10:13 +0000668};
669
Greg Clayton7260f622011-04-18 08:33:37 +0000670
Greg Clayton644247c2011-07-07 01:59:51 +0000671#pragma mark CommandObjectTargetVariable
672
673//----------------------------------------------------------------------
674// "target variable"
675//----------------------------------------------------------------------
676
Jim Ingham5a988412012-06-08 21:56:10 +0000677class CommandObjectTargetVariable : public CommandObjectParsed
Greg Clayton644247c2011-07-07 01:59:51 +0000678{
Saleem Abdulrasool44edda02014-03-18 04:43:47 +0000679 static const uint32_t SHORT_OPTION_FILE = 0x66696c65; // 'file'
680 static const uint32_t SHORT_OPTION_SHLB = 0x73686c62; // 'shlb'
681
Greg Clayton644247c2011-07-07 01:59:51 +0000682public:
683 CommandObjectTargetVariable (CommandInterpreter &interpreter) :
Jim Ingham5a988412012-06-08 21:56:10 +0000684 CommandObjectParsed (interpreter,
685 "target variable",
Greg Claytondfdd1eb2012-11-03 00:10:22 +0000686 "Read global variable(s) prior to, or while running your binary.",
Jim Ingham5a988412012-06-08 21:56:10 +0000687 NULL,
Greg Claytonf9fc6092013-01-09 19:44:40 +0000688 eFlagRequiresTarget),
Greg Clayton644247c2011-07-07 01:59:51 +0000689 m_option_group (interpreter),
Greg Clayton715c2362011-07-07 04:38:25 +0000690 m_option_variable (false), // Don't include frame options
Greg Clayton1deb7962011-10-25 06:44:01 +0000691 m_option_format (eFormatDefault),
Saleem Abdulrasool44edda02014-03-18 04:43:47 +0000692 m_option_compile_units (LLDB_OPT_SET_1, false, "file",
693 SHORT_OPTION_FILE, 0, eArgTypeFilename,
694 "A basename or fullpath to a file that contains global variables. This option can be specified multiple times."),
695 m_option_shared_libraries (LLDB_OPT_SET_1, false, "shlib",
696 SHORT_OPTION_SHLB, 0, eArgTypeFilename,
697 "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 +0000698 m_varobj_options()
699 {
Johnny Chen81ab3f52011-08-22 22:22:00 +0000700 CommandArgumentEntry arg;
701 CommandArgumentData var_name_arg;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000702
Johnny Chen81ab3f52011-08-22 22:22:00 +0000703 // Define the first (and only) variant of this arg.
704 var_name_arg.arg_type = eArgTypeVarName;
705 var_name_arg.arg_repetition = eArgRepeatPlus;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000706
Johnny Chen81ab3f52011-08-22 22:22:00 +0000707 // There is only one variant this argument could be; put it into the argument entry.
708 arg.push_back (var_name_arg);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000709
Johnny Chen81ab3f52011-08-22 22:22:00 +0000710 // Push the data for the first argument into the m_arguments vector.
711 m_arguments.push_back (arg);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000712
Greg Clayton644247c2011-07-07 01:59:51 +0000713 m_option_group.Append (&m_varobj_options, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
Greg Clayton715c2362011-07-07 04:38:25 +0000714 m_option_group.Append (&m_option_variable, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
Greg Clayton5009f9d2011-10-27 17:55:14 +0000715 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 +0000716 m_option_group.Append (&m_option_compile_units, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
717 m_option_group.Append (&m_option_shared_libraries, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
718 m_option_group.Finalize();
719 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000720
Greg Clayton644247c2011-07-07 01:59:51 +0000721 virtual
722 ~CommandObjectTargetVariable ()
723 {
724 }
Greg Clayton884fb692011-07-08 21:46:14 +0000725
726 void
727 DumpValueObject (Stream &s, VariableSP &var_sp, ValueObjectSP &valobj_sp, const char *root_name)
728 {
Enrico Granata4d93b8c2013-09-30 19:11:51 +0000729 DumpValueObjectOptions options(m_varobj_options.GetAsDumpOptions());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000730
Greg Clayton884fb692011-07-08 21:46:14 +0000731 switch (var_sp->GetScope())
732 {
733 case eValueTypeVariableGlobal:
734 if (m_option_variable.show_scope)
735 s.PutCString("GLOBAL: ");
736 break;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000737
Greg Clayton884fb692011-07-08 21:46:14 +0000738 case eValueTypeVariableStatic:
739 if (m_option_variable.show_scope)
740 s.PutCString("STATIC: ");
741 break;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000742
Greg Clayton884fb692011-07-08 21:46:14 +0000743 case eValueTypeVariableArgument:
744 if (m_option_variable.show_scope)
745 s.PutCString(" ARG: ");
746 break;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000747
Greg Clayton884fb692011-07-08 21:46:14 +0000748 case eValueTypeVariableLocal:
749 if (m_option_variable.show_scope)
750 s.PutCString(" LOCAL: ");
751 break;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000752
Greg Clayton884fb692011-07-08 21:46:14 +0000753 default:
754 break;
755 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000756
Greg Clayton45ba8542011-07-10 19:21:23 +0000757 if (m_option_variable.show_decl)
Greg Clayton884fb692011-07-08 21:46:14 +0000758 {
Greg Clayton45ba8542011-07-10 19:21:23 +0000759 bool show_fullpaths = false;
760 bool show_module = true;
761 if (var_sp->DumpDeclaration(&s, show_fullpaths, show_module))
762 s.PutCString (": ");
Greg Clayton884fb692011-07-08 21:46:14 +0000763 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000764
Greg Clayton1deb7962011-10-25 06:44:01 +0000765 const Format format = m_option_format.GetFormat();
Greg Clayton884fb692011-07-08 21:46:14 +0000766 if (format != eFormatDefault)
Enrico Granata0c489f52012-03-01 04:24:26 +0000767 options.SetFormat(format);
768
769 options.SetRootValueObjectName(root_name);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000770
Enrico Granata4d93b8c2013-09-30 19:11:51 +0000771 valobj_sp->Dump(s,options);
Greg Clayton884fb692011-07-08 21:46:14 +0000772 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000773
Greg Claytonc7bece562013-01-25 18:06:21 +0000774 static size_t GetVariableCallback (void *baton,
775 const char *name,
776 VariableList &variable_list)
Greg Clayton884fb692011-07-08 21:46:14 +0000777 {
778 Target *target = static_cast<Target *>(baton);
779 if (target)
780 {
781 return target->GetImages().FindGlobalVariables (ConstString(name),
782 true,
783 UINT32_MAX,
784 variable_list);
785 }
786 return 0;
787 }
Greg Clayton884fb692011-07-08 21:46:14 +0000788
Jim Ingham5a988412012-06-08 21:56:10 +0000789 Options *
790 GetOptions ()
791 {
792 return &m_option_group;
793 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000794
Jim Ingham5a988412012-06-08 21:56:10 +0000795protected:
Greg Clayton3bcdfc02012-12-04 00:32:51 +0000796 void
797 DumpGlobalVariableList(const ExecutionContext &exe_ctx, const SymbolContext &sc, const VariableList &variable_list, Stream &s)
798 {
799 size_t count = variable_list.GetSize();
800 if (count > 0)
801 {
802 if (sc.module_sp)
803 {
804 if (sc.comp_unit)
805 {
Greg Claytonb5ad4ec2013-04-29 17:25:54 +0000806 s.Printf ("Global variables for %s in %s:\n",
807 sc.comp_unit->GetPath().c_str(),
808 sc.module_sp->GetFileSpec().GetPath().c_str());
Greg Clayton3bcdfc02012-12-04 00:32:51 +0000809 }
810 else
811 {
Greg Claytonb5ad4ec2013-04-29 17:25:54 +0000812 s.Printf ("Global variables for %s\n",
813 sc.module_sp->GetFileSpec().GetPath().c_str());
Greg Clayton3bcdfc02012-12-04 00:32:51 +0000814 }
815 }
816 else if (sc.comp_unit)
817 {
Greg Claytonb5ad4ec2013-04-29 17:25:54 +0000818 s.Printf ("Global variables for %s\n",
819 sc.comp_unit->GetPath().c_str());
Greg Clayton3bcdfc02012-12-04 00:32:51 +0000820 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000821
Greg Clayton3bcdfc02012-12-04 00:32:51 +0000822 for (uint32_t i=0; i<count; ++i)
823 {
824 VariableSP var_sp (variable_list.GetVariableAtIndex(i));
825 if (var_sp)
826 {
827 ValueObjectSP valobj_sp (ValueObjectVariable::Create (exe_ctx.GetBestExecutionContextScope(), var_sp));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000828
Greg Clayton3bcdfc02012-12-04 00:32:51 +0000829 if (valobj_sp)
830 DumpValueObject (s, var_sp, valobj_sp, var_sp->GetName().GetCString());
831 }
832 }
833 }
834
835 }
Greg Clayton644247c2011-07-07 01:59:51 +0000836 virtual bool
Jim Ingham5a988412012-06-08 21:56:10 +0000837 DoExecute (Args& args, CommandReturnObject &result)
Greg Clayton644247c2011-07-07 01:59:51 +0000838 {
Greg Claytonf9fc6092013-01-09 19:44:40 +0000839 Target *target = m_exe_ctx.GetTargetPtr();
840 const size_t argc = args.GetArgumentCount();
841 Stream &s = result.GetOutputStream();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000842
Greg Claytonf9fc6092013-01-09 19:44:40 +0000843 if (argc > 0)
Greg Clayton644247c2011-07-07 01:59:51 +0000844 {
Greg Claytonf9fc6092013-01-09 19:44:40 +0000845
846 for (size_t idx = 0; idx < argc; ++idx)
Greg Clayton644247c2011-07-07 01:59:51 +0000847 {
Greg Claytonf9fc6092013-01-09 19:44:40 +0000848 VariableList variable_list;
849 ValueObjectList valobj_list;
Greg Clayton884fb692011-07-08 21:46:14 +0000850
Greg Claytonf9fc6092013-01-09 19:44:40 +0000851 const char *arg = args.GetArgumentAtIndex(idx);
Greg Claytonc7bece562013-01-25 18:06:21 +0000852 size_t matches = 0;
Greg Claytonf9fc6092013-01-09 19:44:40 +0000853 bool use_var_name = false;
854 if (m_option_variable.use_regex)
Greg Clayton644247c2011-07-07 01:59:51 +0000855 {
Greg Claytonf9fc6092013-01-09 19:44:40 +0000856 RegularExpression regex(arg);
857 if (!regex.IsValid ())
Greg Clayton644247c2011-07-07 01:59:51 +0000858 {
Greg Claytonf9fc6092013-01-09 19:44:40 +0000859 result.GetErrorStream().Printf ("error: invalid regular expression: '%s'\n", arg);
Greg Clayton715c2362011-07-07 04:38:25 +0000860 result.SetStatus (eReturnStatusFailed);
861 return false;
862 }
Greg Claytonf9fc6092013-01-09 19:44:40 +0000863 use_var_name = true;
864 matches = target->GetImages().FindGlobalVariables (regex,
865 true,
866 UINT32_MAX,
867 variable_list);
Greg Clayton3bcdfc02012-12-04 00:32:51 +0000868 }
869 else
870 {
Greg Claytonf9fc6092013-01-09 19:44:40 +0000871 Error error (Variable::GetValuesForVariableExpressionPath (arg,
872 m_exe_ctx.GetBestExecutionContextScope(),
873 GetVariableCallback,
874 target,
875 variable_list,
876 valobj_list));
877 matches = variable_list.GetSize();
878 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000879
Greg Claytonf9fc6092013-01-09 19:44:40 +0000880 if (matches == 0)
881 {
882 result.GetErrorStream().Printf ("error: can't find global variable '%s'\n", arg);
883 result.SetStatus (eReturnStatusFailed);
884 return false;
885 }
886 else
887 {
888 for (uint32_t global_idx=0; global_idx<matches; ++global_idx)
Greg Clayton3bcdfc02012-12-04 00:32:51 +0000889 {
Greg Claytonf9fc6092013-01-09 19:44:40 +0000890 VariableSP var_sp (variable_list.GetVariableAtIndex(global_idx));
891 if (var_sp)
Greg Clayton3bcdfc02012-12-04 00:32:51 +0000892 {
Greg Claytonf9fc6092013-01-09 19:44:40 +0000893 ValueObjectSP valobj_sp (valobj_list.GetValueObjectAtIndex(global_idx));
894 if (!valobj_sp)
895 valobj_sp = ValueObjectVariable::Create (m_exe_ctx.GetBestExecutionContextScope(), var_sp);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000896
Greg Claytonf9fc6092013-01-09 19:44:40 +0000897 if (valobj_sp)
898 DumpValueObject (s, var_sp, valobj_sp, use_var_name ? var_sp->GetName().GetCString() : arg);
Greg Clayton3bcdfc02012-12-04 00:32:51 +0000899 }
900 }
Greg Clayton9a5a9342011-10-05 22:17:32 +0000901 }
Greg Clayton644247c2011-07-07 01:59:51 +0000902 }
903 }
904 else
905 {
Greg Claytonf9fc6092013-01-09 19:44:40 +0000906 const FileSpecList &compile_units = m_option_compile_units.GetOptionValue().GetCurrentValue();
907 const FileSpecList &shlibs = m_option_shared_libraries.GetOptionValue().GetCurrentValue();
908 SymbolContextList sc_list;
909 const size_t num_compile_units = compile_units.GetSize();
910 const size_t num_shlibs = shlibs.GetSize();
911 if (num_compile_units == 0 && num_shlibs == 0)
912 {
913 bool success = false;
Jason Molendab57e4a12013-11-04 09:33:30 +0000914 StackFrame *frame = m_exe_ctx.GetFramePtr();
Greg Claytonf9fc6092013-01-09 19:44:40 +0000915 CompileUnit *comp_unit = NULL;
916 if (frame)
917 {
918 SymbolContext sc = frame->GetSymbolContext (eSymbolContextCompUnit);
919 if (sc.comp_unit)
920 {
921 const bool can_create = true;
922 VariableListSP comp_unit_varlist_sp (sc.comp_unit->GetVariableList(can_create));
923 if (comp_unit_varlist_sp)
924 {
925 size_t count = comp_unit_varlist_sp->GetSize();
926 if (count > 0)
927 {
928 DumpGlobalVariableList(m_exe_ctx, sc, *comp_unit_varlist_sp, s);
929 success = true;
930 }
931 }
932 }
933 }
934 if (!success)
935 {
936 if (frame)
937 {
938 if (comp_unit)
Greg Claytonb5ad4ec2013-04-29 17:25:54 +0000939 result.AppendErrorWithFormat ("no global variables in current compile unit: %s\n",
940 comp_unit->GetPath().c_str());
Greg Claytonf9fc6092013-01-09 19:44:40 +0000941 else
942 result.AppendErrorWithFormat ("no debug information for frame %u\n", frame->GetFrameIndex());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000943 }
Greg Claytonf9fc6092013-01-09 19:44:40 +0000944 else
945 result.AppendError ("'target variable' takes one or more global variable names as arguments\n");
946 result.SetStatus (eReturnStatusFailed);
947 }
948 }
949 else
950 {
951 SymbolContextList sc_list;
952 const bool append = true;
953 // We have one or more compile unit or shlib
954 if (num_shlibs > 0)
955 {
956 for (size_t shlib_idx=0; shlib_idx<num_shlibs; ++shlib_idx)
957 {
958 const FileSpec module_file(shlibs.GetFileSpecAtIndex(shlib_idx));
959 ModuleSpec module_spec (module_file);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000960
Greg Claytonf9fc6092013-01-09 19:44:40 +0000961 ModuleSP module_sp (target->GetImages().FindFirstModule(module_spec));
962 if (module_sp)
963 {
964 if (num_compile_units > 0)
965 {
966 for (size_t cu_idx=0; cu_idx<num_compile_units; ++cu_idx)
967 module_sp->FindCompileUnits(compile_units.GetFileSpecAtIndex(cu_idx), append, sc_list);
968 }
969 else
970 {
971 SymbolContext sc;
972 sc.module_sp = module_sp;
973 sc_list.Append(sc);
974 }
975 }
976 else
977 {
978 // Didn't find matching shlib/module in target...
Greg Claytonb5ad4ec2013-04-29 17:25:54 +0000979 result.AppendErrorWithFormat ("target doesn't contain the specified shared library: %s\n",
980 module_file.GetPath().c_str());
Greg Claytonf9fc6092013-01-09 19:44:40 +0000981 }
982 }
983 }
984 else
985 {
986 // No shared libraries, we just want to find globals for the compile units files that were specified
987 for (size_t cu_idx=0; cu_idx<num_compile_units; ++cu_idx)
988 target->GetImages().FindCompileUnits(compile_units.GetFileSpecAtIndex(cu_idx), append, sc_list);
989 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000990
Greg Claytonf9fc6092013-01-09 19:44:40 +0000991 const uint32_t num_scs = sc_list.GetSize();
992 if (num_scs > 0)
993 {
994 SymbolContext sc;
995 for (uint32_t sc_idx=0; sc_idx<num_scs; ++sc_idx)
996 {
997 if (sc_list.GetContextAtIndex(sc_idx, sc))
998 {
999 if (sc.comp_unit)
1000 {
1001 const bool can_create = true;
1002 VariableListSP comp_unit_varlist_sp (sc.comp_unit->GetVariableList(can_create));
1003 if (comp_unit_varlist_sp)
1004 DumpGlobalVariableList(m_exe_ctx, sc, *comp_unit_varlist_sp, s);
1005 }
1006 else if (sc.module_sp)
1007 {
1008 // Get all global variables for this module
1009 lldb_private::RegularExpression all_globals_regex("."); // Any global with at least one character
1010 VariableList variable_list;
1011 sc.module_sp->FindGlobalVariables(all_globals_regex, append, UINT32_MAX, variable_list);
1012 DumpGlobalVariableList(m_exe_ctx, sc, variable_list, s);
1013 }
1014 }
1015 }
1016 }
1017 }
Greg Clayton644247c2011-07-07 01:59:51 +00001018 }
Greg Claytonf9fc6092013-01-09 19:44:40 +00001019
Enrico Granata61a80ba2011-08-12 16:42:31 +00001020 if (m_interpreter.TruncationWarningNecessary())
1021 {
1022 result.GetOutputStream().Printf(m_interpreter.TruncationWarningText(),
1023 m_cmd_name.c_str());
1024 m_interpreter.TruncationWarningGiven();
1025 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001026
Greg Clayton644247c2011-07-07 01:59:51 +00001027 return result.Succeeded();
1028 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001029
Greg Clayton644247c2011-07-07 01:59:51 +00001030 OptionGroupOptions m_option_group;
Greg Clayton715c2362011-07-07 04:38:25 +00001031 OptionGroupVariable m_option_variable;
Greg Clayton1deb7962011-10-25 06:44:01 +00001032 OptionGroupFormat m_option_format;
Greg Clayton644247c2011-07-07 01:59:51 +00001033 OptionGroupFileList m_option_compile_units;
1034 OptionGroupFileList m_option_shared_libraries;
1035 OptionGroupValueObjectDisplay m_varobj_options;
1036
1037};
1038
1039
Greg Claytoneffe5c92011-05-03 22:09:39 +00001040#pragma mark CommandObjectTargetModulesSearchPathsAdd
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001041
Jim Ingham5a988412012-06-08 21:56:10 +00001042class CommandObjectTargetModulesSearchPathsAdd : public CommandObjectParsed
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001043{
1044public:
1045
Greg Claytoneffe5c92011-05-03 22:09:39 +00001046 CommandObjectTargetModulesSearchPathsAdd (CommandInterpreter &interpreter) :
Jim Ingham5a988412012-06-08 21:56:10 +00001047 CommandObjectParsed (interpreter,
1048 "target modules search-paths add",
1049 "Add new image search paths substitution pairs to the current target.",
1050 NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001051 {
Caroline Tice405fe672010-10-04 22:28:36 +00001052 CommandArgumentEntry arg;
1053 CommandArgumentData old_prefix_arg;
1054 CommandArgumentData new_prefix_arg;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001055
Caroline Tice405fe672010-10-04 22:28:36 +00001056 // Define the first variant of this arg pair.
1057 old_prefix_arg.arg_type = eArgTypeOldPathPrefix;
1058 old_prefix_arg.arg_repetition = eArgRepeatPairPlus;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001059
Caroline Tice405fe672010-10-04 22:28:36 +00001060 // Define the first variant of this arg pair.
1061 new_prefix_arg.arg_type = eArgTypeNewPathPrefix;
1062 new_prefix_arg.arg_repetition = eArgRepeatPairPlus;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001063
Caroline Tice405fe672010-10-04 22:28:36 +00001064 // There are two required arguments that must always occur together, i.e. an argument "pair". Because they
1065 // must always occur together, they are treated as two variants of one argument rather than two independent
1066 // arguments. Push them both into the first argument position for m_arguments...
1067
1068 arg.push_back (old_prefix_arg);
1069 arg.push_back (new_prefix_arg);
1070
1071 m_arguments.push_back (arg);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001072 }
1073
Greg Claytoneffe5c92011-05-03 22:09:39 +00001074 ~CommandObjectTargetModulesSearchPathsAdd ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001075 {
1076 }
1077
Jim Ingham5a988412012-06-08 21:56:10 +00001078protected:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001079 bool
Jim Ingham5a988412012-06-08 21:56:10 +00001080 DoExecute (Args& command,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001081 CommandReturnObject &result)
1082 {
Greg Claytona7015092010-09-18 01:14:36 +00001083 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001084 if (target)
1085 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001086 const size_t argc = command.GetArgumentCount();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001087 if (argc & 1)
1088 {
Greg Clayton7260f622011-04-18 08:33:37 +00001089 result.AppendError ("add requires an even number of arguments\n");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001090 result.SetStatus (eReturnStatusFailed);
1091 }
1092 else
1093 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001094 for (size_t i=0; i<argc; i+=2)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001095 {
1096 const char *from = command.GetArgumentAtIndex(i);
1097 const char *to = command.GetArgumentAtIndex(i+1);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001098
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001099 if (from[0] && to[0])
1100 {
1101 bool last_pair = ((argc - i) == 2);
Greg Clayton66111032010-06-23 01:19:29 +00001102 target->GetImageSearchPathList().Append (ConstString(from),
1103 ConstString(to),
1104 last_pair); // Notify if this is the last pair
Johnny Chen7791b332011-02-03 00:30:19 +00001105 result.SetStatus (eReturnStatusSuccessFinishNoResult);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001106 }
1107 else
1108 {
1109 if (from[0])
Greg Clayton7260f622011-04-18 08:33:37 +00001110 result.AppendError ("<path-prefix> can't be empty\n");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001111 else
Greg Clayton7260f622011-04-18 08:33:37 +00001112 result.AppendError ("<new-path-prefix> can't be empty\n");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001113 result.SetStatus (eReturnStatusFailed);
1114 }
1115 }
1116 }
1117 }
1118 else
1119 {
Greg Clayton7260f622011-04-18 08:33:37 +00001120 result.AppendError ("invalid target\n");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001121 result.SetStatus (eReturnStatusFailed);
1122 }
1123 return result.Succeeded();
1124 }
1125};
1126
Greg Claytoneffe5c92011-05-03 22:09:39 +00001127#pragma mark CommandObjectTargetModulesSearchPathsClear
1128
Jim Ingham5a988412012-06-08 21:56:10 +00001129class CommandObjectTargetModulesSearchPathsClear : public CommandObjectParsed
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001130{
1131public:
1132
Greg Claytoneffe5c92011-05-03 22:09:39 +00001133 CommandObjectTargetModulesSearchPathsClear (CommandInterpreter &interpreter) :
Jim Ingham5a988412012-06-08 21:56:10 +00001134 CommandObjectParsed (interpreter,
1135 "target modules search-paths clear",
1136 "Clear all current image search path substitution pairs from the current target.",
1137 "target modules search-paths clear")
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001138 {
1139 }
1140
Greg Claytoneffe5c92011-05-03 22:09:39 +00001141 ~CommandObjectTargetModulesSearchPathsClear ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001142 {
1143 }
1144
Jim Ingham5a988412012-06-08 21:56:10 +00001145protected:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001146 bool
Jim Ingham5a988412012-06-08 21:56:10 +00001147 DoExecute (Args& command,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001148 CommandReturnObject &result)
1149 {
Greg Claytona7015092010-09-18 01:14:36 +00001150 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001151 if (target)
1152 {
1153 bool notify = true;
1154 target->GetImageSearchPathList().Clear(notify);
Johnny Chen7791b332011-02-03 00:30:19 +00001155 result.SetStatus (eReturnStatusSuccessFinishNoResult);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001156 }
1157 else
1158 {
Greg Clayton7260f622011-04-18 08:33:37 +00001159 result.AppendError ("invalid target\n");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001160 result.SetStatus (eReturnStatusFailed);
1161 }
1162 return result.Succeeded();
1163 }
1164};
1165
Greg Claytoneffe5c92011-05-03 22:09:39 +00001166#pragma mark CommandObjectTargetModulesSearchPathsInsert
1167
Jim Ingham5a988412012-06-08 21:56:10 +00001168class CommandObjectTargetModulesSearchPathsInsert : public CommandObjectParsed
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001169{
1170public:
1171
Greg Claytoneffe5c92011-05-03 22:09:39 +00001172 CommandObjectTargetModulesSearchPathsInsert (CommandInterpreter &interpreter) :
Jim Ingham5a988412012-06-08 21:56:10 +00001173 CommandObjectParsed (interpreter,
1174 "target modules search-paths insert",
1175 "Insert a new image search path substitution pair into the current target at the specified index.",
1176 NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001177 {
Caroline Tice405fe672010-10-04 22:28:36 +00001178 CommandArgumentEntry arg1;
1179 CommandArgumentEntry arg2;
1180 CommandArgumentData index_arg;
1181 CommandArgumentData old_prefix_arg;
1182 CommandArgumentData new_prefix_arg;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001183
Caroline Tice405fe672010-10-04 22:28:36 +00001184 // Define the first and only variant of this arg.
1185 index_arg.arg_type = eArgTypeIndex;
1186 index_arg.arg_repetition = eArgRepeatPlain;
1187
1188 // Put the one and only variant into the first arg for m_arguments:
1189 arg1.push_back (index_arg);
1190
1191 // Define the first variant of this arg pair.
1192 old_prefix_arg.arg_type = eArgTypeOldPathPrefix;
1193 old_prefix_arg.arg_repetition = eArgRepeatPairPlus;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001194
Caroline Tice405fe672010-10-04 22:28:36 +00001195 // Define the first variant of this arg pair.
1196 new_prefix_arg.arg_type = eArgTypeNewPathPrefix;
1197 new_prefix_arg.arg_repetition = eArgRepeatPairPlus;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001198
Caroline Tice405fe672010-10-04 22:28:36 +00001199 // There are two required arguments that must always occur together, i.e. an argument "pair". Because they
1200 // must always occur together, they are treated as two variants of one argument rather than two independent
1201 // arguments. Push them both into the same argument position for m_arguments...
1202
1203 arg2.push_back (old_prefix_arg);
1204 arg2.push_back (new_prefix_arg);
1205
1206 // Add arguments to m_arguments.
1207 m_arguments.push_back (arg1);
1208 m_arguments.push_back (arg2);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001209 }
1210
Greg Claytoneffe5c92011-05-03 22:09:39 +00001211 ~CommandObjectTargetModulesSearchPathsInsert ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001212 {
1213 }
1214
Jim Ingham5a988412012-06-08 21:56:10 +00001215protected:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001216 bool
Jim Ingham5a988412012-06-08 21:56:10 +00001217 DoExecute (Args& command,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001218 CommandReturnObject &result)
1219 {
Greg Claytona7015092010-09-18 01:14:36 +00001220 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001221 if (target)
1222 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001223 size_t argc = command.GetArgumentCount();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001224 // check for at least 3 arguments and an odd nubmer of parameters
1225 if (argc >= 3 && argc & 1)
1226 {
1227 bool success = false;
1228
1229 uint32_t insert_idx = Args::StringToUInt32(command.GetArgumentAtIndex(0), UINT32_MAX, 0, &success);
1230
1231 if (!success)
1232 {
1233 result.AppendErrorWithFormat("<index> parameter is not an integer: '%s'.\n", command.GetArgumentAtIndex(0));
1234 result.SetStatus (eReturnStatusFailed);
1235 return result.Succeeded();
1236 }
1237
1238 // shift off the index
1239 command.Shift();
1240 argc = command.GetArgumentCount();
1241
1242 for (uint32_t i=0; i<argc; i+=2, ++insert_idx)
1243 {
1244 const char *from = command.GetArgumentAtIndex(i);
1245 const char *to = command.GetArgumentAtIndex(i+1);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001246
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001247 if (from[0] && to[0])
1248 {
1249 bool last_pair = ((argc - i) == 2);
1250 target->GetImageSearchPathList().Insert (ConstString(from),
1251 ConstString(to),
1252 insert_idx,
1253 last_pair);
Johnny Chen7791b332011-02-03 00:30:19 +00001254 result.SetStatus (eReturnStatusSuccessFinishNoResult);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001255 }
1256 else
1257 {
1258 if (from[0])
Greg Clayton7260f622011-04-18 08:33:37 +00001259 result.AppendError ("<path-prefix> can't be empty\n");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001260 else
Greg Clayton7260f622011-04-18 08:33:37 +00001261 result.AppendError ("<new-path-prefix> can't be empty\n");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001262 result.SetStatus (eReturnStatusFailed);
1263 return false;
1264 }
1265 }
1266 }
1267 else
1268 {
Greg Clayton7260f622011-04-18 08:33:37 +00001269 result.AppendError ("insert requires at least three arguments\n");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001270 result.SetStatus (eReturnStatusFailed);
1271 return result.Succeeded();
1272 }
1273
1274 }
1275 else
1276 {
Greg Clayton7260f622011-04-18 08:33:37 +00001277 result.AppendError ("invalid target\n");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001278 result.SetStatus (eReturnStatusFailed);
1279 }
1280 return result.Succeeded();
1281 }
1282};
1283
Greg Claytoneffe5c92011-05-03 22:09:39 +00001284
1285#pragma mark CommandObjectTargetModulesSearchPathsList
1286
1287
Jim Ingham5a988412012-06-08 21:56:10 +00001288class CommandObjectTargetModulesSearchPathsList : public CommandObjectParsed
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001289{
1290public:
1291
Greg Claytoneffe5c92011-05-03 22:09:39 +00001292 CommandObjectTargetModulesSearchPathsList (CommandInterpreter &interpreter) :
Jim Ingham5a988412012-06-08 21:56:10 +00001293 CommandObjectParsed (interpreter,
1294 "target modules search-paths list",
1295 "List all current image search path substitution pairs in the current target.",
1296 "target modules search-paths list")
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001297 {
1298 }
1299
Greg Claytoneffe5c92011-05-03 22:09:39 +00001300 ~CommandObjectTargetModulesSearchPathsList ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001301 {
1302 }
1303
Jim Ingham5a988412012-06-08 21:56:10 +00001304protected:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001305 bool
Jim Ingham5a988412012-06-08 21:56:10 +00001306 DoExecute (Args& command,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001307 CommandReturnObject &result)
1308 {
Greg Claytona7015092010-09-18 01:14:36 +00001309 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001310 if (target)
1311 {
1312 if (command.GetArgumentCount() != 0)
1313 {
Greg Clayton7260f622011-04-18 08:33:37 +00001314 result.AppendError ("list takes no arguments\n");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001315 result.SetStatus (eReturnStatusFailed);
1316 return result.Succeeded();
1317 }
1318
1319 target->GetImageSearchPathList().Dump(&result.GetOutputStream());
Johnny Chen7791b332011-02-03 00:30:19 +00001320 result.SetStatus (eReturnStatusSuccessFinishResult);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001321 }
1322 else
1323 {
Greg Clayton7260f622011-04-18 08:33:37 +00001324 result.AppendError ("invalid target\n");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001325 result.SetStatus (eReturnStatusFailed);
1326 }
1327 return result.Succeeded();
1328 }
1329};
1330
Greg Claytoneffe5c92011-05-03 22:09:39 +00001331#pragma mark CommandObjectTargetModulesSearchPathsQuery
1332
Jim Ingham5a988412012-06-08 21:56:10 +00001333class CommandObjectTargetModulesSearchPathsQuery : public CommandObjectParsed
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001334{
1335public:
1336
Greg Claytoneffe5c92011-05-03 22:09:39 +00001337 CommandObjectTargetModulesSearchPathsQuery (CommandInterpreter &interpreter) :
Jim Ingham5a988412012-06-08 21:56:10 +00001338 CommandObjectParsed (interpreter,
1339 "target modules search-paths query",
1340 "Transform a path using the first applicable image search path.",
1341 NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001342 {
Caroline Tice405fe672010-10-04 22:28:36 +00001343 CommandArgumentEntry arg;
1344 CommandArgumentData path_arg;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001345
Caroline Tice405fe672010-10-04 22:28:36 +00001346 // Define the first (and only) variant of this arg.
Sean Callanan31542552012-10-24 01:12:14 +00001347 path_arg.arg_type = eArgTypeDirectoryName;
Caroline Tice405fe672010-10-04 22:28:36 +00001348 path_arg.arg_repetition = eArgRepeatPlain;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001349
Caroline Tice405fe672010-10-04 22:28:36 +00001350 // There is only one variant this argument could be; put it into the argument entry.
1351 arg.push_back (path_arg);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001352
Caroline Tice405fe672010-10-04 22:28:36 +00001353 // Push the data for the first argument into the m_arguments vector.
1354 m_arguments.push_back (arg);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001355 }
1356
Greg Claytoneffe5c92011-05-03 22:09:39 +00001357 ~CommandObjectTargetModulesSearchPathsQuery ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001358 {
1359 }
1360
Jim Ingham5a988412012-06-08 21:56:10 +00001361protected:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001362 bool
Jim Ingham5a988412012-06-08 21:56:10 +00001363 DoExecute (Args& command,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001364 CommandReturnObject &result)
1365 {
Greg Claytona7015092010-09-18 01:14:36 +00001366 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001367 if (target)
1368 {
1369 if (command.GetArgumentCount() != 1)
1370 {
Greg Clayton7260f622011-04-18 08:33:37 +00001371 result.AppendError ("query requires one argument\n");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001372 result.SetStatus (eReturnStatusFailed);
1373 return result.Succeeded();
1374 }
1375
1376 ConstString orig(command.GetArgumentAtIndex(0));
1377 ConstString transformed;
1378 if (target->GetImageSearchPathList().RemapPath(orig, transformed))
1379 result.GetOutputStream().Printf("%s\n", transformed.GetCString());
1380 else
1381 result.GetOutputStream().Printf("%s\n", orig.GetCString());
Johnny Chen7791b332011-02-03 00:30:19 +00001382
1383 result.SetStatus (eReturnStatusSuccessFinishResult);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001384 }
1385 else
1386 {
Greg Clayton7260f622011-04-18 08:33:37 +00001387 result.AppendError ("invalid target\n");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001388 result.SetStatus (eReturnStatusFailed);
1389 }
1390 return result.Succeeded();
1391 }
1392};
1393
Greg Claytoneffe5c92011-05-03 22:09:39 +00001394//----------------------------------------------------------------------
1395// Static Helper functions
1396//----------------------------------------------------------------------
1397static void
1398DumpModuleArchitecture (Stream &strm, Module *module, bool full_triple, uint32_t width)
1399{
1400 if (module)
1401 {
1402 const char *arch_cstr;
1403 if (full_triple)
1404 arch_cstr = module->GetArchitecture().GetTriple().str().c_str();
1405 else
1406 arch_cstr = module->GetArchitecture().GetArchitectureName();
1407 if (width)
1408 strm.Printf("%-*s", width, arch_cstr);
1409 else
1410 strm.PutCString(arch_cstr);
1411 }
1412}
1413
1414static void
1415DumpModuleUUID (Stream &strm, Module *module)
1416{
Jim Ingham28eb5712012-10-12 17:34:26 +00001417 if (module && module->GetUUID().IsValid())
Greg Clayton3418c852011-08-10 02:10:13 +00001418 module->GetUUID().Dump (&strm);
1419 else
1420 strm.PutCString(" ");
Greg Claytoneffe5c92011-05-03 22:09:39 +00001421}
1422
1423static uint32_t
Greg Claytona0ca6602012-10-18 16:33:33 +00001424DumpCompileUnitLineTable (CommandInterpreter &interpreter,
1425 Stream &strm,
1426 Module *module,
1427 const FileSpec &file_spec,
1428 bool load_addresses)
Greg Claytoneffe5c92011-05-03 22:09:39 +00001429{
1430 uint32_t num_matches = 0;
1431 if (module)
1432 {
1433 SymbolContextList sc_list;
1434 num_matches = module->ResolveSymbolContextsForFileSpec (file_spec,
1435 0,
1436 false,
1437 eSymbolContextCompUnit,
1438 sc_list);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001439
Greg Claytoneffe5c92011-05-03 22:09:39 +00001440 for (uint32_t i=0; i<num_matches; ++i)
1441 {
1442 SymbolContext sc;
1443 if (sc_list.GetContextAtIndex(i, sc))
1444 {
1445 if (i > 0)
1446 strm << "\n\n";
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001447
Greg Claytoneffe5c92011-05-03 22:09:39 +00001448 strm << "Line table for " << *static_cast<FileSpec*> (sc.comp_unit) << " in `"
1449 << module->GetFileSpec().GetFilename() << "\n";
1450 LineTable *line_table = sc.comp_unit->GetLineTable();
1451 if (line_table)
1452 line_table->GetDescription (&strm,
Greg Claytonc14ee322011-09-22 04:58:26 +00001453 interpreter.GetExecutionContext().GetTargetPtr(),
Greg Claytoneffe5c92011-05-03 22:09:39 +00001454 lldb::eDescriptionLevelBrief);
1455 else
1456 strm << "No line table";
1457 }
1458 }
1459 }
1460 return num_matches;
1461}
1462
1463static void
1464DumpFullpath (Stream &strm, const FileSpec *file_spec_ptr, uint32_t width)
1465{
1466 if (file_spec_ptr)
1467 {
1468 if (width > 0)
1469 {
Jason Molendadb7d11c2013-05-06 10:21:11 +00001470 std::string fullpath = file_spec_ptr->GetPath();
1471 strm.Printf("%-*s", width, fullpath.c_str());
1472 return;
Greg Claytoneffe5c92011-05-03 22:09:39 +00001473 }
1474 else
1475 {
1476 file_spec_ptr->Dump(&strm);
1477 return;
1478 }
1479 }
1480 // Keep the width spacing correct if things go wrong...
1481 if (width > 0)
1482 strm.Printf("%-*s", width, "");
1483}
1484
1485static void
1486DumpDirectory (Stream &strm, const FileSpec *file_spec_ptr, uint32_t width)
1487{
1488 if (file_spec_ptr)
1489 {
1490 if (width > 0)
1491 strm.Printf("%-*s", width, file_spec_ptr->GetDirectory().AsCString(""));
1492 else
1493 file_spec_ptr->GetDirectory().Dump(&strm);
1494 return;
1495 }
1496 // Keep the width spacing correct if things go wrong...
1497 if (width > 0)
1498 strm.Printf("%-*s", width, "");
1499}
1500
1501static void
1502DumpBasename (Stream &strm, const FileSpec *file_spec_ptr, uint32_t width)
1503{
1504 if (file_spec_ptr)
1505 {
1506 if (width > 0)
1507 strm.Printf("%-*s", width, file_spec_ptr->GetFilename().AsCString(""));
1508 else
1509 file_spec_ptr->GetFilename().Dump(&strm);
1510 return;
1511 }
1512 // Keep the width spacing correct if things go wrong...
1513 if (width > 0)
1514 strm.Printf("%-*s", width, "");
1515}
1516
1517
1518static void
1519DumpModuleSymtab (CommandInterpreter &interpreter, Stream &strm, Module *module, SortOrder sort_order)
1520{
1521 if (module)
1522 {
Michael Sartaina7499c92013-07-01 19:45:50 +00001523 SymbolVendor *sym_vendor = module->GetSymbolVendor ();
1524 if (sym_vendor)
Greg Claytoneffe5c92011-05-03 22:09:39 +00001525 {
Michael Sartaina7499c92013-07-01 19:45:50 +00001526 Symtab *symtab = sym_vendor->GetSymtab();
Greg Claytoneffe5c92011-05-03 22:09:39 +00001527 if (symtab)
Greg Claytonc14ee322011-09-22 04:58:26 +00001528 symtab->Dump(&strm, interpreter.GetExecutionContext().GetTargetPtr(), sort_order);
Greg Claytoneffe5c92011-05-03 22:09:39 +00001529 }
1530 }
1531}
1532
1533static void
1534DumpModuleSections (CommandInterpreter &interpreter, Stream &strm, Module *module)
1535{
1536 if (module)
1537 {
Greg Clayton3046e662013-07-10 01:23:25 +00001538 SectionList *section_list = module->GetSectionList();
Michael Sartaina7499c92013-07-01 19:45:50 +00001539 if (section_list)
Greg Claytoneffe5c92011-05-03 22:09:39 +00001540 {
Michael Sartaina7499c92013-07-01 19:45:50 +00001541 strm.Printf ("Sections for '%s' (%s):\n",
1542 module->GetSpecificationDescription().c_str(),
1543 module->GetArchitecture().GetArchitectureName());
1544 strm.IndentMore();
1545 section_list->Dump(&strm, interpreter.GetExecutionContext().GetTargetPtr(), true, UINT32_MAX);
1546 strm.IndentLess();
Greg Claytoneffe5c92011-05-03 22:09:39 +00001547 }
1548 }
1549}
1550
1551static bool
1552DumpModuleSymbolVendor (Stream &strm, Module *module)
1553{
1554 if (module)
1555 {
1556 SymbolVendor *symbol_vendor = module->GetSymbolVendor(true);
1557 if (symbol_vendor)
1558 {
1559 symbol_vendor->Dump(&strm);
1560 return true;
1561 }
1562 }
1563 return false;
1564}
1565
Greg Claytonc4a8a762012-05-15 18:43:44 +00001566static void
1567DumpAddress (ExecutionContextScope *exe_scope, const Address &so_addr, bool verbose, Stream &strm)
1568{
1569 strm.IndentMore();
1570 strm.Indent (" Address: ");
1571 so_addr.Dump (&strm, exe_scope, Address::DumpStyleModuleWithFileAddress);
1572 strm.PutCString (" (");
1573 so_addr.Dump (&strm, exe_scope, Address::DumpStyleSectionNameOffset);
1574 strm.PutCString (")\n");
1575 strm.Indent (" Summary: ");
1576 const uint32_t save_indent = strm.GetIndentLevel ();
1577 strm.SetIndentLevel (save_indent + 13);
1578 so_addr.Dump (&strm, exe_scope, Address::DumpStyleResolvedDescription);
1579 strm.SetIndentLevel (save_indent);
1580 // Print out detailed address information when verbose is enabled
1581 if (verbose)
1582 {
1583 strm.EOL();
1584 so_addr.Dump (&strm, exe_scope, Address::DumpStyleDetailedSymbolContext);
1585 }
1586 strm.IndentLess();
1587}
1588
Greg Claytoneffe5c92011-05-03 22:09:39 +00001589static bool
Greg Claytone72dfb32012-02-24 01:59:29 +00001590LookupAddressInModule (CommandInterpreter &interpreter,
1591 Stream &strm,
1592 Module *module,
1593 uint32_t resolve_mask,
1594 lldb::addr_t raw_addr,
1595 lldb::addr_t offset,
1596 bool verbose)
Greg Claytoneffe5c92011-05-03 22:09:39 +00001597{
1598 if (module)
1599 {
1600 lldb::addr_t addr = raw_addr - offset;
1601 Address so_addr;
1602 SymbolContext sc;
Greg Claytonc14ee322011-09-22 04:58:26 +00001603 Target *target = interpreter.GetExecutionContext().GetTargetPtr();
Greg Claytoneffe5c92011-05-03 22:09:39 +00001604 if (target && !target->GetSectionLoadList().IsEmpty())
1605 {
1606 if (!target->GetSectionLoadList().ResolveLoadAddress (addr, so_addr))
1607 return false;
Greg Claytone72dfb32012-02-24 01:59:29 +00001608 else if (so_addr.GetModule().get() != module)
Greg Claytoneffe5c92011-05-03 22:09:39 +00001609 return false;
1610 }
1611 else
1612 {
1613 if (!module->ResolveFileAddress (addr, so_addr))
1614 return false;
1615 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001616
Greg Claytoneffe5c92011-05-03 22:09:39 +00001617 ExecutionContextScope *exe_scope = interpreter.GetExecutionContext().GetBestExecutionContextScope();
Greg Claytonc4a8a762012-05-15 18:43:44 +00001618 DumpAddress (exe_scope, so_addr, verbose, strm);
1619// strm.IndentMore();
1620// strm.Indent (" Address: ");
1621// so_addr.Dump (&strm, exe_scope, Address::DumpStyleModuleWithFileAddress);
1622// strm.PutCString (" (");
1623// so_addr.Dump (&strm, exe_scope, Address::DumpStyleSectionNameOffset);
1624// strm.PutCString (")\n");
1625// strm.Indent (" Summary: ");
1626// const uint32_t save_indent = strm.GetIndentLevel ();
1627// strm.SetIndentLevel (save_indent + 13);
1628// so_addr.Dump (&strm, exe_scope, Address::DumpStyleResolvedDescription);
1629// strm.SetIndentLevel (save_indent);
1630// // Print out detailed address information when verbose is enabled
1631// if (verbose)
1632// {
1633// strm.EOL();
1634// so_addr.Dump (&strm, exe_scope, Address::DumpStyleDetailedSymbolContext);
1635// }
1636// strm.IndentLess();
Greg Claytoneffe5c92011-05-03 22:09:39 +00001637 return true;
1638 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001639
Greg Claytoneffe5c92011-05-03 22:09:39 +00001640 return false;
1641}
1642
1643static uint32_t
Greg Claytonc4a8a762012-05-15 18:43:44 +00001644LookupSymbolInModule (CommandInterpreter &interpreter, Stream &strm, Module *module, const char *name, bool name_is_regex, bool verbose)
Greg Claytoneffe5c92011-05-03 22:09:39 +00001645{
1646 if (module)
1647 {
1648 SymbolContext sc;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001649
Michael Sartaina7499c92013-07-01 19:45:50 +00001650 SymbolVendor *sym_vendor = module->GetSymbolVendor ();
1651 if (sym_vendor)
Greg Claytoneffe5c92011-05-03 22:09:39 +00001652 {
Michael Sartaina7499c92013-07-01 19:45:50 +00001653 Symtab *symtab = sym_vendor->GetSymtab();
Greg Claytoneffe5c92011-05-03 22:09:39 +00001654 if (symtab)
1655 {
1656 uint32_t i;
1657 std::vector<uint32_t> match_indexes;
1658 ConstString symbol_name (name);
1659 uint32_t num_matches = 0;
1660 if (name_is_regex)
1661 {
1662 RegularExpression name_regexp(name);
1663 num_matches = symtab->AppendSymbolIndexesMatchingRegExAndType (name_regexp,
1664 eSymbolTypeAny,
1665 match_indexes);
1666 }
1667 else
1668 {
1669 num_matches = symtab->AppendSymbolIndexesWithName (symbol_name, match_indexes);
1670 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001671
Greg Claytoneffe5c92011-05-03 22:09:39 +00001672 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();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001708
Greg Claytoneffe5c92011-05-03 22:09:39 +00001709 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;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001715
Sean Callananf6172c22012-02-11 00:24:04 +00001716 sc.GetAddressRange(eSymbolContextEverything,
1717 0,
1718 true,
1719 range);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001720
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 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001762
Greg Claytoneffe5c92011-05-03 22:09:39 +00001763 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);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +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;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001838
Sean Callanand38b4a92012-06-06 20:49:55 +00001839 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;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001843
Sean Callanand38b4a92012-06-06 20:49:55 +00001844 ConstString name(name_cstr);
1845 num_matches = sym_ctx.module_sp->FindTypes(sym_ctx, name, name_is_fully_qualified, max_num_matches, type_list);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001846
Sean Callanand38b4a92012-06-06 20:49:55 +00001847 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");
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001853
Sean Callanand38b4a92012-06-06 20:49:55 +00001854 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;
Greg Claytoneffe5c92011-05-03 22:09:39 +00001908}
1909
Greg Clayton8ee64382011-11-10 01:18:58 +00001910
1911static size_t
1912FindModulesByName (Target *target,
1913 const char *module_name,
1914 ModuleList &module_list,
1915 bool check_global_list)
1916{
1917// Dump specified images (by basename or fullpath)
1918 FileSpec module_file_spec(module_name, false);
Greg Claytonb9a01b32012-02-26 05:51:37 +00001919 ModuleSpec module_spec (module_file_spec);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001920
Greg Clayton8ee64382011-11-10 01:18:58 +00001921 const size_t initial_size = module_list.GetSize ();
1922
Greg Claytonf3156262012-07-11 20:46:47 +00001923 if (check_global_list)
Greg Clayton8ee64382011-11-10 01:18:58 +00001924 {
1925 // Check the global list
Greg Claytonb26e6be2012-01-27 18:08:35 +00001926 Mutex::Locker locker(Module::GetAllocationModuleCollectionMutex());
Greg Claytonc7bece562013-01-25 18:06:21 +00001927 const size_t num_modules = Module::GetNumberAllocatedModules();
Greg Clayton8ee64382011-11-10 01:18:58 +00001928 ModuleSP module_sp;
Greg Claytonc7bece562013-01-25 18:06:21 +00001929 for (size_t image_idx = 0; image_idx<num_modules; ++image_idx)
Greg Clayton8ee64382011-11-10 01:18:58 +00001930 {
1931 Module *module = Module::GetAllocatedModuleAtIndex(image_idx);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001932
Greg Clayton8ee64382011-11-10 01:18:58 +00001933 if (module)
1934 {
Greg Claytonb9a01b32012-02-26 05:51:37 +00001935 if (module->MatchesModuleSpec (module_spec))
Greg Clayton8ee64382011-11-10 01:18:58 +00001936 {
Greg Claytone1cd1be2012-01-29 20:56:30 +00001937 module_sp = module->shared_from_this();
Greg Clayton8ee64382011-11-10 01:18:58 +00001938 module_list.AppendIfNeeded(module_sp);
1939 }
1940 }
1941 }
1942 }
Greg Claytonf3156262012-07-11 20:46:47 +00001943 else
1944 {
1945 if (target)
1946 {
1947 const size_t num_matches = target->GetImages().FindModules (module_spec, module_list);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001948
Greg Claytonf3156262012-07-11 20:46:47 +00001949 // Not found in our module list for our target, check the main
1950 // shared module list in case it is a extra file used somewhere
1951 // else
1952 if (num_matches == 0)
1953 {
1954 module_spec.GetArchitecture() = target->GetArchitecture();
1955 ModuleList::FindSharedModules (module_spec, module_list);
1956 }
1957 }
1958 else
1959 {
1960 ModuleList::FindSharedModules (module_spec,module_list);
1961 }
1962 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001963
Greg Clayton8ee64382011-11-10 01:18:58 +00001964 return module_list.GetSize () - initial_size;
1965}
1966
Greg Claytoneffe5c92011-05-03 22:09:39 +00001967#pragma mark CommandObjectTargetModulesModuleAutoComplete
1968
1969//----------------------------------------------------------------------
1970// A base command object class that can auto complete with module file
1971// paths
1972//----------------------------------------------------------------------
1973
Jim Ingham5a988412012-06-08 21:56:10 +00001974class CommandObjectTargetModulesModuleAutoComplete : public CommandObjectParsed
Greg Claytoneffe5c92011-05-03 22:09:39 +00001975{
1976public:
Greg Claytoneffe5c92011-05-03 22:09:39 +00001977 CommandObjectTargetModulesModuleAutoComplete (CommandInterpreter &interpreter,
1978 const char *name,
1979 const char *help,
1980 const char *syntax) :
Jim Ingham5a988412012-06-08 21:56:10 +00001981 CommandObjectParsed (interpreter, name, help, syntax)
Greg Claytoneffe5c92011-05-03 22:09:39 +00001982 {
1983 CommandArgumentEntry arg;
1984 CommandArgumentData file_arg;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001985
Greg Claytoneffe5c92011-05-03 22:09:39 +00001986 // Define the first (and only) variant of this arg.
1987 file_arg.arg_type = eArgTypeFilename;
1988 file_arg.arg_repetition = eArgRepeatStar;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001989
Greg Claytoneffe5c92011-05-03 22:09:39 +00001990 // There is only one variant this argument could be; put it into the argument entry.
1991 arg.push_back (file_arg);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001992
Greg Claytoneffe5c92011-05-03 22:09:39 +00001993 // Push the data for the first argument into the m_arguments vector.
1994 m_arguments.push_back (arg);
1995 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001996
Greg Claytoneffe5c92011-05-03 22:09:39 +00001997 virtual
1998 ~CommandObjectTargetModulesModuleAutoComplete ()
1999 {
2000 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002001
Greg Claytoneffe5c92011-05-03 22:09:39 +00002002 virtual int
2003 HandleArgumentCompletion (Args &input,
2004 int &cursor_index,
2005 int &cursor_char_position,
2006 OptionElementVector &opt_element_vector,
2007 int match_start_point,
2008 int max_return_elements,
2009 bool &word_complete,
2010 StringList &matches)
2011 {
2012 // Arguments are the standard module completer.
2013 std::string completion_str (input.GetArgumentAtIndex(cursor_index));
2014 completion_str.erase (cursor_char_position);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002015
Greg Claytoneffe5c92011-05-03 22:09:39 +00002016 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
2017 CommandCompletions::eModuleCompletion,
2018 completion_str.c_str(),
2019 match_start_point,
2020 max_return_elements,
2021 NULL,
2022 word_complete,
2023 matches);
2024 return matches.GetSize();
2025 }
2026};
2027
2028#pragma mark CommandObjectTargetModulesSourceFileAutoComplete
2029
2030//----------------------------------------------------------------------
2031// A base command object class that can auto complete with module source
2032// file paths
2033//----------------------------------------------------------------------
2034
Jim Ingham5a988412012-06-08 21:56:10 +00002035class CommandObjectTargetModulesSourceFileAutoComplete : public CommandObjectParsed
Greg Claytoneffe5c92011-05-03 22:09:39 +00002036{
2037public:
Greg Claytoneffe5c92011-05-03 22:09:39 +00002038 CommandObjectTargetModulesSourceFileAutoComplete (CommandInterpreter &interpreter,
Greg Claytonf9fc6092013-01-09 19:44:40 +00002039 const char *name,
2040 const char *help,
2041 const char *syntax,
2042 uint32_t flags) :
2043 CommandObjectParsed (interpreter, name, help, syntax, flags)
Greg Claytoneffe5c92011-05-03 22:09:39 +00002044 {
2045 CommandArgumentEntry arg;
2046 CommandArgumentData source_file_arg;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002047
Greg Claytoneffe5c92011-05-03 22:09:39 +00002048 // Define the first (and only) variant of this arg.
2049 source_file_arg.arg_type = eArgTypeSourceFile;
2050 source_file_arg.arg_repetition = eArgRepeatPlus;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002051
Greg Claytoneffe5c92011-05-03 22:09:39 +00002052 // There is only one variant this argument could be; put it into the argument entry.
2053 arg.push_back (source_file_arg);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002054
Greg Claytoneffe5c92011-05-03 22:09:39 +00002055 // Push the data for the first argument into the m_arguments vector.
2056 m_arguments.push_back (arg);
2057 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002058
Greg Claytoneffe5c92011-05-03 22:09:39 +00002059 virtual
2060 ~CommandObjectTargetModulesSourceFileAutoComplete ()
2061 {
2062 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002063
Greg Claytoneffe5c92011-05-03 22:09:39 +00002064 virtual int
2065 HandleArgumentCompletion (Args &input,
2066 int &cursor_index,
2067 int &cursor_char_position,
2068 OptionElementVector &opt_element_vector,
2069 int match_start_point,
2070 int max_return_elements,
2071 bool &word_complete,
2072 StringList &matches)
2073 {
2074 // Arguments are the standard source file completer.
2075 std::string completion_str (input.GetArgumentAtIndex(cursor_index));
2076 completion_str.erase (cursor_char_position);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002077
Greg Claytoneffe5c92011-05-03 22:09:39 +00002078 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
2079 CommandCompletions::eSourceFileCompletion,
2080 completion_str.c_str(),
2081 match_start_point,
2082 max_return_elements,
2083 NULL,
2084 word_complete,
2085 matches);
2086 return matches.GetSize();
2087 }
2088};
2089
2090
2091#pragma mark CommandObjectTargetModulesDumpSymtab
2092
2093
2094class CommandObjectTargetModulesDumpSymtab : public CommandObjectTargetModulesModuleAutoComplete
2095{
2096public:
2097 CommandObjectTargetModulesDumpSymtab (CommandInterpreter &interpreter) :
2098 CommandObjectTargetModulesModuleAutoComplete (interpreter,
2099 "target modules dump symtab",
2100 "Dump the symbol table from one or more target modules.",
2101 NULL),
2102 m_options (interpreter)
2103 {
2104 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002105
Greg Claytoneffe5c92011-05-03 22:09:39 +00002106 virtual
2107 ~CommandObjectTargetModulesDumpSymtab ()
2108 {
2109 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002110
Jim Ingham5a988412012-06-08 21:56:10 +00002111 virtual Options *
2112 GetOptions ()
2113 {
2114 return &m_options;
2115 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002116
Jim Ingham5a988412012-06-08 21:56:10 +00002117 class CommandOptions : public Options
2118 {
2119 public:
Jim Ingham5a988412012-06-08 21:56:10 +00002120 CommandOptions (CommandInterpreter &interpreter) :
2121 Options(interpreter),
2122 m_sort_order (eSortOrderNone)
2123 {
2124 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002125
Jim Ingham5a988412012-06-08 21:56:10 +00002126 virtual
2127 ~CommandOptions ()
2128 {
2129 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002130
Jim Ingham5a988412012-06-08 21:56:10 +00002131 virtual Error
2132 SetOptionValue (uint32_t option_idx, const char *option_arg)
2133 {
2134 Error error;
Greg Clayton3bcdfc02012-12-04 00:32:51 +00002135 const int short_option = m_getopt_table[option_idx].val;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002136
Jim Ingham5a988412012-06-08 21:56:10 +00002137 switch (short_option)
2138 {
2139 case 's':
2140 m_sort_order = (SortOrder) Args::StringToOptionEnum (option_arg,
2141 g_option_table[option_idx].enum_values,
2142 eSortOrderNone,
2143 error);
2144 break;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002145
Jim Ingham5a988412012-06-08 21:56:10 +00002146 default:
2147 error.SetErrorStringWithFormat("invalid short option character '%c'", short_option);
2148 break;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002149
Jim Ingham5a988412012-06-08 21:56:10 +00002150 }
2151 return error;
2152 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002153
Jim Ingham5a988412012-06-08 21:56:10 +00002154 void
2155 OptionParsingStarting ()
2156 {
2157 m_sort_order = eSortOrderNone;
2158 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002159
Jim Ingham5a988412012-06-08 21:56:10 +00002160 const OptionDefinition*
2161 GetDefinitions ()
2162 {
2163 return g_option_table;
2164 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002165
Jim Ingham5a988412012-06-08 21:56:10 +00002166 // Options table: Required for subclasses of Options.
2167 static OptionDefinition g_option_table[];
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002168
Jim Ingham5a988412012-06-08 21:56:10 +00002169 SortOrder m_sort_order;
2170 };
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002171
Jim Ingham5a988412012-06-08 21:56:10 +00002172protected:
Greg Claytoneffe5c92011-05-03 22:09:39 +00002173 virtual bool
Jim Ingham5a988412012-06-08 21:56:10 +00002174 DoExecute (Args& command,
Greg Claytoneffe5c92011-05-03 22:09:39 +00002175 CommandReturnObject &result)
2176 {
2177 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
2178 if (target == NULL)
2179 {
2180 result.AppendError ("invalid target, create a debug target using the 'target create' command");
2181 result.SetStatus (eReturnStatusFailed);
2182 return false;
2183 }
2184 else
2185 {
2186 uint32_t num_dumped = 0;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002187
Greg Claytoneffe5c92011-05-03 22:09:39 +00002188 uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize();
2189 result.GetOutputStream().SetAddressByteSize(addr_byte_size);
2190 result.GetErrorStream().SetAddressByteSize(addr_byte_size);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002191
Greg Claytoneffe5c92011-05-03 22:09:39 +00002192 if (command.GetArgumentCount() == 0)
2193 {
2194 // Dump all sections for all modules images
Jim Ingham3ee12ef2012-05-30 02:19:25 +00002195 Mutex::Locker modules_locker(target->GetImages().GetMutex());
Greg Claytonc7bece562013-01-25 18:06:21 +00002196 const size_t num_modules = target->GetImages().GetSize();
Greg Claytoneffe5c92011-05-03 22:09:39 +00002197 if (num_modules > 0)
2198 {
Deepak Panickal99fbc072014-03-03 15:39:47 +00002199 result.GetOutputStream().Printf("Dumping symbol table for %" PRIu64 " modules.\n", (uint64_t)num_modules);
Greg Claytonc7bece562013-01-25 18:06:21 +00002200 for (size_t image_idx = 0; image_idx<num_modules; ++image_idx)
Greg Claytoneffe5c92011-05-03 22:09:39 +00002201 {
2202 if (num_dumped > 0)
2203 {
2204 result.GetOutputStream().EOL();
2205 result.GetOutputStream().EOL();
2206 }
2207 num_dumped++;
Jim Ingham3ee12ef2012-05-30 02:19:25 +00002208 DumpModuleSymtab (m_interpreter,
2209 result.GetOutputStream(),
2210 target->GetImages().GetModulePointerAtIndexUnlocked(image_idx),
2211 m_options.m_sort_order);
Greg Claytoneffe5c92011-05-03 22:09:39 +00002212 }
2213 }
2214 else
2215 {
2216 result.AppendError ("the target has no associated executable images");
2217 result.SetStatus (eReturnStatusFailed);
2218 return false;
2219 }
2220 }
2221 else
2222 {
2223 // Dump specified images (by basename or fullpath)
2224 const char *arg_cstr;
2225 for (int arg_idx = 0; (arg_cstr = command.GetArgumentAtIndex(arg_idx)) != NULL; ++arg_idx)
2226 {
Greg Clayton8ee64382011-11-10 01:18:58 +00002227 ModuleList module_list;
2228 const size_t num_matches = FindModulesByName (target, arg_cstr, module_list, true);
2229 if (num_matches > 0)
Greg Claytoneffe5c92011-05-03 22:09:39 +00002230 {
Greg Clayton8ee64382011-11-10 01:18:58 +00002231 for (size_t i=0; i<num_matches; ++i)
Greg Claytoneffe5c92011-05-03 22:09:39 +00002232 {
Greg Clayton8ee64382011-11-10 01:18:58 +00002233 Module *module = module_list.GetModulePointerAtIndex(i);
2234 if (module)
Greg Claytoneffe5c92011-05-03 22:09:39 +00002235 {
2236 if (num_dumped > 0)
2237 {
2238 result.GetOutputStream().EOL();
2239 result.GetOutputStream().EOL();
2240 }
2241 num_dumped++;
Greg Clayton8ee64382011-11-10 01:18:58 +00002242 DumpModuleSymtab (m_interpreter, result.GetOutputStream(), module, m_options.m_sort_order);
Greg Claytoneffe5c92011-05-03 22:09:39 +00002243 }
2244 }
2245 }
2246 else
2247 result.AppendWarningWithFormat("Unable to find an image that matches '%s'.\n", arg_cstr);
2248 }
2249 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002250
Greg Claytoneffe5c92011-05-03 22:09:39 +00002251 if (num_dumped > 0)
2252 result.SetStatus (eReturnStatusSuccessFinishResult);
2253 else
2254 {
2255 result.AppendError ("no matching executable images found");
2256 result.SetStatus (eReturnStatusFailed);
2257 }
2258 }
2259 return result.Succeeded();
2260 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002261
Greg Claytoneffe5c92011-05-03 22:09:39 +00002262 CommandOptions m_options;
2263};
2264
2265static OptionEnumValueElement
2266g_sort_option_enumeration[4] =
2267{
2268 { eSortOrderNone, "none", "No sorting, use the original symbol table order."},
2269 { eSortOrderByAddress, "address", "Sort output by symbol address."},
2270 { eSortOrderByName, "name", "Sort output by symbol name."},
2271 { 0, NULL, NULL }
2272};
2273
2274
2275OptionDefinition
2276CommandObjectTargetModulesDumpSymtab::CommandOptions::g_option_table[] =
2277{
Virgile Belloe2607b52013-09-05 16:42:23 +00002278 { 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 +00002279 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
2280};
2281
2282#pragma mark CommandObjectTargetModulesDumpSections
2283
2284//----------------------------------------------------------------------
2285// Image section dumping command
2286//----------------------------------------------------------------------
2287
2288class CommandObjectTargetModulesDumpSections : public CommandObjectTargetModulesModuleAutoComplete
2289{
2290public:
2291 CommandObjectTargetModulesDumpSections (CommandInterpreter &interpreter) :
2292 CommandObjectTargetModulesModuleAutoComplete (interpreter,
2293 "target modules dump sections",
2294 "Dump the sections from one or more target modules.",
2295 //"target modules dump sections [<file1> ...]")
2296 NULL)
2297 {
2298 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002299
Greg Claytoneffe5c92011-05-03 22:09:39 +00002300 virtual
2301 ~CommandObjectTargetModulesDumpSections ()
2302 {
2303 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002304
Jim Ingham5a988412012-06-08 21:56:10 +00002305protected:
Greg Claytoneffe5c92011-05-03 22:09:39 +00002306 virtual bool
Jim Ingham5a988412012-06-08 21:56:10 +00002307 DoExecute (Args& command,
Greg Claytoneffe5c92011-05-03 22:09:39 +00002308 CommandReturnObject &result)
2309 {
2310 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
2311 if (target == NULL)
2312 {
2313 result.AppendError ("invalid target, create a debug target using the 'target create' command");
2314 result.SetStatus (eReturnStatusFailed);
2315 return false;
2316 }
2317 else
2318 {
2319 uint32_t num_dumped = 0;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002320
Greg Claytoneffe5c92011-05-03 22:09:39 +00002321 uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize();
2322 result.GetOutputStream().SetAddressByteSize(addr_byte_size);
2323 result.GetErrorStream().SetAddressByteSize(addr_byte_size);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002324
Greg Claytoneffe5c92011-05-03 22:09:39 +00002325 if (command.GetArgumentCount() == 0)
2326 {
2327 // Dump all sections for all modules images
Greg Claytonc7bece562013-01-25 18:06:21 +00002328 const size_t num_modules = target->GetImages().GetSize();
Greg Claytoneffe5c92011-05-03 22:09:39 +00002329 if (num_modules > 0)
2330 {
Deepak Panickal99fbc072014-03-03 15:39:47 +00002331 result.GetOutputStream().Printf("Dumping sections for %" PRIu64 " modules.\n", (uint64_t)num_modules);
Greg Claytonc7bece562013-01-25 18:06:21 +00002332 for (size_t image_idx = 0; image_idx<num_modules; ++image_idx)
Greg Claytoneffe5c92011-05-03 22:09:39 +00002333 {
2334 num_dumped++;
2335 DumpModuleSections (m_interpreter, result.GetOutputStream(), target->GetImages().GetModulePointerAtIndex(image_idx));
2336 }
2337 }
2338 else
2339 {
2340 result.AppendError ("the target has no associated executable images");
2341 result.SetStatus (eReturnStatusFailed);
2342 return false;
2343 }
2344 }
2345 else
2346 {
2347 // Dump specified images (by basename or fullpath)
2348 const char *arg_cstr;
2349 for (int arg_idx = 0; (arg_cstr = command.GetArgumentAtIndex(arg_idx)) != NULL; ++arg_idx)
2350 {
Greg Clayton8ee64382011-11-10 01:18:58 +00002351 ModuleList module_list;
2352 const size_t num_matches = FindModulesByName (target, arg_cstr, module_list, true);
2353 if (num_matches > 0)
Greg Claytoneffe5c92011-05-03 22:09:39 +00002354 {
Greg Clayton8ee64382011-11-10 01:18:58 +00002355 for (size_t i=0; i<num_matches; ++i)
Greg Claytoneffe5c92011-05-03 22:09:39 +00002356 {
Greg Clayton8ee64382011-11-10 01:18:58 +00002357 Module *module = module_list.GetModulePointerAtIndex(i);
2358 if (module)
Greg Claytoneffe5c92011-05-03 22:09:39 +00002359 {
2360 num_dumped++;
Greg Clayton8ee64382011-11-10 01:18:58 +00002361 DumpModuleSections (m_interpreter, result.GetOutputStream(), module);
Greg Claytoneffe5c92011-05-03 22:09:39 +00002362 }
2363 }
2364 }
2365 else
Greg Clayton8ee64382011-11-10 01:18:58 +00002366 {
2367 // Check the global list
Greg Claytonb26e6be2012-01-27 18:08:35 +00002368 Mutex::Locker locker(Module::GetAllocationModuleCollectionMutex());
Greg Clayton8ee64382011-11-10 01:18:58 +00002369
Greg Claytoneffe5c92011-05-03 22:09:39 +00002370 result.AppendWarningWithFormat("Unable to find an image that matches '%s'.\n", arg_cstr);
Greg Clayton8ee64382011-11-10 01:18:58 +00002371 }
Greg Claytoneffe5c92011-05-03 22:09:39 +00002372 }
2373 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002374
Greg Claytoneffe5c92011-05-03 22:09:39 +00002375 if (num_dumped > 0)
2376 result.SetStatus (eReturnStatusSuccessFinishResult);
2377 else
2378 {
2379 result.AppendError ("no matching executable images found");
2380 result.SetStatus (eReturnStatusFailed);
2381 }
2382 }
2383 return result.Succeeded();
2384 }
2385};
2386
2387
2388#pragma mark CommandObjectTargetModulesDumpSymfile
2389
2390//----------------------------------------------------------------------
2391// Image debug symbol dumping command
2392//----------------------------------------------------------------------
2393
2394class CommandObjectTargetModulesDumpSymfile : public CommandObjectTargetModulesModuleAutoComplete
2395{
2396public:
2397 CommandObjectTargetModulesDumpSymfile (CommandInterpreter &interpreter) :
2398 CommandObjectTargetModulesModuleAutoComplete (interpreter,
2399 "target modules dump symfile",
2400 "Dump the debug symbol file for one or more target modules.",
2401 //"target modules dump symfile [<file1> ...]")
2402 NULL)
2403 {
2404 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002405
Greg Claytoneffe5c92011-05-03 22:09:39 +00002406 virtual
2407 ~CommandObjectTargetModulesDumpSymfile ()
2408 {
2409 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002410
Jim Ingham5a988412012-06-08 21:56:10 +00002411protected:
Greg Claytoneffe5c92011-05-03 22:09:39 +00002412 virtual bool
Jim Ingham5a988412012-06-08 21:56:10 +00002413 DoExecute (Args& command,
Greg Claytoneffe5c92011-05-03 22:09:39 +00002414 CommandReturnObject &result)
2415 {
2416 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
2417 if (target == NULL)
2418 {
2419 result.AppendError ("invalid target, create a debug target using the 'target create' command");
2420 result.SetStatus (eReturnStatusFailed);
2421 return false;
2422 }
2423 else
2424 {
2425 uint32_t num_dumped = 0;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002426
Greg Claytoneffe5c92011-05-03 22:09:39 +00002427 uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize();
2428 result.GetOutputStream().SetAddressByteSize(addr_byte_size);
2429 result.GetErrorStream().SetAddressByteSize(addr_byte_size);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002430
Greg Claytoneffe5c92011-05-03 22:09:39 +00002431 if (command.GetArgumentCount() == 0)
2432 {
2433 // Dump all sections for all modules images
Enrico Granata17598482012-11-08 02:22:02 +00002434 const ModuleList &target_modules = target->GetImages();
Jim Ingham3ee12ef2012-05-30 02:19:25 +00002435 Mutex::Locker modules_locker (target_modules.GetMutex());
Greg Claytonc7bece562013-01-25 18:06:21 +00002436 const size_t num_modules = target_modules.GetSize();
Greg Claytoneffe5c92011-05-03 22:09:39 +00002437 if (num_modules > 0)
2438 {
Deepak Panickal99fbc072014-03-03 15:39:47 +00002439 result.GetOutputStream().Printf("Dumping debug symbols for %" PRIu64 " modules.\n", (uint64_t)num_modules);
Greg Claytoneffe5c92011-05-03 22:09:39 +00002440 for (uint32_t image_idx = 0; image_idx<num_modules; ++image_idx)
2441 {
Jim Ingham3ee12ef2012-05-30 02:19:25 +00002442 if (DumpModuleSymbolVendor (result.GetOutputStream(), target_modules.GetModulePointerAtIndexUnlocked(image_idx)))
Greg Claytoneffe5c92011-05-03 22:09:39 +00002443 num_dumped++;
2444 }
2445 }
2446 else
2447 {
2448 result.AppendError ("the target has no associated executable images");
2449 result.SetStatus (eReturnStatusFailed);
2450 return false;
2451 }
2452 }
2453 else
2454 {
2455 // Dump specified images (by basename or fullpath)
2456 const char *arg_cstr;
2457 for (int arg_idx = 0; (arg_cstr = command.GetArgumentAtIndex(arg_idx)) != NULL; ++arg_idx)
2458 {
Greg Clayton8ee64382011-11-10 01:18:58 +00002459 ModuleList module_list;
2460 const size_t num_matches = FindModulesByName (target, arg_cstr, module_list, true);
2461 if (num_matches > 0)
Greg Claytoneffe5c92011-05-03 22:09:39 +00002462 {
Greg Clayton8ee64382011-11-10 01:18:58 +00002463 for (size_t i=0; i<num_matches; ++i)
Greg Claytoneffe5c92011-05-03 22:09:39 +00002464 {
Greg Clayton8ee64382011-11-10 01:18:58 +00002465 Module *module = module_list.GetModulePointerAtIndex(i);
2466 if (module)
Greg Claytoneffe5c92011-05-03 22:09:39 +00002467 {
Greg Clayton8ee64382011-11-10 01:18:58 +00002468 if (DumpModuleSymbolVendor (result.GetOutputStream(), module))
Greg Claytoneffe5c92011-05-03 22:09:39 +00002469 num_dumped++;
2470 }
2471 }
2472 }
2473 else
2474 result.AppendWarningWithFormat("Unable to find an image that matches '%s'.\n", arg_cstr);
2475 }
2476 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002477
Greg Claytoneffe5c92011-05-03 22:09:39 +00002478 if (num_dumped > 0)
2479 result.SetStatus (eReturnStatusSuccessFinishResult);
2480 else
2481 {
2482 result.AppendError ("no matching executable images found");
2483 result.SetStatus (eReturnStatusFailed);
2484 }
2485 }
2486 return result.Succeeded();
2487 }
2488};
2489
2490
2491#pragma mark CommandObjectTargetModulesDumpLineTable
2492
2493//----------------------------------------------------------------------
2494// Image debug line table dumping command
2495//----------------------------------------------------------------------
2496
2497class CommandObjectTargetModulesDumpLineTable : public CommandObjectTargetModulesSourceFileAutoComplete
2498{
2499public:
2500 CommandObjectTargetModulesDumpLineTable (CommandInterpreter &interpreter) :
2501 CommandObjectTargetModulesSourceFileAutoComplete (interpreter,
Greg Claytonf9fc6092013-01-09 19:44:40 +00002502 "target modules dump line-table",
Jim Inghamcc0273d2013-06-18 20:27:11 +00002503 "Dump the line table for one or more compilation units.",
Greg Claytonf9fc6092013-01-09 19:44:40 +00002504 NULL,
2505 eFlagRequiresTarget)
Greg Claytoneffe5c92011-05-03 22:09:39 +00002506 {
2507 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002508
Greg Claytoneffe5c92011-05-03 22:09:39 +00002509 virtual
2510 ~CommandObjectTargetModulesDumpLineTable ()
2511 {
2512 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002513
Jim Ingham5a988412012-06-08 21:56:10 +00002514protected:
Greg Claytoneffe5c92011-05-03 22:09:39 +00002515 virtual bool
Jim Ingham5a988412012-06-08 21:56:10 +00002516 DoExecute (Args& command,
Greg Claytoneffe5c92011-05-03 22:09:39 +00002517 CommandReturnObject &result)
2518 {
Greg Claytonf9fc6092013-01-09 19:44:40 +00002519 Target *target = m_exe_ctx.GetTargetPtr();
2520 uint32_t total_num_dumped = 0;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002521
Greg Claytonf9fc6092013-01-09 19:44:40 +00002522 uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize();
2523 result.GetOutputStream().SetAddressByteSize(addr_byte_size);
2524 result.GetErrorStream().SetAddressByteSize(addr_byte_size);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002525
Greg Claytonf9fc6092013-01-09 19:44:40 +00002526 if (command.GetArgumentCount() == 0)
Greg Claytoneffe5c92011-05-03 22:09:39 +00002527 {
Greg Claytonf9fc6092013-01-09 19:44:40 +00002528 result.AppendErrorWithFormat ("\nSyntax: %s\n", m_cmd_syntax.c_str());
Greg Claytoneffe5c92011-05-03 22:09:39 +00002529 result.SetStatus (eReturnStatusFailed);
Greg Claytoneffe5c92011-05-03 22:09:39 +00002530 }
2531 else
2532 {
Greg Claytonf9fc6092013-01-09 19:44:40 +00002533 // Dump specified images (by basename or fullpath)
2534 const char *arg_cstr;
2535 for (int arg_idx = 0; (arg_cstr = command.GetArgumentAtIndex(arg_idx)) != NULL; ++arg_idx)
Greg Claytoneffe5c92011-05-03 22:09:39 +00002536 {
Greg Claytonf9fc6092013-01-09 19:44:40 +00002537 FileSpec file_spec(arg_cstr, false);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002538
Greg Claytonf9fc6092013-01-09 19:44:40 +00002539 const ModuleList &target_modules = target->GetImages();
2540 Mutex::Locker modules_locker(target_modules.GetMutex());
Greg Claytonc7bece562013-01-25 18:06:21 +00002541 const size_t num_modules = target_modules.GetSize();
Greg Claytonf9fc6092013-01-09 19:44:40 +00002542 if (num_modules > 0)
Greg Claytoneffe5c92011-05-03 22:09:39 +00002543 {
Greg Claytonf9fc6092013-01-09 19:44:40 +00002544 uint32_t num_dumped = 0;
2545 for (uint32_t i = 0; i<num_modules; ++i)
Greg Claytoneffe5c92011-05-03 22:09:39 +00002546 {
Greg Claytonf9fc6092013-01-09 19:44:40 +00002547 if (DumpCompileUnitLineTable (m_interpreter,
2548 result.GetOutputStream(),
2549 target_modules.GetModulePointerAtIndexUnlocked(i),
2550 file_spec,
2551 m_exe_ctx.GetProcessPtr() && m_exe_ctx.GetProcessRef().IsAlive()))
2552 num_dumped++;
Greg Claytoneffe5c92011-05-03 22:09:39 +00002553 }
Greg Claytonf9fc6092013-01-09 19:44:40 +00002554 if (num_dumped == 0)
2555 result.AppendWarningWithFormat ("No source filenames matched '%s'.\n", arg_cstr);
2556 else
2557 total_num_dumped += num_dumped;
Greg Claytoneffe5c92011-05-03 22:09:39 +00002558 }
2559 }
Greg Claytonf9fc6092013-01-09 19:44:40 +00002560 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002561
Greg Claytonf9fc6092013-01-09 19:44:40 +00002562 if (total_num_dumped > 0)
2563 result.SetStatus (eReturnStatusSuccessFinishResult);
2564 else
2565 {
2566 result.AppendError ("no source filenames matched any command arguments");
2567 result.SetStatus (eReturnStatusFailed);
Greg Claytoneffe5c92011-05-03 22:09:39 +00002568 }
2569 return result.Succeeded();
2570 }
2571};
2572
2573
2574#pragma mark CommandObjectTargetModulesDump
2575
2576//----------------------------------------------------------------------
2577// Dump multi-word command for target modules
2578//----------------------------------------------------------------------
2579
2580class CommandObjectTargetModulesDump : public CommandObjectMultiword
2581{
2582public:
Greg Claytoneffe5c92011-05-03 22:09:39 +00002583 //------------------------------------------------------------------
2584 // Constructors and Destructors
2585 //------------------------------------------------------------------
2586 CommandObjectTargetModulesDump(CommandInterpreter &interpreter) :
2587 CommandObjectMultiword (interpreter,
2588 "target modules dump",
2589 "A set of commands for dumping information about one or more target modules.",
2590 "target modules dump [symtab|sections|symfile|line-table] [<file1> <file2> ...]")
2591 {
2592 LoadSubCommand ("symtab", CommandObjectSP (new CommandObjectTargetModulesDumpSymtab (interpreter)));
2593 LoadSubCommand ("sections", CommandObjectSP (new CommandObjectTargetModulesDumpSections (interpreter)));
2594 LoadSubCommand ("symfile", CommandObjectSP (new CommandObjectTargetModulesDumpSymfile (interpreter)));
2595 LoadSubCommand ("line-table", CommandObjectSP (new CommandObjectTargetModulesDumpLineTable (interpreter)));
2596 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002597
Greg Claytoneffe5c92011-05-03 22:09:39 +00002598 virtual
2599 ~CommandObjectTargetModulesDump()
2600 {
2601 }
2602};
2603
Jim Ingham5a988412012-06-08 21:56:10 +00002604class CommandObjectTargetModulesAdd : public CommandObjectParsed
Greg Claytoneffe5c92011-05-03 22:09:39 +00002605{
2606public:
2607 CommandObjectTargetModulesAdd (CommandInterpreter &interpreter) :
Jim Ingham5a988412012-06-08 21:56:10 +00002608 CommandObjectParsed (interpreter,
2609 "target modules add",
2610 "Add a new module to the current target's modules.",
Greg Clayton50a24bd2012-11-29 22:16:27 +00002611 "target modules add [<module>]"),
Greg Clayton1c5f1862012-11-30 19:05:35 +00002612 m_option_group (interpreter),
2613 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 +00002614 {
Greg Clayton50a24bd2012-11-29 22:16:27 +00002615 m_option_group.Append (&m_uuid_option_group, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
Greg Clayton1c5f1862012-11-30 19:05:35 +00002616 m_option_group.Append (&m_symbol_file, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
Greg Clayton50a24bd2012-11-29 22:16:27 +00002617 m_option_group.Finalize();
Greg Claytoneffe5c92011-05-03 22:09:39 +00002618 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002619
Greg Claytoneffe5c92011-05-03 22:09:39 +00002620 virtual
2621 ~CommandObjectTargetModulesAdd ()
2622 {
2623 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002624
Greg Clayton50a24bd2012-11-29 22:16:27 +00002625 virtual Options *
2626 GetOptions ()
2627 {
2628 return &m_option_group;
2629 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002630
Greg Claytonc7bece562013-01-25 18:06:21 +00002631 virtual int
Jim Ingham5a988412012-06-08 21:56:10 +00002632 HandleArgumentCompletion (Args &input,
2633 int &cursor_index,
2634 int &cursor_char_position,
2635 OptionElementVector &opt_element_vector,
2636 int match_start_point,
2637 int max_return_elements,
2638 bool &word_complete,
2639 StringList &matches)
2640 {
2641 std::string completion_str (input.GetArgumentAtIndex(cursor_index));
2642 completion_str.erase (cursor_char_position);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002643
Jim Ingham5a988412012-06-08 21:56:10 +00002644 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
2645 CommandCompletions::eDiskFileCompletion,
2646 completion_str.c_str(),
2647 match_start_point,
2648 max_return_elements,
2649 NULL,
2650 word_complete,
2651 matches);
2652 return matches.GetSize();
2653 }
2654
2655protected:
Greg Clayton50a24bd2012-11-29 22:16:27 +00002656 OptionGroupOptions m_option_group;
2657 OptionGroupUUID m_uuid_option_group;
Greg Clayton1c5f1862012-11-30 19:05:35 +00002658 OptionGroupFile m_symbol_file;
Greg Clayton50a24bd2012-11-29 22:16:27 +00002659
Greg Claytoneffe5c92011-05-03 22:09:39 +00002660 virtual bool
Jim Ingham5a988412012-06-08 21:56:10 +00002661 DoExecute (Args& args,
Greg Claytoneffe5c92011-05-03 22:09:39 +00002662 CommandReturnObject &result)
2663 {
2664 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
2665 if (target == NULL)
2666 {
2667 result.AppendError ("invalid target, create a debug target using the 'target create' command");
2668 result.SetStatus (eReturnStatusFailed);
2669 return false;
2670 }
2671 else
2672 {
Sean Callananb36c6c02012-12-13 01:39:39 +00002673 bool flush = false;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002674
Greg Claytoneffe5c92011-05-03 22:09:39 +00002675 const size_t argc = args.GetArgumentCount();
2676 if (argc == 0)
2677 {
Greg Clayton50a24bd2012-11-29 22:16:27 +00002678 if (m_uuid_option_group.GetOptionValue ().OptionWasSet())
2679 {
2680 // We are given a UUID only, go locate the file
2681 ModuleSpec module_spec;
2682 module_spec.GetUUID() = m_uuid_option_group.GetOptionValue ().GetCurrentValue();
Greg Clayton1c5f1862012-11-30 19:05:35 +00002683 if (m_symbol_file.GetOptionValue().OptionWasSet())
2684 module_spec.GetSymbolFileSpec() = m_symbol_file.GetOptionValue().GetCurrentValue();
Greg Clayton50a24bd2012-11-29 22:16:27 +00002685 if (Symbols::DownloadObjectAndSymbolFile (module_spec))
2686 {
2687 ModuleSP module_sp (target->GetSharedModule (module_spec));
2688 if (module_sp)
2689 {
2690 result.SetStatus (eReturnStatusSuccessFinishResult);
2691 return true;
2692 }
2693 else
2694 {
2695 StreamString strm;
2696 module_spec.GetUUID().Dump (&strm);
2697 if (module_spec.GetFileSpec())
2698 {
2699 if (module_spec.GetSymbolFileSpec())
2700 {
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00002701 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 +00002702 strm.GetString().c_str(),
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00002703 module_spec.GetFileSpec().GetPath().c_str(),
2704 module_spec.GetSymbolFileSpec().GetPath().c_str());
Greg Clayton50a24bd2012-11-29 22:16:27 +00002705 }
2706 else
2707 {
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00002708 result.AppendErrorWithFormat ("Unable to create the executable or symbol file with UUID %s with path %s",
Greg Clayton50a24bd2012-11-29 22:16:27 +00002709 strm.GetString().c_str(),
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00002710 module_spec.GetFileSpec().GetPath().c_str());
Greg Clayton50a24bd2012-11-29 22:16:27 +00002711 }
2712 }
2713 else
2714 {
2715 result.AppendErrorWithFormat ("Unable to create the executable or symbol file with UUID %s",
2716 strm.GetString().c_str());
2717 }
2718 result.SetStatus (eReturnStatusFailed);
2719 return false;
2720 }
2721 }
2722 else
2723 {
2724 StreamString strm;
2725 module_spec.GetUUID().Dump (&strm);
2726 result.AppendErrorWithFormat ("Unable to locate the executable or symbol file with UUID %s", strm.GetString().c_str());
2727 result.SetStatus (eReturnStatusFailed);
2728 return false;
2729 }
2730 }
2731 else
2732 {
2733 result.AppendError ("one or more executable image paths must be specified");
2734 result.SetStatus (eReturnStatusFailed);
2735 return false;
2736 }
Greg Claytoneffe5c92011-05-03 22:09:39 +00002737 }
2738 else
2739 {
2740 for (size_t i=0; i<argc; ++i)
2741 {
2742 const char *path = args.GetArgumentAtIndex(i);
2743 if (path)
2744 {
2745 FileSpec file_spec(path, true);
Greg Claytoneffe5c92011-05-03 22:09:39 +00002746 if (file_spec.Exists())
2747 {
Greg Claytonb9a01b32012-02-26 05:51:37 +00002748 ModuleSpec module_spec (file_spec);
Greg Clayton50a24bd2012-11-29 22:16:27 +00002749 if (m_uuid_option_group.GetOptionValue ().OptionWasSet())
2750 module_spec.GetUUID() = m_uuid_option_group.GetOptionValue ().GetCurrentValue();
Greg Clayton1c5f1862012-11-30 19:05:35 +00002751 if (m_symbol_file.GetOptionValue().OptionWasSet())
2752 module_spec.GetSymbolFileSpec() = m_symbol_file.GetOptionValue().GetCurrentValue();
Jason Molendab019cd92013-09-11 21:25:46 +00002753 if (!module_spec.GetArchitecture().IsValid())
2754 module_spec.GetArchitecture() = target->GetArchitecture();
Greg Clayton50a24bd2012-11-29 22:16:27 +00002755 Error error;
2756 ModuleSP module_sp (target->GetSharedModule (module_spec, &error));
Greg Claytoneffe5c92011-05-03 22:09:39 +00002757 if (!module_sp)
2758 {
Greg Clayton50a24bd2012-11-29 22:16:27 +00002759 const char *error_cstr = error.AsCString();
2760 if (error_cstr)
2761 result.AppendError (error_cstr);
2762 else
2763 result.AppendErrorWithFormat ("unsupported module: %s", path);
Greg Claytoneffe5c92011-05-03 22:09:39 +00002764 result.SetStatus (eReturnStatusFailed);
2765 return false;
2766 }
Sean Callananb36c6c02012-12-13 01:39:39 +00002767 else
2768 {
2769 flush = true;
2770 }
Jason Molenda2f7af6a2011-08-02 23:28:55 +00002771 result.SetStatus (eReturnStatusSuccessFinishResult);
Greg Claytoneffe5c92011-05-03 22:09:39 +00002772 }
2773 else
2774 {
2775 char resolved_path[PATH_MAX];
2776 result.SetStatus (eReturnStatusFailed);
2777 if (file_spec.GetPath (resolved_path, sizeof(resolved_path)))
2778 {
2779 if (strcmp (resolved_path, path) != 0)
2780 {
2781 result.AppendErrorWithFormat ("invalid module path '%s' with resolved path '%s'\n", path, resolved_path);
2782 break;
2783 }
2784 }
2785 result.AppendErrorWithFormat ("invalid module path '%s'\n", path);
2786 break;
2787 }
2788 }
2789 }
2790 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002791
Sean Callananb36c6c02012-12-13 01:39:39 +00002792 if (flush)
2793 {
2794 ProcessSP process = target->GetProcessSP();
2795 if (process)
2796 process->Flush();
2797 }
Greg Claytoneffe5c92011-05-03 22:09:39 +00002798 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002799
Greg Claytoneffe5c92011-05-03 22:09:39 +00002800 return result.Succeeded();
2801 }
2802
Greg Claytoneffe5c92011-05-03 22:09:39 +00002803};
2804
2805class CommandObjectTargetModulesLoad : public CommandObjectTargetModulesModuleAutoComplete
2806{
2807public:
2808 CommandObjectTargetModulesLoad (CommandInterpreter &interpreter) :
2809 CommandObjectTargetModulesModuleAutoComplete (interpreter,
2810 "target modules load",
2811 "Set the load addresses for one or more sections in a target module.",
2812 "target modules load [--file <module> --uuid <uuid>] <sect-name> <address> [<sect-name> <address> ....]"),
2813 m_option_group (interpreter),
Sean Callanan31542552012-10-24 01:12:14 +00002814 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 +00002815 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)
2816 {
2817 m_option_group.Append (&m_uuid_option_group, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
2818 m_option_group.Append (&m_file_option, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
2819 m_option_group.Append (&m_slide_option, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
2820 m_option_group.Finalize();
2821 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002822
Greg Claytoneffe5c92011-05-03 22:09:39 +00002823 virtual
2824 ~CommandObjectTargetModulesLoad ()
2825 {
2826 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002827
Jim Ingham5a988412012-06-08 21:56:10 +00002828 virtual Options *
2829 GetOptions ()
2830 {
2831 return &m_option_group;
2832 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002833
Jim Ingham5a988412012-06-08 21:56:10 +00002834protected:
Greg Claytoneffe5c92011-05-03 22:09:39 +00002835 virtual bool
Jim Ingham5a988412012-06-08 21:56:10 +00002836 DoExecute (Args& args,
Greg Claytoneffe5c92011-05-03 22:09:39 +00002837 CommandReturnObject &result)
2838 {
2839 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
2840 if (target == NULL)
2841 {
2842 result.AppendError ("invalid target, create a debug target using the 'target create' command");
2843 result.SetStatus (eReturnStatusFailed);
2844 return false;
2845 }
2846 else
2847 {
2848 const size_t argc = args.GetArgumentCount();
Greg Claytonb9a01b32012-02-26 05:51:37 +00002849 ModuleSpec module_spec;
2850 bool search_using_module_spec = false;
Greg Claytoneffe5c92011-05-03 22:09:39 +00002851 if (m_file_option.GetOptionValue().OptionWasSet())
Greg Claytonb9a01b32012-02-26 05:51:37 +00002852 {
2853 search_using_module_spec = true;
2854 module_spec.GetFileSpec() = m_file_option.GetOptionValue().GetCurrentValue();
2855 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002856
Greg Claytoneffe5c92011-05-03 22:09:39 +00002857 if (m_uuid_option_group.GetOptionValue().OptionWasSet())
Greg Claytonb9a01b32012-02-26 05:51:37 +00002858 {
2859 search_using_module_spec = true;
2860 module_spec.GetUUID() = m_uuid_option_group.GetOptionValue().GetCurrentValue();
2861 }
Greg Claytoneffe5c92011-05-03 22:09:39 +00002862
Greg Claytonb9a01b32012-02-26 05:51:37 +00002863 if (search_using_module_spec)
Greg Claytoneffe5c92011-05-03 22:09:39 +00002864 {
Greg Claytoneffe5c92011-05-03 22:09:39 +00002865 ModuleList matching_modules;
Greg Claytonb9a01b32012-02-26 05:51:37 +00002866 const size_t num_matches = target->GetImages().FindModules (module_spec, matching_modules);
Greg Claytoneffe5c92011-05-03 22:09:39 +00002867
2868 char path[PATH_MAX];
2869 if (num_matches == 1)
2870 {
2871 Module *module = matching_modules.GetModulePointerAtIndex(0);
2872 if (module)
2873 {
2874 ObjectFile *objfile = module->GetObjectFile();
2875 if (objfile)
2876 {
Greg Clayton3046e662013-07-10 01:23:25 +00002877 SectionList *section_list = module->GetSectionList();
Greg Claytoneffe5c92011-05-03 22:09:39 +00002878 if (section_list)
2879 {
Greg Clayton741f3f92012-03-27 21:10:07 +00002880 bool changed = false;
Greg Claytoneffe5c92011-05-03 22:09:39 +00002881 if (argc == 0)
2882 {
2883 if (m_slide_option.GetOptionValue().OptionWasSet())
2884 {
Greg Clayton741f3f92012-03-27 21:10:07 +00002885 const addr_t slide = m_slide_option.GetOptionValue().GetCurrentValue();
Greg Clayton751caf62014-02-07 22:54:47 +00002886 const bool slide_is_offset = true;
2887 module->SetLoadAddress (*target, slide, slide_is_offset, changed);
Greg Claytoneffe5c92011-05-03 22:09:39 +00002888 }
2889 else
2890 {
2891 result.AppendError ("one or more section name + load address pair must be specified");
2892 result.SetStatus (eReturnStatusFailed);
2893 return false;
2894 }
2895 }
2896 else
2897 {
2898 if (m_slide_option.GetOptionValue().OptionWasSet())
2899 {
2900 result.AppendError ("The \"--slide <offset>\" option can't be used in conjunction with setting section load addresses.\n");
2901 result.SetStatus (eReturnStatusFailed);
2902 return false;
2903 }
2904
2905 for (size_t i=0; i<argc; i += 2)
2906 {
2907 const char *sect_name = args.GetArgumentAtIndex(i);
2908 const char *load_addr_cstr = args.GetArgumentAtIndex(i+1);
2909 if (sect_name && load_addr_cstr)
2910 {
2911 ConstString const_sect_name(sect_name);
2912 bool success = false;
2913 addr_t load_addr = Args::StringToUInt64(load_addr_cstr, LLDB_INVALID_ADDRESS, 0, &success);
2914 if (success)
2915 {
2916 SectionSP section_sp (section_list->FindSectionByName(const_sect_name));
2917 if (section_sp)
2918 {
Greg Clayton741f3f92012-03-27 21:10:07 +00002919 if (section_sp->IsThreadSpecific())
2920 {
2921 result.AppendErrorWithFormat ("thread specific sections are not yet supported (section '%s')\n", sect_name);
2922 result.SetStatus (eReturnStatusFailed);
2923 break;
2924 }
2925 else
2926 {
Greg Clayton7820bd12012-07-07 01:24:12 +00002927 if (target->GetSectionLoadList().SetSectionLoadAddress (section_sp, load_addr))
Greg Clayton741f3f92012-03-27 21:10:07 +00002928 changed = true;
Daniel Malead01b2952012-11-29 21:49:15 +00002929 result.AppendMessageWithFormat("section '%s' loaded at 0x%" PRIx64 "\n", sect_name, load_addr);
Greg Clayton741f3f92012-03-27 21:10:07 +00002930 }
Greg Claytoneffe5c92011-05-03 22:09:39 +00002931 }
2932 else
2933 {
2934 result.AppendErrorWithFormat ("no section found that matches the section name '%s'\n", sect_name);
2935 result.SetStatus (eReturnStatusFailed);
2936 break;
2937 }
2938 }
2939 else
2940 {
2941 result.AppendErrorWithFormat ("invalid load address string '%s'\n", load_addr_cstr);
2942 result.SetStatus (eReturnStatusFailed);
2943 break;
2944 }
2945 }
2946 else
2947 {
2948 if (sect_name)
2949 result.AppendError ("section names must be followed by a load address.\n");
2950 else
2951 result.AppendError ("one or more section name + load address pair must be specified.\n");
2952 result.SetStatus (eReturnStatusFailed);
2953 break;
2954 }
2955 }
2956 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002957
Greg Clayton741f3f92012-03-27 21:10:07 +00002958 if (changed)
Greg Clayton3c947372013-01-29 01:17:09 +00002959 {
Greg Clayton741f3f92012-03-27 21:10:07 +00002960 target->ModulesDidLoad (matching_modules);
Greg Clayton3c947372013-01-29 01:17:09 +00002961 Process *process = m_exe_ctx.GetProcessPtr();
2962 if (process)
2963 process->Flush();
2964 }
Greg Claytoneffe5c92011-05-03 22:09:39 +00002965 }
2966 else
2967 {
2968 module->GetFileSpec().GetPath (path, sizeof(path));
2969 result.AppendErrorWithFormat ("no sections in object file '%s'\n", path);
2970 result.SetStatus (eReturnStatusFailed);
2971 }
2972 }
2973 else
2974 {
2975 module->GetFileSpec().GetPath (path, sizeof(path));
2976 result.AppendErrorWithFormat ("no object file for module '%s'\n", path);
2977 result.SetStatus (eReturnStatusFailed);
2978 }
2979 }
2980 else
2981 {
Jim Ingham28eb5712012-10-12 17:34:26 +00002982 FileSpec *module_spec_file = module_spec.GetFileSpecPtr();
2983 if (module_spec_file)
2984 {
2985 module_spec_file->GetPath (path, sizeof(path));
2986 result.AppendErrorWithFormat ("invalid module '%s'.\n", path);
2987 }
2988 else
2989 result.AppendError ("no module spec");
Greg Claytoneffe5c92011-05-03 22:09:39 +00002990 result.SetStatus (eReturnStatusFailed);
2991 }
2992 }
2993 else
2994 {
Jason Molendac16b4af2013-05-03 23:56:12 +00002995 std::string uuid_str;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002996
Greg Claytonb9a01b32012-02-26 05:51:37 +00002997 if (module_spec.GetFileSpec())
2998 module_spec.GetFileSpec().GetPath (path, sizeof(path));
Greg Claytoneffe5c92011-05-03 22:09:39 +00002999 else
3000 path[0] = '\0';
3001
Greg Claytonb9a01b32012-02-26 05:51:37 +00003002 if (module_spec.GetUUIDPtr())
Jason Molendac16b4af2013-05-03 23:56:12 +00003003 uuid_str = module_spec.GetUUID().GetAsString();
Greg Claytoneffe5c92011-05-03 22:09:39 +00003004 if (num_matches > 1)
3005 {
3006 result.AppendErrorWithFormat ("multiple modules match%s%s%s%s:\n",
3007 path[0] ? " file=" : "",
3008 path,
Jason Molendac16b4af2013-05-03 23:56:12 +00003009 !uuid_str.empty() ? " uuid=" : "",
3010 uuid_str.c_str());
Greg Claytoneffe5c92011-05-03 22:09:39 +00003011 for (size_t i=0; i<num_matches; ++i)
3012 {
3013 if (matching_modules.GetModulePointerAtIndex(i)->GetFileSpec().GetPath (path, sizeof(path)))
3014 result.AppendMessageWithFormat("%s\n", path);
3015 }
3016 }
3017 else
3018 {
3019 result.AppendErrorWithFormat ("no modules were found that match%s%s%s%s.\n",
3020 path[0] ? " file=" : "",
3021 path,
Jason Molendac16b4af2013-05-03 23:56:12 +00003022 !uuid_str.empty() ? " uuid=" : "",
3023 uuid_str.c_str());
Greg Claytoneffe5c92011-05-03 22:09:39 +00003024 }
3025 result.SetStatus (eReturnStatusFailed);
3026 }
3027 }
3028 else
3029 {
3030 result.AppendError ("either the \"--file <module>\" or the \"--uuid <uuid>\" option must be specified.\n");
3031 result.SetStatus (eReturnStatusFailed);
3032 return false;
3033 }
3034 }
3035 return result.Succeeded();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003036 }
3037
Greg Claytoneffe5c92011-05-03 22:09:39 +00003038 OptionGroupOptions m_option_group;
3039 OptionGroupUUID m_uuid_option_group;
3040 OptionGroupFile m_file_option;
3041 OptionGroupUInt64 m_slide_option;
3042};
3043
3044//----------------------------------------------------------------------
3045// List images with associated information
3046//----------------------------------------------------------------------
Jim Ingham5a988412012-06-08 21:56:10 +00003047class CommandObjectTargetModulesList : public CommandObjectParsed
Greg Claytoneffe5c92011-05-03 22:09:39 +00003048{
3049public:
Greg Claytoneffe5c92011-05-03 22:09:39 +00003050 class CommandOptions : public Options
3051 {
3052 public:
Greg Claytoneffe5c92011-05-03 22:09:39 +00003053 CommandOptions (CommandInterpreter &interpreter) :
Greg Clayton65a03992011-08-09 00:01:09 +00003054 Options(interpreter),
Jim Inghamc10312c2011-10-24 18:36:33 +00003055 m_format_array(),
Daniel Dunbara08823f2011-10-31 22:50:49 +00003056 m_use_global_module_list (false),
Jim Inghamc10312c2011-10-24 18:36:33 +00003057 m_module_addr (LLDB_INVALID_ADDRESS)
Greg Claytoneffe5c92011-05-03 22:09:39 +00003058 {
3059 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003060
Greg Claytoneffe5c92011-05-03 22:09:39 +00003061 virtual
3062 ~CommandOptions ()
3063 {
3064 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003065
Greg Claytoneffe5c92011-05-03 22:09:39 +00003066 virtual Error
3067 SetOptionValue (uint32_t option_idx, const char *option_arg)
3068 {
Greg Claytonb9d5df52012-12-06 22:49:16 +00003069 Error error;
3070
Greg Clayton3bcdfc02012-12-04 00:32:51 +00003071 const int short_option = m_getopt_table[option_idx].val;
Greg Clayton65a03992011-08-09 00:01:09 +00003072 if (short_option == 'g')
3073 {
3074 m_use_global_module_list = true;
3075 }
Jim Inghamc10312c2011-10-24 18:36:33 +00003076 else if (short_option == 'a')
3077 {
Jim Inghame7b849e2013-03-15 23:09:19 +00003078 ExecutionContext exe_ctx (m_interpreter.GetExecutionContext());
3079 m_module_addr = Args::StringToAddress(&exe_ctx, option_arg, LLDB_INVALID_ADDRESS, &error);
Jim Inghamc10312c2011-10-24 18:36:33 +00003080 }
Greg Clayton65a03992011-08-09 00:01:09 +00003081 else
3082 {
Greg Claytonc7bece562013-01-25 18:06:21 +00003083 unsigned long width = 0;
Greg Clayton65a03992011-08-09 00:01:09 +00003084 if (option_arg)
3085 width = strtoul (option_arg, NULL, 0);
3086 m_format_array.push_back(std::make_pair(short_option, width));
3087 }
Greg Claytoneffe5c92011-05-03 22:09:39 +00003088 return error;
3089 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003090
Greg Claytoneffe5c92011-05-03 22:09:39 +00003091 void
3092 OptionParsingStarting ()
3093 {
3094 m_format_array.clear();
Greg Clayton65a03992011-08-09 00:01:09 +00003095 m_use_global_module_list = false;
Jim Inghamc10312c2011-10-24 18:36:33 +00003096 m_module_addr = LLDB_INVALID_ADDRESS;
Greg Claytoneffe5c92011-05-03 22:09:39 +00003097 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003098
Greg Claytoneffe5c92011-05-03 22:09:39 +00003099 const OptionDefinition*
3100 GetDefinitions ()
3101 {
3102 return g_option_table;
3103 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003104
Greg Claytoneffe5c92011-05-03 22:09:39 +00003105 // Options table: Required for subclasses of Options.
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003106
Greg Claytoneffe5c92011-05-03 22:09:39 +00003107 static OptionDefinition g_option_table[];
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003108
Greg Claytoneffe5c92011-05-03 22:09:39 +00003109 // Instance variables to hold the values for command options.
3110 typedef std::vector< std::pair<char, uint32_t> > FormatWidthCollection;
3111 FormatWidthCollection m_format_array;
Greg Clayton65a03992011-08-09 00:01:09 +00003112 bool m_use_global_module_list;
Jim Inghamc10312c2011-10-24 18:36:33 +00003113 lldb::addr_t m_module_addr;
Greg Claytoneffe5c92011-05-03 22:09:39 +00003114 };
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003115
Greg Claytoneffe5c92011-05-03 22:09:39 +00003116 CommandObjectTargetModulesList (CommandInterpreter &interpreter) :
Jim Ingham5a988412012-06-08 21:56:10 +00003117 CommandObjectParsed (interpreter,
3118 "target modules list",
3119 "List current executable and dependent shared library images.",
3120 "target modules list [<cmd-options>]"),
Greg Claytoneffe5c92011-05-03 22:09:39 +00003121 m_options (interpreter)
3122 {
3123 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003124
Greg Claytoneffe5c92011-05-03 22:09:39 +00003125 virtual
3126 ~CommandObjectTargetModulesList ()
3127 {
3128 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003129
Greg Claytoneffe5c92011-05-03 22:09:39 +00003130 virtual
3131 Options *
3132 GetOptions ()
3133 {
3134 return &m_options;
3135 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003136
Jim Ingham5a988412012-06-08 21:56:10 +00003137protected:
Greg Claytoneffe5c92011-05-03 22:09:39 +00003138 virtual bool
Jim Ingham5a988412012-06-08 21:56:10 +00003139 DoExecute (Args& command,
Greg Claytoneffe5c92011-05-03 22:09:39 +00003140 CommandReturnObject &result)
3141 {
3142 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Greg Clayton3418c852011-08-10 02:10:13 +00003143 const bool use_global_module_list = m_options.m_use_global_module_list;
Greg Clayton234076c2012-06-27 20:26:19 +00003144 // Define a local module list here to ensure it lives longer than any "locker"
3145 // object which might lock its contents below (through the "module_list_ptr"
3146 // variable).
3147 ModuleList module_list;
Greg Clayton3418c852011-08-10 02:10:13 +00003148 if (target == NULL && use_global_module_list == false)
Greg Claytoneffe5c92011-05-03 22:09:39 +00003149 {
3150 result.AppendError ("invalid target, create a debug target using the 'target create' command");
3151 result.SetStatus (eReturnStatusFailed);
3152 return false;
3153 }
3154 else
3155 {
Greg Clayton3418c852011-08-10 02:10:13 +00003156 if (target)
3157 {
3158 uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize();
3159 result.GetOutputStream().SetAddressByteSize(addr_byte_size);
3160 result.GetErrorStream().SetAddressByteSize(addr_byte_size);
3161 }
Greg Claytoneffe5c92011-05-03 22:09:39 +00003162 // Dump all sections for all modules images
Jim Inghamc10312c2011-10-24 18:36:33 +00003163 Stream &strm = result.GetOutputStream();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003164
Jim Inghamc10312c2011-10-24 18:36:33 +00003165 if (m_options.m_module_addr != LLDB_INVALID_ADDRESS)
3166 {
3167 if (target)
3168 {
3169 Address module_address;
3170 if (module_address.SetLoadAddress(m_options.m_module_addr, target))
3171 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003172 ModuleSP module_sp (module_address.GetModule());
3173 if (module_sp)
Jim Inghamc10312c2011-10-24 18:36:33 +00003174 {
Greg Claytonc7bece562013-01-25 18:06:21 +00003175 PrintModule (target, module_sp.get(), 0, strm);
Jim Inghamc10312c2011-10-24 18:36:33 +00003176 result.SetStatus (eReturnStatusSuccessFinishResult);
3177 }
3178 else
3179 {
Jim Ingham17fafa12012-12-15 02:40:54 +00003180 result.AppendErrorWithFormat ("Couldn't find module matching address: 0x%" PRIx64 ".", m_options.m_module_addr);
Jim Inghamc10312c2011-10-24 18:36:33 +00003181 result.SetStatus (eReturnStatusFailed);
3182 }
3183 }
3184 else
3185 {
Jim Ingham17fafa12012-12-15 02:40:54 +00003186 result.AppendErrorWithFormat ("Couldn't find module containing address: 0x%" PRIx64 ".", m_options.m_module_addr);
Jim Inghamc10312c2011-10-24 18:36:33 +00003187 result.SetStatus (eReturnStatusFailed);
3188 }
3189 }
3190 else
3191 {
3192 result.AppendError ("Can only look up modules by address with a valid target.");
3193 result.SetStatus (eReturnStatusFailed);
3194 }
3195 return result.Succeeded();
3196 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003197
Greg Claytonc7bece562013-01-25 18:06:21 +00003198 size_t num_modules = 0;
Jim Ingham3ee12ef2012-05-30 02:19:25 +00003199 Mutex::Locker locker; // This locker will be locked on the mutex in module_list_ptr if it is non-NULL.
3200 // Otherwise it will lock the AllocationModuleCollectionMutex when accessing
3201 // the global module list directly.
Enrico Granata17598482012-11-08 02:22:02 +00003202 const ModuleList *module_list_ptr = NULL;
Greg Claytonc4a8a762012-05-15 18:43:44 +00003203 const size_t argc = command.GetArgumentCount();
3204 if (argc == 0)
Greg Clayton65a03992011-08-09 00:01:09 +00003205 {
Greg Claytonc4a8a762012-05-15 18:43:44 +00003206 if (use_global_module_list)
3207 {
3208 locker.Lock (Module::GetAllocationModuleCollectionMutex());
3209 num_modules = Module::GetNumberAllocatedModules();
3210 }
3211 else
3212 {
3213 module_list_ptr = &target->GetImages();
Greg Claytonc4a8a762012-05-15 18:43:44 +00003214 }
Greg Clayton65a03992011-08-09 00:01:09 +00003215 }
3216 else
Greg Claytonc4a8a762012-05-15 18:43:44 +00003217 {
3218 for (size_t i=0; i<argc; ++i)
3219 {
3220 // Dump specified images (by basename or fullpath)
3221 const char *arg_cstr = command.GetArgumentAtIndex(i);
3222 const size_t num_matches = FindModulesByName (target, arg_cstr, module_list, use_global_module_list);
3223 if (num_matches == 0)
3224 {
3225 if (argc == 1)
3226 {
3227 result.AppendErrorWithFormat ("no modules found that match '%s'", arg_cstr);
3228 result.SetStatus (eReturnStatusFailed);
3229 return false;
3230 }
3231 }
3232 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003233
Greg Claytonc4a8a762012-05-15 18:43:44 +00003234 module_list_ptr = &module_list;
3235 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003236
Jim Ingham3ee12ef2012-05-30 02:19:25 +00003237 if (module_list_ptr != NULL)
3238 {
3239 locker.Lock(module_list_ptr->GetMutex());
3240 num_modules = module_list_ptr->GetSize();
3241 }
Greg Clayton65a03992011-08-09 00:01:09 +00003242
Greg Claytoneffe5c92011-05-03 22:09:39 +00003243 if (num_modules > 0)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003244 {
Greg Claytoneffe5c92011-05-03 22:09:39 +00003245 for (uint32_t image_idx = 0; image_idx<num_modules; ++image_idx)
3246 {
Greg Clayton3418c852011-08-10 02:10:13 +00003247 ModuleSP module_sp;
Greg Clayton65a03992011-08-09 00:01:09 +00003248 Module *module;
Greg Claytonc4a8a762012-05-15 18:43:44 +00003249 if (module_list_ptr)
Greg Clayton65a03992011-08-09 00:01:09 +00003250 {
Jim Ingham3ee12ef2012-05-30 02:19:25 +00003251 module_sp = module_list_ptr->GetModuleAtIndexUnlocked(image_idx);
Greg Claytonc4a8a762012-05-15 18:43:44 +00003252 module = module_sp.get();
Greg Clayton65a03992011-08-09 00:01:09 +00003253 }
3254 else
3255 {
Greg Claytonc4a8a762012-05-15 18:43:44 +00003256 module = Module::GetAllocatedModuleAtIndex(image_idx);
3257 module_sp = module->shared_from_this();
Greg Clayton65a03992011-08-09 00:01:09 +00003258 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003259
Greg Claytonc7bece562013-01-25 18:06:21 +00003260 const size_t indent = strm.Printf("[%3u] ", image_idx);
3261 PrintModule (target, module, indent, strm);
Greg Clayton3418c852011-08-10 02:10:13 +00003262
Greg Claytoneffe5c92011-05-03 22:09:39 +00003263 }
3264 result.SetStatus (eReturnStatusSuccessFinishResult);
3265 }
3266 else
3267 {
Greg Claytonc4a8a762012-05-15 18:43:44 +00003268 if (argc)
3269 {
3270 if (use_global_module_list)
3271 result.AppendError ("the global module list has no matching modules");
3272 else
3273 result.AppendError ("the target has no matching modules");
3274 }
Greg Clayton3418c852011-08-10 02:10:13 +00003275 else
Greg Claytonc4a8a762012-05-15 18:43:44 +00003276 {
3277 if (use_global_module_list)
3278 result.AppendError ("the global module list is empty");
3279 else
3280 result.AppendError ("the target has no associated executable images");
3281 }
Greg Claytoneffe5c92011-05-03 22:09:39 +00003282 result.SetStatus (eReturnStatusFailed);
3283 return false;
3284 }
3285 }
3286 return result.Succeeded();
3287 }
Jim Inghamc10312c2011-10-24 18:36:33 +00003288
3289 void
Greg Claytonc7bece562013-01-25 18:06:21 +00003290 PrintModule (Target *target, Module *module, int indent, Stream &strm)
Jim Inghamc10312c2011-10-24 18:36:33 +00003291 {
3292
Jim Ingham28eb5712012-10-12 17:34:26 +00003293 if (module == NULL)
3294 {
3295 strm.PutCString("Null module");
3296 return;
3297 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003298
Jim Inghamc10312c2011-10-24 18:36:33 +00003299 bool dump_object_name = false;
3300 if (m_options.m_format_array.empty())
3301 {
Greg Claytonc9660542012-02-05 02:38:54 +00003302 m_options.m_format_array.push_back(std::make_pair('u', 0));
3303 m_options.m_format_array.push_back(std::make_pair('h', 0));
3304 m_options.m_format_array.push_back(std::make_pair('f', 0));
3305 m_options.m_format_array.push_back(std::make_pair('S', 0));
Jim Inghamc10312c2011-10-24 18:36:33 +00003306 }
Greg Claytonc9660542012-02-05 02:38:54 +00003307 const size_t num_entries = m_options.m_format_array.size();
3308 bool print_space = false;
3309 for (size_t i=0; i<num_entries; ++i)
Jim Inghamc10312c2011-10-24 18:36:33 +00003310 {
Greg Claytonc9660542012-02-05 02:38:54 +00003311 if (print_space)
3312 strm.PutChar(' ');
3313 print_space = true;
3314 const char format_char = m_options.m_format_array[i].first;
3315 uint32_t width = m_options.m_format_array[i].second;
3316 switch (format_char)
Jim Inghamc10312c2011-10-24 18:36:33 +00003317 {
Greg Claytonc9660542012-02-05 02:38:54 +00003318 case 'A':
3319 DumpModuleArchitecture (strm, module, false, width);
3320 break;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003321
Greg Claytonc9660542012-02-05 02:38:54 +00003322 case 't':
3323 DumpModuleArchitecture (strm, module, true, width);
3324 break;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003325
Greg Claytonc9660542012-02-05 02:38:54 +00003326 case 'f':
3327 DumpFullpath (strm, &module->GetFileSpec(), width);
3328 dump_object_name = true;
3329 break;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003330
Greg Claytonc9660542012-02-05 02:38:54 +00003331 case 'd':
3332 DumpDirectory (strm, &module->GetFileSpec(), width);
3333 break;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003334
Greg Claytonc9660542012-02-05 02:38:54 +00003335 case 'b':
3336 DumpBasename (strm, &module->GetFileSpec(), width);
3337 dump_object_name = true;
3338 break;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003339
Greg Claytonc9660542012-02-05 02:38:54 +00003340 case 'h':
3341 case 'o':
3342 // Image header address
3343 {
3344 uint32_t addr_nibble_width = target ? (target->GetArchitecture().GetAddressByteSize() * 2) : 16;
Jim Inghamc10312c2011-10-24 18:36:33 +00003345
Greg Claytonc9660542012-02-05 02:38:54 +00003346 ObjectFile *objfile = module->GetObjectFile ();
3347 if (objfile)
Jim Inghamc10312c2011-10-24 18:36:33 +00003348 {
Greg Claytonc9660542012-02-05 02:38:54 +00003349 Address header_addr(objfile->GetHeaderAddress());
3350 if (header_addr.IsValid())
Jim Inghamc10312c2011-10-24 18:36:33 +00003351 {
Greg Claytonc9660542012-02-05 02:38:54 +00003352 if (target && !target->GetSectionLoadList().IsEmpty())
Jim Inghamc10312c2011-10-24 18:36:33 +00003353 {
Greg Claytonc9660542012-02-05 02:38:54 +00003354 lldb::addr_t header_load_addr = header_addr.GetLoadAddress (target);
3355 if (header_load_addr == LLDB_INVALID_ADDRESS)
3356 {
3357 header_addr.Dump (&strm, target, Address::DumpStyleModuleWithFileAddress, Address::DumpStyleFileAddress);
3358 }
Jim Inghamc10312c2011-10-24 18:36:33 +00003359 else
Greg Claytonc9660542012-02-05 02:38:54 +00003360 {
3361 if (format_char == 'o')
3362 {
3363 // Show the offset of slide for the image
Daniel Malead01b2952012-11-29 21:49:15 +00003364 strm.Printf ("0x%*.*" PRIx64, addr_nibble_width, addr_nibble_width, header_load_addr - header_addr.GetFileAddress());
Greg Claytonc9660542012-02-05 02:38:54 +00003365 }
3366 else
3367 {
3368 // Show the load address of the image
Daniel Malead01b2952012-11-29 21:49:15 +00003369 strm.Printf ("0x%*.*" PRIx64, addr_nibble_width, addr_nibble_width, header_load_addr);
Greg Claytonc9660542012-02-05 02:38:54 +00003370 }
3371 }
Jim Inghamc10312c2011-10-24 18:36:33 +00003372 break;
3373 }
Greg Claytonc9660542012-02-05 02:38:54 +00003374 // The address was valid, but the image isn't loaded, output the address in an appropriate format
3375 header_addr.Dump (&strm, target, Address::DumpStyleFileAddress);
3376 break;
Jim Inghamc10312c2011-10-24 18:36:33 +00003377 }
Jim Inghamc10312c2011-10-24 18:36:33 +00003378 }
Greg Claytonc9660542012-02-05 02:38:54 +00003379 strm.Printf ("%*s", addr_nibble_width + 2, "");
3380 }
3381 break;
3382 case 'r':
3383 {
Greg Claytonc7bece562013-01-25 18:06:21 +00003384 size_t ref_count = 0;
Greg Claytonc9660542012-02-05 02:38:54 +00003385 ModuleSP module_sp (module->shared_from_this());
3386 if (module_sp)
3387 {
3388 // Take one away to make sure we don't count our local "module_sp"
3389 ref_count = module_sp.use_count() - 1;
3390 }
3391 if (width)
Greg Clayton6fea17e2014-03-03 19:15:20 +00003392 strm.Printf("{%*" PRIu64 "}", width, (uint64_t)ref_count);
Greg Claytonc9660542012-02-05 02:38:54 +00003393 else
Deepak Panickal99fbc072014-03-03 15:39:47 +00003394 strm.Printf("{%" PRIu64 "}", (uint64_t)ref_count);
Greg Claytonc9660542012-02-05 02:38:54 +00003395 }
3396 break;
Jim Inghamc10312c2011-10-24 18:36:33 +00003397
Greg Claytonc9660542012-02-05 02:38:54 +00003398 case 's':
3399 case 'S':
3400 {
3401 SymbolVendor *symbol_vendor = module->GetSymbolVendor();
3402 if (symbol_vendor)
3403 {
3404 SymbolFile *symbol_file = symbol_vendor->GetSymbolFile();
3405 if (symbol_file)
3406 {
3407 if (format_char == 'S')
3408 {
3409 FileSpec &symfile_spec = symbol_file->GetObjectFile()->GetFileSpec();
3410 // Dump symbol file only if different from module file
3411 if (!symfile_spec || symfile_spec == module->GetFileSpec())
3412 {
3413 print_space = false;
3414 break;
3415 }
3416 // Add a newline and indent past the index
3417 strm.Printf ("\n%*s", indent, "");
3418 }
3419 DumpFullpath (strm, &symbol_file->GetObjectFile()->GetFileSpec(), width);
3420 dump_object_name = true;
3421 break;
3422 }
3423 }
3424 strm.Printf("%.*s", width, "<NONE>");
3425 }
3426 break;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003427
Greg Claytonc9660542012-02-05 02:38:54 +00003428 case 'm':
3429 module->GetModificationTime().Dump(&strm, width);
3430 break;
Jim Inghamc10312c2011-10-24 18:36:33 +00003431
Greg Claytonc9660542012-02-05 02:38:54 +00003432 case 'p':
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003433 strm.Printf("%p", static_cast<void*>(module));
Greg Claytonc9660542012-02-05 02:38:54 +00003434 break;
3435
3436 case 'u':
3437 DumpModuleUUID(strm, module);
3438 break;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003439
Greg Claytonc9660542012-02-05 02:38:54 +00003440 default:
3441 break;
Jim Inghamc10312c2011-10-24 18:36:33 +00003442 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003443
Greg Claytonc9660542012-02-05 02:38:54 +00003444 }
3445 if (dump_object_name)
3446 {
3447 const char *object_name = module->GetObjectName().GetCString();
3448 if (object_name)
3449 strm.Printf ("(%s)", object_name);
Jim Inghamc10312c2011-10-24 18:36:33 +00003450 }
3451 strm.EOL();
3452 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003453
Greg Claytoneffe5c92011-05-03 22:09:39 +00003454 CommandOptions m_options;
3455};
3456
3457OptionDefinition
3458CommandObjectTargetModulesList::CommandOptions::g_option_table[] =
3459{
Virgile Belloe2607b52013-09-05 16:42:23 +00003460 { LLDB_OPT_SET_1, false, "address", 'a', OptionParser::eRequiredArgument, NULL, 0, eArgTypeAddressOrExpression, "Display the image at this address."},
3461 { LLDB_OPT_SET_1, false, "arch", 'A', OptionParser::eOptionalArgument, NULL, 0, eArgTypeWidth, "Display the architecture when listing images."},
3462 { LLDB_OPT_SET_1, false, "triple", 't', OptionParser::eOptionalArgument, NULL, 0, eArgTypeWidth, "Display the triple when listing images."},
3463 { 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."},
3464 { 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)."},
3465 { LLDB_OPT_SET_1, false, "uuid", 'u', OptionParser::eNoArgument, NULL, 0, eArgTypeNone, "Display the UUID when listing images."},
3466 { LLDB_OPT_SET_1, false, "fullpath", 'f', OptionParser::eOptionalArgument, NULL, 0, eArgTypeWidth, "Display the fullpath to the image object file."},
3467 { LLDB_OPT_SET_1, false, "directory", 'd', OptionParser::eOptionalArgument, NULL, 0, eArgTypeWidth, "Display the directory with optional width for the image object file."},
3468 { LLDB_OPT_SET_1, false, "basename", 'b', OptionParser::eOptionalArgument, NULL, 0, eArgTypeWidth, "Display the basename with optional width for the image object file."},
3469 { LLDB_OPT_SET_1, false, "symfile", 's', OptionParser::eOptionalArgument, NULL, 0, eArgTypeWidth, "Display the fullpath to the image symbol file with optional width."},
3470 { 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."},
3471 { LLDB_OPT_SET_1, false, "mod-time", 'm', OptionParser::eOptionalArgument, NULL, 0, eArgTypeWidth, "Display the modification time with optional width of the module."},
3472 { 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."},
3473 { LLDB_OPT_SET_1, false, "pointer", 'p', OptionParser::eOptionalArgument, NULL, 0, eArgTypeNone, "Display the module pointer."},
3474 { 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 +00003475 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
3476};
3477
Jason Molenda380241a2012-07-12 00:20:07 +00003478#pragma mark CommandObjectTargetModulesShowUnwind
Greg Claytoneffe5c92011-05-03 22:09:39 +00003479
Jason Molenda380241a2012-07-12 00:20:07 +00003480//----------------------------------------------------------------------
3481// Lookup unwind information in images
3482//----------------------------------------------------------------------
3483
3484class CommandObjectTargetModulesShowUnwind : public CommandObjectParsed
3485{
3486public:
3487
3488 enum
3489 {
3490 eLookupTypeInvalid = -1,
3491 eLookupTypeAddress = 0,
3492 eLookupTypeSymbol,
3493 eLookupTypeFunction,
3494 eLookupTypeFunctionOrSymbol,
3495 kNumLookupTypes
3496 };
3497
3498 class CommandOptions : public Options
3499 {
3500 public:
3501
3502 CommandOptions (CommandInterpreter &interpreter) :
Greg Claytonf9fc6092013-01-09 19:44:40 +00003503 Options(interpreter),
3504 m_type(eLookupTypeInvalid),
3505 m_str(),
3506 m_addr(LLDB_INVALID_ADDRESS)
Jason Molenda380241a2012-07-12 00:20:07 +00003507 {
3508 }
3509
3510 virtual
3511 ~CommandOptions ()
3512 {
3513 }
3514
3515 virtual Error
3516 SetOptionValue (uint32_t option_idx, const char *option_arg)
3517 {
3518 Error error;
3519
Greg Clayton3bcdfc02012-12-04 00:32:51 +00003520 const int short_option = m_getopt_table[option_idx].val;
Jason Molenda380241a2012-07-12 00:20:07 +00003521
3522 switch (short_option)
3523 {
3524 case 'a':
Jason Molenda535ab862013-04-23 04:30:57 +00003525 {
3526 ExecutionContext exe_ctx (m_interpreter.GetExecutionContext());
Michael Sartainb1e15922013-08-22 20:42:30 +00003527 m_str = option_arg;
Jason Molenda380241a2012-07-12 00:20:07 +00003528 m_type = eLookupTypeAddress;
Jason Molenda535ab862013-04-23 04:30:57 +00003529 m_addr = Args::StringToAddress(&exe_ctx, option_arg, LLDB_INVALID_ADDRESS, &error);
Jason Molenda380241a2012-07-12 00:20:07 +00003530 if (m_addr == LLDB_INVALID_ADDRESS)
3531 error.SetErrorStringWithFormat ("invalid address string '%s'", option_arg);
3532 break;
Jason Molenda535ab862013-04-23 04:30:57 +00003533 }
Jason Molenda380241a2012-07-12 00:20:07 +00003534
3535 case 'n':
Jason Molenda535ab862013-04-23 04:30:57 +00003536 {
Jason Molenda380241a2012-07-12 00:20:07 +00003537 m_str = option_arg;
3538 m_type = eLookupTypeFunctionOrSymbol;
3539 break;
Jason Molenda535ab862013-04-23 04:30:57 +00003540 }
Michael Sartainb1e15922013-08-22 20:42:30 +00003541
3542 default:
3543 error.SetErrorStringWithFormat ("unrecognized option %c.", short_option);
3544 break;
Jason Molenda380241a2012-07-12 00:20:07 +00003545 }
3546
3547 return error;
3548 }
3549
3550 void
3551 OptionParsingStarting ()
3552 {
3553 m_type = eLookupTypeInvalid;
3554 m_str.clear();
3555 m_addr = LLDB_INVALID_ADDRESS;
3556 }
3557
3558 const OptionDefinition*
3559 GetDefinitions ()
3560 {
3561 return g_option_table;
3562 }
3563
3564 // Options table: Required for subclasses of Options.
3565
3566 static OptionDefinition g_option_table[];
3567
3568 // Instance variables to hold the values for command options.
3569
3570 int m_type; // Should be a eLookupTypeXXX enum after parsing options
3571 std::string m_str; // Holds name lookup
3572 lldb::addr_t m_addr; // Holds the address to lookup
3573 };
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003574
Jason Molenda380241a2012-07-12 00:20:07 +00003575 CommandObjectTargetModulesShowUnwind (CommandInterpreter &interpreter) :
3576 CommandObjectParsed (interpreter,
3577 "target modules show-unwind",
3578 "Show synthesized unwind instructions for a function.",
Greg Claytonf9fc6092013-01-09 19:44:40 +00003579 NULL,
3580 eFlagRequiresTarget |
3581 eFlagRequiresProcess |
3582 eFlagProcessMustBeLaunched |
3583 eFlagProcessMustBePaused ),
Jason Molenda380241a2012-07-12 00:20:07 +00003584 m_options (interpreter)
3585 {
3586 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003587
Jason Molenda380241a2012-07-12 00:20:07 +00003588 virtual
3589 ~CommandObjectTargetModulesShowUnwind ()
3590 {
3591 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003592
Jason Molenda380241a2012-07-12 00:20:07 +00003593 virtual
3594 Options *
3595 GetOptions ()
3596 {
3597 return &m_options;
3598 }
3599
3600protected:
3601 bool
3602 DoExecute (Args& command,
3603 CommandReturnObject &result)
3604 {
Greg Claytonf9fc6092013-01-09 19:44:40 +00003605 Target *target = m_exe_ctx.GetTargetPtr();
3606 Process *process = m_exe_ctx.GetProcessPtr();
Jason Molenda380241a2012-07-12 00:20:07 +00003607 ABI *abi = NULL;
3608 if (process)
3609 abi = process->GetABI().get();
3610
3611 if (process == NULL)
3612 {
3613 result.AppendError ("You must have a process running to use this command.");
3614 result.SetStatus (eReturnStatusFailed);
3615 return false;
3616 }
3617
3618 ThreadList threads(process->GetThreadList());
3619 if (threads.GetSize() == 0)
3620 {
3621 result.AppendError ("The process must be paused to use this command.");
3622 result.SetStatus (eReturnStatusFailed);
3623 return false;
3624 }
3625
3626 ThreadSP thread(threads.GetThreadAtIndex(0));
3627 if (thread.get() == NULL)
3628 {
3629 result.AppendError ("The process must be paused to use this command.");
3630 result.SetStatus (eReturnStatusFailed);
3631 return false;
3632 }
3633
Jason Molenda535ab862013-04-23 04:30:57 +00003634 SymbolContextList sc_list;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003635
Jason Molenda380241a2012-07-12 00:20:07 +00003636 if (m_options.m_type == eLookupTypeFunctionOrSymbol)
3637 {
Jason Molenda380241a2012-07-12 00:20:07 +00003638 ConstString function_name (m_options.m_str.c_str());
Jason Molenda535ab862013-04-23 04:30:57 +00003639 target->GetImages().FindFunctions (function_name, eFunctionNameTypeAuto, true, false, true, sc_list);
3640 }
3641 else if (m_options.m_type == eLookupTypeAddress && target)
3642 {
3643 Address addr;
3644 if (target->GetSectionLoadList().ResolveLoadAddress (m_options.m_addr, addr))
Jason Molenda380241a2012-07-12 00:20:07 +00003645 {
3646 SymbolContext sc;
Jason Molenda535ab862013-04-23 04:30:57 +00003647 ModuleSP module_sp (addr.GetModule());
3648 module_sp->ResolveSymbolContextForAddress (addr, eSymbolContextEverything, sc);
3649 if (sc.function || sc.symbol)
Jason Molenda380241a2012-07-12 00:20:07 +00003650 {
Jason Molenda535ab862013-04-23 04:30:57 +00003651 sc_list.Append(sc);
Jason Molenda380241a2012-07-12 00:20:07 +00003652 }
Jason Molenda535ab862013-04-23 04:30:57 +00003653 }
3654 }
Michael Sartainb1e15922013-08-22 20:42:30 +00003655 else
3656 {
3657 result.AppendError ("address-expression or function name option must be specified.");
3658 result.SetStatus (eReturnStatusFailed);
3659 return false;
3660 }
Jason Molenda380241a2012-07-12 00:20:07 +00003661
Jason Molenda535ab862013-04-23 04:30:57 +00003662 size_t num_matches = sc_list.GetSize();
Michael Sartainb1e15922013-08-22 20:42:30 +00003663 if (num_matches == 0)
3664 {
3665 result.AppendErrorWithFormat ("no unwind data found that matches '%s'.", m_options.m_str.c_str());
3666 result.SetStatus (eReturnStatusFailed);
3667 return false;
3668 }
3669
Jason Molenda535ab862013-04-23 04:30:57 +00003670 for (uint32_t idx = 0; idx < num_matches; idx++)
3671 {
3672 SymbolContext sc;
3673 sc_list.GetContextAtIndex(idx, sc);
3674 if (sc.symbol == NULL && sc.function == NULL)
3675 continue;
3676 if (sc.module_sp.get() == NULL || sc.module_sp->GetObjectFile() == NULL)
3677 continue;
3678 AddressRange range;
3679 if (!sc.GetAddressRange (eSymbolContextFunction | eSymbolContextSymbol, 0, false, range))
3680 continue;
3681 if (!range.GetBaseAddress().IsValid())
3682 continue;
3683 ConstString funcname(sc.GetFunctionName());
3684 if (funcname.IsEmpty())
3685 continue;
3686 addr_t start_addr = range.GetBaseAddress().GetLoadAddress(target);
3687 if (abi)
3688 start_addr = abi->FixCodeAddress(start_addr);
Jason Molenda380241a2012-07-12 00:20:07 +00003689
Jason Molenda535ab862013-04-23 04:30:57 +00003690 FuncUnwindersSP func_unwinders_sp (sc.module_sp->GetObjectFile()->GetUnwindTable().GetUncachedFuncUnwindersContainingAddress(start_addr, sc));
3691 if (func_unwinders_sp.get() == NULL)
3692 continue;
Jason Molenda380241a2012-07-12 00:20:07 +00003693
Jason Molenda535ab862013-04-23 04:30:57 +00003694 Address first_non_prologue_insn (func_unwinders_sp->GetFirstNonPrologueInsn(*target));
3695 if (first_non_prologue_insn.IsValid())
3696 {
3697 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 +00003698 result.GetOutputStream().Printf ("\n");
3699 }
Jason Molenda535ab862013-04-23 04:30:57 +00003700
3701 UnwindPlanSP non_callsite_unwind_plan = func_unwinders_sp->GetUnwindPlanAtNonCallSite(*thread.get());
3702 if (non_callsite_unwind_plan.get())
3703 {
3704 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);
3705 non_callsite_unwind_plan->Dump(result.GetOutputStream(), thread.get(), LLDB_INVALID_ADDRESS);
3706 result.GetOutputStream().Printf ("\n");
3707 }
3708
3709 UnwindPlanSP callsite_unwind_plan = func_unwinders_sp->GetUnwindPlanAtCallSite(-1);
3710 if (callsite_unwind_plan.get())
3711 {
3712 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);
3713 callsite_unwind_plan->Dump(result.GetOutputStream(), thread.get(), LLDB_INVALID_ADDRESS);
3714 result.GetOutputStream().Printf ("\n");
3715 }
3716
3717 UnwindPlanSP arch_default_unwind_plan = func_unwinders_sp->GetUnwindPlanArchitectureDefault(*thread.get());
3718 if (arch_default_unwind_plan.get())
3719 {
3720 result.GetOutputStream().Printf("Architecture default UnwindPlan for %s`%s (start addr 0x%" PRIx64 "):\n", sc.module_sp->GetPlatformFileSpec().GetFilename().AsCString(), funcname.AsCString(), start_addr);
3721 arch_default_unwind_plan->Dump(result.GetOutputStream(), thread.get(), LLDB_INVALID_ADDRESS);
3722 result.GetOutputStream().Printf ("\n");
3723 }
3724
3725 UnwindPlanSP fast_unwind_plan = func_unwinders_sp->GetUnwindPlanFastUnwind(*thread.get());
3726 if (fast_unwind_plan.get())
3727 {
3728 result.GetOutputStream().Printf("Fast UnwindPlan for %s`%s (start addr 0x%" PRIx64 "):\n", sc.module_sp->GetPlatformFileSpec().GetFilename().AsCString(), funcname.AsCString(), start_addr);
3729 fast_unwind_plan->Dump(result.GetOutputStream(), thread.get(), LLDB_INVALID_ADDRESS);
3730 result.GetOutputStream().Printf ("\n");
3731 }
3732
3733
3734 result.GetOutputStream().Printf ("\n");
Jason Molenda380241a2012-07-12 00:20:07 +00003735 }
3736 return result.Succeeded();
3737 }
3738
3739 CommandOptions m_options;
3740};
3741
3742OptionDefinition
3743CommandObjectTargetModulesShowUnwind::CommandOptions::g_option_table[] =
3744{
Virgile Belloe2607b52013-09-05 16:42:23 +00003745 { LLDB_OPT_SET_1, false, "name", 'n', OptionParser::eRequiredArgument, NULL, 0, eArgTypeFunctionName, "Show unwind instructions for a function or symbol name."},
3746 { 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 +00003747 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
3748};
Greg Claytoneffe5c92011-05-03 22:09:39 +00003749
3750//----------------------------------------------------------------------
3751// Lookup information in images
3752//----------------------------------------------------------------------
Jim Ingham5a988412012-06-08 21:56:10 +00003753class CommandObjectTargetModulesLookup : public CommandObjectParsed
Greg Claytoneffe5c92011-05-03 22:09:39 +00003754{
3755public:
Greg Claytoneffe5c92011-05-03 22:09:39 +00003756 enum
3757 {
3758 eLookupTypeInvalid = -1,
3759 eLookupTypeAddress = 0,
3760 eLookupTypeSymbol,
3761 eLookupTypeFileLine, // Line is optional
3762 eLookupTypeFunction,
Greg Claytonc4a8a762012-05-15 18:43:44 +00003763 eLookupTypeFunctionOrSymbol,
Greg Claytoneffe5c92011-05-03 22:09:39 +00003764 eLookupTypeType,
3765 kNumLookupTypes
3766 };
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003767
Greg Claytoneffe5c92011-05-03 22:09:39 +00003768 class CommandOptions : public Options
3769 {
3770 public:
Greg Claytoneffe5c92011-05-03 22:09:39 +00003771 CommandOptions (CommandInterpreter &interpreter) :
3772 Options(interpreter)
3773 {
3774 OptionParsingStarting();
3775 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003776
Greg Claytoneffe5c92011-05-03 22:09:39 +00003777 virtual
3778 ~CommandOptions ()
3779 {
3780 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003781
Greg Claytoneffe5c92011-05-03 22:09:39 +00003782 virtual Error
3783 SetOptionValue (uint32_t option_idx, const char *option_arg)
3784 {
3785 Error error;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003786
Greg Clayton3bcdfc02012-12-04 00:32:51 +00003787 const int short_option = m_getopt_table[option_idx].val;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003788
Greg Claytoneffe5c92011-05-03 22:09:39 +00003789 switch (short_option)
3790 {
3791 case 'a':
Jim Inghame7b849e2013-03-15 23:09:19 +00003792 {
3793 m_type = eLookupTypeAddress;
3794 ExecutionContext exe_ctx (m_interpreter.GetExecutionContext());
3795 m_addr = Args::StringToAddress(&exe_ctx, option_arg, LLDB_INVALID_ADDRESS, &error);
3796 }
Greg Claytoneffe5c92011-05-03 22:09:39 +00003797 break;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003798
Greg Claytoneffe5c92011-05-03 22:09:39 +00003799 case 'o':
3800 m_offset = Args::StringToUInt64(option_arg, LLDB_INVALID_ADDRESS);
3801 if (m_offset == LLDB_INVALID_ADDRESS)
Greg Clayton86edbf42011-10-26 00:56:27 +00003802 error.SetErrorStringWithFormat ("invalid offset string '%s'", option_arg);
Greg Claytoneffe5c92011-05-03 22:09:39 +00003803 break;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003804
Greg Claytoneffe5c92011-05-03 22:09:39 +00003805 case 's':
3806 m_str = option_arg;
3807 m_type = eLookupTypeSymbol;
3808 break;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003809
Greg Claytoneffe5c92011-05-03 22:09:39 +00003810 case 'f':
3811 m_file.SetFile (option_arg, false);
3812 m_type = eLookupTypeFileLine;
3813 break;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003814
Greg Claytoneffe5c92011-05-03 22:09:39 +00003815 case 'i':
Sean Callanand4a7c122012-02-11 01:22:21 +00003816 m_include_inlines = false;
Greg Claytoneffe5c92011-05-03 22:09:39 +00003817 break;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003818
Greg Claytoneffe5c92011-05-03 22:09:39 +00003819 case 'l':
3820 m_line_number = Args::StringToUInt32(option_arg, UINT32_MAX);
3821 if (m_line_number == UINT32_MAX)
Greg Clayton86edbf42011-10-26 00:56:27 +00003822 error.SetErrorStringWithFormat ("invalid line number string '%s'", option_arg);
Greg Claytoneffe5c92011-05-03 22:09:39 +00003823 else if (m_line_number == 0)
Greg Clayton86edbf42011-10-26 00:56:27 +00003824 error.SetErrorString ("zero is an invalid line number");
Greg Claytoneffe5c92011-05-03 22:09:39 +00003825 m_type = eLookupTypeFileLine;
3826 break;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003827
Greg Claytonc4a8a762012-05-15 18:43:44 +00003828 case 'F':
Greg Claytoneffe5c92011-05-03 22:09:39 +00003829 m_str = option_arg;
3830 m_type = eLookupTypeFunction;
3831 break;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003832
Greg Claytonc4a8a762012-05-15 18:43:44 +00003833 case 'n':
3834 m_str = option_arg;
3835 m_type = eLookupTypeFunctionOrSymbol;
3836 break;
3837
Greg Claytoneffe5c92011-05-03 22:09:39 +00003838 case 't':
3839 m_str = option_arg;
3840 m_type = eLookupTypeType;
3841 break;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003842
Greg Claytoneffe5c92011-05-03 22:09:39 +00003843 case 'v':
3844 m_verbose = 1;
3845 break;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003846
Sean Callanand38b4a92012-06-06 20:49:55 +00003847 case 'A':
3848 m_print_all = true;
3849 break;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003850
Greg Claytoneffe5c92011-05-03 22:09:39 +00003851 case 'r':
3852 m_use_regex = true;
3853 break;
3854 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003855
Greg Claytoneffe5c92011-05-03 22:09:39 +00003856 return error;
3857 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003858
Greg Claytoneffe5c92011-05-03 22:09:39 +00003859 void
3860 OptionParsingStarting ()
3861 {
3862 m_type = eLookupTypeInvalid;
3863 m_str.clear();
3864 m_file.Clear();
3865 m_addr = LLDB_INVALID_ADDRESS;
3866 m_offset = 0;
3867 m_line_number = 0;
3868 m_use_regex = false;
Sean Callanand4a7c122012-02-11 01:22:21 +00003869 m_include_inlines = true;
Greg Claytoneffe5c92011-05-03 22:09:39 +00003870 m_verbose = false;
Sean Callanand38b4a92012-06-06 20:49:55 +00003871 m_print_all = false;
Greg Claytoneffe5c92011-05-03 22:09:39 +00003872 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003873
Greg Claytoneffe5c92011-05-03 22:09:39 +00003874 const OptionDefinition*
3875 GetDefinitions ()
3876 {
3877 return g_option_table;
3878 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003879
Greg Claytoneffe5c92011-05-03 22:09:39 +00003880 // Options table: Required for subclasses of Options.
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003881
Greg Claytoneffe5c92011-05-03 22:09:39 +00003882 static OptionDefinition g_option_table[];
3883 int m_type; // Should be a eLookupTypeXXX enum after parsing options
3884 std::string m_str; // Holds name lookup
3885 FileSpec m_file; // Files for file lookups
3886 lldb::addr_t m_addr; // Holds the address to lookup
3887 lldb::addr_t m_offset; // Subtract this offset from m_addr before doing lookups.
3888 uint32_t m_line_number; // Line number for file+line lookups
3889 bool m_use_regex; // Name lookups in m_str are regular expressions.
Sean Callanand4a7c122012-02-11 01:22:21 +00003890 bool m_include_inlines;// Check for inline entries when looking up by file/line.
Greg Claytoneffe5c92011-05-03 22:09:39 +00003891 bool m_verbose; // Enable verbose lookup info
Sean Callanand38b4a92012-06-06 20:49:55 +00003892 bool m_print_all; // Print all matches, even in cases where there's a best match.
Greg Claytoneffe5c92011-05-03 22:09:39 +00003893 };
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003894
Greg Claytoneffe5c92011-05-03 22:09:39 +00003895 CommandObjectTargetModulesLookup (CommandInterpreter &interpreter) :
Jim Ingham5a988412012-06-08 21:56:10 +00003896 CommandObjectParsed (interpreter,
3897 "target modules lookup",
3898 "Look up information within executable and dependent shared library images.",
Greg Claytonf9fc6092013-01-09 19:44:40 +00003899 NULL,
3900 eFlagRequiresTarget),
Jim Ingham5a988412012-06-08 21:56:10 +00003901 m_options (interpreter)
Greg Claytoneffe5c92011-05-03 22:09:39 +00003902 {
3903 CommandArgumentEntry arg;
3904 CommandArgumentData file_arg;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003905
Greg Claytoneffe5c92011-05-03 22:09:39 +00003906 // Define the first (and only) variant of this arg.
3907 file_arg.arg_type = eArgTypeFilename;
3908 file_arg.arg_repetition = eArgRepeatStar;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003909
Greg Claytoneffe5c92011-05-03 22:09:39 +00003910 // There is only one variant this argument could be; put it into the argument entry.
3911 arg.push_back (file_arg);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003912
Greg Claytoneffe5c92011-05-03 22:09:39 +00003913 // Push the data for the first argument into the m_arguments vector.
3914 m_arguments.push_back (arg);
3915 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003916
Greg Claytoneffe5c92011-05-03 22:09:39 +00003917 virtual
3918 ~CommandObjectTargetModulesLookup ()
3919 {
3920 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003921
Greg Claytoneffe5c92011-05-03 22:09:39 +00003922 virtual Options *
3923 GetOptions ()
3924 {
3925 return &m_options;
3926 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003927
Sean Callanand38b4a92012-06-06 20:49:55 +00003928 bool
3929 LookupHere (CommandInterpreter &interpreter, CommandReturnObject &result, bool &syntax_error)
3930 {
3931 switch (m_options.m_type)
3932 {
3933 case eLookupTypeAddress:
3934 case eLookupTypeFileLine:
3935 case eLookupTypeFunction:
3936 case eLookupTypeFunctionOrSymbol:
3937 case eLookupTypeSymbol:
3938 default:
3939 return false;
3940 case eLookupTypeType:
3941 break;
3942 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003943
Jason Molendab57e4a12013-11-04 09:33:30 +00003944 StackFrameSP frame = m_exe_ctx.GetFrameSP();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003945
Sean Callanand38b4a92012-06-06 20:49:55 +00003946 if (!frame)
3947 return false;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003948
Sean Callanand38b4a92012-06-06 20:49:55 +00003949 const SymbolContext &sym_ctx(frame->GetSymbolContext(eSymbolContextModule));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003950
Sean Callanand38b4a92012-06-06 20:49:55 +00003951 if (!sym_ctx.module_sp)
3952 return false;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003953
Sean Callanand38b4a92012-06-06 20:49:55 +00003954 switch (m_options.m_type)
3955 {
3956 default:
3957 return false;
3958 case eLookupTypeType:
3959 if (!m_options.m_str.empty())
3960 {
3961 if (LookupTypeHere (m_interpreter,
3962 result.GetOutputStream(),
3963 sym_ctx,
3964 m_options.m_str.c_str(),
3965 m_options.m_use_regex))
3966 {
3967 result.SetStatus(eReturnStatusSuccessFinishResult);
3968 return true;
3969 }
3970 }
3971 break;
3972 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003973
Sean Callanand38b4a92012-06-06 20:49:55 +00003974 return true;
3975 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003976
Greg Claytoneffe5c92011-05-03 22:09:39 +00003977 bool
3978 LookupInModule (CommandInterpreter &interpreter, Module *module, CommandReturnObject &result, bool &syntax_error)
3979 {
3980 switch (m_options.m_type)
3981 {
3982 case eLookupTypeAddress:
3983 if (m_options.m_addr != LLDB_INVALID_ADDRESS)
3984 {
3985 if (LookupAddressInModule (m_interpreter,
3986 result.GetOutputStream(),
3987 module,
3988 eSymbolContextEverything,
3989 m_options.m_addr,
3990 m_options.m_offset,
3991 m_options.m_verbose))
3992 {
3993 result.SetStatus(eReturnStatusSuccessFinishResult);
3994 return true;
3995 }
3996 }
3997 break;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003998
Greg Claytoneffe5c92011-05-03 22:09:39 +00003999 case eLookupTypeSymbol:
4000 if (!m_options.m_str.empty())
4001 {
Greg Claytonc4a8a762012-05-15 18:43:44 +00004002 if (LookupSymbolInModule (m_interpreter,
4003 result.GetOutputStream(),
4004 module,
4005 m_options.m_str.c_str(),
4006 m_options.m_use_regex,
4007 m_options.m_verbose))
Greg Claytoneffe5c92011-05-03 22:09:39 +00004008 {
4009 result.SetStatus(eReturnStatusSuccessFinishResult);
4010 return true;
4011 }
4012 }
4013 break;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004014
Greg Claytoneffe5c92011-05-03 22:09:39 +00004015 case eLookupTypeFileLine:
4016 if (m_options.m_file)
4017 {
Greg Claytoneffe5c92011-05-03 22:09:39 +00004018 if (LookupFileAndLineInModule (m_interpreter,
4019 result.GetOutputStream(),
4020 module,
4021 m_options.m_file,
4022 m_options.m_line_number,
Sean Callanand4a7c122012-02-11 01:22:21 +00004023 m_options.m_include_inlines,
Greg Claytoneffe5c92011-05-03 22:09:39 +00004024 m_options.m_verbose))
4025 {
4026 result.SetStatus(eReturnStatusSuccessFinishResult);
4027 return true;
4028 }
4029 }
4030 break;
Greg Claytonc4a8a762012-05-15 18:43:44 +00004031
4032 case eLookupTypeFunctionOrSymbol:
Greg Claytoneffe5c92011-05-03 22:09:39 +00004033 case eLookupTypeFunction:
4034 if (!m_options.m_str.empty())
4035 {
4036 if (LookupFunctionInModule (m_interpreter,
4037 result.GetOutputStream(),
4038 module,
4039 m_options.m_str.c_str(),
4040 m_options.m_use_regex,
Sean Callanand4a7c122012-02-11 01:22:21 +00004041 m_options.m_include_inlines,
Greg Claytonc4a8a762012-05-15 18:43:44 +00004042 m_options.m_type == eLookupTypeFunctionOrSymbol, // include symbols
Greg Claytoneffe5c92011-05-03 22:09:39 +00004043 m_options.m_verbose))
4044 {
4045 result.SetStatus(eReturnStatusSuccessFinishResult);
4046 return true;
4047 }
4048 }
4049 break;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004050
Greg Claytoneffe5c92011-05-03 22:09:39 +00004051 case eLookupTypeType:
4052 if (!m_options.m_str.empty())
4053 {
4054 if (LookupTypeInModule (m_interpreter,
4055 result.GetOutputStream(),
4056 module,
4057 m_options.m_str.c_str(),
4058 m_options.m_use_regex))
4059 {
4060 result.SetStatus(eReturnStatusSuccessFinishResult);
4061 return true;
4062 }
4063 }
4064 break;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004065
Greg Claytoneffe5c92011-05-03 22:09:39 +00004066 default:
4067 m_options.GenerateOptionUsage (result.GetErrorStream(), this);
4068 syntax_error = true;
4069 break;
4070 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004071
Greg Claytoneffe5c92011-05-03 22:09:39 +00004072 result.SetStatus (eReturnStatusFailed);
4073 return false;
4074 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004075
Jim Ingham5a988412012-06-08 21:56:10 +00004076protected:
Greg Claytoneffe5c92011-05-03 22:09:39 +00004077 virtual bool
Jim Ingham5a988412012-06-08 21:56:10 +00004078 DoExecute (Args& command,
Greg Claytoneffe5c92011-05-03 22:09:39 +00004079 CommandReturnObject &result)
4080 {
4081 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
4082 if (target == NULL)
4083 {
4084 result.AppendError ("invalid target, create a debug target using the 'target create' command");
4085 result.SetStatus (eReturnStatusFailed);
4086 return false;
4087 }
4088 else
4089 {
4090 bool syntax_error = false;
4091 uint32_t i;
4092 uint32_t num_successful_lookups = 0;
4093 uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize();
4094 result.GetOutputStream().SetAddressByteSize(addr_byte_size);
4095 result.GetErrorStream().SetAddressByteSize(addr_byte_size);
4096 // Dump all sections for all modules images
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004097
Greg Claytoneffe5c92011-05-03 22:09:39 +00004098 if (command.GetArgumentCount() == 0)
4099 {
Sean Callanand38b4a92012-06-06 20:49:55 +00004100 ModuleSP current_module;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004101
Sean Callanand38b4a92012-06-06 20:49:55 +00004102 // Where it is possible to look in the current symbol context
4103 // first, try that. If this search was successful and --all
4104 // was not passed, don't print anything else.
4105 if (LookupHere (m_interpreter, result, syntax_error))
4106 {
4107 result.GetOutputStream().EOL();
4108 num_successful_lookups++;
4109 if (!m_options.m_print_all)
4110 {
4111 result.SetStatus (eReturnStatusSuccessFinishResult);
4112 return result.Succeeded();
4113 }
4114 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004115
Sean Callanand38b4a92012-06-06 20:49:55 +00004116 // Dump all sections for all other modules
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004117
Enrico Granata17598482012-11-08 02:22:02 +00004118 const ModuleList &target_modules = target->GetImages();
Jim Ingham3ee12ef2012-05-30 02:19:25 +00004119 Mutex::Locker modules_locker(target_modules.GetMutex());
Greg Claytonc7bece562013-01-25 18:06:21 +00004120 const size_t num_modules = target_modules.GetSize();
Greg Claytoneffe5c92011-05-03 22:09:39 +00004121 if (num_modules > 0)
4122 {
4123 for (i = 0; i<num_modules && syntax_error == false; ++i)
4124 {
Sean Callanand38b4a92012-06-06 20:49:55 +00004125 Module *module_pointer = target_modules.GetModulePointerAtIndexUnlocked(i);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004126
Sean Callanand38b4a92012-06-06 20:49:55 +00004127 if (module_pointer != current_module.get() &&
4128 LookupInModule (m_interpreter, target_modules.GetModulePointerAtIndexUnlocked(i), result, syntax_error))
Greg Claytoneffe5c92011-05-03 22:09:39 +00004129 {
4130 result.GetOutputStream().EOL();
4131 num_successful_lookups++;
4132 }
4133 }
4134 }
4135 else
4136 {
4137 result.AppendError ("the target has no associated executable images");
4138 result.SetStatus (eReturnStatusFailed);
4139 return false;
4140 }
4141 }
4142 else
4143 {
4144 // Dump specified images (by basename or fullpath)
4145 const char *arg_cstr;
4146 for (i = 0; (arg_cstr = command.GetArgumentAtIndex(i)) != NULL && syntax_error == false; ++i)
4147 {
Greg Clayton8ee64382011-11-10 01:18:58 +00004148 ModuleList module_list;
4149 const size_t num_matches = FindModulesByName (target, arg_cstr, module_list, false);
4150 if (num_matches > 0)
Greg Claytoneffe5c92011-05-03 22:09:39 +00004151 {
Jason Molendaccd41e52012-10-04 22:47:07 +00004152 for (size_t j=0; j<num_matches; ++j)
Greg Claytoneffe5c92011-05-03 22:09:39 +00004153 {
Jason Molendaccd41e52012-10-04 22:47:07 +00004154 Module *module = module_list.GetModulePointerAtIndex(j);
Greg Clayton8ee64382011-11-10 01:18:58 +00004155 if (module)
Greg Claytoneffe5c92011-05-03 22:09:39 +00004156 {
Greg Clayton8ee64382011-11-10 01:18:58 +00004157 if (LookupInModule (m_interpreter, module, result, syntax_error))
Greg Claytoneffe5c92011-05-03 22:09:39 +00004158 {
4159 result.GetOutputStream().EOL();
4160 num_successful_lookups++;
4161 }
4162 }
4163 }
4164 }
4165 else
4166 result.AppendWarningWithFormat("Unable to find an image that matches '%s'.\n", arg_cstr);
4167 }
4168 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004169
Greg Claytoneffe5c92011-05-03 22:09:39 +00004170 if (num_successful_lookups > 0)
4171 result.SetStatus (eReturnStatusSuccessFinishResult);
4172 else
4173 result.SetStatus (eReturnStatusFailed);
4174 }
4175 return result.Succeeded();
4176 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004177
Greg Claytoneffe5c92011-05-03 22:09:39 +00004178 CommandOptions m_options;
4179};
4180
4181OptionDefinition
4182CommandObjectTargetModulesLookup::CommandOptions::g_option_table[] =
4183{
Virgile Belloe2607b52013-09-05 16:42:23 +00004184 { LLDB_OPT_SET_1, true, "address", 'a', OptionParser::eRequiredArgument, NULL, 0, eArgTypeAddressOrExpression, "Lookup an address in one or more target modules."},
4185 { 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 +00004186 { LLDB_OPT_SET_2| LLDB_OPT_SET_4 | LLDB_OPT_SET_5
4187 /* 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 +00004188 false, "regex", 'r', OptionParser::eNoArgument, NULL, 0, eArgTypeNone, "The <name> argument for name lookups are regular expressions."},
4189 { 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."},
4190 { 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."},
4191 { 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 +00004192 { LLDB_OPT_SET_FROM_TO(3,5),
Virgile Belloe2607b52013-09-05 16:42:23 +00004193 false, "no-inlines", 'i', OptionParser::eNoArgument, NULL, 0, eArgTypeNone, "Ignore inline entries (must be used in conjunction with --file or --function)."},
4194 { 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."},
4195 { 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."},
4196 { 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."},
4197 { LLDB_OPT_SET_ALL, false, "verbose", 'v', OptionParser::eNoArgument, NULL, 0, eArgTypeNone, "Enable verbose lookup information."},
4198 { 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 +00004199 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
Greg Claytoneffe5c92011-05-03 22:09:39 +00004200};
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004201
4202
Jim Ingham9575d842011-03-11 03:53:59 +00004203#pragma mark CommandObjectMultiwordImageSearchPaths
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004204
4205//-------------------------------------------------------------------------
4206// CommandObjectMultiwordImageSearchPaths
4207//-------------------------------------------------------------------------
4208
Greg Claytoneffe5c92011-05-03 22:09:39 +00004209class CommandObjectTargetModulesImageSearchPaths : public CommandObjectMultiword
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004210{
4211public:
Greg Claytoneffe5c92011-05-03 22:09:39 +00004212 CommandObjectTargetModulesImageSearchPaths (CommandInterpreter &interpreter) :
4213 CommandObjectMultiword (interpreter,
4214 "target modules search-paths",
4215 "A set of commands for operating on debugger target image search paths.",
4216 "target modules search-paths <subcommand> [<subcommand-options>]")
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004217 {
Greg Claytoneffe5c92011-05-03 22:09:39 +00004218 LoadSubCommand ("add", CommandObjectSP (new CommandObjectTargetModulesSearchPathsAdd (interpreter)));
4219 LoadSubCommand ("clear", CommandObjectSP (new CommandObjectTargetModulesSearchPathsClear (interpreter)));
4220 LoadSubCommand ("insert", CommandObjectSP (new CommandObjectTargetModulesSearchPathsInsert (interpreter)));
4221 LoadSubCommand ("list", CommandObjectSP (new CommandObjectTargetModulesSearchPathsList (interpreter)));
4222 LoadSubCommand ("query", CommandObjectSP (new CommandObjectTargetModulesSearchPathsQuery (interpreter)));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004223 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004224
Greg Claytoneffe5c92011-05-03 22:09:39 +00004225 ~CommandObjectTargetModulesImageSearchPaths()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004226 {
4227 }
4228};
4229
Greg Claytoneffe5c92011-05-03 22:09:39 +00004230
4231
4232#pragma mark CommandObjectTargetModules
4233
4234//-------------------------------------------------------------------------
4235// CommandObjectTargetModules
4236//-------------------------------------------------------------------------
4237
4238class CommandObjectTargetModules : public CommandObjectMultiword
4239{
4240public:
4241 //------------------------------------------------------------------
4242 // Constructors and Destructors
4243 //------------------------------------------------------------------
4244 CommandObjectTargetModules(CommandInterpreter &interpreter) :
4245 CommandObjectMultiword (interpreter,
4246 "target modules",
4247 "A set of commands for accessing information for one or more target modules.",
4248 "target modules <sub-command> ...")
4249 {
4250 LoadSubCommand ("add", CommandObjectSP (new CommandObjectTargetModulesAdd (interpreter)));
4251 LoadSubCommand ("load", CommandObjectSP (new CommandObjectTargetModulesLoad (interpreter)));
Greg Claytoneffe5c92011-05-03 22:09:39 +00004252 LoadSubCommand ("dump", CommandObjectSP (new CommandObjectTargetModulesDump (interpreter)));
4253 LoadSubCommand ("list", CommandObjectSP (new CommandObjectTargetModulesList (interpreter)));
4254 LoadSubCommand ("lookup", CommandObjectSP (new CommandObjectTargetModulesLookup (interpreter)));
4255 LoadSubCommand ("search-paths", CommandObjectSP (new CommandObjectTargetModulesImageSearchPaths (interpreter)));
Jason Molenda380241a2012-07-12 00:20:07 +00004256 LoadSubCommand ("show-unwind", CommandObjectSP (new CommandObjectTargetModulesShowUnwind (interpreter)));
Greg Claytoneffe5c92011-05-03 22:09:39 +00004257
4258 }
4259 virtual
4260 ~CommandObjectTargetModules()
4261 {
4262 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004263
Greg Claytoneffe5c92011-05-03 22:09:39 +00004264private:
4265 //------------------------------------------------------------------
4266 // For CommandObjectTargetModules only
4267 //------------------------------------------------------------------
4268 DISALLOW_COPY_AND_ASSIGN (CommandObjectTargetModules);
4269};
4270
4271
Greg Claytone72dfb32012-02-24 01:59:29 +00004272
Jim Ingham5a988412012-06-08 21:56:10 +00004273class CommandObjectTargetSymbolsAdd : public CommandObjectParsed
Greg Claytone72dfb32012-02-24 01:59:29 +00004274{
4275public:
4276 CommandObjectTargetSymbolsAdd (CommandInterpreter &interpreter) :
Jim Ingham5a988412012-06-08 21:56:10 +00004277 CommandObjectParsed (interpreter,
4278 "target symbols add",
Greg Claytonb5f0fea2012-09-27 22:26:11 +00004279 "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 +00004280 "target symbols add [<symfile>]", eFlagRequiresTarget),
Greg Claytonb5f0fea2012-09-27 22:26:11 +00004281 m_option_group (interpreter),
4282 m_file_option (LLDB_OPT_SET_1, false, "shlib", 's', CommandCompletions::eModuleCompletion, eArgTypeShlibName, "Fullpath or basename for module to find debug symbols for."),
4283 m_current_frame_option (LLDB_OPT_SET_2, false, "frame", 'F', "Locate the debug symbols the currently selected frame.", false, true)
4284
Greg Claytone72dfb32012-02-24 01:59:29 +00004285 {
Greg Claytonb5f0fea2012-09-27 22:26:11 +00004286 m_option_group.Append (&m_uuid_option_group, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
4287 m_option_group.Append (&m_file_option, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
4288 m_option_group.Append (&m_current_frame_option, LLDB_OPT_SET_2, LLDB_OPT_SET_2);
4289 m_option_group.Finalize();
Greg Claytone72dfb32012-02-24 01:59:29 +00004290 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004291
Greg Claytone72dfb32012-02-24 01:59:29 +00004292 virtual
4293 ~CommandObjectTargetSymbolsAdd ()
4294 {
4295 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004296
Greg Claytonc7bece562013-01-25 18:06:21 +00004297 virtual int
Jim Ingham5a988412012-06-08 21:56:10 +00004298 HandleArgumentCompletion (Args &input,
4299 int &cursor_index,
4300 int &cursor_char_position,
4301 OptionElementVector &opt_element_vector,
4302 int match_start_point,
4303 int max_return_elements,
4304 bool &word_complete,
4305 StringList &matches)
4306 {
4307 std::string completion_str (input.GetArgumentAtIndex(cursor_index));
4308 completion_str.erase (cursor_char_position);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004309
Jim Ingham5a988412012-06-08 21:56:10 +00004310 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
4311 CommandCompletions::eDiskFileCompletion,
4312 completion_str.c_str(),
4313 match_start_point,
4314 max_return_elements,
4315 NULL,
4316 word_complete,
4317 matches);
4318 return matches.GetSize();
4319 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004320
Greg Claytonb5f0fea2012-09-27 22:26:11 +00004321 virtual Options *
4322 GetOptions ()
4323 {
4324 return &m_option_group;
4325 }
Greg Claytonb5f0fea2012-09-27 22:26:11 +00004326
Jim Ingham5a988412012-06-08 21:56:10 +00004327protected:
Greg Claytonb5f0fea2012-09-27 22:26:11 +00004328 bool
4329 AddModuleSymbols (Target *target,
Greg Clayton89deb062012-12-12 01:15:30 +00004330 ModuleSpec &module_spec,
Greg Claytonb5f0fea2012-09-27 22:26:11 +00004331 bool &flush,
4332 CommandReturnObject &result)
4333 {
Greg Clayton89deb062012-12-12 01:15:30 +00004334 const FileSpec &symbol_fspec = module_spec.GetSymbolFileSpec();
4335 if (symbol_fspec)
Greg Claytonb5f0fea2012-09-27 22:26:11 +00004336 {
4337 char symfile_path[PATH_MAX];
Greg Clayton89deb062012-12-12 01:15:30 +00004338 symbol_fspec.GetPath (symfile_path, sizeof(symfile_path));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004339
Greg Clayton89deb062012-12-12 01:15:30 +00004340 if (!module_spec.GetUUID().IsValid())
4341 {
4342 if (!module_spec.GetFileSpec() && !module_spec.GetPlatformFileSpec())
4343 module_spec.GetFileSpec().GetFilename() = symbol_fspec.GetFilename();
4344 }
Greg Claytonb5f0fea2012-09-27 22:26:11 +00004345 // We now have a module that represents a symbol file
4346 // that can be used for a module that might exist in the
4347 // current target, so we need to find that module in the
4348 // target
Greg Clayton89deb062012-12-12 01:15:30 +00004349 ModuleList matching_module_list;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004350
Greg Clayton9aae0a12013-05-15 19:52:08 +00004351 size_t num_matches = 0;
4352 // First extract all module specs from the symbol file
4353 lldb_private::ModuleSpecList symfile_module_specs;
Greg Clayton2540a8a2013-07-12 22:07:46 +00004354 if (ObjectFile::GetModuleSpecifications(module_spec.GetSymbolFileSpec(), 0, 0, symfile_module_specs))
Greg Clayton9aae0a12013-05-15 19:52:08 +00004355 {
4356 // Now extract the module spec that matches the target architecture
4357 ModuleSpec target_arch_module_spec;
4358 ModuleSpec symfile_module_spec;
4359 target_arch_module_spec.GetArchitecture() = target->GetArchitecture();
4360 if (symfile_module_specs.FindMatchingModuleSpec(target_arch_module_spec, symfile_module_spec))
4361 {
4362 // See if it has a UUID?
4363 if (symfile_module_spec.GetUUID().IsValid())
4364 {
4365 // It has a UUID, look for this UUID in the target modules
4366 ModuleSpec symfile_uuid_module_spec;
4367 symfile_uuid_module_spec.GetUUID() = symfile_module_spec.GetUUID();
4368 num_matches = target->GetImages().FindModules (symfile_uuid_module_spec, matching_module_list);
4369 }
4370 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004371
Greg Clayton9aae0a12013-05-15 19:52:08 +00004372 if (num_matches == 0)
4373 {
4374 // No matches yet, iterate through the module specs to find a UUID value that
4375 // we can match up to an image in our target
4376 const size_t num_symfile_module_specs = symfile_module_specs.GetSize();
4377 for (size_t i=0; i<num_symfile_module_specs && num_matches == 0; ++i)
4378 {
4379 if (symfile_module_specs.GetModuleSpecAtIndex(i, symfile_module_spec))
4380 {
4381 if (symfile_module_spec.GetUUID().IsValid())
4382 {
4383 // It has a UUID, look for this UUID in the target modules
4384 ModuleSpec symfile_uuid_module_spec;
4385 symfile_uuid_module_spec.GetUUID() = symfile_module_spec.GetUUID();
4386 num_matches = target->GetImages().FindModules (symfile_uuid_module_spec, matching_module_list);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004387 }
Greg Clayton9aae0a12013-05-15 19:52:08 +00004388 }
4389 }
4390 }
4391 }
4392
4393 // Just try to match up the file by basename if we have no matches at this point
4394 if (num_matches == 0)
4395 num_matches = target->GetImages().FindModules (module_spec, matching_module_list);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004396
Greg Clayton91c0e742013-01-11 23:44:27 +00004397 while (num_matches == 0)
4398 {
4399 ConstString filename_no_extension(module_spec.GetFileSpec().GetFileNameStrippingExtension());
4400 // Empty string returned, lets bail
4401 if (!filename_no_extension)
4402 break;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004403
Greg Clayton91c0e742013-01-11 23:44:27 +00004404 // Check if there was no extension to strip and the basename is the same
4405 if (filename_no_extension == module_spec.GetFileSpec().GetFilename())
4406 break;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004407
Greg Clayton91c0e742013-01-11 23:44:27 +00004408 // Replace basename with one less extension
4409 module_spec.GetFileSpec().GetFilename() = filename_no_extension;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004410
Greg Clayton91c0e742013-01-11 23:44:27 +00004411 num_matches = target->GetImages().FindModules (module_spec, matching_module_list);
4412 }
4413
Greg Clayton89deb062012-12-12 01:15:30 +00004414 if (num_matches > 1)
Greg Claytonb5f0fea2012-09-27 22:26:11 +00004415 {
Greg Clayton89deb062012-12-12 01:15:30 +00004416 result.AppendErrorWithFormat ("multiple modules match symbol file '%s', use the --uuid option to resolve the ambiguity.\n", symfile_path);
4417 }
4418 else if (num_matches == 1)
4419 {
4420 ModuleSP module_sp (matching_module_list.GetModuleAtIndex(0));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004421
Greg Claytonb5f0fea2012-09-27 22:26:11 +00004422 // The module has not yet created its symbol vendor, we can just
4423 // give the existing target module the symfile path to use for
4424 // when it decides to create it!
Greg Clayton89deb062012-12-12 01:15:30 +00004425 module_sp->SetSymbolFileFileSpec (symbol_fspec);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004426
Greg Clayton136dff82012-12-14 02:15:00 +00004427 SymbolVendor *symbol_vendor = module_sp->GetSymbolVendor(true, &result.GetErrorStream());
Greg Clayton89deb062012-12-12 01:15:30 +00004428 if (symbol_vendor)
4429 {
4430 SymbolFile *symbol_file = symbol_vendor->GetSymbolFile();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004431
Greg Clayton89deb062012-12-12 01:15:30 +00004432 if (symbol_file)
4433 {
4434 ObjectFile *object_file = symbol_file->GetObjectFile();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004435
Greg Clayton89deb062012-12-12 01:15:30 +00004436 if (object_file && object_file->GetFileSpec() == symbol_fspec)
4437 {
4438 // Provide feedback that the symfile has been successfully added.
4439 const FileSpec &module_fs = module_sp->GetFileSpec();
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00004440 result.AppendMessageWithFormat("symbol file '%s' has been added to '%s'\n",
Greg Clayton89deb062012-12-12 01:15:30 +00004441 symfile_path,
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00004442 module_fs.GetPath().c_str());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004443
Greg Clayton89deb062012-12-12 01:15:30 +00004444 // Let clients know something changed in the module
4445 // if it is currently loaded
4446 ModuleList module_list;
4447 module_list.Append (module_sp);
Enrico Granataf15ee4e2013-04-05 18:49:06 +00004448 target->SymbolsDidLoad (module_list);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004449
Greg Clayton91c0e742013-01-11 23:44:27 +00004450 // Make sure we load any scripting resources that may be embedded
4451 // in the debug info files in case the platform supports that.
4452 Error error;
Enrico Granata97303392013-05-21 00:00:30 +00004453 StreamString feedback_stream;
4454 module_sp->LoadScriptingResourceInTarget (target, error,&feedback_stream);
Enrico Granatacaa84cb2013-05-20 22:40:54 +00004455 if (error.Fail() && error.AsCString())
Enrico Granata2ea43cd2013-05-13 17:03:52 +00004456 result.AppendWarningWithFormat("unable to load scripting data for module %s - error reported was %s",
4457 module_sp->GetFileSpec().GetFileNameStrippingExtension().GetCString(),
4458 error.AsCString());
Enrico Granata97303392013-05-21 00:00:30 +00004459 else if (feedback_stream.GetSize())
4460 result.AppendWarningWithFormat("%s",feedback_stream.GetData());
Greg Clayton91c0e742013-01-11 23:44:27 +00004461
Greg Clayton89deb062012-12-12 01:15:30 +00004462 flush = true;
4463 result.SetStatus (eReturnStatusSuccessFinishResult);
4464 return true;
4465 }
4466 }
4467 }
4468 // Clear the symbol file spec if anything went wrong
4469 module_sp->SetSymbolFileFileSpec (FileSpec());
Greg Clayton89deb062012-12-12 01:15:30 +00004470 }
4471
4472 if (module_spec.GetUUID().IsValid())
4473 {
4474 StreamString ss_symfile_uuid;
4475 module_spec.GetUUID().Dump(&ss_symfile_uuid);
4476 result.AppendErrorWithFormat ("symbol file '%s' (%s) does not match any existing module%s\n",
4477 symfile_path,
4478 ss_symfile_uuid.GetData(),
4479 (symbol_fspec.GetFileType() != FileSpec::eFileTypeRegular)
4480 ? "\n please specify the full path to the symbol file"
4481 : "");
Greg Claytonb5f0fea2012-09-27 22:26:11 +00004482 }
4483 else
4484 {
Greg Clayton89deb062012-12-12 01:15:30 +00004485 result.AppendErrorWithFormat ("symbol file '%s' does not match any existing module%s\n",
4486 symfile_path,
4487 (symbol_fspec.GetFileType() != FileSpec::eFileTypeRegular)
4488 ? "\n please specify the full path to the symbol file"
4489 : "");
Greg Claytonb5f0fea2012-09-27 22:26:11 +00004490 }
4491 }
4492 else
4493 {
4494 result.AppendError ("one or more executable image paths must be specified");
Greg Claytonb5f0fea2012-09-27 22:26:11 +00004495 }
Greg Clayton89deb062012-12-12 01:15:30 +00004496 result.SetStatus (eReturnStatusFailed);
4497 return false;
Greg Claytonb5f0fea2012-09-27 22:26:11 +00004498 }
4499
Greg Claytone72dfb32012-02-24 01:59:29 +00004500 virtual bool
Jim Ingham5a988412012-06-08 21:56:10 +00004501 DoExecute (Args& args,
Greg Claytone72dfb32012-02-24 01:59:29 +00004502 CommandReturnObject &result)
4503 {
Greg Claytonf9fc6092013-01-09 19:44:40 +00004504 Target *target = m_exe_ctx.GetTargetPtr();
Greg Claytonb5f0fea2012-09-27 22:26:11 +00004505 result.SetStatus (eReturnStatusFailed);
Greg Claytonf9fc6092013-01-09 19:44:40 +00004506 bool flush = false;
4507 ModuleSpec module_spec;
4508 const bool uuid_option_set = m_uuid_option_group.GetOptionValue().OptionWasSet();
4509 const bool file_option_set = m_file_option.GetOptionValue().OptionWasSet();
4510 const bool frame_option_set = m_current_frame_option.GetOptionValue().OptionWasSet();
Greg Claytonb5f0fea2012-09-27 22:26:11 +00004511
Greg Claytonf9fc6092013-01-09 19:44:40 +00004512 const size_t argc = args.GetArgumentCount();
4513 if (argc == 0)
4514 {
4515 if (uuid_option_set || file_option_set || frame_option_set)
Greg Claytone72dfb32012-02-24 01:59:29 +00004516 {
Greg Claytonf9fc6092013-01-09 19:44:40 +00004517 bool success = false;
4518 bool error_set = false;
4519 if (frame_option_set)
Greg Claytone72dfb32012-02-24 01:59:29 +00004520 {
Greg Claytonf9fc6092013-01-09 19:44:40 +00004521 Process *process = m_exe_ctx.GetProcessPtr();
4522 if (process)
Greg Claytone72dfb32012-02-24 01:59:29 +00004523 {
Greg Claytonf9fc6092013-01-09 19:44:40 +00004524 const StateType process_state = process->GetState();
4525 if (StateIsStoppedState (process_state, true))
Greg Claytone72dfb32012-02-24 01:59:29 +00004526 {
Jason Molendab57e4a12013-11-04 09:33:30 +00004527 StackFrame *frame = m_exe_ctx.GetFramePtr();
Greg Claytonf9fc6092013-01-09 19:44:40 +00004528 if (frame)
Greg Claytone72dfb32012-02-24 01:59:29 +00004529 {
Greg Claytonf9fc6092013-01-09 19:44:40 +00004530 ModuleSP frame_module_sp (frame->GetSymbolContext(eSymbolContextModule).module_sp);
4531 if (frame_module_sp)
Greg Claytone72dfb32012-02-24 01:59:29 +00004532 {
Greg Claytonf9fc6092013-01-09 19:44:40 +00004533 if (frame_module_sp->GetPlatformFileSpec().Exists())
Greg Claytonb5f0fea2012-09-27 22:26:11 +00004534 {
Greg Claytonf9fc6092013-01-09 19:44:40 +00004535 module_spec.GetArchitecture() = frame_module_sp->GetArchitecture();
4536 module_spec.GetFileSpec() = frame_module_sp->GetPlatformFileSpec();
Greg Claytonb5f0fea2012-09-27 22:26:11 +00004537 }
Greg Claytonf9fc6092013-01-09 19:44:40 +00004538 module_spec.GetUUID() = frame_module_sp->GetUUID();
4539 success = module_spec.GetUUID().IsValid() || module_spec.GetFileSpec();
Greg Claytone72dfb32012-02-24 01:59:29 +00004540 }
Johnny Chen82e5a262012-08-22 00:18:43 +00004541 else
4542 {
Greg Claytonf9fc6092013-01-09 19:44:40 +00004543 result.AppendError ("frame has no module");
Greg Claytonb5f0fea2012-09-27 22:26:11 +00004544 error_set = true;
Johnny Chen82e5a262012-08-22 00:18:43 +00004545 }
Greg Claytone72dfb32012-02-24 01:59:29 +00004546 }
4547 else
4548 {
Greg Claytonf9fc6092013-01-09 19:44:40 +00004549 result.AppendError ("invalid current frame");
Greg Claytonb5f0fea2012-09-27 22:26:11 +00004550 error_set = true;
Greg Claytone72dfb32012-02-24 01:59:29 +00004551 }
Greg Claytone72dfb32012-02-24 01:59:29 +00004552 }
4553 else
4554 {
Greg Claytonf9fc6092013-01-09 19:44:40 +00004555 result.AppendErrorWithFormat ("process is not stopped: %s", StateAsCString(process_state));
Greg Claytonb5f0fea2012-09-27 22:26:11 +00004556 error_set = true;
4557 }
4558 }
4559 else
4560 {
Greg Claytonf9fc6092013-01-09 19:44:40 +00004561 result.AppendError ("a process must exist in order to use the --frame option");
4562 error_set = true;
Greg Claytonb5f0fea2012-09-27 22:26:11 +00004563 }
4564 }
4565 else
4566 {
Greg Claytonf9fc6092013-01-09 19:44:40 +00004567 if (uuid_option_set)
4568 {
4569 module_spec.GetUUID() = m_uuid_option_group.GetOptionValue().GetCurrentValue();
4570 success |= module_spec.GetUUID().IsValid();
4571 }
4572 else if (file_option_set)
4573 {
4574 module_spec.GetFileSpec() = m_file_option.GetOptionValue().GetCurrentValue();
4575 ModuleSP module_sp (target->GetImages().FindFirstModule(module_spec));
4576 if (module_sp)
4577 {
4578 module_spec.GetFileSpec() = module_sp->GetFileSpec();
4579 module_spec.GetPlatformFileSpec() = module_sp->GetPlatformFileSpec();
4580 module_spec.GetUUID() = module_sp->GetUUID();
4581 module_spec.GetArchitecture() = module_sp->GetArchitecture();
4582 }
4583 else
4584 {
4585 module_spec.GetArchitecture() = target->GetArchitecture();
4586 }
4587 success |= module_spec.GetFileSpec().Exists();
4588 }
4589 }
4590
4591 if (success)
4592 {
4593 if (Symbols::DownloadObjectAndSymbolFile (module_spec))
4594 {
4595 if (module_spec.GetSymbolFileSpec())
4596 success = AddModuleSymbols (target, module_spec, flush, result);
4597 }
4598 }
4599
4600 if (!success && !error_set)
4601 {
4602 StreamString error_strm;
4603 if (uuid_option_set)
4604 {
4605 error_strm.PutCString("unable to find debug symbols for UUID ");
4606 module_spec.GetUUID().Dump (&error_strm);
4607 }
4608 else if (file_option_set)
4609 {
4610 error_strm.PutCString("unable to find debug symbols for the executable file ");
4611 error_strm << module_spec.GetFileSpec();
4612 }
4613 else if (frame_option_set)
4614 {
4615 error_strm.PutCString("unable to find debug symbols for the current frame");
4616 }
4617 result.AppendError (error_strm.GetData());
Greg Claytonb5f0fea2012-09-27 22:26:11 +00004618 }
4619 }
4620 else
4621 {
Greg Claytonf9fc6092013-01-09 19:44:40 +00004622 result.AppendError ("one or more symbol file paths must be specified, or options must be specified");
4623 }
4624 }
4625 else
4626 {
4627 if (uuid_option_set)
4628 {
4629 result.AppendError ("specify either one or more paths to symbol files or use the --uuid option without arguments");
4630 }
4631 else if (file_option_set)
4632 {
4633 result.AppendError ("specify either one or more paths to symbol files or use the --file option without arguments");
4634 }
4635 else if (frame_option_set)
4636 {
4637 result.AppendError ("specify either one or more paths to symbol files or use the --frame option without arguments");
4638 }
4639 else
4640 {
4641 PlatformSP platform_sp (target->GetPlatform());
Greg Claytonb5f0fea2012-09-27 22:26:11 +00004642
Greg Claytonf9fc6092013-01-09 19:44:40 +00004643 for (size_t i=0; i<argc; ++i)
4644 {
4645 const char *symfile_path = args.GetArgumentAtIndex(i);
4646 if (symfile_path)
Greg Claytonb5f0fea2012-09-27 22:26:11 +00004647 {
Greg Claytonf9fc6092013-01-09 19:44:40 +00004648 module_spec.GetSymbolFileSpec().SetFile(symfile_path, true);
4649 if (platform_sp)
Greg Claytonb5f0fea2012-09-27 22:26:11 +00004650 {
Greg Claytonf9fc6092013-01-09 19:44:40 +00004651 FileSpec symfile_spec;
4652 if (platform_sp->ResolveSymbolFile(*target, module_spec, symfile_spec).Success())
4653 module_spec.GetSymbolFileSpec() = symfile_spec;
4654 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004655
Greg Claytonf9fc6092013-01-09 19:44:40 +00004656 ArchSpec arch;
4657 bool symfile_exists = module_spec.GetSymbolFileSpec().Exists();
Greg Claytonb5f0fea2012-09-27 22:26:11 +00004658
Greg Claytonf9fc6092013-01-09 19:44:40 +00004659 if (symfile_exists)
4660 {
4661 if (!AddModuleSymbols (target, module_spec, flush, result))
Greg Claytonb5f0fea2012-09-27 22:26:11 +00004662 break;
Greg Claytonf9fc6092013-01-09 19:44:40 +00004663 }
4664 else
4665 {
4666 char resolved_symfile_path[PATH_MAX];
4667 if (module_spec.GetSymbolFileSpec().GetPath (resolved_symfile_path, sizeof(resolved_symfile_path)))
4668 {
4669 if (strcmp (resolved_symfile_path, symfile_path) != 0)
4670 {
4671 result.AppendErrorWithFormat ("invalid module path '%s' with resolved path '%s'\n", symfile_path, resolved_symfile_path);
4672 break;
4673 }
Greg Claytonb5f0fea2012-09-27 22:26:11 +00004674 }
Greg Claytonf9fc6092013-01-09 19:44:40 +00004675 result.AppendErrorWithFormat ("invalid module path '%s'\n", symfile_path);
4676 break;
Greg Claytone72dfb32012-02-24 01:59:29 +00004677 }
4678 }
4679 }
4680 }
Greg Claytonf9fc6092013-01-09 19:44:40 +00004681 }
Greg Claytonfa559e52012-05-18 02:38:05 +00004682
Greg Claytonf9fc6092013-01-09 19:44:40 +00004683 if (flush)
4684 {
4685 Process *process = m_exe_ctx.GetProcessPtr();
4686 if (process)
4687 process->Flush();
Greg Claytone72dfb32012-02-24 01:59:29 +00004688 }
4689 return result.Succeeded();
4690 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004691
Greg Claytonb5f0fea2012-09-27 22:26:11 +00004692 OptionGroupOptions m_option_group;
4693 OptionGroupUUID m_uuid_option_group;
4694 OptionGroupFile m_file_option;
4695 OptionGroupBoolean m_current_frame_option;
Greg Claytone72dfb32012-02-24 01:59:29 +00004696};
4697
4698
4699#pragma mark CommandObjectTargetSymbols
4700
4701//-------------------------------------------------------------------------
4702// CommandObjectTargetSymbols
4703//-------------------------------------------------------------------------
4704
4705class CommandObjectTargetSymbols : public CommandObjectMultiword
4706{
4707public:
4708 //------------------------------------------------------------------
4709 // Constructors and Destructors
4710 //------------------------------------------------------------------
4711 CommandObjectTargetSymbols(CommandInterpreter &interpreter) :
4712 CommandObjectMultiword (interpreter,
4713 "target symbols",
4714 "A set of commands for adding and managing debug symbol files.",
4715 "target symbols <sub-command> ...")
4716 {
4717 LoadSubCommand ("add", CommandObjectSP (new CommandObjectTargetSymbolsAdd (interpreter)));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004718
Greg Claytone72dfb32012-02-24 01:59:29 +00004719 }
4720 virtual
4721 ~CommandObjectTargetSymbols()
4722 {
4723 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004724
Greg Claytone72dfb32012-02-24 01:59:29 +00004725private:
4726 //------------------------------------------------------------------
4727 // For CommandObjectTargetModules only
4728 //------------------------------------------------------------------
4729 DISALLOW_COPY_AND_ASSIGN (CommandObjectTargetSymbols);
4730};
4731
4732
Jim Ingham9575d842011-03-11 03:53:59 +00004733#pragma mark CommandObjectTargetStopHookAdd
4734
4735//-------------------------------------------------------------------------
4736// CommandObjectTargetStopHookAdd
4737//-------------------------------------------------------------------------
4738
Greg Clayton44d93782014-01-27 23:43:24 +00004739class CommandObjectTargetStopHookAdd :
4740 public CommandObjectParsed,
4741 public IOHandlerDelegateMultiline
Jim Ingham9575d842011-03-11 03:53:59 +00004742{
4743public:
4744
4745 class CommandOptions : public Options
4746 {
4747 public:
Greg Claytoneb0103f2011-04-07 22:46:35 +00004748 CommandOptions (CommandInterpreter &interpreter) :
4749 Options(interpreter),
Jim Ingham9575d842011-03-11 03:53:59 +00004750 m_line_start(0),
4751 m_line_end (UINT_MAX),
4752 m_func_name_type_mask (eFunctionNameTypeAuto),
4753 m_sym_ctx_specified (false),
Johnny Chenb1372c02011-05-02 23:47:55 +00004754 m_thread_specified (false),
4755 m_use_one_liner (false),
4756 m_one_liner()
Jim Ingham9575d842011-03-11 03:53:59 +00004757 {
4758 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004759
Jim Ingham9575d842011-03-11 03:53:59 +00004760 ~CommandOptions () {}
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004761
Greg Claytone0d378b2011-03-24 21:19:54 +00004762 const OptionDefinition*
Jim Ingham9575d842011-03-11 03:53:59 +00004763 GetDefinitions ()
4764 {
4765 return g_option_table;
4766 }
4767
4768 virtual Error
Greg Claytonf6b8b582011-04-13 00:18:08 +00004769 SetOptionValue (uint32_t option_idx, const char *option_arg)
Jim Ingham9575d842011-03-11 03:53:59 +00004770 {
4771 Error error;
Greg Clayton3bcdfc02012-12-04 00:32:51 +00004772 const int short_option = m_getopt_table[option_idx].val;
Jim Ingham9575d842011-03-11 03:53:59 +00004773 bool success;
4774
4775 switch (short_option)
4776 {
4777 case 'c':
4778 m_class_name = option_arg;
4779 m_sym_ctx_specified = true;
4780 break;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004781
Jim Ingham9575d842011-03-11 03:53:59 +00004782 case 'e':
4783 m_line_end = Args::StringToUInt32 (option_arg, UINT_MAX, 0, &success);
4784 if (!success)
4785 {
Greg Clayton86edbf42011-10-26 00:56:27 +00004786 error.SetErrorStringWithFormat ("invalid end line number: \"%s\"", option_arg);
Jim Ingham9575d842011-03-11 03:53:59 +00004787 break;
4788 }
4789 m_sym_ctx_specified = true;
4790 break;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004791
Jim Ingham9575d842011-03-11 03:53:59 +00004792 case 'l':
4793 m_line_start = Args::StringToUInt32 (option_arg, 0, 0, &success);
4794 if (!success)
4795 {
Greg Clayton86edbf42011-10-26 00:56:27 +00004796 error.SetErrorStringWithFormat ("invalid start line number: \"%s\"", option_arg);
Jim Ingham9575d842011-03-11 03:53:59 +00004797 break;
4798 }
4799 m_sym_ctx_specified = true;
4800 break;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004801
Sean Callanand4a7c122012-02-11 01:22:21 +00004802 case 'i':
4803 m_no_inlines = true;
4804 break;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004805
Jim Ingham9575d842011-03-11 03:53:59 +00004806 case 'n':
4807 m_function_name = option_arg;
4808 m_func_name_type_mask |= eFunctionNameTypeAuto;
4809 m_sym_ctx_specified = true;
4810 break;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004811
Jim Ingham9575d842011-03-11 03:53:59 +00004812 case 'f':
4813 m_file_name = option_arg;
4814 m_sym_ctx_specified = true;
4815 break;
4816 case 's':
4817 m_module_name = option_arg;
4818 m_sym_ctx_specified = true;
4819 break;
4820 case 't' :
4821 {
Jim Ingham0292f4a2011-03-22 01:53:33 +00004822 m_thread_id = Args::StringToUInt64(option_arg, LLDB_INVALID_THREAD_ID, 0);
Jim Ingham9575d842011-03-11 03:53:59 +00004823 if (m_thread_id == LLDB_INVALID_THREAD_ID)
Greg Clayton86edbf42011-10-26 00:56:27 +00004824 error.SetErrorStringWithFormat ("invalid thread id string '%s'", option_arg);
Jim Ingham9575d842011-03-11 03:53:59 +00004825 m_thread_specified = true;
4826 }
4827 break;
4828 case 'T':
4829 m_thread_name = option_arg;
4830 m_thread_specified = true;
4831 break;
4832 case 'q':
4833 m_queue_name = option_arg;
4834 m_thread_specified = true;
4835 break;
4836 case 'x':
4837 {
Jim Ingham0292f4a2011-03-22 01:53:33 +00004838 m_thread_index = Args::StringToUInt32(option_arg, UINT32_MAX, 0);
Jim Ingham9575d842011-03-11 03:53:59 +00004839 if (m_thread_id == UINT32_MAX)
Greg Clayton86edbf42011-10-26 00:56:27 +00004840 error.SetErrorStringWithFormat ("invalid thread index string '%s'", option_arg);
Jim Ingham9575d842011-03-11 03:53:59 +00004841 m_thread_specified = true;
4842 }
4843 break;
Johnny Chenb1372c02011-05-02 23:47:55 +00004844 case 'o':
4845 m_use_one_liner = true;
4846 m_one_liner = option_arg;
4847 break;
Jim Ingham9575d842011-03-11 03:53:59 +00004848 default:
Greg Clayton86edbf42011-10-26 00:56:27 +00004849 error.SetErrorStringWithFormat ("unrecognized option %c.", short_option);
Jim Ingham9575d842011-03-11 03:53:59 +00004850 break;
4851 }
4852 return error;
4853 }
4854
4855 void
Greg Claytonf6b8b582011-04-13 00:18:08 +00004856 OptionParsingStarting ()
Jim Ingham9575d842011-03-11 03:53:59 +00004857 {
4858 m_class_name.clear();
4859 m_function_name.clear();
4860 m_line_start = 0;
4861 m_line_end = UINT_MAX;
4862 m_file_name.clear();
4863 m_module_name.clear();
4864 m_func_name_type_mask = eFunctionNameTypeAuto;
4865 m_thread_id = LLDB_INVALID_THREAD_ID;
4866 m_thread_index = UINT32_MAX;
4867 m_thread_name.clear();
4868 m_queue_name.clear();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004869
Sean Callanand4a7c122012-02-11 01:22:21 +00004870 m_no_inlines = false;
Jim Ingham9575d842011-03-11 03:53:59 +00004871 m_sym_ctx_specified = false;
4872 m_thread_specified = false;
Johnny Chenb1372c02011-05-02 23:47:55 +00004873
4874 m_use_one_liner = false;
4875 m_one_liner.clear();
Jim Ingham9575d842011-03-11 03:53:59 +00004876 }
4877
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004878
Greg Claytone0d378b2011-03-24 21:19:54 +00004879 static OptionDefinition g_option_table[];
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004880
Jim Ingham9575d842011-03-11 03:53:59 +00004881 std::string m_class_name;
4882 std::string m_function_name;
4883 uint32_t m_line_start;
4884 uint32_t m_line_end;
4885 std::string m_file_name;
4886 std::string m_module_name;
4887 uint32_t m_func_name_type_mask; // A pick from lldb::FunctionNameType.
4888 lldb::tid_t m_thread_id;
4889 uint32_t m_thread_index;
4890 std::string m_thread_name;
4891 std::string m_queue_name;
4892 bool m_sym_ctx_specified;
Sean Callanand4a7c122012-02-11 01:22:21 +00004893 bool m_no_inlines;
Jim Ingham9575d842011-03-11 03:53:59 +00004894 bool m_thread_specified;
Johnny Chenb1372c02011-05-02 23:47:55 +00004895 // Instance variables to hold the values for one_liner options.
4896 bool m_use_one_liner;
4897 std::string m_one_liner;
Jim Ingham9575d842011-03-11 03:53:59 +00004898 };
4899
4900 Options *
4901 GetOptions ()
4902 {
4903 return &m_options;
4904 }
4905
4906 CommandObjectTargetStopHookAdd (CommandInterpreter &interpreter) :
Jim Ingham5a988412012-06-08 21:56:10 +00004907 CommandObjectParsed (interpreter,
Greg Clayton44d93782014-01-27 23:43:24 +00004908 "target stop-hook add",
Jim Ingham5a988412012-06-08 21:56:10 +00004909 "Add a hook to be executed when the target stops.",
4910 "target stop-hook add"),
Greg Claytonf29bf9a2014-05-02 01:03:07 +00004911 IOHandlerDelegateMultiline ("DONE", true, IOHandlerDelegate::Completion::LLDBCommand),
Greg Claytoneb0103f2011-04-07 22:46:35 +00004912 m_options (interpreter)
Jim Ingham9575d842011-03-11 03:53:59 +00004913 {
4914 }
4915
4916 ~CommandObjectTargetStopHookAdd ()
4917 {
4918 }
4919
Jim Ingham5a988412012-06-08 21:56:10 +00004920protected:
Greg Clayton44d93782014-01-27 23:43:24 +00004921 virtual void
4922 IOHandlerActivated (IOHandler &io_handler)
4923 {
4924 StreamFileSP output_sp(io_handler.GetOutputStreamFile());
4925 if (output_sp)
4926 {
4927 output_sp->PutCString("Enter your stop hook command(s). Type 'DONE' to end.\n");
4928 output_sp->Flush();
4929 }
4930 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004931
Greg Clayton44d93782014-01-27 23:43:24 +00004932 virtual void
4933 IOHandlerInputComplete (IOHandler &io_handler, std::string &line)
4934 {
4935 if (m_stop_hook_sp)
4936 {
4937 if (line.empty())
4938 {
4939 StreamFileSP error_sp(io_handler.GetErrorStreamFile());
4940 if (error_sp)
4941 {
4942 error_sp->Printf("error: stop hook #%" PRIu64 " aborted, no commands.\n", m_stop_hook_sp->GetID());
4943 error_sp->Flush();
4944 }
4945 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
4946 if (target)
4947 target->RemoveStopHookByID(m_stop_hook_sp->GetID());
4948 }
4949 else
4950 {
4951 m_stop_hook_sp->GetCommandPointer()->SplitIntoLines(line);
4952 StreamFileSP output_sp(io_handler.GetOutputStreamFile());
4953 if (output_sp)
4954 {
4955 output_sp->Printf("Stop hook #%" PRIu64 " added.\n", m_stop_hook_sp->GetID());
4956 output_sp->Flush();
4957 }
4958 }
4959 m_stop_hook_sp.reset();
4960 }
4961 io_handler.SetIsDone(true);
4962 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004963
Jim Ingham9575d842011-03-11 03:53:59 +00004964 bool
Jim Ingham5a988412012-06-08 21:56:10 +00004965 DoExecute (Args& command, CommandReturnObject &result)
Jim Ingham9575d842011-03-11 03:53:59 +00004966 {
Greg Clayton44d93782014-01-27 23:43:24 +00004967 m_stop_hook_sp.reset();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004968
Jim Ingham9575d842011-03-11 03:53:59 +00004969 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
4970 if (target)
4971 {
Greg Clayton44d93782014-01-27 23:43:24 +00004972 Target::StopHookSP new_hook_sp = target->CreateStopHook();
Jim Ingham9575d842011-03-11 03:53:59 +00004973
4974 // First step, make the specifier.
Greg Clayton7b0992d2013-04-18 22:45:39 +00004975 std::unique_ptr<SymbolContextSpecifier> specifier_ap;
Jim Ingham9575d842011-03-11 03:53:59 +00004976 if (m_options.m_sym_ctx_specified)
4977 {
4978 specifier_ap.reset(new SymbolContextSpecifier(m_interpreter.GetDebugger().GetSelectedTarget()));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004979
Jim Ingham9575d842011-03-11 03:53:59 +00004980 if (!m_options.m_module_name.empty())
4981 {
4982 specifier_ap->AddSpecification (m_options.m_module_name.c_str(), SymbolContextSpecifier::eModuleSpecified);
4983 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004984
Jim Ingham9575d842011-03-11 03:53:59 +00004985 if (!m_options.m_class_name.empty())
4986 {
4987 specifier_ap->AddSpecification (m_options.m_class_name.c_str(), SymbolContextSpecifier::eClassOrNamespaceSpecified);
4988 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004989
Jim Ingham9575d842011-03-11 03:53:59 +00004990 if (!m_options.m_file_name.empty())
4991 {
4992 specifier_ap->AddSpecification (m_options.m_file_name.c_str(), SymbolContextSpecifier::eFileSpecified);
4993 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004994
Jim Ingham9575d842011-03-11 03:53:59 +00004995 if (m_options.m_line_start != 0)
4996 {
4997 specifier_ap->AddLineSpecification (m_options.m_line_start, SymbolContextSpecifier::eLineStartSpecified);
4998 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00004999
Jim Ingham9575d842011-03-11 03:53:59 +00005000 if (m_options.m_line_end != UINT_MAX)
5001 {
5002 specifier_ap->AddLineSpecification (m_options.m_line_end, SymbolContextSpecifier::eLineEndSpecified);
5003 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005004
Jim Ingham9575d842011-03-11 03:53:59 +00005005 if (!m_options.m_function_name.empty())
5006 {
5007 specifier_ap->AddSpecification (m_options.m_function_name.c_str(), SymbolContextSpecifier::eFunctionSpecified);
5008 }
5009 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005010
Jim Ingham9575d842011-03-11 03:53:59 +00005011 if (specifier_ap.get())
5012 new_hook_sp->SetSpecifier (specifier_ap.release());
5013
5014 // Next see if any of the thread options have been entered:
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005015
Jim Ingham9575d842011-03-11 03:53:59 +00005016 if (m_options.m_thread_specified)
5017 {
5018 ThreadSpec *thread_spec = new ThreadSpec();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005019
Jim Ingham9575d842011-03-11 03:53:59 +00005020 if (m_options.m_thread_id != LLDB_INVALID_THREAD_ID)
5021 {
5022 thread_spec->SetTID (m_options.m_thread_id);
5023 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005024
Jim Ingham9575d842011-03-11 03:53:59 +00005025 if (m_options.m_thread_index != UINT32_MAX)
5026 thread_spec->SetIndex (m_options.m_thread_index);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005027
Jim Ingham9575d842011-03-11 03:53:59 +00005028 if (!m_options.m_thread_name.empty())
5029 thread_spec->SetName (m_options.m_thread_name.c_str());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005030
Jim Ingham9575d842011-03-11 03:53:59 +00005031 if (!m_options.m_queue_name.empty())
5032 thread_spec->SetQueueName (m_options.m_queue_name.c_str());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005033
Jim Ingham9575d842011-03-11 03:53:59 +00005034 new_hook_sp->SetThreadSpecifier (thread_spec);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005035
Jim Ingham9575d842011-03-11 03:53:59 +00005036 }
Johnny Chenb1372c02011-05-02 23:47:55 +00005037 if (m_options.m_use_one_liner)
Jim Ingham9575d842011-03-11 03:53:59 +00005038 {
Johnny Chenb1372c02011-05-02 23:47:55 +00005039 // Use one-liner.
5040 new_hook_sp->GetCommandPointer()->AppendString (m_options.m_one_liner.c_str());
Daniel Malead01b2952012-11-29 21:49:15 +00005041 result.AppendMessageWithFormat("Stop hook #%" PRIu64 " added.\n", new_hook_sp->GetID());
Jim Ingham9575d842011-03-11 03:53:59 +00005042 }
Johnny Chenb1372c02011-05-02 23:47:55 +00005043 else
Jim Ingham9575d842011-03-11 03:53:59 +00005044 {
Greg Clayton44d93782014-01-27 23:43:24 +00005045 m_stop_hook_sp = new_hook_sp;
5046 m_interpreter.GetLLDBCommandsFromIOHandler ("> ", // Prompt
5047 *this, // IOHandlerDelegate
5048 true, // Run IOHandler in async mode
5049 NULL); // Baton for the "io_handler" that will be passed back into our IOHandlerDelegate functions
5050
Jim Ingham9575d842011-03-11 03:53:59 +00005051 }
Jim Ingham9575d842011-03-11 03:53:59 +00005052 result.SetStatus (eReturnStatusSuccessFinishNoResult);
5053 }
5054 else
5055 {
Greg Clayton7260f622011-04-18 08:33:37 +00005056 result.AppendError ("invalid target\n");
Jim Ingham9575d842011-03-11 03:53:59 +00005057 result.SetStatus (eReturnStatusFailed);
5058 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005059
Jim Ingham9575d842011-03-11 03:53:59 +00005060 return result.Succeeded();
5061 }
5062private:
5063 CommandOptions m_options;
Greg Clayton44d93782014-01-27 23:43:24 +00005064 Target::StopHookSP m_stop_hook_sp;
Jim Ingham9575d842011-03-11 03:53:59 +00005065};
5066
Greg Claytone0d378b2011-03-24 21:19:54 +00005067OptionDefinition
Jim Ingham9575d842011-03-11 03:53:59 +00005068CommandObjectTargetStopHookAdd::CommandOptions::g_option_table[] =
5069{
Virgile Belloe2607b52013-09-05 16:42:23 +00005070 { LLDB_OPT_SET_ALL, false, "one-liner", 'o', OptionParser::eRequiredArgument, NULL, 0, eArgTypeOneLiner,
Johnny Chenb1372c02011-05-02 23:47:55 +00005071 "Specify a one-line breakpoint command inline. Be sure to surround it with quotes." },
Virgile Belloe2607b52013-09-05 16:42:23 +00005072 { LLDB_OPT_SET_ALL, false, "shlib", 's', OptionParser::eRequiredArgument, NULL, CommandCompletions::eModuleCompletion, eArgTypeShlibName,
Jim Ingham9575d842011-03-11 03:53:59 +00005073 "Set the module within which the stop-hook is to be run."},
Virgile Belloe2607b52013-09-05 16:42:23 +00005074 { LLDB_OPT_SET_ALL, false, "thread-index", 'x', OptionParser::eRequiredArgument, NULL, 0, eArgTypeThreadIndex,
Jim Ingham9575d842011-03-11 03:53:59 +00005075 "The stop hook is run only for the thread whose index matches this argument."},
Virgile Belloe2607b52013-09-05 16:42:23 +00005076 { LLDB_OPT_SET_ALL, false, "thread-id", 't', OptionParser::eRequiredArgument, NULL, 0, eArgTypeThreadID,
Jim Ingham9575d842011-03-11 03:53:59 +00005077 "The stop hook is run only for the thread whose TID matches this argument."},
Virgile Belloe2607b52013-09-05 16:42:23 +00005078 { LLDB_OPT_SET_ALL, false, "thread-name", 'T', OptionParser::eRequiredArgument, NULL, 0, eArgTypeThreadName,
Jim Ingham9575d842011-03-11 03:53:59 +00005079 "The stop hook is run only for the thread whose thread name matches this argument."},
Virgile Belloe2607b52013-09-05 16:42:23 +00005080 { LLDB_OPT_SET_ALL, false, "queue-name", 'q', OptionParser::eRequiredArgument, NULL, 0, eArgTypeQueueName,
Jim Ingham9575d842011-03-11 03:53:59 +00005081 "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 +00005082 { LLDB_OPT_SET_1, false, "file", 'f', OptionParser::eRequiredArgument, NULL, CommandCompletions::eSourceFileCompletion, eArgTypeFilename,
Jim Ingham9575d842011-03-11 03:53:59 +00005083 "Specify the source file within which the stop-hook is to be run." },
Virgile Belloe2607b52013-09-05 16:42:23 +00005084 { LLDB_OPT_SET_1, false, "start-line", 'l', OptionParser::eRequiredArgument, NULL, 0, eArgTypeLineNum,
Jim Ingham9575d842011-03-11 03:53:59 +00005085 "Set the start of the line range for which the stop-hook is to be run."},
Virgile Belloe2607b52013-09-05 16:42:23 +00005086 { LLDB_OPT_SET_1, false, "end-line", 'e', OptionParser::eRequiredArgument, NULL, 0, eArgTypeLineNum,
Jim Ingham9575d842011-03-11 03:53:59 +00005087 "Set the end of the line range for which the stop-hook is to be run."},
Virgile Belloe2607b52013-09-05 16:42:23 +00005088 { LLDB_OPT_SET_2, false, "classname", 'c', OptionParser::eRequiredArgument, NULL, 0, eArgTypeClassName,
Jim Ingham9575d842011-03-11 03:53:59 +00005089 "Specify the class within which the stop-hook is to be run." },
Virgile Belloe2607b52013-09-05 16:42:23 +00005090 { LLDB_OPT_SET_3, false, "name", 'n', OptionParser::eRequiredArgument, NULL, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName,
Jim Ingham9575d842011-03-11 03:53:59 +00005091 "Set the function name within which the stop hook will be run." },
5092 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
5093};
5094
5095#pragma mark CommandObjectTargetStopHookDelete
5096
5097//-------------------------------------------------------------------------
5098// CommandObjectTargetStopHookDelete
5099//-------------------------------------------------------------------------
5100
Jim Ingham5a988412012-06-08 21:56:10 +00005101class CommandObjectTargetStopHookDelete : public CommandObjectParsed
Jim Ingham9575d842011-03-11 03:53:59 +00005102{
5103public:
5104
5105 CommandObjectTargetStopHookDelete (CommandInterpreter &interpreter) :
Jim Ingham5a988412012-06-08 21:56:10 +00005106 CommandObjectParsed (interpreter,
5107 "target stop-hook delete",
5108 "Delete a stop-hook.",
5109 "target stop-hook delete [<idx>]")
Jim Ingham9575d842011-03-11 03:53:59 +00005110 {
5111 }
5112
5113 ~CommandObjectTargetStopHookDelete ()
5114 {
5115 }
5116
Jim Ingham5a988412012-06-08 21:56:10 +00005117protected:
Jim Ingham9575d842011-03-11 03:53:59 +00005118 bool
Jim Ingham5a988412012-06-08 21:56:10 +00005119 DoExecute (Args& command, CommandReturnObject &result)
Jim Ingham9575d842011-03-11 03:53:59 +00005120 {
5121 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
5122 if (target)
5123 {
5124 // FIXME: see if we can use the breakpoint id style parser?
5125 size_t num_args = command.GetArgumentCount();
5126 if (num_args == 0)
5127 {
5128 if (!m_interpreter.Confirm ("Delete all stop hooks?", true))
5129 {
5130 result.SetStatus (eReturnStatusFailed);
5131 return false;
5132 }
5133 else
5134 {
5135 target->RemoveAllStopHooks();
5136 }
5137 }
5138 else
5139 {
5140 bool success;
5141 for (size_t i = 0; i < num_args; i++)
5142 {
5143 lldb::user_id_t user_id = Args::StringToUInt32 (command.GetArgumentAtIndex(i), 0, 0, &success);
5144 if (!success)
5145 {
Greg Clayton7260f622011-04-18 08:33:37 +00005146 result.AppendErrorWithFormat ("invalid stop hook id: \"%s\".\n", command.GetArgumentAtIndex(i));
Jim Ingham9575d842011-03-11 03:53:59 +00005147 result.SetStatus(eReturnStatusFailed);
5148 return false;
5149 }
5150 success = target->RemoveStopHookByID (user_id);
5151 if (!success)
5152 {
Greg Clayton7260f622011-04-18 08:33:37 +00005153 result.AppendErrorWithFormat ("unknown stop hook id: \"%s\".\n", command.GetArgumentAtIndex(i));
Jim Ingham9575d842011-03-11 03:53:59 +00005154 result.SetStatus(eReturnStatusFailed);
5155 return false;
5156 }
5157 }
5158 }
5159 result.SetStatus (eReturnStatusSuccessFinishNoResult);
5160 }
5161 else
5162 {
Greg Clayton7260f622011-04-18 08:33:37 +00005163 result.AppendError ("invalid target\n");
Jim Ingham9575d842011-03-11 03:53:59 +00005164 result.SetStatus (eReturnStatusFailed);
5165 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005166
Jim Ingham9575d842011-03-11 03:53:59 +00005167 return result.Succeeded();
5168 }
5169};
5170#pragma mark CommandObjectTargetStopHookEnableDisable
5171
5172//-------------------------------------------------------------------------
5173// CommandObjectTargetStopHookEnableDisable
5174//-------------------------------------------------------------------------
5175
Jim Ingham5a988412012-06-08 21:56:10 +00005176class CommandObjectTargetStopHookEnableDisable : public CommandObjectParsed
Jim Ingham9575d842011-03-11 03:53:59 +00005177{
5178public:
5179
5180 CommandObjectTargetStopHookEnableDisable (CommandInterpreter &interpreter, bool enable, const char *name, const char *help, const char *syntax) :
Jim Ingham5a988412012-06-08 21:56:10 +00005181 CommandObjectParsed (interpreter,
5182 name,
5183 help,
5184 syntax),
Jim Ingham9575d842011-03-11 03:53:59 +00005185 m_enable (enable)
5186 {
5187 }
5188
5189 ~CommandObjectTargetStopHookEnableDisable ()
5190 {
5191 }
5192
Jim Ingham5a988412012-06-08 21:56:10 +00005193protected:
Jim Ingham9575d842011-03-11 03:53:59 +00005194 bool
Jim Ingham5a988412012-06-08 21:56:10 +00005195 DoExecute (Args& command, CommandReturnObject &result)
Jim Ingham9575d842011-03-11 03:53:59 +00005196 {
5197 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
5198 if (target)
5199 {
5200 // FIXME: see if we can use the breakpoint id style parser?
5201 size_t num_args = command.GetArgumentCount();
5202 bool success;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005203
Jim Ingham9575d842011-03-11 03:53:59 +00005204 if (num_args == 0)
5205 {
5206 target->SetAllStopHooksActiveState (m_enable);
5207 }
5208 else
5209 {
5210 for (size_t i = 0; i < num_args; i++)
5211 {
5212 lldb::user_id_t user_id = Args::StringToUInt32 (command.GetArgumentAtIndex(i), 0, 0, &success);
5213 if (!success)
5214 {
Greg Clayton7260f622011-04-18 08:33:37 +00005215 result.AppendErrorWithFormat ("invalid stop hook id: \"%s\".\n", command.GetArgumentAtIndex(i));
Jim Ingham9575d842011-03-11 03:53:59 +00005216 result.SetStatus(eReturnStatusFailed);
5217 return false;
5218 }
5219 success = target->SetStopHookActiveStateByID (user_id, m_enable);
5220 if (!success)
5221 {
Greg Clayton7260f622011-04-18 08:33:37 +00005222 result.AppendErrorWithFormat ("unknown stop hook id: \"%s\".\n", command.GetArgumentAtIndex(i));
Jim Ingham9575d842011-03-11 03:53:59 +00005223 result.SetStatus(eReturnStatusFailed);
5224 return false;
5225 }
5226 }
5227 }
5228 result.SetStatus (eReturnStatusSuccessFinishNoResult);
5229 }
5230 else
5231 {
Greg Clayton7260f622011-04-18 08:33:37 +00005232 result.AppendError ("invalid target\n");
Jim Ingham9575d842011-03-11 03:53:59 +00005233 result.SetStatus (eReturnStatusFailed);
5234 }
5235 return result.Succeeded();
5236 }
5237private:
5238 bool m_enable;
5239};
5240
5241#pragma mark CommandObjectTargetStopHookList
5242
5243//-------------------------------------------------------------------------
5244// CommandObjectTargetStopHookList
5245//-------------------------------------------------------------------------
5246
Jim Ingham5a988412012-06-08 21:56:10 +00005247class CommandObjectTargetStopHookList : public CommandObjectParsed
Jim Ingham9575d842011-03-11 03:53:59 +00005248{
5249public:
5250
5251 CommandObjectTargetStopHookList (CommandInterpreter &interpreter) :
Jim Ingham5a988412012-06-08 21:56:10 +00005252 CommandObjectParsed (interpreter,
5253 "target stop-hook list",
5254 "List all stop-hooks.",
5255 "target stop-hook list [<type>]")
Jim Ingham9575d842011-03-11 03:53:59 +00005256 {
5257 }
5258
5259 ~CommandObjectTargetStopHookList ()
5260 {
5261 }
5262
Jim Ingham5a988412012-06-08 21:56:10 +00005263protected:
Jim Ingham9575d842011-03-11 03:53:59 +00005264 bool
Jim Ingham5a988412012-06-08 21:56:10 +00005265 DoExecute (Args& command, CommandReturnObject &result)
Jim Ingham9575d842011-03-11 03:53:59 +00005266 {
5267 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Johnny Chenfaa5c132011-11-29 23:56:14 +00005268 if (!target)
Jim Ingham9575d842011-03-11 03:53:59 +00005269 {
Greg Clayton7260f622011-04-18 08:33:37 +00005270 result.AppendError ("invalid target\n");
Jim Ingham9575d842011-03-11 03:53:59 +00005271 result.SetStatus (eReturnStatusFailed);
Jason Molendaeffcd2a2011-09-23 21:15:42 +00005272 return result.Succeeded();
Jim Ingham9575d842011-03-11 03:53:59 +00005273 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005274
Jim Ingham9575d842011-03-11 03:53:59 +00005275 size_t num_hooks = target->GetNumStopHooks ();
5276 if (num_hooks == 0)
5277 {
5278 result.GetOutputStream().PutCString ("No stop hooks.\n");
5279 }
5280 else
5281 {
5282 for (size_t i = 0; i < num_hooks; i++)
5283 {
5284 Target::StopHookSP this_hook = target->GetStopHookAtIndex (i);
5285 if (i > 0)
5286 result.GetOutputStream().PutCString ("\n");
5287 this_hook->GetDescription (&(result.GetOutputStream()), eDescriptionLevelFull);
5288 }
5289 }
Johnny Chend0cff1e2011-11-30 19:09:20 +00005290 result.SetStatus (eReturnStatusSuccessFinishResult);
Jim Ingham9575d842011-03-11 03:53:59 +00005291 return result.Succeeded();
5292 }
5293};
5294
5295#pragma mark CommandObjectMultiwordTargetStopHooks
5296//-------------------------------------------------------------------------
5297// CommandObjectMultiwordTargetStopHooks
5298//-------------------------------------------------------------------------
5299
5300class CommandObjectMultiwordTargetStopHooks : public CommandObjectMultiword
5301{
5302public:
5303
5304 CommandObjectMultiwordTargetStopHooks (CommandInterpreter &interpreter) :
5305 CommandObjectMultiword (interpreter,
5306 "target stop-hook",
5307 "A set of commands for operating on debugger target stop-hooks.",
5308 "target stop-hook <subcommand> [<subcommand-options>]")
5309 {
5310 LoadSubCommand ("add", CommandObjectSP (new CommandObjectTargetStopHookAdd (interpreter)));
5311 LoadSubCommand ("delete", CommandObjectSP (new CommandObjectTargetStopHookDelete (interpreter)));
5312 LoadSubCommand ("disable", CommandObjectSP (new CommandObjectTargetStopHookEnableDisable (interpreter,
5313 false,
5314 "target stop-hook disable [<id>]",
5315 "Disable a stop-hook.",
5316 "target stop-hook disable")));
5317 LoadSubCommand ("enable", CommandObjectSP (new CommandObjectTargetStopHookEnableDisable (interpreter,
5318 true,
5319 "target stop-hook enable [<id>]",
5320 "Enable a stop-hook.",
5321 "target stop-hook enable")));
5322 LoadSubCommand ("list", CommandObjectSP (new CommandObjectTargetStopHookList (interpreter)));
5323 }
5324
5325 ~CommandObjectMultiwordTargetStopHooks()
5326 {
5327 }
5328};
5329
5330
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005331
5332#pragma mark CommandObjectMultiwordTarget
5333
5334//-------------------------------------------------------------------------
5335// CommandObjectMultiwordTarget
5336//-------------------------------------------------------------------------
5337
Greg Clayton66111032010-06-23 01:19:29 +00005338CommandObjectMultiwordTarget::CommandObjectMultiwordTarget (CommandInterpreter &interpreter) :
Greg Claytona7015092010-09-18 01:14:36 +00005339 CommandObjectMultiword (interpreter,
5340 "target",
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005341 "A set of commands for operating on debugger targets.",
5342 "target <subcommand> [<subcommand-options>]")
5343{
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00005344
Greg Clayton7260f622011-04-18 08:33:37 +00005345 LoadSubCommand ("create", CommandObjectSP (new CommandObjectTargetCreate (interpreter)));
Greg Clayton3418c852011-08-10 02:10:13 +00005346 LoadSubCommand ("delete", CommandObjectSP (new CommandObjectTargetDelete (interpreter)));
Greg Clayton7260f622011-04-18 08:33:37 +00005347 LoadSubCommand ("list", CommandObjectSP (new CommandObjectTargetList (interpreter)));
5348 LoadSubCommand ("select", CommandObjectSP (new CommandObjectTargetSelect (interpreter)));
Jim Ingham9575d842011-03-11 03:53:59 +00005349 LoadSubCommand ("stop-hook", CommandObjectSP (new CommandObjectMultiwordTargetStopHooks (interpreter)));
Greg Claytoneffe5c92011-05-03 22:09:39 +00005350 LoadSubCommand ("modules", CommandObjectSP (new CommandObjectTargetModules (interpreter)));
Greg Claytone72dfb32012-02-24 01:59:29 +00005351 LoadSubCommand ("symbols", CommandObjectSP (new CommandObjectTargetSymbols (interpreter)));
Greg Clayton644247c2011-07-07 01:59:51 +00005352 LoadSubCommand ("variable", CommandObjectSP (new CommandObjectTargetVariable (interpreter)));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005353}
5354
5355CommandObjectMultiwordTarget::~CommandObjectMultiwordTarget ()
5356{
5357}
5358
Greg Clayton7260f622011-04-18 08:33:37 +00005359