Skip to content

Commit

Permalink
(core) Cleans up trace state on crash recovery
Browse files Browse the repository at this point in the history
  • Loading branch information
cipharius committed Oct 7, 2023
1 parent 6d0bd6c commit 5a5219b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 13 deletions.
5 changes: 5 additions & 0 deletions src/engine/arcan_general.h
Expand Up @@ -175,6 +175,11 @@ void arcan_trace_setbuffer(uint8_t* buf, size_t buf_sz, bool* finish_flag);
*/
void arcan_trace_log(const char* message, size_t len);

/*
* cleans up trace buffer and tracy zones
*/
void arcan_trace_close();

/* add a trace entry-point (though call through the TRACE_MARK macros),
* sys returns to the main system group (graphics, video, 3d, ...) and
* subsys for a group specific subsystem (where useful distinctions exist).
Expand Down
8 changes: 8 additions & 0 deletions src/engine/arcan_main.c
Expand Up @@ -608,6 +608,10 @@ int MAIN_REDIR(int argc, char* argv[])
arcan_lua_cbdrop();
arcan_lua_shutdown(main_lua_context);

const char trace_msg[] = "Switching appls, resetting trace";
arcan_trace_log(trace_msg, sizeof(trace_msg));
arcan_trace_close();

/* mask off errors so shutdowns etc. won't queue new events that enter
* the event queue and gets exposed to the new appl */
arcan_event_maskall(evctx);
Expand Down Expand Up @@ -676,6 +680,10 @@ int MAIN_REDIR(int argc, char* argv[])
if (strcmp(fallback, ":self") == 0)
fallback = argv[optind];

const char trace_msg[] = "Recovering from crash, resetting trace";
arcan_trace_log(trace_msg, sizeof(trace_msg));
arcan_trace_close();

if (!arcan_verifyload_appl(fallback, &errmsg)){
arcan_warning("Lua VM error fallback, failure loading (%s), reason: %s\n",
fallback, errmsg);
Expand Down
30 changes: 17 additions & 13 deletions src/engine/arcan_trace.c
Expand Up @@ -43,19 +43,6 @@ void arcan_trace_setbuffer(uint8_t* buf, size_t buf_sz, bool* finish_flag)
arcan_trace_enabled = true;
}

static bool append_string(const char* str)
{
do {
buffer[buffer_pos++] = *str++;

if (buffer_pos == buffer_sz)
return false;

} while (*str);

return true;
}

void arcan_trace_log(const char* message, size_t len)
{
if (!arcan_trace_enabled)
Expand Down Expand Up @@ -344,3 +331,20 @@ void arcan_trace_mark(
*buffer_flag = true;
buffer[start_ofs] = 0xaa;
}

void arcan_trace_close()
{
if (!arcan_trace_enabled)
return;

#ifdef WITH_TRACY
for (int i=tracy_ctx.zone_stack_len-1; i>=0; --i) {
___tracy_emit_zone_end(tracy_ctx.zone_stack[i].ctx);
}
tracy_ctx.zone_stack_len = 0;
tracy_ctx.mark_ids_len = 0;
#endif

// Releases trace buffer if it exists
arcan_trace_setbuffer(buffer, 0, NULL);
}

0 comments on commit 5a5219b

Please sign in to comment.