Skip to content

Commit 0933127

Browse files
authored
[cbuild-run] Debugger integration refinements
1 parent f7a460d commit 0933127

13 files changed

+131
-102
lines changed

tools/projmgr/include/ProjMgrRunDebug.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,8 @@ class ProjMgrRunDebug {
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);
213-
FilesType SetLoadFromOutput(const ContextItem* context, OutputType output, const std::string type);
213+
void AddGeneratedImage(const ContextItem* context, const std::string& filename, const std::string& type, const std::string& load);
214+
void AddGeneratedImages(const ContextItem* context);
214215
const std::string GetAccessAttributes(const RteItem* mem);
215216
void SetAccessPorts(std::vector<AccessPortType>& parent, const std::map<unsigned int,
216217
std::vector<AccessPortType>>& childrenMap);

tools/projmgr/include/ProjMgrWorker.h

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -243,23 +243,13 @@ struct ContextTypesItem {
243243
};
244244

245245
/**
246-
* @brief gdb core item containing
246+
* @brief gdb server item containing
247247
* port number of processor
248248
* processor name
249-
* primary processor
250249
*/
251-
struct GdbCoreItem {
250+
struct GdbServerItem {
252251
unsigned long long port;
253252
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;
263253
};
264254

265255
/**
@@ -270,7 +260,7 @@ struct GdbServerItem {
270260
* debug clock speed
271261
* debug configuration file
272262
* start pname
273-
* gdbserver
263+
* list of gdbserver items
274264
*/
275265
struct DebuggerType {
276266
std::string name;
@@ -279,7 +269,7 @@ struct DebuggerType {
279269
std::optional<unsigned long long> clock;
280270
std::string dbgconf;
281271
std::string startPname;
282-
GdbServerItem gdbserver;
272+
std::vector<GdbServerItem> gdbserver;
283273
};
284274

285275
/**
@@ -341,6 +331,7 @@ struct DebuggerType {
341331
* default dbgconf
342332
* images
343333
* selected target-set
334+
* load offset for generated binary
344335
*/
345336
struct ContextItem {
346337
CdefaultItem* cdefault = nullptr;
@@ -407,6 +398,7 @@ struct ContextItem {
407398
std::pair<std::string, RteFileInstance*> dbgconf;
408399
std::vector<ImageItem> images;
409400
std::string targetSet;
401+
std::string loadOffset;
410402
};
411403

412404
/**

tools/projmgr/schemas/common.schema.json

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2048,11 +2048,11 @@
20482048
"type": { "type": "string", "description": "Specifies the file type." },
20492049
"info": { "type": "string", "description": "Brief description of the file." },
20502050
"load": { "$ref": "#/definitions/TargetSetLoadType" },
2051-
"load-offset": { "type": "number", "description": "Offset applied to the binary content when loading the file." },
2051+
"load-offset": { "type": "number", "description": "Offset applied in *.csolution.yml when loading the image file." },
20522052
"pname": { "type": "string", "description": "Image belongs to processor in a multi-core system." }
20532053
},
20542054
"additionalProperties": false,
2055-
"required": ["file", "type"]
2055+
"required": ["file", "type", "load"]
20562056
},
20572057
"RunSystemFilesType": {
20582058
"title": "output:\nDocumentation: https://open-cmsis-pack.github.io/cmsis-toolbox/YML-CBuild-Format/#system-descriptions",
@@ -2149,35 +2149,25 @@
21492149
"clock": { "type": "number", "description": "Selected debug clock speed (in Hz)." },
21502150
"dbgconf": { "type": "string", "description": "Debugger configuration file (pinout, trace)." },
21512151
"start-pname": { "type": "string", "description": "Debugger connects at start to this processor." },
2152-
"gdbserver": { "$ref": "#/definitions/GdbServerType" }
2152+
"gdbserver": { "$ref": "#/definitions/GdbServersType" },
2153+
"terminal": { "type": "string", "description": "Terminal port of the debugger." },
2154+
"trace": { "type": "string", "description": "Trace port of the debugger." }
21532155
},
21542156
"additionalProperties": true,
21552157
"required": ["name"]
21562158
},
2157-
"GdbServerType": {
2159+
"GdbServersType": {
21582160
"title": "gdbserver:\nDocumentation: https://open-cmsis-pack.github.io/cmsis-toolbox/YML-CBuild-Format/#gdbserver",
21592161
"description": "Information for GDB server option of debugger.",
2160-
"type": "object",
2161-
"properties": {
2162-
"core": { "$ref": "#/definitions/GdbCoresType" },
2163-
"terminal": { "type": "string", "description": "Terminal port of the GDB server." },
2164-
"trace": { "type": "string", "description": "Trace port of the GDB server." }
2165-
},
2166-
"additionalProperties": false,
2167-
"required": ["core"]
2168-
},
2169-
"GdbCoresType": {
2170-
"description": "List of the processor cores along with GDB port number.",
21712162
"type": "array",
21722163
"uniqueItems": true,
2173-
"items": { "$ref": "#/definitions/GdbCoreType" }
2164+
"items": { "$ref": "#/definitions/GdbServerType" }
21742165
},
2175-
"GdbCoreType": {
2166+
"GdbServerType": {
21762167
"type": "object",
21772168
"properties": {
21782169
"port": { "type": "number", "description": "Port number of processor." },
21792170
"pname": { "type": "string", "description": "Processor name of the processor (only required for multi-core systems)." },
2180-
"start": { "type": "null", "description": "Identifies the start or primary processor. Only one processor can have the start: node." },
21812171
"punit": { "type": "number", "description": "Identifies the procssor core in a SMP system." }
21822172
},
21832173
"additionalProperties": false,
@@ -2347,16 +2337,16 @@
23472337
"TargetSetImageType": {
23482338
"type": "object",
23492339
"properties": {
2350-
"project-context": { "type": "string", "description": "Project context in the format 'project-name.build-type'." },
2351-
"image": { "type": "string", "description": "Base filename of the image (without path)." },
2352-
"info": { "type": "string", "description": "Brief description of the file." },
2353-
"type": { "enum": [ "elf", "hex", "bin", "lib" ], "description": "Specifies an explicit file type." },
2340+
"project-context": { "type": "string", "description": "Project output with optional build-type: '<project_name>[.buid_type]'." },
2341+
"image": { "type": "string", "description": "Additional image file to load." },
2342+
"info": { "type": "string", "description": "Brief description of the image file." },
2343+
"type": { "enum": [ "elf", "hex", "bin", "lib" ], "description": "Specifies an explicit image type." },
23542344
"load": { "$ref": "#/definitions/TargetSetLoadType" },
2355-
"load-offset": { "type": "number", "description": "Offset applied to the binary content when loading the file." }
2345+
"load-offset": { "type": "number", "description": "Offset applied to the binary content when loading the image file." }
23562346
},
23572347
"additionalProperties": false,
23582348
"oneOf": [
2359-
{ "required": ["project-context"], "not": {"required": ["image"]} },
2349+
{ "required": ["project-context"], "not": {"required": ["image", "load", "type"]} },
23602350
{ "required": ["image"], "not": {"required": ["project-context"]} }
23612351
]
23622352
},

tools/projmgr/src/ProjMgrCbuildRun.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +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);
34+
void SetGdbServerNode(YAML::Node node, const std::vector<GdbServerItem>& gdbserver);
3535
};
3636

3737
ProjMgrCbuildRun::ProjMgrCbuildRun(YAML::Node node,
@@ -111,15 +111,12 @@ void ProjMgrCbuildRun::SetDebuggerNode(YAML::Node node, const DebuggerType& debu
111111
}
112112
}
113113

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);
114+
void ProjMgrCbuildRun::SetGdbServerNode(YAML::Node node, const std::vector<GdbServerItem>& gdbserver) {
115+
for (const auto& item : gdbserver) {
116+
YAML::Node gdbserverNode;
117+
gdbserverNode[YAML_PORT] = item.port;
118+
SetNodeValue(gdbserverNode[YAML_PNAME], item.pname);
119+
node.push_back(gdbserverNode);
123120
}
124121
}
125122

tools/projmgr/src/ProjMgrRunDebug.cpp

Lines changed: 59 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ using namespace std;
1818
* @brief default debugger parameters
1919
*/
2020
static constexpr const char* DEBUGGER_NAME_DEFAULT = "CMSIS-DAP";
21+
static constexpr const char* LOAD_IMAGE_SYMBOLS = "image+symbols";
22+
static constexpr const char* LOAD_IMAGE = "image";
23+
static constexpr const char* LOAD_SYMBOLS = "symbols";
24+
static constexpr const char* LOAD_NONE = "none";
2125

2226
ProjMgrRunDebug::ProjMgrRunDebug(void) {
2327
// Reserved
@@ -219,36 +223,23 @@ bool ProjMgrRunDebug::CollectSettings(const vector<ContextItem*>& contexts, cons
219223

220224
// outputs
221225
for (const auto& context : contexts) {
222-
// populate load entries from context outputs
223-
const map<const string, const OutputType> types = {
224-
{ RteConstants::OUTPUT_TYPE_ELF, context->outputTypes.elf },
225-
{ RteConstants::OUTPUT_TYPE_HEX, context->outputTypes.hex },
226-
{ RteConstants::OUTPUT_TYPE_BIN, context->outputTypes.bin },
227-
};
228-
for (const auto& [type, output] : types) {
229-
const auto& load = SetLoadFromOutput(context, output, type);
230-
if (!load.file.empty()) {
231-
m_runDebug.outputs.push_back(load);
232-
}
233-
}
226+
// populate image entries from context outputs
227+
AddGeneratedImages(context);
234228
}
235229

236-
// merge/insert target-set image nodes
237-
for (const auto& item : context0->images) {
238-
bool merged = false;
239-
for (auto& output : m_runDebug.outputs) {
240-
if (output.file == item.image) {
241-
output.info = output.info.empty() ? item.info : output.info;
242-
output.type = output.type.empty() ? item.type : output.type;
243-
output.load = output.load.empty() ? item.load : output.load;
244-
output.offset = output.offset.empty() ? item.offset : output.offset;
245-
merged = true;
246-
break;
247-
}
230+
// insert target-set image nodes
231+
for (auto item : context0->images) {
232+
if (item.type.empty()) {
233+
item.type = ProjMgrUtils::FileTypeFromExtension(item.image);
248234
}
249-
if (!merged) {
250-
m_runDebug.outputs.push_back({ item.image, item.info, item.type, item.load, item.offset });
235+
if (item.load.empty()) {
236+
// files with 'type: elf' get 'load: image+symbols'
237+
// files with 'type: lib' get 'load: none'
238+
// all other file types get 'load: image'
239+
item.load = item.type == RteConstants::OUTPUT_TYPE_ELF ? LOAD_IMAGE_SYMBOLS :
240+
item.type == RteConstants::OUTPUT_TYPE_LIB ? LOAD_NONE : LOAD_IMAGE;
251241
}
242+
m_runDebug.outputs.push_back({ item.image, item.info, item.type, item.load, item.offset });
252243
}
253244

254245
// debug vars
@@ -330,11 +321,10 @@ void ProjMgrRunDebug::CollectDebuggerSettings(const ContextItem& context, const
330321
if (adapter.gdbserver) {
331322
unsigned long long port = adapter.defaults.port.empty() ? 0 : RteUtils::StringToULL(adapter.defaults.port);
332323
for (const auto& [pname, _] : pnames) {
333-
GdbCoreItem item;
324+
GdbServerItem item;
334325
item.port = port++;
335326
item.pname = pname;
336-
item.start = !pname.empty() && (pname == m_runDebug.debugger.startPname);
337-
m_runDebug.debugger.gdbserver.core.push_back(item);
327+
m_runDebug.debugger.gdbserver.push_back(item);
338328
}
339329
}
340330
if (m_runDebug.debugger.protocol.empty()) {
@@ -345,6 +335,11 @@ void ProjMgrRunDebug::CollectDebuggerSettings(const ContextItem& context, const
345335
}
346336
}
347337
}
338+
339+
// primary processor
340+
if (m_runDebug.debugger.startPname.empty()) {
341+
m_runDebug.debugger.startPname = context.deviceItem.pname;
342+
}
348343
}
349344

350345
void ProjMgrRunDebug::CollectDebugTopology(const ContextItem& context, const vector<pair<const RteItem*, vector<string>>> debugs,
@@ -519,16 +514,42 @@ void ProjMgrRunDebug::SetProtNodes(const RteDeviceProperty* item, AccessPortType
519514
}
520515
}
521516

522-
FilesType ProjMgrRunDebug::SetLoadFromOutput(const ContextItem* context, OutputType output, const string type) {
523-
FilesType load;
524-
if (output.on) {
525-
RteFsUtils::NormalizePath(output.filename, context->directories.cprj + '/' + context->directories.outdir);
526-
load.file = output.filename;
527-
load.info = "generate by " + context->name;
528-
load.type = type;
529-
load.pname = context->deviceItem.pname;
517+
void ProjMgrRunDebug::AddGeneratedImage(const ContextItem* context, const string& filename, const string& type, const string& load) {
518+
string file = filename;
519+
RteFsUtils::NormalizePath(file, context->directories.cprj + '/' + context->directories.outdir);
520+
if (!file.empty()) {
521+
FilesType image;
522+
image.file = file;
523+
image.info = "generate by " + context->name;
524+
image.type = type;
525+
image.load = load;
526+
image.pname = context->deviceItem.pname;
527+
image.offset = type == RteConstants::OUTPUT_TYPE_BIN ? context->loadOffset : RteUtils::EMPTY_STRING;
528+
m_runDebug.outputs.push_back(image);
529+
}
530+
}
531+
532+
void ProjMgrRunDebug::AddGeneratedImages(const ContextItem* context) {
533+
/*
534+
For 'compiler: AC6':
535+
- When only a file with 'type: elf' is generated, the file gets 'load: image+symbols'
536+
- When a file with 'type: elf' and a file with 'type: hex' is generated, the 'type: elf' file gets 'load: symbols' and the 'type: hex' file gets 'load: image'
537+
- All other file types get 'load: none'
538+
For any other compiler:
539+
- Files with 'type: elf' get 'load: image+symbols'
540+
- All other file types get 'load: none'
541+
*/
542+
if (context->outputTypes.elf.on) {
543+
AddGeneratedImage(context, context->outputTypes.elf.filename, RteConstants::OUTPUT_TYPE_ELF,
544+
context->compiler == "AC6" && context->outputTypes.hex.on ? LOAD_SYMBOLS : LOAD_IMAGE_SYMBOLS);
545+
}
546+
if (context->outputTypes.hex.on) {
547+
AddGeneratedImage(context, context->outputTypes.hex.filename, RteConstants::OUTPUT_TYPE_HEX,
548+
context->compiler == "AC6" ? LOAD_IMAGE : LOAD_NONE);
549+
}
550+
if (context->outputTypes.bin.on) {
551+
AddGeneratedImage(context, context->outputTypes.bin.filename, RteConstants::OUTPUT_TYPE_BIN, LOAD_NONE);
530552
}
531-
return load;
532553
}
533554

534555
void ProjMgrRunDebug::GetDebugSequenceBlock(const RteItem* item, DebugSequencesBlockType& block) {

tools/projmgr/src/ProjMgrWorker.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2515,9 +2515,6 @@ bool ProjMgrWorker::ProcessImages(ContextItem& context) {
25152515
const vector<ImageItem>& images = m_activeTargetSet.images;
25162516
for (auto item : images) {
25172517
if (!item.image.empty()) {
2518-
if (item.type.empty()) {
2519-
item.type = ProjMgrUtils::FileTypeFromExtension(item.image);
2520-
}
25212518
if (!ProcessSequenceRelative(context, item.image, context.csolution->directory)) {
25222519
return false;
25232520
}
@@ -2526,6 +2523,9 @@ bool ProjMgrWorker::ProcessImages(ContextItem& context) {
25262523
}
25272524
context.images.push_back(item);
25282525
}
2526+
else if (item.context == context.cproject->name + (context.type.build.empty() ? "" : '.' + context.type.build)) {
2527+
context.loadOffset = item.offset;
2528+
}
25292529
}
25302530
return true;
25312531
}

tools/projmgr/test/data/TestRunDebug/ref/run-debug+TestHW.cbuild-run.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,19 @@ cbuild-run:
1313
info: generate by run-debug+TestHW
1414
type: elf
1515
load: symbols
16+
- file: out/run-debug/TestHW/run-debug.hex
17+
info: generate by run-debug+TestHW
18+
type: hex
19+
load: image
20+
- file: out/run-debug/TestHW/run-debug.bin
21+
info: generate by run-debug+TestHW
22+
type: bin
23+
load: none
24+
load-offset: 0x0000A000
1625
- file: ../data/TestRunDebug/customImage.bin
1726
info: load image info
1827
type: bin
28+
load: image
1929
load-offset: 0x00001000
2030
system-resources:
2131
memory:
@@ -43,8 +53,7 @@ cbuild-run:
4353
clock: 20000000
4454
dbgconf: ../data/TestRunDebug/RTE/Device/RteTest1/RteTest1.dbgconf
4555
gdbserver:
46-
core:
47-
- port: 3333
56+
- port: 3333
4857
debug-vars:
4958
vars: |
5059
__var DbgMCU_CR = 0x00000007; // DBGMCU_CR: DBG_SLEEP, DBG_STOP, DBG_STANDBY

tools/projmgr/test/data/TestRunDebug/ref/run-debug+TestHW.cbuild.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,12 @@ build:
3636
outdir: out/run-debug/TestHW
3737
rtedir: ../data/TestRunDebug/RTE
3838
output:
39+
- type: bin
40+
file: run-debug.bin
3941
- type: elf
4042
file: run-debug.axf
43+
- type: hex
44+
file: run-debug.hex
4145
components:
4246
- component: ARM::Device:Startup&RteTest [email protected]
4347
condition: ARMCM4 RteTest

0 commit comments

Comments
 (0)