Przeglądaj źródła

[MERGE #5202 @mrkmarron] TTD: explicit support for enable/disable auto-trace

Merge pull request #5202 from mrkmarron:rrfix

Fix for auto-trace behavior.
Mark Marron 7 lat temu
rodzic
commit
1b469e2352

+ 1 - 0
bin/ChakraCore/ChakraCore.def

@@ -46,6 +46,7 @@ JsTTDMoveToTopLevelEvent
 JsTTDReplayExecution
 
 JsTTDDiagWriteLog
+JsTTDDiagSetAutoTraceStatus
 
 JsInitializeModuleRecord
 JsParseModuleSource

+ 11 - 0
lib/Jsrt/ChakraDebug.h

@@ -1014,6 +1014,17 @@ typedef unsigned __int32 uint32_t;
             _Inout_ JsTTDMoveMode* moveMode,
             _Out_ int64_t* rootEventTime);
 
+    /// <summary>
+    ///     TTD API -- may change in future versions:
+    ///     Enable or disable autotrace ability from JsRT.
+    /// </summary>
+    /// <param name="status">True to enable autotracing false to disable it.</param>
+    /// <returns>The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.</returns>
+    CHAKRA_API
+        JsTTDDiagSetAutoTraceStatus(
+            _In_ bool status
+        );
+
     /// <summary>
     ///     TTD API -- may change in future versions:
     ///     A way for the debugger to programatically write a trace when it is at a breakpoint.

+ 21 - 0
lib/Jsrt/Jsrt.cpp

@@ -4625,6 +4625,27 @@ CHAKRA_API JsTTDReplayExecution(_Inout_ JsTTDMoveMode* moveMode, _Out_ int64_t*
 #endif
 }
 
+CHAKRA_API JsTTDDiagSetAutoTraceStatus(_In_ bool status)
+{
+#if !ENABLE_TTD
+    return JsErrorCategoryUsage;
+#else
+    JsrtContext *currentContext = JsrtContext::GetCurrent();
+    JsErrorCode cCheck = CheckContext(currentContext, JSRT_MAYBE_TRUE);
+    TTDAssert(cCheck == JsNoError, "Must have valid context when setting auto trace status.");
+
+    Js::ScriptContext* scriptContext = currentContext->GetScriptContext();
+    ThreadContext* threadContext = scriptContext->GetThreadContext();
+
+    if (threadContext->IsRuntimeInTTDMode())
+    {
+        threadContext->TTDLog->SetAutoTraceEnabled(status);
+    }
+
+    return JsNoError;
+#endif
+}
+
 #ifdef _CHAKRACOREBUILD
 
 template <class SrcChar, class DstChar>

+ 21 - 3
lib/Runtime/Debug/TTEventLog.cpp

@@ -508,6 +508,7 @@ namespace TTD
         TTD_CREATE_EVENTLIST_VTABLE_ENTRY(ExternalCallTag, None, ExternalCallEventLogEntry, nullptr, NSLogEvents::ExternalCallEventLogEntry_UnloadEventMemory, NSLogEvents::ExternalCallEventLogEntry_Emit, NSLogEvents::ExternalCallEventLogEntry_Parse);
         TTD_CREATE_EVENTLIST_VTABLE_ENTRY(ExplicitLogWriteTag, None, ExplicitLogWriteEventLogEntry, nullptr, nullptr, NSLogEvents::ExplicitLogWriteEntry_Emit, NSLogEvents::ExplicitLogWriteEntry_Parse);
         TTD_CREATE_EVENTLIST_VTABLE_ENTRY(TTDInnerLoopLogWriteTag, None, TTDInnerLoopLogWriteEventLogEntry, nullptr, nullptr, NSLogEvents::TTDInnerLoopLogWriteEventLogEntry_Emit, NSLogEvents::TTDInnerLoopLogWriteEventLogEntry_Parse);
+        TTD_CREATE_EVENTLIST_VTABLE_ENTRY(TTDFetchAutoTraceStatusTag, None, TTDFetchAutoTraceStatusEventLogEntry, nullptr, nullptr, NSLogEvents::TTDFetchAutoTraceStatusEventLogEntry_Emit, NSLogEvents::TTDFetchAutoTraceStatusEventLogEntry_Parse);
 
         TTD_CREATE_EVENTLIST_VTABLE_ENTRY(CreateScriptContextActionTag, GlobalAPIWrapper, JsRTCreateScriptContextAction, NSLogEvents::CreateScriptContext_Execute, NSLogEvents::CreateScriptContext_UnloadEventMemory, NSLogEvents::CreateScriptContext_Emit, NSLogEvents::CreateScriptContext_Parse);
         TTD_CREATE_EVENTLIST_VTABLE_ENTRY_COMMON(SetActiveScriptContextActionTag, GlobalAPIWrapper, JsRTSingleVarArgumentAction, SetActiveScriptContext_Execute);
