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.
//
//===----------------------------------------------------------------------===//
2011-09-17 05:41:42 +08:00
# include <string>
2016-02-20 03:33:46 +08:00
# include "CommandObjectFrame.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"
# include "lldb/Core/Value.h"
# include "lldb/Core/ValueObject.h"
# include "lldb/Core/ValueObjectVariable.h"
2013-01-29 07:47:25 +08:00
# include "lldb/DataFormatters/DataVisualization.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"
2011-02-01 09:31:41 +08:00
# include "lldb/Host/Host.h"
2017-03-23 07:33:16 +08:00
# include "lldb/Host/OptionParser.h"
2018-10-31 12:00:22 +08:00
# include "lldb/Host/StringConvert.h"
2010-06-09 00:52:24 +08:00
# include "lldb/Interpreter/CommandInterpreter.h"
# include "lldb/Interpreter/CommandReturnObject.h"
2011-10-25 14:44:01 +08:00
# include "lldb/Interpreter/OptionGroupFormat.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"
2016-09-07 04:57:50 +08:00
# include "lldb/Interpreter/Options.h"
2010-09-02 08:18:39 +08:00
# include "lldb/Symbol/ClangASTContext.h"
2016-09-07 04:57:50 +08:00
# include "lldb/Symbol/CompilerType.h"
2015-10-01 07:12:22 +08:00
# include "lldb/Symbol/Function.h"
2010-09-02 08:18:39 +08:00
# 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"
2013-11-04 17:33:30 +08:00
# include "lldb/Target/StackFrame.h"
2018-10-31 12:00:22 +08:00
# include "lldb/Target/StackFrameRecognizer.h"
Added the "frame diagnose" command and use its output to make crash info better.
When a process stops due to a crash, we get the crashing instruction and the
crashing memory location (if there is one). From the user's perspective it is
often unclear what the reason for the crash is in a symbolic sense.
To address this, I have added new fuctionality to StackFrame to parse the
disassembly and reconstruct the sequence of dereferneces and offsets that were
applied to a known variable (or fuction retrn value) to obtain the invalid
pointer.
This makes use of enhancements in the disassembler, as well as new information
provided by the DWARF expression infrastructure, and is exposed through a
"frame diagnose" command. It is also used to provide symbolic information, when
available, in the event of a crash.
The algorithm is very rudimentary, and it needs a bunch of work, including
- better parsing for assembly, preferably with help from LLVM
- support for non-Apple platforms
- cleanup of the algorithm core, preferably to make it all work in terms of
Operands instead of register/offset pairs
- improvement of the GetExpressioPath() logic to make prettier expression
paths, and
- better handling of vtables.
I welcome all suggestios, improvements, and testcases.
llvm-svn: 280692
2016-09-06 12:48:36 +08:00
# include "lldb/Target/StopInfo.h"
2010-09-02 08:18:39 +08:00
# include "lldb/Target/Target.h"
2016-09-07 04:57:50 +08:00
# include "lldb/Target/Thread.h"
2018-04-18 02:53:35 +08:00
# include "lldb/Utility/Args.h"
Added the "frame diagnose" command and use its output to make crash info better.
When a process stops due to a crash, we get the crashing instruction and the
crashing memory location (if there is one). From the user's perspective it is
often unclear what the reason for the crash is in a symbolic sense.
To address this, I have added new fuctionality to StackFrame to parse the
disassembly and reconstruct the sequence of dereferneces and offsets that were
applied to a known variable (or fuction retrn value) to obtain the invalid
pointer.
This makes use of enhancements in the disassembler, as well as new information
provided by the DWARF expression infrastructure, and is exposed through a
"frame diagnose" command. It is also used to provide symbolic information, when
available, in the event of a crash.
The algorithm is very rudimentary, and it needs a bunch of work, including
- better parsing for assembly, preferably with help from LLVM
- support for non-Apple platforms
- cleanup of the algorithm core, preferably to make it all work in terms of
Operands instead of register/offset pairs
- improvement of the GetExpressioPath() logic to make prettier expression
paths, and
- better handling of vtables.
I welcome all suggestios, improvements, and testcases.
llvm-svn: 280692
2016-09-06 12:48:36 +08:00
# include "lldb/Utility/LLDBAssert.h"
2017-02-03 05:39:50 +08:00
# include "lldb/Utility/StreamString.h"
2017-06-29 22:32:17 +08:00
# include "lldb/Utility/Timer.h"
2010-06-09 00:52:24 +08:00
using namespace lldb ;
using namespace lldb_private ;
Added the "frame diagnose" command and use its output to make crash info better.
When a process stops due to a crash, we get the crashing instruction and the
crashing memory location (if there is one). From the user's perspective it is
often unclear what the reason for the crash is in a symbolic sense.
To address this, I have added new fuctionality to StackFrame to parse the
disassembly and reconstruct the sequence of dereferneces and offsets that were
applied to a known variable (or fuction retrn value) to obtain the invalid
pointer.
This makes use of enhancements in the disassembler, as well as new information
provided by the DWARF expression infrastructure, and is exposed through a
"frame diagnose" command. It is also used to provide symbolic information, when
available, in the event of a crash.
The algorithm is very rudimentary, and it needs a bunch of work, including
- better parsing for assembly, preferably with help from LLVM
- support for non-Apple platforms
- cleanup of the algorithm core, preferably to make it all work in terms of
Operands instead of register/offset pairs
- improvement of the GetExpressioPath() logic to make prettier expression
paths, and
- better handling of vtables.
I welcome all suggestios, improvements, and testcases.
llvm-svn: 280692
2016-09-06 12:48:36 +08:00
# pragma mark CommandObjectFrameDiagnose
//-------------------------------------------------------------------------
// CommandObjectFrameInfo
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
// CommandObjectFrameDiagnose
//-------------------------------------------------------------------------
2018-09-27 02:50:19 +08:00
static constexpr OptionDefinition g_frame_diag_options [ ] = {
Convert option tables to ArrayRefs.
This change is very mechanical. All it does is change the
signature of `Options::GetDefinitions()` and `OptionGroup::
GetDefinitions()` to return an `ArrayRef<OptionDefinition>`
instead of a `const OptionDefinition *`. In the case of the
former, it deletes the sentinel entry from every table, and
in the case of the latter, it removes the `GetNumDefinitions()`
method from the interface. These are no longer necessary as
`ArrayRef` carries its own length.
In the former case, iteration was done by using a sentinel
entry, so there was no knowledge of length. Because of this
the individual option tables were allowed to be defined below
the corresponding class (after all, only a pointer was needed).
Now, however, the length must be known at compile time to
construct the `ArrayRef`, and as a result it is necessary to
move every option table before its corresponding class. This
results in this CL looking very big, but in terms of substance
there is not much here.
Differential revision: https://reviews.llvm.org/D24834
llvm-svn: 282188
2016-09-23 04:22:55 +08:00
// clang-format off
2018-09-27 02:50:19 +08:00
{ LLDB_OPT_SET_1 , false , " register " , ' r ' , OptionParser : : eRequiredArgument , nullptr , { } , 0 , eArgTypeRegisterName , " A register to diagnose. " } ,
{ LLDB_OPT_SET_1 , false , " address " , ' a ' , OptionParser : : eRequiredArgument , nullptr , { } , 0 , eArgTypeAddress , " An address to diagnose. " } ,
{ LLDB_OPT_SET_1 , false , " offset " , ' o ' , OptionParser : : eRequiredArgument , nullptr , { } , 0 , eArgTypeOffset , " An optional offset. Requires --register. " }
Convert option tables to ArrayRefs.
This change is very mechanical. All it does is change the
signature of `Options::GetDefinitions()` and `OptionGroup::
GetDefinitions()` to return an `ArrayRef<OptionDefinition>`
instead of a `const OptionDefinition *`. In the case of the
former, it deletes the sentinel entry from every table, and
in the case of the latter, it removes the `GetNumDefinitions()`
method from the interface. These are no longer necessary as
`ArrayRef` carries its own length.
In the former case, iteration was done by using a sentinel
entry, so there was no knowledge of length. Because of this
the individual option tables were allowed to be defined below
the corresponding class (after all, only a pointer was needed).
Now, however, the length must be known at compile time to
construct the `ArrayRef`, and as a result it is necessary to
move every option table before its corresponding class. This
results in this CL looking very big, but in terms of substance
there is not much here.
Differential revision: https://reviews.llvm.org/D24834
llvm-svn: 282188
2016-09-23 04:22:55 +08:00
// clang-format on
} ;
2016-09-07 04:57:50 +08:00
class CommandObjectFrameDiagnose : public CommandObjectParsed {
Added the "frame diagnose" command and use its output to make crash info better.
When a process stops due to a crash, we get the crashing instruction and the
crashing memory location (if there is one). From the user's perspective it is
often unclear what the reason for the crash is in a symbolic sense.
To address this, I have added new fuctionality to StackFrame to parse the
disassembly and reconstruct the sequence of dereferneces and offsets that were
applied to a known variable (or fuction retrn value) to obtain the invalid
pointer.
This makes use of enhancements in the disassembler, as well as new information
provided by the DWARF expression infrastructure, and is exposed through a
"frame diagnose" command. It is also used to provide symbolic information, when
available, in the event of a crash.
The algorithm is very rudimentary, and it needs a bunch of work, including
- better parsing for assembly, preferably with help from LLVM
- support for non-Apple platforms
- cleanup of the algorithm core, preferably to make it all work in terms of
Operands instead of register/offset pairs
- improvement of the GetExpressioPath() logic to make prettier expression
paths, and
- better handling of vtables.
I welcome all suggestios, improvements, and testcases.
llvm-svn: 280692
2016-09-06 12:48:36 +08:00
public :
2016-09-07 04:57:50 +08:00
class CommandOptions : public Options {
public :
CommandOptions ( ) : Options ( ) { OptionParsingStarting ( nullptr ) ; }
~ CommandOptions ( ) override = default ;
2017-05-12 12:51:55 +08:00
Status SetOptionValue ( uint32_t option_idx , llvm : : StringRef option_arg ,
ExecutionContext * execution_context ) override {
Status error ;
2016-09-07 04:57:50 +08:00
const int short_option = m_getopt_table [ option_idx ] . val ;
switch ( short_option ) {
case ' r ' :
reg = ConstString ( option_arg ) ;
break ;
case ' a ' : {
2016-11-13 00:56:47 +08:00
address . emplace ( ) ;
if ( option_arg . getAsInteger ( 0 , * address ) ) {
2016-09-07 04:57:50 +08:00
address . reset ( ) ;
error . SetErrorStringWithFormat ( " invalid address argument '%s' " ,
2016-11-13 00:56:47 +08:00
option_arg . str ( ) . c_str ( ) ) ;
Added the "frame diagnose" command and use its output to make crash info better.
When a process stops due to a crash, we get the crashing instruction and the
crashing memory location (if there is one). From the user's perspective it is
often unclear what the reason for the crash is in a symbolic sense.
To address this, I have added new fuctionality to StackFrame to parse the
disassembly and reconstruct the sequence of dereferneces and offsets that were
applied to a known variable (or fuction retrn value) to obtain the invalid
pointer.
This makes use of enhancements in the disassembler, as well as new information
provided by the DWARF expression infrastructure, and is exposed through a
"frame diagnose" command. It is also used to provide symbolic information, when
available, in the event of a crash.
The algorithm is very rudimentary, and it needs a bunch of work, including
- better parsing for assembly, preferably with help from LLVM
- support for non-Apple platforms
- cleanup of the algorithm core, preferably to make it all work in terms of
Operands instead of register/offset pairs
- improvement of the GetExpressioPath() logic to make prettier expression
paths, and
- better handling of vtables.
I welcome all suggestios, improvements, and testcases.
llvm-svn: 280692
2016-09-06 12:48:36 +08:00
}
2016-09-07 04:57:50 +08:00
} break ;
case ' o ' : {
2016-11-13 00:56:47 +08:00
offset . emplace ( ) ;
if ( option_arg . getAsInteger ( 0 , * offset ) ) {
2016-09-07 04:57:50 +08:00
offset . reset ( ) ;
error . SetErrorStringWithFormat ( " invalid offset argument '%s' " ,
2016-11-13 00:56:47 +08:00
option_arg . str ( ) . c_str ( ) ) ;
Added the "frame diagnose" command and use its output to make crash info better.
When a process stops due to a crash, we get the crashing instruction and the
crashing memory location (if there is one). From the user's perspective it is
often unclear what the reason for the crash is in a symbolic sense.
To address this, I have added new fuctionality to StackFrame to parse the
disassembly and reconstruct the sequence of dereferneces and offsets that were
applied to a known variable (or fuction retrn value) to obtain the invalid
pointer.
This makes use of enhancements in the disassembler, as well as new information
provided by the DWARF expression infrastructure, and is exposed through a
"frame diagnose" command. It is also used to provide symbolic information, when
available, in the event of a crash.
The algorithm is very rudimentary, and it needs a bunch of work, including
- better parsing for assembly, preferably with help from LLVM
- support for non-Apple platforms
- cleanup of the algorithm core, preferably to make it all work in terms of
Operands instead of register/offset pairs
- improvement of the GetExpressioPath() logic to make prettier expression
paths, and
- better handling of vtables.
I welcome all suggestios, improvements, and testcases.
llvm-svn: 280692
2016-09-06 12:48:36 +08:00
}
2016-09-07 04:57:50 +08:00
} break ;
default :
error . SetErrorStringWithFormat ( " invalid short option character '%c' " ,
short_option ) ;
break ;
}
return error ;
Added the "frame diagnose" command and use its output to make crash info better.
When a process stops due to a crash, we get the crashing instruction and the
crashing memory location (if there is one). From the user's perspective it is
often unclear what the reason for the crash is in a symbolic sense.
To address this, I have added new fuctionality to StackFrame to parse the
disassembly and reconstruct the sequence of dereferneces and offsets that were
applied to a known variable (or fuction retrn value) to obtain the invalid
pointer.
This makes use of enhancements in the disassembler, as well as new information
provided by the DWARF expression infrastructure, and is exposed through a
"frame diagnose" command. It is also used to provide symbolic information, when
available, in the event of a crash.
The algorithm is very rudimentary, and it needs a bunch of work, including
- better parsing for assembly, preferably with help from LLVM
- support for non-Apple platforms
- cleanup of the algorithm core, preferably to make it all work in terms of
Operands instead of register/offset pairs
- improvement of the GetExpressioPath() logic to make prettier expression
paths, and
- better handling of vtables.
I welcome all suggestios, improvements, and testcases.
llvm-svn: 280692
2016-09-06 12:48:36 +08:00
}
2016-09-07 04:57:50 +08:00
void OptionParsingStarting ( ExecutionContext * execution_context ) override {
address . reset ( ) ;
reg . reset ( ) ;
offset . reset ( ) ;
Added the "frame diagnose" command and use its output to make crash info better.
When a process stops due to a crash, we get the crashing instruction and the
crashing memory location (if there is one). From the user's perspective it is
often unclear what the reason for the crash is in a symbolic sense.
To address this, I have added new fuctionality to StackFrame to parse the
disassembly and reconstruct the sequence of dereferneces and offsets that were
applied to a known variable (or fuction retrn value) to obtain the invalid
pointer.
This makes use of enhancements in the disassembler, as well as new information
provided by the DWARF expression infrastructure, and is exposed through a
"frame diagnose" command. It is also used to provide symbolic information, when
available, in the event of a crash.
The algorithm is very rudimentary, and it needs a bunch of work, including
- better parsing for assembly, preferably with help from LLVM
- support for non-Apple platforms
- cleanup of the algorithm core, preferably to make it all work in terms of
Operands instead of register/offset pairs
- improvement of the GetExpressioPath() logic to make prettier expression
paths, and
- better handling of vtables.
I welcome all suggestios, improvements, and testcases.
llvm-svn: 280692
2016-09-06 12:48:36 +08:00
}
Convert option tables to ArrayRefs.
This change is very mechanical. All it does is change the
signature of `Options::GetDefinitions()` and `OptionGroup::
GetDefinitions()` to return an `ArrayRef<OptionDefinition>`
instead of a `const OptionDefinition *`. In the case of the
former, it deletes the sentinel entry from every table, and
in the case of the latter, it removes the `GetNumDefinitions()`
method from the interface. These are no longer necessary as
`ArrayRef` carries its own length.
In the former case, iteration was done by using a sentinel
entry, so there was no knowledge of length. Because of this
the individual option tables were allowed to be defined below
the corresponding class (after all, only a pointer was needed).
Now, however, the length must be known at compile time to
construct the `ArrayRef`, and as a result it is necessary to
move every option table before its corresponding class. This
results in this CL looking very big, but in terms of substance
there is not much here.
Differential revision: https://reviews.llvm.org/D24834
llvm-svn: 282188
2016-09-23 04:22:55 +08:00
llvm : : ArrayRef < OptionDefinition > GetDefinitions ( ) override {
2016-09-23 05:06:13 +08:00
return llvm : : makeArrayRef ( g_frame_diag_options ) ;
Convert option tables to ArrayRefs.
This change is very mechanical. All it does is change the
signature of `Options::GetDefinitions()` and `OptionGroup::
GetDefinitions()` to return an `ArrayRef<OptionDefinition>`
instead of a `const OptionDefinition *`. In the case of the
former, it deletes the sentinel entry from every table, and
in the case of the latter, it removes the `GetNumDefinitions()`
method from the interface. These are no longer necessary as
`ArrayRef` carries its own length.
In the former case, iteration was done by using a sentinel
entry, so there was no knowledge of length. Because of this
the individual option tables were allowed to be defined below
the corresponding class (after all, only a pointer was needed).
Now, however, the length must be known at compile time to
construct the `ArrayRef`, and as a result it is necessary to
move every option table before its corresponding class. This
results in this CL looking very big, but in terms of substance
there is not much here.
Differential revision: https://reviews.llvm.org/D24834
llvm-svn: 282188
2016-09-23 04:22:55 +08:00
}
2016-09-07 04:57:50 +08:00
// Options.
llvm : : Optional < lldb : : addr_t > address ;
llvm : : Optional < ConstString > reg ;
llvm : : Optional < int64_t > offset ;
} ;
CommandObjectFrameDiagnose ( CommandInterpreter & interpreter )
: CommandObjectParsed ( interpreter , " frame diagnose " ,
" Try to determine what path path the current stop "
" location used to get to a register or address " ,
nullptr ,
eCommandRequiresThread | eCommandTryTargetAPILock |
eCommandProcessMustBeLaunched |
eCommandProcessMustBePaused ) ,
m_options ( ) {
CommandArgumentEntry arg ;
CommandArgumentData index_arg ;
// Define the first (and only) variant of this arg.
index_arg . arg_type = eArgTypeFrameIndex ;
index_arg . arg_repetition = eArgRepeatOptional ;
// 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 ) ;
}
~ CommandObjectFrameDiagnose ( ) override = default ;
Options * GetOptions ( ) override { return & m_options ; }
protected :
bool DoExecute ( Args & command , CommandReturnObject & result ) override {
Thread * thread = m_exe_ctx . GetThreadPtr ( ) ;
StackFrameSP frame_sp = thread - > GetSelectedFrame ( ) ;
ValueObjectSP valobj_sp ;
if ( m_options . address . hasValue ( ) ) {
if ( m_options . reg . hasValue ( ) | | m_options . offset . hasValue ( ) ) {
result . AppendError (
" `frame diagnose --address` is incompatible with other arguments. " ) ;
result . SetStatus ( eReturnStatusFailed ) ;
return false ;
}
valobj_sp = frame_sp - > GuessValueForAddress ( m_options . address . getValue ( ) ) ;
} else if ( m_options . reg . hasValue ( ) ) {
valobj_sp = frame_sp - > GuessValueForRegisterAndOffset (
m_options . reg . getValue ( ) , m_options . offset . getValueOr ( 0 ) ) ;
} else {
StopInfoSP stop_info_sp = thread - > GetStopInfo ( ) ;
if ( ! stop_info_sp ) {
result . AppendError ( " No arguments provided, and no stop info. " ) ;
result . SetStatus ( eReturnStatusFailed ) ;
return false ;
}
valobj_sp = StopInfo : : GetCrashingDereference ( stop_info_sp ) ;
}
Added the "frame diagnose" command and use its output to make crash info better.
When a process stops due to a crash, we get the crashing instruction and the
crashing memory location (if there is one). From the user's perspective it is
often unclear what the reason for the crash is in a symbolic sense.
To address this, I have added new fuctionality to StackFrame to parse the
disassembly and reconstruct the sequence of dereferneces and offsets that were
applied to a known variable (or fuction retrn value) to obtain the invalid
pointer.
This makes use of enhancements in the disassembler, as well as new information
provided by the DWARF expression infrastructure, and is exposed through a
"frame diagnose" command. It is also used to provide symbolic information, when
available, in the event of a crash.
The algorithm is very rudimentary, and it needs a bunch of work, including
- better parsing for assembly, preferably with help from LLVM
- support for non-Apple platforms
- cleanup of the algorithm core, preferably to make it all work in terms of
Operands instead of register/offset pairs
- improvement of the GetExpressioPath() logic to make prettier expression
paths, and
- better handling of vtables.
I welcome all suggestios, improvements, and testcases.
llvm-svn: 280692
2016-09-06 12:48:36 +08:00
2016-09-07 04:57:50 +08:00
if ( ! valobj_sp ) {
result . AppendError ( " No diagnosis available. " ) ;
result . SetStatus ( eReturnStatusFailed ) ;
return false ;
Added the "frame diagnose" command and use its output to make crash info better.
When a process stops due to a crash, we get the crashing instruction and the
crashing memory location (if there is one). From the user's perspective it is
often unclear what the reason for the crash is in a symbolic sense.
To address this, I have added new fuctionality to StackFrame to parse the
disassembly and reconstruct the sequence of dereferneces and offsets that were
applied to a known variable (or fuction retrn value) to obtain the invalid
pointer.
This makes use of enhancements in the disassembler, as well as new information
provided by the DWARF expression infrastructure, and is exposed through a
"frame diagnose" command. It is also used to provide symbolic information, when
available, in the event of a crash.
The algorithm is very rudimentary, and it needs a bunch of work, including
- better parsing for assembly, preferably with help from LLVM
- support for non-Apple platforms
- cleanup of the algorithm core, preferably to make it all work in terms of
Operands instead of register/offset pairs
- improvement of the GetExpressioPath() logic to make prettier expression
paths, and
- better handling of vtables.
I welcome all suggestios, improvements, and testcases.
llvm-svn: 280692
2016-09-06 12:48:36 +08:00
}
2016-09-07 04:57:50 +08:00
2017-03-02 08:05:25 +08:00
DumpValueObjectOptions : : DeclPrintingHelper helper = [ & valobj_sp ] (
ConstString type , ConstString var , const DumpValueObjectOptions & opts ,
Stream & stream ) - > bool {
2016-09-07 04:57:50 +08:00
const ValueObject : : GetExpressionPathFormat format = ValueObject : :
GetExpressionPathFormat : : eGetExpressionPathFormatHonorPointers ;
2017-03-02 18:35:53 +08:00
const bool qualify_cxx_base_classes = false ;
2016-09-07 04:57:50 +08:00
valobj_sp - > GetExpressionPath ( stream , qualify_cxx_base_classes , format ) ;
stream . PutCString ( " = " ) ;
return true ;
} ;
DumpValueObjectOptions options ;
options . SetDeclPrintingHelper ( helper ) ;
ValueObjectPrinter printer ( valobj_sp . get ( ) , & result . GetOutputStream ( ) ,
options ) ;
printer . PrintValueObject ( ) ;
return true ;
}
Added the "frame diagnose" command and use its output to make crash info better.
When a process stops due to a crash, we get the crashing instruction and the
crashing memory location (if there is one). From the user's perspective it is
often unclear what the reason for the crash is in a symbolic sense.
To address this, I have added new fuctionality to StackFrame to parse the
disassembly and reconstruct the sequence of dereferneces and offsets that were
applied to a known variable (or fuction retrn value) to obtain the invalid
pointer.
This makes use of enhancements in the disassembler, as well as new information
provided by the DWARF expression infrastructure, and is exposed through a
"frame diagnose" command. It is also used to provide symbolic information, when
available, in the event of a crash.
The algorithm is very rudimentary, and it needs a bunch of work, including
- better parsing for assembly, preferably with help from LLVM
- support for non-Apple platforms
- cleanup of the algorithm core, preferably to make it all work in terms of
Operands instead of register/offset pairs
- improvement of the GetExpressioPath() logic to make prettier expression
paths, and
- better handling of vtables.
I welcome all suggestios, improvements, and testcases.
llvm-svn: 280692
2016-09-06 12:48:36 +08:00
protected :
2016-09-07 04:57:50 +08:00
CommandOptions m_options ;
Added the "frame diagnose" command and use its output to make crash info better.
When a process stops due to a crash, we get the crashing instruction and the
crashing memory location (if there is one). From the user's perspective it is
often unclear what the reason for the crash is in a symbolic sense.
To address this, I have added new fuctionality to StackFrame to parse the
disassembly and reconstruct the sequence of dereferneces and offsets that were
applied to a known variable (or fuction retrn value) to obtain the invalid
pointer.
This makes use of enhancements in the disassembler, as well as new information
provided by the DWARF expression infrastructure, and is exposed through a
"frame diagnose" command. It is also used to provide symbolic information, when
available, in the event of a crash.
The algorithm is very rudimentary, and it needs a bunch of work, including
- better parsing for assembly, preferably with help from LLVM
- support for non-Apple platforms
- cleanup of the algorithm core, preferably to make it all work in terms of
Operands instead of register/offset pairs
- improvement of the GetExpressioPath() logic to make prettier expression
paths, and
- better handling of vtables.
I welcome all suggestios, improvements, and testcases.
llvm-svn: 280692
2016-09-06 12:48:36 +08:00
} ;
2010-06-09 00:52:24 +08:00
# pragma mark CommandObjectFrameInfo
//-------------------------------------------------------------------------
// CommandObjectFrameInfo
//-------------------------------------------------------------------------
2016-09-07 04:57:50 +08:00
class CommandObjectFrameInfo : public CommandObjectParsed {
2010-06-09 00:52:24 +08:00
public :
2016-09-07 04:57:50 +08:00
CommandObjectFrameInfo ( CommandInterpreter & interpreter )
: CommandObjectParsed (
interpreter , " frame info " , " List information about the current "
" stack frame in the current thread. " ,
" frame info " ,
eCommandRequiresFrame | eCommandTryTargetAPILock |
eCommandProcessMustBeLaunched | eCommandProcessMustBePaused ) { }
2010-06-09 00:52:24 +08:00
2016-09-07 04:57:50 +08:00
~ CommandObjectFrameInfo ( ) override = default ;
2010-06-09 00:52:24 +08:00
2012-06-09 05:56:10 +08:00
protected :
2016-09-07 04:57:50 +08:00
bool DoExecute ( Args & command , CommandReturnObject & result ) override {
m_exe_ctx . GetFrameRef ( ) . DumpUsingSettingsFormat ( & result . GetOutputStream ( ) ) ;
result . SetStatus ( eReturnStatusSuccessFinishResult ) ;
return result . Succeeded ( ) ;
}
2010-06-09 00:52:24 +08:00
} ;
# pragma mark CommandObjectFrameSelect
//-------------------------------------------------------------------------
// CommandObjectFrameSelect
//-------------------------------------------------------------------------
Convert option tables to ArrayRefs.
This change is very mechanical. All it does is change the
signature of `Options::GetDefinitions()` and `OptionGroup::
GetDefinitions()` to return an `ArrayRef<OptionDefinition>`
instead of a `const OptionDefinition *`. In the case of the
former, it deletes the sentinel entry from every table, and
in the case of the latter, it removes the `GetNumDefinitions()`
method from the interface. These are no longer necessary as
`ArrayRef` carries its own length.
In the former case, iteration was done by using a sentinel
entry, so there was no knowledge of length. Because of this
the individual option tables were allowed to be defined below
the corresponding class (after all, only a pointer was needed).
Now, however, the length must be known at compile time to
construct the `ArrayRef`, and as a result it is necessary to
move every option table before its corresponding class. This
results in this CL looking very big, but in terms of substance
there is not much here.
Differential revision: https://reviews.llvm.org/D24834
llvm-svn: 282188
2016-09-23 04:22:55 +08:00
static OptionDefinition g_frame_select_options [ ] = {
// clang-format off
2018-09-27 02:50:19 +08:00
{ LLDB_OPT_SET_1 , false , " relative " , ' r ' , OptionParser : : eRequiredArgument , nullptr , { } , 0 , eArgTypeOffset , " A relative frame index offset from the current frame index. " } ,
Convert option tables to ArrayRefs.
This change is very mechanical. All it does is change the
signature of `Options::GetDefinitions()` and `OptionGroup::
GetDefinitions()` to return an `ArrayRef<OptionDefinition>`
instead of a `const OptionDefinition *`. In the case of the
former, it deletes the sentinel entry from every table, and
in the case of the latter, it removes the `GetNumDefinitions()`
method from the interface. These are no longer necessary as
`ArrayRef` carries its own length.
In the former case, iteration was done by using a sentinel
entry, so there was no knowledge of length. Because of this
the individual option tables were allowed to be defined below
the corresponding class (after all, only a pointer was needed).
Now, however, the length must be known at compile time to
construct the `ArrayRef`, and as a result it is necessary to
move every option table before its corresponding class. This
results in this CL looking very big, but in terms of substance
there is not much here.
Differential revision: https://reviews.llvm.org/D24834
llvm-svn: 282188
2016-09-23 04:22:55 +08:00
// clang-format on
} ;
2016-09-07 04:57:50 +08:00
class CommandObjectFrameSelect : public CommandObjectParsed {
2010-06-09 00:52:24 +08:00
public :
2016-09-07 04:57:50 +08:00
class CommandOptions : public Options {
public :
CommandOptions ( ) : Options ( ) { OptionParsingStarting ( nullptr ) ; }
~ CommandOptions ( ) override = default ;
2017-05-12 12:51:55 +08:00
Status SetOptionValue ( uint32_t option_idx , llvm : : StringRef option_arg ,
ExecutionContext * execution_context ) override {
Status error ;
2016-09-07 04:57:50 +08:00
const int short_option = m_getopt_table [ option_idx ] . val ;
switch ( short_option ) {
case ' r ' :
2016-11-13 00:56:47 +08:00
if ( option_arg . getAsInteger ( 0 , relative_frame_offset ) ) {
relative_frame_offset = INT32_MIN ;
2016-09-07 04:57:50 +08:00
error . SetErrorStringWithFormat ( " invalid frame offset argument '%s' " ,
2016-11-13 00:56:47 +08:00
option_arg . str ( ) . c_str ( ) ) ;
}
2016-09-07 04:57:50 +08:00
break ;
default :
error . SetErrorStringWithFormat ( " invalid short option character '%c' " ,
short_option ) ;
break ;
}
return error ;
}
2010-10-11 06:28:11 +08:00
2016-09-07 04:57:50 +08:00
void OptionParsingStarting ( ExecutionContext * execution_context ) override {
relative_frame_offset = INT32_MIN ;
}
2010-10-11 06:28:11 +08:00
Convert option tables to ArrayRefs.
This change is very mechanical. All it does is change the
signature of `Options::GetDefinitions()` and `OptionGroup::
GetDefinitions()` to return an `ArrayRef<OptionDefinition>`
instead of a `const OptionDefinition *`. In the case of the
former, it deletes the sentinel entry from every table, and
in the case of the latter, it removes the `GetNumDefinitions()`
method from the interface. These are no longer necessary as
`ArrayRef` carries its own length.
In the former case, iteration was done by using a sentinel
entry, so there was no knowledge of length. Because of this
the individual option tables were allowed to be defined below
the corresponding class (after all, only a pointer was needed).
Now, however, the length must be known at compile time to
construct the `ArrayRef`, and as a result it is necessary to
move every option table before its corresponding class. This
results in this CL looking very big, but in terms of substance
there is not much here.
Differential revision: https://reviews.llvm.org/D24834
llvm-svn: 282188
2016-09-23 04:22:55 +08:00
llvm : : ArrayRef < OptionDefinition > GetDefinitions ( ) override {
2016-09-23 05:06:13 +08:00
return llvm : : makeArrayRef ( g_frame_select_options ) ;
Convert option tables to ArrayRefs.
This change is very mechanical. All it does is change the
signature of `Options::GetDefinitions()` and `OptionGroup::
GetDefinitions()` to return an `ArrayRef<OptionDefinition>`
instead of a `const OptionDefinition *`. In the case of the
former, it deletes the sentinel entry from every table, and
in the case of the latter, it removes the `GetNumDefinitions()`
method from the interface. These are no longer necessary as
`ArrayRef` carries its own length.
In the former case, iteration was done by using a sentinel
entry, so there was no knowledge of length. Because of this
the individual option tables were allowed to be defined below
the corresponding class (after all, only a pointer was needed).
Now, however, the length must be known at compile time to
construct the `ArrayRef`, and as a result it is necessary to
move every option table before its corresponding class. This
results in this CL looking very big, but in terms of substance
there is not much here.
Differential revision: https://reviews.llvm.org/D24834
llvm-svn: 282188
2016-09-23 04:22:55 +08:00
}
2010-10-11 06:28:11 +08:00
2016-09-07 04:57:50 +08:00
int32_t relative_frame_offset ;
} ;
2016-07-15 06:03:10 +08:00
2016-09-07 04:57:50 +08:00
CommandObjectFrameSelect ( CommandInterpreter & interpreter )
: CommandObjectParsed (
interpreter , " frame select " , " Select the current stack frame by "
" index from within the current thread "
" (see 'thread backtrace'.) " ,
nullptr ,
eCommandRequiresThread | eCommandTryTargetAPILock |
eCommandProcessMustBeLaunched | eCommandProcessMustBePaused ) ,
m_options ( ) {
CommandArgumentEntry arg ;
CommandArgumentData index_arg ;
2010-10-05 06:28:36 +08:00
2016-09-07 04:57:50 +08:00
// Define the first (and only) variant of this arg.
index_arg . arg_type = eArgTypeFrameIndex ;
index_arg . arg_repetition = eArgRepeatOptional ;
2010-10-05 06:28:36 +08:00
2016-09-07 04:57:50 +08:00
// There is only one variant this argument could be; put it into the
// argument entry.
arg . push_back ( index_arg ) ;
2010-10-05 06:28:36 +08:00
2016-09-07 04:57:50 +08:00
// 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
2016-09-07 04:57:50 +08:00
~ CommandObjectFrameSelect ( ) override = default ;
2010-06-09 00:52:24 +08:00
2016-09-07 04:57:50 +08:00
Options * GetOptions ( ) override { return & m_options ; }
2010-10-11 06:28:11 +08:00
2012-06-09 05:56:10 +08:00
protected :
2016-09-07 04:57:50 +08:00
bool DoExecute ( Args & command , CommandReturnObject & result ) override {
// No need to check "thread" for validity as eCommandRequiresThread ensures
// it is valid
Thread * thread = m_exe_ctx . GetThreadPtr ( ) ;
uint32_t frame_idx = UINT32_MAX ;
if ( m_options . relative_frame_offset ! = INT32_MIN ) {
// The one and only argument is a signed relative frame index
frame_idx = thread - > GetSelectedFrameIndex ( ) ;
if ( frame_idx = = UINT32_MAX )
frame_idx = 0 ;
if ( m_options . relative_frame_offset < 0 ) {
if ( static_cast < int32_t > ( frame_idx ) > = - m_options . relative_frame_offset )
frame_idx + = m_options . relative_frame_offset ;
else {
if ( frame_idx = = 0 ) {
2018-05-01 00:49:04 +08:00
// If you are already at the bottom of the stack, then just warn
// and don't reset the frame.
2016-09-07 04:57:50 +08:00
result . AppendError ( " Already at the bottom of the stack. " ) ;
result . SetStatus ( eReturnStatusFailed ) ;
return false ;
} else
frame_idx = 0 ;
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
}
2016-09-07 04:57:50 +08:00
} else if ( m_options . relative_frame_offset > 0 ) {
// I don't want "up 20" where "20" takes you past the top of the stack
// to produce
// an error, but rather to just go to the top. So I have to count the
// stack here...
const uint32_t num_frames = thread - > GetStackFrameCount ( ) ;
if ( static_cast < int32_t > ( num_frames - frame_idx ) >
m_options . relative_frame_offset )
frame_idx + = m_options . relative_frame_offset ;
else {
if ( frame_idx = = num_frames - 1 ) {
// If we are already at the top of the stack, just warn and don't
// reset the frame.
result . AppendError ( " Already at the top of the stack. " ) ;
result . SetStatus ( eReturnStatusFailed ) ;
return false ;
} else
frame_idx = num_frames - 1 ;
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
}
2016-09-07 04:57:50 +08:00
}
} else {
2016-12-08 10:02:09 +08:00
if ( command . GetArgumentCount ( ) > 1 ) {
result . AppendErrorWithFormat (
" too many arguments; expected frame-index, saw '%s'. \n " ,
2016-12-09 09:20:58 +08:00
command [ 0 ] . c_str ( ) ) ;
2016-12-08 10:02:09 +08:00
m_options . GenerateOptionUsage (
result . GetErrorStream ( ) , this ,
GetCommandInterpreter ( ) . GetDebugger ( ) . GetTerminalWidth ( ) ) ;
return false ;
}
2016-09-07 04:57:50 +08:00
if ( command . GetArgumentCount ( ) = = 1 ) {
2016-12-08 10:02:09 +08:00
if ( command [ 0 ] . ref . getAsInteger ( 0 , frame_idx ) ) {
2016-09-07 04:57:50 +08:00
result . AppendErrorWithFormat ( " invalid frame index argument '%s'. " ,
2016-12-08 10:02:09 +08:00
command [ 0 ] . c_str ( ) ) ;
2016-09-07 04:57:50 +08:00
result . SetStatus ( eReturnStatusFailed ) ;
return false ;
2010-06-09 00:52:24 +08:00
}
2016-09-07 04:57:50 +08:00
} else if ( command . GetArgumentCount ( ) = = 0 ) {
frame_idx = thread - > GetSelectedFrameIndex ( ) ;
if ( frame_idx = = UINT32_MAX ) {
frame_idx = 0 ;
2013-02-01 05:46:01 +08:00
}
2016-09-07 04:57:50 +08:00
}
}
bool success = thread - > SetSelectedFrameByIndexNoisily (
frame_idx , result . GetOutputStream ( ) ) ;
if ( success ) {
m_exe_ctx . SetFrameSP ( thread - > GetSelectedFrame ( ) ) ;
result . SetStatus ( eReturnStatusSuccessFinishResult ) ;
} else {
result . AppendErrorWithFormat ( " Frame index (%u) out of range. \n " ,
frame_idx ) ;
result . SetStatus ( eReturnStatusFailed ) ;
2010-06-09 00:52:24 +08:00
}
2010-10-11 06:28:11 +08:00
2016-09-07 04:57:50 +08:00
return result . Succeeded ( ) ;
}
2016-02-20 03:33:46 +08:00
protected :
2016-09-07 04:57:50 +08:00
CommandOptions m_options ;
2010-10-11 06:28:11 +08:00
} ;
2010-09-02 08:18:39 +08:00
# pragma mark CommandObjectFrameVariable
//----------------------------------------------------------------------
// List images with associated information
//----------------------------------------------------------------------
2016-09-07 04:57:50 +08:00
class CommandObjectFrameVariable : public CommandObjectParsed {
2010-09-02 08:18:39 +08:00
public :
2016-09-07 04:57:50 +08:00
CommandObjectFrameVariable ( CommandInterpreter & interpreter )
: CommandObjectParsed (
interpreter , " frame variable " ,
" Show variables for the current stack frame. Defaults to all "
" arguments and local variables in scope. Names of argument, "
" local, file static and file global variables can be specified. "
" Children of aggregate variables can be specified such as "
2018-10-10 08:51:30 +08:00
" 'var->child.x'. The -> and [] operators in 'frame variable' do "
" not invoke operator overloads if they exist, but directly access "
" the specified element. If you want to trigger operator overloads "
" use the expression command to print the variable instead. "
" \n It is worth noting that except for overloaded "
" operators, when printing local variables 'expr local_var' and "
" 'frame var local_var' produce the same "
" results. However, 'frame variable' is more efficient, since it "
" uses debug information and memory reads directly, rather than "
" parsing and evaluating an expression, which may even involve "
" JITing and running code in the target program. " ,
2016-09-07 04:57:50 +08:00
nullptr , eCommandRequiresFrame | eCommandTryTargetAPILock |
eCommandProcessMustBeLaunched |
eCommandProcessMustBePaused | eCommandRequiresProcess ) ,
m_option_group ( ) ,
m_option_variable (
true ) , // Include the frame specific options by passing "true"
m_option_format ( eFormatDefault ) ,
m_varobj_options ( ) {
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 ) ;
m_option_group . Append ( & m_option_variable , LLDB_OPT_SET_ALL , LLDB_OPT_SET_1 ) ;
m_option_group . Append ( & m_option_format ,
OptionGroupFormat : : OPTION_GROUP_FORMAT |
OptionGroupFormat : : OPTION_GROUP_GDB_FMT ,
LLDB_OPT_SET_1 ) ;
m_option_group . Append ( & m_varobj_options , LLDB_OPT_SET_ALL , LLDB_OPT_SET_1 ) ;
m_option_group . Finalize ( ) ;
}
~ CommandObjectFrameVariable ( ) override = default ;
Options * GetOptions ( ) override { return & m_option_group ; }
Refactoring for for the internal command line completion API (NFC)
Summary:
This patch refactors the internal completion API. It now takes (as far as possible) a single
CompletionRequest object instead o half a dozen in/out/in-out parameters. The CompletionRequest
contains a common superset of the different parameters as far as it makes sense. This includes
the raw command line string and raw cursor position, which should make the `expr` command
possible to implement (at least without hacks that reconstruct the command line from the args).
This patch is not intended to change the observable behavior of lldb in any way. It's also as
minimal as possible and doesn't attempt to fix all the problems the API has.
Some Q&A:
Q: Why is this not fixing all the problems in the completion API?
A: Because is a blocker for the expr command completion which I want to get in ASAP. This is the
smallest patch that unblocks the expr completion patch and which allows trivial refactoring in the future.
The patch also doesn't really change the internal information flow in the API, so that hopefully
saves us from ever having to revert and resubmit this humongous patch.
Q: Can we merge all the copy-pasted code in the completion methods
(like computing the current incomplete arg) into CompletionRequest class?
A: Yes, but it's out of scope for this patch.
Q: Why the `word_complete = request.GetWordComplete(); ... ` pattern?
A: I don't want to add a getter that returns a reference to the internal integer. So we have
to use a temporary variable and the Getter/Setter instead. We don't throw exceptions
from what I can tell, so the behavior doesn't change.
Q: Why are we not owning the list of matches?
A: Because that's how the previous API works. But that should be fixed too (in another patch).
Q: Can we make the constructor simpler and compute some of the values from the plain command?
A: I think this works, but I rather want to have this in a follow up commit. Especially when making nested
request it's a bit awkward that the parsed arguments behave as both input/output (as we should in theory
propagate the changes on the nested request back to the parent request if we don't want to change the
behavior too much).
Q: Can't we pass one const request object and then just return another result object instead of mixing
them together in one in/out parameter?
A: It's hard to get keep the same behavior with that pattern, but I think we can also get a nice API with just
a single request object. If we make all input parameters read-only, we have a clear separation between what
is actually an input and what an output parameter (and hopefully we get rid of the in-out parameters).
Q: Can we throw out the 'match' variables that are not implemented according to the comment?
A: We currently just forward them as in the old code to the different methods, even though I think
they are really not used. We can easily remove and readd them once every single completion method just
takes a CompletionRequest, but for now I prefer NFC behavior from the perspective of the API user.
Reviewers: davide, jingham, labath
Reviewed By: jingham
Subscribers: mgorny, friss, lldb-commits
Differential Revision: https://reviews.llvm.org/D48796
llvm-svn: 336146
2018-07-03 05:29:56 +08:00
int HandleArgumentCompletion (
CompletionRequest & request ,
OptionElementVector & opt_element_vector ) override {
2016-09-07 04:57:50 +08:00
// Arguments are the standard source file completer.
CommandCompletions : : InvokeCommonCompletionCallbacks (
GetCommandInterpreter ( ) , CommandCompletions : : eVariablePathCompletion ,
2018-07-14 02:28:14 +08:00
request , nullptr ) ;
2018-07-28 02:42:46 +08:00
return request . GetNumberOfMatches ( ) ;
2016-09-07 04:57:50 +08:00
}
2010-09-02 08:18:39 +08:00
2012-06-09 05:56:10 +08:00
protected :
2016-10-27 03:17:49 +08:00
llvm : : StringRef GetScopeString ( VariableSP var_sp ) {
if ( ! var_sp )
return llvm : : StringRef : : withNullAsEmpty ( nullptr ) ;
switch ( var_sp - > GetScope ( ) ) {
case eValueTypeVariableGlobal :
return " GLOBAL: " ;
case eValueTypeVariableStatic :
return " STATIC: " ;
case eValueTypeVariableArgument :
return " ARG: " ;
case eValueTypeVariableLocal :
return " LOCAL: " ;
case eValueTypeVariableThreadLocal :
return " THREAD: " ;
default :
break ;
}
return llvm : : StringRef : : withNullAsEmpty ( nullptr ) ;
}
2016-09-07 04:57:50 +08:00
bool DoExecute ( Args & command , CommandReturnObject & result ) override {
2018-05-01 00:49:04 +08:00
// No need to check "frame" for validity as eCommandRequiresFrame ensures
// it is valid
2016-09-07 04:57:50 +08:00
StackFrame * frame = m_exe_ctx . GetFramePtr ( ) ;
Stream & s = result . GetOutputStream ( ) ;
// Be careful about the stack frame, if any summary formatter runs code, it
2018-05-01 00:49:04 +08:00
// might clear the StackFrameList for the thread. So hold onto a shared
// pointer to the frame so it stays alive.
2016-09-07 04:57:50 +08:00
VariableList * variable_list =
frame - > GetVariableList ( m_option_variable . show_globals ) ;
VariableSP var_sp ;
ValueObjectSP valobj_sp ;
TypeSummaryImplSP summary_format_sp ;
if ( ! m_option_variable . summary . IsCurrentValueEmpty ( ) )
DataVisualization : : NamedSummaryFormats : : GetSummaryFormat (
ConstString ( m_option_variable . summary . GetCurrentValue ( ) ) ,
summary_format_sp ) ;
else if ( ! m_option_variable . summary_string . IsCurrentValueEmpty ( ) )
summary_format_sp . reset ( new StringSummaryFormat (
TypeSummaryImpl : : Flags ( ) ,
m_option_variable . summary_string . GetCurrentValue ( ) ) ) ;
DumpValueObjectOptions options ( m_varobj_options . GetAsDumpOptions (
eLanguageRuntimeDescriptionDisplayVerbosityFull , eFormatDefault ,
summary_format_sp ) ) ;
const SymbolContext & sym_ctx =
frame - > GetSymbolContext ( eSymbolContextFunction ) ;
if ( sym_ctx . function & & sym_ctx . function - > IsTopLevelFunction ( ) )
m_option_variable . show_globals = true ;
if ( variable_list ) {
const Format format = m_option_format . GetFormat ( ) ;
options . SetFormat ( format ) ;
2016-10-06 04:03:37 +08:00
if ( ! command . empty ( ) ) {
2016-09-07 04:57:50 +08:00
VariableList regex_var_list ;
2018-05-01 00:49:04 +08:00
// If we have any args to the variable command, we will make variable
// objects from them...
2016-12-08 10:02:09 +08:00
for ( auto & entry : command ) {
2016-09-07 04:57:50 +08:00
if ( m_option_variable . use_regex ) {
const size_t regex_start_index = regex_var_list . GetSize ( ) ;
2016-12-08 10:02:09 +08:00
llvm : : StringRef name_str = entry . ref ;
2016-09-22 00:01:28 +08:00
RegularExpression regex ( name_str ) ;
if ( regex . Compile ( name_str ) ) {
2016-09-07 04:57:50 +08:00
size_t num_matches = 0 ;
const size_t num_new_regex_vars =
variable_list - > AppendVariablesIfUnique ( regex , regex_var_list ,
num_matches ) ;
if ( num_new_regex_vars > 0 ) {
for ( size_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 ) {
valobj_sp = frame - > GetValueObjectForFrameVariable (
var_sp , m_varobj_options . use_dynamic ) ;
if ( valobj_sp ) {
2016-10-27 03:17:49 +08:00
std : : string scope_string ;
if ( m_option_variable . show_scope )
scope_string = GetScopeString ( var_sp ) . str ( ) ;
if ( ! scope_string . empty ( ) )
2016-11-03 04:34:10 +08:00
s . PutCString ( scope_string ) ;
2016-10-27 03:17:49 +08:00
2016-09-07 04:57:50 +08:00
if ( m_option_variable . show_decl & &
var_sp - > GetDeclaration ( ) . GetFile ( ) ) {
bool show_fullpaths = false ;
bool show_module = true ;
if ( var_sp - > DumpDeclaration ( & s , show_fullpaths ,
show_module ) )
s . PutCString ( " : " ) ;
}
valobj_sp - > Dump ( result . GetOutputStream ( ) , options ) ;
2010-09-02 08:18:39 +08:00
}
2016-09-07 04:57:50 +08:00
}
2010-09-02 08:18:39 +08:00
}
2016-09-07 04:57:50 +08:00
} else if ( num_matches = = 0 ) {
result . GetErrorStream ( ) . Printf ( " error: no variables matched "
" the regular expression '%s'. \n " ,
2016-12-08 10:02:09 +08:00
entry . c_str ( ) ) ;
2016-09-07 04:57:50 +08:00
}
} 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: unknown regex error when compiling '%s' \n " ,
2016-12-08 10:02:09 +08:00
entry . c_str ( ) ) ;
2011-09-13 07:58:53 +08:00
}
2016-09-07 04:57:50 +08:00
} else // No regex, either exact variable names or variable
// expressions.
{
2017-05-12 12:51:55 +08:00
Status error ;
2016-09-07 04:57:50 +08:00
uint32_t expr_path_options =
StackFrame : : eExpressionPathOptionCheckPtrVsMember |
StackFrame : : eExpressionPathOptionsAllowDirectIVarAccess |
StackFrame : : eExpressionPathOptionsInspectAnonymousUnions ;
lldb : : VariableSP var_sp ;
valobj_sp = frame - > GetValueForVariableExpressionPath (
2016-12-08 10:02:09 +08:00
entry . ref , m_varobj_options . use_dynamic , expr_path_options ,
2016-09-07 04:57:50 +08:00
var_sp , error ) ;
if ( valobj_sp ) {
2016-10-27 03:17:49 +08:00
std : : string scope_string ;
if ( m_option_variable . show_scope )
scope_string = GetScopeString ( var_sp ) . str ( ) ;
if ( ! scope_string . empty ( ) )
2016-11-03 04:34:10 +08:00
s . PutCString ( scope_string ) ;
2016-09-07 04:57:50 +08:00
if ( m_option_variable . show_decl & & var_sp & &
var_sp - > GetDeclaration ( ) . GetFile ( ) ) {
var_sp - > GetDeclaration ( ) . DumpStopContext ( & s , false ) ;
s . PutCString ( " : " ) ;
}
options . SetFormat ( format ) ;
options . SetVariableFormatDisplayLanguage (
valobj_sp - > GetPreferredDisplayLanguage ( ) ) ;
Stream & output_stream = result . GetOutputStream ( ) ;
2016-12-08 10:02:09 +08:00
options . SetRootValueObjectName (
valobj_sp - > GetParent ( ) ? entry . c_str ( ) : nullptr ) ;
2016-09-07 04:57:50 +08:00
valobj_sp - > Dump ( output_stream , options ) ;
} else {
const char * error_cstr = error . AsCString ( nullptr ) ;
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 " ,
2016-12-08 10:02:09 +08:00
entry . c_str ( ) ) ;
2010-09-02 08:18:39 +08:00
}
2016-09-07 04:57:50 +08:00
}
2010-09-02 08:18:39 +08:00
}
2016-09-07 04:57:50 +08:00
} else // No command arg specified. Use variable_list, instead.
{
const size_t num_variables = variable_list - > GetSize ( ) ;
if ( num_variables > 0 ) {
for ( size_t i = 0 ; i < num_variables ; i + + ) {
var_sp = variable_list - > GetVariableAtIndex ( i ) ;
2017-06-19 14:57:54 +08:00
switch ( var_sp - > GetScope ( ) ) {
case eValueTypeVariableGlobal :
if ( ! m_option_variable . show_globals )
2017-04-19 00:52:16 +08:00
continue ;
2017-06-19 14:57:54 +08:00
break ;
case eValueTypeVariableStatic :
if ( ! m_option_variable . show_globals )
continue ;
break ;
case eValueTypeVariableArgument :
if ( ! m_option_variable . show_args )
continue ;
break ;
case eValueTypeVariableLocal :
if ( ! m_option_variable . show_locals )
continue ;
break ;
default :
continue ;
break ;
2017-04-19 00:52:16 +08:00
}
2017-06-19 14:57:54 +08:00
std : : string scope_string ;
if ( m_option_variable . show_scope )
scope_string = GetScopeString ( var_sp ) . str ( ) ;
2017-04-19 00:52:16 +08:00
2018-05-01 00:49:04 +08:00
// Use the variable object code to make sure we are using the same
// APIs as the public API will be using...
2017-04-19 00:52:16 +08:00
valobj_sp = frame - > GetValueObjectForFrameVariable (
var_sp , m_varobj_options . use_dynamic ) ;
if ( valobj_sp ) {
2018-05-01 00:49:04 +08:00
// When dumping all variables, don't print any variables that are
// not in scope to avoid extra unneeded output
2017-04-19 00:52:16 +08:00
if ( valobj_sp - > IsInScope ( ) ) {
if ( ! valobj_sp - > GetTargetSP ( )
- > GetDisplayRuntimeSupportValues ( ) & &
valobj_sp - > IsRuntimeSupportValue ( ) )
continue ;
if ( ! scope_string . empty ( ) )
s . PutCString ( scope_string ) ;
if ( m_option_variable . show_decl & &
var_sp - > GetDeclaration ( ) . GetFile ( ) ) {
var_sp - > GetDeclaration ( ) . DumpStopContext ( & s , false ) ;
s . PutCString ( " : " ) ;
2016-09-07 04:57:50 +08:00
}
2017-04-19 00:52:16 +08:00
options . SetFormat ( format ) ;
options . SetVariableFormatDisplayLanguage (
valobj_sp - > GetPreferredDisplayLanguage ( ) ) ;
options . SetRootValueObjectName (
var_sp ? var_sp - > GetName ( ) . AsCString ( ) : nullptr ) ;
valobj_sp - > Dump ( result . GetOutputStream ( ) , options ) ;
2016-09-07 04:57:50 +08:00
}
}
}
2011-08-13 00:42:31 +08:00
}
2016-09-07 04:57:50 +08:00
}
result . SetStatus ( eReturnStatusSuccessFinishResult ) ;
2010-09-02 08:18:39 +08:00
}
2018-10-31 12:00:22 +08:00
if ( m_option_variable . show_recognized_args ) {
auto recognized_frame = frame - > GetRecognizedFrame ( ) ;
if ( recognized_frame ) {
ValueObjectListSP recognized_arg_list =
recognized_frame - > GetRecognizedArguments ( ) ;
if ( recognized_arg_list ) {
for ( auto & rec_value_sp : recognized_arg_list - > GetObjects ( ) ) {
options . SetFormat ( m_option_format . GetFormat ( ) ) ;
options . SetVariableFormatDisplayLanguage (
rec_value_sp - > GetPreferredDisplayLanguage ( ) ) ;
options . SetRootValueObjectName ( rec_value_sp - > GetName ( ) . AsCString ( ) ) ;
rec_value_sp - > Dump ( result . GetOutputStream ( ) , options ) ;
}
}
}
}
2016-09-07 04:57:50 +08:00
if ( m_interpreter . TruncationWarningNecessary ( ) ) {
result . GetOutputStream ( ) . Printf ( m_interpreter . TruncationWarningText ( ) ,
m_cmd_name . c_str ( ) ) ;
m_interpreter . TruncationWarningGiven ( ) ;
}
2018-04-14 02:02:39 +08:00
// Increment statistics.
bool res = result . Succeeded ( ) ;
2018-04-14 02:37:14 +08:00
Target * target = GetSelectedOrDummyTarget ( ) ;
2018-04-14 02:02:39 +08:00
if ( res )
target - > IncrementStats ( StatisticKind : : FrameVarSuccess ) ;
else
target - > IncrementStats ( StatisticKind : : FrameVarFailure ) ;
return res ;
2016-09-07 04:57:50 +08:00
}
2016-02-20 03:33:46 +08:00
protected :
2016-09-07 04:57:50 +08:00
OptionGroupOptions m_option_group ;
OptionGroupVariable m_option_variable ;
OptionGroupFormat m_option_format ;
OptionGroupValueObjectDisplay m_varobj_options ;
2010-09-02 08:18:39 +08:00
} ;
2018-10-31 12:00:22 +08:00
# pragma mark CommandObjectFrameRecognizer
static OptionDefinition g_frame_recognizer_add_options [ ] = {
// clang-format off
{ LLDB_OPT_SET_ALL , false , " shlib " , ' s ' , OptionParser : : eRequiredArgument , nullptr , { } , CommandCompletions : : eModuleCompletion , eArgTypeShlibName , " Name of the module or shared library that this recognizer applies to. " } ,
{ LLDB_OPT_SET_ALL , false , " function " , ' n ' , OptionParser : : eRequiredArgument , nullptr , { } , CommandCompletions : : eSymbolCompletion , eArgTypeName , " Name of the function that this recognizer applies to. " } ,
{ LLDB_OPT_SET_2 , false , " python-class " , ' l ' , OptionParser : : eRequiredArgument , nullptr , { } , 0 , eArgTypePythonClass , " Give the name of a Python class to use for this frame recognizer. " } ,
{ LLDB_OPT_SET_ALL , false , " regex " , ' x ' , OptionParser : : eNoArgument , nullptr , { } , 0 , eArgTypeNone , " Function name and module name are actually regular expressions. " }
// clang-format on
} ;
class CommandObjectFrameRecognizerAdd : public CommandObjectParsed {
private :
class CommandOptions : public Options {
public :
CommandOptions ( ) : Options ( ) { }
~ CommandOptions ( ) override = default ;
Status SetOptionValue ( uint32_t option_idx , llvm : : StringRef option_arg ,
ExecutionContext * execution_context ) override {
Status error ;
const int short_option = m_getopt_table [ option_idx ] . val ;
switch ( short_option ) {
case ' l ' :
m_class_name = std : : string ( option_arg ) ;
break ;
case ' s ' :
m_module = std : : string ( option_arg ) ;
break ;
case ' n ' :
m_function = std : : string ( option_arg ) ;
break ;
case ' x ' :
m_regex = true ;
break ;
default :
error . SetErrorStringWithFormat ( " unrecognized option '%c' " ,
short_option ) ;
break ;
}
return error ;
}
void OptionParsingStarting ( ExecutionContext * execution_context ) override {
m_module = " " ;
m_function = " " ;
m_class_name = " " ;
m_regex = false ;
}
llvm : : ArrayRef < OptionDefinition > GetDefinitions ( ) override {
return llvm : : makeArrayRef ( g_frame_recognizer_add_options ) ;
}
// Instance variables to hold the values for command options.
std : : string m_class_name ;
std : : string m_module ;
std : : string m_function ;
bool m_regex ;
} ;
CommandOptions m_options ;
Options * GetOptions ( ) override { return & m_options ; }
protected :
bool DoExecute ( Args & command , CommandReturnObject & result ) override ;
public :
CommandObjectFrameRecognizerAdd ( CommandInterpreter & interpreter )
: CommandObjectParsed ( interpreter , " frame recognizer add " ,
" Add a new frame recognizer. " , nullptr ) ,
m_options ( ) {
SetHelpLong ( R " (
Frame recognizers allow for retrieving information about special frames based on
ABI , arguments or other special properties of that frame , even without source
code or debug info . Currently , one use case is to extract function arguments
that would otherwise be unaccesible , or augment existing arguments .
Adding a custom frame recognizer is possible by implementing a Python class
and using the ' frame recognizer add ' command . The Python class should have a
' get_recognized_arguments ' method and it will receive an argument of type
lldb . SBFrame representing the current frame that we are trying to recognize .
The method should return a ( possibly empty ) list of lldb . SBValue objects that
represent the recognized arguments .
An example of a recognizer that retrieves the file descriptor values from libc
functions ' read ' , ' write ' and ' close ' follows :
class LibcFdRecognizer ( object ) :
def get_recognized_arguments ( self , frame ) :
if frame . name in [ " read " , " write " , " close " ] :
fd = frame . EvaluateExpression ( " $arg1 " ) . unsigned
value = lldb . target . CreateValueFromExpression ( " fd " , " (int)%d " % fd )
return [ value ]
return [ ]
The file containing this implementation can be imported via ' command script
import ' and then we can register this recognizer with ' frame recognizer add ' .
It ' s important to restrict the recognizer to the libc library ( which is
libsystem_kernel . dylib on macOS ) to avoid matching functions with the same name
in other modules :
( lldb ) command script import . . . / fd_recognizer . py
( lldb ) frame recognizer add - l fd_recognizer . LibcFdRecognizer - n read - s libsystem_kernel . dylib
When the program is stopped at the beginning of the ' read ' function in libc , we
can view the recognizer arguments in ' frame variable ' :
( lldb ) b read
( lldb ) r
Process 1234 stopped
* thread # 1 , queue = ' com . apple . main - thread ' , stop reason = breakpoint 1.3
frame # 0 : 0x00007fff06013ca0 libsystem_kernel . dylib ` read
( lldb ) frame variable
( int ) fd = 3
) " );
}
~ CommandObjectFrameRecognizerAdd ( ) override = default ;
} ;
bool CommandObjectFrameRecognizerAdd : : DoExecute ( Args & command ,
CommandReturnObject & result ) {
2018-10-31 12:43:09 +08:00
# ifndef LLDB_DISABLE_PYTHON
2018-10-31 12:00:22 +08:00
if ( m_options . m_class_name . empty ( ) ) {
result . AppendErrorWithFormat (
" %s needs a Python class name (-l argument). \n " , m_cmd_name . c_str ( ) ) ;
result . SetStatus ( eReturnStatusFailed ) ;
return false ;
}
if ( m_options . m_module . empty ( ) ) {
result . AppendErrorWithFormat ( " %s needs a module name (-s argument). \n " ,
m_cmd_name . c_str ( ) ) ;
result . SetStatus ( eReturnStatusFailed ) ;
return false ;
}
if ( m_options . m_function . empty ( ) ) {
result . AppendErrorWithFormat ( " %s needs a function name (-n argument). \n " ,
m_cmd_name . c_str ( ) ) ;
result . SetStatus ( eReturnStatusFailed ) ;
return false ;
}
ScriptInterpreter * interpreter = m_interpreter . GetScriptInterpreter ( ) ;
if ( interpreter & &
! interpreter - > CheckObjectExists ( m_options . m_class_name . c_str ( ) ) ) {
result . AppendWarning (
" The provided class does not exist - please define it "
" before attempting to use this frame recognizer " ) ;
}
StackFrameRecognizerSP recognizer_sp =
StackFrameRecognizerSP ( new ScriptedStackFrameRecognizer (
interpreter , m_options . m_class_name . c_str ( ) ) ) ;
if ( m_options . m_regex ) {
auto module =
RegularExpressionSP ( new RegularExpression ( m_options . m_module ) ) ;
auto func =
RegularExpressionSP ( new RegularExpression ( m_options . m_function ) ) ;
StackFrameRecognizerManager : : AddRecognizer ( recognizer_sp , module , func ) ;
} else {
auto module = ConstString ( m_options . m_module ) ;
auto func = ConstString ( m_options . m_function ) ;
StackFrameRecognizerManager : : AddRecognizer ( recognizer_sp , module , func ) ;
}
2018-10-31 12:43:09 +08:00
# endif
2018-10-31 12:00:22 +08:00
result . SetStatus ( eReturnStatusSuccessFinishNoResult ) ;
return result . Succeeded ( ) ;
}
class CommandObjectFrameRecognizerClear : public CommandObjectParsed {
public :
CommandObjectFrameRecognizerClear ( CommandInterpreter & interpreter )
: CommandObjectParsed ( interpreter , " frame recognizer clear " ,
" Delete all frame recognizers. " , nullptr ) { }
~ CommandObjectFrameRecognizerClear ( ) override = default ;
protected :
bool DoExecute ( Args & command , CommandReturnObject & result ) override {
StackFrameRecognizerManager : : RemoveAllRecognizers ( ) ;
result . SetStatus ( eReturnStatusSuccessFinishResult ) ;
return result . Succeeded ( ) ;
}
} ;
class CommandObjectFrameRecognizerDelete : public CommandObjectParsed {
public :
CommandObjectFrameRecognizerDelete ( CommandInterpreter & interpreter )
: CommandObjectParsed ( interpreter , " frame recognizer delete " ,
" Delete an existing frame recognizer. " , nullptr ) { }
~ CommandObjectFrameRecognizerDelete ( ) override = default ;
protected :
bool DoExecute ( Args & command , CommandReturnObject & result ) override {
if ( command . GetArgumentCount ( ) = = 0 ) {
if ( ! m_interpreter . Confirm (
" About to delete all frame recognizers, do you want to do that? " ,
true ) ) {
result . AppendMessage ( " Operation cancelled... " ) ;
result . SetStatus ( eReturnStatusFailed ) ;
return false ;
}
StackFrameRecognizerManager : : RemoveAllRecognizers ( ) ;
result . SetStatus ( eReturnStatusSuccessFinishResult ) ;
return result . Succeeded ( ) ;
}
if ( command . GetArgumentCount ( ) ! = 1 ) {
result . AppendErrorWithFormat ( " '%s' takes zero or one arguments. \n " ,
m_cmd_name . c_str ( ) ) ;
result . SetStatus ( eReturnStatusFailed ) ;
return false ;
}
uint32_t recognizer_id =
StringConvert : : ToUInt32 ( command . GetArgumentAtIndex ( 0 ) , 0 , 0 ) ;
StackFrameRecognizerManager : : RemoveRecognizerWithID ( recognizer_id ) ;
result . SetStatus ( eReturnStatusSuccessFinishResult ) ;
return result . Succeeded ( ) ;
}
} ;
class CommandObjectFrameRecognizerList : public CommandObjectParsed {
public :
CommandObjectFrameRecognizerList ( CommandInterpreter & interpreter )
: CommandObjectParsed ( interpreter , " frame recognizer list " ,
" Show a list of active frame recognizers. " ,
nullptr ) { }
~ CommandObjectFrameRecognizerList ( ) override = default ;
protected :
bool DoExecute ( Args & command , CommandReturnObject & result ) override {
bool any_printed = false ;
StackFrameRecognizerManager : : ForEach (
[ & result , & any_printed ] ( uint32_t recognizer_id , std : : string name ,
std : : string function , std : : string symbol ,
bool regexp ) {
if ( name = = " " ) name = " (internal) " ;
result . GetOutputStream ( ) . Printf (
" %d: %s, module %s, function %s%s \n " , recognizer_id , name . c_str ( ) ,
function . c_str ( ) , symbol . c_str ( ) , regexp ? " (regexp) " : " " ) ;
any_printed = true ;
} ) ;
if ( any_printed )
result . SetStatus ( eReturnStatusSuccessFinishResult ) ;
else {
result . GetOutputStream ( ) . PutCString ( " no matching results found. \n " ) ;
result . SetStatus ( eReturnStatusSuccessFinishNoResult ) ;
}
return result . Succeeded ( ) ;
}
} ;
class CommandObjectFrameRecognizerInfo : public CommandObjectParsed {
public :
CommandObjectFrameRecognizerInfo ( CommandInterpreter & interpreter )
: CommandObjectParsed (
interpreter , " frame recognizer info " ,
" Show which frame recognizer is applied a stack frame (if any). " ,
nullptr ) {
CommandArgumentEntry arg ;
CommandArgumentData index_arg ;
// Define the first (and only) variant of this arg.
index_arg . arg_type = eArgTypeFrameIndex ;
index_arg . arg_repetition = eArgRepeatPlain ;
// 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 ) ;
}
~ CommandObjectFrameRecognizerInfo ( ) override = default ;
protected :
bool DoExecute ( Args & command , CommandReturnObject & result ) override {
Process * process = m_exe_ctx . GetProcessPtr ( ) ;
if ( process = = nullptr ) {
result . AppendError ( " no process " ) ;
result . SetStatus ( eReturnStatusFailed ) ;
return false ;
}
Thread * thread = m_exe_ctx . GetThreadPtr ( ) ;
if ( thread = = nullptr ) {
result . AppendError ( " no thread " ) ;
result . SetStatus ( eReturnStatusFailed ) ;
return false ;
}
if ( command . GetArgumentCount ( ) ! = 1 ) {
result . AppendErrorWithFormat (
" '%s' takes exactly one frame index argument. \n " , m_cmd_name . c_str ( ) ) ;
result . SetStatus ( eReturnStatusFailed ) ;
return false ;
}
uint32_t frame_index =
StringConvert : : ToUInt32 ( command . GetArgumentAtIndex ( 0 ) , 0 , 0 ) ;
StackFrameSP frame_sp = thread - > GetStackFrameAtIndex ( frame_index ) ;
if ( ! frame_sp ) {
result . AppendErrorWithFormat ( " no frame with index %u " , frame_index ) ;
result . SetStatus ( eReturnStatusFailed ) ;
return false ;
}
auto recognizer =
StackFrameRecognizerManager : : GetRecognizerForFrame ( frame_sp ) ;
Stream & output_stream = result . GetOutputStream ( ) ;
output_stream . Printf ( " frame %d " , frame_index ) ;
if ( recognizer ) {
output_stream < < " is recognized by " ;
output_stream < < recognizer - > GetName ( ) ;
} else {
output_stream < < " not recognized by any recognizer " ;
}
output_stream . EOL ( ) ;
result . SetStatus ( eReturnStatusSuccessFinishResult ) ;
return result . Succeeded ( ) ;
}
} ;
class CommandObjectFrameRecognizer : public CommandObjectMultiword {
public :
CommandObjectFrameRecognizer ( CommandInterpreter & interpreter )
: CommandObjectMultiword (
interpreter , " frame recognizer " ,
" Commands for editing and viewing frame recognizers. " ,
" frame recognizer [<sub-command-options>] " ) {
LoadSubCommand (
" add " ,
CommandObjectSP ( new CommandObjectFrameRecognizerAdd ( interpreter ) ) ) ;
LoadSubCommand (
" clear " ,
CommandObjectSP ( new CommandObjectFrameRecognizerClear ( interpreter ) ) ) ;
LoadSubCommand (
" delete " ,
CommandObjectSP ( new CommandObjectFrameRecognizerDelete ( interpreter ) ) ) ;
LoadSubCommand (
" list " ,
CommandObjectSP ( new CommandObjectFrameRecognizerList ( interpreter ) ) ) ;
LoadSubCommand (
" info " ,
CommandObjectSP ( new CommandObjectFrameRecognizerInfo ( interpreter ) ) ) ;
}
~ CommandObjectFrameRecognizer ( ) override = default ;
} ;
2010-06-09 00:52:24 +08:00
# pragma mark CommandObjectMultiwordFrame
//-------------------------------------------------------------------------
// CommandObjectMultiwordFrame
//-------------------------------------------------------------------------
2016-09-07 04:57:50 +08:00
CommandObjectMultiwordFrame : : CommandObjectMultiwordFrame (
CommandInterpreter & interpreter )
: CommandObjectMultiword ( interpreter , " frame " , " Commands for selecting and "
" examing the current "
" thread's stack frames. " ,
" frame <subcommand> [<subcommand-options>] " ) {
LoadSubCommand ( " diagnose " ,
CommandObjectSP ( new CommandObjectFrameDiagnose ( interpreter ) ) ) ;
LoadSubCommand ( " info " ,
CommandObjectSP ( new CommandObjectFrameInfo ( interpreter ) ) ) ;
LoadSubCommand ( " select " ,
CommandObjectSP ( new CommandObjectFrameSelect ( interpreter ) ) ) ;
LoadSubCommand ( " variable " ,
CommandObjectSP ( new CommandObjectFrameVariable ( interpreter ) ) ) ;
2018-10-31 12:00:22 +08:00
# ifndef LLDB_DISABLE_PYTHON
LoadSubCommand (
" recognizer " ,
CommandObjectSP ( new CommandObjectFrameRecognizer ( interpreter ) ) ) ;
# endif
2010-06-09 00:52:24 +08:00
}
2016-02-20 03:33:46 +08:00
CommandObjectMultiwordFrame : : ~ CommandObjectMultiwordFrame ( ) = default ;