Commit 61ad57eb authored by Leszek Swirski's avatar Leszek Swirski Committed by Commit Bot

[debug] Improve gdb code printing

Two usability improvements to the GDB jco macro:

 * Check if the desired pc is within the code space (or large object
   space), to avoid failures
 * Highlight the current pc in the outputted code (yellow and bold) to
   make it easier to find.

Change-Id: Ia094f33b61ed0fd2dd1e5e456992a17d97048639
Reviewed-on: https://chromium-review.googlesource.com/860102
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Reviewed-by: 's avatarRoss McIlroy <rmcilroy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#50514}
parent c6ea0328
......@@ -165,7 +165,8 @@ static void PrintRelocInfo(StringBuilder* out, Isolate* isolate,
}
static int DecodeIt(Isolate* isolate, std::ostream* os,
const V8NameConverter& converter, byte* begin, byte* end) {
const V8NameConverter& converter, byte* begin, byte* end,
void* current_pc) {
SealHandleScope shs(isolate);
DisallowHeapAllocation no_alloc;
ExternalReferenceEncoder ref_encoder(isolate);
......@@ -242,6 +243,10 @@ static int DecodeIt(Isolate* isolate, std::ostream* os,
}
// Instruction address and instruction offset.
if (FLAG_log_colour && prev_pc == current_pc) {
// If this is the given "current" pc, make it yellow and bold.
out.AddFormatted("\033[33;1m");
}
out.AddFormatted("%p %4" V8PRIxPTRDIFF " ", static_cast<void*>(prev_pc),
prev_pc - begin);
......@@ -279,6 +284,10 @@ static int DecodeIt(Isolate* isolate, std::ostream* os,
}
}
if (FLAG_log_colour && prev_pc == current_pc) {
out.AddFormatted("\033[m");
}
DumpBuffer(os, &out);
}
......@@ -297,17 +306,16 @@ static int DecodeIt(Isolate* isolate, std::ostream* os,
return static_cast<int>(pc - begin);
}
int Disassembler::Decode(Isolate* isolate, std::ostream* os, byte* begin,
byte* end, Code* code) {
byte* end, Code* code, void* current_pc) {
V8NameConverter v8NameConverter(code);
return DecodeIt(isolate, os, v8NameConverter, begin, end);
return DecodeIt(isolate, os, v8NameConverter, begin, end, current_pc);
}
#else // ENABLE_DISASSEMBLER
int Disassembler::Decode(Isolate* isolate, std::ostream* os, byte* begin,
byte* end, Code* code) {
byte* end, Code* code, void* current_pc) {
return 0;
}
......
......@@ -17,7 +17,7 @@ class Disassembler : public AllStatic {
// instruction could be decoded.
// the code object is used for name resolution and may be null.
static int Decode(Isolate* isolate, std::ostream* os, byte* begin, byte* end,
Code* code = nullptr);
Code* code = nullptr, void* current_pc = nullptr);
};
} // namespace internal
......
......@@ -1946,15 +1946,36 @@ extern void _v8_internal_Print_Object(void* object) {
}
extern void _v8_internal_Print_Code(void* object) {
i::Address address = reinterpret_cast<i::Address>(object);
i::Isolate* isolate = i::Isolate::Current();
i::wasm::WasmCode* wasm_code =
isolate->wasm_engine()->code_manager()->LookupCode(
reinterpret_cast<i::Address>(object));
isolate->wasm_engine()->code_manager()->LookupCode(address);
if (wasm_code) {
wasm_code->Print(isolate);
return;
}
isolate->FindCodeObject(reinterpret_cast<i::Address>(object))->Print();
if (!isolate->heap()->InSpaceSlow(address, i::CODE_SPACE) &&
!isolate->heap()->InSpaceSlow(address, i::LO_SPACE)) {
i::PrintF(
"%p is not within the current isolate's large object or code spaces\n",
static_cast<void*>(address));
return;
}
i::Code* code = isolate->FindCodeObject(address);
if (!code->IsCode()) {
i::PrintF("No code object found containing %p\n",
static_cast<void*>(address));
return;
}
#ifdef ENABLE_DISASSEMBLER
i::OFStream os(stdout);
code->Disassemble(nullptr, os, address);
#else // ENABLE_DISASSEMBLER
code->Print();
#endif // ENABLE_DISASSEMBLER
}
extern void _v8_internal_Print_FeedbackMetadata(void* object) {
......
......@@ -14536,7 +14536,7 @@ void HandlerTable::HandlerTableReturnPrint(std::ostream& os) {
}
}
void Code::Disassemble(const char* name, std::ostream& os) {
void Code::Disassemble(const char* name, std::ostream& os, void* current_pc) {
os << "kind = " << Kind2String(kind()) << "\n";
if (is_stub()) {
const char* n = CodeStub::MajorName(CodeStub::GetMajorKey(this));
......@@ -14579,7 +14579,7 @@ void Code::Disassemble(const char* name, std::ostream& os) {
os << "Instructions (size = " << code_size << ")\n";
byte* begin = instruction_start();
byte* end = begin + code_size;
Disassembler::Decode(isolate, &os, begin, end, this);
Disassembler::Decode(isolate, &os, begin, end, this, current_pc);
if (constant_pool_offset < size) {
int constant_pool_size = safepoint_offset - constant_pool_offset;
......
......@@ -139,7 +139,8 @@ class Code : public HeapObject {
#endif // defined(OBJECT_PRINT) || defined(ENABLE_DISASSEMBLER)
#ifdef ENABLE_DISASSEMBLER
void Disassemble(const char* name, std::ostream& os); // NOLINT
void Disassemble(const char* name, std::ostream& os,
void* current_pc = nullptr); // NOLINT
#endif
// [instruction_size]: Size of the native instructions
......
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