From c18d4216a431d54813e79a7719e17a30c8a3ec24 Mon Sep 17 00:00:00 2001 From: caitp Date: Wed, 25 Jan 2017 07:45:57 -0800 Subject: [PATCH] [csa] add utilities for printf-style debugging Adds CSA::Print(const char* s), which generates a runtime call to Runtime::kGlobalPrint with a line-terminated ASCII string constant, and CSA::DebugPrint(const char* prefix, Node* tagged_value), which emits a runtime call to Runtime::kDebugPrint() with the tagged value, optionally prefixed by an ascii string constant. These simplify debugging TF builtins by providing a tool to easily observe the contents of values at arbitrary points in a program, without stepping endlessly through assembly in a debugger, and to easily observe the path taken through a TF builtin. These methods do not generate code in release builds. BUG=v8:5268 R=ishell@chromium.org, danno@chromium.org, bmeurer@chromium.org Review-Url: https://codereview.chromium.org/2651673003 Cr-Commit-Position: refs/heads/master@{#42660} --- src/code-stub-assembler.cc | 24 ++++++++++++++++++++++++ src/code-stub-assembler.h | 5 +++++ 2 files changed, 29 insertions(+) diff --git a/src/code-stub-assembler.cc b/src/code-stub-assembler.cc index 9754038d85..d5e6bbdbcb 100644 --- a/src/code-stub-assembler.cc +++ b/src/code-stub-assembler.cc @@ -8365,5 +8365,29 @@ Node* CodeStubAssembler::AllocatePromiseReactionJobInfo( return result; } +void CodeStubAssembler::Print(const char* s) { +#ifdef DEBUG + std::string formatted(s); + formatted += "\n"; + Handle string = isolate()->factory()->NewStringFromAsciiChecked( + formatted.c_str(), TENURED); + CallRuntime(Runtime::kGlobalPrint, NoContextConstant(), HeapConstant(string)); +#endif +} + +void CodeStubAssembler::Print(const char* prefix, Node* tagged_value) { +#ifdef DEBUG + if (prefix != nullptr) { + std::string formatted(prefix); + formatted += ": "; + Handle string = isolate()->factory()->NewStringFromAsciiChecked( + formatted.c_str(), TENURED); + CallRuntime(Runtime::kGlobalPrint, NoContextConstant(), + HeapConstant(string)); + } + CallRuntime(Runtime::kGlobalPrint, NoContextConstant(), tagged_value); +#endif +} + } // namespace internal } // namespace v8 diff --git a/src/code-stub-assembler.h b/src/code-stub-assembler.h index 0628b93e88..e98c22759a 100644 --- a/src/code-stub-assembler.h +++ b/src/code-stub-assembler.h @@ -1167,6 +1167,11 @@ class V8_EXPORT_PRIVATE CodeStubAssembler : public compiler::CodeAssembler { Node* deferred_on_resolve, Node* deferred_on_reject, Node* context); + // Support for printf-style debugging + void Print(const char* s); + void Print(const char* prefix, Node* tagged_value); + inline void Print(Node* tagged_value) { return Print(nullptr, tagged_value); } + protected: void DescriptorLookupLinear(Node* unique_name, Node* descriptors, Node* nof, Label* if_found, Variable* var_name_index,