My Project
Loading...
Searching...
No Matches
omRet2Info.h File Reference

Go to the source code of this file.

Data Structures

struct  omRetInfo_t

Macros

#define omPrintCurrentBackTrace(fd)
#define omFilterRetInfo(info, max, cond)

Functions

int omPrintRetInfo (omRetInfo info, int max, FILE *fd, const char *fmt)
int omBackTrace_2_RetInfo (void **bt, omRetInfo info, int max)
void omInitRet_2_Info (const char *argv0)
int omPrintBackTrace (void **bt, int max, FILE *fd)
int omPrintCurrentBackTraceMax (FILE *fd, int max)
int omFilterRetInfo_i (omRetInfo info, int max, int i)
int _omPrintBackTrace (void **bt, int max, FILE *fd, OM_FLR_DECL)
int _omPrintCurrentBackTrace (FILE *fd, OM_FLR_DECL)

Data Structure Documentation

◆ omRetInfo_s

struct omRetInfo_s

Definition at line 11 of file omRet2Info.h.

Data Fields
void * addr
char file[200]
char func[200]
int line

Macro Definition Documentation

◆ omFilterRetInfo

#define omFilterRetInfo ( info,
max,
cond )
Value:
do \
{ \
int _max = max; \
int _i = max -1; \
while (_i > 0) \
{ \
void* addr_i = info[_i].addr; \
char* file_i = info[_i].file; \
char* func_i = info[_i].func; \
int line_i = info[_i].line; \
\
if (cond) \
_i--; \
} \
} \
while (0)
static int max(int a, int b)
Definition fast_mult.cc:264
#define info
Definition libparse.cc:1256
int omFilterRetInfo_i(omRetInfo info, int max, int i)
Definition omRet2Info.c:182

Definition at line 44 of file omRet2Info.h.

44#define omFilterRetInfo(info, max, cond) \
45do \
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} \
61while (0)

◆ omPrintCurrentBackTrace

#define omPrintCurrentBackTrace ( fd)
Value:
int status int fd
Definition si_signals.h:69
#define omPrintCurrentBackTraceMax(A, B)
Definition xalloc.h:265

Definition at line 39 of file omRet2Info.h.

Function Documentation

◆ _omPrintBackTrace()

int _omPrintBackTrace ( void ** bt,
int max,
FILE * fd,
OM_FLR_DECL  )

Definition at line 201 of file omRet2Info.c.

202{
203#ifndef __OPTIMIZE__
204 int i = 0;
205
206 omRetInfo_t info[OM_MAX_BACKTRACE_DEPTH];
208 if (bt != NULL)
209 {
210 for (; i<max; i++)
211 {
212 if (bt[i] == NULL)
213 {
214 max = i+1;
215 break;
216 }
217 }
219 }
220#ifdef OM_TRACK_RETURN
221 if (i == 0)
222 i = omBackTrace_2_RetInfo(((void*)&r),info, 1);
223#endif
224#ifndef OM_INTERNAL_DEBUG
225 if (i > 1)
226 {
227#ifdef OM_TRACK_RETURN
228 if (r != NULL)
229 omFilterRetInfo(info, i, addr_i == r);
230#endif
231#ifdef OM_TRACK_FILE_LINE
232 if (f != NULL && l > 0)
233 omFilterRetInfo(info, i, strcmp(f, file_i) == 0 && l + 2 >= line_i && l - 2 <= line_i);
234#endif
235 /* if we have both, use overwrite what we got from return addressse --
236 they sometimes are wrong */
237#if defined(OM_TRACK_RETURN) && defined(OM_TRACK_FILE_LINE)
238 if (r != NULL && info[0].addr == r && l > 0 && f != 0)
239 {
240 strcpy(info[0].file, f);
241 info[0].line = l;
242 }
243#endif
244 }
245 if (i == 0)
246 {
247#endif /* ! OM_INTERNAL_DEBUG */
248
249#ifdef OM_TRACK_FILE_LINE
250 fprintf(fd, " %s:%d", f, l);
251#endif
252#ifdef OM_TRACK_RETURN
253 fprintf(fd," ra=%p", r);
254#endif
255
256#ifndef OM_INTERNAL_DEBUG
257 return 1;
258 }
259 else
260#endif /* ! OM_INTERNAL_DEBUG */
261#ifdef OM_PRINT_RETURN_ADDRESS
262 return omPrintRetInfo(info, i, fd, "\n #%i at %L in %N ra=%p");
263#else
264 return omPrintRetInfo(info, i, fd, "\n #%i at %L in %N");
265#endif
266#else
267 return 0;
268#endif
269}
int l
Definition cfEzgcd.cc:100
int i
Definition cfEzgcd.cc:132
FILE * f
Definition checklibs.c:9
#define NULL
Definition omList.c:12
int omPrintRetInfo(omRetInfo info, int max, FILE *fd, const char *fmt)
Definition omRet2Info.c:100
int omBackTrace_2_RetInfo(void **bt, omRetInfo info, int max)
Definition omRet2Info.c:46
#define OM_MAX_BACKTRACE_DEPTH
Definition omRet2Info.c:31
#define omFilterRetInfo(info, max, cond)
Definition omRet2Info.h:44

