Commit faae9fe6 authored by Irina Yatsenko's avatar Irina Yatsenko Committed by Commit Bot

Small improvements in debugging experience on Windows

If running under debugger:
1. Output from _v8_internal_Print_Object into debugger's command window
2. Break into debugger before aborting

Change-Id: I49e4d83c817e6588c4679c9fb9766602927542db
Reviewed-on: https://chromium-review.googlesource.com/c/1435771
Commit-Queue: Irina Yatsenko <irinayat@microsoft.com>
Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#59137}
parent aff79f4e
...@@ -920,6 +920,11 @@ void OS::Sleep(TimeDelta interval) { ...@@ -920,6 +920,11 @@ void OS::Sleep(TimeDelta interval) {
void OS::Abort() { void OS::Abort() {
// Give a chance to debug the failure.
if (IsDebuggerPresent()) {
DebugBreak();
}
// Before aborting, make sure to flush output buffers. // Before aborting, make sure to flush output buffers.
fflush(stdout); fflush(stdout);
fflush(stderr); fflush(stderr);
......
...@@ -69,6 +69,11 @@ namespace internal { ...@@ -69,6 +69,11 @@ namespace internal {
#ifdef OBJECT_PRINT #ifdef OBJECT_PRINT
void Object::Print() const { void Object::Print() const {
// Output into debugger's command window if a debugger is attached.
DbgStdoutStream dbg_os;
this->Print(dbg_os);
dbg_os << std::flush;
StdoutStream os; StdoutStream os;
this->Print(os); this->Print(os);
os << std::flush; os << std::flush;
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "src/objects/string.h" #include "src/objects/string.h"
#if V8_OS_WIN #if V8_OS_WIN
#include <windows.h>
#if _MSC_VER < 1900 #if _MSC_VER < 1900
#define snprintf sprintf_s #define snprintf sprintf_s
#endif #endif
...@@ -20,6 +21,48 @@ ...@@ -20,6 +21,48 @@
namespace v8 { namespace v8 {
namespace internal { namespace internal {
DbgStreamBuf::DbgStreamBuf() { setp(data_, data_ + sizeof(data_)); }
DbgStreamBuf::~DbgStreamBuf() { sync(); }
int DbgStreamBuf::overflow(int c) {
#if V8_OS_WIN
if (!IsDebuggerPresent()) {
return 0;
}
sync();
if (c != EOF) {
if (pbase() == epptr()) {
auto as_char = static_cast<char>(c);
OutputDebugStringA(&as_char);
} else {
sputc(static_cast<char>(c));
}
}
#endif
return 0;
}
int DbgStreamBuf::sync() {
#if V8_OS_WIN
if (!IsDebuggerPresent()) {
return 0;
}
if (pbase() != pptr()) {
OutputDebugStringA(
std::string(pbase(),
static_cast<std::string::size_type>(pptr() - pbase())).c_str());
setp(pbase(), epptr());
}
#endif
return 0;
}
DbgStdoutStream::DbgStdoutStream() : std::ostream(&streambuf_) {}
OFStreamBase::OFStreamBase(FILE* f) : f_(f) {} OFStreamBase::OFStreamBase(FILE* f) : f_(f) {}
int OFStreamBase::sync() { int OFStreamBase::sync() {
......
...@@ -31,6 +31,28 @@ class V8_EXPORT_PRIVATE OFStreamBase : public std::streambuf { ...@@ -31,6 +31,28 @@ class V8_EXPORT_PRIVATE OFStreamBase : public std::streambuf {
std::streamsize xsputn(const char* s, std::streamsize n) override; std::streamsize xsputn(const char* s, std::streamsize n) override;
}; };
// Output buffer and stream writing into debugger's command window.
class V8_EXPORT_PRIVATE DbgStreamBuf : public std::streambuf {
public:
DbgStreamBuf();
~DbgStreamBuf();
private:
int sync() override;
int overflow(int c) override;
char data_[256];
};
class DbgStdoutStream : public std::ostream {
public:
DbgStdoutStream();
~DbgStdoutStream() = default;
private:
DbgStreamBuf streambuf_;
};
// An output stream writing to a file. // An output stream writing to a file.
class V8_EXPORT_PRIVATE OFStream : public std::ostream { class V8_EXPORT_PRIVATE OFStream : public std::ostream {
public: public:
......
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