mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-07-08 05:27:35 +02:00
Adding optional stack traces on potential GC misses detected by conservative tracing.
This commit is contained in:
parent
b39fa4d060
commit
74162906f3
4 changed files with 38 additions and 0 deletions
13
gc.c
13
gc.c
|
@ -223,6 +223,18 @@ int stack_references_pointer_p (sexp ctx, sexp x) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if SEXP_USE_TRACK_ALLOC_BACKTRACE
|
||||||
|
void sexp_print_gc_trace(sexp ctx, sexp p) {
|
||||||
|
int i;
|
||||||
|
char **debug_text = backtrace_symbols(p->backtrace, SEXP_BACKTRACE_SIZE);
|
||||||
|
for (i=0; i < SEXP_BACKTRACE_SIZE; i++)
|
||||||
|
fprintf(stderr, SEXP_BANNER(" : %s"), debug_text[i]);
|
||||||
|
free(debug_text);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
#define sexp_print_gc_trace(ctx, p)
|
||||||
|
#endif
|
||||||
|
|
||||||
void sexp_conservative_mark (sexp ctx) {
|
void sexp_conservative_mark (sexp ctx) {
|
||||||
sexp_heap h = sexp_context_heap(ctx);
|
sexp_heap h = sexp_context_heap(ctx);
|
||||||
sexp p, end;
|
sexp p, end;
|
||||||
|
@ -247,6 +259,7 @@ void sexp_conservative_mark (sexp ctx) {
|
||||||
if (p && sexp_pointerp(p)) {
|
if (p && sexp_pointerp(p)) {
|
||||||
fprintf(stderr, SEXP_BANNER("MISS: %p [%d]: %s"), p,
|
fprintf(stderr, SEXP_BANNER("MISS: %p [%d]: %s"), p,
|
||||||
sexp_pointer_tag(p), sexp_pointer_source(p));
|
sexp_pointer_tag(p), sexp_pointer_source(p));
|
||||||
|
sexp_print_gc_trace(ctx, p);
|
||||||
fflush(stderr);
|
fflush(stderr);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -87,6 +87,10 @@
|
||||||
/* uncomment this to track what C source line each object is allocated from */
|
/* uncomment this to track what C source line each object is allocated from */
|
||||||
/* #define SEXP_USE_TRACK_ALLOC_SOURCE 1 */
|
/* #define SEXP_USE_TRACK_ALLOC_SOURCE 1 */
|
||||||
|
|
||||||
|
/* uncomment this to take a short backtrace of where each object is */
|
||||||
|
/* allocated from */
|
||||||
|
/* #define SEXP_USE_TRACK_ALLOC_BACKTRACE 1 */
|
||||||
|
|
||||||
/* uncomment this to add additional native gc checks to verify a magic header */
|
/* uncomment this to add additional native gc checks to verify a magic header */
|
||||||
/* #define SEXP_USE_HEADER_MAGIC 1 */
|
/* #define SEXP_USE_HEADER_MAGIC 1 */
|
||||||
|
|
||||||
|
@ -372,6 +376,14 @@
|
||||||
#define SEXP_USE_TRACK_ALLOC_SOURCE SEXP_USE_DEBUG_GC > 2
|
#define SEXP_USE_TRACK_ALLOC_SOURCE SEXP_USE_DEBUG_GC > 2
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef SEXP_USE_TRACK_ALLOC_BACKTRACE
|
||||||
|
#define SEXP_USE_TRACK_ALLOC_BACKTRACE SEXP_USE_TRACK_ALLOC_SOURCE
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef SEXP_BACKTRACE_SIZE
|
||||||
|
#define SEXP_BACKTRACE_SIZE 3
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef SEXP_USE_HEADER_MAGIC
|
#ifndef SEXP_USE_HEADER_MAGIC
|
||||||
#define SEXP_USE_HEADER_MAGIC 0
|
#define SEXP_USE_HEADER_MAGIC 0
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -75,6 +75,10 @@ typedef unsigned long size_t;
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if SEXP_USE_TRACK_ALLOC_BACKTRACE
|
||||||
|
#include <execinfo.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
@ -294,6 +298,7 @@ struct sexp_struct {
|
||||||
unsigned int syntacticp:1;
|
unsigned int syntacticp:1;
|
||||||
#if SEXP_USE_TRACK_ALLOC_SOURCE
|
#if SEXP_USE_TRACK_ALLOC_SOURCE
|
||||||
const char* source;
|
const char* source;
|
||||||
|
void* backtrace[SEXP_BACKTRACE_SIZE];
|
||||||
#endif
|
#endif
|
||||||
#if SEXP_USE_HEADER_MAGIC
|
#if SEXP_USE_HEADER_MAGIC
|
||||||
unsigned int magic;
|
unsigned int magic;
|
||||||
|
|
8
sexp.c
8
sexp.c
|
@ -62,11 +62,19 @@ sexp sexp_push_op(sexp ctx, sexp* loc, sexp x) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
sexp sexp_alloc_tagged_aux(sexp ctx, size_t size, sexp_uint_t tag sexp_current_source_param) {
|
sexp sexp_alloc_tagged_aux(sexp ctx, size_t size, sexp_uint_t tag sexp_current_source_param) {
|
||||||
|
#if SEXP_USE_TRACK_ALLOC_BACKTRACE
|
||||||
|
int i;
|
||||||
|
void* trace[SEXP_BACKTRACE_SIZE + 1];
|
||||||
|
#endif
|
||||||
sexp res = (sexp) sexp_alloc(ctx, size);
|
sexp res = (sexp) sexp_alloc(ctx, size);
|
||||||
if (res && ! sexp_exceptionp(res)) {
|
if (res && ! sexp_exceptionp(res)) {
|
||||||
sexp_pointer_tag(res) = tag;
|
sexp_pointer_tag(res) = tag;
|
||||||
#if SEXP_USE_TRACK_ALLOC_SOURCE
|
#if SEXP_USE_TRACK_ALLOC_SOURCE
|
||||||
sexp_pointer_source(res) = source;
|
sexp_pointer_source(res) = source;
|
||||||
|
#if SEXP_USE_TRACK_ALLOC_BACKTRACE
|
||||||
|
backtrace(trace, SEXP_BACKTRACE_SIZE + 1);
|
||||||
|
for (i=0; i<SEXP_BACKTRACE_SIZE; i++) res->backtrace[i] = trace[i+1];
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#if SEXP_USE_HEADER_MAGIC
|
#if SEXP_USE_HEADER_MAGIC
|
||||||
sexp_pointer_magic(res) = SEXP_POINTER_MAGIC;
|
sexp_pointer_magic(res) = SEXP_POINTER_MAGIC;
|
||||||
|
|
Loading…
Add table
Reference in a new issue