Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions tools/projmgr/include/ProjMgrParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@ struct CustomItem {
std::vector<std::pair<std::string, CustomItem>> map;
};

struct TraceItem {
std::string file;
CustomItem custom;
};

/**
* @brief debugger item containing
* name of debug configuration
Expand All @@ -202,6 +207,7 @@ struct DebuggerItem {
std::map<std::string, std::string> deviceSettings;
std::string startPname;
std::vector<TelnetItem> telnet;
std::vector<TraceItem> trace;
SystemViewItem systemView;
CustomItem custom;
};
Expand Down
1 change: 1 addition & 0 deletions tools/projmgr/include/ProjMgrWorker.h
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ struct DebuggerType {
std::string startPname;
std::vector<GdbServerItem> gdbserver;
std::map<std::string, TelnetOptionsItem> telnet;
std::vector<TraceItem> trace;
SystemViewItem systemView;
CustomItem custom;
};
Expand Down
2 changes: 2 additions & 0 deletions tools/projmgr/include/ProjMgrYamlParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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<TelnetItem>& telnet);
void ParseTrace(const YAML::Node& parent, const std::string& file, std::vector<TraceItem>& trace);
void ParseSystemView(const YAML::Node& parent, const std::string& file, SystemViewItem& systemView);
void ParseCustom(const YAML::Node& parent, const std::vector<std::string>& skip, CustomItem& custom);
bool GetTypes(const std::string& type, std::string& buildType, std::string& targetType, std::string& pattern);
Expand Down
21 changes: 21 additions & 0 deletions tools/projmgr/schemas/common.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down Expand Up @@ -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" }
},
Expand Down
13 changes: 13 additions & 0 deletions tools/projmgr/src/ProjMgrCbuildRun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class ProjMgrCbuildRun : public ProjMgrCbuildBase {
void SetDatapatchNode(YAML::Node node, const std::vector<DatapatchType>& datapatch);
void SetGdbServerNode(YAML::Node node, const std::vector<GdbServerItem>& gdbserver);
void SetTelnetNode(YAML::Node node, const std::map<std::string, TelnetOptionsItem>& telnet);
void SetTraceNode(YAML::Node node, const std::vector<TraceItem>& trace);
void SetSystemViewNode(YAML::Node node, const SystemViewItem& systemView);
};

Expand Down Expand Up @@ -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);
Comment thread
brondani marked this conversation as resolved.
Resolved
SetSystemViewNode(node[YAML_SYSTEMVIEW], debugger.systemView);
SetDeviceSettingsNode(node[YAML_DEVICE_SETTINGS], debugger.deviceSettings);
SetCustomNodes(node, debugger.custom);
Expand Down Expand Up @@ -223,6 +225,17 @@ void ProjMgrCbuildRun::SetTelnetNode(YAML::Node node, const std::map<std::string
}
}

void ProjMgrCbuildRun::SetTraceNode(YAML::Node node, const std::vector<TraceItem>& 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));
Expand Down
8 changes: 8 additions & 0 deletions tools/projmgr/src/ProjMgrRunDebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
#include "ProjMgrWorker.h"
#include "ProjMgrLogger.h"
#include "ProjMgrYamlEmitter.h"
#include "ProjMgrYamlParser.h"
#include "RteFsUtils.h"

#include <algorithm>
#include <regex>

using namespace std;
Expand Down Expand Up @@ -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,
Expand Down
11 changes: 11 additions & 0 deletions tools/projmgr/src/ProjMgrWorker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
14 changes: 13 additions & 1 deletion tools/projmgr/src/ProjMgrYamlParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<TraceItem>& 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];
Expand All @@ -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);
}
}

Expand Down
4 changes: 4 additions & 0 deletions tools/projmgr/test/data/TestRunDebug/trace.cproject.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
project:
components:
- component: Startup
- component: CORE
26 changes: 26 additions & 0 deletions tools/projmgr/test/data/TestRunDebug/trace.csolution.yml
Original file line number Diff line number Diff line change
@@ -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
59 changes: 59 additions & 0 deletions tools/projmgr/test/src/ProjMgrUnitTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7359,6 +7359,65 @@ 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;
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<string>() == "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 = 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"];
ASSERT_EQ(3, trace.size());
EXPECT_EQ("trace/SingleCore/trace.SWO.raw", trace[0]["file"].as<string>());
EXPECT_TRUE(trace[0]["swo-uart"].IsNull());
EXPECT_EQ(120000000, trace[0]["input-clock"].as<unsigned long long>());
EXPECT_EQ(RteFsUtils::RelativePath(testinput_folder + "/TestRunDebug/captures/trace.TB_MTB.raw",
output + "/out"), trace[1]["file"].as<string>());
EXPECT_EQ("MTB", trace[1]["trace-buffer"].as<string>());
EXPECT_FALSE(trace[2]["file"].IsDefined());
EXPECT_TRUE(trace[2]["trace-buffer"].IsNull());
EXPECT_EQ(5555, trace[2]["server-port"].as<unsigned>());
}

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";
Expand Down
Loading