Skip to content

Commit

Permalink
add a show_backtrace function for debugging.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dave Jones committed Dec 12, 2013
1 parent 33a5f45 commit 20e3caa
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#define MB (1024 * 1024UL)
#define GB (1024 * MB)

void show_backtrace(void);

void * zmalloc(size_t size);

#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
Expand Down
23 changes: 23 additions & 0 deletions utils.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,31 @@
#include <execinfo.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include "utils.h"

void show_backtrace(void)
{
int j, nptrs;
#define SIZE 100
void *buffer[100];
char **strings;

nptrs = backtrace(buffer, SIZE);

strings = backtrace_symbols(buffer, nptrs);
if (strings == NULL) {
perror("backtrace_symbols");
exit(EXIT_FAILURE);
}

for (j = 0; j < nptrs; j++)
printf("%s\n", strings[j]);

free(strings);
}

void * zmalloc(size_t size)
{
void *p;
Expand Down

0 comments on commit 20e3caa

Please sign in to comment.