Commit c18d4216 authored by caitp's avatar caitp Committed by Commit bot

[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}
parent 7c30fcf2
......@@ -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
......@@ -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,
......
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