Skip to content

Commit 3f076de

Browse files
committed
Address CodeQL findings
1 parent ecd6099 commit 3f076de

File tree

2 files changed

+66
-56
lines changed

2 files changed

+66
-56
lines changed

tools/projmgr/include/ProjMgrRunDebug.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,8 @@ class ProjMgrRunDebug {
216216
std::vector<AccessPortType>>& childrenMap);
217217
void SetProtNodes(const RteDeviceProperty* item, AccessPortType& ap);
218218
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);
219221
};
220222

221223
#endif // PROJMGRRUNDEBUG_H

tools/projmgr/src/ProjMgrRunDebug.cpp

Lines changed: 64 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -276,64 +276,12 @@ bool ProjMgrRunDebug::CollectSettings(const vector<ContextItem*>& contexts, cons
276276
m_runDebug.debugSequences.push_back(sequence);
277277
}
278278

279-
// default debugger parameters from DFP and BSP
280-
DebuggerType defaultDebugger;
281-
defaultDebugger.dbgconf = context0->dbgconf.first;
282-
const auto& debugConfig = context0->devicePack ?
283-
context0->rteDevice->GetSingleEffectiveProperty("debugconfig", context0->deviceItem.pname) : nullptr;
284-
const auto& debugProbe = context0->boardPack ?
285-
context0->rteBoard->GetItemByTag("debugProbe") : nullptr;
286-
defaultDebugger.name = debugProbe ? debugProbe->GetName() : DEBUGGER_NAME_DEFAULT;
287-
const auto& boardProtocol = debugProbe ? debugProbe->GetAttribute("debugLink") : "";
288-
const auto& deviceProtocol = debugConfig ? debugConfig->GetAttribute("default") : "";
289-
defaultDebugger.protocol = !boardProtocol.empty() ? boardProtocol : deviceProtocol;
290-
if (debugProbe && debugProbe->HasAttribute("debugClock")) {
291-
defaultDebugger.clock = debugProbe->GetAttributeAsULL("debugClock");
292-
} else if (debugConfig && debugConfig->HasAttribute("clock")) {
293-
defaultDebugger.clock = debugConfig->GetAttributeAsULL("clock");
294-
}
295-
296-
// user defined debugger parameters
297-
if (!context0->debugger.name.empty()) {
298-
m_runDebug.debugger = context0->debugger;
299-
if (m_runDebug.debugger.protocol.empty()) {
300-
m_runDebug.debugger.protocol = defaultDebugger.protocol;
301-
}
302-
if (!m_runDebug.debugger.clock.has_value()) {
303-
m_runDebug.debugger.clock = defaultDebugger.clock;
304-
}
305-
if (m_runDebug.debugger.dbgconf.empty()) {
306-
m_runDebug.debugger.dbgconf = defaultDebugger.dbgconf;
307-
}
308-
} else {
309-
m_runDebug.debugger = defaultDebugger;
310-
}
311-
312-
// add info from debug-adapters
313-
if (!adapters.empty()) {
314-
DebugAdapterItem adapter;
315-
if (GetDebugAdapter(m_runDebug.debugger.name, adapters, adapter)) {
316-
m_runDebug.debugger.name = adapter.name;
317-
if (adapter.gdbserver) {
318-
unsigned long long port = adapter.defaults.port.empty() ? 0 : RteUtils::StringToULL(adapter.defaults.port);
319-
for (const auto& [pname, _] : pnames) {
320-
GdbCoreItem item;
321-
item.port = port++;
322-
item.pname = pname;
323-
item.start = !pname.empty() && (pname == m_runDebug.debugger.startPname);
324-
m_runDebug.debugger.gdbserver.core.push_back(item);
325-
}
326-
}
327-
if (m_runDebug.debugger.protocol.empty()) {
328-
m_runDebug.debugger.protocol = adapter.defaults.protocol;
329-
}
330-
if (!m_runDebug.debugger.clock.has_value() && !adapter.defaults.clock.empty()) {
331-
m_runDebug.debugger.clock = RteUtils::StringToULL(adapter.defaults.clock);
332-
}
333-
}
334-
}
279+
// debugger settings
280+
CollectDebuggerSettings(*context0, adapters, pnames);
335281

