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
2 changes: 2 additions & 0 deletions tools/projmgr/include/ProjMgrParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ struct CustomItem {
* debug protocol (jtag or swd)
* debug clock speed
* debug configuration file
* device settings
* start pname
* telnet options
* systemview options
Expand All @@ -183,6 +184,7 @@ struct DebuggerItem {
std::string protocol;
std::string clock;
std::string dbgconf;
std::map<std::string, std::string> deviceSettings;
std::string startPname;
std::vector<TelnetItem> telnet;
SystemViewItem systemView;
Expand Down
7 changes: 7 additions & 0 deletions tools/projmgr/include/ProjMgrUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,13 @@ class ProjMgrUtils {
*/
static const std::string FormatPath(const std::string& original, const std::string& directory, bool useAbsolutePaths = false);

/**
* @brief parse variable assignments from a dbgconf file
* @param dbgconf path to dbgconf file
* @return map of variable names to assigned values
*/
static std::map<std::string, std::string> ParseDbgconfFile(const std::string& dbgconf);

/**
* @brief adjust relative path fragments in a list of values
* @param vec list of strings that may contain relative paths
Expand Down
2 changes: 2 additions & 0 deletions tools/projmgr/include/ProjMgrWorker.h
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ struct TemplateItem {
* debug protocol (jtag or swd)
* debug clock speed
* debug configuration file
* device settings
* start pname
* list of gdbserver items
* list of telnet options items
Expand All @@ -397,6 +398,7 @@ struct DebuggerType {
std::string protocol;
std::optional<unsigned long long> clock;
std::string dbgconf;
std::map<std::string, std::string> deviceSettings;
std::string startPname;
std::vector<GdbServerItem> gdbserver;
std::map<std::string, TelnetOptionsItem> telnet;
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 @@ -98,6 +98,7 @@ static constexpr const char* YAML_DEBUG_TOPOLOGY = "debug-topology";
static constexpr const char* YAML_DEBUGGER = "debugger";
static constexpr const char* YAML_DEBUGPORTS = "debugports";
static constexpr const char* YAML_DBGCONF = "dbgconf";
static constexpr const char* YAML_DEVICE_SETTINGS = "device-settings";
static constexpr const char* YAML_DEFAULT = "default";
static constexpr const char* YAML_DEFAULTS = "defaults";
static constexpr const char* YAML_DEFINE = "define";
Expand Down Expand Up @@ -370,6 +371,7 @@ class ProjMgrYamlParser {
void ParseString(const YAML::Node& parent, const std::string& key, std::string& value);
void ParseNumber(const YAML::Node& parent, const std::string& file, const std::string& key, std::string& value);
void ParseInt(const YAML::Node& parent, const std::string& key, int& value);
void ParseMapOfStrings(const YAML::Node& parent, const std::string& key, std::map<std::string, std::string>& value);
void ParseVector(const YAML::Node& parent, const std::string& key, std::vector<std::string>& value);
void ParseVectorOfStringPairs(const YAML::Node& parent, const std::string& key, std::vector<std::pair<std::string, std::string>>& value);
void ParseVectorOrString(const YAML::Node& parent, const std::string& key, std::vector<std::string>& value);
Expand Down
12 changes: 10 additions & 2 deletions tools/projmgr/schemas/common.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2292,11 +2292,18 @@
"gdbserver": { "$ref": "#/definitions/GdbServersType" },
"telnet": { "$ref": "#/definitions/TelnetOptionsType" },
"rtt": { "$ref": "#/definitions/RttOptionsType" },
"systemview": { "$ref": "#/definitions/SystemViewOptionType" }
"systemview": { "$ref": "#/definitions/SystemViewOptionType" },
"device-settings": { "$ref": "#/definitions/DeviceSettingsType" }
},
"additionalProperties": true,
"required": ["name"]
},
"DeviceSettingsType": {
"title": "device-settings:\nDocumentation: https://open-cmsis-pack.github.io/cmsis-toolbox/pyOCD-Debugger/#device-settings",
"description": "Debugger device settings.",
"type": "object",
"additionalProperties": { "type": [ "string", "number", "boolean" ] }
},
"RttOptionsType": {
"title": "rtt:\nDocumentation: https://open-cmsis-pack.github.io/cmsis-toolbox/pyOCD-Debugger/#rtt",
"description": "Configuration for RTT features.",
Expand Down Expand Up @@ -2586,7 +2593,8 @@
"start-pname": { "type": "string", "description": "Debugger connects at start to this processor." },
"telnet": { "$ref": "#/definitions/TelnetOptionsType" },
"rtt": { "$ref": "#/definitions/RttOptionsType" },
"systemview": { "$ref": "#/definitions/SystemViewOptionType" }
"systemview": { "$ref": "#/definitions/SystemViewOptionType" },
"device-settings": { "$ref": "#/definitions/DeviceSettingsType" }
},
"additionalProperties": true,
"required": ["name"]
Expand Down
8 changes: 8 additions & 0 deletions tools/projmgr/src/ProjMgrCbuildRun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class ProjMgrCbuildRun : public ProjMgrCbuildBase {
void SetFilesNode(YAML::Node node, const std::vector<FilesType>& outputs);
void SetResourcesNode(YAML::Node node, const SystemResourcesType& systemResources);
void SetDebuggerNode(YAML::Node node, const DebuggerType& debugger);
void SetDeviceSettingsNode(YAML::Node node, const std::map<std::string, std::string>& deviceSettings);
void SetDebugVarsNode(YAML::Node node, const DebugVarsType& debugVars);
void SetDebugSequencesNode(YAML::Node node, const std::vector<DebugSequencesType>& algorithms);
void SetDebugSequencesBlockNode(YAML::Node node, const std::vector<DebugSequencesBlockType>& blocks);
Expand Down Expand Up @@ -187,10 +188,17 @@ void ProjMgrCbuildRun::SetDebuggerNode(YAML::Node node, const DebuggerType& debu
SetGdbServerNode(node[YAML_GDBSERVER], debugger.gdbserver);
SetTelnetNode(node[YAML_TELNET], debugger.telnet);
SetSystemViewNode(node[YAML_SYSTEMVIEW], debugger.systemView);
SetDeviceSettingsNode(node[YAML_DEVICE_SETTINGS], debugger.deviceSettings);
SetCustomNodes(node, debugger.custom);
}
}

void ProjMgrCbuildRun::SetDeviceSettingsNode(YAML::Node node, const map<string, string>& deviceSettings) {
for (const auto& [key, value] : deviceSettings) {
node[key] = value;
}
}

YAML::Node ProjMgrCbuildRun::GetCustomNode(const CustomItem& value) {
YAML::Node node;
if (!value.scalar.empty()) {
Expand Down
9 changes: 8 additions & 1 deletion tools/projmgr/src/ProjMgrRunDebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,14 @@ void ProjMgrRunDebug::CollectDebuggerSettings(const ContextItem& context, const
m_runDebug.debugger = defaultDebugger;
}

// device-settings from dbgconf
if (m_runDebug.debugger.deviceSettings.empty() && !m_runDebug.debugger.dbgconf.empty()) {
m_runDebug.debugger.deviceSettings = ProjMgrUtils::ParseDbgconfFile(m_runDebug.debugger.dbgconf);
}
if (!m_runDebug.debugger.deviceSettings.empty()) {
m_runDebug.debugger.dbgconf.clear();
}

// primary processor: pname of first cproject
if (m_runDebug.debugger.startPname.empty()) {
m_runDebug.debugger.startPname = context.deviceItem.pname;
Expand Down Expand Up @@ -451,7 +459,6 @@ void ProjMgrRunDebug::CollectDebuggerSettings(const ContextItem& context, const

// merge custom options
MergeCustomItems(context.debugger.custom, m_runDebug.debugger.custom);

}

void ProjMgrRunDebug::CollectTelnetOptions(const ContextItem& context, DebugAdapterItem& adapter,
Expand Down
91 changes: 91 additions & 0 deletions tools/projmgr/src/ProjMgrUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "CrossPlatform.h"
#include "CrossPlatformUtils.h"

#include <cctype>
#include <regex>
#include <sstream>

Expand All @@ -22,6 +23,64 @@ static constexpr const char* HIGHER_OR_EQUAL_OPERATOR = ">=";
static constexpr const char* TILDE_OPERATOR = "~";
static constexpr const char* CARET_OPERATOR = "^";

// Dbgconf assignment names follow C-style identifier rules.
static bool IsDbgconfVariableName(const string& value) {
if (value.empty() || (!isalpha(static_cast<unsigned char>(value[0])) && value[0] != '_')) {
return false;
}
return all_of(value.begin() + 1, value.end(), [](unsigned char c) { return isalnum(c) || c == '_'; });
}

// Remove surrounding whitespace without changing the assignment value content.
static string Trim(const string& value) {
const auto first = find_if_not(value.begin(), value.end(), [](unsigned char c) { return isspace(c); });
const auto last = find_if_not(value.rbegin(), value.rend(), [](unsigned char c) { return isspace(c); }).base();
return first < last ? string(first, last) : string();
}

// Strip C and C++ comments while preserving line breaks that separate statements.
static string StripCComments(const string& input) {
Comment thread
edriouk marked this conversation as resolved.
string output;
bool inLineComment = false;
size_t blockCommentDepth = 0;
size_t index = 0;
while (index < input.length()) {
const char current = input[index];
const char next = index + 1 < input.length() ? input[index + 1] : '\0';

if (inLineComment) {
if (current == '\n' || current == '\r') {
inLineComment = false;
output += current;
}
++index;
} else if (blockCommentDepth > 0) {
if (current == '/' && next == '*') {
++blockCommentDepth;
index += 2;
} else if (current == '*' && next == '/') {
--blockCommentDepth;
index += 2;
} else {
if (current == '\n' || current == '\r') {
output += current;
}
++index;
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
}
} else if (current == '/' && next == '/') {
inLineComment = true;
index += 2;
} else if (current == '/' && next == '*') {
blockCommentDepth = 1;
index += 2;
} else {
output += current;
++index;
}
}
return output;
}

RtePackage* ProjMgrUtils::ReadGpdscFile(const string& gpdsc, bool& valid) {
fs::path path(gpdsc);
error_code ec;
Expand Down Expand Up @@ -439,6 +498,38 @@ const string ProjMgrUtils::FormatPath(const string& original, const string& dire
return path;
}

map<string, string> ProjMgrUtils::ParseDbgconfFile(const string& dbgconf) {
string content;
map<string, string> assignments;
if (!RteFsUtils::ReadFile(dbgconf, content)) {
return assignments;
}

const string contentWithoutComments = StripCComments(content);
// Split semicolon-separated statements, also accepting a final unterminated assignment.
size_t statementStart = 0;
size_t statementEnd = contentWithoutComments.find(';');
while (statementStart < contentWithoutComments.length()) {
const string statement = contentWithoutComments.substr(
statementStart,
statementEnd == string::npos ? string::npos : statementEnd - statementStart);
const size_t assignment = statement.find('=');
if (assignment != string::npos) {
const string key = Trim(statement.substr(0, assignment));
const string value = Trim(statement.substr(assignment + 1));
if (IsDbgconfVariableName(key)) {
assignments[key] = value;
}
}
if (statementEnd == string::npos) {
break;
}
statementStart = statementEnd + 1;
statementEnd = contentWithoutComments.find(';', statementStart);
}
return assignments;
}

bool ProjMgrUtils::ContainsIncompatiblePack(const std::list<RtePackage*>& packs, const std::string& requirement) {
bool incompatible = false;
for (const auto& p : packs) {
Expand Down
1 change: 1 addition & 0 deletions tools/projmgr/src/ProjMgrWorker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2740,6 +2740,7 @@ bool ProjMgrWorker::ProcessDebuggers(ContextItem& context) {
}
}
context.debugger.startPname = m_activeTargetSet.debugger.startPname;
context.debugger.deviceSettings = m_activeTargetSet.debugger.deviceSettings;
for (auto telnet : m_activeTargetSet.debugger.telnet) {
if (!telnet.file.empty()) {
if (!ProcessSequenceRelative(context, telnet.file, context.csolution->directory, false)) {
Expand Down
11 changes: 10 additions & 1 deletion tools/projmgr/src/ProjMgrYamlParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,14 @@ void ProjMgrYamlParser::ParseInt(const YAML::Node& parent, const string& key, in
}
}

void ProjMgrYamlParser::ParseMapOfStrings(const YAML::Node& parent, const string& key, map<string, string>& value) {
if (parent[key].IsDefined() && parent[key].IsMap()) {
for (const auto& item : parent[key]) {
value[item.first.as<string>()] = YAML::IsNullString(item.second.as<string>()) ? "" : item.second.as<string>();
}
}
}

void ProjMgrYamlParser::ParseVector(const YAML::Node& parent, const string& key, vector<string>& value) {
if (parent[key].IsDefined() && parent[key].IsSequence()) {
value = parent[key].as<vector<string>>();
Expand Down Expand Up @@ -637,10 +645,11 @@ void ProjMgrYamlParser::ParseDebugger(const YAML::Node& parent, const string& fi
ParseString(debuggerNode, YAML_PROTOCOL, debugger.protocol);
ParseNumber(debuggerNode, file, YAML_CLOCK, debugger.clock);
ParsePortablePath(debuggerNode, file, YAML_DBGCONF, debugger.dbgconf);
ParseMapOfStrings(debuggerNode, YAML_DEVICE_SETTINGS, debugger.deviceSettings);
ParseString(debuggerNode, YAML_START_PNAME, debugger.startPname);
ParseTelnet(debuggerNode, file, debugger.telnet);
ParseSystemView(debuggerNode, file, debugger.systemView);
ParseCustom(debuggerNode, { YAML_NAME, YAML_PROTOCOL, YAML_CLOCK, YAML_DBGCONF, 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_SYSTEMVIEW }, debugger.custom);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,13 @@ cbuild-run:
name: CMSIS-DAP@pyOCD
protocol: swd
clock: 10000000
dbgconf: ../.cmsis/image-only+CM0.dbgconf
gdbserver:
- port: 3333
device-settings:
ReleaseM0OnConnect: 1
ReleaseM0SubOnConnect: 1
RoutingTPIU: 0x00000000
VecResetWithPeriph: 1
debug-vars:
vars: |
__var DbgMCU_CR = 0x00000007; // DBGMCU_CR: DBG_SLEEP, DBG_STOP, DBG_STANDBY
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,17 @@ cbuild-run:
name: CMSIS-DAP@pyOCD
protocol: swd
clock: 10000000
dbgconf: ../.cmsis/image-only-multicore+CM0.dbgconf
gdbserver:
- port: 3333
- port: 3334
pname: cm0_core0
- port: 3335
pname: cm0_core1
device-settings:
ReleaseM0OnConnect: 1
ReleaseM0SubOnConnect: 1
RoutingTPIU: 0x00000000
VecResetWithPeriph: 1
debug-vars:
vars: |
__var DbgMCU_CR = 0x00000007; // DBGMCU_CR: DBG_SLEEP, DBG_STOP, DBG_STANDBY
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ cbuild-run:
name: Test Custom Adapter
protocol: jtag
clock: 40000000
dbgconf: ../../data/TestRunDebug/.cmsis/custom+TestHW.dbgconf
device-settings:
ReleaseM0OnConnect: 1
ReleaseM0SubOnConnect: 1
RoutingTPIU: 0x00000000
VecResetWithPeriph: 1
custom-adapter-key: custom adapter value
custom-key-overwrite: custom value overwrite
custom-map:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,11 @@ cbuild-run:
info: Info target-set
protocol: jtag
clock: 20000000
dbgconf: ../../data/TestRunDebug/RTE/Device/RteTest1/RteTest1.dbgconf
gdbserver:
- port: 3333
device-settings:
reset-mode: hardware
trace-port: enabled
debug-vars:
vars: |
__var DbgMCU_CR = 0x00000007; // DBGMCU_CR: DBG_SLEEP, DBG_STOP, DBG_STANDBY
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,17 @@ cbuild-run:
name: CMSIS-DAP@pyOCD
protocol: swd
clock: 10000000
dbgconf: ../../data/TestRunDebug/.cmsis/run-debug+TestHW3.dbgconf
start-pname: cm0_core1
gdbserver:
- port: 3333
pname: cm0_core1
- port: 3334
pname: cm0_core0
device-settings:
ReleaseM0OnConnect: 1
ReleaseM0SubOnConnect: 1
RoutingTPIU: 0x00000000
VecResetWithPeriph: 1
debug-vars:
vars: |
__var DbgMCU_CR = 0x00000007; // DBGMCU_CR: DBG_SLEEP, DBG_STOP, DBG_STANDBY
Expand Down
3 changes: 3 additions & 0 deletions tools/projmgr/test/data/TestRunDebug/run-debug.csolution.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ solution:
protocol: jtag
clock: 20000000
dbgconf: RTE/Device/RteTest1/RteTest1.dbgconf
device-settings:
reset-mode: hardware
trace-port: enabled
images:
- project-context: run-debug
load: none
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,17 @@ cbuild-run:
name: CMSIS-DAP@pyOCD
protocol: swd
clock: 10000000
dbgconf: ../.cmsis/solution+CM0.dbgconf
start-pname: cm0_core0
gdbserver:
- port: 3333
pname: cm0_core0
- port: 3334
pname: cm0_core1
device-settings:
ReleaseM0OnConnect: 1
ReleaseM0SubOnConnect: 1
RoutingTPIU: 0x00000000
VecResetWithPeriph: 1
debug-vars:
vars: |
__var DbgMCU_CR = 0x00000007; // DBGMCU_CR: DBG_SLEEP, DBG_STOP, DBG_STANDBY
Expand Down
Loading
Loading