Skip to content

Commit 72c274f

Browse files
committed
[MERGE #5586 @duongnhn] OS#18260893 [OSS-Fuzz #9267] [OSS-Fuzz #9326] avoid assertion for re-start/stop in debugger mode
Merge pull request #5586 from duongnhn:user/duongn/avoid-assertion-debugger-attach-detach
2 parents 4460013 + e534568 commit 72c274f

File tree

5 files changed

+66
-2
lines changed

5 files changed

+66
-2
lines changed

bin/ch/Debugger.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,14 @@ bool Debugger::DumpFunctionPosition(JsValueRef functionPosition)
427427

428428
bool Debugger::StartDebugging(JsRuntimeHandle runtime)
429429
{
430-
IfJsrtErrorFailLogAndRetFalse(ChakraRTInterface::JsDiagStartDebugging(runtime, Debugger::DebugEventHandler, this));
430+
JsErrorCode errorCode = ChakraRTInterface::JsDiagStartDebugging(runtime, Debugger::DebugEventHandler, this);
431+
432+
if (errorCode == JsErrorCode::JsErrorDiagAlreadyInDebugMode)
433+
{
434+
return false;
435+
}
436+
437+
IfJsrtErrorFailLogAndRetFalse(errorCode);
431438

432439
this->m_isDetached = false;
433440

@@ -437,7 +444,15 @@ bool Debugger::StartDebugging(JsRuntimeHandle runtime)
437444
bool Debugger::StopDebugging(JsRuntimeHandle runtime)
438445
{
439446
void* callbackState = nullptr;
440-
IfJsrtErrorFailLogAndRetFalse(ChakraRTInterface::JsDiagStopDebugging(runtime, &callbackState));
447+
448+
JsErrorCode errorCode = ChakraRTInterface::JsDiagStopDebugging(runtime, &callbackState);
449+
450+
if (errorCode == JsErrorCode::JsErrorDiagNotInDebugMode)
451+
{
452+
return false;
453+
}
454+
455+
IfJsrtErrorFailLogAndRetFalse(errorCode);
441456

442457
Assert(callbackState == this);
443458

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//-------------------------------------------------------------------------------------------------------
2+
// Copyright (C) Microsoft. All rights reserved.
3+
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
4+
//-------------------------------------------------------------------------------------------------------
5+
6+
function foo() {
7+
var x = 1; /**bp:dumpSourceList();**/
8+
WScript.Echo("foo");
9+
}
10+
// Attach twice, detach twice
11+
WScript.Attach(foo);
12+
WScript.Attach(foo);
13+
WScript.Detach(foo);
14+
WScript.Detach(foo);
15+
WScript.Echo("Pass");
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Pass
2+
foo
3+
foo
4+
foo
5+
foo
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[
2+
{
3+
"sources": [
4+
{
5+
"fileName": "JsDebuggerAttachDetach.js",
6+
"lineCount": 16,
7+
"sourceLength": 605,
8+
"scriptId": 1
9+
}
10+
]
11+
},
12+
{
13+
"sources": [
14+
{
15+
"fileName": "JsDebuggerAttachDetach.js",
16+
"lineCount": 16,
17+
"sourceLength": 605,
18+
"scriptId": 1
19+
}
20+
]
21+
}
22+
]

test/Debugger/rlexe.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,11 @@
114114
<files>loadscript_after_detach.js</files>
115115
</default>
116116
</test>
117+
<test>
118+
<default>
119+
<compile-flags>-dbgbaseline:JsDebuggerAttachDetach.js.dbg.baseline</compile-flags>
120+
<files>JsDebuggerAttachDetach.js</files>
121+
<baseline>JsDebuggerAttachDetach.js.baseline</baseline>
122+
</default>
123+
</test>
117124
</regress-exe>

0 commit comments

Comments
 (0)