本文整理汇总了C++中DataExtractor::Dump方法的典型用法代码示例。如果您正苦于以下问题:C++ DataExtractor::Dump方法的具体用法?C++ DataExtractor::Dump怎么用?C++ DataExtractor::Dump使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataExtractor
的用法示例。
在下文中一共展示了DataExtractor::Dump方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: data
static bool
DumpUInt (ExecutionContextScope *exe_scope, const Address &address, uint32_t byte_size, Stream* strm)
{
if (exe_scope == NULL || byte_size == 0)
return 0;
std::vector<uint8_t> buf(byte_size, 0);
if (ReadBytes (exe_scope, address, &buf[0], buf.size()) == buf.size())
{
ByteOrder byte_order = eByteOrderInvalid;
uint32_t addr_size = 0;
if (GetByteOrderAndAddressSize (exe_scope, address, byte_order, addr_size))
{
DataExtractor data (&buf.front(), buf.size(), byte_order, addr_size);
data.Dump (strm,
0, // Start offset in "data"
eFormatHex, // Print as characters
buf.size(), // Size of item
1, // Items count
UINT32_MAX, // num per line
LLDB_INVALID_ADDRESS,// base address
0, // bitfield bit size
0); // bitfield bit offset
return true;
}
}
return false;
}
示例2: Dump
bool RegisterValue::Dump(Stream *s, const RegisterInfo *reg_info,
bool prefix_with_name, bool prefix_with_alt_name,
Format format,
uint32_t reg_name_right_align_at) const {
DataExtractor data;
if (GetData(data)) {
bool name_printed = false;
// For simplicity, alignment of the register name printing applies only
// in the most common case where:
//
// prefix_with_name^prefix_with_alt_name is true
//
StreamString format_string;
if (reg_name_right_align_at && (prefix_with_name ^ prefix_with_alt_name))
format_string.Printf("%%%us", reg_name_right_align_at);
else
format_string.Printf("%%s");
const char *fmt = format_string.GetData();
if (prefix_with_name) {
if (reg_info->name) {
s->Printf(fmt, reg_info->name);
name_printed = true;
} else if (reg_info->alt_name) {
s->Printf(fmt, reg_info->alt_name);
prefix_with_alt_name = false;
name_printed = true;
}
}
if (prefix_with_alt_name) {
if (name_printed)
s->PutChar('/');
if (reg_info->alt_name) {
s->Printf(fmt, reg_info->alt_name);
name_printed = true;
} else if (!name_printed) {
// No alternate name but we were asked to display a name, so show the
// main name
s->Printf(fmt, reg_info->name);
name_printed = true;
}
}
if (name_printed)
s->PutCString(" = ");
if (format == eFormatDefault)
format = reg_info->format;
data.Dump(s,
0, // Offset in "data"
format, // Format to use when dumping
reg_info->byte_size, // item_byte_size
1, // item_count
UINT32_MAX, // num_per_line
LLDB_INVALID_ADDRESS, // base_addr
0, // item_bit_size
0); // item_bit_offset
return true;
}
return false;
}
示例3: Dump
void EventDataBytes::Dump(Stream *s) const {
size_t num_printable_chars =
std::count_if(m_bytes.begin(), m_bytes.end(), isprint);
if (num_printable_chars == m_bytes.size()) {
s->Printf("\"%s\"", m_bytes.c_str());
} else if (!m_bytes.empty()) {
DataExtractor data;
data.SetData(m_bytes.data(), m_bytes.size(), endian::InlHostByteOrder());
data.Dump(s, 0, eFormatBytes, 1, m_bytes.size(), 32, LLDB_INVALID_ADDRESS,
0, 0);
}
}
示例4: exe_ctx
bool
TypeFormatImpl_Format::FormatObject (ValueObject *valobj,
std::string& dest) const
{
if (!valobj)
return false;
if (valobj->CanProvideValue())
{
Value& value(valobj->GetValue());
const Value::ContextType context_type = value.GetContextType();
ExecutionContext exe_ctx (valobj->GetExecutionContextRef());
DataExtractor data;
if (context_type == Value::eContextTypeRegisterInfo)
{
const RegisterInfo *reg_info = value.GetRegisterInfo();
if (reg_info)
{
Error error;
valobj->GetData(data, error);
if (error.Fail())
return false;
StreamString reg_sstr;
data.Dump (®_sstr,
0,
GetFormat(),
reg_info->byte_size,
1,
UINT32_MAX,
LLDB_INVALID_ADDRESS,
0,
0,
exe_ctx.GetBestExecutionContextScope());
dest.swap(reg_sstr.GetString());
}
}
else
{
CompilerType compiler_type = value.GetCompilerType ();
if (compiler_type)
{
// put custom bytes to display in the DataExtractor to override the default value logic
if (GetFormat() == eFormatCString)
{
lldb_private::Flags type_flags(compiler_type.GetTypeInfo(NULL)); // disambiguate w.r.t. TypeFormatImpl::Flags
if (type_flags.Test(eTypeIsPointer) && !type_flags.Test(eTypeIsObjC))
{
// if we are dumping a pointer as a c-string, get the pointee data as a string
TargetSP target_sp(valobj->GetTargetSP());
if (target_sp)
{
size_t max_len = target_sp->GetMaximumSizeOfStringSummary();
Error error;
DataBufferSP buffer_sp(new DataBufferHeap(max_len+1,0));
Address address(valobj->GetPointerValue());
if (target_sp->ReadCStringFromMemory(address, (char*)buffer_sp->GetBytes(), max_len, error) && error.Success())
data.SetData(buffer_sp);
}
}
}
else
{
Error error;
valobj->GetData(data, error);
if (error.Fail())
return false;
}
StreamString sstr;
compiler_type.DumpTypeValue (&sstr, // The stream to use for display
GetFormat(), // Format to display this type with
data, // Data to extract from
0, // Byte offset into "m_data"
valobj->GetByteSize(), // Byte size of item in "m_data"
valobj->GetBitfieldBitSize(), // Bitfield bit size
valobj->GetBitfieldBitOffset(), // Bitfield bit offset
exe_ctx.GetBestExecutionContextScope());
// Given that we do not want to set the ValueObject's m_error
// for a formatting error (or else we wouldn't be able to reformat
// until a next update), an empty string is treated as a "false"
// return from here, but that's about as severe as we get
// CompilerType::DumpTypeValue() should always return
// something, even if that something is an error message
if (sstr.GetString().empty())
dest.clear();
else
dest.swap(sstr.GetString());
}
}
return !dest.empty();
}
else
return false;
}
示例5: data
size_t
UnwindAssemblyInstEmulation::WriteMemory (EmulateInstruction *instruction,
const EmulateInstruction::Context &context,
lldb::addr_t addr,
const void *dst,
size_t dst_len)
{
DataExtractor data (dst,
dst_len,
instruction->GetArchitecture ().GetByteOrder(),
instruction->GetArchitecture ().GetAddressByteSize());
Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_UNWIND));
if (log && log->GetVerbose ())
{
StreamString strm;
strm.PutCString ("UnwindAssemblyInstEmulation::WriteMemory (");
data.Dump(&strm, 0, eFormatBytes, 1, dst_len, UINT32_MAX, addr, 0, 0);
strm.PutCString (", context = ");
context.Dump(strm, instruction);
log->PutCString (strm.GetData());
}
const bool cant_replace = false;
switch (context.type)
{
default:
case EmulateInstruction::eContextInvalid:
case EmulateInstruction::eContextReadOpcode:
case EmulateInstruction::eContextImmediate:
case EmulateInstruction::eContextAdjustBaseRegister:
case EmulateInstruction::eContextRegisterPlusOffset:
case EmulateInstruction::eContextAdjustPC:
case EmulateInstruction::eContextRegisterStore:
case EmulateInstruction::eContextRegisterLoad:
case EmulateInstruction::eContextRelativeBranchImmediate:
case EmulateInstruction::eContextAbsoluteBranchRegister:
case EmulateInstruction::eContextSupervisorCall:
case EmulateInstruction::eContextTableBranchReadMemory:
case EmulateInstruction::eContextWriteRegisterRandomBits:
case EmulateInstruction::eContextWriteMemoryRandomBits:
case EmulateInstruction::eContextArithmetic:
case EmulateInstruction::eContextAdvancePC:
case EmulateInstruction::eContextReturnFromException:
case EmulateInstruction::eContextPopRegisterOffStack:
case EmulateInstruction::eContextAdjustStackPointer:
break;
case EmulateInstruction::eContextPushRegisterOnStack:
{
uint32_t reg_num = LLDB_INVALID_REGNUM;
uint32_t generic_regnum = LLDB_INVALID_REGNUM;
if (context.info_type == EmulateInstruction::eInfoTypeRegisterToRegisterPlusOffset)
{
const uint32_t unwind_reg_kind = m_unwind_plan_ptr->GetRegisterKind();
reg_num = context.info.RegisterToRegisterPlusOffset.data_reg.kinds[unwind_reg_kind];
generic_regnum = context.info.RegisterToRegisterPlusOffset.data_reg.kinds[eRegisterKindGeneric];
}
else
assert (!"unhandled case, add code to handle this!");
if (reg_num != LLDB_INVALID_REGNUM && generic_regnum != LLDB_REGNUM_GENERIC_SP)
{
if (m_pushed_regs.find (reg_num) == m_pushed_regs.end())
{
m_pushed_regs[reg_num] = addr;
const int32_t offset = addr - m_initial_sp;
m_curr_row->SetRegisterLocationToAtCFAPlusOffset (reg_num, offset, cant_replace);
m_curr_row_modified = true;
}
}
}
break;
}
return dst_len;
}
示例6: if
//.........这里部分代码省略.........
return false;
}
else if (item_count != 0)
{
result.AppendErrorWithFormat("Specify either the end address (0x%llx) or the count (--count %u), not both.\n", end_addr, item_count);
result.SetStatus(eReturnStatusFailed);
return false;
}
total_byte_size = end_addr - addr;
item_count = total_byte_size / item_byte_size;
}
else
{
if (item_count == 0)
item_count = 32;
}
DataBufferSP data_sp(new DataBufferHeap (total_byte_size, '\0'));
Error error;
size_t bytes_read = process->ReadMemory(addr, data_sp->GetBytes (), data_sp->GetByteSize(), error);
if (bytes_read == 0)
{
result.AppendWarningWithFormat("Read from 0x%llx failed.\n", addr);
result.AppendError(error.AsCString());
result.SetStatus(eReturnStatusFailed);
return false;
}
if (bytes_read < total_byte_size)
result.AppendWarningWithFormat("Not all bytes (%u/%u) were able to be read from 0x%llx.\n", bytes_read, total_byte_size, addr);
result.SetStatus(eReturnStatusSuccessFinishResult);
DataExtractor data (data_sp,
process->GetTarget().GetArchitecture().GetByteOrder(),
process->GetTarget().GetArchitecture().GetAddressByteSize());
StreamFile outfile_stream;
Stream *output_stream = NULL;
if (m_options.m_outfile_filespec)
{
char path[PATH_MAX];
m_options.m_outfile_filespec.GetPath (path, sizeof(path));
char mode[16] = { 'w', '\0' };
if (m_options.m_append_to_outfile)
mode[0] = 'a';
if (outfile_stream.GetFile ().Open (path, File::eOpenOptionWrite | File::eOpenOptionCanCreate).Success())
{
if (m_options.m_output_as_binary)
{
int bytes_written = outfile_stream.Write (data_sp->GetBytes(), bytes_read);
if (bytes_written > 0)
{
result.GetOutputStream().Printf ("%i bytes %s to '%s'\n",
bytes_written,
m_options.m_append_to_outfile ? "appended" : "written",
path);
return true;
}
else
{
result.AppendErrorWithFormat("Failed to write %zu bytes to '%s'.\n", bytes_read, path);
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
{
result.AppendErrorWithFormat("Failed to open file '%s' with a mode of '%s'.\n", path, mode);
result.SetStatus(eReturnStatusFailed);
return false;
}
}
else
{
output_stream = &result.GetOutputStream();
}
assert (output_stream);
data.Dump (output_stream,
0,
m_options.m_format,
item_byte_size,
item_count,
num_per_line,
addr,
0,
0);
output_stream->EOL();
return true;
}
示例7: switch
bool
GoASTContext::DumpTypeValue(lldb::opaque_compiler_type_t type,
Stream *s,
lldb::Format format,
const DataExtractor &data,
lldb::offset_t byte_offset,
size_t byte_size,
uint32_t bitfield_bit_size,
uint32_t bitfield_bit_offset,
ExecutionContextScope *exe_scope,
bool is_base_class)
{
if (!type)
return false;
if (IsAggregateType(type))
{
return false;
}
else
{
GoType *t = static_cast<GoType *>(type);
if (t->IsTypedef())
{
CompilerType typedef_compiler_type = t->GetElementType();
if (format == eFormatDefault)
format = typedef_compiler_type.GetFormat();
uint64_t typedef_byte_size = typedef_compiler_type.GetByteSize(exe_scope);
return typedef_compiler_type.DumpTypeValue(
s,
format, // The format with which to display the element
data, // Data buffer containing all bytes for this type
byte_offset, // Offset into "data" where to grab value from
typedef_byte_size, // Size of this type in bytes
bitfield_bit_size, // Size in bits of a bitfield value, if zero don't treat as a bitfield
bitfield_bit_offset, // Offset in bits of a bitfield value if bitfield_bit_size != 0
exe_scope,
is_base_class);
}
uint32_t item_count = 1;
// A few formats, we might need to modify our size and count for depending
// on how we are trying to display the value...
switch (format)
{
default:
case eFormatBoolean:
case eFormatBinary:
case eFormatComplex:
case eFormatCString: // NULL terminated C strings
case eFormatDecimal:
case eFormatEnum:
case eFormatHex:
case eFormatHexUppercase:
case eFormatFloat:
case eFormatOctal:
case eFormatOSType:
case eFormatUnsigned:
case eFormatPointer:
case eFormatVectorOfChar:
case eFormatVectorOfSInt8:
case eFormatVectorOfUInt8:
case eFormatVectorOfSInt16:
case eFormatVectorOfUInt16:
case eFormatVectorOfSInt32:
case eFormatVectorOfUInt32:
case eFormatVectorOfSInt64:
case eFormatVectorOfUInt64:
case eFormatVectorOfFloat32:
case eFormatVectorOfFloat64:
case eFormatVectorOfUInt128:
break;
case eFormatChar:
case eFormatCharPrintable:
case eFormatCharArray:
case eFormatBytes:
case eFormatBytesWithASCII:
item_count = byte_size;
byte_size = 1;
break;
case eFormatUnicode16:
item_count = byte_size / 2;
byte_size = 2;
break;
case eFormatUnicode32:
item_count = byte_size / 4;
byte_size = 4;
break;
}
return data.Dump(s, byte_offset, format, byte_size, item_count, UINT32_MAX, LLDB_INVALID_ADDRESS,
bitfield_bit_size, bitfield_bit_offset, exe_scope);
}
return 0;
}
示例8: GetOpaqueClangQualType
const char *
ValueObject::GetSummaryAsCString (ExecutionContextScope *exe_scope)
{
if (UpdateValueIfNeeded (exe_scope))
{
if (m_summary_str.empty())
{
void *clang_type = GetOpaqueClangQualType();
// See if this is a pointer to a C string?
uint32_t fixed_length = 0;
if (clang_type && ClangASTContext::IsCStringType (clang_type, fixed_length))
{
Process *process = exe_scope->CalculateProcess();
if (process != NULL)
{
StreamString sstr;
lldb::addr_t cstr_address = LLDB_INVALID_ADDRESS;
lldb::AddressType cstr_address_type = eAddressTypeInvalid;
switch (GetValue().GetValueType())
{
case Value::eValueTypeScalar:
cstr_address = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
cstr_address_type = eAddressTypeLoad;
break;
case Value::eValueTypeLoadAddress:
case Value::eValueTypeFileAddress:
case Value::eValueTypeHostAddress:
{
uint32_t data_offset = 0;
cstr_address = m_data.GetPointer(&data_offset);
cstr_address_type = m_value.GetValueAddressType();
if (cstr_address_type == eAddressTypeInvalid)
cstr_address_type = eAddressTypeLoad;
}
break;
}
if (cstr_address != LLDB_INVALID_ADDRESS)
{
DataExtractor data;
size_t bytes_read = 0;
std::vector<char> data_buffer;
std::vector<char> cstr_buffer;
size_t cstr_length;
Error error;
if (fixed_length > 0)
{
data_buffer.resize(fixed_length);
// Resize the formatted buffer in case every character
// uses the "\xXX" format and one extra byte for a NULL
cstr_buffer.resize(data_buffer.size() * 4 + 1);
data.SetData (data_buffer.data(), data_buffer.size(), eByteOrderHost);
bytes_read = process->ReadMemory (cstr_address, data_buffer.data(), fixed_length, error);
if (bytes_read > 0)
{
sstr << '"';
cstr_length = data.Dump (&sstr,
0, // Start offset in "data"
eFormatChar, // Print as characters
1, // Size of item (1 byte for a char!)
bytes_read, // How many bytes to print?
UINT32_MAX, // num per line
LLDB_INVALID_ADDRESS,// base address
0, // bitfield bit size
0); // bitfield bit offset
sstr << '"';
}
}
else
{
const size_t k_max_buf_size = 256;
data_buffer.resize (k_max_buf_size + 1);
// NULL terminate in case we don't get the entire C string
data_buffer.back() = '\0';
// Make a formatted buffer that can contain take 4
// bytes per character in case each byte uses the
// "\xXX" format and one extra byte for a NULL
cstr_buffer.resize (k_max_buf_size * 4 + 1);
data.SetData (data_buffer.data(), data_buffer.size(), eByteOrderHost);
size_t total_cstr_len = 0;
while ((bytes_read = process->ReadMemory (cstr_address, data_buffer.data(), k_max_buf_size, error)) > 0)
{
size_t len = strlen(data_buffer.data());
if (len == 0)
break;
if (len > bytes_read)
len = bytes_read;
if (sstr.GetSize() == 0)
sstr << '"';
cstr_length = data.Dump (&sstr,
0, // Start offset in "data"
eFormatChar, // Print as characters
1, // Size of item (1 byte for a char!)
len, // How many bytes to print?
UINT32_MAX, // num per line
LLDB_INVALID_ADDRESS,// base address
//.........这里部分代码省略.........
示例9: exe_ctx
//.........这里部分代码省略.........
path);
return true;
}
else
{
result.AppendErrorWithFormat("Failed to write %zu bytes to '%s'.\n", bytes_read, path);
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
{
result.AppendErrorWithFormat("Failed to open file '%s' for %s.\n", path, append ? "append" : "write");
result.SetStatus(eReturnStatusFailed);
return false;
}
}
else
{
output_stream = &result.GetOutputStream();
}
ExecutionContextScope *exe_scope = exe_ctx.GetBestExecutionContextScope();
if (clang_ast_type.GetOpaqueQualType())
{
for (uint32_t i = 0; i<item_count; ++i)
{
addr_t item_addr = addr + (i * item_byte_size);
Address address (item_addr);
StreamString name_strm;
name_strm.Printf ("0x%llx", item_addr);
ValueObjectSP valobj_sp (ValueObjectMemory::Create (exe_scope,
name_strm.GetString().c_str(),
address,
clang_ast_type));
if (valobj_sp)
{
if (format != eFormatDefault)
valobj_sp->SetFormat (format);
bool scope_already_checked = true;
ValueObject::DumpValueObjectOptions options;
options.SetMaximumPointerDepth(m_varobj_options.ptr_depth)
.SetMaximumDepth(m_varobj_options.max_depth)
.SetShowLocation(m_varobj_options.show_location)
.SetShowTypes(m_varobj_options.show_types)
.SetUseObjectiveC(m_varobj_options.use_objc)
.SetScopeChecked(scope_already_checked)
.SetFlatOutput(m_varobj_options.flat_output)
.SetUseSyntheticValue(m_varobj_options.be_raw ? false : m_varobj_options.use_synth)
.SetOmitSummaryDepth(m_varobj_options.be_raw ? UINT32_MAX : m_varobj_options.no_summary_depth)
.SetIgnoreCap(m_varobj_options.be_raw ? true : m_varobj_options.ignore_cap)
.SetFormat(format)
.SetSummary();
ValueObject::DumpValueObject (*output_stream,
valobj_sp.get(),
options);
}
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,
target->GetArchitecture().GetByteOrder(),
target->GetArchitecture().GetAddressByteSize());
assert (output_stream);
uint32_t bytes_dumped = data.Dump (output_stream,
0,
m_format_options.GetFormat(),
item_byte_size,
item_count,
num_per_line,
addr,
0,
0,
exe_scope);
m_next_addr = addr + bytes_dumped;
output_stream->EOL();
return true;
}