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