@@ -586,7 +587,7 @@ namespace TTD
         : m_threadContext(threadContext), m_eventSlabAllocator(TTD_SLAB_BLOCK_ALLOCATION_SIZE_MID), m_miscSlabAllocator(TTD_SLAB_BLOCK_ALLOCATION_SIZE_SMALL),
         m_eventTimeCtr(0), m_timer(), m_topLevelCallbackEventTime(-1),
         m_eventListVTable(nullptr), m_eventList(&this->m_eventSlabAllocator), m_currentReplayEventIterator(),
-        m_modeStack(), m_currentMode(TTDMode::Invalid),
+        m_modeStack(), m_currentMode(TTDMode::Invalid), m_autoTracesEnabled(true),
         m_snapExtractor(), m_elapsedExecutionTimeSinceSnapshot(0.0),
         m_lastInflateSnapshotTime(-1), m_lastInflateMap(nullptr), m_propertyRecordList(&this->m_miscSlabAllocator),
         m_sourceInfoCount(0), m_loadedTopLevelScripts(&this->m_miscSlabAllocator), m_newFunctionTopLevelScripts(&this->m_miscSlabAllocator), m_evalTopLevelScripts(&this->m_miscSlabAllocator)
@@ -879,6 +880,18 @@ namespace TTD
         }
     }
 
+    void EventLog::RecordTTDFetchAutoTraceStatusEvent(bool status)
+    {
+        NSLogEvents::TTDFetchAutoTraceStatusEventLogEntry* atfEvent = this->RecordGetInitializedEvent_DataOnly<NSLogEvents::TTDFetchAutoTraceStatusEventLogEntry, NSLogEvents::EventKind::TTDFetchAutoTraceStatusTag>();
+        atfEvent->IsEnabled = status;
+    }
+
+    bool EventLog::ReplayTTDFetchAutoTraceStatusLogEvent()
+    {
+        const NSLogEvents::TTDFetchAutoTraceStatusEventLogEntry* atfEvent = this->ReplayGetReplayEvent_Helper<NSLogEvents::TTDFetchAutoTraceStatusEventLogEntry, NSLogEvents::EventKind::TTDFetchAutoTraceStatusTag>();
+        return atfEvent->IsEnabled;
+    }
+
     void EventLog::RecordDateTimeEvent(double time)
     {
         NSLogEvents::DoubleEventLogEntry* dEvent = this->RecordGetInitializedEvent_DataOnly<NSLogEvents::DoubleEventLogEntry, NSLogEvents::EventKind::DoubleTag>();
@@ -2558,9 +2571,14 @@ namespace TTD
         return isInnerLoop & isEnabled;
     }
 
-    bool EventLog::SuppressDiagnosticTracesDuringInnerLoop() const
+    void EventLog::SetAutoTraceEnabled(bool enabled)
+    {
+        this->m_autoTracesEnabled = enabled;
+    }
+
+    bool EventLog::GetAutoTraceEnabled() const
     {
-        return (this->m_currentMode & (TTDMode::DebuggerAttachedMode)) == TTDMode::DebuggerAttachedMode;
+        return this->m_autoTracesEnabled;
     }
 
     void EventLog::EmitLog(const char* emitUri, size_t emitUriLength, NSLogEvents::EventLogEntry* optInnerLoopEvent)

+ 9 - 1
lib/Runtime/Debug/TTEventLog.h

@@ -226,6 +226,7 @@ namespace TTD
         //The current mode the system is running in (and a stack of mode push/pops that we use to generate it)
         TTModeStack m_modeStack;
         TTDMode m_currentMode;
+        bool m_autoTracesEnabled;
 
         //The snapshot extractor that this log uses
         SnapshotExtractor m_snapExtractor;
@@ -393,6 +394,12 @@ namespace TTD
         //Replay a event that writes the log to a given uri
         void ReplayEmitLogEvent();
 
+        //Record that we are accessing the TTDFetchAutoTraceStatus and what the value is
+        void RecordTTDFetchAutoTraceStatusEvent(bool status);
+
+        //Replay that we are accessing the TTDFetchAutoTraceStatus
+        bool ReplayTTDFetchAutoTraceStatusLogEvent();
+
         //Log a time that is fetched during date operations
         void RecordDateTimeEvent(double time);
 
@@ -605,7 +612,8 @@ namespace TTD
         void InnerLoopEmitLog(const TTDebuggerSourceLocation& writeLocation, const char* emitUri, size_t emitUriLength);
 
         bool CanWriteInnerLoopTrace() const;
