mirror of
https://git.suyu.dev/suyu/breakpad.git
synced 2026-01-05 05:58:24 +01:00
minidump_dump: dump stack memory like hexdump
The current stack output is one line byte string which is not easy for
humans to parse. Extend the print mode to support a hexdump-like view
and switch to that by default. Now we get something like:
Stack
00000000 20 67 7b 53 94 7f 00 00 01 00 00 00 00 00 00 00 | g{S...........|
00000010 00 70 c4 44 9a 25 00 00 08 65 7a 53 94 7f 00 00 |.p.D.%...ezS...|
BUG=chromium:598947
Change-Id: I868e1cf4faa435a14c5f1c35f94a5db4a49b6a6d
Reviewed-on: https://chromium-review.googlesource.com/404008
Reviewed-by: Mark Mentovai <mark@chromium.org>
This commit is contained in:
parent
117aa25107
commit
e1b3620ec7
3 changed files with 97 additions and 14 deletions
|
|
@ -1202,6 +1202,8 @@ MinidumpMemoryRegion::MinidumpMemoryRegion(Minidump* minidump)
|
|||
: MinidumpObject(minidump),
|
||||
descriptor_(NULL),
|
||||
memory_(NULL) {
|
||||
hexdump_width_ = minidump->HexdumpMode();
|
||||
hexdump_ = hexdump_width_ != 0;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -1360,19 +1362,77 @@ void MinidumpMemoryRegion::Print() const {
|
|||
|
||||
const uint8_t* memory = GetMemory();
|
||||
if (memory) {
|
||||
printf("0x");
|
||||
for (unsigned int byte_index = 0;
|
||||
byte_index < descriptor_->memory.data_size;
|
||||
byte_index++) {
|
||||
printf("%02x", memory[byte_index]);
|
||||
if (hexdump_) {
|
||||
// Pretty hexdump view.
|
||||
for (unsigned int byte_index = 0;
|
||||
byte_index < descriptor_->memory.data_size;
|
||||
byte_index += hexdump_width_) {
|
||||
// In case the memory won't fill a whole line.
|
||||
unsigned int num_bytes = std::min(
|
||||
descriptor_->memory.data_size - byte_index, hexdump_width_);
|
||||
|
||||
// Display the leading address.
|
||||
printf("%08x ", byte_index);
|
||||
|
||||
// Show the bytes in hex.
|
||||
for (unsigned int i = 0; i < hexdump_width_; ++i) {
|
||||
if (i < num_bytes) {
|
||||
// Show the single byte of memory in hex.
|
||||
printf("%02x ", memory[byte_index + i]);
|
||||
} else {
|
||||
// If this line doesn't fill up, pad it out.
|
||||
printf(" ");
|
||||
}
|
||||
|
||||
// Insert a space every 8 bytes to make it more readable.
|
||||
if (((i + 1) % 8) == 0) {
|
||||
printf(" ");
|
||||
}
|
||||
}
|
||||
|
||||
// Decode the line as ASCII.
|
||||
printf("|");
|
||||
for (unsigned int i = 0; i < hexdump_width_; ++i) {
|
||||
if (i < num_bytes) {
|
||||
uint8_t byte = memory[byte_index + i];
|
||||
printf("%c", isprint(byte) ? byte : '.');
|
||||
} else {
|
||||
// If this line doesn't fill up, pad it out.
|
||||
printf(" ");
|
||||
}
|
||||
}
|
||||
printf("|\n");
|
||||
}
|
||||
} else {
|
||||
// Ugly raw string view.
|
||||
printf("0x");
|
||||
for (unsigned int i = 0;
|
||||
i < descriptor_->memory.data_size;
|
||||
i++) {
|
||||
printf("%02x", memory[i]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
printf("\n");
|
||||
} else {
|
||||
printf("No memory\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MinidumpMemoryRegion::SetPrintMode(bool hexdump,
|
||||
unsigned int hexdump_width) {
|
||||
// Require the width to be a multiple of 8 bytes.
|
||||
if (hexdump_width == 0 || (hexdump_width % 8) != 0) {
|
||||
BPLOG(ERROR) << "MinidumpMemoryRegion print hexdump_width must be "
|
||||
"multiple of 8, not " << hexdump_width;
|
||||
return;
|
||||
}
|
||||
|
||||
hexdump_ = hexdump;
|
||||
hexdump_width_ = hexdump_width;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// MinidumpThread
|
||||
//
|
||||
|
|
@ -4694,14 +4754,16 @@ uint32_t Minidump::max_streams_ = 128;
|
|||
unsigned int Minidump::max_string_length_ = 1024;
|
||||
|
||||
|
||||
Minidump::Minidump(const string& path)
|
||||
Minidump::Minidump(const string& path, bool hexdump, unsigned int hexdump_width)
|
||||
: header_(),
|
||||
directory_(NULL),
|
||||
stream_map_(new MinidumpStreamMap()),
|
||||
path_(path),
|
||||
stream_(NULL),
|
||||
swap_(false),
|
||||
valid_(false) {
|
||||
valid_(false),
|
||||
hexdump_(hexdump),
|
||||
hexdump_width_(hexdump_width) {
|
||||
}
|
||||
|
||||
Minidump::Minidump(istream& stream)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue