Skip to content

Commit 1b469e2

Browse files
committed
[MERGE #5202 @mrkmarron] TTD: explicit support for enable/disable auto-trace
Merge pull request #5202 from mrkmarron:rrfix Fix for auto-trace behavior.
2 parents fe4d653 + d1fdc0f commit 1b469e2

File tree

8 files changed

+100
-6
lines changed

8 files changed

+100
-6
lines changed

bin/ChakraCore/ChakraCore.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ JsTTDMoveToTopLevelEvent
4646
JsTTDReplayExecution
4747

4848
JsTTDDiagWriteLog
49+
JsTTDDiagSetAutoTraceStatus
4950

5051
JsInitializeModuleRecord
5152
JsParseModuleSource

lib/Jsrt/ChakraDebug.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,6 +1014,17 @@ typedef unsigned __int32 uint32_t;
10141014
_Inout_ JsTTDMoveMode* moveMode,
10151015
_Out_ int64_t* rootEventTime);
10161016

1017+
/// <summary>
1018+
/// TTD API -- may change in future versions:
1019+
/// Enable or disable autotrace ability from JsRT.
1020+
/// </summary>
1021+
/// <param name="status">True to enable autotracing false to disable it.</param>
1022+
/// <returns>The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.</returns>
1023+
CHAKRA_API
1024+
JsTTDDiagSetAutoTraceStatus(
1025+
_In_ bool status
1026+
);
1027+
10171028
/// <summary>
10181029
/// TTD API -- may change in future versions:
10191030
/// A way for the debugger to programatically write a trace when it is at a breakpoint.

lib/Jsrt/Jsrt.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4625,6 +4625,27 @@ CHAKRA_API JsTTDReplayExecution(_Inout_ JsTTDMoveMode* moveMode, _Out_ int64_t*
46254625
#endif
46264626
}
46274627

4628+
CHAKRA_API JsTTDDiagSetAutoTraceStatus(_In_ bool status)
4629+
{
4630+
#if !ENABLE_TTD
4631+
return JsErrorCategoryUsage;
4632+
#else
4633+
JsrtContext *currentContext = JsrtContext::GetCurrent();
4634+
JsErrorCode cCheck = CheckContext(currentContext, JSRT_MAYBE_TRUE);
4635+
TTDAssert(cCheck == JsNoError, "Must have valid context when setting auto trace status.");
4636+
4637+
Js::ScriptContext* scriptContext = currentContext->GetScriptContext();
4638+
ThreadContext* threadContext = scriptContext->GetThreadContext();
4639+
4640+
if (threadContext->IsRuntimeInTTDMode())
4641+
{
4642+
threadContext->TTDLog->SetAutoTraceEnabled(status);
4643+
}
4644+
4645+
return JsNoError;
4646+
#endif
4647+
}
4648+
46284649
#ifdef _CHAKRACOREBUILD
46294650

46304651
template <class SrcChar, class DstChar>

lib/Runtime/Debug/TTEventLog.cpp

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,7 @@ namespace TTD
508508
TTD_CREATE_EVENTLIST_VTABLE_ENTRY(ExternalCallTag, None, ExternalCallEventLogEntry, nullptr, NSLogEvents::ExternalCallEventLogEntry_UnloadEventMemory, NSLogEvents::ExternalCallEventLogEntry_Emit, NSLogEvents::ExternalCallEventLogEntry_Parse);
509509
TTD_CREATE_EVENTLIST_VTABLE_ENTRY(ExplicitLogWriteTag, None, ExplicitLogWriteEventLogEntry, nullptr, nullptr, NSLogEvents::ExplicitLogWriteEntry_Emit, NSLogEvents::ExplicitLogWriteEntry_Parse);
510510
TTD_CREATE_EVENTLIST_VTABLE_ENTRY(TTDInnerLoopLogWriteTag, None, TTDInnerLoopLogWriteEventLogEntry, nullptr, nullptr, NSLogEvents::TTDInnerLoopLogWriteEventLogEntry_Emit, NSLogEvents::TTDInnerLoopLogWriteEventLogEntry_Parse);
511+
TTD_CREATE_EVENTLIST_VTABLE_ENTRY(TTDFetchAutoTraceStatusTag, None, TTDFetchAutoTraceStatusEventLogEntry, nullptr, nullptr, NSLogEvents::TTDFetchAutoTraceStatusEventLogEntry_Emit, NSLogEvents::TTDFetchAutoTraceStatusEventLogEntry_Parse);
511512

