Skip to content

Commit

Permalink
Improve Optick error reporting to debugger and to console stderr for …
Browse files Browse the repository at this point in the history
…all platforms
  • Loading branch information
SRSaunders committed Feb 20, 2024
1 parent 2a1b010 commit a697a00
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
23 changes: 16 additions & 7 deletions src/optick_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "optick.h"

#include <cstdio>
#include <iostream>
#include <stdarg.h>
#include <stddef.h>
#include <stdint.h>
Expand Down Expand Up @@ -134,21 +135,29 @@ static const ProcessID INVALID_PROCESS_ID = (ProcessID)-1;
// Asserts
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#if defined(OPTICK_MSVC)
#define OPTICK_DEBUG_BREAK __debugbreak()
#ifdef UNICODE
#define OPTICK_DEBUG_BREAK(description) OutputDebugString(L"Optick ERROR: " description L"\n"); __debugbreak()
#else
#define OPTICK_DEBUG_BREAK(description) OutputDebugString("Optick ERROR: " description "\n"); __debugbreak()
#endif
#elif defined(OPTICK_GCC)
#define OPTICK_DEBUG_BREAK __builtin_trap()
#if __has_builtin(__builtin_debugtrap)
#define OPTICK_DEBUG_BREAK(description) std::cerr << "Optick ERROR: " << description << std::endl; __builtin_debugtrap()
#else
#define OPTICK_DEBUG_BREAK(description) std::cerr << "Optick ERROR: " << description << std::endl; __builtin_trap()
#endif
#else
#error Can not define OPTICK_DEBUG_BREAK. Unknown platform.
#endif
#define OPTICK_UNUSED(x) (void)(x)
#ifdef _DEBUG
#define OPTICK_ASSERT(arg, description) if (!(arg)) { OPTICK_DEBUG_BREAK; }
#define OPTICK_FAILED(description) { OPTICK_DEBUG_BREAK; }
#define OPTICK_VERIFY(arg, description, operation) if (!(arg)) { OPTICK_DEBUG_BREAK; operation; }
#define OPTICK_ASSERT(arg, description) if (!(arg)) { OPTICK_DEBUG_BREAK(description); }
#define OPTICK_FAILED(description) { OPTICK_DEBUG_BREAK(description); }
#define OPTICK_VERIFY(arg, description, operation) if (!(arg)) { OPTICK_DEBUG_BREAK(description); operation; }
#else
#define OPTICK_ASSERT(arg, description)
#define OPTICK_FAILED(description) { throw std::runtime_error(description); }
#define OPTICK_VERIFY(arg, description, operation) if (!(arg)) { printf("%s\n", description); operation; }
#define OPTICK_FAILED(description) { std::cerr << "Optick FATAL ERROR: " << description << std::endl; throw std::runtime_error("Optick FAILED"); }
#define OPTICK_VERIFY(arg, description, operation) if (!(arg)) { std::cerr << "Optick ERROR: " << description << std::endl; operation; }
#endif
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Expand Down
4 changes: 2 additions & 2 deletions src/optick_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ class Socket
return true;
}

#if defined(_WIN32)
#if defined(USE_WINDOWS_SOCKETS)
int Receive(char *buf, int len)
#else
ssize_t Receive(char *buf, int len)
Expand Down Expand Up @@ -308,7 +308,7 @@ void Server::Update()
if (!InitConnection())
return;

#if defined(_WIN32)
#if defined(USE_WINDOWS_SOCKETS)
int length = -1;
#else
ssize_t length = -1;
Expand Down

0 comments on commit a697a00

Please sign in to comment.