[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}
This commit is contained in:
caitp 2017-01-25 07:45:57 -08:00 committed by Commit bot
parent 7c30fcf22d
commit c18d4216a4
2 changed files with 29 additions and 0 deletions

View File

@ -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> 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> 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

View File

@ -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,