From 2d56aa5f95d0cdf2a1589e0c4cc56dd6a962f9fc Mon Sep 17 00:00:00 2001 From: Daniel Brondani Date: Tue, 10 Nov 2026 15:04:39 +0100 Subject: [PATCH 1/2] [projmgr] Add `trace` configuration schema and `file` node handling --- tools/projmgr/include/ProjMgrParser.h | 6 +++ tools/projmgr/include/ProjMgrWorker.h | 1 + tools/projmgr/include/ProjMgrYamlParser.h | 2 + tools/projmgr/schemas/common.schema.json | 21 ++++++++++ tools/projmgr/src/ProjMgrCbuildRun.cpp | 13 +++++++ tools/projmgr/src/ProjMgrWorker.cpp | 11 ++++++ tools/projmgr/src/ProjMgrYamlParser.cpp | 14 ++++++- .../test/data/TestRunDebug/trace.cproject.yml | 4 ++ .../data/TestRunDebug/trace.csolution.yml | 26 +++++++++++++ tools/projmgr/test/src/ProjMgrUnitTests.cpp | 39 +++++++++++++++++++ 10 files changed, 136 insertions(+), 1 deletion(-) create mode 100644 tools/projmgr/test/data/TestRunDebug/trace.cproject.yml create mode 100644 tools/projmgr/test/data/TestRunDebug/trace.csolution.yml diff --git a/tools/projmgr/include/ProjMgrParser.h b/tools/projmgr/include/ProjMgrParser.h index 58450d398..fda796d03 100644 --- a/tools/projmgr/include/ProjMgrParser.h +++ b/tools/projmgr/include/ProjMgrParser.h @@ -182,6 +182,11 @@ struct CustomItem { std::vector> map; }; +struct TraceItem { + std::string file; + CustomItem custom; +}; + /** * @brief debugger item containing * name of debug configuration @@ -202,6 +207,7 @@ struct DebuggerItem { std::map deviceSettings; std::string startPname; std::vector telnet; + std::vector trace; SystemViewItem systemView; CustomItem custom; }; diff --git a/tools/projmgr/include/ProjMgrWorker.h b/tools/projmgr/include/ProjMgrWorker.h index dc0cd4fcc..d7da96cdb 100644 --- a/tools/projmgr/include/ProjMgrWorker.h +++ b/tools/projmgr/include/ProjMgrWorker.h @@ -403,6 +403,7 @@ struct DebuggerType { std::string startPname; std::vector gdbserver; std::map telnet; + std::vector trace; SystemViewItem systemView; CustomItem custom; }; diff --git a/tools/projmgr/include/ProjMgrYamlParser.h b/tools/projmgr/include/ProjMgrYamlParser.h index 6c2c2d54f..718fd574d 100644 --- a/tools/projmgr/include/ProjMgrYamlParser.h +++ b/tools/projmgr/include/ProjMgrYamlParser.h @@ -276,6 +276,7 @@ static constexpr const char* YAML_TARGETTYPE = "target-type"; static constexpr const char* YAML_TARGETTYPES = "target-types"; static constexpr const char* YAML_TEMPLATE = "template"; static constexpr const char* YAML_TELNET = "telnet"; +static constexpr const char* YAML_TRACE = "trace"; static constexpr const char* YAML_TRACE_SINKS = "trace-sinks"; static constexpr const char* YAML_TRACEBUFFER = "tracebuffer"; static constexpr const char* YAML_SERIALWIRE = "serialwire"; @@ -411,6 +412,7 @@ class ProjMgrYamlParser { void ParseRte(const YAML::Node& parent, std::string& rteBaseDir); void ParseDebugDefaults(const YAML::Node& parent, const std::string& file, DebugAdapterDefaultsItem& defaults); void ParseTelnet(const YAML::Node& parent, const std::string& file, std::vector& telnet); + void ParseTrace(const YAML::Node& parent, const std::string& file, std::vector& trace); void ParseSystemView(const YAML::Node& parent, const std::string& file, SystemViewItem& systemView); void ParseCustom(const YAML::Node& parent, const std::vector& skip, CustomItem& custom); bool GetTypes(const std::string& type, std::string& buildType, std::string& targetType, std::string& pattern); diff --git a/tools/projmgr/schemas/common.schema.json b/tools/projmgr/schemas/common.schema.json index 23db577fe..f9da9e9b8 100644 --- a/tools/projmgr/schemas/common.schema.json +++ b/tools/projmgr/schemas/common.schema.json @@ -2317,12 +2317,32 @@ "gdbserver": { "$ref": "#/definitions/GdbServersType" }, "telnet": { "$ref": "#/definitions/TelnetOptionsType" }, "rtt": { "$ref": "#/definitions/RttOptionsType" }, + "trace": { "$ref": "#/definitions/TraceOptionsType" }, "systemview": { "$ref": "#/definitions/SystemViewOptionType" }, "device-settings": { "$ref": "#/definitions/DeviceSettingsType" } }, "additionalProperties": true, "required": ["name"] }, + "TraceOptionsType": { + "title": "trace:\nDocumentation: https://open-cmsis-pack.github.io/cmsis-toolbox/pyOCD-Debugger/#trace", + "description": "Configuration for trace transports.", + "type": "array", + "items": { "$ref": "#/definitions/TraceOptionType" } + }, + "TraceOptionType": { + "type": "object", + "properties": { + "swo-uart": { "type": "null", "description": "Selects SWO trace output in UART mode." }, + "trace-buffer": { "type": ["string", "null"], "description": "Selects an on-device trace buffer by name. The name may be omitted for a single unnamed trace buffer." }, + "mode": { "anyOf": [{ "enum": [ "off", "server", "file" ] }, { "type": "string" }], "description": "Trace output mode. Default: off." }, + "server-port": { "type": "integer", "minimum": 1, "maximum": 65535, "description": "TCP port for trace output in server mode. Default: 5555." }, + "file": { "type": "string", "description": "Path to the raw trace output file in file mode." }, + "input-clock": { "type": "number", "exclusiveMinimum": 0, "description": "Trace input clock frequency in Hz." }, + "output-clock": { "type": "number", "minimum": 0, "description": "SWO output clock frequency in Hz. Omitted or zero selects an automatically calculated frequency." } + }, + "additionalProperties": true + }, "DeviceSettingsType": { "title": "device-settings:\nDocumentation: https://open-cmsis-pack.github.io/cmsis-toolbox/pyOCD-Debugger/#device-settings", "description": "Debugger device settings.", @@ -2640,6 +2660,7 @@ "start-pname": { "type": "string", "description": "Debugger connects at start to this processor." }, "telnet": { "$ref": "#/definitions/TelnetOptionsType" }, "rtt": { "$ref": "#/definitions/RttOptionsType" }, + "trace": { "$ref": "#/definitions/TraceOptionsType" }, "systemview": { "$ref": "#/definitions/SystemViewOptionType" }, "device-settings": { "$ref": "#/definitions/DeviceSettingsType" } }, diff --git a/tools/projmgr/src/ProjMgrCbuildRun.cpp b/tools/projmgr/src/ProjMgrCbuildRun.cpp index 6138b2fb6..14601e684 100644 --- a/tools/projmgr/src/ProjMgrCbuildRun.cpp +++ b/tools/projmgr/src/ProjMgrCbuildRun.cpp @@ -37,6 +37,7 @@ class ProjMgrCbuildRun : public ProjMgrCbuildBase { void SetDatapatchNode(YAML::Node node, const std::vector& datapatch); void SetGdbServerNode(YAML::Node node, const std::vector& gdbserver); void SetTelnetNode(YAML::Node node, const std::map& telnet); + void SetTraceNode(YAML::Node node, const std::vector& trace); void SetSystemViewNode(YAML::Node node, const SystemViewItem& systemView); }; @@ -189,6 +190,7 @@ void ProjMgrCbuildRun::SetDebuggerNode(YAML::Node node, const DebuggerType& debu SetNodeValue(node[YAML_START_PNAME], debugger.startPname); SetGdbServerNode(node[YAML_GDBSERVER], debugger.gdbserver); SetTelnetNode(node[YAML_TELNET], debugger.telnet); + SetTraceNode(node[YAML_TRACE], debugger.trace); SetSystemViewNode(node[YAML_SYSTEMVIEW], debugger.systemView); SetDeviceSettingsNode(node[YAML_DEVICE_SETTINGS], debugger.deviceSettings); SetCustomNodes(node, debugger.custom); @@ -223,6 +225,17 @@ void ProjMgrCbuildRun::SetTelnetNode(YAML::Node node, const std::map& trace) { + for (const auto& item : trace) { + YAML::Node traceNode(YAML::NodeType::Map); + SetCustomNodes(traceNode, item.custom); + if (!item.file.empty()) { + SetNodeValue(traceNode[YAML_FILE], FormatPath(item.file, m_directory)); + } + node.push_back(traceNode); + } +} + void ProjMgrCbuildRun::SetSystemViewNode(YAML::Node node, const SystemViewItem& systemView) { if (!systemView.file.empty()) { SetNodeValue(node[YAML_FILE], FormatPath(systemView.file, m_directory)); diff --git a/tools/projmgr/src/ProjMgrWorker.cpp b/tools/projmgr/src/ProjMgrWorker.cpp index b4a8cff6b..b5c0bbf08 100644 --- a/tools/projmgr/src/ProjMgrWorker.cpp +++ b/tools/projmgr/src/ProjMgrWorker.cpp @@ -2779,6 +2779,17 @@ bool ProjMgrWorker::ProcessDebuggers(ContextItem& context) { } context.debugger.telnet[telnet.pname] = { telnet }; } + for (auto trace : m_activeTargetSet.debugger.trace) { + if (!trace.file.empty()) { + if (!ProcessSequenceRelative(context, trace.file, context.csolution->directory, false)) { + return false; + } + if (RteFsUtils::IsRelative(trace.file)) { + RteFsUtils::NormalizePath(trace.file, context.directories.cprj); + } + } + context.debugger.trace.push_back(trace); + } auto systemView = m_activeTargetSet.debugger.systemView; if (!systemView.file.empty()) { if (!ProcessSequenceRelative(context, systemView.file, context.csolution->directory, false)) { diff --git a/tools/projmgr/src/ProjMgrYamlParser.cpp b/tools/projmgr/src/ProjMgrYamlParser.cpp index 086305055..7edd75086 100644 --- a/tools/projmgr/src/ProjMgrYamlParser.cpp +++ b/tools/projmgr/src/ProjMgrYamlParser.cpp @@ -646,6 +646,17 @@ void ProjMgrYamlParser::ParseTelnet(const YAML::Node& parent, const std::string& } } +void ProjMgrYamlParser::ParseTrace(const YAML::Node& parent, const std::string& file, std::vector& trace) { + if (parent[YAML_TRACE].IsDefined()) { + for (const auto& traceEntry : parent[YAML_TRACE]) { + TraceItem traceItem; + ParseString(traceEntry, YAML_FILE, traceItem.file); + ParseCustom(traceEntry, { YAML_FILE }, traceItem.custom); + trace.push_back(traceItem); + } + } +} + void ProjMgrYamlParser::ParseSystemView(const YAML::Node& parent, const std::string& file, SystemViewItem& systemView) { if (parent[YAML_SYSTEMVIEW].IsDefined()) { const YAML::Node& systemViewNode = parent[YAML_SYSTEMVIEW]; @@ -669,8 +680,9 @@ void ProjMgrYamlParser::ParseDebugger(const YAML::Node& parent, const string& fi ParseMapOfStrings(debuggerNode, YAML_DEVICE_SETTINGS, debugger.deviceSettings); ParseString(debuggerNode, YAML_START_PNAME, debugger.startPname); ParseTelnet(debuggerNode, file, debugger.telnet); + ParseTrace(debuggerNode, file, debugger.trace); ParseSystemView(debuggerNode, file, debugger.systemView); - ParseCustom(debuggerNode, { YAML_NAME, YAML_PROTOCOL, YAML_CLOCK, YAML_DBGCONF, YAML_DEVICE_SETTINGS, YAML_START_PNAME, YAML_TELNET, YAML_SYSTEMVIEW }, debugger.custom); + ParseCustom(debuggerNode, { YAML_NAME, YAML_PROTOCOL, YAML_CLOCK, YAML_DBGCONF, YAML_DEVICE_SETTINGS, YAML_START_PNAME, YAML_TELNET, YAML_TRACE, YAML_SYSTEMVIEW }, debugger.custom); } } diff --git a/tools/projmgr/test/data/TestRunDebug/trace.cproject.yml b/tools/projmgr/test/data/TestRunDebug/trace.cproject.yml new file mode 100644 index 000000000..cf6750937 --- /dev/null +++ b/tools/projmgr/test/data/TestRunDebug/trace.cproject.yml @@ -0,0 +1,4 @@ +project: + components: + - component: Startup + - component: CORE diff --git a/tools/projmgr/test/data/TestRunDebug/trace.csolution.yml b/tools/projmgr/test/data/TestRunDebug/trace.csolution.yml new file mode 100644 index 000000000..49535ed33 --- /dev/null +++ b/tools/projmgr/test/data/TestRunDebug/trace.csolution.yml @@ -0,0 +1,26 @@ +solution: + compiler: AC6 + packs: + - pack: ARM::RteTest_DFP + target-types: + - type: SingleCore + device: RteTest_ARMCM0 + target-set: + - set: + debugger: + name: CMSIS-DAP + trace: + - swo-uart: + input-clock: 120000000 + mode: file + file: $OutDir(trace)$/trace.SWO.raw + - trace-buffer: MTB + mode: file + file: captures/trace.TB_MTB.raw + - trace-buffer: + mode: server + server-port: 5555 + images: + - project-context: trace + projects: + - project: trace.cproject.yml diff --git a/tools/projmgr/test/src/ProjMgrUnitTests.cpp b/tools/projmgr/test/src/ProjMgrUnitTests.cpp index c78fd6179..1049942a4 100644 --- a/tools/projmgr/test/src/ProjMgrUnitTests.cpp +++ b/tools/projmgr/test/src/ProjMgrUnitTests.cpp @@ -7359,6 +7359,45 @@ TEST_F(ProjMgrUnitTests, TestRunDebugMulticore) { testinput_folder + "/TestRunDebug/ref/run-debug+TestHW3.cbuild-run.yml"); } +TEST_F(ProjMgrUnitTests, TestRunDebugTrace) { + const string csolution = testinput_folder + "/TestRunDebug/trace.csolution.yml"; + ASSERT_TRUE(RteFsUtils::Exists(csolution)) << "Missing test fixture: " << csolution; + const string cproject = testinput_folder + "/TestRunDebug/trace.cproject.yml"; + ASSERT_TRUE(RteFsUtils::Exists(cproject)) << "Missing test fixture: " << cproject; + for (const auto& output : { testinput_folder + "/TestRunDebug", testoutput_folder }) { + StdStreamRedirect streamRedirect; + char* argv[7] = { nullptr, (char*)"convert", (char*)csolution.c_str(), + (char*)"--active", (char*)"SingleCore", (char*)"--output", (char*)output.c_str() }; + const auto result = RunProjMgr(7, argv, m_envp); + ASSERT_EQ(0, result) << streamRedirect.GetErrorString(); + const auto cbuildrun = YAML::LoadFile(output + "/out/trace+SingleCore.cbuild-run.yml"); + const auto trace = cbuildrun["cbuild-run"]["debugger"]["trace"]; + ASSERT_EQ(3, trace.size()); + EXPECT_EQ("trace/SingleCore/trace.SWO.raw", trace[0]["file"].as()); + EXPECT_TRUE(trace[0]["swo-uart"].IsNull()); + EXPECT_EQ(120000000, trace[0]["input-clock"].as()); + EXPECT_EQ(RteFsUtils::RelativePath(testinput_folder + "/TestRunDebug/captures/trace.TB_MTB.raw", + output + "/out"), trace[1]["file"].as()); + EXPECT_EQ("MTB", trace[1]["trace-buffer"].as()); + EXPECT_FALSE(trace[2]["file"].IsDefined()); + EXPECT_TRUE(trace[2]["trace-buffer"].IsNull()); + EXPECT_EQ(5555, trace[2]["server-port"].as()); + } + + const string invalidSolution = testinput_folder + "/TestRunDebug/trace-invalid.csolution.yml"; + auto root = YAML::LoadFile(csolution); + root["solution"]["target-types"][0]["target-set"][0]["debugger"]["trace"][0]["file"] = "$Unknown$/trace.raw"; + std::stringstream content; + content << root; + ASSERT_TRUE(RteFsUtils::CreateTextFile(invalidSolution, content.str())); + StdStreamRedirect streamRedirect; + char* argv[5] = { nullptr, (char*)"convert", (char*)invalidSolution.c_str(), + (char*)"--active", (char*)"SingleCore" }; + EXPECT_EQ(1, RunProjMgr(5, argv, m_envp)); + EXPECT_NE(string::npos, streamRedirect.GetErrorString().find("unknown access sequence: 'Unknown'")); + EXPECT_TRUE(RteFsUtils::RemoveFile(invalidSolution)); +} + TEST_F(ProjMgrUnitTests, TestRunDebugTelnet) { char* argv[5]; const string& csolution = testinput_folder + "/TestRunDebug/telnet.csolution.yml"; From 310789508790ff6bbcc1b7d63fd784baa1b17246 Mon Sep 17 00:00:00 2001 From: Daniel Brondani Date: Wed, 11 Nov 2026 13:36:35 +0100 Subject: [PATCH 2/2] Address review findings --- tools/projmgr/src/ProjMgrRunDebug.cpp | 8 ++++++++ tools/projmgr/test/src/ProjMgrUnitTests.cpp | 22 ++++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/tools/projmgr/src/ProjMgrRunDebug.cpp b/tools/projmgr/src/ProjMgrRunDebug.cpp index ba2f3f7e5..e3d3f88cd 100644 --- a/tools/projmgr/src/ProjMgrRunDebug.cpp +++ b/tools/projmgr/src/ProjMgrRunDebug.cpp @@ -8,8 +8,10 @@ #include "ProjMgrWorker.h" #include "ProjMgrLogger.h" #include "ProjMgrYamlEmitter.h" +#include "ProjMgrYamlParser.h" #include "RteFsUtils.h" +#include #include using namespace std; @@ -477,6 +479,12 @@ void ProjMgrRunDebug::CollectDebuggerSettings(const ContextItem& context, const // merge custom options ProjMgrUtils::MergeCustomItems(context.debugger.custom, m_runDebug.debugger.custom); + if (!context.debugger.trace.empty()) { + auto& custom = m_runDebug.debugger.custom.map; + custom.erase(remove_if(custom.begin(), custom.end(), [](const auto& item) { + return item.first == YAML_TRACE; + }), custom.end()); + } } void ProjMgrRunDebug::CollectTelnetOptions(const ContextItem& context, DebugAdapterItem& adapter, diff --git a/tools/projmgr/test/src/ProjMgrUnitTests.cpp b/tools/projmgr/test/src/ProjMgrUnitTests.cpp index 1049942a4..199f98188 100644 --- a/tools/projmgr/test/src/ProjMgrUnitTests.cpp +++ b/tools/projmgr/test/src/ProjMgrUnitTests.cpp @@ -7364,11 +7364,31 @@ TEST_F(ProjMgrUnitTests, TestRunDebugTrace) { ASSERT_TRUE(RteFsUtils::Exists(csolution)) << "Missing test fixture: " << csolution; const string cproject = testinput_folder + "/TestRunDebug/trace.cproject.yml"; ASSERT_TRUE(RteFsUtils::Exists(cproject)) << "Missing test fixture: " << cproject; + const string debugAdaptersPath = etc_folder + "/debug-adapters.yml"; + auto debugAdapters = YAML::LoadFile(debugAdaptersPath); + bool adapterFound = false; + for (auto adapter : debugAdapters["debug-adapters"]) { + if (adapter["name"].as() == "CMSIS-DAP@pyOCD") { + adapter["defaults"]["trace"][0]["trace-buffer"] = "adapter-default"; + adapterFound = true; + } + } + ASSERT_TRUE(adapterFound); + stringstream adapterContent; + adapterContent << debugAdapters; for (const auto& output : { testinput_folder + "/TestRunDebug", testoutput_folder }) { + const string backup = RteFsUtils::BackupFile(debugAdaptersPath); + ASSERT_FALSE(backup.empty()); + const bool written = RteFsUtils::CreateTextFile(debugAdaptersPath, adapterContent.str()); StdStreamRedirect streamRedirect; char* argv[7] = { nullptr, (char*)"convert", (char*)csolution.c_str(), (char*)"--active", (char*)"SingleCore", (char*)"--output", (char*)output.c_str() }; - const auto result = RunProjMgr(7, argv, m_envp); + const auto result = written ? RunProjMgr(7, argv, m_envp) : -1; + error_code ec; + fs::copy_file(backup, debugAdaptersPath, fs::copy_options::overwrite_existing, ec); + ASSERT_FALSE(ec) << ec.message(); + EXPECT_TRUE(RteFsUtils::RemoveFile(backup)); + ASSERT_TRUE(written); ASSERT_EQ(0, result) << streamRedirect.GetErrorString(); const auto cbuildrun = YAML::LoadFile(output + "/out/trace+SingleCore.cbuild-run.yml"); const auto trace = cbuildrun["cbuild-run"]["debugger"]["trace"];