◆ _omPrintCurrentBackTrace()

int _omPrintCurrentBackTrace ( FILE * fd,
OM_FLR_DECL  )

Definition at line 271 of file omRet2Info.c.

272{
273#ifdef __OPTIMIZE__
274 /* does not work without -g */
275 return 0;
276#else
277 int i;
278 void* bt[OM_MAX_BACKTRACE_DEPTH];
279
281 return _omPrintBackTrace(bt, i, fd , OM_FLR_VAL);
282#endif
283}
#define omGetBackTrace(bt, s, max)
int _omPrintBackTrace(void **bt, int max, FILE *fd, OM_FLR_DECL)
Definition omRet2Info.c:201

◆ omBackTrace_2_RetInfo()

int omBackTrace_2_RetInfo ( void ** bt,
omRetInfo info,
int max )

Definition at line 46 of file omRet2Info.c.

47{
48 int i=0, j=0, filled = 0;
49 if (max <= 0 || bt == NULL || info == NULL) return 0;
51 memset(info, 0, max*sizeof(omRetInfo_t));
52 while (i<max)
53 {
54 if (bt[i])
55 {
56 info[j].addr = bt[i];
57 j++;
58 }
59 i++;
60 }
61 if (j == 0) return 0;
62
63#if defined(HAVE_POPEN) && defined(OM_PROG_ADDR2LINE)
64 if (*om_this_prog != '\0')
65 {
66 char command[2*MAXPATHLEN + 15 + OM_MAX_BACKTRACE_DEPTH*(2*SIZEOF_VOIDP + 4)];
67 FILE *pipe;
68 int l;
69 l = snprintf(command,2*MAXPATHLEN + 15 + OM_MAX_BACKTRACE_DEPTH*(2*SIZEOF_VOIDP + 4),
70 "%s -s -C -f -e %s",
71 OM_PROG_ADDR2LINE, om_this_prog);
72 i=0;
73 while (i<j)
74 {
75 l+=sprintf(&command[l], " %p", info[i].addr);
76 i++;
77 }
78 fflush(NULL);
79 pipe = popen(command, "r");
80 if (pipe != NULL)
81 {
82 /* An output entry of addr2line looks as follows:
83FunctionName
84File:Line
85 */
86 while ((filled < j) &&
87 (fscanf(pipe, "%200[^\n]\n%200[^:]:%d\n", info[filled].func, info[filled].file, &(info[filled].line)) == 3))
88 {
89 if (*info[filled].func != '?' && *info[filled].file != '?' && info[filled].line > 0)
90 filled++;
91 }
92 pclose(pipe);
93 }
94 return filled;
95 }
96#endif
97 return j;
98}
int j
Definition facHensel.cc:110
ip_command * command
Definition ipid.h:23
static char om_this_prog[MAXPATHLEN]
Definition omRet2Info.c:28
#define MAXPATHLEN
Definition omRet2Info.c:22

