Loading...
Searching...
No Matches
omRet2Info.c File Reference
`#include <stdio.h>`
`#include <string.h>`
`#include "omConfig.h"`
`#include "omDerivedConfig.h"`
`#include "omStructs.h"`
`#include "omRet2Info.h"`
`#include "omGetBackTrace.h"`

Go to the source code of this file.

## Macros

#define | MAXPATHLEN 1024
#define | OM_MAX_BACKTRACE_DEPTH 16

## Functions

void | omInitRet_2_Info (const char *argv0)
int | omBackTrace_2_RetInfo (void **bt, omRetInfo info, int max)
int | omPrintRetInfo (omRetInfo info, int max, FILE *fd, const char *fmt)
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)

## Variables

static char | om_this_prog [MAXPATHLEN] = ""

## Macro Definition Documentation

## MAXPATHLEN

#define MAXPATHLEN 1024

Definition at line 22 of file omRet2Info.c.

## OM_MAX_BACKTRACE_DEPTH

#define OM_MAX_BACKTRACE_DEPTH 16

Definition at line 31 of file omRet2Info.c.

## Function Documentation

## _omPrintBackTrace()

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

Definition at line 201 of file omRet2Info.c.

{
#ifndef __OPTIMIZE__
int i = 0;
omRetInfo_t info[OM_MAX_BACKTRACE_DEPTH];
if (max > OM_MAX_BACKTRACE_DEPTH) max = OM_MAX_BACKTRACE_DEPTH;
if (bt != NULL)
{
for (; i<max; i++)
{
if (bt[i] == NULL)
{
max = i+1;
break;
}
}
i = omBackTrace_2_RetInfo(bt, info, max);
}
#ifdef OM_TRACK_RETURN
if (i == 0)
i = omBackTrace_2_RetInfo(((void*)&r),info, 1);
#endif
#ifndef OM_INTERNAL_DEBUG
if (i > 1)
{
#ifdef OM_TRACK_RETURN
if (r != NULL)
omFilterRetInfo(info, i, addr_i == r);
#endif
#ifdef OM_TRACK_FILE_LINE
if (f != NULL && l > 0)
omFilterRetInfo(info, i, strcmp(f, file_i) == 0 && l + 2 >= line_i && l - 2 <= line_i);
#endif
/* if we have both, use overwrite what we got from return addressse --
they sometimes are wrong */
#if defined(OM_TRACK_RETURN) && defined(OM_TRACK_FILE_LINE)
if (r != NULL && info[0].addr == r && l > 0 && f != 0)
{
strcpy(info[0].file, f);
info[0].line = l;
}
#endif
}
if (i == 0)
{
#endif /* ! OM_INTERNAL_DEBUG */
#ifdef OM_TRACK_FILE_LINE
fprintf(fd, " %s:%d", f, l);
#endif
#ifdef OM_TRACK_RETURN
fprintf(fd," ra=%p", r);
#endif
#ifndef OM_INTERNAL_DEBUG
return 1;
}
else
#endif /* ! OM_INTERNAL_DEBUG */
#ifdef OM_PRINT_RETURN_ADDRESS
return omPrintRetInfo(info, i, fd, "\n #%i at %L in %N ra=%p");
#else
return omPrintRetInfo(info, i, fd, "\n #%i at %L in %N");
#endif
#else
return 0;
#endif
}
l
int l
Definition cfEzgcd.cc:100
i
int i
Definition cfEzgcd.cc:132
f
FILE * f
Definition checklibs.c:9
max
static int max(int a, int b)
Definition fast_mult.cc:264
info
#define info
Definition libparse.cc:1256
NULL
#define NULL
Definition omList.c:12
omPrintRetInfo
int omPrintRetInfo(omRetInfo info, int max, FILE *fd, const char *fmt)
Definition omRet2Info.c:100
omBackTrace_2_RetInfo
int omBackTrace_2_RetInfo(void **bt, omRetInfo info, int max)
Definition omRet2Info.c:46
OM_MAX_BACKTRACE_DEPTH
#define OM_MAX_BACKTRACE_DEPTH
Definition omRet2Info.c:31
omFilterRetInfo
#define omFilterRetInfo(info, max, cond)
Definition omRet2Info.h:44
fd
int status int fd
Definition si_signals.h:69

## _omPrintCurrentBackTrace()

int _omPrintCurrentBackTrace | ( | FILE * | fd,
|  | OM_FLR_DECL | )

Definition at line 271 of file omRet2Info.c.

{
#ifdef __OPTIMIZE__
/* does not work without -g */
return 0;
#else
int i;
void* bt[OM_MAX_BACKTRACE_DEPTH];
i = omGetBackTrace(bt, 1, OM_MAX_BACKTRACE_DEPTH);
return _omPrintBackTrace(bt, i, fd , OM_FLR_VAL);
#endif
}
omGetBackTrace
#define omGetBackTrace(bt, s, max)
Definition omGetBackTrace.h:15
_omPrintBackTrace
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.

