130fdc8d8SChris Lattner //===-- CommandObjectFrame.cpp ----------------------------------*- C++ -*-===// 230fdc8d8SChris Lattner // 330fdc8d8SChris Lattner // The LLVM Compiler Infrastructure 430fdc8d8SChris Lattner // 530fdc8d8SChris Lattner // This file is distributed under the University of Illinois Open Source 630fdc8d8SChris Lattner // License. See LICENSE.TXT for details. 730fdc8d8SChris Lattner // 830fdc8d8SChris Lattner //===----------------------------------------------------------------------===// 930fdc8d8SChris Lattner 1030fdc8d8SChris Lattner #include "CommandObjectFrame.h" 1130fdc8d8SChris Lattner 1230fdc8d8SChris Lattner // C Includes 1330fdc8d8SChris Lattner // C++ Includes 14de6bd243SJohnny Chen #include <string> 1530fdc8d8SChris Lattner // Other libraries and framework includes 1630fdc8d8SChris Lattner // Project includes 17*5d043464SJohnny Chen #include "lldb/Breakpoint/WatchpointLocation.h" 180a976141SEnrico Granata #include "lldb/Core/DataVisualization.h" 1930fdc8d8SChris Lattner #include "lldb/Core/Debugger.h" 206d56d2ceSJim Ingham #include "lldb/Core/Module.h" 216d56d2ceSJim Ingham #include "lldb/Core/StreamFile.h" 22de6bd243SJohnny Chen #include "lldb/Core/StreamString.h" 2330fdc8d8SChris Lattner #include "lldb/Core/Timer.h" 246d56d2ceSJim Ingham #include "lldb/Core/Value.h" 256d56d2ceSJim Ingham #include "lldb/Core/ValueObject.h" 266d56d2ceSJim Ingham #include "lldb/Core/ValueObjectVariable.h" 277fb56d0aSGreg Clayton #include "lldb/Host/Host.h" 286d56d2ceSJim Ingham #include "lldb/Interpreter/Args.h" 2930fdc8d8SChris Lattner #include "lldb/Interpreter/CommandInterpreter.h" 3030fdc8d8SChris Lattner #include "lldb/Interpreter/CommandReturnObject.h" 316d56d2ceSJim Ingham #include "lldb/Interpreter/Options.h" 322837b766SJim Ingham #include "lldb/Interpreter/OptionGroupValueObjectDisplay.h" 33715c2365SGreg Clayton #include "lldb/Interpreter/OptionGroupVariable.h" 34b1d7529eSJohnny Chen #include "lldb/Interpreter/OptionGroupWatchpoint.h" 356d56d2ceSJim Ingham #include "lldb/Symbol/ClangASTType.h" 366d56d2ceSJim Ingham #include "lldb/Symbol/ClangASTContext.h" 376d56d2ceSJim Ingham #include "lldb/Symbol/ObjectFile.h" 386d56d2ceSJim Ingham #include "lldb/Symbol/SymbolContext.h" 396d56d2ceSJim Ingham #include "lldb/Symbol/Type.h" 406d56d2ceSJim Ingham #include "lldb/Symbol/Variable.h" 416d56d2ceSJim Ingham #include "lldb/Symbol/VariableList.h" 4230fdc8d8SChris Lattner #include "lldb/Target/Process.h" 4330fdc8d8SChris Lattner #include "lldb/Target/StackFrame.h" 4430fdc8d8SChris Lattner #include "lldb/Target/Thread.h" 456d56d2ceSJim Ingham #include "lldb/Target/Target.h" 4630fdc8d8SChris Lattner 4730fdc8d8SChris Lattner using namespace lldb; 4830fdc8d8SChris Lattner using namespace lldb_private; 4930fdc8d8SChris Lattner 5030fdc8d8SChris Lattner #pragma mark CommandObjectFrameInfo 5130fdc8d8SChris Lattner 5230fdc8d8SChris Lattner //------------------------------------------------------------------------- 5330fdc8d8SChris Lattner // CommandObjectFrameInfo 5430fdc8d8SChris Lattner //------------------------------------------------------------------------- 5530fdc8d8SChris Lattner 5630fdc8d8SChris Lattner class CommandObjectFrameInfo : public CommandObject 5730fdc8d8SChris Lattner { 5830fdc8d8SChris Lattner public: 5930fdc8d8SChris Lattner 60a7015092SGreg Clayton CommandObjectFrameInfo (CommandInterpreter &interpreter) : 61a7015092SGreg Clayton CommandObject (interpreter, 62a7015092SGreg Clayton "frame info", 63e3d26315SCaroline Tice "List information about the currently selected frame in the current thread.", 6430fdc8d8SChris Lattner "frame info", 6530fdc8d8SChris Lattner eFlagProcessMustBeLaunched | eFlagProcessMustBePaused) 6630fdc8d8SChris Lattner { 6730fdc8d8SChris Lattner } 6830fdc8d8SChris Lattner 6930fdc8d8SChris Lattner ~CommandObjectFrameInfo () 7030fdc8d8SChris Lattner { 7130fdc8d8SChris Lattner } 7230fdc8d8SChris Lattner 7330fdc8d8SChris Lattner bool 74a7015092SGreg Clayton Execute (Args& command, 7530fdc8d8SChris Lattner CommandReturnObject &result) 7630fdc8d8SChris Lattner { 778b82f087SGreg Clayton ExecutionContext exe_ctx(m_interpreter.GetExecutionContext()); 78c14ee32dSGreg Clayton StackFrame *frame = exe_ctx.GetFramePtr(); 79c14ee32dSGreg Clayton if (frame) 8030fdc8d8SChris Lattner { 81c14ee32dSGreg Clayton frame->DumpUsingSettingsFormat (&result.GetOutputStream()); 8230fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishResult); 8330fdc8d8SChris Lattner } 8430fdc8d8SChris Lattner else 8530fdc8d8SChris Lattner { 8630fdc8d8SChris Lattner result.AppendError ("no current frame"); 8730fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 8830fdc8d8SChris Lattner } 8930fdc8d8SChris Lattner return result.Succeeded(); 9030fdc8d8SChris Lattner } 9130fdc8d8SChris Lattner }; 9230fdc8d8SChris Lattner 9330fdc8d8SChris Lattner #pragma mark CommandObjectFrameSelect 9430fdc8d8SChris Lattner 9530fdc8d8SChris Lattner //------------------------------------------------------------------------- 9630fdc8d8SChris Lattner // CommandObjectFrameSelect 9730fdc8d8SChris Lattner //------------------------------------------------------------------------- 9830fdc8d8SChris Lattner 9930fdc8d8SChris Lattner class CommandObjectFrameSelect : public CommandObject 10030fdc8d8SChris Lattner { 10130fdc8d8SChris Lattner public: 10230fdc8d8SChris Lattner 103864174e1SGreg Clayton class CommandOptions : public Options 104864174e1SGreg Clayton { 105864174e1SGreg Clayton public: 106864174e1SGreg Clayton 107eb0103f2SGreg Clayton CommandOptions (CommandInterpreter &interpreter) : 108f16066e8SJohnny Chen Options(interpreter) 109864174e1SGreg Clayton { 110f6b8b581SGreg Clayton OptionParsingStarting (); 111864174e1SGreg Clayton } 112864174e1SGreg Clayton 113864174e1SGreg Clayton virtual 114864174e1SGreg Clayton ~CommandOptions () 115864174e1SGreg Clayton { 116864174e1SGreg Clayton } 117864174e1SGreg Clayton 118864174e1SGreg Clayton virtual Error 119f6b8b581SGreg Clayton SetOptionValue (uint32_t option_idx, const char *option_arg) 120864174e1SGreg Clayton { 121864174e1SGreg Clayton Error error; 122864174e1SGreg Clayton bool success = false; 123864174e1SGreg Clayton char short_option = (char) m_getopt_table[option_idx].val; 124864174e1SGreg Clayton switch (short_option) 125864174e1SGreg Clayton { 126864174e1SGreg Clayton case 'r': 127864174e1SGreg Clayton relative_frame_offset = Args::StringToSInt32 (option_arg, INT32_MIN, 0, &success); 128864174e1SGreg Clayton if (!success) 129864174e1SGreg Clayton error.SetErrorStringWithFormat ("invalid frame offset argument '%s'.\n", option_arg); 130864174e1SGreg Clayton break; 131864174e1SGreg Clayton 132864174e1SGreg Clayton default: 1332c88643aSBenjamin Kramer error.SetErrorStringWithFormat ("Invalid short option character '%c'.\n", short_option); 134864174e1SGreg Clayton break; 135864174e1SGreg Clayton } 136864174e1SGreg Clayton 137864174e1SGreg Clayton return error; 138864174e1SGreg Clayton } 139864174e1SGreg Clayton 140864174e1SGreg Clayton void 141f6b8b581SGreg Clayton OptionParsingStarting () 142864174e1SGreg Clayton { 143864174e1SGreg Clayton relative_frame_offset = INT32_MIN; 144864174e1SGreg Clayton } 145864174e1SGreg Clayton 146e0d378b3SGreg Clayton const OptionDefinition* 147864174e1SGreg Clayton GetDefinitions () 148864174e1SGreg Clayton { 149864174e1SGreg Clayton return g_option_table; 150864174e1SGreg Clayton } 151864174e1SGreg Clayton 152864174e1SGreg Clayton // Options table: Required for subclasses of Options. 153864174e1SGreg Clayton 154e0d378b3SGreg Clayton static OptionDefinition g_option_table[]; 155864174e1SGreg Clayton int32_t relative_frame_offset; 156864174e1SGreg Clayton }; 157864174e1SGreg Clayton 158a7015092SGreg Clayton CommandObjectFrameSelect (CommandInterpreter &interpreter) : 159a7015092SGreg Clayton CommandObject (interpreter, 160a7015092SGreg Clayton "frame select", 161e3d26315SCaroline Tice "Select a frame by index from within the current thread and make it the current frame.", 162405fe67fSCaroline Tice NULL, 163eb0103f2SGreg Clayton eFlagProcessMustBeLaunched | eFlagProcessMustBePaused), 164eb0103f2SGreg Clayton m_options (interpreter) 16530fdc8d8SChris Lattner { 166405fe67fSCaroline Tice CommandArgumentEntry arg; 167405fe67fSCaroline Tice CommandArgumentData index_arg; 168405fe67fSCaroline Tice 169405fe67fSCaroline Tice // Define the first (and only) variant of this arg. 170405fe67fSCaroline Tice index_arg.arg_type = eArgTypeFrameIndex; 171864174e1SGreg Clayton index_arg.arg_repetition = eArgRepeatOptional; 172405fe67fSCaroline Tice 173405fe67fSCaroline Tice // There is only one variant this argument could be; put it into the argument entry. 174405fe67fSCaroline Tice arg.push_back (index_arg); 175405fe67fSCaroline Tice 176405fe67fSCaroline Tice // Push the data for the first argument into the m_arguments vector. 177405fe67fSCaroline Tice m_arguments.push_back (arg); 17830fdc8d8SChris Lattner } 17930fdc8d8SChris Lattner 18030fdc8d8SChris Lattner ~CommandObjectFrameSelect () 18130fdc8d8SChris Lattner { 18230fdc8d8SChris Lattner } 18330fdc8d8SChris Lattner 184864174e1SGreg Clayton virtual 185864174e1SGreg Clayton Options * 186864174e1SGreg Clayton GetOptions () 187864174e1SGreg Clayton { 188864174e1SGreg Clayton return &m_options; 189864174e1SGreg Clayton } 190864174e1SGreg Clayton 191864174e1SGreg Clayton 19230fdc8d8SChris Lattner bool 193a7015092SGreg Clayton Execute (Args& command, 19430fdc8d8SChris Lattner CommandReturnObject &result) 19530fdc8d8SChris Lattner { 1968b82f087SGreg Clayton ExecutionContext exe_ctx (m_interpreter.GetExecutionContext()); 197c14ee32dSGreg Clayton Thread *thread = exe_ctx.GetThreadPtr(); 198c14ee32dSGreg Clayton if (thread) 19930fdc8d8SChris Lattner { 200c14ee32dSGreg Clayton const uint32_t num_frames = thread->GetStackFrameCount(); 201864174e1SGreg Clayton uint32_t frame_idx = UINT32_MAX; 202864174e1SGreg Clayton if (m_options.relative_frame_offset != INT32_MIN) 203864174e1SGreg Clayton { 204864174e1SGreg Clayton // The one and only argument is a signed relative frame index 205c14ee32dSGreg Clayton frame_idx = thread->GetSelectedFrameIndex (); 206864174e1SGreg Clayton if (frame_idx == UINT32_MAX) 207864174e1SGreg Clayton frame_idx = 0; 208864174e1SGreg Clayton 209864174e1SGreg Clayton if (m_options.relative_frame_offset < 0) 210864174e1SGreg Clayton { 211864174e1SGreg Clayton if (frame_idx >= -m_options.relative_frame_offset) 212864174e1SGreg Clayton frame_idx += m_options.relative_frame_offset; 213864174e1SGreg Clayton else 214213b4546SJim Ingham { 215213b4546SJim Ingham if (frame_idx == 0) 216213b4546SJim Ingham { 217213b4546SJim Ingham //If you are already at the bottom of the stack, then just warn and don't reset the frame. 218213b4546SJim Ingham result.AppendError("Already at the bottom of the stack"); 219213b4546SJim Ingham result.SetStatus(eReturnStatusFailed); 220213b4546SJim Ingham return false; 221213b4546SJim Ingham } 222213b4546SJim Ingham else 223864174e1SGreg Clayton frame_idx = 0; 224864174e1SGreg Clayton } 225213b4546SJim Ingham } 226864174e1SGreg Clayton else if (m_options.relative_frame_offset > 0) 227864174e1SGreg Clayton { 228864174e1SGreg Clayton if (num_frames - frame_idx > m_options.relative_frame_offset) 229864174e1SGreg Clayton frame_idx += m_options.relative_frame_offset; 230864174e1SGreg Clayton else 231213b4546SJim Ingham { 232213b4546SJim Ingham if (frame_idx == num_frames - 1) 233213b4546SJim Ingham { 234213b4546SJim Ingham //If we are already at the top of the stack, just warn and don't reset the frame. 235213b4546SJim Ingham result.AppendError("Already at the top of the stack"); 236213b4546SJim Ingham result.SetStatus(eReturnStatusFailed); 237213b4546SJim Ingham return false; 238213b4546SJim Ingham } 239213b4546SJim Ingham else 240864174e1SGreg Clayton frame_idx = num_frames - 1; 241864174e1SGreg Clayton } 242864174e1SGreg Clayton } 243213b4546SJim Ingham } 244864174e1SGreg Clayton else 245864174e1SGreg Clayton { 24630fdc8d8SChris Lattner if (command.GetArgumentCount() == 1) 24730fdc8d8SChris Lattner { 24830fdc8d8SChris Lattner const char *frame_idx_cstr = command.GetArgumentAtIndex(0); 249864174e1SGreg Clayton frame_idx = Args::StringToUInt32 (frame_idx_cstr, UINT32_MAX, 0); 250864174e1SGreg Clayton } 251864174e1SGreg Clayton else 252864174e1SGreg Clayton { 253864174e1SGreg Clayton result.AppendError ("invalid arguments.\n"); 254eb0103f2SGreg Clayton m_options.GenerateOptionUsage (result.GetErrorStream(), this); 255864174e1SGreg Clayton } 256864174e1SGreg Clayton } 25730fdc8d8SChris Lattner 25830fdc8d8SChris Lattner if (frame_idx < num_frames) 25930fdc8d8SChris Lattner { 260c14ee32dSGreg Clayton thread->SetSelectedFrameByIndex (frame_idx); 261c14ee32dSGreg Clayton exe_ctx.SetFrameSP(thread->GetSelectedFrame ()); 262c14ee32dSGreg Clayton StackFrame *frame = exe_ctx.GetFramePtr(); 263c14ee32dSGreg Clayton if (frame) 26430fdc8d8SChris Lattner { 265e40e4218SJim Ingham bool already_shown = false; 266c14ee32dSGreg Clayton SymbolContext frame_sc(frame->GetSymbolContext(eSymbolContextLineEntry)); 267daccaa9eSCaroline Tice if (m_interpreter.GetDebugger().GetUseExternalEditor() && frame_sc.line_entry.file && frame_sc.line_entry.line != 0) 268e40e4218SJim Ingham { 269e40e4218SJim Ingham already_shown = Host::OpenFileInExternalEditor (frame_sc.line_entry.file, frame_sc.line_entry.line); 270e40e4218SJim Ingham } 271e40e4218SJim Ingham 2727260f620SGreg Clayton bool show_frame_info = true; 2737260f620SGreg Clayton bool show_source = !already_shown; 2747260f620SGreg Clayton uint32_t source_lines_before = 3; 2757260f620SGreg Clayton uint32_t source_lines_after = 3; 276c14ee32dSGreg Clayton if (frame->GetStatus (result.GetOutputStream(), 2777260f620SGreg Clayton show_frame_info, 2787260f620SGreg Clayton show_source, 2797260f620SGreg Clayton source_lines_before, 2807260f620SGreg Clayton source_lines_after)) 28130fdc8d8SChris Lattner { 28230fdc8d8SChris Lattner result.SetStatus (eReturnStatusSuccessFinishResult); 28330fdc8d8SChris Lattner return result.Succeeded(); 28430fdc8d8SChris Lattner } 28530fdc8d8SChris Lattner } 28630fdc8d8SChris Lattner } 28730fdc8d8SChris Lattner result.AppendErrorWithFormat ("Frame index (%u) out of range.\n", frame_idx); 28830fdc8d8SChris Lattner } 28930fdc8d8SChris Lattner else 29030fdc8d8SChris Lattner { 29130fdc8d8SChris Lattner result.AppendError ("no current thread"); 29230fdc8d8SChris Lattner } 29330fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 29430fdc8d8SChris Lattner return false; 29530fdc8d8SChris Lattner } 296864174e1SGreg Clayton protected: 297864174e1SGreg Clayton 298864174e1SGreg Clayton CommandOptions m_options; 299864174e1SGreg Clayton }; 300864174e1SGreg Clayton 301e0d378b3SGreg Clayton OptionDefinition 302864174e1SGreg Clayton CommandObjectFrameSelect::CommandOptions::g_option_table[] = 303864174e1SGreg Clayton { 304864174e1SGreg Clayton { LLDB_OPT_SET_1, false, "relative", 'r', required_argument, NULL, 0, eArgTypeOffset, "A relative frame index offset from the current frame index."}, 305864174e1SGreg Clayton { 0, false, NULL, 0, 0, NULL, NULL, eArgTypeNone, NULL } 30630fdc8d8SChris Lattner }; 30730fdc8d8SChris Lattner 3086d56d2ceSJim Ingham #pragma mark CommandObjectFrameVariable 3096d56d2ceSJim Ingham //---------------------------------------------------------------------- 3106d56d2ceSJim Ingham // List images with associated information 3116d56d2ceSJim Ingham //---------------------------------------------------------------------- 3126d56d2ceSJim Ingham class CommandObjectFrameVariable : public CommandObject 3136d56d2ceSJim Ingham { 3146d56d2ceSJim Ingham public: 3156d56d2ceSJim Ingham 316a7015092SGreg Clayton CommandObjectFrameVariable (CommandInterpreter &interpreter) : 317a7015092SGreg Clayton CommandObject (interpreter, 3186d56d2ceSJim Ingham "frame variable", 319ed8a705cSGreg Clayton "Show frame variables. All argument and local variables " 320ed8a705cSGreg Clayton "that are in scope will be shown when no arguments are given. " 321ed8a705cSGreg Clayton "If any arguments are specified, they can be names of " 322ed8a705cSGreg Clayton "argument, local, file static and file global variables. " 323ed8a705cSGreg Clayton "Children of aggregate variables can be specified such as " 324b1d7529eSJohnny Chen "'var->child.x'. " 325b1d7529eSJohnny Chen "NOTE that '-w' option is not working yet!!! " 326b1d7529eSJohnny Chen "You can choose to watch a variable with the '-w' option. " 327b1d7529eSJohnny Chen "Note that hardware resources for watching are often limited.", 328ff471a94SJim Ingham NULL, 329eb0103f2SGreg Clayton eFlagProcessMustBeLaunched | eFlagProcessMustBePaused), 3302837b766SJim Ingham m_option_group (interpreter), 331715c2365SGreg Clayton m_option_variable(true), // Include the frame specific options by passing "true" 332b1d7529eSJohnny Chen m_option_watchpoint(), 3332837b766SJim Ingham m_varobj_options() 3346d56d2ceSJim Ingham { 335405fe67fSCaroline Tice CommandArgumentEntry arg; 336405fe67fSCaroline Tice CommandArgumentData var_name_arg; 337405fe67fSCaroline Tice 338405fe67fSCaroline Tice // Define the first (and only) variant of this arg. 339405fe67fSCaroline Tice var_name_arg.arg_type = eArgTypeVarName; 340405fe67fSCaroline Tice var_name_arg.arg_repetition = eArgRepeatStar; 341405fe67fSCaroline Tice 342405fe67fSCaroline Tice // There is only one variant this argument could be; put it into the argument entry. 343405fe67fSCaroline Tice arg.push_back (var_name_arg); 344405fe67fSCaroline Tice 345405fe67fSCaroline Tice // Push the data for the first argument into the m_arguments vector. 346405fe67fSCaroline Tice m_arguments.push_back (arg); 3472837b766SJim Ingham 348715c2365SGreg Clayton m_option_group.Append (&m_option_variable, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1); 349b1d7529eSJohnny Chen m_option_group.Append (&m_option_watchpoint, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1); 3502837b766SJim Ingham m_option_group.Append (&m_varobj_options, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1); 3512837b766SJim Ingham m_option_group.Finalize(); 3526d56d2ceSJim Ingham } 3536d56d2ceSJim Ingham 3546d56d2ceSJim Ingham virtual 3556d56d2ceSJim Ingham ~CommandObjectFrameVariable () 3566d56d2ceSJim Ingham { 3576d56d2ceSJim Ingham } 3586d56d2ceSJim Ingham 3596d56d2ceSJim Ingham virtual 3606d56d2ceSJim Ingham Options * 3616d56d2ceSJim Ingham GetOptions () 3626d56d2ceSJim Ingham { 3632837b766SJim Ingham return &m_option_group; 3646d56d2ceSJim Ingham } 3656d56d2ceSJim Ingham 3666d56d2ceSJim Ingham 3676d56d2ceSJim Ingham virtual bool 3686d56d2ceSJim Ingham Execute 3696d56d2ceSJim Ingham ( 3706d56d2ceSJim Ingham Args& command, 3716d56d2ceSJim Ingham CommandReturnObject &result 3726d56d2ceSJim Ingham ) 3736d56d2ceSJim Ingham { 3748b82f087SGreg Clayton ExecutionContext exe_ctx(m_interpreter.GetExecutionContext()); 375c14ee32dSGreg Clayton StackFrame *frame = exe_ctx.GetFramePtr(); 376c14ee32dSGreg Clayton if (frame == NULL) 3776d56d2ceSJim Ingham { 378340b2baaSGreg Clayton result.AppendError ("you must be stopped in a valid stack frame to view frame variables."); 3796d56d2ceSJim Ingham result.SetStatus (eReturnStatusFailed); 3806d56d2ceSJim Ingham return false; 3816d56d2ceSJim Ingham } 3821e49e5e7SJohnny Chen 383a134cc1bSGreg Clayton Stream &s = result.GetOutputStream(); 3846d56d2ceSJim Ingham 385a134cc1bSGreg Clayton bool get_file_globals = true; 386650543f9SJim Ingham 387650543f9SJim Ingham // Be careful about the stack frame, if any summary formatter runs code, it might clear the StackFrameList 388650543f9SJim Ingham // for the thread. So hold onto a shared pointer to the frame so it stays alive. 389650543f9SJim Ingham 390c14ee32dSGreg Clayton VariableList *variable_list = frame->GetVariableList (get_file_globals); 391a134cc1bSGreg Clayton 3926d56d2ceSJim Ingham VariableSP var_sp; 3936d56d2ceSJim Ingham ValueObjectSP valobj_sp; 39478a685aaSJim Ingham 3956d56d2ceSJim Ingham const char *name_cstr = NULL; 3966d56d2ceSJim Ingham size_t idx; 3976d56d2ceSJim Ingham 398f9fa6ee5SEnrico Granata SummaryFormatSP summary_format_sp; 399f9fa6ee5SEnrico Granata if (!m_option_variable.summary.empty()) 40078d0638bSEnrico Granata DataVisualization::NamedSummaryFormats::GetSummaryFormat(ConstString(m_option_variable.summary.c_str()), summary_format_sp); 401f9fa6ee5SEnrico Granata 402379447a7SEnrico Granata ValueObject::DumpValueObjectOptions options; 403379447a7SEnrico Granata 404379447a7SEnrico Granata options.SetPointerDepth(m_varobj_options.ptr_depth) 405379447a7SEnrico Granata .SetMaximumDepth(m_varobj_options.max_depth) 406379447a7SEnrico Granata .SetShowTypes(m_varobj_options.show_types) 407379447a7SEnrico Granata .SetShowLocation(m_varobj_options.show_location) 408379447a7SEnrico Granata .SetUseObjectiveC(m_varobj_options.use_objc) 409379447a7SEnrico Granata .SetUseDynamicType(m_varobj_options.use_dynamic) 410379447a7SEnrico Granata .SetUseSyntheticValue((lldb::SyntheticValueType)m_varobj_options.use_synth) 411379447a7SEnrico Granata .SetFlatOutput(m_varobj_options.flat_output) 412379447a7SEnrico Granata .SetOmitSummaryDepth(m_varobj_options.no_summary_depth) 413379447a7SEnrico Granata .SetIgnoreCap(m_varobj_options.ignore_cap); 414379447a7SEnrico Granata 415379447a7SEnrico Granata if (m_varobj_options.be_raw) 416379447a7SEnrico Granata options.SetRawDisplay(true); 417379447a7SEnrico Granata 418715c2365SGreg Clayton if (variable_list) 4199df87c17SGreg Clayton { 4203a9838c0SJohnny Chen // If watching a variable, there are certain restrictions to be followed. 4213a9838c0SJohnny Chen if (m_option_watchpoint.watch_variable) 4223a9838c0SJohnny Chen { 4233a9838c0SJohnny Chen if (command.GetArgumentCount() != 1) { 4243a9838c0SJohnny Chen result.GetErrorStream().Printf("error: specify exactly one variable when using the '-w' option\n"); 4253a9838c0SJohnny Chen result.SetStatus(eReturnStatusFailed); 4263a9838c0SJohnny Chen return false; 4273a9838c0SJohnny Chen } else if (m_option_variable.use_regex) { 4283a9838c0SJohnny Chen result.GetErrorStream().Printf("error: specify your variable name exactly (no regex) when using the '-w' option\n"); 4293a9838c0SJohnny Chen result.SetStatus(eReturnStatusFailed); 4303a9838c0SJohnny Chen return false; 4313a9838c0SJohnny Chen } 4323a9838c0SJohnny Chen 4333a9838c0SJohnny Chen // Things have checked out ok... 4343a9838c0SJohnny Chen // m_option_watchpoint.watch_mode specifies the mode for watching. 4353a9838c0SJohnny Chen } 4369df87c17SGreg Clayton if (command.GetArgumentCount() > 0) 4376d56d2ceSJim Ingham { 43846747022SGreg Clayton VariableList regex_var_list; 43946747022SGreg Clayton 4406d56d2ceSJim Ingham // If we have any args to the variable command, we will make 4416d56d2ceSJim Ingham // variable objects from them... 4426d56d2ceSJim Ingham for (idx = 0; (name_cstr = command.GetArgumentAtIndex(idx)) != NULL; ++idx) 4436d56d2ceSJim Ingham { 444715c2365SGreg Clayton if (m_option_variable.use_regex) 44546747022SGreg Clayton { 44646747022SGreg Clayton const uint32_t regex_start_index = regex_var_list.GetSize(); 44746747022SGreg Clayton RegularExpression regex (name_cstr); 44846747022SGreg Clayton if (regex.Compile(name_cstr)) 44946747022SGreg Clayton { 45046747022SGreg Clayton size_t num_matches = 0; 45178a685aaSJim Ingham const size_t num_new_regex_vars = variable_list->AppendVariablesIfUnique(regex, 45278a685aaSJim Ingham regex_var_list, 45378a685aaSJim Ingham num_matches); 45446747022SGreg Clayton if (num_new_regex_vars > 0) 45546747022SGreg Clayton { 45646747022SGreg Clayton for (uint32_t regex_idx = regex_start_index, end_index = regex_var_list.GetSize(); 45746747022SGreg Clayton regex_idx < end_index; 45846747022SGreg Clayton ++regex_idx) 45946747022SGreg Clayton { 46046747022SGreg Clayton var_sp = regex_var_list.GetVariableAtIndex (regex_idx); 46146747022SGreg Clayton if (var_sp) 46246747022SGreg Clayton { 463c14ee32dSGreg Clayton valobj_sp = frame->GetValueObjectForFrameVariable (var_sp, m_varobj_options.use_dynamic); 46446747022SGreg Clayton if (valobj_sp) 46546747022SGreg Clayton { 466715c2365SGreg Clayton if (m_option_variable.format != eFormatDefault) 467715c2365SGreg Clayton valobj_sp->SetFormat (m_option_variable.format); 468ded470d3SGreg Clayton 469715c2365SGreg Clayton if (m_option_variable.show_decl && var_sp->GetDeclaration ().GetFile()) 47046747022SGreg Clayton { 47145ba8543SGreg Clayton bool show_fullpaths = false; 47245ba8543SGreg Clayton bool show_module = true; 47345ba8543SGreg Clayton if (var_sp->DumpDeclaration(&s, show_fullpaths, show_module)) 47446747022SGreg Clayton s.PutCString (": "); 47546747022SGreg Clayton } 476f9fa6ee5SEnrico Granata if (summary_format_sp) 477f9fa6ee5SEnrico Granata valobj_sp->SetCustomSummaryFormat(summary_format_sp); 47846747022SGreg Clayton ValueObject::DumpValueObject (result.GetOutputStream(), 47946747022SGreg Clayton valobj_sp.get(), 480379447a7SEnrico Granata options); 48146747022SGreg Clayton } 48246747022SGreg Clayton } 48346747022SGreg Clayton } 48446747022SGreg Clayton } 48546747022SGreg Clayton else if (num_matches == 0) 48646747022SGreg Clayton { 48746747022SGreg Clayton result.GetErrorStream().Printf ("error: no variables matched the regular expression '%s'.\n", name_cstr); 48846747022SGreg Clayton } 48946747022SGreg Clayton } 49046747022SGreg Clayton else 49146747022SGreg Clayton { 49246747022SGreg Clayton char regex_error[1024]; 49346747022SGreg Clayton if (regex.GetErrorAsCString(regex_error, sizeof(regex_error))) 49446747022SGreg Clayton result.GetErrorStream().Printf ("error: %s\n", regex_error); 49546747022SGreg Clayton else 49646747022SGreg Clayton result.GetErrorStream().Printf ("error: unkown regex error when compiling '%s'\n", name_cstr); 49746747022SGreg Clayton } 49846747022SGreg Clayton } 499887062aeSJohnny Chen else // No regex, either exact variable names or variable expressions. 50046747022SGreg Clayton { 50154979cddSGreg Clayton Error error; 50278a685aaSJim Ingham uint32_t expr_path_options = StackFrame::eExpressionPathOptionCheckPtrVsMember; 5032837b766SJim Ingham lldb::VariableSP var_sp; 504c14ee32dSGreg Clayton valobj_sp = frame->GetValueForVariableExpressionPath (name_cstr, 5052837b766SJim Ingham m_varobj_options.use_dynamic, 5062837b766SJim Ingham expr_path_options, 5072837b766SJim Ingham var_sp, 5082837b766SJim Ingham error); 5096d56d2ceSJim Ingham if (valobj_sp) 5106d56d2ceSJim Ingham { 511715c2365SGreg Clayton if (m_option_variable.format != eFormatDefault) 512715c2365SGreg Clayton valobj_sp->SetFormat (m_option_variable.format); 513715c2365SGreg Clayton if (m_option_variable.show_decl && var_sp && var_sp->GetDeclaration ().GetFile()) 514a134cc1bSGreg Clayton { 515a134cc1bSGreg Clayton var_sp->GetDeclaration ().DumpStopContext (&s, false); 516a134cc1bSGreg Clayton s.PutCString (": "); 517a134cc1bSGreg Clayton } 518f9fa6ee5SEnrico Granata if (summary_format_sp) 519f9fa6ee5SEnrico Granata valobj_sp->SetCustomSummaryFormat(summary_format_sp); 520887062aeSJohnny Chen 521887062aeSJohnny Chen Stream &output_stream = result.GetOutputStream(); 522887062aeSJohnny Chen ValueObject::DumpValueObject (output_stream, 523a134cc1bSGreg Clayton valobj_sp.get(), 52483c5cd9dSGreg Clayton valobj_sp->GetParent() ? name_cstr : NULL, 525379447a7SEnrico Granata options); 526887062aeSJohnny Chen // Process watchpoint if necessary. 527887062aeSJohnny Chen if (m_option_watchpoint.watch_variable) 528887062aeSJohnny Chen { 5292fd89a09SJohnny Chen AddressType addr_type; 5302fd89a09SJohnny Chen lldb::addr_t addr = valobj_sp->GetAddressOf(false, &addr_type); 531887062aeSJohnny Chen size_t size = 0; 5322fd89a09SJohnny Chen if (addr_type == eAddressTypeLoad) { 5332fd89a09SJohnny Chen // We're in business. 5342fd89a09SJohnny Chen // Find out the size of this variable. 5352fd89a09SJohnny Chen size = valobj_sp->GetByteSize(); 5362fd89a09SJohnny Chen } 537887062aeSJohnny Chen uint32_t watch_type = m_option_watchpoint.watch_type; 538c14ee32dSGreg Clayton WatchpointLocation *wp_loc = exe_ctx.GetTargetRef().CreateWatchpointLocation(addr, size, watch_type).get(); 539887062aeSJohnny Chen if (wp_loc) 540887062aeSJohnny Chen { 541de6bd243SJohnny Chen if (var_sp && var_sp->GetDeclaration().GetFile()) 542de6bd243SJohnny Chen { 543de6bd243SJohnny Chen StreamString ss; 54418d7b950SJohnny Chen // True to show fullpath for declaration file. 545de6bd243SJohnny Chen var_sp->GetDeclaration().DumpStopContext(&ss, true); 546de6bd243SJohnny Chen wp_loc->SetDeclInfo(ss.GetString()); 547de6bd243SJohnny Chen } 548de6bd243SJohnny Chen StreamString ss; 549887062aeSJohnny Chen output_stream.Printf("Watchpoint created: "); 550de6bd243SJohnny Chen wp_loc->GetDescription(&output_stream, lldb::eDescriptionLevelFull); 551887062aeSJohnny Chen output_stream.EOL(); 552887062aeSJohnny Chen result.SetStatus(eReturnStatusSuccessFinishResult); 553887062aeSJohnny Chen } 554887062aeSJohnny Chen else 555887062aeSJohnny Chen { 556887062aeSJohnny Chen result.AppendErrorWithFormat("Watchpoint creation failed.\n"); 557887062aeSJohnny Chen result.SetStatus(eReturnStatusFailed); 558887062aeSJohnny Chen } 559887062aeSJohnny Chen return (wp_loc != NULL); 560887062aeSJohnny Chen } 5616d56d2ceSJim Ingham } 5626d56d2ceSJim Ingham else 5636d56d2ceSJim Ingham { 56454979cddSGreg Clayton const char *error_cstr = error.AsCString(NULL); 56554979cddSGreg Clayton if (error_cstr) 56654979cddSGreg Clayton result.GetErrorStream().Printf("error: %s\n", error_cstr); 56754979cddSGreg Clayton else 56854979cddSGreg Clayton result.GetErrorStream().Printf ("error: unable to find any variable expression path that matches '%s'\n", name_cstr); 5696d56d2ceSJim Ingham } 5706d56d2ceSJim Ingham } 5716d56d2ceSJim Ingham } 57246747022SGreg Clayton } 573926d086eSJohnny Chen else // No command arg specified. Use variable_list, instead. 5746d56d2ceSJim Ingham { 575a134cc1bSGreg Clayton const uint32_t num_variables = variable_list->GetSize(); 5766d56d2ceSJim Ingham if (num_variables > 0) 5776d56d2ceSJim Ingham { 5786d56d2ceSJim Ingham for (uint32_t i=0; i<num_variables; i++) 5796d56d2ceSJim Ingham { 5801a65ae11SGreg Clayton var_sp = variable_list->GetVariableAtIndex(i); 5816d56d2ceSJim Ingham bool dump_variable = true; 582a134cc1bSGreg Clayton switch (var_sp->GetScope()) 5836d56d2ceSJim Ingham { 5846d56d2ceSJim Ingham case eValueTypeVariableGlobal: 585715c2365SGreg Clayton dump_variable = m_option_variable.show_globals; 586715c2365SGreg Clayton if (dump_variable && m_option_variable.show_scope) 587a134cc1bSGreg Clayton s.PutCString("GLOBAL: "); 5886d56d2ceSJim Ingham break; 5896d56d2ceSJim Ingham 5906d56d2ceSJim Ingham case eValueTypeVariableStatic: 591715c2365SGreg Clayton dump_variable = m_option_variable.show_globals; 592715c2365SGreg Clayton if (dump_variable && m_option_variable.show_scope) 593a134cc1bSGreg Clayton s.PutCString("STATIC: "); 5946d56d2ceSJim Ingham break; 5956d56d2ceSJim Ingham 5966d56d2ceSJim Ingham case eValueTypeVariableArgument: 597715c2365SGreg Clayton dump_variable = m_option_variable.show_args; 598715c2365SGreg Clayton if (dump_variable && m_option_variable.show_scope) 599a134cc1bSGreg Clayton s.PutCString(" ARG: "); 6006d56d2ceSJim Ingham break; 6016d56d2ceSJim Ingham 6026d56d2ceSJim Ingham case eValueTypeVariableLocal: 603715c2365SGreg Clayton dump_variable = m_option_variable.show_locals; 604715c2365SGreg Clayton if (dump_variable && m_option_variable.show_scope) 605a134cc1bSGreg Clayton s.PutCString(" LOCAL: "); 6066d56d2ceSJim Ingham break; 6076d56d2ceSJim Ingham 6086d56d2ceSJim Ingham default: 6096d56d2ceSJim Ingham break; 6106d56d2ceSJim Ingham } 6116d56d2ceSJim Ingham 6126d56d2ceSJim Ingham if (dump_variable) 613a134cc1bSGreg Clayton { 614a134cc1bSGreg Clayton // Use the variable object code to make sure we are 615a134cc1bSGreg Clayton // using the same APIs as the the public API will be 616a134cc1bSGreg Clayton // using... 617c14ee32dSGreg Clayton valobj_sp = frame->GetValueObjectForFrameVariable (var_sp, 6182837b766SJim Ingham m_varobj_options.use_dynamic); 619a134cc1bSGreg Clayton if (valobj_sp) 620a134cc1bSGreg Clayton { 621715c2365SGreg Clayton if (m_option_variable.format != eFormatDefault) 622715c2365SGreg Clayton valobj_sp->SetFormat (m_option_variable.format); 623ded470d3SGreg Clayton 6246f00abd5SGreg Clayton // When dumping all variables, don't print any variables 6256f00abd5SGreg Clayton // that are not in scope to avoid extra unneeded output 6266035b67dSJim Ingham if (valobj_sp->IsInScope ()) 6276f00abd5SGreg Clayton { 628715c2365SGreg Clayton if (m_option_variable.show_decl && var_sp->GetDeclaration ().GetFile()) 629a134cc1bSGreg Clayton { 630a134cc1bSGreg Clayton var_sp->GetDeclaration ().DumpStopContext (&s, false); 631a134cc1bSGreg Clayton s.PutCString (": "); 632a134cc1bSGreg Clayton } 633f9fa6ee5SEnrico Granata if (summary_format_sp) 634f9fa6ee5SEnrico Granata valobj_sp->SetCustomSummaryFormat(summary_format_sp); 6351d3afba3SGreg Clayton ValueObject::DumpValueObject (result.GetOutputStream(), 636a134cc1bSGreg Clayton valobj_sp.get(), 637a134cc1bSGreg Clayton name_cstr, 638379447a7SEnrico Granata options); 639a134cc1bSGreg Clayton } 640a134cc1bSGreg Clayton } 6416d56d2ceSJim Ingham } 6426d56d2ceSJim Ingham } 6436d56d2ceSJim Ingham } 6446f00abd5SGreg Clayton } 6456d56d2ceSJim Ingham result.SetStatus (eReturnStatusSuccessFinishResult); 6466d56d2ceSJim Ingham } 64761a80ba6SEnrico Granata 64861a80ba6SEnrico Granata if (m_interpreter.TruncationWarningNecessary()) 64961a80ba6SEnrico Granata { 65061a80ba6SEnrico Granata result.GetOutputStream().Printf(m_interpreter.TruncationWarningText(), 65161a80ba6SEnrico Granata m_cmd_name.c_str()); 65261a80ba6SEnrico Granata m_interpreter.TruncationWarningGiven(); 65361a80ba6SEnrico Granata } 65461a80ba6SEnrico Granata 6556d56d2ceSJim Ingham return result.Succeeded(); 6566d56d2ceSJim Ingham } 6576d56d2ceSJim Ingham protected: 6586d56d2ceSJim Ingham 6592837b766SJim Ingham OptionGroupOptions m_option_group; 660715c2365SGreg Clayton OptionGroupVariable m_option_variable; 661b1d7529eSJohnny Chen OptionGroupWatchpoint m_option_watchpoint; 6622837b766SJim Ingham OptionGroupValueObjectDisplay m_varobj_options; 6636d56d2ceSJim Ingham }; 6646d56d2ceSJim Ingham 6652837b766SJim Ingham 66630fdc8d8SChris Lattner #pragma mark CommandObjectMultiwordFrame 66730fdc8d8SChris Lattner 66830fdc8d8SChris Lattner //------------------------------------------------------------------------- 66930fdc8d8SChris Lattner // CommandObjectMultiwordFrame 67030fdc8d8SChris Lattner //------------------------------------------------------------------------- 67130fdc8d8SChris Lattner 6726611103cSGreg Clayton CommandObjectMultiwordFrame::CommandObjectMultiwordFrame (CommandInterpreter &interpreter) : 673a7015092SGreg Clayton CommandObjectMultiword (interpreter, 674a7015092SGreg Clayton "frame", 67530fdc8d8SChris Lattner "A set of commands for operating on the current thread's frames.", 67630fdc8d8SChris Lattner "frame <subcommand> [<subcommand-options>]") 67730fdc8d8SChris Lattner { 678a7015092SGreg Clayton LoadSubCommand ("info", CommandObjectSP (new CommandObjectFrameInfo (interpreter))); 679a7015092SGreg Clayton LoadSubCommand ("select", CommandObjectSP (new CommandObjectFrameSelect (interpreter))); 680a7015092SGreg Clayton LoadSubCommand ("variable", CommandObjectSP (new CommandObjectFrameVariable (interpreter))); 68130fdc8d8SChris Lattner } 68230fdc8d8SChris Lattner 68330fdc8d8SChris Lattner CommandObjectMultiwordFrame::~CommandObjectMultiwordFrame () 68430fdc8d8SChris Lattner { 68530fdc8d8SChris Lattner } 68630fdc8d8SChris Lattner 687