Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- 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 Malea | 93a6430 | 2012-12-05 00:20:57 +0000 | [diff] [blame] | 10 | #include "lldb/lldb-python.h" |
| 11 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 12 | #include "CommandObjectTarget.h" |
| 13 | |
| 14 | // C Includes |
| 15 | #include <errno.h> |
Greg Clayton | c4a99bc | 2011-02-01 01:13:32 +0000 | [diff] [blame] | 16 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 17 | // C++ Includes |
| 18 | // Other libraries and framework includes |
| 19 | // Project includes |
Jim Ingham | 40af72e | 2010-06-15 19:49:27 +0000 | [diff] [blame] | 20 | #include "lldb/Interpreter/Args.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 21 | #include "lldb/Core/Debugger.h" |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 22 | #include "lldb/Core/InputReader.h" |
Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 23 | #include "lldb/Core/Module.h" |
| 24 | #include "lldb/Core/ModuleSpec.h" |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 25 | #include "lldb/Core/Section.h" |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 26 | #include "lldb/Core/State.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 27 | #include "lldb/Core/Timer.h" |
Greg Clayton | 644247c | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 28 | #include "lldb/Core/ValueObjectVariable.h" |
Greg Clayton | c8f814d | 2012-09-27 03:13:55 +0000 | [diff] [blame] | 29 | #include "lldb/Host/Symbols.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 30 | #include "lldb/Interpreter/CommandInterpreter.h" |
| 31 | #include "lldb/Interpreter/CommandReturnObject.h" |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 32 | #include "lldb/Interpreter/Options.h" |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 33 | #include "lldb/Interpreter/OptionGroupArchitecture.h" |
Greg Clayton | aa149cb | 2011-08-11 02:48:45 +0000 | [diff] [blame] | 34 | #include "lldb/Interpreter/OptionGroupBoolean.h" |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 35 | #include "lldb/Interpreter/OptionGroupFile.h" |
Greg Clayton | 1deb796 | 2011-10-25 06:44:01 +0000 | [diff] [blame] | 36 | #include "lldb/Interpreter/OptionGroupFormat.h" |
Greg Clayton | 715c236 | 2011-07-07 04:38:25 +0000 | [diff] [blame] | 37 | #include "lldb/Interpreter/OptionGroupVariable.h" |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 38 | #include "lldb/Interpreter/OptionGroupPlatform.h" |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 39 | #include "lldb/Interpreter/OptionGroupUInt64.h" |
| 40 | #include "lldb/Interpreter/OptionGroupUUID.h" |
Greg Clayton | 644247c | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 41 | #include "lldb/Interpreter/OptionGroupValueObjectDisplay.h" |
Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 42 | #include "lldb/Symbol/CompileUnit.h" |
Jason Molenda | 380241a | 2012-07-12 00:20:07 +0000 | [diff] [blame] | 43 | #include "lldb/Symbol/FuncUnwinders.h" |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 44 | #include "lldb/Symbol/LineTable.h" |
| 45 | #include "lldb/Symbol/ObjectFile.h" |
| 46 | #include "lldb/Symbol/SymbolFile.h" |
| 47 | #include "lldb/Symbol/SymbolVendor.h" |
Jason Molenda | 380241a | 2012-07-12 00:20:07 +0000 | [diff] [blame] | 48 | #include "lldb/Symbol/UnwindPlan.h" |
Greg Clayton | 644247c | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 49 | #include "lldb/Symbol/VariableList.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 50 | #include "lldb/Target/Process.h" |
| 51 | #include "lldb/Target/StackFrame.h" |
| 52 | #include "lldb/Target/Thread.h" |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 53 | #include "lldb/Target/ThreadSpec.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 54 | |
| 55 | using namespace lldb; |
| 56 | using namespace lldb_private; |
| 57 | |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 58 | |
| 59 | |
| 60 | static void |
| 61 | DumpTargetInfo (uint32_t target_idx, Target *target, const char *prefix_cstr, bool show_stopped_process_status, Stream &strm) |
| 62 | { |
Greg Clayton | 176761e | 2011-04-19 04:19:37 +0000 | [diff] [blame] | 63 | const ArchSpec &target_arch = target->GetArchitecture(); |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 64 | |
Greg Clayton | aa149cb | 2011-08-11 02:48:45 +0000 | [diff] [blame] | 65 | Module *exe_module = target->GetExecutableModulePointer(); |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 66 | char exe_path[PATH_MAX]; |
| 67 | bool exe_valid = false; |
Greg Clayton | aa149cb | 2011-08-11 02:48:45 +0000 | [diff] [blame] | 68 | if (exe_module) |
| 69 | exe_valid = exe_module->GetFileSpec().GetPath (exe_path, sizeof(exe_path)); |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 70 | |
| 71 | if (!exe_valid) |
| 72 | ::strcpy (exe_path, "<none>"); |
| 73 | |
| 74 | strm.Printf ("%starget #%u: %s", prefix_cstr ? prefix_cstr : "", target_idx, exe_path); |
| 75 | |
| 76 | uint32_t properties = 0; |
| 77 | if (target_arch.IsValid()) |
| 78 | { |
| 79 | strm.Printf ("%sarch=%s", properties++ > 0 ? ", " : " ( ", target_arch.GetTriple().str().c_str()); |
| 80 | properties++; |
| 81 | } |
| 82 | PlatformSP platform_sp (target->GetPlatform()); |
| 83 | if (platform_sp) |
Greg Clayton | 57abc5d | 2013-05-10 21:47:16 +0000 | [diff] [blame] | 84 | strm.Printf ("%splatform=%s", properties++ > 0 ? ", " : " ( ", platform_sp->GetName().GetCString()); |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 85 | |
| 86 | ProcessSP process_sp (target->GetProcessSP()); |
| 87 | bool show_process_status = false; |
| 88 | if (process_sp) |
| 89 | { |
| 90 | lldb::pid_t pid = process_sp->GetID(); |
| 91 | StateType state = process_sp->GetState(); |
| 92 | if (show_stopped_process_status) |
Greg Clayton | 2637f82 | 2011-11-17 01:23:07 +0000 | [diff] [blame] | 93 | show_process_status = StateIsStoppedState(state, true); |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 94 | const char *state_cstr = StateAsCString (state); |
| 95 | if (pid != LLDB_INVALID_PROCESS_ID) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 96 | strm.Printf ("%spid=%" PRIu64, properties++ > 0 ? ", " : " ( ", pid); |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 97 | strm.Printf ("%sstate=%s", properties++ > 0 ? ", " : " ( ", state_cstr); |
| 98 | } |
| 99 | if (properties > 0) |
| 100 | strm.PutCString (" )\n"); |
| 101 | else |
| 102 | strm.EOL(); |
| 103 | if (show_process_status) |
| 104 | { |
| 105 | const bool only_threads_with_stop_reason = true; |
| 106 | const uint32_t start_frame = 0; |
| 107 | const uint32_t num_frames = 1; |
| 108 | const uint32_t num_frames_with_source = 1; |
| 109 | process_sp->GetStatus (strm); |
| 110 | process_sp->GetThreadStatus (strm, |
| 111 | only_threads_with_stop_reason, |
| 112 | start_frame, |
| 113 | num_frames, |
| 114 | num_frames_with_source); |
| 115 | |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | static uint32_t |
| 120 | DumpTargetList (TargetList &target_list, bool show_stopped_process_status, Stream &strm) |
| 121 | { |
| 122 | const uint32_t num_targets = target_list.GetNumTargets(); |
| 123 | if (num_targets) |
| 124 | { |
| 125 | TargetSP selected_target_sp (target_list.GetSelectedTarget()); |
| 126 | strm.PutCString ("Current targets:\n"); |
| 127 | for (uint32_t i=0; i<num_targets; ++i) |
| 128 | { |
| 129 | TargetSP target_sp (target_list.GetTargetAtIndex (i)); |
| 130 | if (target_sp) |
| 131 | { |
| 132 | bool is_selected = target_sp.get() == selected_target_sp.get(); |
| 133 | DumpTargetInfo (i, |
| 134 | target_sp.get(), |
| 135 | is_selected ? "* " : " ", |
| 136 | show_stopped_process_status, |
| 137 | strm); |
| 138 | } |
| 139 | } |
| 140 | } |
| 141 | return num_targets; |
| 142 | } |
| 143 | #pragma mark CommandObjectTargetCreate |
| 144 | |
| 145 | //------------------------------------------------------------------------- |
| 146 | // "target create" |
| 147 | //------------------------------------------------------------------------- |
| 148 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 149 | class CommandObjectTargetCreate : public CommandObjectParsed |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 150 | { |
| 151 | public: |
| 152 | CommandObjectTargetCreate(CommandInterpreter &interpreter) : |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 153 | CommandObjectParsed (interpreter, |
| 154 | "target create", |
| 155 | "Create a target using the argument as the main executable.", |
| 156 | NULL), |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 157 | m_option_group (interpreter), |
Greg Clayton | 644247c | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 158 | m_arch_option (), |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 159 | m_platform_options(true), // Do include the "--platform" option in the platform settings by passing true |
Greg Clayton | 1c5f186 | 2012-11-30 19:05:35 +0000 | [diff] [blame] | 160 | m_core_file (LLDB_OPT_SET_1, false, "core", 'c', 0, eArgTypeFilename, "Fullpath to a core file to use for this target."), |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame^] | 161 | m_platform_path (LLDB_OPT_SET_1, false, "platform-path", 'P', 0, eArgTypePath, "Path to the remote file to use for this target."), |
Greg Clayton | 1c5f186 | 2012-11-30 19:05:35 +0000 | [diff] [blame] | 162 | 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 Ingham | bf22b96 | 2013-07-11 01:47:46 +0000 | [diff] [blame] | 163 | 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 Clayton | 1c5f186 | 2012-11-30 19:05:35 +0000 | [diff] [blame] | 164 | 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 Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 165 | { |
| 166 | CommandArgumentEntry arg; |
| 167 | CommandArgumentData file_arg; |
| 168 | |
| 169 | // Define the first (and only) variant of this arg. |
| 170 | file_arg.arg_type = eArgTypeFilename; |
| 171 | file_arg.arg_repetition = eArgRepeatPlain; |
| 172 | |
| 173 | // There is only one variant this argument could be; put it into the argument entry. |
| 174 | arg.push_back (file_arg); |
| 175 | |
| 176 | // Push the data for the first argument into the m_arguments vector. |
| 177 | m_arguments.push_back (arg); |
| 178 | |
Greg Clayton | 644247c | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 179 | m_option_group.Append (&m_arch_option, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1); |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 180 | m_option_group.Append (&m_platform_options, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1); |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 181 | m_option_group.Append (&m_core_file, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1); |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame^] | 182 | m_option_group.Append (&m_platform_path, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1); |
Greg Clayton | 1c5f186 | 2012-11-30 19:05:35 +0000 | [diff] [blame] | 183 | m_option_group.Append (&m_symbol_file, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1); |
Jim Ingham | bf22b96 | 2013-07-11 01:47:46 +0000 | [diff] [blame] | 184 | m_option_group.Append (&m_remote_file, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1); |
Greg Clayton | 1c5f186 | 2012-11-30 19:05:35 +0000 | [diff] [blame] | 185 | m_option_group.Append (&m_add_dependents, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1); |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 186 | m_option_group.Finalize(); |
| 187 | } |
| 188 | |
| 189 | ~CommandObjectTargetCreate () |
| 190 | { |
| 191 | } |
| 192 | |
| 193 | Options * |
| 194 | GetOptions () |
| 195 | { |
| 196 | return &m_option_group; |
| 197 | } |
| 198 | |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 199 | virtual int |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 200 | HandleArgumentCompletion (Args &input, |
| 201 | int &cursor_index, |
| 202 | int &cursor_char_position, |
| 203 | OptionElementVector &opt_element_vector, |
| 204 | int match_start_point, |
| 205 | int max_return_elements, |
| 206 | bool &word_complete, |
| 207 | StringList &matches) |
| 208 | { |
| 209 | std::string completion_str (input.GetArgumentAtIndex(cursor_index)); |
| 210 | completion_str.erase (cursor_char_position); |
| 211 | |
| 212 | CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter, |
| 213 | CommandCompletions::eDiskFileCompletion, |
| 214 | completion_str.c_str(), |
| 215 | match_start_point, |
| 216 | max_return_elements, |
| 217 | NULL, |
| 218 | word_complete, |
| 219 | matches); |
| 220 | return matches.GetSize(); |
| 221 | } |
| 222 | |
| 223 | protected: |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 224 | bool |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 225 | DoExecute (Args& command, CommandReturnObject &result) |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 226 | { |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 227 | const size_t argc = command.GetArgumentCount(); |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 228 | FileSpec core_file (m_core_file.GetOptionValue().GetCurrentValue()); |
Jim Ingham | bf22b96 | 2013-07-11 01:47:46 +0000 | [diff] [blame] | 229 | FileSpec remote_file (m_remote_file.GetOptionValue().GetCurrentValue()); |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 230 | |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame^] | 231 | if (argc == 1 || core_file || remote_file) |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 232 | { |
Greg Clayton | 1c5f186 | 2012-11-30 19:05:35 +0000 | [diff] [blame] | 233 | FileSpec symfile (m_symbol_file.GetOptionValue().GetCurrentValue()); |
| 234 | if (symfile) |
| 235 | { |
| 236 | if (!symfile.Exists()) |
| 237 | { |
| 238 | char symfile_path[PATH_MAX]; |
| 239 | symfile.GetPath(symfile_path, sizeof(symfile_path)); |
| 240 | result.AppendErrorWithFormat("invalid symbol file path '%s'", symfile_path); |
| 241 | result.SetStatus (eReturnStatusFailed); |
| 242 | return false; |
| 243 | } |
| 244 | } |
| 245 | |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 246 | const char *file_path = command.GetArgumentAtIndex(0); |
| 247 | Timer scoped_timer(__PRETTY_FUNCTION__, "(lldb) target create '%s'", file_path); |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame^] | 248 | FileSpec file_spec; |
| 249 | |
| 250 | if (file_path) |
| 251 | file_spec.SetFile (file_path, true); |
| 252 | |
| 253 | bool must_set_platform_path = false; |
| 254 | |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 255 | Debugger &debugger = m_interpreter.GetDebugger(); |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame^] | 256 | PlatformSP platform_sp(debugger.GetPlatformList().GetSelectedPlatform ()); |
| 257 | |
| 258 | if (remote_file) |
| 259 | { |
| 260 | // I have a remote file.. two possible cases |
| 261 | if (file_spec && file_spec.Exists()) |
| 262 | { |
| 263 | // if the remote file does not exist, push it there |
| 264 | if (!platform_sp->GetFileExists (remote_file)) |
| 265 | { |
| 266 | Error err = platform_sp->PutFile(file_spec, remote_file); |
| 267 | if (err.Fail()) |
| 268 | { |
| 269 | result.AppendError(err.AsCString()); |
| 270 | result.SetStatus (eReturnStatusFailed); |
| 271 | return false; |
| 272 | } |
| 273 | } |
| 274 | } |
| 275 | else |
| 276 | { |
| 277 | // there is no local file and we need one |
| 278 | // in order to make the remote ---> local transfer we need a platform |
| 279 | // TODO: if the user has passed in a --platform argument, use it to fetch the right platform |
| 280 | if (!platform_sp) |
| 281 | { |
| 282 | result.AppendError("unable to perform remote debugging without a platform"); |
| 283 | result.SetStatus (eReturnStatusFailed); |
| 284 | return false; |
| 285 | } |
| 286 | if (file_path) |
| 287 | { |
| 288 | // copy the remote file to the local file |
| 289 | Error err = platform_sp->GetFile(remote_file, file_spec); |
| 290 | if (err.Fail()) |
| 291 | { |
| 292 | result.AppendError(err.AsCString()); |
| 293 | result.SetStatus (eReturnStatusFailed); |
| 294 | return false; |
| 295 | } |
| 296 | } |
| 297 | else |
| 298 | { |
| 299 | // make up a local file |
| 300 | result.AppendError("remote --> local transfer without local path is not implemented yet"); |
| 301 | result.SetStatus (eReturnStatusFailed); |
| 302 | return false; |
| 303 | } |
| 304 | } |
| 305 | } |
| 306 | |
| 307 | TargetSP target_sp; |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 308 | const char *arch_cstr = m_arch_option.GetArchitectureName(); |
Greg Clayton | 1c5f186 | 2012-11-30 19:05:35 +0000 | [diff] [blame] | 309 | const bool get_dependent_files = m_add_dependents.GetOptionValue().GetCurrentValue(); |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 310 | Error error (debugger.GetTargetList().CreateTarget (debugger, |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame^] | 311 | // remote_file ? remote_file : file_spec, |
Greg Clayton | a0ca660 | 2012-10-18 16:33:33 +0000 | [diff] [blame] | 312 | file_path, |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 313 | arch_cstr, |
| 314 | get_dependent_files, |
| 315 | &m_platform_options, |
| 316 | target_sp)); |
| 317 | |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 318 | if (target_sp) |
| 319 | { |
Jim Ingham | bf22b96 | 2013-07-11 01:47:46 +0000 | [diff] [blame] | 320 | if (symfile || remote_file) |
Greg Clayton | 1c5f186 | 2012-11-30 19:05:35 +0000 | [diff] [blame] | 321 | { |
| 322 | ModuleSP module_sp (target_sp->GetExecutableModule()); |
| 323 | if (module_sp) |
Jim Ingham | bf22b96 | 2013-07-11 01:47:46 +0000 | [diff] [blame] | 324 | { |
| 325 | if (symfile) |
| 326 | module_sp->SetSymbolFileFileSpec(symfile); |
| 327 | if (remote_file) |
| 328 | { |
| 329 | std::string remote_path = remote_file.GetPath(); |
| 330 | target_sp->SetArg0(remote_path.c_str()); |
| 331 | module_sp->SetPlatformFileSpec(remote_file); |
| 332 | } |
| 333 | } |
Greg Clayton | 1c5f186 | 2012-11-30 19:05:35 +0000 | [diff] [blame] | 334 | } |
| 335 | |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 336 | debugger.GetTargetList().SetSelectedTarget(target_sp.get()); |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame^] | 337 | if (must_set_platform_path) |
| 338 | { |
| 339 | ModuleSpec main_module_spec(file_spec); |
| 340 | ModuleSP module_sp = target_sp->GetSharedModule(main_module_spec); |
| 341 | if (module_sp) |
| 342 | module_sp->SetPlatformFileSpec(remote_file); |
| 343 | } |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 344 | if (core_file) |
| 345 | { |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 346 | char core_path[PATH_MAX]; |
| 347 | core_file.GetPath(core_path, sizeof(core_path)); |
Greg Clayton | c859e2d | 2012-02-13 23:10:39 +0000 | [diff] [blame] | 348 | if (core_file.Exists()) |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 349 | { |
Greg Clayton | c859e2d | 2012-02-13 23:10:39 +0000 | [diff] [blame] | 350 | FileSpec core_file_dir; |
| 351 | core_file_dir.GetDirectory() = core_file.GetDirectory(); |
| 352 | target_sp->GetExecutableSearchPaths ().Append (core_file_dir); |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 353 | |
Greg Clayton | c859e2d | 2012-02-13 23:10:39 +0000 | [diff] [blame] | 354 | ProcessSP process_sp (target_sp->CreateProcess (m_interpreter.GetDebugger().GetListener(), NULL, &core_file)); |
| 355 | |
| 356 | if (process_sp) |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 357 | { |
Greg Clayton | c859e2d | 2012-02-13 23:10:39 +0000 | [diff] [blame] | 358 | // Seems wierd that we Launch a core file, but that is |
| 359 | // what we do! |
| 360 | error = process_sp->LoadCore(); |
| 361 | |
| 362 | if (error.Fail()) |
| 363 | { |
| 364 | result.AppendError(error.AsCString("can't find plug-in for core file")); |
| 365 | result.SetStatus (eReturnStatusFailed); |
| 366 | return false; |
| 367 | } |
| 368 | else |
| 369 | { |
| 370 | result.AppendMessageWithFormat ("Core file '%s' (%s) was loaded.\n", core_path, target_sp->GetArchitecture().GetArchitectureName()); |
| 371 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 372 | } |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 373 | } |
| 374 | else |
| 375 | { |
Greg Clayton | c859e2d | 2012-02-13 23:10:39 +0000 | [diff] [blame] | 376 | result.AppendErrorWithFormat ("Unable to find process plug-in for core file '%s'\n", core_path); |
| 377 | result.SetStatus (eReturnStatusFailed); |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 378 | } |
| 379 | } |
| 380 | else |
| 381 | { |
Greg Clayton | c859e2d | 2012-02-13 23:10:39 +0000 | [diff] [blame] | 382 | result.AppendErrorWithFormat ("Core file '%s' does not exist\n", core_path); |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 383 | result.SetStatus (eReturnStatusFailed); |
| 384 | } |
| 385 | } |
| 386 | else |
| 387 | { |
| 388 | result.AppendMessageWithFormat ("Current executable set to '%s' (%s).\n", file_path, target_sp->GetArchitecture().GetArchitectureName()); |
| 389 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 390 | } |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 391 | } |
| 392 | else |
| 393 | { |
| 394 | result.AppendError(error.AsCString()); |
| 395 | result.SetStatus (eReturnStatusFailed); |
| 396 | } |
| 397 | } |
| 398 | else |
| 399 | { |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 400 | result.AppendErrorWithFormat("'%s' takes exactly one executable path argument, or use the --core-file option.\n", m_cmd_name.c_str()); |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 401 | result.SetStatus (eReturnStatusFailed); |
| 402 | } |
| 403 | return result.Succeeded(); |
| 404 | |
| 405 | } |
| 406 | |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 407 | private: |
| 408 | OptionGroupOptions m_option_group; |
Greg Clayton | 644247c | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 409 | OptionGroupArchitecture m_arch_option; |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 410 | OptionGroupPlatform m_platform_options; |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 411 | OptionGroupFile m_core_file; |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame^] | 412 | OptionGroupFile m_platform_path; |
Greg Clayton | 1c5f186 | 2012-11-30 19:05:35 +0000 | [diff] [blame] | 413 | OptionGroupFile m_symbol_file; |
Jim Ingham | bf22b96 | 2013-07-11 01:47:46 +0000 | [diff] [blame] | 414 | OptionGroupFile m_remote_file; |
Greg Clayton | 1c5f186 | 2012-11-30 19:05:35 +0000 | [diff] [blame] | 415 | OptionGroupBoolean m_add_dependents; |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 416 | }; |
| 417 | |
| 418 | #pragma mark CommandObjectTargetList |
| 419 | |
| 420 | //---------------------------------------------------------------------- |
| 421 | // "target list" |
| 422 | //---------------------------------------------------------------------- |
| 423 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 424 | class CommandObjectTargetList : public CommandObjectParsed |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 425 | { |
| 426 | public: |
| 427 | CommandObjectTargetList (CommandInterpreter &interpreter) : |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 428 | CommandObjectParsed (interpreter, |
| 429 | "target list", |
| 430 | "List all current targets in the current debug session.", |
| 431 | NULL, |
| 432 | 0) |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 433 | { |
| 434 | } |
| 435 | |
| 436 | virtual |
| 437 | ~CommandObjectTargetList () |
| 438 | { |
| 439 | } |
| 440 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 441 | protected: |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 442 | virtual bool |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 443 | DoExecute (Args& args, CommandReturnObject &result) |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 444 | { |
| 445 | if (args.GetArgumentCount() == 0) |
| 446 | { |
| 447 | Stream &strm = result.GetOutputStream(); |
| 448 | |
| 449 | bool show_stopped_process_status = false; |
| 450 | if (DumpTargetList (m_interpreter.GetDebugger().GetTargetList(), show_stopped_process_status, strm) == 0) |
| 451 | { |
| 452 | strm.PutCString ("No targets.\n"); |
| 453 | } |
Johnny Chen | 1ee61a7 | 2011-04-18 21:08:05 +0000 | [diff] [blame] | 454 | result.SetStatus (eReturnStatusSuccessFinishResult); |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 455 | } |
| 456 | else |
| 457 | { |
| 458 | result.AppendError ("the 'target list' command takes no arguments\n"); |
| 459 | result.SetStatus (eReturnStatusFailed); |
| 460 | } |
| 461 | return result.Succeeded(); |
| 462 | } |
| 463 | }; |
| 464 | |
| 465 | |
| 466 | #pragma mark CommandObjectTargetSelect |
| 467 | |
| 468 | //---------------------------------------------------------------------- |
| 469 | // "target select" |
| 470 | //---------------------------------------------------------------------- |
| 471 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 472 | class CommandObjectTargetSelect : public CommandObjectParsed |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 473 | { |
| 474 | public: |
| 475 | CommandObjectTargetSelect (CommandInterpreter &interpreter) : |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 476 | CommandObjectParsed (interpreter, |
| 477 | "target select", |
| 478 | "Select a target as the current target by target index.", |
| 479 | NULL, |
| 480 | 0) |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 481 | { |
| 482 | } |
| 483 | |
| 484 | virtual |
| 485 | ~CommandObjectTargetSelect () |
| 486 | { |
| 487 | } |
| 488 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 489 | protected: |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 490 | virtual bool |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 491 | DoExecute (Args& args, CommandReturnObject &result) |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 492 | { |
| 493 | if (args.GetArgumentCount() == 1) |
| 494 | { |
| 495 | bool success = false; |
| 496 | const char *target_idx_arg = args.GetArgumentAtIndex(0); |
| 497 | uint32_t target_idx = Args::StringToUInt32 (target_idx_arg, UINT32_MAX, 0, &success); |
| 498 | if (success) |
| 499 | { |
| 500 | TargetList &target_list = m_interpreter.GetDebugger().GetTargetList(); |
| 501 | const uint32_t num_targets = target_list.GetNumTargets(); |
| 502 | if (target_idx < num_targets) |
| 503 | { |
| 504 | TargetSP target_sp (target_list.GetTargetAtIndex (target_idx)); |
| 505 | if (target_sp) |
| 506 | { |
| 507 | Stream &strm = result.GetOutputStream(); |
| 508 | target_list.SetSelectedTarget (target_sp.get()); |
| 509 | bool show_stopped_process_status = false; |
| 510 | DumpTargetList (target_list, show_stopped_process_status, strm); |
Johnny Chen | 1ee61a7 | 2011-04-18 21:08:05 +0000 | [diff] [blame] | 511 | result.SetStatus (eReturnStatusSuccessFinishResult); |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 512 | } |
| 513 | else |
| 514 | { |
| 515 | result.AppendErrorWithFormat ("target #%u is NULL in target list\n", target_idx); |
| 516 | result.SetStatus (eReturnStatusFailed); |
| 517 | } |
| 518 | } |
| 519 | else |
| 520 | { |
| 521 | result.AppendErrorWithFormat ("index %u is out of range, valid target indexes are 0 - %u\n", |
| 522 | target_idx, |
| 523 | num_targets - 1); |
| 524 | result.SetStatus (eReturnStatusFailed); |
| 525 | } |
| 526 | } |
| 527 | else |
| 528 | { |
| 529 | result.AppendErrorWithFormat("invalid index string value '%s'\n", target_idx_arg); |
| 530 | result.SetStatus (eReturnStatusFailed); |
| 531 | } |
| 532 | } |
| 533 | else |
| 534 | { |
| 535 | result.AppendError ("'target select' takes a single argument: a target index\n"); |
| 536 | result.SetStatus (eReturnStatusFailed); |
| 537 | } |
| 538 | return result.Succeeded(); |
| 539 | } |
| 540 | }; |
| 541 | |
Greg Clayton | 3418c85 | 2011-08-10 02:10:13 +0000 | [diff] [blame] | 542 | #pragma mark CommandObjectTargetSelect |
| 543 | |
| 544 | //---------------------------------------------------------------------- |
| 545 | // "target delete" |
| 546 | //---------------------------------------------------------------------- |
| 547 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 548 | class CommandObjectTargetDelete : public CommandObjectParsed |
Greg Clayton | 3418c85 | 2011-08-10 02:10:13 +0000 | [diff] [blame] | 549 | { |
| 550 | public: |
| 551 | CommandObjectTargetDelete (CommandInterpreter &interpreter) : |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 552 | CommandObjectParsed (interpreter, |
| 553 | "target delete", |
| 554 | "Delete one or more targets by target index.", |
| 555 | NULL, |
| 556 | 0), |
Greg Clayton | aa149cb | 2011-08-11 02:48:45 +0000 | [diff] [blame] | 557 | m_option_group (interpreter), |
Greg Clayton | b5f0fea | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 558 | m_cleanup_option (LLDB_OPT_SET_1, false, "clean", 'c', "Perform extra cleanup to minimize memory consumption after deleting the target.", false, false) |
Greg Clayton | 3418c85 | 2011-08-10 02:10:13 +0000 | [diff] [blame] | 559 | { |
Greg Clayton | aa149cb | 2011-08-11 02:48:45 +0000 | [diff] [blame] | 560 | m_option_group.Append (&m_cleanup_option, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1); |
| 561 | m_option_group.Finalize(); |
Greg Clayton | 3418c85 | 2011-08-10 02:10:13 +0000 | [diff] [blame] | 562 | } |
| 563 | |
| 564 | virtual |
| 565 | ~CommandObjectTargetDelete () |
| 566 | { |
| 567 | } |
| 568 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 569 | Options * |
| 570 | GetOptions () |
| 571 | { |
| 572 | return &m_option_group; |
| 573 | } |
| 574 | |
| 575 | protected: |
Greg Clayton | 3418c85 | 2011-08-10 02:10:13 +0000 | [diff] [blame] | 576 | virtual bool |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 577 | DoExecute (Args& args, CommandReturnObject &result) |
Greg Clayton | 3418c85 | 2011-08-10 02:10:13 +0000 | [diff] [blame] | 578 | { |
| 579 | const size_t argc = args.GetArgumentCount(); |
| 580 | std::vector<TargetSP> delete_target_list; |
| 581 | TargetList &target_list = m_interpreter.GetDebugger().GetTargetList(); |
| 582 | bool success = true; |
| 583 | TargetSP target_sp; |
| 584 | if (argc > 0) |
| 585 | { |
| 586 | const uint32_t num_targets = target_list.GetNumTargets(); |
Filipe Cabecinhas | f065fdc | 2012-07-09 13:02:17 +0000 | [diff] [blame] | 587 | // Bail out if don't have any targets. |
| 588 | if (num_targets == 0) { |
| 589 | result.AppendError("no targets to delete"); |
| 590 | result.SetStatus(eReturnStatusFailed); |
| 591 | success = false; |
| 592 | } |
| 593 | |
Greg Clayton | 3418c85 | 2011-08-10 02:10:13 +0000 | [diff] [blame] | 594 | for (uint32_t arg_idx = 0; success && arg_idx < argc; ++arg_idx) |
| 595 | { |
| 596 | const char *target_idx_arg = args.GetArgumentAtIndex(arg_idx); |
| 597 | uint32_t target_idx = Args::StringToUInt32 (target_idx_arg, UINT32_MAX, 0, &success); |
| 598 | if (success) |
| 599 | { |
| 600 | if (target_idx < num_targets) |
| 601 | { |
| 602 | target_sp = target_list.GetTargetAtIndex (target_idx); |
| 603 | if (target_sp) |
| 604 | { |
| 605 | delete_target_list.push_back (target_sp); |
| 606 | continue; |
| 607 | } |
| 608 | } |
Filipe Cabecinhas | f065fdc | 2012-07-09 13:02:17 +0000 | [diff] [blame] | 609 | if (num_targets > 1) |
| 610 | result.AppendErrorWithFormat ("target index %u is out of range, valid target indexes are 0 - %u\n", |
| 611 | target_idx, |
| 612 | num_targets - 1); |
| 613 | else |
| 614 | result.AppendErrorWithFormat("target index %u is out of range, the only valid index is 0\n", |
| 615 | target_idx); |
| 616 | |
Greg Clayton | 3418c85 | 2011-08-10 02:10:13 +0000 | [diff] [blame] | 617 | result.SetStatus (eReturnStatusFailed); |
| 618 | success = false; |
| 619 | } |
| 620 | else |
| 621 | { |
| 622 | result.AppendErrorWithFormat("invalid target index '%s'\n", target_idx_arg); |
| 623 | result.SetStatus (eReturnStatusFailed); |
| 624 | success = false; |
| 625 | } |
| 626 | } |
| 627 | |
| 628 | } |
| 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 Clayton | aa149cb | 2011-08-11 02:48:45 +0000 | [diff] [blame] | 652 | // If "--clean" was specified, prune any orphaned shared modules from |
| 653 | // the global shared module list |
| 654 | if (m_cleanup_option.GetOptionValue ()) |
| 655 | { |
Greg Clayton | 0cd7086 | 2012-04-09 20:22:01 +0000 | [diff] [blame] | 656 | const bool mandatory = true; |
| 657 | ModuleList::RemoveOrphanSharedModules(mandatory); |
Greg Clayton | aa149cb | 2011-08-11 02:48:45 +0000 | [diff] [blame] | 658 | } |
Greg Clayton | 3418c85 | 2011-08-10 02:10:13 +0000 | [diff] [blame] | 659 | result.GetOutputStream().Printf("%u targets deleted.\n", (uint32_t)num_targets_to_delete); |
| 660 | result.SetStatus(eReturnStatusSuccessFinishResult); |
| 661 | } |
| 662 | |
| 663 | return result.Succeeded(); |
| 664 | } |
Greg Clayton | aa149cb | 2011-08-11 02:48:45 +0000 | [diff] [blame] | 665 | |
Greg Clayton | aa149cb | 2011-08-11 02:48:45 +0000 | [diff] [blame] | 666 | OptionGroupOptions m_option_group; |
| 667 | OptionGroupBoolean m_cleanup_option; |
Greg Clayton | 3418c85 | 2011-08-10 02:10:13 +0000 | [diff] [blame] | 668 | }; |
| 669 | |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 670 | |
Greg Clayton | 644247c | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 671 | #pragma mark CommandObjectTargetVariable |
| 672 | |
| 673 | //---------------------------------------------------------------------- |
| 674 | // "target variable" |
| 675 | //---------------------------------------------------------------------- |
| 676 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 677 | class CommandObjectTargetVariable : public CommandObjectParsed |
Greg Clayton | 644247c | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 678 | { |
| 679 | public: |
| 680 | CommandObjectTargetVariable (CommandInterpreter &interpreter) : |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 681 | CommandObjectParsed (interpreter, |
| 682 | "target variable", |
Greg Clayton | dfdd1eb | 2012-11-03 00:10:22 +0000 | [diff] [blame] | 683 | "Read global variable(s) prior to, or while running your binary.", |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 684 | NULL, |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 685 | eFlagRequiresTarget), |
Greg Clayton | 644247c | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 686 | m_option_group (interpreter), |
Greg Clayton | 715c236 | 2011-07-07 04:38:25 +0000 | [diff] [blame] | 687 | m_option_variable (false), // Don't include frame options |
Greg Clayton | 1deb796 | 2011-10-25 06:44:01 +0000 | [diff] [blame] | 688 | m_option_format (eFormatDefault), |
Greg Clayton | 3bcdfc0 | 2012-12-04 00:32:51 +0000 | [diff] [blame] | 689 | m_option_compile_units (LLDB_OPT_SET_1, false, "file", 'file', 0, eArgTypeFilename, "A basename or fullpath to a file that contains global variables. This option can be specified multiple times."), |
| 690 | m_option_shared_libraries (LLDB_OPT_SET_1, false, "shlib",'shlb', 0, eArgTypeFilename, "A basename or fullpath to a shared library to use in the search for global variables. This option can be specified multiple times."), |
Greg Clayton | 644247c | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 691 | m_varobj_options() |
| 692 | { |
Johnny Chen | 81ab3f5 | 2011-08-22 22:22:00 +0000 | [diff] [blame] | 693 | CommandArgumentEntry arg; |
| 694 | CommandArgumentData var_name_arg; |
| 695 | |
| 696 | // Define the first (and only) variant of this arg. |
| 697 | var_name_arg.arg_type = eArgTypeVarName; |
| 698 | var_name_arg.arg_repetition = eArgRepeatPlus; |
| 699 | |
| 700 | // There is only one variant this argument could be; put it into the argument entry. |
| 701 | arg.push_back (var_name_arg); |
| 702 | |
| 703 | // Push the data for the first argument into the m_arguments vector. |
| 704 | m_arguments.push_back (arg); |
| 705 | |
Greg Clayton | 644247c | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 706 | m_option_group.Append (&m_varobj_options, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1); |
Greg Clayton | 715c236 | 2011-07-07 04:38:25 +0000 | [diff] [blame] | 707 | m_option_group.Append (&m_option_variable, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1); |
Greg Clayton | 5009f9d | 2011-10-27 17:55:14 +0000 | [diff] [blame] | 708 | m_option_group.Append (&m_option_format, OptionGroupFormat::OPTION_GROUP_FORMAT | OptionGroupFormat::OPTION_GROUP_GDB_FMT, LLDB_OPT_SET_1); |
Greg Clayton | 644247c | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 709 | m_option_group.Append (&m_option_compile_units, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1); |
| 710 | m_option_group.Append (&m_option_shared_libraries, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1); |
| 711 | m_option_group.Finalize(); |
| 712 | } |
| 713 | |
| 714 | virtual |
| 715 | ~CommandObjectTargetVariable () |
| 716 | { |
| 717 | } |
Greg Clayton | 884fb69 | 2011-07-08 21:46:14 +0000 | [diff] [blame] | 718 | |
| 719 | void |
| 720 | DumpValueObject (Stream &s, VariableSP &var_sp, ValueObjectSP &valobj_sp, const char *root_name) |
| 721 | { |
Enrico Granata | 9fb5ab5 | 2013-03-26 18:04:53 +0000 | [diff] [blame] | 722 | ValueObject::DumpValueObjectOptions options(m_varobj_options.GetAsDumpOptions()); |
Enrico Granata | 379447a | 2011-08-15 18:01:31 +0000 | [diff] [blame] | 723 | |
Greg Clayton | 884fb69 | 2011-07-08 21:46:14 +0000 | [diff] [blame] | 724 | switch (var_sp->GetScope()) |
| 725 | { |
| 726 | case eValueTypeVariableGlobal: |
| 727 | if (m_option_variable.show_scope) |
| 728 | s.PutCString("GLOBAL: "); |
| 729 | break; |
| 730 | |
| 731 | case eValueTypeVariableStatic: |
| 732 | if (m_option_variable.show_scope) |
| 733 | s.PutCString("STATIC: "); |
| 734 | break; |
| 735 | |
| 736 | case eValueTypeVariableArgument: |
| 737 | if (m_option_variable.show_scope) |
| 738 | s.PutCString(" ARG: "); |
| 739 | break; |
| 740 | |
| 741 | case eValueTypeVariableLocal: |
| 742 | if (m_option_variable.show_scope) |
| 743 | s.PutCString(" LOCAL: "); |
| 744 | break; |
| 745 | |
| 746 | default: |
| 747 | break; |
| 748 | } |
| 749 | |
Greg Clayton | 45ba854 | 2011-07-10 19:21:23 +0000 | [diff] [blame] | 750 | if (m_option_variable.show_decl) |
Greg Clayton | 884fb69 | 2011-07-08 21:46:14 +0000 | [diff] [blame] | 751 | { |
Greg Clayton | 45ba854 | 2011-07-10 19:21:23 +0000 | [diff] [blame] | 752 | bool show_fullpaths = false; |
| 753 | bool show_module = true; |
| 754 | if (var_sp->DumpDeclaration(&s, show_fullpaths, show_module)) |
| 755 | s.PutCString (": "); |
Greg Clayton | 884fb69 | 2011-07-08 21:46:14 +0000 | [diff] [blame] | 756 | } |
| 757 | |
Greg Clayton | 1deb796 | 2011-10-25 06:44:01 +0000 | [diff] [blame] | 758 | const Format format = m_option_format.GetFormat(); |
Greg Clayton | 884fb69 | 2011-07-08 21:46:14 +0000 | [diff] [blame] | 759 | if (format != eFormatDefault) |
Enrico Granata | 0c489f5 | 2012-03-01 04:24:26 +0000 | [diff] [blame] | 760 | options.SetFormat(format); |
| 761 | |
| 762 | options.SetRootValueObjectName(root_name); |
Greg Clayton | 884fb69 | 2011-07-08 21:46:14 +0000 | [diff] [blame] | 763 | |
| 764 | ValueObject::DumpValueObject (s, |
| 765 | valobj_sp.get(), |
Enrico Granata | 0c489f5 | 2012-03-01 04:24:26 +0000 | [diff] [blame] | 766 | options); |
Greg Clayton | 884fb69 | 2011-07-08 21:46:14 +0000 | [diff] [blame] | 767 | |
| 768 | } |
Greg Clayton | 644247c | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 769 | |
Greg Clayton | 884fb69 | 2011-07-08 21:46:14 +0000 | [diff] [blame] | 770 | |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 771 | static size_t GetVariableCallback (void *baton, |
| 772 | const char *name, |
| 773 | VariableList &variable_list) |
Greg Clayton | 884fb69 | 2011-07-08 21:46:14 +0000 | [diff] [blame] | 774 | { |
| 775 | Target *target = static_cast<Target *>(baton); |
| 776 | if (target) |
| 777 | { |
| 778 | return target->GetImages().FindGlobalVariables (ConstString(name), |
| 779 | true, |
| 780 | UINT32_MAX, |
| 781 | variable_list); |
| 782 | } |
| 783 | return 0; |
| 784 | } |
| 785 | |
| 786 | |
| 787 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 788 | Options * |
| 789 | GetOptions () |
| 790 | { |
| 791 | return &m_option_group; |
| 792 | } |
| 793 | |
| 794 | protected: |
Greg Clayton | 3bcdfc0 | 2012-12-04 00:32:51 +0000 | [diff] [blame] | 795 | |
| 796 | 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 Clayton | b5ad4ec | 2013-04-29 17:25:54 +0000 | [diff] [blame] | 806 | 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 Clayton | 3bcdfc0 | 2012-12-04 00:32:51 +0000 | [diff] [blame] | 809 | } |
| 810 | else |
| 811 | { |
Greg Clayton | b5ad4ec | 2013-04-29 17:25:54 +0000 | [diff] [blame] | 812 | s.Printf ("Global variables for %s\n", |
| 813 | sc.module_sp->GetFileSpec().GetPath().c_str()); |
Greg Clayton | 3bcdfc0 | 2012-12-04 00:32:51 +0000 | [diff] [blame] | 814 | } |
| 815 | } |
| 816 | else if (sc.comp_unit) |
| 817 | { |
Greg Clayton | b5ad4ec | 2013-04-29 17:25:54 +0000 | [diff] [blame] | 818 | s.Printf ("Global variables for %s\n", |
| 819 | sc.comp_unit->GetPath().c_str()); |
Greg Clayton | 3bcdfc0 | 2012-12-04 00:32:51 +0000 | [diff] [blame] | 820 | } |
| 821 | |
| 822 | 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)); |
| 828 | |
| 829 | if (valobj_sp) |
| 830 | DumpValueObject (s, var_sp, valobj_sp, var_sp->GetName().GetCString()); |
| 831 | } |
| 832 | } |
| 833 | } |
| 834 | |
| 835 | } |
Greg Clayton | 644247c | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 836 | virtual bool |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 837 | DoExecute (Args& args, CommandReturnObject &result) |
Greg Clayton | 644247c | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 838 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 839 | Target *target = m_exe_ctx.GetTargetPtr(); |
| 840 | const size_t argc = args.GetArgumentCount(); |
| 841 | Stream &s = result.GetOutputStream(); |
| 842 | |
| 843 | if (argc > 0) |
Greg Clayton | 644247c | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 844 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 845 | |
| 846 | for (size_t idx = 0; idx < argc; ++idx) |
Greg Clayton | 644247c | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 847 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 848 | VariableList variable_list; |
| 849 | ValueObjectList valobj_list; |
Greg Clayton | 884fb69 | 2011-07-08 21:46:14 +0000 | [diff] [blame] | 850 | |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 851 | const char *arg = args.GetArgumentAtIndex(idx); |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 852 | size_t matches = 0; |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 853 | bool use_var_name = false; |
| 854 | if (m_option_variable.use_regex) |
Greg Clayton | 644247c | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 855 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 856 | RegularExpression regex(arg); |
| 857 | if (!regex.IsValid ()) |
Greg Clayton | 644247c | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 858 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 859 | result.GetErrorStream().Printf ("error: invalid regular expression: '%s'\n", arg); |
Greg Clayton | 715c236 | 2011-07-07 04:38:25 +0000 | [diff] [blame] | 860 | result.SetStatus (eReturnStatusFailed); |
| 861 | return false; |
| 862 | } |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 863 | use_var_name = true; |
| 864 | matches = target->GetImages().FindGlobalVariables (regex, |
| 865 | true, |
| 866 | UINT32_MAX, |
| 867 | variable_list); |
Greg Clayton | 3bcdfc0 | 2012-12-04 00:32:51 +0000 | [diff] [blame] | 868 | } |
| 869 | else |
| 870 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 871 | 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 | } |
| 879 | |
| 880 | 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 Clayton | 3bcdfc0 | 2012-12-04 00:32:51 +0000 | [diff] [blame] | 889 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 890 | VariableSP var_sp (variable_list.GetVariableAtIndex(global_idx)); |
| 891 | if (var_sp) |
Greg Clayton | 3bcdfc0 | 2012-12-04 00:32:51 +0000 | [diff] [blame] | 892 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 893 | ValueObjectSP valobj_sp (valobj_list.GetValueObjectAtIndex(global_idx)); |
| 894 | if (!valobj_sp) |
| 895 | valobj_sp = ValueObjectVariable::Create (m_exe_ctx.GetBestExecutionContextScope(), var_sp); |
Greg Clayton | 3bcdfc0 | 2012-12-04 00:32:51 +0000 | [diff] [blame] | 896 | |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 897 | if (valobj_sp) |
| 898 | DumpValueObject (s, var_sp, valobj_sp, use_var_name ? var_sp->GetName().GetCString() : arg); |
Greg Clayton | 3bcdfc0 | 2012-12-04 00:32:51 +0000 | [diff] [blame] | 899 | } |
| 900 | } |
Greg Clayton | 9a5a934 | 2011-10-05 22:17:32 +0000 | [diff] [blame] | 901 | } |
Greg Clayton | 644247c | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 902 | } |
| 903 | } |
| 904 | else |
| 905 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 906 | 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; |
| 914 | StackFrame *frame = m_exe_ctx.GetFramePtr(); |
| 915 | 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 Clayton | b5ad4ec | 2013-04-29 17:25:54 +0000 | [diff] [blame] | 939 | result.AppendErrorWithFormat ("no global variables in current compile unit: %s\n", |
| 940 | comp_unit->GetPath().c_str()); |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 941 | else |
| 942 | result.AppendErrorWithFormat ("no debug information for frame %u\n", frame->GetFrameIndex()); |
| 943 | } |
| 944 | 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); |
| 960 | |
| 961 | 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 Clayton | b5ad4ec | 2013-04-29 17:25:54 +0000 | [diff] [blame] | 979 | result.AppendErrorWithFormat ("target doesn't contain the specified shared library: %s\n", |
| 980 | module_file.GetPath().c_str()); |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 981 | } |
| 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 | } |
| 990 | |
| 991 | 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 Clayton | 644247c | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 1018 | } |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 1019 | |
Enrico Granata | 61a80ba | 2011-08-12 16:42:31 +0000 | [diff] [blame] | 1020 | if (m_interpreter.TruncationWarningNecessary()) |
| 1021 | { |
| 1022 | result.GetOutputStream().Printf(m_interpreter.TruncationWarningText(), |
| 1023 | m_cmd_name.c_str()); |
| 1024 | m_interpreter.TruncationWarningGiven(); |
| 1025 | } |
| 1026 | |
Greg Clayton | 644247c | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 1027 | return result.Succeeded(); |
| 1028 | } |
| 1029 | |
Greg Clayton | 644247c | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 1030 | OptionGroupOptions m_option_group; |
Greg Clayton | 715c236 | 2011-07-07 04:38:25 +0000 | [diff] [blame] | 1031 | OptionGroupVariable m_option_variable; |
Greg Clayton | 1deb796 | 2011-10-25 06:44:01 +0000 | [diff] [blame] | 1032 | OptionGroupFormat m_option_format; |
Greg Clayton | 644247c | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 1033 | OptionGroupFileList m_option_compile_units; |
| 1034 | OptionGroupFileList m_option_shared_libraries; |
| 1035 | OptionGroupValueObjectDisplay m_varobj_options; |
| 1036 | |
| 1037 | }; |
| 1038 | |
| 1039 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1040 | #pragma mark CommandObjectTargetModulesSearchPathsAdd |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1041 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1042 | class CommandObjectTargetModulesSearchPathsAdd : public CommandObjectParsed |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1043 | { |
| 1044 | public: |
| 1045 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1046 | CommandObjectTargetModulesSearchPathsAdd (CommandInterpreter &interpreter) : |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1047 | CommandObjectParsed (interpreter, |
| 1048 | "target modules search-paths add", |
| 1049 | "Add new image search paths substitution pairs to the current target.", |
| 1050 | NULL) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1051 | { |
Caroline Tice | 405fe67 | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 1052 | CommandArgumentEntry arg; |
| 1053 | CommandArgumentData old_prefix_arg; |
| 1054 | CommandArgumentData new_prefix_arg; |
| 1055 | |
| 1056 | // Define the first variant of this arg pair. |
| 1057 | old_prefix_arg.arg_type = eArgTypeOldPathPrefix; |
| 1058 | old_prefix_arg.arg_repetition = eArgRepeatPairPlus; |
| 1059 | |
| 1060 | // Define the first variant of this arg pair. |
| 1061 | new_prefix_arg.arg_type = eArgTypeNewPathPrefix; |
| 1062 | new_prefix_arg.arg_repetition = eArgRepeatPairPlus; |
| 1063 | |
| 1064 | // 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 Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1072 | } |
| 1073 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1074 | ~CommandObjectTargetModulesSearchPathsAdd () |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1075 | { |
| 1076 | } |
| 1077 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1078 | protected: |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1079 | bool |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1080 | DoExecute (Args& command, |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1081 | CommandReturnObject &result) |
| 1082 | { |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1083 | Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1084 | if (target) |
| 1085 | { |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 1086 | const size_t argc = command.GetArgumentCount(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1087 | if (argc & 1) |
| 1088 | { |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1089 | result.AppendError ("add requires an even number of arguments\n"); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1090 | result.SetStatus (eReturnStatusFailed); |
| 1091 | } |
| 1092 | else |
| 1093 | { |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 1094 | for (size_t i=0; i<argc; i+=2) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1095 | { |
| 1096 | const char *from = command.GetArgumentAtIndex(i); |
| 1097 | const char *to = command.GetArgumentAtIndex(i+1); |
| 1098 | |
| 1099 | if (from[0] && to[0]) |
| 1100 | { |
| 1101 | bool last_pair = ((argc - i) == 2); |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 1102 | target->GetImageSearchPathList().Append (ConstString(from), |
| 1103 | ConstString(to), |
| 1104 | last_pair); // Notify if this is the last pair |
Johnny Chen | 7791b33 | 2011-02-03 00:30:19 +0000 | [diff] [blame] | 1105 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1106 | } |
| 1107 | else |
| 1108 | { |
| 1109 | if (from[0]) |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1110 | result.AppendError ("<path-prefix> can't be empty\n"); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1111 | else |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1112 | result.AppendError ("<new-path-prefix> can't be empty\n"); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1113 | result.SetStatus (eReturnStatusFailed); |
| 1114 | } |
| 1115 | } |
| 1116 | } |
| 1117 | } |
| 1118 | else |
| 1119 | { |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1120 | result.AppendError ("invalid target\n"); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1121 | result.SetStatus (eReturnStatusFailed); |
| 1122 | } |
| 1123 | return result.Succeeded(); |
| 1124 | } |
| 1125 | }; |
| 1126 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1127 | #pragma mark CommandObjectTargetModulesSearchPathsClear |
| 1128 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1129 | class CommandObjectTargetModulesSearchPathsClear : public CommandObjectParsed |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1130 | { |
| 1131 | public: |
| 1132 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1133 | CommandObjectTargetModulesSearchPathsClear (CommandInterpreter &interpreter) : |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1134 | 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 Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1138 | { |
| 1139 | } |
| 1140 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1141 | ~CommandObjectTargetModulesSearchPathsClear () |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1142 | { |
| 1143 | } |
| 1144 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1145 | protected: |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1146 | bool |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1147 | DoExecute (Args& command, |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1148 | CommandReturnObject &result) |
| 1149 | { |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1150 | Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1151 | if (target) |
| 1152 | { |
| 1153 | bool notify = true; |
| 1154 | target->GetImageSearchPathList().Clear(notify); |
Johnny Chen | 7791b33 | 2011-02-03 00:30:19 +0000 | [diff] [blame] | 1155 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1156 | } |
| 1157 | else |
| 1158 | { |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1159 | result.AppendError ("invalid target\n"); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1160 | result.SetStatus (eReturnStatusFailed); |
| 1161 | } |
| 1162 | return result.Succeeded(); |
| 1163 | } |
| 1164 | }; |
| 1165 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1166 | #pragma mark CommandObjectTargetModulesSearchPathsInsert |
| 1167 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1168 | class CommandObjectTargetModulesSearchPathsInsert : public CommandObjectParsed |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1169 | { |
| 1170 | public: |
| 1171 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1172 | CommandObjectTargetModulesSearchPathsInsert (CommandInterpreter &interpreter) : |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1173 | 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 Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1177 | { |
Caroline Tice | 405fe67 | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 1178 | CommandArgumentEntry arg1; |
| 1179 | CommandArgumentEntry arg2; |
| 1180 | CommandArgumentData index_arg; |
| 1181 | CommandArgumentData old_prefix_arg; |
| 1182 | CommandArgumentData new_prefix_arg; |
| 1183 | |
| 1184 | // 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; |
| 1194 | |
| 1195 | // Define the first variant of this arg pair. |
| 1196 | new_prefix_arg.arg_type = eArgTypeNewPathPrefix; |
| 1197 | new_prefix_arg.arg_repetition = eArgRepeatPairPlus; |
| 1198 | |
| 1199 | // 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 Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1209 | } |
| 1210 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1211 | ~CommandObjectTargetModulesSearchPathsInsert () |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1212 | { |
| 1213 | } |
| 1214 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1215 | protected: |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1216 | bool |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1217 | DoExecute (Args& command, |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1218 | CommandReturnObject &result) |
| 1219 | { |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1220 | Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1221 | if (target) |
| 1222 | { |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 1223 | size_t argc = command.GetArgumentCount(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1224 | // 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); |
| 1246 | |
| 1247 | 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 Chen | 7791b33 | 2011-02-03 00:30:19 +0000 | [diff] [blame] | 1254 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1255 | } |
| 1256 | else |
| 1257 | { |
| 1258 | if (from[0]) |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1259 | result.AppendError ("<path-prefix> can't be empty\n"); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1260 | else |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1261 | result.AppendError ("<new-path-prefix> can't be empty\n"); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1262 | result.SetStatus (eReturnStatusFailed); |
| 1263 | return false; |
| 1264 | } |
| 1265 | } |
| 1266 | } |
| 1267 | else |
| 1268 | { |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1269 | result.AppendError ("insert requires at least three arguments\n"); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1270 | result.SetStatus (eReturnStatusFailed); |
| 1271 | return result.Succeeded(); |
| 1272 | } |
| 1273 | |
| 1274 | } |
| 1275 | else |
| 1276 | { |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1277 | result.AppendError ("invalid target\n"); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1278 | result.SetStatus (eReturnStatusFailed); |
| 1279 | } |
| 1280 | return result.Succeeded(); |
| 1281 | } |
| 1282 | }; |
| 1283 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1284 | |
| 1285 | #pragma mark CommandObjectTargetModulesSearchPathsList |
| 1286 | |
| 1287 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1288 | class CommandObjectTargetModulesSearchPathsList : public CommandObjectParsed |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1289 | { |
| 1290 | public: |
| 1291 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1292 | CommandObjectTargetModulesSearchPathsList (CommandInterpreter &interpreter) : |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1293 | 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 Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1297 | { |
| 1298 | } |
| 1299 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1300 | ~CommandObjectTargetModulesSearchPathsList () |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1301 | { |
| 1302 | } |
| 1303 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1304 | protected: |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1305 | bool |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1306 | DoExecute (Args& command, |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1307 | CommandReturnObject &result) |
| 1308 | { |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1309 | Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1310 | if (target) |
| 1311 | { |
| 1312 | if (command.GetArgumentCount() != 0) |
| 1313 | { |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1314 | result.AppendError ("list takes no arguments\n"); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1315 | result.SetStatus (eReturnStatusFailed); |
| 1316 | return result.Succeeded(); |
| 1317 | } |
| 1318 | |
| 1319 | target->GetImageSearchPathList().Dump(&result.GetOutputStream()); |
Johnny Chen | 7791b33 | 2011-02-03 00:30:19 +0000 | [diff] [blame] | 1320 | result.SetStatus (eReturnStatusSuccessFinishResult); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1321 | } |
| 1322 | else |
| 1323 | { |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1324 | result.AppendError ("invalid target\n"); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1325 | result.SetStatus (eReturnStatusFailed); |
| 1326 | } |
| 1327 | return result.Succeeded(); |
| 1328 | } |
| 1329 | }; |
| 1330 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1331 | #pragma mark CommandObjectTargetModulesSearchPathsQuery |
| 1332 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1333 | class CommandObjectTargetModulesSearchPathsQuery : public CommandObjectParsed |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1334 | { |
| 1335 | public: |
| 1336 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1337 | CommandObjectTargetModulesSearchPathsQuery (CommandInterpreter &interpreter) : |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1338 | CommandObjectParsed (interpreter, |
| 1339 | "target modules search-paths query", |
| 1340 | "Transform a path using the first applicable image search path.", |
| 1341 | NULL) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1342 | { |
Caroline Tice | 405fe67 | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 1343 | CommandArgumentEntry arg; |
| 1344 | CommandArgumentData path_arg; |
| 1345 | |
| 1346 | // Define the first (and only) variant of this arg. |
Sean Callanan | 3154255 | 2012-10-24 01:12:14 +0000 | [diff] [blame] | 1347 | path_arg.arg_type = eArgTypeDirectoryName; |
Caroline Tice | 405fe67 | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 1348 | path_arg.arg_repetition = eArgRepeatPlain; |
| 1349 | |
| 1350 | // There is only one variant this argument could be; put it into the argument entry. |
| 1351 | arg.push_back (path_arg); |
| 1352 | |
| 1353 | // Push the data for the first argument into the m_arguments vector. |
| 1354 | m_arguments.push_back (arg); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1355 | } |
| 1356 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1357 | ~CommandObjectTargetModulesSearchPathsQuery () |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1358 | { |
| 1359 | } |
| 1360 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1361 | protected: |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1362 | bool |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1363 | DoExecute (Args& command, |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1364 | CommandReturnObject &result) |
| 1365 | { |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1366 | Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1367 | if (target) |
| 1368 | { |
| 1369 | if (command.GetArgumentCount() != 1) |
| 1370 | { |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1371 | result.AppendError ("query requires one argument\n"); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1372 | 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 Chen | 7791b33 | 2011-02-03 00:30:19 +0000 | [diff] [blame] | 1382 | |
| 1383 | result.SetStatus (eReturnStatusSuccessFinishResult); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1384 | } |
| 1385 | else |
| 1386 | { |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1387 | result.AppendError ("invalid target\n"); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1388 | result.SetStatus (eReturnStatusFailed); |
| 1389 | } |
| 1390 | return result.Succeeded(); |
| 1391 | } |
| 1392 | }; |
| 1393 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1394 | //---------------------------------------------------------------------- |
| 1395 | // Static Helper functions |
| 1396 | //---------------------------------------------------------------------- |
| 1397 | static void |
| 1398 | DumpModuleArchitecture (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 | |
| 1414 | static void |
| 1415 | DumpModuleUUID (Stream &strm, Module *module) |
| 1416 | { |
Jim Ingham | 28eb571 | 2012-10-12 17:34:26 +0000 | [diff] [blame] | 1417 | if (module && module->GetUUID().IsValid()) |
Greg Clayton | 3418c85 | 2011-08-10 02:10:13 +0000 | [diff] [blame] | 1418 | module->GetUUID().Dump (&strm); |
| 1419 | else |
| 1420 | strm.PutCString(" "); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1421 | } |
| 1422 | |
| 1423 | static uint32_t |
Greg Clayton | a0ca660 | 2012-10-18 16:33:33 +0000 | [diff] [blame] | 1424 | DumpCompileUnitLineTable (CommandInterpreter &interpreter, |
| 1425 | Stream &strm, |
| 1426 | Module *module, |
| 1427 | const FileSpec &file_spec, |
| 1428 | bool load_addresses) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1429 | { |
| 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); |
| 1439 | |
| 1440 | 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"; |
| 1447 | |
| 1448 | 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 Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 1453 | interpreter.GetExecutionContext().GetTargetPtr(), |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1454 | lldb::eDescriptionLevelBrief); |
| 1455 | else |
| 1456 | strm << "No line table"; |
| 1457 | } |
| 1458 | } |
| 1459 | } |
| 1460 | return num_matches; |
| 1461 | } |
| 1462 | |
| 1463 | static void |
| 1464 | DumpFullpath (Stream &strm, const FileSpec *file_spec_ptr, uint32_t width) |
| 1465 | { |
| 1466 | if (file_spec_ptr) |
| 1467 | { |
| 1468 | if (width > 0) |
| 1469 | { |
Jason Molenda | db7d11c | 2013-05-06 10:21:11 +0000 | [diff] [blame] | 1470 | std::string fullpath = file_spec_ptr->GetPath(); |
| 1471 | strm.Printf("%-*s", width, fullpath.c_str()); |
| 1472 | return; |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1473 | } |
| 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 | |
| 1485 | static void |
| 1486 | DumpDirectory (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 | |
| 1501 | static void |
| 1502 | DumpBasename (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 | |
| 1518 | static void |
| 1519 | DumpModuleSymtab (CommandInterpreter &interpreter, Stream &strm, Module *module, SortOrder sort_order) |
| 1520 | { |
| 1521 | if (module) |
| 1522 | { |
Michael Sartain | a7499c9 | 2013-07-01 19:45:50 +0000 | [diff] [blame] | 1523 | SymbolVendor *sym_vendor = module->GetSymbolVendor (); |
| 1524 | if (sym_vendor) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1525 | { |
Michael Sartain | a7499c9 | 2013-07-01 19:45:50 +0000 | [diff] [blame] | 1526 | Symtab *symtab = sym_vendor->GetSymtab(); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1527 | if (symtab) |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 1528 | symtab->Dump(&strm, interpreter.GetExecutionContext().GetTargetPtr(), sort_order); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1529 | } |
| 1530 | } |
| 1531 | } |
| 1532 | |
| 1533 | static void |
| 1534 | DumpModuleSections (CommandInterpreter &interpreter, Stream &strm, Module *module) |
| 1535 | { |
| 1536 | if (module) |
| 1537 | { |
Greg Clayton | 3046e66 | 2013-07-10 01:23:25 +0000 | [diff] [blame] | 1538 | SectionList *section_list = module->GetSectionList(); |
Michael Sartain | a7499c9 | 2013-07-01 19:45:50 +0000 | [diff] [blame] | 1539 | if (section_list) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1540 | { |
Michael Sartain | a7499c9 | 2013-07-01 19:45:50 +0000 | [diff] [blame] | 1541 | 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 Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1547 | } |
| 1548 | } |
| 1549 | } |
| 1550 | |
| 1551 | static bool |
| 1552 | DumpModuleSymbolVendor (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 Clayton | c4a8a76 | 2012-05-15 18:43:44 +0000 | [diff] [blame] | 1566 | static void |
| 1567 | DumpAddress (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 Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1589 | static bool |
Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 1590 | LookupAddressInModule (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 Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1597 | { |
| 1598 | if (module) |
| 1599 | { |
| 1600 | lldb::addr_t addr = raw_addr - offset; |
| 1601 | Address so_addr; |
| 1602 | SymbolContext sc; |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 1603 | Target *target = interpreter.GetExecutionContext().GetTargetPtr(); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1604 | if (target && !target->GetSectionLoadList().IsEmpty()) |
| 1605 | { |
| 1606 | if (!target->GetSectionLoadList().ResolveLoadAddress (addr, so_addr)) |
| 1607 | return false; |
Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 1608 | else if (so_addr.GetModule().get() != module) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1609 | return false; |
| 1610 | } |
| 1611 | else |
| 1612 | { |
| 1613 | if (!module->ResolveFileAddress (addr, so_addr)) |
| 1614 | return false; |
| 1615 | } |
| 1616 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1617 | ExecutionContextScope *exe_scope = interpreter.GetExecutionContext().GetBestExecutionContextScope(); |
Greg Clayton | c4a8a76 | 2012-05-15 18:43:44 +0000 | [diff] [blame] | 1618 | 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 Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1637 | return true; |
| 1638 | } |
| 1639 | |
| 1640 | return false; |
| 1641 | } |
| 1642 | |
| 1643 | static uint32_t |
Greg Clayton | c4a8a76 | 2012-05-15 18:43:44 +0000 | [diff] [blame] | 1644 | LookupSymbolInModule (CommandInterpreter &interpreter, Stream &strm, Module *module, const char *name, bool name_is_regex, bool verbose) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1645 | { |
| 1646 | if (module) |
| 1647 | { |
| 1648 | SymbolContext sc; |
| 1649 | |
Michael Sartain | a7499c9 | 2013-07-01 19:45:50 +0000 | [diff] [blame] | 1650 | SymbolVendor *sym_vendor = module->GetSymbolVendor (); |
| 1651 | if (sym_vendor) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1652 | { |
Michael Sartain | a7499c9 | 2013-07-01 19:45:50 +0000 | [diff] [blame] | 1653 | Symtab *symtab = sym_vendor->GetSymtab(); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1654 | 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 | } |
| 1671 | |
| 1672 | |
| 1673 | if (num_matches > 0) |
| 1674 | { |
| 1675 | strm.Indent (); |
| 1676 | strm.Printf("%u symbols match %s'%s' in ", num_matches, |
| 1677 | name_is_regex ? "the regular expression " : "", name); |
| 1678 | DumpFullpath (strm, &module->GetFileSpec(), 0); |
| 1679 | strm.PutCString(":\n"); |
| 1680 | strm.IndentMore (); |
Greg Clayton | c4a8a76 | 2012-05-15 18:43:44 +0000 | [diff] [blame] | 1681 | //Symtab::DumpSymbolHeader (&strm); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1682 | for (i=0; i < num_matches; ++i) |
| 1683 | { |
| 1684 | Symbol *symbol = symtab->SymbolAtIndex(match_indexes[i]); |
Greg Clayton | c4a8a76 | 2012-05-15 18:43:44 +0000 | [diff] [blame] | 1685 | DumpAddress (interpreter.GetExecutionContext().GetBestExecutionContextScope(), |
| 1686 | symbol->GetAddress(), |
| 1687 | verbose, |
| 1688 | strm); |
| 1689 | |
| 1690 | // strm.Indent (); |
| 1691 | // symbol->Dump (&strm, interpreter.GetExecutionContext().GetTargetPtr(), i); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1692 | } |
| 1693 | strm.IndentLess (); |
| 1694 | return num_matches; |
| 1695 | } |
| 1696 | } |
| 1697 | } |
| 1698 | } |
| 1699 | return 0; |
| 1700 | } |
| 1701 | |
| 1702 | |
| 1703 | static void |
Greg Clayton | c4a8a76 | 2012-05-15 18:43:44 +0000 | [diff] [blame] | 1704 | DumpSymbolContextList (ExecutionContextScope *exe_scope, Stream &strm, SymbolContextList &sc_list, bool verbose) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1705 | { |
| 1706 | strm.IndentMore (); |
| 1707 | uint32_t i; |
| 1708 | const uint32_t num_matches = sc_list.GetSize(); |
| 1709 | |
| 1710 | for (i=0; i<num_matches; ++i) |
| 1711 | { |
| 1712 | SymbolContext sc; |
| 1713 | if (sc_list.GetContextAtIndex(i, sc)) |
| 1714 | { |
Sean Callanan | f6172c2 | 2012-02-11 00:24:04 +0000 | [diff] [blame] | 1715 | AddressRange range; |
| 1716 | |
| 1717 | sc.GetAddressRange(eSymbolContextEverything, |
| 1718 | 0, |
| 1719 | true, |
| 1720 | range); |
| 1721 | |
Greg Clayton | c4a8a76 | 2012-05-15 18:43:44 +0000 | [diff] [blame] | 1722 | DumpAddress (exe_scope, range.GetBaseAddress(), verbose, strm); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1723 | } |
| 1724 | } |
| 1725 | strm.IndentLess (); |
| 1726 | } |
| 1727 | |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 1728 | static size_t |
Greg Clayton | c4a8a76 | 2012-05-15 18:43:44 +0000 | [diff] [blame] | 1729 | LookupFunctionInModule (CommandInterpreter &interpreter, |
| 1730 | Stream &strm, |
| 1731 | Module *module, |
| 1732 | const char *name, |
| 1733 | bool name_is_regex, |
| 1734 | bool include_inlines, |
| 1735 | bool include_symbols, |
| 1736 | bool verbose) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1737 | { |
| 1738 | if (module && name && name[0]) |
| 1739 | { |
| 1740 | SymbolContextList sc_list; |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1741 | const bool append = true; |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 1742 | size_t num_matches = 0; |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1743 | if (name_is_regex) |
| 1744 | { |
| 1745 | RegularExpression function_name_regex (name); |
| 1746 | num_matches = module->FindFunctions (function_name_regex, |
| 1747 | include_symbols, |
Sean Callanan | 9df05fb | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 1748 | include_inlines, |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1749 | append, |
| 1750 | sc_list); |
| 1751 | } |
| 1752 | else |
| 1753 | { |
| 1754 | ConstString function_name (name); |
Sean Callanan | b6d70eb | 2011-10-12 02:08:07 +0000 | [diff] [blame] | 1755 | num_matches = module->FindFunctions (function_name, |
| 1756 | NULL, |
Greg Clayton | 6ecb232 | 2013-05-18 00:11:21 +0000 | [diff] [blame] | 1757 | eFunctionNameTypeAuto, |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1758 | include_symbols, |
Sean Callanan | 9df05fb | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 1759 | include_inlines, |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1760 | append, |
| 1761 | sc_list); |
| 1762 | } |
| 1763 | |
| 1764 | if (num_matches) |
| 1765 | { |
| 1766 | strm.Indent (); |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 1767 | strm.Printf("%zu match%s found in ", num_matches, num_matches > 1 ? "es" : ""); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1768 | DumpFullpath (strm, &module->GetFileSpec(), 0); |
| 1769 | strm.PutCString(":\n"); |
Greg Clayton | c4a8a76 | 2012-05-15 18:43:44 +0000 | [diff] [blame] | 1770 | DumpSymbolContextList (interpreter.GetExecutionContext().GetBestExecutionContextScope(), strm, sc_list, verbose); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1771 | } |
| 1772 | return num_matches; |
| 1773 | } |
| 1774 | return 0; |
| 1775 | } |
| 1776 | |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 1777 | static size_t |
Greg Clayton | aafa5c9 | 2012-05-15 19:26:12 +0000 | [diff] [blame] | 1778 | LookupTypeInModule (CommandInterpreter &interpreter, |
Greg Clayton | 644247c | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 1779 | Stream &strm, |
| 1780 | Module *module, |
| 1781 | const char *name_cstr, |
| 1782 | bool name_is_regex) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1783 | { |
| 1784 | if (module && name_cstr && name_cstr[0]) |
| 1785 | { |
Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 1786 | TypeList type_list; |
Greg Clayton | 84db910 | 2012-03-26 23:03:23 +0000 | [diff] [blame] | 1787 | const uint32_t max_num_matches = UINT32_MAX; |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 1788 | size_t num_matches = 0; |
Greg Clayton | 84db910 | 2012-03-26 23:03:23 +0000 | [diff] [blame] | 1789 | bool name_is_fully_qualified = false; |
Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 1790 | SymbolContext sc; |
| 1791 | |
| 1792 | ConstString name(name_cstr); |
Greg Clayton | 84db910 | 2012-03-26 23:03:23 +0000 | [diff] [blame] | 1793 | num_matches = module->FindTypes(sc, name, name_is_fully_qualified, max_num_matches, type_list); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1794 | |
Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 1795 | if (num_matches) |
| 1796 | { |
| 1797 | strm.Indent (); |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 1798 | strm.Printf("%zu match%s found in ", num_matches, num_matches > 1 ? "es" : ""); |
Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 1799 | DumpFullpath (strm, &module->GetFileSpec(), 0); |
| 1800 | strm.PutCString(":\n"); |
| 1801 | const uint32_t num_types = type_list.GetSize(); |
| 1802 | for (uint32_t i=0; i<num_types; ++i) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1803 | { |
Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 1804 | TypeSP type_sp (type_list.GetTypeAtIndex(i)); |
| 1805 | if (type_sp) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1806 | { |
Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 1807 | // Resolve the clang type so that any forward references |
| 1808 | // to types that haven't yet been parsed will get parsed. |
| 1809 | type_sp->GetClangFullType (); |
| 1810 | type_sp->GetDescription (&strm, eDescriptionLevelFull, true); |
Greg Clayton | aafa5c9 | 2012-05-15 19:26:12 +0000 | [diff] [blame] | 1811 | // Print all typedef chains |
| 1812 | TypeSP typedef_type_sp (type_sp); |
| 1813 | TypeSP typedefed_type_sp (typedef_type_sp->GetTypedefType()); |
| 1814 | while (typedefed_type_sp) |
| 1815 | { |
| 1816 | strm.EOL(); |
| 1817 | strm.Printf(" typedef '%s': ", typedef_type_sp->GetName().GetCString()); |
| 1818 | typedefed_type_sp->GetClangFullType (); |
| 1819 | typedefed_type_sp->GetDescription (&strm, eDescriptionLevelFull, true); |
| 1820 | typedef_type_sp = typedefed_type_sp; |
| 1821 | typedefed_type_sp = typedef_type_sp->GetTypedefType(); |
| 1822 | } |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1823 | } |
Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 1824 | strm.EOL(); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1825 | } |
Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 1826 | } |
| 1827 | return num_matches; |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1828 | } |
| 1829 | return 0; |
| 1830 | } |
| 1831 | |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 1832 | static size_t |
Sean Callanan | d38b4a9 | 2012-06-06 20:49:55 +0000 | [diff] [blame] | 1833 | LookupTypeHere (CommandInterpreter &interpreter, |
| 1834 | Stream &strm, |
| 1835 | const SymbolContext &sym_ctx, |
| 1836 | const char *name_cstr, |
| 1837 | bool name_is_regex) |
| 1838 | { |
| 1839 | if (!sym_ctx.module_sp) |
| 1840 | return 0; |
| 1841 | |
| 1842 | TypeList type_list; |
| 1843 | const uint32_t max_num_matches = UINT32_MAX; |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 1844 | size_t num_matches = 1; |
Sean Callanan | d38b4a9 | 2012-06-06 20:49:55 +0000 | [diff] [blame] | 1845 | bool name_is_fully_qualified = false; |
| 1846 | |
| 1847 | ConstString name(name_cstr); |
| 1848 | num_matches = sym_ctx.module_sp->FindTypes(sym_ctx, name, name_is_fully_qualified, max_num_matches, type_list); |
| 1849 | |
| 1850 | if (num_matches) |
| 1851 | { |
| 1852 | strm.Indent (); |
| 1853 | strm.PutCString("Best match found in "); |
| 1854 | DumpFullpath (strm, &sym_ctx.module_sp->GetFileSpec(), 0); |
| 1855 | strm.PutCString(":\n"); |
| 1856 | |
| 1857 | TypeSP type_sp (type_list.GetTypeAtIndex(0)); |
| 1858 | if (type_sp) |
| 1859 | { |
| 1860 | // Resolve the clang type so that any forward references |
| 1861 | // to types that haven't yet been parsed will get parsed. |
| 1862 | type_sp->GetClangFullType (); |
| 1863 | type_sp->GetDescription (&strm, eDescriptionLevelFull, true); |
| 1864 | // Print all typedef chains |
| 1865 | TypeSP typedef_type_sp (type_sp); |
| 1866 | TypeSP typedefed_type_sp (typedef_type_sp->GetTypedefType()); |
| 1867 | while (typedefed_type_sp) |
| 1868 | { |
| 1869 | strm.EOL(); |
| 1870 | strm.Printf(" typedef '%s': ", typedef_type_sp->GetName().GetCString()); |
| 1871 | typedefed_type_sp->GetClangFullType (); |
| 1872 | typedefed_type_sp->GetDescription (&strm, eDescriptionLevelFull, true); |
| 1873 | typedef_type_sp = typedefed_type_sp; |
| 1874 | typedefed_type_sp = typedef_type_sp->GetTypedefType(); |
| 1875 | } |
| 1876 | } |
| 1877 | strm.EOL(); |
| 1878 | } |
| 1879 | return num_matches; |
| 1880 | } |
| 1881 | |
| 1882 | static uint32_t |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1883 | LookupFileAndLineInModule (CommandInterpreter &interpreter, |
Sean Callanan | d38b4a9 | 2012-06-06 20:49:55 +0000 | [diff] [blame] | 1884 | Stream &strm, |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1885 | Module *module, |
| 1886 | const FileSpec &file_spec, |
| 1887 | uint32_t line, |
| 1888 | bool check_inlines, |
| 1889 | bool verbose) |
| 1890 | { |
| 1891 | if (module && file_spec) |
| 1892 | { |
| 1893 | SymbolContextList sc_list; |
| 1894 | const uint32_t num_matches = module->ResolveSymbolContextsForFileSpec(file_spec, line, check_inlines, |
| 1895 | eSymbolContextEverything, sc_list); |
| 1896 | if (num_matches > 0) |
| 1897 | { |
| 1898 | strm.Indent (); |
| 1899 | strm.Printf("%u match%s found in ", num_matches, num_matches > 1 ? "es" : ""); |
| 1900 | strm << file_spec; |
| 1901 | if (line > 0) |
| 1902 | strm.Printf (":%u", line); |
| 1903 | strm << " in "; |
| 1904 | DumpFullpath (strm, &module->GetFileSpec(), 0); |
| 1905 | strm.PutCString(":\n"); |
Greg Clayton | c4a8a76 | 2012-05-15 18:43:44 +0000 | [diff] [blame] | 1906 | DumpSymbolContextList (interpreter.GetExecutionContext().GetBestExecutionContextScope(), strm, sc_list, verbose); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1907 | return num_matches; |
| 1908 | } |
| 1909 | } |
| 1910 | return 0; |
| 1911 | |
| 1912 | } |
| 1913 | |
Greg Clayton | 8ee6438 | 2011-11-10 01:18:58 +0000 | [diff] [blame] | 1914 | |
| 1915 | static size_t |
| 1916 | FindModulesByName (Target *target, |
| 1917 | const char *module_name, |
| 1918 | ModuleList &module_list, |
| 1919 | bool check_global_list) |
| 1920 | { |
| 1921 | // Dump specified images (by basename or fullpath) |
| 1922 | FileSpec module_file_spec(module_name, false); |
Greg Clayton | b9a01b3 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 1923 | ModuleSpec module_spec (module_file_spec); |
Greg Clayton | 8ee6438 | 2011-11-10 01:18:58 +0000 | [diff] [blame] | 1924 | |
| 1925 | const size_t initial_size = module_list.GetSize (); |
| 1926 | |
Greg Clayton | f315626 | 2012-07-11 20:46:47 +0000 | [diff] [blame] | 1927 | if (check_global_list) |
Greg Clayton | 8ee6438 | 2011-11-10 01:18:58 +0000 | [diff] [blame] | 1928 | { |
| 1929 | // Check the global list |
Greg Clayton | b26e6be | 2012-01-27 18:08:35 +0000 | [diff] [blame] | 1930 | Mutex::Locker locker(Module::GetAllocationModuleCollectionMutex()); |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 1931 | const size_t num_modules = Module::GetNumberAllocatedModules(); |
Greg Clayton | 8ee6438 | 2011-11-10 01:18:58 +0000 | [diff] [blame] | 1932 | ModuleSP module_sp; |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 1933 | for (size_t image_idx = 0; image_idx<num_modules; ++image_idx) |
Greg Clayton | 8ee6438 | 2011-11-10 01:18:58 +0000 | [diff] [blame] | 1934 | { |
| 1935 | Module *module = Module::GetAllocatedModuleAtIndex(image_idx); |
| 1936 | |
| 1937 | if (module) |
| 1938 | { |
Greg Clayton | b9a01b3 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 1939 | if (module->MatchesModuleSpec (module_spec)) |
Greg Clayton | 8ee6438 | 2011-11-10 01:18:58 +0000 | [diff] [blame] | 1940 | { |
Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 1941 | module_sp = module->shared_from_this(); |
Greg Clayton | 8ee6438 | 2011-11-10 01:18:58 +0000 | [diff] [blame] | 1942 | module_list.AppendIfNeeded(module_sp); |
| 1943 | } |
| 1944 | } |
| 1945 | } |
| 1946 | } |
Greg Clayton | f315626 | 2012-07-11 20:46:47 +0000 | [diff] [blame] | 1947 | else |
| 1948 | { |
| 1949 | if (target) |
| 1950 | { |
| 1951 | const size_t num_matches = target->GetImages().FindModules (module_spec, module_list); |
| 1952 | |
| 1953 | // Not found in our module list for our target, check the main |
| 1954 | // shared module list in case it is a extra file used somewhere |
| 1955 | // else |
| 1956 | if (num_matches == 0) |
| 1957 | { |
| 1958 | module_spec.GetArchitecture() = target->GetArchitecture(); |
| 1959 | ModuleList::FindSharedModules (module_spec, module_list); |
| 1960 | } |
| 1961 | } |
| 1962 | else |
| 1963 | { |
| 1964 | ModuleList::FindSharedModules (module_spec,module_list); |
| 1965 | } |
| 1966 | } |
| 1967 | |
Greg Clayton | 8ee6438 | 2011-11-10 01:18:58 +0000 | [diff] [blame] | 1968 | return module_list.GetSize () - initial_size; |
| 1969 | } |
| 1970 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1971 | #pragma mark CommandObjectTargetModulesModuleAutoComplete |
| 1972 | |
| 1973 | //---------------------------------------------------------------------- |
| 1974 | // A base command object class that can auto complete with module file |
| 1975 | // paths |
| 1976 | //---------------------------------------------------------------------- |
| 1977 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1978 | class CommandObjectTargetModulesModuleAutoComplete : public CommandObjectParsed |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1979 | { |
| 1980 | public: |
| 1981 | |
| 1982 | CommandObjectTargetModulesModuleAutoComplete (CommandInterpreter &interpreter, |
| 1983 | const char *name, |
| 1984 | const char *help, |
| 1985 | const char *syntax) : |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1986 | CommandObjectParsed (interpreter, name, help, syntax) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1987 | { |
| 1988 | CommandArgumentEntry arg; |
| 1989 | CommandArgumentData file_arg; |
| 1990 | |
| 1991 | // Define the first (and only) variant of this arg. |
| 1992 | file_arg.arg_type = eArgTypeFilename; |
| 1993 | file_arg.arg_repetition = eArgRepeatStar; |
| 1994 | |
| 1995 | // There is only one variant this argument could be; put it into the argument entry. |
| 1996 | arg.push_back (file_arg); |
| 1997 | |
| 1998 | // Push the data for the first argument into the m_arguments vector. |
| 1999 | m_arguments.push_back (arg); |
| 2000 | } |
| 2001 | |
| 2002 | virtual |
| 2003 | ~CommandObjectTargetModulesModuleAutoComplete () |
| 2004 | { |
| 2005 | } |
| 2006 | |
| 2007 | virtual int |
| 2008 | HandleArgumentCompletion (Args &input, |
| 2009 | int &cursor_index, |
| 2010 | int &cursor_char_position, |
| 2011 | OptionElementVector &opt_element_vector, |
| 2012 | int match_start_point, |
| 2013 | int max_return_elements, |
| 2014 | bool &word_complete, |
| 2015 | StringList &matches) |
| 2016 | { |
| 2017 | // Arguments are the standard module completer. |
| 2018 | std::string completion_str (input.GetArgumentAtIndex(cursor_index)); |
| 2019 | completion_str.erase (cursor_char_position); |
| 2020 | |
| 2021 | CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter, |
| 2022 | CommandCompletions::eModuleCompletion, |
| 2023 | completion_str.c_str(), |
| 2024 | match_start_point, |
| 2025 | max_return_elements, |
| 2026 | NULL, |
| 2027 | word_complete, |
| 2028 | matches); |
| 2029 | return matches.GetSize(); |
| 2030 | } |
| 2031 | }; |
| 2032 | |
| 2033 | #pragma mark CommandObjectTargetModulesSourceFileAutoComplete |
| 2034 | |
| 2035 | //---------------------------------------------------------------------- |
| 2036 | // A base command object class that can auto complete with module source |
| 2037 | // file paths |
| 2038 | //---------------------------------------------------------------------- |
| 2039 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 2040 | class CommandObjectTargetModulesSourceFileAutoComplete : public CommandObjectParsed |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2041 | { |
| 2042 | public: |
| 2043 | |
| 2044 | CommandObjectTargetModulesSourceFileAutoComplete (CommandInterpreter &interpreter, |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 2045 | const char *name, |
| 2046 | const char *help, |
| 2047 | const char *syntax, |
| 2048 | uint32_t flags) : |
| 2049 | CommandObjectParsed (interpreter, name, help, syntax, flags) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2050 | { |
| 2051 | CommandArgumentEntry arg; |
| 2052 | CommandArgumentData source_file_arg; |
| 2053 | |
| 2054 | // Define the first (and only) variant of this arg. |
| 2055 | source_file_arg.arg_type = eArgTypeSourceFile; |
| 2056 | source_file_arg.arg_repetition = eArgRepeatPlus; |
| 2057 | |
| 2058 | // There is only one variant this argument could be; put it into the argument entry. |
| 2059 | arg.push_back (source_file_arg); |
| 2060 | |
| 2061 | // Push the data for the first argument into the m_arguments vector. |
| 2062 | m_arguments.push_back (arg); |
| 2063 | } |
| 2064 | |
| 2065 | virtual |
| 2066 | ~CommandObjectTargetModulesSourceFileAutoComplete () |
| 2067 | { |
| 2068 | } |
| 2069 | |
| 2070 | virtual int |
| 2071 | HandleArgumentCompletion (Args &input, |
| 2072 | int &cursor_index, |
| 2073 | int &cursor_char_position, |
| 2074 | OptionElementVector &opt_element_vector, |
| 2075 | int match_start_point, |
| 2076 | int max_return_elements, |
| 2077 | bool &word_complete, |
| 2078 | StringList &matches) |
| 2079 | { |
| 2080 | // Arguments are the standard source file completer. |
| 2081 | std::string completion_str (input.GetArgumentAtIndex(cursor_index)); |
| 2082 | completion_str.erase (cursor_char_position); |
| 2083 | |
| 2084 | CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter, |
| 2085 | CommandCompletions::eSourceFileCompletion, |
| 2086 | completion_str.c_str(), |
| 2087 | match_start_point, |
| 2088 | max_return_elements, |
| 2089 | NULL, |
| 2090 | word_complete, |
| 2091 | matches); |
| 2092 | return matches.GetSize(); |
| 2093 | } |
| 2094 | }; |
| 2095 | |
| 2096 | |
| 2097 | #pragma mark CommandObjectTargetModulesDumpSymtab |
| 2098 | |
| 2099 | |
| 2100 | class CommandObjectTargetModulesDumpSymtab : public CommandObjectTargetModulesModuleAutoComplete |
| 2101 | { |
| 2102 | public: |
| 2103 | CommandObjectTargetModulesDumpSymtab (CommandInterpreter &interpreter) : |
| 2104 | CommandObjectTargetModulesModuleAutoComplete (interpreter, |
| 2105 | "target modules dump symtab", |
| 2106 | "Dump the symbol table from one or more target modules.", |
| 2107 | NULL), |
| 2108 | m_options (interpreter) |
| 2109 | { |
| 2110 | } |
| 2111 | |
| 2112 | virtual |
| 2113 | ~CommandObjectTargetModulesDumpSymtab () |
| 2114 | { |
| 2115 | } |
| 2116 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 2117 | virtual Options * |
| 2118 | GetOptions () |
| 2119 | { |
| 2120 | return &m_options; |
| 2121 | } |
| 2122 | |
| 2123 | class CommandOptions : public Options |
| 2124 | { |
| 2125 | public: |
| 2126 | |
| 2127 | CommandOptions (CommandInterpreter &interpreter) : |
| 2128 | Options(interpreter), |
| 2129 | m_sort_order (eSortOrderNone) |
| 2130 | { |
| 2131 | } |
| 2132 | |
| 2133 | virtual |
| 2134 | ~CommandOptions () |
| 2135 | { |
| 2136 | } |
| 2137 | |
| 2138 | virtual Error |
| 2139 | SetOptionValue (uint32_t option_idx, const char *option_arg) |
| 2140 | { |
| 2141 | Error error; |
Greg Clayton | 3bcdfc0 | 2012-12-04 00:32:51 +0000 | [diff] [blame] | 2142 | const int short_option = m_getopt_table[option_idx].val; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 2143 | |
| 2144 | switch (short_option) |
| 2145 | { |
| 2146 | case 's': |
| 2147 | m_sort_order = (SortOrder) Args::StringToOptionEnum (option_arg, |
| 2148 | g_option_table[option_idx].enum_values, |
| 2149 | eSortOrderNone, |
| 2150 | error); |
| 2151 | break; |
| 2152 | |
| 2153 | default: |
| 2154 | error.SetErrorStringWithFormat("invalid short option character '%c'", short_option); |
| 2155 | break; |
| 2156 | |
| 2157 | } |
| 2158 | return error; |
| 2159 | } |
| 2160 | |
| 2161 | void |
| 2162 | OptionParsingStarting () |
| 2163 | { |
| 2164 | m_sort_order = eSortOrderNone; |
| 2165 | } |
| 2166 | |
| 2167 | const OptionDefinition* |
| 2168 | GetDefinitions () |
| 2169 | { |
| 2170 | return g_option_table; |
| 2171 | } |
| 2172 | |
| 2173 | // Options table: Required for subclasses of Options. |
| 2174 | static OptionDefinition g_option_table[]; |
| 2175 | |
| 2176 | SortOrder m_sort_order; |
| 2177 | }; |
| 2178 | |
| 2179 | protected: |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2180 | virtual bool |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 2181 | DoExecute (Args& command, |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2182 | CommandReturnObject &result) |
| 2183 | { |
| 2184 | Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); |
| 2185 | if (target == NULL) |
| 2186 | { |
| 2187 | result.AppendError ("invalid target, create a debug target using the 'target create' command"); |
| 2188 | result.SetStatus (eReturnStatusFailed); |
| 2189 | return false; |
| 2190 | } |
| 2191 | else |
| 2192 | { |
| 2193 | uint32_t num_dumped = 0; |
| 2194 | |
| 2195 | uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize(); |
| 2196 | result.GetOutputStream().SetAddressByteSize(addr_byte_size); |
| 2197 | result.GetErrorStream().SetAddressByteSize(addr_byte_size); |
| 2198 | |
| 2199 | if (command.GetArgumentCount() == 0) |
| 2200 | { |
| 2201 | // Dump all sections for all modules images |
Jim Ingham | 3ee12ef | 2012-05-30 02:19:25 +0000 | [diff] [blame] | 2202 | Mutex::Locker modules_locker(target->GetImages().GetMutex()); |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 2203 | const size_t num_modules = target->GetImages().GetSize(); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2204 | if (num_modules > 0) |
| 2205 | { |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 2206 | result.GetOutputStream().Printf("Dumping symbol table for %zu modules.\n", num_modules); |
| 2207 | for (size_t image_idx = 0; image_idx<num_modules; ++image_idx) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2208 | { |
| 2209 | if (num_dumped > 0) |
| 2210 | { |
| 2211 | result.GetOutputStream().EOL(); |
| 2212 | result.GetOutputStream().EOL(); |
| 2213 | } |
| 2214 | num_dumped++; |
Jim Ingham | 3ee12ef | 2012-05-30 02:19:25 +0000 | [diff] [blame] | 2215 | DumpModuleSymtab (m_interpreter, |
| 2216 | result.GetOutputStream(), |
| 2217 | target->GetImages().GetModulePointerAtIndexUnlocked(image_idx), |
| 2218 | m_options.m_sort_order); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2219 | } |
| 2220 | } |
| 2221 | else |
| 2222 | { |
| 2223 | result.AppendError ("the target has no associated executable images"); |
| 2224 | result.SetStatus (eReturnStatusFailed); |
| 2225 | return false; |
| 2226 | } |
| 2227 | } |
| 2228 | else |
| 2229 | { |
| 2230 | // Dump specified images (by basename or fullpath) |
| 2231 | const char *arg_cstr; |
| 2232 | for (int arg_idx = 0; (arg_cstr = command.GetArgumentAtIndex(arg_idx)) != NULL; ++arg_idx) |
| 2233 | { |
Greg Clayton | 8ee6438 | 2011-11-10 01:18:58 +0000 | [diff] [blame] | 2234 | ModuleList module_list; |
| 2235 | const size_t num_matches = FindModulesByName (target, arg_cstr, module_list, true); |
| 2236 | if (num_matches > 0) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2237 | { |
Greg Clayton | 8ee6438 | 2011-11-10 01:18:58 +0000 | [diff] [blame] | 2238 | for (size_t i=0; i<num_matches; ++i) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2239 | { |
Greg Clayton | 8ee6438 | 2011-11-10 01:18:58 +0000 | [diff] [blame] | 2240 | Module *module = module_list.GetModulePointerAtIndex(i); |
| 2241 | if (module) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2242 | { |
| 2243 | if (num_dumped > 0) |
| 2244 | { |
| 2245 | result.GetOutputStream().EOL(); |
| 2246 | result.GetOutputStream().EOL(); |
| 2247 | } |
| 2248 | num_dumped++; |
Greg Clayton | 8ee6438 | 2011-11-10 01:18:58 +0000 | [diff] [blame] | 2249 | DumpModuleSymtab (m_interpreter, result.GetOutputStream(), module, m_options.m_sort_order); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2250 | } |
| 2251 | } |
| 2252 | } |
| 2253 | else |
| 2254 | result.AppendWarningWithFormat("Unable to find an image that matches '%s'.\n", arg_cstr); |
| 2255 | } |
| 2256 | } |
| 2257 | |
| 2258 | if (num_dumped > 0) |
| 2259 | result.SetStatus (eReturnStatusSuccessFinishResult); |
| 2260 | else |
| 2261 | { |
| 2262 | result.AppendError ("no matching executable images found"); |
| 2263 | result.SetStatus (eReturnStatusFailed); |
| 2264 | } |
| 2265 | } |
| 2266 | return result.Succeeded(); |
| 2267 | } |
| 2268 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2269 | |
| 2270 | CommandOptions m_options; |
| 2271 | }; |
| 2272 | |
| 2273 | static OptionEnumValueElement |
| 2274 | g_sort_option_enumeration[4] = |
| 2275 | { |
| 2276 | { eSortOrderNone, "none", "No sorting, use the original symbol table order."}, |
| 2277 | { eSortOrderByAddress, "address", "Sort output by symbol address."}, |
| 2278 | { eSortOrderByName, "name", "Sort output by symbol name."}, |
| 2279 | { 0, NULL, NULL } |
| 2280 | }; |
| 2281 | |
| 2282 | |
| 2283 | OptionDefinition |
| 2284 | CommandObjectTargetModulesDumpSymtab::CommandOptions::g_option_table[] = |
| 2285 | { |
| 2286 | { LLDB_OPT_SET_1, false, "sort", 's', required_argument, g_sort_option_enumeration, 0, eArgTypeSortOrder, "Supply a sort order when dumping the symbol table."}, |
| 2287 | { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL } |
| 2288 | }; |
| 2289 | |
| 2290 | #pragma mark CommandObjectTargetModulesDumpSections |
| 2291 | |
| 2292 | //---------------------------------------------------------------------- |
| 2293 | // Image section dumping command |
| 2294 | //---------------------------------------------------------------------- |
| 2295 | |
| 2296 | class CommandObjectTargetModulesDumpSections : public CommandObjectTargetModulesModuleAutoComplete |
| 2297 | { |
| 2298 | public: |
| 2299 | CommandObjectTargetModulesDumpSections (CommandInterpreter &interpreter) : |
| 2300 | CommandObjectTargetModulesModuleAutoComplete (interpreter, |
| 2301 | "target modules dump sections", |
| 2302 | "Dump the sections from one or more target modules.", |
| 2303 | //"target modules dump sections [<file1> ...]") |
| 2304 | NULL) |
| 2305 | { |
| 2306 | } |
| 2307 | |
| 2308 | virtual |
| 2309 | ~CommandObjectTargetModulesDumpSections () |
| 2310 | { |
| 2311 | } |
| 2312 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 2313 | protected: |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2314 | virtual bool |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 2315 | DoExecute (Args& command, |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2316 | CommandReturnObject &result) |
| 2317 | { |
| 2318 | Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); |
| 2319 | if (target == NULL) |
| 2320 | { |
| 2321 | result.AppendError ("invalid target, create a debug target using the 'target create' command"); |
| 2322 | result.SetStatus (eReturnStatusFailed); |
| 2323 | return false; |
| 2324 | } |
| 2325 | else |
| 2326 | { |
| 2327 | uint32_t num_dumped = 0; |
| 2328 | |
| 2329 | uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize(); |
| 2330 | result.GetOutputStream().SetAddressByteSize(addr_byte_size); |
| 2331 | result.GetErrorStream().SetAddressByteSize(addr_byte_size); |
| 2332 | |
| 2333 | if (command.GetArgumentCount() == 0) |
| 2334 | { |
| 2335 | // Dump all sections for all modules images |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 2336 | const size_t num_modules = target->GetImages().GetSize(); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2337 | if (num_modules > 0) |
| 2338 | { |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 2339 | result.GetOutputStream().Printf("Dumping sections for %zu modules.\n", num_modules); |
| 2340 | for (size_t image_idx = 0; image_idx<num_modules; ++image_idx) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2341 | { |
| 2342 | num_dumped++; |
| 2343 | DumpModuleSections (m_interpreter, result.GetOutputStream(), target->GetImages().GetModulePointerAtIndex(image_idx)); |
| 2344 | } |
| 2345 | } |
| 2346 | else |
| 2347 | { |
| 2348 | result.AppendError ("the target has no associated executable images"); |
| 2349 | result.SetStatus (eReturnStatusFailed); |
| 2350 | return false; |
| 2351 | } |
| 2352 | } |
| 2353 | else |
| 2354 | { |
| 2355 | // Dump specified images (by basename or fullpath) |
| 2356 | const char *arg_cstr; |
| 2357 | for (int arg_idx = 0; (arg_cstr = command.GetArgumentAtIndex(arg_idx)) != NULL; ++arg_idx) |
| 2358 | { |
Greg Clayton | 8ee6438 | 2011-11-10 01:18:58 +0000 | [diff] [blame] | 2359 | ModuleList module_list; |
| 2360 | const size_t num_matches = FindModulesByName (target, arg_cstr, module_list, true); |
| 2361 | if (num_matches > 0) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2362 | { |
Greg Clayton | 8ee6438 | 2011-11-10 01:18:58 +0000 | [diff] [blame] | 2363 | for (size_t i=0; i<num_matches; ++i) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2364 | { |
Greg Clayton | 8ee6438 | 2011-11-10 01:18:58 +0000 | [diff] [blame] | 2365 | Module *module = module_list.GetModulePointerAtIndex(i); |
| 2366 | if (module) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2367 | { |
| 2368 | num_dumped++; |
Greg Clayton | 8ee6438 | 2011-11-10 01:18:58 +0000 | [diff] [blame] | 2369 | DumpModuleSections (m_interpreter, result.GetOutputStream(), module); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2370 | } |
| 2371 | } |
| 2372 | } |
| 2373 | else |
Greg Clayton | 8ee6438 | 2011-11-10 01:18:58 +0000 | [diff] [blame] | 2374 | { |
| 2375 | // Check the global list |
Greg Clayton | b26e6be | 2012-01-27 18:08:35 +0000 | [diff] [blame] | 2376 | Mutex::Locker locker(Module::GetAllocationModuleCollectionMutex()); |
Greg Clayton | 8ee6438 | 2011-11-10 01:18:58 +0000 | [diff] [blame] | 2377 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2378 | result.AppendWarningWithFormat("Unable to find an image that matches '%s'.\n", arg_cstr); |
Greg Clayton | 8ee6438 | 2011-11-10 01:18:58 +0000 | [diff] [blame] | 2379 | } |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2380 | } |
| 2381 | } |
| 2382 | |
| 2383 | if (num_dumped > 0) |
| 2384 | result.SetStatus (eReturnStatusSuccessFinishResult); |
| 2385 | else |
| 2386 | { |
| 2387 | result.AppendError ("no matching executable images found"); |
| 2388 | result.SetStatus (eReturnStatusFailed); |
| 2389 | } |
| 2390 | } |
| 2391 | return result.Succeeded(); |
| 2392 | } |
| 2393 | }; |
| 2394 | |
| 2395 | |
| 2396 | #pragma mark CommandObjectTargetModulesDumpSymfile |
| 2397 | |
| 2398 | //---------------------------------------------------------------------- |
| 2399 | // Image debug symbol dumping command |
| 2400 | //---------------------------------------------------------------------- |
| 2401 | |
| 2402 | class CommandObjectTargetModulesDumpSymfile : public CommandObjectTargetModulesModuleAutoComplete |
| 2403 | { |
| 2404 | public: |
| 2405 | CommandObjectTargetModulesDumpSymfile (CommandInterpreter &interpreter) : |
| 2406 | CommandObjectTargetModulesModuleAutoComplete (interpreter, |
| 2407 | "target modules dump symfile", |
| 2408 | "Dump the debug symbol file for one or more target modules.", |
| 2409 | //"target modules dump symfile [<file1> ...]") |
| 2410 | NULL) |
| 2411 | { |
| 2412 | } |
| 2413 | |
| 2414 | virtual |
| 2415 | ~CommandObjectTargetModulesDumpSymfile () |
| 2416 | { |
| 2417 | } |
| 2418 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 2419 | protected: |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2420 | virtual bool |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 2421 | DoExecute (Args& command, |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2422 | CommandReturnObject &result) |
| 2423 | { |
| 2424 | Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); |
| 2425 | if (target == NULL) |
| 2426 | { |
| 2427 | result.AppendError ("invalid target, create a debug target using the 'target create' command"); |
| 2428 | result.SetStatus (eReturnStatusFailed); |
| 2429 | return false; |
| 2430 | } |
| 2431 | else |
| 2432 | { |
| 2433 | uint32_t num_dumped = 0; |
| 2434 | |
| 2435 | uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize(); |
| 2436 | result.GetOutputStream().SetAddressByteSize(addr_byte_size); |
| 2437 | result.GetErrorStream().SetAddressByteSize(addr_byte_size); |
| 2438 | |
| 2439 | if (command.GetArgumentCount() == 0) |
| 2440 | { |
| 2441 | // Dump all sections for all modules images |
Enrico Granata | 1759848 | 2012-11-08 02:22:02 +0000 | [diff] [blame] | 2442 | const ModuleList &target_modules = target->GetImages(); |
Jim Ingham | 3ee12ef | 2012-05-30 02:19:25 +0000 | [diff] [blame] | 2443 | Mutex::Locker modules_locker (target_modules.GetMutex()); |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 2444 | const size_t num_modules = target_modules.GetSize(); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2445 | if (num_modules > 0) |
| 2446 | { |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 2447 | result.GetOutputStream().Printf("Dumping debug symbols for %zu modules.\n", num_modules); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2448 | for (uint32_t image_idx = 0; image_idx<num_modules; ++image_idx) |
| 2449 | { |
Jim Ingham | 3ee12ef | 2012-05-30 02:19:25 +0000 | [diff] [blame] | 2450 | if (DumpModuleSymbolVendor (result.GetOutputStream(), target_modules.GetModulePointerAtIndexUnlocked(image_idx))) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2451 | num_dumped++; |
| 2452 | } |
| 2453 | } |
| 2454 | else |
| 2455 | { |
| 2456 | result.AppendError ("the target has no associated executable images"); |
| 2457 | result.SetStatus (eReturnStatusFailed); |
| 2458 | return false; |
| 2459 | } |
| 2460 | } |
| 2461 | else |
| 2462 | { |
| 2463 | // Dump specified images (by basename or fullpath) |
| 2464 | const char *arg_cstr; |
| 2465 | for (int arg_idx = 0; (arg_cstr = command.GetArgumentAtIndex(arg_idx)) != NULL; ++arg_idx) |
| 2466 | { |
Greg Clayton | 8ee6438 | 2011-11-10 01:18:58 +0000 | [diff] [blame] | 2467 | ModuleList module_list; |
| 2468 | const size_t num_matches = FindModulesByName (target, arg_cstr, module_list, true); |
| 2469 | if (num_matches > 0) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2470 | { |
Greg Clayton | 8ee6438 | 2011-11-10 01:18:58 +0000 | [diff] [blame] | 2471 | for (size_t i=0; i<num_matches; ++i) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2472 | { |
Greg Clayton | 8ee6438 | 2011-11-10 01:18:58 +0000 | [diff] [blame] | 2473 | Module *module = module_list.GetModulePointerAtIndex(i); |
| 2474 | if (module) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2475 | { |
Greg Clayton | 8ee6438 | 2011-11-10 01:18:58 +0000 | [diff] [blame] | 2476 | if (DumpModuleSymbolVendor (result.GetOutputStream(), module)) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2477 | num_dumped++; |
| 2478 | } |
| 2479 | } |
| 2480 | } |
| 2481 | else |
| 2482 | result.AppendWarningWithFormat("Unable to find an image that matches '%s'.\n", arg_cstr); |
| 2483 | } |
| 2484 | } |
| 2485 | |
| 2486 | if (num_dumped > 0) |
| 2487 | result.SetStatus (eReturnStatusSuccessFinishResult); |
| 2488 | else |
| 2489 | { |
| 2490 | result.AppendError ("no matching executable images found"); |
| 2491 | result.SetStatus (eReturnStatusFailed); |
| 2492 | } |
| 2493 | } |
| 2494 | return result.Succeeded(); |
| 2495 | } |
| 2496 | }; |
| 2497 | |
| 2498 | |
| 2499 | #pragma mark CommandObjectTargetModulesDumpLineTable |
| 2500 | |
| 2501 | //---------------------------------------------------------------------- |
| 2502 | // Image debug line table dumping command |
| 2503 | //---------------------------------------------------------------------- |
| 2504 | |
| 2505 | class CommandObjectTargetModulesDumpLineTable : public CommandObjectTargetModulesSourceFileAutoComplete |
| 2506 | { |
| 2507 | public: |
| 2508 | CommandObjectTargetModulesDumpLineTable (CommandInterpreter &interpreter) : |
| 2509 | CommandObjectTargetModulesSourceFileAutoComplete (interpreter, |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 2510 | "target modules dump line-table", |
Jim Ingham | cc0273d | 2013-06-18 20:27:11 +0000 | [diff] [blame] | 2511 | "Dump the line table for one or more compilation units.", |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 2512 | NULL, |
| 2513 | eFlagRequiresTarget) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2514 | { |
| 2515 | } |
| 2516 | |
| 2517 | virtual |
| 2518 | ~CommandObjectTargetModulesDumpLineTable () |
| 2519 | { |
| 2520 | } |
| 2521 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 2522 | protected: |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2523 | virtual bool |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 2524 | DoExecute (Args& command, |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2525 | CommandReturnObject &result) |
| 2526 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 2527 | Target *target = m_exe_ctx.GetTargetPtr(); |
| 2528 | uint32_t total_num_dumped = 0; |
| 2529 | |
| 2530 | uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize(); |
| 2531 | result.GetOutputStream().SetAddressByteSize(addr_byte_size); |
| 2532 | result.GetErrorStream().SetAddressByteSize(addr_byte_size); |
| 2533 | |
| 2534 | if (command.GetArgumentCount() == 0) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2535 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 2536 | result.AppendErrorWithFormat ("\nSyntax: %s\n", m_cmd_syntax.c_str()); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2537 | result.SetStatus (eReturnStatusFailed); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2538 | } |
| 2539 | else |
| 2540 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 2541 | // Dump specified images (by basename or fullpath) |
| 2542 | const char *arg_cstr; |
| 2543 | for (int arg_idx = 0; (arg_cstr = command.GetArgumentAtIndex(arg_idx)) != NULL; ++arg_idx) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2544 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 2545 | FileSpec file_spec(arg_cstr, false); |
| 2546 | |
| 2547 | const ModuleList &target_modules = target->GetImages(); |
| 2548 | Mutex::Locker modules_locker(target_modules.GetMutex()); |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 2549 | const size_t num_modules = target_modules.GetSize(); |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 2550 | if (num_modules > 0) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2551 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 2552 | uint32_t num_dumped = 0; |
| 2553 | for (uint32_t i = 0; i<num_modules; ++i) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2554 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 2555 | if (DumpCompileUnitLineTable (m_interpreter, |
| 2556 | result.GetOutputStream(), |
| 2557 | target_modules.GetModulePointerAtIndexUnlocked(i), |
| 2558 | file_spec, |
| 2559 | m_exe_ctx.GetProcessPtr() && m_exe_ctx.GetProcessRef().IsAlive())) |
| 2560 | num_dumped++; |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2561 | } |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 2562 | if (num_dumped == 0) |
| 2563 | result.AppendWarningWithFormat ("No source filenames matched '%s'.\n", arg_cstr); |
| 2564 | else |
| 2565 | total_num_dumped += num_dumped; |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2566 | } |
| 2567 | } |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 2568 | } |
| 2569 | |
| 2570 | if (total_num_dumped > 0) |
| 2571 | result.SetStatus (eReturnStatusSuccessFinishResult); |
| 2572 | else |
| 2573 | { |
| 2574 | result.AppendError ("no source filenames matched any command arguments"); |
| 2575 | result.SetStatus (eReturnStatusFailed); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2576 | } |
| 2577 | return result.Succeeded(); |
| 2578 | } |
| 2579 | }; |
| 2580 | |
| 2581 | |
| 2582 | #pragma mark CommandObjectTargetModulesDump |
| 2583 | |
| 2584 | //---------------------------------------------------------------------- |
| 2585 | // Dump multi-word command for target modules |
| 2586 | //---------------------------------------------------------------------- |
| 2587 | |
| 2588 | class CommandObjectTargetModulesDump : public CommandObjectMultiword |
| 2589 | { |
| 2590 | public: |
| 2591 | |
| 2592 | //------------------------------------------------------------------ |
| 2593 | // Constructors and Destructors |
| 2594 | //------------------------------------------------------------------ |
| 2595 | CommandObjectTargetModulesDump(CommandInterpreter &interpreter) : |
| 2596 | CommandObjectMultiword (interpreter, |
| 2597 | "target modules dump", |
| 2598 | "A set of commands for dumping information about one or more target modules.", |
| 2599 | "target modules dump [symtab|sections|symfile|line-table] [<file1> <file2> ...]") |
| 2600 | { |
| 2601 | LoadSubCommand ("symtab", CommandObjectSP (new CommandObjectTargetModulesDumpSymtab (interpreter))); |
| 2602 | LoadSubCommand ("sections", CommandObjectSP (new CommandObjectTargetModulesDumpSections (interpreter))); |
| 2603 | LoadSubCommand ("symfile", CommandObjectSP (new CommandObjectTargetModulesDumpSymfile (interpreter))); |
| 2604 | LoadSubCommand ("line-table", CommandObjectSP (new CommandObjectTargetModulesDumpLineTable (interpreter))); |
| 2605 | } |
| 2606 | |
| 2607 | virtual |
| 2608 | ~CommandObjectTargetModulesDump() |
| 2609 | { |
| 2610 | } |
| 2611 | }; |
| 2612 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 2613 | class CommandObjectTargetModulesAdd : public CommandObjectParsed |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2614 | { |
| 2615 | public: |
| 2616 | CommandObjectTargetModulesAdd (CommandInterpreter &interpreter) : |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 2617 | CommandObjectParsed (interpreter, |
| 2618 | "target modules add", |
| 2619 | "Add a new module to the current target's modules.", |
Greg Clayton | 50a24bd | 2012-11-29 22:16:27 +0000 | [diff] [blame] | 2620 | "target modules add [<module>]"), |
Greg Clayton | 1c5f186 | 2012-11-30 19:05:35 +0000 | [diff] [blame] | 2621 | m_option_group (interpreter), |
| 2622 | 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 Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2623 | { |
Greg Clayton | 50a24bd | 2012-11-29 22:16:27 +0000 | [diff] [blame] | 2624 | m_option_group.Append (&m_uuid_option_group, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1); |
Greg Clayton | 1c5f186 | 2012-11-30 19:05:35 +0000 | [diff] [blame] | 2625 | m_option_group.Append (&m_symbol_file, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1); |
Greg Clayton | 50a24bd | 2012-11-29 22:16:27 +0000 | [diff] [blame] | 2626 | m_option_group.Finalize(); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2627 | } |
| 2628 | |
| 2629 | virtual |
| 2630 | ~CommandObjectTargetModulesAdd () |
| 2631 | { |
| 2632 | } |
Greg Clayton | 50a24bd | 2012-11-29 22:16:27 +0000 | [diff] [blame] | 2633 | |
| 2634 | virtual Options * |
| 2635 | GetOptions () |
| 2636 | { |
| 2637 | return &m_option_group; |
| 2638 | } |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2639 | |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 2640 | virtual int |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 2641 | HandleArgumentCompletion (Args &input, |
| 2642 | int &cursor_index, |
| 2643 | int &cursor_char_position, |
| 2644 | OptionElementVector &opt_element_vector, |
| 2645 | int match_start_point, |
| 2646 | int max_return_elements, |
| 2647 | bool &word_complete, |
| 2648 | StringList &matches) |
| 2649 | { |
| 2650 | std::string completion_str (input.GetArgumentAtIndex(cursor_index)); |
| 2651 | completion_str.erase (cursor_char_position); |
| 2652 | |
| 2653 | CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter, |
| 2654 | CommandCompletions::eDiskFileCompletion, |
| 2655 | completion_str.c_str(), |
| 2656 | match_start_point, |
| 2657 | max_return_elements, |
| 2658 | NULL, |
| 2659 | word_complete, |
| 2660 | matches); |
| 2661 | return matches.GetSize(); |
| 2662 | } |
| 2663 | |
| 2664 | protected: |
Greg Clayton | 50a24bd | 2012-11-29 22:16:27 +0000 | [diff] [blame] | 2665 | |
| 2666 | OptionGroupOptions m_option_group; |
| 2667 | OptionGroupUUID m_uuid_option_group; |
Greg Clayton | 1c5f186 | 2012-11-30 19:05:35 +0000 | [diff] [blame] | 2668 | OptionGroupFile m_symbol_file; |
Greg Clayton | 50a24bd | 2012-11-29 22:16:27 +0000 | [diff] [blame] | 2669 | |
| 2670 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2671 | virtual bool |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 2672 | DoExecute (Args& args, |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2673 | CommandReturnObject &result) |
| 2674 | { |
| 2675 | Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); |
| 2676 | if (target == NULL) |
| 2677 | { |
| 2678 | result.AppendError ("invalid target, create a debug target using the 'target create' command"); |
| 2679 | result.SetStatus (eReturnStatusFailed); |
| 2680 | return false; |
| 2681 | } |
| 2682 | else |
| 2683 | { |
Sean Callanan | b36c6c0 | 2012-12-13 01:39:39 +0000 | [diff] [blame] | 2684 | bool flush = false; |
| 2685 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2686 | const size_t argc = args.GetArgumentCount(); |
| 2687 | if (argc == 0) |
| 2688 | { |
Greg Clayton | 50a24bd | 2012-11-29 22:16:27 +0000 | [diff] [blame] | 2689 | if (m_uuid_option_group.GetOptionValue ().OptionWasSet()) |
| 2690 | { |
| 2691 | // We are given a UUID only, go locate the file |
| 2692 | ModuleSpec module_spec; |
| 2693 | module_spec.GetUUID() = m_uuid_option_group.GetOptionValue ().GetCurrentValue(); |
Greg Clayton | 1c5f186 | 2012-11-30 19:05:35 +0000 | [diff] [blame] | 2694 | if (m_symbol_file.GetOptionValue().OptionWasSet()) |
| 2695 | module_spec.GetSymbolFileSpec() = m_symbol_file.GetOptionValue().GetCurrentValue(); |
Greg Clayton | 50a24bd | 2012-11-29 22:16:27 +0000 | [diff] [blame] | 2696 | if (Symbols::DownloadObjectAndSymbolFile (module_spec)) |
| 2697 | { |
| 2698 | ModuleSP module_sp (target->GetSharedModule (module_spec)); |
| 2699 | if (module_sp) |
| 2700 | { |
| 2701 | result.SetStatus (eReturnStatusSuccessFinishResult); |
| 2702 | return true; |
| 2703 | } |
| 2704 | else |
| 2705 | { |
Sean Callanan | b36c6c0 | 2012-12-13 01:39:39 +0000 | [diff] [blame] | 2706 | flush = true; |
| 2707 | |
Greg Clayton | 50a24bd | 2012-11-29 22:16:27 +0000 | [diff] [blame] | 2708 | StreamString strm; |
| 2709 | module_spec.GetUUID().Dump (&strm); |
| 2710 | if (module_spec.GetFileSpec()) |
| 2711 | { |
| 2712 | if (module_spec.GetSymbolFileSpec()) |
| 2713 | { |
Greg Clayton | b5ad4ec | 2013-04-29 17:25:54 +0000 | [diff] [blame] | 2714 | result.AppendErrorWithFormat ("Unable to create the executable or symbol file with UUID %s with path %s and symbol file %s", |
Greg Clayton | 50a24bd | 2012-11-29 22:16:27 +0000 | [diff] [blame] | 2715 | strm.GetString().c_str(), |
Greg Clayton | b5ad4ec | 2013-04-29 17:25:54 +0000 | [diff] [blame] | 2716 | module_spec.GetFileSpec().GetPath().c_str(), |
| 2717 | module_spec.GetSymbolFileSpec().GetPath().c_str()); |
Greg Clayton | 50a24bd | 2012-11-29 22:16:27 +0000 | [diff] [blame] | 2718 | } |
| 2719 | else |
| 2720 | { |
Greg Clayton | b5ad4ec | 2013-04-29 17:25:54 +0000 | [diff] [blame] | 2721 | result.AppendErrorWithFormat ("Unable to create the executable or symbol file with UUID %s with path %s", |
Greg Clayton | 50a24bd | 2012-11-29 22:16:27 +0000 | [diff] [blame] | 2722 | strm.GetString().c_str(), |
Greg Clayton | b5ad4ec | 2013-04-29 17:25:54 +0000 | [diff] [blame] | 2723 | module_spec.GetFileSpec().GetPath().c_str()); |
Greg Clayton | 50a24bd | 2012-11-29 22:16:27 +0000 | [diff] [blame] | 2724 | } |
| 2725 | } |
| 2726 | else |
| 2727 | { |
| 2728 | result.AppendErrorWithFormat ("Unable to create the executable or symbol file with UUID %s", |
| 2729 | strm.GetString().c_str()); |
| 2730 | } |
| 2731 | result.SetStatus (eReturnStatusFailed); |
| 2732 | return false; |
| 2733 | } |
| 2734 | } |
| 2735 | else |
| 2736 | { |
| 2737 | StreamString strm; |
| 2738 | module_spec.GetUUID().Dump (&strm); |
| 2739 | result.AppendErrorWithFormat ("Unable to locate the executable or symbol file with UUID %s", strm.GetString().c_str()); |
| 2740 | result.SetStatus (eReturnStatusFailed); |
| 2741 | return false; |
| 2742 | } |
| 2743 | } |
| 2744 | else |
| 2745 | { |
| 2746 | result.AppendError ("one or more executable image paths must be specified"); |
| 2747 | result.SetStatus (eReturnStatusFailed); |
| 2748 | return false; |
| 2749 | } |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2750 | } |
| 2751 | else |
| 2752 | { |
| 2753 | for (size_t i=0; i<argc; ++i) |
| 2754 | { |
| 2755 | const char *path = args.GetArgumentAtIndex(i); |
| 2756 | if (path) |
| 2757 | { |
| 2758 | FileSpec file_spec(path, true); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2759 | if (file_spec.Exists()) |
| 2760 | { |
Greg Clayton | b9a01b3 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 2761 | ModuleSpec module_spec (file_spec); |
Greg Clayton | 50a24bd | 2012-11-29 22:16:27 +0000 | [diff] [blame] | 2762 | if (m_uuid_option_group.GetOptionValue ().OptionWasSet()) |
| 2763 | module_spec.GetUUID() = m_uuid_option_group.GetOptionValue ().GetCurrentValue(); |
Greg Clayton | 1c5f186 | 2012-11-30 19:05:35 +0000 | [diff] [blame] | 2764 | if (m_symbol_file.GetOptionValue().OptionWasSet()) |
| 2765 | module_spec.GetSymbolFileSpec() = m_symbol_file.GetOptionValue().GetCurrentValue(); |
Greg Clayton | 50a24bd | 2012-11-29 22:16:27 +0000 | [diff] [blame] | 2766 | Error error; |
| 2767 | ModuleSP module_sp (target->GetSharedModule (module_spec, &error)); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2768 | if (!module_sp) |
| 2769 | { |
Greg Clayton | 50a24bd | 2012-11-29 22:16:27 +0000 | [diff] [blame] | 2770 | const char *error_cstr = error.AsCString(); |
| 2771 | if (error_cstr) |
| 2772 | result.AppendError (error_cstr); |
| 2773 | else |
| 2774 | result.AppendErrorWithFormat ("unsupported module: %s", path); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2775 | result.SetStatus (eReturnStatusFailed); |
| 2776 | return false; |
| 2777 | } |
Sean Callanan | b36c6c0 | 2012-12-13 01:39:39 +0000 | [diff] [blame] | 2778 | else |
| 2779 | { |
| 2780 | flush = true; |
| 2781 | } |
Jason Molenda | 2f7af6a | 2011-08-02 23:28:55 +0000 | [diff] [blame] | 2782 | result.SetStatus (eReturnStatusSuccessFinishResult); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2783 | } |
| 2784 | else |
| 2785 | { |
| 2786 | char resolved_path[PATH_MAX]; |
| 2787 | result.SetStatus (eReturnStatusFailed); |
| 2788 | if (file_spec.GetPath (resolved_path, sizeof(resolved_path))) |
| 2789 | { |
| 2790 | if (strcmp (resolved_path, path) != 0) |
| 2791 | { |
| 2792 | result.AppendErrorWithFormat ("invalid module path '%s' with resolved path '%s'\n", path, resolved_path); |
| 2793 | break; |
| 2794 | } |
| 2795 | } |
| 2796 | result.AppendErrorWithFormat ("invalid module path '%s'\n", path); |
| 2797 | break; |
| 2798 | } |
| 2799 | } |
| 2800 | } |
| 2801 | } |
Sean Callanan | b36c6c0 | 2012-12-13 01:39:39 +0000 | [diff] [blame] | 2802 | |
| 2803 | if (flush) |
| 2804 | { |
| 2805 | ProcessSP process = target->GetProcessSP(); |
| 2806 | if (process) |
| 2807 | process->Flush(); |
| 2808 | } |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2809 | } |
Sean Callanan | b36c6c0 | 2012-12-13 01:39:39 +0000 | [diff] [blame] | 2810 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2811 | return result.Succeeded(); |
| 2812 | } |
| 2813 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2814 | }; |
| 2815 | |
| 2816 | class CommandObjectTargetModulesLoad : public CommandObjectTargetModulesModuleAutoComplete |
| 2817 | { |
| 2818 | public: |
| 2819 | CommandObjectTargetModulesLoad (CommandInterpreter &interpreter) : |
| 2820 | CommandObjectTargetModulesModuleAutoComplete (interpreter, |
| 2821 | "target modules load", |
| 2822 | "Set the load addresses for one or more sections in a target module.", |
| 2823 | "target modules load [--file <module> --uuid <uuid>] <sect-name> <address> [<sect-name> <address> ....]"), |
| 2824 | m_option_group (interpreter), |
Sean Callanan | 3154255 | 2012-10-24 01:12:14 +0000 | [diff] [blame] | 2825 | m_file_option (LLDB_OPT_SET_1, false, "file", 'f', 0, eArgTypeFilename, "Fullpath or basename for module to load."), |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2826 | 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) |
| 2827 | { |
| 2828 | m_option_group.Append (&m_uuid_option_group, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1); |
| 2829 | m_option_group.Append (&m_file_option, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1); |
| 2830 | m_option_group.Append (&m_slide_option, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1); |
| 2831 | m_option_group.Finalize(); |
| 2832 | } |
| 2833 | |
| 2834 | virtual |
| 2835 | ~CommandObjectTargetModulesLoad () |
| 2836 | { |
| 2837 | } |
| 2838 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 2839 | virtual Options * |
| 2840 | GetOptions () |
| 2841 | { |
| 2842 | return &m_option_group; |
| 2843 | } |
| 2844 | |
| 2845 | protected: |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2846 | virtual bool |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 2847 | DoExecute (Args& args, |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2848 | CommandReturnObject &result) |
| 2849 | { |
| 2850 | Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); |
| 2851 | if (target == NULL) |
| 2852 | { |
| 2853 | result.AppendError ("invalid target, create a debug target using the 'target create' command"); |
| 2854 | result.SetStatus (eReturnStatusFailed); |
| 2855 | return false; |
| 2856 | } |
| 2857 | else |
| 2858 | { |
| 2859 | const size_t argc = args.GetArgumentCount(); |
Greg Clayton | b9a01b3 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 2860 | ModuleSpec module_spec; |
| 2861 | bool search_using_module_spec = false; |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2862 | if (m_file_option.GetOptionValue().OptionWasSet()) |
Greg Clayton | b9a01b3 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 2863 | { |
| 2864 | search_using_module_spec = true; |
| 2865 | module_spec.GetFileSpec() = m_file_option.GetOptionValue().GetCurrentValue(); |
| 2866 | } |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2867 | |
| 2868 | if (m_uuid_option_group.GetOptionValue().OptionWasSet()) |
Greg Clayton | b9a01b3 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 2869 | { |
| 2870 | search_using_module_spec = true; |
| 2871 | module_spec.GetUUID() = m_uuid_option_group.GetOptionValue().GetCurrentValue(); |
| 2872 | } |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2873 | |
Greg Clayton | b9a01b3 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 2874 | if (search_using_module_spec) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2875 | { |
| 2876 | |
| 2877 | ModuleList matching_modules; |
Greg Clayton | b9a01b3 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 2878 | const size_t num_matches = target->GetImages().FindModules (module_spec, matching_modules); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2879 | |
| 2880 | char path[PATH_MAX]; |
| 2881 | if (num_matches == 1) |
| 2882 | { |
| 2883 | Module *module = matching_modules.GetModulePointerAtIndex(0); |
| 2884 | if (module) |
| 2885 | { |
| 2886 | ObjectFile *objfile = module->GetObjectFile(); |
| 2887 | if (objfile) |
| 2888 | { |
Greg Clayton | 3046e66 | 2013-07-10 01:23:25 +0000 | [diff] [blame] | 2889 | SectionList *section_list = module->GetSectionList(); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2890 | if (section_list) |
| 2891 | { |
Greg Clayton | 741f3f9 | 2012-03-27 21:10:07 +0000 | [diff] [blame] | 2892 | bool changed = false; |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2893 | if (argc == 0) |
| 2894 | { |
| 2895 | if (m_slide_option.GetOptionValue().OptionWasSet()) |
| 2896 | { |
Greg Clayton | 741f3f9 | 2012-03-27 21:10:07 +0000 | [diff] [blame] | 2897 | const addr_t slide = m_slide_option.GetOptionValue().GetCurrentValue(); |
| 2898 | module->SetLoadAddress (*target, slide, changed); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2899 | } |
| 2900 | else |
| 2901 | { |
| 2902 | result.AppendError ("one or more section name + load address pair must be specified"); |
| 2903 | result.SetStatus (eReturnStatusFailed); |
| 2904 | return false; |
| 2905 | } |
| 2906 | } |
| 2907 | else |
| 2908 | { |
| 2909 | if (m_slide_option.GetOptionValue().OptionWasSet()) |
| 2910 | { |
| 2911 | result.AppendError ("The \"--slide <offset>\" option can't be used in conjunction with setting section load addresses.\n"); |
| 2912 | result.SetStatus (eReturnStatusFailed); |
| 2913 | return false; |
| 2914 | } |
| 2915 | |
| 2916 | for (size_t i=0; i<argc; i += 2) |
| 2917 | { |
| 2918 | const char *sect_name = args.GetArgumentAtIndex(i); |
| 2919 | const char *load_addr_cstr = args.GetArgumentAtIndex(i+1); |
| 2920 | if (sect_name && load_addr_cstr) |
| 2921 | { |
| 2922 | ConstString const_sect_name(sect_name); |
| 2923 | bool success = false; |
| 2924 | addr_t load_addr = Args::StringToUInt64(load_addr_cstr, LLDB_INVALID_ADDRESS, 0, &success); |
| 2925 | if (success) |
| 2926 | { |
| 2927 | SectionSP section_sp (section_list->FindSectionByName(const_sect_name)); |
| 2928 | if (section_sp) |
| 2929 | { |
Greg Clayton | 741f3f9 | 2012-03-27 21:10:07 +0000 | [diff] [blame] | 2930 | if (section_sp->IsThreadSpecific()) |
| 2931 | { |
| 2932 | result.AppendErrorWithFormat ("thread specific sections are not yet supported (section '%s')\n", sect_name); |
| 2933 | result.SetStatus (eReturnStatusFailed); |
| 2934 | break; |
| 2935 | } |
| 2936 | else |
| 2937 | { |
Greg Clayton | 7820bd1 | 2012-07-07 01:24:12 +0000 | [diff] [blame] | 2938 | if (target->GetSectionLoadList().SetSectionLoadAddress (section_sp, load_addr)) |
Greg Clayton | 741f3f9 | 2012-03-27 21:10:07 +0000 | [diff] [blame] | 2939 | changed = true; |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 2940 | result.AppendMessageWithFormat("section '%s' loaded at 0x%" PRIx64 "\n", sect_name, load_addr); |
Greg Clayton | 741f3f9 | 2012-03-27 21:10:07 +0000 | [diff] [blame] | 2941 | } |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2942 | } |
| 2943 | else |
| 2944 | { |
| 2945 | result.AppendErrorWithFormat ("no section found that matches the section name '%s'\n", sect_name); |
| 2946 | result.SetStatus (eReturnStatusFailed); |
| 2947 | break; |
| 2948 | } |
| 2949 | } |
| 2950 | else |
| 2951 | { |
| 2952 | result.AppendErrorWithFormat ("invalid load address string '%s'\n", load_addr_cstr); |
| 2953 | result.SetStatus (eReturnStatusFailed); |
| 2954 | break; |
| 2955 | } |
| 2956 | } |
| 2957 | else |
| 2958 | { |
| 2959 | if (sect_name) |
| 2960 | result.AppendError ("section names must be followed by a load address.\n"); |
| 2961 | else |
| 2962 | result.AppendError ("one or more section name + load address pair must be specified.\n"); |
| 2963 | result.SetStatus (eReturnStatusFailed); |
| 2964 | break; |
| 2965 | } |
| 2966 | } |
| 2967 | } |
Greg Clayton | 741f3f9 | 2012-03-27 21:10:07 +0000 | [diff] [blame] | 2968 | |
| 2969 | if (changed) |
Greg Clayton | 3c94737 | 2013-01-29 01:17:09 +0000 | [diff] [blame] | 2970 | { |
Greg Clayton | 741f3f9 | 2012-03-27 21:10:07 +0000 | [diff] [blame] | 2971 | target->ModulesDidLoad (matching_modules); |
Greg Clayton | 3c94737 | 2013-01-29 01:17:09 +0000 | [diff] [blame] | 2972 | Process *process = m_exe_ctx.GetProcessPtr(); |
| 2973 | if (process) |
| 2974 | process->Flush(); |
| 2975 | } |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2976 | } |
| 2977 | else |
| 2978 | { |
| 2979 | module->GetFileSpec().GetPath (path, sizeof(path)); |
| 2980 | result.AppendErrorWithFormat ("no sections in object file '%s'\n", path); |
| 2981 | result.SetStatus (eReturnStatusFailed); |
| 2982 | } |
| 2983 | } |
| 2984 | else |
| 2985 | { |
| 2986 | module->GetFileSpec().GetPath (path, sizeof(path)); |
| 2987 | result.AppendErrorWithFormat ("no object file for module '%s'\n", path); |
| 2988 | result.SetStatus (eReturnStatusFailed); |
| 2989 | } |
| 2990 | } |
| 2991 | else |
| 2992 | { |
Jim Ingham | 28eb571 | 2012-10-12 17:34:26 +0000 | [diff] [blame] | 2993 | FileSpec *module_spec_file = module_spec.GetFileSpecPtr(); |
| 2994 | if (module_spec_file) |
| 2995 | { |
| 2996 | module_spec_file->GetPath (path, sizeof(path)); |
| 2997 | result.AppendErrorWithFormat ("invalid module '%s'.\n", path); |
| 2998 | } |
| 2999 | else |
| 3000 | result.AppendError ("no module spec"); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3001 | result.SetStatus (eReturnStatusFailed); |
| 3002 | } |
| 3003 | } |
| 3004 | else |
| 3005 | { |
Jason Molenda | c16b4af | 2013-05-03 23:56:12 +0000 | [diff] [blame] | 3006 | std::string uuid_str; |
Greg Clayton | b9a01b3 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 3007 | |
| 3008 | if (module_spec.GetFileSpec()) |
| 3009 | module_spec.GetFileSpec().GetPath (path, sizeof(path)); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3010 | else |
| 3011 | path[0] = '\0'; |
| 3012 | |
Greg Clayton | b9a01b3 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 3013 | if (module_spec.GetUUIDPtr()) |
Jason Molenda | c16b4af | 2013-05-03 23:56:12 +0000 | [diff] [blame] | 3014 | uuid_str = module_spec.GetUUID().GetAsString(); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3015 | if (num_matches > 1) |
| 3016 | { |
| 3017 | result.AppendErrorWithFormat ("multiple modules match%s%s%s%s:\n", |
| 3018 | path[0] ? " file=" : "", |
| 3019 | path, |
Jason Molenda | c16b4af | 2013-05-03 23:56:12 +0000 | [diff] [blame] | 3020 | !uuid_str.empty() ? " uuid=" : "", |
| 3021 | uuid_str.c_str()); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3022 | for (size_t i=0; i<num_matches; ++i) |
| 3023 | { |
| 3024 | if (matching_modules.GetModulePointerAtIndex(i)->GetFileSpec().GetPath (path, sizeof(path))) |
| 3025 | result.AppendMessageWithFormat("%s\n", path); |
| 3026 | } |
| 3027 | } |
| 3028 | else |
| 3029 | { |
| 3030 | result.AppendErrorWithFormat ("no modules were found that match%s%s%s%s.\n", |
| 3031 | path[0] ? " file=" : "", |
| 3032 | path, |
Jason Molenda | c16b4af | 2013-05-03 23:56:12 +0000 | [diff] [blame] | 3033 | !uuid_str.empty() ? " uuid=" : "", |
| 3034 | uuid_str.c_str()); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3035 | } |
| 3036 | result.SetStatus (eReturnStatusFailed); |
| 3037 | } |
| 3038 | } |
| 3039 | else |
| 3040 | { |
| 3041 | result.AppendError ("either the \"--file <module>\" or the \"--uuid <uuid>\" option must be specified.\n"); |
| 3042 | result.SetStatus (eReturnStatusFailed); |
| 3043 | return false; |
| 3044 | } |
| 3045 | } |
| 3046 | return result.Succeeded(); |
| 3047 | } |
| 3048 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3049 | OptionGroupOptions m_option_group; |
| 3050 | OptionGroupUUID m_uuid_option_group; |
| 3051 | OptionGroupFile m_file_option; |
| 3052 | OptionGroupUInt64 m_slide_option; |
| 3053 | }; |
| 3054 | |
| 3055 | //---------------------------------------------------------------------- |
| 3056 | // List images with associated information |
| 3057 | //---------------------------------------------------------------------- |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 3058 | class CommandObjectTargetModulesList : public CommandObjectParsed |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3059 | { |
| 3060 | public: |
| 3061 | |
| 3062 | class CommandOptions : public Options |
| 3063 | { |
| 3064 | public: |
| 3065 | |
| 3066 | CommandOptions (CommandInterpreter &interpreter) : |
Greg Clayton | 65a0399 | 2011-08-09 00:01:09 +0000 | [diff] [blame] | 3067 | Options(interpreter), |
Jim Ingham | c10312c | 2011-10-24 18:36:33 +0000 | [diff] [blame] | 3068 | m_format_array(), |
Daniel Dunbar | a08823f | 2011-10-31 22:50:49 +0000 | [diff] [blame] | 3069 | m_use_global_module_list (false), |
Jim Ingham | c10312c | 2011-10-24 18:36:33 +0000 | [diff] [blame] | 3070 | m_module_addr (LLDB_INVALID_ADDRESS) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3071 | { |
| 3072 | } |
| 3073 | |
| 3074 | virtual |
| 3075 | ~CommandOptions () |
| 3076 | { |
| 3077 | } |
| 3078 | |
| 3079 | virtual Error |
| 3080 | SetOptionValue (uint32_t option_idx, const char *option_arg) |
| 3081 | { |
Greg Clayton | b9d5df5 | 2012-12-06 22:49:16 +0000 | [diff] [blame] | 3082 | Error error; |
| 3083 | |
Greg Clayton | 3bcdfc0 | 2012-12-04 00:32:51 +0000 | [diff] [blame] | 3084 | const int short_option = m_getopt_table[option_idx].val; |
Greg Clayton | 65a0399 | 2011-08-09 00:01:09 +0000 | [diff] [blame] | 3085 | if (short_option == 'g') |
| 3086 | { |
| 3087 | m_use_global_module_list = true; |
| 3088 | } |
Jim Ingham | c10312c | 2011-10-24 18:36:33 +0000 | [diff] [blame] | 3089 | else if (short_option == 'a') |
| 3090 | { |
Jim Ingham | e7b849e | 2013-03-15 23:09:19 +0000 | [diff] [blame] | 3091 | ExecutionContext exe_ctx (m_interpreter.GetExecutionContext()); |
| 3092 | m_module_addr = Args::StringToAddress(&exe_ctx, option_arg, LLDB_INVALID_ADDRESS, &error); |
Jim Ingham | c10312c | 2011-10-24 18:36:33 +0000 | [diff] [blame] | 3093 | } |
Greg Clayton | 65a0399 | 2011-08-09 00:01:09 +0000 | [diff] [blame] | 3094 | else |
| 3095 | { |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 3096 | unsigned long width = 0; |
Greg Clayton | 65a0399 | 2011-08-09 00:01:09 +0000 | [diff] [blame] | 3097 | if (option_arg) |
| 3098 | width = strtoul (option_arg, NULL, 0); |
| 3099 | m_format_array.push_back(std::make_pair(short_option, width)); |
| 3100 | } |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3101 | return error; |
| 3102 | } |
| 3103 | |
| 3104 | void |
| 3105 | OptionParsingStarting () |
| 3106 | { |
| 3107 | m_format_array.clear(); |
Greg Clayton | 65a0399 | 2011-08-09 00:01:09 +0000 | [diff] [blame] | 3108 | m_use_global_module_list = false; |
Jim Ingham | c10312c | 2011-10-24 18:36:33 +0000 | [diff] [blame] | 3109 | m_module_addr = LLDB_INVALID_ADDRESS; |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3110 | } |
| 3111 | |
| 3112 | const OptionDefinition* |
| 3113 | GetDefinitions () |
| 3114 | { |
| 3115 | return g_option_table; |
| 3116 | } |
| 3117 | |
| 3118 | // Options table: Required for subclasses of Options. |
| 3119 | |
| 3120 | static OptionDefinition g_option_table[]; |
| 3121 | |
| 3122 | // Instance variables to hold the values for command options. |
| 3123 | typedef std::vector< std::pair<char, uint32_t> > FormatWidthCollection; |
| 3124 | FormatWidthCollection m_format_array; |
Greg Clayton | 65a0399 | 2011-08-09 00:01:09 +0000 | [diff] [blame] | 3125 | bool m_use_global_module_list; |
Jim Ingham | c10312c | 2011-10-24 18:36:33 +0000 | [diff] [blame] | 3126 | lldb::addr_t m_module_addr; |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3127 | }; |
| 3128 | |
| 3129 | CommandObjectTargetModulesList (CommandInterpreter &interpreter) : |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 3130 | CommandObjectParsed (interpreter, |
| 3131 | "target modules list", |
| 3132 | "List current executable and dependent shared library images.", |
| 3133 | "target modules list [<cmd-options>]"), |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3134 | m_options (interpreter) |
| 3135 | { |
| 3136 | } |
| 3137 | |
| 3138 | virtual |
| 3139 | ~CommandObjectTargetModulesList () |
| 3140 | { |
| 3141 | } |
| 3142 | |
| 3143 | virtual |
| 3144 | Options * |
| 3145 | GetOptions () |
| 3146 | { |
| 3147 | return &m_options; |
| 3148 | } |
| 3149 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 3150 | protected: |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3151 | virtual bool |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 3152 | DoExecute (Args& command, |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3153 | CommandReturnObject &result) |
| 3154 | { |
| 3155 | Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); |
Greg Clayton | 3418c85 | 2011-08-10 02:10:13 +0000 | [diff] [blame] | 3156 | const bool use_global_module_list = m_options.m_use_global_module_list; |
Greg Clayton | 234076c | 2012-06-27 20:26:19 +0000 | [diff] [blame] | 3157 | // Define a local module list here to ensure it lives longer than any "locker" |
| 3158 | // object which might lock its contents below (through the "module_list_ptr" |
| 3159 | // variable). |
| 3160 | ModuleList module_list; |
Greg Clayton | 3418c85 | 2011-08-10 02:10:13 +0000 | [diff] [blame] | 3161 | if (target == NULL && use_global_module_list == false) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3162 | { |
| 3163 | result.AppendError ("invalid target, create a debug target using the 'target create' command"); |
| 3164 | result.SetStatus (eReturnStatusFailed); |
| 3165 | return false; |
| 3166 | } |
| 3167 | else |
| 3168 | { |
Greg Clayton | 3418c85 | 2011-08-10 02:10:13 +0000 | [diff] [blame] | 3169 | if (target) |
| 3170 | { |
| 3171 | uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize(); |
| 3172 | result.GetOutputStream().SetAddressByteSize(addr_byte_size); |
| 3173 | result.GetErrorStream().SetAddressByteSize(addr_byte_size); |
| 3174 | } |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3175 | // Dump all sections for all modules images |
Jim Ingham | c10312c | 2011-10-24 18:36:33 +0000 | [diff] [blame] | 3176 | Stream &strm = result.GetOutputStream(); |
| 3177 | |
| 3178 | if (m_options.m_module_addr != LLDB_INVALID_ADDRESS) |
| 3179 | { |
| 3180 | if (target) |
| 3181 | { |
| 3182 | Address module_address; |
| 3183 | if (module_address.SetLoadAddress(m_options.m_module_addr, target)) |
| 3184 | { |
Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 3185 | ModuleSP module_sp (module_address.GetModule()); |
| 3186 | if (module_sp) |
Jim Ingham | c10312c | 2011-10-24 18:36:33 +0000 | [diff] [blame] | 3187 | { |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 3188 | PrintModule (target, module_sp.get(), 0, strm); |
Jim Ingham | c10312c | 2011-10-24 18:36:33 +0000 | [diff] [blame] | 3189 | result.SetStatus (eReturnStatusSuccessFinishResult); |
| 3190 | } |
| 3191 | else |
| 3192 | { |
Jim Ingham | 17fafa1 | 2012-12-15 02:40:54 +0000 | [diff] [blame] | 3193 | result.AppendErrorWithFormat ("Couldn't find module matching address: 0x%" PRIx64 ".", m_options.m_module_addr); |
Jim Ingham | c10312c | 2011-10-24 18:36:33 +0000 | [diff] [blame] | 3194 | result.SetStatus (eReturnStatusFailed); |
| 3195 | } |
| 3196 | } |
| 3197 | else |
| 3198 | { |
Jim Ingham | 17fafa1 | 2012-12-15 02:40:54 +0000 | [diff] [blame] | 3199 | result.AppendErrorWithFormat ("Couldn't find module containing address: 0x%" PRIx64 ".", m_options.m_module_addr); |
Jim Ingham | c10312c | 2011-10-24 18:36:33 +0000 | [diff] [blame] | 3200 | result.SetStatus (eReturnStatusFailed); |
| 3201 | } |
| 3202 | } |
| 3203 | else |
| 3204 | { |
| 3205 | result.AppendError ("Can only look up modules by address with a valid target."); |
| 3206 | result.SetStatus (eReturnStatusFailed); |
| 3207 | } |
| 3208 | return result.Succeeded(); |
| 3209 | } |
| 3210 | |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 3211 | size_t num_modules = 0; |
Jim Ingham | 3ee12ef | 2012-05-30 02:19:25 +0000 | [diff] [blame] | 3212 | Mutex::Locker locker; // This locker will be locked on the mutex in module_list_ptr if it is non-NULL. |
| 3213 | // Otherwise it will lock the AllocationModuleCollectionMutex when accessing |
| 3214 | // the global module list directly. |
Enrico Granata | 1759848 | 2012-11-08 02:22:02 +0000 | [diff] [blame] | 3215 | const ModuleList *module_list_ptr = NULL; |
Greg Clayton | c4a8a76 | 2012-05-15 18:43:44 +0000 | [diff] [blame] | 3216 | const size_t argc = command.GetArgumentCount(); |
| 3217 | if (argc == 0) |
Greg Clayton | 65a0399 | 2011-08-09 00:01:09 +0000 | [diff] [blame] | 3218 | { |
Greg Clayton | c4a8a76 | 2012-05-15 18:43:44 +0000 | [diff] [blame] | 3219 | if (use_global_module_list) |
| 3220 | { |
| 3221 | locker.Lock (Module::GetAllocationModuleCollectionMutex()); |
| 3222 | num_modules = Module::GetNumberAllocatedModules(); |
| 3223 | } |
| 3224 | else |
| 3225 | { |
| 3226 | module_list_ptr = &target->GetImages(); |
Greg Clayton | c4a8a76 | 2012-05-15 18:43:44 +0000 | [diff] [blame] | 3227 | } |
Greg Clayton | 65a0399 | 2011-08-09 00:01:09 +0000 | [diff] [blame] | 3228 | } |
| 3229 | else |
Greg Clayton | c4a8a76 | 2012-05-15 18:43:44 +0000 | [diff] [blame] | 3230 | { |
| 3231 | for (size_t i=0; i<argc; ++i) |
| 3232 | { |
| 3233 | // Dump specified images (by basename or fullpath) |
| 3234 | const char *arg_cstr = command.GetArgumentAtIndex(i); |
| 3235 | const size_t num_matches = FindModulesByName (target, arg_cstr, module_list, use_global_module_list); |
| 3236 | if (num_matches == 0) |
| 3237 | { |
| 3238 | if (argc == 1) |
| 3239 | { |
| 3240 | result.AppendErrorWithFormat ("no modules found that match '%s'", arg_cstr); |
| 3241 | result.SetStatus (eReturnStatusFailed); |
| 3242 | return false; |
| 3243 | } |
| 3244 | } |
| 3245 | } |
| 3246 | |
Greg Clayton | c4a8a76 | 2012-05-15 18:43:44 +0000 | [diff] [blame] | 3247 | module_list_ptr = &module_list; |
| 3248 | } |
Jim Ingham | 3ee12ef | 2012-05-30 02:19:25 +0000 | [diff] [blame] | 3249 | |
| 3250 | if (module_list_ptr != NULL) |
| 3251 | { |
| 3252 | locker.Lock(module_list_ptr->GetMutex()); |
| 3253 | num_modules = module_list_ptr->GetSize(); |
| 3254 | } |
Greg Clayton | 65a0399 | 2011-08-09 00:01:09 +0000 | [diff] [blame] | 3255 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3256 | if (num_modules > 0) |
Jim Ingham | c10312c | 2011-10-24 18:36:33 +0000 | [diff] [blame] | 3257 | { |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3258 | for (uint32_t image_idx = 0; image_idx<num_modules; ++image_idx) |
| 3259 | { |
Greg Clayton | 3418c85 | 2011-08-10 02:10:13 +0000 | [diff] [blame] | 3260 | ModuleSP module_sp; |
Greg Clayton | 65a0399 | 2011-08-09 00:01:09 +0000 | [diff] [blame] | 3261 | Module *module; |
Greg Clayton | c4a8a76 | 2012-05-15 18:43:44 +0000 | [diff] [blame] | 3262 | if (module_list_ptr) |
Greg Clayton | 65a0399 | 2011-08-09 00:01:09 +0000 | [diff] [blame] | 3263 | { |
Jim Ingham | 3ee12ef | 2012-05-30 02:19:25 +0000 | [diff] [blame] | 3264 | module_sp = module_list_ptr->GetModuleAtIndexUnlocked(image_idx); |
Greg Clayton | c4a8a76 | 2012-05-15 18:43:44 +0000 | [diff] [blame] | 3265 | module = module_sp.get(); |
Greg Clayton | 65a0399 | 2011-08-09 00:01:09 +0000 | [diff] [blame] | 3266 | } |
| 3267 | else |
| 3268 | { |
Greg Clayton | c4a8a76 | 2012-05-15 18:43:44 +0000 | [diff] [blame] | 3269 | module = Module::GetAllocatedModuleAtIndex(image_idx); |
| 3270 | module_sp = module->shared_from_this(); |
Greg Clayton | 65a0399 | 2011-08-09 00:01:09 +0000 | [diff] [blame] | 3271 | } |
Jim Ingham | c10312c | 2011-10-24 18:36:33 +0000 | [diff] [blame] | 3272 | |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 3273 | const size_t indent = strm.Printf("[%3u] ", image_idx); |
| 3274 | PrintModule (target, module, indent, strm); |
Greg Clayton | 3418c85 | 2011-08-10 02:10:13 +0000 | [diff] [blame] | 3275 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3276 | } |
| 3277 | result.SetStatus (eReturnStatusSuccessFinishResult); |
| 3278 | } |
| 3279 | else |
| 3280 | { |
Greg Clayton | c4a8a76 | 2012-05-15 18:43:44 +0000 | [diff] [blame] | 3281 | if (argc) |
| 3282 | { |
| 3283 | if (use_global_module_list) |
| 3284 | result.AppendError ("the global module list has no matching modules"); |
| 3285 | else |
| 3286 | result.AppendError ("the target has no matching modules"); |
| 3287 | } |
Greg Clayton | 3418c85 | 2011-08-10 02:10:13 +0000 | [diff] [blame] | 3288 | else |
Greg Clayton | c4a8a76 | 2012-05-15 18:43:44 +0000 | [diff] [blame] | 3289 | { |
| 3290 | if (use_global_module_list) |
| 3291 | result.AppendError ("the global module list is empty"); |
| 3292 | else |
| 3293 | result.AppendError ("the target has no associated executable images"); |
| 3294 | } |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3295 | result.SetStatus (eReturnStatusFailed); |
| 3296 | return false; |
| 3297 | } |
| 3298 | } |
| 3299 | return result.Succeeded(); |
| 3300 | } |
Jim Ingham | c10312c | 2011-10-24 18:36:33 +0000 | [diff] [blame] | 3301 | |
| 3302 | void |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 3303 | PrintModule (Target *target, Module *module, int indent, Stream &strm) |
Jim Ingham | c10312c | 2011-10-24 18:36:33 +0000 | [diff] [blame] | 3304 | { |
| 3305 | |
Jim Ingham | 28eb571 | 2012-10-12 17:34:26 +0000 | [diff] [blame] | 3306 | if (module == NULL) |
| 3307 | { |
| 3308 | strm.PutCString("Null module"); |
| 3309 | return; |
| 3310 | } |
| 3311 | |
Jim Ingham | c10312c | 2011-10-24 18:36:33 +0000 | [diff] [blame] | 3312 | bool dump_object_name = false; |
| 3313 | if (m_options.m_format_array.empty()) |
| 3314 | { |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 3315 | m_options.m_format_array.push_back(std::make_pair('u', 0)); |
| 3316 | m_options.m_format_array.push_back(std::make_pair('h', 0)); |
| 3317 | m_options.m_format_array.push_back(std::make_pair('f', 0)); |
| 3318 | m_options.m_format_array.push_back(std::make_pair('S', 0)); |
Jim Ingham | c10312c | 2011-10-24 18:36:33 +0000 | [diff] [blame] | 3319 | } |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 3320 | const size_t num_entries = m_options.m_format_array.size(); |
| 3321 | bool print_space = false; |
| 3322 | for (size_t i=0; i<num_entries; ++i) |
Jim Ingham | c10312c | 2011-10-24 18:36:33 +0000 | [diff] [blame] | 3323 | { |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 3324 | if (print_space) |
| 3325 | strm.PutChar(' '); |
| 3326 | print_space = true; |
| 3327 | const char format_char = m_options.m_format_array[i].first; |
| 3328 | uint32_t width = m_options.m_format_array[i].second; |
| 3329 | switch (format_char) |
Jim Ingham | c10312c | 2011-10-24 18:36:33 +0000 | [diff] [blame] | 3330 | { |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 3331 | case 'A': |
| 3332 | DumpModuleArchitecture (strm, module, false, width); |
| 3333 | break; |
| 3334 | |
| 3335 | case 't': |
| 3336 | DumpModuleArchitecture (strm, module, true, width); |
| 3337 | break; |
| 3338 | |
| 3339 | case 'f': |
| 3340 | DumpFullpath (strm, &module->GetFileSpec(), width); |
| 3341 | dump_object_name = true; |
| 3342 | break; |
| 3343 | |
| 3344 | case 'd': |
| 3345 | DumpDirectory (strm, &module->GetFileSpec(), width); |
| 3346 | break; |
| 3347 | |
| 3348 | case 'b': |
| 3349 | DumpBasename (strm, &module->GetFileSpec(), width); |
| 3350 | dump_object_name = true; |
| 3351 | break; |
| 3352 | |
| 3353 | case 'h': |
| 3354 | case 'o': |
| 3355 | // Image header address |
| 3356 | { |
| 3357 | uint32_t addr_nibble_width = target ? (target->GetArchitecture().GetAddressByteSize() * 2) : 16; |
Jim Ingham | c10312c | 2011-10-24 18:36:33 +0000 | [diff] [blame] | 3358 | |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 3359 | ObjectFile *objfile = module->GetObjectFile (); |
| 3360 | if (objfile) |
Jim Ingham | c10312c | 2011-10-24 18:36:33 +0000 | [diff] [blame] | 3361 | { |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 3362 | Address header_addr(objfile->GetHeaderAddress()); |
| 3363 | if (header_addr.IsValid()) |
Jim Ingham | c10312c | 2011-10-24 18:36:33 +0000 | [diff] [blame] | 3364 | { |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 3365 | if (target && !target->GetSectionLoadList().IsEmpty()) |
Jim Ingham | c10312c | 2011-10-24 18:36:33 +0000 | [diff] [blame] | 3366 | { |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 3367 | lldb::addr_t header_load_addr = header_addr.GetLoadAddress (target); |
| 3368 | if (header_load_addr == LLDB_INVALID_ADDRESS) |
| 3369 | { |
| 3370 | header_addr.Dump (&strm, target, Address::DumpStyleModuleWithFileAddress, Address::DumpStyleFileAddress); |
| 3371 | } |
Jim Ingham | c10312c | 2011-10-24 18:36:33 +0000 | [diff] [blame] | 3372 | else |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 3373 | { |
| 3374 | if (format_char == 'o') |
| 3375 | { |
| 3376 | // Show the offset of slide for the image |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 3377 | strm.Printf ("0x%*.*" PRIx64, addr_nibble_width, addr_nibble_width, header_load_addr - header_addr.GetFileAddress()); |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 3378 | } |
| 3379 | else |
| 3380 | { |
| 3381 | // Show the load address of the image |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 3382 | strm.Printf ("0x%*.*" PRIx64, addr_nibble_width, addr_nibble_width, header_load_addr); |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 3383 | } |
| 3384 | } |
Jim Ingham | c10312c | 2011-10-24 18:36:33 +0000 | [diff] [blame] | 3385 | break; |
| 3386 | } |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 3387 | // The address was valid, but the image isn't loaded, output the address in an appropriate format |
| 3388 | header_addr.Dump (&strm, target, Address::DumpStyleFileAddress); |
| 3389 | break; |
Jim Ingham | c10312c | 2011-10-24 18:36:33 +0000 | [diff] [blame] | 3390 | } |
Jim Ingham | c10312c | 2011-10-24 18:36:33 +0000 | [diff] [blame] | 3391 | } |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 3392 | strm.Printf ("%*s", addr_nibble_width + 2, ""); |
| 3393 | } |
| 3394 | break; |
| 3395 | case 'r': |
| 3396 | { |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 3397 | size_t ref_count = 0; |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 3398 | ModuleSP module_sp (module->shared_from_this()); |
| 3399 | if (module_sp) |
| 3400 | { |
| 3401 | // Take one away to make sure we don't count our local "module_sp" |
| 3402 | ref_count = module_sp.use_count() - 1; |
| 3403 | } |
| 3404 | if (width) |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 3405 | strm.Printf("{%*zu}", width, ref_count); |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 3406 | else |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 3407 | strm.Printf("{%zu}", ref_count); |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 3408 | } |
| 3409 | break; |
Jim Ingham | c10312c | 2011-10-24 18:36:33 +0000 | [diff] [blame] | 3410 | |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 3411 | case 's': |
| 3412 | case 'S': |
| 3413 | { |
| 3414 | SymbolVendor *symbol_vendor = module->GetSymbolVendor(); |
| 3415 | if (symbol_vendor) |
| 3416 | { |
| 3417 | SymbolFile *symbol_file = symbol_vendor->GetSymbolFile(); |
| 3418 | if (symbol_file) |
| 3419 | { |
| 3420 | if (format_char == 'S') |
| 3421 | { |
| 3422 | FileSpec &symfile_spec = symbol_file->GetObjectFile()->GetFileSpec(); |
| 3423 | // Dump symbol file only if different from module file |
| 3424 | if (!symfile_spec || symfile_spec == module->GetFileSpec()) |
| 3425 | { |
| 3426 | print_space = false; |
| 3427 | break; |
| 3428 | } |
| 3429 | // Add a newline and indent past the index |
| 3430 | strm.Printf ("\n%*s", indent, ""); |
| 3431 | } |
| 3432 | DumpFullpath (strm, &symbol_file->GetObjectFile()->GetFileSpec(), width); |
| 3433 | dump_object_name = true; |
| 3434 | break; |
| 3435 | } |
| 3436 | } |
| 3437 | strm.Printf("%.*s", width, "<NONE>"); |
| 3438 | } |
| 3439 | break; |
| 3440 | |
| 3441 | case 'm': |
| 3442 | module->GetModificationTime().Dump(&strm, width); |
| 3443 | break; |
Jim Ingham | c10312c | 2011-10-24 18:36:33 +0000 | [diff] [blame] | 3444 | |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 3445 | case 'p': |
| 3446 | strm.Printf("%p", module); |
| 3447 | break; |
| 3448 | |
| 3449 | case 'u': |
| 3450 | DumpModuleUUID(strm, module); |
| 3451 | break; |
| 3452 | |
| 3453 | default: |
| 3454 | break; |
Jim Ingham | c10312c | 2011-10-24 18:36:33 +0000 | [diff] [blame] | 3455 | } |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 3456 | |
| 3457 | } |
| 3458 | if (dump_object_name) |
| 3459 | { |
| 3460 | const char *object_name = module->GetObjectName().GetCString(); |
| 3461 | if (object_name) |
| 3462 | strm.Printf ("(%s)", object_name); |
Jim Ingham | c10312c | 2011-10-24 18:36:33 +0000 | [diff] [blame] | 3463 | } |
| 3464 | strm.EOL(); |
| 3465 | } |
| 3466 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3467 | CommandOptions m_options; |
| 3468 | }; |
| 3469 | |
| 3470 | OptionDefinition |
| 3471 | CommandObjectTargetModulesList::CommandOptions::g_option_table[] = |
| 3472 | { |
Enrico Granata | b84a9db | 2013-01-29 01:48:30 +0000 | [diff] [blame] | 3473 | { LLDB_OPT_SET_1, false, "address", 'a', required_argument, NULL, 0, eArgTypeAddressOrExpression, "Display the image at this address."}, |
Jim Ingham | c10312c | 2011-10-24 18:36:33 +0000 | [diff] [blame] | 3474 | { LLDB_OPT_SET_1, false, "arch", 'A', optional_argument, NULL, 0, eArgTypeWidth, "Display the architecture when listing images."}, |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3475 | { LLDB_OPT_SET_1, false, "triple", 't', optional_argument, NULL, 0, eArgTypeWidth, "Display the triple when listing images."}, |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 3476 | { LLDB_OPT_SET_1, false, "header", 'h', no_argument, NULL, 0, eArgTypeNone, "Display the image header address as a load address if debugging, a file address otherwise."}, |
| 3477 | { LLDB_OPT_SET_1, false, "offset", 'o', no_argument, NULL, 0, eArgTypeNone, "Display the image header address offset from the header file address (the slide amount)."}, |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3478 | { LLDB_OPT_SET_1, false, "uuid", 'u', no_argument, NULL, 0, eArgTypeNone, "Display the UUID when listing images."}, |
| 3479 | { LLDB_OPT_SET_1, false, "fullpath", 'f', optional_argument, NULL, 0, eArgTypeWidth, "Display the fullpath to the image object file."}, |
| 3480 | { LLDB_OPT_SET_1, false, "directory", 'd', optional_argument, NULL, 0, eArgTypeWidth, "Display the directory with optional width for the image object file."}, |
| 3481 | { LLDB_OPT_SET_1, false, "basename", 'b', optional_argument, NULL, 0, eArgTypeWidth, "Display the basename with optional width for the image object file."}, |
| 3482 | { LLDB_OPT_SET_1, false, "symfile", 's', optional_argument, NULL, 0, eArgTypeWidth, "Display the fullpath to the image symbol file with optional width."}, |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 3483 | { LLDB_OPT_SET_1, false, "symfile-unique", 'S', optional_argument, NULL, 0, eArgTypeWidth, "Display the symbol file with optional width only if it is different from the executable object file."}, |
Greg Clayton | 3418c85 | 2011-08-10 02:10:13 +0000 | [diff] [blame] | 3484 | { LLDB_OPT_SET_1, false, "mod-time", 'm', optional_argument, NULL, 0, eArgTypeWidth, "Display the modification time with optional width of the module."}, |
| 3485 | { LLDB_OPT_SET_1, false, "ref-count", 'r', optional_argument, NULL, 0, eArgTypeWidth, "Display the reference count if the module is still in the shared module cache."}, |
| 3486 | { LLDB_OPT_SET_1, false, "pointer", 'p', optional_argument, NULL, 0, eArgTypeNone, "Display the module pointer."}, |
Greg Clayton | 65a0399 | 2011-08-09 00:01:09 +0000 | [diff] [blame] | 3487 | { LLDB_OPT_SET_1, false, "global", 'g', no_argument, NULL, 0, eArgTypeNone, "Display the modules from the global module list, not just the current target."}, |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3488 | { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL } |
| 3489 | }; |
| 3490 | |
Jason Molenda | 380241a | 2012-07-12 00:20:07 +0000 | [diff] [blame] | 3491 | #pragma mark CommandObjectTargetModulesShowUnwind |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3492 | |
Jason Molenda | 380241a | 2012-07-12 00:20:07 +0000 | [diff] [blame] | 3493 | //---------------------------------------------------------------------- |
| 3494 | // Lookup unwind information in images |
| 3495 | //---------------------------------------------------------------------- |
| 3496 | |
| 3497 | class CommandObjectTargetModulesShowUnwind : public CommandObjectParsed |
| 3498 | { |
| 3499 | public: |
| 3500 | |
| 3501 | enum |
| 3502 | { |
| 3503 | eLookupTypeInvalid = -1, |
| 3504 | eLookupTypeAddress = 0, |
| 3505 | eLookupTypeSymbol, |
| 3506 | eLookupTypeFunction, |
| 3507 | eLookupTypeFunctionOrSymbol, |
| 3508 | kNumLookupTypes |
| 3509 | }; |
| 3510 | |
| 3511 | class CommandOptions : public Options |
| 3512 | { |
| 3513 | public: |
| 3514 | |
| 3515 | CommandOptions (CommandInterpreter &interpreter) : |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 3516 | Options(interpreter), |
| 3517 | m_type(eLookupTypeInvalid), |
| 3518 | m_str(), |
| 3519 | m_addr(LLDB_INVALID_ADDRESS) |
Jason Molenda | 380241a | 2012-07-12 00:20:07 +0000 | [diff] [blame] | 3520 | { |
| 3521 | } |
| 3522 | |
| 3523 | virtual |
| 3524 | ~CommandOptions () |
| 3525 | { |
| 3526 | } |
| 3527 | |
| 3528 | virtual Error |
| 3529 | SetOptionValue (uint32_t option_idx, const char *option_arg) |
| 3530 | { |
| 3531 | Error error; |
| 3532 | |
Greg Clayton | 3bcdfc0 | 2012-12-04 00:32:51 +0000 | [diff] [blame] | 3533 | const int short_option = m_getopt_table[option_idx].val; |
Jason Molenda | 380241a | 2012-07-12 00:20:07 +0000 | [diff] [blame] | 3534 | |
| 3535 | switch (short_option) |
| 3536 | { |
| 3537 | case 'a': |
Jason Molenda | 535ab86 | 2013-04-23 04:30:57 +0000 | [diff] [blame] | 3538 | { |
| 3539 | ExecutionContext exe_ctx (m_interpreter.GetExecutionContext()); |
Michael Sartain | b1e1592 | 2013-08-22 20:42:30 +0000 | [diff] [blame] | 3540 | m_str = option_arg; |
Jason Molenda | 380241a | 2012-07-12 00:20:07 +0000 | [diff] [blame] | 3541 | m_type = eLookupTypeAddress; |
Jason Molenda | 535ab86 | 2013-04-23 04:30:57 +0000 | [diff] [blame] | 3542 | m_addr = Args::StringToAddress(&exe_ctx, option_arg, LLDB_INVALID_ADDRESS, &error); |
Jason Molenda | 380241a | 2012-07-12 00:20:07 +0000 | [diff] [blame] | 3543 | if (m_addr == LLDB_INVALID_ADDRESS) |
| 3544 | error.SetErrorStringWithFormat ("invalid address string '%s'", option_arg); |
| 3545 | break; |
Jason Molenda | 535ab86 | 2013-04-23 04:30:57 +0000 | [diff] [blame] | 3546 | } |
Jason Molenda | 380241a | 2012-07-12 00:20:07 +0000 | [diff] [blame] | 3547 | |
| 3548 | case 'n': |
Jason Molenda | 535ab86 | 2013-04-23 04:30:57 +0000 | [diff] [blame] | 3549 | { |
Jason Molenda | 380241a | 2012-07-12 00:20:07 +0000 | [diff] [blame] | 3550 | m_str = option_arg; |
| 3551 | m_type = eLookupTypeFunctionOrSymbol; |
| 3552 | break; |
Jason Molenda | 535ab86 | 2013-04-23 04:30:57 +0000 | [diff] [blame] | 3553 | } |
Michael Sartain | b1e1592 | 2013-08-22 20:42:30 +0000 | [diff] [blame] | 3554 | |
| 3555 | default: |
| 3556 | error.SetErrorStringWithFormat ("unrecognized option %c.", short_option); |
| 3557 | break; |
Jason Molenda | 380241a | 2012-07-12 00:20:07 +0000 | [diff] [blame] | 3558 | } |
| 3559 | |
| 3560 | return error; |
| 3561 | } |
| 3562 | |
| 3563 | void |
| 3564 | OptionParsingStarting () |
| 3565 | { |
| 3566 | m_type = eLookupTypeInvalid; |
| 3567 | m_str.clear(); |
| 3568 | m_addr = LLDB_INVALID_ADDRESS; |
| 3569 | } |
| 3570 | |
| 3571 | const OptionDefinition* |
| 3572 | GetDefinitions () |
| 3573 | { |
| 3574 | return g_option_table; |
| 3575 | } |
| 3576 | |
| 3577 | // Options table: Required for subclasses of Options. |
| 3578 | |
| 3579 | static OptionDefinition g_option_table[]; |
| 3580 | |
| 3581 | // Instance variables to hold the values for command options. |
| 3582 | |
| 3583 | int m_type; // Should be a eLookupTypeXXX enum after parsing options |
| 3584 | std::string m_str; // Holds name lookup |
| 3585 | lldb::addr_t m_addr; // Holds the address to lookup |
| 3586 | }; |
| 3587 | |
| 3588 | CommandObjectTargetModulesShowUnwind (CommandInterpreter &interpreter) : |
| 3589 | CommandObjectParsed (interpreter, |
| 3590 | "target modules show-unwind", |
| 3591 | "Show synthesized unwind instructions for a function.", |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 3592 | NULL, |
| 3593 | eFlagRequiresTarget | |
| 3594 | eFlagRequiresProcess | |
| 3595 | eFlagProcessMustBeLaunched | |
| 3596 | eFlagProcessMustBePaused ), |
Jason Molenda | 380241a | 2012-07-12 00:20:07 +0000 | [diff] [blame] | 3597 | m_options (interpreter) |
| 3598 | { |
| 3599 | } |
| 3600 | |
| 3601 | virtual |
| 3602 | ~CommandObjectTargetModulesShowUnwind () |
| 3603 | { |
| 3604 | } |
| 3605 | |
| 3606 | virtual |
| 3607 | Options * |
| 3608 | GetOptions () |
| 3609 | { |
| 3610 | return &m_options; |
| 3611 | } |
| 3612 | |
| 3613 | protected: |
| 3614 | bool |
| 3615 | DoExecute (Args& command, |
| 3616 | CommandReturnObject &result) |
| 3617 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 3618 | Target *target = m_exe_ctx.GetTargetPtr(); |
| 3619 | Process *process = m_exe_ctx.GetProcessPtr(); |
Jason Molenda | 380241a | 2012-07-12 00:20:07 +0000 | [diff] [blame] | 3620 | ABI *abi = NULL; |
| 3621 | if (process) |
| 3622 | abi = process->GetABI().get(); |
| 3623 | |
| 3624 | if (process == NULL) |
| 3625 | { |
| 3626 | result.AppendError ("You must have a process running to use this command."); |
| 3627 | result.SetStatus (eReturnStatusFailed); |
| 3628 | return false; |
| 3629 | } |
| 3630 | |
| 3631 | ThreadList threads(process->GetThreadList()); |
| 3632 | if (threads.GetSize() == 0) |
| 3633 | { |
| 3634 | result.AppendError ("The process must be paused to use this command."); |
| 3635 | result.SetStatus (eReturnStatusFailed); |
| 3636 | return false; |
| 3637 | } |
| 3638 | |
| 3639 | ThreadSP thread(threads.GetThreadAtIndex(0)); |
| 3640 | if (thread.get() == NULL) |
| 3641 | { |
| 3642 | result.AppendError ("The process must be paused to use this command."); |
| 3643 | result.SetStatus (eReturnStatusFailed); |
| 3644 | return false; |
| 3645 | } |
| 3646 | |
Jason Molenda | 535ab86 | 2013-04-23 04:30:57 +0000 | [diff] [blame] | 3647 | SymbolContextList sc_list; |
| 3648 | |
Jason Molenda | 380241a | 2012-07-12 00:20:07 +0000 | [diff] [blame] | 3649 | if (m_options.m_type == eLookupTypeFunctionOrSymbol) |
| 3650 | { |
Jason Molenda | 380241a | 2012-07-12 00:20:07 +0000 | [diff] [blame] | 3651 | ConstString function_name (m_options.m_str.c_str()); |
Jason Molenda | 535ab86 | 2013-04-23 04:30:57 +0000 | [diff] [blame] | 3652 | target->GetImages().FindFunctions (function_name, eFunctionNameTypeAuto, true, false, true, sc_list); |
| 3653 | } |
| 3654 | else if (m_options.m_type == eLookupTypeAddress && target) |
| 3655 | { |
| 3656 | Address addr; |
| 3657 | if (target->GetSectionLoadList().ResolveLoadAddress (m_options.m_addr, addr)) |
Jason Molenda | 380241a | 2012-07-12 00:20:07 +0000 | [diff] [blame] | 3658 | { |
| 3659 | SymbolContext sc; |
Jason Molenda | 535ab86 | 2013-04-23 04:30:57 +0000 | [diff] [blame] | 3660 | ModuleSP module_sp (addr.GetModule()); |
| 3661 | module_sp->ResolveSymbolContextForAddress (addr, eSymbolContextEverything, sc); |
| 3662 | if (sc.function || sc.symbol) |
Jason Molenda | 380241a | 2012-07-12 00:20:07 +0000 | [diff] [blame] | 3663 | { |
Jason Molenda | 535ab86 | 2013-04-23 04:30:57 +0000 | [diff] [blame] | 3664 | sc_list.Append(sc); |
Jason Molenda | 380241a | 2012-07-12 00:20:07 +0000 | [diff] [blame] | 3665 | } |
Jason Molenda | 535ab86 | 2013-04-23 04:30:57 +0000 | [diff] [blame] | 3666 | } |
| 3667 | } |
Michael Sartain | b1e1592 | 2013-08-22 20:42:30 +0000 | [diff] [blame] | 3668 | else |
| 3669 | { |
| 3670 | result.AppendError ("address-expression or function name option must be specified."); |
| 3671 | result.SetStatus (eReturnStatusFailed); |
| 3672 | return false; |
| 3673 | } |
Jason Molenda | 380241a | 2012-07-12 00:20:07 +0000 | [diff] [blame] | 3674 | |
Jason Molenda | 535ab86 | 2013-04-23 04:30:57 +0000 | [diff] [blame] | 3675 | size_t num_matches = sc_list.GetSize(); |
Michael Sartain | b1e1592 | 2013-08-22 20:42:30 +0000 | [diff] [blame] | 3676 | if (num_matches == 0) |
| 3677 | { |
| 3678 | result.AppendErrorWithFormat ("no unwind data found that matches '%s'.", m_options.m_str.c_str()); |
| 3679 | result.SetStatus (eReturnStatusFailed); |
| 3680 | return false; |
| 3681 | } |
| 3682 | |
Jason Molenda | 535ab86 | 2013-04-23 04:30:57 +0000 | [diff] [blame] | 3683 | for (uint32_t idx = 0; idx < num_matches; idx++) |
| 3684 | { |
| 3685 | SymbolContext sc; |
| 3686 | sc_list.GetContextAtIndex(idx, sc); |
| 3687 | if (sc.symbol == NULL && sc.function == NULL) |
| 3688 | continue; |
| 3689 | if (sc.module_sp.get() == NULL || sc.module_sp->GetObjectFile() == NULL) |
| 3690 | continue; |
| 3691 | AddressRange range; |
| 3692 | if (!sc.GetAddressRange (eSymbolContextFunction | eSymbolContextSymbol, 0, false, range)) |
| 3693 | continue; |
| 3694 | if (!range.GetBaseAddress().IsValid()) |
| 3695 | continue; |
| 3696 | ConstString funcname(sc.GetFunctionName()); |
| 3697 | if (funcname.IsEmpty()) |
| 3698 | continue; |
| 3699 | addr_t start_addr = range.GetBaseAddress().GetLoadAddress(target); |
| 3700 | if (abi) |
| 3701 | start_addr = abi->FixCodeAddress(start_addr); |
Jason Molenda | 380241a | 2012-07-12 00:20:07 +0000 | [diff] [blame] | 3702 | |
Jason Molenda | 535ab86 | 2013-04-23 04:30:57 +0000 | [diff] [blame] | 3703 | FuncUnwindersSP func_unwinders_sp (sc.module_sp->GetObjectFile()->GetUnwindTable().GetUncachedFuncUnwindersContainingAddress(start_addr, sc)); |
| 3704 | if (func_unwinders_sp.get() == NULL) |
| 3705 | continue; |
Jason Molenda | 380241a | 2012-07-12 00:20:07 +0000 | [diff] [blame] | 3706 | |
Jason Molenda | 535ab86 | 2013-04-23 04:30:57 +0000 | [diff] [blame] | 3707 | Address first_non_prologue_insn (func_unwinders_sp->GetFirstNonPrologueInsn(*target)); |
| 3708 | if (first_non_prologue_insn.IsValid()) |
| 3709 | { |
| 3710 | result.GetOutputStream().Printf("First non-prologue instruction is at address 0x%" PRIx64 " or offset %" PRId64 " into the function.\n", first_non_prologue_insn.GetLoadAddress(target), first_non_prologue_insn.GetLoadAddress(target) - start_addr); |
Jason Molenda | 380241a | 2012-07-12 00:20:07 +0000 | [diff] [blame] | 3711 | result.GetOutputStream().Printf ("\n"); |
| 3712 | } |
Jason Molenda | 535ab86 | 2013-04-23 04:30:57 +0000 | [diff] [blame] | 3713 | |
| 3714 | UnwindPlanSP non_callsite_unwind_plan = func_unwinders_sp->GetUnwindPlanAtNonCallSite(*thread.get()); |
| 3715 | if (non_callsite_unwind_plan.get()) |
| 3716 | { |
| 3717 | result.GetOutputStream().Printf("Asynchronous (not restricted to call-sites) UnwindPlan for %s`%s (start addr 0x%" PRIx64 "):\n", sc.module_sp->GetPlatformFileSpec().GetFilename().AsCString(), funcname.AsCString(), start_addr); |
| 3718 | non_callsite_unwind_plan->Dump(result.GetOutputStream(), thread.get(), LLDB_INVALID_ADDRESS); |
| 3719 | result.GetOutputStream().Printf ("\n"); |
| 3720 | } |
| 3721 | |
| 3722 | UnwindPlanSP callsite_unwind_plan = func_unwinders_sp->GetUnwindPlanAtCallSite(-1); |
| 3723 | if (callsite_unwind_plan.get()) |
| 3724 | { |
| 3725 | result.GetOutputStream().Printf("Synchronous (restricted to call-sites) UnwindPlan for %s`%s (start addr 0x%" PRIx64 "):\n", sc.module_sp->GetPlatformFileSpec().GetFilename().AsCString(), funcname.AsCString(), start_addr); |
| 3726 | callsite_unwind_plan->Dump(result.GetOutputStream(), thread.get(), LLDB_INVALID_ADDRESS); |
| 3727 | result.GetOutputStream().Printf ("\n"); |
| 3728 | } |
| 3729 | |
| 3730 | UnwindPlanSP arch_default_unwind_plan = func_unwinders_sp->GetUnwindPlanArchitectureDefault(*thread.get()); |
| 3731 | if (arch_default_unwind_plan.get()) |
| 3732 | { |
| 3733 | result.GetOutputStream().Printf("Architecture default UnwindPlan for %s`%s (start addr 0x%" PRIx64 "):\n", sc.module_sp->GetPlatformFileSpec().GetFilename().AsCString(), funcname.AsCString(), start_addr); |
| 3734 | arch_default_unwind_plan->Dump(result.GetOutputStream(), thread.get(), LLDB_INVALID_ADDRESS); |
| 3735 | result.GetOutputStream().Printf ("\n"); |
| 3736 | } |
| 3737 | |
| 3738 | UnwindPlanSP fast_unwind_plan = func_unwinders_sp->GetUnwindPlanFastUnwind(*thread.get()); |
| 3739 | if (fast_unwind_plan.get()) |
| 3740 | { |
| 3741 | result.GetOutputStream().Printf("Fast UnwindPlan for %s`%s (start addr 0x%" PRIx64 "):\n", sc.module_sp->GetPlatformFileSpec().GetFilename().AsCString(), funcname.AsCString(), start_addr); |
| 3742 | fast_unwind_plan->Dump(result.GetOutputStream(), thread.get(), LLDB_INVALID_ADDRESS); |
| 3743 | result.GetOutputStream().Printf ("\n"); |
| 3744 | } |
| 3745 | |
| 3746 | |
| 3747 | result.GetOutputStream().Printf ("\n"); |
Jason Molenda | 380241a | 2012-07-12 00:20:07 +0000 | [diff] [blame] | 3748 | } |
| 3749 | return result.Succeeded(); |
| 3750 | } |
| 3751 | |
| 3752 | CommandOptions m_options; |
| 3753 | }; |
| 3754 | |
| 3755 | OptionDefinition |
| 3756 | CommandObjectTargetModulesShowUnwind::CommandOptions::g_option_table[] = |
| 3757 | { |
Jason Molenda | 535ab86 | 2013-04-23 04:30:57 +0000 | [diff] [blame] | 3758 | { LLDB_OPT_SET_1, false, "name", 'n', required_argument, NULL, 0, eArgTypeFunctionName, "Show unwind instructions for a function or symbol name."}, |
| 3759 | { LLDB_OPT_SET_2, false, "address", 'a', required_argument, NULL, 0, eArgTypeAddressOrExpression, "Show unwind instructions for a function or symbol containing an address"}, |
Jason Molenda | 380241a | 2012-07-12 00:20:07 +0000 | [diff] [blame] | 3760 | { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL } |
| 3761 | }; |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3762 | |
| 3763 | //---------------------------------------------------------------------- |
| 3764 | // Lookup information in images |
| 3765 | //---------------------------------------------------------------------- |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 3766 | class CommandObjectTargetModulesLookup : public CommandObjectParsed |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3767 | { |
| 3768 | public: |
| 3769 | |
| 3770 | enum |
| 3771 | { |
| 3772 | eLookupTypeInvalid = -1, |
| 3773 | eLookupTypeAddress = 0, |
| 3774 | eLookupTypeSymbol, |
| 3775 | eLookupTypeFileLine, // Line is optional |
| 3776 | eLookupTypeFunction, |
Greg Clayton | c4a8a76 | 2012-05-15 18:43:44 +0000 | [diff] [blame] | 3777 | eLookupTypeFunctionOrSymbol, |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3778 | eLookupTypeType, |
| 3779 | kNumLookupTypes |
| 3780 | }; |
| 3781 | |
| 3782 | class CommandOptions : public Options |
| 3783 | { |
| 3784 | public: |
| 3785 | |
| 3786 | CommandOptions (CommandInterpreter &interpreter) : |
| 3787 | Options(interpreter) |
| 3788 | { |
| 3789 | OptionParsingStarting(); |
| 3790 | } |
| 3791 | |
| 3792 | virtual |
| 3793 | ~CommandOptions () |
| 3794 | { |
| 3795 | } |
| 3796 | |
| 3797 | virtual Error |
| 3798 | SetOptionValue (uint32_t option_idx, const char *option_arg) |
| 3799 | { |
| 3800 | Error error; |
| 3801 | |
Greg Clayton | 3bcdfc0 | 2012-12-04 00:32:51 +0000 | [diff] [blame] | 3802 | const int short_option = m_getopt_table[option_idx].val; |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3803 | |
| 3804 | switch (short_option) |
| 3805 | { |
| 3806 | case 'a': |
Jim Ingham | e7b849e | 2013-03-15 23:09:19 +0000 | [diff] [blame] | 3807 | { |
| 3808 | m_type = eLookupTypeAddress; |
| 3809 | ExecutionContext exe_ctx (m_interpreter.GetExecutionContext()); |
| 3810 | m_addr = Args::StringToAddress(&exe_ctx, option_arg, LLDB_INVALID_ADDRESS, &error); |
| 3811 | } |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3812 | break; |
| 3813 | |
| 3814 | case 'o': |
| 3815 | m_offset = Args::StringToUInt64(option_arg, LLDB_INVALID_ADDRESS); |
| 3816 | if (m_offset == LLDB_INVALID_ADDRESS) |
Greg Clayton | 86edbf4 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 3817 | error.SetErrorStringWithFormat ("invalid offset string '%s'", option_arg); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3818 | break; |
| 3819 | |
| 3820 | case 's': |
| 3821 | m_str = option_arg; |
| 3822 | m_type = eLookupTypeSymbol; |
| 3823 | break; |
| 3824 | |
| 3825 | case 'f': |
| 3826 | m_file.SetFile (option_arg, false); |
| 3827 | m_type = eLookupTypeFileLine; |
| 3828 | break; |
| 3829 | |
| 3830 | case 'i': |
Sean Callanan | d4a7c12 | 2012-02-11 01:22:21 +0000 | [diff] [blame] | 3831 | m_include_inlines = false; |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3832 | break; |
| 3833 | |
| 3834 | case 'l': |
| 3835 | m_line_number = Args::StringToUInt32(option_arg, UINT32_MAX); |
| 3836 | if (m_line_number == UINT32_MAX) |
Greg Clayton | 86edbf4 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 3837 | error.SetErrorStringWithFormat ("invalid line number string '%s'", option_arg); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3838 | else if (m_line_number == 0) |
Greg Clayton | 86edbf4 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 3839 | error.SetErrorString ("zero is an invalid line number"); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3840 | m_type = eLookupTypeFileLine; |
| 3841 | break; |
| 3842 | |
Greg Clayton | c4a8a76 | 2012-05-15 18:43:44 +0000 | [diff] [blame] | 3843 | case 'F': |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3844 | m_str = option_arg; |
| 3845 | m_type = eLookupTypeFunction; |
| 3846 | break; |
Greg Clayton | c4a8a76 | 2012-05-15 18:43:44 +0000 | [diff] [blame] | 3847 | |
| 3848 | case 'n': |
| 3849 | m_str = option_arg; |
| 3850 | m_type = eLookupTypeFunctionOrSymbol; |
| 3851 | break; |
| 3852 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3853 | case 't': |
| 3854 | m_str = option_arg; |
| 3855 | m_type = eLookupTypeType; |
| 3856 | break; |
| 3857 | |
| 3858 | case 'v': |
| 3859 | m_verbose = 1; |
| 3860 | break; |
Sean Callanan | d38b4a9 | 2012-06-06 20:49:55 +0000 | [diff] [blame] | 3861 | |
| 3862 | case 'A': |
| 3863 | m_print_all = true; |
| 3864 | break; |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3865 | |
| 3866 | case 'r': |
| 3867 | m_use_regex = true; |
| 3868 | break; |
| 3869 | } |
| 3870 | |
| 3871 | return error; |
| 3872 | } |
| 3873 | |
| 3874 | void |
| 3875 | OptionParsingStarting () |
| 3876 | { |
| 3877 | m_type = eLookupTypeInvalid; |
| 3878 | m_str.clear(); |
| 3879 | m_file.Clear(); |
| 3880 | m_addr = LLDB_INVALID_ADDRESS; |
| 3881 | m_offset = 0; |
| 3882 | m_line_number = 0; |
| 3883 | m_use_regex = false; |
Sean Callanan | d4a7c12 | 2012-02-11 01:22:21 +0000 | [diff] [blame] | 3884 | m_include_inlines = true; |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3885 | m_verbose = false; |
Sean Callanan | d38b4a9 | 2012-06-06 20:49:55 +0000 | [diff] [blame] | 3886 | m_print_all = false; |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3887 | } |
| 3888 | |
| 3889 | const OptionDefinition* |
| 3890 | GetDefinitions () |
| 3891 | { |
| 3892 | return g_option_table; |
| 3893 | } |
| 3894 | |
| 3895 | // Options table: Required for subclasses of Options. |
| 3896 | |
| 3897 | static OptionDefinition g_option_table[]; |
| 3898 | int m_type; // Should be a eLookupTypeXXX enum after parsing options |
| 3899 | std::string m_str; // Holds name lookup |
| 3900 | FileSpec m_file; // Files for file lookups |
| 3901 | lldb::addr_t m_addr; // Holds the address to lookup |
| 3902 | lldb::addr_t m_offset; // Subtract this offset from m_addr before doing lookups. |
| 3903 | uint32_t m_line_number; // Line number for file+line lookups |
| 3904 | bool m_use_regex; // Name lookups in m_str are regular expressions. |
Sean Callanan | d4a7c12 | 2012-02-11 01:22:21 +0000 | [diff] [blame] | 3905 | bool m_include_inlines;// Check for inline entries when looking up by file/line. |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3906 | bool m_verbose; // Enable verbose lookup info |
Sean Callanan | d38b4a9 | 2012-06-06 20:49:55 +0000 | [diff] [blame] | 3907 | bool m_print_all; // Print all matches, even in cases where there's a best match. |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3908 | |
| 3909 | }; |
| 3910 | |
| 3911 | CommandObjectTargetModulesLookup (CommandInterpreter &interpreter) : |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 3912 | CommandObjectParsed (interpreter, |
| 3913 | "target modules lookup", |
| 3914 | "Look up information within executable and dependent shared library images.", |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 3915 | NULL, |
| 3916 | eFlagRequiresTarget), |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 3917 | m_options (interpreter) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3918 | { |
| 3919 | CommandArgumentEntry arg; |
| 3920 | CommandArgumentData file_arg; |
| 3921 | |
| 3922 | // Define the first (and only) variant of this arg. |
| 3923 | file_arg.arg_type = eArgTypeFilename; |
| 3924 | file_arg.arg_repetition = eArgRepeatStar; |
| 3925 | |
| 3926 | // There is only one variant this argument could be; put it into the argument entry. |
| 3927 | arg.push_back (file_arg); |
| 3928 | |
| 3929 | // Push the data for the first argument into the m_arguments vector. |
| 3930 | m_arguments.push_back (arg); |
| 3931 | } |
| 3932 | |
| 3933 | virtual |
| 3934 | ~CommandObjectTargetModulesLookup () |
| 3935 | { |
| 3936 | } |
| 3937 | |
| 3938 | virtual Options * |
| 3939 | GetOptions () |
| 3940 | { |
| 3941 | return &m_options; |
| 3942 | } |
| 3943 | |
Sean Callanan | d38b4a9 | 2012-06-06 20:49:55 +0000 | [diff] [blame] | 3944 | bool |
| 3945 | LookupHere (CommandInterpreter &interpreter, CommandReturnObject &result, bool &syntax_error) |
| 3946 | { |
| 3947 | switch (m_options.m_type) |
| 3948 | { |
| 3949 | case eLookupTypeAddress: |
| 3950 | case eLookupTypeFileLine: |
| 3951 | case eLookupTypeFunction: |
| 3952 | case eLookupTypeFunctionOrSymbol: |
| 3953 | case eLookupTypeSymbol: |
| 3954 | default: |
| 3955 | return false; |
| 3956 | case eLookupTypeType: |
| 3957 | break; |
| 3958 | } |
| 3959 | |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 3960 | StackFrameSP frame = m_exe_ctx.GetFrameSP(); |
Sean Callanan | d38b4a9 | 2012-06-06 20:49:55 +0000 | [diff] [blame] | 3961 | |
| 3962 | if (!frame) |
| 3963 | return false; |
| 3964 | |
| 3965 | const SymbolContext &sym_ctx(frame->GetSymbolContext(eSymbolContextModule)); |
| 3966 | |
| 3967 | if (!sym_ctx.module_sp) |
| 3968 | return false; |
| 3969 | |
| 3970 | switch (m_options.m_type) |
| 3971 | { |
| 3972 | default: |
| 3973 | return false; |
| 3974 | case eLookupTypeType: |
| 3975 | if (!m_options.m_str.empty()) |
| 3976 | { |
| 3977 | if (LookupTypeHere (m_interpreter, |
| 3978 | result.GetOutputStream(), |
| 3979 | sym_ctx, |
| 3980 | m_options.m_str.c_str(), |
| 3981 | m_options.m_use_regex)) |
| 3982 | { |
| 3983 | result.SetStatus(eReturnStatusSuccessFinishResult); |
| 3984 | return true; |
| 3985 | } |
| 3986 | } |
| 3987 | break; |
| 3988 | } |
| 3989 | |
| 3990 | return true; |
| 3991 | } |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3992 | |
| 3993 | bool |
| 3994 | LookupInModule (CommandInterpreter &interpreter, Module *module, CommandReturnObject &result, bool &syntax_error) |
| 3995 | { |
| 3996 | switch (m_options.m_type) |
| 3997 | { |
| 3998 | case eLookupTypeAddress: |
| 3999 | if (m_options.m_addr != LLDB_INVALID_ADDRESS) |
| 4000 | { |
| 4001 | if (LookupAddressInModule (m_interpreter, |
| 4002 | result.GetOutputStream(), |
| 4003 | module, |
| 4004 | eSymbolContextEverything, |
| 4005 | m_options.m_addr, |
| 4006 | m_options.m_offset, |
| 4007 | m_options.m_verbose)) |
| 4008 | { |
| 4009 | result.SetStatus(eReturnStatusSuccessFinishResult); |
| 4010 | return true; |
| 4011 | } |
| 4012 | } |
| 4013 | break; |
| 4014 | |
| 4015 | case eLookupTypeSymbol: |
| 4016 | if (!m_options.m_str.empty()) |
| 4017 | { |
Greg Clayton | c4a8a76 | 2012-05-15 18:43:44 +0000 | [diff] [blame] | 4018 | if (LookupSymbolInModule (m_interpreter, |
| 4019 | result.GetOutputStream(), |
| 4020 | module, |
| 4021 | m_options.m_str.c_str(), |
| 4022 | m_options.m_use_regex, |
| 4023 | m_options.m_verbose)) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 4024 | { |
| 4025 | result.SetStatus(eReturnStatusSuccessFinishResult); |
| 4026 | return true; |
| 4027 | } |
| 4028 | } |
| 4029 | break; |
| 4030 | |
| 4031 | case eLookupTypeFileLine: |
| 4032 | if (m_options.m_file) |
| 4033 | { |
| 4034 | |
| 4035 | if (LookupFileAndLineInModule (m_interpreter, |
| 4036 | result.GetOutputStream(), |
| 4037 | module, |
| 4038 | m_options.m_file, |
| 4039 | m_options.m_line_number, |
Sean Callanan | d4a7c12 | 2012-02-11 01:22:21 +0000 | [diff] [blame] | 4040 | m_options.m_include_inlines, |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 4041 | m_options.m_verbose)) |
| 4042 | { |
| 4043 | result.SetStatus(eReturnStatusSuccessFinishResult); |
| 4044 | return true; |
| 4045 | } |
| 4046 | } |
| 4047 | break; |
Greg Clayton | c4a8a76 | 2012-05-15 18:43:44 +0000 | [diff] [blame] | 4048 | |
| 4049 | case eLookupTypeFunctionOrSymbol: |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 4050 | case eLookupTypeFunction: |
| 4051 | if (!m_options.m_str.empty()) |
| 4052 | { |
| 4053 | if (LookupFunctionInModule (m_interpreter, |
| 4054 | result.GetOutputStream(), |
| 4055 | module, |
| 4056 | m_options.m_str.c_str(), |
| 4057 | m_options.m_use_regex, |
Sean Callanan | d4a7c12 | 2012-02-11 01:22:21 +0000 | [diff] [blame] | 4058 | m_options.m_include_inlines, |
Greg Clayton | c4a8a76 | 2012-05-15 18:43:44 +0000 | [diff] [blame] | 4059 | m_options.m_type == eLookupTypeFunctionOrSymbol, // include symbols |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 4060 | m_options.m_verbose)) |
| 4061 | { |
| 4062 | result.SetStatus(eReturnStatusSuccessFinishResult); |
| 4063 | return true; |
| 4064 | } |
| 4065 | } |
| 4066 | break; |
| 4067 | |
Greg Clayton | c4a8a76 | 2012-05-15 18:43:44 +0000 | [diff] [blame] | 4068 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 4069 | case eLookupTypeType: |
| 4070 | if (!m_options.m_str.empty()) |
| 4071 | { |
| 4072 | if (LookupTypeInModule (m_interpreter, |
| 4073 | result.GetOutputStream(), |
| 4074 | module, |
| 4075 | m_options.m_str.c_str(), |
| 4076 | m_options.m_use_regex)) |
| 4077 | { |
| 4078 | result.SetStatus(eReturnStatusSuccessFinishResult); |
| 4079 | return true; |
| 4080 | } |
| 4081 | } |
| 4082 | break; |
| 4083 | |
| 4084 | default: |
| 4085 | m_options.GenerateOptionUsage (result.GetErrorStream(), this); |
| 4086 | syntax_error = true; |
| 4087 | break; |
| 4088 | } |
| 4089 | |
| 4090 | result.SetStatus (eReturnStatusFailed); |
| 4091 | return false; |
| 4092 | } |
| 4093 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 4094 | protected: |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 4095 | virtual bool |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 4096 | DoExecute (Args& command, |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 4097 | CommandReturnObject &result) |
| 4098 | { |
| 4099 | Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); |
| 4100 | if (target == NULL) |
| 4101 | { |
| 4102 | result.AppendError ("invalid target, create a debug target using the 'target create' command"); |
| 4103 | result.SetStatus (eReturnStatusFailed); |
| 4104 | return false; |
| 4105 | } |
| 4106 | else |
| 4107 | { |
| 4108 | bool syntax_error = false; |
| 4109 | uint32_t i; |
| 4110 | uint32_t num_successful_lookups = 0; |
| 4111 | uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize(); |
| 4112 | result.GetOutputStream().SetAddressByteSize(addr_byte_size); |
| 4113 | result.GetErrorStream().SetAddressByteSize(addr_byte_size); |
| 4114 | // Dump all sections for all modules images |
| 4115 | |
| 4116 | if (command.GetArgumentCount() == 0) |
| 4117 | { |
Sean Callanan | d38b4a9 | 2012-06-06 20:49:55 +0000 | [diff] [blame] | 4118 | ModuleSP current_module; |
| 4119 | |
| 4120 | // Where it is possible to look in the current symbol context |
| 4121 | // first, try that. If this search was successful and --all |
| 4122 | // was not passed, don't print anything else. |
| 4123 | if (LookupHere (m_interpreter, result, syntax_error)) |
| 4124 | { |
| 4125 | result.GetOutputStream().EOL(); |
| 4126 | num_successful_lookups++; |
| 4127 | if (!m_options.m_print_all) |
| 4128 | { |
| 4129 | result.SetStatus (eReturnStatusSuccessFinishResult); |
| 4130 | return result.Succeeded(); |
| 4131 | } |
| 4132 | } |
| 4133 | |
| 4134 | // Dump all sections for all other modules |
| 4135 | |
Enrico Granata | 1759848 | 2012-11-08 02:22:02 +0000 | [diff] [blame] | 4136 | const ModuleList &target_modules = target->GetImages(); |
Jim Ingham | 3ee12ef | 2012-05-30 02:19:25 +0000 | [diff] [blame] | 4137 | Mutex::Locker modules_locker(target_modules.GetMutex()); |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 4138 | const size_t num_modules = target_modules.GetSize(); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 4139 | if (num_modules > 0) |
| 4140 | { |
| 4141 | for (i = 0; i<num_modules && syntax_error == false; ++i) |
| 4142 | { |
Sean Callanan | d38b4a9 | 2012-06-06 20:49:55 +0000 | [diff] [blame] | 4143 | Module *module_pointer = target_modules.GetModulePointerAtIndexUnlocked(i); |
| 4144 | |
| 4145 | if (module_pointer != current_module.get() && |
| 4146 | LookupInModule (m_interpreter, target_modules.GetModulePointerAtIndexUnlocked(i), result, syntax_error)) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 4147 | { |
| 4148 | result.GetOutputStream().EOL(); |
| 4149 | num_successful_lookups++; |
| 4150 | } |
| 4151 | } |
| 4152 | } |
| 4153 | else |
| 4154 | { |
| 4155 | result.AppendError ("the target has no associated executable images"); |
| 4156 | result.SetStatus (eReturnStatusFailed); |
| 4157 | return false; |
| 4158 | } |
| 4159 | } |
| 4160 | else |
| 4161 | { |
| 4162 | // Dump specified images (by basename or fullpath) |
| 4163 | const char *arg_cstr; |
| 4164 | for (i = 0; (arg_cstr = command.GetArgumentAtIndex(i)) != NULL && syntax_error == false; ++i) |
| 4165 | { |
Greg Clayton | 8ee6438 | 2011-11-10 01:18:58 +0000 | [diff] [blame] | 4166 | ModuleList module_list; |
| 4167 | const size_t num_matches = FindModulesByName (target, arg_cstr, module_list, false); |
| 4168 | if (num_matches > 0) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 4169 | { |
Jason Molenda | ccd41e5 | 2012-10-04 22:47:07 +0000 | [diff] [blame] | 4170 | for (size_t j=0; j<num_matches; ++j) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 4171 | { |
Jason Molenda | ccd41e5 | 2012-10-04 22:47:07 +0000 | [diff] [blame] | 4172 | Module *module = module_list.GetModulePointerAtIndex(j); |
Greg Clayton | 8ee6438 | 2011-11-10 01:18:58 +0000 | [diff] [blame] | 4173 | if (module) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 4174 | { |
Greg Clayton | 8ee6438 | 2011-11-10 01:18:58 +0000 | [diff] [blame] | 4175 | if (LookupInModule (m_interpreter, module, result, syntax_error)) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 4176 | { |
| 4177 | result.GetOutputStream().EOL(); |
| 4178 | num_successful_lookups++; |
| 4179 | } |
| 4180 | } |
| 4181 | } |
| 4182 | } |
| 4183 | else |
| 4184 | result.AppendWarningWithFormat("Unable to find an image that matches '%s'.\n", arg_cstr); |
| 4185 | } |
| 4186 | } |
| 4187 | |
| 4188 | if (num_successful_lookups > 0) |
| 4189 | result.SetStatus (eReturnStatusSuccessFinishResult); |
| 4190 | else |
| 4191 | result.SetStatus (eReturnStatusFailed); |
| 4192 | } |
| 4193 | return result.Succeeded(); |
| 4194 | } |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 4195 | |
| 4196 | CommandOptions m_options; |
| 4197 | }; |
| 4198 | |
| 4199 | OptionDefinition |
| 4200 | CommandObjectTargetModulesLookup::CommandOptions::g_option_table[] = |
| 4201 | { |
Jim Ingham | e7b849e | 2013-03-15 23:09:19 +0000 | [diff] [blame] | 4202 | { LLDB_OPT_SET_1, true, "address", 'a', required_argument, NULL, 0, eArgTypeAddressOrExpression, "Lookup an address in one or more target modules."}, |
Sean Callanan | cd8b7cd | 2012-09-13 21:11:40 +0000 | [diff] [blame] | 4203 | { LLDB_OPT_SET_1, false, "offset", 'o', required_argument, NULL, 0, eArgTypeOffset, "When looking up an address subtract <offset> from any addresses before doing the lookup."}, |
Greg Clayton | c4a8a76 | 2012-05-15 18:43:44 +0000 | [diff] [blame] | 4204 | { LLDB_OPT_SET_2| LLDB_OPT_SET_4 | LLDB_OPT_SET_5 |
| 4205 | /* FIXME: re-enable this for types when the LookupTypeInModule actually uses the regex option: | LLDB_OPT_SET_6 */ , |
Sean Callanan | cd8b7cd | 2012-09-13 21:11:40 +0000 | [diff] [blame] | 4206 | false, "regex", 'r', no_argument, NULL, 0, eArgTypeNone, "The <name> argument for name lookups are regular expressions."}, |
| 4207 | { LLDB_OPT_SET_2, true, "symbol", 's', required_argument, NULL, 0, eArgTypeSymbol, "Lookup a symbol by name in the symbol tables in one or more target modules."}, |
| 4208 | { LLDB_OPT_SET_3, true, "file", 'f', required_argument, NULL, 0, eArgTypeFilename, "Lookup a file by fullpath or basename in one or more target modules."}, |
| 4209 | { LLDB_OPT_SET_3, false, "line", 'l', required_argument, NULL, 0, eArgTypeLineNum, "Lookup a line number in a file (must be used in conjunction with --file)."}, |
Jim Ingham | a8f5566 | 2012-06-04 22:47:34 +0000 | [diff] [blame] | 4210 | { LLDB_OPT_SET_FROM_TO(3,5), |
Sean Callanan | cd8b7cd | 2012-09-13 21:11:40 +0000 | [diff] [blame] | 4211 | false, "no-inlines", 'i', no_argument, NULL, 0, eArgTypeNone, "Ignore inline entries (must be used in conjunction with --file or --function)."}, |
| 4212 | { LLDB_OPT_SET_4, true, "function", 'F', required_argument, NULL, 0, eArgTypeFunctionName, "Lookup a function by name in the debug symbols in one or more target modules."}, |
| 4213 | { LLDB_OPT_SET_5, true, "name", 'n', required_argument, NULL, 0, eArgTypeFunctionOrSymbol, "Lookup a function or symbol by name in one or more target modules."}, |
| 4214 | { LLDB_OPT_SET_6, true, "type", 't', required_argument, NULL, 0, eArgTypeName, "Lookup a type by name in the debug symbols in one or more target modules."}, |
| 4215 | { LLDB_OPT_SET_ALL, false, "verbose", 'v', no_argument, NULL, 0, eArgTypeNone, "Enable verbose lookup information."}, |
| 4216 | { LLDB_OPT_SET_ALL, false, "all", 'A', no_argument, NULL, 0, eArgTypeNone, "Print all matches, not just the best match, if a best match is available."}, |
| 4217 | { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL } |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 4218 | }; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4219 | |
| 4220 | |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 4221 | #pragma mark CommandObjectMultiwordImageSearchPaths |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4222 | |
| 4223 | //------------------------------------------------------------------------- |
| 4224 | // CommandObjectMultiwordImageSearchPaths |
| 4225 | //------------------------------------------------------------------------- |
| 4226 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 4227 | class CommandObjectTargetModulesImageSearchPaths : public CommandObjectMultiword |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4228 | { |
| 4229 | public: |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 4230 | |
| 4231 | CommandObjectTargetModulesImageSearchPaths (CommandInterpreter &interpreter) : |
| 4232 | CommandObjectMultiword (interpreter, |
| 4233 | "target modules search-paths", |
| 4234 | "A set of commands for operating on debugger target image search paths.", |
| 4235 | "target modules search-paths <subcommand> [<subcommand-options>]") |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4236 | { |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 4237 | LoadSubCommand ("add", CommandObjectSP (new CommandObjectTargetModulesSearchPathsAdd (interpreter))); |
| 4238 | LoadSubCommand ("clear", CommandObjectSP (new CommandObjectTargetModulesSearchPathsClear (interpreter))); |
| 4239 | LoadSubCommand ("insert", CommandObjectSP (new CommandObjectTargetModulesSearchPathsInsert (interpreter))); |
| 4240 | LoadSubCommand ("list", CommandObjectSP (new CommandObjectTargetModulesSearchPathsList (interpreter))); |
| 4241 | LoadSubCommand ("query", CommandObjectSP (new CommandObjectTargetModulesSearchPathsQuery (interpreter))); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4242 | } |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 4243 | |
| 4244 | ~CommandObjectTargetModulesImageSearchPaths() |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4245 | { |
| 4246 | } |
| 4247 | }; |
| 4248 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 4249 | |
| 4250 | |
| 4251 | #pragma mark CommandObjectTargetModules |
| 4252 | |
| 4253 | //------------------------------------------------------------------------- |
| 4254 | // CommandObjectTargetModules |
| 4255 | //------------------------------------------------------------------------- |
| 4256 | |
| 4257 | class CommandObjectTargetModules : public CommandObjectMultiword |
| 4258 | { |
| 4259 | public: |
| 4260 | //------------------------------------------------------------------ |
| 4261 | // Constructors and Destructors |
| 4262 | //------------------------------------------------------------------ |
| 4263 | CommandObjectTargetModules(CommandInterpreter &interpreter) : |
| 4264 | CommandObjectMultiword (interpreter, |
| 4265 | "target modules", |
| 4266 | "A set of commands for accessing information for one or more target modules.", |
| 4267 | "target modules <sub-command> ...") |
| 4268 | { |
| 4269 | LoadSubCommand ("add", CommandObjectSP (new CommandObjectTargetModulesAdd (interpreter))); |
| 4270 | LoadSubCommand ("load", CommandObjectSP (new CommandObjectTargetModulesLoad (interpreter))); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 4271 | LoadSubCommand ("dump", CommandObjectSP (new CommandObjectTargetModulesDump (interpreter))); |
| 4272 | LoadSubCommand ("list", CommandObjectSP (new CommandObjectTargetModulesList (interpreter))); |
| 4273 | LoadSubCommand ("lookup", CommandObjectSP (new CommandObjectTargetModulesLookup (interpreter))); |
| 4274 | LoadSubCommand ("search-paths", CommandObjectSP (new CommandObjectTargetModulesImageSearchPaths (interpreter))); |
Jason Molenda | 380241a | 2012-07-12 00:20:07 +0000 | [diff] [blame] | 4275 | LoadSubCommand ("show-unwind", CommandObjectSP (new CommandObjectTargetModulesShowUnwind (interpreter))); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 4276 | |
| 4277 | } |
| 4278 | virtual |
| 4279 | ~CommandObjectTargetModules() |
| 4280 | { |
| 4281 | } |
| 4282 | |
| 4283 | private: |
| 4284 | //------------------------------------------------------------------ |
| 4285 | // For CommandObjectTargetModules only |
| 4286 | //------------------------------------------------------------------ |
| 4287 | DISALLOW_COPY_AND_ASSIGN (CommandObjectTargetModules); |
| 4288 | }; |
| 4289 | |
| 4290 | |
Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 4291 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 4292 | class CommandObjectTargetSymbolsAdd : public CommandObjectParsed |
Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 4293 | { |
| 4294 | public: |
| 4295 | CommandObjectTargetSymbolsAdd (CommandInterpreter &interpreter) : |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 4296 | CommandObjectParsed (interpreter, |
| 4297 | "target symbols add", |
Greg Clayton | b5f0fea | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 4298 | "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 Molenda | b9c9f9b | 2013-02-02 06:00:36 +0000 | [diff] [blame] | 4299 | "target symbols add [<symfile>]", eFlagRequiresTarget), |
Greg Clayton | b5f0fea | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 4300 | m_option_group (interpreter), |
| 4301 | m_file_option (LLDB_OPT_SET_1, false, "shlib", 's', CommandCompletions::eModuleCompletion, eArgTypeShlibName, "Fullpath or basename for module to find debug symbols for."), |
| 4302 | m_current_frame_option (LLDB_OPT_SET_2, false, "frame", 'F', "Locate the debug symbols the currently selected frame.", false, true) |
| 4303 | |
Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 4304 | { |
Greg Clayton | b5f0fea | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 4305 | m_option_group.Append (&m_uuid_option_group, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1); |
| 4306 | m_option_group.Append (&m_file_option, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1); |
| 4307 | m_option_group.Append (&m_current_frame_option, LLDB_OPT_SET_2, LLDB_OPT_SET_2); |
| 4308 | m_option_group.Finalize(); |
Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 4309 | } |
| 4310 | |
| 4311 | virtual |
| 4312 | ~CommandObjectTargetSymbolsAdd () |
| 4313 | { |
| 4314 | } |
| 4315 | |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 4316 | virtual int |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 4317 | HandleArgumentCompletion (Args &input, |
| 4318 | int &cursor_index, |
| 4319 | int &cursor_char_position, |
| 4320 | OptionElementVector &opt_element_vector, |
| 4321 | int match_start_point, |
| 4322 | int max_return_elements, |
| 4323 | bool &word_complete, |
| 4324 | StringList &matches) |
| 4325 | { |
| 4326 | std::string completion_str (input.GetArgumentAtIndex(cursor_index)); |
| 4327 | completion_str.erase (cursor_char_position); |
| 4328 | |
| 4329 | CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter, |
| 4330 | CommandCompletions::eDiskFileCompletion, |
| 4331 | completion_str.c_str(), |
| 4332 | match_start_point, |
| 4333 | max_return_elements, |
| 4334 | NULL, |
| 4335 | word_complete, |
| 4336 | matches); |
| 4337 | return matches.GetSize(); |
| 4338 | } |
| 4339 | |
Greg Clayton | b5f0fea | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 4340 | virtual Options * |
| 4341 | GetOptions () |
| 4342 | { |
| 4343 | return &m_option_group; |
| 4344 | } |
| 4345 | |
| 4346 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 4347 | protected: |
Greg Clayton | b5f0fea | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 4348 | |
| 4349 | bool |
| 4350 | AddModuleSymbols (Target *target, |
Greg Clayton | 89deb06 | 2012-12-12 01:15:30 +0000 | [diff] [blame] | 4351 | ModuleSpec &module_spec, |
Greg Clayton | b5f0fea | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 4352 | bool &flush, |
| 4353 | CommandReturnObject &result) |
| 4354 | { |
Greg Clayton | 89deb06 | 2012-12-12 01:15:30 +0000 | [diff] [blame] | 4355 | const FileSpec &symbol_fspec = module_spec.GetSymbolFileSpec(); |
| 4356 | if (symbol_fspec) |
Greg Clayton | b5f0fea | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 4357 | { |
| 4358 | char symfile_path[PATH_MAX]; |
Greg Clayton | 89deb06 | 2012-12-12 01:15:30 +0000 | [diff] [blame] | 4359 | symbol_fspec.GetPath (symfile_path, sizeof(symfile_path)); |
| 4360 | |
| 4361 | if (!module_spec.GetUUID().IsValid()) |
| 4362 | { |
| 4363 | if (!module_spec.GetFileSpec() && !module_spec.GetPlatformFileSpec()) |
| 4364 | module_spec.GetFileSpec().GetFilename() = symbol_fspec.GetFilename(); |
| 4365 | } |
Greg Clayton | b5f0fea | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 4366 | // We now have a module that represents a symbol file |
| 4367 | // that can be used for a module that might exist in the |
| 4368 | // current target, so we need to find that module in the |
| 4369 | // target |
Greg Clayton | 89deb06 | 2012-12-12 01:15:30 +0000 | [diff] [blame] | 4370 | ModuleList matching_module_list; |
Greg Clayton | 9aae0a1 | 2013-05-15 19:52:08 +0000 | [diff] [blame] | 4371 | |
| 4372 | size_t num_matches = 0; |
| 4373 | // First extract all module specs from the symbol file |
| 4374 | lldb_private::ModuleSpecList symfile_module_specs; |
Greg Clayton | 2540a8a | 2013-07-12 22:07:46 +0000 | [diff] [blame] | 4375 | if (ObjectFile::GetModuleSpecifications(module_spec.GetSymbolFileSpec(), 0, 0, symfile_module_specs)) |
Greg Clayton | 9aae0a1 | 2013-05-15 19:52:08 +0000 | [diff] [blame] | 4376 | { |
| 4377 | // Now extract the module spec that matches the target architecture |
| 4378 | ModuleSpec target_arch_module_spec; |
| 4379 | ModuleSpec symfile_module_spec; |
| 4380 | target_arch_module_spec.GetArchitecture() = target->GetArchitecture(); |
| 4381 | if (symfile_module_specs.FindMatchingModuleSpec(target_arch_module_spec, symfile_module_spec)) |
| 4382 | { |
| 4383 | // See if it has a UUID? |
| 4384 | if (symfile_module_spec.GetUUID().IsValid()) |
| 4385 | { |
| 4386 | // It has a UUID, look for this UUID in the target modules |
| 4387 | ModuleSpec symfile_uuid_module_spec; |
| 4388 | symfile_uuid_module_spec.GetUUID() = symfile_module_spec.GetUUID(); |
| 4389 | num_matches = target->GetImages().FindModules (symfile_uuid_module_spec, matching_module_list); |
| 4390 | } |
| 4391 | } |
| 4392 | |
| 4393 | if (num_matches == 0) |
| 4394 | { |
| 4395 | // No matches yet, iterate through the module specs to find a UUID value that |
| 4396 | // we can match up to an image in our target |
| 4397 | const size_t num_symfile_module_specs = symfile_module_specs.GetSize(); |
| 4398 | for (size_t i=0; i<num_symfile_module_specs && num_matches == 0; ++i) |
| 4399 | { |
| 4400 | if (symfile_module_specs.GetModuleSpecAtIndex(i, symfile_module_spec)) |
| 4401 | { |
| 4402 | if (symfile_module_spec.GetUUID().IsValid()) |
| 4403 | { |
| 4404 | // It has a UUID, look for this UUID in the target modules |
| 4405 | ModuleSpec symfile_uuid_module_spec; |
| 4406 | symfile_uuid_module_spec.GetUUID() = symfile_module_spec.GetUUID(); |
| 4407 | num_matches = target->GetImages().FindModules (symfile_uuid_module_spec, matching_module_list); |
| 4408 | } |
| 4409 | } |
| 4410 | } |
| 4411 | } |
| 4412 | } |
| 4413 | |
| 4414 | // Just try to match up the file by basename if we have no matches at this point |
| 4415 | if (num_matches == 0) |
| 4416 | num_matches = target->GetImages().FindModules (module_spec, matching_module_list); |
| 4417 | |
Greg Clayton | 91c0e74 | 2013-01-11 23:44:27 +0000 | [diff] [blame] | 4418 | while (num_matches == 0) |
| 4419 | { |
| 4420 | ConstString filename_no_extension(module_spec.GetFileSpec().GetFileNameStrippingExtension()); |
| 4421 | // Empty string returned, lets bail |
| 4422 | if (!filename_no_extension) |
| 4423 | break; |
| 4424 | |
| 4425 | // Check if there was no extension to strip and the basename is the same |
| 4426 | if (filename_no_extension == module_spec.GetFileSpec().GetFilename()) |
| 4427 | break; |
| 4428 | |
| 4429 | // Replace basename with one less extension |
| 4430 | module_spec.GetFileSpec().GetFilename() = filename_no_extension; |
| 4431 | |
| 4432 | num_matches = target->GetImages().FindModules (module_spec, matching_module_list); |
Greg Clayton | 9aae0a1 | 2013-05-15 19:52:08 +0000 | [diff] [blame] | 4433 | |
Greg Clayton | 91c0e74 | 2013-01-11 23:44:27 +0000 | [diff] [blame] | 4434 | } |
| 4435 | |
Greg Clayton | 89deb06 | 2012-12-12 01:15:30 +0000 | [diff] [blame] | 4436 | if (num_matches > 1) |
Greg Clayton | b5f0fea | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 4437 | { |
Greg Clayton | 89deb06 | 2012-12-12 01:15:30 +0000 | [diff] [blame] | 4438 | result.AppendErrorWithFormat ("multiple modules match symbol file '%s', use the --uuid option to resolve the ambiguity.\n", symfile_path); |
| 4439 | } |
| 4440 | else if (num_matches == 1) |
| 4441 | { |
| 4442 | ModuleSP module_sp (matching_module_list.GetModuleAtIndex(0)); |
| 4443 | |
Greg Clayton | b5f0fea | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 4444 | // The module has not yet created its symbol vendor, we can just |
| 4445 | // give the existing target module the symfile path to use for |
| 4446 | // when it decides to create it! |
Greg Clayton | 89deb06 | 2012-12-12 01:15:30 +0000 | [diff] [blame] | 4447 | module_sp->SetSymbolFileFileSpec (symbol_fspec); |
Greg Clayton | b5f0fea | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 4448 | |
Greg Clayton | 136dff8 | 2012-12-14 02:15:00 +0000 | [diff] [blame] | 4449 | SymbolVendor *symbol_vendor = module_sp->GetSymbolVendor(true, &result.GetErrorStream()); |
Greg Clayton | 89deb06 | 2012-12-12 01:15:30 +0000 | [diff] [blame] | 4450 | if (symbol_vendor) |
| 4451 | { |
| 4452 | SymbolFile *symbol_file = symbol_vendor->GetSymbolFile(); |
| 4453 | |
| 4454 | if (symbol_file) |
| 4455 | { |
| 4456 | ObjectFile *object_file = symbol_file->GetObjectFile(); |
| 4457 | |
| 4458 | if (object_file && object_file->GetFileSpec() == symbol_fspec) |
| 4459 | { |
| 4460 | // Provide feedback that the symfile has been successfully added. |
| 4461 | const FileSpec &module_fs = module_sp->GetFileSpec(); |
Greg Clayton | b5ad4ec | 2013-04-29 17:25:54 +0000 | [diff] [blame] | 4462 | result.AppendMessageWithFormat("symbol file '%s' has been added to '%s'\n", |
Greg Clayton | 89deb06 | 2012-12-12 01:15:30 +0000 | [diff] [blame] | 4463 | symfile_path, |
Greg Clayton | b5ad4ec | 2013-04-29 17:25:54 +0000 | [diff] [blame] | 4464 | module_fs.GetPath().c_str()); |
Greg Clayton | 89deb06 | 2012-12-12 01:15:30 +0000 | [diff] [blame] | 4465 | |
| 4466 | // Let clients know something changed in the module |
| 4467 | // if it is currently loaded |
| 4468 | ModuleList module_list; |
| 4469 | module_list.Append (module_sp); |
Enrico Granata | f15ee4e | 2013-04-05 18:49:06 +0000 | [diff] [blame] | 4470 | target->SymbolsDidLoad (module_list); |
Greg Clayton | 91c0e74 | 2013-01-11 23:44:27 +0000 | [diff] [blame] | 4471 | |
| 4472 | // Make sure we load any scripting resources that may be embedded |
| 4473 | // in the debug info files in case the platform supports that. |
| 4474 | Error error; |
Enrico Granata | 9730339 | 2013-05-21 00:00:30 +0000 | [diff] [blame] | 4475 | StreamString feedback_stream; |
| 4476 | module_sp->LoadScriptingResourceInTarget (target, error,&feedback_stream); |
Enrico Granata | caa84cb | 2013-05-20 22:40:54 +0000 | [diff] [blame] | 4477 | if (error.Fail() && error.AsCString()) |
Enrico Granata | 2ea43cd | 2013-05-13 17:03:52 +0000 | [diff] [blame] | 4478 | result.AppendWarningWithFormat("unable to load scripting data for module %s - error reported was %s", |
| 4479 | module_sp->GetFileSpec().GetFileNameStrippingExtension().GetCString(), |
| 4480 | error.AsCString()); |
Enrico Granata | 9730339 | 2013-05-21 00:00:30 +0000 | [diff] [blame] | 4481 | else if (feedback_stream.GetSize()) |
| 4482 | result.AppendWarningWithFormat("%s",feedback_stream.GetData()); |
Greg Clayton | 91c0e74 | 2013-01-11 23:44:27 +0000 | [diff] [blame] | 4483 | |
Greg Clayton | 89deb06 | 2012-12-12 01:15:30 +0000 | [diff] [blame] | 4484 | flush = true; |
| 4485 | result.SetStatus (eReturnStatusSuccessFinishResult); |
| 4486 | return true; |
| 4487 | } |
| 4488 | } |
| 4489 | } |
| 4490 | // Clear the symbol file spec if anything went wrong |
| 4491 | module_sp->SetSymbolFileFileSpec (FileSpec()); |
Greg Clayton | 89deb06 | 2012-12-12 01:15:30 +0000 | [diff] [blame] | 4492 | } |
| 4493 | |
| 4494 | if (module_spec.GetUUID().IsValid()) |
| 4495 | { |
| 4496 | StreamString ss_symfile_uuid; |
| 4497 | module_spec.GetUUID().Dump(&ss_symfile_uuid); |
| 4498 | result.AppendErrorWithFormat ("symbol file '%s' (%s) does not match any existing module%s\n", |
| 4499 | symfile_path, |
| 4500 | ss_symfile_uuid.GetData(), |
| 4501 | (symbol_fspec.GetFileType() != FileSpec::eFileTypeRegular) |
| 4502 | ? "\n please specify the full path to the symbol file" |
| 4503 | : ""); |
Greg Clayton | b5f0fea | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 4504 | } |
| 4505 | else |
| 4506 | { |
Greg Clayton | 89deb06 | 2012-12-12 01:15:30 +0000 | [diff] [blame] | 4507 | result.AppendErrorWithFormat ("symbol file '%s' does not match any existing module%s\n", |
| 4508 | symfile_path, |
| 4509 | (symbol_fspec.GetFileType() != FileSpec::eFileTypeRegular) |
| 4510 | ? "\n please specify the full path to the symbol file" |
| 4511 | : ""); |
Greg Clayton | b5f0fea | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 4512 | } |
| 4513 | } |
| 4514 | else |
| 4515 | { |
| 4516 | result.AppendError ("one or more executable image paths must be specified"); |
Greg Clayton | b5f0fea | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 4517 | } |
Greg Clayton | 89deb06 | 2012-12-12 01:15:30 +0000 | [diff] [blame] | 4518 | result.SetStatus (eReturnStatusFailed); |
| 4519 | return false; |
Greg Clayton | b5f0fea | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 4520 | } |
| 4521 | |
Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 4522 | virtual bool |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 4523 | DoExecute (Args& args, |
Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 4524 | CommandReturnObject &result) |
| 4525 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 4526 | Target *target = m_exe_ctx.GetTargetPtr(); |
Greg Clayton | b5f0fea | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 4527 | result.SetStatus (eReturnStatusFailed); |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 4528 | bool flush = false; |
| 4529 | ModuleSpec module_spec; |
| 4530 | const bool uuid_option_set = m_uuid_option_group.GetOptionValue().OptionWasSet(); |
| 4531 | const bool file_option_set = m_file_option.GetOptionValue().OptionWasSet(); |
| 4532 | const bool frame_option_set = m_current_frame_option.GetOptionValue().OptionWasSet(); |
Greg Clayton | b5f0fea | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 4533 | |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 4534 | const size_t argc = args.GetArgumentCount(); |
| 4535 | if (argc == 0) |
| 4536 | { |
| 4537 | if (uuid_option_set || file_option_set || frame_option_set) |
Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 4538 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 4539 | bool success = false; |
| 4540 | bool error_set = false; |
| 4541 | if (frame_option_set) |
Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 4542 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 4543 | Process *process = m_exe_ctx.GetProcessPtr(); |
| 4544 | if (process) |
Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 4545 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 4546 | const StateType process_state = process->GetState(); |
| 4547 | if (StateIsStoppedState (process_state, true)) |
Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 4548 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 4549 | StackFrame *frame = m_exe_ctx.GetFramePtr(); |
| 4550 | if (frame) |
Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 4551 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 4552 | ModuleSP frame_module_sp (frame->GetSymbolContext(eSymbolContextModule).module_sp); |
| 4553 | if (frame_module_sp) |
Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 4554 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 4555 | if (frame_module_sp->GetPlatformFileSpec().Exists()) |
Greg Clayton | b5f0fea | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 4556 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 4557 | module_spec.GetArchitecture() = frame_module_sp->GetArchitecture(); |
| 4558 | module_spec.GetFileSpec() = frame_module_sp->GetPlatformFileSpec(); |
Greg Clayton | b5f0fea | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 4559 | } |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 4560 | module_spec.GetUUID() = frame_module_sp->GetUUID(); |
| 4561 | success = module_spec.GetUUID().IsValid() || module_spec.GetFileSpec(); |
Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 4562 | } |
Johnny Chen | 82e5a26 | 2012-08-22 00:18:43 +0000 | [diff] [blame] | 4563 | else |
| 4564 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 4565 | result.AppendError ("frame has no module"); |
Greg Clayton | b5f0fea | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 4566 | error_set = true; |
Johnny Chen | 82e5a26 | 2012-08-22 00:18:43 +0000 | [diff] [blame] | 4567 | } |
Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 4568 | } |
| 4569 | else |
| 4570 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 4571 | result.AppendError ("invalid current frame"); |
Greg Clayton | b5f0fea | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 4572 | error_set = true; |
Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 4573 | } |
Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 4574 | } |
| 4575 | else |
| 4576 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 4577 | result.AppendErrorWithFormat ("process is not stopped: %s", StateAsCString(process_state)); |
Greg Clayton | b5f0fea | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 4578 | error_set = true; |
| 4579 | } |
| 4580 | } |
| 4581 | else |
| 4582 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 4583 | result.AppendError ("a process must exist in order to use the --frame option"); |
| 4584 | error_set = true; |
Greg Clayton | b5f0fea | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 4585 | } |
| 4586 | } |
| 4587 | else |
| 4588 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 4589 | if (uuid_option_set) |
| 4590 | { |
| 4591 | module_spec.GetUUID() = m_uuid_option_group.GetOptionValue().GetCurrentValue(); |
| 4592 | success |= module_spec.GetUUID().IsValid(); |
| 4593 | } |
| 4594 | else if (file_option_set) |
| 4595 | { |
| 4596 | module_spec.GetFileSpec() = m_file_option.GetOptionValue().GetCurrentValue(); |
| 4597 | ModuleSP module_sp (target->GetImages().FindFirstModule(module_spec)); |
| 4598 | if (module_sp) |
| 4599 | { |
| 4600 | module_spec.GetFileSpec() = module_sp->GetFileSpec(); |
| 4601 | module_spec.GetPlatformFileSpec() = module_sp->GetPlatformFileSpec(); |
| 4602 | module_spec.GetUUID() = module_sp->GetUUID(); |
| 4603 | module_spec.GetArchitecture() = module_sp->GetArchitecture(); |
| 4604 | } |
| 4605 | else |
| 4606 | { |
| 4607 | module_spec.GetArchitecture() = target->GetArchitecture(); |
| 4608 | } |
| 4609 | success |= module_spec.GetFileSpec().Exists(); |
| 4610 | } |
| 4611 | } |
| 4612 | |
| 4613 | if (success) |
| 4614 | { |
| 4615 | if (Symbols::DownloadObjectAndSymbolFile (module_spec)) |
| 4616 | { |
| 4617 | if (module_spec.GetSymbolFileSpec()) |
| 4618 | success = AddModuleSymbols (target, module_spec, flush, result); |
| 4619 | } |
| 4620 | } |
| 4621 | |
| 4622 | if (!success && !error_set) |
| 4623 | { |
| 4624 | StreamString error_strm; |
| 4625 | if (uuid_option_set) |
| 4626 | { |
| 4627 | error_strm.PutCString("unable to find debug symbols for UUID "); |
| 4628 | module_spec.GetUUID().Dump (&error_strm); |
| 4629 | } |
| 4630 | else if (file_option_set) |
| 4631 | { |
| 4632 | error_strm.PutCString("unable to find debug symbols for the executable file "); |
| 4633 | error_strm << module_spec.GetFileSpec(); |
| 4634 | } |
| 4635 | else if (frame_option_set) |
| 4636 | { |
| 4637 | error_strm.PutCString("unable to find debug symbols for the current frame"); |
| 4638 | } |
| 4639 | result.AppendError (error_strm.GetData()); |
Greg Clayton | b5f0fea | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 4640 | } |
| 4641 | } |
| 4642 | else |
| 4643 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 4644 | result.AppendError ("one or more symbol file paths must be specified, or options must be specified"); |
| 4645 | } |
| 4646 | } |
| 4647 | else |
| 4648 | { |
| 4649 | if (uuid_option_set) |
| 4650 | { |
| 4651 | result.AppendError ("specify either one or more paths to symbol files or use the --uuid option without arguments"); |
| 4652 | } |
| 4653 | else if (file_option_set) |
| 4654 | { |
| 4655 | result.AppendError ("specify either one or more paths to symbol files or use the --file option without arguments"); |
| 4656 | } |
| 4657 | else if (frame_option_set) |
| 4658 | { |
| 4659 | result.AppendError ("specify either one or more paths to symbol files or use the --frame option without arguments"); |
| 4660 | } |
| 4661 | else |
| 4662 | { |
| 4663 | PlatformSP platform_sp (target->GetPlatform()); |
Greg Clayton | b5f0fea | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 4664 | |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 4665 | for (size_t i=0; i<argc; ++i) |
| 4666 | { |
| 4667 | const char *symfile_path = args.GetArgumentAtIndex(i); |
| 4668 | if (symfile_path) |
Greg Clayton | b5f0fea | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 4669 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 4670 | module_spec.GetSymbolFileSpec().SetFile(symfile_path, true); |
| 4671 | if (platform_sp) |
Greg Clayton | b5f0fea | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 4672 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 4673 | FileSpec symfile_spec; |
| 4674 | if (platform_sp->ResolveSymbolFile(*target, module_spec, symfile_spec).Success()) |
| 4675 | module_spec.GetSymbolFileSpec() = symfile_spec; |
| 4676 | } |
| 4677 | |
| 4678 | ArchSpec arch; |
| 4679 | bool symfile_exists = module_spec.GetSymbolFileSpec().Exists(); |
Greg Clayton | b5f0fea | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 4680 | |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 4681 | if (symfile_exists) |
| 4682 | { |
| 4683 | if (!AddModuleSymbols (target, module_spec, flush, result)) |
Greg Clayton | b5f0fea | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 4684 | break; |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 4685 | } |
| 4686 | else |
| 4687 | { |
| 4688 | char resolved_symfile_path[PATH_MAX]; |
| 4689 | if (module_spec.GetSymbolFileSpec().GetPath (resolved_symfile_path, sizeof(resolved_symfile_path))) |
| 4690 | { |
| 4691 | if (strcmp (resolved_symfile_path, symfile_path) != 0) |
| 4692 | { |
| 4693 | result.AppendErrorWithFormat ("invalid module path '%s' with resolved path '%s'\n", symfile_path, resolved_symfile_path); |
| 4694 | break; |
| 4695 | } |
Greg Clayton | b5f0fea | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 4696 | } |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 4697 | result.AppendErrorWithFormat ("invalid module path '%s'\n", symfile_path); |
| 4698 | break; |
Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 4699 | } |
| 4700 | } |
| 4701 | } |
| 4702 | } |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 4703 | } |
Greg Clayton | fa559e5 | 2012-05-18 02:38:05 +0000 | [diff] [blame] | 4704 | |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 4705 | if (flush) |
| 4706 | { |
| 4707 | Process *process = m_exe_ctx.GetProcessPtr(); |
| 4708 | if (process) |
| 4709 | process->Flush(); |
Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 4710 | } |
| 4711 | return result.Succeeded(); |
| 4712 | } |
| 4713 | |
Greg Clayton | b5f0fea | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 4714 | OptionGroupOptions m_option_group; |
| 4715 | OptionGroupUUID m_uuid_option_group; |
| 4716 | OptionGroupFile m_file_option; |
| 4717 | OptionGroupBoolean m_current_frame_option; |
| 4718 | |
| 4719 | |
Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 4720 | }; |
| 4721 | |
| 4722 | |
| 4723 | #pragma mark CommandObjectTargetSymbols |
| 4724 | |
| 4725 | //------------------------------------------------------------------------- |
| 4726 | // CommandObjectTargetSymbols |
| 4727 | //------------------------------------------------------------------------- |
| 4728 | |
| 4729 | class CommandObjectTargetSymbols : public CommandObjectMultiword |
| 4730 | { |
| 4731 | public: |
| 4732 | //------------------------------------------------------------------ |
| 4733 | // Constructors and Destructors |
| 4734 | //------------------------------------------------------------------ |
| 4735 | CommandObjectTargetSymbols(CommandInterpreter &interpreter) : |
| 4736 | CommandObjectMultiword (interpreter, |
| 4737 | "target symbols", |
| 4738 | "A set of commands for adding and managing debug symbol files.", |
| 4739 | "target symbols <sub-command> ...") |
| 4740 | { |
| 4741 | LoadSubCommand ("add", CommandObjectSP (new CommandObjectTargetSymbolsAdd (interpreter))); |
| 4742 | |
| 4743 | } |
| 4744 | virtual |
| 4745 | ~CommandObjectTargetSymbols() |
| 4746 | { |
| 4747 | } |
| 4748 | |
| 4749 | private: |
| 4750 | //------------------------------------------------------------------ |
| 4751 | // For CommandObjectTargetModules only |
| 4752 | //------------------------------------------------------------------ |
| 4753 | DISALLOW_COPY_AND_ASSIGN (CommandObjectTargetSymbols); |
| 4754 | }; |
| 4755 | |
| 4756 | |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 4757 | #pragma mark CommandObjectTargetStopHookAdd |
| 4758 | |
| 4759 | //------------------------------------------------------------------------- |
| 4760 | // CommandObjectTargetStopHookAdd |
| 4761 | //------------------------------------------------------------------------- |
| 4762 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 4763 | class CommandObjectTargetStopHookAdd : public CommandObjectParsed |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 4764 | { |
| 4765 | public: |
| 4766 | |
| 4767 | class CommandOptions : public Options |
| 4768 | { |
| 4769 | public: |
Greg Clayton | eb0103f | 2011-04-07 22:46:35 +0000 | [diff] [blame] | 4770 | CommandOptions (CommandInterpreter &interpreter) : |
| 4771 | Options(interpreter), |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 4772 | m_line_start(0), |
| 4773 | m_line_end (UINT_MAX), |
| 4774 | m_func_name_type_mask (eFunctionNameTypeAuto), |
| 4775 | m_sym_ctx_specified (false), |
Johnny Chen | b1372c0 | 2011-05-02 23:47:55 +0000 | [diff] [blame] | 4776 | m_thread_specified (false), |
| 4777 | m_use_one_liner (false), |
| 4778 | m_one_liner() |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 4779 | { |
| 4780 | } |
| 4781 | |
| 4782 | ~CommandOptions () {} |
| 4783 | |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 4784 | const OptionDefinition* |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 4785 | GetDefinitions () |
| 4786 | { |
| 4787 | return g_option_table; |
| 4788 | } |
| 4789 | |
| 4790 | virtual Error |
Greg Clayton | f6b8b58 | 2011-04-13 00:18:08 +0000 | [diff] [blame] | 4791 | SetOptionValue (uint32_t option_idx, const char *option_arg) |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 4792 | { |
| 4793 | Error error; |
Greg Clayton | 3bcdfc0 | 2012-12-04 00:32:51 +0000 | [diff] [blame] | 4794 | const int short_option = m_getopt_table[option_idx].val; |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 4795 | bool success; |
| 4796 | |
| 4797 | switch (short_option) |
| 4798 | { |
| 4799 | case 'c': |
| 4800 | m_class_name = option_arg; |
| 4801 | m_sym_ctx_specified = true; |
| 4802 | break; |
| 4803 | |
| 4804 | case 'e': |
| 4805 | m_line_end = Args::StringToUInt32 (option_arg, UINT_MAX, 0, &success); |
| 4806 | if (!success) |
| 4807 | { |
Greg Clayton | 86edbf4 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 4808 | error.SetErrorStringWithFormat ("invalid end line number: \"%s\"", option_arg); |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 4809 | break; |
| 4810 | } |
| 4811 | m_sym_ctx_specified = true; |
| 4812 | break; |
| 4813 | |
| 4814 | case 'l': |
| 4815 | m_line_start = Args::StringToUInt32 (option_arg, 0, 0, &success); |
| 4816 | if (!success) |
| 4817 | { |
Greg Clayton | 86edbf4 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 4818 | error.SetErrorStringWithFormat ("invalid start line number: \"%s\"", option_arg); |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 4819 | break; |
| 4820 | } |
| 4821 | m_sym_ctx_specified = true; |
| 4822 | break; |
Sean Callanan | d4a7c12 | 2012-02-11 01:22:21 +0000 | [diff] [blame] | 4823 | |
| 4824 | case 'i': |
| 4825 | m_no_inlines = true; |
| 4826 | break; |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 4827 | |
| 4828 | case 'n': |
| 4829 | m_function_name = option_arg; |
| 4830 | m_func_name_type_mask |= eFunctionNameTypeAuto; |
| 4831 | m_sym_ctx_specified = true; |
| 4832 | break; |
| 4833 | |
| 4834 | case 'f': |
| 4835 | m_file_name = option_arg; |
| 4836 | m_sym_ctx_specified = true; |
| 4837 | break; |
| 4838 | case 's': |
| 4839 | m_module_name = option_arg; |
| 4840 | m_sym_ctx_specified = true; |
| 4841 | break; |
| 4842 | case 't' : |
| 4843 | { |
Jim Ingham | 0292f4a | 2011-03-22 01:53:33 +0000 | [diff] [blame] | 4844 | m_thread_id = Args::StringToUInt64(option_arg, LLDB_INVALID_THREAD_ID, 0); |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 4845 | if (m_thread_id == LLDB_INVALID_THREAD_ID) |
Greg Clayton | 86edbf4 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 4846 | error.SetErrorStringWithFormat ("invalid thread id string '%s'", option_arg); |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 4847 | m_thread_specified = true; |
| 4848 | } |
| 4849 | break; |
| 4850 | case 'T': |
| 4851 | m_thread_name = option_arg; |
| 4852 | m_thread_specified = true; |
| 4853 | break; |
| 4854 | case 'q': |
| 4855 | m_queue_name = option_arg; |
| 4856 | m_thread_specified = true; |
| 4857 | break; |
| 4858 | case 'x': |
| 4859 | { |
Jim Ingham | 0292f4a | 2011-03-22 01:53:33 +0000 | [diff] [blame] | 4860 | m_thread_index = Args::StringToUInt32(option_arg, UINT32_MAX, 0); |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 4861 | if (m_thread_id == UINT32_MAX) |
Greg Clayton | 86edbf4 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 4862 | error.SetErrorStringWithFormat ("invalid thread index string '%s'", option_arg); |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 4863 | m_thread_specified = true; |
| 4864 | } |
| 4865 | break; |
Johnny Chen | b1372c0 | 2011-05-02 23:47:55 +0000 | [diff] [blame] | 4866 | case 'o': |
| 4867 | m_use_one_liner = true; |
| 4868 | m_one_liner = option_arg; |
| 4869 | break; |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 4870 | default: |
Greg Clayton | 86edbf4 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 4871 | error.SetErrorStringWithFormat ("unrecognized option %c.", short_option); |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 4872 | break; |
| 4873 | } |
| 4874 | return error; |
| 4875 | } |
| 4876 | |
| 4877 | void |
Greg Clayton | f6b8b58 | 2011-04-13 00:18:08 +0000 | [diff] [blame] | 4878 | OptionParsingStarting () |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 4879 | { |
| 4880 | m_class_name.clear(); |
| 4881 | m_function_name.clear(); |
| 4882 | m_line_start = 0; |
| 4883 | m_line_end = UINT_MAX; |
| 4884 | m_file_name.clear(); |
| 4885 | m_module_name.clear(); |
| 4886 | m_func_name_type_mask = eFunctionNameTypeAuto; |
| 4887 | m_thread_id = LLDB_INVALID_THREAD_ID; |
| 4888 | m_thread_index = UINT32_MAX; |
| 4889 | m_thread_name.clear(); |
| 4890 | m_queue_name.clear(); |
Sean Callanan | d4a7c12 | 2012-02-11 01:22:21 +0000 | [diff] [blame] | 4891 | |
| 4892 | m_no_inlines = false; |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 4893 | m_sym_ctx_specified = false; |
| 4894 | m_thread_specified = false; |
Johnny Chen | b1372c0 | 2011-05-02 23:47:55 +0000 | [diff] [blame] | 4895 | |
| 4896 | m_use_one_liner = false; |
| 4897 | m_one_liner.clear(); |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 4898 | } |
| 4899 | |
| 4900 | |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 4901 | static OptionDefinition g_option_table[]; |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 4902 | |
| 4903 | std::string m_class_name; |
| 4904 | std::string m_function_name; |
| 4905 | uint32_t m_line_start; |
| 4906 | uint32_t m_line_end; |
| 4907 | std::string m_file_name; |
| 4908 | std::string m_module_name; |
| 4909 | uint32_t m_func_name_type_mask; // A pick from lldb::FunctionNameType. |
| 4910 | lldb::tid_t m_thread_id; |
| 4911 | uint32_t m_thread_index; |
| 4912 | std::string m_thread_name; |
| 4913 | std::string m_queue_name; |
| 4914 | bool m_sym_ctx_specified; |
Sean Callanan | d4a7c12 | 2012-02-11 01:22:21 +0000 | [diff] [blame] | 4915 | bool m_no_inlines; |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 4916 | bool m_thread_specified; |
Johnny Chen | b1372c0 | 2011-05-02 23:47:55 +0000 | [diff] [blame] | 4917 | // Instance variables to hold the values for one_liner options. |
| 4918 | bool m_use_one_liner; |
| 4919 | std::string m_one_liner; |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 4920 | }; |
| 4921 | |
| 4922 | Options * |
| 4923 | GetOptions () |
| 4924 | { |
| 4925 | return &m_options; |
| 4926 | } |
| 4927 | |
| 4928 | CommandObjectTargetStopHookAdd (CommandInterpreter &interpreter) : |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 4929 | CommandObjectParsed (interpreter, |
| 4930 | "target stop-hook add ", |
| 4931 | "Add a hook to be executed when the target stops.", |
| 4932 | "target stop-hook add"), |
Greg Clayton | eb0103f | 2011-04-07 22:46:35 +0000 | [diff] [blame] | 4933 | m_options (interpreter) |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 4934 | { |
| 4935 | } |
| 4936 | |
| 4937 | ~CommandObjectTargetStopHookAdd () |
| 4938 | { |
| 4939 | } |
| 4940 | |
| 4941 | static size_t |
| 4942 | ReadCommandsCallbackFunction (void *baton, |
| 4943 | InputReader &reader, |
| 4944 | lldb::InputReaderAction notification, |
| 4945 | const char *bytes, |
| 4946 | size_t bytes_len) |
| 4947 | { |
Caroline Tice | d61c10b | 2011-06-16 16:27:19 +0000 | [diff] [blame] | 4948 | StreamSP out_stream = reader.GetDebugger().GetAsyncOutputStream(); |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 4949 | Target::StopHook *new_stop_hook = ((Target::StopHook *) baton); |
Jim Ingham | c60695a | 2011-05-05 01:03:36 +0000 | [diff] [blame] | 4950 | static bool got_interrupted; |
Caroline Tice | d61c10b | 2011-06-16 16:27:19 +0000 | [diff] [blame] | 4951 | bool batch_mode = reader.GetDebugger().GetCommandInterpreter().GetBatchCommandMode(); |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 4952 | |
| 4953 | switch (notification) |
| 4954 | { |
| 4955 | case eInputReaderActivate: |
Caroline Tice | d61c10b | 2011-06-16 16:27:19 +0000 | [diff] [blame] | 4956 | if (!batch_mode) |
| 4957 | { |
| 4958 | out_stream->Printf ("%s\n", "Enter your stop hook command(s). Type 'DONE' to end."); |
| 4959 | if (reader.GetPrompt()) |
| 4960 | out_stream->Printf ("%s", reader.GetPrompt()); |
| 4961 | out_stream->Flush(); |
| 4962 | } |
Jim Ingham | c60695a | 2011-05-05 01:03:36 +0000 | [diff] [blame] | 4963 | got_interrupted = false; |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 4964 | break; |
| 4965 | |
| 4966 | case eInputReaderDeactivate: |
| 4967 | break; |
| 4968 | |
| 4969 | case eInputReaderReactivate: |
Caroline Tice | d61c10b | 2011-06-16 16:27:19 +0000 | [diff] [blame] | 4970 | if (reader.GetPrompt() && !batch_mode) |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 4971 | { |
Caroline Tice | d61c10b | 2011-06-16 16:27:19 +0000 | [diff] [blame] | 4972 | out_stream->Printf ("%s", reader.GetPrompt()); |
| 4973 | out_stream->Flush(); |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 4974 | } |
Jim Ingham | c60695a | 2011-05-05 01:03:36 +0000 | [diff] [blame] | 4975 | got_interrupted = false; |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 4976 | break; |
| 4977 | |
Caroline Tice | 969ed3d | 2011-05-02 20:41:46 +0000 | [diff] [blame] | 4978 | case eInputReaderAsynchronousOutputWritten: |
| 4979 | break; |
| 4980 | |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 4981 | case eInputReaderGotToken: |
| 4982 | if (bytes && bytes_len && baton) |
| 4983 | { |
| 4984 | StringList *commands = new_stop_hook->GetCommandPointer(); |
| 4985 | if (commands) |
| 4986 | { |
| 4987 | commands->AppendString (bytes, bytes_len); |
| 4988 | } |
| 4989 | } |
Caroline Tice | d61c10b | 2011-06-16 16:27:19 +0000 | [diff] [blame] | 4990 | if (!reader.IsDone() && reader.GetPrompt() && !batch_mode) |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 4991 | { |
Caroline Tice | d61c10b | 2011-06-16 16:27:19 +0000 | [diff] [blame] | 4992 | out_stream->Printf ("%s", reader.GetPrompt()); |
| 4993 | out_stream->Flush(); |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 4994 | } |
| 4995 | break; |
| 4996 | |
| 4997 | case eInputReaderInterrupt: |
| 4998 | { |
| 4999 | // Finish, and cancel the stop hook. |
| 5000 | new_stop_hook->GetTarget()->RemoveStopHookByID(new_stop_hook->GetID()); |
Caroline Tice | d61c10b | 2011-06-16 16:27:19 +0000 | [diff] [blame] | 5001 | if (!batch_mode) |
| 5002 | { |
| 5003 | out_stream->Printf ("Stop hook cancelled.\n"); |
| 5004 | out_stream->Flush(); |
| 5005 | } |
| 5006 | |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5007 | reader.SetIsDone (true); |
| 5008 | } |
Jim Ingham | c60695a | 2011-05-05 01:03:36 +0000 | [diff] [blame] | 5009 | got_interrupted = true; |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5010 | break; |
| 5011 | |
| 5012 | case eInputReaderEndOfFile: |
| 5013 | reader.SetIsDone (true); |
| 5014 | break; |
| 5015 | |
| 5016 | case eInputReaderDone: |
Caroline Tice | d61c10b | 2011-06-16 16:27:19 +0000 | [diff] [blame] | 5017 | if (!got_interrupted && !batch_mode) |
| 5018 | { |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 5019 | out_stream->Printf ("Stop hook #%" PRIu64 " added.\n", new_stop_hook->GetID()); |
Caroline Tice | d61c10b | 2011-06-16 16:27:19 +0000 | [diff] [blame] | 5020 | out_stream->Flush(); |
| 5021 | } |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5022 | break; |
| 5023 | } |
| 5024 | |
| 5025 | return bytes_len; |
| 5026 | } |
| 5027 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 5028 | protected: |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5029 | bool |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 5030 | DoExecute (Args& command, CommandReturnObject &result) |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5031 | { |
| 5032 | Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); |
| 5033 | if (target) |
| 5034 | { |
| 5035 | Target::StopHookSP new_hook_sp; |
| 5036 | target->AddStopHook (new_hook_sp); |
| 5037 | |
| 5038 | // First step, make the specifier. |
Greg Clayton | 7b0992d | 2013-04-18 22:45:39 +0000 | [diff] [blame] | 5039 | std::unique_ptr<SymbolContextSpecifier> specifier_ap; |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5040 | if (m_options.m_sym_ctx_specified) |
| 5041 | { |
| 5042 | specifier_ap.reset(new SymbolContextSpecifier(m_interpreter.GetDebugger().GetSelectedTarget())); |
| 5043 | |
| 5044 | if (!m_options.m_module_name.empty()) |
| 5045 | { |
| 5046 | specifier_ap->AddSpecification (m_options.m_module_name.c_str(), SymbolContextSpecifier::eModuleSpecified); |
| 5047 | } |
| 5048 | |
| 5049 | if (!m_options.m_class_name.empty()) |
| 5050 | { |
| 5051 | specifier_ap->AddSpecification (m_options.m_class_name.c_str(), SymbolContextSpecifier::eClassOrNamespaceSpecified); |
| 5052 | } |
| 5053 | |
| 5054 | if (!m_options.m_file_name.empty()) |
| 5055 | { |
| 5056 | specifier_ap->AddSpecification (m_options.m_file_name.c_str(), SymbolContextSpecifier::eFileSpecified); |
| 5057 | } |
| 5058 | |
| 5059 | if (m_options.m_line_start != 0) |
| 5060 | { |
| 5061 | specifier_ap->AddLineSpecification (m_options.m_line_start, SymbolContextSpecifier::eLineStartSpecified); |
| 5062 | } |
| 5063 | |
| 5064 | if (m_options.m_line_end != UINT_MAX) |
| 5065 | { |
| 5066 | specifier_ap->AddLineSpecification (m_options.m_line_end, SymbolContextSpecifier::eLineEndSpecified); |
| 5067 | } |
| 5068 | |
| 5069 | if (!m_options.m_function_name.empty()) |
| 5070 | { |
| 5071 | specifier_ap->AddSpecification (m_options.m_function_name.c_str(), SymbolContextSpecifier::eFunctionSpecified); |
| 5072 | } |
| 5073 | } |
| 5074 | |
| 5075 | if (specifier_ap.get()) |
| 5076 | new_hook_sp->SetSpecifier (specifier_ap.release()); |
| 5077 | |
| 5078 | // Next see if any of the thread options have been entered: |
| 5079 | |
| 5080 | if (m_options.m_thread_specified) |
| 5081 | { |
| 5082 | ThreadSpec *thread_spec = new ThreadSpec(); |
| 5083 | |
| 5084 | if (m_options.m_thread_id != LLDB_INVALID_THREAD_ID) |
| 5085 | { |
| 5086 | thread_spec->SetTID (m_options.m_thread_id); |
| 5087 | } |
| 5088 | |
| 5089 | if (m_options.m_thread_index != UINT32_MAX) |
| 5090 | thread_spec->SetIndex (m_options.m_thread_index); |
| 5091 | |
| 5092 | if (!m_options.m_thread_name.empty()) |
| 5093 | thread_spec->SetName (m_options.m_thread_name.c_str()); |
| 5094 | |
| 5095 | if (!m_options.m_queue_name.empty()) |
| 5096 | thread_spec->SetQueueName (m_options.m_queue_name.c_str()); |
| 5097 | |
| 5098 | new_hook_sp->SetThreadSpecifier (thread_spec); |
| 5099 | |
| 5100 | } |
Johnny Chen | b1372c0 | 2011-05-02 23:47:55 +0000 | [diff] [blame] | 5101 | if (m_options.m_use_one_liner) |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5102 | { |
Johnny Chen | b1372c0 | 2011-05-02 23:47:55 +0000 | [diff] [blame] | 5103 | // Use one-liner. |
| 5104 | new_hook_sp->GetCommandPointer()->AppendString (m_options.m_one_liner.c_str()); |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 5105 | result.AppendMessageWithFormat("Stop hook #%" PRIu64 " added.\n", new_hook_sp->GetID()); |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5106 | } |
Johnny Chen | b1372c0 | 2011-05-02 23:47:55 +0000 | [diff] [blame] | 5107 | else |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5108 | { |
Johnny Chen | b1372c0 | 2011-05-02 23:47:55 +0000 | [diff] [blame] | 5109 | // Otherwise gather up the command list, we'll push an input reader and suck the data from that directly into |
| 5110 | // the new stop hook's command string. |
| 5111 | InputReaderSP reader_sp (new InputReader(m_interpreter.GetDebugger())); |
| 5112 | if (!reader_sp) |
| 5113 | { |
| 5114 | result.AppendError("out of memory\n"); |
| 5115 | result.SetStatus (eReturnStatusFailed); |
| 5116 | target->RemoveStopHookByID (new_hook_sp->GetID()); |
| 5117 | return false; |
| 5118 | } |
| 5119 | |
| 5120 | Error err (reader_sp->Initialize (CommandObjectTargetStopHookAdd::ReadCommandsCallbackFunction, |
| 5121 | new_hook_sp.get(), // baton |
| 5122 | eInputReaderGranularityLine, // token size, to pass to callback function |
| 5123 | "DONE", // end token |
| 5124 | "> ", // prompt |
| 5125 | true)); // echo input |
| 5126 | if (!err.Success()) |
| 5127 | { |
| 5128 | result.AppendError (err.AsCString()); |
| 5129 | result.SetStatus (eReturnStatusFailed); |
| 5130 | target->RemoveStopHookByID (new_hook_sp->GetID()); |
| 5131 | return false; |
| 5132 | } |
| 5133 | m_interpreter.GetDebugger().PushInputReader (reader_sp); |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5134 | } |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5135 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 5136 | } |
| 5137 | else |
| 5138 | { |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 5139 | result.AppendError ("invalid target\n"); |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5140 | result.SetStatus (eReturnStatusFailed); |
| 5141 | } |
| 5142 | |
| 5143 | return result.Succeeded(); |
| 5144 | } |
| 5145 | private: |
| 5146 | CommandOptions m_options; |
| 5147 | }; |
| 5148 | |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 5149 | OptionDefinition |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5150 | CommandObjectTargetStopHookAdd::CommandOptions::g_option_table[] = |
| 5151 | { |
Filipe Cabecinhas | bc6e85c | 2012-09-11 16:09:27 +0000 | [diff] [blame] | 5152 | { LLDB_OPT_SET_ALL, false, "one-liner", 'o', required_argument, NULL, 0, eArgTypeOneLiner, |
Johnny Chen | b1372c0 | 2011-05-02 23:47:55 +0000 | [diff] [blame] | 5153 | "Specify a one-line breakpoint command inline. Be sure to surround it with quotes." }, |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5154 | { LLDB_OPT_SET_ALL, false, "shlib", 's', required_argument, NULL, CommandCompletions::eModuleCompletion, eArgTypeShlibName, |
| 5155 | "Set the module within which the stop-hook is to be run."}, |
Filipe Cabecinhas | bc6e85c | 2012-09-11 16:09:27 +0000 | [diff] [blame] | 5156 | { LLDB_OPT_SET_ALL, false, "thread-index", 'x', required_argument, NULL, 0, eArgTypeThreadIndex, |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5157 | "The stop hook is run only for the thread whose index matches this argument."}, |
Filipe Cabecinhas | bc6e85c | 2012-09-11 16:09:27 +0000 | [diff] [blame] | 5158 | { LLDB_OPT_SET_ALL, false, "thread-id", 't', required_argument, NULL, 0, eArgTypeThreadID, |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5159 | "The stop hook is run only for the thread whose TID matches this argument."}, |
Filipe Cabecinhas | bc6e85c | 2012-09-11 16:09:27 +0000 | [diff] [blame] | 5160 | { LLDB_OPT_SET_ALL, false, "thread-name", 'T', required_argument, NULL, 0, eArgTypeThreadName, |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5161 | "The stop hook is run only for the thread whose thread name matches this argument."}, |
Filipe Cabecinhas | bc6e85c | 2012-09-11 16:09:27 +0000 | [diff] [blame] | 5162 | { LLDB_OPT_SET_ALL, false, "queue-name", 'q', required_argument, NULL, 0, eArgTypeQueueName, |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5163 | "The stop hook is run only for threads in the queue whose name is given by this argument."}, |
| 5164 | { LLDB_OPT_SET_1, false, "file", 'f', required_argument, NULL, CommandCompletions::eSourceFileCompletion, eArgTypeFilename, |
| 5165 | "Specify the source file within which the stop-hook is to be run." }, |
| 5166 | { LLDB_OPT_SET_1, false, "start-line", 'l', required_argument, NULL, 0, eArgTypeLineNum, |
| 5167 | "Set the start of the line range for which the stop-hook is to be run."}, |
| 5168 | { LLDB_OPT_SET_1, false, "end-line", 'e', required_argument, NULL, 0, eArgTypeLineNum, |
| 5169 | "Set the end of the line range for which the stop-hook is to be run."}, |
Filipe Cabecinhas | bc6e85c | 2012-09-11 16:09:27 +0000 | [diff] [blame] | 5170 | { LLDB_OPT_SET_2, false, "classname", 'c', required_argument, NULL, 0, eArgTypeClassName, |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5171 | "Specify the class within which the stop-hook is to be run." }, |
| 5172 | { LLDB_OPT_SET_3, false, "name", 'n', required_argument, NULL, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName, |
| 5173 | "Set the function name within which the stop hook will be run." }, |
| 5174 | { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL } |
| 5175 | }; |
| 5176 | |
| 5177 | #pragma mark CommandObjectTargetStopHookDelete |
| 5178 | |
| 5179 | //------------------------------------------------------------------------- |
| 5180 | // CommandObjectTargetStopHookDelete |
| 5181 | //------------------------------------------------------------------------- |
| 5182 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 5183 | class CommandObjectTargetStopHookDelete : public CommandObjectParsed |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5184 | { |
| 5185 | public: |
| 5186 | |
| 5187 | CommandObjectTargetStopHookDelete (CommandInterpreter &interpreter) : |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 5188 | CommandObjectParsed (interpreter, |
| 5189 | "target stop-hook delete", |
| 5190 | "Delete a stop-hook.", |
| 5191 | "target stop-hook delete [<idx>]") |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5192 | { |
| 5193 | } |
| 5194 | |
| 5195 | ~CommandObjectTargetStopHookDelete () |
| 5196 | { |
| 5197 | } |
| 5198 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 5199 | protected: |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5200 | bool |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 5201 | DoExecute (Args& command, CommandReturnObject &result) |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5202 | { |
| 5203 | Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); |
| 5204 | if (target) |
| 5205 | { |
| 5206 | // FIXME: see if we can use the breakpoint id style parser? |
| 5207 | size_t num_args = command.GetArgumentCount(); |
| 5208 | if (num_args == 0) |
| 5209 | { |
| 5210 | if (!m_interpreter.Confirm ("Delete all stop hooks?", true)) |
| 5211 | { |
| 5212 | result.SetStatus (eReturnStatusFailed); |
| 5213 | return false; |
| 5214 | } |
| 5215 | else |
| 5216 | { |
| 5217 | target->RemoveAllStopHooks(); |
| 5218 | } |
| 5219 | } |
| 5220 | else |
| 5221 | { |
| 5222 | bool success; |
| 5223 | for (size_t i = 0; i < num_args; i++) |
| 5224 | { |
| 5225 | lldb::user_id_t user_id = Args::StringToUInt32 (command.GetArgumentAtIndex(i), 0, 0, &success); |
| 5226 | if (!success) |
| 5227 | { |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 5228 | result.AppendErrorWithFormat ("invalid stop hook id: \"%s\".\n", command.GetArgumentAtIndex(i)); |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5229 | result.SetStatus(eReturnStatusFailed); |
| 5230 | return false; |
| 5231 | } |
| 5232 | success = target->RemoveStopHookByID (user_id); |
| 5233 | if (!success) |
| 5234 | { |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 5235 | result.AppendErrorWithFormat ("unknown stop hook id: \"%s\".\n", command.GetArgumentAtIndex(i)); |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5236 | result.SetStatus(eReturnStatusFailed); |
| 5237 | return false; |
| 5238 | } |
| 5239 | } |
| 5240 | } |
| 5241 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 5242 | } |
| 5243 | else |
| 5244 | { |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 5245 | result.AppendError ("invalid target\n"); |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5246 | result.SetStatus (eReturnStatusFailed); |
| 5247 | } |
| 5248 | |
| 5249 | return result.Succeeded(); |
| 5250 | } |
| 5251 | }; |
| 5252 | #pragma mark CommandObjectTargetStopHookEnableDisable |
| 5253 | |
| 5254 | //------------------------------------------------------------------------- |
| 5255 | // CommandObjectTargetStopHookEnableDisable |
| 5256 | //------------------------------------------------------------------------- |
| 5257 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 5258 | class CommandObjectTargetStopHookEnableDisable : public CommandObjectParsed |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5259 | { |
| 5260 | public: |
| 5261 | |
| 5262 | CommandObjectTargetStopHookEnableDisable (CommandInterpreter &interpreter, bool enable, const char *name, const char *help, const char *syntax) : |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 5263 | CommandObjectParsed (interpreter, |
| 5264 | name, |
| 5265 | help, |
| 5266 | syntax), |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5267 | m_enable (enable) |
| 5268 | { |
| 5269 | } |
| 5270 | |
| 5271 | ~CommandObjectTargetStopHookEnableDisable () |
| 5272 | { |
| 5273 | } |
| 5274 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 5275 | protected: |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5276 | bool |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 5277 | DoExecute (Args& command, CommandReturnObject &result) |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5278 | { |
| 5279 | Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); |
| 5280 | if (target) |
| 5281 | { |
| 5282 | // FIXME: see if we can use the breakpoint id style parser? |
| 5283 | size_t num_args = command.GetArgumentCount(); |
| 5284 | bool success; |
| 5285 | |
| 5286 | if (num_args == 0) |
| 5287 | { |
| 5288 | target->SetAllStopHooksActiveState (m_enable); |
| 5289 | } |
| 5290 | else |
| 5291 | { |
| 5292 | for (size_t i = 0; i < num_args; i++) |
| 5293 | { |
| 5294 | lldb::user_id_t user_id = Args::StringToUInt32 (command.GetArgumentAtIndex(i), 0, 0, &success); |
| 5295 | if (!success) |
| 5296 | { |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 5297 | result.AppendErrorWithFormat ("invalid stop hook id: \"%s\".\n", command.GetArgumentAtIndex(i)); |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5298 | result.SetStatus(eReturnStatusFailed); |
| 5299 | return false; |
| 5300 | } |
| 5301 | success = target->SetStopHookActiveStateByID (user_id, m_enable); |
| 5302 | if (!success) |
| 5303 | { |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 5304 | result.AppendErrorWithFormat ("unknown stop hook id: \"%s\".\n", command.GetArgumentAtIndex(i)); |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5305 | result.SetStatus(eReturnStatusFailed); |
| 5306 | return false; |
| 5307 | } |
| 5308 | } |
| 5309 | } |
| 5310 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 5311 | } |
| 5312 | else |
| 5313 | { |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 5314 | result.AppendError ("invalid target\n"); |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5315 | result.SetStatus (eReturnStatusFailed); |
| 5316 | } |
| 5317 | return result.Succeeded(); |
| 5318 | } |
| 5319 | private: |
| 5320 | bool m_enable; |
| 5321 | }; |
| 5322 | |
| 5323 | #pragma mark CommandObjectTargetStopHookList |
| 5324 | |
| 5325 | //------------------------------------------------------------------------- |
| 5326 | // CommandObjectTargetStopHookList |
| 5327 | //------------------------------------------------------------------------- |
| 5328 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 5329 | class CommandObjectTargetStopHookList : public CommandObjectParsed |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5330 | { |
| 5331 | public: |
| 5332 | |
| 5333 | CommandObjectTargetStopHookList (CommandInterpreter &interpreter) : |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 5334 | CommandObjectParsed (interpreter, |
| 5335 | "target stop-hook list", |
| 5336 | "List all stop-hooks.", |
| 5337 | "target stop-hook list [<type>]") |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5338 | { |
| 5339 | } |
| 5340 | |
| 5341 | ~CommandObjectTargetStopHookList () |
| 5342 | { |
| 5343 | } |
| 5344 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 5345 | protected: |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5346 | bool |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 5347 | DoExecute (Args& command, CommandReturnObject &result) |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5348 | { |
| 5349 | Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); |
Johnny Chen | faa5c13 | 2011-11-29 23:56:14 +0000 | [diff] [blame] | 5350 | if (!target) |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5351 | { |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 5352 | result.AppendError ("invalid target\n"); |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5353 | result.SetStatus (eReturnStatusFailed); |
Jason Molenda | effcd2a | 2011-09-23 21:15:42 +0000 | [diff] [blame] | 5354 | return result.Succeeded(); |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5355 | } |
| 5356 | |
| 5357 | size_t num_hooks = target->GetNumStopHooks (); |
| 5358 | if (num_hooks == 0) |
| 5359 | { |
| 5360 | result.GetOutputStream().PutCString ("No stop hooks.\n"); |
| 5361 | } |
| 5362 | else |
| 5363 | { |
| 5364 | for (size_t i = 0; i < num_hooks; i++) |
| 5365 | { |
| 5366 | Target::StopHookSP this_hook = target->GetStopHookAtIndex (i); |
| 5367 | if (i > 0) |
| 5368 | result.GetOutputStream().PutCString ("\n"); |
| 5369 | this_hook->GetDescription (&(result.GetOutputStream()), eDescriptionLevelFull); |
| 5370 | } |
| 5371 | } |
Johnny Chen | d0cff1e | 2011-11-30 19:09:20 +0000 | [diff] [blame] | 5372 | result.SetStatus (eReturnStatusSuccessFinishResult); |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5373 | return result.Succeeded(); |
| 5374 | } |
| 5375 | }; |
| 5376 | |
| 5377 | #pragma mark CommandObjectMultiwordTargetStopHooks |
| 5378 | //------------------------------------------------------------------------- |
| 5379 | // CommandObjectMultiwordTargetStopHooks |
| 5380 | //------------------------------------------------------------------------- |
| 5381 | |
| 5382 | class CommandObjectMultiwordTargetStopHooks : public CommandObjectMultiword |
| 5383 | { |
| 5384 | public: |
| 5385 | |
| 5386 | CommandObjectMultiwordTargetStopHooks (CommandInterpreter &interpreter) : |
| 5387 | CommandObjectMultiword (interpreter, |
| 5388 | "target stop-hook", |
| 5389 | "A set of commands for operating on debugger target stop-hooks.", |
| 5390 | "target stop-hook <subcommand> [<subcommand-options>]") |
| 5391 | { |
| 5392 | LoadSubCommand ("add", CommandObjectSP (new CommandObjectTargetStopHookAdd (interpreter))); |
| 5393 | LoadSubCommand ("delete", CommandObjectSP (new CommandObjectTargetStopHookDelete (interpreter))); |
| 5394 | LoadSubCommand ("disable", CommandObjectSP (new CommandObjectTargetStopHookEnableDisable (interpreter, |
| 5395 | false, |
| 5396 | "target stop-hook disable [<id>]", |
| 5397 | "Disable a stop-hook.", |
| 5398 | "target stop-hook disable"))); |
| 5399 | LoadSubCommand ("enable", CommandObjectSP (new CommandObjectTargetStopHookEnableDisable (interpreter, |
| 5400 | true, |
| 5401 | "target stop-hook enable [<id>]", |
| 5402 | "Enable a stop-hook.", |
| 5403 | "target stop-hook enable"))); |
| 5404 | LoadSubCommand ("list", CommandObjectSP (new CommandObjectTargetStopHookList (interpreter))); |
| 5405 | } |
| 5406 | |
| 5407 | ~CommandObjectMultiwordTargetStopHooks() |
| 5408 | { |
| 5409 | } |
| 5410 | }; |
| 5411 | |
| 5412 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5413 | |
| 5414 | #pragma mark CommandObjectMultiwordTarget |
| 5415 | |
| 5416 | //------------------------------------------------------------------------- |
| 5417 | // CommandObjectMultiwordTarget |
| 5418 | //------------------------------------------------------------------------- |
| 5419 | |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 5420 | CommandObjectMultiwordTarget::CommandObjectMultiwordTarget (CommandInterpreter &interpreter) : |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 5421 | CommandObjectMultiword (interpreter, |
| 5422 | "target", |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5423 | "A set of commands for operating on debugger targets.", |
| 5424 | "target <subcommand> [<subcommand-options>]") |
| 5425 | { |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 5426 | |
| 5427 | LoadSubCommand ("create", CommandObjectSP (new CommandObjectTargetCreate (interpreter))); |
Greg Clayton | 3418c85 | 2011-08-10 02:10:13 +0000 | [diff] [blame] | 5428 | LoadSubCommand ("delete", CommandObjectSP (new CommandObjectTargetDelete (interpreter))); |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 5429 | LoadSubCommand ("list", CommandObjectSP (new CommandObjectTargetList (interpreter))); |
| 5430 | LoadSubCommand ("select", CommandObjectSP (new CommandObjectTargetSelect (interpreter))); |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5431 | LoadSubCommand ("stop-hook", CommandObjectSP (new CommandObjectMultiwordTargetStopHooks (interpreter))); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 5432 | LoadSubCommand ("modules", CommandObjectSP (new CommandObjectTargetModules (interpreter))); |
Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 5433 | LoadSubCommand ("symbols", CommandObjectSP (new CommandObjectTargetSymbols (interpreter))); |
Greg Clayton | 644247c | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 5434 | LoadSubCommand ("variable", CommandObjectSP (new CommandObjectTargetVariable (interpreter))); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5435 | } |
| 5436 | |
| 5437 | CommandObjectMultiwordTarget::~CommandObjectMultiwordTarget () |
| 5438 | { |
| 5439 | } |
| 5440 | |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 5441 | |