summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/pmdb/aout_syms.c13
-rw-r--r--usr.bin/pmdb/arch/alpha/alpha_trace.c6
-rw-r--r--usr.bin/pmdb/arch/hppa/hppa.c4
-rw-r--r--usr.bin/pmdb/arch/i386/i386.c8
-rw-r--r--usr.bin/pmdb/arch/powerpc/powerpc.c6
-rw-r--r--usr.bin/pmdb/arch/sparc/sparc.c4
-rw-r--r--usr.bin/pmdb/arch/sparc64/sparc64.c4
-rw-r--r--usr.bin/pmdb/arch/vax/vax.c4
-rw-r--r--usr.bin/pmdb/break.c12
-rw-r--r--usr.bin/pmdb/core.c46
-rw-r--r--usr.bin/pmdb/core.h5
-rw-r--r--usr.bin/pmdb/elf_syms.c11
-rw-r--r--usr.bin/pmdb/pmdb.c11
-rw-r--r--usr.bin/pmdb/pmdb.h8
-rw-r--r--usr.bin/pmdb/process.c117
15 files changed, 190 insertions, 69 deletions
diff --git a/usr.bin/pmdb/aout_syms.c b/usr.bin/pmdb/aout_syms.c
index 2773ef83b90..d3b2147b139 100644
--- a/usr.bin/pmdb/aout_syms.c
+++ b/usr.bin/pmdb/aout_syms.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: aout_syms.c,v 1.8 2002/06/11 06:34:38 art Exp $ */
+/* $OpenBSD: aout_syms.c,v 1.9 2002/07/22 01:20:50 art Exp $ */
/*
* Copyright (c) 2002 Federico Schwindt <fgsch@openbsd.org>
* All rights reserved.
@@ -273,7 +273,6 @@ restart:
void
aout_update(struct pstate *ps)
{
- pid_t pid = ps->ps_pid;
struct _dynamic dyn;
struct so_debug sdeb;
struct section_dispatch_table sdt;
@@ -288,7 +287,7 @@ aout_update(struct pstate *ps)
}
addr = s->n_value + ps->ps_sym_exe->st_offs;
- if (read_from_pid(pid, addr, &dyn, sizeof(dyn)) < 0) {
+ if (process_read(ps, addr, &dyn, sizeof(dyn)) < 0) {
warn("Can't read __DYNAMIC");
return;
}
@@ -298,7 +297,7 @@ aout_update(struct pstate *ps)
return;
}
- if (read_from_pid(pid, (off_t)(reg)dyn.d_debug, &sdeb, sizeof(sdeb)) < 0) {
+ if (process_read(ps, (off_t)(reg)dyn.d_debug, &sdeb, sizeof(sdeb)) < 0) {
warn("Can't read __DYNAMIC.d_debug");
return;
}
@@ -308,7 +307,7 @@ aout_update(struct pstate *ps)
return;
}
- if (read_from_pid(pid, (off_t)(reg)dyn.d_un.d_sdt, &sdt, sizeof(sdt)) < 0) {
+ if (process_read(ps, (off_t)(reg)dyn.d_un.d_sdt, &sdt, sizeof(sdt)) < 0) {
warn("Can't read section dispatch table");
return;
}
@@ -318,12 +317,12 @@ aout_update(struct pstate *ps)
char fname[MAXPATHLEN];
int i;
- if (read_from_pid(pid, somp, &som, sizeof(som)) < 0) {
+ if (process_read(ps, somp, &som, sizeof(som)) < 0) {
warn("Can't read so_map");
break;
}
somp = (off_t)(reg)som.som_next;
- if (read_from_pid(pid, (off_t)(reg)som.som_path, fname,
+ if (process_read(ps, (off_t)(reg)som.som_path, fname,
sizeof(fname)) < 0) {
warn("Can't read so filename");
continue;
diff --git a/usr.bin/pmdb/arch/alpha/alpha_trace.c b/usr.bin/pmdb/arch/alpha/alpha_trace.c
index be2d37b84a4..305690848cc 100644
--- a/usr.bin/pmdb/arch/alpha/alpha_trace.c
+++ b/usr.bin/pmdb/arch/alpha/alpha_trace.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: alpha_trace.c,v 1.2 2002/03/15 16:41:06 jason Exp $ */
+/* $OpenBSD: alpha_trace.c,v 1.3 2002/07/22 01:20:50 art Exp $ */
/*
* Copyright (c) 2002 Artur Grabowski <art@openbsd.org>
* All rights reserved.
@@ -272,7 +272,7 @@ md_getframe(struct pstate *ps, int framec, struct md_frame *fram)
framesize = 0;
for (i = sizeof (int); i <= offset; i += sizeof (int)) {
- if (read_from_pid(ps->ps_pid, pc - i, &inst, sizeof(inst)) < 0)
+ if (process_read(ps, pc - i, &inst, sizeof(inst)) < 0)
return -1;
/*
@@ -324,7 +324,7 @@ md_getframe(struct pstate *ps, int framec, struct md_frame *fram)
if (slot[R_RA] == -1)
ra = regs.r_regs[R_RA];
else
- if (read_from_pid(ps->ps_pid, (off_t)slot[R_RA],
+ if (process_read(ps, (off_t)slot[R_RA],
&ra, sizeof(ra)) < 0)
return -1;
} else {
diff --git a/usr.bin/pmdb/arch/hppa/hppa.c b/usr.bin/pmdb/arch/hppa/hppa.c
index a482ac0554a..800fc404944 100644
--- a/usr.bin/pmdb/arch/hppa/hppa.c
+++ b/usr.bin/pmdb/arch/hppa/hppa.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: hppa.c,v 1.2 2002/03/19 21:32:10 fgsch Exp $ */
+/* $OpenBSD: hppa.c,v 1.3 2002/07/22 01:20:50 art Exp $ */
/*
* Copyright (c) 2002 Michael Shalayeff
@@ -71,7 +71,7 @@ md_getframe(struct pstate *ps, int frame, struct md_frame *fram)
for (i = 1; i < frame; i++) {
- if (read_from_pid(ps->ps_pid, fp-60, &fr, sizeof(fr)) < 0)
+ if (process_read(ps, fp-60, &fr, sizeof(fr)) < 0)
return (-1);
pc = rp;
diff --git a/usr.bin/pmdb/arch/i386/i386.c b/usr.bin/pmdb/arch/i386/i386.c
index 7b565481487..bb8056c0651 100644
--- a/usr.bin/pmdb/arch/i386/i386.c
+++ b/usr.bin/pmdb/arch/i386/i386.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: i386.c,v 1.3 2002/03/19 21:32:10 fgsch Exp $ */
+/* $OpenBSD: i386.c,v 1.4 2002/07/22 01:20:50 art Exp $ */
/*
* Copyright (c) 2002 Federico Schwindt <fgsch@openbsd.org>
* All rights reserved.
@@ -58,13 +58,13 @@ md_getframe(struct pstate *ps, int frame, struct md_frame *fram)
struct reg r;
int count;
- if (ptrace(PT_GETREGS, ps->ps_pid, (caddr_t)&r, 0) != 0)
+ if (process_getregs(ps, &r) != 0)
return (-1);
fr.fp = r.r_ebp;
fr.pc = r.r_eip;
for (count = 0; count < frame; count++) {
- if (read_from_pid(ps->ps_pid, fr.fp, &fr, sizeof(fr)) < 0)
+ if (process_read(ps, fr.fp, &fr, sizeof(fr)) < 0)
return (-1);
if (fr.pc < 0x1000)
@@ -82,7 +82,7 @@ md_getregs(struct pstate *ps, reg *regs)
{
struct reg r;
- if (ptrace(PT_GETREGS, ps->ps_pid, (caddr_t)&r, 0) != 0)
+ if (process_getregs(ps, &r) != 0)
return (-1);
memcpy(regs, &r, sizeof(r));
diff --git a/usr.bin/pmdb/arch/powerpc/powerpc.c b/usr.bin/pmdb/arch/powerpc/powerpc.c
index 1894049e2a5..9efafd430c1 100644
--- a/usr.bin/pmdb/arch/powerpc/powerpc.c
+++ b/usr.bin/pmdb/arch/powerpc/powerpc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: powerpc.c,v 1.1 2002/03/19 23:15:31 drahn Exp $ */
+/* $OpenBSD: powerpc.c,v 1.2 2002/07/22 01:20:50 art Exp $ */
/*
* Copyright (c) 2002 Dale Rahn <drahn@openbsd.org>
* All rights reserved.
@@ -67,9 +67,9 @@ md_getframe(struct pstate *ps, int frame, struct md_frame *fram)
if (fp != (fp & ~7)) { /* should be 0xf */
return -1;
}
- if (read_from_pid(ps->ps_pid, fp, &fp, sizeof(fp)) < 0)
+ if (process_read(ps, fp, &fp, sizeof(fp)) < 0)
return -1;
- if (read_from_pid(ps->ps_pid, fp+4, &pc, sizeof(pc)) < 0)
+ if (process_read(ps, fp+4, &pc, sizeof(pc)) < 0)
return -1;
if (fp == 0) {
return -1;
diff --git a/usr.bin/pmdb/arch/sparc/sparc.c b/usr.bin/pmdb/arch/sparc/sparc.c
index a791df3088a..fc5c6921f50 100644
--- a/usr.bin/pmdb/arch/sparc/sparc.c
+++ b/usr.bin/pmdb/arch/sparc/sparc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sparc.c,v 1.3 2002/03/19 21:32:10 fgsch Exp $ */
+/* $OpenBSD: sparc.c,v 1.4 2002/07/22 01:20:50 art Exp $ */
/*
* Copyright (c) 2002 Federico Schwindt <fgsch@openbsd.org>
* All rights reserved.
@@ -70,7 +70,7 @@ md_getframe(struct pstate *ps, int frame, struct md_frame *fram)
if (fp < 8192 || (fp & 7) != 0)
return (-1);
- if (read_from_pid(ps->ps_pid, fp, &fr, sizeof(fr)) < 0)
+ if (process_read(ps, fp, &fr, sizeof(fr)) < 0)
return (-1);
fp = (unsigned long)next_frame((&fr));
pc = fr.fr_pc;
diff --git a/usr.bin/pmdb/arch/sparc64/sparc64.c b/usr.bin/pmdb/arch/sparc64/sparc64.c
index 42af2277be7..b71d29f88aa 100644
--- a/usr.bin/pmdb/arch/sparc64/sparc64.c
+++ b/usr.bin/pmdb/arch/sparc64/sparc64.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sparc64.c,v 1.4 2002/03/19 21:32:10 fgsch Exp $ */
+/* $OpenBSD: sparc64.c,v 1.5 2002/07/22 01:20:50 art Exp $ */
/*
* Copyright (c) 2002 Artur Grabowski <art@openbsd.org>
* All rights reserved.
@@ -79,7 +79,7 @@ md_getframe(struct pstate *ps, int frame, struct md_frame *fram)
if (fp < 8192 || (fp & 7) != 0)
return (-1);
- if (read_from_pid(ps->ps_pid, fp, &fr, sizeof(fr)) < 0)
+ if (process_read(ps, fp, &fr, sizeof(fr)) < 0)
return (-1);
fp = (unsigned long)v9next_frame((&fr));
diff --git a/usr.bin/pmdb/arch/vax/vax.c b/usr.bin/pmdb/arch/vax/vax.c
index 1151fb5c16b..5b3e7051e55 100644
--- a/usr.bin/pmdb/arch/vax/vax.c
+++ b/usr.bin/pmdb/arch/vax/vax.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vax.c,v 1.3 2002/03/19 21:43:05 fgsch Exp $ */
+/* $OpenBSD: vax.c,v 1.4 2002/07/22 01:20:50 art Exp $ */
/*
* Copyright (c) 2002 Federico Schwindt <fgsch@openbsd.org>
* All rights reserved.
@@ -56,7 +56,7 @@ md_getframe(struct pstate *ps, int frame, struct md_frame *fram)
fr.ca_fp = r.fp;
fr.ca_pc = r.pc;
for (count = 0; count < frame; count++) {
- if (read_from_pid(ps->ps_pid, fr.ca_fp, &fr, sizeof(fr)) < 0)
+ if (process_read(ps, fr.ca_fp, &fr, sizeof(fr)) < 0)
return (-1);
if (fr.ca_pc < 0x1000)
diff --git a/usr.bin/pmdb/break.c b/usr.bin/pmdb/break.c
index 1e2455297ca..7a578ec4f11 100644
--- a/usr.bin/pmdb/break.c
+++ b/usr.bin/pmdb/break.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: break.c,v 1.3 2002/07/12 00:24:53 deraadt Exp $ */
+/* $OpenBSD: break.c,v 1.4 2002/07/22 01:20:50 art Exp $ */
/*
* Copyright (c) 2002 Artur Grabowski <art@openbsd.org>
* All rights reserved.
@@ -79,14 +79,13 @@ bkpt_enable(struct pstate *ps, struct breakpoint *bkpt)
{
reg pc = bkpt->bkpt_pc;
- if (read_from_pid(ps->ps_pid, pc, &bkpt->bkpt_old, BREAKPOINT_LEN)) {
+ if (process_read(ps, pc, &bkpt->bkpt_old, BREAKPOINT_LEN)) {
warn("Can't read process contents at 0x%lx", pc);
return (-1);
}
- if (write_to_pid(ps->ps_pid, pc, &bkpt_insn, BREAKPOINT_LEN)) {
+ if (process_write(ps, pc, &bkpt_insn, BREAKPOINT_LEN)) {
warn("Can't write breakpoint at 0x%lx, attempting backout.", pc);
- if (write_to_pid(ps->ps_pid, pc, &bkpt->bkpt_old,
- BREAKPOINT_LEN))
+ if (process_write(ps, pc, &bkpt->bkpt_old, BREAKPOINT_LEN))
warn("Backout failed, process unstable");
return (-1);
}
@@ -130,8 +129,7 @@ bkpt_delete(struct pstate *ps, struct breakpoint *bkpt)
{
TAILQ_REMOVE(&ps->ps_bkpts, bkpt, bkpt_list);
- if (write_to_pid(ps->ps_pid, bkpt->bkpt_pc, &bkpt->bkpt_old,
- BREAKPOINT_LEN))
+ if (process_write(ps, bkpt->bkpt_pc, &bkpt->bkpt_old, BREAKPOINT_LEN))
warn("Breakpoint removal failed, process unstable");
free(bkpt);
diff --git a/usr.bin/pmdb/core.c b/usr.bin/pmdb/core.c
index 761274890d1..874d834d30d 100644
--- a/usr.bin/pmdb/core.c
+++ b/usr.bin/pmdb/core.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: core.c,v 1.1 2002/06/05 18:02:27 fgsch Exp $ */
+/* $OpenBSD: core.c,v 1.2 2002/07/22 01:20:50 art Exp $ */
/*
* Copyright (c) 2002 Jean-Francois Brousseau <krapht@secureops.com>
* All rights reserved.
@@ -139,3 +139,47 @@ core_printregs(struct corefile *cf)
printf("%s:\t0x%.*lx\n", md_def.md_reg_names[i],
(int)(sizeof(reg) * 2), (long) rg[i]);
}
+
+
+ssize_t
+core_read(struct pstate *ps, off_t from, void *to, size_t size)
+{
+ int i;
+ size_t read;
+ void *fp;
+ struct coreseg *cs;
+
+ for (i = 0; i < ps->ps_core->chdr->c_nseg; i++) {
+ cs = ps->ps_core->segs[i];
+ if ((from >= cs->c_addr) && (from < (cs->c_addr + cs->c_size))) {
+ read = size;
+ fp = cs + sizeof(*cs) + (from - cs->c_addr);
+ memcpy(to, fp, read);
+ return read;
+ }
+ }
+
+ return (-1);
+}
+
+
+ssize_t
+core_write(struct pstate *ps, off_t to, void *from, size_t size)
+{
+ int i;
+ size_t written;
+ void *fp;
+ struct coreseg *cs;
+
+ for (i = 0; i < ps->ps_core->chdr->c_nseg; i++) {
+ cs = ps->ps_core->segs[i];
+ if ((to > cs->c_addr) && (to < (cs->c_addr + cs->c_size))) {
+ written = size;
+ fp = cs + sizeof(*cs) + (to - cs->c_addr);
+ memcpy(fp, from, written);
+ return written;
+ }
+ }
+
+ return (-1);
+}
diff --git a/usr.bin/pmdb/core.h b/usr.bin/pmdb/core.h
index 520c2716549..b228517a402 100644
--- a/usr.bin/pmdb/core.h
+++ b/usr.bin/pmdb/core.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: core.h,v 1.1 2002/06/05 18:02:27 fgsch Exp $ */
+/* $OpenBSD: core.h,v 1.2 2002/07/22 01:20:50 art Exp $ */
/*
* Copyright (c) 2002 Jean-Francois Brousseau <krapht@secureops.com>
* All rights reserved.
@@ -42,3 +42,6 @@ struct corefile {
int read_core(const char *, struct pstate *);
void free_core(struct pstate *);
void core_printregs(struct corefile *);
+
+ssize_t core_read(struct pstate *, off_t, void *, size_t);
+ssize_t core_write(struct pstate *, off_t, void *, size_t);
diff --git a/usr.bin/pmdb/elf_syms.c b/usr.bin/pmdb/elf_syms.c
index 986cca41c84..218213022fc 100644
--- a/usr.bin/pmdb/elf_syms.c
+++ b/usr.bin/pmdb/elf_syms.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: elf_syms.c,v 1.5 2002/06/05 16:54:02 fgsch Exp $ */
+/* $OpenBSD: elf_syms.c,v 1.6 2002/07/22 01:20:50 art Exp $ */
/*
* Copyright (c) 2002 Artur Grabowski <art@openbsd.org>
* All rights reserved.
@@ -318,7 +318,6 @@ void
elf_update(struct pstate *ps)
{
#ifndef __NetBSD__
- pid_t pid = ps->ps_pid;
struct elf_object_v1 eobj;
struct r_debug rdeb;
reg addr;
@@ -333,7 +332,7 @@ elf_update(struct pstate *ps)
addr = s->st_value + ps->ps_sym_exe->st_offs;
do {
- if (read_from_pid(pid, addr, &dyn, sizeof(dyn)) < 0) {
+ if (process_read(ps, addr, &dyn, sizeof(dyn)) < 0) {
warnx("Can't read _DYNAMIC");
return;
}
@@ -345,7 +344,7 @@ elf_update(struct pstate *ps)
return;
}
- if (read_from_pid(pid, dyn.d_un.d_ptr, &rdeb, sizeof(rdeb)) < 0) {
+ if (process_read(ps, dyn.d_un.d_ptr, &rdeb, sizeof(rdeb)) < 0) {
warnx("Can't read DT_DEBUG");
return;
}
@@ -370,7 +369,7 @@ elf_update(struct pstate *ps)
char fname[MAXPATHLEN];
int i;
- if (read_from_pid(pid, addr, &eobj, sizeof(eobj)) < 0) {
+ if (process_read(ps, addr, &eobj, sizeof(eobj)) < 0) {
warnx("Can't read symbols...");
return;
}
@@ -379,7 +378,7 @@ elf_update(struct pstate *ps)
if (eobj.load_name == NULL || eobj.load_name == (char *)-1)
continue;
- if (read_from_pid(pid, (Elf_Addr)eobj.load_name, fname,
+ if (process_read(ps, (Elf_Addr)eobj.load_name, fname,
sizeof(fname)) < 0) {
warnx("Can't read symbols...");
return;
diff --git a/usr.bin/pmdb/pmdb.c b/usr.bin/pmdb/pmdb.c
index fdabeea0893..dd53a8256ca 100644
--- a/usr.bin/pmdb/pmdb.c
+++ b/usr.bin/pmdb/pmdb.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pmdb.c,v 1.9 2002/06/09 04:33:42 fgsch Exp $ */
+/* $OpenBSD: pmdb.c,v 1.10 2002/07/22 01:20:50 art Exp $ */
/*
* Copyright (c) 2002 Artur Grabowski <art@openbsd.org>
* All rights reserved.
@@ -153,10 +153,11 @@ main(int argc, char **argv)
md_def_init();
init_sigstate(&ps);
- process_load(&ps);
+ if ((core != NULL) && (read_core(core, &ps) < 0))
+ warnx("failed to load core file");
- if (core != NULL)
- read_core(core, &ps);
+ if (process_load(&ps) < 0)
+ errx(1, "failed to load process");
cm = cmdinit(cmds, NCMDS);
while (ps.ps_state != TERMINATED) {
@@ -270,7 +271,7 @@ cmd_show_backtrace(int argc, char **argv, void *arg)
struct pstate *ps = arg;
int i;
- if (ps->ps_state != STOPPED) {
+ if (ps->ps_state != STOPPED && !(ps->ps_flags & PSF_CORE)) {
fprintf(stderr, "process not stopped\n");
return (0);
}
diff --git a/usr.bin/pmdb/pmdb.h b/usr.bin/pmdb/pmdb.h
index d5aeec0e511..ab406bdd8b6 100644
--- a/usr.bin/pmdb/pmdb.h
+++ b/usr.bin/pmdb/pmdb.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: pmdb.h,v 1.3 2002/06/05 18:02:27 fgsch Exp $ */
+/* $OpenBSD: pmdb.h,v 1.4 2002/07/22 01:20:50 art Exp $ */
/*
* Copyright (c) 2002 Artur Grabowski <art@openbsd.org>
* All rights reserved.
@@ -45,6 +45,7 @@ struct callback;
struct corefile;
struct sym_table;
struct sym_ops;
+struct reg;
/* XXX - should be machdep some day. */
typedef unsigned long reg;
@@ -86,6 +87,11 @@ int write_to_pid(pid_t pid, off_t to, void *from, size_t size);
/* process.c */
int process_load(struct pstate *);
+int process_run(struct pstate *);
+int process_read(struct pstate *, off_t, void *, size_t);
+int process_write(struct pstate *, off_t, void *, size_t);
+int process_getregs(struct pstate *, struct reg *);
+
int cmd_process_run(int, char **, void *);
int cmd_process_cont(int, char **, void *);
int cmd_process_kill(int, char **, void *);
diff --git a/usr.bin/pmdb/process.c b/usr.bin/pmdb/process.c
index 9b36d42b913..749b8d189dc 100644
--- a/usr.bin/pmdb/process.c
+++ b/usr.bin/pmdb/process.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: process.c,v 1.5 2002/06/09 04:33:42 fgsch Exp $ */
+/* $OpenBSD: process.c,v 1.6 2002/07/22 01:20:50 art Exp $ */
/*
* Copyright (c) 2002 Artur Grabowski <art@openbsd.org>
* All rights reserved.
@@ -29,6 +29,8 @@
#include <sys/wait.h>
#include <sys/stat.h>
+#include <machine/reg.h>
+
#include <err.h>
#include <errno.h>
#include <signal.h>
@@ -38,14 +40,13 @@
#include <unistd.h>
#include "pmdb.h"
+#include "core.h"
#include "symbol.h"
#include "break.h"
int
process_load(struct pstate *ps)
{
- int status;
-
if (ps->ps_state == LOADED)
return (0);
@@ -58,6 +59,13 @@ process_load(struct pstate *ps)
if (stat(ps->ps_argv[0], &(ps->exec_stat)) < 0)
err(1, "stat()");
+ if ((ps->ps_flags & PSF_SYMBOLS) == 0) {
+ sym_init_exec(ps, ps->ps_argv[0]);
+ ps->ps_flags |= PSF_SYMBOLS;
+ }
+
+ ps->ps_state = LOADED;
+
if (ps->ps_pid != 0) {
/* attach to an already running process */
if (ptrace(PT_ATTACH, ps->ps_pid, (caddr_t) 0, 0) < 0)
@@ -65,40 +73,49 @@ process_load(struct pstate *ps)
ps->ps_state = STOPPED;
ps->ps_flags |= PSF_ATCH;
}
- else {
- switch (ps->ps_pid = fork()) {
- case 0:
- if (ptrace(PT_TRACE_ME, getpid(), NULL, 0) != 0)
- err(1, "ptrace(PT_TRACE_ME)");
- execvp(*ps->ps_argv, ps->ps_argv);
- err(1, "exec");
- /* NOTREACHED */
- case -1:
- err(1, "fork");
- /* NOTREACHED */
- default:
- break;
- }
-
- ps->ps_state = LOADED;
+
+ return (0);
+}
+
+
+int
+process_run(struct pstate *ps)
+{
+ int status;
+
+ if ((ps->ps_state == RUNNING) || (ps->ps_state == STOPPED)) {
+ warnx("process is already running");
+ return 0;
}
- if ((ps->ps_flags & PSF_SYMBOLS) == 0) {
- sym_init_exec(ps, ps->ps_argv[0]);
- ps->ps_flags |= PSF_SYMBOLS;
+ switch (ps->ps_pid = fork()) {
+ case 0:
+ if (ptrace(PT_TRACE_ME, getpid(), NULL, 0) != 0)
+ err(1, "ptrace(PT_TRACE_ME)");
+ execvp(*ps->ps_argv, ps->ps_argv);
+ err(1, "exec");
+ /* NOTREACHED */
+ case -1:
+ err(1, "fork");
+ /* NOTREACHED */
+ default:
+ warnx("process started with PID %d", ps->ps_pid);
+ break;
}
+ ps->ps_state = LOADED;
+
if (wait(&status) == 0)
err(1, "wait");
return (0);
}
+
int
process_kill(struct pstate *ps)
{
switch(ps->ps_state) {
- case LOADED:
case RUNNING:
case STOPPED:
if (ptrace(PT_KILL, ps->ps_pid, NULL, 0) != 0)
@@ -110,6 +127,59 @@ process_kill(struct pstate *ps)
}
int
+process_read(struct pstate *ps, off_t from, void *to, size_t size)
+{
+ struct ptrace_io_desc piod;
+
+ if (((ps->ps_state == NONE) || (ps->ps_state == LOADED) ||
+ (ps->ps_state == TERMINATED)) && (ps->ps_flags & PSF_CORE)) {
+ return core_read(ps, from, to, size);
+ }
+ else {
+ piod.piod_op = PIOD_READ_D;
+ piod.piod_offs = (void *)(long)from;
+ piod.piod_addr = to;
+ piod.piod_len = size;
+
+ return (ptrace(PT_IO, ps->ps_pid, (caddr_t)&piod, 0));
+ }
+}
+
+int
+process_write(struct pstate *ps, off_t to, void *from, size_t size)
+{
+ struct ptrace_io_desc piod;
+
+ if ((ps->ps_state == NONE) && (ps->ps_flags & PSF_CORE))
+ return core_write(ps, to, from, size);
+ else {
+ piod.piod_op = PIOD_WRITE_D;
+ piod.piod_offs = (void *)(long)to;
+ piod.piod_addr = from;
+ piod.piod_len = size;
+
+ return (ptrace(PT_IO, ps->ps_pid, (caddr_t)&piod, 0));
+ }
+}
+
+int
+process_getregs(struct pstate *ps, struct reg *r)
+{
+
+ if (ps->ps_state == STOPPED) {
+ if (ptrace(PT_GETREGS, ps->ps_pid, (caddr_t)&r, 0) != 0)
+ return (-1);
+ }
+ else if (ps->ps_flags & PSF_CORE) {
+ memcpy(r, ps->ps_core->regs, sizeof(*r));
+ }
+ else
+ return (-1);
+
+ return 0;
+}
+
+int
cmd_process_kill(int argc, char **argv, void *arg)
{
struct pstate *ps = arg;
@@ -147,6 +217,7 @@ cmd_process_run(int argc, char **argv, void *arg)
return (0);
}
+ process_run(ps);
/*
* XXX - there isn't really any difference between STOPPED and
* LOADED, we should probably get rid of one.