{
int i=0, j=0, filled = 0;
if (max <= 0 || bt == NULL || info == NULL) return 0;
if (max > OM_MAX_BACKTRACE_DEPTH) max = OM_MAX_BACKTRACE_DEPTH;
memset(info, 0, max*sizeof(omRetInfo_t));
while (i<max)
{
if (bt[i])
{
info[j].addr = bt[i];
j++;
}
i++;
}
if (j == 0) return 0;
#if defined(HAVE_POPEN) && defined(OM_PROG_ADDR2LINE)
if (*om_this_prog != '\0')
{
char command[2*MAXPATHLEN + 15 + OM_MAX_BACKTRACE_DEPTH*(2*SIZEOF_VOIDP + 4)];
FILE *pipe;
int l;
l = snprintf(command,2*MAXPATHLEN + 15 + OM_MAX_BACKTRACE_DEPTH*(2*SIZEOF_VOIDP + 4),
"%s -s -C -f -e %s",
OM_PROG_ADDR2LINE, om_this_prog);
i=0;
while (i<j)
{
l+=sprintf(&command[l], " %p", info[i].addr);
i++;
}
fflush(NULL);
pipe = popen(command, "r");
if (pipe != NULL)
{
/* An output entry of addr2line looks as follows:
FunctionName
File:Line
*/
while ((filled < j) &&
(fscanf(pipe, "%200[^\n]\n%200[^:]:%d\n", info[filled].func, info[filled].file, &(info[filled].line)) == 3))
{
if (*info[filled].func != '?' && *info[filled].file != '?' && info[filled].line > 0)
filled++;
}
pclose(pipe);
}
return filled;
}
#endif
return j;
}
j
int j
Definition facHensel.cc:110
command
ip_command * command
Definition ipid.h:23
om_this_prog
static char om_this_prog[MAXPATHLEN]
Definition omRet2Info.c:28
MAXPATHLEN
#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.

{
int j=0, k=i;
while (k < max)
{
info[j] = info[k];
j++;
k++;
}
return j;
}
k
int k
Definition cfEzgcd.cc:99

## omInitRet_2_Info()

void omInitRet_2_Info | ( | const char * | argv0 | ) |

Definition at line 34 of file omRet2Info.c.

{
// char buf[MAXPATHLEN];
if (argv0 != NULL) // // && omFindExec(argv0, buf))
{
strncpy(om_this_prog, argv0, MAXPATHLEN); // // buf);
om_this_prog[MAXPATHLEN - 1]= '\0';
}
}
argv0
char * argv0
Definition coeffs_test_runner.cpp:14

## omPrintBackTrace()

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

Definition at line 151 of file omRet2Info.c.

{
int i;
omRetInfo_t info[OM_MAX_BACKTRACE_DEPTH];
if (max > OM_MAX_BACKTRACE_DEPTH) max = OM_MAX_BACKTRACE_DEPTH;
i = omBackTrace_2_RetInfo(bt, info, max);
#ifdef OM_PRINT_RETURN_ADDRESS
return omPrintRetInfo(info, i, fd, " #%i at %L in %N ra=%p\n");
#else
return omPrintRetInfo(info, i, fd, " #%i at %L in %N\n");
#endif
}

## omPrintCurrentBackTraceMax()

int omPrintCurrentBackTraceMax | ( | FILE * | fd,
|  | int | max )

Definition at line 166 of file omRet2Info.c.

{
int i;
void* bt[OM_MAX_BACKTRACE_DEPTH];
if (max > OM_MAX_BACKTRACE_DEPTH)
max = OM_MAX_BACKTRACE_DEPTH;
if (max <= 0) return 0;
i = omGetBackTrace(bt, 1, max);
return omPrintBackTrace(bt, i, fd);
}
omPrintBackTrace
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.

{
int i = 0;
if (max <= 0 || info == NULL || fmt == NULL || fd == NULL) return 0;
while (i < max && info[i].addr != NULL)
{
int l = 0;
while (fmt[l] != 0)
{
if (fmt[l] == '%')
{
l++;
if (fmt[l] == 'p') fprintf(fd, "%p", info[i].addr);
else if (fmt[l] == 'f') fprintf(fd, "%-20s", (*info[i].file != '\0' ? info[i].file : "??"));
else if (fmt[l] == 'F') fprintf(fd, "%-20s", (*info[i].func != '\0' ? info[i].func : "??"));
else if (fmt[l] == 'l') fprintf(fd, "%d", info[i].line);
else if (fmt[l] == 'N')
{
if (*info[i].func != '\0')
{
char* found = (char*) strchr(info[i].func, '(');
if (found) *found = '\0';
fprintf(fd, "%-20s", info[i].func);
if (found) *found = '(';
}
else
fprintf(fd, "%-20s", "??");
}
else if (fmt[l] == 'L')
{
int n = fprintf(fd, "%s:%d", (*info[i].func != '\0' ? info[i].file : "??"), info[i].line);
if (n < 20) fprintf(fd, "%*s", 20-n, " ");
}
else if (fmt[l] == 'i') fprintf(fd, "%d", i);
else
{
fputc('%', fd);
l--;
}
}
else
{
fputc(fmt[l], fd);
}
l++;
}
i++;
}
return i;
}
found
bool found
Definition facFactorize.cc:55

## Variable Documentation

## om_this_prog

char om_this_prog[MAXPATHLEN] = ""

static

Definition at line 28 of file omRet2Info.c.