Description
Describe the problem
Arduino IDE has an integrated debugger for debugging sketches.
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 AFAIK).
A CMSIS-DAP compliant or J-Link debug probe. Note that the Arduino Zero has an on-board debug probe.
Steps
- Set up your board as needed for use with the debugger.
- Create and save a sketch that contains a variable you can watch:
int foo; void setup() {} void loop() { foo++; }
- 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 - Enable Sketch > Optimize for Debugging in the Arduino IDE menus.
- Select Sketch > Upload from the Arduino IDE menus.
- Wait for the upload to finish.
- Click the "Start Debugging" button in the IDE toolbar.
- Wait for the debugger to start.
- Click the ❯ control next to "WATCH" in the "DEBUG" view to expand the "WATCH" section if it is not already expanded.
- Click the "+" icon ("Add Expression") button in the "WATCH" section heading.
- In the "Edit Watch Expression" field, type
foo
- Click the OK button.
🙂 Thefoo
variable is watched as expected. - Click the red square icon ("Stop") on the debugger toolbar.
- 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:
- 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.
I bisected the introduction of the bug to 112153f / #791
I see the following log output after attempting to start the debugger under these conditions:
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 112153f, there was similar output:
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 #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
- I searched for previous reports in the issue tracker
- I verified the problem still occurs when using the latest nightly build
- My report contains all necessary details