Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- CommandObjectFrame.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 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 10 | // C Includes |
| 11 | // C++ Includes |
Johnny Chen | de6bd24 | 2011-09-16 21:41:42 +0000 | [diff] [blame] | 12 | #include <string> |
Eugene Zelenko | c8ecc2a | 2016-02-19 19:33:46 +0000 | [diff] [blame] | 13 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 14 | // Other libraries and framework includes |
| 15 | // Project includes |
Eugene Zelenko | c8ecc2a | 2016-02-19 19:33:46 +0000 | [diff] [blame] | 16 | #include "CommandObjectFrame.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 17 | #include "lldb/Core/Debugger.h" |
Jim Ingham | 6d56d2c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 18 | #include "lldb/Core/Module.h" |
| 19 | #include "lldb/Core/StreamFile.h" |
Johnny Chen | de6bd24 | 2011-09-16 21:41:42 +0000 | [diff] [blame] | 20 | #include "lldb/Core/StreamString.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 21 | #include "lldb/Core/Timer.h" |
Jim Ingham | 6d56d2c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 22 | #include "lldb/Core/Value.h" |
| 23 | #include "lldb/Core/ValueObject.h" |
| 24 | #include "lldb/Core/ValueObjectVariable.h" |
Enrico Granata | 5548cb5 | 2013-01-28 23:47:25 +0000 | [diff] [blame] | 25 | #include "lldb/DataFormatters/DataVisualization.h" |
Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 26 | #include "lldb/DataFormatters/ValueObjectPrinter.h" |
Greg Clayton | 7fb56d0 | 2011-02-01 01:31:41 +0000 | [diff] [blame] | 27 | #include "lldb/Host/Host.h" |
Vince Harron | 5275aaa | 2015-01-15 20:08:35 +0000 | [diff] [blame] | 28 | #include "lldb/Host/StringConvert.h" |
Jim Ingham | 6d56d2c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 29 | #include "lldb/Interpreter/Args.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" |
Jim Ingham | 6d56d2c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 32 | #include "lldb/Interpreter/Options.h" |
Greg Clayton | 1deb796 | 2011-10-25 06:44:01 +0000 | [diff] [blame] | 33 | #include "lldb/Interpreter/OptionGroupFormat.h" |
Jim Ingham | 2837b76 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 34 | #include "lldb/Interpreter/OptionGroupValueObjectDisplay.h" |
Greg Clayton | 715c236 | 2011-07-07 04:38:25 +0000 | [diff] [blame] | 35 | #include "lldb/Interpreter/OptionGroupVariable.h" |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 36 | #include "lldb/Symbol/CompilerType.h" |
Jim Ingham | 6d56d2c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 37 | #include "lldb/Symbol/ClangASTContext.h" |
Enrico Granata | 6754e04 | 2015-09-30 23:12:22 +0000 | [diff] [blame] | 38 | #include "lldb/Symbol/Function.h" |
Jim Ingham | 6d56d2c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 39 | #include "lldb/Symbol/ObjectFile.h" |
| 40 | #include "lldb/Symbol/SymbolContext.h" |
| 41 | #include "lldb/Symbol/Type.h" |
| 42 | #include "lldb/Symbol/Variable.h" |
| 43 | #include "lldb/Symbol/VariableList.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 44 | #include "lldb/Target/Process.h" |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 45 | #include "lldb/Target/StackFrame.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 46 | #include "lldb/Target/Thread.h" |
Jim Ingham | 6d56d2c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 47 | #include "lldb/Target/Target.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 48 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 49 | using namespace lldb; |
| 50 | using namespace lldb_private; |
| 51 | |
| 52 | #pragma mark CommandObjectFrameInfo |
| 53 | |
| 54 | //------------------------------------------------------------------------- |
| 55 | // CommandObjectFrameInfo |
| 56 | //------------------------------------------------------------------------- |
| 57 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 58 | class CommandObjectFrameInfo : public CommandObjectParsed |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 59 | { |
| 60 | public: |
Kate Stone | 7428a18 | 2016-07-14 22:03:10 +0000 | [diff] [blame] | 61 | CommandObjectFrameInfo(CommandInterpreter &interpreter) |
| 62 | : CommandObjectParsed(interpreter, "frame info", |
| 63 | "List information about the current stack frame in the current thread.", "frame info", |
| 64 | eCommandRequiresFrame | eCommandTryTargetAPILock | eCommandProcessMustBeLaunched | |
| 65 | eCommandProcessMustBePaused) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 66 | { |
| 67 | } |
| 68 | |
Eugene Zelenko | c8ecc2a | 2016-02-19 19:33:46 +0000 | [diff] [blame] | 69 | ~CommandObjectFrameInfo() override = default; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 70 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 71 | protected: |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 72 | bool |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 73 | DoExecute (Args& command, CommandReturnObject &result) override |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 74 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 75 | m_exe_ctx.GetFrameRef().DumpUsingSettingsFormat (&result.GetOutputStream()); |
| 76 | result.SetStatus (eReturnStatusSuccessFinishResult); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 77 | return result.Succeeded(); |
| 78 | } |
| 79 | }; |
| 80 | |
| 81 | #pragma mark CommandObjectFrameSelect |
| 82 | |
| 83 | //------------------------------------------------------------------------- |
| 84 | // CommandObjectFrameSelect |
| 85 | //------------------------------------------------------------------------- |
| 86 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 87 | class CommandObjectFrameSelect : public CommandObjectParsed |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 88 | { |
| 89 | public: |
Eugene Zelenko | c8ecc2a | 2016-02-19 19:33:46 +0000 | [diff] [blame] | 90 | class CommandOptions : public Options |
Greg Clayton | 864174e | 2010-10-10 22:28:11 +0000 | [diff] [blame] | 91 | { |
| 92 | public: |
Todd Fiala | e1cfbc7 | 2016-08-11 23:51:28 +0000 | [diff] [blame^] | 93 | CommandOptions() : |
| 94 | Options() |
Greg Clayton | 864174e | 2010-10-10 22:28:11 +0000 | [diff] [blame] | 95 | { |
Todd Fiala | e1cfbc7 | 2016-08-11 23:51:28 +0000 | [diff] [blame^] | 96 | OptionParsingStarting(nullptr); |
Greg Clayton | 864174e | 2010-10-10 22:28:11 +0000 | [diff] [blame] | 97 | } |
| 98 | |
Eugene Zelenko | c8ecc2a | 2016-02-19 19:33:46 +0000 | [diff] [blame] | 99 | ~CommandOptions() override = default; |
Greg Clayton | 864174e | 2010-10-10 22:28:11 +0000 | [diff] [blame] | 100 | |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 101 | Error |
Todd Fiala | e1cfbc7 | 2016-08-11 23:51:28 +0000 | [diff] [blame^] | 102 | SetOptionValue(uint32_t option_idx, const char *option_arg, |
| 103 | ExecutionContext *execution_context) override |
Greg Clayton | 864174e | 2010-10-10 22:28:11 +0000 | [diff] [blame] | 104 | { |
| 105 | Error error; |
| 106 | bool success = false; |
Greg Clayton | 3bcdfc0 | 2012-12-04 00:32:51 +0000 | [diff] [blame] | 107 | const int short_option = m_getopt_table[option_idx].val; |
Greg Clayton | 864174e | 2010-10-10 22:28:11 +0000 | [diff] [blame] | 108 | switch (short_option) |
| 109 | { |
| 110 | case 'r': |
Vince Harron | 5275aaa | 2015-01-15 20:08:35 +0000 | [diff] [blame] | 111 | relative_frame_offset = StringConvert::ToSInt32 (option_arg, INT32_MIN, 0, &success); |
Greg Clayton | 864174e | 2010-10-10 22:28:11 +0000 | [diff] [blame] | 112 | if (!success) |
Greg Clayton | 86edbf4 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 113 | error.SetErrorStringWithFormat ("invalid frame offset argument '%s'", option_arg); |
Greg Clayton | 864174e | 2010-10-10 22:28:11 +0000 | [diff] [blame] | 114 | break; |
| 115 | |
| 116 | default: |
Greg Clayton | 86edbf4 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 117 | error.SetErrorStringWithFormat ("invalid short option character '%c'", short_option); |
Greg Clayton | 864174e | 2010-10-10 22:28:11 +0000 | [diff] [blame] | 118 | break; |
| 119 | } |
| 120 | |
| 121 | return error; |
| 122 | } |
| 123 | |
| 124 | void |
Todd Fiala | e1cfbc7 | 2016-08-11 23:51:28 +0000 | [diff] [blame^] | 125 | OptionParsingStarting(ExecutionContext *execution_context) override |
Greg Clayton | 864174e | 2010-10-10 22:28:11 +0000 | [diff] [blame] | 126 | { |
Greg Clayton | 864174e | 2010-10-10 22:28:11 +0000 | [diff] [blame] | 127 | relative_frame_offset = INT32_MIN; |
| 128 | } |
| 129 | |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 130 | const OptionDefinition* |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 131 | GetDefinitions () override |
Greg Clayton | 864174e | 2010-10-10 22:28:11 +0000 | [diff] [blame] | 132 | { |
| 133 | return g_option_table; |
| 134 | } |
| 135 | |
| 136 | // Options table: Required for subclasses of Options. |
| 137 | |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 138 | static OptionDefinition g_option_table[]; |
Greg Clayton | 864174e | 2010-10-10 22:28:11 +0000 | [diff] [blame] | 139 | int32_t relative_frame_offset; |
| 140 | }; |
Kate Stone | 7428a18 | 2016-07-14 22:03:10 +0000 | [diff] [blame] | 141 | |
| 142 | CommandObjectFrameSelect(CommandInterpreter &interpreter) |
| 143 | : CommandObjectParsed( |
| 144 | interpreter, "frame select", |
| 145 | "Select the current stack frame by index from within the current thread (see 'thread backtrace'.)", |
| 146 | nullptr, eCommandRequiresThread | eCommandTryTargetAPILock | eCommandProcessMustBeLaunched | |
| 147 | eCommandProcessMustBePaused), |
Todd Fiala | e1cfbc7 | 2016-08-11 23:51:28 +0000 | [diff] [blame^] | 148 | m_options() |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 149 | { |
Caroline Tice | 405fe67 | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 150 | CommandArgumentEntry arg; |
| 151 | CommandArgumentData index_arg; |
| 152 | |
| 153 | // Define the first (and only) variant of this arg. |
| 154 | index_arg.arg_type = eArgTypeFrameIndex; |
Greg Clayton | 864174e | 2010-10-10 22:28:11 +0000 | [diff] [blame] | 155 | index_arg.arg_repetition = eArgRepeatOptional; |
Caroline Tice | 405fe67 | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 156 | |
| 157 | // There is only one variant this argument could be; put it into the argument entry. |
| 158 | arg.push_back (index_arg); |
| 159 | |
| 160 | // Push the data for the first argument into the m_arguments vector. |
| 161 | m_arguments.push_back (arg); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 162 | } |
| 163 | |
Eugene Zelenko | c8ecc2a | 2016-02-19 19:33:46 +0000 | [diff] [blame] | 164 | ~CommandObjectFrameSelect() override = default; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 165 | |
Greg Clayton | 864174e | 2010-10-10 22:28:11 +0000 | [diff] [blame] | 166 | Options * |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 167 | GetOptions () override |
Greg Clayton | 864174e | 2010-10-10 22:28:11 +0000 | [diff] [blame] | 168 | { |
| 169 | return &m_options; |
| 170 | } |
| 171 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 172 | protected: |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 173 | bool |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 174 | DoExecute (Args& command, CommandReturnObject &result) override |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 175 | { |
Enrico Granata | e87764f | 2015-05-27 05:04:35 +0000 | [diff] [blame] | 176 | // No need to check "thread" for validity as eCommandRequiresThread ensures it is valid |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 177 | Thread *thread = m_exe_ctx.GetThreadPtr(); |
| 178 | |
| 179 | uint32_t frame_idx = UINT32_MAX; |
| 180 | if (m_options.relative_frame_offset != INT32_MIN) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 181 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 182 | // The one and only argument is a signed relative frame index |
| 183 | frame_idx = thread->GetSelectedFrameIndex (); |
| 184 | if (frame_idx == UINT32_MAX) |
| 185 | frame_idx = 0; |
| 186 | |
| 187 | if (m_options.relative_frame_offset < 0) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 188 | { |
Saleem Abdulrasool | 3985c8c | 2014-04-02 03:51:35 +0000 | [diff] [blame] | 189 | if (static_cast<int32_t>(frame_idx) >= -m_options.relative_frame_offset) |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 190 | frame_idx += m_options.relative_frame_offset; |
Greg Clayton | 864174e | 2010-10-10 22:28:11 +0000 | [diff] [blame] | 191 | else |
| 192 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 193 | if (frame_idx == 0) |
| 194 | { |
| 195 | //If you are already at the bottom of the stack, then just warn and don't reset the frame. |
Kate Stone | 7428a18 | 2016-07-14 22:03:10 +0000 | [diff] [blame] | 196 | result.AppendError("Already at the bottom of the stack."); |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 197 | result.SetStatus(eReturnStatusFailed); |
| 198 | return false; |
| 199 | } |
| 200 | else |
| 201 | frame_idx = 0; |
Greg Clayton | 864174e | 2010-10-10 22:28:11 +0000 | [diff] [blame] | 202 | } |
| 203 | } |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 204 | else if (m_options.relative_frame_offset > 0) |
Greg Clayton | 864174e | 2010-10-10 22:28:11 +0000 | [diff] [blame] | 205 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 206 | // I don't want "up 20" where "20" takes you past the top of the stack to produce |
| 207 | // an error, but rather to just go to the top. So I have to count the stack here... |
| 208 | const uint32_t num_frames = thread->GetStackFrameCount(); |
Saleem Abdulrasool | 3985c8c | 2014-04-02 03:51:35 +0000 | [diff] [blame] | 209 | if (static_cast<int32_t>(num_frames - frame_idx) > m_options.relative_frame_offset) |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 210 | frame_idx += m_options.relative_frame_offset; |
| 211 | else |
Greg Clayton | 864174e | 2010-10-10 22:28:11 +0000 | [diff] [blame] | 212 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 213 | if (frame_idx == num_frames - 1) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 214 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 215 | //If we are already at the top of the stack, just warn and don't reset the frame. |
Kate Stone | 7428a18 | 2016-07-14 22:03:10 +0000 | [diff] [blame] | 216 | result.AppendError("Already at the top of the stack."); |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 217 | result.SetStatus(eReturnStatusFailed); |
| 218 | return false; |
Greg Clayton | 864174e | 2010-10-10 22:28:11 +0000 | [diff] [blame] | 219 | } |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 220 | else |
| 221 | frame_idx = num_frames - 1; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 222 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 223 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 224 | } |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 225 | else |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 226 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 227 | if (command.GetArgumentCount() == 1) |
| 228 | { |
| 229 | const char *frame_idx_cstr = command.GetArgumentAtIndex(0); |
Jim Ingham | afbb0af | 2013-11-05 18:25:23 +0000 | [diff] [blame] | 230 | bool success = false; |
Vince Harron | 5275aaa | 2015-01-15 20:08:35 +0000 | [diff] [blame] | 231 | frame_idx = StringConvert::ToUInt32 (frame_idx_cstr, UINT32_MAX, 0, &success); |
Jim Ingham | afbb0af | 2013-11-05 18:25:23 +0000 | [diff] [blame] | 232 | if (!success) |
| 233 | { |
Kate Stone | 7428a18 | 2016-07-14 22:03:10 +0000 | [diff] [blame] | 234 | result.AppendErrorWithFormat("invalid frame index argument '%s'.", frame_idx_cstr); |
Jim Ingham | afbb0af | 2013-11-05 18:25:23 +0000 | [diff] [blame] | 235 | result.SetStatus (eReturnStatusFailed); |
| 236 | return false; |
| 237 | } |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 238 | } |
| 239 | else if (command.GetArgumentCount() == 0) |
| 240 | { |
| 241 | frame_idx = thread->GetSelectedFrameIndex (); |
| 242 | if (frame_idx == UINT32_MAX) |
| 243 | { |
| 244 | frame_idx = 0; |
| 245 | } |
| 246 | } |
| 247 | else |
| 248 | { |
Adrian McCarthy | c2961ab | 2015-12-22 16:50:28 +0000 | [diff] [blame] | 249 | result.AppendErrorWithFormat ("too many arguments; expected frame-index, saw '%s'.\n", |
| 250 | command.GetArgumentAtIndex(0)); |
Todd Fiala | e1cfbc7 | 2016-08-11 23:51:28 +0000 | [diff] [blame^] | 251 | m_options.GenerateOptionUsage(result.GetErrorStream(), this, |
| 252 | GetCommandInterpreter() |
| 253 | .GetDebugger() |
| 254 | .GetTerminalWidth()); |
Adrian McCarthy | c2961ab | 2015-12-22 16:50:28 +0000 | [diff] [blame] | 255 | return false; |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 256 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 257 | } |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 258 | |
Jim Ingham | 93208b8 | 2013-01-31 21:46:01 +0000 | [diff] [blame] | 259 | bool success = thread->SetSelectedFrameByIndexNoisily (frame_idx, result.GetOutputStream()); |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 260 | if (success) |
| 261 | { |
| 262 | m_exe_ctx.SetFrameSP(thread->GetSelectedFrame ()); |
Jim Ingham | 93208b8 | 2013-01-31 21:46:01 +0000 | [diff] [blame] | 263 | result.SetStatus (eReturnStatusSuccessFinishResult); |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 264 | } |
Jim Ingham | 93208b8 | 2013-01-31 21:46:01 +0000 | [diff] [blame] | 265 | else |
| 266 | { |
| 267 | result.AppendErrorWithFormat ("Frame index (%u) out of range.\n", frame_idx); |
| 268 | result.SetStatus (eReturnStatusFailed); |
| 269 | } |
| 270 | |
| 271 | return result.Succeeded(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 272 | } |
Greg Clayton | 864174e | 2010-10-10 22:28:11 +0000 | [diff] [blame] | 273 | |
Eugene Zelenko | c8ecc2a | 2016-02-19 19:33:46 +0000 | [diff] [blame] | 274 | protected: |
Greg Clayton | 864174e | 2010-10-10 22:28:11 +0000 | [diff] [blame] | 275 | CommandOptions m_options; |
| 276 | }; |
| 277 | |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 278 | OptionDefinition |
Greg Clayton | 864174e | 2010-10-10 22:28:11 +0000 | [diff] [blame] | 279 | CommandObjectFrameSelect::CommandOptions::g_option_table[] = |
| 280 | { |
Eugene Zelenko | c8ecc2a | 2016-02-19 19:33:46 +0000 | [diff] [blame] | 281 | { LLDB_OPT_SET_1, false, "relative", 'r', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeOffset, "A relative frame index offset from the current frame index."}, |
| 282 | { 0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 283 | }; |
| 284 | |
Jim Ingham | 6d56d2c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 285 | #pragma mark CommandObjectFrameVariable |
| 286 | //---------------------------------------------------------------------- |
| 287 | // List images with associated information |
| 288 | //---------------------------------------------------------------------- |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 289 | class CommandObjectFrameVariable : public CommandObjectParsed |
Jim Ingham | 6d56d2c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 290 | { |
| 291 | public: |
Kate Stone | 7428a18 | 2016-07-14 22:03:10 +0000 | [diff] [blame] | 292 | CommandObjectFrameVariable(CommandInterpreter &interpreter) |
| 293 | : CommandObjectParsed( |
| 294 | interpreter, "frame variable", "Show variables for the current stack frame. Defaults to all " |
| 295 | "arguments and local variables in scope. Names of argument, " |
| 296 | "local, file static and file global variables can be specified. " |
| 297 | "Children of aggregate variables can be specified such as " |
| 298 | "'var->child.x'.", |
| 299 | nullptr, eCommandRequiresFrame | eCommandTryTargetAPILock | eCommandProcessMustBeLaunched | |
| 300 | eCommandProcessMustBePaused | eCommandRequiresProcess), |
Todd Fiala | e1cfbc7 | 2016-08-11 23:51:28 +0000 | [diff] [blame^] | 301 | m_option_group(), |
Kate Stone | 7428a18 | 2016-07-14 22:03:10 +0000 | [diff] [blame] | 302 | m_option_variable(true), // Include the frame specific options by passing "true" |
| 303 | m_option_format(eFormatDefault), |
| 304 | m_varobj_options() |
Jim Ingham | 6d56d2c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 305 | { |
Caroline Tice | 405fe67 | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 306 | CommandArgumentEntry arg; |
| 307 | CommandArgumentData var_name_arg; |
| 308 | |
| 309 | // Define the first (and only) variant of this arg. |
| 310 | var_name_arg.arg_type = eArgTypeVarName; |
| 311 | var_name_arg.arg_repetition = eArgRepeatStar; |
| 312 | |
| 313 | // There is only one variant this argument could be; put it into the argument entry. |
| 314 | arg.push_back (var_name_arg); |
| 315 | |
| 316 | // Push the data for the first argument into the m_arguments vector. |
| 317 | m_arguments.push_back (arg); |
Jim Ingham | 2837b76 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 318 | |
Greg Clayton | 715c236 | 2011-07-07 04:38:25 +0000 | [diff] [blame] | 319 | 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] | 320 | m_option_group.Append (&m_option_format, OptionGroupFormat::OPTION_GROUP_FORMAT | OptionGroupFormat::OPTION_GROUP_GDB_FMT, LLDB_OPT_SET_1); |
Jim Ingham | 2837b76 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 321 | m_option_group.Append (&m_varobj_options, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1); |
| 322 | m_option_group.Finalize(); |
Jim Ingham | 6d56d2c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 323 | } |
| 324 | |
Eugene Zelenko | c8ecc2a | 2016-02-19 19:33:46 +0000 | [diff] [blame] | 325 | ~CommandObjectFrameVariable() override = default; |
Jim Ingham | 6d56d2c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 326 | |
Jim Ingham | 6d56d2c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 327 | Options * |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 328 | GetOptions () override |
Jim Ingham | 6d56d2c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 329 | { |
Jim Ingham | 2837b76 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 330 | return &m_option_group; |
Jim Ingham | 6d56d2c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 331 | } |
Greg Clayton | f21fead | 2013-05-14 23:43:18 +0000 | [diff] [blame] | 332 | |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 333 | int |
Greg Clayton | f21fead | 2013-05-14 23:43:18 +0000 | [diff] [blame] | 334 | HandleArgumentCompletion (Args &input, |
| 335 | int &cursor_index, |
| 336 | int &cursor_char_position, |
| 337 | OptionElementVector &opt_element_vector, |
| 338 | int match_start_point, |
| 339 | int max_return_elements, |
| 340 | bool &word_complete, |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 341 | StringList &matches) override |
Greg Clayton | f21fead | 2013-05-14 23:43:18 +0000 | [diff] [blame] | 342 | { |
| 343 | // Arguments are the standard source file completer. |
| 344 | std::string completion_str (input.GetArgumentAtIndex(cursor_index)); |
| 345 | completion_str.erase (cursor_char_position); |
Todd Fiala | e1cfbc7 | 2016-08-11 23:51:28 +0000 | [diff] [blame^] | 346 | |
| 347 | CommandCompletions::InvokeCommonCompletionCallbacks(GetCommandInterpreter(), |
Eugene Zelenko | c8ecc2a | 2016-02-19 19:33:46 +0000 | [diff] [blame] | 348 | CommandCompletions::eVariablePathCompletion, |
| 349 | completion_str.c_str(), |
| 350 | match_start_point, |
| 351 | max_return_elements, |
| 352 | nullptr, |
| 353 | word_complete, |
| 354 | matches); |
Greg Clayton | f21fead | 2013-05-14 23:43:18 +0000 | [diff] [blame] | 355 | return matches.GetSize(); |
| 356 | } |
Jim Ingham | 6d56d2c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 357 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 358 | protected: |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 359 | bool |
| 360 | DoExecute (Args& command, CommandReturnObject &result) override |
Jim Ingham | 6d56d2c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 361 | { |
Enrico Granata | e87764f | 2015-05-27 05:04:35 +0000 | [diff] [blame] | 362 | // No need to check "frame" for validity as eCommandRequiresFrame ensures it is valid |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 363 | StackFrame *frame = m_exe_ctx.GetFramePtr(); |
Johnny Chen | 1e49e5e | 2011-09-12 23:58:53 +0000 | [diff] [blame] | 364 | |
| 365 | Stream &s = result.GetOutputStream(); |
| 366 | |
Johnny Chen | 1e49e5e | 2011-09-12 23:58:53 +0000 | [diff] [blame] | 367 | // Be careful about the stack frame, if any summary formatter runs code, it might clear the StackFrameList |
| 368 | // for the thread. So hold onto a shared pointer to the frame so it stays alive. |
| 369 | |
Greg Clayton | 4e26dd3 | 2016-06-09 23:56:12 +0000 | [diff] [blame] | 370 | VariableList *variable_list = frame->GetVariableList (m_option_variable.show_globals); |
Johnny Chen | 1e49e5e | 2011-09-12 23:58:53 +0000 | [diff] [blame] | 371 | |
| 372 | VariableSP var_sp; |
| 373 | ValueObjectSP valobj_sp; |
| 374 | |
Eugene Zelenko | c8ecc2a | 2016-02-19 19:33:46 +0000 | [diff] [blame] | 375 | const char *name_cstr = nullptr; |
Johnny Chen | 1e49e5e | 2011-09-12 23:58:53 +0000 | [diff] [blame] | 376 | size_t idx; |
| 377 | |
Enrico Granata | 061858c | 2012-02-15 02:34:21 +0000 | [diff] [blame] | 378 | TypeSummaryImplSP summary_format_sp; |
Enrico Granata | 17b1174 | 2012-08-09 22:02:51 +0000 | [diff] [blame] | 379 | if (!m_option_variable.summary.IsCurrentValueEmpty()) |
| 380 | DataVisualization::NamedSummaryFormats::GetSummaryFormat(ConstString(m_option_variable.summary.GetCurrentValue()), summary_format_sp); |
| 381 | else if (!m_option_variable.summary_string.IsCurrentValueEmpty()) |
| 382 | summary_format_sp.reset(new StringSummaryFormat(TypeSummaryImpl::Flags(),m_option_variable.summary_string.GetCurrentValue())); |
Johnny Chen | 1e49e5e | 2011-09-12 23:58:53 +0000 | [diff] [blame] | 383 | |
Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 384 | DumpValueObjectOptions options(m_varobj_options.GetAsDumpOptions(eLanguageRuntimeDescriptionDisplayVerbosityFull,eFormatDefault,summary_format_sp)); |
Johnny Chen | 1e49e5e | 2011-09-12 23:58:53 +0000 | [diff] [blame] | 385 | |
Enrico Granata | 6754e04 | 2015-09-30 23:12:22 +0000 | [diff] [blame] | 386 | const SymbolContext& sym_ctx = frame->GetSymbolContext(eSymbolContextFunction); |
| 387 | if (sym_ctx.function && sym_ctx.function->IsTopLevelFunction()) |
| 388 | m_option_variable.show_globals = true; |
| 389 | |
Johnny Chen | 1e49e5e | 2011-09-12 23:58:53 +0000 | [diff] [blame] | 390 | if (variable_list) |
Jim Ingham | 6d56d2c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 391 | { |
Greg Clayton | 1deb796 | 2011-10-25 06:44:01 +0000 | [diff] [blame] | 392 | const Format format = m_option_format.GetFormat(); |
Enrico Granata | 0c489f5 | 2012-03-01 04:24:26 +0000 | [diff] [blame] | 393 | options.SetFormat(format); |
Greg Clayton | 1deb796 | 2011-10-25 06:44:01 +0000 | [diff] [blame] | 394 | |
Johnny Chen | 1e49e5e | 2011-09-12 23:58:53 +0000 | [diff] [blame] | 395 | if (command.GetArgumentCount() > 0) |
| 396 | { |
| 397 | VariableList regex_var_list; |
| 398 | |
| 399 | // If we have any args to the variable command, we will make |
| 400 | // variable objects from them... |
Eugene Zelenko | c8ecc2a | 2016-02-19 19:33:46 +0000 | [diff] [blame] | 401 | for (idx = 0; (name_cstr = command.GetArgumentAtIndex(idx)) != nullptr; ++idx) |
Johnny Chen | 1e49e5e | 2011-09-12 23:58:53 +0000 | [diff] [blame] | 402 | { |
| 403 | if (m_option_variable.use_regex) |
Jim Ingham | 6d56d2c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 404 | { |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 405 | const size_t regex_start_index = regex_var_list.GetSize(); |
Johnny Chen | 1e49e5e | 2011-09-12 23:58:53 +0000 | [diff] [blame] | 406 | RegularExpression regex (name_cstr); |
| 407 | if (regex.Compile(name_cstr)) |
Jim Ingham | 6d56d2c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 408 | { |
Johnny Chen | 1e49e5e | 2011-09-12 23:58:53 +0000 | [diff] [blame] | 409 | size_t num_matches = 0; |
| 410 | const size_t num_new_regex_vars = variable_list->AppendVariablesIfUnique(regex, |
| 411 | regex_var_list, |
| 412 | num_matches); |
| 413 | if (num_new_regex_vars > 0) |
Jim Ingham | 6d56d2c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 414 | { |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 415 | for (size_t regex_idx = regex_start_index, end_index = regex_var_list.GetSize(); |
Johnny Chen | 1e49e5e | 2011-09-12 23:58:53 +0000 | [diff] [blame] | 416 | regex_idx < end_index; |
| 417 | ++regex_idx) |
Jim Ingham | 6d56d2c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 418 | { |
Johnny Chen | 1e49e5e | 2011-09-12 23:58:53 +0000 | [diff] [blame] | 419 | var_sp = regex_var_list.GetVariableAtIndex (regex_idx); |
| 420 | if (var_sp) |
Jim Ingham | 6d56d2c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 421 | { |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 422 | valobj_sp = frame->GetValueObjectForFrameVariable (var_sp, m_varobj_options.use_dynamic); |
Johnny Chen | 1e49e5e | 2011-09-12 23:58:53 +0000 | [diff] [blame] | 423 | if (valobj_sp) |
Jim Ingham | 6d56d2c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 424 | { |
Greg Clayton | 6efba4f | 2012-01-26 21:08:30 +0000 | [diff] [blame] | 425 | // if (format != eFormatDefault) |
| 426 | // valobj_sp->SetFormat (format); |
Johnny Chen | 1e49e5e | 2011-09-12 23:58:53 +0000 | [diff] [blame] | 427 | |
| 428 | if (m_option_variable.show_decl && var_sp->GetDeclaration ().GetFile()) |
| 429 | { |
| 430 | bool show_fullpaths = false; |
| 431 | bool show_module = true; |
| 432 | if (var_sp->DumpDeclaration(&s, show_fullpaths, show_module)) |
| 433 | s.PutCString (": "); |
Greg Clayton | 4674702 | 2010-10-10 23:55:27 +0000 | [diff] [blame] | 434 | } |
Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 435 | valobj_sp->Dump(result.GetOutputStream(),options); |
Greg Clayton | 4674702 | 2010-10-10 23:55:27 +0000 | [diff] [blame] | 436 | } |
| 437 | } |
| 438 | } |
Greg Clayton | 4674702 | 2010-10-10 23:55:27 +0000 | [diff] [blame] | 439 | } |
Johnny Chen | 1e49e5e | 2011-09-12 23:58:53 +0000 | [diff] [blame] | 440 | else if (num_matches == 0) |
Greg Clayton | 4674702 | 2010-10-10 23:55:27 +0000 | [diff] [blame] | 441 | { |
Johnny Chen | 1e49e5e | 2011-09-12 23:58:53 +0000 | [diff] [blame] | 442 | result.GetErrorStream().Printf ("error: no variables matched the regular expression '%s'.\n", name_cstr); |
Greg Clayton | 4674702 | 2010-10-10 23:55:27 +0000 | [diff] [blame] | 443 | } |
| 444 | } |
Johnny Chen | 1e49e5e | 2011-09-12 23:58:53 +0000 | [diff] [blame] | 445 | else |
Greg Clayton | 4674702 | 2010-10-10 23:55:27 +0000 | [diff] [blame] | 446 | { |
Johnny Chen | 1e49e5e | 2011-09-12 23:58:53 +0000 | [diff] [blame] | 447 | char regex_error[1024]; |
| 448 | if (regex.GetErrorAsCString(regex_error, sizeof(regex_error))) |
| 449 | result.GetErrorStream().Printf ("error: %s\n", regex_error); |
Greg Clayton | 4674702 | 2010-10-10 23:55:27 +0000 | [diff] [blame] | 450 | else |
Sylvestre Ledru | f610289 | 2014-08-11 18:06:28 +0000 | [diff] [blame] | 451 | result.GetErrorStream().Printf ("error: unknown regex error when compiling '%s'\n", name_cstr); |
Johnny Chen | 1e49e5e | 2011-09-12 23:58:53 +0000 | [diff] [blame] | 452 | } |
| 453 | } |
| 454 | else // No regex, either exact variable names or variable expressions. |
| 455 | { |
| 456 | Error error; |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 457 | uint32_t expr_path_options = StackFrame::eExpressionPathOptionCheckPtrVsMember | |
Enrico Granata | 4625239 | 2015-11-19 22:28:58 +0000 | [diff] [blame] | 458 | StackFrame::eExpressionPathOptionsAllowDirectIVarAccess | |
| 459 | StackFrame::eExpressionPathOptionsInspectAnonymousUnions; |
Johnny Chen | 1e49e5e | 2011-09-12 23:58:53 +0000 | [diff] [blame] | 460 | lldb::VariableSP var_sp; |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 461 | valobj_sp = frame->GetValueForVariableExpressionPath (name_cstr, |
| 462 | m_varobj_options.use_dynamic, |
| 463 | expr_path_options, |
| 464 | var_sp, |
| 465 | error); |
Johnny Chen | 1e49e5e | 2011-09-12 23:58:53 +0000 | [diff] [blame] | 466 | if (valobj_sp) |
| 467 | { |
Greg Clayton | 6efba4f | 2012-01-26 21:08:30 +0000 | [diff] [blame] | 468 | // if (format != eFormatDefault) |
| 469 | // valobj_sp->SetFormat (format); |
Johnny Chen | 1e49e5e | 2011-09-12 23:58:53 +0000 | [diff] [blame] | 470 | if (m_option_variable.show_decl && var_sp && var_sp->GetDeclaration ().GetFile()) |
Greg Clayton | 4674702 | 2010-10-10 23:55:27 +0000 | [diff] [blame] | 471 | { |
Johnny Chen | 1e49e5e | 2011-09-12 23:58:53 +0000 | [diff] [blame] | 472 | var_sp->GetDeclaration ().DumpStopContext (&s, false); |
| 473 | s.PutCString (": "); |
Greg Clayton | 4674702 | 2010-10-10 23:55:27 +0000 | [diff] [blame] | 474 | } |
Enrico Granata | 0c489f5 | 2012-03-01 04:24:26 +0000 | [diff] [blame] | 475 | |
| 476 | options.SetFormat(format); |
Enrico Granata | 73e8c4d | 2015-10-07 02:36:35 +0000 | [diff] [blame] | 477 | options.SetVariableFormatDisplayLanguage(valobj_sp->GetPreferredDisplayLanguage()); |
Johnny Chen | 1e49e5e | 2011-09-12 23:58:53 +0000 | [diff] [blame] | 478 | |
| 479 | Stream &output_stream = result.GetOutputStream(); |
Eugene Zelenko | c8ecc2a | 2016-02-19 19:33:46 +0000 | [diff] [blame] | 480 | options.SetRootValueObjectName(valobj_sp->GetParent() ? name_cstr : nullptr); |
Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 481 | valobj_sp->Dump(output_stream,options); |
Johnny Chen | 1e49e5e | 2011-09-12 23:58:53 +0000 | [diff] [blame] | 482 | } |
| 483 | else |
| 484 | { |
Eugene Zelenko | c8ecc2a | 2016-02-19 19:33:46 +0000 | [diff] [blame] | 485 | const char *error_cstr = error.AsCString(nullptr); |
Johnny Chen | 1e49e5e | 2011-09-12 23:58:53 +0000 | [diff] [blame] | 486 | if (error_cstr) |
| 487 | result.GetErrorStream().Printf("error: %s\n", error_cstr); |
| 488 | else |
Kate Stone | 7428a18 | 2016-07-14 22:03:10 +0000 | [diff] [blame] | 489 | result.GetErrorStream().Printf( |
| 490 | "error: unable to find any variable expression path that matches '%s'.\n", |
| 491 | name_cstr); |
Greg Clayton | 9df87c1 | 2010-09-13 03:44:33 +0000 | [diff] [blame] | 492 | } |
Jim Ingham | 6d56d2c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 493 | } |
| 494 | } |
Johnny Chen | 1e49e5e | 2011-09-12 23:58:53 +0000 | [diff] [blame] | 495 | } |
| 496 | else // No command arg specified. Use variable_list, instead. |
| 497 | { |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 498 | const size_t num_variables = variable_list->GetSize(); |
Johnny Chen | 1e49e5e | 2011-09-12 23:58:53 +0000 | [diff] [blame] | 499 | if (num_variables > 0) |
Greg Clayton | 9df87c1 | 2010-09-13 03:44:33 +0000 | [diff] [blame] | 500 | { |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 501 | for (size_t i=0; i<num_variables; i++) |
Greg Clayton | 9df87c1 | 2010-09-13 03:44:33 +0000 | [diff] [blame] | 502 | { |
Johnny Chen | 1e49e5e | 2011-09-12 23:58:53 +0000 | [diff] [blame] | 503 | var_sp = variable_list->GetVariableAtIndex(i); |
| 504 | bool dump_variable = true; |
Enrico Granata | 560558e | 2015-02-11 02:35:39 +0000 | [diff] [blame] | 505 | std::string scope_string; |
Johnny Chen | 1e49e5e | 2011-09-12 23:58:53 +0000 | [diff] [blame] | 506 | switch (var_sp->GetScope()) |
Greg Clayton | 9df87c1 | 2010-09-13 03:44:33 +0000 | [diff] [blame] | 507 | { |
Greg Clayton | 9df87c1 | 2010-09-13 03:44:33 +0000 | [diff] [blame] | 508 | case eValueTypeVariableGlobal: |
Greg Clayton | 4e26dd3 | 2016-06-09 23:56:12 +0000 | [diff] [blame] | 509 | // Always dump globals since we only fetched them if |
| 510 | // m_option_variable.show_scope was true |
Greg Clayton | 715c236 | 2011-07-07 04:38:25 +0000 | [diff] [blame] | 511 | if (dump_variable && m_option_variable.show_scope) |
Enrico Granata | 560558e | 2015-02-11 02:35:39 +0000 | [diff] [blame] | 512 | scope_string = "GLOBAL: "; |
Greg Clayton | 9df87c1 | 2010-09-13 03:44:33 +0000 | [diff] [blame] | 513 | break; |
| 514 | |
| 515 | case eValueTypeVariableStatic: |
Greg Clayton | 4e26dd3 | 2016-06-09 23:56:12 +0000 | [diff] [blame] | 516 | // Always dump globals since we only fetched them if |
| 517 | // m_option_variable.show_scope was true, or this is |
| 518 | // a static variable from a block in the current scope |
Greg Clayton | 715c236 | 2011-07-07 04:38:25 +0000 | [diff] [blame] | 519 | if (dump_variable && m_option_variable.show_scope) |
Enrico Granata | 560558e | 2015-02-11 02:35:39 +0000 | [diff] [blame] | 520 | scope_string = "STATIC: "; |
Greg Clayton | 9df87c1 | 2010-09-13 03:44:33 +0000 | [diff] [blame] | 521 | break; |
Johnny Chen | 1e49e5e | 2011-09-12 23:58:53 +0000 | [diff] [blame] | 522 | |
Greg Clayton | 9df87c1 | 2010-09-13 03:44:33 +0000 | [diff] [blame] | 523 | case eValueTypeVariableArgument: |
Greg Clayton | 715c236 | 2011-07-07 04:38:25 +0000 | [diff] [blame] | 524 | dump_variable = m_option_variable.show_args; |
| 525 | if (dump_variable && m_option_variable.show_scope) |
Enrico Granata | 560558e | 2015-02-11 02:35:39 +0000 | [diff] [blame] | 526 | scope_string = " ARG: "; |
Greg Clayton | 9df87c1 | 2010-09-13 03:44:33 +0000 | [diff] [blame] | 527 | break; |
Johnny Chen | 1e49e5e | 2011-09-12 23:58:53 +0000 | [diff] [blame] | 528 | |
Greg Clayton | 9df87c1 | 2010-09-13 03:44:33 +0000 | [diff] [blame] | 529 | case eValueTypeVariableLocal: |
Greg Clayton | 715c236 | 2011-07-07 04:38:25 +0000 | [diff] [blame] | 530 | dump_variable = m_option_variable.show_locals; |
| 531 | if (dump_variable && m_option_variable.show_scope) |
Enrico Granata | 560558e | 2015-02-11 02:35:39 +0000 | [diff] [blame] | 532 | scope_string = " LOCAL: "; |
Greg Clayton | 9df87c1 | 2010-09-13 03:44:33 +0000 | [diff] [blame] | 533 | break; |
| 534 | |
Greg Clayton | 63a27af | 2016-07-01 17:17:23 +0000 | [diff] [blame] | 535 | case eValueTypeVariableThreadLocal: |
| 536 | if (dump_variable && m_option_variable.show_scope) |
| 537 | scope_string = "THREAD: "; |
| 538 | break; |
Greg Clayton | 9df87c1 | 2010-09-13 03:44:33 +0000 | [diff] [blame] | 539 | default: |
| 540 | break; |
Johnny Chen | 1e49e5e | 2011-09-12 23:58:53 +0000 | [diff] [blame] | 541 | } |
Greg Clayton | 9df87c1 | 2010-09-13 03:44:33 +0000 | [diff] [blame] | 542 | |
Johnny Chen | 1e49e5e | 2011-09-12 23:58:53 +0000 | [diff] [blame] | 543 | if (dump_variable) |
| 544 | { |
| 545 | // Use the variable object code to make sure we are |
Bruce Mitchener | 58ef391 | 2015-06-18 05:27:05 +0000 | [diff] [blame] | 546 | // using the same APIs as the public API will be |
Johnny Chen | 1e49e5e | 2011-09-12 23:58:53 +0000 | [diff] [blame] | 547 | // using... |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 548 | valobj_sp = frame->GetValueObjectForFrameVariable (var_sp, |
| 549 | m_varobj_options.use_dynamic); |
Johnny Chen | 1e49e5e | 2011-09-12 23:58:53 +0000 | [diff] [blame] | 550 | if (valobj_sp) |
| 551 | { |
Greg Clayton | 6efba4f | 2012-01-26 21:08:30 +0000 | [diff] [blame] | 552 | // if (format != eFormatDefault) |
| 553 | // valobj_sp->SetFormat (format); |
Johnny Chen | 1e49e5e | 2011-09-12 23:58:53 +0000 | [diff] [blame] | 554 | |
| 555 | // When dumping all variables, don't print any variables |
| 556 | // that are not in scope to avoid extra unneeded output |
| 557 | if (valobj_sp->IsInScope ()) |
Greg Clayton | 9df87c1 | 2010-09-13 03:44:33 +0000 | [diff] [blame] | 558 | { |
Eugene Zelenko | c8ecc2a | 2016-02-19 19:33:46 +0000 | [diff] [blame] | 559 | if (!valobj_sp->GetTargetSP()->GetDisplayRuntimeSupportValues() && |
| 560 | valobj_sp->IsRuntimeSupportValue()) |
Enrico Granata | 560558e | 2015-02-11 02:35:39 +0000 | [diff] [blame] | 561 | continue; |
| 562 | |
| 563 | if (!scope_string.empty()) |
| 564 | s.PutCString(scope_string.c_str()); |
| 565 | |
Johnny Chen | 1e49e5e | 2011-09-12 23:58:53 +0000 | [diff] [blame] | 566 | if (m_option_variable.show_decl && var_sp->GetDeclaration ().GetFile()) |
Greg Clayton | 9df87c1 | 2010-09-13 03:44:33 +0000 | [diff] [blame] | 567 | { |
Johnny Chen | 1e49e5e | 2011-09-12 23:58:53 +0000 | [diff] [blame] | 568 | var_sp->GetDeclaration ().DumpStopContext (&s, false); |
| 569 | s.PutCString (": "); |
Greg Clayton | 6f00abd | 2010-09-14 03:16:58 +0000 | [diff] [blame] | 570 | } |
Enrico Granata | 0c489f5 | 2012-03-01 04:24:26 +0000 | [diff] [blame] | 571 | |
| 572 | options.SetFormat(format); |
Enrico Granata | 73e8c4d | 2015-10-07 02:36:35 +0000 | [diff] [blame] | 573 | options.SetVariableFormatDisplayLanguage(valobj_sp->GetPreferredDisplayLanguage()); |
Enrico Granata | 0c489f5 | 2012-03-01 04:24:26 +0000 | [diff] [blame] | 574 | options.SetRootValueObjectName(name_cstr); |
Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 575 | valobj_sp->Dump(result.GetOutputStream(),options); |
Greg Clayton | 9df87c1 | 2010-09-13 03:44:33 +0000 | [diff] [blame] | 576 | } |
| 577 | } |
| 578 | } |
| 579 | } |
| 580 | } |
Jim Ingham | 6d56d2c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 581 | } |
Johnny Chen | 1e49e5e | 2011-09-12 23:58:53 +0000 | [diff] [blame] | 582 | result.SetStatus (eReturnStatusSuccessFinishResult); |
Jim Ingham | 6d56d2c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 583 | } |
Enrico Granata | 61a80ba | 2011-08-12 16:42:31 +0000 | [diff] [blame] | 584 | |
| 585 | if (m_interpreter.TruncationWarningNecessary()) |
| 586 | { |
| 587 | result.GetOutputStream().Printf(m_interpreter.TruncationWarningText(), |
| 588 | m_cmd_name.c_str()); |
| 589 | m_interpreter.TruncationWarningGiven(); |
| 590 | } |
| 591 | |
Jim Ingham | 6d56d2c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 592 | return result.Succeeded(); |
| 593 | } |
Jim Ingham | 6d56d2c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 594 | |
Eugene Zelenko | c8ecc2a | 2016-02-19 19:33:46 +0000 | [diff] [blame] | 595 | protected: |
Jim Ingham | 2837b76 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 596 | OptionGroupOptions m_option_group; |
Greg Clayton | 715c236 | 2011-07-07 04:38:25 +0000 | [diff] [blame] | 597 | OptionGroupVariable m_option_variable; |
Greg Clayton | 1deb796 | 2011-10-25 06:44:01 +0000 | [diff] [blame] | 598 | OptionGroupFormat m_option_format; |
Jim Ingham | 2837b76 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 599 | OptionGroupValueObjectDisplay m_varobj_options; |
Jim Ingham | 6d56d2c | 2010-09-02 00:18:39 +0000 | [diff] [blame] | 600 | }; |
| 601 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 602 | #pragma mark CommandObjectMultiwordFrame |
| 603 | |
| 604 | //------------------------------------------------------------------------- |
| 605 | // CommandObjectMultiwordFrame |
| 606 | //------------------------------------------------------------------------- |
| 607 | |
Kate Stone | 7428a18 | 2016-07-14 22:03:10 +0000 | [diff] [blame] | 608 | CommandObjectMultiwordFrame::CommandObjectMultiwordFrame(CommandInterpreter &interpreter) |
| 609 | : CommandObjectMultiword(interpreter, "frame", |
| 610 | "Commands for selecting and examing the current thread's stack frames.", |
| 611 | "frame <subcommand> [<subcommand-options>]") |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 612 | { |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 613 | LoadSubCommand ("info", CommandObjectSP (new CommandObjectFrameInfo (interpreter))); |
| 614 | LoadSubCommand ("select", CommandObjectSP (new CommandObjectFrameSelect (interpreter))); |
| 615 | LoadSubCommand ("variable", CommandObjectSP (new CommandObjectFrameVariable (interpreter))); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 616 | } |
| 617 | |
Eugene Zelenko | c8ecc2a | 2016-02-19 19:33:46 +0000 | [diff] [blame] | 618 | CommandObjectMultiwordFrame::~CommandObjectMultiwordFrame() = default; |