2010-06-09 00:52:24 +08:00
|
|
|
//===-- CommandObjectFrame.cpp ----------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "CommandObjectFrame.h"
|
|
|
|
|
|
|
|
// C Includes
|
|
|
|
// C++ Includes
|
|
|
|
// Other libraries and framework includes
|
|
|
|
// Project includes
|
2011-08-23 06:03:47 +08:00
|
|
|
#include "lldb/Core/DataVisualization.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Core/Debugger.h"
|
2010-09-02 08:18:39 +08:00
|
|
|
#include "lldb/Core/Module.h"
|
|
|
|
#include "lldb/Core/StreamFile.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Core/Timer.h"
|
2010-09-02 08:18:39 +08:00
|
|
|
#include "lldb/Core/Value.h"
|
|
|
|
#include "lldb/Core/ValueObject.h"
|
|
|
|
#include "lldb/Core/ValueObjectVariable.h"
|
2011-02-01 09:31:41 +08:00
|
|
|
#include "lldb/Host/Host.h"
|
2010-09-02 08:18:39 +08:00
|
|
|
#include "lldb/Interpreter/Args.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Interpreter/CommandInterpreter.h"
|
|
|
|
#include "lldb/Interpreter/CommandReturnObject.h"
|
2010-09-02 08:18:39 +08:00
|
|
|
#include "lldb/Interpreter/Options.h"
|
2011-05-04 11:43:18 +08:00
|
|
|
#include "lldb/Interpreter/OptionGroupValueObjectDisplay.h"
|
2011-07-07 12:38:25 +08:00
|
|
|
#include "lldb/Interpreter/OptionGroupVariable.h"
|
2010-09-02 08:18:39 +08:00
|
|
|
#include "lldb/Symbol/ClangASTType.h"
|
|
|
|
#include "lldb/Symbol/ClangASTContext.h"
|
|
|
|
#include "lldb/Symbol/ObjectFile.h"
|
|
|
|
#include "lldb/Symbol/SymbolContext.h"
|
|
|
|
#include "lldb/Symbol/Type.h"
|
|
|
|
#include "lldb/Symbol/Variable.h"
|
|
|
|
#include "lldb/Symbol/VariableList.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Target/Process.h"
|
|
|
|
#include "lldb/Target/StackFrame.h"
|
|
|
|
#include "lldb/Target/Thread.h"
|
2010-09-02 08:18:39 +08:00
|
|
|
#include "lldb/Target/Target.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
|
|
#pragma mark CommandObjectFrameInfo
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
// CommandObjectFrameInfo
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class CommandObjectFrameInfo : public CommandObject
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2010-09-18 09:14:36 +08:00
|
|
|
CommandObjectFrameInfo (CommandInterpreter &interpreter) :
|
|
|
|
CommandObject (interpreter,
|
|
|
|
"frame info",
|
|
|
|
"List information about the currently selected frame in the current thread.",
|
|
|
|
"frame info",
|
|
|
|
eFlagProcessMustBeLaunched | eFlagProcessMustBePaused)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
~CommandObjectFrameInfo ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2010-09-18 09:14:36 +08:00
|
|
|
Execute (Args& command,
|
2010-06-09 00:52:24 +08:00
|
|
|
CommandReturnObject &result)
|
|
|
|
{
|
2011-04-12 13:54:46 +08:00
|
|
|
ExecutionContext exe_ctx(m_interpreter.GetExecutionContext());
|
2010-06-09 00:52:24 +08:00
|
|
|
if (exe_ctx.frame)
|
|
|
|
{
|
2010-10-04 09:05:56 +08:00
|
|
|
exe_ctx.frame->DumpUsingSettingsFormat (&result.GetOutputStream());
|
2010-06-09 00:52:24 +08:00
|
|
|
result.SetStatus (eReturnStatusSuccessFinishResult);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result.AppendError ("no current frame");
|
|
|
|
result.SetStatus (eReturnStatusFailed);
|
|
|
|
}
|
|
|
|
return result.Succeeded();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#pragma mark CommandObjectFrameSelect
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
// CommandObjectFrameSelect
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class CommandObjectFrameSelect : public CommandObject
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2010-10-11 06:28:11 +08:00
|
|
|
class CommandOptions : public Options
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2011-04-08 06:46:35 +08:00
|
|
|
CommandOptions (CommandInterpreter &interpreter) :
|
2011-04-09 06:39:17 +08:00
|
|
|
Options(interpreter)
|
2010-10-11 06:28:11 +08:00
|
|
|
{
|
2011-04-13 08:18:08 +08:00
|
|
|
OptionParsingStarting ();
|
2010-10-11 06:28:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual
|
|
|
|
~CommandOptions ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual Error
|
2011-04-13 08:18:08 +08:00
|
|
|
SetOptionValue (uint32_t option_idx, const char *option_arg)
|
2010-10-11 06:28:11 +08:00
|
|
|
{
|
|
|
|
Error error;
|
|
|
|
bool success = false;
|
|
|
|
char short_option = (char) m_getopt_table[option_idx].val;
|
|
|
|
switch (short_option)
|
|
|
|
{
|
|
|
|
case 'r':
|
|
|
|
relative_frame_offset = Args::StringToSInt32 (option_arg, INT32_MIN, 0, &success);
|
|
|
|
if (!success)
|
|
|
|
error.SetErrorStringWithFormat ("invalid frame offset argument '%s'.\n", option_arg);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2010-11-11 04:16:47 +08:00
|
|
|
error.SetErrorStringWithFormat ("Invalid short option character '%c'.\n", short_option);
|
2010-10-11 06:28:11 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-04-13 08:18:08 +08:00
|
|
|
OptionParsingStarting ()
|
2010-10-11 06:28:11 +08:00
|
|
|
{
|
|
|
|
relative_frame_offset = INT32_MIN;
|
|
|
|
}
|
|
|
|
|
2011-03-25 05:19:54 +08:00
|
|
|
const OptionDefinition*
|
2010-10-11 06:28:11 +08:00
|
|
|
GetDefinitions ()
|
|
|
|
{
|
|
|
|
return g_option_table;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Options table: Required for subclasses of Options.
|
|
|
|
|
2011-03-25 05:19:54 +08:00
|
|
|
static OptionDefinition g_option_table[];
|
2010-10-11 06:28:11 +08:00
|
|
|
int32_t relative_frame_offset;
|
|
|
|
};
|
|
|
|
|
2010-09-18 09:14:36 +08:00
|
|
|
CommandObjectFrameSelect (CommandInterpreter &interpreter) :
|
|
|
|
CommandObject (interpreter,
|
|
|
|
"frame select",
|
|
|
|
"Select a frame by index from within the current thread and make it the current frame.",
|
2010-10-05 06:28:36 +08:00
|
|
|
NULL,
|
2011-04-08 06:46:35 +08:00
|
|
|
eFlagProcessMustBeLaunched | eFlagProcessMustBePaused),
|
|
|
|
m_options (interpreter)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-10-05 06:28:36 +08:00
|
|
|
CommandArgumentEntry arg;
|
|
|
|
CommandArgumentData index_arg;
|
|
|
|
|
|
|
|
// Define the first (and only) variant of this arg.
|
|
|
|
index_arg.arg_type = eArgTypeFrameIndex;
|
2010-10-11 06:28:11 +08:00
|
|
|
index_arg.arg_repetition = eArgRepeatOptional;
|
2010-10-05 06:28:36 +08:00
|
|
|
|
|
|
|
// There is only one variant this argument could be; put it into the argument entry.
|
|
|
|
arg.push_back (index_arg);
|
|
|
|
|
|
|
|
// Push the data for the first argument into the m_arguments vector.
|
|
|
|
m_arguments.push_back (arg);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
~CommandObjectFrameSelect ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-10-11 06:28:11 +08:00
|
|
|
virtual
|
|
|
|
Options *
|
|
|
|
GetOptions ()
|
|
|
|
{
|
|
|
|
return &m_options;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
bool
|
2010-09-18 09:14:36 +08:00
|
|
|
Execute (Args& command,
|
2010-06-09 00:52:24 +08:00
|
|
|
CommandReturnObject &result)
|
|
|
|
{
|
2011-04-12 13:54:46 +08:00
|
|
|
ExecutionContext exe_ctx (m_interpreter.GetExecutionContext());
|
2010-06-09 00:52:24 +08:00
|
|
|
if (exe_ctx.thread)
|
|
|
|
{
|
2010-10-11 06:28:11 +08:00
|
|
|
const uint32_t num_frames = exe_ctx.thread->GetStackFrameCount();
|
|
|
|
uint32_t frame_idx = UINT32_MAX;
|
|
|
|
if (m_options.relative_frame_offset != INT32_MIN)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-10-11 06:28:11 +08:00
|
|
|
// The one and only argument is a signed relative frame index
|
|
|
|
frame_idx = exe_ctx.thread->GetSelectedFrameIndex ();
|
|
|
|
if (frame_idx == UINT32_MAX)
|
|
|
|
frame_idx = 0;
|
|
|
|
|
|
|
|
if (m_options.relative_frame_offset < 0)
|
|
|
|
{
|
|
|
|
if (frame_idx >= -m_options.relative_frame_offset)
|
|
|
|
frame_idx += m_options.relative_frame_offset;
|
|
|
|
else
|
|
|
|
frame_idx = 0;
|
|
|
|
}
|
|
|
|
else if (m_options.relative_frame_offset > 0)
|
|
|
|
{
|
|
|
|
if (num_frames - frame_idx > m_options.relative_frame_offset)
|
|
|
|
frame_idx += m_options.relative_frame_offset;
|
|
|
|
else
|
|
|
|
frame_idx = num_frames - 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (command.GetArgumentCount() == 1)
|
|
|
|
{
|
|
|
|
const char *frame_idx_cstr = command.GetArgumentAtIndex(0);
|
|
|
|
frame_idx = Args::StringToUInt32 (frame_idx_cstr, UINT32_MAX, 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result.AppendError ("invalid arguments.\n");
|
2011-04-08 06:46:35 +08:00
|
|
|
m_options.GenerateOptionUsage (result.GetErrorStream(), this);
|
2010-10-11 06:28:11 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (frame_idx < num_frames)
|
|
|
|
{
|
|
|
|
exe_ctx.thread->SetSelectedFrameByIndex (frame_idx);
|
|
|
|
exe_ctx.frame = exe_ctx.thread->GetSelectedFrame ().get();
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2010-10-11 06:28:11 +08:00
|
|
|
if (exe_ctx.frame)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-10-11 06:28:11 +08:00
|
|
|
bool already_shown = false;
|
|
|
|
SymbolContext frame_sc(exe_ctx.frame->GetSymbolContext(eSymbolContextLineEntry));
|
|
|
|
if (m_interpreter.GetDebugger().GetUseExternalEditor() && frame_sc.line_entry.file && frame_sc.line_entry.line != 0)
|
|
|
|
{
|
|
|
|
already_shown = Host::OpenFileInExternalEditor (frame_sc.line_entry.file, frame_sc.line_entry.line);
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
Centralized a lot of the status information for processes,
threads, and stack frame down in the lldb_private::Process,
lldb_private::Thread, lldb_private::StackFrameList and the
lldb_private::StackFrame classes. We had some command line
commands that had duplicate versions of the process status
output ("thread list" and "process status" for example).
Removed the "file" command and placed it where it should
have been: "target create". Made an alias for "file" to
"target create" so we stay compatible with GDB commands.
We can now have multple usable targets in lldb at the
same time. This is nice for comparing two runs of a program
or debugging more than one binary at the same time. The
new command is "target select <target-idx>" and also to see
a list of the current targets you can use the new "target list"
command. The flow in a debug session can be:
(lldb) target create /path/to/exe/a.out
(lldb) breakpoint set --name main
(lldb) run
... hit breakpoint
(lldb) target create /bin/ls
(lldb) run /tmp
Process 36001 exited with status = 0 (0x00000000)
(lldb) target list
Current targets:
target #0: /tmp/args/a.out ( arch=x86_64-apple-darwin, platform=localhost, pid=35999, state=stopped )
* target #1: /bin/ls ( arch=x86_64-apple-darwin, platform=localhost, pid=36001, state=exited )
(lldb) target select 0
Current targets:
* target #0: /tmp/args/a.out ( arch=x86_64-apple-darwin, platform=localhost, pid=35999, state=stopped )
target #1: /bin/ls ( arch=x86_64-apple-darwin, platform=localhost, pid=36001, state=exited )
(lldb) bt
* thread #1: tid = 0x2d03, 0x0000000100000b9a a.out`main + 42 at main.c:16, stop reason = breakpoint 1.1
frame #0: 0x0000000100000b9a a.out`main + 42 at main.c:16
frame #1: 0x0000000100000b64 a.out`start + 52
Above we created a target for "a.out" and ran and hit a
breakpoint at "main". Then we created a new target for /bin/ls
and ran it. Then we listed the targest and selected our original
"a.out" program, so we showed two concurent debug sessions
going on at the same time.
llvm-svn: 129695
2011-04-18 16:33:37 +08:00
|
|
|
bool show_frame_info = true;
|
|
|
|
bool show_source = !already_shown;
|
|
|
|
uint32_t source_lines_before = 3;
|
|
|
|
uint32_t source_lines_after = 3;
|
|
|
|
if (exe_ctx.frame->GetStatus(result.GetOutputStream(),
|
|
|
|
show_frame_info,
|
|
|
|
show_source,
|
|
|
|
source_lines_before,
|
|
|
|
source_lines_after))
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-10-11 06:28:11 +08:00
|
|
|
result.SetStatus (eReturnStatusSuccessFinishResult);
|
|
|
|
return result.Succeeded();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-10-11 06:28:11 +08:00
|
|
|
result.AppendErrorWithFormat ("Frame index (%u) out of range.\n", frame_idx);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result.AppendError ("no current thread");
|
|
|
|
}
|
|
|
|
result.SetStatus (eReturnStatusFailed);
|
|
|
|
return false;
|
|
|
|
}
|
2010-10-11 06:28:11 +08:00
|
|
|
protected:
|
|
|
|
|
|
|
|
CommandOptions m_options;
|
|
|
|
};
|
|
|
|
|
2011-03-25 05:19:54 +08:00
|
|
|
OptionDefinition
|
2010-10-11 06:28:11 +08:00
|
|
|
CommandObjectFrameSelect::CommandOptions::g_option_table[] =
|
|
|
|
{
|
|
|
|
{ LLDB_OPT_SET_1, false, "relative", 'r', required_argument, NULL, 0, eArgTypeOffset, "A relative frame index offset from the current frame index."},
|
|
|
|
{ 0, false, NULL, 0, 0, NULL, NULL, eArgTypeNone, NULL }
|
2010-06-09 00:52:24 +08:00
|
|
|
};
|
|
|
|
|
2010-09-02 08:18:39 +08:00
|
|
|
#pragma mark CommandObjectFrameVariable
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// List images with associated information
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
class CommandObjectFrameVariable : public CommandObject
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2011-05-04 11:43:18 +08:00
|
|
|
class OptionGroupFrameVariable : public OptionGroup
|
2010-09-02 08:18:39 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2011-05-04 11:43:18 +08:00
|
|
|
OptionGroupFrameVariable ()
|
2010-09-02 08:18:39 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual
|
2011-05-04 11:43:18 +08:00
|
|
|
~OptionGroupFrameVariable ()
|
2010-09-02 08:18:39 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-05-04 11:43:18 +08:00
|
|
|
virtual uint32_t
|
|
|
|
GetNumDefinitions ();
|
|
|
|
|
|
|
|
virtual const OptionDefinition*
|
|
|
|
GetDefinitions ()
|
|
|
|
{
|
|
|
|
return g_option_table;
|
|
|
|
}
|
|
|
|
|
2010-09-02 08:18:39 +08:00
|
|
|
virtual Error
|
2011-05-04 11:43:18 +08:00
|
|
|
SetOptionValue (CommandInterpreter &interpreter,
|
|
|
|
uint32_t option_idx,
|
|
|
|
const char *option_arg)
|
2010-09-02 08:18:39 +08:00
|
|
|
{
|
|
|
|
Error error;
|
2011-05-04 11:43:18 +08:00
|
|
|
char short_option = (char) g_option_table[option_idx].short_option;
|
2010-09-02 08:18:39 +08:00
|
|
|
switch (short_option)
|
|
|
|
{
|
|
|
|
case 'r': use_regex = true; break;
|
|
|
|
case 'a': show_args = false; break;
|
|
|
|
case 'l': show_locals = false; break;
|
2010-09-13 10:37:44 +08:00
|
|
|
case 'g': show_globals = true; break;
|
|
|
|
case 'c': show_decl = true; break;
|
2011-04-29 04:55:26 +08:00
|
|
|
case 'f': error = Args::StringToFormat(option_arg, format, NULL); break;
|
2010-09-02 08:18:39 +08:00
|
|
|
case 'G':
|
2010-09-13 10:37:44 +08:00
|
|
|
globals.push_back(ConstString (option_arg));
|
2010-09-02 08:18:39 +08:00
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
show_scope = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
error.SetErrorStringWithFormat("Invalid short option character '%c'.\n", short_option);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2011-05-04 11:43:18 +08:00
|
|
|
virtual void
|
|
|
|
OptionParsingStarting (CommandInterpreter &interpreter)
|
2010-09-02 08:18:39 +08:00
|
|
|
{
|
|
|
|
show_args = true;
|
2010-09-13 10:37:44 +08:00
|
|
|
show_decl = false;
|
2011-03-19 09:12:21 +08:00
|
|
|
format = eFormatDefault;
|
2011-05-04 11:43:18 +08:00
|
|
|
show_globals = false;
|
|
|
|
show_locals = true;
|
|
|
|
use_regex = false;
|
|
|
|
show_scope = false;
|
2010-09-02 08:18:39 +08:00
|
|
|
globals.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Options table: Required for subclasses of Options.
|
|
|
|
|
2011-03-25 05:19:54 +08:00
|
|
|
static OptionDefinition g_option_table[];
|
2011-05-04 11:43:18 +08:00
|
|
|
|
|
|
|
bool use_regex:1,
|
2010-09-13 10:37:44 +08:00
|
|
|
show_args:1,
|
|
|
|
show_locals:1,
|
|
|
|
show_globals:1,
|
|
|
|
show_scope:1,
|
2011-05-04 11:43:18 +08:00
|
|
|
show_decl:1;
|
2011-03-19 09:12:21 +08:00
|
|
|
lldb::Format format; // The format to use when dumping variables or children of variables
|
2010-09-02 08:18:39 +08:00
|
|
|
std::vector<ConstString> globals;
|
|
|
|
// Instance variables to hold the values for command options.
|
|
|
|
};
|
|
|
|
|
2010-09-18 09:14:36 +08:00
|
|
|
CommandObjectFrameVariable (CommandInterpreter &interpreter) :
|
|
|
|
CommandObject (interpreter,
|
|
|
|
"frame variable",
|
2010-09-18 11:37:20 +08:00
|
|
|
"Show frame variables. All argument and local variables "
|
|
|
|
"that are in scope will be shown when no arguments are given. "
|
|
|
|
"If any arguments are specified, they can be names of "
|
2010-10-26 07:57:26 +08:00
|
|
|
"argument, local, file static and file global variables. "
|
2010-09-18 11:37:20 +08:00
|
|
|
"Children of aggregate variables can be specified such as "
|
|
|
|
"'var->child.x'.",
|
2010-12-23 10:17:54 +08:00
|
|
|
NULL,
|
2011-04-08 06:46:35 +08:00
|
|
|
eFlagProcessMustBeLaunched | eFlagProcessMustBePaused),
|
2011-05-04 11:43:18 +08:00
|
|
|
m_option_group (interpreter),
|
2011-07-07 12:38:25 +08:00
|
|
|
m_option_variable(true), // Include the frame specific options by passing "true"
|
2011-05-04 11:43:18 +08:00
|
|
|
m_varobj_options()
|
2010-09-02 08:18:39 +08:00
|
|
|
{
|
2010-10-05 06:28:36 +08:00
|
|
|
CommandArgumentEntry arg;
|
|
|
|
CommandArgumentData var_name_arg;
|
|
|
|
|
|
|
|
// Define the first (and only) variant of this arg.
|
|
|
|
var_name_arg.arg_type = eArgTypeVarName;
|
|
|
|
var_name_arg.arg_repetition = eArgRepeatStar;
|
|
|
|
|
|
|
|
// There is only one variant this argument could be; put it into the argument entry.
|
|
|
|
arg.push_back (var_name_arg);
|
|
|
|
|
|
|
|
// Push the data for the first argument into the m_arguments vector.
|
|
|
|
m_arguments.push_back (arg);
|
2011-05-04 11:43:18 +08:00
|
|
|
|
2011-07-07 12:38:25 +08:00
|
|
|
m_option_group.Append (&m_option_variable, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
|
2011-05-04 11:43:18 +08:00
|
|
|
m_option_group.Append (&m_varobj_options, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
|
|
|
|
m_option_group.Finalize();
|
2010-09-02 08:18:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual
|
|
|
|
~CommandObjectFrameVariable ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual
|
|
|
|
Options *
|
|
|
|
GetOptions ()
|
|
|
|
{
|
2011-05-04 11:43:18 +08:00
|
|
|
return &m_option_group;
|
2010-09-02 08:18:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
virtual bool
|
|
|
|
Execute
|
|
|
|
(
|
|
|
|
Args& command,
|
|
|
|
CommandReturnObject &result
|
|
|
|
)
|
|
|
|
{
|
2011-04-12 13:54:46 +08:00
|
|
|
ExecutionContext exe_ctx(m_interpreter.GetExecutionContext());
|
2010-09-02 08:18:39 +08:00
|
|
|
if (exe_ctx.frame == NULL)
|
|
|
|
{
|
2010-09-18 12:06:15 +08:00
|
|
|
result.AppendError ("you must be stopped in a valid stack frame to view frame variables.");
|
2010-09-02 08:18:39 +08:00
|
|
|
result.SetStatus (eReturnStatusFailed);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-09-13 10:37:44 +08:00
|
|
|
Stream &s = result.GetOutputStream();
|
|
|
|
|
|
|
|
bool get_file_globals = true;
|
2011-08-27 09:22:52 +08:00
|
|
|
|
|
|
|
// Be careful about the stack frame, if any summary formatter runs code, it might clear the StackFrameList
|
|
|
|
// for the thread. So hold onto a shared pointer to the frame so it stays alive.
|
|
|
|
|
|
|
|
StackFrameSP frame_sp = exe_ctx.frame->GetSP();
|
|
|
|
|
|
|
|
VariableList *variable_list = frame_sp->GetVariableList (get_file_globals);
|
2010-09-02 08:18:39 +08:00
|
|
|
|
|
|
|
VariableSP var_sp;
|
|
|
|
ValueObjectSP valobj_sp;
|
2011-04-16 08:01:13 +08:00
|
|
|
|
2010-09-02 08:18:39 +08:00
|
|
|
const char *name_cstr = NULL;
|
|
|
|
size_t idx;
|
2011-07-12 08:18:11 +08:00
|
|
|
|
|
|
|
SummaryFormatSP summary_format_sp;
|
|
|
|
if (!m_option_variable.summary.empty())
|
2011-08-18 06:13:59 +08:00
|
|
|
DataVisualization::NamedSummaryFormats::Get(ConstString(m_option_variable.summary.c_str()), summary_format_sp);
|
2011-08-16 02:01:31 +08:00
|
|
|
|
|
|
|
ValueObject::DumpValueObjectOptions options;
|
|
|
|
|
|
|
|
options.SetPointerDepth(m_varobj_options.ptr_depth)
|
|
|
|
.SetMaximumDepth(m_varobj_options.max_depth)
|
|
|
|
.SetShowTypes(m_varobj_options.show_types)
|
|
|
|
.SetShowLocation(m_varobj_options.show_location)
|
|
|
|
.SetUseObjectiveC(m_varobj_options.use_objc)
|
|
|
|
.SetUseDynamicType(m_varobj_options.use_dynamic)
|
|
|
|
.SetUseSyntheticValue((lldb::SyntheticValueType)m_varobj_options.use_synth)
|
|
|
|
.SetFlatOutput(m_varobj_options.flat_output)
|
|
|
|
.SetOmitSummaryDepth(m_varobj_options.no_summary_depth)
|
|
|
|
.SetIgnoreCap(m_varobj_options.ignore_cap);
|
|
|
|
|
|
|
|
if (m_varobj_options.be_raw)
|
|
|
|
options.SetRawDisplay(true);
|
|
|
|
|
2011-07-07 12:38:25 +08:00
|
|
|
if (variable_list)
|
2010-09-02 08:18:39 +08:00
|
|
|
{
|
2010-09-13 11:44:33 +08:00
|
|
|
if (command.GetArgumentCount() > 0)
|
2010-09-02 08:18:39 +08:00
|
|
|
{
|
2010-10-11 07:55:27 +08:00
|
|
|
VariableList regex_var_list;
|
|
|
|
|
2010-09-13 11:44:33 +08:00
|
|
|
// If we have any args to the variable command, we will make
|
|
|
|
// variable objects from them...
|
|
|
|
for (idx = 0; (name_cstr = command.GetArgumentAtIndex(idx)) != NULL; ++idx)
|
2010-09-02 08:18:39 +08:00
|
|
|
{
|
2011-07-07 12:38:25 +08:00
|
|
|
if (m_option_variable.use_regex)
|
2010-09-13 11:44:33 +08:00
|
|
|
{
|
2010-10-11 07:55:27 +08:00
|
|
|
const uint32_t regex_start_index = regex_var_list.GetSize();
|
|
|
|
RegularExpression regex (name_cstr);
|
|
|
|
if (regex.Compile(name_cstr))
|
|
|
|
{
|
|
|
|
size_t num_matches = 0;
|
2011-04-16 08:01:13 +08:00
|
|
|
const size_t num_new_regex_vars = variable_list->AppendVariablesIfUnique(regex,
|
|
|
|
regex_var_list,
|
|
|
|
num_matches);
|
2010-10-11 07:55:27 +08:00
|
|
|
if (num_new_regex_vars > 0)
|
|
|
|
{
|
|
|
|
for (uint32_t regex_idx = regex_start_index, end_index = regex_var_list.GetSize();
|
|
|
|
regex_idx < end_index;
|
|
|
|
++regex_idx)
|
|
|
|
{
|
|
|
|
var_sp = regex_var_list.GetVariableAtIndex (regex_idx);
|
|
|
|
if (var_sp)
|
|
|
|
{
|
2011-08-27 09:22:52 +08:00
|
|
|
valobj_sp = frame_sp->GetValueObjectForFrameVariable (var_sp, m_varobj_options.use_dynamic);
|
2010-10-11 07:55:27 +08:00
|
|
|
if (valobj_sp)
|
2011-04-16 08:01:13 +08:00
|
|
|
{
|
2011-07-07 12:38:25 +08:00
|
|
|
if (m_option_variable.format != eFormatDefault)
|
|
|
|
valobj_sp->SetFormat (m_option_variable.format);
|
2011-03-19 09:12:21 +08:00
|
|
|
|
2011-07-07 12:38:25 +08:00
|
|
|
if (m_option_variable.show_decl && var_sp->GetDeclaration ().GetFile())
|
2010-10-11 07:55:27 +08:00
|
|
|
{
|
2011-07-11 03:21:23 +08:00
|
|
|
bool show_fullpaths = false;
|
|
|
|
bool show_module = true;
|
|
|
|
if (var_sp->DumpDeclaration(&s, show_fullpaths, show_module))
|
|
|
|
s.PutCString (": ");
|
2010-10-11 07:55:27 +08:00
|
|
|
}
|
2011-07-12 08:18:11 +08:00
|
|
|
if (summary_format_sp)
|
|
|
|
valobj_sp->SetCustomSummaryFormat(summary_format_sp);
|
2010-10-11 07:55:27 +08:00
|
|
|
ValueObject::DumpValueObject (result.GetOutputStream(),
|
2011-08-16 02:01:31 +08:00
|
|
|
valobj_sp.get(),
|
|
|
|
options);
|
2010-10-11 07:55:27 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (num_matches == 0)
|
|
|
|
{
|
|
|
|
result.GetErrorStream().Printf ("error: no variables matched the regular expression '%s'.\n", name_cstr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
char regex_error[1024];
|
|
|
|
if (regex.GetErrorAsCString(regex_error, sizeof(regex_error)))
|
|
|
|
result.GetErrorStream().Printf ("error: %s\n", regex_error);
|
|
|
|
else
|
|
|
|
result.GetErrorStream().Printf ("error: unkown regex error when compiling '%s'\n", name_cstr);
|
|
|
|
}
|
2010-09-13 11:44:33 +08:00
|
|
|
}
|
|
|
|
else
|
2010-09-02 08:18:39 +08:00
|
|
|
{
|
2010-12-15 13:08:08 +08:00
|
|
|
Error error;
|
2011-04-16 08:01:13 +08:00
|
|
|
uint32_t expr_path_options = StackFrame::eExpressionPathOptionCheckPtrVsMember;
|
2011-05-04 11:43:18 +08:00
|
|
|
lldb::VariableSP var_sp;
|
2011-08-27 09:22:52 +08:00
|
|
|
valobj_sp = frame_sp->GetValueForVariableExpressionPath (name_cstr,
|
2011-05-04 11:43:18 +08:00
|
|
|
m_varobj_options.use_dynamic,
|
|
|
|
expr_path_options,
|
|
|
|
var_sp,
|
|
|
|
error);
|
2010-12-15 13:08:08 +08:00
|
|
|
if (valobj_sp)
|
2010-10-11 07:55:27 +08:00
|
|
|
{
|
2011-07-07 12:38:25 +08:00
|
|
|
if (m_option_variable.format != eFormatDefault)
|
|
|
|
valobj_sp->SetFormat (m_option_variable.format);
|
|
|
|
if (m_option_variable.show_decl && var_sp && var_sp->GetDeclaration ().GetFile())
|
2010-10-11 07:55:27 +08:00
|
|
|
{
|
2010-12-15 13:08:08 +08:00
|
|
|
var_sp->GetDeclaration ().DumpStopContext (&s, false);
|
|
|
|
s.PutCString (": ");
|
2010-10-11 07:55:27 +08:00
|
|
|
}
|
2011-07-12 08:18:11 +08:00
|
|
|
if (summary_format_sp)
|
|
|
|
valobj_sp->SetCustomSummaryFormat(summary_format_sp);
|
2010-12-15 13:08:08 +08:00
|
|
|
ValueObject::DumpValueObject (result.GetOutputStream(),
|
|
|
|
valobj_sp.get(),
|
2011-08-16 02:01:31 +08:00
|
|
|
valobj_sp->GetParent() ? name_cstr : NULL,
|
|
|
|
options);
|
2010-10-11 07:55:27 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-12-15 13:08:08 +08:00
|
|
|
const char *error_cstr = error.AsCString(NULL);
|
|
|
|
if (error_cstr)
|
|
|
|
result.GetErrorStream().Printf("error: %s\n", error_cstr);
|
|
|
|
else
|
|
|
|
result.GetErrorStream().Printf ("error: unable to find any variable expression path that matches '%s'\n", name_cstr);
|
2010-09-13 10:37:44 +08:00
|
|
|
}
|
2010-09-13 11:44:33 +08:00
|
|
|
}
|
2010-09-02 08:18:39 +08:00
|
|
|
}
|
|
|
|
}
|
2010-09-13 11:44:33 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
const uint32_t num_variables = variable_list->GetSize();
|
|
|
|
|
|
|
|
if (num_variables > 0)
|
|
|
|
{
|
|
|
|
for (uint32_t i=0; i<num_variables; i++)
|
|
|
|
{
|
2011-01-26 07:55:37 +08:00
|
|
|
var_sp = variable_list->GetVariableAtIndex(i);
|
2011-04-16 08:01:13 +08:00
|
|
|
|
2010-09-13 11:44:33 +08:00
|
|
|
bool dump_variable = true;
|
|
|
|
|
|
|
|
switch (var_sp->GetScope())
|
|
|
|
{
|
|
|
|
case eValueTypeVariableGlobal:
|
2011-07-07 12:38:25 +08:00
|
|
|
dump_variable = m_option_variable.show_globals;
|
|
|
|
if (dump_variable && m_option_variable.show_scope)
|
2010-09-13 11:44:33 +08:00
|
|
|
s.PutCString("GLOBAL: ");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eValueTypeVariableStatic:
|
2011-07-07 12:38:25 +08:00
|
|
|
dump_variable = m_option_variable.show_globals;
|
|
|
|
if (dump_variable && m_option_variable.show_scope)
|
2010-09-13 11:44:33 +08:00
|
|
|
s.PutCString("STATIC: ");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eValueTypeVariableArgument:
|
2011-07-07 12:38:25 +08:00
|
|
|
dump_variable = m_option_variable.show_args;
|
|
|
|
if (dump_variable && m_option_variable.show_scope)
|
2010-09-13 11:44:33 +08:00
|
|
|
s.PutCString(" ARG: ");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eValueTypeVariableLocal:
|
2011-07-07 12:38:25 +08:00
|
|
|
dump_variable = m_option_variable.show_locals;
|
|
|
|
if (dump_variable && m_option_variable.show_scope)
|
2010-09-13 11:44:33 +08:00
|
|
|
s.PutCString(" LOCAL: ");
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dump_variable)
|
|
|
|
{
|
|
|
|
|
|
|
|
// Use the variable object code to make sure we are
|
|
|
|
// using the same APIs as the the public API will be
|
|
|
|
// using...
|
2011-08-27 09:22:52 +08:00
|
|
|
valobj_sp = frame_sp->GetValueObjectForFrameVariable (var_sp,
|
2011-05-04 11:43:18 +08:00
|
|
|
m_varobj_options.use_dynamic);
|
2010-09-13 11:44:33 +08:00
|
|
|
if (valobj_sp)
|
|
|
|
{
|
2011-07-07 12:38:25 +08:00
|
|
|
if (m_option_variable.format != eFormatDefault)
|
|
|
|
valobj_sp->SetFormat (m_option_variable.format);
|
2011-03-19 09:12:21 +08:00
|
|
|
|
2010-09-14 11:16:58 +08:00
|
|
|
// When dumping all variables, don't print any variables
|
|
|
|
// that are not in scope to avoid extra unneeded output
|
2011-03-31 08:19:25 +08:00
|
|
|
if (valobj_sp->IsInScope ())
|
2010-09-13 11:44:33 +08:00
|
|
|
{
|
2011-07-07 12:38:25 +08:00
|
|
|
if (m_option_variable.show_decl && var_sp->GetDeclaration ().GetFile())
|
2010-09-14 11:16:58 +08:00
|
|
|
{
|
|
|
|
var_sp->GetDeclaration ().DumpStopContext (&s, false);
|
|
|
|
s.PutCString (": ");
|
|
|
|
}
|
2011-07-12 08:18:11 +08:00
|
|
|
if (summary_format_sp)
|
|
|
|
valobj_sp->SetCustomSummaryFormat(summary_format_sp);
|
2010-10-05 08:00:42 +08:00
|
|
|
ValueObject::DumpValueObject (result.GetOutputStream(),
|
|
|
|
valobj_sp.get(),
|
2011-08-16 02:01:31 +08:00
|
|
|
name_cstr,
|
|
|
|
options);
|
2010-09-13 11:44:33 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result.SetStatus (eReturnStatusSuccessFinishResult);
|
2010-09-02 08:18:39 +08:00
|
|
|
}
|
|
|
|
}
|
2011-08-13 00:42:31 +08:00
|
|
|
|
|
|
|
if (m_interpreter.TruncationWarningNecessary())
|
|
|
|
{
|
|
|
|
result.GetOutputStream().Printf(m_interpreter.TruncationWarningText(),
|
|
|
|
m_cmd_name.c_str());
|
|
|
|
m_interpreter.TruncationWarningGiven();
|
|
|
|
}
|
|
|
|
|
2010-09-02 08:18:39 +08:00
|
|
|
return result.Succeeded();
|
|
|
|
}
|
|
|
|
protected:
|
|
|
|
|
2011-05-04 11:43:18 +08:00
|
|
|
OptionGroupOptions m_option_group;
|
2011-07-07 12:38:25 +08:00
|
|
|
OptionGroupVariable m_option_variable;
|
2011-05-04 11:43:18 +08:00
|
|
|
OptionGroupValueObjectDisplay m_varobj_options;
|
2010-09-02 08:18:39 +08:00
|
|
|
};
|
|
|
|
|
2011-05-04 11:43:18 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
#pragma mark CommandObjectMultiwordFrame
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
// CommandObjectMultiwordFrame
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
|
2010-06-23 09:19:29 +08:00
|
|
|
CommandObjectMultiwordFrame::CommandObjectMultiwordFrame (CommandInterpreter &interpreter) :
|
2010-09-18 09:14:36 +08:00
|
|
|
CommandObjectMultiword (interpreter,
|
|
|
|
"frame",
|
2010-06-09 00:52:24 +08:00
|
|
|
"A set of commands for operating on the current thread's frames.",
|
|
|
|
"frame <subcommand> [<subcommand-options>]")
|
|
|
|
{
|
2010-09-18 09:14:36 +08:00
|
|
|
LoadSubCommand ("info", CommandObjectSP (new CommandObjectFrameInfo (interpreter)));
|
|
|
|
LoadSubCommand ("select", CommandObjectSP (new CommandObjectFrameSelect (interpreter)));
|
|
|
|
LoadSubCommand ("variable", CommandObjectSP (new CommandObjectFrameVariable (interpreter)));
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CommandObjectMultiwordFrame::~CommandObjectMultiwordFrame ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|