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