336282
// debug topology
283+
const auto& debugConfig = context0->devicePack ?
284+
context0->rteDevice->GetSingleEffectiveProperty("debugconfig", context0->deviceItem.pname) : nullptr;
337285
if (debugConfig) {
338286
if (debugConfig->HasAttribute("dormant")) {
339287
m_runDebug.debugTopology.dormant = debugConfig->GetAttributeAsBool("dormant", false);
@@ -580,3 +528,63 @@ bool ProjMgrRunDebug::GetDebugAdapter(const string& name, const DebugAdaptersIte
580528
}
581529
return false;
582530
}
531+
532+
void ProjMgrRunDebug::CollectDebuggerSettings(const ContextItem& context, const DebugAdaptersItem& adapters,
533+
const std::map<std::string, RteDeviceProperty*>& pnames) {
534+
// default debugger parameters from DFP and BSP
535+
DebuggerType defaultDebugger;
536+
defaultDebugger.dbgconf = context.dbgconf.first;
537+
const auto& debugConfig = context.devicePack ?
538+
context.rteDevice->GetSingleEffectiveProperty("debugconfig", context.deviceItem.pname) : nullptr;
539+
const auto& debugProbe = context.boardPack ?
540+
context.rteBoard->GetItemByTag("debugProbe") : nullptr;
541+
defaultDebugger.name = debugProbe ? debugProbe->GetName() : DEBUGGER_NAME_DEFAULT;
542+
const auto& boardProtocol = debugProbe ? debugProbe->GetAttribute("debugLink") : "";
543+
const auto& deviceProtocol = debugConfig ? debugConfig->GetAttribute("default") : "";
544+
defaultDebugger.protocol = !boardProtocol.empty() ? boardProtocol : deviceProtocol;
545+
if (debugProbe && debugProbe->HasAttribute("debugClock")) {
546+
defaultDebugger.clock = debugProbe->GetAttributeAsULL("debugClock");
547+
} else if (debugConfig && debugConfig->HasAttribute("clock")) {
548+
defaultDebugger.clock = debugConfig->GetAttributeAsULL("clock");
549+
}
550+
551+
// user defined debugger parameters
552+
if (!context.debugger.name.empty()) {
553+
m_runDebug.debugger = context.debugger;
554+
if (m_runDebug.debugger.protocol.empty()) {
555+
m_runDebug.debugger.protocol = defaultDebugger.protocol;
556+
}
557+
if (!m_runDebug.debugger.clock.has_value()) {
558+
m_runDebug.debugger.clock = defaultDebugger.clock;
559+
}
560+
if (m_runDebug.debugger.dbgconf.empty()) {
561+
m_runDebug.debugger.dbgconf = defaultDebugger.dbgconf;
562+
}
563+
} else {
564+
m_runDebug.debugger = defaultDebugger;
565+
}
566+
567+
// add info from debug-adapters
568+
if (!adapters.empty()) {
569+
DebugAdapterItem adapter;
570+
if (GetDebugAdapter(m_runDebug.debugger.name, adapters, adapter)) {
571+
m_runDebug.debugger.name = adapter.name;
572+
if (adapter.gdbserver) {
573+
unsigned long long port = adapter.defaults.port.empty() ? 0 : RteUtils::StringToULL(adapter.defaults.port);
574+
for (const auto& [pname, _] : pnames) {
575+
GdbCoreItem item;
576+
item.port = port++;
577+
item.pname = pname;
578+
item.start = !pname.empty() && (pname == m_runDebug.debugger.startPname);
579+
m_runDebug.debugger.gdbserver.core.push_back(item);
580+
}
581+
}
582+
if (m_runDebug.debugger.protocol.empty()) {
583+
m_runDebug.debugger.protocol = adapter.defaults.protocol;
584+
}
585+
if (!m_runDebug.debugger.clock.has_value() && !adapter.defaults.clock.empty()) {
586+
m_runDebug.debugger.clock = RteUtils::StringToULL(adapter.defaults.clock);
587+
}
588+
}
589+
}
590+
}

0 commit comments

Comments
 (0)