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.
//
//===----------------------------------------------------------------------===//
# include "CommandObjectExpression.h"
// C Includes
// C++ Includes
// Other libraries and framework includes
// Project includes
# include "lldb/Core/Value.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"
2015-01-16 04:08:35 +08:00
# include "lldb/Host/StringConvert.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"
2014-06-27 13:17:41 +08:00
# include "llvm/ADT/STLExtras.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 [ ] =
{
2014-07-10 00:31:49 +08:00
{ LLDB_OPT_SET_1 | LLDB_OPT_SET_2 , false , " all-threads " , ' a ' , OptionParser : : eRequiredArgument , NULL , 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 , NULL , 0 , eArgTypeBoolean , " Ignore breakpoint hits while running expressions " } ,
{ LLDB_OPT_SET_1 | LLDB_OPT_SET_2 , false , " timeout " , ' t ' , OptionParser : : eRequiredArgument , NULL , 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 , 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). " } ,
{ LLDB_OPT_SET_1 | LLDB_OPT_SET_2 , false , " debug " , ' g ' , OptionParser : : eNoArgument , NULL , NULL , 0 , eArgTypeNone , " When specified, debug the JIT code by setting a breakpoint on the first instruction and forcing breakpoints to not be ignored (-i0) and no unwinding to happen on error (-u0). " } ,
2015-07-25 08:19:39 +08:00
{ LLDB_OPT_SET_1 | LLDB_OPT_SET_2 , false , " language " , ' l ' , OptionParser : : eRequiredArgument , NULL , NULL , 0 , eArgTypeLanguage , " Specifies the Language to use when parsing the expression. If not set the target.language setting is used. " } ,
2014-07-10 00:31:49 +08:00
{ LLDB_OPT_SET_1 , false , " description-verbosity " , ' v ' , OptionParser : : eOptionalArgument , NULL , 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 ( )
{
2014-06-27 13:17:41 +08:00
return llvm : : array_lengthof ( g_option_table ) ;
2011-10-25 14:44:01 +08:00
}
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 )
{
2015-07-25 08:19:39 +08:00
case ' l ' :
language = LanguageRuntime : : GetLanguageTypeFromString ( option_arg ) ;
if ( language = = eLanguageTypeUnknown )
error . SetErrorStringWithFormat ( " unknown language type: '%s' for expression " , option_arg ) ;
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 ;
2015-01-16 04:08:35 +08:00
result = StringConvert : : ToUInt32 ( option_arg , 0 , 0 , & success ) ;
2012-10-17 05:41:58 +08:00
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 ;
2013-11-05 03:35:17 +08:00
case ' g ' :
debug = true ;
unwind_on_error = false ;
ignore_breakpoints = false ;
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
{
2014-03-26 02:47:07 +08:00
ignore_breakpoints = true ;
2013-01-15 10:47:48 +08:00
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 ;
2013-11-05 03:35:17 +08:00
debug = false ;
2015-07-25 08:19:39 +08:00
language = eLanguageTypeUnknown ;
<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 " ,
2015-07-25 08:19:39 +08:00
" Evaluate an expression in the current program context, using user defined variables and variables currently in scope. " ,
2012-06-09 05:56:10 +08:00
NULL ,
2015-05-27 13:04:35 +08:00
eCommandProcessMustBePaused | eCommandTryTargetAPILock ) ,
2014-01-28 07:43:24 +08:00
IOHandlerDelegate ( IOHandlerDelegate : : Completion : : Expression ) ,
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 ( )
{
2015-07-14 13:48:36 +08:00
SetHelpLong (
R " (
Timeouts :
) " " If the expression can be evaluated statically ( without running code ) then it will be . \
Otherwise , by default the expression will run on the current thread with a short timeout : \
currently .25 seconds . If it doesn ' t return in that time , the evaluation will be interrupted \
and resumed with all threads running . You can use the - a option to disable retrying on all \
threads . You can use the - t option to set a shorter timeout . " R " (
User defined variables :
) " " You can define your own variables for convenience or to be used in subsequent expressions . \
You define them the same way you would define variables in C . If the first character of \
your user defined variable is a $ , then the variable ' s value will be available in future \
expressions , otherwise it will just be available in the current expression . " R " (
Continuing evaluation after a breakpoint :
) " " If the \ " -i false \" option is used, and execution is interrupted by a breakpoint hit, once \
you are done with your investigation , you can either remove the expression execution frames \
from the stack with \ " thread return -x \" or if you are still interested in the expression result \
you can issue the \ " continue \" command and the expression evaluation will complete and the \
expression result will be available using the \ " thread.completed-expression \" key in the thread \
format . " R " (
Examples :
expr my_struct - > a = my_array [ 3 ]
expr - f bin - - ( index * 8 ) + 5
expr unsigned int $ foo = 5
expr char c [ ] = \ " foo \" ; c[0]) "
) ;
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
}
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 )
2014-11-22 09:42:44 +08:00
target = GetDummyTarget ( ) ;
2011-10-28 05:22:25 +08:00
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-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-11-07 08:11:47 +08:00
options . SetCoerceToId ( m_varobj_options . use_objc ) ;
options . SetUnwindOnError ( m_command_options . unwind_on_error ) ;
options . SetIgnoreBreakpoints ( m_command_options . ignore_breakpoints ) ;
options . SetKeepInMemory ( keep_in_memory ) ;
options . SetUseDynamic ( m_varobj_options . use_dynamic ) ;
options . SetTryAllThreads ( m_command_options . try_all_threads ) ;
options . SetDebug ( m_command_options . debug ) ;
2013-11-05 03:35:17 +08:00
2015-07-25 08:19:39 +08:00
// If the language was not specified, set it from target's properties
if ( m_command_options . language ! = eLanguageTypeUnknown )
options . SetLanguage ( m_command_options . language ) ;
else
options . SetLanguage ( target - > GetLanguage ( ) ) ;
2014-03-25 07:10:19 +08:00
// If there is any chance we are going to stop and want to see
// what went wrong with our expression, we should generate debug info
if ( ! m_command_options . ignore_breakpoints | |
! m_command_options . unwind_on_error )
options . SetGenerateDebugInfo ( true ) ;
2013-11-05 03:35:17 +08:00
if ( m_command_options . timeout > 0 )
options . SetTimeoutUsec ( m_command_options . timeout ) ;
2014-01-18 04:09:23 +08:00
else
options . SetTimeoutUsec ( 0 ) ;
2014-03-23 04:23:26 +08:00
target - > EvaluateExpression ( expr , exe_ctx . GetFramePtr ( ) ,
result_valobj_sp , 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
}
2014-01-28 07:43:24 +08:00
void
CommandObjectExpression : : IOHandlerInputComplete ( IOHandler & io_handler , std : : string & line )
{
io_handler . SetIsDone ( true ) ;
// StreamSP output_stream = io_handler.GetDebugger().GetAsyncOutputStream();
// StreamSP error_stream = io_handler.GetDebugger().GetAsyncErrorStream();
StreamFileSP output_sp ( io_handler . GetOutputStreamFile ( ) ) ;
StreamFileSP error_sp ( io_handler . GetErrorStreamFile ( ) ) ;
EvaluateExpression ( line . c_str ( ) ,
output_sp . get ( ) ,
error_sp . get ( ) ) ;
if ( output_sp )
output_sp - > Flush ( ) ;
if ( error_sp )
error_sp - > Flush ( ) ;
}
LineStatus
CommandObjectExpression : : IOHandlerLinesUpdated ( IOHandler & io_handler ,
StringList & lines ,
uint32_t line_idx ,
Error & error )
{
if ( line_idx = = UINT32_MAX )
{
// Remove the last line from "lines" so it doesn't appear
// in our final expression
lines . PopBack ( ) ;
error . Clear ( ) ;
return LineStatus : : Done ;
}
else if ( line_idx + 1 = = lines . GetSize ( ) )
{
// The last line was edited, if this line is empty, then we are done
// getting our multiple lines.
if ( lines [ line_idx ] . empty ( ) )
return LineStatus : : Done ;
}
return LineStatus : : Success ;
}
2014-03-14 07:42:30 +08:00
void
CommandObjectExpression : : GetMultilineExpression ( )
{
m_expr_lines . clear ( ) ;
m_expr_line_count = 0 ;
Debugger & debugger = GetCommandInterpreter ( ) . GetDebugger ( ) ;
2014-11-18 03:06:59 +08:00
bool color_prompt = debugger . GetUseColor ( ) ;
2014-03-14 07:42:30 +08:00
const bool multiple_lines = true ; // Get multiple lines
IOHandlerSP io_handler_sp ( new IOHandlerEditline ( debugger ,
2014-11-18 03:06:59 +08:00
IOHandler : : Type : : Expression ,
2014-03-14 07:42:30 +08:00
" lldb-expr " , // Name of input reader for history
NULL , // No prompt
2014-11-18 03:06:59 +08:00
NULL , // Continuation prompt
2014-03-14 07:42:30 +08:00
multiple_lines ,
2014-11-18 03:06:59 +08:00
color_prompt ,
2014-03-14 07:42:30 +08:00
1 , // Show line numbers starting at 1
* this ) ) ;
StreamFileSP output_sp ( io_handler_sp - > GetOutputStreamFile ( ) ) ;
if ( output_sp )
{
output_sp - > PutCString ( " Enter expressions, then terminate with an empty line to evaluate: \n " ) ;
output_sp - > Flush ( ) ;
}
debugger . PushIOHandler ( io_handler_sp ) ;
}
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 ' )
{
2014-03-14 07:42:30 +08:00
GetMultilineExpression ( ) ;
2010-06-09 00:52:24 +08:00
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 )
{
2015-03-02 20:46:22 +08:00
Args args ( llvm : : StringRef ( 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 ;
}
2014-03-14 07:42:30 +08:00
// No expression following options
2014-03-14 07:48:40 +08:00
if ( expr = = NULL | | expr [ 0 ] = = ' \0 ' )
2014-03-14 07:42:30 +08:00
{
GetMultilineExpression ( ) ;
return result . Succeeded ( ) ;
}
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
}