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: Clemens Hammacher <clemensh@chromium.org> Reviewed-by: Michael Lippautz <mlippautz@chromium.org> Cr-Commit-Position: refs/heads/master@{#59137}
This commit is contained in:
parent
aff79f4eb1
commit
faae9fe694
@ -920,6 +920,11 @@ void OS::Sleep(TimeDelta interval) {
|
||||
|
||||
|
||||
void OS::Abort() {
|
||||
// Give a chance to debug the failure.
|
||||
if (IsDebuggerPresent()) {
|
||||
DebugBreak();
|
||||
}
|
||||
|
||||
// Before aborting, make sure to flush output buffers.
|
||||
fflush(stdout);
|
||||
fflush(stderr);
|
||||
|
@ -69,6 +69,11 @@ namespace internal {
|
||||
#ifdef OBJECT_PRINT
|
||||
|
||||
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;
|
||||
this->Print(os);
|
||||
os << std::flush;
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include "src/objects/string.h"
|
||||
|
||||
#if V8_OS_WIN
|
||||
#include <windows.h>
|
||||
#if _MSC_VER < 1900
|
||||
#define snprintf sprintf_s
|
||||
#endif
|
||||
@ -20,6 +21,48 @@
|
||||
namespace v8 {
|
||||
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) {}
|
||||
|
||||
int OFStreamBase::sync() {
|
||||
|
@ -31,6 +31,28 @@ class V8_EXPORT_PRIVATE OFStreamBase : public std::streambuf {
|
||||
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.
|
||||
class V8_EXPORT_PRIVATE OFStream : public std::ostream {
|
||||
public:
|
||||
|
Loading…
Reference in New Issue
Block a user