Skip to content

Commit fd5df25

Browse files
authored
[projmgr] Implement debug-adapters.yml handling
1 parent 2114cf7 commit fd5df25

21 files changed

+352
-35
lines changed

tools/projmgr/include/ProjMgr.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,14 @@ class ProjMgr {
122122
* @brief get cmsis-toolbox version from manifest file
123123
* @return version as string
124124
*/
125-
std::string GetToolboxVersion(const std::string& manifestFilePath);
125+
const std::string GetToolboxVersion(const std::string& manifestFilePath);
126+
127+
/**
128+
* @brief get debug adapters file path
129+
* @return file path or empty string if it does not exist
130+
*/
131+
const std::string GetDebugAdaptersFile(void);
132+
126133
protected:
127134
ProjMgrParser m_parser;
128135
ProjMgrExtGenerator m_extGenerator;

tools/projmgr/include/ProjMgrParser.h

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,39 @@ struct CbuildSetItem {
596596
std::string compiler;
597597
};
598598

599+
/**
600+
* @brief debug-adapter defaults item containing
601+
* port number of processor
602+
* debug protocol(jtag or swd)
603+
* debug clock speed
604+
*/
605+
struct DebugAdapterDefaultsItem {
606+
std::string port;
607+
std::string protocol;
608+
std::string clock;
609+
};
610+
611+
/**
612+
* @brief debug-adapter item containing
613+
* name
614+
* list of alias
615+
* template
616+
* gdbserver
617+
* defaults
618+
*/
619+
struct DebugAdapterItem {
620+
std::string name;
621+
std::vector<std::string> alias;
622+
std::string templateFile;
623+
bool gdbserver = false;
624+
DebugAdapterDefaultsItem defaults;
625+
};
626+
627+
/**
628+
* @brief debug-adapters item containing
629+
* list of debug-adapters
630+
*/
631+
typedef std::vector<DebugAdapterItem> DebugAdaptersItem;
599632

600633
/**
601634
* @brief projmgr parser class for public interfacing
@@ -656,6 +689,13 @@ class ProjMgrParser {
656689
*/
657690
bool ParseCbuildSet(const std::string& input, bool checkSchema);
658691

692+
/**
693+
* @brief parse debug-adapters file
694+
* @param checkSchema false to skip schema validation
695+
* @param input path to *.debug-adapters.yml file
696+
*/
697+
bool ParseDebugAdapters(const std::string& input, bool checkSchema);
698+
659699
/**
660700
* @brief get cdefault
661701
* @return cdefault item
@@ -692,10 +732,17 @@ class ProjMgrParser {
692732
*/
693733
CbuildSetItem& GetCbuildSetItem(void);
694734

735+
/**
736+
* @brief get debug adapters
737+
* @return debug adapters list
738+
*/
739+
DebugAdaptersItem& GetDebugAdaptersItem(void);
740+
695741
protected:
696742
CdefaultItem m_cdefault;
697743
CsolutionItem m_csolution;
698744
CbuildSetItem m_cbuildSet;
745+
DebugAdaptersItem m_debugAdapters;
699746
std::map<std::string, CprojectItem> m_cprojects;
700747
std::map<std::string, ClayerItem> m_clayers;
701748
std::map<std::string, ClayerItem> m_genericClayers;

tools/projmgr/include/ProjMgrRunDebug.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,18 +203,23 @@ class ProjMgrRunDebug {
203203
* @param vector of selected contexts
204204
* @return true if executed successfully
205205
*/
206-
bool CollectSettings(const std::vector<ContextItem*>& contexts);
206+
bool CollectSettings(const std::vector<ContextItem*>& contexts, const DebugAdaptersItem& adapters);
207207

208208
protected:
209209
RunDebugType m_runDebug;
210210
void GetDebugSequenceBlock(const RteItem* item, DebugSequencesBlockType& block);
211211
void PushBackUniquely(std::vector<std::pair<const RteItem*, std::vector<std::string>>>& vec,
212212
const RteItem* item, const std::string pname);
213213
FilesType SetLoadFromOutput(const ContextItem* context, OutputType output, const std::string type);
214-
std::string GetAccessAttributes(const RteItem* mem);
214+
const std::string GetAccessAttributes(const RteItem* mem);
215215
void SetAccessPorts(std::vector<AccessPortType>& parent, const std::map<unsigned int,
216216
std::vector<AccessPortType>>& childrenMap);
217217
void SetProtNodes(const RteDeviceProperty* item, AccessPortType& ap);
218+
bool GetDebugAdapter(const std::string& name, const DebugAdaptersItem& adapters, DebugAdapterItem& match);
219+
void CollectDebuggerSettings(const ContextItem& context, const DebugAdaptersItem& adapters,
220+
const std::map<std::string, RteDeviceProperty*>& pnames);
221+
void CollectDebugTopology(const ContextItem& context, std::vector<std::pair<const RteItem*, std::vector<std::string>>> debugs,
222+
const std::map<std::string, RteDeviceProperty*>& pnames);
218223
};
219224

220225
#endif // PROJMGRRUNDEBUG_H

tools/projmgr/include/ProjMgrWorker.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,26 @@ struct ContextTypesItem {
242242
BoolMap missingTargetTypes;
243243
};
244244

245+
/**
246+
* @brief gdb core item containing
247+
* port number of processor
248+
* processor name
249+
* primary processor
250+
*/
251+
struct GdbCoreItem {
252+
unsigned long long port;
253+
std::string pname;
254+
bool start = false;
255+
};
256+
257+
/**
258+
* @brief gdb server item containing
259+
* list of the gdb core items
260+
*/
261+
struct GdbServerItem {
262+
std::vector<GdbCoreItem> core;
263+
};
264+
245265
/**
246266
* @brief debugger type
247267
* name of debug configuration
@@ -250,6 +270,7 @@ struct ContextTypesItem {
250270
* debug clock speed
251271
* debug configuration file
252272
* start pname
273+
* gdbserver
253274
*/
254275
struct DebuggerType {
255276
std::string name;
@@ -258,6 +279,7 @@ struct DebuggerType {
258279
std::optional<unsigned long long> clock;
259280
std::string dbgconf;
260281
std::string startPname;
282+
GdbServerItem gdbserver;
261283
};
262284

263285
/**

tools/projmgr/include/ProjMgrYamlParser.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ static constexpr const char* YAML_ACCESS = "access";
1717
static constexpr const char* YAML_ACCESSPORTS = "accessports";
1818
static constexpr const char* YAML_ALGORITHM = "algorithm";
1919
static constexpr const char* YAML_ALIAS = "alias";
20+
static constexpr const char* YAML_ALIAS_NAME = "alias-name";
2021
static constexpr const char* YAML_ADDPATH = "add-path";
2122
static constexpr const char* YAML_ADDPATH_ASM = "add-path-asm";
2223
static constexpr const char* YAML_ADDRESS = "address";
@@ -78,13 +79,15 @@ static constexpr const char* YAML_CREATED_BY = "created-by";
7879
static constexpr const char* YAML_CREATED_FOR = "created-for";
7980
static constexpr const char* YAML_DATAPATCH = "datapatch";
8081
static constexpr const char* YAML_DEBUG = "debug";
82+
static constexpr const char* YAML_DEBUG_ADAPTERS = "debug-adapters";
8183
static constexpr const char* YAML_DEBUG_SEQUENCES = "debug-sequences";
8284
static constexpr const char* YAML_DEBUG_VARS = "debug-vars";
8385
static constexpr const char* YAML_DEBUG_TOPOLOGY = "debug-topology";
8486
static constexpr const char* YAML_DEBUGGER = "debugger";
8587
static constexpr const char* YAML_DEBUGPORTS = "debugports";
8688
static constexpr const char* YAML_DBGCONF = "dbgconf";
8789
static constexpr const char* YAML_DEFAULT = "default";
90+
static constexpr const char* YAML_DEFAULTS = "defaults";
8891
static constexpr const char* YAML_DEFINE = "define";
8992
static constexpr const char* YAML_DEFINE_ASM = "define-asm";
9093
static constexpr const char* YAML_DELPATH = "del-path";
@@ -111,6 +114,7 @@ static constexpr const char* YAML_FORCONTEXT = "for-context";
111114
static constexpr const char* YAML_FORDEVICE = "for-device";
112115
static constexpr const char* YAML_FORPROJECTPART = "for-project-part";
113116
static constexpr const char* YAML_FPU = "fpu";
117+
static constexpr const char* YAML_GDBSERVER = "gdbserver";
114118
static constexpr const char* YAML_GENERATED_BY = "generated-by";
115119
static constexpr const char* YAML_GENERATOR = "generator";
116120
static constexpr const char* YAML_GENERATORS = "generators";
@@ -175,6 +179,7 @@ static constexpr const char* YAML_PACKS_MISSING = "packs-missing";
175179
static constexpr const char* YAML_PACKS_UNUSED = "packs-unused";
176180
static constexpr const char* YAML_PATH = "path";
177181
static constexpr const char* YAML_PNAME = "pname";
182+
static constexpr const char* YAML_PORT = "port";
178183
static constexpr const char* YAML_PUNITS = "punits";
179184
static constexpr const char* YAML_PUNIT = "punit";
180185
static constexpr const char* YAML_PROCESSORS = "processors";
@@ -223,6 +228,7 @@ static constexpr const char* YAML_TARGETSEL = "targetsel";
223228
static constexpr const char* YAML_TARGET_SET = "target-set";
224229
static constexpr const char* YAML_TARGETTYPE = "target-type";
225230
static constexpr const char* YAML_TARGETTYPES = "target-types";
231+
static constexpr const char* YAML_TEMPLATE = "template";
226232
static constexpr const char* YAML_TIMEOUT = "timeout";
227233
static constexpr const char* YAML_TRUSTZONE = "trustzone";
228234
static constexpr const char* YAML_TITLE = "title";
@@ -298,6 +304,14 @@ class ProjMgrYamlParser {
298304
*/
299305
bool ParseCbuildSet(const std::string& input, CbuildSetItem& cbuildSet, bool checkSchema);
300306

307+
/**
308+
* @brief parse debug-adapters file
309+
* @param input path to debug-adapters.yml file
310+
* @param reference to store parsed debug-adapters item
311+
* @param checkSchema false to skip schema validation
312+
* @return true if executed successfully
313+
*/
314+
bool ParseDebugAdapters(const std::string& input, DebugAdaptersItem& adapters, bool checkSchema);
301315

302316
protected:
303317
bool ParseCbuildPack(const std::string& input, CbuildPackItem& cbuildPack, bool checkSchema);
@@ -336,6 +350,7 @@ class ProjMgrYamlParser {
336350
bool ParseTypePair(std::vector<std::string>& vec, std::vector<TypePair>& typeVec);
337351
bool ParseLinker(const YAML::Node& parent, const std::string& file, std::vector<LinkerItem>& linker);
338352
void ParseRte(const YAML::Node& parent, std::string& rteBaseDir);
353+
void ParseDebugDefaults(const YAML::Node& parent, const std::string& file, DebugAdapterDefaultsItem& defaults);
339354
bool GetTypes(const std::string& type, std::string& buildType, std::string& targetType, std::string& pattern);
340355
bool ValidateCdefault(const std::string& input, const YAML::Node& root);
341356
bool ValidateCsolution(const std::string& input, const YAML::Node& root);

tools/projmgr/schemas/common.schema.json

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,6 @@
6565
"title": "update:",
6666
"type": "string",
6767
"description": "New configuration file used for merge utility."
68-
},
69-
"debugger": {
70-
"title": "debugger:",
71-
"type": "string",
72-
"description": "Associated debugger connections."
7368
}
7469
},
7570
"required": [ "file" ],
@@ -2359,7 +2354,11 @@
23592354
"load": { "$ref": "#/definitions/TargetSetLoadType" },
23602355
"load-offset": { "type": "number", "description": "Offset applied to the binary content when loading the file." }
23612356
},
2362-
"additionalProperties": false
2357+
"additionalProperties": false,
2358+
"oneOf": [
2359+
{ "required": ["project-context"], "not": {"required": ["image"]} },
2360+
{ "required": ["image"], "not": {"required": ["project-context"]} }
2361+
]
23632362
},
23642363
"TargetSetDebuggerType": {
23652364
"title": "optimize:\nDocumentation: https://open-cmsis-pack.github.io/cmsis-toolbox/YML-Input-Format/#debugger",
@@ -2379,6 +2378,35 @@
23792378
"title": "optimize:\nDocumentation: https://open-cmsis-pack.github.io/cmsis-toolbox/YML-Input-Format/#load",
23802379
"description": "Specifies the load mode for the project output or image file.",
23812380
"enum": [ "image+symbols", "symbols", "image", "none" ]
2381+
},
2382+
"DebugAdaptersDescType": {
2383+
"title": "debug-adapters:\nDocumentation: https://open-cmsis-pack.github.io/cmsis-toolbox/build-operation/#debug-adapter-integration",
2384+
"description": "Contains the list of supported debug adapters.",
2385+
"type": "array",
2386+
"uniqueItems": true,
2387+
"items": { "$ref": "#/definitions/DebugAdapterDescType" }
2388+
},
2389+
"DebugAdapterDescType": {
2390+
"type": "object",
2391+
"properties": {
2392+
"name": { "type": "string", "description": "Debugger adapter name." },
2393+
"alias-name": { "type": "array", "items": { "type": "string"}, "description": "List of names (in input node or BSP) that map to this debug adapter." },
2394+
"template": { "type": "string", "description": "Used only by the VS Code CMSIS Solution extension for configuration." },
2395+
"gdbserver": { "type": "null", "description": "Add the gdbserver: node in the cbuild-run.yml file." },
2396+
"defaults": { "$ref": "#/definitions/DebugAdaptersDefaultsType" }
2397+
},
2398+
"additionalProperties": false,
2399+
"required": ["name"]
2400+
},
2401+
"DebugAdaptersDefaultsType": {
2402+
"description": "List of default options to use when not specified in the target-set: node.",
2403+
"type": "object",
2404+
"properties": {
2405+
"port": { "type": "number", "description": "Port number." },
2406+
"protocol": { "enum": [ "jtag", "swd" ], "description": "Selected debug protocol (jtag or swd)." },
2407+
"clock": { "type": "number", "description": "Selected debug clock speed (in Hz)." }
2408+
},
2409+
"additionalProperties": false
23822410
}
23832411
}
23842412
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"$id": "https://raw.githubusercontent.com/Open-CMSIS-Pack/devtools/schemas/projmgr/2.9.0/tools/projmgr/schemas/debug-adapters.schema.json",
4+
"title": "CMSIS debug-adapters",
5+
"description": "contains the list of supported debug adapters",
6+
"version": "2.9.0",
7+
"type": "object",
8+
"properties": {
9+
"debug-adapters": {
10+
"$ref": "./common.schema.json#/definitions/DebugAdaptersDescType"
11+
}
12+
},
13+
"additionalProperties": false,
14+
"required": [ "debug-adapters" ]
15+
}

