Skip to content

Commit

Permalink
[1.8>1.9] [MERGE #4610 @agarwal-sandeep] OS#15522456 ScriptContext cr…
Browse files Browse the repository at this point in the history
…eated after calling JsDiagStopDebugging should set debugging mode as SourceRunDown instead of Debugging.

Merge pull request #4610 from agarwal-sandeep:fixstopdebuggingbug

Found by OSS-Fuzz.
  • Loading branch information
agarwal-sandeep committed Jan 30, 2018
2 parents abd18d0 + 685ff60 commit 5644e6c
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 9 deletions.
22 changes: 16 additions & 6 deletions lib/Jsrt/Jsrt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,17 +178,27 @@ JsErrorCode CreateContextCore(_In_ JsRuntimeHandle runtimeHandle, _In_ TTDRecord

if(jsrtDebugManager != nullptr)
{
// JsDiagStartDebugging was called
threadContext->GetDebugManager()->SetLocalsDisplayFlags(Js::DebugManager::LocalsDisplayFlags::LocalsDisplayFlags_NoGroupMethods);

Js::ScriptContext* scriptContext = context->GetScriptContext();
scriptContext->InitializeDebugging();

Js::DebugContext* debugContext = scriptContext->GetDebugContext();
debugContext->SetHostDebugContext(jsrtDebugManager);

Js::ProbeContainer* probeContainer = debugContext->GetProbeContainer();
probeContainer->InitializeInlineBreakEngine(jsrtDebugManager);
probeContainer->InitializeDebuggerScriptOptionCallback(jsrtDebugManager);

threadContext->GetDebugManager()->SetLocalsDisplayFlags(Js::DebugManager::LocalsDisplayFlags::LocalsDisplayFlags_NoGroupMethods);
if (!jsrtDebugManager->IsDebugEventCallbackSet())
{
// JsDiagStopDebugging was called so we need to be in SourceRunDownMode
debugContext->SetDebuggerMode(Js::DebuggerMode::SourceRundown);
}
else
{
// Set Debugging mode
scriptContext->InitializeDebugging();
Js::ProbeContainer* probeContainer = debugContext->GetProbeContainer();
probeContainer->InitializeInlineBreakEngine(jsrtDebugManager);
probeContainer->InitializeDebuggerScriptOptionCallback(jsrtDebugManager);
}
}
#endif

Expand Down
10 changes: 7 additions & 3 deletions lib/Jsrt/JsrtDiag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,13 @@ CHAKRA_API JsDiagStartDebugging(
return JsErrorFatal;
}

Js::ProbeContainer* probeContainer = debugContext->GetProbeContainer();
probeContainer->InitializeInlineBreakEngine(jsrtDebugManager);
probeContainer->InitializeDebuggerScriptOptionCallback(jsrtDebugManager);
// ScriptContext might get closed in OnDebuggerAttached
if (!scriptContext->IsClosed())
{
Js::ProbeContainer* probeContainer = debugContext->GetProbeContainer();
probeContainer->InitializeInlineBreakEngine(jsrtDebugManager);
probeContainer->InitializeDebuggerScriptOptionCallback(jsrtDebugManager);
}
}

return JsNoError;
Expand Down
1 change: 1 addition & 0 deletions test/Debugger/emptyJson.dbg.baseline
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
17 changes: 17 additions & 0 deletions test/Debugger/loadscript_after_detach.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------

var count = 0;
function foo() {
count++;
if (count == 3) {
WScript.LoadScript("", "samethread"); // ScriptContext should be created in sourcerundown mode instead of debugging mode
}
}
foo();
WScript.Attach(foo);
WScript.Detach(foo);
WScript.Attach(foo);
WScript.Echo("pass");
6 changes: 6 additions & 0 deletions test/Debugger/rlexe.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,10 @@
<files>dumpFunctionProperties.js</files>
</default>
</test>
<test>
<default>
<compile-flags>-dbgbaseline:emptyJson.dbg.baseline</compile-flags>
<files>loadscript_after_detach.js</files>
</default>
</test>
</regress-exe>

0 comments on commit 5644e6c

Please sign in to comment.