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