/
trace.c
52 lines (45 loc) · 1.08 KB
/
trace.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/* Tracing tool
* Ben Matthews <ben@kc2vjw.com>
* compile your code with gcc -g -finstrument-functions
* -O0 is also a good idea
* and link with this file
*/
#include <stdio.h>
#include <execinfo.h>
#include <string.h>
#include <stdlib.h>
/* This function (more or less) stolen from GNU Libc
* documentation
* Obtain a backtrace (uncomment for loop to display
* entire backtrace
*/
void
__attribute__((__no_instrument_function__))
print_trace (void)
{
void *array[1000];
size_t size;
char **strings;
size_t i;
size = backtrace (array, 1000);
strings = backtrace_symbols (array, size);
// for (i = 0; i < size; i++)
//printf ("%s\n", strings[i]);
printf ("funcall: %s\n", strings[2]);
free (strings);
}
/* Called when functions enter */
void
__attribute__((__no_instrument_function__))
__cyg_profile_func_enter(void* this_function, void* call_site)
{
print_trace();
(void) call_site;
}
/* Called at when functions return() */
void
__attribute__((__no_instrument_function__))
__cyg_profile_func_exit(void* this_function, void* call_site)
{
(void) call_site;
}