diff --git a/tools/projmgr/include/ProjMgrRunDebug.h b/tools/projmgr/include/ProjMgrRunDebug.h index e4bf6c1db..ccacc5997 100644 --- a/tools/projmgr/include/ProjMgrRunDebug.h +++ b/tools/projmgr/include/ProjMgrRunDebug.h @@ -227,6 +227,7 @@ class ProjMgrRunDebug { const std::map& pnames); void CollectTelnetOptions(const ContextItem& context, DebugAdapterItem& adapter, const std::map& pnames); + void SetTelnetPort(TelnetOptionsItem& item, unsigned long long& port, std::set& usedPorts); CustomItem& CustomMapFind(std::vector>& customMap, const std::string& key); void MergeCustomItems(const CustomItem& src, CustomItem& dst); }; diff --git a/tools/projmgr/src/ProjMgrRunDebug.cpp b/tools/projmgr/src/ProjMgrRunDebug.cpp index 33920d5b5..7411927cb 100644 --- a/tools/projmgr/src/ProjMgrRunDebug.cpp +++ b/tools/projmgr/src/ProjMgrRunDebug.cpp @@ -410,29 +410,34 @@ void ProjMgrRunDebug::CollectTelnetOptions(const ContextItem& context, DebugAdap unsigned long long port = adapter.defaults.telnet.port.empty() ? 0 : RteUtils::StringToULL(adapter.defaults.telnet.port); if (m_runDebug.debugger.telnet.find(m_runDebug.debugger.startPname) != m_runDebug.debugger.telnet.end()) { // add primary processor port first - auto& startPort = m_runDebug.debugger.telnet[m_runDebug.debugger.startPname].ullPort; - if (startPort == 0) { - startPort = port; - } else { - port = startPort; - } - usedPorts.insert(port); + auto& start = m_runDebug.debugger.telnet[m_runDebug.debugger.startPname]; + // set next available port + SetTelnetPort(start, port, usedPorts); + // set starting port for other processors + port = start.ullPort; } for (auto& [pname, telnet] : m_runDebug.debugger.telnet) { // add ports for other processors if (pname != m_runDebug.debugger.startPname) { - // get customized port if set - port = telnet.port.empty() ? port : telnet.ullPort; - while (usedPorts.find(port) != usedPorts.end()) { - // skip port number if it has already been used - port++; - } - telnet.ullPort = port; + // set next available port + SetTelnetPort(telnet, port, usedPorts); } } } } +void ProjMgrRunDebug::SetTelnetPort(TelnetOptionsItem& item, unsigned long long& port, std::set& usedPorts) { + // only assign a port number if it has not been already specified + if (item.port.empty()) { + while (usedPorts.find(port) != usedPorts.end()) { + // skip port number if it has already been used + port++; + } + item.ullPort = port; + usedPorts.insert(port); + } +} + void ProjMgrRunDebug::CollectDebugTopology(const ContextItem& context, const vector>> debugs, const std::map& pnames) { // debug topology diff --git a/tools/projmgr/test/data/TestRunDebug/telnet.csolution.yml b/tools/projmgr/test/data/TestRunDebug/telnet.csolution.yml index e142db8a2..9f3ff9a40 100644 --- a/tools/projmgr/test/data/TestRunDebug/telnet.csolution.yml +++ b/tools/projmgr/test/data/TestRunDebug/telnet.csolution.yml @@ -54,6 +54,20 @@ solution: name: J-Link Server start-pname: cm0_core1 + - set: CustomPorts + images: + - project-context: core0 + - project-context: core1 + debugger: + name: CMSIS-DAP + telnet: + - mode: monitor + pname: cm0_core1 + port: 1234 + - mode: monitor + pname: cm0_core0 + port: 5678 + - set: Warnings images: - project-context: core0 diff --git a/tools/projmgr/test/src/ProjMgrUnitTests.cpp b/tools/projmgr/test/src/ProjMgrUnitTests.cpp index 16e25e55a..769fb7987 100644 --- a/tools/projmgr/test/src/ProjMgrUnitTests.cpp +++ b/tools/projmgr/test/src/ProjMgrUnitTests.cpp @@ -6904,6 +6904,20 @@ R"(- mode: off pname: cm0_core1 port: 4444)", sstream3.str()); + // dual core with custom port numbers + argv[6] = (char*)"DualCore@CustomPorts"; + EXPECT_EQ(0, RunProjMgr(7, argv, m_envp)); + const YAML::Node& cbuildrun4 = YAML::LoadFile(testoutput_folder + "/out/telnet+DualCore.cbuild-run.yml"); + stringstream sstream4; + sstream4 << cbuildrun4["cbuild-run"]["debugger"]["telnet"]; + EXPECT_EQ( + R"(- mode: monitor + pname: cm0_core0 + port: 5678 +- mode: monitor + pname: cm0_core1 + port: 1234)", sstream4.str()); + // warnings StdStreamRedirect streamRedirect; argv[6] = (char*)"DualCore@Warnings";