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