Commit 4a02c06b authored by Darshan Sen's avatar Darshan Sen Committed by V8 LUCI CQ

[message] Print to a std::ostream from PrintCurrentStackTrace()

Signed-off-by: 's avatarDarshan Sen <raisinten@gmail.com>
Change-Id: I51650e87261c817d6a58a34d56920b6fb8c1e281
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3112985Reviewed-by: 's avatarCamillo Bruni <cbruni@chromium.org>
Reviewed-by: 's avatarClemens Backes <clemensb@chromium.org>
Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/main@{#76788}
parent e8708fe3
......@@ -7,6 +7,8 @@
#include <stdio.h>
#include <ostream>
#include "v8-local-handle.h" // NOLINT(build/include_directory)
#include "v8-maybe.h" // NOLINT(build/include_directory)
#include "v8config.h" // NOLINT(build/include_directory)
......@@ -206,8 +208,9 @@ class V8_EXPORT Message {
bool IsSharedCrossOrigin() const;
bool IsOpaque() const;
// TODO(1245381): Print to a string instead of on a FILE.
V8_DEPRECATE_SOON("Use the version that takes a std::ostream&.")
static void PrintCurrentStackTrace(Isolate* isolate, FILE* out);
static void PrintCurrentStackTrace(Isolate* isolate, std::ostream& out);
static const int kNoLineNumberInfo = 0;
static const int kNoColumnInfo = 0;
......
......@@ -7,6 +7,7 @@
#include <algorithm> // For min
#include <cmath> // For isnan.
#include <limits>
#include <sstream>
#include <string>
#include <utility> // For move
#include <vector>
......@@ -3094,6 +3095,14 @@ MaybeLocal<String> Message::GetSourceLine(Local<Context> context) const {
}
void Message::PrintCurrentStackTrace(Isolate* isolate, FILE* out) {
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
std::ostringstream stack_trace_stream;
i_isolate->PrintCurrentStackTrace(stack_trace_stream);
i::PrintF(out, "%s", stack_trace_stream.str().c_str());
}
void Message::PrintCurrentStackTrace(Isolate* isolate, std::ostream& out) {
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
i_isolate->PrintCurrentStackTrace(out);
......
......@@ -1564,7 +1564,9 @@ Handle<JSMessageObject> Isolate::CreateMessageOrAbort(
// print a user-friendly stack trace (not an internal one).
PrintF(stderr, "%s\n\nFROM\n",
MessageHandler::GetLocalizedMessage(this, message_obj).get());
PrintCurrentStackTrace(stderr);
std::ostringstream stack_trace_stream;
PrintCurrentStackTrace(stack_trace_stream);
PrintF(stderr, "%s", stack_trace_stream.str().c_str());
base::OS::Abort();
}
}
......@@ -2125,7 +2127,7 @@ Object Isolate::PromoteScheduledException() {
return ReThrow(thrown);
}
void Isolate::PrintCurrentStackTrace(FILE* out) {
void Isolate::PrintCurrentStackTrace(std::ostream& out) {
CaptureStackTraceOptions options;
options.limit = 0;
options.skip_mode = SKIP_NONE;
......
......@@ -853,7 +853,7 @@ class V8_EXPORT_PRIVATE Isolate final : private HiddenFactory {
v8::Isolate::AbortOnUncaughtExceptionCallback callback);
enum PrintStackMode { kPrintStackConcise, kPrintStackVerbose };
void PrintCurrentStackTrace(FILE* out);
void PrintCurrentStackTrace(std::ostream& out);
void PrintStack(StringStream* accumulator,
PrintStackMode mode = kPrintStackVerbose);
void PrintStack(FILE* out, PrintStackMode mode = kPrintStackVerbose);
......
......@@ -1453,6 +1453,13 @@ void String::PrintOn(FILE* file) {
}
}
void String::PrintOn(std::ostream& ostream) {
int length = this->length();
for (int i = 0; i < length; i++) {
ostream.put(Get(i));
}
}
Handle<String> SeqString::Truncate(Handle<SeqString> string, int new_length) {
if (new_length == 0) return string->GetReadOnlyRoots().empty_string_handle();
......
......@@ -403,6 +403,7 @@ class String : public TorqueGeneratedString<String, Name> {
enum TrimMode { kTrim, kTrimStart, kTrimEnd };
V8_EXPORT_PRIVATE void PrintOn(FILE* out);
V8_EXPORT_PRIVATE void PrintOn(std::ostream& out);
// For use during stack traces. Performs rudimentary sanity check.
bool LooksValid();
......
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