gallium/util: clean up stack frame printing

Prep work for next patch.

Ideally 'struct debug_stack_frame' would be opaque, but it is embedded
in a bunch of places.  But at least we can treat it opaquely.

Signed-off-by: Rob Clark <robdclark@gmail.com>
This commit is contained in:
Rob Clark 2017-03-24 15:04:58 -04:00
parent 0c0b29591c
commit c3c884c49c
3 changed files with 26 additions and 23 deletions

View file

@ -134,18 +134,6 @@ debug_serial_delete(void *p)
#define STACK_LEN 64
static void
dump_stack(const char *symbols[STACK_LEN])
{
unsigned i;
for (i = 0; i < STACK_LEN; ++i) {
if (symbols[i])
fprintf(stream, "%s\n", symbols[i]);
}
fprintf(stream, "\n");
}
/**
* Log a reference count change to the log file (if enabled).
* This is called via the pipe_reference() and debug_reference() functions,
@ -180,7 +168,6 @@ debug_reference_slowpath(const struct pipe_reference *p,
if (debug_refcnt_state > 0) {
struct debug_stack_frame frames[STACK_LEN];
const char *symbols[STACK_LEN];
char buf[1024];
unsigned i;
unsigned refcnt = p->count;
@ -188,18 +175,12 @@ debug_reference_slowpath(const struct pipe_reference *p,
boolean existing = debug_serial((void *) p, &serial);
debug_backtrace_capture(frames, 1, STACK_LEN);
for (i = 0; i < STACK_LEN; ++i) {
if (frames[i].function)
symbols[i] = debug_symbol_name_cached(frames[i].function);
else
symbols[i] = 0;
}
get_desc(buf, p);
if (!existing) {
fprintf(stream, "<%s> %p %u Create\n", buf, (void *) p, serial);
dump_stack(symbols);
debug_backtrace_print(stream, frames, STACK_LEN);
/* this is here to provide a gradual change even if we don't see
* the initialization
@ -207,20 +188,20 @@ debug_reference_slowpath(const struct pipe_reference *p,
for (i = 1; i <= refcnt - change; ++i) {
fprintf(stream, "<%s> %p %u AddRef %u\n", buf, (void *) p,
serial, i);
dump_stack(symbols);
debug_backtrace_print(stream, frames, STACK_LEN);
}
}
if (change) {
fprintf(stream, "<%s> %p %u %s %u\n", buf, (void *) p, serial,
change > 0 ? "AddRef" : "Release", refcnt);
dump_stack(symbols);
debug_backtrace_print(stream, frames, STACK_LEN);
}
if (!refcnt) {
debug_serial_delete((void *) p);
fprintf(stream, "<%s> %p %u Destroy\n", buf, (void *) p, serial);
dump_stack(symbols);
debug_backtrace_print(stream, frames, STACK_LEN);
}
fflush(stream);

View file

@ -162,3 +162,20 @@ debug_backtrace_dump(const struct debug_stack_frame *backtrace,
}
}
void
debug_backtrace_print(FILE *f,
const struct debug_stack_frame *backtrace,
unsigned nr_frames)
{
unsigned i;
for (i = 0; i < nr_frames; ++i) {
const char *symbol;
if (!backtrace[i].function)
break;
symbol = debug_symbol_name_cached(backtrace[i].function);
if (symbol)
fprintf(f, "%s\n", symbol);
}
}

View file

@ -28,6 +28,7 @@
#ifndef U_DEBUG_STACK_H_
#define U_DEBUG_STACK_H_
#include <stdio.h>
/**
* @file
@ -64,6 +65,10 @@ void
debug_backtrace_dump(const struct debug_stack_frame *backtrace,
unsigned nr_frames);
void
debug_backtrace_print(FILE *f,
const struct debug_stack_frame *backtrace,
unsigned nr_frames);
#ifdef __cplusplus
}