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