tools/projmgr/src/ProjMgr.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,13 @@ bool ProjMgr::GenerateYMLConfigurationFiles(bool previousResult) {
538538
// Generate cbuild-run file
539539
if (previousResult && !m_processedContexts.empty() &&
540540
(m_contextSet || !m_activeTargetSet.empty())) {
541-
if (!m_runDebug.CollectSettings(m_processedContexts)) {
541+
const auto& debugAdapters = GetDebugAdaptersFile();
542+
if (!debugAdapters.empty()) {
543+
if (!m_parser.ParseDebugAdapters(debugAdapters, m_checkSchema)) {
544+
return false;
545+
}
546+
}
547+
if (!m_runDebug.CollectSettings(m_processedContexts, m_parser.GetDebugAdaptersItem())) {
542548
result = false;
543549
}
544550
if (!m_emitter.GenerateCbuildRun(m_runDebug.Get())) {
@@ -1127,7 +1133,7 @@ bool ProjMgr::ValidateCreatedFor(const string& createdFor) {
11271133
return true;
11281134
}
11291135

1130-
string ProjMgr::GetToolboxVersion(const string& toolboxDir) {
1136+
const string ProjMgr::GetToolboxVersion(const string& toolboxDir) {
11311137
// Find file non recursively under given search directory
11321138
string manifestFilePattern = "manifest_(\\d+\\.\\d+\\.\\d+)(.*).yml";
11331139
string manifestFile;
@@ -1143,3 +1149,13 @@ string ProjMgr::GetToolboxVersion(const string& toolboxDir) {
11431149
regex_match(manifestFile, matchResult, regEx);
11441150
return matchResult[1].str();
11451151
}
1152+
1153+
const string ProjMgr::GetDebugAdaptersFile(void) {
1154+
error_code ec;
1155+
const string exePath = RteUtils::ExtractFilePath(CrossPlatformUtils::GetExecutablePath(ec), true);
1156+
const string debugAdapterFile = fs::path(exePath).parent_path().parent_path().append("etc/debug-adapters.yml").generic_string();
1157+
if (RteFsUtils::Exists(debugAdapterFile)) {
1158+
return debugAdapterFile;
1159+
}
1160+
return RteUtils::EMPTY_STRING;
1161+
}

tools/projmgr/src/ProjMgrCbuild.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@ void ProjMgrCbuild::SetDebugConfigNode(YAML::Node node, const ContextItem* conte
164164
SetNodeValue(fileNode[YAML_VERSION], context->dbgconf.second->GetSemVer(true));
165165
SetPLMStatus(fileNode, context, dbgconf);
166166
}
167-
SetNodeValue(fileNode[YAML_DEBUGGER], context->debugger.name);
168167
node.push_back(fileNode);
169168
}
170169
}

tools/projmgr/src/ProjMgrCbuildRun.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class ProjMgrCbuildRun : public ProjMgrCbuildBase {
3131
void SetDebugPortsNode(YAML::Node node, const std::vector<DebugPortType>& debugPorts);
3232
void SetAccessPortsNode(YAML::Node node, const std::vector<AccessPortType>& accessPorts);
3333
void SetDatapatchNode(YAML::Node node, const std::vector<DatapatchType>& datapatch);
34+
void SetGdbServerNode(YAML::Node node, const GdbServerItem& gdbserver);
3435
};
3536

3637
ProjMgrCbuildRun::ProjMgrCbuildRun(YAML::Node node,
@@ -106,6 +107,19 @@ void ProjMgrCbuildRun::SetDebuggerNode(YAML::Node node, const DebuggerType& debu
106107
}
107108
SetNodeValue(node[YAML_DBGCONF], FormatPath(debugger.dbgconf, m_directory));
108109
SetNodeValue(node[YAML_START_PNAME], debugger.startPname);
110+
SetGdbServerNode(node[YAML_GDBSERVER], debugger.gdbserver);
111+
}
112+
}
113+
114+
void ProjMgrCbuildRun::SetGdbServerNode(YAML::Node node, const GdbServerItem& gdbserver) {
115+
for (const auto& item : gdbserver.core) {
116+
YAML::Node coreNode;
117+
coreNode[YAML_PORT] = item.port;
118+
SetNodeValue(coreNode[YAML_PNAME], item.pname);
119+
if (item.start) {
120+
coreNode[YAML_START] = YAML::Null;
121+
}
122+
node[YAML_CORE].push_back(coreNode);
109123
}
110124
}
111125

0 commit comments

Comments
 (0)