Commit afc37ebd authored by Zhao Jiazhong's avatar Zhao Jiazhong Committed by Commit Bot

[mips][simulator] Add a new command to the debugger to dump memory.

Port 820faa6e
https://crrev.com/c/2056468

Original Commit Message:

  The arm/arm64 simulators debugger has a command "mem" that prints
  the content of the memory. It also prints a short summary for JS
  objects (SMI, Array, JSFunction, ...). That is very handy, but
  when trying to print incomplete initialized memory, it could raise
  an exception.

  It is useful to have a command that prints the content of the memory
  for non-initialized or bogus values without the risk of raising
  an exception. This CL adds the command "dump".

Change-Id: If8c96d7bac4a484c2a4fee9d192a29ea2696580a
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2089224Reviewed-by: 's avatarVictor Gomes <victorgomes@chromium.org>
Reviewed-by: 's avatarIgor Sheludko <ishell@chromium.org>
Commit-Queue: Victor Gomes <victorgomes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#66615}
parent d29c68be
...@@ -465,7 +465,8 @@ void MipsDebugger::Debug() { ...@@ -465,7 +465,8 @@ void MipsDebugger::Debug() {
} else { } else {
PrintF("printobject <value>\n"); PrintF("printobject <value>\n");
} }
} else if (strcmp(cmd, "stack") == 0 || strcmp(cmd, "mem") == 0) { } else if (strcmp(cmd, "stack") == 0 || strcmp(cmd, "mem") == 0 ||
strcmp(cmd, "dump") == 0) {
int32_t* cur = nullptr; int32_t* cur = nullptr;
int32_t* end = nullptr; int32_t* end = nullptr;
int next_arg = 1; int next_arg = 1;
...@@ -505,20 +506,23 @@ void MipsDebugger::Debug() { ...@@ -505,20 +506,23 @@ void MipsDebugger::Debug() {
end = cur + words; end = cur + words;
} }
bool skip_obj_print = (strcmp(cmd, "dump") == 0);
while (cur < end) { while (cur < end) {
PrintF(" 0x%08" PRIxPTR ": 0x%08x %10d", PrintF(" 0x%08" PRIxPTR ": 0x%08x %10d",
reinterpret_cast<intptr_t>(cur), *cur, *cur); reinterpret_cast<intptr_t>(cur), *cur, *cur);
Object obj(*cur); Object obj(*cur);
Heap* current_heap = sim_->isolate_->heap(); Heap* current_heap = sim_->isolate_->heap();
if (obj.IsSmi() || if (!skip_obj_print) {
IsValidHeapObject(current_heap, HeapObject::cast(obj))) { if (obj.IsSmi() ||
PrintF(" ("); IsValidHeapObject(current_heap, HeapObject::cast(obj))) {
if (obj.IsSmi()) { PrintF(" (");
PrintF("smi %d", Smi::ToInt(obj)); if (obj.IsSmi()) {
} else { PrintF("smi %d", Smi::ToInt(obj));
obj.ShortPrint(); } else {
obj.ShortPrint();
}
PrintF(")");
} }
PrintF(")");
} }
PrintF("\n"); PrintF("\n");
cur++; cur++;
...@@ -702,6 +706,10 @@ void MipsDebugger::Debug() { ...@@ -702,6 +706,10 @@ void MipsDebugger::Debug() {
PrintF(" dump stack content, default dump 10 words)\n"); PrintF(" dump stack content, default dump 10 words)\n");
PrintF("mem <address> [<words>]\n"); PrintF("mem <address> [<words>]\n");
PrintF(" dump memory content, default dump 10 words)\n"); PrintF(" dump memory content, default dump 10 words)\n");
PrintF("dump [<words>]\n");
PrintF(
" dump memory content without pretty printing JS objects, default "
"dump 10 words)\n");
PrintF("flags\n"); PrintF("flags\n");
PrintF(" print flags\n"); PrintF(" print flags\n");
PrintF("disasm [<instructions>]\n"); PrintF("disasm [<instructions>]\n");
......
...@@ -420,7 +420,8 @@ void MipsDebugger::Debug() { ...@@ -420,7 +420,8 @@ void MipsDebugger::Debug() {
} else { } else {
PrintF("printobject <value>\n"); PrintF("printobject <value>\n");
} }
} else if (strcmp(cmd, "stack") == 0 || strcmp(cmd, "mem") == 0) { } else if (strcmp(cmd, "stack") == 0 || strcmp(cmd, "mem") == 0 ||
strcmp(cmd, "dump") == 0) {
int64_t* cur = nullptr; int64_t* cur = nullptr;
int64_t* end = nullptr; int64_t* end = nullptr;
int next_arg = 1; int next_arg = 1;
...@@ -447,20 +448,23 @@ void MipsDebugger::Debug() { ...@@ -447,20 +448,23 @@ void MipsDebugger::Debug() {
} }
end = cur + words; end = cur + words;
bool skip_obj_print = (strcmp(cmd, "dump") == 0);
while (cur < end) { while (cur < end) {
PrintF(" 0x%012" PRIxPTR " : 0x%016" PRIx64 " %14" PRId64 " ", PrintF(" 0x%012" PRIxPTR " : 0x%016" PRIx64 " %14" PRId64 " ",
reinterpret_cast<intptr_t>(cur), *cur, *cur); reinterpret_cast<intptr_t>(cur), *cur, *cur);
Object obj(*cur); Object obj(*cur);
Heap* current_heap = sim_->isolate_->heap(); Heap* current_heap = sim_->isolate_->heap();
if (obj.IsSmi() || if (!skip_obj_print) {
IsValidHeapObject(current_heap, HeapObject::cast(obj))) { if (obj.IsSmi() ||
PrintF(" ("); IsValidHeapObject(current_heap, HeapObject::cast(obj))) {
if (obj.IsSmi()) { PrintF(" (");
PrintF("smi %d", Smi::ToInt(obj)); if (obj.IsSmi()) {
} else { PrintF("smi %d", Smi::ToInt(obj));
obj.ShortPrint(); } else {
obj.ShortPrint();
}
PrintF(")");
} }
PrintF(")");
} }
PrintF("\n"); PrintF("\n");
cur++; cur++;
...@@ -644,6 +648,10 @@ void MipsDebugger::Debug() { ...@@ -644,6 +648,10 @@ void MipsDebugger::Debug() {
PrintF(" dump stack content, default dump 10 words)\n"); PrintF(" dump stack content, default dump 10 words)\n");
PrintF("mem <address> [<words>]\n"); PrintF("mem <address> [<words>]\n");
PrintF(" dump memory content, default dump 10 words)\n"); PrintF(" dump memory content, default dump 10 words)\n");
PrintF("dump [<words>]\n");
PrintF(
" dump memory content without pretty printing JS objects, default "
"dump 10 words)\n");
PrintF("flags\n"); PrintF("flags\n");
PrintF(" print flags\n"); PrintF(" print flags\n");
PrintF("disasm [<instructions>]\n"); PrintF("disasm [<instructions>]\n");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment