2010-06-09 00:52:24 +08:00
//===-- CommandObjectMemory.cpp ---------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
2012-12-05 08:20:57 +08:00
# include "lldb/lldb-python.h"
2010-06-09 00:52:24 +08:00
# include "CommandObjectMemory.h"
// C Includes
2013-08-28 20:14:27 +08:00
# include <inttypes.h>
2010-06-09 00:52:24 +08:00
// C++ Includes
// Other libraries and framework includes
// Project includes
# include "lldb/Core/DataBufferHeap.h"
# include "lldb/Core/DataExtractor.h"
2010-06-23 09:19:29 +08:00
# include "lldb/Core/Debugger.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/Module.h"
2010-06-09 00:52:24 +08:00
# include "lldb/Core/StreamString.h"
2011-04-28 06:04:39 +08:00
# include "lldb/Core/ValueObjectMemory.h"
<rdar://problem/14393032>
DumpValueObject() 2.0
This checkin restores pre-Xcode5 functionality to the "po" (expr -O) command:
- expr now has a new --description-verbosity (-v) argument, which takes either compact or full as a value (-v is the same as -vfull)
When the full mode is on, "po" will show the extended output with type name, persistent variable name and value, as in
(lldb) expr -O -v -- foo
(id) $0 = 0x000000010010baf0 {
1 = 2;
2 = 3;
}
When -v is omitted, or -vcompact is passed, the Xcode5-style output will be shown, as in
(lldb) expr -O -- foo
{
1 = 2;
2 = 3;
}
- for a non-ObjectiveC object, LLDB will still try to retrieve a summary and/or value to display
(lldb) po 5
5
-v also works in this mode
(lldb) expr -O -vfull -- 5
(int) $4 = 5
On top of that, this is a major refactoring of the ValueObject printing code. The functionality is now factored into a ValueObjectPrinter class for easier maintenance in the future
DumpValueObject() was turned into an instance method ValueObject::Dump() which simply calls through to the printer code, Dump_Impl has been removed
Test case to follow
llvm-svn: 191694
2013-10-01 03:11:51 +08:00
# include "lldb/DataFormatters/ValueObjectPrinter.h"
2010-06-23 09:19:29 +08:00
# include "lldb/Interpreter/Args.h"
2010-06-09 00:52:24 +08:00
# include "lldb/Interpreter/CommandReturnObject.h"
2010-06-23 09:19:29 +08:00
# include "lldb/Interpreter/CommandInterpreter.h"
# include "lldb/Interpreter/Options.h"
2011-04-28 06:04:39 +08:00
# include "lldb/Interpreter/OptionGroupFormat.h"
# include "lldb/Interpreter/OptionGroupOutputFile.h"
2011-04-29 04:55:26 +08:00
# include "lldb/Interpreter/OptionGroupValueObjectDisplay.h"
2012-08-23 01:17:09 +08:00
# include "lldb/Interpreter/OptionValueString.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/Symbol/TypeList.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"
2010-06-09 00:52:24 +08:00
using namespace lldb ;
using namespace lldb_private ;
2011-04-29 04:55:26 +08:00
static OptionDefinition
2011-04-28 06:04:39 +08:00
g_option_table [ ] =
2010-06-09 00:52:24 +08:00
{
2013-09-06 00:42:23 +08:00
{ LLDB_OPT_SET_1 , false , " num-per-line " , ' l ' , OptionParser : : eRequiredArgument , NULL , 0 , eArgTypeNumberPerLine , " The number of items per line to display. " } ,
{ LLDB_OPT_SET_2 , false , " binary " , ' b ' , OptionParser : : eNoArgument , NULL , 0 , eArgTypeNone , " If true, memory will be saved as binary. If false, the memory is saved save as an ASCII dump that uses the format, size, count and number per line settings. " } ,
{ LLDB_OPT_SET_3 , true , " type " , ' t ' , OptionParser : : eRequiredArgument , NULL , 0 , eArgTypeNone , " The name of a type to view memory as. " } ,
2012-11-03 05:14:58 +08:00
{ LLDB_OPT_SET_1 |
LLDB_OPT_SET_2 |
2013-09-06 00:42:23 +08:00
LLDB_OPT_SET_3 , false , " force " , ' r ' , OptionParser : : eNoArgument , NULL , 0 , eArgTypeNone , " Necessary if reading over target.max-memory-read-size bytes. " } ,
2011-04-28 06:04:39 +08:00
} ;
2010-06-09 00:52:24 +08:00
2011-04-28 06:04:39 +08:00
class OptionGroupReadMemory : public OptionGroup
{
public :
2010-06-09 00:52:24 +08:00
2011-04-28 06:04:39 +08:00
OptionGroupReadMemory ( ) :
2011-04-29 04:55:26 +08:00
m_num_per_line ( 1 , 1 ) ,
2011-04-28 06:04:39 +08:00
m_output_as_binary ( false ) ,
m_view_as_type ( )
{
}
2010-06-09 00:52:24 +08:00
2011-04-28 06:04:39 +08:00
virtual
~ OptionGroupReadMemory ( )
{
}
virtual uint32_t
GetNumDefinitions ( )
{
return sizeof ( g_option_table ) / sizeof ( OptionDefinition ) ;
}
virtual const OptionDefinition *
GetDefinitions ( )
{
return g_option_table ;
}
virtual Error
SetOptionValue ( CommandInterpreter & interpreter ,
uint32_t option_idx ,
const char * option_arg )
{
Error error ;
2012-12-04 08:32:51 +08:00
const int short_option = g_option_table [ option_idx ] . short_option ;
2011-04-28 06:04:39 +08:00
switch ( short_option )
{
2010-06-09 00:52:24 +08:00
case ' l ' :
2011-04-28 06:04:39 +08:00
error = m_num_per_line . SetValueFromCString ( option_arg ) ;
if ( m_num_per_line . GetCurrentValue ( ) = = 0 )
2011-10-26 08:56:27 +08:00
error . SetErrorStringWithFormat ( " invalid value for --num-per-line option '%s' " , option_arg ) ;
2010-06-09 00:52:24 +08:00
break ;
2011-10-25 14:44:01 +08:00
2010-10-11 04:52:20 +08:00
case ' b ' :
m_output_as_binary = true ;
break ;
2011-04-28 06:04:39 +08:00
case ' t ' :
error = m_view_as_type . SetValueFromCString ( option_arg ) ;
2010-10-11 04:52:20 +08:00
break ;
2012-04-28 09:27:38 +08:00
case ' r ' :
m_force = true ;
break ;
2011-04-28 06:04:39 +08:00
2010-06-09 00:52:24 +08:00
default :
2011-10-26 08:56:27 +08:00
error . SetErrorStringWithFormat ( " unrecognized short option '%c' " , short_option ) ;
2010-06-09 00:52:24 +08:00
break ;
}
2011-04-28 06:04:39 +08:00
return error ;
}
virtual void
OptionParsingStarting ( CommandInterpreter & interpreter )
{
m_num_per_line . Clear ( ) ;
m_output_as_binary = false ;
m_view_as_type . Clear ( ) ;
2013-06-05 06:54:16 +08:00
m_force = false ;
2011-04-28 06:04:39 +08:00
}
2011-04-29 04:55:26 +08:00
Error
2011-10-25 14:44:01 +08:00
FinalizeSettings ( Target * target , OptionGroupFormat & format_options )
2011-04-28 06:04:39 +08:00
{
2011-04-29 04:55:26 +08:00
Error error ;
2011-10-25 14:44:01 +08:00
OptionValueUInt64 & byte_size_value = format_options . GetByteSizeValue ( ) ;
OptionValueUInt64 & count_value = format_options . GetCountValue ( ) ;
2011-10-26 08:56:27 +08:00
const bool byte_size_option_set = byte_size_value . OptionWasSet ( ) ;
2011-04-29 04:55:26 +08:00
const bool num_per_line_option_set = m_num_per_line . OptionWasSet ( ) ;
2011-10-25 14:44:01 +08:00
const bool count_option_set = format_options . GetCountValue ( ) . OptionWasSet ( ) ;
2011-04-29 04:55:26 +08:00
switch ( format_options . GetFormat ( ) )
2010-06-09 00:52:24 +08:00
{
2011-04-28 06:04:39 +08:00
default :
break ;
case eFormatBoolean :
2011-04-29 04:55:26 +08:00
if ( ! byte_size_option_set )
2011-10-25 14:44:01 +08:00
byte_size_value = 1 ;
2011-04-29 04:55:26 +08:00
if ( ! num_per_line_option_set )
m_num_per_line = 1 ;
if ( ! count_option_set )
2011-10-25 14:44:01 +08:00
format_options . GetCountValue ( ) = 8 ;
2011-04-28 06:04:39 +08:00
break ;
case eFormatCString :
break ;
Added support for the new ".apple_objc" accelerator tables. These tables are
in the same hashed format as the ".apple_names", but they map objective C
class names to all of the methods and class functions. We need to do this
because in the DWARF the methods for Objective C are never contained in the
class definition, they are scattered about at the translation unit level and
they don't even have attributes that say the are contained within the class
itself.
Added 3 new formats which can be used to display data:
eFormatAddressInfo
eFormatHexFloat
eFormatInstruction
eFormatAddressInfo describes an address such as function+offset and file+line,
or symbol + offset, or constant data (c string, 2, 4, 8, or 16 byte constants).
The format character for this is "A", the long format is "address".
eFormatHexFloat will print out the hex float format that compilers tend to use.
The format character for this is "X", the long format is "hex float".
eFormatInstruction will print out disassembly with bytes and it will use the
current target's architecture. The format character for this is "i" (which
used to be being used for the integer format, but the integer format also has
"d", so we gave the "i" format to disassembly), the long format is
"instruction".
Mate the lldb::FormatterChoiceCriterion enumeration private as it should have
been from the start. It is very specialized and doesn't belong in the public
API.
llvm-svn: 143114
2011-10-28 01:55:14 +08:00
case eFormatInstruction :
if ( count_option_set )
2012-11-07 09:52:04 +08:00
byte_size_value = target - > GetArchitecture ( ) . GetMaximumOpcodeByteSize ( ) ;
Added support for the new ".apple_objc" accelerator tables. These tables are
in the same hashed format as the ".apple_names", but they map objective C
class names to all of the methods and class functions. We need to do this
because in the DWARF the methods for Objective C are never contained in the
class definition, they are scattered about at the translation unit level and
they don't even have attributes that say the are contained within the class
itself.
Added 3 new formats which can be used to display data:
eFormatAddressInfo
eFormatHexFloat
eFormatInstruction
eFormatAddressInfo describes an address such as function+offset and file+line,
or symbol + offset, or constant data (c string, 2, 4, 8, or 16 byte constants).
The format character for this is "A", the long format is "address".
eFormatHexFloat will print out the hex float format that compilers tend to use.
The format character for this is "X", the long format is "hex float".
eFormatInstruction will print out disassembly with bytes and it will use the
current target's architecture. The format character for this is "i" (which
used to be being used for the integer format, but the integer format also has
"d", so we gave the "i" format to disassembly), the long format is
"instruction".
Mate the lldb::FormatterChoiceCriterion enumeration private as it should have
been from the start. It is very specialized and doesn't belong in the public
API.
llvm-svn: 143114
2011-10-28 01:55:14 +08:00
m_num_per_line = 1 ;
break ;
case eFormatAddressInfo :
if ( ! byte_size_option_set )
byte_size_value = target - > GetArchitecture ( ) . GetAddressByteSize ( ) ;
m_num_per_line = 1 ;
if ( ! count_option_set )
format_options . GetCountValue ( ) = 8 ;
break ;
2011-04-28 06:04:39 +08:00
case eFormatPointer :
2011-10-25 14:44:01 +08:00
byte_size_value = target - > GetArchitecture ( ) . GetAddressByteSize ( ) ;
2011-04-29 04:55:26 +08:00
if ( ! num_per_line_option_set )
m_num_per_line = 4 ;
if ( ! count_option_set )
2011-10-25 14:44:01 +08:00
format_options . GetCountValue ( ) = 8 ;
2011-04-28 06:04:39 +08:00
break ;
case eFormatBinary :
case eFormatFloat :
case eFormatOctal :
case eFormatDecimal :
case eFormatEnum :
case eFormatUnicode16 :
case eFormatUnicode32 :
case eFormatUnsigned :
Added support for the new ".apple_objc" accelerator tables. These tables are
in the same hashed format as the ".apple_names", but they map objective C
class names to all of the methods and class functions. We need to do this
because in the DWARF the methods for Objective C are never contained in the
class definition, they are scattered about at the translation unit level and
they don't even have attributes that say the are contained within the class
itself.
Added 3 new formats which can be used to display data:
eFormatAddressInfo
eFormatHexFloat
eFormatInstruction
eFormatAddressInfo describes an address such as function+offset and file+line,
or symbol + offset, or constant data (c string, 2, 4, 8, or 16 byte constants).
The format character for this is "A", the long format is "address".
eFormatHexFloat will print out the hex float format that compilers tend to use.
The format character for this is "X", the long format is "hex float".
eFormatInstruction will print out disassembly with bytes and it will use the
current target's architecture. The format character for this is "i" (which
used to be being used for the integer format, but the integer format also has
"d", so we gave the "i" format to disassembly), the long format is
"instruction".
Mate the lldb::FormatterChoiceCriterion enumeration private as it should have
been from the start. It is very specialized and doesn't belong in the public
API.
llvm-svn: 143114
2011-10-28 01:55:14 +08:00
case eFormatHexFloat :
2011-04-29 04:55:26 +08:00
if ( ! byte_size_option_set )
2011-10-25 14:44:01 +08:00
byte_size_value = 4 ;
2011-04-29 04:55:26 +08:00
if ( ! num_per_line_option_set )
m_num_per_line = 1 ;
if ( ! count_option_set )
2011-10-25 14:44:01 +08:00
format_options . GetCountValue ( ) = 8 ;
2011-04-28 06:04:39 +08:00
break ;
Added support for the new ".apple_objc" accelerator tables. These tables are
in the same hashed format as the ".apple_names", but they map objective C
class names to all of the methods and class functions. We need to do this
because in the DWARF the methods for Objective C are never contained in the
class definition, they are scattered about at the translation unit level and
they don't even have attributes that say the are contained within the class
itself.
Added 3 new formats which can be used to display data:
eFormatAddressInfo
eFormatHexFloat
eFormatInstruction
eFormatAddressInfo describes an address such as function+offset and file+line,
or symbol + offset, or constant data (c string, 2, 4, 8, or 16 byte constants).
The format character for this is "A", the long format is "address".
eFormatHexFloat will print out the hex float format that compilers tend to use.
The format character for this is "X", the long format is "hex float".
eFormatInstruction will print out disassembly with bytes and it will use the
current target's architecture. The format character for this is "i" (which
used to be being used for the integer format, but the integer format also has
"d", so we gave the "i" format to disassembly), the long format is
"instruction".
Mate the lldb::FormatterChoiceCriterion enumeration private as it should have
been from the start. It is very specialized and doesn't belong in the public
API.
llvm-svn: 143114
2011-10-28 01:55:14 +08:00
2011-04-28 06:04:39 +08:00
case eFormatBytes :
case eFormatBytesWithASCII :
2011-10-26 08:56:27 +08:00
if ( byte_size_option_set )
2011-04-29 04:55:26 +08:00
{
2011-10-25 14:44:01 +08:00
if ( byte_size_value > 1 )
2012-11-30 05:49:15 +08:00
error . SetErrorStringWithFormat ( " display format (bytes/bytes with ascii) conflicts with the specified byte size % " PRIu64 " \n "
2012-03-06 09:17:59 +08:00
" \t consider using a different display format or don't specify the byte size " ,
byte_size_value . GetCurrentValue ( ) ) ;
2011-04-29 04:55:26 +08:00
}
else
2011-10-25 14:44:01 +08:00
byte_size_value = 1 ;
2011-04-29 04:55:26 +08:00
if ( ! num_per_line_option_set )
m_num_per_line = 16 ;
if ( ! count_option_set )
2011-10-25 14:44:01 +08:00
format_options . GetCountValue ( ) = 32 ;
2011-04-28 06:04:39 +08:00
break ;
2011-06-18 07:50:44 +08:00
case eFormatCharArray :
2011-04-28 06:04:39 +08:00
case eFormatChar :
case eFormatCharPrintable :
2011-04-29 04:55:26 +08:00
if ( ! byte_size_option_set )
2011-10-25 14:44:01 +08:00
byte_size_value = 1 ;
2011-04-29 04:55:26 +08:00
if ( ! num_per_line_option_set )
m_num_per_line = 32 ;
if ( ! count_option_set )
2011-10-25 14:44:01 +08:00
format_options . GetCountValue ( ) = 64 ;
2011-04-28 06:04:39 +08:00
break ;
case eFormatComplex :
2011-04-29 04:55:26 +08:00
if ( ! byte_size_option_set )
2011-10-25 14:44:01 +08:00
byte_size_value = 8 ;
2011-04-29 04:55:26 +08:00
if ( ! num_per_line_option_set )
m_num_per_line = 1 ;
if ( ! count_option_set )
2011-10-25 14:44:01 +08:00
format_options . GetCountValue ( ) = 8 ;
2013-03-23 13:16:54 +08:00
break ;
case eFormatComplexInteger :
if ( ! byte_size_option_set )
byte_size_value = 8 ;
if ( ! num_per_line_option_set )
m_num_per_line = 1 ;
if ( ! count_option_set )
format_options . GetCountValue ( ) = 8 ;
2011-04-28 06:04:39 +08:00
break ;
case eFormatHex :
2011-04-29 04:55:26 +08:00
if ( ! byte_size_option_set )
2011-10-25 14:44:01 +08:00
byte_size_value = 4 ;
2011-04-29 04:55:26 +08:00
if ( ! num_per_line_option_set )
{
2011-10-25 14:44:01 +08:00
switch ( byte_size_value )
2011-04-29 04:55:26 +08:00
{
case 1 :
case 2 :
m_num_per_line = 8 ;
break ;
case 4 :
m_num_per_line = 4 ;
break ;
case 8 :
m_num_per_line = 2 ;
break ;
default :
m_num_per_line = 1 ;
break ;
}
}
if ( ! count_option_set )
2011-10-25 14:44:01 +08:00
count_value = 8 ;
2011-04-28 06:04:39 +08:00
break ;
case eFormatVectorOfChar :
case eFormatVectorOfSInt8 :
case eFormatVectorOfUInt8 :
case eFormatVectorOfSInt16 :
case eFormatVectorOfUInt16 :
case eFormatVectorOfSInt32 :
case eFormatVectorOfUInt32 :
case eFormatVectorOfSInt64 :
case eFormatVectorOfUInt64 :
case eFormatVectorOfFloat32 :
case eFormatVectorOfFloat64 :
case eFormatVectorOfUInt128 :
2011-04-29 04:55:26 +08:00
if ( ! byte_size_option_set )
2011-10-25 14:44:01 +08:00
byte_size_value = 128 ;
2011-04-29 04:55:26 +08:00
if ( ! num_per_line_option_set )
m_num_per_line = 1 ;
if ( ! count_option_set )
2011-10-25 14:44:01 +08:00
count_value = 4 ;
2011-04-28 06:04:39 +08:00
break ;
2010-06-09 00:52:24 +08:00
}
2011-04-29 04:55:26 +08:00
return error ;
2011-04-28 06:04:39 +08:00
}
2010-06-09 00:52:24 +08:00
2011-10-26 12:32:38 +08:00
bool
AnyOptionWasSet ( ) const
{
return m_num_per_line . OptionWasSet ( ) | |
m_output_as_binary | |
m_view_as_type . OptionWasSet ( ) ;
}
2011-04-28 06:04:39 +08:00
OptionValueUInt64 m_num_per_line ;
bool m_output_as_binary ;
OptionValueString m_view_as_type ;
2012-04-28 09:27:38 +08:00
bool m_force ;
2011-04-28 06:04:39 +08:00
} ;
2010-06-09 00:52:24 +08:00
2011-04-28 06:04:39 +08:00
//----------------------------------------------------------------------
// Read memory from the inferior process
//----------------------------------------------------------------------
2012-06-09 05:56:10 +08:00
class CommandObjectMemoryRead : public CommandObjectParsed
2011-04-28 06:04:39 +08:00
{
public :
2010-09-18 09:14:36 +08:00
CommandObjectMemoryRead ( CommandInterpreter & interpreter ) :
2012-06-09 05:56:10 +08:00
CommandObjectParsed ( interpreter ,
" memory read " ,
" Read from the memory of the process being debugged. " ,
NULL ,
Expanded the flags that can be set for a command object in lldb_private::CommandObject. This list of available flags are:
enum
{
//----------------------------------------------------------------------
// eFlagRequiresTarget
//
// Ensures a valid target is contained in m_exe_ctx prior to executing
// the command. If a target doesn't exist or is invalid, the command
// will fail and CommandObject::GetInvalidTargetDescription() will be
// returned as the error. CommandObject subclasses can override the
// virtual function for GetInvalidTargetDescription() to provide custom
// strings when needed.
//----------------------------------------------------------------------
eFlagRequiresTarget = (1u << 0),
//----------------------------------------------------------------------
// eFlagRequiresProcess
//
// Ensures a valid process is contained in m_exe_ctx prior to executing
// the command. If a process doesn't exist or is invalid, the command
// will fail and CommandObject::GetInvalidProcessDescription() will be
// returned as the error. CommandObject subclasses can override the
// virtual function for GetInvalidProcessDescription() to provide custom
// strings when needed.
//----------------------------------------------------------------------
eFlagRequiresProcess = (1u << 1),
//----------------------------------------------------------------------
// eFlagRequiresThread
//
// Ensures a valid thread is contained in m_exe_ctx prior to executing
// the command. If a thread doesn't exist or is invalid, the command
// will fail and CommandObject::GetInvalidThreadDescription() will be
// returned as the error. CommandObject subclasses can override the
// virtual function for GetInvalidThreadDescription() to provide custom
// strings when needed.
//----------------------------------------------------------------------
eFlagRequiresThread = (1u << 2),
//----------------------------------------------------------------------
// eFlagRequiresFrame
//
// Ensures a valid frame is contained in m_exe_ctx prior to executing
// the command. If a frame doesn't exist or is invalid, the command
// will fail and CommandObject::GetInvalidFrameDescription() will be
// returned as the error. CommandObject subclasses can override the
// virtual function for GetInvalidFrameDescription() to provide custom
// strings when needed.
//----------------------------------------------------------------------
eFlagRequiresFrame = (1u << 3),
//----------------------------------------------------------------------
// eFlagRequiresRegContext
//
// Ensures a valid register context (from the selected frame if there
// is a frame in m_exe_ctx, or from the selected thread from m_exe_ctx)
// is availble from m_exe_ctx prior to executing the command. If a
// target doesn't exist or is invalid, the command will fail and
// CommandObject::GetInvalidRegContextDescription() will be returned as
// the error. CommandObject subclasses can override the virtual function
// for GetInvalidRegContextDescription() to provide custom strings when
// needed.
//----------------------------------------------------------------------
eFlagRequiresRegContext = (1u << 4),
//----------------------------------------------------------------------
// eFlagTryTargetAPILock
//
// Attempts to acquire the target lock if a target is selected in the
// command interpreter. If the command object fails to acquire the API
// lock, the command will fail with an appropriate error message.
//----------------------------------------------------------------------
eFlagTryTargetAPILock = (1u << 5),
//----------------------------------------------------------------------
// eFlagProcessMustBeLaunched
//
// Verifies that there is a launched process in m_exe_ctx, if there
// isn't, the command will fail with an appropriate error message.
//----------------------------------------------------------------------
eFlagProcessMustBeLaunched = (1u << 6),
//----------------------------------------------------------------------
// eFlagProcessMustBePaused
//
// Verifies that there is a paused process in m_exe_ctx, if there
// isn't, the command will fail with an appropriate error message.
//----------------------------------------------------------------------
eFlagProcessMustBePaused = (1u << 7)
};
Now each command object contains a "ExecutionContext m_exe_ctx;" member variable that gets initialized prior to running the command. The validity of the target objects in m_exe_ctx are checked to ensure that any target/process/thread/frame/reg context that are required are valid prior to executing the command. Each command object also contains a Mutex::Locker m_api_locker which gets used if eFlagTryTargetAPILock is set. This centralizes a lot of checking code that was previously and inconsistently implemented across many commands.
llvm-svn: 171990
2013-01-10 03:44:40 +08:00
eFlagRequiresTarget | eFlagProcessMustBePaused ) ,
2011-04-28 06:04:39 +08:00
m_option_group ( interpreter ) ,
2011-10-25 14:44:01 +08:00
m_format_options ( eFormatBytesWithASCII , 1 , 8 ) ,
2011-04-28 06:04:39 +08:00
m_memory_options ( ) ,
2011-04-29 04:55:26 +08:00
m_outfile_options ( ) ,
2011-10-26 12:32:38 +08:00
m_varobj_options ( ) ,
m_next_addr ( LLDB_INVALID_ADDRESS ) ,
m_prev_byte_size ( 0 ) ,
m_prev_format_options ( eFormatBytesWithASCII , 1 , 8 ) ,
m_prev_memory_options ( ) ,
m_prev_outfile_options ( ) ,
m_prev_varobj_options ( )
2010-06-09 00:52:24 +08:00
{
2010-10-05 06:28:36 +08:00
CommandArgumentEntry arg1 ;
CommandArgumentEntry arg2 ;
CommandArgumentData start_addr_arg ;
CommandArgumentData end_addr_arg ;
// Define the first (and only) variant of this arg.
2013-01-29 09:48:30 +08:00
start_addr_arg . arg_type = eArgTypeAddressOrExpression ;
2010-10-05 06:28:36 +08:00
start_addr_arg . arg_repetition = eArgRepeatPlain ;
// There is only one variant this argument could be; put it into the argument entry.
arg1 . push_back ( start_addr_arg ) ;
// Define the first (and only) variant of this arg.
2013-01-29 09:48:30 +08:00
end_addr_arg . arg_type = eArgTypeAddressOrExpression ;
2010-10-05 06:28:36 +08:00
end_addr_arg . arg_repetition = eArgRepeatOptional ;
// There is only one variant this argument could be; put it into the argument entry.
arg2 . push_back ( end_addr_arg ) ;
// Push the data for the first argument into the m_arguments vector.
m_arguments . push_back ( arg1 ) ;
m_arguments . push_back ( arg2 ) ;
2011-04-28 06:04:39 +08:00
2011-10-25 14:44:01 +08:00
// Add the "--format" and "--count" options to group 1 and 3
m_option_group . Append ( & m_format_options ,
OptionGroupFormat : : OPTION_GROUP_FORMAT | OptionGroupFormat : : OPTION_GROUP_COUNT ,
2011-11-23 02:07:35 +08:00
LLDB_OPT_SET_1 | LLDB_OPT_SET_2 | LLDB_OPT_SET_3 ) ;
Added support for the new ".apple_objc" accelerator tables. These tables are
in the same hashed format as the ".apple_names", but they map objective C
class names to all of the methods and class functions. We need to do this
because in the DWARF the methods for Objective C are never contained in the
class definition, they are scattered about at the translation unit level and
they don't even have attributes that say the are contained within the class
itself.
Added 3 new formats which can be used to display data:
eFormatAddressInfo
eFormatHexFloat
eFormatInstruction
eFormatAddressInfo describes an address such as function+offset and file+line,
or symbol + offset, or constant data (c string, 2, 4, 8, or 16 byte constants).
The format character for this is "A", the long format is "address".
eFormatHexFloat will print out the hex float format that compilers tend to use.
The format character for this is "X", the long format is "hex float".
eFormatInstruction will print out disassembly with bytes and it will use the
current target's architecture. The format character for this is "i" (which
used to be being used for the integer format, but the integer format also has
"d", so we gave the "i" format to disassembly), the long format is
"instruction".
Mate the lldb::FormatterChoiceCriterion enumeration private as it should have
been from the start. It is very specialized and doesn't belong in the public
API.
llvm-svn: 143114
2011-10-28 01:55:14 +08:00
m_option_group . Append ( & m_format_options ,
OptionGroupFormat : : OPTION_GROUP_GDB_FMT ,
2011-11-23 02:07:35 +08:00
LLDB_OPT_SET_1 | LLDB_OPT_SET_3 ) ;
2011-10-25 14:44:01 +08:00
// Add the "--size" option to group 1 and 2
m_option_group . Append ( & m_format_options ,
OptionGroupFormat : : OPTION_GROUP_SIZE ,
LLDB_OPT_SET_1 | LLDB_OPT_SET_2 ) ;
2011-04-28 06:04:39 +08:00
m_option_group . Append ( & m_memory_options ) ;
m_option_group . Append ( & m_outfile_options , LLDB_OPT_SET_ALL , LLDB_OPT_SET_1 | LLDB_OPT_SET_2 | LLDB_OPT_SET_3 ) ;
2011-04-29 04:55:26 +08:00
m_option_group . Append ( & m_varobj_options , LLDB_OPT_SET_ALL , LLDB_OPT_SET_3 ) ;
2011-04-28 06:04:39 +08:00
m_option_group . Finalize ( ) ;
2010-06-09 00:52:24 +08:00
}
virtual
~ CommandObjectMemoryRead ( )
{
}
Options *
GetOptions ( )
{
2011-04-28 06:04:39 +08:00
return & m_option_group ;
2010-06-09 00:52:24 +08:00
}
2011-10-26 12:32:38 +08:00
virtual const char * GetRepeatCommand ( Args & current_command_args , uint32_t index )
{
return m_cmd_name . c_str ( ) ;
}
2012-06-09 05:56:10 +08:00
protected :
2010-06-09 00:52:24 +08:00
virtual bool
2012-12-07 06:49:16 +08:00
DoExecute ( Args & command , CommandReturnObject & result )
2010-06-09 00:52:24 +08:00
{
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
// No need to check "target" for validity as eFlagRequiresTarget ensures it is valid
Target * target = m_exe_ctx . GetTargetPtr ( ) ;
2010-06-09 00:52:24 +08:00
const size_t argc = command . GetArgumentCount ( ) ;
2011-10-26 12:32:38 +08:00
if ( ( argc = = 0 & & m_next_addr = = LLDB_INVALID_ADDRESS ) | | argc > 2 )
2010-06-09 00:52:24 +08:00
{
2012-12-07 06:49:16 +08:00
result . AppendErrorWithFormat ( " %s takes a start address expression with an optional end address expression. \n " , m_cmd_name . c_str ( ) ) ;
2012-12-15 10:08:17 +08:00
result . AppendRawWarning ( " Expressions should be quoted if they contain spaces or other special characters. \n " ) ;
2010-06-09 00:52:24 +08:00
result . SetStatus ( eReturnStatusFailed ) ;
return false ;
}
2011-04-29 04:55:26 +08:00
ClangASTType clang_ast_type ;
Error error ;
2011-04-28 06:04:39 +08:00
const char * view_as_type_cstr = m_memory_options . m_view_as_type . GetCurrentValue ( ) ;
if ( view_as_type_cstr & & view_as_type_cstr [ 0 ] )
2010-06-09 00:52:24 +08:00
{
2011-04-28 06:04:39 +08:00
// We are viewing memory as a type
2012-12-15 10:08:17 +08:00
2011-04-28 06:04:39 +08:00
SymbolContext sc ;
2012-03-27 07:03:23 +08:00
const bool exact_match = false ;
2011-04-28 06:04:39 +08:00
TypeList type_list ;
uint32_t reference_count = 0 ;
uint32_t pointer_count = 0 ;
size_t idx ;
2012-07-11 05:24:26 +08:00
# define ALL_KEYWORDS \
KEYWORD ( " const " ) \
KEYWORD ( " volatile " ) \
KEYWORD ( " restrict " ) \
KEYWORD ( " struct " ) \
KEYWORD ( " class " ) \
KEYWORD ( " union " )
# define KEYWORD(s) s,
static const char * g_keywords [ ] =
{
ALL_KEYWORDS
} ;
# undef KEYWORD
# define KEYWORD(s) (sizeof(s) - 1),
static const int g_keyword_lengths [ ] =
{
ALL_KEYWORDS
} ;
# undef KEYWORD
# undef ALL_KEYWORDS
static size_t g_num_keywords = sizeof ( g_keywords ) / sizeof ( const char * ) ;
2011-04-28 06:04:39 +08:00
std : : string type_str ( view_as_type_cstr ) ;
// Remove all instances of g_keywords that are followed by spaces
for ( size_t i = 0 ; i < g_num_keywords ; + + i )
{
const char * keyword = g_keywords [ i ] ;
2012-07-11 05:24:26 +08:00
int keyword_len = g_keyword_lengths [ i ] ;
idx = 0 ;
while ( ( idx = type_str . find ( keyword , idx ) ) ! = std : : string : : npos )
2011-04-28 06:04:39 +08:00
{
if ( type_str [ idx + keyword_len ] = = ' ' | | type_str [ idx + keyword_len ] = = ' \t ' )
2012-07-11 05:24:26 +08:00
{
2011-04-28 06:04:39 +08:00
type_str . erase ( idx , keyword_len + 1 ) ;
2012-07-11 05:24:26 +08:00
idx = 0 ;
}
else
{
idx + = keyword_len ;
}
2011-04-28 06:04:39 +08:00
}
}
bool done = type_str . empty ( ) ;
//
idx = type_str . find_first_not_of ( " \t " ) ;
if ( idx > 0 & & idx ! = std : : string : : npos )
type_str . erase ( 0 , idx ) ;
while ( ! done )
{
// Strip trailing spaces
if ( type_str . empty ( ) )
done = true ;
else
{
switch ( type_str [ type_str . size ( ) - 1 ] )
{
case ' * ' :
+ + pointer_count ;
// fall through...
case ' ' :
case ' \t ' :
type_str . erase ( type_str . size ( ) - 1 ) ;
break ;
case ' & ' :
if ( reference_count = = 0 )
{
reference_count = 1 ;
type_str . erase ( type_str . size ( ) - 1 ) ;
}
else
{
result . AppendErrorWithFormat ( " invalid type string: '%s' \n " , view_as_type_cstr ) ;
result . SetStatus ( eReturnStatusFailed ) ;
return false ;
}
break ;
default :
done = true ;
break ;
}
}
}
ConstString lookup_type_name ( type_str . c_str ( ) ) ;
2013-11-04 17:33:30 +08:00
StackFrame * frame = m_exe_ctx . GetFramePtr ( ) ;
2011-09-22 12:58:26 +08:00
if ( frame )
2011-04-28 06:04:39 +08:00
{
2011-09-22 12:58:26 +08:00
sc = frame - > GetSymbolContext ( eSymbolContextModule ) ;
2011-04-28 06:04:39 +08:00
if ( sc . module_sp )
{
2011-10-12 10:08:07 +08:00
sc . module_sp - > FindTypes ( sc ,
lookup_type_name ,
2012-03-27 07:03:23 +08:00
exact_match ,
2011-04-28 06:04:39 +08:00
1 ,
type_list ) ;
}
}
if ( type_list . GetSize ( ) = = 0 )
{
2012-04-07 01:41:13 +08:00
target - > GetImages ( ) . FindTypes ( sc ,
2011-09-22 12:58:26 +08:00
lookup_type_name ,
2012-03-27 07:03:23 +08:00
exact_match ,
2011-09-22 12:58:26 +08:00
1 ,
type_list ) ;
2011-04-28 06:04:39 +08:00
}
2013-06-12 02:47:55 +08:00
if ( type_list . GetSize ( ) = = 0 & & lookup_type_name . GetCString ( ) & & * lookup_type_name . GetCString ( ) = = ' $ ' )
2011-04-28 06:04:39 +08:00
{
2013-06-12 02:47:55 +08:00
clang : : TypeDecl * tdecl = target - > GetPersistentVariables ( ) . GetPersistentType ( ConstString ( lookup_type_name ) ) ;
if ( tdecl )
{
clang_ast_type . SetClangType ( & tdecl - > getASTContext ( ) , ( lldb : : clang_type_t ) tdecl - > getTypeForDecl ( ) ) ;
}
2011-04-28 06:04:39 +08:00
}
2013-06-12 02:47:55 +08:00
if ( clang_ast_type . IsValid ( ) = = false )
{
if ( type_list . GetSize ( ) = = 0 )
{
result . AppendErrorWithFormat ( " unable to find any types that match the raw type '%s' for full type '%s' \n " ,
lookup_type_name . GetCString ( ) ,
view_as_type_cstr ) ;
result . SetStatus ( eReturnStatusFailed ) ;
return false ;
}
else
{
TypeSP type_sp ( type_list . GetTypeAtIndex ( 0 ) ) ;
2013-07-12 06:46:58 +08:00
clang_ast_type = type_sp - > GetClangFullType ( ) ;
2013-06-12 02:47:55 +08:00
}
}
2011-04-28 06:04:39 +08:00
while ( pointer_count > 0 )
{
2013-07-12 06:46:58 +08:00
ClangASTType pointer_type = clang_ast_type . GetPointerType ( ) ;
if ( pointer_type . IsValid ( ) )
clang_ast_type = pointer_type ;
2011-04-28 06:04:39 +08:00
else
{
result . AppendError ( " unable make a pointer type \n " ) ;
result . SetStatus ( eReturnStatusFailed ) ;
return false ;
}
- - pointer_count ;
}
2013-07-12 06:46:58 +08:00
m_format_options . GetByteSizeValue ( ) = clang_ast_type . GetByteSize ( ) ;
2011-04-28 06:04:39 +08:00
2011-10-25 14:44:01 +08:00
if ( m_format_options . GetByteSizeValue ( ) = = 0 )
2011-04-28 06:04:39 +08:00
{
result . AppendErrorWithFormat ( " unable to get the byte size of the type '%s' \n " ,
view_as_type_cstr ) ;
result . SetStatus ( eReturnStatusFailed ) ;
return false ;
}
2011-04-29 04:55:26 +08:00
2011-10-25 14:44:01 +08:00
if ( ! m_format_options . GetCountValue ( ) . OptionWasSet ( ) )
m_format_options . GetCountValue ( ) = 1 ;
2011-04-28 06:04:39 +08:00
}
else
{
2011-09-22 12:58:26 +08:00
error = m_memory_options . FinalizeSettings ( target , m_format_options ) ;
2010-06-09 00:52:24 +08:00
}
2011-04-29 04:55:26 +08:00
// Look for invalid combinations of settings
if ( error . Fail ( ) )
2010-06-09 00:52:24 +08:00
{
2012-12-07 06:49:16 +08:00
result . AppendError ( error . AsCString ( ) ) ;
2011-04-29 04:55:26 +08:00
result . SetStatus ( eReturnStatusFailed ) ;
return false ;
2010-06-09 00:52:24 +08:00
}
2011-10-26 12:32:38 +08:00
lldb : : addr_t addr ;
size_t total_byte_size = 0 ;
if ( argc = = 0 )
{
// Use the last address and byte size and all options as they were
// if no options have been set
addr = m_next_addr ;
total_byte_size = m_prev_byte_size ;
2012-12-15 10:08:17 +08:00
clang_ast_type = m_prev_clang_ast_type ;
if ( ! m_format_options . AnyOptionWasSet ( ) & &
2011-10-26 12:32:38 +08:00
! m_memory_options . AnyOptionWasSet ( ) & &
! m_outfile_options . AnyOptionWasSet ( ) & &
! m_varobj_options . AnyOptionWasSet ( ) )
{
m_format_options = m_prev_format_options ;
m_memory_options = m_prev_memory_options ;
m_outfile_options = m_prev_outfile_options ;
m_varobj_options = m_prev_varobj_options ;
}
}
2011-10-25 14:44:01 +08:00
size_t item_count = m_format_options . GetCountValue ( ) . GetCurrentValue ( ) ;
2013-01-22 03:20:50 +08:00
size_t item_byte_size = m_format_options . GetByteSizeValue ( ) . GetCurrentValue ( ) ;
2011-04-29 04:55:26 +08:00
const size_t num_per_line = m_memory_options . m_num_per_line . GetCurrentValue ( ) ;
2010-06-09 00:52:24 +08:00
if ( total_byte_size = = 0 )
2011-10-26 12:32:38 +08:00
{
total_byte_size = item_count * item_byte_size ;
if ( total_byte_size = = 0 )
total_byte_size = 32 ;
}
2010-06-09 00:52:24 +08:00
2011-10-26 12:32:38 +08:00
if ( argc > 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
addr = Args : : StringToAddress ( & m_exe_ctx , command . GetArgumentAtIndex ( 0 ) , LLDB_INVALID_ADDRESS , & error ) ;
2010-06-09 00:52:24 +08:00
if ( addr = = LLDB_INVALID_ADDRESS )
{
2012-12-07 06:49:16 +08:00
result . AppendError ( " invalid start address expression. " ) ;
result . AppendError ( error . AsCString ( ) ) ;
2010-06-09 00:52:24 +08:00
result . SetStatus ( eReturnStatusFailed ) ;
return false ;
}
if ( argc = = 2 )
{
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
lldb : : addr_t end_addr = Args : : StringToAddress ( & m_exe_ctx , command . GetArgumentAtIndex ( 1 ) , LLDB_INVALID_ADDRESS , 0 ) ;
2010-06-09 00:52:24 +08:00
if ( end_addr = = LLDB_INVALID_ADDRESS )
{
2012-12-07 06:49:16 +08:00
result . AppendError ( " invalid end address expression. " ) ;
result . AppendError ( error . AsCString ( ) ) ;
2010-06-09 00:52:24 +08:00
result . SetStatus ( eReturnStatusFailed ) ;
return false ;
}
else if ( end_addr < = addr )
{
2012-11-30 05:49:15 +08:00
result . AppendErrorWithFormat ( " end address (0x% " PRIx64 " ) must be greater that the start address (0x% " PRIx64 " ). \n " , end_addr , addr ) ;
2010-06-09 00:52:24 +08:00
result . SetStatus ( eReturnStatusFailed ) ;
return false ;
}
2011-10-25 14:44:01 +08:00
else if ( m_format_options . GetCountValue ( ) . OptionWasSet ( ) )
2010-06-09 00:52:24 +08:00
{
2013-11-01 07:55:19 +08:00
result . AppendErrorWithFormat ( " specify either the end address (0x% " PRIx64 " ) or the count (--count %zu), not both. \n " , end_addr , item_count ) ;
2010-06-09 00:52:24 +08:00
result . SetStatus ( eReturnStatusFailed ) ;
return false ;
}
total_byte_size = end_addr - addr ;
item_count = total_byte_size / item_byte_size ;
}
2011-04-28 06:04:39 +08:00
2013-06-05 06:54:16 +08:00
uint32_t max_unforced_size = target - > GetMaximumMemReadSize ( ) ;
if ( total_byte_size > max_unforced_size & & ! m_memory_options . m_force )
2012-04-28 09:27:38 +08:00
{
2013-06-05 06:54:16 +08:00
result . AppendErrorWithFormat ( " Normally, \' memory read \' will not read over % " PRIu32 " bytes of data. \n " , max_unforced_size ) ;
result . AppendErrorWithFormat ( " Please use --force to override this restriction just once. \n " ) ;
result . AppendErrorWithFormat ( " or set target.max-memory-read-size if you will often need a larger limit. \n " ) ;
2012-04-28 09:27:38 +08:00
return false ;
}
2011-04-28 06:04:39 +08:00
DataBufferSP data_sp ;
size_t bytes_read = 0 ;
2012-12-15 10:08:17 +08:00
if ( clang_ast_type . GetOpaqueQualType ( ) )
{
// Make sure we don't display our type as ASCII bytes like the default memory read
if ( m_format_options . GetFormatValue ( ) . OptionWasSet ( ) = = false )
m_format_options . GetFormatValue ( ) . SetCurrentValue ( eFormatDefault ) ;
2013-07-12 06:46:58 +08:00
bytes_read = clang_ast_type . GetByteSize ( ) * m_format_options . GetCountValue ( ) . GetCurrentValue ( ) ;
2012-12-15 10:08:17 +08:00
}
2013-01-22 03:20:50 +08:00
else if ( m_format_options . GetFormatValue ( ) . GetCurrentValue ( ) ! = eFormatCString )
2010-06-09 00:52:24 +08:00
{
2011-04-28 06:04:39 +08:00
data_sp . reset ( new DataBufferHeap ( total_byte_size , ' \0 ' ) ) ;
2013-07-25 02:17:35 +08:00
if ( data_sp - > GetBytes ( ) = = NULL )
{
result . AppendErrorWithFormat ( " can't allocate 0x%zx bytes for the memory read buffer, specify a smaller size to read " , total_byte_size ) ;
result . SetStatus ( eReturnStatusFailed ) ;
return false ;
}
2012-02-24 09:59:29 +08:00
Address address ( addr , NULL ) ;
2011-09-22 12:58:26 +08:00
bytes_read = target - > ReadMemory ( address , false , data_sp - > GetBytes ( ) , data_sp - > GetByteSize ( ) , error ) ;
2011-04-28 06:04:39 +08:00
if ( bytes_read = = 0 )
{
2012-05-26 01:05:55 +08:00
const char * error_cstr = error . AsCString ( ) ;
if ( error_cstr & & error_cstr [ 0 ] )
{
result . AppendError ( error_cstr ) ;
}
else
{
2012-11-30 05:49:15 +08:00
result . AppendErrorWithFormat ( " failed to read memory from 0x% " PRIx64 " . \n " , addr ) ;
2012-05-26 01:05:55 +08:00
}
2011-04-28 06:04:39 +08:00
result . SetStatus ( eReturnStatusFailed ) ;
return false ;
}
if ( bytes_read < total_byte_size )
2013-11-01 07:55:19 +08:00
result . AppendWarningWithFormat ( " Not all bytes (%zu/%zu) were able to be read from 0x% " PRIx64 " . \n " , bytes_read , total_byte_size , addr ) ;
2013-01-22 03:20:50 +08:00
}
else
{
// we treat c-strings as a special case because they do not have a fixed size
if ( m_format_options . GetByteSizeValue ( ) . OptionWasSet ( ) & & ! m_format_options . HasGDBFormat ( ) )
item_byte_size = m_format_options . GetByteSizeValue ( ) . GetCurrentValue ( ) ;
else
item_byte_size = target - > GetMaximumSizeOfStringSummary ( ) ;
if ( ! m_format_options . GetCountValue ( ) . OptionWasSet ( ) )
item_count = 1 ;
data_sp . reset ( new DataBufferHeap ( ( item_byte_size + 1 ) * item_count , ' \0 ' ) ) ; // account for NULLs as necessary
2013-07-25 02:17:35 +08:00
if ( data_sp - > GetBytes ( ) = = NULL )
{
result . AppendErrorWithFormat ( " can't allocate 0x% " PRIx64 " bytes for the memory read buffer, specify a smaller size to read " , ( uint64_t ) ( ( item_byte_size + 1 ) * item_count ) ) ;
result . SetStatus ( eReturnStatusFailed ) ;
return false ;
}
2013-01-22 03:20:50 +08:00
uint8_t * data_ptr = data_sp - > GetBytes ( ) ;
auto data_addr = addr ;
auto count = item_count ;
item_count = 0 ;
while ( item_count < count )
{
std : : string buffer ;
buffer . resize ( item_byte_size + 1 , 0 ) ;
Error error ;
size_t read = target - > ReadCStringFromMemory ( data_addr , & buffer [ 0 ] , item_byte_size + 1 , error ) ;
if ( error . Fail ( ) )
{
result . AppendErrorWithFormat ( " failed to read memory from 0x% " PRIx64 " . \n " , addr ) ;
result . SetStatus ( eReturnStatusFailed ) ;
return false ;
}
if ( item_byte_size = = read )
{
result . AppendWarningWithFormat ( " unable to find a NULL terminated string at 0x% " PRIx64 " .Consider increasing the maximum read length. \n " , data_addr ) ;
break ;
}
read + = 1 ; // account for final NULL byte
memcpy ( data_ptr , & buffer [ 0 ] , read ) ;
data_ptr + = read ;
data_addr + = read ;
bytes_read + = read ;
item_count + + ; // if we break early we know we only read item_count strings
}
data_sp . reset ( new DataBufferHeap ( data_sp - > GetBytes ( ) , bytes_read + 1 ) ) ;
2010-06-09 00:52:24 +08:00
}
2012-12-15 10:08:17 +08:00
m_next_addr = addr + bytes_read ;
m_prev_byte_size = bytes_read ;
m_prev_format_options = m_format_options ;
m_prev_memory_options = m_memory_options ;
m_prev_outfile_options = m_outfile_options ;
m_prev_varobj_options = m_varobj_options ;
m_prev_clang_ast_type = clang_ast_type ;
2010-10-11 04:52:20 +08:00
StreamFile outfile_stream ;
Stream * output_stream = NULL ;
2011-04-28 06:04:39 +08:00
const FileSpec & outfile_spec = m_outfile_options . GetFile ( ) . GetCurrentValue ( ) ;
if ( outfile_spec )
2010-10-11 04:52:20 +08:00
{
char path [ PATH_MAX ] ;
2011-04-28 06:04:39 +08:00
outfile_spec . GetPath ( path , sizeof ( path ) ) ;
uint32_t open_options = File : : eOpenOptionWrite | File : : eOpenOptionCanCreate ;
const bool append = m_outfile_options . GetAppend ( ) . GetCurrentValue ( ) ;
if ( append )
open_options | = File : : eOpenOptionAppend ;
if ( outfile_stream . GetFile ( ) . Open ( path , open_options ) . Success ( ) )
2010-10-11 04:52:20 +08:00
{
2011-04-28 06:04:39 +08:00
if ( m_memory_options . m_output_as_binary )
2010-10-11 04:52:20 +08:00
{
2013-01-26 02:06:21 +08:00
const size_t bytes_written = outfile_stream . Write ( data_sp - > GetBytes ( ) , bytes_read ) ;
2010-10-11 04:52:20 +08:00
if ( bytes_written > 0 )
{
2013-01-26 02:06:21 +08:00
result . GetOutputStream ( ) . Printf ( " %zi bytes %s to '%s' \n " ,
2010-10-11 04:52:20 +08:00
bytes_written ,
2011-04-28 06:04:39 +08:00
append ? " appended " : " written " ,
2010-10-11 04:52:20 +08:00
path ) ;
return true ;
}
else
{
2012-11-30 05:49:15 +08:00
result . AppendErrorWithFormat ( " Failed to write % " PRIu64 " bytes to '%s'. \n " , ( uint64_t ) bytes_read , path ) ;
2010-10-11 04:52:20 +08:00
result . SetStatus ( eReturnStatusFailed ) ;
return false ;
}
}
else
{
// We are going to write ASCII to the file just point the
// output_stream to our outfile_stream...
output_stream = & outfile_stream ;
}
}
else
{
2011-04-28 06:04:39 +08:00
result . AppendErrorWithFormat ( " Failed to open file '%s' for %s. \n " , path , append ? " append " : " write " ) ;
2010-10-11 04:52:20 +08:00
result . SetStatus ( eReturnStatusFailed ) ;
return false ;
}
}
else
{
output_stream = & result . GetOutputStream ( ) ;
}
2011-04-28 06:04:39 +08:00
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
ExecutionContextScope * exe_scope = m_exe_ctx . GetBestExecutionContextScope ( ) ;
2011-04-28 06:04:39 +08:00
if ( clang_ast_type . GetOpaqueQualType ( ) )
{
for ( uint32_t i = 0 ; i < item_count ; + + i )
{
addr_t item_addr = addr + ( i * item_byte_size ) ;
2012-02-24 09:59:29 +08:00
Address address ( item_addr ) ;
2011-04-28 06:04:39 +08:00
StreamString name_strm ;
2012-11-30 05:49:15 +08:00
name_strm . Printf ( " 0x% " PRIx64 , item_addr ) ;
Added support for the new ".apple_objc" accelerator tables. These tables are
in the same hashed format as the ".apple_names", but they map objective C
class names to all of the methods and class functions. We need to do this
because in the DWARF the methods for Objective C are never contained in the
class definition, they are scattered about at the translation unit level and
they don't even have attributes that say the are contained within the class
itself.
Added 3 new formats which can be used to display data:
eFormatAddressInfo
eFormatHexFloat
eFormatInstruction
eFormatAddressInfo describes an address such as function+offset and file+line,
or symbol + offset, or constant data (c string, 2, 4, 8, or 16 byte constants).
The format character for this is "A", the long format is "address".
eFormatHexFloat will print out the hex float format that compilers tend to use.
The format character for this is "X", the long format is "hex float".
eFormatInstruction will print out disassembly with bytes and it will use the
current target's architecture. The format character for this is "i" (which
used to be being used for the integer format, but the integer format also has
"d", so we gave the "i" format to disassembly), the long format is
"instruction".
Mate the lldb::FormatterChoiceCriterion enumeration private as it should have
been from the start. It is very specialized and doesn't belong in the public
API.
llvm-svn: 143114
2011-10-28 01:55:14 +08:00
ValueObjectSP valobj_sp ( ValueObjectMemory : : Create ( exe_scope ,
2011-04-28 06:04:39 +08:00
name_strm . GetString ( ) . c_str ( ) ,
address ,
clang_ast_type ) ) ;
if ( valobj_sp )
{
2012-12-15 10:08:17 +08:00
Format format = m_format_options . GetFormat ( ) ;
2011-04-29 04:55:26 +08:00
if ( format ! = eFormatDefault )
valobj_sp - > SetFormat ( format ) ;
<rdar://problem/14393032>
DumpValueObject() 2.0
This checkin restores pre-Xcode5 functionality to the "po" (expr -O) command:
- expr now has a new --description-verbosity (-v) argument, which takes either compact or full as a value (-v is the same as -vfull)
When the full mode is on, "po" will show the extended output with type name, persistent variable name and value, as in
(lldb) expr -O -v -- foo
(id) $0 = 0x000000010010baf0 {
1 = 2;
2 = 3;
}
When -v is omitted, or -vcompact is passed, the Xcode5-style output will be shown, as in
(lldb) expr -O -- foo
{
1 = 2;
2 = 3;
}
- for a non-ObjectiveC object, LLDB will still try to retrieve a summary and/or value to display
(lldb) po 5
5
-v also works in this mode
(lldb) expr -O -vfull -- 5
(int) $4 = 5
On top of that, this is a major refactoring of the ValueObject printing code. The functionality is now factored into a ValueObjectPrinter class for easier maintenance in the future
DumpValueObject() was turned into an instance method ValueObject::Dump() which simply calls through to the printer code, Dump_Impl has been removed
Test case to follow
llvm-svn: 191694
2013-10-01 03:11:51 +08:00
DumpValueObjectOptions options ( m_varobj_options . GetAsDumpOptions ( eLanguageRuntimeDescriptionDisplayVerbosityFull , format ) ) ;
2013-03-27 02:04:53 +08:00
<rdar://problem/14393032>
DumpValueObject() 2.0
This checkin restores pre-Xcode5 functionality to the "po" (expr -O) command:
- expr now has a new --description-verbosity (-v) argument, which takes either compact or full as a value (-v is the same as -vfull)
When the full mode is on, "po" will show the extended output with type name, persistent variable name and value, as in
(lldb) expr -O -v -- foo
(id) $0 = 0x000000010010baf0 {
1 = 2;
2 = 3;
}
When -v is omitted, or -vcompact is passed, the Xcode5-style output will be shown, as in
(lldb) expr -O -- foo
{
1 = 2;
2 = 3;
}
- for a non-ObjectiveC object, LLDB will still try to retrieve a summary and/or value to display
(lldb) po 5
5
-v also works in this mode
(lldb) expr -O -vfull -- 5
(int) $4 = 5
On top of that, this is a major refactoring of the ValueObject printing code. The functionality is now factored into a ValueObjectPrinter class for easier maintenance in the future
DumpValueObject() was turned into an instance method ValueObject::Dump() which simply calls through to the printer code, Dump_Impl has been removed
Test case to follow
llvm-svn: 191694
2013-10-01 03:11:51 +08:00
valobj_sp - > Dump ( * output_stream , options ) ;
2011-04-28 06:04:39 +08:00
}
else
{
result . AppendErrorWithFormat ( " failed to create a value object for: (%s) %s \n " ,
view_as_type_cstr ,
name_strm . GetString ( ) . c_str ( ) ) ;
result . SetStatus ( eReturnStatusFailed ) ;
return false ;
}
}
return true ;
}
result . SetStatus ( eReturnStatusSuccessFinishResult ) ;
DataExtractor data ( data_sp ,
2011-09-22 12:58:26 +08:00
target - > GetArchitecture ( ) . GetByteOrder ( ) ,
target - > GetArchitecture ( ) . GetAddressByteSize ( ) ) ;
2013-05-22 01:39:04 +08:00
Format format = m_format_options . GetFormat ( ) ;
if ( ( ( format = = eFormatChar ) | | ( format = = eFormatCharPrintable ) )
2013-10-30 07:04:29 +08:00
& & ( item_byte_size ! = 1 ) )
2013-05-22 01:39:04 +08:00
{
2013-10-30 07:04:29 +08:00
// if a count was not passed, or it is 1
if ( m_format_options . GetCountValue ( ) . OptionWasSet ( ) = = false | | item_count = = 1 )
{
// this turns requests such as
// memory read -fc -s10 -c1 *charPtrPtr
// which make no sense (what is a char of size 10?)
// into a request for fetching 10 chars of size 1 from the same memory location
format = eFormatCharArray ;
item_count = item_byte_size ;
item_byte_size = 1 ;
}
else
{
// here we passed a count, and it was not 1
// so we have a byte_size and a count
// we could well multiply those, but instead let's just fail
result . AppendErrorWithFormat ( " reading memory as characters of size %zu is not supported " , item_byte_size ) ;
result . SetStatus ( eReturnStatusFailed ) ;
return false ;
}
2013-05-22 01:39:04 +08:00
}
2011-04-28 06:04:39 +08:00
2010-10-11 04:52:20 +08:00
assert ( output_stream ) ;
2013-01-26 02:06:21 +08:00
size_t bytes_dumped = data . Dump ( output_stream ,
0 ,
2013-05-22 01:39:04 +08:00
format ,
2013-01-26 02:06:21 +08:00
item_byte_size ,
item_count ,
num_per_line ,
addr ,
0 ,
0 ,
exe_scope ) ;
2011-10-29 07:44:55 +08:00
m_next_addr = addr + bytes_dumped ;
2010-10-11 04:52:20 +08:00
output_stream - > EOL ( ) ;
2010-06-09 00:52:24 +08:00
return true ;
}
2011-04-28 06:04:39 +08:00
OptionGroupOptions m_option_group ;
OptionGroupFormat m_format_options ;
OptionGroupReadMemory m_memory_options ;
OptionGroupOutputFile m_outfile_options ;
2011-04-29 04:55:26 +08:00
OptionGroupValueObjectDisplay m_varobj_options ;
2011-10-26 12:32:38 +08:00
lldb : : addr_t m_next_addr ;
lldb : : addr_t m_prev_byte_size ;
OptionGroupFormat m_prev_format_options ;
OptionGroupReadMemory m_prev_memory_options ;
OptionGroupOutputFile m_prev_outfile_options ;
OptionGroupValueObjectDisplay m_prev_varobj_options ;
2012-12-15 10:08:17 +08:00
ClangASTType m_prev_clang_ast_type ;
2010-06-09 00:52:24 +08:00
} ;
2011-10-25 14:44:01 +08:00
OptionDefinition
g_memory_write_option_table [ ] =
{
2013-09-06 00:42:23 +08:00
{ LLDB_OPT_SET_1 , true , " infile " , ' i ' , OptionParser : : eRequiredArgument , NULL , 0 , eArgTypeFilename , " Write memory using the contents of a file. " } ,
{ LLDB_OPT_SET_1 , false , " offset " , ' o ' , OptionParser : : eRequiredArgument , NULL , 0 , eArgTypeOffset , " Start writng bytes from an offset within the input file. " } ,
2011-10-25 14:44:01 +08:00
} ;
2010-06-09 00:52:24 +08:00
//----------------------------------------------------------------------
// Write memory to the inferior process
//----------------------------------------------------------------------
2012-06-09 05:56:10 +08:00
class CommandObjectMemoryWrite : public CommandObjectParsed
2010-06-09 00:52:24 +08:00
{
public :
2011-10-25 14:44:01 +08:00
class OptionGroupWriteMemory : public OptionGroup
2010-06-09 00:52:24 +08:00
{
public :
2011-10-25 14:44:01 +08:00
OptionGroupWriteMemory ( ) :
OptionGroup ( )
2010-06-09 00:52:24 +08:00
{
}
virtual
2011-10-25 14:44:01 +08:00
~ OptionGroupWriteMemory ( )
2010-06-09 00:52:24 +08:00
{
}
2011-10-25 14:44:01 +08:00
virtual uint32_t
GetNumDefinitions ( )
{
return sizeof ( g_memory_write_option_table ) / sizeof ( OptionDefinition ) ;
}
virtual const OptionDefinition *
GetDefinitions ( )
{
return g_memory_write_option_table ;
}
2010-06-09 00:52:24 +08:00
virtual Error
2011-10-25 14:44:01 +08:00
SetOptionValue ( CommandInterpreter & interpreter ,
uint32_t option_idx ,
const char * option_arg )
2010-06-09 00:52:24 +08:00
{
Error error ;
2012-12-04 08:32:51 +08:00
const int short_option = g_memory_write_option_table [ option_idx ] . short_option ;
2011-10-25 14:44:01 +08:00
2010-06-09 00:52:24 +08:00
switch ( short_option )
{
2011-10-25 14:44:01 +08:00
case ' i ' :
m_infile . SetFile ( option_arg , true ) ;
if ( ! m_infile . Exists ( ) )
2010-10-11 04:52:20 +08:00
{
2011-10-25 14:44:01 +08:00
m_infile . Clear ( ) ;
2011-10-26 08:56:27 +08:00
error . SetErrorStringWithFormat ( " input file does not exist: '%s' " , option_arg ) ;
2010-10-11 04:52:20 +08:00
}
2011-10-25 14:44:01 +08:00
break ;
case ' o ' :
{
bool success ;
m_infile_offset = Args : : StringToUInt64 ( option_arg , 0 , 0 , & success ) ;
if ( ! success )
{
2011-10-26 08:56:27 +08:00
error . SetErrorStringWithFormat ( " invalid offset string '%s' " , option_arg ) ;
2011-10-25 14:44:01 +08:00
}
}
break ;
default :
2011-10-26 08:56:27 +08:00
error . SetErrorStringWithFormat ( " unrecognized short option '%c' " , short_option ) ;
2011-10-25 14:44:01 +08:00
break ;
2010-06-09 00:52:24 +08:00
}
return error ;
}
2011-10-25 14:44:01 +08:00
virtual void
OptionParsingStarting ( CommandInterpreter & interpreter )
2010-06-09 00:52:24 +08:00
{
2010-10-11 04:52:20 +08:00
m_infile . Clear ( ) ;
m_infile_offset = 0 ;
2010-06-09 00:52:24 +08:00
}
2010-10-11 04:52:20 +08:00
FileSpec m_infile ;
off_t m_infile_offset ;
2010-06-09 00:52:24 +08:00
} ;
2010-09-18 09:14:36 +08:00
CommandObjectMemoryWrite ( CommandInterpreter & interpreter ) :
2012-06-09 05:56:10 +08:00
CommandObjectParsed ( interpreter ,
" memory write " ,
" Write to the memory of the process being debugged. " ,
NULL ,
Expanded the flags that can be set for a command object in lldb_private::CommandObject. This list of available flags are:
enum
{
//----------------------------------------------------------------------
// eFlagRequiresTarget
//
// Ensures a valid target is contained in m_exe_ctx prior to executing
// the command. If a target doesn't exist or is invalid, the command
// will fail and CommandObject::GetInvalidTargetDescription() will be
// returned as the error. CommandObject subclasses can override the
// virtual function for GetInvalidTargetDescription() to provide custom
// strings when needed.
//----------------------------------------------------------------------
eFlagRequiresTarget = (1u << 0),
//----------------------------------------------------------------------
// eFlagRequiresProcess
//
// Ensures a valid process is contained in m_exe_ctx prior to executing
// the command. If a process doesn't exist or is invalid, the command
// will fail and CommandObject::GetInvalidProcessDescription() will be
// returned as the error. CommandObject subclasses can override the
// virtual function for GetInvalidProcessDescription() to provide custom
// strings when needed.
//----------------------------------------------------------------------
eFlagRequiresProcess = (1u << 1),
//----------------------------------------------------------------------
// eFlagRequiresThread
//
// Ensures a valid thread is contained in m_exe_ctx prior to executing
// the command. If a thread doesn't exist or is invalid, the command
// will fail and CommandObject::GetInvalidThreadDescription() will be
// returned as the error. CommandObject subclasses can override the
// virtual function for GetInvalidThreadDescription() to provide custom
// strings when needed.
//----------------------------------------------------------------------
eFlagRequiresThread = (1u << 2),
//----------------------------------------------------------------------
// eFlagRequiresFrame
//
// Ensures a valid frame is contained in m_exe_ctx prior to executing
// the command. If a frame doesn't exist or is invalid, the command
// will fail and CommandObject::GetInvalidFrameDescription() will be
// returned as the error. CommandObject subclasses can override the
// virtual function for GetInvalidFrameDescription() to provide custom
// strings when needed.
//----------------------------------------------------------------------
eFlagRequiresFrame = (1u << 3),
//----------------------------------------------------------------------
// eFlagRequiresRegContext
//
// Ensures a valid register context (from the selected frame if there
// is a frame in m_exe_ctx, or from the selected thread from m_exe_ctx)
// is availble from m_exe_ctx prior to executing the command. If a
// target doesn't exist or is invalid, the command will fail and
// CommandObject::GetInvalidRegContextDescription() will be returned as
// the error. CommandObject subclasses can override the virtual function
// for GetInvalidRegContextDescription() to provide custom strings when
// needed.
//----------------------------------------------------------------------
eFlagRequiresRegContext = (1u << 4),
//----------------------------------------------------------------------
// eFlagTryTargetAPILock
//
// Attempts to acquire the target lock if a target is selected in the
// command interpreter. If the command object fails to acquire the API
// lock, the command will fail with an appropriate error message.
//----------------------------------------------------------------------
eFlagTryTargetAPILock = (1u << 5),
//----------------------------------------------------------------------
// eFlagProcessMustBeLaunched
//
// Verifies that there is a launched process in m_exe_ctx, if there
// isn't, the command will fail with an appropriate error message.
//----------------------------------------------------------------------
eFlagProcessMustBeLaunched = (1u << 6),
//----------------------------------------------------------------------
// eFlagProcessMustBePaused
//
// Verifies that there is a paused process in m_exe_ctx, if there
// isn't, the command will fail with an appropriate error message.
//----------------------------------------------------------------------
eFlagProcessMustBePaused = (1u << 7)
};
Now each command object contains a "ExecutionContext m_exe_ctx;" member variable that gets initialized prior to running the command. The validity of the target objects in m_exe_ctx are checked to ensure that any target/process/thread/frame/reg context that are required are valid prior to executing the command. Each command object also contains a Mutex::Locker m_api_locker which gets used if eFlagTryTargetAPILock is set. This centralizes a lot of checking code that was previously and inconsistently implemented across many commands.
llvm-svn: 171990
2013-01-10 03:44:40 +08:00
eFlagRequiresProcess | eFlagProcessMustBeLaunched ) ,
2011-10-25 14:44:01 +08:00
m_option_group ( interpreter ) ,
m_format_options ( eFormatBytes , 1 , UINT64_MAX ) ,
m_memory_options ( )
2010-06-09 00:52:24 +08:00
{
2010-10-05 06:28:36 +08:00
CommandArgumentEntry arg1 ;
CommandArgumentEntry arg2 ;
CommandArgumentData addr_arg ;
CommandArgumentData value_arg ;
// Define the first (and only) variant of this arg.
addr_arg . arg_type = eArgTypeAddress ;
addr_arg . arg_repetition = eArgRepeatPlain ;
// There is only one variant this argument could be; put it into the argument entry.
arg1 . push_back ( addr_arg ) ;
// Define the first (and only) variant of this arg.
value_arg . arg_type = eArgTypeValue ;
value_arg . arg_repetition = eArgRepeatPlus ;
// There is only one variant this argument could be; put it into the argument entry.
arg2 . push_back ( value_arg ) ;
// Push the data for the first argument into the m_arguments vector.
m_arguments . push_back ( arg1 ) ;
m_arguments . push_back ( arg2 ) ;
2011-10-25 14:44:01 +08:00
m_option_group . Append ( & m_format_options , OptionGroupFormat : : OPTION_GROUP_FORMAT , LLDB_OPT_SET_1 ) ;
m_option_group . Append ( & m_format_options , OptionGroupFormat : : OPTION_GROUP_SIZE , LLDB_OPT_SET_1 | LLDB_OPT_SET_2 ) ;
m_option_group . Append ( & m_memory_options , LLDB_OPT_SET_ALL , LLDB_OPT_SET_2 ) ;
m_option_group . Finalize ( ) ;
2010-06-09 00:52:24 +08:00
}
virtual
~ CommandObjectMemoryWrite ( )
{
}
Options *
GetOptions ( )
{
2011-10-25 14:44:01 +08:00
return & m_option_group ;
2010-06-09 00:52:24 +08:00
}
bool
UIntValueIsValidForSize ( uint64_t uval64 , size_t total_byte_size )
{
if ( total_byte_size > 8 )
return false ;
if ( total_byte_size = = 8 )
return true ;
const uint64_t max = ( ( uint64_t ) 1 < < ( uint64_t ) ( total_byte_size * 8 ) ) - 1 ;
return uval64 < = max ;
}
bool
SIntValueIsValidForSize ( int64_t sval64 , size_t total_byte_size )
{
if ( total_byte_size > 8 )
return false ;
if ( total_byte_size = = 8 )
return true ;
const int64_t max = ( ( int64_t ) 1 < < ( uint64_t ) ( total_byte_size * 8 - 1 ) ) - 1 ;
const int64_t min = ~ ( max ) ;
return min < = sval64 & & sval64 < = max ;
}
2012-06-09 05:56:10 +08:00
protected :
2010-06-09 00:52:24 +08:00
virtual bool
2012-06-09 05:56:10 +08:00
DoExecute ( Args & command , CommandReturnObject & result )
2010-06-09 00:52:24 +08:00
{
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
// No need to check "process" for validity as eFlagRequiresProcess ensures it is valid
Process * process = m_exe_ctx . GetProcessPtr ( ) ;
2010-06-09 00:52:24 +08:00
const size_t argc = command . GetArgumentCount ( ) ;
2011-10-25 14:44:01 +08:00
if ( m_memory_options . m_infile )
2010-06-09 00:52:24 +08:00
{
2010-10-11 04:52:20 +08:00
if ( argc < 1 )
{
result . AppendErrorWithFormat ( " %s takes a destination address when writing file contents. \n " , m_cmd_name . c_str ( ) ) ;
result . SetStatus ( eReturnStatusFailed ) ;
return false ;
}
}
else if ( argc < 2 )
{
result . AppendErrorWithFormat ( " %s takes a destination address and at least one value. \n " , m_cmd_name . c_str ( ) ) ;
2010-06-09 00:52:24 +08:00
result . SetStatus ( eReturnStatusFailed ) ;
return false ;
}
StreamString buffer ( Stream : : eBinary ,
2011-02-16 05:59:32 +08:00
process - > GetTarget ( ) . GetArchitecture ( ) . GetAddressByteSize ( ) ,
process - > GetTarget ( ) . GetArchitecture ( ) . GetByteOrder ( ) ) ;
2010-06-09 00:52:24 +08:00
2011-10-25 14:44:01 +08:00
OptionValueUInt64 & byte_size_value = m_format_options . GetByteSizeValue ( ) ;
size_t item_byte_size = byte_size_value . GetCurrentValue ( ) ;
2010-07-10 04:39:50 +08:00
2012-12-07 06:49:16 +08:00
Error error ;
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
lldb : : addr_t addr = Args : : StringToAddress ( & m_exe_ctx ,
2012-12-07 06:49:16 +08:00
command . GetArgumentAtIndex ( 0 ) ,
LLDB_INVALID_ADDRESS ,
& error ) ;
2010-06-09 00:52:24 +08:00
if ( addr = = LLDB_INVALID_ADDRESS )
{
2012-12-07 06:49:16 +08:00
result . AppendError ( " invalid address expression \n " ) ;
result . AppendError ( error . AsCString ( ) ) ;
2010-06-09 00:52:24 +08:00
result . SetStatus ( eReturnStatusFailed ) ;
return false ;
}
2010-10-11 04:52:20 +08:00
2011-10-25 14:44:01 +08:00
if ( m_memory_options . m_infile )
2010-10-11 04:52:20 +08:00
{
size_t length = SIZE_MAX ;
2011-10-25 14:44:01 +08:00
if ( item_byte_size > 0 )
length = item_byte_size ;
lldb : : DataBufferSP data_sp ( m_memory_options . m_infile . ReadFileContents ( m_memory_options . m_infile_offset , length ) ) ;
2010-10-11 04:52:20 +08:00
if ( data_sp )
{
length = data_sp - > GetByteSize ( ) ;
if ( length > 0 )
{
Error error ;
size_t bytes_written = process - > WriteMemory ( addr , data_sp - > GetBytes ( ) , length , error ) ;
if ( bytes_written = = length )
{
// All bytes written
2012-11-30 05:49:15 +08:00
result . GetOutputStream ( ) . Printf ( " % " PRIu64 " bytes were written to 0x% " PRIx64 " \n " , ( uint64_t ) bytes_written , addr ) ;
2010-10-11 04:52:20 +08:00
result . SetStatus ( eReturnStatusSuccessFinishResult ) ;
}
else if ( bytes_written > 0 )
{
// Some byte written
2012-11-30 05:49:15 +08:00
result . GetOutputStream ( ) . Printf ( " % " PRIu64 " bytes of % " PRIu64 " requested were written to 0x% " PRIx64 " \n " , ( uint64_t ) bytes_written , ( uint64_t ) length , addr ) ;
2010-10-11 04:52:20 +08:00
result . SetStatus ( eReturnStatusSuccessFinishResult ) ;
}
else
{
2012-11-30 05:49:15 +08:00
result . AppendErrorWithFormat ( " Memory write to 0x% " PRIx64 " failed: %s. \n " , addr , error . AsCString ( ) ) ;
2010-10-11 04:52:20 +08:00
result . SetStatus ( eReturnStatusFailed ) ;
}
}
}
else
{
result . AppendErrorWithFormat ( " Unable to read contents of file. \n " ) ;
result . SetStatus ( eReturnStatusFailed ) ;
}
return result . Succeeded ( ) ;
}
2011-10-25 14:44:01 +08:00
else if ( item_byte_size = = 0 )
2010-10-11 04:52:20 +08:00
{
2011-10-25 14:44:01 +08:00
if ( m_format_options . GetFormat ( ) = = eFormatPointer )
2010-10-11 04:52:20 +08:00
item_byte_size = buffer . GetAddressByteSize ( ) ;
else
item_byte_size = 1 ;
}
2010-06-09 00:52:24 +08:00
command . Shift ( ) ; // shift off the address argument
uint64_t uval64 ;
int64_t sval64 ;
bool success = false ;
2013-01-26 02:06:21 +08:00
const size_t num_value_args = command . GetArgumentCount ( ) ;
for ( size_t i = 0 ; i < num_value_args ; + + i )
2010-06-09 00:52:24 +08:00
{
const char * value_str = command . GetArgumentAtIndex ( i ) ;
2011-10-25 14:44:01 +08:00
switch ( m_format_options . GetFormat ( ) )
2010-06-09 00:52:24 +08:00
{
2011-06-24 05:22:24 +08:00
case kNumFormats :
2010-06-09 00:52:24 +08:00
case eFormatFloat : // TODO: add support for floats soon
case eFormatCharPrintable :
case eFormatBytesWithASCII :
case eFormatComplex :
case eFormatEnum :
case eFormatUnicode16 :
case eFormatUnicode32 :
case eFormatVectorOfChar :
case eFormatVectorOfSInt8 :
case eFormatVectorOfUInt8 :
case eFormatVectorOfSInt16 :
case eFormatVectorOfUInt16 :
case eFormatVectorOfSInt32 :
case eFormatVectorOfUInt32 :
case eFormatVectorOfSInt64 :
case eFormatVectorOfUInt64 :
case eFormatVectorOfFloat32 :
case eFormatVectorOfFloat64 :
case eFormatVectorOfUInt128 :
2011-03-20 12:57:14 +08:00
case eFormatOSType :
case eFormatComplexInteger :
Added support for the new ".apple_objc" accelerator tables. These tables are
in the same hashed format as the ".apple_names", but they map objective C
class names to all of the methods and class functions. We need to do this
because in the DWARF the methods for Objective C are never contained in the
class definition, they are scattered about at the translation unit level and
they don't even have attributes that say the are contained within the class
itself.
Added 3 new formats which can be used to display data:
eFormatAddressInfo
eFormatHexFloat
eFormatInstruction
eFormatAddressInfo describes an address such as function+offset and file+line,
or symbol + offset, or constant data (c string, 2, 4, 8, or 16 byte constants).
The format character for this is "A", the long format is "address".
eFormatHexFloat will print out the hex float format that compilers tend to use.
The format character for this is "X", the long format is "hex float".
eFormatInstruction will print out disassembly with bytes and it will use the
current target's architecture. The format character for this is "i" (which
used to be being used for the integer format, but the integer format also has
"d", so we gave the "i" format to disassembly), the long format is
"instruction".
Mate the lldb::FormatterChoiceCriterion enumeration private as it should have
been from the start. It is very specialized and doesn't belong in the public
API.
llvm-svn: 143114
2011-10-28 01:55:14 +08:00
case eFormatAddressInfo :
case eFormatHexFloat :
case eFormatInstruction :
2012-08-09 01:35:10 +08:00
case eFormatVoid :
2010-06-09 00:52:24 +08:00
result . AppendError ( " unsupported format for writing memory " ) ;
result . SetStatus ( eReturnStatusFailed ) ;
return false ;
case eFormatDefault :
case eFormatBytes :
case eFormatHex :
2012-08-10 03:33:34 +08:00
case eFormatHexUppercase :
2010-07-10 04:39:50 +08:00
case eFormatPointer :
2010-06-09 00:52:24 +08:00
// Decode hex bytes
uval64 = Args : : StringToUInt64 ( value_str , UINT64_MAX , 16 , & success ) ;
if ( ! success )
{
result . AppendErrorWithFormat ( " '%s' is not a valid hex string value. \n " , value_str ) ;
result . SetStatus ( eReturnStatusFailed ) ;
return false ;
}
else if ( ! UIntValueIsValidForSize ( uval64 , item_byte_size ) )
{
2013-11-01 07:55:19 +08:00
result . AppendErrorWithFormat ( " Value 0x% " PRIx64 " is too large to fit in a %zu byte unsigned integer value. \n " , uval64 , item_byte_size ) ;
2010-06-09 00:52:24 +08:00
result . SetStatus ( eReturnStatusFailed ) ;
return false ;
}
buffer . PutMaxHex64 ( uval64 , item_byte_size ) ;
break ;
case eFormatBoolean :
uval64 = Args : : StringToBoolean ( value_str , false , & success ) ;
if ( ! success )
{
result . AppendErrorWithFormat ( " '%s' is not a valid boolean string value. \n " , value_str ) ;
result . SetStatus ( eReturnStatusFailed ) ;
return false ;
}
buffer . PutMaxHex64 ( uval64 , item_byte_size ) ;
break ;
case eFormatBinary :
uval64 = Args : : StringToUInt64 ( value_str , UINT64_MAX , 2 , & success ) ;
if ( ! success )
{
result . AppendErrorWithFormat ( " '%s' is not a valid binary string value. \n " , value_str ) ;
result . SetStatus ( eReturnStatusFailed ) ;
return false ;
}
else if ( ! UIntValueIsValidForSize ( uval64 , item_byte_size ) )
{
2013-11-01 07:55:19 +08:00
result . AppendErrorWithFormat ( " Value 0x% " PRIx64 " is too large to fit in a %zu byte unsigned integer value. \n " , uval64 , item_byte_size ) ;
2010-06-09 00:52:24 +08:00
result . SetStatus ( eReturnStatusFailed ) ;
return false ;
}
buffer . PutMaxHex64 ( uval64 , item_byte_size ) ;
break ;
2011-06-18 07:50:44 +08:00
case eFormatCharArray :
2010-06-09 00:52:24 +08:00
case eFormatChar :
case eFormatCString :
if ( value_str [ 0 ] )
{
size_t len = strlen ( value_str ) ;
// Include the NULL for C strings...
2011-10-25 14:44:01 +08:00
if ( m_format_options . GetFormat ( ) = = eFormatCString )
2010-06-09 00:52:24 +08:00
+ + len ;
Error error ;
if ( process - > WriteMemory ( addr , value_str , len , error ) = = len )
{
addr + = len ;
}
else
{
2012-11-30 05:49:15 +08:00
result . AppendErrorWithFormat ( " Memory write to 0x% " PRIx64 " failed: %s. \n " , addr , error . AsCString ( ) ) ;
2010-06-09 00:52:24 +08:00
result . SetStatus ( eReturnStatusFailed ) ;
return false ;
}
}
break ;
case eFormatDecimal :
sval64 = Args : : StringToSInt64 ( value_str , INT64_MAX , 0 , & success ) ;
if ( ! success )
{
result . AppendErrorWithFormat ( " '%s' is not a valid signed decimal value. \n " , value_str ) ;
result . SetStatus ( eReturnStatusFailed ) ;
return false ;
}
else if ( ! SIntValueIsValidForSize ( sval64 , item_byte_size ) )
{
2013-11-01 07:55:19 +08:00
result . AppendErrorWithFormat ( " Value % " PRIi64 " is too large or small to fit in a %zu byte signed integer value. \n " , sval64 , item_byte_size ) ;
2010-06-09 00:52:24 +08:00
result . SetStatus ( eReturnStatusFailed ) ;
return false ;
}
buffer . PutMaxHex64 ( sval64 , item_byte_size ) ;
break ;
case eFormatUnsigned :
uval64 = Args : : StringToUInt64 ( value_str , UINT64_MAX , 0 , & success ) ;
if ( ! success )
{
result . AppendErrorWithFormat ( " '%s' is not a valid unsigned decimal string value. \n " , value_str ) ;
result . SetStatus ( eReturnStatusFailed ) ;
return false ;
}
else if ( ! UIntValueIsValidForSize ( uval64 , item_byte_size ) )
{
2013-11-01 07:55:19 +08:00
result . AppendErrorWithFormat ( " Value % " PRIu64 " is too large to fit in a %zu byte unsigned integer value. \n " , uval64 , item_byte_size ) ;
2010-06-09 00:52:24 +08:00
result . SetStatus ( eReturnStatusFailed ) ;
return false ;
}
buffer . PutMaxHex64 ( uval64 , item_byte_size ) ;
break ;
case eFormatOctal :
uval64 = Args : : StringToUInt64 ( value_str , UINT64_MAX , 8 , & success ) ;
if ( ! success )
{
result . AppendErrorWithFormat ( " '%s' is not a valid octal string value. \n " , value_str ) ;
result . SetStatus ( eReturnStatusFailed ) ;
return false ;
}
else if ( ! UIntValueIsValidForSize ( uval64 , item_byte_size ) )
{
2013-11-01 07:55:19 +08:00
result . AppendErrorWithFormat ( " Value % " PRIo64 " is too large to fit in a %zu byte unsigned integer value. \n " , uval64 , item_byte_size ) ;
2010-06-09 00:52:24 +08:00
result . SetStatus ( eReturnStatusFailed ) ;
return false ;
}
buffer . PutMaxHex64 ( uval64 , item_byte_size ) ;
break ;
}
}
if ( ! buffer . GetString ( ) . empty ( ) )
{
Error error ;
2010-07-21 06:52:08 +08:00
if ( process - > WriteMemory ( addr , buffer . GetString ( ) . c_str ( ) , buffer . GetString ( ) . size ( ) , error ) = = buffer . GetString ( ) . size ( ) )
2010-06-09 00:52:24 +08:00
return true ;
else
{
2012-11-30 05:49:15 +08:00
result . AppendErrorWithFormat ( " Memory write to 0x% " PRIx64 " failed: %s. \n " , addr , error . AsCString ( ) ) ;
2010-06-09 00:52:24 +08:00
result . SetStatus ( eReturnStatusFailed ) ;
return false ;
}
}
return true ;
}
2011-10-25 14:44:01 +08:00
OptionGroupOptions m_option_group ;
OptionGroupFormat m_format_options ;
OptionGroupWriteMemory m_memory_options ;
2010-06-09 00:52:24 +08:00
} ;
//-------------------------------------------------------------------------
// CommandObjectMemory
//-------------------------------------------------------------------------
2010-06-23 09:19:29 +08:00
CommandObjectMemory : : CommandObjectMemory ( CommandInterpreter & interpreter ) :
2010-09-18 09:14:36 +08:00
CommandObjectMultiword ( interpreter ,
" memory " ,
2010-09-08 06:38:08 +08:00
" A set of commands for operating on memory. " ,
2010-06-09 00:52:24 +08:00
" memory <subcommand> [<subcommand-options>] " )
{
2010-09-18 09:14:36 +08:00
LoadSubCommand ( " read " , CommandObjectSP ( new CommandObjectMemoryRead ( interpreter ) ) ) ;
LoadSubCommand ( " write " , CommandObjectSP ( new CommandObjectMemoryWrite ( interpreter ) ) ) ;
2010-06-09 00:52:24 +08:00
}
CommandObjectMemory : : ~ CommandObjectMemory ( )
{
}