Преглед на файлове

OS#18260893 [OSS-Fuzz #9267] [OSS-Fuzz #9326] avoid assertion for re-start/stop in debugger mode

add comment
Duong Nguyen-Huu преди 7 години
родител
ревизия
e534568f57

+ 17 - 2
bin/ch/Debugger.cpp

@@ -427,7 +427,14 @@ bool Debugger::DumpFunctionPosition(JsValueRef functionPosition)
 
 bool Debugger::StartDebugging(JsRuntimeHandle runtime)
 {
-    IfJsrtErrorFailLogAndRetFalse(ChakraRTInterface::JsDiagStartDebugging(runtime, Debugger::DebugEventHandler, this));
+    JsErrorCode errorCode = ChakraRTInterface::JsDiagStartDebugging(runtime, Debugger::DebugEventHandler, this);
+
+    if (errorCode == JsErrorCode::JsErrorDiagAlreadyInDebugMode)
+    {
+        return false;
+    }
+
+    IfJsrtErrorFailLogAndRetFalse(errorCode);
 
     this->m_isDetached = false;
 
@@ -437,7 +444,15 @@ bool Debugger::StartDebugging(JsRuntimeHandle runtime)
 bool Debugger::StopDebugging(JsRuntimeHandle runtime)
 {
     void* callbackState = nullptr;
-    IfJsrtErrorFailLogAndRetFalse(ChakraRTInterface::JsDiagStopDebugging(runtime, &callbackState));
+
+    JsErrorCode errorCode = ChakraRTInterface::JsDiagStopDebugging(runtime, &callbackState);
+
+    if (errorCode == JsErrorCode::JsErrorDiagNotInDebugMode)
+    {
+        return false;
+    }
+
+    IfJsrtErrorFailLogAndRetFalse(errorCode);
 
     Assert(callbackState == this);
 

+ 15 - 0
test/Debugger/JsDebuggerAttachDetach.js

@@ -0,0 +1,15 @@
+//-------------------------------------------------------------------------------------------------------
+// Copyright (C) Microsoft. All rights reserved.
+// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
+//-------------------------------------------------------------------------------------------------------
+
+function foo() {
+    var x = 1; /**bp:dumpSourceList();**/
+    WScript.Echo("foo");
+}
+// Attach twice, detach twice
+WScript.Attach(foo);
+WScript.Attach(foo);
+WScript.Detach(foo);
+WScript.Detach(foo);
+WScript.Echo("Pass");

+ 5 - 0
test/Debugger/JsDebuggerAttachDetach.js.baseline

@@ -0,0 +1,5 @@
+Pass
+foo
+foo
+foo
+foo

+ 22 - 0
test/Debugger/JsDebuggerAttachDetach.js.dbg.baseline

@@ -0,0 +1,22 @@
+[
+  {
+    "sources": [
+      {
+        "fileName": "JsDebuggerAttachDetach.js",
+        "lineCount": 16,
+        "sourceLength": 605,
+        "scriptId": 1
+      }
+    ]
+  },
+  {
+    "sources": [
+      {
+        "fileName": "JsDebuggerAttachDetach.js",
+        "lineCount": 16,
+        "sourceLength": 605,
+        "scriptId": 1
+      }
+    ]
+  }
+]

+ 7 - 0
test/Debugger/rlexe.xml

@@ -114,4 +114,11 @@
       <files>loadscript_after_detach.js</files>
     </default>
   </test>
+  <test>
+    <default>
+      <compile-flags>-dbgbaseline:JsDebuggerAttachDetach.js.dbg.baseline</compile-flags>
+      <files>JsDebuggerAttachDetach.js</files>
+      <baseline>JsDebuggerAttachDetach.js.baseline</baseline>
+    </default>
+  </test>
 </regress-exe>