79 const u32 hash =
fnv_hash(tag, wcslen(tag)*
sizeof(tag[0]));
98 const u32 hash =
fnv_hash(tag, wcslen(tag)*
sizeof(tag[0]));
100 for(
size_t i = 0; i <
MAX_TAGS; i++)
125 if(text[i] ==
' ' || text[i] ==
'\0')
127 if(text[i] ==
'|' && i != 0)
131 const u32 hash =
fnv_hash(text, i*
sizeof(text[0]));
141 #undef debug_printf // allowing #defining it out
174 static volatile intptr_t
state;
184 DEBUG_DISPLAY_ERROR(L
"Unable to open crashlog.txt for writing (please ensure the log directory is writable)");
189 fwprintf(f, L
"%ls\n", text);
190 fwprintf(f, L
"\n\n====================================\n\n");
250 const size_t len = wcslen(
m_pos);
263 const wchar_t* description,
264 const wchar_t* filename,
int line,
const char* func,
265 void* context,
const wchar_t* lastFuncToSkip,
270 wchar_t description_buf[100] = L
"?";
271 wchar_t os_error[100] = L
"?";
279 wchar_t*
const buf = (
wchar_t*)emm->
pa_mem;
281 return L
"(insufficient memory to generate error message)";
287 L
"Location: %ls:%d (%hs)\r\n"
291 description, filename, line, func
295 return L
"(error while formatting error message)";
303 L
"While generating an error report, we encountered a second "
304 L
"problem. Please be sure to report both this and the subsequent "
311 wchar_t error_buf[100] = {
'?'};
313 L
"(error while dumping stack: %ls)",
326 L
"errno = %d (%ls)\r\n"
327 L
"OS error = %ls\r\n",
328 errno, description_buf, os_error
395 if(shouldHandleBreak)
427 size_t flags,
void* context,
const wchar_t* lastFuncToSkip,
428 const wchar_t* pathname,
int line,
const char* func,
452 if(!pathname || pathname[0] ==
'\0')
453 pathname = L
"unknown";
456 if(!func || func[0] ==
'\0')
463 debug_printf(L
"%ls(%d): %ls\n", filename, line, description);
466 const wchar_t* text =
debug_BuildErrorMessage(description, filename, line, func, context, lastFuncToSkip, &emm);
542 const wchar_t* lastFuncToSkip = L
"debug_OnError";
545 swprintf_s(buf,
ARRAY_SIZE(buf), L
"Function call failed: return value was %lld (%ls)", (
long long)err, err_buf);
555 const std::wstring lastFuncToSkip = L
"debug_OnAssertionFailure";
static intptr_t skipStatus
LIB_API void debug_puts(const wchar_t *text)
[system-dependent] write a string to the debug channel.
static ErrorReactionInternal CallDisplayError(const wchar_t *text, size_t flags)
static const size_t messageSize
const wchar_t * debug_BuildErrorMessage(const wchar_t *description, const wchar_t *filename, int line, const char *func, void *context, const wchar_t *lastFuncToSkip, ErrorMessageMem *emm)
build a string describing the given error.
#define COMPILER_FENCE
prevent the compiler from reordering loads or stores across this point.
const Status SYM_UNSUPPORTED
static const size_t MAX_TAGS
const Status SYM_SUPPRESS_OUTPUT
ErrorReaction debug_DisplayError(const wchar_t *description, size_t flags, void *context, const wchar_t *lastFuncToSkip, const wchar_t *pathname, int line, const char *func, atomic_bool *suppress)
display an error dialog with a message and stack trace.
wchar_t * Position() const
enable the Suppress button.
special return value for the display_error app hook stub to indicate that it has done nothing and tha...
ErrorReactionInternal sys_display_error(const wchar_t *text, size_t flags)
show the error dialog.
ErrorReaction
choices offered by the error dialog that are returned by debug_DisplayError.
const Status SYM_CHILD_NOT_FOUND
int swprintf_s(wchar_t *buf, size_t max_chars, const wchar_t *fmt,...) WPRINTF_ARGS(3)
Status debug_WriteCrashlog(const wchar_t *text)
write an error description and all logs into crashlog.txt (in unicode format).
const Status SYM_UNRETRIEVABLE_STATIC
FILE * sys_OpenFile(const OsPath &pathname, const char *mode)
open a file like with fopen (but taking an OsPath argument).
LIB_API Status debug_CaptureContext(void *context)
const Status SYM_UNRETRIEVABLE
exit the program immediately.
Status sys_StatusDescription(int err, wchar_t *buf, size_t max_chars)
describe the current OS error state.
volatile intptr_t atomic_bool
a bool that is reasonably certain to be set atomically.
void wdbg_heap_Enable(bool enable)
enable or disable manual and automatic heap validity checking.
const Status SYM_NO_STACK_FRAMES_FOUND
display just the given message; do not add any information about the call stack, do not write crashlo...
static const atomic_bool DEBUG_SUPPRESS
value for suppress flag once set by debug_DisplayError.
bool debug_filter_allows(const wchar_t *text)
indicate if the given text would be printed.
void debug_filter_clear()
clear all filter state; equivalent to debug_filter_remove for each tag that was debug_filter_add-ed.
void sys_display_msg(const wchar_t *caption, const wchar_t *msg)
display a message.
void debug_DisplayMessage(const wchar_t *caption, const wchar_t *msg)
translates and displays the given strings in a dialog.
ErrorReactionInternal ah_display_error(const wchar_t *text, size_t flags)
display an error dialog, thus overriding sys_display_error.
void debug_filter_add(const wchar_t *tag)
debug output is very useful, but "too much of a good thing can kill you".
const Status SYM_TYPE_INFO_UNAVAILABLE
i64 Status
Error handling system.
void debug_break()
trigger a breakpoint when reached/"called".
PrintfWriter(wchar_t *buf, size_t maxChars)
#define STATUS_ADD_DEFINITIONS(definitions)
add a module's array of StatusDefinition to the list.
do not trigger a breakpoint inside debug_DisplayError; caller will take care of this if ER_BREAK is r...
#define DEBUG_WARN_ERR(status)
display the error dialog with text corresponding to the given error code.
u32 fnv_hash(const void *buf, size_t len)
rationale: this algorithm was chosen because it delivers 'good' results for string data and is relati...
#define WPRINTF_ARGS(fmtpos)
static Status errorToSkip
ignore and do not report again.
static ErrorReaction PerformErrorReaction(ErrorReactionInternal er, size_t flags, atomic_bool *suppress)
void debug_FreeErrorMessage(ErrorMessageMem *emm)
free memory from the error message.
ErrorReaction debug_OnError(Status err, atomic_bool *suppress, const wchar_t *file, int line, const char *func)
called when a DEBUG_WARN_ERR indicates an error occurred; notifies the user via debug_DisplayError.
const Status SYM_INTERNAL_ERROR
bool cpu_CAS(volatile intptr_t *location, intptr_t expected, intptr_t newValue)
atomic "compare and swap".
static bool ShouldSuppressError(atomic_bool *suppress)
wchar_t * StatusDescription(Status status, wchar_t *buf, size_t max_chars)
generate textual description of a Status.
holds memory for an error message.
const wchar_t * path_name_only(const wchar_t *path)
Get the path component of a path.
size_t debug_StopSkippingErrors()
bool operator()(const wchar_t *fmt,...) WPRINTF_ARGS(2)
#define DEBUG_DISPLAY_ERROR(description)
void * Allocate(size_t size, PageType pageType, int prot)
reserve address space and commit memory.
static const size_t DEBUG_CONTEXT_SIZE
void debug_filter_remove(const wchar_t *tag)
in future, discard output with the given tag.
const OsPath & ah_get_log_dir()
return path to directory into which crash dumps should be written.
const Status SYM_NESTING_LIMIT
static const StatusDefinition debugStatusDefinitions[]
#define CACHE_ALIGNED(type)
#define cassert(expr)
Compile-time assertion.
const Status SYM_SINGLE_SYMBOL_LIMIT
static u32 tags[MAX_TAGS]
ErrorReaction debug_OnAssertionFailure(const wchar_t *expr, atomic_bool *suppress, const wchar_t *file, int line, const char *func)
called when a ENSURE/ASSERT fails; notifies the user via debug_DisplayError.
static bool ShouldSkipError(Status err)
void Free(void *p, size_t size)
decommit memory and release address space.
int vswprintf_s(wchar_t *dst, size_t max_dst_chars, const wchar_t *fmt, va_list ap) VWPRINTF_ARGS(3)
static atomic_bool isExiting
void debug_printf(const wchar_t *fmt,...)
write a formatted string to the debug channel, subject to filtering (see below).
ignore, continue as if nothing happened.
LIB_API Status debug_DumpStack(wchar_t *buf, size_t maxChars, void *context, const wchar_t *lastFuncToSkip)
write a complete stack trace (including values of local variables) into the specified buffer...
const wchar_t * ah_translate(const wchar_t *text)
translate text to the current locale.
ErrorReactionInternal
all choices offered by the error dialog.
void ah_bundle_logs(FILE *f)
gather all app-related logs/information and write it to file.
void debug_SkipErrors(Status err)
suppress (prevent from showing) the error dialog from subsequent debug_OnError for the given Status...