version 1.6, 2002/03/19 23:17:58 |
version 1.7, 2002/06/05 18:02:27 |
|
|
#include <sys/types.h> |
#include <sys/types.h> |
#include <sys/ptrace.h> |
#include <sys/ptrace.h> |
#include <sys/wait.h> |
#include <sys/wait.h> |
|
#include <sys/endian.h> |
|
|
#include <stdlib.h> |
#include <stdlib.h> |
#include <stdio.h> |
#include <stdio.h> |
|
|
#include <errno.h> |
#include <errno.h> |
#include <string.h> |
#include <string.h> |
|
|
#include <sys/endian.h> |
|
|
|
#include "pmdb.h" |
#include "pmdb.h" |
#include "symbol.h" |
#include "symbol.h" |
#include "clit.h" |
#include "clit.h" |
#include "break.h" |
#include "break.h" |
|
#include "core.h" |
|
|
static int cmd_show_registers(int, char **, void *); |
static int cmd_show_registers(int, char **, void *); |
static int cmd_show_backtrace(int, char **, void *); |
static int cmd_show_backtrace(int, char **, void *); |
|
|
|
|
#define NCMDS sizeof(cmds)/sizeof(cmds[0]) |
#define NCMDS sizeof(cmds)/sizeof(cmds[0]) |
|
|
|
void |
|
usage() |
|
{ |
|
extern char *__progname; |
|
|
|
fprintf(stderr, "Usage: %s [-c core] <program> args\n", __progname); |
|
exit(1); |
|
} |
|
|
int |
int |
main(int argc, char **argv) |
main(int argc, char **argv) |
{ |
{ |
extern const char *__progname; |
|
struct pstate ps; |
struct pstate ps; |
int i; |
int i, c; |
int status; |
int status; |
void *cm; |
void *cm; |
char *pmenv; |
char *pmenv, *core; |
int level; |
int level; |
|
|
if (argc < 2) { |
if (argc < 2) { |
fprintf(stderr, "Usage: %s <program> args\n", __progname); |
usage(); |
exit(1); |
|
} |
} |
|
|
|
core = NULL; |
|
|
|
while ((c = getopt(argc, argv, "c:")) != -1) { |
|
switch(c) { |
|
case 'c': |
|
core = optarg; |
|
break; |
|
case '?': |
|
default: |
|
usage(); |
|
/* NOTREACHED */ |
|
} |
|
} |
|
argc -= optind; |
|
argv += optind; |
|
|
if ((pmenv = getenv("IN_PMDB")) != NULL) { |
if ((pmenv = getenv("IN_PMDB")) != NULL) { |
level = atoi(pmenv); |
level = atoi(pmenv); |
level++; |
level++; |
|
|
|
|
ps.ps_pid = 0; |
ps.ps_pid = 0; |
ps.ps_state = NONE; |
ps.ps_state = NONE; |
ps.ps_argc = --argc; |
ps.ps_argc = argc; |
ps.ps_argv = ++argv; |
ps.ps_argv = argv; |
ps.ps_flags = 0; |
ps.ps_flags = 0; |
ps.ps_signum = 0; |
ps.ps_signum = 0; |
ps.ps_npc = 1; |
ps.ps_npc = 1; |
|
|
|
|
process_load(&ps); |
process_load(&ps); |
|
|
|
if (core != NULL) |
|
read_core(core, &ps); |
|
|
cm = cmdinit(cmds, NCMDS); |
cm = cmdinit(cmds, NCMDS); |
while (ps.ps_state != TERMINATED) { |
while (ps.ps_state != TERMINATED) { |
int signum; |
int signum; |
|
|
reg *rg; |
reg *rg; |
|
|
if (ps->ps_state != STOPPED) { |
if (ps->ps_state != STOPPED) { |
|
if (ps->ps_flags & PSF_CORE) { |
|
/* dump registers from core */ |
|
core_printregs(ps->ps_core); |
|
return (0); |
|
} |
fprintf(stderr, "process not stopped\n"); |
fprintf(stderr, "process not stopped\n"); |
return 0; |
return (0); |
} |
} |
|
|
rg = alloca(sizeof(*rg) * md_def.nregs); |
rg = alloca(sizeof(*rg) * md_def.nregs); |
|
|
printf("%s:\t0x%.*lx\t%s\n", md_def.md_reg_names[i], |
printf("%s:\t0x%.*lx\t%s\n", md_def.md_reg_names[i], |
(int)(sizeof(reg) * 2), (long)rg[i], |
(int)(sizeof(reg) * 2), (long)rg[i], |
sym_print(ps, rg[i], buf, sizeof(buf))); |
sym_print(ps, rg[i], buf, sizeof(buf))); |
return 0; |
return (0); |
} |
} |
|
|
static int |
static int |
|
|
|
|
if (ps->ps_state != STOPPED) { |
if (ps->ps_state != STOPPED) { |
fprintf(stderr, "process not stopped\n"); |
fprintf(stderr, "process not stopped\n"); |
return 0; |
return (0); |
} |
} |
|
|
/* no more than 100 frames */ |
/* no more than 100 frames */ |
|
|
printf(")+0x%lx\n", offs); |
printf(")+0x%lx\n", offs); |
} |
} |
} |
} |
return 0; |
|
|
return (0); |
} |
} |
|
|
static int |
static int |
|
|
} |
} |
|
|
/* |
/* |
* The "stadard" wrapper |
* The "standard" wrapper |
*/ |
*/ |
void * |
void * |
emalloc(size_t sz) |
emalloc(size_t sz) |