512513
TTD_CREATE_EVENTLIST_VTABLE_ENTRY(CreateScriptContextActionTag, GlobalAPIWrapper, JsRTCreateScriptContextAction, NSLogEvents::CreateScriptContext_Execute, NSLogEvents::CreateScriptContext_UnloadEventMemory, NSLogEvents::CreateScriptContext_Emit, NSLogEvents::CreateScriptContext_Parse);
513514
TTD_CREATE_EVENTLIST_VTABLE_ENTRY_COMMON(SetActiveScriptContextActionTag, GlobalAPIWrapper, JsRTSingleVarArgumentAction, SetActiveScriptContext_Execute);
@@ -586,7 +587,7 @@ namespace TTD
586587
: m_threadContext(threadContext), m_eventSlabAllocator(TTD_SLAB_BLOCK_ALLOCATION_SIZE_MID), m_miscSlabAllocator(TTD_SLAB_BLOCK_ALLOCATION_SIZE_SMALL),
587588
m_eventTimeCtr(0), m_timer(), m_topLevelCallbackEventTime(-1),
588589
m_eventListVTable(nullptr), m_eventList(&this->m_eventSlabAllocator), m_currentReplayEventIterator(),
589-
m_modeStack(), m_currentMode(TTDMode::Invalid),
590+
m_modeStack(), m_currentMode(TTDMode::Invalid), m_autoTracesEnabled(true),
590591
m_snapExtractor(), m_elapsedExecutionTimeSinceSnapshot(0.0),
591592
m_lastInflateSnapshotTime(-1), m_lastInflateMap(nullptr), m_propertyRecordList(&this->m_miscSlabAllocator),
592593
m_sourceInfoCount(0), m_loadedTopLevelScripts(&this->m_miscSlabAllocator), m_newFunctionTopLevelScripts(&this->m_miscSlabAllocator), m_evalTopLevelScripts(&this->m_miscSlabAllocator)
@@ -879,6 +880,18 @@ namespace TTD
879880
}
880881
}
881882

883+
void EventLog::RecordTTDFetchAutoTraceStatusEvent(bool status)
884+
{
885+
NSLogEvents::TTDFetchAutoTraceStatusEventLogEntry* atfEvent = this->RecordGetInitializedEvent_DataOnly<NSLogEvents::TTDFetchAutoTraceStatusEventLogEntry, NSLogEvents::EventKind::TTDFetchAutoTraceStatusTag>();
886+
atfEvent->IsEnabled = status;
887+
}
888+
889+
bool EventLog::ReplayTTDFetchAutoTraceStatusLogEvent()
890+
{
891+
const NSLogEvents::TTDFetchAutoTraceStatusEventLogEntry* atfEvent = this->ReplayGetReplayEvent_Helper<NSLogEvents::TTDFetchAutoTraceStatusEventLogEntry, NSLogEvents::EventKind::TTDFetchAutoTraceStatusTag>();
892+
return atfEvent->IsEnabled;
893+
}
894+
882895
void EventLog::RecordDateTimeEvent(double time)
883896
{
884897
NSLogEvents::DoubleEventLogEntry* dEvent = this->RecordGetInitializedEvent_DataOnly<NSLogEvents::DoubleEventLogEntry, NSLogEvents::EventKind::DoubleTag>();
@@ -2558,9 +2571,14 @@ namespace TTD
25582571
return isInnerLoop & isEnabled;
25592572
}
25602573

2561-
bool EventLog::SuppressDiagnosticTracesDuringInnerLoop() const
2574+
void EventLog::SetAutoTraceEnabled(bool enabled)
2575+
{
2576+
this->m_autoTracesEnabled = enabled;
2577+
}
2578+
2579+
bool EventLog::GetAutoTraceEnabled() const
25622580
{
2563-
return (this->m_currentMode & (TTDMode::DebuggerAttachedMode)) == TTDMode::DebuggerAttachedMode;
2581+
return this->m_autoTracesEnabled;
25642582
}
25652583

25662584
void EventLog::EmitLog(const char* emitUri, size_t emitUriLength, NSLogEvents::EventLogEntry* optInnerLoopEvent)

lib/Runtime/Debug/TTEventLog.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ namespace TTD
226226
//The current mode the system is running in (and a stack of mode push/pops that we use to generate it)
227227
TTModeStack m_modeStack;
228228
TTDMode m_currentMode;
229+
bool m_autoTracesEnabled;
229230

230231
//The snapshot extractor that this log uses
231232
SnapshotExtractor m_snapExtractor;
@@ -393,6 +394,12 @@ namespace TTD
393394
//Replay a event that writes the log to a given uri
394395
void ReplayEmitLogEvent();
395396

397+
//Record that we are accessing the TTDFetchAutoTraceStatus and what the value is
398+
void RecordTTDFetchAutoTraceStatusEvent(bool status);
399+
400+
//Replay that we are accessing the TTDFetchAutoTraceStatus
401+
bool ReplayTTDFetchAutoTraceStatusLogEvent();
402+
396403
//Log a time that is fetched during date operations
397404
void RecordDateTimeEvent(double time);
398405

@@ -605,7 +612,8 @@ namespace TTD
605612
void InnerLoopEmitLog(const TTDebuggerSourceLocation& writeLocation, const char* emitUri, size_t emitUriLength);
606613