-        bool SuppressDiagnosticTracesDuringInnerLoop() const;
+        void SetAutoTraceEnabled(bool enabled);
+        bool GetAutoTraceEnabled() const;
 
         void EmitLog(const char* emitUri, size_t emitUriLength, NSLogEvents::EventLogEntry* optInnerLoopEvent = nullptr);
         void ParseLogInto(TTDataIOInfo& iofp, const char* parseUri, size_t parseUriLength);

+ 14 - 0
lib/Runtime/Debug/TTEvents.cpp

@@ -597,6 +597,20 @@ namespace TTD
             ilevt->Line = reader->ReadUInt32(NSTokens::Key::line, true);
             ilevt->Column = reader->ReadUInt32(NSTokens::Key::column, true);
         }
+
+        void TTDFetchAutoTraceStatusEventLogEntry_Emit(const EventLogEntry* evt, FileWriter* writer, ThreadContext* threadContext)
+        {
+            const TTDFetchAutoTraceStatusEventLogEntry* atfevt = GetInlineEventDataAs<TTDFetchAutoTraceStatusEventLogEntry, EventKind::TTDFetchAutoTraceStatusTag>(evt);
+
+            writer->WriteLogTag(NSTokens::Key::boolVal, atfevt->IsEnabled, NSTokens::Separator::CommaSeparator);
+        }
+
+        void TTDFetchAutoTraceStatusEventLogEntry_Parse(EventLogEntry* evt, ThreadContext* threadContext, FileReader* reader, UnlinkableSlabAllocator& alloc)
+        {
+            TTDFetchAutoTraceStatusEventLogEntry* atfevt = GetInlineEventDataAs<TTDFetchAutoTraceStatusEventLogEntry, EventKind::TTDFetchAutoTraceStatusTag>(evt);
+
+            atfevt->IsEnabled = reader->ReadLogTag(NSTokens::Key::boolVal, true);
+        }
     }
 }
 

+ 10 - 0
lib/Runtime/Debug/TTEvents.h

@@ -98,6 +98,7 @@ namespace TTD
             ExternalCallTag,
             ExplicitLogWriteTag,
             TTDInnerLoopLogWriteTag,
+            TTDFetchAutoTraceStatusTag,
             //JsRTActionTag is a marker for where the JsRT actions begin
             JsRTActionTag,
 
@@ -498,6 +499,15 @@ namespace TTD
 
         void TTDInnerLoopLogWriteEventLogEntry_Emit(const EventLogEntry* evt, FileWriter* writer, ThreadContext* threadContext);
         void TTDInnerLoopLogWriteEventLogEntry_Parse(EventLogEntry* evt, ThreadContext* threadContext, FileReader* reader, UnlinkableSlabAllocator& alloc);
+
+        //A struct for recording the result of a read of the AutoTraceStatus
+        struct TTDFetchAutoTraceStatusEventLogEntry
+        {
+            bool IsEnabled;
+        };
+
+        void TTDFetchAutoTraceStatusEventLogEntry_Emit(const EventLogEntry* evt, FileWriter* writer, ThreadContext* threadContext);
+        void TTDFetchAutoTraceStatusEventLogEntry_Parse(EventLogEntry* evt, ThreadContext* threadContext, FileReader* reader, UnlinkableSlabAllocator& alloc);
     }
 }
 

+ 13 - 2
lib/Runtime/Library/GlobalObject.cpp

@@ -1674,9 +1674,20 @@ LHexError:
         PROBE_STACK(function->GetScriptContext(), Js::Constants::MinStackDefault);
         ARGUMENTS(args, callInfo);
 
-        if(function->GetScriptContext()->ShouldPerformRecordOrReplayAction() && !function->GetScriptContext()->GetThreadContext()->TTDLog->SuppressDiagnosticTracesDuringInnerLoop())
+        if (function->GetScriptContext()->ShouldPerformReplayAction())
         {
-            return function->GetScriptContext()->GetLibrary()->GetTrue();
+            TTD::EventLog* ttlog = function->GetScriptContext()->GetThreadContext()->TTDLog;
+            bool isEnabled = ttlog->ReplayTTDFetchAutoTraceStatusLogEvent();
+
+            return function->GetScriptContext()->GetLibrary()->CreateBoolean(isEnabled);
+        }
+        else if (function->GetScriptContext()->ShouldPerformRecordAction())
+        {
+            TTD::EventLog* ttlog = function->GetScriptContext()->GetThreadContext()->TTDLog;
+            bool isEnabled = ttlog->GetAutoTraceEnabled();
+            ttlog->RecordTTDFetchAutoTraceStatusEvent(isEnabled);
+
+            return function->GetScriptContext()->GetLibrary()->CreateBoolean(isEnabled);
         }
         else
         {