hgycap October 26, 2022, 1:53am 1 I am trying to debug Arduino Zero with Arduino IDE 2.0. When I hit 'Start Debugging' for the first time it works. But after I stop the debugging and try to restart I got an error "Request 4 cancelled on connection close" and the debugger does not start. Anyone can help me to figure out this situation?
Hi @hgycap .
Please provide detailed instructions I can follow to exactly replicate this procedure. I did some experiments with my Zero and the Arduino IDE 2.x integrated debugger and was not able to reproduce that error.
Where is the error shown? Is it in the "Debug Console " view, in a notification, somewhere else?
If there is any additional text, please post all of it.
hgycap October 26, 2022, 6:11am 3 Type in or open an example. Open the debug panel. Put a breakpoint. Start debugging with the 'Start Debugging' button in the debug panel. Stop the debugging with the 'Stop' button in the debug panel. Start debugging again with the 'Start Debugging' button in the debug panel. Then I got an error as in the attached image.
One curious thing is that I can restart a debugging session with the blink sketch in examples. But I got an error with the sketch attached above.
Same failure message for me. If I rename the sketch, debugging is possible again.
hgycap October 26, 2022, 10:57am 5 Thank you very much. But for me, some work but some do not.
Here is another problem. For the sketches unable to debug has an empty launch.json when I press the "Open launch.json" button in debug panel. Of course, after I renamed the sketch. It looks like this:
{ // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. "version": "0.2.0", "configurations": [] }
"launch.json" is not an auto-generated one? Is there any way to set up manually the content of launch.json?
Hi @hgycap and @peter28357 I am able to reproduce the problem and found it is caused by having a "watch" expression configured, as you can see here in the screenshot shared by @hgycap :
I have submitted a bug report to the Arduino IDE developers:
opened 03:39AM - 27 Oct 22 UTC
closed 10:43AM - 01 Dec 22 UTC
conclusion: resolved type: imperfection topic: debugger
### Describe the problem Arduino IDE has [an integrated debugger for debuggin… g sketches](https://docs.arduino.cc/software/ide-v2/tutorials/ide-v2-debugger). One of the features of the debugger is the ability to configure expressions to "watch", which is useful for tracking the value of variables at each point in the program execution. 🐛 If a watch expression is configured, the debugger fails to start. ### To reproduce #### Equipment Any board of a platform that is configured for use with the debugger (currently only ["**Arduino SAMD (32-bits ARM Cortex-M0+) Boards**" platform](https://github.com/arduino/ArduinoCore-samd) AFAIK). A CMSIS-DAP compliant or J-Link debug probe. Note that the [Arduino Zero](https://store.arduino.cc/products/arduino-zero) has an on-board debug probe. #### Steps 1. Set up your board as needed for use with the debugger. 1. Create and save a sketch that contains a variable you can watch: ```cpp int foo; void setup() {} void loop() { foo++; } ``` 1. If you are using a J-Link, add the `debug_custom.json` file to the sketch: https://docs.arduino.cc/tutorials/mkr-wifi-1010/mkr-jlink-setup#debugging-in-arduino-ide-20 1. Enable **Sketch > Optimize for Debugging** in the Arduino IDE menus. 1. Select **Sketch > Upload** from the Arduino IDE menus. 1. Wait for the upload to finish. 1. Click the "**Start Debugging**" button in the IDE toolbar. 1. Wait for the debugger to start. 1. Click the **❯** control next to "**WATCH**" in the "**DEBUG**" view to expand the "**WATCH**" section if it is not already expanded. 1. Click the "**+**" icon ("**Add Expression**") button in the "**WATCH**" section heading. 1. In the "**Edit Watch Expression**" field, type `foo` 1. Click the <kbd>**OK**</kbd> button. 🙂 The `foo` variable is watched as expected. 1. Click the red square icon ("**Stop**") on the debugger toolbar. 1. Click the green triangle icon ("**Start Debugging**") on the debugger toolbar. 🐛 The debugger does not start. An error notification is shown: > **Request 4 cancelled on connection close** It will no longer be possible to start the debugger for that sketch even after restarting the IDE. The debugger can only be started once more after removing the watch expression. ### Expected behavior Debugger can be started even if a watch expression is configured. ### Arduino IDE version 2.0.1-snapshot-2b2463b ### Operating system - Windows - Linux ### Operating system version - Windows 10 - Ubuntu 20.04 ### Additional context The bug can be worked around by the following procedure: 1. Hover the mouse pointer over the heading of the "**WATCH**" section in the debugger view. You will now see an icon with an **X** at the right side of the heading:  Click that icon. 1. Start the debugger. 1. Replace any watch expressions you need. --- I bisected the introduction of the bug to 112153fb / https://github.com/arduino/arduino-ide/pull/791 --- I see the following log output after attempting to start the debugger under these conditions: ```text root INFO [hosted-plugin: 14416] Creating local connection: 722ebbc7-f483-4d36-bd66-67c1f636e6ec root INFO [hosted-plugin: 14416] starting debug adapter session '722ebbc7-f483-4d36-bd66-67c1f636e6ec' root INFO [hosted-plugin: 14416] Creating plugin connection: 722ebbc7-f483-4d36-bd66-67c1f636e6ec root ERROR [hosted-plugin: 14416] (node:10684) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead. (Use `Arduino IDE --trace-deprecation ...` to show where the warning was created) root ERROR [hosted-plugin: 14416] C:\ide 2\tip\149-2b2463b\resources\app\plugins\cortex-debug\extension\dist\debugadapter.js:9 const s=r(3),n=r(1),o=r(12),i=r(51),a=process.binding("constants"),u=i(),c="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", [... and tens of thousands more characters; longer than GitHub will allow in an issue] root ERROR [hosted-plugin: 14416] n"[object Number]"===n.call(e)&&e%1==0},o.int=o.integer,o.notANumber=function(e){return!o.num(e)||e!=e}, [... and tens of thousands more characters; longer than GitHub will allow in an issue] TypeError: Cannot read properties of undefined (reading 'showDevDebugOutput') at _.wrapTimeStamp (C:\ide 2\tip\149-2b2463b\resources\app\plugins\cortex-debug\extension\dist\debugadapter.js:9:21659) at _.handleMsg (C:\ide 2\tip\149-2b2463b\resources\app\plugins\cortex-debug\extension\dist\debugadapter.js:9:22029) at _.<anonymous> (C:\ide 2\tip\149-2b2463b\resources\app\plugins\cortex-debug\extension\dist\debugadapter.js:9:39946) at Generator.next (<anonymous>) at C:\ide 2\tip\149-2b2463b\resources\app\plugins\cortex-debug\extension\dist\debugadapter.js:9:4272 at new Promise (<anonymous>) at s (C:\ide 2\tip\149-2b2463b\resources\app\plugins\cortex-debug\extension\dist\debugadapter.js:9:4017) at _.evaluateRequest (C:\ide 2\tip\149-2b2463b\resources\app\plugins\cortex-debug\extension\dist\debugadapter.js:9:39565) at _.dispatchRequest (C:\ide 2\tip\149-2b2463b\resources\app\plugins\cortex-debug\extension\dist\debugadapter.js:1:12109) at _.handleMessage (C:\ide 2\tip\149-2b2463b\resources\app\plugins\cortex-debug\extension\dist\debugadapter.js:9:42356) root INFO [hosted-plugin: 14416] onDebugAdapterExit session: '722ebbc7-f483-4d36-bd66-67c1f636e6ec' root ERROR Error on disconnect root ERROR [hosted-plugin: 14416] Error: ENOENT: no such file or directory, open 'c:\Users\per\Documents\Arduino\sketch_oct26b\.vscode\.cortex-debug.registers.state.json' at Object.openSync (node:fs:582:3) at Object.func [as openSync] (node:electron/js2c/asar_bundle:5:1800) at Object.writeFileSync (node:fs:2143:35) at t.RegisterTreeProvider._saveState (C:\ide 2\tip\149-2b2463b\resources\app\plugins\cortex-debug\extension\dist\extension.js:214:12938) at t.RegisterTreeProvider.debugSessionTerminated (C:\ide 2\tip\149-2b2463b\resources\app\plugins\cortex-debug\extension\dist\extension.js:214:13208) at k.debugSessionTerminated (C:\ide 2\tip\149-2b2463b\resources\app\plugins\cortex-debug\extension\dist\extension.js:129:61849) at C:\ide 2\tip\149-2b2463b\resources\app\node_modules\@theia\core\lib\common\event.js:103:69 at CallbackList.invoke (C:\ide 2\tip\149-2b2463b\resources\app\node_modules\@theia\core\lib\common\event.js:109:26) at Emitter.fire (C:\ide 2\tip\149-2b2463b\resources\app\node_modules\@theia\core\lib\common\event.js:224:29) at DebugExtImpl.$sessionDidDestroy (C:\ide 2\tip\149-2b2463b\resources\app\node_modules\@theia\plugin-ext\lib\plugin\node\debug\debug.js:186:52) { errno: -4058, syscall: 'open', code: 'ENOENT', path: 'c:\\Users\\per\\Documents\\Arduino\\sketch_oct26b\\.vscode\\.cortex-debug.registers.state.json' } ``` The problem still occurs, except without the `ENOENT` error in the logs, after I create `c:\Users\per\Documents\Arduino\sketch_oct26b\.vscode\.cortex-debug.registers.state.json`, which makes me question whether that part of the output is relevant. Prior to 112153fb, there was similar output: ```text root INFO [hosted-plugin: 14104] PLUGIN_HOST(14104): PluginManagerExtImpl/loadPlugin(E:\ide2\tip\1-69ac1f4\resources\app\plugins\cortex-debug\extension\dist\extension) root INFO [hosted-plugin: 14104] Debug configuration provider has been registered: cortex-debug, trigger: 1 root ERROR [hosted-plugin: 14104] (node:10576) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead. root ERROR [hosted-plugin: 14104] (node:10576) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'showDevDebugOutput' of undefined at _.wrapTimeStamp (E:\ide2\tip\1-69ac1f4\resources\app\plugins\cortex-debug\extension\dist\debugadapter.js:9:21659) at _.handleMsg (E:\ide2\tip\1-69ac1f4\resources\app\plugins\cortex-debug\extension\dist\debugadapter.js:9:22029) at _.<anonymous> (E:\ide2\tip\1-69ac1f4\resources\app\plugins\cortex-debug\extension\dist\debugadapter.js:9:39946) at Generator.next (<anonymous>) at E:\ide2\tip\1-69ac1f4\resources\app\plugins\cortex-debug\extension\dist\debugadapter.js:9:4272 at new Promise (<anonymous>) at s (E:\ide2\tip\1-69ac1f4\resources\app\plugins\cortex-debug\extension\dist\debugadapter.js:9:4017) at _.evaluateRequest (E:\ide2\tip\1-69ac1f4\resources\app\plugins\cortex-debug\extension\dist\debugadapter.js:9:39565) at _.dispatchRequest (E:\ide2\tip\1-69ac1f4\resources\app\plugins\cortex-debug\extension\dist\debugadapter.js:1:12109) at _.handleMessage (E:\ide2\tip\1-69ac1f4\resources\app\plugins\cortex-debug\extension\dist\debugadapter.js:9:42356) root ERROR [hosted-plugin: 14104] (node:10576) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1) (node:10576) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. ``` --- It may be related to https://github.com/arduino/arduino-ide/issues/412 in that this is a report of the watch expression not working if it was configured before the debugger was started. --- Originally reported at: - https://forum.arduino.cc/t/getting-the-debugger-to-work/1020797/1 - https://forum.arduino.cc/t/getting-the-debugger-to-work/1020797/8 - https://forum.arduino.cc/t/arduino-zero-debug-error-with-ide-2-0/1046036/1 - https://forum.arduino.cc/t/arduino-zero-debug-error-with-ide-2-0/1046036/4 ### Issue checklist - [X] I searched for previous reports in [the issue tracker](https://github.com/arduino/arduino-ide/issues?q=) - [X] I verified the problem still occurs when using the latest [nightly build](https://github.com/arduino/arduino-ide#nightly-builds) - [X] My report contains all necessary details
The workaround is to remove any watch expressions before starting the IDE:
Hover the mouse pointer over the heading of the "WATCH " section in the debugger view. You will now see an icon with an X at the right side of the heading: Click that icon. Start the debugger. Replace any watch expressions you need. Please let me know if you have any questions or problems while following those instructions.
hgycap October 27, 2022, 8:14am 7 Thank you very much. Your solution works for me. Thank you again.
You are welcome. I'm glad if I was able to be of assistance.
Thanks also to you for bringing this problem to our attention. I received a couple of reports of it previously, but was not able to reproduce the problem at that time. The information you shared gave me the essential clue that the presence of a watch expression was the required condition.
Regards, Per
system Closed April 25, 2023, 8:27am 9 This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.