Marus / cortex-debug

Visual Studio Code extension for enhancing debug capabilities for Cortex-M Microcontrollers
MIT License
996 stars 238 forks source link

getTCPPorts returning used port #592

Closed NickolasLapp closed 2 years ago

NickolasLapp commented 2 years ago

I'm running into an error regarding port assignment when simultaneously debugging two devices with cortex-debug. The first debugger opens fine, using ports 50000, 50001, 50002 (

GDBInit file:                  none
GDB Server Listening port:     50000
SWO raw output listening port: 50001
Terminal I/O port:             50002

) but attempting to open a second debugger to attach to a different JLink USB device results in a port confilct:

ERROR: Failed to open listener port 50000
Restoring target state and closing J-Link connection...
Shutting down...
Failed to open listener port 50000

I am on version 0.4.10, Mac OS X 11.6.2.

I saw this similar issue: https://github.com/Marus/cortex-debug/issues/117 which appears to be resolved, so not sure what I'm running into here.

Also of note, I do see the port in use:

✗ netstat -anvp tcp | awk 'NR<3 || /LISTEN/' | rg '500'
tcp4       0      0  *.50002                *.*                    LISTEN      131072 131072  11310      0 0x0000 0x00000006
tcp4       0      0  *.50000                *.*                    LISTEN      131072 131072  11310      0 0x0000 0x00000006
tcp4       0      0  *.50001                *.*                    LISTEN      131072 131072  11310      0 0x0000 0x00000006

Please let me know if I can provide any more information or help in resolving this problem!

haneefdm commented 2 years ago

People generally have the opposite problem. NodeJS/OS tells us port(s) is busy when it is not.

In this case, we should have detected that ports 5000-50002 are busy and hopped onto new/unused ones.

I have a Mac but upgraded it over the weekend to 12.1 Hopefully, we can duplicate this. We should be able to do that using plain javascript (NodeJS) with no VSCode involved.

Thanks for reporting this problem

haneefdm commented 2 years ago

Found the issue. I can use nc (netcat) to create a server and our extension does indeed think it is free. It is because on 0.0.0.0 it is reported as free but not on 127.0.0.1. We do check both now... and I remember this used to be different. Now we check both. I have two sessions (I don't have two JLinks)

Launching gdb-server: /Users/hdm/cypress/rtt/cyopenocd-build/bin/openocd -c "gdb_port 50000" -c "tcl_port 50002" -c "telnet_port 50004" -s /Users/hdm/rtt/Hello_World -s /Applications/ModusToolbox/tools_2.3/openocd/scripts/ -f /Users/hdm/.vscode/extensions/marus25.cortex-debug-1.3.1/support/openocd-helpers.tcl -f openocd.tcl

Above was OpenOCD -- used up 5000-5004 and the following was JLink avoiding each other

Command line: -singlerun -nogui -if swd -port 50005 -swoport 50006 -telnetport 50007 -device CY8C6xx7_CM4_sect256KB -rtttelnetport 19021 -rtos GDBServer/RTOSPlugin_FreeRTOS.dylib
-----GDB Server start settings-----
GDBInit file:                  none
GDB Server Listening port:     50005
SWO raw output listening port: 50006
Terminal I/O port:             50007

It will be fixed in the next pre-release (due out in a couple of days) if you are subscribed to that

NickolasLapp commented 2 years ago

That's awesome! Really appreciate the support. I'll make sure to subscribe to the pre-release and confirm it is fixed then.

haneefdm commented 2 years ago

The fix is available as a pre-release 1.3.2. Thank you for reporting this. I hope you can verify the fix

You can opt-in and install the pre-release right from VSCode extensions tab.