Skip to content

Commit

Permalink
#341 Allow setting breakpoints on memory traces
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderMertens committed Jan 16, 2016
1 parent c323166 commit 23af99e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/corto/include/corto.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ extern int8_t CORTO_DEBUG_ENABLED;
extern corto_string CORTO_TRACE_OBJECT;
extern int8_t CORTO_TRACE_NOTIFICATIONS;
extern int8_t CORTO_BACKTRACE_ENABLED;
extern int32_t CORTO_MEMTRACE_BREAKPOINT;
/* $end */

#ifdef __cplusplus
}
#endif
#endif

3 changes: 3 additions & 0 deletions packages/corto/src/corto.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ int8_t CORTO_TRACE_NOTIFICATIONS = 0;
/* When set, the core adds backtraces to memory tracing */
int8_t CORTO_BACKTRACE_ENABLED = 0;

/* When set, the core will break at the specified id */
int32_t CORTO_MEMTRACE_BREAKPOINT;

/*
* Indicator for whether corto is operational
* 0 = running
Expand Down
15 changes: 13 additions & 2 deletions packages/corto/src/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ static corto_observerAdmin observerAdmin[CORTO_MAX_THREADS];
/* Stack for tracing memory management operations */
static corto_string memtrace[50];
static corto_int8 memtraceSp = 0;
static corto_int8 memtraceCount = 0;

static struct corto_observerAdmin* corto_observerAdminGet(void) {
corto_observerAdmin *admin = corto_threadTlsGet(CORTO_KEY_OBSERVER_ADMIN);
Expand Down Expand Up @@ -253,12 +254,14 @@ static corto_object corto__initScope(corto_object o, corto_string name, corto_ob
corto_seterr(
"%s/init failed", corto_fullpath(NULL, corto_typeof(o)));
}
/* Reset parent so deinitScope won't release it */
scope->parent = NULL;
goto error;
}

/* Add object to the scope of the parent-object */
if (!(result = corto_adopt(parent, o))) {
/* Reset parent */
/* Reset parent so deinitScope won't release it */
scope->parent = NULL;
goto error;
}
Expand Down Expand Up @@ -609,7 +612,10 @@ static void corto_memtrace(corto_string oper, corto_object o, corto_string conte
corto_asprintf(&memtrace[memtraceSp], "%s (%s) %s", path, oper, context ? context : "");

if (!strcmp(path, CORTO_TRACE_OBJECT)) {
printf("%s: %s (count = %d, destructed = %d)\n",
memtraceCount ++;

printf("%d: %s: %s (count = %d, destructed = %d)\n",
memtraceCount,
oper,
path,
corto_countof(o),
Expand All @@ -630,6 +636,11 @@ static void corto_memtrace(corto_string oper, corto_object o, corto_string conte
corto_backtrace(stdout);
}
printf("\n");

if (CORTO_MEMTRACE_BREAKPOINT == memtraceCount) {
printf(" << BREAKPOINT >>\n");
abort();
}
}
}

Expand Down

0 comments on commit 23af99e

Please sign in to comment.