Bug 1299839: TraceLogger - Disable on throwing an exception in IonMonkey with Debugger enabled, r=bbouvier

This commit is contained in:
Hannes Verschore 2016-09-02 18:19:27 +02:00
parent 0bf1786e83
commit 67f478581c
3 changed files with 40 additions and 18 deletions

View File

@ -787,6 +787,15 @@ HandleException(ResumeFromException* rfe)
IonScript* ionScript = nullptr;
bool invalidated = iter.checkInvalidation(&ionScript);
#ifdef JS_TRACE_LOGGING
if (logger && cx->compartment()->isDebuggee() && logger->enabled()) {
logger->disable(/* force = */ true,
"Forcefully disabled tracelogger, due to "
"throwing an exception with an active Debugger "
"in IonMonkey.");
}
#endif
for (;;) {
HandleExceptionIon(cx, frames, rfe, &overrecursed);

View File

@ -176,15 +176,15 @@ TraceLoggerThread::~TraceLoggerThread()
bool
TraceLoggerThread::enable()
{
if (enabled > 0) {
enabled++;
if (enabled_ > 0) {
enabled_++;
return true;
}
if (failed)
return false;
enabled = 1;
enabled_ = 1;
logTimestamp(TraceLogger_Enable);
return true;
@ -195,7 +195,7 @@ TraceLoggerThread::fail(JSContext* cx, const char* error)
{
JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, JSMSG_TRACELOGGER_ENABLE_FAIL, error);
failed = true;
enabled = 0;
enabled_ = 0;
return false;
}
@ -206,7 +206,7 @@ TraceLoggerThread::enable(JSContext* cx)
if (!enable())
return fail(cx, "internal error");
if (enabled == 1) {
if (enabled_ == 1) {
// Get the top Activation to log the top script/pc (No inlined frames).
ActivationIterator iter(cx->runtime());
Activation* act = iter.activation();
@ -252,21 +252,24 @@ TraceLoggerThread::enable(JSContext* cx)
}
bool
TraceLoggerThread::disable()
TraceLoggerThread::disable(bool force, const char* error)
{
if (failed)
return false;
if (enabled == 0)
if (enabled_ == 0)
return true;
if (enabled > 1) {
enabled--;
if (enabled_ > 1 && !force) {
enabled_--;
return true;
}
if (force)
traceLoggerState->maybeSpewError(error);
logTimestamp(TraceLogger_Disable);
enabled = 0;
enabled_ = 0;
return true;
}
@ -492,7 +495,7 @@ TraceLoggerThread::startEvent(uint32_t id)
return;
#ifdef DEBUG
if (enabled > 0) {
if (enabled_ > 0) {
AutoEnterOOMUnsafeRegion oomUnsafe;
if (!graphStack.append(id))
oomUnsafe.crash("Could not add item to debug stack.");
@ -525,7 +528,7 @@ TraceLoggerThread::stopEvent(uint32_t id)
return;
#ifdef DEBUG
if (enabled > 0) {
if (enabled_ > 0) {
uint32_t prev = graphStack.popCopy();
if (id == TraceLogger_Engine) {
MOZ_ASSERT(prev == TraceLogger_IonMonkey || prev == TraceLogger_Baseline ||
@ -560,7 +563,7 @@ TraceLoggerThread::logTimestamp(uint32_t id)
void
TraceLoggerThread::log(uint32_t id)
{
if (enabled == 0)
if (enabled_ == 0)
return;
MOZ_ASSERT(traceLoggerState);
@ -784,6 +787,7 @@ TraceLoggerThreadState::init()
" EnableMainThread Start logging the main thread immediately.\n"
" EnableOffThread Start logging helper threads immediately.\n"
" EnableGraph Enable spewing the tracelogging graph to a file.\n"
" Errors Report errors during tracing to stderr.\n"
);
printf("\n");
exit(0);
@ -796,6 +800,8 @@ TraceLoggerThreadState::init()
offThreadEnabled = true;
if (strstr(options, "EnableGraph"))
graphSpewingEnabled = true;
if (strstr(options, "Errors"))
spewErrors = true;
}
startupTime = rdtsc();

View File

@ -167,7 +167,7 @@ class TraceLoggerThread
DefaultHasher<uint32_t>,
SystemAllocPolicy> TextIdHashMap;
uint32_t enabled;
uint32_t enabled_;
bool failed;
UniquePtr<TraceLoggerGraph> graph;
@ -192,7 +192,7 @@ class TraceLoggerThread
AutoTraceLog* top;
TraceLoggerThread()
: enabled(0),
: enabled_(0),
failed(false),
graph(),
nextTextId(TraceLogger_Last),
@ -208,7 +208,8 @@ class TraceLoggerThread
bool enable();
bool enable(JSContext* cx);
bool disable();
bool disable(bool force = false, const char* = "");
bool enabled() { return enabled_ > 0; }
private:
bool fail(JSContext* cx, const char* error);
@ -296,7 +297,7 @@ class TraceLoggerThread
public:
static unsigned offsetOfEnabled() {
return offsetof(TraceLoggerThread, enabled);
return offsetof(TraceLoggerThread, enabled_);
}
#endif
};
@ -318,6 +319,7 @@ class TraceLoggerThreadState
bool mainThreadEnabled;
bool offThreadEnabled;
bool graphSpewingEnabled;
bool spewErrors;
ThreadLoggerHashMap threadLoggers;
MainThreadLoggers mainThreadLoggers;
@ -332,7 +334,8 @@ class TraceLoggerThreadState
#endif
mainThreadEnabled(false),
offThreadEnabled(false),
graphSpewingEnabled(false)
graphSpewingEnabled(false),
spewErrors(false)
{ }
bool init();
@ -349,6 +352,10 @@ class TraceLoggerThreadState
}
void enableTextId(JSContext* cx, uint32_t textId);
void disableTextId(JSContext* cx, uint32_t textId);
void maybeSpewError(const char* text) {
if (spewErrors)
fprintf(stderr, "%s\n", text);
}
private:
TraceLoggerThread* forMainThread(PerThreadData* mainThread);