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 | |
| 10 | #include "CommandObjectTarget.h" |
| 11 | |
| 12 | // C Includes |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 13 | // C++ Includes |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 14 | #include <cerrno> |
| 15 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 16 | // Other libraries and framework includes |
| 17 | // Project includes |
Jim Ingham | 40af72e | 2010-06-15 19:49:27 +0000 | [diff] [blame] | 18 | #include "lldb/Interpreter/Args.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 19 | #include "lldb/Core/Debugger.h" |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 20 | #include "lldb/Core/IOHandler.h" |
Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 21 | #include "lldb/Core/Module.h" |
| 22 | #include "lldb/Core/ModuleSpec.h" |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 23 | #include "lldb/Core/Section.h" |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 24 | #include "lldb/Core/State.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 25 | #include "lldb/Core/Timer.h" |
Greg Clayton | 644247c | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 26 | #include "lldb/Core/ValueObjectVariable.h" |
Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 27 | #include "lldb/DataFormatters/ValueObjectPrinter.h" |
Vince Harron | 5275aaa | 2015-01-15 20:08:35 +0000 | [diff] [blame] | 28 | #include "lldb/Host/StringConvert.h" |
Greg Clayton | c8f814d | 2012-09-27 03:13:55 +0000 | [diff] [blame] | 29 | #include "lldb/Host/Symbols.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 30 | #include "lldb/Interpreter/CommandInterpreter.h" |
| 31 | #include "lldb/Interpreter/CommandReturnObject.h" |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 32 | #include "lldb/Interpreter/Options.h" |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 33 | #include "lldb/Interpreter/OptionGroupArchitecture.h" |
Greg Clayton | aa149cb | 2011-08-11 02:48:45 +0000 | [diff] [blame] | 34 | #include "lldb/Interpreter/OptionGroupBoolean.h" |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 35 | #include "lldb/Interpreter/OptionGroupFile.h" |
Greg Clayton | 1deb796 | 2011-10-25 06:44:01 +0000 | [diff] [blame] | 36 | #include "lldb/Interpreter/OptionGroupFormat.h" |
Greg Clayton | 715c236 | 2011-07-07 04:38:25 +0000 | [diff] [blame] | 37 | #include "lldb/Interpreter/OptionGroupVariable.h" |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 38 | #include "lldb/Interpreter/OptionGroupPlatform.h" |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 39 | #include "lldb/Interpreter/OptionGroupUInt64.h" |
| 40 | #include "lldb/Interpreter/OptionGroupUUID.h" |
Jason Molenda | c6127dd | 2014-11-21 02:25:15 +0000 | [diff] [blame] | 41 | #include "lldb/Interpreter/OptionGroupString.h" |
Greg Clayton | 644247c | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 42 | #include "lldb/Interpreter/OptionGroupValueObjectDisplay.h" |
Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 43 | #include "lldb/Symbol/CompileUnit.h" |
Jason Molenda | 380241a | 2012-07-12 00:20:07 +0000 | [diff] [blame] | 44 | #include "lldb/Symbol/FuncUnwinders.h" |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 45 | #include "lldb/Symbol/LineTable.h" |
| 46 | #include "lldb/Symbol/ObjectFile.h" |
| 47 | #include "lldb/Symbol/SymbolFile.h" |
| 48 | #include "lldb/Symbol/SymbolVendor.h" |
Jason Molenda | 380241a | 2012-07-12 00:20:07 +0000 | [diff] [blame] | 49 | #include "lldb/Symbol/UnwindPlan.h" |
Greg Clayton | 644247c | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 50 | #include "lldb/Symbol/VariableList.h" |
Zachary Turner | 32abc6e | 2015-03-03 19:23:09 +0000 | [diff] [blame] | 51 | #include "lldb/Target/ABI.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 52 | #include "lldb/Target/Process.h" |
Greg Clayton | d5944cd | 2013-12-06 01:12:00 +0000 | [diff] [blame] | 53 | #include "lldb/Target/SectionLoadList.h" |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 54 | #include "lldb/Target/StackFrame.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 55 | #include "lldb/Target/Thread.h" |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 56 | #include "lldb/Target/ThreadSpec.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 57 | |
| 58 | using namespace lldb; |
| 59 | using namespace lldb_private; |
| 60 | |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 61 | static void |
| 62 | DumpTargetInfo (uint32_t target_idx, Target *target, const char *prefix_cstr, bool show_stopped_process_status, Stream &strm) |
| 63 | { |
Greg Clayton | 176761e | 2011-04-19 04:19:37 +0000 | [diff] [blame] | 64 | const ArchSpec &target_arch = target->GetArchitecture(); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 65 | |
Greg Clayton | aa149cb | 2011-08-11 02:48:45 +0000 | [diff] [blame] | 66 | Module *exe_module = target->GetExecutableModulePointer(); |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 67 | char exe_path[PATH_MAX]; |
| 68 | bool exe_valid = false; |
Greg Clayton | aa149cb | 2011-08-11 02:48:45 +0000 | [diff] [blame] | 69 | if (exe_module) |
| 70 | exe_valid = exe_module->GetFileSpec().GetPath (exe_path, sizeof(exe_path)); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 71 | |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 72 | if (!exe_valid) |
| 73 | ::strcpy (exe_path, "<none>"); |
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 | 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] | 76 | |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 77 | uint32_t properties = 0; |
| 78 | if (target_arch.IsValid()) |
| 79 | { |
Todd Fiala | 7df337f | 2015-10-13 23:41:19 +0000 | [diff] [blame] | 80 | strm.Printf ("%sarch=", properties++ > 0 ? ", " : " ( "); |
| 81 | target_arch.DumpTriple (strm); |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 82 | properties++; |
| 83 | } |
| 84 | PlatformSP platform_sp (target->GetPlatform()); |
| 85 | if (platform_sp) |
Greg Clayton | 57abc5d | 2013-05-10 21:47:16 +0000 | [diff] [blame] | 86 | strm.Printf ("%splatform=%s", properties++ > 0 ? ", " : " ( ", platform_sp->GetName().GetCString()); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 87 | |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 88 | ProcessSP process_sp (target->GetProcessSP()); |
| 89 | bool show_process_status = false; |
| 90 | if (process_sp) |
| 91 | { |
| 92 | lldb::pid_t pid = process_sp->GetID(); |
| 93 | StateType state = process_sp->GetState(); |
| 94 | if (show_stopped_process_status) |
Greg Clayton | 2637f82 | 2011-11-17 01:23:07 +0000 | [diff] [blame] | 95 | show_process_status = StateIsStoppedState(state, true); |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 96 | const char *state_cstr = StateAsCString (state); |
| 97 | if (pid != LLDB_INVALID_PROCESS_ID) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 98 | strm.Printf ("%spid=%" PRIu64, properties++ > 0 ? ", " : " ( ", pid); |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 99 | strm.Printf ("%sstate=%s", properties++ > 0 ? ", " : " ( ", state_cstr); |
| 100 | } |
| 101 | if (properties > 0) |
| 102 | strm.PutCString (" )\n"); |
| 103 | else |
| 104 | strm.EOL(); |
| 105 | if (show_process_status) |
| 106 | { |
| 107 | const bool only_threads_with_stop_reason = true; |
| 108 | const uint32_t start_frame = 0; |
| 109 | const uint32_t num_frames = 1; |
| 110 | const uint32_t num_frames_with_source = 1; |
| 111 | process_sp->GetStatus (strm); |
| 112 | process_sp->GetThreadStatus (strm, |
| 113 | only_threads_with_stop_reason, |
| 114 | start_frame, |
| 115 | num_frames, |
| 116 | num_frames_with_source); |
| 117 | |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | static uint32_t |
| 122 | DumpTargetList (TargetList &target_list, bool show_stopped_process_status, Stream &strm) |
| 123 | { |
| 124 | const uint32_t num_targets = target_list.GetNumTargets(); |
| 125 | if (num_targets) |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 126 | { |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 127 | TargetSP selected_target_sp (target_list.GetSelectedTarget()); |
| 128 | strm.PutCString ("Current targets:\n"); |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 129 | for (uint32_t i = 0; i < num_targets; ++i) |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 130 | { |
| 131 | TargetSP target_sp (target_list.GetTargetAtIndex (i)); |
| 132 | if (target_sp) |
| 133 | { |
| 134 | bool is_selected = target_sp.get() == selected_target_sp.get(); |
| 135 | DumpTargetInfo (i, |
| 136 | target_sp.get(), |
| 137 | is_selected ? "* " : " ", |
| 138 | show_stopped_process_status, |
| 139 | strm); |
| 140 | } |
| 141 | } |
| 142 | } |
| 143 | return num_targets; |
| 144 | } |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 145 | |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 146 | #pragma mark CommandObjectTargetCreate |
| 147 | |
| 148 | //------------------------------------------------------------------------- |
| 149 | // "target create" |
| 150 | //------------------------------------------------------------------------- |
| 151 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 152 | class CommandObjectTargetCreate : public CommandObjectParsed |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 153 | { |
| 154 | public: |
| 155 | CommandObjectTargetCreate(CommandInterpreter &interpreter) : |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 156 | CommandObjectParsed(interpreter, |
| 157 | "target create", |
| 158 | "Create a target using the argument as the main executable.", |
| 159 | nullptr), |
Todd Fiala | e1cfbc7 | 2016-08-11 23:51:28 +0000 | [diff] [blame] | 160 | m_option_group (), |
Greg Clayton | 644247c | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 161 | m_arch_option (), |
Greg Clayton | 1c5f186 | 2012-11-30 19:05:35 +0000 | [diff] [blame] | 162 | 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] | 163 | 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] | 164 | 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] | 165 | 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] | 166 | 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] | 167 | { |
| 168 | CommandArgumentEntry arg; |
| 169 | CommandArgumentData file_arg; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 170 | |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 171 | // Define the first (and only) variant of this arg. |
| 172 | file_arg.arg_type = eArgTypeFilename; |
| 173 | file_arg.arg_repetition = eArgRepeatPlain; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 174 | |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 175 | // There is only one variant this argument could be; put it into the argument entry. |
| 176 | arg.push_back (file_arg); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 177 | |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 178 | // Push the data for the first argument into the m_arguments vector. |
| 179 | m_arguments.push_back (arg); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 180 | |
Greg Clayton | 644247c | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 181 | m_option_group.Append (&m_arch_option, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1); |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 182 | 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] | 183 | 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] | 184 | 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] | 185 | 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] | 186 | 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] | 187 | m_option_group.Finalize(); |
| 188 | } |
| 189 | |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 190 | ~CommandObjectTargetCreate() override = default; |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 191 | |
| 192 | Options * |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 193 | GetOptions () override |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 194 | { |
| 195 | return &m_option_group; |
| 196 | } |
| 197 | |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 198 | int |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 199 | HandleArgumentCompletion (Args &input, |
| 200 | int &cursor_index, |
| 201 | int &cursor_char_position, |
| 202 | OptionElementVector &opt_element_vector, |
| 203 | int match_start_point, |
| 204 | int max_return_elements, |
| 205 | bool &word_complete, |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 206 | StringList &matches) override |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 207 | { |
| 208 | std::string completion_str (input.GetArgumentAtIndex(cursor_index)); |
| 209 | completion_str.erase (cursor_char_position); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 210 | |
Todd Fiala | e1cfbc7 | 2016-08-11 23:51:28 +0000 | [diff] [blame] | 211 | CommandCompletions::InvokeCommonCompletionCallbacks(GetCommandInterpreter(), |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 212 | CommandCompletions::eDiskFileCompletion, |
| 213 | completion_str.c_str(), |
| 214 | match_start_point, |
| 215 | max_return_elements, |
| 216 | nullptr, |
| 217 | word_complete, |
| 218 | matches); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 219 | return matches.GetSize(); |
| 220 | } |
| 221 | |
| 222 | protected: |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 223 | bool |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 224 | DoExecute (Args& command, CommandReturnObject &result) override |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 225 | { |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 226 | const size_t argc = command.GetArgumentCount(); |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 227 | FileSpec core_file (m_core_file.GetOptionValue().GetCurrentValue()); |
Jim Ingham | bf22b96 | 2013-07-11 01:47:46 +0000 | [diff] [blame] | 228 | FileSpec remote_file (m_remote_file.GetOptionValue().GetCurrentValue()); |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 229 | |
Greg Clayton | 5acc125 | 2014-08-15 18:00:45 +0000 | [diff] [blame] | 230 | if (core_file) |
| 231 | { |
| 232 | if (!core_file.Exists()) |
| 233 | { |
| 234 | result.AppendErrorWithFormat("core file '%s' doesn't exist", core_file.GetPath().c_str()); |
| 235 | result.SetStatus (eReturnStatusFailed); |
| 236 | return false; |
| 237 | |
| 238 | } |
| 239 | if (!core_file.Readable()) |
| 240 | { |
| 241 | result.AppendErrorWithFormat("core file '%s' is not readable", core_file.GetPath().c_str()); |
| 242 | result.SetStatus (eReturnStatusFailed); |
| 243 | return false; |
| 244 | } |
| 245 | } |
| 246 | |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 247 | if (argc == 1 || core_file || remote_file) |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 248 | { |
Greg Clayton | 1c5f186 | 2012-11-30 19:05:35 +0000 | [diff] [blame] | 249 | FileSpec symfile (m_symbol_file.GetOptionValue().GetCurrentValue()); |
| 250 | if (symfile) |
| 251 | { |
Greg Clayton | 5acc125 | 2014-08-15 18:00:45 +0000 | [diff] [blame] | 252 | if (symfile.Exists()) |
| 253 | { |
| 254 | if (!symfile.Readable()) |
| 255 | { |
Adrian McCarthy | f7d1893 | 2015-11-20 23:09:11 +0000 | [diff] [blame] | 256 | result.AppendErrorWithFormat("symbol file '%s' is not readable", symfile.GetPath().c_str()); |
Greg Clayton | 5acc125 | 2014-08-15 18:00:45 +0000 | [diff] [blame] | 257 | result.SetStatus (eReturnStatusFailed); |
| 258 | return false; |
| 259 | } |
| 260 | } |
| 261 | else |
Greg Clayton | 1c5f186 | 2012-11-30 19:05:35 +0000 | [diff] [blame] | 262 | { |
| 263 | char symfile_path[PATH_MAX]; |
| 264 | symfile.GetPath(symfile_path, sizeof(symfile_path)); |
| 265 | result.AppendErrorWithFormat("invalid symbol file path '%s'", symfile_path); |
| 266 | result.SetStatus (eReturnStatusFailed); |
| 267 | return false; |
| 268 | } |
| 269 | } |
| 270 | |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 271 | const char *file_path = command.GetArgumentAtIndex(0); |
Zachary Turner | f343968f | 2016-08-09 23:06:08 +0000 | [diff] [blame] | 272 | Timer scoped_timer(LLVM_PRETTY_FUNCTION, "(lldb) target create '%s'", file_path); |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 273 | FileSpec file_spec; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 274 | |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 275 | if (file_path) |
| 276 | file_spec.SetFile (file_path, true); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 277 | |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 278 | bool must_set_platform_path = false; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 279 | |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 280 | Debugger &debugger = m_interpreter.GetDebugger(); |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 281 | |
| 282 | TargetSP target_sp; |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 283 | const char *arch_cstr = m_arch_option.GetArchitectureName(); |
Greg Clayton | 1c5f186 | 2012-11-30 19:05:35 +0000 | [diff] [blame] | 284 | const bool get_dependent_files = m_add_dependents.GetOptionValue().GetCurrentValue(); |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 285 | Error error(debugger.GetTargetList().CreateTarget(debugger, |
| 286 | file_path, |
| 287 | arch_cstr, |
| 288 | get_dependent_files, |
| 289 | nullptr, |
| 290 | target_sp)); |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 291 | |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 292 | if (target_sp) |
| 293 | { |
Greg Clayton | d26a1e5 | 2015-01-28 22:08:17 +0000 | [diff] [blame] | 294 | // Only get the platform after we create the target because we might have |
| 295 | // switched platforms depending on what the arguments were to CreateTarget() |
| 296 | // we can't rely on the selected platform. |
| 297 | |
| 298 | PlatformSP platform_sp = target_sp->GetPlatform(); |
| 299 | |
| 300 | if (remote_file) |
| 301 | { |
| 302 | if (platform_sp) |
| 303 | { |
| 304 | // I have a remote file.. two possible cases |
| 305 | if (file_spec && file_spec.Exists()) |
| 306 | { |
| 307 | // if the remote file does not exist, push it there |
| 308 | if (!platform_sp->GetFileExists (remote_file)) |
| 309 | { |
| 310 | Error err = platform_sp->PutFile(file_spec, remote_file); |
| 311 | if (err.Fail()) |
| 312 | { |
| 313 | result.AppendError(err.AsCString()); |
| 314 | result.SetStatus (eReturnStatusFailed); |
| 315 | return false; |
| 316 | } |
| 317 | } |
| 318 | } |
| 319 | else |
| 320 | { |
| 321 | // there is no local file and we need one |
| 322 | // in order to make the remote ---> local transfer we need a platform |
| 323 | // TODO: if the user has passed in a --platform argument, use it to fetch the right platform |
| 324 | if (!platform_sp) |
| 325 | { |
| 326 | result.AppendError("unable to perform remote debugging without a platform"); |
| 327 | result.SetStatus (eReturnStatusFailed); |
| 328 | return false; |
| 329 | } |
| 330 | if (file_path) |
| 331 | { |
| 332 | // copy the remote file to the local file |
| 333 | Error err = platform_sp->GetFile(remote_file, file_spec); |
| 334 | if (err.Fail()) |
| 335 | { |
| 336 | result.AppendError(err.AsCString()); |
| 337 | result.SetStatus (eReturnStatusFailed); |
| 338 | return false; |
| 339 | } |
| 340 | } |
| 341 | else |
| 342 | { |
| 343 | // make up a local file |
| 344 | result.AppendError("remote --> local transfer without local path is not implemented yet"); |
| 345 | result.SetStatus (eReturnStatusFailed); |
| 346 | return false; |
| 347 | } |
| 348 | } |
| 349 | } |
| 350 | else |
| 351 | { |
| 352 | result.AppendError("no platform found for target"); |
| 353 | result.SetStatus (eReturnStatusFailed); |
| 354 | return false; |
| 355 | } |
| 356 | } |
| 357 | |
Jim Ingham | bf22b96 | 2013-07-11 01:47:46 +0000 | [diff] [blame] | 358 | if (symfile || remote_file) |
Greg Clayton | 1c5f186 | 2012-11-30 19:05:35 +0000 | [diff] [blame] | 359 | { |
| 360 | ModuleSP module_sp (target_sp->GetExecutableModule()); |
| 361 | if (module_sp) |
Jim Ingham | bf22b96 | 2013-07-11 01:47:46 +0000 | [diff] [blame] | 362 | { |
| 363 | if (symfile) |
| 364 | module_sp->SetSymbolFileFileSpec(symfile); |
| 365 | if (remote_file) |
| 366 | { |
| 367 | std::string remote_path = remote_file.GetPath(); |
| 368 | target_sp->SetArg0(remote_path.c_str()); |
| 369 | module_sp->SetPlatformFileSpec(remote_file); |
| 370 | } |
| 371 | } |
Greg Clayton | 1c5f186 | 2012-11-30 19:05:35 +0000 | [diff] [blame] | 372 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 373 | |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 374 | debugger.GetTargetList().SetSelectedTarget(target_sp.get()); |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 375 | if (must_set_platform_path) |
| 376 | { |
| 377 | ModuleSpec main_module_spec(file_spec); |
| 378 | ModuleSP module_sp = target_sp->GetSharedModule(main_module_spec); |
| 379 | if (module_sp) |
| 380 | module_sp->SetPlatformFileSpec(remote_file); |
| 381 | } |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 382 | if (core_file) |
| 383 | { |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 384 | char core_path[PATH_MAX]; |
| 385 | core_file.GetPath(core_path, sizeof(core_path)); |
Greg Clayton | c859e2d | 2012-02-13 23:10:39 +0000 | [diff] [blame] | 386 | if (core_file.Exists()) |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 387 | { |
Jason Molenda | 25c9101 | 2015-06-26 02:16:48 +0000 | [diff] [blame] | 388 | if (!core_file.Readable()) |
| 389 | { |
| 390 | result.AppendMessageWithFormat ("Core file '%s' is not readable.\n", core_path); |
| 391 | result.SetStatus (eReturnStatusFailed); |
| 392 | return false; |
| 393 | } |
Greg Clayton | c859e2d | 2012-02-13 23:10:39 +0000 | [diff] [blame] | 394 | FileSpec core_file_dir; |
| 395 | core_file_dir.GetDirectory() = core_file.GetDirectory(); |
| 396 | target_sp->GetExecutableSearchPaths ().Append (core_file_dir); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 397 | |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 398 | ProcessSP process_sp(target_sp->CreateProcess(m_interpreter.GetDebugger().GetListener(), nullptr, &core_file)); |
Greg Clayton | c859e2d | 2012-02-13 23:10:39 +0000 | [diff] [blame] | 399 | |
| 400 | if (process_sp) |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 401 | { |
Bruce Mitchener | 4d31a48 | 2015-10-07 10:11:10 +0000 | [diff] [blame] | 402 | // Seems weird that we Launch a core file, but that is |
Greg Clayton | c859e2d | 2012-02-13 23:10:39 +0000 | [diff] [blame] | 403 | // what we do! |
| 404 | error = process_sp->LoadCore(); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 405 | |
Greg Clayton | c859e2d | 2012-02-13 23:10:39 +0000 | [diff] [blame] | 406 | if (error.Fail()) |
| 407 | { |
| 408 | result.AppendError(error.AsCString("can't find plug-in for core file")); |
| 409 | result.SetStatus (eReturnStatusFailed); |
| 410 | return false; |
| 411 | } |
| 412 | else |
| 413 | { |
| 414 | result.AppendMessageWithFormat ("Core file '%s' (%s) was loaded.\n", core_path, target_sp->GetArchitecture().GetArchitectureName()); |
| 415 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 416 | } |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 417 | } |
| 418 | else |
| 419 | { |
Greg Clayton | c859e2d | 2012-02-13 23:10:39 +0000 | [diff] [blame] | 420 | result.AppendErrorWithFormat ("Unable to find process plug-in for core file '%s'\n", core_path); |
| 421 | result.SetStatus (eReturnStatusFailed); |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 422 | } |
| 423 | } |
| 424 | else |
| 425 | { |
Greg Clayton | c859e2d | 2012-02-13 23:10:39 +0000 | [diff] [blame] | 426 | result.AppendErrorWithFormat ("Core file '%s' does not exist\n", core_path); |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 427 | result.SetStatus (eReturnStatusFailed); |
| 428 | } |
| 429 | } |
| 430 | else |
| 431 | { |
| 432 | result.AppendMessageWithFormat ("Current executable set to '%s' (%s).\n", file_path, target_sp->GetArchitecture().GetArchitectureName()); |
| 433 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 434 | } |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 435 | } |
| 436 | else |
| 437 | { |
| 438 | result.AppendError(error.AsCString()); |
| 439 | result.SetStatus (eReturnStatusFailed); |
| 440 | } |
| 441 | } |
| 442 | else |
| 443 | { |
Jason Molenda | 65e0642 | 2015-01-20 03:06:17 +0000 | [diff] [blame] | 444 | result.AppendErrorWithFormat("'%s' takes exactly one executable path argument, or use the --core option.\n", m_cmd_name.c_str()); |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 445 | result.SetStatus (eReturnStatusFailed); |
| 446 | } |
| 447 | return result.Succeeded(); |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 448 | } |
| 449 | |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 450 | private: |
| 451 | OptionGroupOptions m_option_group; |
Greg Clayton | 644247c | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 452 | OptionGroupArchitecture m_arch_option; |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 453 | OptionGroupFile m_core_file; |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 454 | OptionGroupFile m_platform_path; |
Greg Clayton | 1c5f186 | 2012-11-30 19:05:35 +0000 | [diff] [blame] | 455 | OptionGroupFile m_symbol_file; |
Jim Ingham | bf22b96 | 2013-07-11 01:47:46 +0000 | [diff] [blame] | 456 | OptionGroupFile m_remote_file; |
Greg Clayton | 1c5f186 | 2012-11-30 19:05:35 +0000 | [diff] [blame] | 457 | OptionGroupBoolean m_add_dependents; |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 458 | }; |
| 459 | |
| 460 | #pragma mark CommandObjectTargetList |
| 461 | |
| 462 | //---------------------------------------------------------------------- |
| 463 | // "target list" |
| 464 | //---------------------------------------------------------------------- |
| 465 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 466 | class CommandObjectTargetList : public CommandObjectParsed |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 467 | { |
| 468 | public: |
| 469 | CommandObjectTargetList (CommandInterpreter &interpreter) : |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 470 | CommandObjectParsed(interpreter, |
| 471 | "target list", |
| 472 | "List all current targets in the current debug session.", |
| 473 | nullptr) |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 474 | { |
| 475 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 476 | |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 477 | ~CommandObjectTargetList() override = default; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 478 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 479 | protected: |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 480 | bool |
| 481 | DoExecute (Args& args, CommandReturnObject &result) override |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 482 | { |
| 483 | if (args.GetArgumentCount() == 0) |
| 484 | { |
| 485 | Stream &strm = result.GetOutputStream(); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 486 | |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 487 | bool show_stopped_process_status = false; |
| 488 | if (DumpTargetList (m_interpreter.GetDebugger().GetTargetList(), show_stopped_process_status, strm) == 0) |
| 489 | { |
| 490 | strm.PutCString ("No targets.\n"); |
| 491 | } |
Johnny Chen | 1ee61a7 | 2011-04-18 21:08:05 +0000 | [diff] [blame] | 492 | result.SetStatus (eReturnStatusSuccessFinishResult); |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 493 | } |
| 494 | else |
| 495 | { |
| 496 | result.AppendError ("the 'target list' command takes no arguments\n"); |
| 497 | result.SetStatus (eReturnStatusFailed); |
| 498 | } |
| 499 | return result.Succeeded(); |
| 500 | } |
| 501 | }; |
| 502 | |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 503 | #pragma mark CommandObjectTargetSelect |
| 504 | |
| 505 | //---------------------------------------------------------------------- |
| 506 | // "target select" |
| 507 | //---------------------------------------------------------------------- |
| 508 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 509 | class CommandObjectTargetSelect : public CommandObjectParsed |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 510 | { |
| 511 | public: |
| 512 | CommandObjectTargetSelect (CommandInterpreter &interpreter) : |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 513 | CommandObjectParsed(interpreter, |
| 514 | "target select", |
| 515 | "Select a target as the current target by target index.", |
| 516 | nullptr) |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 517 | { |
| 518 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 519 | |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 520 | ~CommandObjectTargetSelect() override = default; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 521 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 522 | protected: |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 523 | bool |
| 524 | DoExecute (Args& args, CommandReturnObject &result) override |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 525 | { |
| 526 | if (args.GetArgumentCount() == 1) |
| 527 | { |
| 528 | bool success = false; |
| 529 | const char *target_idx_arg = args.GetArgumentAtIndex(0); |
Vince Harron | 5275aaa | 2015-01-15 20:08:35 +0000 | [diff] [blame] | 530 | 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] | 531 | if (success) |
| 532 | { |
| 533 | TargetList &target_list = m_interpreter.GetDebugger().GetTargetList(); |
| 534 | const uint32_t num_targets = target_list.GetNumTargets(); |
| 535 | if (target_idx < num_targets) |
| 536 | { |
| 537 | TargetSP target_sp (target_list.GetTargetAtIndex (target_idx)); |
| 538 | if (target_sp) |
| 539 | { |
| 540 | Stream &strm = result.GetOutputStream(); |
| 541 | target_list.SetSelectedTarget (target_sp.get()); |
| 542 | bool show_stopped_process_status = false; |
| 543 | DumpTargetList (target_list, show_stopped_process_status, strm); |
Johnny Chen | 1ee61a7 | 2011-04-18 21:08:05 +0000 | [diff] [blame] | 544 | result.SetStatus (eReturnStatusSuccessFinishResult); |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 545 | } |
| 546 | else |
| 547 | { |
| 548 | result.AppendErrorWithFormat ("target #%u is NULL in target list\n", target_idx); |
| 549 | result.SetStatus (eReturnStatusFailed); |
| 550 | } |
| 551 | } |
| 552 | else |
| 553 | { |
Todd Fiala | 352237d | 2014-08-29 20:14:21 +0000 | [diff] [blame] | 554 | if (num_targets > 0) |
| 555 | { |
| 556 | result.AppendErrorWithFormat ("index %u is out of range, valid target indexes are 0 - %u\n", |
| 557 | target_idx, |
| 558 | num_targets - 1); |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 559 | } |
| 560 | else |
Todd Fiala | 352237d | 2014-08-29 20:14:21 +0000 | [diff] [blame] | 561 | { |
| 562 | result.AppendErrorWithFormat ("index %u is out of range since there are no active targets\n", |
| 563 | target_idx); |
| 564 | } |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 565 | result.SetStatus (eReturnStatusFailed); |
| 566 | } |
| 567 | } |
| 568 | else |
| 569 | { |
| 570 | result.AppendErrorWithFormat("invalid index string value '%s'\n", target_idx_arg); |
| 571 | result.SetStatus (eReturnStatusFailed); |
| 572 | } |
| 573 | } |
| 574 | else |
| 575 | { |
| 576 | result.AppendError ("'target select' takes a single argument: a target index\n"); |
| 577 | result.SetStatus (eReturnStatusFailed); |
| 578 | } |
| 579 | return result.Succeeded(); |
| 580 | } |
| 581 | }; |
| 582 | |
Greg Clayton | 3418c85 | 2011-08-10 02:10:13 +0000 | [diff] [blame] | 583 | #pragma mark CommandObjectTargetSelect |
| 584 | |
| 585 | //---------------------------------------------------------------------- |
| 586 | // "target delete" |
| 587 | //---------------------------------------------------------------------- |
| 588 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 589 | class CommandObjectTargetDelete : public CommandObjectParsed |
Greg Clayton | 3418c85 | 2011-08-10 02:10:13 +0000 | [diff] [blame] | 590 | { |
| 591 | public: |
| 592 | CommandObjectTargetDelete (CommandInterpreter &interpreter) : |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 593 | CommandObjectParsed(interpreter, |
| 594 | "target delete", |
| 595 | "Delete one or more targets by target index.", |
| 596 | nullptr), |
Todd Fiala | e1cfbc7 | 2016-08-11 23:51:28 +0000 | [diff] [blame] | 597 | m_option_group(), |
Zachary Turner | aa4dabf | 2015-03-26 16:43:13 +0000 | [diff] [blame] | 598 | m_all_option(LLDB_OPT_SET_1, false, "all", 'a', "Delete all targets.", false, true), |
| 599 | m_cleanup_option( |
| 600 | LLDB_OPT_SET_1, |
| 601 | false, |
| 602 | "clean", 'c', |
| 603 | "Perform extra cleanup to minimize memory consumption after deleting the target. " |
| 604 | "By default, LLDB will keep in memory any modules previously loaded by the target as well " |
| 605 | "as all of its debug info. Specifying --clean will unload all of these shared modules and " |
| 606 | "cause them to be reparsed again the next time the target is run", |
| 607 | false, true) |
Greg Clayton | 3418c85 | 2011-08-10 02:10:13 +0000 | [diff] [blame] | 608 | { |
Zachary Turner | aa4dabf | 2015-03-26 16:43:13 +0000 | [diff] [blame] | 609 | m_option_group.Append(&m_all_option, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1); |
| 610 | m_option_group.Append(&m_cleanup_option, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1); |
Greg Clayton | aa149cb | 2011-08-11 02:48:45 +0000 | [diff] [blame] | 611 | m_option_group.Finalize(); |
Greg Clayton | 3418c85 | 2011-08-10 02:10:13 +0000 | [diff] [blame] | 612 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 613 | |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 614 | ~CommandObjectTargetDelete() override = default; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 615 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 616 | Options * |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 617 | GetOptions () override |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 618 | { |
| 619 | return &m_option_group; |
| 620 | } |
| 621 | |
| 622 | protected: |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 623 | bool |
| 624 | DoExecute (Args& args, CommandReturnObject &result) override |
Greg Clayton | 3418c85 | 2011-08-10 02:10:13 +0000 | [diff] [blame] | 625 | { |
| 626 | const size_t argc = args.GetArgumentCount(); |
| 627 | std::vector<TargetSP> delete_target_list; |
| 628 | TargetList &target_list = m_interpreter.GetDebugger().GetTargetList(); |
Greg Clayton | 3418c85 | 2011-08-10 02:10:13 +0000 | [diff] [blame] | 629 | TargetSP target_sp; |
Zachary Turner | aa4dabf | 2015-03-26 16:43:13 +0000 | [diff] [blame] | 630 | |
| 631 | if (m_all_option.GetOptionValue()) |
| 632 | { |
David Blaikie | dab893c | 2015-03-27 20:19:14 +0000 | [diff] [blame] | 633 | for (int i = 0; i < target_list.GetNumTargets(); ++i) |
Zachary Turner | aa4dabf | 2015-03-26 16:43:13 +0000 | [diff] [blame] | 634 | delete_target_list.push_back(target_list.GetTargetAtIndex(i)); |
| 635 | } |
| 636 | else if (argc > 0) |
Greg Clayton | 3418c85 | 2011-08-10 02:10:13 +0000 | [diff] [blame] | 637 | { |
| 638 | const uint32_t num_targets = target_list.GetNumTargets(); |
Filipe Cabecinhas | f065fdc | 2012-07-09 13:02:17 +0000 | [diff] [blame] | 639 | // Bail out if don't have any targets. |
| 640 | if (num_targets == 0) { |
| 641 | result.AppendError("no targets to delete"); |
| 642 | result.SetStatus(eReturnStatusFailed); |
Zachary Turner | aa4dabf | 2015-03-26 16:43:13 +0000 | [diff] [blame] | 643 | return false; |
Filipe Cabecinhas | f065fdc | 2012-07-09 13:02:17 +0000 | [diff] [blame] | 644 | } |
| 645 | |
Zachary Turner | aa4dabf | 2015-03-26 16:43:13 +0000 | [diff] [blame] | 646 | for (uint32_t arg_idx = 0; arg_idx < argc; ++arg_idx) |
Greg Clayton | 3418c85 | 2011-08-10 02:10:13 +0000 | [diff] [blame] | 647 | { |
| 648 | const char *target_idx_arg = args.GetArgumentAtIndex(arg_idx); |
Zachary Turner | aa4dabf | 2015-03-26 16:43:13 +0000 | [diff] [blame] | 649 | bool success = false; |
Vince Harron | 5275aaa | 2015-01-15 20:08:35 +0000 | [diff] [blame] | 650 | uint32_t target_idx = StringConvert::ToUInt32 (target_idx_arg, UINT32_MAX, 0, &success); |
Zachary Turner | aa4dabf | 2015-03-26 16:43:13 +0000 | [diff] [blame] | 651 | if (!success) |
Greg Clayton | 3418c85 | 2011-08-10 02:10:13 +0000 | [diff] [blame] | 652 | { |
| 653 | result.AppendErrorWithFormat("invalid target index '%s'\n", target_idx_arg); |
| 654 | result.SetStatus (eReturnStatusFailed); |
Zachary Turner | aa4dabf | 2015-03-26 16:43:13 +0000 | [diff] [blame] | 655 | return false; |
Greg Clayton | 3418c85 | 2011-08-10 02:10:13 +0000 | [diff] [blame] | 656 | } |
Zachary Turner | aa4dabf | 2015-03-26 16:43:13 +0000 | [diff] [blame] | 657 | if (target_idx < num_targets) |
| 658 | { |
| 659 | target_sp = target_list.GetTargetAtIndex (target_idx); |
| 660 | if (target_sp) |
| 661 | { |
| 662 | delete_target_list.push_back (target_sp); |
| 663 | continue; |
| 664 | } |
| 665 | } |
| 666 | if (num_targets > 1) |
| 667 | result.AppendErrorWithFormat ("target index %u is out of range, valid target indexes are 0 - %u\n", |
| 668 | target_idx, |
| 669 | num_targets - 1); |
| 670 | else |
| 671 | result.AppendErrorWithFormat("target index %u is out of range, the only valid index is 0\n", |
| 672 | target_idx); |
| 673 | |
| 674 | result.SetStatus (eReturnStatusFailed); |
| 675 | return false; |
Greg Clayton | 3418c85 | 2011-08-10 02:10:13 +0000 | [diff] [blame] | 676 | } |
Greg Clayton | 3418c85 | 2011-08-10 02:10:13 +0000 | [diff] [blame] | 677 | } |
| 678 | else |
| 679 | { |
| 680 | target_sp = target_list.GetSelectedTarget(); |
Zachary Turner | aa4dabf | 2015-03-26 16:43:13 +0000 | [diff] [blame] | 681 | if (!target_sp) |
Greg Clayton | 3418c85 | 2011-08-10 02:10:13 +0000 | [diff] [blame] | 682 | { |
| 683 | result.AppendErrorWithFormat("no target is currently selected\n"); |
| 684 | result.SetStatus (eReturnStatusFailed); |
Zachary Turner | aa4dabf | 2015-03-26 16:43:13 +0000 | [diff] [blame] | 685 | return false; |
Greg Clayton | 3418c85 | 2011-08-10 02:10:13 +0000 | [diff] [blame] | 686 | } |
Zachary Turner | aa4dabf | 2015-03-26 16:43:13 +0000 | [diff] [blame] | 687 | delete_target_list.push_back (target_sp); |
Greg Clayton | 3418c85 | 2011-08-10 02:10:13 +0000 | [diff] [blame] | 688 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 689 | |
Zachary Turner | aa4dabf | 2015-03-26 16:43:13 +0000 | [diff] [blame] | 690 | const size_t num_targets_to_delete = delete_target_list.size(); |
| 691 | for (size_t idx = 0; idx < num_targets_to_delete; ++idx) |
| 692 | { |
| 693 | target_sp = delete_target_list[idx]; |
| 694 | target_list.DeleteTarget(target_sp); |
| 695 | target_sp->Destroy(); |
| 696 | } |
| 697 | // If "--clean" was specified, prune any orphaned shared modules from |
| 698 | // the global shared module list |
| 699 | if (m_cleanup_option.GetOptionValue ()) |
| 700 | { |
| 701 | const bool mandatory = true; |
| 702 | ModuleList::RemoveOrphanSharedModules(mandatory); |
| 703 | } |
| 704 | result.GetOutputStream().Printf("%u targets deleted.\n", (uint32_t)num_targets_to_delete); |
| 705 | result.SetStatus(eReturnStatusSuccessFinishResult); |
| 706 | |
| 707 | return true; |
Greg Clayton | 3418c85 | 2011-08-10 02:10:13 +0000 | [diff] [blame] | 708 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 709 | |
Greg Clayton | aa149cb | 2011-08-11 02:48:45 +0000 | [diff] [blame] | 710 | OptionGroupOptions m_option_group; |
Zachary Turner | aa4dabf | 2015-03-26 16:43:13 +0000 | [diff] [blame] | 711 | OptionGroupBoolean m_all_option; |
Greg Clayton | aa149cb | 2011-08-11 02:48:45 +0000 | [diff] [blame] | 712 | OptionGroupBoolean m_cleanup_option; |
Greg Clayton | 3418c85 | 2011-08-10 02:10:13 +0000 | [diff] [blame] | 713 | }; |
| 714 | |
Greg Clayton | 644247c | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 715 | #pragma mark CommandObjectTargetVariable |
| 716 | |
| 717 | //---------------------------------------------------------------------- |
| 718 | // "target variable" |
| 719 | //---------------------------------------------------------------------- |
| 720 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 721 | class CommandObjectTargetVariable : public CommandObjectParsed |
Greg Clayton | 644247c | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 722 | { |
Saleem Abdulrasool | 44edda0 | 2014-03-18 04:43:47 +0000 | [diff] [blame] | 723 | static const uint32_t SHORT_OPTION_FILE = 0x66696c65; // 'file' |
| 724 | static const uint32_t SHORT_OPTION_SHLB = 0x73686c62; // 'shlb' |
| 725 | |
Greg Clayton | 644247c | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 726 | public: |
Kate Stone | 7428a18 | 2016-07-14 22:03:10 +0000 | [diff] [blame] | 727 | CommandObjectTargetVariable(CommandInterpreter &interpreter) |
| 728 | : CommandObjectParsed(interpreter, "target variable", |
| 729 | "Read global variables for the current target, before or while running a process.", |
| 730 | nullptr, eCommandRequiresTarget), |
Todd Fiala | e1cfbc7 | 2016-08-11 23:51:28 +0000 | [diff] [blame] | 731 | m_option_group(), |
Kate Stone | 7428a18 | 2016-07-14 22:03:10 +0000 | [diff] [blame] | 732 | m_option_variable(false), // Don't include frame options |
| 733 | m_option_format(eFormatDefault), |
| 734 | m_option_compile_units(LLDB_OPT_SET_1, false, "file", SHORT_OPTION_FILE, 0, eArgTypeFilename, |
| 735 | "A basename or fullpath to a file that contains global variables. This option can be " |
| 736 | "specified multiple times."), |
| 737 | m_option_shared_libraries(LLDB_OPT_SET_1, false, "shlib", SHORT_OPTION_SHLB, 0, eArgTypeFilename, |
| 738 | "A basename or fullpath to a shared library to use in the search for global " |
| 739 | "variables. This option can be specified multiple times."), |
| 740 | m_varobj_options() |
Greg Clayton | 644247c | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 741 | { |
Johnny Chen | 81ab3f5 | 2011-08-22 22:22:00 +0000 | [diff] [blame] | 742 | CommandArgumentEntry arg; |
| 743 | CommandArgumentData 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 | // Define the first (and only) variant of this arg. |
| 746 | var_name_arg.arg_type = eArgTypeVarName; |
| 747 | var_name_arg.arg_repetition = eArgRepeatPlus; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 748 | |
Johnny Chen | 81ab3f5 | 2011-08-22 22:22:00 +0000 | [diff] [blame] | 749 | // There is only one variant this argument could be; put it into the argument entry. |
| 750 | arg.push_back (var_name_arg); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 751 | |
Johnny Chen | 81ab3f5 | 2011-08-22 22:22:00 +0000 | [diff] [blame] | 752 | // Push the data for the first argument into the m_arguments vector. |
| 753 | m_arguments.push_back (arg); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 754 | |
Greg Clayton | 644247c | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 755 | 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] | 756 | 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] | 757 | 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] | 758 | m_option_group.Append (&m_option_compile_units, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1); |
| 759 | m_option_group.Append (&m_option_shared_libraries, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1); |
| 760 | m_option_group.Finalize(); |
| 761 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 762 | |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 763 | ~CommandObjectTargetVariable() override = default; |
Greg Clayton | 884fb69 | 2011-07-08 21:46:14 +0000 | [diff] [blame] | 764 | |
| 765 | void |
| 766 | DumpValueObject (Stream &s, VariableSP &var_sp, ValueObjectSP &valobj_sp, const char *root_name) |
| 767 | { |
Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 768 | DumpValueObjectOptions options(m_varobj_options.GetAsDumpOptions()); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 769 | |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 770 | if (!valobj_sp->GetTargetSP()->GetDisplayRuntimeSupportValues() && |
| 771 | valobj_sp->IsRuntimeSupportValue()) |
Enrico Granata | 560558e | 2015-02-11 02:35:39 +0000 | [diff] [blame] | 772 | return; |
| 773 | |
Greg Clayton | 884fb69 | 2011-07-08 21:46:14 +0000 | [diff] [blame] | 774 | switch (var_sp->GetScope()) |
| 775 | { |
| 776 | case eValueTypeVariableGlobal: |
| 777 | if (m_option_variable.show_scope) |
| 778 | s.PutCString("GLOBAL: "); |
| 779 | break; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 780 | |
Greg Clayton | 884fb69 | 2011-07-08 21:46:14 +0000 | [diff] [blame] | 781 | case eValueTypeVariableStatic: |
| 782 | if (m_option_variable.show_scope) |
| 783 | s.PutCString("STATIC: "); |
| 784 | break; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 785 | |
Greg Clayton | 884fb69 | 2011-07-08 21:46:14 +0000 | [diff] [blame] | 786 | case eValueTypeVariableArgument: |
| 787 | if (m_option_variable.show_scope) |
| 788 | s.PutCString(" ARG: "); |
| 789 | break; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 790 | |
Greg Clayton | 884fb69 | 2011-07-08 21:46:14 +0000 | [diff] [blame] | 791 | case eValueTypeVariableLocal: |
| 792 | if (m_option_variable.show_scope) |
| 793 | s.PutCString(" LOCAL: "); |
| 794 | break; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 795 | |
Greg Clayton | 63a27af | 2016-07-01 17:17:23 +0000 | [diff] [blame] | 796 | case eValueTypeVariableThreadLocal: |
| 797 | if (m_option_variable.show_scope) |
| 798 | s.PutCString("THREAD: "); |
| 799 | break; |
| 800 | |
Greg Clayton | 884fb69 | 2011-07-08 21:46:14 +0000 | [diff] [blame] | 801 | default: |
| 802 | break; |
| 803 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 804 | |
Greg Clayton | 45ba854 | 2011-07-10 19:21:23 +0000 | [diff] [blame] | 805 | if (m_option_variable.show_decl) |
Greg Clayton | 884fb69 | 2011-07-08 21:46:14 +0000 | [diff] [blame] | 806 | { |
Greg Clayton | 45ba854 | 2011-07-10 19:21:23 +0000 | [diff] [blame] | 807 | bool show_fullpaths = false; |
| 808 | bool show_module = true; |
| 809 | if (var_sp->DumpDeclaration(&s, show_fullpaths, show_module)) |
| 810 | s.PutCString (": "); |
Greg Clayton | 884fb69 | 2011-07-08 21:46:14 +0000 | [diff] [blame] | 811 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 812 | |
Greg Clayton | 1deb796 | 2011-10-25 06:44:01 +0000 | [diff] [blame] | 813 | const Format format = m_option_format.GetFormat(); |
Greg Clayton | 884fb69 | 2011-07-08 21:46:14 +0000 | [diff] [blame] | 814 | if (format != eFormatDefault) |
Enrico Granata | 0c489f5 | 2012-03-01 04:24:26 +0000 | [diff] [blame] | 815 | options.SetFormat(format); |
| 816 | |
| 817 | options.SetRootValueObjectName(root_name); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 818 | |
Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 819 | valobj_sp->Dump(s,options); |
Greg Clayton | 884fb69 | 2011-07-08 21:46:14 +0000 | [diff] [blame] | 820 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 821 | |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 822 | static size_t GetVariableCallback (void *baton, |
| 823 | const char *name, |
| 824 | VariableList &variable_list) |
Greg Clayton | 884fb69 | 2011-07-08 21:46:14 +0000 | [diff] [blame] | 825 | { |
| 826 | Target *target = static_cast<Target *>(baton); |
| 827 | if (target) |
| 828 | { |
| 829 | return target->GetImages().FindGlobalVariables (ConstString(name), |
| 830 | true, |
| 831 | UINT32_MAX, |
| 832 | variable_list); |
| 833 | } |
| 834 | return 0; |
| 835 | } |
Greg Clayton | 884fb69 | 2011-07-08 21:46:14 +0000 | [diff] [blame] | 836 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 837 | Options * |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 838 | GetOptions () override |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 839 | { |
| 840 | return &m_option_group; |
| 841 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 842 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 843 | protected: |
Greg Clayton | 3bcdfc0 | 2012-12-04 00:32:51 +0000 | [diff] [blame] | 844 | void |
| 845 | DumpGlobalVariableList(const ExecutionContext &exe_ctx, const SymbolContext &sc, const VariableList &variable_list, Stream &s) |
| 846 | { |
| 847 | size_t count = variable_list.GetSize(); |
| 848 | if (count > 0) |
| 849 | { |
| 850 | if (sc.module_sp) |
| 851 | { |
| 852 | if (sc.comp_unit) |
| 853 | { |
Greg Clayton | b5ad4ec | 2013-04-29 17:25:54 +0000 | [diff] [blame] | 854 | s.Printf ("Global variables for %s in %s:\n", |
| 855 | sc.comp_unit->GetPath().c_str(), |
| 856 | sc.module_sp->GetFileSpec().GetPath().c_str()); |
Greg Clayton | 3bcdfc0 | 2012-12-04 00:32:51 +0000 | [diff] [blame] | 857 | } |
| 858 | else |
| 859 | { |
Greg Clayton | b5ad4ec | 2013-04-29 17:25:54 +0000 | [diff] [blame] | 860 | s.Printf ("Global variables for %s\n", |
| 861 | sc.module_sp->GetFileSpec().GetPath().c_str()); |
Greg Clayton | 3bcdfc0 | 2012-12-04 00:32:51 +0000 | [diff] [blame] | 862 | } |
| 863 | } |
| 864 | else if (sc.comp_unit) |
| 865 | { |
Greg Clayton | b5ad4ec | 2013-04-29 17:25:54 +0000 | [diff] [blame] | 866 | s.Printf ("Global variables for %s\n", |
| 867 | sc.comp_unit->GetPath().c_str()); |
Greg Clayton | 3bcdfc0 | 2012-12-04 00:32:51 +0000 | [diff] [blame] | 868 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 869 | |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 870 | for (uint32_t i = 0; i < count; ++i) |
Greg Clayton | 3bcdfc0 | 2012-12-04 00:32:51 +0000 | [diff] [blame] | 871 | { |
| 872 | VariableSP var_sp (variable_list.GetVariableAtIndex(i)); |
| 873 | if (var_sp) |
| 874 | { |
| 875 | ValueObjectSP valobj_sp (ValueObjectVariable::Create (exe_ctx.GetBestExecutionContextScope(), var_sp)); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 876 | |
Greg Clayton | 3bcdfc0 | 2012-12-04 00:32:51 +0000 | [diff] [blame] | 877 | if (valobj_sp) |
| 878 | DumpValueObject (s, var_sp, valobj_sp, var_sp->GetName().GetCString()); |
| 879 | } |
| 880 | } |
| 881 | } |
Greg Clayton | 3bcdfc0 | 2012-12-04 00:32:51 +0000 | [diff] [blame] | 882 | } |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 883 | |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 884 | bool |
| 885 | DoExecute (Args& args, CommandReturnObject &result) override |
Greg Clayton | 644247c | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 886 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 887 | Target *target = m_exe_ctx.GetTargetPtr(); |
| 888 | const size_t argc = args.GetArgumentCount(); |
| 889 | Stream &s = result.GetOutputStream(); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 890 | |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 891 | if (argc > 0) |
Greg Clayton | 644247c | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 892 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 893 | |
| 894 | for (size_t idx = 0; idx < argc; ++idx) |
Greg Clayton | 644247c | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 895 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 896 | VariableList variable_list; |
| 897 | ValueObjectList valobj_list; |
Greg Clayton | 884fb69 | 2011-07-08 21:46:14 +0000 | [diff] [blame] | 898 | |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 899 | const char *arg = args.GetArgumentAtIndex(idx); |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 900 | size_t matches = 0; |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 901 | bool use_var_name = false; |
| 902 | if (m_option_variable.use_regex) |
Greg Clayton | 644247c | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 903 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 904 | RegularExpression regex(arg); |
| 905 | if (!regex.IsValid ()) |
Greg Clayton | 644247c | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 906 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 907 | result.GetErrorStream().Printf ("error: invalid regular expression: '%s'\n", arg); |
Greg Clayton | 715c236 | 2011-07-07 04:38:25 +0000 | [diff] [blame] | 908 | result.SetStatus (eReturnStatusFailed); |
| 909 | return false; |
| 910 | } |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 911 | use_var_name = true; |
| 912 | matches = target->GetImages().FindGlobalVariables (regex, |
| 913 | true, |
| 914 | UINT32_MAX, |
| 915 | variable_list); |
Greg Clayton | 3bcdfc0 | 2012-12-04 00:32:51 +0000 | [diff] [blame] | 916 | } |
| 917 | else |
| 918 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 919 | Error error (Variable::GetValuesForVariableExpressionPath (arg, |
| 920 | m_exe_ctx.GetBestExecutionContextScope(), |
| 921 | GetVariableCallback, |
| 922 | target, |
| 923 | variable_list, |
| 924 | valobj_list)); |
| 925 | matches = variable_list.GetSize(); |
| 926 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 927 | |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 928 | if (matches == 0) |
| 929 | { |
| 930 | result.GetErrorStream().Printf ("error: can't find global variable '%s'\n", arg); |
| 931 | result.SetStatus (eReturnStatusFailed); |
| 932 | return false; |
| 933 | } |
| 934 | else |
| 935 | { |
| 936 | for (uint32_t global_idx=0; global_idx<matches; ++global_idx) |
Greg Clayton | 3bcdfc0 | 2012-12-04 00:32:51 +0000 | [diff] [blame] | 937 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 938 | VariableSP var_sp (variable_list.GetVariableAtIndex(global_idx)); |
| 939 | if (var_sp) |
Greg Clayton | 3bcdfc0 | 2012-12-04 00:32:51 +0000 | [diff] [blame] | 940 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 941 | ValueObjectSP valobj_sp (valobj_list.GetValueObjectAtIndex(global_idx)); |
| 942 | if (!valobj_sp) |
| 943 | valobj_sp = ValueObjectVariable::Create (m_exe_ctx.GetBestExecutionContextScope(), var_sp); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 944 | |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 945 | if (valobj_sp) |
| 946 | 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] | 947 | } |
| 948 | } |
Greg Clayton | 9a5a934 | 2011-10-05 22:17:32 +0000 | [diff] [blame] | 949 | } |
Greg Clayton | 644247c | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 950 | } |
| 951 | } |
| 952 | else |
| 953 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 954 | const FileSpecList &compile_units = m_option_compile_units.GetOptionValue().GetCurrentValue(); |
| 955 | const FileSpecList &shlibs = m_option_shared_libraries.GetOptionValue().GetCurrentValue(); |
| 956 | SymbolContextList sc_list; |
| 957 | const size_t num_compile_units = compile_units.GetSize(); |
| 958 | const size_t num_shlibs = shlibs.GetSize(); |
| 959 | if (num_compile_units == 0 && num_shlibs == 0) |
| 960 | { |
| 961 | bool success = false; |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 962 | StackFrame *frame = m_exe_ctx.GetFramePtr(); |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 963 | CompileUnit *comp_unit = nullptr; |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 964 | if (frame) |
| 965 | { |
| 966 | SymbolContext sc = frame->GetSymbolContext (eSymbolContextCompUnit); |
| 967 | if (sc.comp_unit) |
| 968 | { |
| 969 | const bool can_create = true; |
| 970 | VariableListSP comp_unit_varlist_sp (sc.comp_unit->GetVariableList(can_create)); |
| 971 | if (comp_unit_varlist_sp) |
| 972 | { |
| 973 | size_t count = comp_unit_varlist_sp->GetSize(); |
| 974 | if (count > 0) |
| 975 | { |
| 976 | DumpGlobalVariableList(m_exe_ctx, sc, *comp_unit_varlist_sp, s); |
| 977 | success = true; |
| 978 | } |
| 979 | } |
| 980 | } |
| 981 | } |
| 982 | if (!success) |
| 983 | { |
| 984 | if (frame) |
| 985 | { |
| 986 | if (comp_unit) |
Greg Clayton | b5ad4ec | 2013-04-29 17:25:54 +0000 | [diff] [blame] | 987 | result.AppendErrorWithFormat ("no global variables in current compile unit: %s\n", |
| 988 | comp_unit->GetPath().c_str()); |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 989 | else |
| 990 | result.AppendErrorWithFormat ("no debug information for frame %u\n", frame->GetFrameIndex()); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 991 | } |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 992 | else |
| 993 | result.AppendError ("'target variable' takes one or more global variable names as arguments\n"); |
| 994 | result.SetStatus (eReturnStatusFailed); |
| 995 | } |
| 996 | } |
| 997 | else |
| 998 | { |
| 999 | SymbolContextList sc_list; |
| 1000 | const bool append = true; |
| 1001 | // We have one or more compile unit or shlib |
| 1002 | if (num_shlibs > 0) |
| 1003 | { |
| 1004 | for (size_t shlib_idx=0; shlib_idx<num_shlibs; ++shlib_idx) |
| 1005 | { |
| 1006 | const FileSpec module_file(shlibs.GetFileSpecAtIndex(shlib_idx)); |
| 1007 | ModuleSpec module_spec (module_file); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1008 | |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 1009 | ModuleSP module_sp (target->GetImages().FindFirstModule(module_spec)); |
| 1010 | if (module_sp) |
| 1011 | { |
| 1012 | if (num_compile_units > 0) |
| 1013 | { |
| 1014 | for (size_t cu_idx=0; cu_idx<num_compile_units; ++cu_idx) |
| 1015 | module_sp->FindCompileUnits(compile_units.GetFileSpecAtIndex(cu_idx), append, sc_list); |
| 1016 | } |
| 1017 | else |
| 1018 | { |
| 1019 | SymbolContext sc; |
| 1020 | sc.module_sp = module_sp; |
| 1021 | sc_list.Append(sc); |
| 1022 | } |
| 1023 | } |
| 1024 | else |
| 1025 | { |
| 1026 | // Didn't find matching shlib/module in target... |
Greg Clayton | b5ad4ec | 2013-04-29 17:25:54 +0000 | [diff] [blame] | 1027 | result.AppendErrorWithFormat ("target doesn't contain the specified shared library: %s\n", |
| 1028 | module_file.GetPath().c_str()); |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 1029 | } |
| 1030 | } |
| 1031 | } |
| 1032 | else |
| 1033 | { |
| 1034 | // No shared libraries, we just want to find globals for the compile units files that were specified |
| 1035 | for (size_t cu_idx=0; cu_idx<num_compile_units; ++cu_idx) |
| 1036 | target->GetImages().FindCompileUnits(compile_units.GetFileSpecAtIndex(cu_idx), append, sc_list); |
| 1037 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1038 | |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 1039 | const uint32_t num_scs = sc_list.GetSize(); |
| 1040 | if (num_scs > 0) |
| 1041 | { |
| 1042 | SymbolContext sc; |
| 1043 | for (uint32_t sc_idx=0; sc_idx<num_scs; ++sc_idx) |
| 1044 | { |
| 1045 | if (sc_list.GetContextAtIndex(sc_idx, sc)) |
| 1046 | { |
| 1047 | if (sc.comp_unit) |
| 1048 | { |
| 1049 | const bool can_create = true; |
| 1050 | VariableListSP comp_unit_varlist_sp (sc.comp_unit->GetVariableList(can_create)); |
| 1051 | if (comp_unit_varlist_sp) |
| 1052 | DumpGlobalVariableList(m_exe_ctx, sc, *comp_unit_varlist_sp, s); |
| 1053 | } |
| 1054 | else if (sc.module_sp) |
| 1055 | { |
| 1056 | // Get all global variables for this module |
| 1057 | lldb_private::RegularExpression all_globals_regex("."); // Any global with at least one character |
| 1058 | VariableList variable_list; |
| 1059 | sc.module_sp->FindGlobalVariables(all_globals_regex, append, UINT32_MAX, variable_list); |
| 1060 | DumpGlobalVariableList(m_exe_ctx, sc, variable_list, s); |
| 1061 | } |
| 1062 | } |
| 1063 | } |
| 1064 | } |
| 1065 | } |
Greg Clayton | 644247c | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 1066 | } |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 1067 | |
Enrico Granata | 61a80ba | 2011-08-12 16:42:31 +0000 | [diff] [blame] | 1068 | if (m_interpreter.TruncationWarningNecessary()) |
| 1069 | { |
| 1070 | result.GetOutputStream().Printf(m_interpreter.TruncationWarningText(), |
| 1071 | m_cmd_name.c_str()); |
| 1072 | m_interpreter.TruncationWarningGiven(); |
| 1073 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1074 | |
Greg Clayton | 644247c | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 1075 | return result.Succeeded(); |
| 1076 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1077 | |
Greg Clayton | 644247c | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 1078 | OptionGroupOptions m_option_group; |
Greg Clayton | 715c236 | 2011-07-07 04:38:25 +0000 | [diff] [blame] | 1079 | OptionGroupVariable m_option_variable; |
Greg Clayton | 1deb796 | 2011-10-25 06:44:01 +0000 | [diff] [blame] | 1080 | OptionGroupFormat m_option_format; |
Greg Clayton | 644247c | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 1081 | OptionGroupFileList m_option_compile_units; |
| 1082 | OptionGroupFileList m_option_shared_libraries; |
| 1083 | OptionGroupValueObjectDisplay m_varobj_options; |
Greg Clayton | 644247c | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 1084 | }; |
| 1085 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1086 | #pragma mark CommandObjectTargetModulesSearchPathsAdd |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1087 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1088 | class CommandObjectTargetModulesSearchPathsAdd : public CommandObjectParsed |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1089 | { |
| 1090 | public: |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1091 | CommandObjectTargetModulesSearchPathsAdd (CommandInterpreter &interpreter) : |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 1092 | CommandObjectParsed(interpreter, |
| 1093 | "target modules search-paths add", |
| 1094 | "Add new image search paths substitution pairs to the current target.", |
| 1095 | nullptr) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1096 | { |
Caroline Tice | 405fe67 | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 1097 | CommandArgumentEntry arg; |
| 1098 | CommandArgumentData old_prefix_arg; |
| 1099 | CommandArgumentData new_prefix_arg; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1100 | |
Caroline Tice | 405fe67 | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 1101 | // Define the first variant of this arg pair. |
| 1102 | old_prefix_arg.arg_type = eArgTypeOldPathPrefix; |
| 1103 | old_prefix_arg.arg_repetition = eArgRepeatPairPlus; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1104 | |
Caroline Tice | 405fe67 | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 1105 | // Define the first variant of this arg pair. |
| 1106 | new_prefix_arg.arg_type = eArgTypeNewPathPrefix; |
| 1107 | new_prefix_arg.arg_repetition = eArgRepeatPairPlus; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1108 | |
Caroline Tice | 405fe67 | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 1109 | // There are two required arguments that must always occur together, i.e. an argument "pair". Because they |
| 1110 | // must always occur together, they are treated as two variants of one argument rather than two independent |
| 1111 | // arguments. Push them both into the first argument position for m_arguments... |
| 1112 | |
| 1113 | arg.push_back (old_prefix_arg); |
| 1114 | arg.push_back (new_prefix_arg); |
| 1115 | |
| 1116 | m_arguments.push_back (arg); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1117 | } |
| 1118 | |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 1119 | ~CommandObjectTargetModulesSearchPathsAdd() override = default; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1120 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1121 | protected: |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1122 | bool |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 1123 | DoExecute (Args& command, CommandReturnObject &result) override |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1124 | { |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1125 | Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1126 | if (target) |
| 1127 | { |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 1128 | const size_t argc = command.GetArgumentCount(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1129 | if (argc & 1) |
| 1130 | { |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1131 | result.AppendError ("add requires an even number of arguments\n"); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1132 | result.SetStatus (eReturnStatusFailed); |
| 1133 | } |
| 1134 | else |
| 1135 | { |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 1136 | for (size_t i = 0; i < argc; i+=2) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1137 | { |
| 1138 | const char *from = command.GetArgumentAtIndex(i); |
| 1139 | const char *to = command.GetArgumentAtIndex(i+1); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1140 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1141 | if (from[0] && to[0]) |
| 1142 | { |
Jason Molenda | 7138765 | 2015-07-31 04:21:25 +0000 | [diff] [blame] | 1143 | Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST); |
| 1144 | if (log) |
| 1145 | { |
| 1146 | log->Printf ("target modules search path adding ImageSearchPath pair: '%s' -> '%s'", |
| 1147 | from, to); |
| 1148 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1149 | bool last_pair = ((argc - i) == 2); |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 1150 | target->GetImageSearchPathList().Append (ConstString(from), |
| 1151 | ConstString(to), |
| 1152 | last_pair); // Notify if this is the last pair |
Johnny Chen | 7791b33 | 2011-02-03 00:30:19 +0000 | [diff] [blame] | 1153 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1154 | } |
| 1155 | else |
| 1156 | { |
| 1157 | if (from[0]) |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1158 | result.AppendError ("<path-prefix> can't be empty\n"); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1159 | else |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1160 | result.AppendError ("<new-path-prefix> can't be empty\n"); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1161 | result.SetStatus (eReturnStatusFailed); |
| 1162 | } |
| 1163 | } |
| 1164 | } |
| 1165 | } |
| 1166 | else |
| 1167 | { |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1168 | result.AppendError ("invalid target\n"); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1169 | result.SetStatus (eReturnStatusFailed); |
| 1170 | } |
| 1171 | return result.Succeeded(); |
| 1172 | } |
| 1173 | }; |
| 1174 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1175 | #pragma mark CommandObjectTargetModulesSearchPathsClear |
| 1176 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1177 | class CommandObjectTargetModulesSearchPathsClear : public CommandObjectParsed |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1178 | { |
| 1179 | public: |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1180 | CommandObjectTargetModulesSearchPathsClear (CommandInterpreter &interpreter) : |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1181 | CommandObjectParsed (interpreter, |
| 1182 | "target modules search-paths clear", |
| 1183 | "Clear all current image search path substitution pairs from the current target.", |
| 1184 | "target modules search-paths clear") |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1185 | { |
| 1186 | } |
| 1187 | |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 1188 | ~CommandObjectTargetModulesSearchPathsClear() override = default; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1189 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1190 | protected: |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1191 | bool |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 1192 | DoExecute (Args& command, CommandReturnObject &result) override |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1193 | { |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1194 | Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1195 | if (target) |
| 1196 | { |
| 1197 | bool notify = true; |
| 1198 | target->GetImageSearchPathList().Clear(notify); |
Johnny Chen | 7791b33 | 2011-02-03 00:30:19 +0000 | [diff] [blame] | 1199 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1200 | } |
| 1201 | else |
| 1202 | { |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1203 | result.AppendError ("invalid target\n"); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1204 | result.SetStatus (eReturnStatusFailed); |
| 1205 | } |
| 1206 | return result.Succeeded(); |
| 1207 | } |
| 1208 | }; |
| 1209 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1210 | #pragma mark CommandObjectTargetModulesSearchPathsInsert |
| 1211 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1212 | class CommandObjectTargetModulesSearchPathsInsert : public CommandObjectParsed |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1213 | { |
| 1214 | public: |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1215 | CommandObjectTargetModulesSearchPathsInsert (CommandInterpreter &interpreter) : |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 1216 | CommandObjectParsed(interpreter, |
| 1217 | "target modules search-paths insert", |
| 1218 | "Insert a new image search path substitution pair into the current target at the specified index.", |
| 1219 | nullptr) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1220 | { |
Caroline Tice | 405fe67 | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 1221 | CommandArgumentEntry arg1; |
| 1222 | CommandArgumentEntry arg2; |
| 1223 | CommandArgumentData index_arg; |
| 1224 | CommandArgumentData old_prefix_arg; |
| 1225 | CommandArgumentData new_prefix_arg; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1226 | |
Caroline Tice | 405fe67 | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 1227 | // Define the first and only variant of this arg. |
| 1228 | index_arg.arg_type = eArgTypeIndex; |
| 1229 | index_arg.arg_repetition = eArgRepeatPlain; |
| 1230 | |
| 1231 | // Put the one and only variant into the first arg for m_arguments: |
| 1232 | arg1.push_back (index_arg); |
| 1233 | |
| 1234 | // Define the first variant of this arg pair. |
| 1235 | old_prefix_arg.arg_type = eArgTypeOldPathPrefix; |
| 1236 | old_prefix_arg.arg_repetition = eArgRepeatPairPlus; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1237 | |
Caroline Tice | 405fe67 | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 1238 | // Define the first variant of this arg pair. |
| 1239 | new_prefix_arg.arg_type = eArgTypeNewPathPrefix; |
| 1240 | new_prefix_arg.arg_repetition = eArgRepeatPairPlus; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1241 | |
Caroline Tice | 405fe67 | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 1242 | // There are two required arguments that must always occur together, i.e. an argument "pair". Because they |
| 1243 | // must always occur together, they are treated as two variants of one argument rather than two independent |
| 1244 | // arguments. Push them both into the same argument position for m_arguments... |
| 1245 | |
| 1246 | arg2.push_back (old_prefix_arg); |
| 1247 | arg2.push_back (new_prefix_arg); |
| 1248 | |
| 1249 | // Add arguments to m_arguments. |
| 1250 | m_arguments.push_back (arg1); |
| 1251 | m_arguments.push_back (arg2); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1252 | } |
| 1253 | |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 1254 | ~CommandObjectTargetModulesSearchPathsInsert() override = default; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1255 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1256 | protected: |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1257 | bool |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 1258 | DoExecute (Args& command, CommandReturnObject &result) override |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1259 | { |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1260 | Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1261 | if (target) |
| 1262 | { |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 1263 | size_t argc = command.GetArgumentCount(); |
Bruce Mitchener | 4d31a48 | 2015-10-07 10:11:10 +0000 | [diff] [blame] | 1264 | // check for at least 3 arguments and an odd number of parameters |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1265 | if (argc >= 3 && argc & 1) |
| 1266 | { |
| 1267 | bool success = false; |
| 1268 | |
Vince Harron | 5275aaa | 2015-01-15 20:08:35 +0000 | [diff] [blame] | 1269 | 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] | 1270 | |
| 1271 | if (!success) |
| 1272 | { |
| 1273 | result.AppendErrorWithFormat("<index> parameter is not an integer: '%s'.\n", command.GetArgumentAtIndex(0)); |
| 1274 | result.SetStatus (eReturnStatusFailed); |
| 1275 | return result.Succeeded(); |
| 1276 | } |
| 1277 | |
| 1278 | // shift off the index |
| 1279 | command.Shift(); |
| 1280 | argc = command.GetArgumentCount(); |
| 1281 | |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 1282 | for (uint32_t i = 0; i < argc; i += 2, ++insert_idx) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1283 | { |
| 1284 | const char *from = command.GetArgumentAtIndex(i); |
| 1285 | const char *to = command.GetArgumentAtIndex(i+1); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1286 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1287 | if (from[0] && to[0]) |
| 1288 | { |
| 1289 | bool last_pair = ((argc - i) == 2); |
| 1290 | target->GetImageSearchPathList().Insert (ConstString(from), |
| 1291 | ConstString(to), |
| 1292 | insert_idx, |
| 1293 | last_pair); |
Johnny Chen | 7791b33 | 2011-02-03 00:30:19 +0000 | [diff] [blame] | 1294 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1295 | } |
| 1296 | else |
| 1297 | { |
| 1298 | if (from[0]) |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1299 | result.AppendError ("<path-prefix> can't be empty\n"); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1300 | else |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1301 | result.AppendError ("<new-path-prefix> can't be empty\n"); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1302 | result.SetStatus (eReturnStatusFailed); |
| 1303 | return false; |
| 1304 | } |
| 1305 | } |
| 1306 | } |
| 1307 | else |
| 1308 | { |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1309 | result.AppendError ("insert requires at least three arguments\n"); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1310 | result.SetStatus (eReturnStatusFailed); |
| 1311 | return result.Succeeded(); |
| 1312 | } |
| 1313 | |
| 1314 | } |
| 1315 | else |
| 1316 | { |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1317 | result.AppendError ("invalid target\n"); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1318 | result.SetStatus (eReturnStatusFailed); |
| 1319 | } |
| 1320 | return result.Succeeded(); |
| 1321 | } |
| 1322 | }; |
| 1323 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1324 | #pragma mark CommandObjectTargetModulesSearchPathsList |
| 1325 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1326 | class CommandObjectTargetModulesSearchPathsList : public CommandObjectParsed |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1327 | { |
| 1328 | public: |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1329 | CommandObjectTargetModulesSearchPathsList (CommandInterpreter &interpreter) : |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1330 | CommandObjectParsed (interpreter, |
| 1331 | "target modules search-paths list", |
| 1332 | "List all current image search path substitution pairs in the current target.", |
| 1333 | "target modules search-paths list") |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1334 | { |
| 1335 | } |
| 1336 | |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 1337 | ~CommandObjectTargetModulesSearchPathsList() override = default; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 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 |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 1341 | DoExecute (Args& command, CommandReturnObject &result) override |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1342 | { |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1343 | Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1344 | if (target) |
| 1345 | { |
| 1346 | if (command.GetArgumentCount() != 0) |
| 1347 | { |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1348 | result.AppendError ("list takes no arguments\n"); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1349 | result.SetStatus (eReturnStatusFailed); |
| 1350 | return result.Succeeded(); |
| 1351 | } |
| 1352 | |
| 1353 | target->GetImageSearchPathList().Dump(&result.GetOutputStream()); |
Johnny Chen | 7791b33 | 2011-02-03 00:30:19 +0000 | [diff] [blame] | 1354 | result.SetStatus (eReturnStatusSuccessFinishResult); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1355 | } |
| 1356 | else |
| 1357 | { |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1358 | result.AppendError ("invalid target\n"); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1359 | result.SetStatus (eReturnStatusFailed); |
| 1360 | } |
| 1361 | return result.Succeeded(); |
| 1362 | } |
| 1363 | }; |
| 1364 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1365 | #pragma mark CommandObjectTargetModulesSearchPathsQuery |
| 1366 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1367 | class CommandObjectTargetModulesSearchPathsQuery : public CommandObjectParsed |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1368 | { |
| 1369 | public: |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1370 | CommandObjectTargetModulesSearchPathsQuery (CommandInterpreter &interpreter) : |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 1371 | CommandObjectParsed(interpreter, |
| 1372 | "target modules search-paths query", |
| 1373 | "Transform a path using the first applicable image search path.", |
| 1374 | nullptr) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1375 | { |
Caroline Tice | 405fe67 | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 1376 | CommandArgumentEntry arg; |
| 1377 | CommandArgumentData path_arg; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1378 | |
Caroline Tice | 405fe67 | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 1379 | // Define the first (and only) variant of this arg. |
Sean Callanan | 3154255 | 2012-10-24 01:12:14 +0000 | [diff] [blame] | 1380 | path_arg.arg_type = eArgTypeDirectoryName; |
Caroline Tice | 405fe67 | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 1381 | path_arg.arg_repetition = eArgRepeatPlain; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1382 | |
Caroline Tice | 405fe67 | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 1383 | // There is only one variant this argument could be; put it into the argument entry. |
| 1384 | arg.push_back (path_arg); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1385 | |
Caroline Tice | 405fe67 | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 1386 | // Push the data for the first argument into the m_arguments vector. |
| 1387 | m_arguments.push_back (arg); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1388 | } |
| 1389 | |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 1390 | ~CommandObjectTargetModulesSearchPathsQuery() override = default; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1391 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1392 | protected: |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1393 | bool |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 1394 | DoExecute (Args& command, CommandReturnObject &result) override |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1395 | { |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1396 | Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1397 | if (target) |
| 1398 | { |
| 1399 | if (command.GetArgumentCount() != 1) |
| 1400 | { |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1401 | result.AppendError ("query requires one argument\n"); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1402 | result.SetStatus (eReturnStatusFailed); |
| 1403 | return result.Succeeded(); |
| 1404 | } |
| 1405 | |
| 1406 | ConstString orig(command.GetArgumentAtIndex(0)); |
| 1407 | ConstString transformed; |
| 1408 | if (target->GetImageSearchPathList().RemapPath(orig, transformed)) |
| 1409 | result.GetOutputStream().Printf("%s\n", transformed.GetCString()); |
| 1410 | else |
| 1411 | result.GetOutputStream().Printf("%s\n", orig.GetCString()); |
Johnny Chen | 7791b33 | 2011-02-03 00:30:19 +0000 | [diff] [blame] | 1412 | |
| 1413 | result.SetStatus (eReturnStatusSuccessFinishResult); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1414 | } |
| 1415 | else |
| 1416 | { |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1417 | result.AppendError ("invalid target\n"); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1418 | result.SetStatus (eReturnStatusFailed); |
| 1419 | } |
| 1420 | return result.Succeeded(); |
| 1421 | } |
| 1422 | }; |
| 1423 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1424 | //---------------------------------------------------------------------- |
| 1425 | // Static Helper functions |
| 1426 | //---------------------------------------------------------------------- |
| 1427 | static void |
| 1428 | DumpModuleArchitecture (Stream &strm, Module *module, bool full_triple, uint32_t width) |
| 1429 | { |
| 1430 | if (module) |
| 1431 | { |
Todd Fiala | 7df337f | 2015-10-13 23:41:19 +0000 | [diff] [blame] | 1432 | StreamString arch_strm; |
| 1433 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1434 | if (full_triple) |
Todd Fiala | 7df337f | 2015-10-13 23:41:19 +0000 | [diff] [blame] | 1435 | module->GetArchitecture().DumpTriple(arch_strm); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1436 | else |
Todd Fiala | 7df337f | 2015-10-13 23:41:19 +0000 | [diff] [blame] | 1437 | arch_strm.PutCString(module->GetArchitecture().GetArchitectureName()); |
| 1438 | std::string arch_str = arch_strm.GetString(); |
| 1439 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1440 | if (width) |
Todd Fiala | 7df337f | 2015-10-13 23:41:19 +0000 | [diff] [blame] | 1441 | strm.Printf("%-*s", width, arch_str.c_str()); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1442 | else |
Todd Fiala | 7df337f | 2015-10-13 23:41:19 +0000 | [diff] [blame] | 1443 | strm.PutCString(arch_str.c_str()); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1444 | } |
| 1445 | } |
| 1446 | |
| 1447 | static void |
| 1448 | DumpModuleUUID (Stream &strm, Module *module) |
| 1449 | { |
Jim Ingham | 28eb571 | 2012-10-12 17:34:26 +0000 | [diff] [blame] | 1450 | if (module && module->GetUUID().IsValid()) |
Greg Clayton | 3418c85 | 2011-08-10 02:10:13 +0000 | [diff] [blame] | 1451 | module->GetUUID().Dump (&strm); |
| 1452 | else |
| 1453 | strm.PutCString(" "); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1454 | } |
| 1455 | |
| 1456 | static uint32_t |
Greg Clayton | a0ca660 | 2012-10-18 16:33:33 +0000 | [diff] [blame] | 1457 | DumpCompileUnitLineTable (CommandInterpreter &interpreter, |
| 1458 | Stream &strm, |
| 1459 | Module *module, |
| 1460 | const FileSpec &file_spec, |
| 1461 | bool load_addresses) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1462 | { |
| 1463 | uint32_t num_matches = 0; |
| 1464 | if (module) |
| 1465 | { |
| 1466 | SymbolContextList sc_list; |
| 1467 | num_matches = module->ResolveSymbolContextsForFileSpec (file_spec, |
| 1468 | 0, |
| 1469 | false, |
| 1470 | eSymbolContextCompUnit, |
| 1471 | sc_list); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1472 | |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 1473 | for (uint32_t i = 0; i < num_matches; ++i) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1474 | { |
| 1475 | SymbolContext sc; |
| 1476 | if (sc_list.GetContextAtIndex(i, sc)) |
| 1477 | { |
| 1478 | if (i > 0) |
| 1479 | strm << "\n\n"; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1480 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1481 | strm << "Line table for " << *static_cast<FileSpec*> (sc.comp_unit) << " in `" |
| 1482 | << module->GetFileSpec().GetFilename() << "\n"; |
| 1483 | LineTable *line_table = sc.comp_unit->GetLineTable(); |
| 1484 | if (line_table) |
| 1485 | line_table->GetDescription (&strm, |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 1486 | interpreter.GetExecutionContext().GetTargetPtr(), |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1487 | lldb::eDescriptionLevelBrief); |
| 1488 | else |
| 1489 | strm << "No line table"; |
| 1490 | } |
| 1491 | } |
| 1492 | } |
| 1493 | return num_matches; |
| 1494 | } |
| 1495 | |
| 1496 | static void |
| 1497 | DumpFullpath (Stream &strm, const FileSpec *file_spec_ptr, uint32_t width) |
| 1498 | { |
| 1499 | if (file_spec_ptr) |
| 1500 | { |
| 1501 | if (width > 0) |
| 1502 | { |
Jason Molenda | db7d11c | 2013-05-06 10:21:11 +0000 | [diff] [blame] | 1503 | std::string fullpath = file_spec_ptr->GetPath(); |
| 1504 | strm.Printf("%-*s", width, fullpath.c_str()); |
| 1505 | return; |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1506 | } |
| 1507 | else |
| 1508 | { |
| 1509 | file_spec_ptr->Dump(&strm); |
| 1510 | return; |
| 1511 | } |
| 1512 | } |
| 1513 | // Keep the width spacing correct if things go wrong... |
| 1514 | if (width > 0) |
| 1515 | strm.Printf("%-*s", width, ""); |
| 1516 | } |
| 1517 | |
| 1518 | static void |
| 1519 | DumpDirectory (Stream &strm, const FileSpec *file_spec_ptr, uint32_t width) |
| 1520 | { |
| 1521 | if (file_spec_ptr) |
| 1522 | { |
| 1523 | if (width > 0) |
| 1524 | strm.Printf("%-*s", width, file_spec_ptr->GetDirectory().AsCString("")); |
| 1525 | else |
| 1526 | file_spec_ptr->GetDirectory().Dump(&strm); |
| 1527 | return; |
| 1528 | } |
| 1529 | // Keep the width spacing correct if things go wrong... |
| 1530 | if (width > 0) |
| 1531 | strm.Printf("%-*s", width, ""); |
| 1532 | } |
| 1533 | |
| 1534 | static void |
| 1535 | DumpBasename (Stream &strm, const FileSpec *file_spec_ptr, uint32_t width) |
| 1536 | { |
| 1537 | if (file_spec_ptr) |
| 1538 | { |
| 1539 | if (width > 0) |
| 1540 | strm.Printf("%-*s", width, file_spec_ptr->GetFilename().AsCString("")); |
| 1541 | else |
| 1542 | file_spec_ptr->GetFilename().Dump(&strm); |
| 1543 | return; |
| 1544 | } |
| 1545 | // Keep the width spacing correct if things go wrong... |
| 1546 | if (width > 0) |
| 1547 | strm.Printf("%-*s", width, ""); |
| 1548 | } |
| 1549 | |
Adrian McCarthy | 543725c | 2016-04-04 21:21:49 +0000 | [diff] [blame] | 1550 | static size_t |
| 1551 | DumpModuleObjfileHeaders(Stream &strm, ModuleList &module_list) |
| 1552 | { |
| 1553 | size_t num_dumped = 0; |
Saleem Abdulrasool | bb19a13 | 2016-05-19 05:13:57 +0000 | [diff] [blame] | 1554 | std::lock_guard<std::recursive_mutex> guard(module_list.GetMutex()); |
Adrian McCarthy | 543725c | 2016-04-04 21:21:49 +0000 | [diff] [blame] | 1555 | const size_t num_modules = module_list.GetSize(); |
| 1556 | if (num_modules > 0) |
| 1557 | { |
| 1558 | strm.Printf("Dumping headers for %" PRIu64 " module(s).\n", static_cast<uint64_t>(num_modules)); |
| 1559 | strm.IndentMore(); |
| 1560 | for (size_t image_idx = 0; image_idx < num_modules; ++image_idx) |
| 1561 | { |
| 1562 | Module *module = module_list.GetModulePointerAtIndexUnlocked(image_idx); |
| 1563 | if (module) |
| 1564 | { |
| 1565 | if (num_dumped++ > 0) |
| 1566 | { |
| 1567 | strm.EOL(); |
| 1568 | strm.EOL(); |
| 1569 | } |
| 1570 | ObjectFile *objfile = module->GetObjectFile(); |
| 1571 | objfile->Dump(&strm); |
| 1572 | } |
| 1573 | } |
| 1574 | strm.IndentLess(); |
| 1575 | } |
| 1576 | return num_dumped; |
| 1577 | } |
| 1578 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1579 | static void |
| 1580 | DumpModuleSymtab (CommandInterpreter &interpreter, Stream &strm, Module *module, SortOrder sort_order) |
| 1581 | { |
| 1582 | if (module) |
| 1583 | { |
Michael Sartain | a7499c9 | 2013-07-01 19:45:50 +0000 | [diff] [blame] | 1584 | SymbolVendor *sym_vendor = module->GetSymbolVendor (); |
| 1585 | if (sym_vendor) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1586 | { |
Michael Sartain | a7499c9 | 2013-07-01 19:45:50 +0000 | [diff] [blame] | 1587 | Symtab *symtab = sym_vendor->GetSymtab(); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1588 | if (symtab) |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 1589 | symtab->Dump(&strm, interpreter.GetExecutionContext().GetTargetPtr(), sort_order); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1590 | } |
| 1591 | } |
| 1592 | } |
| 1593 | |
| 1594 | static void |
| 1595 | DumpModuleSections (CommandInterpreter &interpreter, Stream &strm, Module *module) |
| 1596 | { |
| 1597 | if (module) |
| 1598 | { |
Greg Clayton | 3046e66 | 2013-07-10 01:23:25 +0000 | [diff] [blame] | 1599 | SectionList *section_list = module->GetSectionList(); |
Michael Sartain | a7499c9 | 2013-07-01 19:45:50 +0000 | [diff] [blame] | 1600 | if (section_list) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1601 | { |
Michael Sartain | a7499c9 | 2013-07-01 19:45:50 +0000 | [diff] [blame] | 1602 | strm.Printf ("Sections for '%s' (%s):\n", |
| 1603 | module->GetSpecificationDescription().c_str(), |
| 1604 | module->GetArchitecture().GetArchitectureName()); |
| 1605 | strm.IndentMore(); |
| 1606 | section_list->Dump(&strm, interpreter.GetExecutionContext().GetTargetPtr(), true, UINT32_MAX); |
| 1607 | strm.IndentLess(); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1608 | } |
| 1609 | } |
| 1610 | } |
| 1611 | |
| 1612 | static bool |
| 1613 | DumpModuleSymbolVendor (Stream &strm, Module *module) |
| 1614 | { |
| 1615 | if (module) |
| 1616 | { |
| 1617 | SymbolVendor *symbol_vendor = module->GetSymbolVendor(true); |
| 1618 | if (symbol_vendor) |
| 1619 | { |
| 1620 | symbol_vendor->Dump(&strm); |
| 1621 | return true; |
| 1622 | } |
| 1623 | } |
| 1624 | return false; |
| 1625 | } |
| 1626 | |
Greg Clayton | c4a8a76 | 2012-05-15 18:43:44 +0000 | [diff] [blame] | 1627 | static void |
| 1628 | DumpAddress (ExecutionContextScope *exe_scope, const Address &so_addr, bool verbose, Stream &strm) |
| 1629 | { |
| 1630 | strm.IndentMore(); |
| 1631 | strm.Indent (" Address: "); |
| 1632 | so_addr.Dump (&strm, exe_scope, Address::DumpStyleModuleWithFileAddress); |
| 1633 | strm.PutCString (" ("); |
| 1634 | so_addr.Dump (&strm, exe_scope, Address::DumpStyleSectionNameOffset); |
| 1635 | strm.PutCString (")\n"); |
| 1636 | strm.Indent (" Summary: "); |
| 1637 | const uint32_t save_indent = strm.GetIndentLevel (); |
| 1638 | strm.SetIndentLevel (save_indent + 13); |
| 1639 | so_addr.Dump (&strm, exe_scope, Address::DumpStyleResolvedDescription); |
| 1640 | strm.SetIndentLevel (save_indent); |
| 1641 | // Print out detailed address information when verbose is enabled |
| 1642 | if (verbose) |
| 1643 | { |
| 1644 | strm.EOL(); |
| 1645 | so_addr.Dump (&strm, exe_scope, Address::DumpStyleDetailedSymbolContext); |
| 1646 | } |
| 1647 | strm.IndentLess(); |
| 1648 | } |
| 1649 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1650 | static bool |
Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 1651 | LookupAddressInModule (CommandInterpreter &interpreter, |
| 1652 | Stream &strm, |
| 1653 | Module *module, |
| 1654 | uint32_t resolve_mask, |
| 1655 | lldb::addr_t raw_addr, |
| 1656 | lldb::addr_t offset, |
| 1657 | bool verbose) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1658 | { |
| 1659 | if (module) |
| 1660 | { |
| 1661 | lldb::addr_t addr = raw_addr - offset; |
| 1662 | Address so_addr; |
| 1663 | SymbolContext sc; |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 1664 | Target *target = interpreter.GetExecutionContext().GetTargetPtr(); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1665 | if (target && !target->GetSectionLoadList().IsEmpty()) |
| 1666 | { |
| 1667 | if (!target->GetSectionLoadList().ResolveLoadAddress (addr, so_addr)) |
| 1668 | return false; |
Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 1669 | else if (so_addr.GetModule().get() != module) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1670 | return false; |
| 1671 | } |
| 1672 | else |
| 1673 | { |
| 1674 | if (!module->ResolveFileAddress (addr, so_addr)) |
| 1675 | return false; |
| 1676 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1677 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1678 | ExecutionContextScope *exe_scope = interpreter.GetExecutionContext().GetBestExecutionContextScope(); |
Greg Clayton | c4a8a76 | 2012-05-15 18:43:44 +0000 | [diff] [blame] | 1679 | DumpAddress (exe_scope, so_addr, verbose, strm); |
| 1680 | // strm.IndentMore(); |
| 1681 | // strm.Indent (" Address: "); |
| 1682 | // so_addr.Dump (&strm, exe_scope, Address::DumpStyleModuleWithFileAddress); |
| 1683 | // strm.PutCString (" ("); |
| 1684 | // so_addr.Dump (&strm, exe_scope, Address::DumpStyleSectionNameOffset); |
| 1685 | // strm.PutCString (")\n"); |
| 1686 | // strm.Indent (" Summary: "); |
| 1687 | // const uint32_t save_indent = strm.GetIndentLevel (); |
| 1688 | // strm.SetIndentLevel (save_indent + 13); |
| 1689 | // so_addr.Dump (&strm, exe_scope, Address::DumpStyleResolvedDescription); |
| 1690 | // strm.SetIndentLevel (save_indent); |
| 1691 | // // Print out detailed address information when verbose is enabled |
| 1692 | // if (verbose) |
| 1693 | // { |
| 1694 | // strm.EOL(); |
| 1695 | // so_addr.Dump (&strm, exe_scope, Address::DumpStyleDetailedSymbolContext); |
| 1696 | // } |
| 1697 | // strm.IndentLess(); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1698 | return true; |
| 1699 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1700 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1701 | return false; |
| 1702 | } |
| 1703 | |
| 1704 | static uint32_t |
Greg Clayton | c4a8a76 | 2012-05-15 18:43:44 +0000 | [diff] [blame] | 1705 | 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] | 1706 | { |
| 1707 | if (module) |
| 1708 | { |
| 1709 | SymbolContext sc; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1710 | |
Michael Sartain | a7499c9 | 2013-07-01 19:45:50 +0000 | [diff] [blame] | 1711 | SymbolVendor *sym_vendor = module->GetSymbolVendor (); |
| 1712 | if (sym_vendor) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1713 | { |
Michael Sartain | a7499c9 | 2013-07-01 19:45:50 +0000 | [diff] [blame] | 1714 | Symtab *symtab = sym_vendor->GetSymtab(); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1715 | if (symtab) |
| 1716 | { |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1717 | std::vector<uint32_t> match_indexes; |
| 1718 | ConstString symbol_name (name); |
| 1719 | uint32_t num_matches = 0; |
| 1720 | if (name_is_regex) |
| 1721 | { |
| 1722 | RegularExpression name_regexp(name); |
| 1723 | num_matches = symtab->AppendSymbolIndexesMatchingRegExAndType (name_regexp, |
| 1724 | eSymbolTypeAny, |
| 1725 | match_indexes); |
| 1726 | } |
| 1727 | else |
| 1728 | { |
| 1729 | num_matches = symtab->AppendSymbolIndexesWithName (symbol_name, match_indexes); |
| 1730 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1731 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1732 | if (num_matches > 0) |
| 1733 | { |
| 1734 | strm.Indent (); |
| 1735 | strm.Printf("%u symbols match %s'%s' in ", num_matches, |
| 1736 | name_is_regex ? "the regular expression " : "", name); |
| 1737 | DumpFullpath (strm, &module->GetFileSpec(), 0); |
| 1738 | strm.PutCString(":\n"); |
| 1739 | strm.IndentMore (); |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 1740 | for (uint32_t i = 0; i < num_matches; ++i) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1741 | { |
| 1742 | Symbol *symbol = symtab->SymbolAtIndex(match_indexes[i]); |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 1743 | if (symbol && symbol->ValueIsAddress()) |
| 1744 | { |
| 1745 | DumpAddress (interpreter.GetExecutionContext().GetBestExecutionContextScope(), |
| 1746 | symbol->GetAddressRef(), |
| 1747 | verbose, |
| 1748 | strm); |
| 1749 | } |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1750 | } |
| 1751 | strm.IndentLess (); |
| 1752 | return num_matches; |
| 1753 | } |
| 1754 | } |
| 1755 | } |
| 1756 | } |
| 1757 | return 0; |
| 1758 | } |
| 1759 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1760 | static void |
Greg Clayton | c4a8a76 | 2012-05-15 18:43:44 +0000 | [diff] [blame] | 1761 | DumpSymbolContextList (ExecutionContextScope *exe_scope, Stream &strm, SymbolContextList &sc_list, bool verbose) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1762 | { |
| 1763 | strm.IndentMore (); |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 1764 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1765 | const uint32_t num_matches = sc_list.GetSize(); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1766 | |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 1767 | for (uint32_t i = 0; i < num_matches; ++i) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1768 | { |
| 1769 | SymbolContext sc; |
| 1770 | if (sc_list.GetContextAtIndex(i, sc)) |
| 1771 | { |
Sean Callanan | f6172c2 | 2012-02-11 00:24:04 +0000 | [diff] [blame] | 1772 | AddressRange range; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1773 | |
Sean Callanan | f6172c2 | 2012-02-11 00:24:04 +0000 | [diff] [blame] | 1774 | sc.GetAddressRange(eSymbolContextEverything, |
| 1775 | 0, |
| 1776 | true, |
| 1777 | range); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1778 | |
Greg Clayton | c4a8a76 | 2012-05-15 18:43:44 +0000 | [diff] [blame] | 1779 | DumpAddress (exe_scope, range.GetBaseAddress(), verbose, strm); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1780 | } |
| 1781 | } |
| 1782 | strm.IndentLess (); |
| 1783 | } |
| 1784 | |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 1785 | static size_t |
Greg Clayton | c4a8a76 | 2012-05-15 18:43:44 +0000 | [diff] [blame] | 1786 | LookupFunctionInModule (CommandInterpreter &interpreter, |
| 1787 | Stream &strm, |
| 1788 | Module *module, |
| 1789 | const char *name, |
| 1790 | bool name_is_regex, |
| 1791 | bool include_inlines, |
| 1792 | bool include_symbols, |
| 1793 | bool verbose) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1794 | { |
| 1795 | if (module && name && name[0]) |
| 1796 | { |
| 1797 | SymbolContextList sc_list; |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1798 | const bool append = true; |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 1799 | size_t num_matches = 0; |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1800 | if (name_is_regex) |
| 1801 | { |
| 1802 | RegularExpression function_name_regex (name); |
| 1803 | num_matches = module->FindFunctions (function_name_regex, |
| 1804 | include_symbols, |
Sean Callanan | 9df05fb | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 1805 | include_inlines, |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1806 | append, |
| 1807 | sc_list); |
| 1808 | } |
| 1809 | else |
| 1810 | { |
| 1811 | ConstString function_name (name); |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 1812 | num_matches = module->FindFunctions(function_name, |
| 1813 | nullptr, |
| 1814 | eFunctionNameTypeAuto, |
| 1815 | include_symbols, |
| 1816 | include_inlines, |
| 1817 | append, |
| 1818 | sc_list); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1819 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1820 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1821 | if (num_matches) |
| 1822 | { |
| 1823 | strm.Indent (); |
Deepak Panickal | 99fbc07 | 2014-03-03 15:39:47 +0000 | [diff] [blame] | 1824 | 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] | 1825 | DumpFullpath (strm, &module->GetFileSpec(), 0); |
| 1826 | strm.PutCString(":\n"); |
Greg Clayton | c4a8a76 | 2012-05-15 18:43:44 +0000 | [diff] [blame] | 1827 | DumpSymbolContextList (interpreter.GetExecutionContext().GetBestExecutionContextScope(), strm, sc_list, verbose); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1828 | } |
| 1829 | return num_matches; |
| 1830 | } |
| 1831 | return 0; |
| 1832 | } |
| 1833 | |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 1834 | static size_t |
Greg Clayton | aafa5c9 | 2012-05-15 19:26:12 +0000 | [diff] [blame] | 1835 | LookupTypeInModule (CommandInterpreter &interpreter, |
Greg Clayton | 644247c | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 1836 | Stream &strm, |
| 1837 | Module *module, |
| 1838 | const char *name_cstr, |
| 1839 | bool name_is_regex) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1840 | { |
| 1841 | if (module && name_cstr && name_cstr[0]) |
| 1842 | { |
Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 1843 | TypeList type_list; |
Greg Clayton | 84db910 | 2012-03-26 23:03:23 +0000 | [diff] [blame] | 1844 | const uint32_t max_num_matches = UINT32_MAX; |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 1845 | size_t num_matches = 0; |
Greg Clayton | 84db910 | 2012-03-26 23:03:23 +0000 | [diff] [blame] | 1846 | bool name_is_fully_qualified = false; |
Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 1847 | SymbolContext sc; |
| 1848 | |
| 1849 | ConstString name(name_cstr); |
Greg Clayton | ae088e5 | 2016-02-10 21:28:13 +0000 | [diff] [blame] | 1850 | llvm::DenseSet<lldb_private::SymbolFile *> searched_symbol_files; |
| 1851 | num_matches = module->FindTypes(sc, name, name_is_fully_qualified, max_num_matches, searched_symbol_files, type_list); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1852 | |
Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 1853 | if (num_matches) |
| 1854 | { |
| 1855 | strm.Indent (); |
Deepak Panickal | 99fbc07 | 2014-03-03 15:39:47 +0000 | [diff] [blame] | 1856 | 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] | 1857 | DumpFullpath (strm, &module->GetFileSpec(), 0); |
| 1858 | strm.PutCString(":\n"); |
Sean Callanan | 5c19eac | 2013-11-06 19:28:40 +0000 | [diff] [blame] | 1859 | for (TypeSP type_sp : type_list.Types()) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1860 | { |
Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 1861 | if (type_sp) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1862 | { |
Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 1863 | // Resolve the clang type so that any forward references |
| 1864 | // to types that haven't yet been parsed will get parsed. |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 1865 | type_sp->GetFullCompilerType (); |
Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 1866 | type_sp->GetDescription (&strm, eDescriptionLevelFull, true); |
Greg Clayton | aafa5c9 | 2012-05-15 19:26:12 +0000 | [diff] [blame] | 1867 | // Print all typedef chains |
| 1868 | TypeSP typedef_type_sp (type_sp); |
| 1869 | TypeSP typedefed_type_sp (typedef_type_sp->GetTypedefType()); |
| 1870 | while (typedefed_type_sp) |
| 1871 | { |
| 1872 | strm.EOL(); |
| 1873 | strm.Printf(" typedef '%s': ", typedef_type_sp->GetName().GetCString()); |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 1874 | typedefed_type_sp->GetFullCompilerType (); |
Greg Clayton | aafa5c9 | 2012-05-15 19:26:12 +0000 | [diff] [blame] | 1875 | typedefed_type_sp->GetDescription (&strm, eDescriptionLevelFull, true); |
| 1876 | typedef_type_sp = typedefed_type_sp; |
| 1877 | typedefed_type_sp = typedef_type_sp->GetTypedefType(); |
| 1878 | } |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1879 | } |
Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 1880 | strm.EOL(); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1881 | } |
Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 1882 | } |
| 1883 | return num_matches; |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1884 | } |
| 1885 | return 0; |
| 1886 | } |
| 1887 | |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 1888 | static size_t |
Sean Callanan | d38b4a9 | 2012-06-06 20:49:55 +0000 | [diff] [blame] | 1889 | LookupTypeHere (CommandInterpreter &interpreter, |
| 1890 | Stream &strm, |
| 1891 | const SymbolContext &sym_ctx, |
| 1892 | const char *name_cstr, |
| 1893 | bool name_is_regex) |
| 1894 | { |
| 1895 | if (!sym_ctx.module_sp) |
| 1896 | return 0; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1897 | |
Sean Callanan | d38b4a9 | 2012-06-06 20:49:55 +0000 | [diff] [blame] | 1898 | TypeList type_list; |
| 1899 | const uint32_t max_num_matches = UINT32_MAX; |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 1900 | size_t num_matches = 1; |
Sean Callanan | d38b4a9 | 2012-06-06 20:49:55 +0000 | [diff] [blame] | 1901 | bool name_is_fully_qualified = false; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1902 | |
Sean Callanan | d38b4a9 | 2012-06-06 20:49:55 +0000 | [diff] [blame] | 1903 | ConstString name(name_cstr); |
Greg Clayton | ae088e5 | 2016-02-10 21:28:13 +0000 | [diff] [blame] | 1904 | llvm::DenseSet<SymbolFile *> searched_symbol_files; |
| 1905 | num_matches = sym_ctx.module_sp->FindTypes(sym_ctx, name, name_is_fully_qualified, max_num_matches, searched_symbol_files, type_list); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1906 | |
Sean Callanan | d38b4a9 | 2012-06-06 20:49:55 +0000 | [diff] [blame] | 1907 | if (num_matches) |
| 1908 | { |
| 1909 | strm.Indent (); |
| 1910 | strm.PutCString("Best match found in "); |
| 1911 | DumpFullpath (strm, &sym_ctx.module_sp->GetFileSpec(), 0); |
| 1912 | strm.PutCString(":\n"); |
Enrico Granata | e5ffa08 | 2015-09-23 19:32:56 +0000 | [diff] [blame] | 1913 | |
Sean Callanan | d38b4a9 | 2012-06-06 20:49:55 +0000 | [diff] [blame] | 1914 | TypeSP type_sp (type_list.GetTypeAtIndex(0)); |
| 1915 | if (type_sp) |
| 1916 | { |
| 1917 | // Resolve the clang type so that any forward references |
| 1918 | // to types that haven't yet been parsed will get parsed. |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 1919 | type_sp->GetFullCompilerType (); |
Sean Callanan | d38b4a9 | 2012-06-06 20:49:55 +0000 | [diff] [blame] | 1920 | type_sp->GetDescription (&strm, eDescriptionLevelFull, true); |
| 1921 | // Print all typedef chains |
| 1922 | TypeSP typedef_type_sp (type_sp); |
| 1923 | TypeSP typedefed_type_sp (typedef_type_sp->GetTypedefType()); |
| 1924 | while (typedefed_type_sp) |
| 1925 | { |
| 1926 | strm.EOL(); |
| 1927 | strm.Printf(" typedef '%s': ", typedef_type_sp->GetName().GetCString()); |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 1928 | typedefed_type_sp->GetFullCompilerType (); |
Sean Callanan | d38b4a9 | 2012-06-06 20:49:55 +0000 | [diff] [blame] | 1929 | typedefed_type_sp->GetDescription (&strm, eDescriptionLevelFull, true); |
| 1930 | typedef_type_sp = typedefed_type_sp; |
| 1931 | typedefed_type_sp = typedef_type_sp->GetTypedefType(); |
| 1932 | } |
| 1933 | } |
| 1934 | strm.EOL(); |
| 1935 | } |
| 1936 | return num_matches; |
| 1937 | } |
| 1938 | |
| 1939 | static uint32_t |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1940 | LookupFileAndLineInModule (CommandInterpreter &interpreter, |
Sean Callanan | d38b4a9 | 2012-06-06 20:49:55 +0000 | [diff] [blame] | 1941 | Stream &strm, |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1942 | Module *module, |
| 1943 | const FileSpec &file_spec, |
| 1944 | uint32_t line, |
| 1945 | bool check_inlines, |
| 1946 | bool verbose) |
| 1947 | { |
| 1948 | if (module && file_spec) |
| 1949 | { |
| 1950 | SymbolContextList sc_list; |
| 1951 | const uint32_t num_matches = module->ResolveSymbolContextsForFileSpec(file_spec, line, check_inlines, |
| 1952 | eSymbolContextEverything, sc_list); |
| 1953 | if (num_matches > 0) |
| 1954 | { |
| 1955 | strm.Indent (); |
| 1956 | strm.Printf("%u match%s found in ", num_matches, num_matches > 1 ? "es" : ""); |
| 1957 | strm << file_spec; |
| 1958 | if (line > 0) |
| 1959 | strm.Printf (":%u", line); |
| 1960 | strm << " in "; |
| 1961 | DumpFullpath (strm, &module->GetFileSpec(), 0); |
| 1962 | strm.PutCString(":\n"); |
Greg Clayton | c4a8a76 | 2012-05-15 18:43:44 +0000 | [diff] [blame] | 1963 | DumpSymbolContextList (interpreter.GetExecutionContext().GetBestExecutionContextScope(), strm, sc_list, verbose); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1964 | return num_matches; |
| 1965 | } |
| 1966 | } |
| 1967 | return 0; |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1968 | } |
| 1969 | |
Greg Clayton | 8ee6438 | 2011-11-10 01:18:58 +0000 | [diff] [blame] | 1970 | static size_t |
| 1971 | FindModulesByName (Target *target, |
| 1972 | const char *module_name, |
| 1973 | ModuleList &module_list, |
| 1974 | bool check_global_list) |
| 1975 | { |
Greg Clayton | 8ee6438 | 2011-11-10 01:18:58 +0000 | [diff] [blame] | 1976 | FileSpec module_file_spec(module_name, false); |
Greg Clayton | b9a01b3 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 1977 | ModuleSpec module_spec (module_file_spec); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1978 | |
Greg Clayton | 8ee6438 | 2011-11-10 01:18:58 +0000 | [diff] [blame] | 1979 | const size_t initial_size = module_list.GetSize (); |
| 1980 | |
Greg Clayton | f315626 | 2012-07-11 20:46:47 +0000 | [diff] [blame] | 1981 | if (check_global_list) |
Greg Clayton | 8ee6438 | 2011-11-10 01:18:58 +0000 | [diff] [blame] | 1982 | { |
| 1983 | // Check the global list |
Saleem Abdulrasool | 16ff860 | 2016-05-18 01:59:10 +0000 | [diff] [blame] | 1984 | std::lock_guard<std::recursive_mutex> guard(Module::GetAllocationModuleCollectionMutex()); |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 1985 | const size_t num_modules = Module::GetNumberAllocatedModules(); |
Greg Clayton | 8ee6438 | 2011-11-10 01:18:58 +0000 | [diff] [blame] | 1986 | ModuleSP module_sp; |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 1987 | for (size_t image_idx = 0; image_idx<num_modules; ++image_idx) |
Greg Clayton | 8ee6438 | 2011-11-10 01:18:58 +0000 | [diff] [blame] | 1988 | { |
| 1989 | Module *module = Module::GetAllocatedModuleAtIndex(image_idx); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1990 | |
Greg Clayton | 8ee6438 | 2011-11-10 01:18:58 +0000 | [diff] [blame] | 1991 | if (module) |
| 1992 | { |
Greg Clayton | b9a01b3 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 1993 | if (module->MatchesModuleSpec (module_spec)) |
Greg Clayton | 8ee6438 | 2011-11-10 01:18:58 +0000 | [diff] [blame] | 1994 | { |
Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 1995 | module_sp = module->shared_from_this(); |
Greg Clayton | 8ee6438 | 2011-11-10 01:18:58 +0000 | [diff] [blame] | 1996 | module_list.AppendIfNeeded(module_sp); |
| 1997 | } |
| 1998 | } |
| 1999 | } |
| 2000 | } |
Greg Clayton | f315626 | 2012-07-11 20:46:47 +0000 | [diff] [blame] | 2001 | else |
| 2002 | { |
| 2003 | if (target) |
| 2004 | { |
| 2005 | const size_t num_matches = target->GetImages().FindModules (module_spec, module_list); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2006 | |
Greg Clayton | f315626 | 2012-07-11 20:46:47 +0000 | [diff] [blame] | 2007 | // Not found in our module list for our target, check the main |
| 2008 | // shared module list in case it is a extra file used somewhere |
| 2009 | // else |
| 2010 | if (num_matches == 0) |
| 2011 | { |
| 2012 | module_spec.GetArchitecture() = target->GetArchitecture(); |
| 2013 | ModuleList::FindSharedModules (module_spec, module_list); |
| 2014 | } |
| 2015 | } |
| 2016 | else |
| 2017 | { |
| 2018 | ModuleList::FindSharedModules (module_spec,module_list); |
| 2019 | } |
| 2020 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2021 | |
Greg Clayton | 8ee6438 | 2011-11-10 01:18:58 +0000 | [diff] [blame] | 2022 | return module_list.GetSize () - initial_size; |
| 2023 | } |
| 2024 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2025 | #pragma mark CommandObjectTargetModulesModuleAutoComplete |
| 2026 | |
| 2027 | //---------------------------------------------------------------------- |
| 2028 | // A base command object class that can auto complete with module file |
| 2029 | // paths |
| 2030 | //---------------------------------------------------------------------- |
| 2031 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 2032 | class CommandObjectTargetModulesModuleAutoComplete : public CommandObjectParsed |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2033 | { |
| 2034 | public: |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2035 | CommandObjectTargetModulesModuleAutoComplete (CommandInterpreter &interpreter, |
| 2036 | const char *name, |
| 2037 | const char *help, |
| 2038 | const char *syntax) : |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 2039 | CommandObjectParsed (interpreter, name, help, syntax) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2040 | { |
| 2041 | CommandArgumentEntry arg; |
| 2042 | CommandArgumentData file_arg; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2043 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2044 | // Define the first (and only) variant of this arg. |
| 2045 | file_arg.arg_type = eArgTypeFilename; |
| 2046 | file_arg.arg_repetition = eArgRepeatStar; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2047 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2048 | // There is only one variant this argument could be; put it into the argument entry. |
| 2049 | arg.push_back (file_arg); |
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 | // Push the data for the first argument into the m_arguments vector. |
| 2052 | m_arguments.push_back (arg); |
| 2053 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2054 | |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 2055 | ~CommandObjectTargetModulesModuleAutoComplete() override = default; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2056 | |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 2057 | int |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2058 | HandleArgumentCompletion (Args &input, |
| 2059 | int &cursor_index, |
| 2060 | int &cursor_char_position, |
| 2061 | OptionElementVector &opt_element_vector, |
| 2062 | int match_start_point, |
| 2063 | int max_return_elements, |
| 2064 | bool &word_complete, |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 2065 | StringList &matches) override |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2066 | { |
| 2067 | // Arguments are the standard module completer. |
| 2068 | std::string completion_str (input.GetArgumentAtIndex(cursor_index)); |
| 2069 | completion_str.erase (cursor_char_position); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2070 | |
Todd Fiala | e1cfbc7 | 2016-08-11 23:51:28 +0000 | [diff] [blame] | 2071 | CommandCompletions::InvokeCommonCompletionCallbacks(GetCommandInterpreter(), |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 2072 | CommandCompletions::eModuleCompletion, |
| 2073 | completion_str.c_str(), |
| 2074 | match_start_point, |
| 2075 | max_return_elements, |
| 2076 | nullptr, |
| 2077 | word_complete, |
| 2078 | matches); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2079 | return matches.GetSize(); |
| 2080 | } |
| 2081 | }; |
| 2082 | |
| 2083 | #pragma mark CommandObjectTargetModulesSourceFileAutoComplete |
| 2084 | |
| 2085 | //---------------------------------------------------------------------- |
| 2086 | // A base command object class that can auto complete with module source |
| 2087 | // file paths |
| 2088 | //---------------------------------------------------------------------- |
| 2089 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 2090 | class CommandObjectTargetModulesSourceFileAutoComplete : public CommandObjectParsed |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2091 | { |
| 2092 | public: |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2093 | CommandObjectTargetModulesSourceFileAutoComplete (CommandInterpreter &interpreter, |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 2094 | const char *name, |
| 2095 | const char *help, |
| 2096 | const char *syntax, |
| 2097 | uint32_t flags) : |
| 2098 | CommandObjectParsed (interpreter, name, help, syntax, flags) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2099 | { |
| 2100 | CommandArgumentEntry arg; |
| 2101 | CommandArgumentData source_file_arg; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2102 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2103 | // Define the first (and only) variant of this arg. |
| 2104 | source_file_arg.arg_type = eArgTypeSourceFile; |
| 2105 | source_file_arg.arg_repetition = eArgRepeatPlus; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2106 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2107 | // There is only one variant this argument could be; put it into the argument entry. |
| 2108 | arg.push_back (source_file_arg); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2109 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2110 | // Push the data for the first argument into the m_arguments vector. |
| 2111 | m_arguments.push_back (arg); |
| 2112 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2113 | |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 2114 | ~CommandObjectTargetModulesSourceFileAutoComplete() override = default; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2115 | |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 2116 | int |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2117 | HandleArgumentCompletion (Args &input, |
| 2118 | int &cursor_index, |
| 2119 | int &cursor_char_position, |
| 2120 | OptionElementVector &opt_element_vector, |
| 2121 | int match_start_point, |
| 2122 | int max_return_elements, |
| 2123 | bool &word_complete, |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 2124 | StringList &matches) override |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2125 | { |
| 2126 | // Arguments are the standard source file completer. |
| 2127 | std::string completion_str (input.GetArgumentAtIndex(cursor_index)); |
| 2128 | completion_str.erase (cursor_char_position); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2129 | |
Todd Fiala | e1cfbc7 | 2016-08-11 23:51:28 +0000 | [diff] [blame] | 2130 | CommandCompletions::InvokeCommonCompletionCallbacks(GetCommandInterpreter(), |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 2131 | CommandCompletions::eSourceFileCompletion, |
| 2132 | completion_str.c_str(), |
| 2133 | match_start_point, |
| 2134 | max_return_elements, |
| 2135 | nullptr, |
| 2136 | word_complete, |
| 2137 | matches); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2138 | return matches.GetSize(); |
| 2139 | } |
| 2140 | }; |
| 2141 | |
Adrian McCarthy | 543725c | 2016-04-04 21:21:49 +0000 | [diff] [blame] | 2142 | #pragma mark CommandObjectTargetModulesDumpObjfile |
| 2143 | |
| 2144 | class CommandObjectTargetModulesDumpObjfile : public CommandObjectTargetModulesModuleAutoComplete |
| 2145 | { |
| 2146 | public: |
| 2147 | CommandObjectTargetModulesDumpObjfile(CommandInterpreter &interpreter) |
| 2148 | : CommandObjectTargetModulesModuleAutoComplete(interpreter, "target modules dump objfile", |
| 2149 | "Dump the object file headers from one or more target modules.", |
| 2150 | nullptr) |
| 2151 | { |
| 2152 | } |
| 2153 | |
| 2154 | ~CommandObjectTargetModulesDumpObjfile() override = default; |
| 2155 | |
| 2156 | protected: |
| 2157 | bool |
| 2158 | DoExecute(Args &command, CommandReturnObject &result) override |
| 2159 | { |
| 2160 | Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); |
| 2161 | if (target == nullptr) |
| 2162 | { |
| 2163 | result.AppendError("invalid target, create a debug target using the 'target create' command"); |
| 2164 | result.SetStatus(eReturnStatusFailed); |
| 2165 | return false; |
| 2166 | } |
| 2167 | |
| 2168 | uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize(); |
| 2169 | result.GetOutputStream().SetAddressByteSize(addr_byte_size); |
| 2170 | result.GetErrorStream().SetAddressByteSize(addr_byte_size); |
| 2171 | |
| 2172 | size_t num_dumped = 0; |
| 2173 | if (command.GetArgumentCount() == 0) |
| 2174 | { |
| 2175 | // Dump all headers for all modules images |
| 2176 | num_dumped = DumpModuleObjfileHeaders(result.GetOutputStream(), target->GetImages()); |
| 2177 | if (num_dumped == 0) |
| 2178 | { |
| 2179 | result.AppendError("the target has no associated executable images"); |
| 2180 | result.SetStatus(eReturnStatusFailed); |
| 2181 | } |
| 2182 | } |
| 2183 | else |
| 2184 | { |
| 2185 | // Find the modules that match the basename or full path. |
| 2186 | ModuleList module_list; |
| 2187 | const char *arg_cstr; |
| 2188 | for (int arg_idx = 0; (arg_cstr = command.GetArgumentAtIndex(arg_idx)) != nullptr; ++arg_idx) |
| 2189 | { |
| 2190 | size_t num_matched = FindModulesByName(target, arg_cstr, module_list, true); |
| 2191 | if (num_matched == 0) |
| 2192 | { |
| 2193 | result.AppendWarningWithFormat("Unable to find an image that matches '%s'.\n", arg_cstr); |
| 2194 | } |
| 2195 | } |
| 2196 | // Dump all the modules we found. |
| 2197 | num_dumped = DumpModuleObjfileHeaders(result.GetOutputStream(), module_list); |
| 2198 | } |
| 2199 | |
| 2200 | if (num_dumped > 0) |
| 2201 | { |
| 2202 | result.SetStatus(eReturnStatusSuccessFinishResult); |
| 2203 | } |
| 2204 | else |
| 2205 | { |
| 2206 | result.AppendError("no matching executable images found"); |
| 2207 | result.SetStatus(eReturnStatusFailed); |
| 2208 | } |
| 2209 | return result.Succeeded(); |
| 2210 | } |
| 2211 | }; |
| 2212 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2213 | #pragma mark CommandObjectTargetModulesDumpSymtab |
| 2214 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2215 | class CommandObjectTargetModulesDumpSymtab : public CommandObjectTargetModulesModuleAutoComplete |
| 2216 | { |
| 2217 | public: |
| 2218 | CommandObjectTargetModulesDumpSymtab (CommandInterpreter &interpreter) : |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 2219 | CommandObjectTargetModulesModuleAutoComplete(interpreter, |
| 2220 | "target modules dump symtab", |
| 2221 | "Dump the symbol table from one or more target modules.", |
| 2222 | nullptr), |
Todd Fiala | e1cfbc7 | 2016-08-11 23:51:28 +0000 | [diff] [blame] | 2223 | m_options() |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2224 | { |
| 2225 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2226 | |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 2227 | ~CommandObjectTargetModulesDumpSymtab() override = default; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2228 | |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 2229 | Options * |
| 2230 | GetOptions () override |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 2231 | { |
| 2232 | return &m_options; |
| 2233 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2234 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 2235 | class CommandOptions : public Options |
| 2236 | { |
| 2237 | public: |
Todd Fiala | e1cfbc7 | 2016-08-11 23:51:28 +0000 | [diff] [blame] | 2238 | CommandOptions() : |
| 2239 | Options(), |
| 2240 | m_sort_order(eSortOrderNone) |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 2241 | { |
| 2242 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2243 | |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 2244 | ~CommandOptions() override = default; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2245 | |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 2246 | Error |
Todd Fiala | e1cfbc7 | 2016-08-11 23:51:28 +0000 | [diff] [blame] | 2247 | SetOptionValue(uint32_t option_idx, const char *option_arg, |
| 2248 | ExecutionContext *execution_context) override |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 2249 | { |
| 2250 | Error error; |
Greg Clayton | 3bcdfc0 | 2012-12-04 00:32:51 +0000 | [diff] [blame] | 2251 | const int short_option = m_getopt_table[option_idx].val; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2252 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 2253 | switch (short_option) |
| 2254 | { |
| 2255 | case 's': |
| 2256 | m_sort_order = (SortOrder) Args::StringToOptionEnum (option_arg, |
| 2257 | g_option_table[option_idx].enum_values, |
| 2258 | eSortOrderNone, |
| 2259 | error); |
| 2260 | break; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2261 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 2262 | default: |
| 2263 | error.SetErrorStringWithFormat("invalid short option character '%c'", short_option); |
| 2264 | break; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 2265 | } |
| 2266 | return error; |
| 2267 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2268 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 2269 | void |
Todd Fiala | e1cfbc7 | 2016-08-11 23:51:28 +0000 | [diff] [blame] | 2270 | OptionParsingStarting(ExecutionContext *execution_context) override |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 2271 | { |
| 2272 | m_sort_order = eSortOrderNone; |
| 2273 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2274 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 2275 | const OptionDefinition* |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 2276 | GetDefinitions () override |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 2277 | { |
| 2278 | return g_option_table; |
| 2279 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2280 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 2281 | // Options table: Required for subclasses of Options. |
| 2282 | static OptionDefinition g_option_table[]; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2283 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 2284 | SortOrder m_sort_order; |
| 2285 | }; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2286 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 2287 | protected: |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 2288 | bool |
| 2289 | DoExecute (Args& command, CommandReturnObject &result) override |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2290 | { |
| 2291 | Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 2292 | if (target == nullptr) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2293 | { |
| 2294 | result.AppendError ("invalid target, create a debug target using the 'target create' command"); |
| 2295 | result.SetStatus (eReturnStatusFailed); |
| 2296 | return false; |
| 2297 | } |
| 2298 | else |
| 2299 | { |
| 2300 | uint32_t num_dumped = 0; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2301 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2302 | uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize(); |
| 2303 | result.GetOutputStream().SetAddressByteSize(addr_byte_size); |
| 2304 | result.GetErrorStream().SetAddressByteSize(addr_byte_size); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2305 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2306 | if (command.GetArgumentCount() == 0) |
| 2307 | { |
| 2308 | // Dump all sections for all modules images |
Saleem Abdulrasool | bb19a13 | 2016-05-19 05:13:57 +0000 | [diff] [blame] | 2309 | std::lock_guard<std::recursive_mutex> guard(target->GetImages().GetMutex()); |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 2310 | const size_t num_modules = target->GetImages().GetSize(); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2311 | if (num_modules > 0) |
| 2312 | { |
Deepak Panickal | 99fbc07 | 2014-03-03 15:39:47 +0000 | [diff] [blame] | 2313 | 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] | 2314 | for (size_t image_idx = 0; image_idx<num_modules; ++image_idx) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2315 | { |
| 2316 | if (num_dumped > 0) |
| 2317 | { |
| 2318 | result.GetOutputStream().EOL(); |
| 2319 | result.GetOutputStream().EOL(); |
| 2320 | } |
| 2321 | num_dumped++; |
Jim Ingham | 3ee12ef | 2012-05-30 02:19:25 +0000 | [diff] [blame] | 2322 | DumpModuleSymtab (m_interpreter, |
| 2323 | result.GetOutputStream(), |
| 2324 | target->GetImages().GetModulePointerAtIndexUnlocked(image_idx), |
| 2325 | m_options.m_sort_order); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2326 | } |
| 2327 | } |
| 2328 | else |
| 2329 | { |
| 2330 | result.AppendError ("the target has no associated executable images"); |
| 2331 | result.SetStatus (eReturnStatusFailed); |
| 2332 | return false; |
| 2333 | } |
| 2334 | } |
| 2335 | else |
| 2336 | { |
| 2337 | // Dump specified images (by basename or fullpath) |
| 2338 | const char *arg_cstr; |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 2339 | for (int arg_idx = 0; (arg_cstr = command.GetArgumentAtIndex(arg_idx)) != nullptr; ++arg_idx) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2340 | { |
Greg Clayton | 8ee6438 | 2011-11-10 01:18:58 +0000 | [diff] [blame] | 2341 | ModuleList module_list; |
| 2342 | const size_t num_matches = FindModulesByName (target, arg_cstr, module_list, true); |
| 2343 | if (num_matches > 0) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2344 | { |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 2345 | for (size_t i = 0; i < num_matches; ++i) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2346 | { |
Greg Clayton | 8ee6438 | 2011-11-10 01:18:58 +0000 | [diff] [blame] | 2347 | Module *module = module_list.GetModulePointerAtIndex(i); |
| 2348 | if (module) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2349 | { |
| 2350 | if (num_dumped > 0) |
| 2351 | { |
| 2352 | result.GetOutputStream().EOL(); |
| 2353 | result.GetOutputStream().EOL(); |
| 2354 | } |
| 2355 | num_dumped++; |
Greg Clayton | 8ee6438 | 2011-11-10 01:18:58 +0000 | [diff] [blame] | 2356 | DumpModuleSymtab (m_interpreter, result.GetOutputStream(), module, m_options.m_sort_order); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2357 | } |
| 2358 | } |
| 2359 | } |
| 2360 | else |
| 2361 | result.AppendWarningWithFormat("Unable to find an image that matches '%s'.\n", arg_cstr); |
| 2362 | } |
| 2363 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2364 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2365 | if (num_dumped > 0) |
| 2366 | result.SetStatus (eReturnStatusSuccessFinishResult); |
| 2367 | else |
| 2368 | { |
| 2369 | result.AppendError ("no matching executable images found"); |
| 2370 | result.SetStatus (eReturnStatusFailed); |
| 2371 | } |
| 2372 | } |
| 2373 | return result.Succeeded(); |
| 2374 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2375 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2376 | CommandOptions m_options; |
| 2377 | }; |
| 2378 | |
| 2379 | static OptionEnumValueElement |
| 2380 | g_sort_option_enumeration[4] = |
| 2381 | { |
| 2382 | { eSortOrderNone, "none", "No sorting, use the original symbol table order."}, |
| 2383 | { eSortOrderByAddress, "address", "Sort output by symbol address."}, |
| 2384 | { eSortOrderByName, "name", "Sort output by symbol name."}, |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 2385 | { 0, nullptr, nullptr } |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2386 | }; |
| 2387 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2388 | OptionDefinition |
| 2389 | CommandObjectTargetModulesDumpSymtab::CommandOptions::g_option_table[] = |
| 2390 | { |
Kate Stone | ac9c3a6 | 2016-08-26 23:28:47 +0000 | [diff] [blame] | 2391 | // clang-format off |
| 2392 | {LLDB_OPT_SET_1, false, "sort", 's', OptionParser::eRequiredArgument, nullptr, g_sort_option_enumeration, 0, eArgTypeSortOrder, "Supply a sort order when dumping the symbol table."}, |
| 2393 | {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr} |
| 2394 | // clang-format on |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2395 | }; |
| 2396 | |
| 2397 | #pragma mark CommandObjectTargetModulesDumpSections |
| 2398 | |
| 2399 | //---------------------------------------------------------------------- |
| 2400 | // Image section dumping command |
| 2401 | //---------------------------------------------------------------------- |
| 2402 | |
| 2403 | class CommandObjectTargetModulesDumpSections : public CommandObjectTargetModulesModuleAutoComplete |
| 2404 | { |
| 2405 | public: |
| 2406 | CommandObjectTargetModulesDumpSections (CommandInterpreter &interpreter) : |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 2407 | CommandObjectTargetModulesModuleAutoComplete(interpreter, |
| 2408 | "target modules dump sections", |
| 2409 | "Dump the sections from one or more target modules.", |
| 2410 | //"target modules dump sections [<file1> ...]") |
| 2411 | nullptr) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2412 | { |
| 2413 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2414 | |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 2415 | ~CommandObjectTargetModulesDumpSections() override = default; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2416 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 2417 | protected: |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 2418 | bool |
| 2419 | DoExecute (Args& command, CommandReturnObject &result) override |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2420 | { |
| 2421 | Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 2422 | if (target == nullptr) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2423 | { |
| 2424 | result.AppendError ("invalid target, create a debug target using the 'target create' command"); |
| 2425 | result.SetStatus (eReturnStatusFailed); |
| 2426 | return false; |
| 2427 | } |
| 2428 | else |
| 2429 | { |
| 2430 | uint32_t num_dumped = 0; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2431 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2432 | uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize(); |
| 2433 | result.GetOutputStream().SetAddressByteSize(addr_byte_size); |
| 2434 | result.GetErrorStream().SetAddressByteSize(addr_byte_size); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2435 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2436 | if (command.GetArgumentCount() == 0) |
| 2437 | { |
| 2438 | // Dump all sections for all modules images |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 2439 | const size_t num_modules = target->GetImages().GetSize(); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2440 | if (num_modules > 0) |
| 2441 | { |
Deepak Panickal | 99fbc07 | 2014-03-03 15:39:47 +0000 | [diff] [blame] | 2442 | 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] | 2443 | for (size_t image_idx = 0; image_idx<num_modules; ++image_idx) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2444 | { |
| 2445 | num_dumped++; |
| 2446 | DumpModuleSections (m_interpreter, result.GetOutputStream(), target->GetImages().GetModulePointerAtIndex(image_idx)); |
| 2447 | } |
| 2448 | } |
| 2449 | else |
| 2450 | { |
| 2451 | result.AppendError ("the target has no associated executable images"); |
| 2452 | result.SetStatus (eReturnStatusFailed); |
| 2453 | return false; |
| 2454 | } |
| 2455 | } |
| 2456 | else |
| 2457 | { |
| 2458 | // Dump specified images (by basename or fullpath) |
| 2459 | const char *arg_cstr; |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 2460 | for (int arg_idx = 0; (arg_cstr = command.GetArgumentAtIndex(arg_idx)) != nullptr; ++arg_idx) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2461 | { |
Greg Clayton | 8ee6438 | 2011-11-10 01:18:58 +0000 | [diff] [blame] | 2462 | ModuleList module_list; |
| 2463 | const size_t num_matches = FindModulesByName (target, arg_cstr, module_list, true); |
| 2464 | if (num_matches > 0) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2465 | { |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 2466 | for (size_t i = 0; i < num_matches; ++i) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2467 | { |
Greg Clayton | 8ee6438 | 2011-11-10 01:18:58 +0000 | [diff] [blame] | 2468 | Module *module = module_list.GetModulePointerAtIndex(i); |
| 2469 | if (module) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2470 | { |
| 2471 | num_dumped++; |
Greg Clayton | 8ee6438 | 2011-11-10 01:18:58 +0000 | [diff] [blame] | 2472 | DumpModuleSections (m_interpreter, result.GetOutputStream(), module); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2473 | } |
| 2474 | } |
| 2475 | } |
| 2476 | else |
Greg Clayton | 8ee6438 | 2011-11-10 01:18:58 +0000 | [diff] [blame] | 2477 | { |
| 2478 | // Check the global list |
Saleem Abdulrasool | 16ff860 | 2016-05-18 01:59:10 +0000 | [diff] [blame] | 2479 | std::lock_guard<std::recursive_mutex> guard(Module::GetAllocationModuleCollectionMutex()); |
Greg Clayton | 8ee6438 | 2011-11-10 01:18:58 +0000 | [diff] [blame] | 2480 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2481 | 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] | 2482 | } |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2483 | } |
| 2484 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2485 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2486 | if (num_dumped > 0) |
| 2487 | result.SetStatus (eReturnStatusSuccessFinishResult); |
| 2488 | else |
| 2489 | { |
| 2490 | result.AppendError ("no matching executable images found"); |
| 2491 | result.SetStatus (eReturnStatusFailed); |
| 2492 | } |
| 2493 | } |
| 2494 | return result.Succeeded(); |
| 2495 | } |
| 2496 | }; |
| 2497 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2498 | #pragma mark CommandObjectTargetModulesDumpSymfile |
| 2499 | |
| 2500 | //---------------------------------------------------------------------- |
| 2501 | // Image debug symbol dumping command |
| 2502 | //---------------------------------------------------------------------- |
| 2503 | |
| 2504 | class CommandObjectTargetModulesDumpSymfile : public CommandObjectTargetModulesModuleAutoComplete |
| 2505 | { |
| 2506 | public: |
| 2507 | CommandObjectTargetModulesDumpSymfile (CommandInterpreter &interpreter) : |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 2508 | CommandObjectTargetModulesModuleAutoComplete(interpreter, |
| 2509 | "target modules dump symfile", |
| 2510 | "Dump the debug symbol file for one or more target modules.", |
| 2511 | //"target modules dump symfile [<file1> ...]") |
| 2512 | nullptr) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2513 | { |
| 2514 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2515 | |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 2516 | ~CommandObjectTargetModulesDumpSymfile() override = default; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2517 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 2518 | protected: |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 2519 | bool |
| 2520 | DoExecute (Args& command, CommandReturnObject &result) override |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2521 | { |
| 2522 | Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 2523 | if (target == nullptr) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2524 | { |
| 2525 | result.AppendError ("invalid target, create a debug target using the 'target create' command"); |
| 2526 | result.SetStatus (eReturnStatusFailed); |
| 2527 | return false; |
| 2528 | } |
| 2529 | else |
| 2530 | { |
| 2531 | uint32_t num_dumped = 0; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2532 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2533 | uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize(); |
| 2534 | result.GetOutputStream().SetAddressByteSize(addr_byte_size); |
| 2535 | result.GetErrorStream().SetAddressByteSize(addr_byte_size); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2536 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2537 | if (command.GetArgumentCount() == 0) |
| 2538 | { |
| 2539 | // Dump all sections for all modules images |
Enrico Granata | 1759848 | 2012-11-08 02:22:02 +0000 | [diff] [blame] | 2540 | const ModuleList &target_modules = target->GetImages(); |
Saleem Abdulrasool | bb19a13 | 2016-05-19 05:13:57 +0000 | [diff] [blame] | 2541 | std::lock_guard<std::recursive_mutex> guard(target_modules.GetMutex()); |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 2542 | const size_t num_modules = target_modules.GetSize(); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2543 | if (num_modules > 0) |
| 2544 | { |
Deepak Panickal | 99fbc07 | 2014-03-03 15:39:47 +0000 | [diff] [blame] | 2545 | 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] | 2546 | for (uint32_t image_idx = 0; image_idx<num_modules; ++image_idx) |
| 2547 | { |
Jim Ingham | 3ee12ef | 2012-05-30 02:19:25 +0000 | [diff] [blame] | 2548 | if (DumpModuleSymbolVendor (result.GetOutputStream(), target_modules.GetModulePointerAtIndexUnlocked(image_idx))) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2549 | num_dumped++; |
| 2550 | } |
| 2551 | } |
| 2552 | else |
| 2553 | { |
| 2554 | result.AppendError ("the target has no associated executable images"); |
| 2555 | result.SetStatus (eReturnStatusFailed); |
| 2556 | return false; |
| 2557 | } |
| 2558 | } |
| 2559 | else |
| 2560 | { |
| 2561 | // Dump specified images (by basename or fullpath) |
| 2562 | const char *arg_cstr; |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 2563 | for (int arg_idx = 0; (arg_cstr = command.GetArgumentAtIndex(arg_idx)) != nullptr; ++arg_idx) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2564 | { |
Greg Clayton | 8ee6438 | 2011-11-10 01:18:58 +0000 | [diff] [blame] | 2565 | ModuleList module_list; |
| 2566 | const size_t num_matches = FindModulesByName (target, arg_cstr, module_list, true); |
| 2567 | if (num_matches > 0) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2568 | { |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 2569 | for (size_t i = 0; i < num_matches; ++i) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2570 | { |
Greg Clayton | 8ee6438 | 2011-11-10 01:18:58 +0000 | [diff] [blame] | 2571 | Module *module = module_list.GetModulePointerAtIndex(i); |
| 2572 | if (module) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2573 | { |
Greg Clayton | 8ee6438 | 2011-11-10 01:18:58 +0000 | [diff] [blame] | 2574 | if (DumpModuleSymbolVendor (result.GetOutputStream(), module)) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2575 | num_dumped++; |
| 2576 | } |
| 2577 | } |
| 2578 | } |
| 2579 | else |
| 2580 | result.AppendWarningWithFormat("Unable to find an image that matches '%s'.\n", arg_cstr); |
| 2581 | } |
| 2582 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2583 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2584 | if (num_dumped > 0) |
| 2585 | result.SetStatus (eReturnStatusSuccessFinishResult); |
| 2586 | else |
| 2587 | { |
| 2588 | result.AppendError ("no matching executable images found"); |
| 2589 | result.SetStatus (eReturnStatusFailed); |
| 2590 | } |
| 2591 | } |
| 2592 | return result.Succeeded(); |
| 2593 | } |
| 2594 | }; |
| 2595 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2596 | #pragma mark CommandObjectTargetModulesDumpLineTable |
| 2597 | |
| 2598 | //---------------------------------------------------------------------- |
| 2599 | // Image debug line table dumping command |
| 2600 | //---------------------------------------------------------------------- |
| 2601 | |
| 2602 | class CommandObjectTargetModulesDumpLineTable : public CommandObjectTargetModulesSourceFileAutoComplete |
| 2603 | { |
| 2604 | public: |
| 2605 | CommandObjectTargetModulesDumpLineTable (CommandInterpreter &interpreter) : |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 2606 | CommandObjectTargetModulesSourceFileAutoComplete(interpreter, |
| 2607 | "target modules dump line-table", |
| 2608 | "Dump the line table for one or more compilation units.", |
| 2609 | nullptr, |
| 2610 | eCommandRequiresTarget) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2611 | { |
| 2612 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2613 | |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 2614 | ~CommandObjectTargetModulesDumpLineTable() override = default; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2615 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 2616 | protected: |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 2617 | bool |
| 2618 | DoExecute (Args& command, CommandReturnObject &result) override |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2619 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 2620 | Target *target = m_exe_ctx.GetTargetPtr(); |
| 2621 | uint32_t total_num_dumped = 0; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2622 | |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 2623 | uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize(); |
| 2624 | result.GetOutputStream().SetAddressByteSize(addr_byte_size); |
| 2625 | result.GetErrorStream().SetAddressByteSize(addr_byte_size); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2626 | |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 2627 | if (command.GetArgumentCount() == 0) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2628 | { |
Dawn Perchik | 954b40b | 2016-01-05 19:51:51 +0000 | [diff] [blame] | 2629 | result.AppendError ("file option must be specified."); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2630 | result.SetStatus (eReturnStatusFailed); |
Dawn Perchik | 954b40b | 2016-01-05 19:51:51 +0000 | [diff] [blame] | 2631 | return result.Succeeded(); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2632 | } |
| 2633 | else |
| 2634 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 2635 | // Dump specified images (by basename or fullpath) |
| 2636 | const char *arg_cstr; |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 2637 | for (int arg_idx = 0; (arg_cstr = command.GetArgumentAtIndex(arg_idx)) != nullptr; ++arg_idx) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2638 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 2639 | FileSpec file_spec(arg_cstr, false); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2640 | |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 2641 | const ModuleList &target_modules = target->GetImages(); |
Saleem Abdulrasool | bb19a13 | 2016-05-19 05:13:57 +0000 | [diff] [blame] | 2642 | std::lock_guard<std::recursive_mutex> guard(target_modules.GetMutex()); |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 2643 | const size_t num_modules = target_modules.GetSize(); |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 2644 | if (num_modules > 0) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2645 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 2646 | uint32_t num_dumped = 0; |
| 2647 | for (uint32_t i = 0; i<num_modules; ++i) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2648 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 2649 | if (DumpCompileUnitLineTable (m_interpreter, |
| 2650 | result.GetOutputStream(), |
| 2651 | target_modules.GetModulePointerAtIndexUnlocked(i), |
| 2652 | file_spec, |
| 2653 | m_exe_ctx.GetProcessPtr() && m_exe_ctx.GetProcessRef().IsAlive())) |
| 2654 | num_dumped++; |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2655 | } |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 2656 | if (num_dumped == 0) |
| 2657 | result.AppendWarningWithFormat ("No source filenames matched '%s'.\n", arg_cstr); |
| 2658 | else |
| 2659 | total_num_dumped += num_dumped; |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2660 | } |
| 2661 | } |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 2662 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2663 | |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 2664 | if (total_num_dumped > 0) |
| 2665 | result.SetStatus (eReturnStatusSuccessFinishResult); |
| 2666 | else |
| 2667 | { |
| 2668 | result.AppendError ("no source filenames matched any command arguments"); |
| 2669 | result.SetStatus (eReturnStatusFailed); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2670 | } |
| 2671 | return result.Succeeded(); |
| 2672 | } |
| 2673 | }; |
| 2674 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2675 | #pragma mark CommandObjectTargetModulesDump |
| 2676 | |
| 2677 | //---------------------------------------------------------------------- |
| 2678 | // Dump multi-word command for target modules |
| 2679 | //---------------------------------------------------------------------- |
| 2680 | |
| 2681 | class CommandObjectTargetModulesDump : public CommandObjectMultiword |
| 2682 | { |
| 2683 | public: |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2684 | //------------------------------------------------------------------ |
| 2685 | // Constructors and Destructors |
| 2686 | //------------------------------------------------------------------ |
Adrian McCarthy | 543725c | 2016-04-04 21:21:49 +0000 | [diff] [blame] | 2687 | CommandObjectTargetModulesDump(CommandInterpreter &interpreter) |
| 2688 | : CommandObjectMultiword( |
Kate Stone | 7428a18 | 2016-07-14 22:03:10 +0000 | [diff] [blame] | 2689 | interpreter, "target modules dump", "Commands for dumping information about one or more target modules.", |
Adrian McCarthy | 543725c | 2016-04-04 21:21:49 +0000 | [diff] [blame] | 2690 | "target modules dump [headers|symtab|sections|symfile|line-table] [<file1> <file2> ...]") |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2691 | { |
Adrian McCarthy | 543725c | 2016-04-04 21:21:49 +0000 | [diff] [blame] | 2692 | LoadSubCommand("objfile", CommandObjectSP(new CommandObjectTargetModulesDumpObjfile(interpreter))); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2693 | LoadSubCommand ("symtab", CommandObjectSP (new CommandObjectTargetModulesDumpSymtab (interpreter))); |
| 2694 | LoadSubCommand ("sections", CommandObjectSP (new CommandObjectTargetModulesDumpSections (interpreter))); |
| 2695 | LoadSubCommand ("symfile", CommandObjectSP (new CommandObjectTargetModulesDumpSymfile (interpreter))); |
| 2696 | LoadSubCommand ("line-table", CommandObjectSP (new CommandObjectTargetModulesDumpLineTable (interpreter))); |
| 2697 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2698 | |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 2699 | ~CommandObjectTargetModulesDump() override = default; |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2700 | }; |
| 2701 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 2702 | class CommandObjectTargetModulesAdd : public CommandObjectParsed |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2703 | { |
| 2704 | public: |
| 2705 | CommandObjectTargetModulesAdd (CommandInterpreter &interpreter) : |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 2706 | CommandObjectParsed (interpreter, |
| 2707 | "target modules add", |
| 2708 | "Add a new module to the current target's modules.", |
Greg Clayton | 50a24bd | 2012-11-29 22:16:27 +0000 | [diff] [blame] | 2709 | "target modules add [<module>]"), |
Todd Fiala | e1cfbc7 | 2016-08-11 23:51:28 +0000 | [diff] [blame] | 2710 | m_option_group(), |
Greg Clayton | 1c5f186 | 2012-11-30 19:05:35 +0000 | [diff] [blame] | 2711 | 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] | 2712 | { |
Greg Clayton | 50a24bd | 2012-11-29 22:16:27 +0000 | [diff] [blame] | 2713 | 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] | 2714 | 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] | 2715 | m_option_group.Finalize(); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2716 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2717 | |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 2718 | ~CommandObjectTargetModulesAdd() override = default; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2719 | |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 2720 | Options * |
| 2721 | GetOptions () override |
Greg Clayton | 50a24bd | 2012-11-29 22:16:27 +0000 | [diff] [blame] | 2722 | { |
| 2723 | return &m_option_group; |
| 2724 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2725 | |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 2726 | int |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 2727 | HandleArgumentCompletion (Args &input, |
| 2728 | int &cursor_index, |
| 2729 | int &cursor_char_position, |
| 2730 | OptionElementVector &opt_element_vector, |
| 2731 | int match_start_point, |
| 2732 | int max_return_elements, |
| 2733 | bool &word_complete, |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 2734 | StringList &matches) override |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 2735 | { |
| 2736 | std::string completion_str (input.GetArgumentAtIndex(cursor_index)); |
| 2737 | completion_str.erase (cursor_char_position); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2738 | |
Todd Fiala | e1cfbc7 | 2016-08-11 23:51:28 +0000 | [diff] [blame] | 2739 | CommandCompletions::InvokeCommonCompletionCallbacks(GetCommandInterpreter(), |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 2740 | CommandCompletions::eDiskFileCompletion, |
| 2741 | completion_str.c_str(), |
| 2742 | match_start_point, |
| 2743 | max_return_elements, |
| 2744 | nullptr, |
| 2745 | word_complete, |
| 2746 | matches); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 2747 | return matches.GetSize(); |
| 2748 | } |
| 2749 | |
| 2750 | protected: |
Greg Clayton | 50a24bd | 2012-11-29 22:16:27 +0000 | [diff] [blame] | 2751 | OptionGroupOptions m_option_group; |
| 2752 | OptionGroupUUID m_uuid_option_group; |
Greg Clayton | 1c5f186 | 2012-11-30 19:05:35 +0000 | [diff] [blame] | 2753 | OptionGroupFile m_symbol_file; |
Greg Clayton | 50a24bd | 2012-11-29 22:16:27 +0000 | [diff] [blame] | 2754 | |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 2755 | bool |
| 2756 | DoExecute (Args& args, CommandReturnObject &result) override |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2757 | { |
| 2758 | Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 2759 | if (target == nullptr) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2760 | { |
| 2761 | result.AppendError ("invalid target, create a debug target using the 'target create' command"); |
| 2762 | result.SetStatus (eReturnStatusFailed); |
| 2763 | return false; |
| 2764 | } |
| 2765 | else |
| 2766 | { |
Sean Callanan | b36c6c0 | 2012-12-13 01:39:39 +0000 | [diff] [blame] | 2767 | bool flush = false; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2768 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2769 | const size_t argc = args.GetArgumentCount(); |
| 2770 | if (argc == 0) |
| 2771 | { |
Greg Clayton | 50a24bd | 2012-11-29 22:16:27 +0000 | [diff] [blame] | 2772 | if (m_uuid_option_group.GetOptionValue ().OptionWasSet()) |
| 2773 | { |
| 2774 | // We are given a UUID only, go locate the file |
| 2775 | ModuleSpec module_spec; |
| 2776 | module_spec.GetUUID() = m_uuid_option_group.GetOptionValue ().GetCurrentValue(); |
Greg Clayton | 1c5f186 | 2012-11-30 19:05:35 +0000 | [diff] [blame] | 2777 | if (m_symbol_file.GetOptionValue().OptionWasSet()) |
| 2778 | module_spec.GetSymbolFileSpec() = m_symbol_file.GetOptionValue().GetCurrentValue(); |
Greg Clayton | 50a24bd | 2012-11-29 22:16:27 +0000 | [diff] [blame] | 2779 | if (Symbols::DownloadObjectAndSymbolFile (module_spec)) |
| 2780 | { |
| 2781 | ModuleSP module_sp (target->GetSharedModule (module_spec)); |
| 2782 | if (module_sp) |
| 2783 | { |
| 2784 | result.SetStatus (eReturnStatusSuccessFinishResult); |
| 2785 | return true; |
| 2786 | } |
| 2787 | else |
| 2788 | { |
| 2789 | StreamString strm; |
| 2790 | module_spec.GetUUID().Dump (&strm); |
| 2791 | if (module_spec.GetFileSpec()) |
| 2792 | { |
| 2793 | if (module_spec.GetSymbolFileSpec()) |
| 2794 | { |
Greg Clayton | b5ad4ec | 2013-04-29 17:25:54 +0000 | [diff] [blame] | 2795 | 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] | 2796 | strm.GetString().c_str(), |
Greg Clayton | b5ad4ec | 2013-04-29 17:25:54 +0000 | [diff] [blame] | 2797 | module_spec.GetFileSpec().GetPath().c_str(), |
| 2798 | module_spec.GetSymbolFileSpec().GetPath().c_str()); |
Greg Clayton | 50a24bd | 2012-11-29 22:16:27 +0000 | [diff] [blame] | 2799 | } |
| 2800 | else |
| 2801 | { |
Greg Clayton | b5ad4ec | 2013-04-29 17:25:54 +0000 | [diff] [blame] | 2802 | 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] | 2803 | strm.GetString().c_str(), |
Greg Clayton | b5ad4ec | 2013-04-29 17:25:54 +0000 | [diff] [blame] | 2804 | module_spec.GetFileSpec().GetPath().c_str()); |
Greg Clayton | 50a24bd | 2012-11-29 22:16:27 +0000 | [diff] [blame] | 2805 | } |
| 2806 | } |
| 2807 | else |
| 2808 | { |
| 2809 | result.AppendErrorWithFormat ("Unable to create the executable or symbol file with UUID %s", |
| 2810 | strm.GetString().c_str()); |
| 2811 | } |
| 2812 | result.SetStatus (eReturnStatusFailed); |
| 2813 | return false; |
| 2814 | } |
| 2815 | } |
| 2816 | else |
| 2817 | { |
| 2818 | StreamString strm; |
| 2819 | module_spec.GetUUID().Dump (&strm); |
| 2820 | result.AppendErrorWithFormat ("Unable to locate the executable or symbol file with UUID %s", strm.GetString().c_str()); |
| 2821 | result.SetStatus (eReturnStatusFailed); |
| 2822 | return false; |
| 2823 | } |
| 2824 | } |
| 2825 | else |
| 2826 | { |
| 2827 | result.AppendError ("one or more executable image paths must be specified"); |
| 2828 | result.SetStatus (eReturnStatusFailed); |
| 2829 | return false; |
| 2830 | } |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2831 | } |
| 2832 | else |
| 2833 | { |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 2834 | for (size_t i = 0; i < argc; ++i) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2835 | { |
| 2836 | const char *path = args.GetArgumentAtIndex(i); |
| 2837 | if (path) |
| 2838 | { |
| 2839 | FileSpec file_spec(path, true); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2840 | if (file_spec.Exists()) |
| 2841 | { |
Greg Clayton | b9a01b3 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 2842 | ModuleSpec module_spec (file_spec); |
Greg Clayton | 50a24bd | 2012-11-29 22:16:27 +0000 | [diff] [blame] | 2843 | if (m_uuid_option_group.GetOptionValue ().OptionWasSet()) |
| 2844 | module_spec.GetUUID() = m_uuid_option_group.GetOptionValue ().GetCurrentValue(); |
Greg Clayton | 1c5f186 | 2012-11-30 19:05:35 +0000 | [diff] [blame] | 2845 | if (m_symbol_file.GetOptionValue().OptionWasSet()) |
| 2846 | module_spec.GetSymbolFileSpec() = m_symbol_file.GetOptionValue().GetCurrentValue(); |
Jason Molenda | b019cd9 | 2013-09-11 21:25:46 +0000 | [diff] [blame] | 2847 | if (!module_spec.GetArchitecture().IsValid()) |
| 2848 | module_spec.GetArchitecture() = target->GetArchitecture(); |
Greg Clayton | 50a24bd | 2012-11-29 22:16:27 +0000 | [diff] [blame] | 2849 | Error error; |
| 2850 | ModuleSP module_sp (target->GetSharedModule (module_spec, &error)); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2851 | if (!module_sp) |
| 2852 | { |
Greg Clayton | 50a24bd | 2012-11-29 22:16:27 +0000 | [diff] [blame] | 2853 | const char *error_cstr = error.AsCString(); |
| 2854 | if (error_cstr) |
| 2855 | result.AppendError (error_cstr); |
| 2856 | else |
| 2857 | result.AppendErrorWithFormat ("unsupported module: %s", path); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2858 | result.SetStatus (eReturnStatusFailed); |
| 2859 | return false; |
| 2860 | } |
Sean Callanan | b36c6c0 | 2012-12-13 01:39:39 +0000 | [diff] [blame] | 2861 | else |
| 2862 | { |
| 2863 | flush = true; |
| 2864 | } |
Jason Molenda | 2f7af6a | 2011-08-02 23:28:55 +0000 | [diff] [blame] | 2865 | result.SetStatus (eReturnStatusSuccessFinishResult); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2866 | } |
| 2867 | else |
| 2868 | { |
| 2869 | char resolved_path[PATH_MAX]; |
| 2870 | result.SetStatus (eReturnStatusFailed); |
| 2871 | if (file_spec.GetPath (resolved_path, sizeof(resolved_path))) |
| 2872 | { |
| 2873 | if (strcmp (resolved_path, path) != 0) |
| 2874 | { |
| 2875 | result.AppendErrorWithFormat ("invalid module path '%s' with resolved path '%s'\n", path, resolved_path); |
| 2876 | break; |
| 2877 | } |
| 2878 | } |
| 2879 | result.AppendErrorWithFormat ("invalid module path '%s'\n", path); |
| 2880 | break; |
| 2881 | } |
| 2882 | } |
| 2883 | } |
| 2884 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2885 | |
Sean Callanan | b36c6c0 | 2012-12-13 01:39:39 +0000 | [diff] [blame] | 2886 | if (flush) |
| 2887 | { |
| 2888 | ProcessSP process = target->GetProcessSP(); |
| 2889 | if (process) |
| 2890 | process->Flush(); |
| 2891 | } |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2892 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2893 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2894 | return result.Succeeded(); |
| 2895 | } |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2896 | }; |
| 2897 | |
| 2898 | class CommandObjectTargetModulesLoad : public CommandObjectTargetModulesModuleAutoComplete |
| 2899 | { |
| 2900 | public: |
| 2901 | CommandObjectTargetModulesLoad (CommandInterpreter &interpreter) : |
| 2902 | CommandObjectTargetModulesModuleAutoComplete (interpreter, |
| 2903 | "target modules load", |
| 2904 | "Set the load addresses for one or more sections in a target module.", |
| 2905 | "target modules load [--file <module> --uuid <uuid>] <sect-name> <address> [<sect-name> <address> ....]"), |
Todd Fiala | e1cfbc7 | 2016-08-11 23:51:28 +0000 | [diff] [blame] | 2906 | m_option_group(), |
Jason Molenda | c6127dd | 2014-11-21 02:25:15 +0000 | [diff] [blame] | 2907 | 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] | 2908 | 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) |
| 2909 | { |
| 2910 | m_option_group.Append (&m_uuid_option_group, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1); |
| 2911 | m_option_group.Append (&m_file_option, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1); |
| 2912 | m_option_group.Append (&m_slide_option, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1); |
| 2913 | m_option_group.Finalize(); |
| 2914 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2915 | |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 2916 | ~CommandObjectTargetModulesLoad() override = default; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2917 | |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 2918 | Options * |
| 2919 | GetOptions () override |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 2920 | { |
| 2921 | return &m_option_group; |
| 2922 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2923 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 2924 | protected: |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 2925 | bool |
| 2926 | DoExecute (Args& args, CommandReturnObject &result) override |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2927 | { |
| 2928 | Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 2929 | if (target == nullptr) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2930 | { |
| 2931 | result.AppendError ("invalid target, create a debug target using the 'target create' command"); |
| 2932 | result.SetStatus (eReturnStatusFailed); |
| 2933 | return false; |
| 2934 | } |
| 2935 | else |
| 2936 | { |
| 2937 | const size_t argc = args.GetArgumentCount(); |
Greg Clayton | b9a01b3 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 2938 | ModuleSpec module_spec; |
| 2939 | bool search_using_module_spec = false; |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2940 | if (m_file_option.GetOptionValue().OptionWasSet()) |
Greg Clayton | b9a01b3 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 2941 | { |
| 2942 | search_using_module_spec = true; |
Jason Molenda | c6127dd | 2014-11-21 02:25:15 +0000 | [diff] [blame] | 2943 | const char *arg_cstr = m_file_option.GetOptionValue().GetCurrentValue(); |
| 2944 | const bool use_global_module_list = true; |
| 2945 | ModuleList module_list; |
| 2946 | const size_t num_matches = FindModulesByName (target, arg_cstr, module_list, use_global_module_list); |
| 2947 | if (num_matches == 1) |
| 2948 | { |
| 2949 | module_spec.GetFileSpec() = module_list.GetModuleAtIndex(0)->GetFileSpec(); |
| 2950 | } |
| 2951 | else if (num_matches > 1 ) |
| 2952 | { |
| 2953 | search_using_module_spec = false; |
| 2954 | result.AppendErrorWithFormat ("more than 1 module matched by name '%s'\n", arg_cstr); |
| 2955 | result.SetStatus (eReturnStatusFailed); |
| 2956 | } |
| 2957 | else |
| 2958 | { |
| 2959 | search_using_module_spec = false; |
| 2960 | result.AppendErrorWithFormat ("no object file for module '%s'\n", arg_cstr); |
| 2961 | result.SetStatus (eReturnStatusFailed); |
| 2962 | } |
Greg Clayton | b9a01b3 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 2963 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2964 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2965 | if (m_uuid_option_group.GetOptionValue().OptionWasSet()) |
Greg Clayton | b9a01b3 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 2966 | { |
| 2967 | search_using_module_spec = true; |
| 2968 | module_spec.GetUUID() = m_uuid_option_group.GetOptionValue().GetCurrentValue(); |
| 2969 | } |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2970 | |
Greg Clayton | b9a01b3 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 2971 | if (search_using_module_spec) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2972 | { |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2973 | ModuleList matching_modules; |
Greg Clayton | b9a01b3 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 2974 | const size_t num_matches = target->GetImages().FindModules (module_spec, matching_modules); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2975 | |
| 2976 | char path[PATH_MAX]; |
| 2977 | if (num_matches == 1) |
| 2978 | { |
| 2979 | Module *module = matching_modules.GetModulePointerAtIndex(0); |
| 2980 | if (module) |
| 2981 | { |
| 2982 | ObjectFile *objfile = module->GetObjectFile(); |
| 2983 | if (objfile) |
| 2984 | { |
Greg Clayton | 3046e66 | 2013-07-10 01:23:25 +0000 | [diff] [blame] | 2985 | SectionList *section_list = module->GetSectionList(); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2986 | if (section_list) |
| 2987 | { |
Greg Clayton | 741f3f9 | 2012-03-27 21:10:07 +0000 | [diff] [blame] | 2988 | bool changed = false; |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2989 | if (argc == 0) |
| 2990 | { |
| 2991 | if (m_slide_option.GetOptionValue().OptionWasSet()) |
| 2992 | { |
Greg Clayton | 741f3f9 | 2012-03-27 21:10:07 +0000 | [diff] [blame] | 2993 | const addr_t slide = m_slide_option.GetOptionValue().GetCurrentValue(); |
Greg Clayton | 751caf6 | 2014-02-07 22:54:47 +0000 | [diff] [blame] | 2994 | const bool slide_is_offset = true; |
| 2995 | module->SetLoadAddress (*target, slide, slide_is_offset, changed); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 2996 | } |
| 2997 | else |
| 2998 | { |
| 2999 | result.AppendError ("one or more section name + load address pair must be specified"); |
| 3000 | result.SetStatus (eReturnStatusFailed); |
| 3001 | return false; |
| 3002 | } |
| 3003 | } |
| 3004 | else |
| 3005 | { |
| 3006 | if (m_slide_option.GetOptionValue().OptionWasSet()) |
| 3007 | { |
| 3008 | result.AppendError ("The \"--slide <offset>\" option can't be used in conjunction with setting section load addresses.\n"); |
| 3009 | result.SetStatus (eReturnStatusFailed); |
| 3010 | return false; |
| 3011 | } |
| 3012 | |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 3013 | for (size_t i = 0; i < argc; i += 2) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3014 | { |
| 3015 | const char *sect_name = args.GetArgumentAtIndex(i); |
| 3016 | const char *load_addr_cstr = args.GetArgumentAtIndex(i+1); |
| 3017 | if (sect_name && load_addr_cstr) |
| 3018 | { |
| 3019 | ConstString const_sect_name(sect_name); |
| 3020 | bool success = false; |
Vince Harron | 5275aaa | 2015-01-15 20:08:35 +0000 | [diff] [blame] | 3021 | 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] | 3022 | if (success) |
| 3023 | { |
| 3024 | SectionSP section_sp (section_list->FindSectionByName(const_sect_name)); |
| 3025 | if (section_sp) |
| 3026 | { |
Greg Clayton | 741f3f9 | 2012-03-27 21:10:07 +0000 | [diff] [blame] | 3027 | if (section_sp->IsThreadSpecific()) |
| 3028 | { |
| 3029 | result.AppendErrorWithFormat ("thread specific sections are not yet supported (section '%s')\n", sect_name); |
| 3030 | result.SetStatus (eReturnStatusFailed); |
| 3031 | break; |
| 3032 | } |
| 3033 | else |
| 3034 | { |
Greg Clayton | 7820bd1 | 2012-07-07 01:24:12 +0000 | [diff] [blame] | 3035 | if (target->GetSectionLoadList().SetSectionLoadAddress (section_sp, load_addr)) |
Greg Clayton | 741f3f9 | 2012-03-27 21:10:07 +0000 | [diff] [blame] | 3036 | changed = true; |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 3037 | 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] | 3038 | } |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3039 | } |
| 3040 | else |
| 3041 | { |
| 3042 | result.AppendErrorWithFormat ("no section found that matches the section name '%s'\n", sect_name); |
| 3043 | result.SetStatus (eReturnStatusFailed); |
| 3044 | break; |
| 3045 | } |
| 3046 | } |
| 3047 | else |
| 3048 | { |
| 3049 | result.AppendErrorWithFormat ("invalid load address string '%s'\n", load_addr_cstr); |
| 3050 | result.SetStatus (eReturnStatusFailed); |
| 3051 | break; |
| 3052 | } |
| 3053 | } |
| 3054 | else |
| 3055 | { |
| 3056 | if (sect_name) |
| 3057 | result.AppendError ("section names must be followed by a load address.\n"); |
| 3058 | else |
| 3059 | result.AppendError ("one or more section name + load address pair must be specified.\n"); |
| 3060 | result.SetStatus (eReturnStatusFailed); |
| 3061 | break; |
| 3062 | } |
| 3063 | } |
| 3064 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3065 | |
Greg Clayton | 741f3f9 | 2012-03-27 21:10:07 +0000 | [diff] [blame] | 3066 | if (changed) |
Greg Clayton | 3c94737 | 2013-01-29 01:17:09 +0000 | [diff] [blame] | 3067 | { |
Greg Clayton | 741f3f9 | 2012-03-27 21:10:07 +0000 | [diff] [blame] | 3068 | target->ModulesDidLoad (matching_modules); |
Greg Clayton | 3c94737 | 2013-01-29 01:17:09 +0000 | [diff] [blame] | 3069 | Process *process = m_exe_ctx.GetProcessPtr(); |
| 3070 | if (process) |
| 3071 | process->Flush(); |
| 3072 | } |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3073 | } |
| 3074 | else |
| 3075 | { |
| 3076 | module->GetFileSpec().GetPath (path, sizeof(path)); |
| 3077 | result.AppendErrorWithFormat ("no sections in object file '%s'\n", path); |
| 3078 | result.SetStatus (eReturnStatusFailed); |
| 3079 | } |
| 3080 | } |
| 3081 | else |
| 3082 | { |
| 3083 | module->GetFileSpec().GetPath (path, sizeof(path)); |
| 3084 | result.AppendErrorWithFormat ("no object file for module '%s'\n", path); |
| 3085 | result.SetStatus (eReturnStatusFailed); |
| 3086 | } |
| 3087 | } |
| 3088 | else |
| 3089 | { |
Jim Ingham | 28eb571 | 2012-10-12 17:34:26 +0000 | [diff] [blame] | 3090 | FileSpec *module_spec_file = module_spec.GetFileSpecPtr(); |
| 3091 | if (module_spec_file) |
| 3092 | { |
| 3093 | module_spec_file->GetPath (path, sizeof(path)); |
| 3094 | result.AppendErrorWithFormat ("invalid module '%s'.\n", path); |
| 3095 | } |
| 3096 | else |
| 3097 | result.AppendError ("no module spec"); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3098 | result.SetStatus (eReturnStatusFailed); |
| 3099 | } |
| 3100 | } |
| 3101 | else |
| 3102 | { |
Jason Molenda | c16b4af | 2013-05-03 23:56:12 +0000 | [diff] [blame] | 3103 | std::string uuid_str; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3104 | |
Greg Clayton | b9a01b3 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 3105 | if (module_spec.GetFileSpec()) |
| 3106 | module_spec.GetFileSpec().GetPath (path, sizeof(path)); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3107 | else |
| 3108 | path[0] = '\0'; |
| 3109 | |
Greg Clayton | b9a01b3 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 3110 | if (module_spec.GetUUIDPtr()) |
Jason Molenda | c16b4af | 2013-05-03 23:56:12 +0000 | [diff] [blame] | 3111 | uuid_str = module_spec.GetUUID().GetAsString(); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3112 | if (num_matches > 1) |
| 3113 | { |
| 3114 | result.AppendErrorWithFormat ("multiple modules match%s%s%s%s:\n", |
| 3115 | path[0] ? " file=" : "", |
| 3116 | path, |
Jason Molenda | c16b4af | 2013-05-03 23:56:12 +0000 | [diff] [blame] | 3117 | !uuid_str.empty() ? " uuid=" : "", |
| 3118 | uuid_str.c_str()); |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 3119 | for (size_t i = 0; i < num_matches; ++i) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3120 | { |
| 3121 | if (matching_modules.GetModulePointerAtIndex(i)->GetFileSpec().GetPath (path, sizeof(path))) |
| 3122 | result.AppendMessageWithFormat("%s\n", path); |
| 3123 | } |
| 3124 | } |
| 3125 | else |
| 3126 | { |
| 3127 | result.AppendErrorWithFormat ("no modules were found that match%s%s%s%s.\n", |
| 3128 | path[0] ? " file=" : "", |
| 3129 | path, |
Jason Molenda | c16b4af | 2013-05-03 23:56:12 +0000 | [diff] [blame] | 3130 | !uuid_str.empty() ? " uuid=" : "", |
| 3131 | uuid_str.c_str()); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3132 | } |
| 3133 | result.SetStatus (eReturnStatusFailed); |
| 3134 | } |
| 3135 | } |
| 3136 | else |
| 3137 | { |
| 3138 | result.AppendError ("either the \"--file <module>\" or the \"--uuid <uuid>\" option must be specified.\n"); |
| 3139 | result.SetStatus (eReturnStatusFailed); |
| 3140 | return false; |
| 3141 | } |
| 3142 | } |
| 3143 | return result.Succeeded(); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3144 | } |
| 3145 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3146 | OptionGroupOptions m_option_group; |
| 3147 | OptionGroupUUID m_uuid_option_group; |
Jason Molenda | c6127dd | 2014-11-21 02:25:15 +0000 | [diff] [blame] | 3148 | OptionGroupString m_file_option; |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3149 | OptionGroupUInt64 m_slide_option; |
| 3150 | }; |
| 3151 | |
| 3152 | //---------------------------------------------------------------------- |
| 3153 | // List images with associated information |
| 3154 | //---------------------------------------------------------------------- |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 3155 | class CommandObjectTargetModulesList : public CommandObjectParsed |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3156 | { |
| 3157 | public: |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3158 | class CommandOptions : public Options |
| 3159 | { |
| 3160 | public: |
Todd Fiala | e1cfbc7 | 2016-08-11 23:51:28 +0000 | [diff] [blame] | 3161 | CommandOptions() : |
| 3162 | Options(), |
Jim Ingham | c10312c | 2011-10-24 18:36:33 +0000 | [diff] [blame] | 3163 | m_format_array(), |
Daniel Dunbar | a08823f | 2011-10-31 22:50:49 +0000 | [diff] [blame] | 3164 | m_use_global_module_list (false), |
Jim Ingham | c10312c | 2011-10-24 18:36:33 +0000 | [diff] [blame] | 3165 | m_module_addr (LLDB_INVALID_ADDRESS) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3166 | { |
| 3167 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3168 | |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 3169 | ~CommandOptions() override = default; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3170 | |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 3171 | Error |
Todd Fiala | e1cfbc7 | 2016-08-11 23:51:28 +0000 | [diff] [blame] | 3172 | SetOptionValue(uint32_t option_idx, const char *option_arg, |
| 3173 | ExecutionContext *execution_context) override |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3174 | { |
Greg Clayton | b9d5df5 | 2012-12-06 22:49:16 +0000 | [diff] [blame] | 3175 | Error error; |
| 3176 | |
Greg Clayton | 3bcdfc0 | 2012-12-04 00:32:51 +0000 | [diff] [blame] | 3177 | const int short_option = m_getopt_table[option_idx].val; |
Greg Clayton | 65a0399 | 2011-08-09 00:01:09 +0000 | [diff] [blame] | 3178 | if (short_option == 'g') |
| 3179 | { |
| 3180 | m_use_global_module_list = true; |
| 3181 | } |
Jim Ingham | c10312c | 2011-10-24 18:36:33 +0000 | [diff] [blame] | 3182 | else if (short_option == 'a') |
| 3183 | { |
Todd Fiala | e1cfbc7 | 2016-08-11 23:51:28 +0000 | [diff] [blame] | 3184 | m_module_addr = Args::StringToAddress(execution_context, |
| 3185 | option_arg, |
| 3186 | LLDB_INVALID_ADDRESS, |
| 3187 | &error); |
Jim Ingham | c10312c | 2011-10-24 18:36:33 +0000 | [diff] [blame] | 3188 | } |
Greg Clayton | 65a0399 | 2011-08-09 00:01:09 +0000 | [diff] [blame] | 3189 | else |
| 3190 | { |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 3191 | unsigned long width = 0; |
Greg Clayton | 65a0399 | 2011-08-09 00:01:09 +0000 | [diff] [blame] | 3192 | if (option_arg) |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 3193 | width = strtoul(option_arg, nullptr, 0); |
Greg Clayton | 65a0399 | 2011-08-09 00:01:09 +0000 | [diff] [blame] | 3194 | m_format_array.push_back(std::make_pair(short_option, width)); |
| 3195 | } |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3196 | return error; |
| 3197 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3198 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3199 | void |
Todd Fiala | e1cfbc7 | 2016-08-11 23:51:28 +0000 | [diff] [blame] | 3200 | OptionParsingStarting(ExecutionContext *execution_context) override |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3201 | { |
| 3202 | m_format_array.clear(); |
Greg Clayton | 65a0399 | 2011-08-09 00:01:09 +0000 | [diff] [blame] | 3203 | m_use_global_module_list = false; |
Jim Ingham | c10312c | 2011-10-24 18:36:33 +0000 | [diff] [blame] | 3204 | m_module_addr = LLDB_INVALID_ADDRESS; |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3205 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3206 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3207 | const OptionDefinition* |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 3208 | GetDefinitions () override |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3209 | { |
| 3210 | return g_option_table; |
| 3211 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3212 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3213 | // Options table: Required for subclasses of Options. |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3214 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3215 | static OptionDefinition g_option_table[]; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3216 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3217 | // Instance variables to hold the values for command options. |
| 3218 | typedef std::vector< std::pair<char, uint32_t> > FormatWidthCollection; |
| 3219 | FormatWidthCollection m_format_array; |
Greg Clayton | 65a0399 | 2011-08-09 00:01:09 +0000 | [diff] [blame] | 3220 | bool m_use_global_module_list; |
Jim Ingham | c10312c | 2011-10-24 18:36:33 +0000 | [diff] [blame] | 3221 | lldb::addr_t m_module_addr; |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3222 | }; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3223 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3224 | CommandObjectTargetModulesList (CommandInterpreter &interpreter) : |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 3225 | CommandObjectParsed (interpreter, |
| 3226 | "target modules list", |
| 3227 | "List current executable and dependent shared library images.", |
| 3228 | "target modules list [<cmd-options>]"), |
Todd Fiala | e1cfbc7 | 2016-08-11 23:51:28 +0000 | [diff] [blame] | 3229 | m_options() |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3230 | { |
| 3231 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3232 | |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 3233 | ~CommandObjectTargetModulesList() override = default; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3234 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3235 | Options * |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 3236 | GetOptions () override |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3237 | { |
| 3238 | return &m_options; |
| 3239 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3240 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 3241 | protected: |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 3242 | bool |
| 3243 | DoExecute (Args& command, CommandReturnObject &result) override |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3244 | { |
| 3245 | Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); |
Greg Clayton | 3418c85 | 2011-08-10 02:10:13 +0000 | [diff] [blame] | 3246 | 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] | 3247 | // Define a local module list here to ensure it lives longer than any "locker" |
| 3248 | // object which might lock its contents below (through the "module_list_ptr" |
| 3249 | // variable). |
| 3250 | ModuleList module_list; |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 3251 | if (target == nullptr && !use_global_module_list) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3252 | { |
| 3253 | result.AppendError ("invalid target, create a debug target using the 'target create' command"); |
| 3254 | result.SetStatus (eReturnStatusFailed); |
| 3255 | return false; |
| 3256 | } |
| 3257 | else |
| 3258 | { |
Greg Clayton | 3418c85 | 2011-08-10 02:10:13 +0000 | [diff] [blame] | 3259 | if (target) |
| 3260 | { |
| 3261 | uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize(); |
| 3262 | result.GetOutputStream().SetAddressByteSize(addr_byte_size); |
| 3263 | result.GetErrorStream().SetAddressByteSize(addr_byte_size); |
| 3264 | } |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3265 | // Dump all sections for all modules images |
Jim Ingham | c10312c | 2011-10-24 18:36:33 +0000 | [diff] [blame] | 3266 | Stream &strm = result.GetOutputStream(); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3267 | |
Jim Ingham | c10312c | 2011-10-24 18:36:33 +0000 | [diff] [blame] | 3268 | if (m_options.m_module_addr != LLDB_INVALID_ADDRESS) |
| 3269 | { |
| 3270 | if (target) |
| 3271 | { |
| 3272 | Address module_address; |
| 3273 | if (module_address.SetLoadAddress(m_options.m_module_addr, target)) |
| 3274 | { |
Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 3275 | ModuleSP module_sp (module_address.GetModule()); |
| 3276 | if (module_sp) |
Jim Ingham | c10312c | 2011-10-24 18:36:33 +0000 | [diff] [blame] | 3277 | { |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 3278 | PrintModule (target, module_sp.get(), 0, strm); |
Jim Ingham | c10312c | 2011-10-24 18:36:33 +0000 | [diff] [blame] | 3279 | result.SetStatus (eReturnStatusSuccessFinishResult); |
| 3280 | } |
| 3281 | else |
| 3282 | { |
Jim Ingham | 17fafa1 | 2012-12-15 02:40:54 +0000 | [diff] [blame] | 3283 | 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] | 3284 | result.SetStatus (eReturnStatusFailed); |
| 3285 | } |
| 3286 | } |
| 3287 | else |
| 3288 | { |
Jim Ingham | 17fafa1 | 2012-12-15 02:40:54 +0000 | [diff] [blame] | 3289 | 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] | 3290 | result.SetStatus (eReturnStatusFailed); |
| 3291 | } |
| 3292 | } |
| 3293 | else |
| 3294 | { |
| 3295 | result.AppendError ("Can only look up modules by address with a valid target."); |
| 3296 | result.SetStatus (eReturnStatusFailed); |
| 3297 | } |
| 3298 | return result.Succeeded(); |
| 3299 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3300 | |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 3301 | size_t num_modules = 0; |
Saleem Abdulrasool | 16ff860 | 2016-05-18 01:59:10 +0000 | [diff] [blame] | 3302 | |
| 3303 | // This locker will be locked on the mutex in module_list_ptr if it is non-nullptr. |
| 3304 | // Otherwise it will lock the AllocationModuleCollectionMutex when accessing |
| 3305 | // the global module list directly. |
| 3306 | std::unique_lock<std::recursive_mutex> guard(Module::GetAllocationModuleCollectionMutex(), std::defer_lock); |
Saleem Abdulrasool | 16ff860 | 2016-05-18 01:59:10 +0000 | [diff] [blame] | 3307 | |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 3308 | const ModuleList *module_list_ptr = nullptr; |
Greg Clayton | c4a8a76 | 2012-05-15 18:43:44 +0000 | [diff] [blame] | 3309 | const size_t argc = command.GetArgumentCount(); |
| 3310 | if (argc == 0) |
Greg Clayton | 65a0399 | 2011-08-09 00:01:09 +0000 | [diff] [blame] | 3311 | { |
Greg Clayton | c4a8a76 | 2012-05-15 18:43:44 +0000 | [diff] [blame] | 3312 | if (use_global_module_list) |
| 3313 | { |
Saleem Abdulrasool | 16ff860 | 2016-05-18 01:59:10 +0000 | [diff] [blame] | 3314 | guard.lock(); |
Greg Clayton | c4a8a76 | 2012-05-15 18:43:44 +0000 | [diff] [blame] | 3315 | num_modules = Module::GetNumberAllocatedModules(); |
| 3316 | } |
| 3317 | else |
| 3318 | { |
| 3319 | module_list_ptr = &target->GetImages(); |
Greg Clayton | c4a8a76 | 2012-05-15 18:43:44 +0000 | [diff] [blame] | 3320 | } |
Greg Clayton | 65a0399 | 2011-08-09 00:01:09 +0000 | [diff] [blame] | 3321 | } |
| 3322 | else |
Greg Clayton | c4a8a76 | 2012-05-15 18:43:44 +0000 | [diff] [blame] | 3323 | { |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 3324 | for (size_t i = 0; i < argc; ++i) |
Greg Clayton | c4a8a76 | 2012-05-15 18:43:44 +0000 | [diff] [blame] | 3325 | { |
| 3326 | // Dump specified images (by basename or fullpath) |
| 3327 | const char *arg_cstr = command.GetArgumentAtIndex(i); |
| 3328 | const size_t num_matches = FindModulesByName (target, arg_cstr, module_list, use_global_module_list); |
| 3329 | if (num_matches == 0) |
| 3330 | { |
| 3331 | if (argc == 1) |
| 3332 | { |
| 3333 | result.AppendErrorWithFormat ("no modules found that match '%s'", arg_cstr); |
| 3334 | result.SetStatus (eReturnStatusFailed); |
| 3335 | return false; |
| 3336 | } |
| 3337 | } |
| 3338 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3339 | |
Greg Clayton | c4a8a76 | 2012-05-15 18:43:44 +0000 | [diff] [blame] | 3340 | module_list_ptr = &module_list; |
| 3341 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3342 | |
Saleem Abdulrasool | bb19a13 | 2016-05-19 05:13:57 +0000 | [diff] [blame] | 3343 | std::unique_lock<std::recursive_mutex> lock; |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 3344 | if (module_list_ptr != nullptr) |
Jim Ingham | 3ee12ef | 2012-05-30 02:19:25 +0000 | [diff] [blame] | 3345 | { |
Saleem Abdulrasool | bb19a13 | 2016-05-19 05:13:57 +0000 | [diff] [blame] | 3346 | lock = std::unique_lock<std::recursive_mutex>(module_list_ptr->GetMutex()); |
| 3347 | |
Jim Ingham | 3ee12ef | 2012-05-30 02:19:25 +0000 | [diff] [blame] | 3348 | num_modules = module_list_ptr->GetSize(); |
| 3349 | } |
Greg Clayton | 65a0399 | 2011-08-09 00:01:09 +0000 | [diff] [blame] | 3350 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3351 | if (num_modules > 0) |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3352 | { |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3353 | for (uint32_t image_idx = 0; image_idx<num_modules; ++image_idx) |
| 3354 | { |
Greg Clayton | 3418c85 | 2011-08-10 02:10:13 +0000 | [diff] [blame] | 3355 | ModuleSP module_sp; |
Greg Clayton | 65a0399 | 2011-08-09 00:01:09 +0000 | [diff] [blame] | 3356 | Module *module; |
Greg Clayton | c4a8a76 | 2012-05-15 18:43:44 +0000 | [diff] [blame] | 3357 | if (module_list_ptr) |
Greg Clayton | 65a0399 | 2011-08-09 00:01:09 +0000 | [diff] [blame] | 3358 | { |
Jim Ingham | 3ee12ef | 2012-05-30 02:19:25 +0000 | [diff] [blame] | 3359 | module_sp = module_list_ptr->GetModuleAtIndexUnlocked(image_idx); |
Greg Clayton | c4a8a76 | 2012-05-15 18:43:44 +0000 | [diff] [blame] | 3360 | module = module_sp.get(); |
Greg Clayton | 65a0399 | 2011-08-09 00:01:09 +0000 | [diff] [blame] | 3361 | } |
| 3362 | else |
| 3363 | { |
Greg Clayton | c4a8a76 | 2012-05-15 18:43:44 +0000 | [diff] [blame] | 3364 | module = Module::GetAllocatedModuleAtIndex(image_idx); |
| 3365 | module_sp = module->shared_from_this(); |
Greg Clayton | 65a0399 | 2011-08-09 00:01:09 +0000 | [diff] [blame] | 3366 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3367 | |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 3368 | const size_t indent = strm.Printf("[%3u] ", image_idx); |
| 3369 | PrintModule (target, module, indent, strm); |
Greg Clayton | 3418c85 | 2011-08-10 02:10:13 +0000 | [diff] [blame] | 3370 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3371 | } |
| 3372 | result.SetStatus (eReturnStatusSuccessFinishResult); |
| 3373 | } |
| 3374 | else |
| 3375 | { |
Greg Clayton | c4a8a76 | 2012-05-15 18:43:44 +0000 | [diff] [blame] | 3376 | if (argc) |
| 3377 | { |
| 3378 | if (use_global_module_list) |
| 3379 | result.AppendError ("the global module list has no matching modules"); |
| 3380 | else |
| 3381 | result.AppendError ("the target has no matching modules"); |
| 3382 | } |
Greg Clayton | 3418c85 | 2011-08-10 02:10:13 +0000 | [diff] [blame] | 3383 | else |
Greg Clayton | c4a8a76 | 2012-05-15 18:43:44 +0000 | [diff] [blame] | 3384 | { |
| 3385 | if (use_global_module_list) |
| 3386 | result.AppendError ("the global module list is empty"); |
| 3387 | else |
| 3388 | result.AppendError ("the target has no associated executable images"); |
| 3389 | } |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3390 | result.SetStatus (eReturnStatusFailed); |
| 3391 | return false; |
| 3392 | } |
| 3393 | } |
| 3394 | return result.Succeeded(); |
| 3395 | } |
Jim Ingham | c10312c | 2011-10-24 18:36:33 +0000 | [diff] [blame] | 3396 | |
| 3397 | void |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 3398 | PrintModule (Target *target, Module *module, int indent, Stream &strm) |
Jim Ingham | c10312c | 2011-10-24 18:36:33 +0000 | [diff] [blame] | 3399 | { |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 3400 | if (module == nullptr) |
Jim Ingham | 28eb571 | 2012-10-12 17:34:26 +0000 | [diff] [blame] | 3401 | { |
| 3402 | strm.PutCString("Null module"); |
| 3403 | return; |
| 3404 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3405 | |
Jim Ingham | c10312c | 2011-10-24 18:36:33 +0000 | [diff] [blame] | 3406 | bool dump_object_name = false; |
| 3407 | if (m_options.m_format_array.empty()) |
| 3408 | { |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 3409 | m_options.m_format_array.push_back(std::make_pair('u', 0)); |
| 3410 | m_options.m_format_array.push_back(std::make_pair('h', 0)); |
| 3411 | m_options.m_format_array.push_back(std::make_pair('f', 0)); |
| 3412 | m_options.m_format_array.push_back(std::make_pair('S', 0)); |
Jim Ingham | c10312c | 2011-10-24 18:36:33 +0000 | [diff] [blame] | 3413 | } |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 3414 | const size_t num_entries = m_options.m_format_array.size(); |
| 3415 | bool print_space = false; |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 3416 | for (size_t i = 0; i < num_entries; ++i) |
Jim Ingham | c10312c | 2011-10-24 18:36:33 +0000 | [diff] [blame] | 3417 | { |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 3418 | if (print_space) |
| 3419 | strm.PutChar(' '); |
| 3420 | print_space = true; |
| 3421 | const char format_char = m_options.m_format_array[i].first; |
| 3422 | uint32_t width = m_options.m_format_array[i].second; |
| 3423 | switch (format_char) |
Jim Ingham | c10312c | 2011-10-24 18:36:33 +0000 | [diff] [blame] | 3424 | { |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 3425 | case 'A': |
| 3426 | DumpModuleArchitecture (strm, module, false, width); |
| 3427 | break; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3428 | |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 3429 | case 't': |
| 3430 | DumpModuleArchitecture (strm, module, true, width); |
| 3431 | break; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3432 | |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 3433 | case 'f': |
| 3434 | DumpFullpath (strm, &module->GetFileSpec(), width); |
| 3435 | dump_object_name = true; |
| 3436 | break; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3437 | |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 3438 | case 'd': |
| 3439 | DumpDirectory (strm, &module->GetFileSpec(), width); |
| 3440 | break; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3441 | |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 3442 | case 'b': |
| 3443 | DumpBasename (strm, &module->GetFileSpec(), width); |
| 3444 | dump_object_name = true; |
| 3445 | break; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3446 | |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 3447 | case 'h': |
| 3448 | case 'o': |
| 3449 | // Image header address |
| 3450 | { |
| 3451 | uint32_t addr_nibble_width = target ? (target->GetArchitecture().GetAddressByteSize() * 2) : 16; |
Jim Ingham | c10312c | 2011-10-24 18:36:33 +0000 | [diff] [blame] | 3452 | |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 3453 | ObjectFile *objfile = module->GetObjectFile (); |
| 3454 | if (objfile) |
Jim Ingham | c10312c | 2011-10-24 18:36:33 +0000 | [diff] [blame] | 3455 | { |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 3456 | Address header_addr(objfile->GetHeaderAddress()); |
| 3457 | if (header_addr.IsValid()) |
Jim Ingham | c10312c | 2011-10-24 18:36:33 +0000 | [diff] [blame] | 3458 | { |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 3459 | if (target && !target->GetSectionLoadList().IsEmpty()) |
Jim Ingham | c10312c | 2011-10-24 18:36:33 +0000 | [diff] [blame] | 3460 | { |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 3461 | lldb::addr_t header_load_addr = header_addr.GetLoadAddress (target); |
| 3462 | if (header_load_addr == LLDB_INVALID_ADDRESS) |
| 3463 | { |
| 3464 | header_addr.Dump (&strm, target, Address::DumpStyleModuleWithFileAddress, Address::DumpStyleFileAddress); |
| 3465 | } |
Jim Ingham | c10312c | 2011-10-24 18:36:33 +0000 | [diff] [blame] | 3466 | else |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 3467 | { |
| 3468 | if (format_char == 'o') |
| 3469 | { |
| 3470 | // Show the offset of slide for the image |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 3471 | 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] | 3472 | } |
| 3473 | else |
| 3474 | { |
| 3475 | // Show the load address of the image |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 3476 | 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] | 3477 | } |
| 3478 | } |
Jim Ingham | c10312c | 2011-10-24 18:36:33 +0000 | [diff] [blame] | 3479 | break; |
| 3480 | } |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 3481 | // The address was valid, but the image isn't loaded, output the address in an appropriate format |
| 3482 | header_addr.Dump (&strm, target, Address::DumpStyleFileAddress); |
| 3483 | break; |
Jim Ingham | c10312c | 2011-10-24 18:36:33 +0000 | [diff] [blame] | 3484 | } |
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 | strm.Printf ("%*s", addr_nibble_width + 2, ""); |
| 3487 | } |
| 3488 | break; |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 3489 | |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 3490 | case 'r': |
| 3491 | { |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 3492 | size_t ref_count = 0; |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 3493 | ModuleSP module_sp (module->shared_from_this()); |
| 3494 | if (module_sp) |
| 3495 | { |
| 3496 | // Take one away to make sure we don't count our local "module_sp" |
| 3497 | ref_count = module_sp.use_count() - 1; |
| 3498 | } |
| 3499 | if (width) |
Greg Clayton | 6fea17e | 2014-03-03 19:15:20 +0000 | [diff] [blame] | 3500 | strm.Printf("{%*" PRIu64 "}", width, (uint64_t)ref_count); |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 3501 | else |
Deepak Panickal | 99fbc07 | 2014-03-03 15:39:47 +0000 | [diff] [blame] | 3502 | strm.Printf("{%" PRIu64 "}", (uint64_t)ref_count); |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 3503 | } |
| 3504 | break; |
Jim Ingham | c10312c | 2011-10-24 18:36:33 +0000 | [diff] [blame] | 3505 | |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 3506 | case 's': |
| 3507 | case 'S': |
| 3508 | { |
Ilia K | e912e3e | 2015-03-10 21:18:59 +0000 | [diff] [blame] | 3509 | const SymbolVendor *symbol_vendor = module->GetSymbolVendor(); |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 3510 | if (symbol_vendor) |
| 3511 | { |
Ilia K | e912e3e | 2015-03-10 21:18:59 +0000 | [diff] [blame] | 3512 | const FileSpec symfile_spec = symbol_vendor->GetMainFileSpec(); |
| 3513 | if (format_char == 'S') |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 3514 | { |
Ilia K | e912e3e | 2015-03-10 21:18:59 +0000 | [diff] [blame] | 3515 | // Dump symbol file only if different from module file |
| 3516 | if (!symfile_spec || symfile_spec == module->GetFileSpec()) |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 3517 | { |
Ilia K | e912e3e | 2015-03-10 21:18:59 +0000 | [diff] [blame] | 3518 | print_space = false; |
| 3519 | break; |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 3520 | } |
Ilia K | e912e3e | 2015-03-10 21:18:59 +0000 | [diff] [blame] | 3521 | // Add a newline and indent past the index |
| 3522 | strm.Printf ("\n%*s", indent, ""); |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 3523 | } |
Ilia K | e912e3e | 2015-03-10 21:18:59 +0000 | [diff] [blame] | 3524 | DumpFullpath (strm, &symfile_spec, width); |
| 3525 | dump_object_name = true; |
| 3526 | break; |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 3527 | } |
| 3528 | strm.Printf("%.*s", width, "<NONE>"); |
| 3529 | } |
| 3530 | break; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3531 | |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 3532 | case 'm': |
| 3533 | module->GetModificationTime().Dump(&strm, width); |
| 3534 | break; |
Jim Ingham | c10312c | 2011-10-24 18:36:33 +0000 | [diff] [blame] | 3535 | |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 3536 | case 'p': |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3537 | strm.Printf("%p", static_cast<void*>(module)); |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 3538 | break; |
| 3539 | |
| 3540 | case 'u': |
| 3541 | DumpModuleUUID(strm, module); |
| 3542 | break; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3543 | |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 3544 | default: |
| 3545 | break; |
Jim Ingham | c10312c | 2011-10-24 18:36:33 +0000 | [diff] [blame] | 3546 | } |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 3547 | } |
| 3548 | if (dump_object_name) |
| 3549 | { |
| 3550 | const char *object_name = module->GetObjectName().GetCString(); |
| 3551 | if (object_name) |
| 3552 | strm.Printf ("(%s)", object_name); |
Jim Ingham | c10312c | 2011-10-24 18:36:33 +0000 | [diff] [blame] | 3553 | } |
| 3554 | strm.EOL(); |
| 3555 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3556 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3557 | CommandOptions m_options; |
| 3558 | }; |
| 3559 | |
| 3560 | OptionDefinition |
| 3561 | CommandObjectTargetModulesList::CommandOptions::g_option_table[] = |
| 3562 | { |
Kate Stone | ac9c3a6 | 2016-08-26 23:28:47 +0000 | [diff] [blame] | 3563 | // clang-format off |
| 3564 | {LLDB_OPT_SET_1, false, "address", 'a', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeAddressOrExpression, "Display the image at this address."}, |
| 3565 | {LLDB_OPT_SET_1, false, "arch", 'A', OptionParser::eOptionalArgument, nullptr, nullptr, 0, eArgTypeWidth, "Display the architecture when listing images."}, |
| 3566 | {LLDB_OPT_SET_1, false, "triple", 't', OptionParser::eOptionalArgument, nullptr, nullptr, 0, eArgTypeWidth, "Display the triple when listing images."}, |
| 3567 | {LLDB_OPT_SET_1, false, "header", 'h', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Display the image header address as a load address if debugging, a file address otherwise."}, |
| 3568 | {LLDB_OPT_SET_1, false, "offset", 'o', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Display the image header address offset from the header file address (the slide amount)."}, |
| 3569 | {LLDB_OPT_SET_1, false, "uuid", 'u', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Display the UUID when listing images."}, |
| 3570 | {LLDB_OPT_SET_1, false, "fullpath", 'f', OptionParser::eOptionalArgument, nullptr, nullptr, 0, eArgTypeWidth, "Display the fullpath to the image object file."}, |
| 3571 | {LLDB_OPT_SET_1, false, "directory", 'd', OptionParser::eOptionalArgument, nullptr, nullptr, 0, eArgTypeWidth, "Display the directory with optional width for the image object file."}, |
| 3572 | {LLDB_OPT_SET_1, false, "basename", 'b', OptionParser::eOptionalArgument, nullptr, nullptr, 0, eArgTypeWidth, "Display the basename with optional width for the image object file."}, |
| 3573 | {LLDB_OPT_SET_1, false, "symfile", 's', OptionParser::eOptionalArgument, nullptr, nullptr, 0, eArgTypeWidth, "Display the fullpath to the image symbol file with optional width."}, |
| 3574 | {LLDB_OPT_SET_1, false, "symfile-unique", 'S', OptionParser::eOptionalArgument, nullptr, nullptr, 0, eArgTypeWidth, "Display the symbol file with optional width only if it is different from the executable object file."}, |
| 3575 | {LLDB_OPT_SET_1, false, "mod-time", 'm', OptionParser::eOptionalArgument, nullptr, nullptr, 0, eArgTypeWidth, "Display the modification time with optional width of the module."}, |
| 3576 | {LLDB_OPT_SET_1, false, "ref-count", 'r', OptionParser::eOptionalArgument, nullptr, nullptr, 0, eArgTypeWidth, "Display the reference count if the module is still in the shared module cache."}, |
| 3577 | {LLDB_OPT_SET_1, false, "pointer", 'p', OptionParser::eOptionalArgument, nullptr, nullptr, 0, eArgTypeNone, "Display the module pointer."}, |
| 3578 | {LLDB_OPT_SET_1, false, "global", 'g', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Display the modules from the global module list, not just the current target."}, |
| 3579 | {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr} |
| 3580 | // clang-format on |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3581 | }; |
| 3582 | |
Jason Molenda | 380241a | 2012-07-12 00:20:07 +0000 | [diff] [blame] | 3583 | #pragma mark CommandObjectTargetModulesShowUnwind |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3584 | |
Jason Molenda | 380241a | 2012-07-12 00:20:07 +0000 | [diff] [blame] | 3585 | //---------------------------------------------------------------------- |
| 3586 | // Lookup unwind information in images |
| 3587 | //---------------------------------------------------------------------- |
| 3588 | |
| 3589 | class CommandObjectTargetModulesShowUnwind : public CommandObjectParsed |
| 3590 | { |
| 3591 | public: |
Jason Molenda | 380241a | 2012-07-12 00:20:07 +0000 | [diff] [blame] | 3592 | enum |
| 3593 | { |
| 3594 | eLookupTypeInvalid = -1, |
| 3595 | eLookupTypeAddress = 0, |
| 3596 | eLookupTypeSymbol, |
| 3597 | eLookupTypeFunction, |
| 3598 | eLookupTypeFunctionOrSymbol, |
| 3599 | kNumLookupTypes |
| 3600 | }; |
| 3601 | |
| 3602 | class CommandOptions : public Options |
| 3603 | { |
| 3604 | public: |
Todd Fiala | e1cfbc7 | 2016-08-11 23:51:28 +0000 | [diff] [blame] | 3605 | CommandOptions() : |
| 3606 | Options(), |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 3607 | m_type(eLookupTypeInvalid), |
| 3608 | m_str(), |
| 3609 | m_addr(LLDB_INVALID_ADDRESS) |
Jason Molenda | 380241a | 2012-07-12 00:20:07 +0000 | [diff] [blame] | 3610 | { |
| 3611 | } |
| 3612 | |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 3613 | ~CommandOptions() override = default; |
Jason Molenda | 380241a | 2012-07-12 00:20:07 +0000 | [diff] [blame] | 3614 | |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 3615 | Error |
Todd Fiala | e1cfbc7 | 2016-08-11 23:51:28 +0000 | [diff] [blame] | 3616 | SetOptionValue(uint32_t option_idx, const char *option_arg, |
| 3617 | ExecutionContext *execution_context) override |
Jason Molenda | 380241a | 2012-07-12 00:20:07 +0000 | [diff] [blame] | 3618 | { |
| 3619 | Error error; |
| 3620 | |
Greg Clayton | 3bcdfc0 | 2012-12-04 00:32:51 +0000 | [diff] [blame] | 3621 | const int short_option = m_getopt_table[option_idx].val; |
Jason Molenda | 380241a | 2012-07-12 00:20:07 +0000 | [diff] [blame] | 3622 | |
| 3623 | switch (short_option) |
| 3624 | { |
| 3625 | case 'a': |
Jason Molenda | 535ab86 | 2013-04-23 04:30:57 +0000 | [diff] [blame] | 3626 | { |
Michael Sartain | b1e1592 | 2013-08-22 20:42:30 +0000 | [diff] [blame] | 3627 | m_str = option_arg; |
Jason Molenda | 380241a | 2012-07-12 00:20:07 +0000 | [diff] [blame] | 3628 | m_type = eLookupTypeAddress; |
Todd Fiala | e1cfbc7 | 2016-08-11 23:51:28 +0000 | [diff] [blame] | 3629 | m_addr = Args::StringToAddress(execution_context, |
| 3630 | option_arg, |
| 3631 | LLDB_INVALID_ADDRESS, |
| 3632 | &error); |
Jason Molenda | 380241a | 2012-07-12 00:20:07 +0000 | [diff] [blame] | 3633 | if (m_addr == LLDB_INVALID_ADDRESS) |
| 3634 | error.SetErrorStringWithFormat ("invalid address string '%s'", option_arg); |
| 3635 | break; |
Jason Molenda | 535ab86 | 2013-04-23 04:30:57 +0000 | [diff] [blame] | 3636 | } |
Jason Molenda | 380241a | 2012-07-12 00:20:07 +0000 | [diff] [blame] | 3637 | |
| 3638 | case 'n': |
| 3639 | m_str = option_arg; |
| 3640 | m_type = eLookupTypeFunctionOrSymbol; |
| 3641 | break; |
Michael Sartain | b1e1592 | 2013-08-22 20:42:30 +0000 | [diff] [blame] | 3642 | |
| 3643 | default: |
| 3644 | error.SetErrorStringWithFormat ("unrecognized option %c.", short_option); |
| 3645 | break; |
Jason Molenda | 380241a | 2012-07-12 00:20:07 +0000 | [diff] [blame] | 3646 | } |
| 3647 | |
| 3648 | return error; |
| 3649 | } |
| 3650 | |
| 3651 | void |
Todd Fiala | e1cfbc7 | 2016-08-11 23:51:28 +0000 | [diff] [blame] | 3652 | OptionParsingStarting(ExecutionContext *execution_context) override |
Jason Molenda | 380241a | 2012-07-12 00:20:07 +0000 | [diff] [blame] | 3653 | { |
| 3654 | m_type = eLookupTypeInvalid; |
| 3655 | m_str.clear(); |
| 3656 | m_addr = LLDB_INVALID_ADDRESS; |
| 3657 | } |
| 3658 | |
| 3659 | const OptionDefinition* |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 3660 | GetDefinitions () override |
Jason Molenda | 380241a | 2012-07-12 00:20:07 +0000 | [diff] [blame] | 3661 | { |
| 3662 | return g_option_table; |
| 3663 | } |
| 3664 | |
| 3665 | // Options table: Required for subclasses of Options. |
| 3666 | |
| 3667 | static OptionDefinition g_option_table[]; |
| 3668 | |
| 3669 | // Instance variables to hold the values for command options. |
| 3670 | |
| 3671 | int m_type; // Should be a eLookupTypeXXX enum after parsing options |
| 3672 | std::string m_str; // Holds name lookup |
| 3673 | lldb::addr_t m_addr; // Holds the address to lookup |
| 3674 | }; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3675 | |
Jason Molenda | 380241a | 2012-07-12 00:20:07 +0000 | [diff] [blame] | 3676 | CommandObjectTargetModulesShowUnwind (CommandInterpreter &interpreter) : |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 3677 | CommandObjectParsed(interpreter, |
| 3678 | "target modules show-unwind", |
| 3679 | "Show synthesized unwind instructions for a function.", |
| 3680 | nullptr, |
| 3681 | eCommandRequiresTarget | |
| 3682 | eCommandRequiresProcess | |
| 3683 | eCommandProcessMustBeLaunched | |
| 3684 | eCommandProcessMustBePaused ), |
Todd Fiala | e1cfbc7 | 2016-08-11 23:51:28 +0000 | [diff] [blame] | 3685 | m_options() |
Jason Molenda | 380241a | 2012-07-12 00:20:07 +0000 | [diff] [blame] | 3686 | { |
| 3687 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3688 | |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 3689 | ~CommandObjectTargetModulesShowUnwind() override = default; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3690 | |
Jason Molenda | 380241a | 2012-07-12 00:20:07 +0000 | [diff] [blame] | 3691 | Options * |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 3692 | GetOptions () override |
Jason Molenda | 380241a | 2012-07-12 00:20:07 +0000 | [diff] [blame] | 3693 | { |
| 3694 | return &m_options; |
| 3695 | } |
| 3696 | |
| 3697 | protected: |
| 3698 | bool |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 3699 | DoExecute (Args& command, CommandReturnObject &result) override |
Jason Molenda | 380241a | 2012-07-12 00:20:07 +0000 | [diff] [blame] | 3700 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 3701 | Target *target = m_exe_ctx.GetTargetPtr(); |
| 3702 | Process *process = m_exe_ctx.GetProcessPtr(); |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 3703 | ABI *abi = nullptr; |
Jason Molenda | 380241a | 2012-07-12 00:20:07 +0000 | [diff] [blame] | 3704 | if (process) |
| 3705 | abi = process->GetABI().get(); |
| 3706 | |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 3707 | if (process == nullptr) |
Jason Molenda | 380241a | 2012-07-12 00:20:07 +0000 | [diff] [blame] | 3708 | { |
| 3709 | result.AppendError ("You must have a process running to use this command."); |
| 3710 | result.SetStatus (eReturnStatusFailed); |
| 3711 | return false; |
| 3712 | } |
| 3713 | |
| 3714 | ThreadList threads(process->GetThreadList()); |
| 3715 | if (threads.GetSize() == 0) |
| 3716 | { |
| 3717 | result.AppendError ("The process must be paused to use this command."); |
| 3718 | result.SetStatus (eReturnStatusFailed); |
| 3719 | return false; |
| 3720 | } |
| 3721 | |
| 3722 | ThreadSP thread(threads.GetThreadAtIndex(0)); |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 3723 | if (!thread) |
Jason Molenda | 380241a | 2012-07-12 00:20:07 +0000 | [diff] [blame] | 3724 | { |
| 3725 | result.AppendError ("The process must be paused to use this command."); |
| 3726 | result.SetStatus (eReturnStatusFailed); |
| 3727 | return false; |
| 3728 | } |
| 3729 | |
Jason Molenda | 535ab86 | 2013-04-23 04:30:57 +0000 | [diff] [blame] | 3730 | SymbolContextList sc_list; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3731 | |
Jason Molenda | 380241a | 2012-07-12 00:20:07 +0000 | [diff] [blame] | 3732 | if (m_options.m_type == eLookupTypeFunctionOrSymbol) |
| 3733 | { |
Jason Molenda | 380241a | 2012-07-12 00:20:07 +0000 | [diff] [blame] | 3734 | ConstString function_name (m_options.m_str.c_str()); |
Jason Molenda | 535ab86 | 2013-04-23 04:30:57 +0000 | [diff] [blame] | 3735 | target->GetImages().FindFunctions (function_name, eFunctionNameTypeAuto, true, false, true, sc_list); |
| 3736 | } |
| 3737 | else if (m_options.m_type == eLookupTypeAddress && target) |
| 3738 | { |
| 3739 | Address addr; |
| 3740 | if (target->GetSectionLoadList().ResolveLoadAddress (m_options.m_addr, addr)) |
Jason Molenda | 380241a | 2012-07-12 00:20:07 +0000 | [diff] [blame] | 3741 | { |
| 3742 | SymbolContext sc; |
Jason Molenda | 535ab86 | 2013-04-23 04:30:57 +0000 | [diff] [blame] | 3743 | ModuleSP module_sp (addr.GetModule()); |
| 3744 | module_sp->ResolveSymbolContextForAddress (addr, eSymbolContextEverything, sc); |
| 3745 | if (sc.function || sc.symbol) |
Jason Molenda | 380241a | 2012-07-12 00:20:07 +0000 | [diff] [blame] | 3746 | { |
Jason Molenda | 535ab86 | 2013-04-23 04:30:57 +0000 | [diff] [blame] | 3747 | sc_list.Append(sc); |
Jason Molenda | 380241a | 2012-07-12 00:20:07 +0000 | [diff] [blame] | 3748 | } |
Jason Molenda | 535ab86 | 2013-04-23 04:30:57 +0000 | [diff] [blame] | 3749 | } |
| 3750 | } |
Michael Sartain | b1e1592 | 2013-08-22 20:42:30 +0000 | [diff] [blame] | 3751 | else |
| 3752 | { |
| 3753 | result.AppendError ("address-expression or function name option must be specified."); |
| 3754 | result.SetStatus (eReturnStatusFailed); |
| 3755 | return false; |
| 3756 | } |
Jason Molenda | 380241a | 2012-07-12 00:20:07 +0000 | [diff] [blame] | 3757 | |
Jason Molenda | 535ab86 | 2013-04-23 04:30:57 +0000 | [diff] [blame] | 3758 | size_t num_matches = sc_list.GetSize(); |
Michael Sartain | b1e1592 | 2013-08-22 20:42:30 +0000 | [diff] [blame] | 3759 | if (num_matches == 0) |
| 3760 | { |
| 3761 | result.AppendErrorWithFormat ("no unwind data found that matches '%s'.", m_options.m_str.c_str()); |
| 3762 | result.SetStatus (eReturnStatusFailed); |
| 3763 | return false; |
| 3764 | } |
| 3765 | |
Jason Molenda | 535ab86 | 2013-04-23 04:30:57 +0000 | [diff] [blame] | 3766 | for (uint32_t idx = 0; idx < num_matches; idx++) |
| 3767 | { |
| 3768 | SymbolContext sc; |
| 3769 | sc_list.GetContextAtIndex(idx, sc); |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 3770 | if (sc.symbol == nullptr && sc.function == nullptr) |
Jason Molenda | 535ab86 | 2013-04-23 04:30:57 +0000 | [diff] [blame] | 3771 | continue; |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 3772 | if (!sc.module_sp || sc.module_sp->GetObjectFile() == nullptr) |
Jason Molenda | 535ab86 | 2013-04-23 04:30:57 +0000 | [diff] [blame] | 3773 | continue; |
| 3774 | AddressRange range; |
| 3775 | if (!sc.GetAddressRange (eSymbolContextFunction | eSymbolContextSymbol, 0, false, range)) |
| 3776 | continue; |
| 3777 | if (!range.GetBaseAddress().IsValid()) |
| 3778 | continue; |
| 3779 | ConstString funcname(sc.GetFunctionName()); |
| 3780 | if (funcname.IsEmpty()) |
| 3781 | continue; |
| 3782 | addr_t start_addr = range.GetBaseAddress().GetLoadAddress(target); |
| 3783 | if (abi) |
| 3784 | start_addr = abi->FixCodeAddress(start_addr); |
Jason Molenda | 380241a | 2012-07-12 00:20:07 +0000 | [diff] [blame] | 3785 | |
Jason Molenda | 535ab86 | 2013-04-23 04:30:57 +0000 | [diff] [blame] | 3786 | FuncUnwindersSP func_unwinders_sp (sc.module_sp->GetObjectFile()->GetUnwindTable().GetUncachedFuncUnwindersContainingAddress(start_addr, sc)); |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 3787 | if (!func_unwinders_sp) |
Jason Molenda | 535ab86 | 2013-04-23 04:30:57 +0000 | [diff] [blame] | 3788 | continue; |
Jason Molenda | 380241a | 2012-07-12 00:20:07 +0000 | [diff] [blame] | 3789 | |
Jason Molenda | 34549b8 | 2015-01-13 06:04:04 +0000 | [diff] [blame] | 3790 | 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] | 3791 | |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 3792 | UnwindPlanSP non_callsite_unwind_plan = func_unwinders_sp->GetUnwindPlanAtNonCallSite(*target, *thread, -1); |
| 3793 | if (non_callsite_unwind_plan) |
Jason Molenda | 535ab86 | 2013-04-23 04:30:57 +0000 | [diff] [blame] | 3794 | { |
Jason Molenda | 34549b8 | 2015-01-13 06:04:04 +0000 | [diff] [blame] | 3795 | 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] | 3796 | } |
Jason Molenda | e589e7e | 2014-12-08 03:09:00 +0000 | [diff] [blame] | 3797 | UnwindPlanSP callsite_unwind_plan = func_unwinders_sp->GetUnwindPlanAtCallSite(*target, -1); |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 3798 | if (callsite_unwind_plan) |
Jason Molenda | 535ab86 | 2013-04-23 04:30:57 +0000 | [diff] [blame] | 3799 | { |
Jason Molenda | 34549b8 | 2015-01-13 06:04:04 +0000 | [diff] [blame] | 3800 | 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] | 3801 | } |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 3802 | UnwindPlanSP fast_unwind_plan = func_unwinders_sp->GetUnwindPlanFastUnwind(*target, *thread); |
| 3803 | if (fast_unwind_plan) |
Jason Molenda | 535ab86 | 2013-04-23 04:30:57 +0000 | [diff] [blame] | 3804 | { |
Jason Molenda | 34549b8 | 2015-01-13 06:04:04 +0000 | [diff] [blame] | 3805 | 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] | 3806 | } |
| 3807 | |
Jason Molenda | 34549b8 | 2015-01-13 06:04:04 +0000 | [diff] [blame] | 3808 | result.GetOutputStream().Printf("\n"); |
| 3809 | |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 3810 | UnwindPlanSP assembly_sp = func_unwinders_sp->GetAssemblyUnwindPlan(*target, *thread, 0); |
Jason Molenda | 34549b8 | 2015-01-13 06:04:04 +0000 | [diff] [blame] | 3811 | if (assembly_sp) |
| 3812 | { |
| 3813 | result.GetOutputStream().Printf("Assembly language inspection UnwindPlan:\n"); |
| 3814 | assembly_sp->Dump(result.GetOutputStream(), thread.get(), LLDB_INVALID_ADDRESS); |
| 3815 | result.GetOutputStream().Printf("\n"); |
| 3816 | } |
Jason Molenda | 34549b8 | 2015-01-13 06:04:04 +0000 | [diff] [blame] | 3817 | |
| 3818 | UnwindPlanSP ehframe_sp = func_unwinders_sp->GetEHFrameUnwindPlan(*target, 0); |
| 3819 | if (ehframe_sp) |
| 3820 | { |
| 3821 | result.GetOutputStream().Printf("eh_frame UnwindPlan:\n"); |
| 3822 | ehframe_sp->Dump(result.GetOutputStream(), thread.get(), LLDB_INVALID_ADDRESS); |
| 3823 | result.GetOutputStream().Printf("\n"); |
| 3824 | } |
| 3825 | |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 3826 | UnwindPlanSP ehframe_augmented_sp = func_unwinders_sp->GetEHFrameAugmentedUnwindPlan(*target, *thread, 0); |
Jason Molenda | 34549b8 | 2015-01-13 06:04:04 +0000 | [diff] [blame] | 3827 | if (ehframe_augmented_sp) |
| 3828 | { |
| 3829 | result.GetOutputStream().Printf("eh_frame augmented UnwindPlan:\n"); |
| 3830 | ehframe_augmented_sp->Dump(result.GetOutputStream(), thread.get(), LLDB_INVALID_ADDRESS); |
| 3831 | result.GetOutputStream().Printf("\n"); |
| 3832 | } |
| 3833 | |
Tamas Berghammer | 648f3c7 | 2015-09-30 13:50:14 +0000 | [diff] [blame] | 3834 | UnwindPlanSP arm_unwind_sp = func_unwinders_sp->GetArmUnwindUnwindPlan(*target, 0); |
| 3835 | if (arm_unwind_sp) |
| 3836 | { |
| 3837 | result.GetOutputStream().Printf("ARM.exidx unwind UnwindPlan:\n"); |
| 3838 | arm_unwind_sp->Dump(result.GetOutputStream(), thread.get(), LLDB_INVALID_ADDRESS); |
| 3839 | result.GetOutputStream().Printf("\n"); |
| 3840 | } |
| 3841 | |
Jason Molenda | 34549b8 | 2015-01-13 06:04:04 +0000 | [diff] [blame] | 3842 | UnwindPlanSP compact_unwind_sp = func_unwinders_sp->GetCompactUnwindUnwindPlan(*target, 0); |
| 3843 | if (compact_unwind_sp) |
| 3844 | { |
| 3845 | result.GetOutputStream().Printf("Compact unwind UnwindPlan:\n"); |
| 3846 | compact_unwind_sp->Dump(result.GetOutputStream(), thread.get(), LLDB_INVALID_ADDRESS); |
| 3847 | result.GetOutputStream().Printf("\n"); |
| 3848 | } |
| 3849 | |
| 3850 | if (fast_unwind_plan) |
| 3851 | { |
| 3852 | result.GetOutputStream().Printf("Fast UnwindPlan:\n"); |
| 3853 | fast_unwind_plan->Dump(result.GetOutputStream(), thread.get(), LLDB_INVALID_ADDRESS); |
| 3854 | result.GetOutputStream().Printf("\n"); |
| 3855 | } |
| 3856 | |
| 3857 | ABISP abi_sp = process->GetABI(); |
| 3858 | if (abi_sp) |
| 3859 | { |
| 3860 | UnwindPlan arch_default(lldb::eRegisterKindGeneric); |
| 3861 | if (abi_sp->CreateDefaultUnwindPlan (arch_default)) |
| 3862 | { |
| 3863 | result.GetOutputStream().Printf("Arch default UnwindPlan:\n"); |
| 3864 | arch_default.Dump(result.GetOutputStream(), thread.get(), LLDB_INVALID_ADDRESS); |
| 3865 | result.GetOutputStream().Printf("\n"); |
| 3866 | } |
| 3867 | |
| 3868 | UnwindPlan arch_entry(lldb::eRegisterKindGeneric); |
| 3869 | if (abi_sp->CreateFunctionEntryUnwindPlan (arch_entry)) |
| 3870 | { |
| 3871 | result.GetOutputStream().Printf("Arch default at entry point UnwindPlan:\n"); |
| 3872 | arch_entry.Dump(result.GetOutputStream(), thread.get(), LLDB_INVALID_ADDRESS); |
| 3873 | result.GetOutputStream().Printf("\n"); |
| 3874 | } |
| 3875 | } |
Jason Molenda | 535ab86 | 2013-04-23 04:30:57 +0000 | [diff] [blame] | 3876 | |
| 3877 | result.GetOutputStream().Printf ("\n"); |
Jason Molenda | 380241a | 2012-07-12 00:20:07 +0000 | [diff] [blame] | 3878 | } |
| 3879 | return result.Succeeded(); |
| 3880 | } |
| 3881 | |
| 3882 | CommandOptions m_options; |
| 3883 | }; |
| 3884 | |
| 3885 | OptionDefinition |
| 3886 | CommandObjectTargetModulesShowUnwind::CommandOptions::g_option_table[] = |
| 3887 | { |
Kate Stone | ac9c3a6 | 2016-08-26 23:28:47 +0000 | [diff] [blame] | 3888 | // clang-format off |
| 3889 | {LLDB_OPT_SET_1, false, "name", 'n', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeFunctionName, "Show unwind instructions for a function or symbol name."}, |
| 3890 | {LLDB_OPT_SET_2, false, "address", 'a', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeAddressOrExpression, "Show unwind instructions for a function or symbol containing an address"}, |
| 3891 | {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr} |
| 3892 | // clang-format on |
Jason Molenda | 380241a | 2012-07-12 00:20:07 +0000 | [diff] [blame] | 3893 | }; |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3894 | |
| 3895 | //---------------------------------------------------------------------- |
| 3896 | // Lookup information in images |
| 3897 | //---------------------------------------------------------------------- |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 3898 | class CommandObjectTargetModulesLookup : public CommandObjectParsed |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3899 | { |
| 3900 | public: |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3901 | enum |
| 3902 | { |
| 3903 | eLookupTypeInvalid = -1, |
| 3904 | eLookupTypeAddress = 0, |
| 3905 | eLookupTypeSymbol, |
| 3906 | eLookupTypeFileLine, // Line is optional |
| 3907 | eLookupTypeFunction, |
Greg Clayton | c4a8a76 | 2012-05-15 18:43:44 +0000 | [diff] [blame] | 3908 | eLookupTypeFunctionOrSymbol, |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3909 | eLookupTypeType, |
| 3910 | kNumLookupTypes |
| 3911 | }; |
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 | class CommandOptions : public Options |
| 3914 | { |
| 3915 | public: |
Todd Fiala | e1cfbc7 | 2016-08-11 23:51:28 +0000 | [diff] [blame] | 3916 | CommandOptions() : |
| 3917 | Options() |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3918 | { |
Todd Fiala | e1cfbc7 | 2016-08-11 23:51:28 +0000 | [diff] [blame] | 3919 | OptionParsingStarting(nullptr); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3920 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3921 | |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 3922 | ~CommandOptions() override = default; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3923 | |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 3924 | Error |
Todd Fiala | e1cfbc7 | 2016-08-11 23:51:28 +0000 | [diff] [blame] | 3925 | SetOptionValue (uint32_t option_idx, const char *option_arg, |
| 3926 | ExecutionContext *execution_context) override |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3927 | { |
| 3928 | Error error; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3929 | |
Greg Clayton | 3bcdfc0 | 2012-12-04 00:32:51 +0000 | [diff] [blame] | 3930 | const int short_option = m_getopt_table[option_idx].val; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3931 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3932 | switch (short_option) |
| 3933 | { |
| 3934 | case 'a': |
Jim Ingham | e7b849e | 2013-03-15 23:09:19 +0000 | [diff] [blame] | 3935 | { |
| 3936 | m_type = eLookupTypeAddress; |
Todd Fiala | e1cfbc7 | 2016-08-11 23:51:28 +0000 | [diff] [blame] | 3937 | m_addr = Args::StringToAddress(execution_context, |
| 3938 | option_arg, |
| 3939 | LLDB_INVALID_ADDRESS, |
| 3940 | &error); |
Jim Ingham | e7b849e | 2013-03-15 23:09:19 +0000 | [diff] [blame] | 3941 | } |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3942 | break; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3943 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3944 | case 'o': |
Vince Harron | 5275aaa | 2015-01-15 20:08:35 +0000 | [diff] [blame] | 3945 | m_offset = StringConvert::ToUInt64(option_arg, LLDB_INVALID_ADDRESS); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3946 | if (m_offset == LLDB_INVALID_ADDRESS) |
Greg Clayton | 86edbf4 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 3947 | error.SetErrorStringWithFormat ("invalid offset string '%s'", option_arg); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3948 | break; |
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 | case 's': |
| 3951 | m_str = option_arg; |
| 3952 | m_type = eLookupTypeSymbol; |
| 3953 | break; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3954 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3955 | case 'f': |
| 3956 | m_file.SetFile (option_arg, false); |
| 3957 | m_type = eLookupTypeFileLine; |
| 3958 | break; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3959 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3960 | case 'i': |
Sean Callanan | d4a7c12 | 2012-02-11 01:22:21 +0000 | [diff] [blame] | 3961 | m_include_inlines = false; |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3962 | break; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3963 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3964 | case 'l': |
Vince Harron | 5275aaa | 2015-01-15 20:08:35 +0000 | [diff] [blame] | 3965 | m_line_number = StringConvert::ToUInt32(option_arg, UINT32_MAX); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3966 | if (m_line_number == UINT32_MAX) |
Greg Clayton | 86edbf4 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 3967 | error.SetErrorStringWithFormat ("invalid line number string '%s'", option_arg); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3968 | else if (m_line_number == 0) |
Greg Clayton | 86edbf4 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 3969 | error.SetErrorString ("zero is an invalid line number"); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3970 | m_type = eLookupTypeFileLine; |
| 3971 | break; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3972 | |
Greg Clayton | c4a8a76 | 2012-05-15 18:43:44 +0000 | [diff] [blame] | 3973 | case 'F': |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3974 | m_str = option_arg; |
| 3975 | m_type = eLookupTypeFunction; |
| 3976 | break; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3977 | |
Greg Clayton | c4a8a76 | 2012-05-15 18:43:44 +0000 | [diff] [blame] | 3978 | case 'n': |
| 3979 | m_str = option_arg; |
| 3980 | m_type = eLookupTypeFunctionOrSymbol; |
| 3981 | break; |
| 3982 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3983 | case 't': |
| 3984 | m_str = option_arg; |
| 3985 | m_type = eLookupTypeType; |
| 3986 | break; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3987 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3988 | case 'v': |
| 3989 | m_verbose = 1; |
| 3990 | break; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3991 | |
Sean Callanan | d38b4a9 | 2012-06-06 20:49:55 +0000 | [diff] [blame] | 3992 | case 'A': |
| 3993 | m_print_all = true; |
| 3994 | break; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3995 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 3996 | case 'r': |
| 3997 | m_use_regex = true; |
| 3998 | break; |
| 3999 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4000 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 4001 | return error; |
| 4002 | } |
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 | void |
Todd Fiala | e1cfbc7 | 2016-08-11 23:51:28 +0000 | [diff] [blame] | 4005 | OptionParsingStarting(ExecutionContext *execution_context) override |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 4006 | { |
| 4007 | m_type = eLookupTypeInvalid; |
| 4008 | m_str.clear(); |
| 4009 | m_file.Clear(); |
| 4010 | m_addr = LLDB_INVALID_ADDRESS; |
| 4011 | m_offset = 0; |
| 4012 | m_line_number = 0; |
| 4013 | m_use_regex = false; |
Sean Callanan | d4a7c12 | 2012-02-11 01:22:21 +0000 | [diff] [blame] | 4014 | m_include_inlines = true; |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 4015 | m_verbose = false; |
Sean Callanan | d38b4a9 | 2012-06-06 20:49:55 +0000 | [diff] [blame] | 4016 | m_print_all = false; |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 4017 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4018 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 4019 | const OptionDefinition* |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 4020 | GetDefinitions () override |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 4021 | { |
| 4022 | return g_option_table; |
| 4023 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4024 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 4025 | // Options table: Required for subclasses of Options. |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4026 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 4027 | static OptionDefinition g_option_table[]; |
| 4028 | int m_type; // Should be a eLookupTypeXXX enum after parsing options |
| 4029 | std::string m_str; // Holds name lookup |
| 4030 | FileSpec m_file; // Files for file lookups |
| 4031 | lldb::addr_t m_addr; // Holds the address to lookup |
| 4032 | lldb::addr_t m_offset; // Subtract this offset from m_addr before doing lookups. |
| 4033 | uint32_t m_line_number; // Line number for file+line lookups |
| 4034 | bool m_use_regex; // Name lookups in m_str are regular expressions. |
Sean Callanan | d4a7c12 | 2012-02-11 01:22:21 +0000 | [diff] [blame] | 4035 | 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] | 4036 | bool m_verbose; // Enable verbose lookup info |
Sean Callanan | d38b4a9 | 2012-06-06 20:49:55 +0000 | [diff] [blame] | 4037 | 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] | 4038 | }; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4039 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 4040 | CommandObjectTargetModulesLookup (CommandInterpreter &interpreter) : |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 4041 | CommandObjectParsed(interpreter, |
| 4042 | "target modules lookup", |
| 4043 | "Look up information within executable and dependent shared library images.", |
| 4044 | nullptr, |
| 4045 | eCommandRequiresTarget), |
Todd Fiala | e1cfbc7 | 2016-08-11 23:51:28 +0000 | [diff] [blame] | 4046 | m_options() |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 4047 | { |
| 4048 | CommandArgumentEntry arg; |
| 4049 | CommandArgumentData file_arg; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4050 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 4051 | // Define the first (and only) variant of this arg. |
| 4052 | file_arg.arg_type = eArgTypeFilename; |
| 4053 | file_arg.arg_repetition = eArgRepeatStar; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4054 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 4055 | // There is only one variant this argument could be; put it into the argument entry. |
| 4056 | arg.push_back (file_arg); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4057 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 4058 | // Push the data for the first argument into the m_arguments vector. |
| 4059 | m_arguments.push_back (arg); |
| 4060 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4061 | |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 4062 | ~CommandObjectTargetModulesLookup() override = default; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4063 | |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 4064 | Options * |
| 4065 | GetOptions () override |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 4066 | { |
| 4067 | return &m_options; |
| 4068 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4069 | |
Sean Callanan | d38b4a9 | 2012-06-06 20:49:55 +0000 | [diff] [blame] | 4070 | bool |
| 4071 | LookupHere (CommandInterpreter &interpreter, CommandReturnObject &result, bool &syntax_error) |
| 4072 | { |
| 4073 | switch (m_options.m_type) |
| 4074 | { |
| 4075 | case eLookupTypeAddress: |
| 4076 | case eLookupTypeFileLine: |
| 4077 | case eLookupTypeFunction: |
| 4078 | case eLookupTypeFunctionOrSymbol: |
| 4079 | case eLookupTypeSymbol: |
| 4080 | default: |
| 4081 | return false; |
| 4082 | case eLookupTypeType: |
| 4083 | break; |
| 4084 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4085 | |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 4086 | StackFrameSP frame = m_exe_ctx.GetFrameSP(); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4087 | |
Sean Callanan | d38b4a9 | 2012-06-06 20:49:55 +0000 | [diff] [blame] | 4088 | if (!frame) |
| 4089 | return false; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4090 | |
Sean Callanan | d38b4a9 | 2012-06-06 20:49:55 +0000 | [diff] [blame] | 4091 | const SymbolContext &sym_ctx(frame->GetSymbolContext(eSymbolContextModule)); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4092 | |
Sean Callanan | d38b4a9 | 2012-06-06 20:49:55 +0000 | [diff] [blame] | 4093 | if (!sym_ctx.module_sp) |
| 4094 | return false; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4095 | |
Sean Callanan | d38b4a9 | 2012-06-06 20:49:55 +0000 | [diff] [blame] | 4096 | switch (m_options.m_type) |
| 4097 | { |
| 4098 | default: |
| 4099 | return false; |
| 4100 | case eLookupTypeType: |
| 4101 | if (!m_options.m_str.empty()) |
| 4102 | { |
| 4103 | if (LookupTypeHere (m_interpreter, |
| 4104 | result.GetOutputStream(), |
| 4105 | sym_ctx, |
| 4106 | m_options.m_str.c_str(), |
| 4107 | m_options.m_use_regex)) |
| 4108 | { |
| 4109 | result.SetStatus(eReturnStatusSuccessFinishResult); |
| 4110 | return true; |
| 4111 | } |
| 4112 | } |
| 4113 | break; |
| 4114 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4115 | |
Sean Callanan | d38b4a9 | 2012-06-06 20:49:55 +0000 | [diff] [blame] | 4116 | return true; |
| 4117 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4118 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 4119 | bool |
| 4120 | LookupInModule (CommandInterpreter &interpreter, Module *module, CommandReturnObject &result, bool &syntax_error) |
| 4121 | { |
| 4122 | switch (m_options.m_type) |
| 4123 | { |
| 4124 | case eLookupTypeAddress: |
| 4125 | if (m_options.m_addr != LLDB_INVALID_ADDRESS) |
| 4126 | { |
Saleem Abdulrasool | c98d969 | 2016-01-22 20:26:34 +0000 | [diff] [blame] | 4127 | if (LookupAddressInModule (m_interpreter, |
| 4128 | result.GetOutputStream(), |
| 4129 | module, |
| 4130 | eSymbolContextEverything | (m_options.m_verbose ? static_cast<int>(eSymbolContextVariable) : 0), |
| 4131 | m_options.m_addr, |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 4132 | m_options.m_offset, |
| 4133 | m_options.m_verbose)) |
| 4134 | { |
| 4135 | result.SetStatus(eReturnStatusSuccessFinishResult); |
| 4136 | return true; |
| 4137 | } |
| 4138 | } |
| 4139 | break; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4140 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 4141 | case eLookupTypeSymbol: |
| 4142 | if (!m_options.m_str.empty()) |
| 4143 | { |
Greg Clayton | c4a8a76 | 2012-05-15 18:43:44 +0000 | [diff] [blame] | 4144 | if (LookupSymbolInModule (m_interpreter, |
| 4145 | result.GetOutputStream(), |
| 4146 | module, |
| 4147 | m_options.m_str.c_str(), |
| 4148 | m_options.m_use_regex, |
| 4149 | m_options.m_verbose)) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 4150 | { |
| 4151 | result.SetStatus(eReturnStatusSuccessFinishResult); |
| 4152 | return true; |
| 4153 | } |
| 4154 | } |
| 4155 | break; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4156 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 4157 | case eLookupTypeFileLine: |
| 4158 | if (m_options.m_file) |
| 4159 | { |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 4160 | if (LookupFileAndLineInModule (m_interpreter, |
| 4161 | result.GetOutputStream(), |
| 4162 | module, |
| 4163 | m_options.m_file, |
| 4164 | m_options.m_line_number, |
Sean Callanan | d4a7c12 | 2012-02-11 01:22:21 +0000 | [diff] [blame] | 4165 | m_options.m_include_inlines, |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 4166 | m_options.m_verbose)) |
| 4167 | { |
| 4168 | result.SetStatus(eReturnStatusSuccessFinishResult); |
| 4169 | return true; |
| 4170 | } |
| 4171 | } |
| 4172 | break; |
Greg Clayton | c4a8a76 | 2012-05-15 18:43:44 +0000 | [diff] [blame] | 4173 | |
| 4174 | case eLookupTypeFunctionOrSymbol: |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 4175 | case eLookupTypeFunction: |
| 4176 | if (!m_options.m_str.empty()) |
| 4177 | { |
| 4178 | if (LookupFunctionInModule (m_interpreter, |
| 4179 | result.GetOutputStream(), |
| 4180 | module, |
| 4181 | m_options.m_str.c_str(), |
| 4182 | m_options.m_use_regex, |
Sean Callanan | d4a7c12 | 2012-02-11 01:22:21 +0000 | [diff] [blame] | 4183 | m_options.m_include_inlines, |
Greg Clayton | c4a8a76 | 2012-05-15 18:43:44 +0000 | [diff] [blame] | 4184 | m_options.m_type == eLookupTypeFunctionOrSymbol, // include symbols |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 4185 | m_options.m_verbose)) |
| 4186 | { |
| 4187 | result.SetStatus(eReturnStatusSuccessFinishResult); |
| 4188 | return true; |
| 4189 | } |
| 4190 | } |
| 4191 | break; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4192 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 4193 | case eLookupTypeType: |
| 4194 | if (!m_options.m_str.empty()) |
| 4195 | { |
| 4196 | if (LookupTypeInModule (m_interpreter, |
| 4197 | result.GetOutputStream(), |
| 4198 | module, |
| 4199 | m_options.m_str.c_str(), |
| 4200 | m_options.m_use_regex)) |
| 4201 | { |
| 4202 | result.SetStatus(eReturnStatusSuccessFinishResult); |
| 4203 | return true; |
| 4204 | } |
| 4205 | } |
| 4206 | break; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4207 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 4208 | default: |
Todd Fiala | e1cfbc7 | 2016-08-11 23:51:28 +0000 | [diff] [blame] | 4209 | m_options.GenerateOptionUsage(result.GetErrorStream(), this, |
| 4210 | GetCommandInterpreter() |
| 4211 | .GetDebugger() |
| 4212 | .GetTerminalWidth()); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 4213 | syntax_error = true; |
| 4214 | break; |
| 4215 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4216 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 4217 | result.SetStatus (eReturnStatusFailed); |
| 4218 | return false; |
| 4219 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4220 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 4221 | protected: |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 4222 | bool |
| 4223 | DoExecute (Args& command, CommandReturnObject &result) override |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 4224 | { |
| 4225 | Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 4226 | if (target == nullptr) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 4227 | { |
| 4228 | result.AppendError ("invalid target, create a debug target using the 'target create' command"); |
| 4229 | result.SetStatus (eReturnStatusFailed); |
| 4230 | return false; |
| 4231 | } |
| 4232 | else |
| 4233 | { |
| 4234 | bool syntax_error = false; |
| 4235 | uint32_t i; |
| 4236 | uint32_t num_successful_lookups = 0; |
| 4237 | uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize(); |
| 4238 | result.GetOutputStream().SetAddressByteSize(addr_byte_size); |
| 4239 | result.GetErrorStream().SetAddressByteSize(addr_byte_size); |
| 4240 | // Dump all sections for all modules images |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4241 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 4242 | if (command.GetArgumentCount() == 0) |
| 4243 | { |
Sean Callanan | d38b4a9 | 2012-06-06 20:49:55 +0000 | [diff] [blame] | 4244 | ModuleSP current_module; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4245 | |
Sean Callanan | d38b4a9 | 2012-06-06 20:49:55 +0000 | [diff] [blame] | 4246 | // Where it is possible to look in the current symbol context |
| 4247 | // first, try that. If this search was successful and --all |
| 4248 | // was not passed, don't print anything else. |
| 4249 | if (LookupHere (m_interpreter, result, syntax_error)) |
| 4250 | { |
| 4251 | result.GetOutputStream().EOL(); |
| 4252 | num_successful_lookups++; |
| 4253 | if (!m_options.m_print_all) |
| 4254 | { |
| 4255 | result.SetStatus (eReturnStatusSuccessFinishResult); |
| 4256 | return result.Succeeded(); |
| 4257 | } |
| 4258 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4259 | |
Sean Callanan | d38b4a9 | 2012-06-06 20:49:55 +0000 | [diff] [blame] | 4260 | // Dump all sections for all other modules |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4261 | |
Enrico Granata | 1759848 | 2012-11-08 02:22:02 +0000 | [diff] [blame] | 4262 | const ModuleList &target_modules = target->GetImages(); |
Saleem Abdulrasool | bb19a13 | 2016-05-19 05:13:57 +0000 | [diff] [blame] | 4263 | std::lock_guard<std::recursive_mutex> guard(target_modules.GetMutex()); |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 4264 | const size_t num_modules = target_modules.GetSize(); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 4265 | if (num_modules > 0) |
| 4266 | { |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 4267 | for (i = 0; i < num_modules && !syntax_error; ++i) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 4268 | { |
Sean Callanan | d38b4a9 | 2012-06-06 20:49:55 +0000 | [diff] [blame] | 4269 | Module *module_pointer = target_modules.GetModulePointerAtIndexUnlocked(i); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4270 | |
Sean Callanan | d38b4a9 | 2012-06-06 20:49:55 +0000 | [diff] [blame] | 4271 | if (module_pointer != current_module.get() && |
| 4272 | LookupInModule (m_interpreter, target_modules.GetModulePointerAtIndexUnlocked(i), result, syntax_error)) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 4273 | { |
| 4274 | result.GetOutputStream().EOL(); |
| 4275 | num_successful_lookups++; |
| 4276 | } |
| 4277 | } |
| 4278 | } |
| 4279 | else |
| 4280 | { |
| 4281 | result.AppendError ("the target has no associated executable images"); |
| 4282 | result.SetStatus (eReturnStatusFailed); |
| 4283 | return false; |
| 4284 | } |
| 4285 | } |
| 4286 | else |
| 4287 | { |
| 4288 | // Dump specified images (by basename or fullpath) |
| 4289 | const char *arg_cstr; |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 4290 | for (i = 0; (arg_cstr = command.GetArgumentAtIndex(i)) != nullptr && !syntax_error; ++i) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 4291 | { |
Greg Clayton | 8ee6438 | 2011-11-10 01:18:58 +0000 | [diff] [blame] | 4292 | ModuleList module_list; |
| 4293 | const size_t num_matches = FindModulesByName (target, arg_cstr, module_list, false); |
| 4294 | if (num_matches > 0) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 4295 | { |
Jason Molenda | ccd41e5 | 2012-10-04 22:47:07 +0000 | [diff] [blame] | 4296 | for (size_t j=0; j<num_matches; ++j) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 4297 | { |
Jason Molenda | ccd41e5 | 2012-10-04 22:47:07 +0000 | [diff] [blame] | 4298 | Module *module = module_list.GetModulePointerAtIndex(j); |
Greg Clayton | 8ee6438 | 2011-11-10 01:18:58 +0000 | [diff] [blame] | 4299 | if (module) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 4300 | { |
Greg Clayton | 8ee6438 | 2011-11-10 01:18:58 +0000 | [diff] [blame] | 4301 | if (LookupInModule (m_interpreter, module, result, syntax_error)) |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 4302 | { |
| 4303 | result.GetOutputStream().EOL(); |
| 4304 | num_successful_lookups++; |
| 4305 | } |
| 4306 | } |
| 4307 | } |
| 4308 | } |
| 4309 | else |
| 4310 | result.AppendWarningWithFormat("Unable to find an image that matches '%s'.\n", arg_cstr); |
| 4311 | } |
| 4312 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4313 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 4314 | if (num_successful_lookups > 0) |
| 4315 | result.SetStatus (eReturnStatusSuccessFinishResult); |
| 4316 | else |
| 4317 | result.SetStatus (eReturnStatusFailed); |
| 4318 | } |
| 4319 | return result.Succeeded(); |
| 4320 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4321 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 4322 | CommandOptions m_options; |
| 4323 | }; |
| 4324 | |
| 4325 | OptionDefinition |
| 4326 | CommandObjectTargetModulesLookup::CommandOptions::g_option_table[] = |
| 4327 | { |
Kate Stone | ac9c3a6 | 2016-08-26 23:28:47 +0000 | [diff] [blame] | 4328 | // clang-format off |
| 4329 | {LLDB_OPT_SET_1, true, "address", 'a', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeAddressOrExpression, "Lookup an address in one or more target modules."}, |
| 4330 | {LLDB_OPT_SET_1, false, "offset", 'o', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeOffset, "When looking up an address subtract <offset> from any addresses before doing the lookup."}, |
| 4331 | /* FIXME: re-enable regex for types when the LookupTypeInModule actually uses the regex option: | LLDB_OPT_SET_6 */ |
| 4332 | {LLDB_OPT_SET_2| LLDB_OPT_SET_4 | LLDB_OPT_SET_5, false, "regex", 'r', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "The <name> argument for name lookups are regular expressions."}, |
| 4333 | {LLDB_OPT_SET_2, true, "symbol", 's', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeSymbol, "Lookup a symbol by name in the symbol tables in one or more target modules."}, |
| 4334 | {LLDB_OPT_SET_3, true, "file", 'f', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeFilename, "Lookup a file by fullpath or basename in one or more target modules."}, |
| 4335 | {LLDB_OPT_SET_3, false, "line", 'l', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeLineNum, "Lookup a line number in a file (must be used in conjunction with --file)."}, |
| 4336 | {LLDB_OPT_SET_FROM_TO(3,5), false, "no-inlines", 'i', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Ignore inline entries (must be used in conjunction with --file or --function)."}, |
| 4337 | {LLDB_OPT_SET_4, true, "function", 'F', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeFunctionName, "Lookup a function by name in the debug symbols in one or more target modules."}, |
| 4338 | {LLDB_OPT_SET_5, true, "name", 'n', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeFunctionOrSymbol, "Lookup a function or symbol by name in one or more target modules."}, |
| 4339 | {LLDB_OPT_SET_6, true, "type", 't', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeName, "Lookup a type by name in the debug symbols in one or more target modules."}, |
| 4340 | {LLDB_OPT_SET_ALL, false, "verbose", 'v', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Enable verbose lookup information."}, |
| 4341 | {LLDB_OPT_SET_ALL, false, "all", 'A', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Print all matches, not just the best match, if a best match is available."}, |
| 4342 | {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr} |
| 4343 | // clang-format on |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 4344 | }; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4345 | |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 4346 | #pragma mark CommandObjectMultiwordImageSearchPaths |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4347 | |
| 4348 | //------------------------------------------------------------------------- |
| 4349 | // CommandObjectMultiwordImageSearchPaths |
| 4350 | //------------------------------------------------------------------------- |
| 4351 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 4352 | class CommandObjectTargetModulesImageSearchPaths : public CommandObjectMultiword |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4353 | { |
| 4354 | public: |
Kate Stone | 7428a18 | 2016-07-14 22:03:10 +0000 | [diff] [blame] | 4355 | CommandObjectTargetModulesImageSearchPaths(CommandInterpreter &interpreter) |
| 4356 | : CommandObjectMultiword(interpreter, "target modules search-paths", |
| 4357 | "Commands for managing module search paths for a target.", |
| 4358 | "target modules search-paths <subcommand> [<subcommand-options>]") |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4359 | { |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 4360 | LoadSubCommand ("add", CommandObjectSP (new CommandObjectTargetModulesSearchPathsAdd (interpreter))); |
| 4361 | LoadSubCommand ("clear", CommandObjectSP (new CommandObjectTargetModulesSearchPathsClear (interpreter))); |
| 4362 | LoadSubCommand ("insert", CommandObjectSP (new CommandObjectTargetModulesSearchPathsInsert (interpreter))); |
| 4363 | LoadSubCommand ("list", CommandObjectSP (new CommandObjectTargetModulesSearchPathsList (interpreter))); |
| 4364 | LoadSubCommand ("query", CommandObjectSP (new CommandObjectTargetModulesSearchPathsQuery (interpreter))); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4365 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4366 | |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 4367 | ~CommandObjectTargetModulesImageSearchPaths() override = default; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4368 | }; |
| 4369 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 4370 | #pragma mark CommandObjectTargetModules |
| 4371 | |
| 4372 | //------------------------------------------------------------------------- |
| 4373 | // CommandObjectTargetModules |
| 4374 | //------------------------------------------------------------------------- |
| 4375 | |
| 4376 | class CommandObjectTargetModules : public CommandObjectMultiword |
| 4377 | { |
| 4378 | public: |
| 4379 | //------------------------------------------------------------------ |
| 4380 | // Constructors and Destructors |
| 4381 | //------------------------------------------------------------------ |
Kate Stone | 7428a18 | 2016-07-14 22:03:10 +0000 | [diff] [blame] | 4382 | CommandObjectTargetModules(CommandInterpreter &interpreter) |
| 4383 | : CommandObjectMultiword(interpreter, "target modules", |
| 4384 | "Commands for accessing information for one or more target modules.", |
| 4385 | "target modules <sub-command> ...") |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 4386 | { |
| 4387 | LoadSubCommand ("add", CommandObjectSP (new CommandObjectTargetModulesAdd (interpreter))); |
| 4388 | LoadSubCommand ("load", CommandObjectSP (new CommandObjectTargetModulesLoad (interpreter))); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 4389 | LoadSubCommand ("dump", CommandObjectSP (new CommandObjectTargetModulesDump (interpreter))); |
| 4390 | LoadSubCommand ("list", CommandObjectSP (new CommandObjectTargetModulesList (interpreter))); |
| 4391 | LoadSubCommand ("lookup", CommandObjectSP (new CommandObjectTargetModulesLookup (interpreter))); |
| 4392 | LoadSubCommand ("search-paths", CommandObjectSP (new CommandObjectTargetModulesImageSearchPaths (interpreter))); |
Jason Molenda | 380241a | 2012-07-12 00:20:07 +0000 | [diff] [blame] | 4393 | LoadSubCommand ("show-unwind", CommandObjectSP (new CommandObjectTargetModulesShowUnwind (interpreter))); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 4394 | |
| 4395 | } |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 4396 | |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 4397 | ~CommandObjectTargetModules() override = default; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4398 | |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 4399 | private: |
| 4400 | //------------------------------------------------------------------ |
| 4401 | // For CommandObjectTargetModules only |
| 4402 | //------------------------------------------------------------------ |
| 4403 | DISALLOW_COPY_AND_ASSIGN (CommandObjectTargetModules); |
| 4404 | }; |
| 4405 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 4406 | class CommandObjectTargetSymbolsAdd : public CommandObjectParsed |
Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 4407 | { |
| 4408 | public: |
| 4409 | CommandObjectTargetSymbolsAdd (CommandInterpreter &interpreter) : |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 4410 | CommandObjectParsed (interpreter, |
| 4411 | "target symbols add", |
Greg Clayton | b5f0fea | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 4412 | "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.", |
Enrico Granata | e87764f | 2015-05-27 05:04:35 +0000 | [diff] [blame] | 4413 | "target symbols add [<symfile>]", eCommandRequiresTarget), |
Todd Fiala | e1cfbc7 | 2016-08-11 23:51:28 +0000 | [diff] [blame] | 4414 | m_option_group(), |
Greg Clayton | b5f0fea | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 4415 | m_file_option (LLDB_OPT_SET_1, false, "shlib", 's', CommandCompletions::eModuleCompletion, eArgTypeShlibName, "Fullpath or basename for module to find debug symbols for."), |
| 4416 | m_current_frame_option (LLDB_OPT_SET_2, false, "frame", 'F', "Locate the debug symbols the currently selected frame.", false, true) |
| 4417 | |
Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 4418 | { |
Greg Clayton | b5f0fea | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 4419 | m_option_group.Append (&m_uuid_option_group, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1); |
| 4420 | m_option_group.Append (&m_file_option, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1); |
| 4421 | m_option_group.Append (&m_current_frame_option, LLDB_OPT_SET_2, LLDB_OPT_SET_2); |
| 4422 | m_option_group.Finalize(); |
Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 4423 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4424 | |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 4425 | ~CommandObjectTargetSymbolsAdd() override = default; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4426 | |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 4427 | int |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 4428 | HandleArgumentCompletion (Args &input, |
| 4429 | int &cursor_index, |
| 4430 | int &cursor_char_position, |
| 4431 | OptionElementVector &opt_element_vector, |
| 4432 | int match_start_point, |
| 4433 | int max_return_elements, |
| 4434 | bool &word_complete, |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 4435 | StringList &matches) override |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 4436 | { |
| 4437 | std::string completion_str (input.GetArgumentAtIndex(cursor_index)); |
| 4438 | completion_str.erase (cursor_char_position); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4439 | |
Todd Fiala | e1cfbc7 | 2016-08-11 23:51:28 +0000 | [diff] [blame] | 4440 | CommandCompletions::InvokeCommonCompletionCallbacks(GetCommandInterpreter(), |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 4441 | CommandCompletions::eDiskFileCompletion, |
| 4442 | completion_str.c_str(), |
| 4443 | match_start_point, |
| 4444 | max_return_elements, |
| 4445 | nullptr, |
| 4446 | word_complete, |
| 4447 | matches); |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 4448 | return matches.GetSize(); |
| 4449 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4450 | |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 4451 | Options * |
| 4452 | GetOptions () override |
Greg Clayton | b5f0fea | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 4453 | { |
| 4454 | return &m_option_group; |
| 4455 | } |
Greg Clayton | b5f0fea | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 4456 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 4457 | protected: |
Greg Clayton | b5f0fea | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 4458 | bool |
| 4459 | AddModuleSymbols (Target *target, |
Greg Clayton | 89deb06 | 2012-12-12 01:15:30 +0000 | [diff] [blame] | 4460 | ModuleSpec &module_spec, |
Greg Clayton | b5f0fea | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 4461 | bool &flush, |
| 4462 | CommandReturnObject &result) |
| 4463 | { |
Greg Clayton | 89deb06 | 2012-12-12 01:15:30 +0000 | [diff] [blame] | 4464 | const FileSpec &symbol_fspec = module_spec.GetSymbolFileSpec(); |
| 4465 | if (symbol_fspec) |
Greg Clayton | b5f0fea | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 4466 | { |
| 4467 | char symfile_path[PATH_MAX]; |
Greg Clayton | 89deb06 | 2012-12-12 01:15:30 +0000 | [diff] [blame] | 4468 | symbol_fspec.GetPath (symfile_path, sizeof(symfile_path)); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4469 | |
Greg Clayton | 89deb06 | 2012-12-12 01:15:30 +0000 | [diff] [blame] | 4470 | if (!module_spec.GetUUID().IsValid()) |
| 4471 | { |
| 4472 | if (!module_spec.GetFileSpec() && !module_spec.GetPlatformFileSpec()) |
| 4473 | module_spec.GetFileSpec().GetFilename() = symbol_fspec.GetFilename(); |
| 4474 | } |
Greg Clayton | b5f0fea | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 4475 | // We now have a module that represents a symbol file |
| 4476 | // that can be used for a module that might exist in the |
| 4477 | // current target, so we need to find that module in the |
| 4478 | // target |
Greg Clayton | 89deb06 | 2012-12-12 01:15:30 +0000 | [diff] [blame] | 4479 | ModuleList matching_module_list; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4480 | |
Greg Clayton | 9aae0a1 | 2013-05-15 19:52:08 +0000 | [diff] [blame] | 4481 | size_t num_matches = 0; |
| 4482 | // First extract all module specs from the symbol file |
| 4483 | lldb_private::ModuleSpecList symfile_module_specs; |
Greg Clayton | 2540a8a | 2013-07-12 22:07:46 +0000 | [diff] [blame] | 4484 | if (ObjectFile::GetModuleSpecifications(module_spec.GetSymbolFileSpec(), 0, 0, symfile_module_specs)) |
Greg Clayton | 9aae0a1 | 2013-05-15 19:52:08 +0000 | [diff] [blame] | 4485 | { |
| 4486 | // Now extract the module spec that matches the target architecture |
| 4487 | ModuleSpec target_arch_module_spec; |
| 4488 | ModuleSpec symfile_module_spec; |
| 4489 | target_arch_module_spec.GetArchitecture() = target->GetArchitecture(); |
| 4490 | if (symfile_module_specs.FindMatchingModuleSpec(target_arch_module_spec, symfile_module_spec)) |
| 4491 | { |
| 4492 | // See if it has a UUID? |
| 4493 | if (symfile_module_spec.GetUUID().IsValid()) |
| 4494 | { |
| 4495 | // It has a UUID, look for this UUID in the target modules |
| 4496 | ModuleSpec symfile_uuid_module_spec; |
| 4497 | symfile_uuid_module_spec.GetUUID() = symfile_module_spec.GetUUID(); |
| 4498 | num_matches = target->GetImages().FindModules (symfile_uuid_module_spec, matching_module_list); |
| 4499 | } |
| 4500 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4501 | |
Greg Clayton | 9aae0a1 | 2013-05-15 19:52:08 +0000 | [diff] [blame] | 4502 | if (num_matches == 0) |
| 4503 | { |
| 4504 | // No matches yet, iterate through the module specs to find a UUID value that |
| 4505 | // we can match up to an image in our target |
| 4506 | const size_t num_symfile_module_specs = symfile_module_specs.GetSize(); |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 4507 | for (size_t i = 0; i < num_symfile_module_specs && num_matches == 0; ++i) |
Greg Clayton | 9aae0a1 | 2013-05-15 19:52:08 +0000 | [diff] [blame] | 4508 | { |
| 4509 | if (symfile_module_specs.GetModuleSpecAtIndex(i, symfile_module_spec)) |
| 4510 | { |
| 4511 | if (symfile_module_spec.GetUUID().IsValid()) |
| 4512 | { |
| 4513 | // It has a UUID, look for this UUID in the target modules |
| 4514 | ModuleSpec symfile_uuid_module_spec; |
| 4515 | symfile_uuid_module_spec.GetUUID() = symfile_module_spec.GetUUID(); |
| 4516 | num_matches = target->GetImages().FindModules (symfile_uuid_module_spec, matching_module_list); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4517 | } |
Greg Clayton | 9aae0a1 | 2013-05-15 19:52:08 +0000 | [diff] [blame] | 4518 | } |
| 4519 | } |
| 4520 | } |
| 4521 | } |
| 4522 | |
| 4523 | // Just try to match up the file by basename if we have no matches at this point |
| 4524 | if (num_matches == 0) |
| 4525 | num_matches = target->GetImages().FindModules (module_spec, matching_module_list); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4526 | |
Greg Clayton | 91c0e74 | 2013-01-11 23:44:27 +0000 | [diff] [blame] | 4527 | while (num_matches == 0) |
| 4528 | { |
| 4529 | ConstString filename_no_extension(module_spec.GetFileSpec().GetFileNameStrippingExtension()); |
| 4530 | // Empty string returned, lets bail |
| 4531 | if (!filename_no_extension) |
| 4532 | break; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4533 | |
Greg Clayton | 91c0e74 | 2013-01-11 23:44:27 +0000 | [diff] [blame] | 4534 | // Check if there was no extension to strip and the basename is the same |
| 4535 | if (filename_no_extension == module_spec.GetFileSpec().GetFilename()) |
| 4536 | break; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4537 | |
Greg Clayton | 91c0e74 | 2013-01-11 23:44:27 +0000 | [diff] [blame] | 4538 | // Replace basename with one less extension |
| 4539 | module_spec.GetFileSpec().GetFilename() = filename_no_extension; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4540 | |
Greg Clayton | 91c0e74 | 2013-01-11 23:44:27 +0000 | [diff] [blame] | 4541 | num_matches = target->GetImages().FindModules (module_spec, matching_module_list); |
| 4542 | } |
| 4543 | |
Greg Clayton | 89deb06 | 2012-12-12 01:15:30 +0000 | [diff] [blame] | 4544 | if (num_matches > 1) |
Greg Clayton | b5f0fea | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 4545 | { |
Greg Clayton | 89deb06 | 2012-12-12 01:15:30 +0000 | [diff] [blame] | 4546 | result.AppendErrorWithFormat ("multiple modules match symbol file '%s', use the --uuid option to resolve the ambiguity.\n", symfile_path); |
| 4547 | } |
| 4548 | else if (num_matches == 1) |
| 4549 | { |
| 4550 | ModuleSP module_sp (matching_module_list.GetModuleAtIndex(0)); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4551 | |
Greg Clayton | b5f0fea | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 4552 | // The module has not yet created its symbol vendor, we can just |
| 4553 | // give the existing target module the symfile path to use for |
| 4554 | // when it decides to create it! |
Greg Clayton | 89deb06 | 2012-12-12 01:15:30 +0000 | [diff] [blame] | 4555 | module_sp->SetSymbolFileFileSpec (symbol_fspec); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4556 | |
Greg Clayton | 136dff8 | 2012-12-14 02:15:00 +0000 | [diff] [blame] | 4557 | SymbolVendor *symbol_vendor = module_sp->GetSymbolVendor(true, &result.GetErrorStream()); |
Greg Clayton | 89deb06 | 2012-12-12 01:15:30 +0000 | [diff] [blame] | 4558 | if (symbol_vendor) |
| 4559 | { |
| 4560 | SymbolFile *symbol_file = symbol_vendor->GetSymbolFile(); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4561 | |
Greg Clayton | 89deb06 | 2012-12-12 01:15:30 +0000 | [diff] [blame] | 4562 | if (symbol_file) |
| 4563 | { |
| 4564 | ObjectFile *object_file = symbol_file->GetObjectFile(); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4565 | |
Greg Clayton | 89deb06 | 2012-12-12 01:15:30 +0000 | [diff] [blame] | 4566 | if (object_file && object_file->GetFileSpec() == symbol_fspec) |
| 4567 | { |
| 4568 | // Provide feedback that the symfile has been successfully added. |
| 4569 | const FileSpec &module_fs = module_sp->GetFileSpec(); |
Greg Clayton | b5ad4ec | 2013-04-29 17:25:54 +0000 | [diff] [blame] | 4570 | result.AppendMessageWithFormat("symbol file '%s' has been added to '%s'\n", |
Greg Clayton | 89deb06 | 2012-12-12 01:15:30 +0000 | [diff] [blame] | 4571 | symfile_path, |
Greg Clayton | b5ad4ec | 2013-04-29 17:25:54 +0000 | [diff] [blame] | 4572 | module_fs.GetPath().c_str()); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4573 | |
Greg Clayton | 89deb06 | 2012-12-12 01:15:30 +0000 | [diff] [blame] | 4574 | // Let clients know something changed in the module |
| 4575 | // if it is currently loaded |
| 4576 | ModuleList module_list; |
| 4577 | module_list.Append (module_sp); |
Enrico Granata | f15ee4e | 2013-04-05 18:49:06 +0000 | [diff] [blame] | 4578 | target->SymbolsDidLoad (module_list); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4579 | |
Greg Clayton | 91c0e74 | 2013-01-11 23:44:27 +0000 | [diff] [blame] | 4580 | // Make sure we load any scripting resources that may be embedded |
| 4581 | // in the debug info files in case the platform supports that. |
| 4582 | Error error; |
Enrico Granata | 9730339 | 2013-05-21 00:00:30 +0000 | [diff] [blame] | 4583 | StreamString feedback_stream; |
| 4584 | module_sp->LoadScriptingResourceInTarget (target, error,&feedback_stream); |
Enrico Granata | caa84cb | 2013-05-20 22:40:54 +0000 | [diff] [blame] | 4585 | if (error.Fail() && error.AsCString()) |
Enrico Granata | 2ea43cd | 2013-05-13 17:03:52 +0000 | [diff] [blame] | 4586 | result.AppendWarningWithFormat("unable to load scripting data for module %s - error reported was %s", |
| 4587 | module_sp->GetFileSpec().GetFileNameStrippingExtension().GetCString(), |
| 4588 | error.AsCString()); |
Enrico Granata | 9730339 | 2013-05-21 00:00:30 +0000 | [diff] [blame] | 4589 | else if (feedback_stream.GetSize()) |
| 4590 | result.AppendWarningWithFormat("%s",feedback_stream.GetData()); |
Greg Clayton | 91c0e74 | 2013-01-11 23:44:27 +0000 | [diff] [blame] | 4591 | |
Greg Clayton | 89deb06 | 2012-12-12 01:15:30 +0000 | [diff] [blame] | 4592 | flush = true; |
| 4593 | result.SetStatus (eReturnStatusSuccessFinishResult); |
| 4594 | return true; |
| 4595 | } |
| 4596 | } |
| 4597 | } |
| 4598 | // Clear the symbol file spec if anything went wrong |
| 4599 | module_sp->SetSymbolFileFileSpec (FileSpec()); |
Greg Clayton | 89deb06 | 2012-12-12 01:15:30 +0000 | [diff] [blame] | 4600 | } |
| 4601 | |
| 4602 | if (module_spec.GetUUID().IsValid()) |
| 4603 | { |
| 4604 | StreamString ss_symfile_uuid; |
| 4605 | module_spec.GetUUID().Dump(&ss_symfile_uuid); |
| 4606 | result.AppendErrorWithFormat ("symbol file '%s' (%s) does not match any existing module%s\n", |
| 4607 | symfile_path, |
| 4608 | ss_symfile_uuid.GetData(), |
| 4609 | (symbol_fspec.GetFileType() != FileSpec::eFileTypeRegular) |
| 4610 | ? "\n please specify the full path to the symbol file" |
| 4611 | : ""); |
Greg Clayton | b5f0fea | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 4612 | } |
| 4613 | else |
| 4614 | { |
Greg Clayton | 89deb06 | 2012-12-12 01:15:30 +0000 | [diff] [blame] | 4615 | result.AppendErrorWithFormat ("symbol file '%s' does not match any existing module%s\n", |
| 4616 | symfile_path, |
| 4617 | (symbol_fspec.GetFileType() != FileSpec::eFileTypeRegular) |
| 4618 | ? "\n please specify the full path to the symbol file" |
| 4619 | : ""); |
Greg Clayton | b5f0fea | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 4620 | } |
| 4621 | } |
| 4622 | else |
| 4623 | { |
| 4624 | result.AppendError ("one or more executable image paths must be specified"); |
Greg Clayton | b5f0fea | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 4625 | } |
Greg Clayton | 89deb06 | 2012-12-12 01:15:30 +0000 | [diff] [blame] | 4626 | result.SetStatus (eReturnStatusFailed); |
| 4627 | return false; |
Greg Clayton | b5f0fea | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 4628 | } |
| 4629 | |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 4630 | bool |
| 4631 | DoExecute (Args& args, CommandReturnObject &result) override |
Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 4632 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 4633 | Target *target = m_exe_ctx.GetTargetPtr(); |
Greg Clayton | b5f0fea | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 4634 | result.SetStatus (eReturnStatusFailed); |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 4635 | bool flush = false; |
| 4636 | ModuleSpec module_spec; |
| 4637 | const bool uuid_option_set = m_uuid_option_group.GetOptionValue().OptionWasSet(); |
| 4638 | const bool file_option_set = m_file_option.GetOptionValue().OptionWasSet(); |
| 4639 | const bool frame_option_set = m_current_frame_option.GetOptionValue().OptionWasSet(); |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 4640 | const size_t argc = args.GetArgumentCount(); |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 4641 | |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 4642 | if (argc == 0) |
| 4643 | { |
| 4644 | if (uuid_option_set || file_option_set || frame_option_set) |
Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 4645 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 4646 | bool success = false; |
| 4647 | bool error_set = false; |
| 4648 | if (frame_option_set) |
Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 4649 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 4650 | Process *process = m_exe_ctx.GetProcessPtr(); |
| 4651 | if (process) |
Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 4652 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 4653 | const StateType process_state = process->GetState(); |
| 4654 | if (StateIsStoppedState (process_state, true)) |
Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 4655 | { |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 4656 | StackFrame *frame = m_exe_ctx.GetFramePtr(); |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 4657 | if (frame) |
Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 4658 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 4659 | ModuleSP frame_module_sp (frame->GetSymbolContext(eSymbolContextModule).module_sp); |
| 4660 | if (frame_module_sp) |
Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 4661 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 4662 | if (frame_module_sp->GetPlatformFileSpec().Exists()) |
Greg Clayton | b5f0fea | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 4663 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 4664 | module_spec.GetArchitecture() = frame_module_sp->GetArchitecture(); |
| 4665 | module_spec.GetFileSpec() = frame_module_sp->GetPlatformFileSpec(); |
Greg Clayton | b5f0fea | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 4666 | } |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 4667 | module_spec.GetUUID() = frame_module_sp->GetUUID(); |
| 4668 | success = module_spec.GetUUID().IsValid() || module_spec.GetFileSpec(); |
Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 4669 | } |
Johnny Chen | 82e5a26 | 2012-08-22 00:18:43 +0000 | [diff] [blame] | 4670 | else |
| 4671 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 4672 | result.AppendError ("frame has no module"); |
Greg Clayton | b5f0fea | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 4673 | error_set = true; |
Johnny Chen | 82e5a26 | 2012-08-22 00:18:43 +0000 | [diff] [blame] | 4674 | } |
Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 4675 | } |
| 4676 | else |
| 4677 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 4678 | result.AppendError ("invalid current frame"); |
Greg Clayton | b5f0fea | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 4679 | error_set = true; |
Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 4680 | } |
Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 4681 | } |
| 4682 | else |
| 4683 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 4684 | result.AppendErrorWithFormat ("process is not stopped: %s", StateAsCString(process_state)); |
Greg Clayton | b5f0fea | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 4685 | error_set = true; |
| 4686 | } |
| 4687 | } |
| 4688 | else |
| 4689 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 4690 | result.AppendError ("a process must exist in order to use the --frame option"); |
| 4691 | error_set = true; |
Greg Clayton | b5f0fea | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 4692 | } |
| 4693 | } |
| 4694 | else |
| 4695 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 4696 | if (uuid_option_set) |
| 4697 | { |
| 4698 | module_spec.GetUUID() = m_uuid_option_group.GetOptionValue().GetCurrentValue(); |
| 4699 | success |= module_spec.GetUUID().IsValid(); |
| 4700 | } |
| 4701 | else if (file_option_set) |
| 4702 | { |
| 4703 | module_spec.GetFileSpec() = m_file_option.GetOptionValue().GetCurrentValue(); |
| 4704 | ModuleSP module_sp (target->GetImages().FindFirstModule(module_spec)); |
| 4705 | if (module_sp) |
| 4706 | { |
| 4707 | module_spec.GetFileSpec() = module_sp->GetFileSpec(); |
| 4708 | module_spec.GetPlatformFileSpec() = module_sp->GetPlatformFileSpec(); |
| 4709 | module_spec.GetUUID() = module_sp->GetUUID(); |
| 4710 | module_spec.GetArchitecture() = module_sp->GetArchitecture(); |
| 4711 | } |
| 4712 | else |
| 4713 | { |
| 4714 | module_spec.GetArchitecture() = target->GetArchitecture(); |
| 4715 | } |
Greg Clayton | 479d545 | 2016-02-25 00:56:47 +0000 | [diff] [blame] | 4716 | success |= module_spec.GetUUID().IsValid() || module_spec.GetFileSpec().Exists(); |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 4717 | } |
| 4718 | } |
| 4719 | |
| 4720 | if (success) |
| 4721 | { |
| 4722 | if (Symbols::DownloadObjectAndSymbolFile (module_spec)) |
| 4723 | { |
| 4724 | if (module_spec.GetSymbolFileSpec()) |
| 4725 | success = AddModuleSymbols (target, module_spec, flush, result); |
| 4726 | } |
| 4727 | } |
| 4728 | |
| 4729 | if (!success && !error_set) |
| 4730 | { |
| 4731 | StreamString error_strm; |
| 4732 | if (uuid_option_set) |
| 4733 | { |
| 4734 | error_strm.PutCString("unable to find debug symbols for UUID "); |
| 4735 | module_spec.GetUUID().Dump (&error_strm); |
| 4736 | } |
| 4737 | else if (file_option_set) |
| 4738 | { |
| 4739 | error_strm.PutCString("unable to find debug symbols for the executable file "); |
| 4740 | error_strm << module_spec.GetFileSpec(); |
| 4741 | } |
| 4742 | else if (frame_option_set) |
| 4743 | { |
| 4744 | error_strm.PutCString("unable to find debug symbols for the current frame"); |
| 4745 | } |
| 4746 | result.AppendError (error_strm.GetData()); |
Greg Clayton | b5f0fea | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 4747 | } |
| 4748 | } |
| 4749 | else |
| 4750 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 4751 | result.AppendError ("one or more symbol file paths must be specified, or options must be specified"); |
| 4752 | } |
| 4753 | } |
| 4754 | else |
| 4755 | { |
| 4756 | if (uuid_option_set) |
| 4757 | { |
| 4758 | result.AppendError ("specify either one or more paths to symbol files or use the --uuid option without arguments"); |
| 4759 | } |
| 4760 | else if (file_option_set) |
| 4761 | { |
| 4762 | result.AppendError ("specify either one or more paths to symbol files or use the --file option without arguments"); |
| 4763 | } |
| 4764 | else if (frame_option_set) |
| 4765 | { |
| 4766 | result.AppendError ("specify either one or more paths to symbol files or use the --frame option without arguments"); |
| 4767 | } |
| 4768 | else |
| 4769 | { |
| 4770 | PlatformSP platform_sp (target->GetPlatform()); |
Greg Clayton | b5f0fea | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 4771 | |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 4772 | for (size_t i = 0; i < argc; ++i) |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 4773 | { |
| 4774 | const char *symfile_path = args.GetArgumentAtIndex(i); |
| 4775 | if (symfile_path) |
Greg Clayton | b5f0fea | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 4776 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 4777 | module_spec.GetSymbolFileSpec().SetFile(symfile_path, true); |
| 4778 | if (platform_sp) |
Greg Clayton | b5f0fea | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 4779 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 4780 | FileSpec symfile_spec; |
| 4781 | if (platform_sp->ResolveSymbolFile(*target, module_spec, symfile_spec).Success()) |
| 4782 | module_spec.GetSymbolFileSpec() = symfile_spec; |
| 4783 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4784 | |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 4785 | ArchSpec arch; |
| 4786 | bool symfile_exists = module_spec.GetSymbolFileSpec().Exists(); |
Greg Clayton | b5f0fea | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 4787 | |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 4788 | if (symfile_exists) |
| 4789 | { |
| 4790 | if (!AddModuleSymbols (target, module_spec, flush, result)) |
Greg Clayton | b5f0fea | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 4791 | break; |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 4792 | } |
| 4793 | else |
| 4794 | { |
| 4795 | char resolved_symfile_path[PATH_MAX]; |
| 4796 | if (module_spec.GetSymbolFileSpec().GetPath (resolved_symfile_path, sizeof(resolved_symfile_path))) |
| 4797 | { |
| 4798 | if (strcmp (resolved_symfile_path, symfile_path) != 0) |
| 4799 | { |
| 4800 | result.AppendErrorWithFormat ("invalid module path '%s' with resolved path '%s'\n", symfile_path, resolved_symfile_path); |
| 4801 | break; |
| 4802 | } |
Greg Clayton | b5f0fea | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 4803 | } |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 4804 | result.AppendErrorWithFormat ("invalid module path '%s'\n", symfile_path); |
| 4805 | break; |
Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 4806 | } |
| 4807 | } |
| 4808 | } |
| 4809 | } |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 4810 | } |
Greg Clayton | fa559e5 | 2012-05-18 02:38:05 +0000 | [diff] [blame] | 4811 | |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 4812 | if (flush) |
| 4813 | { |
| 4814 | Process *process = m_exe_ctx.GetProcessPtr(); |
| 4815 | if (process) |
| 4816 | process->Flush(); |
Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 4817 | } |
| 4818 | return result.Succeeded(); |
| 4819 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4820 | |
Greg Clayton | b5f0fea | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 4821 | OptionGroupOptions m_option_group; |
| 4822 | OptionGroupUUID m_uuid_option_group; |
| 4823 | OptionGroupFile m_file_option; |
| 4824 | OptionGroupBoolean m_current_frame_option; |
Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 4825 | }; |
| 4826 | |
Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 4827 | #pragma mark CommandObjectTargetSymbols |
| 4828 | |
| 4829 | //------------------------------------------------------------------------- |
| 4830 | // CommandObjectTargetSymbols |
| 4831 | //------------------------------------------------------------------------- |
| 4832 | |
| 4833 | class CommandObjectTargetSymbols : public CommandObjectMultiword |
| 4834 | { |
| 4835 | public: |
| 4836 | //------------------------------------------------------------------ |
| 4837 | // Constructors and Destructors |
| 4838 | //------------------------------------------------------------------ |
Kate Stone | 7428a18 | 2016-07-14 22:03:10 +0000 | [diff] [blame] | 4839 | CommandObjectTargetSymbols(CommandInterpreter &interpreter) |
| 4840 | : CommandObjectMultiword(interpreter, "target symbols", "Commands for adding and managing debug symbol files.", |
| 4841 | "target symbols <sub-command> ...") |
Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 4842 | { |
| 4843 | LoadSubCommand ("add", CommandObjectSP (new CommandObjectTargetSymbolsAdd (interpreter))); |
Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 4844 | } |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 4845 | |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 4846 | ~CommandObjectTargetSymbols() override = default; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4847 | |
Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 4848 | private: |
| 4849 | //------------------------------------------------------------------ |
| 4850 | // For CommandObjectTargetModules only |
| 4851 | //------------------------------------------------------------------ |
| 4852 | DISALLOW_COPY_AND_ASSIGN (CommandObjectTargetSymbols); |
| 4853 | }; |
| 4854 | |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 4855 | #pragma mark CommandObjectTargetStopHookAdd |
| 4856 | |
| 4857 | //------------------------------------------------------------------------- |
| 4858 | // CommandObjectTargetStopHookAdd |
| 4859 | //------------------------------------------------------------------------- |
| 4860 | |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 4861 | class CommandObjectTargetStopHookAdd : |
| 4862 | public CommandObjectParsed, |
| 4863 | public IOHandlerDelegateMultiline |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 4864 | { |
| 4865 | public: |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 4866 | class CommandOptions : public Options |
| 4867 | { |
| 4868 | public: |
Todd Fiala | e1cfbc7 | 2016-08-11 23:51:28 +0000 | [diff] [blame] | 4869 | CommandOptions() : |
| 4870 | Options(), |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 4871 | m_line_start(0), |
| 4872 | m_line_end (UINT_MAX), |
| 4873 | m_func_name_type_mask (eFunctionNameTypeAuto), |
| 4874 | m_sym_ctx_specified (false), |
Johnny Chen | b1372c0 | 2011-05-02 23:47:55 +0000 | [diff] [blame] | 4875 | m_thread_specified (false), |
| 4876 | m_use_one_liner (false), |
| 4877 | m_one_liner() |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 4878 | { |
| 4879 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4880 | |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 4881 | ~CommandOptions() override = default; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4882 | |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 4883 | const OptionDefinition* |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 4884 | GetDefinitions () override |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 4885 | { |
| 4886 | return g_option_table; |
| 4887 | } |
| 4888 | |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 4889 | Error |
Todd Fiala | e1cfbc7 | 2016-08-11 23:51:28 +0000 | [diff] [blame] | 4890 | SetOptionValue(uint32_t option_idx, const char *option_arg, |
| 4891 | ExecutionContext *execution_context) override |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 4892 | { |
| 4893 | Error error; |
Greg Clayton | 3bcdfc0 | 2012-12-04 00:32:51 +0000 | [diff] [blame] | 4894 | const int short_option = m_getopt_table[option_idx].val; |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 4895 | bool success; |
| 4896 | |
| 4897 | switch (short_option) |
| 4898 | { |
| 4899 | case 'c': |
| 4900 | m_class_name = option_arg; |
| 4901 | m_sym_ctx_specified = true; |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 4902 | break; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4903 | |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 4904 | case 'e': |
Vince Harron | 5275aaa | 2015-01-15 20:08:35 +0000 | [diff] [blame] | 4905 | m_line_end = StringConvert::ToUInt32 (option_arg, UINT_MAX, 0, &success); |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 4906 | if (!success) |
| 4907 | { |
Greg Clayton | 86edbf4 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 4908 | error.SetErrorStringWithFormat ("invalid end line number: \"%s\"", option_arg); |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 4909 | break; |
| 4910 | } |
| 4911 | m_sym_ctx_specified = true; |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 4912 | break; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4913 | |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 4914 | case 'l': |
Vince Harron | 5275aaa | 2015-01-15 20:08:35 +0000 | [diff] [blame] | 4915 | m_line_start = StringConvert::ToUInt32 (option_arg, 0, 0, &success); |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 4916 | if (!success) |
| 4917 | { |
Greg Clayton | 86edbf4 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 4918 | error.SetErrorStringWithFormat ("invalid start line number: \"%s\"", option_arg); |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 4919 | break; |
| 4920 | } |
| 4921 | m_sym_ctx_specified = true; |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 4922 | break; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4923 | |
Sean Callanan | d4a7c12 | 2012-02-11 01:22:21 +0000 | [diff] [blame] | 4924 | case 'i': |
| 4925 | m_no_inlines = true; |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 4926 | break; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4927 | |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 4928 | case 'n': |
| 4929 | m_function_name = option_arg; |
| 4930 | m_func_name_type_mask |= eFunctionNameTypeAuto; |
| 4931 | m_sym_ctx_specified = true; |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 4932 | break; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4933 | |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 4934 | case 'f': |
| 4935 | m_file_name = option_arg; |
| 4936 | m_sym_ctx_specified = true; |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 4937 | break; |
| 4938 | |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 4939 | case 's': |
| 4940 | m_module_name = option_arg; |
| 4941 | m_sym_ctx_specified = true; |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 4942 | break; |
| 4943 | |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 4944 | case 't' : |
Vince Harron | 5275aaa | 2015-01-15 20:08:35 +0000 | [diff] [blame] | 4945 | m_thread_id = StringConvert::ToUInt64(option_arg, LLDB_INVALID_THREAD_ID, 0); |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 4946 | if (m_thread_id == LLDB_INVALID_THREAD_ID) |
Greg Clayton | 86edbf4 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 4947 | error.SetErrorStringWithFormat ("invalid thread id string '%s'", option_arg); |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 4948 | m_thread_specified = true; |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 4949 | break; |
| 4950 | |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 4951 | case 'T': |
| 4952 | m_thread_name = option_arg; |
| 4953 | m_thread_specified = true; |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 4954 | break; |
| 4955 | |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 4956 | case 'q': |
| 4957 | m_queue_name = option_arg; |
| 4958 | m_thread_specified = true; |
| 4959 | break; |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 4960 | |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 4961 | case 'x': |
Vince Harron | 5275aaa | 2015-01-15 20:08:35 +0000 | [diff] [blame] | 4962 | m_thread_index = StringConvert::ToUInt32(option_arg, UINT32_MAX, 0); |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 4963 | if (m_thread_id == UINT32_MAX) |
Greg Clayton | 86edbf4 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 4964 | error.SetErrorStringWithFormat ("invalid thread index string '%s'", option_arg); |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 4965 | m_thread_specified = true; |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 4966 | break; |
| 4967 | |
Johnny Chen | b1372c0 | 2011-05-02 23:47:55 +0000 | [diff] [blame] | 4968 | case 'o': |
| 4969 | m_use_one_liner = true; |
| 4970 | m_one_liner = option_arg; |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 4971 | break; |
| 4972 | |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 4973 | default: |
Greg Clayton | 86edbf4 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 4974 | error.SetErrorStringWithFormat ("unrecognized option %c.", short_option); |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 4975 | break; |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 4976 | } |
| 4977 | return error; |
| 4978 | } |
| 4979 | |
| 4980 | void |
Todd Fiala | e1cfbc7 | 2016-08-11 23:51:28 +0000 | [diff] [blame] | 4981 | OptionParsingStarting(ExecutionContext *execution_context) override |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 4982 | { |
| 4983 | m_class_name.clear(); |
| 4984 | m_function_name.clear(); |
| 4985 | m_line_start = 0; |
| 4986 | m_line_end = UINT_MAX; |
| 4987 | m_file_name.clear(); |
| 4988 | m_module_name.clear(); |
| 4989 | m_func_name_type_mask = eFunctionNameTypeAuto; |
| 4990 | m_thread_id = LLDB_INVALID_THREAD_ID; |
| 4991 | m_thread_index = UINT32_MAX; |
| 4992 | m_thread_name.clear(); |
| 4993 | m_queue_name.clear(); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4994 | |
Sean Callanan | d4a7c12 | 2012-02-11 01:22:21 +0000 | [diff] [blame] | 4995 | m_no_inlines = false; |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 4996 | m_sym_ctx_specified = false; |
| 4997 | m_thread_specified = false; |
Johnny Chen | b1372c0 | 2011-05-02 23:47:55 +0000 | [diff] [blame] | 4998 | |
| 4999 | m_use_one_liner = false; |
| 5000 | m_one_liner.clear(); |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5001 | } |
| 5002 | |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 5003 | static OptionDefinition g_option_table[]; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5004 | |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5005 | std::string m_class_name; |
| 5006 | std::string m_function_name; |
| 5007 | uint32_t m_line_start; |
| 5008 | uint32_t m_line_end; |
| 5009 | std::string m_file_name; |
| 5010 | std::string m_module_name; |
| 5011 | uint32_t m_func_name_type_mask; // A pick from lldb::FunctionNameType. |
| 5012 | lldb::tid_t m_thread_id; |
| 5013 | uint32_t m_thread_index; |
| 5014 | std::string m_thread_name; |
| 5015 | std::string m_queue_name; |
| 5016 | bool m_sym_ctx_specified; |
Sean Callanan | d4a7c12 | 2012-02-11 01:22:21 +0000 | [diff] [blame] | 5017 | bool m_no_inlines; |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5018 | bool m_thread_specified; |
Johnny Chen | b1372c0 | 2011-05-02 23:47:55 +0000 | [diff] [blame] | 5019 | // Instance variables to hold the values for one_liner options. |
| 5020 | bool m_use_one_liner; |
| 5021 | std::string m_one_liner; |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5022 | }; |
| 5023 | |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5024 | CommandObjectTargetStopHookAdd (CommandInterpreter &interpreter) : |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 5025 | CommandObjectParsed (interpreter, |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 5026 | "target stop-hook add", |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 5027 | "Add a hook to be executed when the target stops.", |
| 5028 | "target stop-hook add"), |
Greg Clayton | c3d874a | 2014-05-08 16:59:00 +0000 | [diff] [blame] | 5029 | IOHandlerDelegateMultiline ("DONE", IOHandlerDelegate::Completion::LLDBCommand), |
Todd Fiala | e1cfbc7 | 2016-08-11 23:51:28 +0000 | [diff] [blame] | 5030 | m_options() |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5031 | { |
| 5032 | } |
| 5033 | |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 5034 | ~CommandObjectTargetStopHookAdd() override = default; |
| 5035 | |
| 5036 | Options * |
| 5037 | GetOptions () override |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5038 | { |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 5039 | return &m_options; |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5040 | } |
| 5041 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 5042 | protected: |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 5043 | void |
| 5044 | IOHandlerActivated (IOHandler &io_handler) override |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 5045 | { |
| 5046 | StreamFileSP output_sp(io_handler.GetOutputStreamFile()); |
| 5047 | if (output_sp) |
| 5048 | { |
| 5049 | output_sp->PutCString("Enter your stop hook command(s). Type 'DONE' to end.\n"); |
| 5050 | output_sp->Flush(); |
| 5051 | } |
| 5052 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5053 | |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 5054 | void |
| 5055 | IOHandlerInputComplete (IOHandler &io_handler, std::string &line) override |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 5056 | { |
| 5057 | if (m_stop_hook_sp) |
| 5058 | { |
| 5059 | if (line.empty()) |
| 5060 | { |
| 5061 | StreamFileSP error_sp(io_handler.GetErrorStreamFile()); |
| 5062 | if (error_sp) |
| 5063 | { |
| 5064 | error_sp->Printf("error: stop hook #%" PRIu64 " aborted, no commands.\n", m_stop_hook_sp->GetID()); |
| 5065 | error_sp->Flush(); |
| 5066 | } |
| 5067 | Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); |
| 5068 | if (target) |
| 5069 | target->RemoveStopHookByID(m_stop_hook_sp->GetID()); |
| 5070 | } |
| 5071 | else |
| 5072 | { |
| 5073 | m_stop_hook_sp->GetCommandPointer()->SplitIntoLines(line); |
| 5074 | StreamFileSP output_sp(io_handler.GetOutputStreamFile()); |
| 5075 | if (output_sp) |
| 5076 | { |
| 5077 | output_sp->Printf("Stop hook #%" PRIu64 " added.\n", m_stop_hook_sp->GetID()); |
| 5078 | output_sp->Flush(); |
| 5079 | } |
| 5080 | } |
| 5081 | m_stop_hook_sp.reset(); |
| 5082 | } |
| 5083 | io_handler.SetIsDone(true); |
| 5084 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5085 | |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5086 | bool |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 5087 | DoExecute (Args& command, CommandReturnObject &result) override |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5088 | { |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 5089 | m_stop_hook_sp.reset(); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5090 | |
Jim Ingham | 893c932 | 2014-11-22 01:42:44 +0000 | [diff] [blame] | 5091 | Target *target = GetSelectedOrDummyTarget(); |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5092 | if (target) |
| 5093 | { |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 5094 | Target::StopHookSP new_hook_sp = target->CreateStopHook(); |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5095 | |
| 5096 | // First step, make the specifier. |
Greg Clayton | 7b0992d | 2013-04-18 22:45:39 +0000 | [diff] [blame] | 5097 | std::unique_ptr<SymbolContextSpecifier> specifier_ap; |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5098 | if (m_options.m_sym_ctx_specified) |
| 5099 | { |
| 5100 | specifier_ap.reset(new SymbolContextSpecifier(m_interpreter.GetDebugger().GetSelectedTarget())); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5101 | |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5102 | if (!m_options.m_module_name.empty()) |
| 5103 | { |
| 5104 | specifier_ap->AddSpecification (m_options.m_module_name.c_str(), SymbolContextSpecifier::eModuleSpecified); |
| 5105 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5106 | |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5107 | if (!m_options.m_class_name.empty()) |
| 5108 | { |
| 5109 | specifier_ap->AddSpecification (m_options.m_class_name.c_str(), SymbolContextSpecifier::eClassOrNamespaceSpecified); |
| 5110 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5111 | |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5112 | if (!m_options.m_file_name.empty()) |
| 5113 | { |
| 5114 | specifier_ap->AddSpecification (m_options.m_file_name.c_str(), SymbolContextSpecifier::eFileSpecified); |
| 5115 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5116 | |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5117 | if (m_options.m_line_start != 0) |
| 5118 | { |
| 5119 | specifier_ap->AddLineSpecification (m_options.m_line_start, SymbolContextSpecifier::eLineStartSpecified); |
| 5120 | } |
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_line_end != UINT_MAX) |
| 5123 | { |
| 5124 | specifier_ap->AddLineSpecification (m_options.m_line_end, SymbolContextSpecifier::eLineEndSpecified); |
| 5125 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5126 | |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5127 | if (!m_options.m_function_name.empty()) |
| 5128 | { |
| 5129 | specifier_ap->AddSpecification (m_options.m_function_name.c_str(), SymbolContextSpecifier::eFunctionSpecified); |
| 5130 | } |
| 5131 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5132 | |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 5133 | if (specifier_ap) |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5134 | new_hook_sp->SetSpecifier (specifier_ap.release()); |
| 5135 | |
| 5136 | // Next see if any of the thread options have been entered: |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5137 | |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5138 | if (m_options.m_thread_specified) |
| 5139 | { |
| 5140 | ThreadSpec *thread_spec = new ThreadSpec(); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5141 | |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5142 | if (m_options.m_thread_id != LLDB_INVALID_THREAD_ID) |
| 5143 | { |
| 5144 | thread_spec->SetTID (m_options.m_thread_id); |
| 5145 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5146 | |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5147 | if (m_options.m_thread_index != UINT32_MAX) |
| 5148 | thread_spec->SetIndex (m_options.m_thread_index); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5149 | |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5150 | if (!m_options.m_thread_name.empty()) |
| 5151 | thread_spec->SetName (m_options.m_thread_name.c_str()); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5152 | |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5153 | if (!m_options.m_queue_name.empty()) |
| 5154 | thread_spec->SetQueueName (m_options.m_queue_name.c_str()); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5155 | |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5156 | new_hook_sp->SetThreadSpecifier (thread_spec); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5157 | |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5158 | } |
Johnny Chen | b1372c0 | 2011-05-02 23:47:55 +0000 | [diff] [blame] | 5159 | if (m_options.m_use_one_liner) |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5160 | { |
Johnny Chen | b1372c0 | 2011-05-02 23:47:55 +0000 | [diff] [blame] | 5161 | // Use one-liner. |
| 5162 | new_hook_sp->GetCommandPointer()->AppendString (m_options.m_one_liner.c_str()); |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 5163 | result.AppendMessageWithFormat("Stop hook #%" PRIu64 " added.\n", new_hook_sp->GetID()); |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5164 | } |
Johnny Chen | b1372c0 | 2011-05-02 23:47:55 +0000 | [diff] [blame] | 5165 | else |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5166 | { |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 5167 | m_stop_hook_sp = new_hook_sp; |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 5168 | m_interpreter.GetLLDBCommandsFromIOHandler("> ", // Prompt |
| 5169 | *this, // IOHandlerDelegate |
| 5170 | true, // Run IOHandler in async mode |
| 5171 | nullptr); // Baton for the "io_handler" that will be passed back into our IOHandlerDelegate functions |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 5172 | |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5173 | } |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5174 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 5175 | } |
| 5176 | else |
| 5177 | { |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 5178 | result.AppendError ("invalid target\n"); |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5179 | result.SetStatus (eReturnStatusFailed); |
| 5180 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5181 | |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5182 | return result.Succeeded(); |
| 5183 | } |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 5184 | |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5185 | private: |
| 5186 | CommandOptions m_options; |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 5187 | Target::StopHookSP m_stop_hook_sp; |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5188 | }; |
| 5189 | |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 5190 | OptionDefinition |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5191 | CommandObjectTargetStopHookAdd::CommandOptions::g_option_table[] = |
| 5192 | { |
Kate Stone | ac9c3a6 | 2016-08-26 23:28:47 +0000 | [diff] [blame] | 5193 | // clang-format off |
| 5194 | {LLDB_OPT_SET_ALL, false, "one-liner", 'o', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeOneLiner, "Specify a one-line breakpoint command inline. Be sure to surround it with quotes."}, |
| 5195 | {LLDB_OPT_SET_ALL, false, "shlib", 's', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eModuleCompletion, eArgTypeShlibName, "Set the module within which the stop-hook is to be run."}, |
| 5196 | {LLDB_OPT_SET_ALL, false, "thread-index", 'x', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeThreadIndex, "The stop hook is run only for the thread whose index matches this argument."}, |
| 5197 | {LLDB_OPT_SET_ALL, false, "thread-id", 't', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeThreadID, "The stop hook is run only for the thread whose TID matches this argument."}, |
| 5198 | {LLDB_OPT_SET_ALL, false, "thread-name", 'T', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeThreadName, "The stop hook is run only for the thread whose thread name matches this argument."}, |
| 5199 | {LLDB_OPT_SET_ALL, false, "queue-name", 'q', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeQueueName, "The stop hook is run only for threads in the queue whose name is given by this argument."}, |
| 5200 | {LLDB_OPT_SET_1, false, "file", 'f', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSourceFileCompletion, eArgTypeFilename, "Specify the source file within which the stop-hook is to be run."}, |
| 5201 | {LLDB_OPT_SET_1, false, "start-line", 'l', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeLineNum, "Set the start of the line range for which the stop-hook is to be run."}, |
| 5202 | {LLDB_OPT_SET_1, false, "end-line", 'e', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeLineNum, "Set the end of the line range for which the stop-hook is to be run."}, |
| 5203 | {LLDB_OPT_SET_2, false, "classname", 'c', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeClassName, "Specify the class within which the stop-hook is to be run."}, |
| 5204 | {LLDB_OPT_SET_3, false, "name", 'n', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName, "Set the function name within which the stop hook will be run."}, |
| 5205 | {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr } |
| 5206 | // clang-format on |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5207 | }; |
| 5208 | |
| 5209 | #pragma mark CommandObjectTargetStopHookDelete |
| 5210 | |
| 5211 | //------------------------------------------------------------------------- |
| 5212 | // CommandObjectTargetStopHookDelete |
| 5213 | //------------------------------------------------------------------------- |
| 5214 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 5215 | class CommandObjectTargetStopHookDelete : public CommandObjectParsed |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5216 | { |
| 5217 | public: |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5218 | CommandObjectTargetStopHookDelete (CommandInterpreter &interpreter) : |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 5219 | CommandObjectParsed (interpreter, |
| 5220 | "target stop-hook delete", |
| 5221 | "Delete a stop-hook.", |
| 5222 | "target stop-hook delete [<idx>]") |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5223 | { |
| 5224 | } |
| 5225 | |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 5226 | ~CommandObjectTargetStopHookDelete() override = default; |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5227 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 5228 | protected: |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5229 | bool |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 5230 | DoExecute (Args& command, CommandReturnObject &result) override |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5231 | { |
Jim Ingham | 893c932 | 2014-11-22 01:42:44 +0000 | [diff] [blame] | 5232 | Target *target = GetSelectedOrDummyTarget(); |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5233 | if (target) |
| 5234 | { |
| 5235 | // FIXME: see if we can use the breakpoint id style parser? |
| 5236 | size_t num_args = command.GetArgumentCount(); |
| 5237 | if (num_args == 0) |
| 5238 | { |
| 5239 | if (!m_interpreter.Confirm ("Delete all stop hooks?", true)) |
| 5240 | { |
| 5241 | result.SetStatus (eReturnStatusFailed); |
| 5242 | return false; |
| 5243 | } |
| 5244 | else |
| 5245 | { |
| 5246 | target->RemoveAllStopHooks(); |
| 5247 | } |
| 5248 | } |
| 5249 | else |
| 5250 | { |
| 5251 | bool success; |
| 5252 | for (size_t i = 0; i < num_args; i++) |
| 5253 | { |
Vince Harron | 5275aaa | 2015-01-15 20:08:35 +0000 | [diff] [blame] | 5254 | 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] | 5255 | if (!success) |
| 5256 | { |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 5257 | result.AppendErrorWithFormat ("invalid stop hook id: \"%s\".\n", command.GetArgumentAtIndex(i)); |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5258 | result.SetStatus(eReturnStatusFailed); |
| 5259 | return false; |
| 5260 | } |
| 5261 | success = target->RemoveStopHookByID (user_id); |
| 5262 | if (!success) |
| 5263 | { |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 5264 | result.AppendErrorWithFormat ("unknown stop hook id: \"%s\".\n", command.GetArgumentAtIndex(i)); |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5265 | result.SetStatus(eReturnStatusFailed); |
| 5266 | return false; |
| 5267 | } |
| 5268 | } |
| 5269 | } |
| 5270 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 5271 | } |
| 5272 | else |
| 5273 | { |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 5274 | result.AppendError ("invalid target\n"); |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5275 | result.SetStatus (eReturnStatusFailed); |
| 5276 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5277 | |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5278 | return result.Succeeded(); |
| 5279 | } |
| 5280 | }; |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 5281 | |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5282 | #pragma mark CommandObjectTargetStopHookEnableDisable |
| 5283 | |
| 5284 | //------------------------------------------------------------------------- |
| 5285 | // CommandObjectTargetStopHookEnableDisable |
| 5286 | //------------------------------------------------------------------------- |
| 5287 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 5288 | class CommandObjectTargetStopHookEnableDisable : public CommandObjectParsed |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5289 | { |
| 5290 | public: |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5291 | 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] | 5292 | CommandObjectParsed (interpreter, |
| 5293 | name, |
| 5294 | help, |
| 5295 | syntax), |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5296 | m_enable (enable) |
| 5297 | { |
| 5298 | } |
| 5299 | |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 5300 | ~CommandObjectTargetStopHookEnableDisable() override = default; |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5301 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 5302 | protected: |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5303 | bool |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 5304 | DoExecute (Args& command, CommandReturnObject &result) override |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5305 | { |
Jim Ingham | 893c932 | 2014-11-22 01:42:44 +0000 | [diff] [blame] | 5306 | Target *target = GetSelectedOrDummyTarget(); |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5307 | if (target) |
| 5308 | { |
| 5309 | // FIXME: see if we can use the breakpoint id style parser? |
| 5310 | size_t num_args = command.GetArgumentCount(); |
| 5311 | bool success; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5312 | |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5313 | if (num_args == 0) |
| 5314 | { |
| 5315 | target->SetAllStopHooksActiveState (m_enable); |
| 5316 | } |
| 5317 | else |
| 5318 | { |
| 5319 | for (size_t i = 0; i < num_args; i++) |
| 5320 | { |
Vince Harron | 5275aaa | 2015-01-15 20:08:35 +0000 | [diff] [blame] | 5321 | 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] | 5322 | if (!success) |
| 5323 | { |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 5324 | result.AppendErrorWithFormat ("invalid stop hook id: \"%s\".\n", command.GetArgumentAtIndex(i)); |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5325 | result.SetStatus(eReturnStatusFailed); |
| 5326 | return false; |
| 5327 | } |
| 5328 | success = target->SetStopHookActiveStateByID (user_id, m_enable); |
| 5329 | if (!success) |
| 5330 | { |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 5331 | result.AppendErrorWithFormat ("unknown stop hook id: \"%s\".\n", command.GetArgumentAtIndex(i)); |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5332 | result.SetStatus(eReturnStatusFailed); |
| 5333 | return false; |
| 5334 | } |
| 5335 | } |
| 5336 | } |
| 5337 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 5338 | } |
| 5339 | else |
| 5340 | { |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 5341 | result.AppendError ("invalid target\n"); |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5342 | result.SetStatus (eReturnStatusFailed); |
| 5343 | } |
| 5344 | return result.Succeeded(); |
| 5345 | } |
| 5346 | private: |
| 5347 | bool m_enable; |
| 5348 | }; |
| 5349 | |
| 5350 | #pragma mark CommandObjectTargetStopHookList |
| 5351 | |
| 5352 | //------------------------------------------------------------------------- |
| 5353 | // CommandObjectTargetStopHookList |
| 5354 | //------------------------------------------------------------------------- |
| 5355 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 5356 | class CommandObjectTargetStopHookList : public CommandObjectParsed |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5357 | { |
| 5358 | public: |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5359 | CommandObjectTargetStopHookList (CommandInterpreter &interpreter) : |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 5360 | CommandObjectParsed (interpreter, |
| 5361 | "target stop-hook list", |
| 5362 | "List all stop-hooks.", |
| 5363 | "target stop-hook list [<type>]") |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5364 | { |
| 5365 | } |
| 5366 | |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 5367 | ~CommandObjectTargetStopHookList() override = default; |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5368 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 5369 | protected: |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5370 | bool |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 5371 | DoExecute (Args& command, CommandReturnObject &result) override |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5372 | { |
Jim Ingham | 893c932 | 2014-11-22 01:42:44 +0000 | [diff] [blame] | 5373 | Target *target = GetSelectedOrDummyTarget(); |
Johnny Chen | faa5c13 | 2011-11-29 23:56:14 +0000 | [diff] [blame] | 5374 | if (!target) |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5375 | { |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 5376 | result.AppendError ("invalid target\n"); |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5377 | result.SetStatus (eReturnStatusFailed); |
Jason Molenda | effcd2a | 2011-09-23 21:15:42 +0000 | [diff] [blame] | 5378 | return result.Succeeded(); |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5379 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5380 | |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5381 | size_t num_hooks = target->GetNumStopHooks (); |
| 5382 | if (num_hooks == 0) |
| 5383 | { |
| 5384 | result.GetOutputStream().PutCString ("No stop hooks.\n"); |
| 5385 | } |
| 5386 | else |
| 5387 | { |
| 5388 | for (size_t i = 0; i < num_hooks; i++) |
| 5389 | { |
| 5390 | Target::StopHookSP this_hook = target->GetStopHookAtIndex (i); |
| 5391 | if (i > 0) |
| 5392 | result.GetOutputStream().PutCString ("\n"); |
| 5393 | this_hook->GetDescription (&(result.GetOutputStream()), eDescriptionLevelFull); |
| 5394 | } |
| 5395 | } |
Johnny Chen | d0cff1e | 2011-11-30 19:09:20 +0000 | [diff] [blame] | 5396 | result.SetStatus (eReturnStatusSuccessFinishResult); |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5397 | return result.Succeeded(); |
| 5398 | } |
| 5399 | }; |
| 5400 | |
| 5401 | #pragma mark CommandObjectMultiwordTargetStopHooks |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 5402 | |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5403 | //------------------------------------------------------------------------- |
| 5404 | // CommandObjectMultiwordTargetStopHooks |
| 5405 | //------------------------------------------------------------------------- |
| 5406 | |
| 5407 | class CommandObjectMultiwordTargetStopHooks : public CommandObjectMultiword |
| 5408 | { |
| 5409 | public: |
Kate Stone | 7428a18 | 2016-07-14 22:03:10 +0000 | [diff] [blame] | 5410 | CommandObjectMultiwordTargetStopHooks(CommandInterpreter &interpreter) |
| 5411 | : CommandObjectMultiword(interpreter, "target stop-hook", |
| 5412 | "Commands for operating on debugger target stop-hooks.", |
| 5413 | "target stop-hook <subcommand> [<subcommand-options>]") |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5414 | { |
| 5415 | LoadSubCommand ("add", CommandObjectSP (new CommandObjectTargetStopHookAdd (interpreter))); |
| 5416 | LoadSubCommand ("delete", CommandObjectSP (new CommandObjectTargetStopHookDelete (interpreter))); |
| 5417 | LoadSubCommand ("disable", CommandObjectSP (new CommandObjectTargetStopHookEnableDisable (interpreter, |
| 5418 | false, |
| 5419 | "target stop-hook disable [<id>]", |
| 5420 | "Disable a stop-hook.", |
| 5421 | "target stop-hook disable"))); |
| 5422 | LoadSubCommand ("enable", CommandObjectSP (new CommandObjectTargetStopHookEnableDisable (interpreter, |
| 5423 | true, |
| 5424 | "target stop-hook enable [<id>]", |
| 5425 | "Enable a stop-hook.", |
| 5426 | "target stop-hook enable"))); |
| 5427 | LoadSubCommand ("list", CommandObjectSP (new CommandObjectTargetStopHookList (interpreter))); |
| 5428 | } |
| 5429 | |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 5430 | ~CommandObjectMultiwordTargetStopHooks() override = default; |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5431 | }; |
| 5432 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5433 | #pragma mark CommandObjectMultiwordTarget |
| 5434 | |
| 5435 | //------------------------------------------------------------------------- |
| 5436 | // CommandObjectMultiwordTarget |
| 5437 | //------------------------------------------------------------------------- |
| 5438 | |
Kate Stone | 7428a18 | 2016-07-14 22:03:10 +0000 | [diff] [blame] | 5439 | CommandObjectMultiwordTarget::CommandObjectMultiwordTarget(CommandInterpreter &interpreter) |
| 5440 | : CommandObjectMultiword(interpreter, "target", "Commands for operating on debugger targets.", |
| 5441 | "target <subcommand> [<subcommand-options>]") |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5442 | { |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 5443 | LoadSubCommand ("create", CommandObjectSP (new CommandObjectTargetCreate (interpreter))); |
Greg Clayton | 3418c85 | 2011-08-10 02:10:13 +0000 | [diff] [blame] | 5444 | LoadSubCommand ("delete", CommandObjectSP (new CommandObjectTargetDelete (interpreter))); |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 5445 | LoadSubCommand ("list", CommandObjectSP (new CommandObjectTargetList (interpreter))); |
| 5446 | LoadSubCommand ("select", CommandObjectSP (new CommandObjectTargetSelect (interpreter))); |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 5447 | LoadSubCommand ("stop-hook", CommandObjectSP (new CommandObjectMultiwordTargetStopHooks (interpreter))); |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 5448 | LoadSubCommand ("modules", CommandObjectSP (new CommandObjectTargetModules (interpreter))); |
Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 5449 | LoadSubCommand ("symbols", CommandObjectSP (new CommandObjectTargetSymbols (interpreter))); |
Greg Clayton | 644247c | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 5450 | LoadSubCommand ("variable", CommandObjectSP (new CommandObjectTargetVariable (interpreter))); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5451 | } |
| 5452 | |
Eugene Zelenko | f13e652 | 2016-02-25 19:02:39 +0000 | [diff] [blame] | 5453 | CommandObjectMultiwordTarget::~CommandObjectMultiwordTarget() = default; |