{
char proc_path[BCTEXTLEN], exe_path[BCTEXTLEN];
sprintf(proc_path, "/proc/%d/exe", (int)getpid());
- int ret = readlink(proc_path, exe_path, sizeof(exe_path));
- if( ret < 0 ) { fprintf(fp,"readlink: %m\n"); return; }
- exe_path[ret] = 0;
+
+ int ret = -1, n = 100;
+ for( int len; (len=readlink(proc_path, exe_path, sizeof(exe_path)))>0; --n ) {
+ exe_path[len] = 0; strcpy(proc_path, exe_path);
+ ret = 0;
+ }
+ if( n < 0 || ret < 0 ) { fprintf(fp,"readlink: %m\n"); return; }
+
struct stat st;
- if( stat(exe_path,&st) ) { fprintf(fp,"stat: %m\n"); return; }
- fprintf(fp, "path: %s = %9jd bytes\n",exe_path,st.st_size);
- int fd = open(exe_path,O_RDONLY+O_NONBLOCK);
+ if( stat(proc_path,&st) ) { fprintf(fp,"stat: %m\n"); return; }
+ fprintf(fp, "path: %s = %9jd bytes\n",proc_path,st.st_size);
+ struct tm *tm = localtime(&st.st_mtime);
+ char mtime[256];
+ strftime(mtime, sizeof(mtime), "%F %T", tm);
+ fprintf(fp,"mtime: %s\n", mtime);
+
+ int fd = open(proc_path,O_RDONLY+O_NONBLOCK);
if( fd < 0 ) { fprintf(fp,"open: %m\n"); return; }
uint8_t *bfr = 0;
int64_t bfrsz = 0;
#include <ctype.h>
#include <dirent.h>
#include <execinfo.h>
+#include <fcntl.h>
#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
ucontext_t *uc = (ucontext_t *)sc;
int pid = getpid(), tid = gettid();
struct sigcontext *c = (struct sigcontext *)&uc->uc_mcontext;
+ uint8_t *ip = (uint8_t *)c->IP;
fprintf(stderr,"** %s at %p in pid %d, tid %d\n",
n==SIGSEGV? "segv" : n==SIGINT? "intr" : "trap",
- (void*)c->IP, pid, tid);
+ (void*)ip, pid, tid);
FILE *fp = 0;
char fn[PATH_MAX];
if( BC_Signals::trap_path ) {
fprintf(fp,"\nVERSION:\n"); bc_copy_textfile(INT_MAX, fp,"/proc/version");
fprintf(fp,"\nMEMINFO:\n"); bc_copy_textfile(INT_MAX, fp,"/proc/meminfo");
fprintf(fp,"\nMAPS:\n"); bc_copy_textfile(INT_MAX, fp,"/proc/%d/maps",pid);
+ char proc_mem[64];
+ if( tid > 0 && tid != pid )
+ sprintf(proc_mem,"/proc/%d/task/%d/mem",pid,tid);
+ else
+ sprintf(proc_mem,"/proc/%d/mem",pid);
+ int pfd = open(proc_mem,O_RDONLY);
+ if( pfd >= 0 ) {
+ fprintf(fp,"\nCODE:\n");
+ for( int i=-32; i<32; ) {
+ uint8_t v; void *vp = (void *)(ip + i);
+ if( !(i & 7) ) fprintf(fp,"%p: ", vp);
+ if( pread(pfd,&v,sizeof(v),(off_t)vp) != sizeof(v) ) break;
+ fprintf(fp,"%c%02x", !i ? '>' : ' ', v);
+ if( !(++i & 7) ) fprintf(fp,"\n");
+ }
+ fprintf(fp,"\n");
+ close(pfd);
+ }
+ else
+ fprintf(fp,"err opening: %s, %m\n", proc_mem);
+
fprintf(fp,"\n\n");
if( fp != stdout ) fclose(fp);
char cmd[1024], *cp = cmd;