2010-06-09 00:52:24 +08:00
//===-- CommandObjectArgs.cpp -----------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// C Includes
// C++ Includes
// Other libraries and framework includes
// Project includes
2016-02-20 03:33:46 +08:00
# include "CommandObjectArgs.h"
2016-09-07 04:57:50 +08:00
# include "Plugins/ExpressionParser/Clang/ClangExpressionVariable.h"
<rdar://problem/11757916>
Make breakpoint setting by file and line much more efficient by only looking for inlined breakpoint locations if we are setting a breakpoint in anything but a source implementation file. Implementing this complex for a many reasons. Turns out that parsing compile units lazily had some issues with respect to how we need to do things with DWARF in .o files. So the fixes in the checkin for this makes these changes:
- Add a new setting called "target.inline-breakpoint-strategy" which can be set to "never", "always", or "headers". "never" will never try and set any inlined breakpoints (fastest). "always" always looks for inlined breakpoint locations (slowest, but most accurate). "headers", which is the default setting, will only look for inlined breakpoint locations if the breakpoint is set in what are consudered to be header files, which is realy defined as "not in an implementation source file".
- modify the breakpoint setting by file and line to check the current "target.inline-breakpoint-strategy" setting and act accordingly
- Modify compile units to be able to get their language and other info lazily. This allows us to create compile units from the debug map and not have to fill all of the details in, and then lazily discover this information as we go on debuggging. This is needed to avoid parsing all .o files when setting breakpoints in implementation only files (no inlines). Otherwise we would need to parse the .o file, the object file (mach-o in our case) and the symbol file (DWARF in the object file) just to see what the compile unit was.
- modify the "SymbolFileDWARFDebugMap" to subclass lldb_private::Module so that the virtual "GetObjectFile()" and "GetSymbolVendor()" functions can be intercepted when the .o file contenst are later lazilly needed. Prior to this fix, when we first instantiated the "SymbolFileDWARFDebugMap" class, we would also make modules, object files and symbol files for every .o file in the debug map because we needed to fix up the sections in the .o files with information that is in the executable debug map. Now we lazily do this in the DebugMapModule::GetObjectFile()
Cleaned up header includes a bit as well.
llvm-svn: 162860
2012-08-30 05:13:06 +08:00
# include "lldb/Core/Debugger.h"
# include "lldb/Core/Module.h"
2010-06-09 00:52:24 +08:00
# include "lldb/Core/Value.h"
# include "lldb/Host/Host.h"
2017-03-23 07:33:16 +08:00
# include "lldb/Host/OptionParser.h"
2016-09-07 04:57:50 +08:00
# include "lldb/Interpreter/Args.h"
2010-06-09 00:52:24 +08:00
# include "lldb/Interpreter/CommandInterpreter.h"
# include "lldb/Interpreter/CommandReturnObject.h"
2015-03-04 07:11:11 +08:00
# include "lldb/Symbol/ClangASTContext.h"
2010-06-09 00:52:24 +08:00
# include "lldb/Symbol/ObjectFile.h"
# include "lldb/Symbol/Variable.h"
2015-03-04 03:23:09 +08:00
# include "lldb/Target/ABI.h"
2010-06-09 00:52:24 +08:00
# include "lldb/Target/Process.h"
2016-09-07 04:57:50 +08:00
# include "lldb/Target/StackFrame.h"
2010-06-09 00:52:24 +08:00
# include "lldb/Target/Target.h"
# include "lldb/Target/Thread.h"
2016-10-06 04:03:37 +08:00
# include "llvm/ADT/StringSwitch.h"
2010-06-09 00:52:24 +08:00
using namespace lldb ;
using namespace lldb_private ;
2016-09-07 04:57:50 +08:00
// This command is a toy. I'm just using it to have a way to construct the
// arguments to
2010-06-09 00:52:24 +08:00
// calling functions.
//
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_arg_options [ ] = {
// clang-format off
{ LLDB_OPT_SET_1 , false , " debug " , ' g ' , OptionParser : : eNoArgument , nullptr , nullptr , 0 , eArgTypeNone , " Enable verbose debug logging of the expression parsing and evaluation. " } ,
// clang-format on
} ;
2016-09-07 04:57:50 +08:00
CommandObjectArgs : : CommandOptions : : CommandOptions (
CommandInterpreter & interpreter )
: Options ( ) {
// Keep only one place to reset the values to their defaults
OptionParsingStarting ( nullptr ) ;
2010-06-09 00:52:24 +08:00
}
2016-02-20 03:33:46 +08:00
CommandObjectArgs : : CommandOptions : : ~ CommandOptions ( ) = default ;
2010-06-09 00:52:24 +08:00
2017-05-12 12:51:55 +08:00
Status CommandObjectArgs : : CommandOptions : : SetOptionValue (
2016-11-13 00:56:47 +08:00
uint32_t option_idx , llvm : : StringRef option_arg ,
2016-09-07 04:57:50 +08:00
ExecutionContext * execution_context ) {
2017-05-12 12:51:55 +08:00
Status error ;
2010-06-09 00:52:24 +08:00
2016-09-07 04:57:50 +08:00
const int short_option = m_getopt_table [ option_idx ] . val ;
error . SetErrorStringWithFormat ( " invalid short option character '%c' " ,
short_option ) ;
2010-06-09 00:52:24 +08:00
2016-09-07 04:57:50 +08:00
return error ;
2010-06-09 00:52:24 +08:00
}
2016-09-07 04:57:50 +08:00
void CommandObjectArgs : : CommandOptions : : OptionParsingStarting (
ExecutionContext * execution_context ) { }
2010-06-09 00:52:24 +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 >
CommandObjectArgs : : CommandOptions : : GetDefinitions ( ) {
2016-09-23 05:06:13 +08:00
return llvm : : makeArrayRef ( g_arg_options ) ;
2010-06-09 00:52:24 +08:00
}
2016-09-07 04:57:50 +08:00
CommandObjectArgs : : CommandObjectArgs ( CommandInterpreter & interpreter )
: CommandObjectParsed ( interpreter , " args " ,
" When stopped at the start of a function, reads "
" function arguments of type (u?)int(8|16|32|64)_t, "
" (void|char)* " ,
" args " ) ,
m_options ( interpreter ) { }
2016-02-20 03:33:46 +08:00
2016-09-07 04:57:50 +08:00
CommandObjectArgs : : ~ CommandObjectArgs ( ) = default ;
Options * CommandObjectArgs : : GetOptions ( ) { return & m_options ; }
bool CommandObjectArgs : : DoExecute ( Args & args , CommandReturnObject & result ) {
ConstString target_triple ;
Process * process = m_exe_ctx . GetProcessPtr ( ) ;
if ( ! process ) {
result . AppendError ( " Args found no process. " ) ;
result . SetStatus ( eReturnStatusFailed ) ;
return false ;
}
const ABI * abi = process - > GetABI ( ) . get ( ) ;
if ( ! abi ) {
result . AppendError ( " The current process has no ABI. " ) ;
result . SetStatus ( eReturnStatusFailed ) ;
return false ;
}
2016-10-06 04:03:37 +08:00
if ( args . empty ( ) ) {
2016-09-07 04:57:50 +08:00
result . AppendError ( " args requires at least one argument " ) ;
result . SetStatus ( eReturnStatusFailed ) ;
return false ;
}
Thread * thread = m_exe_ctx . GetThreadPtr ( ) ;
if ( ! thread ) {
result . AppendError ( " args found no thread. " ) ;
result . SetStatus ( eReturnStatusFailed ) ;
return false ;
}
lldb : : StackFrameSP thread_cur_frame = thread - > GetSelectedFrame ( ) ;
if ( ! thread_cur_frame ) {
result . AppendError ( " The current thread has no current frame. " ) ;
result . SetStatus ( eReturnStatusFailed ) ;
return false ;
}
ModuleSP thread_module_sp (
thread_cur_frame - > GetFrameCodeAddress ( ) . GetModule ( ) ) ;
if ( ! thread_module_sp ) {
result . AppendError ( " The PC has no associated module. " ) ;
result . SetStatus ( eReturnStatusFailed ) ;
return false ;
}
TypeSystem * type_system =
thread_module_sp - > GetTypeSystemForLanguage ( eLanguageTypeC ) ;
if ( type_system = = nullptr ) {
result . AppendError ( " Unable to create C type system. " ) ;
result . SetStatus ( eReturnStatusFailed ) ;
return false ;
}
ValueList value_list ;
2016-10-06 04:03:37 +08:00
for ( auto & arg_entry : args . entries ( ) ) {
llvm : : StringRef arg_type = arg_entry . ref ;
2016-09-07 04:57:50 +08:00
Value value ;
value . SetValueType ( Value : : eValueTypeScalar ) ;
CompilerType compiler_type ;
2016-10-06 04:03:37 +08:00
std : : size_t int_pos = arg_type . find ( " int " ) ;
if ( int_pos ! = llvm : : StringRef : : npos ) {
2016-09-07 04:57:50 +08:00
Encoding encoding = eEncodingSint ;
int width = 0 ;
2016-10-06 04:03:37 +08:00
if ( int_pos > 1 ) {
result . AppendErrorWithFormat ( " Invalid format: %s. \n " ,
arg_entry . c_str ( ) ) ;
2016-09-07 04:57:50 +08:00
result . SetStatus ( eReturnStatusFailed ) ;
2010-06-09 00:52:24 +08:00
return false ;
2016-09-07 04:57:50 +08:00
}
2016-10-06 04:03:37 +08:00
if ( int_pos = = 1 & & arg_type [ 0 ] ! = ' u ' ) {
result . AppendErrorWithFormat ( " Invalid format: %s. \n " ,
arg_entry . c_str ( ) ) ;
2016-09-07 04:57:50 +08:00
result . SetStatus ( eReturnStatusFailed ) ;
2010-06-09 00:52:24 +08:00
return false ;
2016-09-07 04:57:50 +08:00
}
2016-10-06 04:03:37 +08:00
if ( arg_type [ 0 ] = = ' u ' ) {
2016-09-07 04:57:50 +08:00
encoding = eEncodingUint ;
}
2016-10-06 04:03:37 +08:00
llvm : : StringRef width_spec = arg_type . drop_front ( int_pos + 3 ) ;
auto exp_result = llvm : : StringSwitch < llvm : : Optional < int > > ( width_spec )
. Case ( " 8_t " , 8 )
. Case ( " 16_t " , 16 )
. Case ( " 32_t " , 32 )
. Case ( " 64_t " , 64 )
. Default ( llvm : : None ) ;
if ( ! exp_result . hasValue ( ) ) {
result . AppendErrorWithFormat ( " Invalid format: %s. \n " ,
arg_entry . c_str ( ) ) ;
2016-09-07 04:57:50 +08:00
result . SetStatus ( eReturnStatusFailed ) ;
2010-06-09 00:52:24 +08:00
return false ;
2016-09-07 04:57:50 +08:00
}
2016-10-06 04:03:37 +08:00
width = * exp_result ;
2016-09-07 04:57:50 +08:00
compiler_type =
type_system - > GetBuiltinTypeForEncodingAndBitSize ( encoding , width ) ;
TypeSystem is now a plugin interface and removed any "ClangASTContext &Class::GetClangASTContext()" functions.
This cleans up type systems to be more pluggable. Prior to this we had issues:
- Module, SymbolFile, and many others has "ClangASTContext &GetClangASTContext()" functions. All have been switched over to use "TypeSystem *GetTypeSystemForLanguage()"
- Cleaned up any places that were using the GetClangASTContext() functions to use TypeSystem
- Cleaned up Module so that it no longer has dedicated type system member variables:
lldb::ClangASTContextUP m_ast; ///< The Clang AST context for this module.
lldb::GoASTContextUP m_go_ast; ///< The Go AST context for this module.
Now we have a type system map:
typedef std::map<lldb::LanguageType, lldb::TypeSystemSP> TypeSystemMap;
TypeSystemMap m_type_system_map; ///< A map of any type systems associated with this module
- Many places in code were using ClangASTContext static functions to place with CompilerType objects and add modifiers (const, volatile, restrict) and to make typedefs, L and R value references and more. These have been made into CompilerType functions that are abstract:
class CompilerType
{
...
//----------------------------------------------------------------------
// Return a new CompilerType that is a L value reference to this type if
// this type is valid and the type system supports L value references,
// else return an invalid type.
//----------------------------------------------------------------------
CompilerType
GetLValueReferenceType () const;
//----------------------------------------------------------------------
// Return a new CompilerType that is a R value reference to this type if
// this type is valid and the type system supports R value references,
// else return an invalid type.
//----------------------------------------------------------------------
CompilerType
GetRValueReferenceType () const;
//----------------------------------------------------------------------
// Return a new CompilerType adds a const modifier to this type if
// this type is valid and the type system supports const modifiers,
// else return an invalid type.
//----------------------------------------------------------------------
CompilerType
AddConstModifier () const;
//----------------------------------------------------------------------
// Return a new CompilerType adds a volatile modifier to this type if
// this type is valid and the type system supports volatile modifiers,
// else return an invalid type.
//----------------------------------------------------------------------
CompilerType
AddVolatileModifier () const;
//----------------------------------------------------------------------
// Return a new CompilerType adds a restrict modifier to this type if
// this type is valid and the type system supports restrict modifiers,
// else return an invalid type.
//----------------------------------------------------------------------
CompilerType
AddRestrictModifier () const;
//----------------------------------------------------------------------
// Create a typedef to this type using "name" as the name of the typedef
// this type is valid and the type system supports typedefs, else return
// an invalid type.
//----------------------------------------------------------------------
CompilerType
CreateTypedef (const char *name, const CompilerDeclContext &decl_ctx) const;
};
Other changes include:
- Removed "CompilerType TypeSystem::GetIntTypeFromBitSize(...)" and CompilerType TypeSystem::GetFloatTypeFromBitSize(...) and replaced it with "CompilerType TypeSystem::GetBuiltinTypeForEncodingAndBitSize(lldb::Encoding encoding, size_t bit_size);"
- Fixed code in Type.h to not request the full type for a type for no good reason, just request the forward type and let the type expand as needed
llvm-svn: 247953
2015-09-18 06:23:34 +08:00
2016-09-07 04:57:50 +08:00
if ( ! compiler_type . IsValid ( ) ) {
result . AppendErrorWithFormat (
" Couldn't get Clang type for format %s (%s integer, width %d). \n " ,
2016-10-06 04:03:37 +08:00
arg_entry . c_str ( ) ,
( encoding = = eEncodingSint ? " signed " : " unsigned " ) , width ) ;
2016-09-07 04:57:50 +08:00
result . SetStatus ( eReturnStatusFailed ) ;
TypeSystem is now a plugin interface and removed any "ClangASTContext &Class::GetClangASTContext()" functions.
This cleans up type systems to be more pluggable. Prior to this we had issues:
- Module, SymbolFile, and many others has "ClangASTContext &GetClangASTContext()" functions. All have been switched over to use "TypeSystem *GetTypeSystemForLanguage()"
- Cleaned up any places that were using the GetClangASTContext() functions to use TypeSystem
- Cleaned up Module so that it no longer has dedicated type system member variables:
lldb::ClangASTContextUP m_ast; ///< The Clang AST context for this module.
lldb::GoASTContextUP m_go_ast; ///< The Go AST context for this module.
Now we have a type system map:
typedef std::map<lldb::LanguageType, lldb::TypeSystemSP> TypeSystemMap;
TypeSystemMap m_type_system_map; ///< A map of any type systems associated with this module
- Many places in code were using ClangASTContext static functions to place with CompilerType objects and add modifiers (const, volatile, restrict) and to make typedefs, L and R value references and more. These have been made into CompilerType functions that are abstract:
class CompilerType
{
...
//----------------------------------------------------------------------
// Return a new CompilerType that is a L value reference to this type if
// this type is valid and the type system supports L value references,
// else return an invalid type.
//----------------------------------------------------------------------
CompilerType
GetLValueReferenceType () const;
//----------------------------------------------------------------------
// Return a new CompilerType that is a R value reference to this type if
// this type is valid and the type system supports R value references,
// else return an invalid type.
//----------------------------------------------------------------------
CompilerType
GetRValueReferenceType () const;
//----------------------------------------------------------------------
// Return a new CompilerType adds a const modifier to this type if
// this type is valid and the type system supports const modifiers,
// else return an invalid type.
//----------------------------------------------------------------------
CompilerType
AddConstModifier () const;
//----------------------------------------------------------------------
// Return a new CompilerType adds a volatile modifier to this type if
// this type is valid and the type system supports volatile modifiers,
// else return an invalid type.
//----------------------------------------------------------------------
CompilerType
AddVolatileModifier () const;
//----------------------------------------------------------------------
// Return a new CompilerType adds a restrict modifier to this type if
// this type is valid and the type system supports restrict modifiers,
// else return an invalid type.
//----------------------------------------------------------------------
CompilerType
AddRestrictModifier () const;
//----------------------------------------------------------------------
// Create a typedef to this type using "name" as the name of the typedef
// this type is valid and the type system supports typedefs, else return
// an invalid type.
//----------------------------------------------------------------------
CompilerType
CreateTypedef (const char *name, const CompilerDeclContext &decl_ctx) const;
};
Other changes include:
- Removed "CompilerType TypeSystem::GetIntTypeFromBitSize(...)" and CompilerType TypeSystem::GetFloatTypeFromBitSize(...) and replaced it with "CompilerType TypeSystem::GetBuiltinTypeForEncodingAndBitSize(lldb::Encoding encoding, size_t bit_size);"
- Fixed code in Type.h to not request the full type for a type for no good reason, just request the forward type and let the type expand as needed
llvm-svn: 247953
2015-09-18 06:23:34 +08:00
return false ;
2016-09-07 04:57:50 +08:00
}
2016-10-06 04:03:37 +08:00
} else if ( arg_type = = " void* " ) {
compiler_type =
type_system - > GetBasicTypeFromAST ( eBasicTypeVoid ) . GetPointerType ( ) ;
} else if ( arg_type = = " char* " ) {
compiler_type =
type_system - > GetBasicTypeFromAST ( eBasicTypeChar ) . GetPointerType ( ) ;
2016-09-07 04:57:50 +08:00
} else {
2016-10-06 04:03:37 +08:00
result . AppendErrorWithFormat ( " Invalid format: %s. \n " , arg_entry . 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
value . SetCompilerType ( compiler_type ) ;
value_list . PushValue ( value ) ;
}
if ( ! abi - > GetArgumentValues ( * thread , value_list ) ) {
result . AppendError ( " Couldn't get argument values " ) ;
result . SetStatus ( eReturnStatusFailed ) ;
return false ;
}
result . GetOutputStream ( ) . Printf ( " Arguments : \n " ) ;
2016-10-06 04:03:37 +08:00
for ( auto entry : llvm : : enumerate ( args . entries ( ) ) ) {
2017-03-14 01:12:12 +08:00
result . GetOutputStream ( ) . Printf (
" % " PRIu64 " (%s): " , ( uint64_t ) entry . index ( ) , entry . value ( ) . c_str ( ) ) ;
value_list . GetValueAtIndex ( entry . index ( ) ) - > Dump ( & result . GetOutputStream ( ) ) ;
2016-09-07 04:57:50 +08:00
result . GetOutputStream ( ) . Printf ( " \n " ) ;
}
return result . Succeeded ( ) ;
2010-06-09 00:52:24 +08:00
}