Added debugger attachment utilities to the engine, fixed crash when showing console variables, improvements to timeout handling and small cleanup (#3591)
* Added debugger attachment utilities to the engine, fixed crash when showing console variables Signed-off-by: Garcia Ruiz <aljanru@amazon.co.uk> * Removed unused variables Signed-off-by: Garcia Ruiz <aljanru@amazon.co.uk> * Removed unneded check Signed-off-by: Garcia Ruiz <aljanru@amazon.co.uk> * Small fix for crashes/timeouts Signed-off-by: Garcia Ruiz <aljanru@amazon.co.uk> * Removed unused variable, fixed compile error Signed-off-by: Garcia Ruiz <aljanru@amazon.co.uk> * Fix compile Signed-off-by: Garcia Ruiz <aljanru@amazon.co.uk> * Addressed esteban comments * Addressed tom comments Co-authored-by: Garcia Ruiz <aljanru@amazon.co.uk>
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
#include <AzCore/std/containers/unordered_set.h>
|
||||
#include <AzCore/Module/Environment.h>
|
||||
#include <AzCore/Console/IConsole.h>
|
||||
#include <AzCore/std/chrono/chrono.h>
|
||||
|
||||
namespace AZ
|
||||
{
|
||||
@@ -33,6 +34,7 @@ namespace AZ
|
||||
namespace Platform
|
||||
{
|
||||
#if defined(AZ_ENABLE_DEBUG_TOOLS)
|
||||
bool AttachDebugger();
|
||||
bool IsDebuggerPresent();
|
||||
void HandleExceptions(bool isEnabled);
|
||||
void DebugBreak();
|
||||
@@ -141,6 +143,40 @@ namespace AZ
|
||||
#endif
|
||||
}
|
||||
|
||||
bool
|
||||
Trace::AttachDebugger()
|
||||
{
|
||||
#if defined(AZ_ENABLE_DEBUG_TOOLS)
|
||||
return Platform::AttachDebugger();
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool
|
||||
Trace::WaitForDebugger(float timeoutSeconds/*=-1.f*/)
|
||||
{
|
||||
#if defined(AZ_ENABLE_DEBUG_TOOLS)
|
||||
using AZStd::chrono::system_clock;
|
||||
using AZStd::chrono::time_point;
|
||||
using AZStd::chrono::milliseconds;
|
||||
|
||||
milliseconds timeoutMs = milliseconds(aznumeric_cast<long long>(timeoutSeconds * 1000));
|
||||
system_clock clock;
|
||||
time_point start = clock.now();
|
||||
auto hasTimedOut = [&clock, start, timeoutMs]()
|
||||
{
|
||||
return timeoutMs.count() >= 0 && (clock.now() - start) >= timeoutMs;
|
||||
};
|
||||
|
||||
while (!AZ::Debug::Trace::IsDebuggerPresent() && !hasTimedOut())
|
||||
{
|
||||
AZStd::this_thread::sleep_for(milliseconds(1));
|
||||
}
|
||||
return AZ::Debug::Trace::IsDebuggerPresent();
|
||||
#endif
|
||||
}
|
||||
|
||||
//=========================================================================
|
||||
// HandleExceptions
|
||||
// [8/3/2009]
|
||||
|
||||
@@ -49,6 +49,8 @@ namespace AZ
|
||||
*/
|
||||
static const char* GetDefaultSystemWindow();
|
||||
static bool IsDebuggerPresent();
|
||||
static bool AttachDebugger();
|
||||
static bool WaitForDebugger(float timeoutSeconds = -1.f);
|
||||
|
||||
/// True or false if we want to handle system exceptions.
|
||||
static void HandleExceptions(bool isEnabled);
|
||||
|
||||
Reference in New Issue
Block a user