1 | /******************************************************************* |
---|
2 | * File: omAddr2Info.h |
---|
3 | * Purpose: translation of return addr to RetInfo |
---|
4 | * Author: obachman (Olaf Bachmann) |
---|
5 | * Created: 11/99 |
---|
6 | *******************************************************************/ |
---|
7 | #ifndef OM_RET_2_INFO_H |
---|
8 | #define OM_RET_2_INFO_H |
---|
9 | |
---|
10 | |
---|
11 | struct omRetInfo_s |
---|
12 | { |
---|
13 | void* addr; |
---|
14 | char func[200]; /* if you change these numbers, alos change */ |
---|
15 | char file[200]; /* the fscanf statement in BackTrace_2_RetInfo */ |
---|
16 | int line; |
---|
17 | }; |
---|
18 | |
---|
19 | /* print to fd array of max RetInfo's and use fmt as format string for one RetInfo. |
---|
20 | The following conversions are recognized: |
---|
21 | %i -- number of return addr |
---|
22 | %p -- address (in hex) |
---|
23 | %F -- function name with arguments (for C++, only) |
---|
24 | %N -- funtion name without arguments |
---|
25 | %f -- file |
---|
26 | %l -- line |
---|
27 | %L -- file:line |
---|
28 | return how many lines were printed */ |
---|
29 | #ifndef OM_NDEBUG |
---|
30 | int omPrintRetInfo(omRetInfo info, int max, FILE *fd, const char* fmt); |
---|
31 | /* translate array of max BackTrace addresses into array of max RetInfos |
---|
32 | return how many were translated */ |
---|
33 | int omBackTrace_2_RetInfo(void** bt, omRetInfo info, int max); |
---|
34 | |
---|
35 | /* call with argv[0] to enable RetInfo translations */ |
---|
36 | void omInitRet_2_Info(const char* argv0); |
---|
37 | |
---|
38 | int omPrintBackTrace(void** bt, int max, FILE* fd); |
---|
39 | #define omPrintCurrentBackTrace(fd) omPrintCurrentBackTraceMax(fd, 1000) |
---|
40 | int omPrintCurrentBackTraceMax(FILE* fd, int max); |
---|
41 | |
---|
42 | int omFilterRetInfo_i(omRetInfo info, int max, int i); |
---|
43 | |
---|
44 | #define omFilterRetInfo(info, max, cond) \ |
---|
45 | do \ |
---|
46 | { \ |
---|
47 | int _max = max; \ |
---|
48 | int _i = max -1; \ |
---|
49 | while (_i > 0) \ |
---|
50 | { \ |
---|
51 | void* addr_i = info[_i].addr; \ |
---|
52 | char* file_i = info[_i].file; \ |
---|
53 | char* func_i = info[_i].func; \ |
---|
54 | int line_i = info[_i].line; \ |
---|
55 | \ |
---|
56 | if (cond) \ |
---|
57 | max = omFilterRetInfo_i(info, max, _i); \ |
---|
58 | _i--; \ |
---|
59 | } \ |
---|
60 | } \ |
---|
61 | while (0) |
---|
62 | |
---|
63 | |
---|
64 | /*BEGINPRIVATE*/ |
---|
65 | int _omPrintBackTrace(void** bt, int max, FILE* fd , OM_FLR_DECL); |
---|
66 | int _omPrintCurrentBackTrace(FILE* fd , OM_FLR_DECL); |
---|
67 | /*ENDPRIVATE*/ |
---|
68 | |
---|
69 | #else /* OM_NDEBUG */ |
---|
70 | #define omPrintRetInfo(i, max, fd, fmt) do {} while (0) |
---|
71 | #define omBackTrace_2_RetInfo(bt, i, m) do {} while (0) |
---|
72 | #define omInitRet_2_Info(a) do {} while (0) |
---|
73 | #define omPrintBackTrace(bt,max,fd) do {} while (0) |
---|
74 | #define omPrintCurrentBackTrace(fd) do {} while (0) |
---|
75 | #define omPrintCurrentBackTraceMax(fd,max) do {} while (0) |
---|
76 | #define omFilterRetInfo_i(info,max,i) do {} while (0) |
---|
77 | #define omFilterRetInfo(info, max, cond)do {} while (0) |
---|
78 | #endif /* ! OM_NDEBUG */ |
---|
79 | |
---|
80 | #endif /* OM_RET_2_INFO_H */ |
---|