From 0518713ba0b0c47a680ab00c146c7469e367023c Mon Sep 17 00:00:00 2001 From: Nathan Glenn Date: Tue, 3 Sep 2024 12:57:50 -0500 Subject: [PATCH 1/2] Fix debugger warnings in unit tests The sml client Agent destructor calls `KillDebugger` as a precautionary cleanup, though the debugger process may never have been spawned. This lead to hundreds of warnings in the unit tests, where agents are constantly created and destroyed. Users are likely seeing this message in their applications as well. Add an `ignoreNonExistent` parameter to `KillDebugger` that prevents a warning from being printed when the debugger process is not present. Don't expose to SWIG bindings for now, but use it in the Agent destructor, which takes care of spurious warnings. Thanks to Aaron Mininger for reporting. --- Core/ClientSML/src/sml_ClientAgent.cpp | 9 ++++++--- Core/ClientSML/src/sml_ClientAgent.h | 10 ++++++++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/Core/ClientSML/src/sml_ClientAgent.cpp b/Core/ClientSML/src/sml_ClientAgent.cpp index 4054082a78..12b9300703 100644 --- a/Core/ClientSML/src/sml_ClientAgent.cpp +++ b/Core/ClientSML/src/sml_ClientAgent.cpp @@ -152,7 +152,7 @@ Agent::Agent(Kernel* pKernel, char const* pName) Agent::~Agent() { - KillDebugger(); + KillDebugger(true); } Connection* Agent::GetConnection() const @@ -1839,11 +1839,14 @@ bool Agent::SpawnDebugger(int port, const char* jarpath) #endif // _WIN32 } -bool Agent::KillDebugger() +bool Agent::KillDebugger(bool ignoreNonExistent) { if (!m_pDPI) { - std::cerr << "KillDebugger: No existing debugger process information" << std::endl; + if (!ignoreNonExistent) + { + std::cerr << "KillDebugger: No existing debugger process information" << std::endl; + } return false; } bool successful = false; diff --git a/Core/ClientSML/src/sml_ClientAgent.h b/Core/ClientSML/src/sml_ClientAgent.h index e8b3f25b59..f745d5f887 100644 --- a/Core/ClientSML/src/sml_ClientAgent.h +++ b/Core/ClientSML/src/sml_ClientAgent.h @@ -884,8 +884,14 @@ namespace sml * @brief Kills the previously spawned debugger. Returns false * if the debugger was never spawned or an OS issue occurs * while killing the process. - *************************************************************/ - bool KillDebugger(); + * @param ignoreNonExistent if true, do not print a warning if + * no debugger process exists to kill. This is useful, for example, + * when the client doesn't know if the debugger was ever actually + * opened, or whether the user may have closed the window, but wants + * to close it just in case for cleanup purposes. Not currently + * exposed via SWIG bindings. + *************************************************************/ + bool KillDebugger(bool ignoreNonExistent = false); /************************************************************* * @brief Convert a client-side identifier string to kernel-side. From fc529fa090c60961cb7021e9b501d9ec4f7f7e10 Mon Sep 17 00:00:00 2001 From: Nathan Glenn Date: Wed, 11 Sep 2024 14:57:25 -0500 Subject: [PATCH 2/2] Use more explicit nullptr instead of 0 --- Core/ClientSML/src/sml_ClientAgent.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Core/ClientSML/src/sml_ClientAgent.cpp b/Core/ClientSML/src/sml_ClientAgent.cpp index 12b9300703..1188e80812 100644 --- a/Core/ClientSML/src/sml_ClientAgent.cpp +++ b/Core/ClientSML/src/sml_ClientAgent.cpp @@ -145,7 +145,7 @@ Agent::Agent(Kernel* pKernel, char const* pName) m_WorkingMemory.SetAgent(this) ; - m_pDPI = 0; + m_pDPI = nullptr; ClearError() ; } @@ -1880,7 +1880,7 @@ void Agent::ClearDebuggerProcessInformation() if (m_pDPI) { delete m_pDPI; - m_pDPI = 0; + m_pDPI = nullptr; } }