2010-06-09 00:52:24 +08:00
//===-- CommandObjectExpression.cpp -----------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
2012-12-05 08:20:57 +08:00
# include "lldb/lldb-python.h"
2010-06-09 00:52:24 +08:00
# include "CommandObjectExpression.h"
// C Includes
// C++ Includes
// Other libraries and framework includes
// Project includes
2010-07-23 08:16:21 +08:00
# include "lldb/Interpreter/Args.h"
2010-06-09 00:52:24 +08:00
# include "lldb/Core/Value.h"
# include "lldb/Core/InputReader.h"
2010-09-30 08:54:27 +08:00
# include "lldb/Core/ValueObjectVariable.h"
<rdar://problem/14393032>
DumpValueObject() 2.0
This checkin restores pre-Xcode5 functionality to the "po" (expr -O) command:
- expr now has a new --description-verbosity (-v) argument, which takes either compact or full as a value (-v is the same as -vfull)
When the full mode is on, "po" will show the extended output with type name, persistent variable name and value, as in
(lldb) expr -O -v -- foo
(id) $0 = 0x000000010010baf0 {
1 = 2;
2 = 3;
}
When -v is omitted, or -vcompact is passed, the Xcode5-style output will be shown, as in
(lldb) expr -O -- foo
{
1 = 2;
2 = 3;
}
- for a non-ObjectiveC object, LLDB will still try to retrieve a summary and/or value to display
(lldb) po 5
5
-v also works in this mode
(lldb) expr -O -vfull -- 5
(int) $4 = 5
On top of that, this is a major refactoring of the ValueObject printing code. The functionality is now factored into a ValueObjectPrinter class for easier maintenance in the future
DumpValueObject() was turned into an instance method ValueObject::Dump() which simply calls through to the printer code, Dump_Impl has been removed
Test case to follow
llvm-svn: 191694
2013-10-01 03:11:51 +08:00
# include "lldb/DataFormatters/ValueObjectPrinter.h"
2010-06-09 00:52:24 +08:00
# include "lldb/Expression/ClangExpressionVariable.h"
This is a major refactoring of the expression parser.
The goal is to separate the parser's data from the data
belonging to the parser's clients. This allows clients
to use the parser to obtain (for example) a JIT compiled
function or some DWARF code, and then discard the parser
state.
Previously, parser state was held in ClangExpression and
used liberally by ClangFunction, which inherited from
ClangExpression. The main effects of this refactoring
are:
- reducing ClangExpression to an abstract class that
declares methods that any client must expose to the
expression parser,
- moving the code specific to implementing the "expr"
command from ClangExpression and
CommandObjectExpression into ClangUserExpression,
a new class,
- moving the common parser interaction code from
ClangExpression into ClangExpressionParser, a new
class, and
- making ClangFunction rely only on
ClangExpressionParser and not depend on the
internal implementation of ClangExpression.
Side effects include:
- the compiler interaction code has been factored
out of ClangFunction and is now in an AST pass
(ASTStructExtractor),
- the header file for ClangFunction is now fully
documented,
- several bugs that only popped up when Clang was
deallocated (which never happened, since the
lifetime of the compiler was essentially infinite)
are now fixed, and
- the developer-only "call" command has been
disabled.
I have tested the expr command and the Objective-C
step-into code, which use ClangUserExpression and
ClangFunction, respectively, and verified that they
work. Please let me know if you encounter bugs or
poor documentation.
llvm-svn: 112249
2010-08-27 09:01:44 +08:00
# include "lldb/Expression/ClangUserExpression.h"
2010-07-24 05:47:22 +08:00
# include "lldb/Expression/ClangFunction.h"
2010-06-09 00:52:24 +08:00
# include "lldb/Expression/DWARFExpression.h"
# include "lldb/Host/Host.h"
2010-07-23 08:16:21 +08:00
# include "lldb/Core/Debugger.h"
2010-06-23 09:19:29 +08:00
# include "lldb/Interpreter/CommandInterpreter.h"
2010-06-09 00:52:24 +08:00
# include "lldb/Interpreter/CommandReturnObject.h"
2010-09-30 08:54:27 +08:00
# include "lldb/Target/ObjCLanguageRuntime.h"
2010-06-09 00:52:24 +08:00
# include "lldb/Symbol/ObjectFile.h"
# include "lldb/Symbol/Variable.h"
# include "lldb/Target/Process.h"
2013-11-04 17:33:30 +08:00
# include "lldb/Target/StackFrame.h"
2010-06-09 00:52:24 +08:00
# include "lldb/Target/Target.h"
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
# include "lldb/Target/Thread.h"
2010-07-23 08:16:21 +08:00
# include "llvm/ADT/StringRef.h"
2010-06-09 00:52:24 +08:00
using namespace lldb ;
using namespace lldb_private ;
2011-10-25 14:44:01 +08:00
CommandObjectExpression : : CommandOptions : : CommandOptions ( ) :
OptionGroup ( )
2010-06-09 00:52:24 +08:00
{
}
CommandObjectExpression : : CommandOptions : : ~ CommandOptions ( )
{
}
<rdar://problem/14393032>
DumpValueObject() 2.0
This checkin restores pre-Xcode5 functionality to the "po" (expr -O) command:
- expr now has a new --description-verbosity (-v) argument, which takes either compact or full as a value (-v is the same as -vfull)
When the full mode is on, "po" will show the extended output with type name, persistent variable name and value, as in
(lldb) expr -O -v -- foo
(id) $0 = 0x000000010010baf0 {
1 = 2;
2 = 3;
}
When -v is omitted, or -vcompact is passed, the Xcode5-style output will be shown, as in
(lldb) expr -O -- foo
{
1 = 2;
2 = 3;
}
- for a non-ObjectiveC object, LLDB will still try to retrieve a summary and/or value to display
(lldb) po 5
5
-v also works in this mode
(lldb) expr -O -vfull -- 5
(int) $4 = 5
On top of that, this is a major refactoring of the ValueObject printing code. The functionality is now factored into a ValueObjectPrinter class for easier maintenance in the future
DumpValueObject() was turned into an instance method ValueObject::Dump() which simply calls through to the printer code, Dump_Impl has been removed
Test case to follow
llvm-svn: 191694
2013-10-01 03:11:51 +08:00
static OptionEnumValueElement g_description_verbosity_type [ ] =
{
{ eLanguageRuntimeDescriptionDisplayVerbosityCompact , " compact " , " Only show the description string " } ,
{ eLanguageRuntimeDescriptionDisplayVerbosityFull , " full " , " Show the full output, including persistent variable's name and type " } ,
{ 0 , NULL , NULL }
} ;
2011-10-25 14:44:01 +08:00
OptionDefinition
CommandObjectExpression : : CommandOptions : : g_option_table [ ] =
{
2013-09-06 00:42:23 +08:00
{ LLDB_OPT_SET_1 | LLDB_OPT_SET_2 , false , " all-threads " , ' a ' , OptionParser : : eRequiredArgument , NULL , 0 , eArgTypeBoolean , " Should we run all threads if the execution doesn't complete on one thread. " } ,
{ LLDB_OPT_SET_1 | LLDB_OPT_SET_2 , false , " ignore-breakpoints " , ' i ' , OptionParser : : eRequiredArgument , NULL , 0 , eArgTypeBoolean , " Ignore breakpoint hits while running expressions " } ,
{ LLDB_OPT_SET_1 | LLDB_OPT_SET_2 , false , " timeout " , ' t ' , OptionParser : : eRequiredArgument , NULL , 0 , eArgTypeUnsignedInteger , " Timeout value (in microseconds) for running the expression. " } ,
{ LLDB_OPT_SET_1 | LLDB_OPT_SET_2 , false , " unwind-on-error " , ' u ' , OptionParser : : eRequiredArgument , NULL , 0 , eArgTypeBoolean , " Clean up program state if the expression causes a crash, or raises a signal. Note, unlike gdb hitting a breakpoint is controlled by another option (-i). " } ,
<rdar://problem/14393032>
DumpValueObject() 2.0
This checkin restores pre-Xcode5 functionality to the "po" (expr -O) command:
- expr now has a new --description-verbosity (-v) argument, which takes either compact or full as a value (-v is the same as -vfull)
When the full mode is on, "po" will show the extended output with type name, persistent variable name and value, as in
(lldb) expr -O -v -- foo
(id) $0 = 0x000000010010baf0 {
1 = 2;
2 = 3;
}
When -v is omitted, or -vcompact is passed, the Xcode5-style output will be shown, as in
(lldb) expr -O -- foo
{
1 = 2;
2 = 3;
}
- for a non-ObjectiveC object, LLDB will still try to retrieve a summary and/or value to display
(lldb) po 5
5
-v also works in this mode
(lldb) expr -O -vfull -- 5
(int) $4 = 5
On top of that, this is a major refactoring of the ValueObject printing code. The functionality is now factored into a ValueObjectPrinter class for easier maintenance in the future
DumpValueObject() was turned into an instance method ValueObject::Dump() which simply calls through to the printer code, Dump_Impl has been removed
Test case to follow
llvm-svn: 191694
2013-10-01 03:11:51 +08:00
{ LLDB_OPT_SET_1 , false , " description-verbosity " , ' v ' , OptionParser : : eOptionalArgument , g_description_verbosity_type , 0 , eArgTypeDescriptionVerbosity , " How verbose should the output of this expression be, if the object description is asked for. " } ,
2011-10-25 14:44:01 +08:00
} ;
uint32_t
CommandObjectExpression : : CommandOptions : : GetNumDefinitions ( )
{
return sizeof ( g_option_table ) / sizeof ( OptionDefinition ) ;
}
2010-06-09 00:52:24 +08:00
Error
2011-10-25 14:44:01 +08:00
CommandObjectExpression : : CommandOptions : : SetOptionValue ( CommandInterpreter & interpreter ,
uint32_t option_idx ,
const char * option_arg )
2010-06-09 00:52:24 +08:00
{
Error error ;
2012-12-04 08:32:51 +08:00
const int short_option = g_option_table [ option_idx ] . short_option ;
2010-06-09 00:52:24 +08:00
switch ( short_option )
{
2010-09-08 06:38:08 +08:00
//case 'l':
//if (language.SetLanguageFromCString (option_arg) == false)
//{
2011-10-26 08:56:27 +08:00
// error.SetErrorStringWithFormat("invalid language option argument '%s'", option_arg);
2010-09-08 06:38:08 +08:00
//}
//break;
2010-06-09 00:52:24 +08:00
2012-10-17 05:41:58 +08:00
case ' a ' :
{
bool success ;
bool result ;
result = Args : : StringToBoolean ( option_arg , true , & success ) ;
if ( ! success )
error . SetErrorStringWithFormat ( " invalid all-threads value setting: \" %s \" " , option_arg ) ;
else
try_all_threads = result ;
}
2010-09-30 08:54:27 +08:00
break ;
2010-11-06 03:25:48 +08:00
2013-01-15 10:47:48 +08:00
case ' i ' :
{
bool success ;
bool tmp_value = Args : : StringToBoolean ( option_arg , true , & success ) ;
if ( success )
ignore_breakpoints = tmp_value ;
else
error . SetErrorStringWithFormat ( " could not convert \" %s \" to a boolean value. " , option_arg ) ;
break ;
}
2012-10-17 05:41:58 +08:00
case ' t ' :
{
bool success ;
uint32_t result ;
result = Args : : StringToUInt32 ( option_arg , 0 , 0 , & success ) ;
if ( success )
timeout = result ;
else
error . SetErrorStringWithFormat ( " invalid timeout setting \" %s \" " , option_arg ) ;
}
break ;
2010-11-06 03:25:48 +08:00
case ' u ' :
This patch modifies the expression parser to allow it
to execute expressions even in the absence of a process.
This allows expressions to run in situations where the
target cannot run -- e.g., to perform calculations based
on type information, or to inspect a binary's static
data.
This modification touches the following files:
lldb-private-enumerations.h
Introduce a new enum specifying the policy for
processing an expression. Some expressions should
always be JITted, for example if they are functions
that will be used over and over again. Some
expressions should always be interpreted, for
example if the target is unsafe to run. For most,
it is acceptable to JIT them, but interpretation
is preferable when possible.
Target.[h,cpp]
Have EvaluateExpression now accept the new enum.
ClangExpressionDeclMap.[cpp,h]
Add support for the IR interpreter and also make
the ClangExpressionDeclMap more robust in the
absence of a process.
ClangFunction.[cpp,h]
Add support for the new enum.
IRInterpreter.[cpp,h]
New implementation.
ClangUserExpression.[cpp,h]
Add support for the new enum, and for running
expressions in the absence of a process.
ClangExpression.h
Remove references to the old DWARF-based method
of evaluating expressions, because it has been
superseded for now.
ClangUtilityFunction.[cpp,h]
Add support for the new enum.
ClangExpressionParser.[cpp,h]
Add support for the new enum, remove references
to DWARF, and add support for checking whether
the expression could be evaluated statically.
IRForTarget.[h,cpp]
Add support for the new enum, and add utility
functions to support the interpreter.
IRToDWARF.cpp
Removed
CommandObjectExpression.cpp
Remove references to the obsolete -i option.
Process.cpp
Modify calls to ClangUserExpression::Evaluate
to pass the correct enum (for dlopen/dlclose)
SBValue.cpp
Add support for the new enum.
SBFrame.cpp
Add support for he new enum.
BreakpointOptions.cpp
Add support for the new enum.
llvm-svn: 139772
2011-09-15 10:13:07 +08:00
{
bool success ;
2013-01-15 10:47:48 +08:00
bool tmp_value = Args : : StringToBoolean ( option_arg , true , & success ) ;
if ( success )
unwind_on_error = tmp_value ;
else
2011-10-26 08:56:27 +08:00
error . SetErrorStringWithFormat ( " could not convert \" %s \" to a boolean value. " , option_arg ) ;
This patch modifies the expression parser to allow it
to execute expressions even in the absence of a process.
This allows expressions to run in situations where the
target cannot run -- e.g., to perform calculations based
on type information, or to inspect a binary's static
data.
This modification touches the following files:
lldb-private-enumerations.h
Introduce a new enum specifying the policy for
processing an expression. Some expressions should
always be JITted, for example if they are functions
that will be used over and over again. Some
expressions should always be interpreted, for
example if the target is unsafe to run. For most,
it is acceptable to JIT them, but interpretation
is preferable when possible.
Target.[h,cpp]
Have EvaluateExpression now accept the new enum.
ClangExpressionDeclMap.[cpp,h]
Add support for the IR interpreter and also make
the ClangExpressionDeclMap more robust in the
absence of a process.
ClangFunction.[cpp,h]
Add support for the new enum.
IRInterpreter.[cpp,h]
New implementation.
ClangUserExpression.[cpp,h]
Add support for the new enum, and for running
expressions in the absence of a process.
ClangExpression.h
Remove references to the old DWARF-based method
of evaluating expressions, because it has been
superseded for now.
ClangUtilityFunction.[cpp,h]
Add support for the new enum.
ClangExpressionParser.[cpp,h]
Add support for the new enum, remove references
to DWARF, and add support for checking whether
the expression could be evaluated statically.
IRForTarget.[h,cpp]
Add support for the new enum, and add utility
functions to support the interpreter.
IRToDWARF.cpp
Removed
CommandObjectExpression.cpp
Remove references to the obsolete -i option.
Process.cpp
Modify calls to ClangUserExpression::Evaluate
to pass the correct enum (for dlopen/dlclose)
SBValue.cpp
Add support for the new enum.
SBFrame.cpp
Add support for he new enum.
BreakpointOptions.cpp
Add support for the new enum.
llvm-svn: 139772
2011-09-15 10:13:07 +08:00
break ;
}
<rdar://problem/14393032>
DumpValueObject() 2.0
This checkin restores pre-Xcode5 functionality to the "po" (expr -O) command:
- expr now has a new --description-verbosity (-v) argument, which takes either compact or full as a value (-v is the same as -vfull)
When the full mode is on, "po" will show the extended output with type name, persistent variable name and value, as in
(lldb) expr -O -v -- foo
(id) $0 = 0x000000010010baf0 {
1 = 2;
2 = 3;
}
When -v is omitted, or -vcompact is passed, the Xcode5-style output will be shown, as in
(lldb) expr -O -- foo
{
1 = 2;
2 = 3;
}
- for a non-ObjectiveC object, LLDB will still try to retrieve a summary and/or value to display
(lldb) po 5
5
-v also works in this mode
(lldb) expr -O -vfull -- 5
(int) $4 = 5
On top of that, this is a major refactoring of the ValueObject printing code. The functionality is now factored into a ValueObjectPrinter class for easier maintenance in the future
DumpValueObject() was turned into an instance method ValueObject::Dump() which simply calls through to the printer code, Dump_Impl has been removed
Test case to follow
llvm-svn: 191694
2013-10-01 03:11:51 +08:00
case ' v ' :
if ( ! option_arg )
{
m_verbosity = eLanguageRuntimeDescriptionDisplayVerbosityFull ;
break ;
}
m_verbosity = ( LanguageRuntimeDescriptionDisplayVerbosity ) Args : : StringToOptionEnum ( option_arg , g_option_table [ option_idx ] . enum_values , 0 , error ) ;
if ( ! error . Success ( ) )
error . SetErrorStringWithFormat ( " unrecognized value for description-verbosity '%s' " , option_arg ) ;
break ;
2010-06-09 00:52:24 +08:00
default :
2011-10-26 08:56:27 +08:00
error . SetErrorStringWithFormat ( " invalid short option character '%c' " , short_option ) ;
2010-06-09 00:52:24 +08:00
break ;
}
return error ;
}
void
2011-10-25 14:44:01 +08:00
CommandObjectExpression : : CommandOptions : : OptionParsingStarting ( CommandInterpreter & interpreter )
2010-06-09 00:52:24 +08:00
{
2013-01-15 10:47:48 +08:00
Process * process = interpreter . GetExecutionContext ( ) . GetProcessPtr ( ) ;
if ( process ! = NULL )
{
ignore_breakpoints = process - > GetIgnoreBreakpointsInExpressions ( ) ;
unwind_on_error = process - > GetUnwindOnErrorInExpressions ( ) ;
}
else
{
ignore_breakpoints = false ;
unwind_on_error = true ;
}
2010-06-09 00:52:24 +08:00
show_summary = true ;
2012-10-17 05:41:58 +08:00
try_all_threads = true ;
timeout = 0 ;
<rdar://problem/14393032>
DumpValueObject() 2.0
This checkin restores pre-Xcode5 functionality to the "po" (expr -O) command:
- expr now has a new --description-verbosity (-v) argument, which takes either compact or full as a value (-v is the same as -vfull)
When the full mode is on, "po" will show the extended output with type name, persistent variable name and value, as in
(lldb) expr -O -v -- foo
(id) $0 = 0x000000010010baf0 {
1 = 2;
2 = 3;
}
When -v is omitted, or -vcompact is passed, the Xcode5-style output will be shown, as in
(lldb) expr -O -- foo
{
1 = 2;
2 = 3;
}
- for a non-ObjectiveC object, LLDB will still try to retrieve a summary and/or value to display
(lldb) po 5
5
-v also works in this mode
(lldb) expr -O -vfull -- 5
(int) $4 = 5
On top of that, this is a major refactoring of the ValueObject printing code. The functionality is now factored into a ValueObjectPrinter class for easier maintenance in the future
DumpValueObject() was turned into an instance method ValueObject::Dump() which simply calls through to the printer code, Dump_Impl has been removed
Test case to follow
llvm-svn: 191694
2013-10-01 03:11:51 +08:00
m_verbosity = eLanguageRuntimeDescriptionDisplayVerbosityCompact ;
2010-06-09 00:52:24 +08:00
}
2011-03-25 05:19:54 +08:00
const OptionDefinition *
2010-06-09 00:52:24 +08:00
CommandObjectExpression : : CommandOptions : : GetDefinitions ( )
{
return g_option_table ;
}
2010-09-18 09:14:36 +08:00
CommandObjectExpression : : CommandObjectExpression ( CommandInterpreter & interpreter ) :
2012-06-09 05:56:10 +08:00
CommandObjectRaw ( interpreter ,
" expression " ,
2012-10-26 02:11:24 +08:00
" Evaluate a C/ObjC/C++ expression in the current program context, using user defined variables and variables currently in scope. " ,
2012-06-09 05:56:10 +08:00
NULL ,
Expanded the flags that can be set for a command object in lldb_private::CommandObject. This list of available flags are:
enum
{
//----------------------------------------------------------------------
// eFlagRequiresTarget
//
// Ensures a valid target is contained in m_exe_ctx prior to executing
// the command. If a target doesn't exist or is invalid, the command
// will fail and CommandObject::GetInvalidTargetDescription() will be
// returned as the error. CommandObject subclasses can override the
// virtual function for GetInvalidTargetDescription() to provide custom
// strings when needed.
//----------------------------------------------------------------------
eFlagRequiresTarget = (1u << 0),
//----------------------------------------------------------------------
// eFlagRequiresProcess
//
// Ensures a valid process is contained in m_exe_ctx prior to executing
// the command. If a process doesn't exist or is invalid, the command
// will fail and CommandObject::GetInvalidProcessDescription() will be
// returned as the error. CommandObject subclasses can override the
// virtual function for GetInvalidProcessDescription() to provide custom
// strings when needed.
//----------------------------------------------------------------------
eFlagRequiresProcess = (1u << 1),
//----------------------------------------------------------------------
// eFlagRequiresThread
//
// Ensures a valid thread is contained in m_exe_ctx prior to executing
// the command. If a thread doesn't exist or is invalid, the command
// will fail and CommandObject::GetInvalidThreadDescription() will be
// returned as the error. CommandObject subclasses can override the
// virtual function for GetInvalidThreadDescription() to provide custom
// strings when needed.
//----------------------------------------------------------------------
eFlagRequiresThread = (1u << 2),
//----------------------------------------------------------------------
// eFlagRequiresFrame
//
// Ensures a valid frame is contained in m_exe_ctx prior to executing
// the command. If a frame doesn't exist or is invalid, the command
// will fail and CommandObject::GetInvalidFrameDescription() will be
// returned as the error. CommandObject subclasses can override the
// virtual function for GetInvalidFrameDescription() to provide custom
// strings when needed.
//----------------------------------------------------------------------
eFlagRequiresFrame = (1u << 3),
//----------------------------------------------------------------------
// eFlagRequiresRegContext
//
// Ensures a valid register context (from the selected frame if there
// is a frame in m_exe_ctx, or from the selected thread from m_exe_ctx)
// is availble from m_exe_ctx prior to executing the command. If a
// target doesn't exist or is invalid, the command will fail and
// CommandObject::GetInvalidRegContextDescription() will be returned as
// the error. CommandObject subclasses can override the virtual function
// for GetInvalidRegContextDescription() to provide custom strings when
// needed.
//----------------------------------------------------------------------
eFlagRequiresRegContext = (1u << 4),
//----------------------------------------------------------------------
// eFlagTryTargetAPILock
//
// Attempts to acquire the target lock if a target is selected in the
// command interpreter. If the command object fails to acquire the API
// lock, the command will fail with an appropriate error message.
//----------------------------------------------------------------------
eFlagTryTargetAPILock = (1u << 5),
//----------------------------------------------------------------------
// eFlagProcessMustBeLaunched
//
// Verifies that there is a launched process in m_exe_ctx, if there
// isn't, the command will fail with an appropriate error message.
//----------------------------------------------------------------------
eFlagProcessMustBeLaunched = (1u << 6),
//----------------------------------------------------------------------
// eFlagProcessMustBePaused
//
// Verifies that there is a paused process in m_exe_ctx, if there
// isn't, the command will fail with an appropriate error message.
//----------------------------------------------------------------------
eFlagProcessMustBePaused = (1u << 7)
};
Now each command object contains a "ExecutionContext m_exe_ctx;" member variable that gets initialized prior to running the command. The validity of the target objects in m_exe_ctx are checked to ensure that any target/process/thread/frame/reg context that are required are valid prior to executing the command. Each command object also contains a Mutex::Locker m_api_locker which gets used if eFlagTryTargetAPILock is set. This centralizes a lot of checking code that was previously and inconsistently implemented across many commands.
llvm-svn: 171990
2013-01-10 03:44:40 +08:00
eFlagProcessMustBePaused | eFlagTryTargetAPILock ) ,
2011-10-25 14:44:01 +08:00
m_option_group ( interpreter ) ,
m_format_options ( eFormatDefault ) ,
m_command_options ( ) ,
2010-10-01 02:30:25 +08:00
m_expr_line_count ( 0 ) ,
2010-06-09 00:52:24 +08:00
m_expr_lines ( )
{
SetHelpLong (
2012-10-17 05:41:58 +08:00
" Timeouts: \n \
If the expression can be evaluated statically ( without runnning code ) then it will be . \ n \
Otherwise , by default the expression will run on the current thread with a short timeout : \ n \
currently .25 seconds . If it doesn ' t return in that time , the evaluation will be interrupted \ n \
and resumed with all threads running . You can use the - a option to disable retrying on all \ n \
threads . You can use the - t option to set a shorter timeout . \ n \
2012-10-26 02:11:24 +08:00
\ n \
User defined variables : \ n \
You can define your own variables for convenience or to be used in subsequent expressions . \ n \
You define them the same way you would define variables in C . If the first character of \ n \
your user defined variable is a $ , then the variable ' s value will be available in future \ n \
expressions , otherwise it will just be available in the current expression . \ n \
\ n \
2012-10-17 05:41:58 +08:00
Examples : \ n \
2010-06-09 00:52:24 +08:00
\ n \
expr my_struct - > a = my_array [ 3 ] \ n \
expr - f bin - - ( index * 8 ) + 5 \ n \
2012-10-26 02:11:24 +08:00
expr unsigned int $ foo = 5 \ n \
2010-06-09 00:52:24 +08:00
expr char c [ ] = \ " foo \" ; c[0] \n " ) ;
2010-10-05 06:28:36 +08:00
CommandArgumentEntry arg ;
CommandArgumentData expression_arg ;
// Define the first (and only) variant of this arg.
expression_arg . arg_type = eArgTypeExpression ;
expression_arg . arg_repetition = eArgRepeatPlain ;
// There is only one variant this argument could be; put it into the argument entry.
arg . push_back ( expression_arg ) ;
// Push the data for the first argument into the m_arguments vector.
m_arguments . push_back ( arg ) ;
2011-10-25 14:44:01 +08:00
Added support for the new ".apple_objc" accelerator tables. These tables are
in the same hashed format as the ".apple_names", but they map objective C
class names to all of the methods and class functions. We need to do this
because in the DWARF the methods for Objective C are never contained in the
class definition, they are scattered about at the translation unit level and
they don't even have attributes that say the are contained within the class
itself.
Added 3 new formats which can be used to display data:
eFormatAddressInfo
eFormatHexFloat
eFormatInstruction
eFormatAddressInfo describes an address such as function+offset and file+line,
or symbol + offset, or constant data (c string, 2, 4, 8, or 16 byte constants).
The format character for this is "A", the long format is "address".
eFormatHexFloat will print out the hex float format that compilers tend to use.
The format character for this is "X", the long format is "hex float".
eFormatInstruction will print out disassembly with bytes and it will use the
current target's architecture. The format character for this is "i" (which
used to be being used for the integer format, but the integer format also has
"d", so we gave the "i" format to disassembly), the long format is
"instruction".
Mate the lldb::FormatterChoiceCriterion enumeration private as it should have
been from the start. It is very specialized and doesn't belong in the public
API.
llvm-svn: 143114
2011-10-28 01:55:14 +08:00
// Add the "--format" and "--gdb-format"
m_option_group . Append ( & m_format_options , OptionGroupFormat : : OPTION_GROUP_FORMAT | OptionGroupFormat : : OPTION_GROUP_GDB_FMT , LLDB_OPT_SET_1 ) ;
2011-10-25 14:44:01 +08:00
m_option_group . Append ( & m_command_options ) ;
2013-01-10 04:12:53 +08:00
m_option_group . Append ( & m_varobj_options , LLDB_OPT_SET_ALL , LLDB_OPT_SET_1 | LLDB_OPT_SET_2 ) ;
2011-10-25 14:44:01 +08:00
m_option_group . Finalize ( ) ;
2010-06-09 00:52:24 +08:00
}
CommandObjectExpression : : ~ CommandObjectExpression ( )
{
}
Options *
CommandObjectExpression : : GetOptions ( )
{
2011-10-25 14:44:01 +08:00
return & m_option_group ;
2010-06-09 00:52:24 +08:00
}
size_t
CommandObjectExpression : : MultiLineExpressionCallback
(
void * baton ,
2010-06-23 09:19:29 +08:00
InputReader & reader ,
2010-06-09 00:52:24 +08:00
lldb : : InputReaderAction notification ,
const char * bytes ,
size_t bytes_len
)
{
CommandObjectExpression * cmd_object_expr = ( CommandObjectExpression * ) baton ;
2011-06-17 00:27:19 +08:00
bool batch_mode = reader . GetDebugger ( ) . GetCommandInterpreter ( ) . GetBatchCommandMode ( ) ;
2010-06-09 00:52:24 +08:00
switch ( notification )
{
case eInputReaderActivate :
2011-06-17 00:27:19 +08:00
if ( ! batch_mode )
2011-06-16 03:35:17 +08:00
{
2011-07-20 11:41:06 +08:00
StreamSP async_strm_sp ( reader . GetDebugger ( ) . GetAsyncOutputStream ( ) ) ;
if ( async_strm_sp )
{
async_strm_sp - > PutCString ( " Enter expressions, then terminate with an empty line to evaluate: \n " ) ;
async_strm_sp - > Flush ( ) ;
}
2011-06-16 03:35:17 +08:00
}
2010-06-09 00:52:24 +08:00
// Fall through
case eInputReaderReactivate :
break ;
case eInputReaderDeactivate :
break ;
This patch captures and serializes all output being written by the
command line driver, including the lldb prompt being output by
editline, the asynchronous process output & error messages, and
asynchronous messages written by target stop-hooks.
As part of this it introduces a new Stream class,
StreamAsynchronousIO. A StreamAsynchronousIO object is created with a
broadcaster, who will eventually broadcast the stream's data for a
listener to handle, and an event type indicating what type of event
the broadcaster will broadcast. When the Write method is called on a
StreamAsynchronousIO object, the data is appended to an internal
string. When the Flush method is called on a StreamAsynchronousIO
object, it broadcasts it's data string and clears the string.
Anything in lldb-core that needs to generate asynchronous output for
the end-user should use the StreamAsynchronousIO objects.
I have also added a new notification type for InputReaders, to let
them know that a asynchronous output has been written. This is to
allow the input readers to, for example, refresh their prompts and
lines, if desired. I added the case statements to all the input
readers to catch this notification, but I haven't added any code for
handling them yet (except to the IOChannel input reader).
llvm-svn: 130721
2011-05-03 04:41:46 +08:00
case eInputReaderAsynchronousOutputWritten :
break ;
2010-06-09 00:52:24 +08:00
case eInputReaderGotToken :
+ + cmd_object_expr - > m_expr_line_count ;
if ( bytes & & bytes_len )
{
cmd_object_expr - > m_expr_lines . append ( bytes , bytes_len + 1 ) ;
}
if ( bytes_len = = 0 )
2010-06-23 09:19:29 +08:00
reader . SetIsDone ( true ) ;
2010-06-09 00:52:24 +08:00
break ;
2010-11-20 04:47:54 +08:00
case eInputReaderInterrupt :
cmd_object_expr - > m_expr_lines . clear ( ) ;
reader . SetIsDone ( true ) ;
2011-06-17 00:27:19 +08:00
if ( ! batch_mode )
2011-06-16 03:35:17 +08:00
{
2011-07-20 11:41:06 +08:00
StreamSP async_strm_sp ( reader . GetDebugger ( ) . GetAsyncOutputStream ( ) ) ;
if ( async_strm_sp )
{
async_strm_sp - > PutCString ( " Expression evaluation cancelled. \n " ) ;
async_strm_sp - > Flush ( ) ;
}
2011-06-16 03:35:17 +08:00
}
2010-11-20 04:47:54 +08:00
break ;
case eInputReaderEndOfFile :
reader . SetIsDone ( true ) ;
break ;
2010-06-09 00:52:24 +08:00
case eInputReaderDone :
2010-11-20 04:47:54 +08:00
if ( cmd_object_expr - > m_expr_lines . size ( ) > 0 )
2010-06-09 00:52:24 +08:00
{
2011-06-14 04:20:29 +08:00
StreamSP output_stream = reader . GetDebugger ( ) . GetAsyncOutputStream ( ) ;
StreamSP error_stream = reader . GetDebugger ( ) . GetAsyncErrorStream ( ) ;
2010-06-09 00:52:24 +08:00
cmd_object_expr - > EvaluateExpression ( cmd_object_expr - > m_expr_lines . c_str ( ) ,
2011-06-14 04:20:29 +08:00
output_stream . get ( ) ,
error_stream . get ( ) ) ;
output_stream - > Flush ( ) ;
error_stream - > Flush ( ) ;
2010-06-09 00:52:24 +08:00
}
break ;
}
return bytes_len ;
}
bool
2010-10-05 08:00:42 +08:00
CommandObjectExpression : : EvaluateExpression
(
const char * expr ,
2011-06-14 04:20:29 +08:00
Stream * output_stream ,
Stream * error_stream ,
2010-10-05 08:00:42 +08:00
CommandReturnObject * result
)
2010-06-09 00:52:24 +08:00
{
2013-01-27 07:54:29 +08:00
// Don't use m_exe_ctx as this might be called asynchronously
// after the command object DoExecute has finished when doing
// multi-line expression that use an input reader...
ExecutionContext exe_ctx ( m_interpreter . GetExecutionContext ( ) ) ;
Target * target = exe_ctx . GetTargetPtr ( ) ;
2011-10-28 05:22:25 +08:00
if ( ! target )
target = Host : : GetDummyTarget ( m_interpreter . GetDebugger ( ) ) . get ( ) ;
2011-09-22 12:58:26 +08:00
if ( target )
2010-07-23 08:16:21 +08:00
{
2010-12-14 10:59:59 +08:00
lldb : : ValueObjectSP result_valobj_sp ;
2011-03-25 05:19:54 +08:00
ExecutionResults exe_results ;
2011-01-13 16:53:35 +08:00
bool keep_in_memory = true ;
2013-01-10 04:12:53 +08:00
2012-10-17 05:41:58 +08:00
EvaluateExpressionOptions options ;
2013-01-10 04:12:53 +08:00
options . SetCoerceToId ( m_varobj_options . use_objc )
2012-09-06 04:41:26 +08:00
. SetUnwindOnError ( m_command_options . unwind_on_error )
2013-01-15 10:47:48 +08:00
. SetIgnoreBreakpoints ( m_command_options . ignore_breakpoints )
2012-09-06 04:41:26 +08:00
. SetKeepInMemory ( keep_in_memory )
2013-01-10 04:12:53 +08:00
. SetUseDynamic ( m_varobj_options . use_dynamic )
2012-10-17 05:41:58 +08:00
. SetRunOthers ( m_command_options . try_all_threads )
. SetTimeoutUsec ( m_command_options . timeout ) ;
2012-09-06 04:41:26 +08:00
2011-09-22 12:58:26 +08:00
exe_results = target - > EvaluateExpression ( expr ,
2013-01-27 07:54:29 +08:00
exe_ctx . GetFramePtr ( ) ,
2012-07-17 07:10:35 +08:00
result_valobj_sp ,
2012-09-06 04:41:26 +08:00
options ) ;
2013-07-31 03:54:09 +08:00
2010-12-14 10:59:59 +08:00
if ( result_valobj_sp )
{
2012-08-09 01:35:10 +08:00
Format format = m_format_options . GetFormat ( ) ;
2010-12-14 10:59:59 +08:00
if ( result_valobj_sp - > GetError ( ) . Success ( ) )
{
2012-08-09 01:35:10 +08:00
if ( format ! = eFormatVoid )
{
if ( format ! = eFormatDefault )
result_valobj_sp - > SetFormat ( format ) ;
<rdar://problem/14393032>
DumpValueObject() 2.0
This checkin restores pre-Xcode5 functionality to the "po" (expr -O) command:
- expr now has a new --description-verbosity (-v) argument, which takes either compact or full as a value (-v is the same as -vfull)
When the full mode is on, "po" will show the extended output with type name, persistent variable name and value, as in
(lldb) expr -O -v -- foo
(id) $0 = 0x000000010010baf0 {
1 = 2;
2 = 3;
}
When -v is omitted, or -vcompact is passed, the Xcode5-style output will be shown, as in
(lldb) expr -O -- foo
{
1 = 2;
2 = 3;
}
- for a non-ObjectiveC object, LLDB will still try to retrieve a summary and/or value to display
(lldb) po 5
5
-v also works in this mode
(lldb) expr -O -vfull -- 5
(int) $4 = 5
On top of that, this is a major refactoring of the ValueObject printing code. The functionality is now factored into a ValueObjectPrinter class for easier maintenance in the future
DumpValueObject() was turned into an instance method ValueObject::Dump() which simply calls through to the printer code, Dump_Impl has been removed
Test case to follow
llvm-svn: 191694
2013-10-01 03:11:51 +08:00
DumpValueObjectOptions options ( m_varobj_options . GetAsDumpOptions ( m_command_options . m_verbosity , format ) ) ;
2013-01-10 04:12:53 +08:00
<rdar://problem/14393032>
DumpValueObject() 2.0
This checkin restores pre-Xcode5 functionality to the "po" (expr -O) command:
- expr now has a new --description-verbosity (-v) argument, which takes either compact or full as a value (-v is the same as -vfull)
When the full mode is on, "po" will show the extended output with type name, persistent variable name and value, as in
(lldb) expr -O -v -- foo
(id) $0 = 0x000000010010baf0 {
1 = 2;
2 = 3;
}
When -v is omitted, or -vcompact is passed, the Xcode5-style output will be shown, as in
(lldb) expr -O -- foo
{
1 = 2;
2 = 3;
}
- for a non-ObjectiveC object, LLDB will still try to retrieve a summary and/or value to display
(lldb) po 5
5
-v also works in this mode
(lldb) expr -O -vfull -- 5
(int) $4 = 5
On top of that, this is a major refactoring of the ValueObject printing code. The functionality is now factored into a ValueObjectPrinter class for easier maintenance in the future
DumpValueObject() was turned into an instance method ValueObject::Dump() which simply calls through to the printer code, Dump_Impl has been removed
Test case to follow
llvm-svn: 191694
2013-10-01 03:11:51 +08:00
result_valobj_sp - > Dump ( * output_stream , options ) ;
2012-08-09 01:35:10 +08:00
if ( result )
result - > SetStatus ( eReturnStatusSuccessFinishResult ) ;
}
2010-12-14 10:59:59 +08:00
}
else
{
2011-08-24 05:20:51 +08:00
if ( result_valobj_sp - > GetError ( ) . GetError ( ) = = ClangUserExpression : : kNoResult )
2011-06-25 06:31:10 +08:00
{
2012-08-10 02:18:47 +08:00
if ( format ! = eFormatVoid & & m_interpreter . GetDebugger ( ) . GetNotifyVoid ( ) )
2012-08-09 01:35:10 +08:00
{
2012-08-10 02:18:47 +08:00
error_stream - > PutCString ( " (void) \n " ) ;
2012-08-09 01:35:10 +08:00
}
2012-08-10 02:18:47 +08:00
if ( result )
result - > SetStatus ( eReturnStatusSuccessFinishResult ) ;
2011-06-25 06:31:10 +08:00
}
else
{
2011-08-24 05:20:51 +08:00
const char * error_cstr = result_valobj_sp - > GetError ( ) . AsCString ( ) ;
if ( error_cstr & & error_cstr [ 0 ] )
{
2013-01-26 02:06:21 +08:00
const size_t error_cstr_len = strlen ( error_cstr ) ;
2011-08-24 05:20:51 +08:00
const bool ends_with_newline = error_cstr [ error_cstr_len - 1 ] = = ' \n ' ;
if ( strstr ( error_cstr , " error: " ) ! = error_cstr )
error_stream - > PutCString ( " error: " ) ;
error_stream - > Write ( error_cstr , error_cstr_len ) ;
if ( ! ends_with_newline )
error_stream - > EOL ( ) ;
}
else
{
error_stream - > PutCString ( " error: unknown error \n " ) ;
}
if ( result )
result - > SetStatus ( eReturnStatusFailed ) ;
2011-06-25 06:31:10 +08:00
}
2010-11-30 10:22:11 +08:00
}
}
2010-12-14 10:59:59 +08:00
}
else
{
2011-06-14 04:20:29 +08:00
error_stream - > Printf ( " error: invalid execution context for expression \n " ) ;
2010-12-14 10:59:59 +08:00
return false ;
2010-07-23 08:16:21 +08:00
}
2010-08-12 09:56:52 +08:00
2010-07-23 08:16:21 +08:00
return true ;
2010-06-09 00:52:24 +08:00
}
bool
2012-06-09 05:56:10 +08:00
CommandObjectExpression : : DoExecute
2010-06-09 00:52:24 +08:00
(
const char * command ,
CommandReturnObject & result
)
{
2011-10-25 14:44:01 +08:00
m_option_group . NotifyOptionParsingStarting ( ) ;
2010-06-09 00:52:24 +08:00
const char * expr = NULL ;
if ( command [ 0 ] = = ' \0 ' )
{
m_expr_lines . clear ( ) ;
m_expr_line_count = 0 ;
2010-09-18 09:14:36 +08:00
InputReaderSP reader_sp ( new InputReader ( m_interpreter . GetDebugger ( ) ) ) ;
2010-06-09 00:52:24 +08:00
if ( reader_sp )
{
Error err ( reader_sp - > Initialize ( CommandObjectExpression : : MultiLineExpressionCallback ,
this , // baton
eInputReaderGranularityLine , // token size, to pass to callback function
2010-06-23 09:19:29 +08:00
NULL , // end token
2010-06-09 00:52:24 +08:00
NULL , // prompt
true ) ) ; // echo input
if ( err . Success ( ) )
{
2010-09-18 09:14:36 +08:00
m_interpreter . GetDebugger ( ) . PushInputReader ( reader_sp ) ;
2010-06-09 00:52:24 +08:00
result . SetStatus ( eReturnStatusSuccessFinishNoResult ) ;
}
else
{
result . AppendError ( err . AsCString ( ) ) ;
result . SetStatus ( eReturnStatusFailed ) ;
}
}
else
{
result . AppendError ( " out of memory " ) ;
result . SetStatus ( eReturnStatusFailed ) ;
}
return result . Succeeded ( ) ;
}
if ( command [ 0 ] = = ' - ' )
{
// We have some options and these options MUST end with --.
const char * end_options = NULL ;
const char * s = command ;
while ( s & & s [ 0 ] )
{
end_options = : : strstr ( s , " -- " ) ;
if ( end_options )
{
end_options + = 2 ; // Get past the "--"
if ( : : isspace ( end_options [ 0 ] ) )
{
expr = end_options ;
while ( : : isspace ( * expr ) )
+ + expr ;
break ;
}
}
s = end_options ;
}
if ( end_options )
{
2010-06-23 09:19:29 +08:00
Args args ( command , end_options - command ) ;
2010-09-18 09:14:36 +08:00
if ( ! ParseOptions ( args , result ) )
2010-06-09 00:52:24 +08:00
return false ;
2011-04-13 08:18:08 +08:00
2011-10-25 14:44:01 +08:00
Error error ( m_option_group . NotifyOptionParsingFinished ( ) ) ;
2011-04-13 08:18:08 +08:00
if ( error . Fail ( ) )
{
result . AppendError ( error . AsCString ( ) ) ;
result . SetStatus ( eReturnStatusFailed ) ;
return false ;
}
2010-06-09 00:52:24 +08:00
}
}
if ( expr = = NULL )
expr = command ;
2010-06-24 08:16:27 +08:00
2011-06-14 04:20:29 +08:00
if ( EvaluateExpression ( expr , & ( result . GetOutputStream ( ) ) , & ( result . GetErrorStream ( ) ) , & result ) )
2010-08-13 08:42:30 +08:00
return true ;
result . SetStatus ( eReturnStatusFailed ) ;
return false ;
2010-06-09 00:52:24 +08:00
}