607614
bool CanWriteInnerLoopTrace() const;
608-
bool SuppressDiagnosticTracesDuringInnerLoop() const;
615+
void SetAutoTraceEnabled(bool enabled);
616+
bool GetAutoTraceEnabled() const;
609617

610618
void EmitLog(const char* emitUri, size_t emitUriLength, NSLogEvents::EventLogEntry* optInnerLoopEvent = nullptr);
611619
void ParseLogInto(TTDataIOInfo& iofp, const char* parseUri, size_t parseUriLength);

lib/Runtime/Debug/TTEvents.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,20 @@ namespace TTD
597597
ilevt->Line = reader->ReadUInt32(NSTokens::Key::line, true);
598598
ilevt->Column = reader->ReadUInt32(NSTokens::Key::column, true);
599599
}
600+
601+
void TTDFetchAutoTraceStatusEventLogEntry_Emit(const EventLogEntry* evt, FileWriter* writer, ThreadContext* threadContext)
602+
{
603+
const TTDFetchAutoTraceStatusEventLogEntry* atfevt = GetInlineEventDataAs<TTDFetchAutoTraceStatusEventLogEntry, EventKind::TTDFetchAutoTraceStatusTag>(evt);
604+
605+
writer->WriteLogTag(NSTokens::Key::boolVal, atfevt->IsEnabled, NSTokens::Separator::CommaSeparator);
606+
}
607+
608+
void TTDFetchAutoTraceStatusEventLogEntry_Parse(EventLogEntry* evt, ThreadContext* threadContext, FileReader* reader, UnlinkableSlabAllocator& alloc)
609+
{
610+
TTDFetchAutoTraceStatusEventLogEntry* atfevt = GetInlineEventDataAs<TTDFetchAutoTraceStatusEventLogEntry, EventKind::TTDFetchAutoTraceStatusTag>(evt);
611+
612+
atfevt->IsEnabled = reader->ReadLogTag(NSTokens::Key::boolVal, true);
613+
}
600614
}
601615
}
602616

lib/Runtime/Debug/TTEvents.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ namespace TTD
9898
ExternalCallTag,
9999
ExplicitLogWriteTag,
100100
TTDInnerLoopLogWriteTag,
101+
TTDFetchAutoTraceStatusTag,
101102
//JsRTActionTag is a marker for where the JsRT actions begin
102103
JsRTActionTag,
103104

@@ -498,6 +499,15 @@ namespace TTD
498499

499500
void TTDInnerLoopLogWriteEventLogEntry_Emit(const EventLogEntry* evt, FileWriter* writer, ThreadContext* threadContext);
500501
void TTDInnerLoopLogWriteEventLogEntry_Parse(EventLogEntry* evt, ThreadContext* threadContext, FileReader* reader, UnlinkableSlabAllocator& alloc);
502+
503+
//A struct for recording the result of a read of the AutoTraceStatus
504+
struct TTDFetchAutoTraceStatusEventLogEntry
505+
{
506+
bool IsEnabled;
507+
};
508+
509+
void TTDFetchAutoTraceStatusEventLogEntry_Emit(const EventLogEntry* evt, FileWriter* writer, ThreadContext* threadContext);
510+
void TTDFetchAutoTraceStatusEventLogEntry_Parse(EventLogEntry* evt, ThreadContext* threadContext, FileReader* reader, UnlinkableSlabAllocator& alloc);
501511
}
502512
}
503513

lib/Runtime/Library/GlobalObject.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1674,9 +1674,20 @@ namespace Js
16741674
PROBE_STACK(function->GetScriptContext(), Js::Constants::MinStackDefault);
16751675
ARGUMENTS(args, callInfo);
16761676

1677-
if(function->GetScriptContext()->ShouldPerformRecordOrReplayAction() && !function->GetScriptContext()->GetThreadContext()->TTDLog->SuppressDiagnosticTracesDuringInnerLoop())
1677+
if (function->GetScriptContext()->ShouldPerformReplayAction())
16781678
{
1679-
return function->GetScriptContext()->GetLibrary()->GetTrue();
1679+
TTD::EventLog* ttlog = function->GetScriptContext()->GetThreadContext()->TTDLog;
1680+
bool isEnabled = ttlog->ReplayTTDFetchAutoTraceStatusLogEvent();
1681+
1682+
return function->GetScriptContext()->GetLibrary()->CreateBoolean(isEnabled);
1683+
}
1684+
else if (function->GetScriptContext()->ShouldPerformRecordAction())
1685+
{
1686+
TTD::EventLog* ttlog = function->GetScriptContext()->GetThreadContext()->TTDLog;
1687+
bool isEnabled = ttlog->GetAutoTraceEnabled();
1688+
ttlog->RecordTTDFetchAutoTraceStatusEvent(isEnabled);
1689+
1690+
return function->GetScriptContext()->GetLibrary()->CreateBoolean(isEnabled);
16801691
}
16811692
else
16821693
{

0 commit comments

Comments
 (0)