本文整理汇总了C++中DataExtractor::PeekCStr方法的典型用法代码示例。如果您正苦于以下问题:C++ DataExtractor::PeekCStr方法的具体用法?C++ DataExtractor::PeekCStr怎么用?C++ DataExtractor::PeekCStr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataExtractor
的用法示例。
在下文中一共展示了DataExtractor::PeekCStr方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DumpPacket
//.........这里部分代码省略.........
&s, // Stream to dump to
offset, // Offset within "packet"
eFormatBytesWithASCII, // Format to use
1, // Size of each item
// in bytes
count, // Number of items
16, // Number per line
m_last_read_memory_addr, // Don't show addresses
// before each line
0, 0); // No bitfields
} break;
case KDP_READREGS: {
const uint32_t error = packet.GetU32(&offset);
const uint32_t count = packet.GetByteSize() - offset;
s.Printf(" (error = 0x%8.8x regs:\n", error);
if (count > 0)
DumpDataExtractor(packet,
&s, // Stream to dump to
offset, // Offset within "packet"
eFormatHex, // Format to use
m_addr_byte_size, // Size of each item
// in bytes
count / m_addr_byte_size, // Number of items
16 / m_addr_byte_size, // Number per line
LLDB_INVALID_ADDRESS,
// Don't
// show addresses before
// each line
0, 0); // No bitfields
} break;
case KDP_KERNELVERSION: {
const char *kernel_version = packet.PeekCStr(8);
s.Printf(" (version = \"%s\")", kernel_version);
} break;
case KDP_MAXBYTES: {
const uint32_t max_bytes = packet.GetU32(&offset);
s.Printf(" (max_bytes = 0x%8.8x (%u))", max_bytes, max_bytes);
} break;
case KDP_IMAGEPATH: {
const char *path = packet.GetCStr(&offset);
s.Printf(" (path = \"%s\")", path);
} break;
case KDP_READIOPORT:
case KDP_READMSR64: {
const uint32_t error = packet.GetU32(&offset);
const uint32_t count = packet.GetByteSize() - offset;
s.Printf(" (error = 0x%8.8x io:\n", error);
if (count > 0)
DumpDataExtractor(packet,
&s, // Stream to dump to
offset, // Offset within "packet"
eFormatHex, // Format to use
1, // Size of each item in bytes
count, // Number of items
16, // Number per line
LLDB_INVALID_ADDRESS, // Don't show addresses
// before each line
0, 0); // No bitfields
} break;
case KDP_DUMPINFO: {
const uint32_t count = packet.GetByteSize() - offset;
s.Printf(" (count = %u, bytes = \n", count);
示例2: ParseLoadCommands
// Parse the load commands for an image
uint32_t DynamicLoaderMacOSXDYLD::ParseLoadCommands(const DataExtractor &data,
ImageInfo &dylib_info,
FileSpec *lc_id_dylinker) {
lldb::offset_t offset = 0;
uint32_t cmd_idx;
Segment segment;
dylib_info.Clear(true);
for (cmd_idx = 0; cmd_idx < dylib_info.header.ncmds; cmd_idx++) {
// Clear out any load command specific data from DYLIB_INFO since we are
// about to read it.
if (data.ValidOffsetForDataOfSize(offset,
sizeof(llvm::MachO::load_command))) {
llvm::MachO::load_command load_cmd;
lldb::offset_t load_cmd_offset = offset;
load_cmd.cmd = data.GetU32(&offset);
load_cmd.cmdsize = data.GetU32(&offset);
switch (load_cmd.cmd) {
case llvm::MachO::LC_SEGMENT: {
segment.name.SetTrimmedCStringWithLength(
(const char *)data.GetData(&offset, 16), 16);
// We are putting 4 uint32_t values 4 uint64_t values so we have to use
// multiple 32 bit gets below.
segment.vmaddr = data.GetU32(&offset);
segment.vmsize = data.GetU32(&offset);
segment.fileoff = data.GetU32(&offset);
segment.filesize = data.GetU32(&offset);
// Extract maxprot, initprot, nsects and flags all at once
data.GetU32(&offset, &segment.maxprot, 4);
dylib_info.segments.push_back(segment);
} break;
case llvm::MachO::LC_SEGMENT_64: {
segment.name.SetTrimmedCStringWithLength(
(const char *)data.GetData(&offset, 16), 16);
// Extract vmaddr, vmsize, fileoff, and filesize all at once
data.GetU64(&offset, &segment.vmaddr, 4);
// Extract maxprot, initprot, nsects and flags all at once
data.GetU32(&offset, &segment.maxprot, 4);
dylib_info.segments.push_back(segment);
} break;
case llvm::MachO::LC_ID_DYLINKER:
if (lc_id_dylinker) {
const lldb::offset_t name_offset =
load_cmd_offset + data.GetU32(&offset);
const char *path = data.PeekCStr(name_offset);
lc_id_dylinker->SetFile(path, FileSpec::Style::native);
FileSystem::Instance().Resolve(*lc_id_dylinker);
}
break;
case llvm::MachO::LC_UUID:
dylib_info.uuid = UUID::fromOptionalData(data.GetData(&offset, 16), 16);
break;
default:
break;
}
// Set offset to be the beginning of the next load command.
offset = load_cmd_offset + load_cmd.cmdsize;
}
}
// All sections listed in the dyld image info structure will all either be
// fixed up already, or they will all be off by a single slide amount that is
// determined by finding the first segment that is at file offset zero which
// also has bytes (a file size that is greater than zero) in the object file.
// Determine the slide amount (if any)
const size_t num_sections = dylib_info.segments.size();
for (size_t i = 0; i < num_sections; ++i) {
// Iterate through the object file sections to find the first section that
// starts of file offset zero and that has bytes in the file...
if ((dylib_info.segments[i].fileoff == 0 &&
dylib_info.segments[i].filesize > 0) ||
(dylib_info.segments[i].name == "__TEXT")) {
dylib_info.slide = dylib_info.address - dylib_info.segments[i].vmaddr;
// We have found the slide amount, so we can exit this for loop.
break;
}
}
return cmd_idx;
}