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