◆ omFilterRetInfo_i()

int omFilterRetInfo_i ( omRetInfo info,
int max,
int i )

Definition at line 182 of file omRet2Info.c.

183{
184 int j=0, k=i;
185
186 while (k < max)
187 {
188 info[j] = info[k];
189 j++;
190 k++;
191 }
192 return j;
193}
int k
Definition cfEzgcd.cc:99

◆ omInitRet_2_Info()

void omInitRet_2_Info ( const char * argv0)

Definition at line 34 of file omRet2Info.c.

35{
36// char buf[MAXPATHLEN];
37
38 if (argv0 != NULL) // // && omFindExec(argv0, buf))
39 {
40 strncpy(om_this_prog, argv0, MAXPATHLEN); // // buf);
41 om_this_prog[MAXPATHLEN - 1]= '\0';
42 }
43}
char * argv0

◆ omPrintBackTrace()

int omPrintBackTrace ( void ** bt,
int max,
FILE * fd )

Definition at line 151 of file omRet2Info.c.

152{
153 int i;
154
155 omRetInfo_t info[OM_MAX_BACKTRACE_DEPTH];
157
159#ifdef OM_PRINT_RETURN_ADDRESS
160 return omPrintRetInfo(info, i, fd, " #%i at %L in %N ra=%p\n");
161#else
162 return omPrintRetInfo(info, i, fd, " #%i at %L in %N\n");
163#endif
164}

◆ omPrintCurrentBackTraceMax()

int omPrintCurrentBackTraceMax ( FILE * fd,
int max )

Definition at line 166 of file omRet2Info.c.

167{
168 int i;
169 void* bt[OM_MAX_BACKTRACE_DEPTH];
172 if (max <= 0) return 0;
173 i = omGetBackTrace(bt, 1, max);
174 return omPrintBackTrace(bt, i, fd);
175}
int omPrintBackTrace(void **bt, int max, FILE *fd)
Definition omRet2Info.c:151

◆ omPrintRetInfo()

int omPrintRetInfo ( omRetInfo info,
int max,
FILE * fd,
const char * fmt )

Definition at line 100 of file omRet2Info.c.

101{
102 int i = 0;
103 if (max <= 0 || info == NULL || fmt == NULL || fd == NULL) return 0;
104 while (i < max && info[i].addr != NULL)
105 {
106 int l = 0;
107 while (fmt[l] != 0)
108 {
109 if (fmt[l] == '%')
110 {
111 l++;
112 if (fmt[l] == 'p') fprintf(fd, "%p", info[i].addr);
113 else if (fmt[l] == 'f') fprintf(fd, "%-20s", (*info[i].file != '\0' ? info[i].file : "??"));
114 else if (fmt[l] == 'F') fprintf(fd, "%-20s", (*info[i].func != '\0' ? info[i].func : "??"));
115 else if (fmt[l] == 'l') fprintf(fd, "%d", info[i].line);
116 else if (fmt[l] == 'N')
117 {
118 if (*info[i].func != '\0')
119 {
120 char* found = (char*) strchr(info[i].func, '(');
121 if (found) *found = '\0';
122 fprintf(fd, "%-20s", info[i].func);
123 if (found) *found = '(';
124 }
125 else
126 fprintf(fd, "%-20s", "??");
127 }
128 else if (fmt[l] == 'L')
129 {
130 int n = fprintf(fd, "%s:%d", (*info[i].func != '\0' ? info[i].file : "??"), info[i].line);
131 if (n < 20) fprintf(fd, "%*s", 20-n, " ");
132 }
133 else if (fmt[l] == 'i') fprintf(fd, "%d", i);
134 else
135 {
136 fputc('%', fd);
137 l--;
138 }
139 }
140 else
141 {
142 fputc(fmt[l], fd);
143 }
144 l++;
145 }
146 i++;
147 }
148 return i;
149}
bool found