Commit ba020627 authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm] Enable highlighting of current instruction in "jco"

For on-heap code, there is the nice feature of highlighting the current
pc on the "jco" gdb macro (calling {Code->Print}, {Code->Disassemble}
or {WasmCode::Disassemble}). For wasm code, this feature was missing so
far. This CL adds it.

R=ahaas@chromium.org

Change-Id: I0ee86d3c5cf9f42581f03c2ba4ec16b4c992e016
Reviewed-on: https://chromium-review.googlesource.com/1021517Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#52721}
parent f7f7cd2e
...@@ -187,7 +187,7 @@ static void PrintRelocInfo(StringBuilder* out, Isolate* isolate, ...@@ -187,7 +187,7 @@ static void PrintRelocInfo(StringBuilder* out, Isolate* isolate,
static int DecodeIt(Isolate* isolate, std::ostream* os, 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) { Address current_pc) {
SealHandleScope shs(isolate); SealHandleScope shs(isolate);
DisallowHeapAllocation no_alloc; DisallowHeapAllocation no_alloc;
ExternalReferenceEncoder ref_encoder(isolate); ExternalReferenceEncoder ref_encoder(isolate);
...@@ -265,7 +265,7 @@ static int DecodeIt(Isolate* isolate, std::ostream* os, ...@@ -265,7 +265,7 @@ static int DecodeIt(Isolate* isolate, std::ostream* os,
} }
// Instruction address and instruction offset. // Instruction address and instruction offset.
if (FLAG_log_colour && prev_pc == current_pc) { if (FLAG_log_colour && reinterpret_cast<Address>(prev_pc) == current_pc) {
// If this is the given "current" pc, make it yellow and bold. // If this is the given "current" pc, make it yellow and bold.
out.AddFormatted("\033[33;1m"); out.AddFormatted("\033[33;1m");
} }
...@@ -310,7 +310,7 @@ static int DecodeIt(Isolate* isolate, std::ostream* os, ...@@ -310,7 +310,7 @@ static int DecodeIt(Isolate* isolate, std::ostream* os,
} }
} }
if (FLAG_log_colour && prev_pc == current_pc) { if (FLAG_log_colour && reinterpret_cast<Address>(prev_pc) == current_pc) {
out.AddFormatted("\033[m"); out.AddFormatted("\033[m");
} }
...@@ -333,14 +333,14 @@ static int DecodeIt(Isolate* isolate, std::ostream* os, ...@@ -333,14 +333,14 @@ static int DecodeIt(Isolate* isolate, std::ostream* os,
} }
int Disassembler::Decode(Isolate* isolate, std::ostream* os, byte* begin, int Disassembler::Decode(Isolate* isolate, std::ostream* os, byte* begin,
byte* end, Code* code, void* current_pc) { byte* end, Code* code, Address current_pc) {
V8NameConverter v8NameConverter(code); V8NameConverter v8NameConverter(code);
return DecodeIt(isolate, os, v8NameConverter, begin, end, current_pc); return DecodeIt(isolate, os, v8NameConverter, begin, end, current_pc);
} }
int Disassembler::Decode(Isolate* isolate, std::ostream* os, byte* begin, int Disassembler::Decode(Isolate* isolate, std::ostream* os, byte* begin,
byte* end, const wasm::WasmCode* code, byte* end, const wasm::WasmCode* code,
void* current_pc) { Address current_pc) {
V8NameConverter v8NameConverter(isolate, code); V8NameConverter v8NameConverter(isolate, code);
return DecodeIt(isolate, os, v8NameConverter, begin, end, current_pc); return DecodeIt(isolate, os, v8NameConverter, begin, end, current_pc);
} }
...@@ -348,7 +348,7 @@ int Disassembler::Decode(Isolate* isolate, std::ostream* os, byte* begin, ...@@ -348,7 +348,7 @@ int Disassembler::Decode(Isolate* isolate, std::ostream* os, byte* begin,
#else // ENABLE_DISASSEMBLER #else // ENABLE_DISASSEMBLER
int Disassembler::Decode(Isolate* isolate, std::ostream* os, byte* begin, int Disassembler::Decode(Isolate* isolate, std::ostream* os, byte* begin,
byte* end, Code* code, void* current_pc) { byte* end, Code* code, Address current_pc) {
return 0; return 0;
} }
......
...@@ -21,9 +21,10 @@ class Disassembler : public AllStatic { ...@@ -21,9 +21,10 @@ class Disassembler : public AllStatic {
// instruction could be decoded. // instruction could be decoded.
// the code object is used for name resolution and may be null. // the code object is used for name resolution and may be null.
static int Decode(Isolate* isolate, std::ostream* os, byte* begin, byte* end, static int Decode(Isolate* isolate, std::ostream* os, byte* begin, byte* end,
Code* code = nullptr, void* current_pc = nullptr); Code* code = nullptr, Address current_pc = kNullAddress);
static int Decode(Isolate* isolate, std::ostream* os, byte* begin, byte* end, static int Decode(Isolate* isolate, std::ostream* os, byte* begin, byte* end,
const wasm::WasmCode* code, void* current_pc = nullptr); const wasm::WasmCode* code,
Address current_pc = kNullAddress);
}; };
} // namespace internal } // namespace internal
......
...@@ -2165,7 +2165,8 @@ extern void _v8_internal_Print_Code(void* object) { ...@@ -2165,7 +2165,8 @@ extern void _v8_internal_Print_Code(void* object) {
i::wasm::WasmCode* wasm_code = i::wasm::WasmCode* wasm_code =
isolate->wasm_engine()->code_manager()->LookupCode(address); isolate->wasm_engine()->code_manager()->LookupCode(address);
if (wasm_code) { if (wasm_code) {
wasm_code->Print(isolate); i::OFStream os(stdout);
wasm_code->Disassemble(nullptr, isolate, os, address);
return; return;
} }
...@@ -2173,19 +2174,18 @@ extern void _v8_internal_Print_Code(void* object) { ...@@ -2173,19 +2174,18 @@ extern void _v8_internal_Print_Code(void* object) {
!isolate->heap()->InSpaceSlow(address, i::LO_SPACE)) { !isolate->heap()->InSpaceSlow(address, i::LO_SPACE)) {
i::PrintF( i::PrintF(
"%p is not within the current isolate's large object or code spaces\n", "%p is not within the current isolate's large object or code spaces\n",
reinterpret_cast<void*>(address)); object);
return; return;
} }
i::Code* code = isolate->FindCodeObject(address); i::Code* code = isolate->FindCodeObject(address);
if (!code->IsCode()) { if (!code->IsCode()) {
i::PrintF("No code object found containing %p\n", i::PrintF("No code object found containing %p\n", object);
reinterpret_cast<void*>(address));
return; return;
} }
#ifdef ENABLE_DISASSEMBLER #ifdef ENABLE_DISASSEMBLER
i::OFStream os(stdout); i::OFStream os(stdout);
code->Disassemble(nullptr, os, reinterpret_cast<void*>(address)); code->Disassemble(nullptr, os, address);
#else // ENABLE_DISASSEMBLER #else // ENABLE_DISASSEMBLER
code->Print(); code->Print();
#endif // ENABLE_DISASSEMBLER #endif // ENABLE_DISASSEMBLER
......
...@@ -14586,8 +14586,7 @@ void DeoptimizationData::DeoptimizationDataPrint(std::ostream& os) { // NOLINT ...@@ -14586,8 +14586,7 @@ void DeoptimizationData::DeoptimizationDataPrint(std::ostream& os) { // NOLINT
} }
} }
void Code::Disassemble(const char* name, std::ostream& os, Address current_pc) {
void Code::Disassemble(const char* name, std::ostream& os, void* current_pc) {
os << "kind = " << Kind2String(kind()) << "\n"; os << "kind = " << Kind2String(kind()) << "\n";
if (is_stub()) { if (is_stub()) {
const char* n = CodeStub::MajorName(CodeStub::GetMajorKey(this)); const char* n = CodeStub::MajorName(CodeStub::GetMajorKey(this));
......
...@@ -49,7 +49,7 @@ class Code : public HeapObject { ...@@ -49,7 +49,7 @@ class Code : public HeapObject {
#ifdef ENABLE_DISASSEMBLER #ifdef ENABLE_DISASSEMBLER
void Disassemble(const char* name, std::ostream& os, void Disassemble(const char* name, std::ostream& os,
void* current_pc = nullptr); // NOLINT Address current_pc = kNullAddress);
#endif #endif
// [instruction_size]: Size of the native instructions, including embedded // [instruction_size]: Size of the native instructions, including embedded
......
...@@ -232,8 +232,8 @@ void WasmCode::Print(Isolate* isolate) const { ...@@ -232,8 +232,8 @@ void WasmCode::Print(Isolate* isolate) const {
Disassemble(nullptr, isolate, os); Disassemble(nullptr, isolate, os);
} }
void WasmCode::Disassemble(const char* name, Isolate* isolate, void WasmCode::Disassemble(const char* name, Isolate* isolate, std::ostream& os,
std::ostream& os) const { Address current_pc) const {
if (name) os << "name: " << name << "\n"; if (name) os << "name: " << name << "\n";
if (index_.IsJust()) os << "index: " << index_.FromJust() << "\n"; if (index_.IsJust()) os << "index: " << index_.FromJust() << "\n";
os << "kind: " << GetWasmCodeKindAsString(kind_) << "\n"; os << "kind: " << GetWasmCodeKindAsString(kind_) << "\n";
...@@ -255,7 +255,8 @@ void WasmCode::Disassemble(const char* name, Isolate* isolate, ...@@ -255,7 +255,8 @@ void WasmCode::Disassemble(const char* name, Isolate* isolate,
// TODO(mtrofin): rework the dependency on isolate and code in // TODO(mtrofin): rework the dependency on isolate and code in
// Disassembler::Decode. // Disassembler::Decode.
Disassembler::Decode(isolate, &os, instructions().start(), Disassembler::Decode(isolate, &os, instructions().start(),
instructions().start() + instruction_size, this); instructions().start() + instruction_size, this,
current_pc);
os << "\n"; os << "\n";
if (!source_positions().is_empty()) { if (!source_positions().is_empty()) {
......
...@@ -128,7 +128,8 @@ class V8_EXPORT_PRIVATE WasmCode final { ...@@ -128,7 +128,8 @@ class V8_EXPORT_PRIVATE WasmCode final {
} }
void Print(Isolate* isolate) const; void Print(Isolate* isolate) const;
void Disassemble(const char* name, Isolate* isolate, std::ostream& os) const; void Disassemble(const char* name, Isolate* isolate, std::ostream& os,
Address current_pc = kNullAddress) const;
static bool ShouldBeLogged(Isolate* isolate); static bool ShouldBeLogged(Isolate* isolate);
void LogCode(Isolate* isolate) const; void LogCode(Isolate* isolate) const;
......
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