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