Skip to content

Commit 8986491

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

File tree

2 files changed

+77
-67
lines changed

2 files changed

+77
-67
lines changed

tools/projmgr/include/ProjMgrRunDebug.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,8 @@ class ProjMgrRunDebug {
218218
bool GetDebugAdapter(const std::string& name, const DebugAdaptersItem& adapters, DebugAdapterItem& match);
219219
void CollectDebuggerSettings(const ContextItem& context, const DebugAdaptersItem& adapters,
220220
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);
221223
};
222224

223225
#endif // PROJMGRRUNDEBUG_H

tools/projmgr/src/ProjMgrRunDebug.cpp

Lines changed: 75 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,78 @@ bool ProjMgrRunDebug::CollectSettings(const vector<ContextItem*>& contexts, cons
280280
CollectDebuggerSettings(*context0, adapters, pnames);
281281

282282
// debug topology
283-
const auto& debugConfig = context0->devicePack ?
284-
context0->rteDevice->GetSingleEffectiveProperty("debugconfig", context0->deviceItem.pname) : nullptr;
283+
CollectDebugTopology(*context0, debugs, pnames);
284+
285+
return true;
286+
}
287+
288+
void ProjMgrRunDebug::CollectDebuggerSettings(const ContextItem& context, const DebugAdaptersItem& adapters,
289+
const std::map<std::string, RteDeviceProperty*>& pnames) {
290+
// default debugger parameters from DFP and BSP
291+
DebuggerType defaultDebugger;
292+
defaultDebugger.dbgconf = context.dbgconf.first;
293+
const auto& debugConfig = context.devicePack ?
294+
context.rteDevice->GetSingleEffectiveProperty("debugconfig", context.deviceItem.pname) : nullptr;
295+
const auto& debugProbe = context.boardPack ?
296+
context.rteBoard->GetItemByTag("debugProbe") : nullptr;
297+
defaultDebugger.name = debugProbe ? debugProbe->GetName() : DEBUGGER_NAME_DEFAULT;
298+
const auto& boardProtocol = debugProbe ? debugProbe->GetAttribute("debugLink") : "";
299+
const auto& deviceProtocol = debugConfig ? debugConfig->GetAttribute("default") : "";
300+
defaultDebugger.protocol = !boardProtocol.empty() ? boardProtocol : deviceProtocol;
301+
if (debugProbe && debugProbe->HasAttribute("debugClock")) {
302+
defaultDebugger.clock = debugProbe->GetAttributeAsULL("debugClock");
303+
}
304+
else if (debugConfig && debugConfig->HasAttribute("clock")) {
305+
defaultDebugger.clock = debugConfig->GetAttributeAsULL("clock");
306+
}
307+
308+
// user defined debugger parameters
309+
if (!context.debugger.name.empty()) {
310+
m_runDebug.debugger = context.debugger;
311+
if (m_runDebug.debugger.protocol.empty()) {
312+
m_runDebug.debugger.protocol = defaultDebugger.protocol;
313+
}
314+
if (!m_runDebug.debugger.clock.has_value()) {
315+
m_runDebug.debugger.clock = defaultDebugger.clock;
316+
}
317+
if (m_runDebug.debugger.dbgconf.empty()) {
318+
m_runDebug.debugger.dbgconf = defaultDebugger.dbgconf;
319+
}
320+
}
321+
else {
322+
m_runDebug.debugger = defaultDebugger;
323+
}
324+
325+
// add info from debug-adapters
326+
if (!adapters.empty()) {
327+
DebugAdapterItem adapter;
328+
if (GetDebugAdapter(m_runDebug.debugger.name, adapters, adapter)) {
329+
m_runDebug.debugger.name = adapter.name;
330+
if (adapter.gdbserver) {
331+
unsigned long long port = adapter.defaults.port.empty() ? 0 : RteUtils::StringToULL(adapter.defaults.port);
332+
for (const auto& [pname, _] : pnames) {
333+
GdbCoreItem item;
334+
item.port = port++;
335+
item.pname = pname;
336+
item.start = !pname.empty() && (pname == m_runDebug.debugger.startPname);
337+
m_runDebug.debugger.gdbserver.core.push_back(item);
338+
}
339+
}
340+
if (m_runDebug.debugger.protocol.empty()) {
341+
m_runDebug.debugger.protocol = adapter.defaults.protocol;
342+
}
343+
if (!m_runDebug.debugger.clock.has_value() && !adapter.defaults.clock.empty()) {
344+
m_runDebug.debugger.clock = RteUtils::StringToULL(adapter.defaults.clock);
345+
}
346+
}
347+
}
348+
}
349+
350+
void ProjMgrRunDebug::CollectDebugTopology(const ContextItem& context, const vector<pair<const RteItem*, vector<string>>> debugs,
351+
const std::map<std::string, RteDeviceProperty*>& pnames) {
352+
// debug topology
353+
const auto& debugConfig = context.devicePack ?
354+
context.rteDevice->GetSingleEffectiveProperty("debugconfig", context.deviceItem.pname) : nullptr;
285355
if (debugConfig) {
286356
if (debugConfig->HasAttribute("dormant")) {
287357
m_runDebug.debugTopology.dormant = debugConfig->GetAttributeAsBool("dormant", false);
@@ -300,9 +370,9 @@ bool ProjMgrRunDebug::CollectSettings(const vector<ContextItem*>& contexts, cons
300370
map<unsigned int, vector<AccessPortType>> accessPortsChildrenMap;
301371
map<unsigned int, vector<DatapatchType>> datapatchById;
302372
map<unsigned int, map<unsigned int, vector<DatapatchType>>> datapatchByIndex;
303-
const auto& accessPortsV1 = context0->rteDevice->GetEffectiveProperties("accessportV1", context0->deviceItem.pname);
304-
const auto& accessPortsV2 = context0->rteDevice->GetEffectiveProperties("accessportV2", context0->deviceItem.pname);
305-
const auto& debugPorts = context0->rteDevice->GetEffectiveProperties("debugport", context0->deviceItem.pname);
373+
const auto& accessPortsV1 = context.rteDevice->GetEffectiveProperties("accessportV1", context.deviceItem.pname);
374+
const auto& accessPortsV2 = context.rteDevice->GetEffectiveProperties("accessportV2", context.deviceItem.pname);
375+
const auto& debugPorts = context.rteDevice->GetEffectiveProperties("debugport", context.deviceItem.pname);
306376
const auto& defaultDp = debugPorts.empty() ? 0 : debugPorts.front()->GetAttributeAsInt("__dp");
307377

308378
// datapatches
@@ -428,8 +498,6 @@ bool ProjMgrRunDebug::CollectSettings(const vector<ContextItem*>& contexts, cons
428498
// add nested children access ports
429499
SetAccessPorts(dp.accessPorts, accessPortsChildrenMap);
430500
}
431-
432-
return true;
433501
}
434502

435503
void ProjMgrRunDebug::SetAccessPorts(vector<AccessPortType>& parent, const map<unsigned int, vector<AccessPortType>>& childrenMap) {
@@ -528,63 +596,3 @@ bool ProjMgrRunDebug::GetDebugAdapter(const string& name, const DebugAdaptersIte
528596
}
529597
return false;
530598
}
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)