diff options
author | 2012-08-30 15:53:47 +0000 | |
---|---|---|
committer | 2012-08-30 15:53:47 +0000 | |
commit | aa75424dde6d99442cda70a2261fd8b16231d149 (patch) | |
tree | 9636124db792af9cc67774a6e1c4762bb2ac818b | |
parent | no md_root_setconf (diff) | |
download | wireguard-openbsd-aa75424dde6d99442cda70a2261fd8b16231d149.tar.xz wireguard-openbsd-aa75424dde6d99442cda70a2261fd8b16231d149.zip |
Move pmdb to the attic.
It's unfinished. It will never be finished.
It's unfinishable. deraadt@
58 files changed, 2 insertions, 5935 deletions
diff --git a/usr.bin/Makefile b/usr.bin/Makefile index c4ed87c9c61..9a024e3975c 100644 --- a/usr.bin/Makefile +++ b/usr.bin/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.124 2012/06/19 09:30:44 espie Exp $ +# $OpenBSD: Makefile,v 1.125 2012/08/30 15:53:47 kettenis Exp $ .include <bsd.own.mk> @@ -18,7 +18,7 @@ SUBDIR= apply apropos ar arch asa asn1_compile at aucat audioctl awk banner \ newsyslog \ nfsstat nice nm nohup oldrdist pagesize passwd paste patch pctr \ pkg-config pkill \ - pmdb pr printenv printf quota radioctl ranlib rcs rdist rdistd \ + pr printenv printf quota radioctl ranlib rcs rdist rdistd \ readlink renice rev rpcgen rpcinfo rs rsh rup ruptime rusers rwall \ rwho sdiff script sed sendbug shar showmount skey \ skeyaudit skeyinfo skeyinit sort spell split sqlite3 ssh stat su systat \ diff --git a/usr.bin/pmdb/Makefile b/usr.bin/pmdb/Makefile deleted file mode 100644 index 543894cba58..00000000000 --- a/usr.bin/pmdb/Makefile +++ /dev/null @@ -1,52 +0,0 @@ -# $OpenBSD: Makefile,v 1.12 2010/02/03 20:49:01 miod Exp $ - -.include <bsd.own.mk> - -MAN=pmdb.1 - -.if (!exists(arch/${MACHINE}/Makefile.inc) && \ - !exists(arch/${MACHINE_CPU}/Makefile.inc)) -NOPROG=no, man -.else - -PROG=pmdb -SRCS=pmdb.c symbol.c clit.c process.c signal.c break.c core.c -# support for NetBSD -.if defined(OBJECT_FMT) -.if ${OBJECT_FMT} == "ELF" -ELF_TOOLCHAIN=yes -.else -ELF_TOOLCHAIN=no -.endif -.endif - -.if (${ELF_TOOLCHAIN:L} == "yes") -SRCS+=elf_syms.c -CPPFLAGS+=-DPMDB_ELF -.else -SRCS+=aout_syms.c -CPPFLAGS+=-DPMDB_AOUT -.endif - -LDADD=-ledit -lcurses -DPADD=${LIBEDIT} ${LIBCURSES} - -CPPFLAGS+=-I${.CURDIR} - -.if exists(arch/${MACHINE}/Makefile.inc) -.PATH: ${.CURDIR}/arch/${MACHINE} -.include "arch/${MACHINE}/Makefile.inc" -CPPFLAGS+=-I${.CURDIR}/arch/${MACHINE} -.endif - -.if (${MACHINE_CPU} != ${MACHINE}) && exists(arch/${MACHINE_CPU}/Makefile.inc) -.PATH: ${.CURDIR}/arch/${MACHINE_CPU} -.include "arch/${MACHINE_CPU}/Makefile.inc" -CPPFLAGS+=-I${.CURDIR}/arch/${MACHINE_CPU} -.endif - -COPTS+=-Wall -Wno-uninitialized - -.endif - -.include <bsd.prog.mk> diff --git a/usr.bin/pmdb/aout_syms.c b/usr.bin/pmdb/aout_syms.c deleted file mode 100644 index ef9f3e4d479..00000000000 --- a/usr.bin/pmdb/aout_syms.c +++ /dev/null @@ -1,342 +0,0 @@ -/* $OpenBSD: aout_syms.c,v 1.11 2007/07/24 21:11:02 deraadt Exp $ */ -/* - * Copyright (c) 2002 Federico Schwindt <fgsch@openbsd.org> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include <sys/param.h> -#include <sys/ptrace.h> -#include <sys/mman.h> -#include <sys/stat.h> - -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <fcntl.h> -#include <string.h> -#include <err.h> - -#include <a.out.h> -#include <link.h> - -#include "pmdb.h" -#include "symbol.h" - -struct aout_symbol_handle { - struct sym_table ash_st; - int ash_fd; - char *ash_strtab; - u_int32_t ash_strsize; - struct nlist *ash_symtab; - int ash_symsize; -}; - -#define ASH_TO_ST(ash) (&(ash)->ash_st) -#define ST_TO_ASH(st) ((struct aout_symbol_handle *)(st)) - -struct sym_table *aout_open(const char *); -void aout_close(struct sym_table *); -char *aout_name_and_off(struct sym_table *, reg, reg *); -int aout_lookup(struct pstate *, const char *, reg *); -void aout_update(struct pstate *); - -struct sym_ops aout_sops = { - aout_open, - aout_close, - aout_name_and_off, - aout_lookup, - aout_update -}; - -int -sym_check_aout(const char *name, struct pstate *ps) -{ - struct exec ahdr; - int error = 0; - int fd; - - if ((fd = open(name, O_RDONLY)) < 0) - return (1); - - if (pread(fd, &ahdr, sizeof(ahdr), 0) != sizeof(ahdr)) { - error = 1; - } - - if (!error && N_BADMAG(ahdr)) { - error = 1; - } - - close(fd); - - if (!error) - ps->ps_sops = &aout_sops; - - return (error); -} - -struct sym_table * -aout_open(const char *name) -{ - struct aout_symbol_handle *ash; - struct stat sb; - u_int32_t symoff, stroff; - struct exec ahdr; - - if ((ash = malloc(sizeof(*ash))) == NULL) { - return NULL; - } - - memset(ash, 0, sizeof(*ash)); - ash->ash_fd = -1; - - if ((ash->ash_fd = open(name, O_RDONLY)) < 0) { - warn("open(%s)", name); - goto fail; - } - - if (pread(ash->ash_fd, &ahdr, sizeof(ahdr), 0) != sizeof(ahdr)) { - warn("pread(header)"); - goto fail; - } - - if (N_BADMAG(ahdr)) { - warnx("Bad magic."); - goto fail; - } - - /* Don't go further for stripped files. */ - if (fstat(ash->ash_fd, &sb) < 0 || N_SYMOFF(ahdr) == sb.st_size || - N_STROFF(ahdr) == sb.st_size) - goto fail; - - symoff = N_SYMOFF(ahdr); - ash->ash_symsize = ahdr.a_syms; - stroff = N_STROFF(ahdr); - - if (ahdr.a_syms == 0) { - warnx("No symbol table"); - goto fail; - } - - if (pread(ash->ash_fd, &ash->ash_strsize, sizeof(u_int32_t), - stroff) != sizeof(u_int32_t)) { - warn("pread(strsize)"); - goto fail; - } - - if ((ash->ash_strtab = mmap(NULL, ash->ash_strsize, PROT_READ, - MAP_SHARED, ash->ash_fd, stroff)) == MAP_FAILED) { - warn("mmap(strtab)"); - goto fail; - } - - if ((ash->ash_symtab = mmap(NULL, ash->ash_symsize, PROT_READ, - MAP_SHARED, ash->ash_fd, symoff)) == MAP_FAILED) { - warn("mmap(symtab)"); - goto fail; - } - - return (ASH_TO_ST(ash)); -fail: - - aout_close(ASH_TO_ST(ash)); - return (NULL); -} - -void -aout_close(struct sym_table *st) -{ - struct aout_symbol_handle *ash = ST_TO_ASH(st); - - if (ash->ash_fd != -1) - close(ash->ash_fd); - - munmap(ash->ash_strtab, ash->ash_strsize); - munmap(ash->ash_symtab, ash->ash_symsize); - free(ash); -} - -char * -aout_name_and_off(struct sym_table *st, reg pc, reg *offs) -{ - struct aout_symbol_handle *ash = ST_TO_ASH(st); - struct nlist *s, *bests = NULL; - int bestoff = 0; - int nsyms, i; - char *symn; - -#define SYMVAL(S) (unsigned long)((S)->n_value + st->st_offs) - - nsyms = ash->ash_symsize / sizeof(struct nlist); - - bests = NULL; - for (i = 0; i < nsyms; i++) { - s = &ash->ash_symtab[i]; - - if (s->n_value == 0 || - s->n_un.n_strx == 0) - continue; - - symn = &ash->ash_strtab[s->n_un.n_strx]; - if (SYMVAL(s) <= pc && SYMVAL(s) > bestoff && - symn[0] != '\0' && strcmp(symn, "gcc2_compiled.")) { - bests = s; - bestoff = SYMVAL(s); - } - } - - if ((s = bests) == NULL) - return (NULL); - - *offs = pc - SYMVAL(s); - - return &ash->ash_strtab[s->n_un.n_strx]; -} - -static struct nlist * -aout_lookup_table(struct aout_symbol_handle *ash, const char *name) -{ - int nsyms, i; - char *symn; - struct nlist *s = NULL; - - nsyms = ash->ash_symsize / sizeof(struct nlist); - for (i = 0; i < nsyms; i++) { - s = &ash->ash_symtab[i]; - symn = &ash->ash_strtab[s->n_un.n_strx]; - if (strcmp(name, symn) == 0) - break; - } - - if (i == nsyms) - return (NULL); - - return (s); -} - -int -aout_lookup(struct pstate *ps, const char *name, reg *res) -{ - struct sym_table *st; - struct nlist *s = NULL; - int first = 1; - char *sname = (char *)name; - -restart: - TAILQ_FOREACH(st, &ps->ps_syms, st_list) { - if ((s = aout_lookup_table(ST_TO_ASH(st), sname)) != NULL) - break; - } - - if (!first) - free(sname); - - if (s == NULL) { - if (first) { - if (asprintf(&sname, "_%s", sname) != -1) { - first = 0; - goto restart; - } - } - - return (-1); - } - - *res = s->n_value + st->st_offs; - return (0); -} - -/* - * Called after execution started so that we can load any dynamic symbols. - */ -void -aout_update(struct pstate *ps) -{ - struct _dynamic dyn; - struct so_debug sdeb; - struct section_dispatch_table sdt; - struct so_map som; - off_t somp; - reg addr; - struct nlist *s; - - if ((s = aout_lookup_table(ST_TO_ASH(ps->ps_sym_exe), "__DYNAMIC")) == NULL) { - warnx("Can't find __DYNAMIC"); - return; - } - addr = s->n_value + ps->ps_sym_exe->st_offs; - - if (process_read(ps, addr, &dyn, sizeof(dyn)) < 0) { - warn("Can't read __DYNAMIC"); - return; - } - - if (dyn.d_version != LD_VERSION_BSD) { - warn("Can't handle __DYNAMIC version %d", dyn.d_version); - return; - } - - if (process_read(ps, (off_t)(reg)dyn.d_debug, &sdeb, sizeof(sdeb)) < 0) { - warn("Can't read __DYNAMIC.d_debug"); - return; - } - - if (sdeb.dd_version != 0) { - warn("Can't handle so_debug version %d", sdeb.dd_version); - return; - } - - if (process_read(ps, (off_t)(reg)dyn.d_un.d_sdt, &sdt, sizeof(sdt)) < 0) { - warn("Can't read section dispatch table"); - return; - } - - somp = (off_t)(reg)sdt.sdt_loaded; - while (somp) { - char fname[MAXPATHLEN]; - int i; - - if (process_read(ps, somp, &som, sizeof(som)) < 0) { - warn("Can't read so_map"); - break; - } - somp = (off_t)(reg)som.som_next; - if (process_read(ps, (off_t)(reg)som.som_path, fname, - sizeof(fname)) < 0) { - warn("Can't read so filename"); - continue; - } - - /* sanity check the file name */ - for (i = 0; i < MAXPATHLEN; i++) - if (fname[i] == '\0') - break; - if (i == MAXPATHLEN) { - warnx("so filename invalid"); - continue; - } - - if (st_open(ps, fname, (reg)som.som_addr) == NULL) - warn("symbol loading failed"); - } -} diff --git a/usr.bin/pmdb/arch/alpha/Makefile.inc b/usr.bin/pmdb/arch/alpha/Makefile.inc deleted file mode 100644 index 7a812303e91..00000000000 --- a/usr.bin/pmdb/arch/alpha/Makefile.inc +++ /dev/null @@ -1,3 +0,0 @@ -# $OpenBSD: Makefile.inc,v 1.2 2002/03/15 18:33:03 mickey Exp $ - -SRCS+=alpha.c alpha_trace.c diff --git a/usr.bin/pmdb/arch/alpha/alpha.c b/usr.bin/pmdb/arch/alpha/alpha.c deleted file mode 100644 index 5070b14aac9..00000000000 --- a/usr.bin/pmdb/arch/alpha/alpha.c +++ /dev/null @@ -1,70 +0,0 @@ -/* $OpenBSD: alpha.c,v 1.4 2008/02/09 20:59:09 martin Exp $ */ -/* - * Copyright (c) 2002 Artur Grabowski <art@openbsd.org> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include <sys/param.h> -#include <sys/ptrace.h> -#include <machine/reg.h> -#include <machine/frame.h> - -#include <string.h> - -#include "pmdb.h" - -/* - * This happens to be the same order as in struct reg. - */ - -static const char *md_reg_names[] = { - "v0", - "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7", - "s0", "s1", "s2", "s3", "s4", "s5", "s6", - "a0", "a1", "a2", "a3", "a4", "a5", - "t8", "t9", "t10", "t11", - "ra", - "t12", - "at", "gp", "sp", "zero" -}; - -struct md_def md_def = { md_reg_names, 32, 31 }; - -void -md_def_init(void) -{ - /* nothing */ -} - -int -md_getregs(struct pstate *ps, reg *regs) -{ - struct reg r; - - if (process_getregs(ps, &r)) - return (-1); - - memcpy(regs, &r, sizeof(r)); - - return (0); -} diff --git a/usr.bin/pmdb/arch/alpha/alpha_instruction.h b/usr.bin/pmdb/arch/alpha/alpha_instruction.h deleted file mode 100644 index 14c736683ca..00000000000 --- a/usr.bin/pmdb/arch/alpha/alpha_instruction.h +++ /dev/null @@ -1,750 +0,0 @@ -/* $OpenBSD: alpha_instruction.h,v 1.3 2002/07/10 20:30:15 jsyn Exp $ */ -/* - * Copyright (c) 2002 Artur Grabowski <art@openbsd.org> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * Copyright (c) 1999 Christopher G. Demetriou. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Christopher G. Demetriou - * for the NetBSD Project. - * 4. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * Mach Operating System - * Copyright (c) 1993,1992 Carnegie Mellon University - * All Rights Reserved. - * - * Permission to use, copy, modify and distribute this software and its - * documentation is hereby granted, provided that both the copyright - * notice and this permission notice appear in all copies of the - * software, derivative works or modified versions, and any portions - * thereof, and that both notices appear in supporting documentation. - * - * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" - * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR - * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. - * - * Carnegie Mellon requests users of this software to return to - * - * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU - * School of Computer Science - * Carnegie Mellon University - * Pittsburgh PA 15213-3890 - * - * any improvements or extensions that they make and grant Carnegie Mellon - * the rights to redistribute these changes. - */ - -/* - * File: alpha_instruction.h - * Author: Alessandro Forin, Carnegie Mellon University - * Date: 11/91 - * - * Alpha Instruction set definition - * - * Reference: "Alpha System Reference Manual", V4.0, April 1991 - * - */ - -#ifndef _ALPHA_INSTRUCTION_H_ -#define _ALPHA_INSTRUCTION_H_ 1 - -#if !defined(ASSEMBLER) - -/* - * All instructions are in one of five formats: - * Memory, Branch, Operate, Floating-point Operate, PAL - * - * The original Mach sources attempted to use 'smarter' names - * for registers, which reflected source and destination. These - * definitions use the names from the Architecture Reference Manual, - * both for clarity and because you can't differentiate between - * 'source' and 'destinations' for some types of instructions (loads - * and stores; they'd be correct for one, but swapped for the other). - */ - - -typedef union { - /* - * All instructions are 32 bits wide - */ - unsigned int bits; - - /* - * Generic instruction pseudo format; look at - * opcode to see how to interpret the rest. - */ - struct { - unsigned bits:26, - opcode:6; - } generic_format; - - /* - * Memory instructions contain a 16 bit - * signed immediate value and two register - * specifiers - */ - struct { - signed short displacement; - unsigned rb : 5, - ra : 5, - opcode : 6; - } mem_format; - - /* - * Branch instruction contain a 21 bit offset, - * which is sign-extended, shifted and combined - * with the PC to form a 64 bit destination address. - * - * In computed jump instructions the opcode is further - * specified in the offset field, the rest of it is - * used as branch target hint. The destination of the - * jump is the source register. - */ - struct { - signed int displacement : 21; - unsigned ra : 5, - opcode : 6; - } branch_format; - - struct { - signed int hint : 14; - unsigned action : 2, - rb : 5, - ra : 5, - opcode : 6; - } jump_format; - - - /* - * Operate instructions are of two types, with - * a second source register or with a literal - * specifier. Bit 12 says which is which. - */ - struct { - unsigned rc : 5, - function : 7, - is_lit : 1, - sbz_or_litlo : 3, - rb_or_lithi : 5, - ra : 5, - opcode : 6; - } operate_generic_format; - - struct { - unsigned rc : 5, - function : 7, - zero : 1, - sbz : 3, - rb : 5, - ra : 5, - opcode : 6; - } operate_reg_format; - - struct { - unsigned rc : 5, - function : 7, - one : 1, - literal : 8, - ra : 5, - opcode : 6; - } operate_lit_format; - - - /* - * Floating point operate instruction are quite - * uniform in the encoding. As for the semantics.. - */ - struct { - unsigned fc : 5, - function : 11, - fb : 5, - fa : 5, - opcode : 6; - } float_format; - - - /* - * PAL instructions just define the major opcode - */ - - struct { - unsigned function : 26, - opcode : 6; - } pal_format; - -} alpha_instruction; - -#endif /* !defined(ASSEMBLER) */ - -/* - * - * Encoding of regular instructions (Appendix C op cit) - * - */ - - /* OPCODE, bits 26..31 */ - -#define op_pal 0x00 /* see PAL sub-table */ - /* 1..7 reserved */ -#define op_lda 0x08 -#define op_ldah 0x09 -#define op_ldbu 0x0a -#define op_ldq_u 0x0b -#define op_ldwu 0x0c -#define op_stw 0x0d -#define op_stb 0x0e -#define op_stq_u 0x0f - -#define op_arit 0x10 /* see ARIT sub-table */ -#define op_logical 0x11 /* see LOGICAL sub-table */ -#define op_bit 0x12 /* see BIT sub-table */ -#define op_mul 0x13 /* see MUL sub-table */ - /* reserved */ -#define op_vax_float 0x15 /* see FLOAT sub-table */ -#define op_ieee_float 0x16 /* see FLOAT sub-table */ -#define op_any_float 0x17 /* see FLOAT sub-table */ - -#define op_special 0x18 /* see SPECIAL sub-table */ -#define op_pal19 0x19 /* reserved for pal code */ -#define op_j 0x1a /* see JUMP sub-table */ -#define op_pal1b 0x1b /* reserved for pal code */ -#define op_intmisc 0x1c /* see INTMISC sub-table */ -#define op_pal1d 0x1d /* reserved for pal code */ -#define op_pal1e 0x1e /* reserved for pal code */ -#define op_pal1f 0x1f /* reserved for pal code */ - -#define op_ldf 0x20 -#define op_ldg 0x21 -#define op_lds 0x22 -#define op_ldt 0x23 -#define op_stf 0x24 -#define op_stg 0x25 -#define op_sts 0x26 -#define op_stt 0x27 -#define op_ldl 0x28 -#define op_ldq 0x29 -#define op_ldl_l 0x2a -#define op_ldq_l 0x2b -#define op_stl 0x2c -#define op_stq 0x2d -#define op_stl_c 0x2e -#define op_stq_c 0x2f -#define op_br 0x30 -#define op_fbeq 0x31 -#define op_fblt 0x32 -#define op_fble 0x33 -#define op_bsr 0x34 -#define op_fbne 0x35 -#define op_fbge 0x36 -#define op_fbgt 0x37 -#define op_blbc 0x38 -#define op_beq 0x39 -#define op_blt 0x3a -#define op_ble 0x3b -#define op_blbs 0x3c -#define op_bne 0x3d -#define op_bge 0x3e -#define op_bgt 0x3f - - - /* PAL, "function" opcodes (bits 0..25) */ -/* - * What we will implement is TBD. These are the unprivileged ones - * that we probably have to support for compat reasons. - */ - -/* See <machine/pal.h> */ - - /* ARIT, "function" opcodes (bits 5..11) */ - -#define op_addl 0x00 -#define op_s4addl 0x02 -#define op_subl 0x09 -#define op_s4subl 0x0b -#define op_cmpbge 0x0f -#define op_s8addl 0x12 -#define op_s8subl 0x1b -#define op_cmpult 0x1d -#define op_addq 0x20 -#define op_s4addq 0x22 -#define op_subq 0x29 -#define op_s4subq 0x2b -#define op_cmpeq 0x2d -#define op_s8addq 0x32 -#define op_s8subq 0x3b -#define op_cmpule 0x3d -#define op_addl_v 0x40 -#define op_subl_v 0x49 -#define op_cmplt 0x4d -#define op_addq_v 0x60 -#define op_subq_v 0x69 -#define op_cmple 0x6d - - - /* LOGICAL, "function" opcodes (bits 5..11) */ - -#define op_and 0x00 -#define op_andnot 0x08 /* bic */ -#define op_cmovlbs 0x14 -#define op_cmovlbc 0x16 -#define op_or 0x20 /* bis */ -#define op_cmoveq 0x24 -#define op_cmovne 0x26 -#define op_ornot 0x28 -#define op_xor 0x40 -#define op_cmovlt 0x44 -#define op_cmovge 0x46 -#define op_xornot 0x48 /* eqv */ -#define op_amask 0x61 -#define op_cmovle 0x64 -#define op_cmovgt 0x66 -#define op_implver 0x6c - - /* BIT, "function" opcodes (bits 5..11) */ - -#define op_mskbl 0x02 -#define op_extbl 0x06 -#define op_insbl 0x0b -#define op_mskwl 0x12 -#define op_extwl 0x16 -#define op_inswl 0x1b -#define op_mskll 0x22 -#define op_extll 0x26 -#define op_insll 0x2b -#define op_zap 0x30 -#define op_zapnot 0x31 -#define op_mskql 0x32 -#define op_srl 0x34 -#define op_extql 0x36 -#define op_sll 0x39 -#define op_insql 0x3b -#define op_sra 0x3c -#define op_mskwh 0x52 -#define op_inswh 0x57 -#define op_extwh 0x5a -#define op_msklh 0x62 -#define op_inslh 0x67 -#define op_extlh 0x6a -#define op_extqh 0x7a -#define op_insqh 0x77 -#define op_mskqh 0x72 - - /* MUL, "function" opcodes (bits 5..11) */ - -#define op_mull 0x00 -#define op_mulq_v 0x60 -#define op_mull_v 0x40 -#define op_umulh 0x30 -#define op_mulq 0x20 - - - /* SPECIAL, "displacement" opcodes (bits 0..15) */ - -#define op_trapb 0x0000 -#define op_excb 0x0400 -#define op_mb 0x4000 -#define op_wmb 0x4400 -#define op_fetch 0x8000 -#define op_fetch_m 0xa000 -#define op_rpcc 0xc000 -#define op_rc 0xe000 -#define op_ecb 0xe800 -#define op_rs 0xf000 -#define op_wh64 0xf800 - - /* JUMP, "action" opcodes (bits 14..15) */ - -#define op_jmp 0x0 -#define op_jsr 0x1 -#define op_ret 0x2 -#define op_jcr 0x3 - - /* INTMISC, "function" opcodes (operate format) */ - -#define op_sextb 0x00 -#define op_sextw 0x01 -#define op_ctpop 0x30 -#define op_perr 0x31 -#define op_ctlz 0x32 -#define op_cttz 0x33 -#define op_unpkbw 0x34 -#define op_unpkbl 0x35 -#define op_pkwb 0x36 -#define op_pklb 0x37 -#define op_minsb8 0x38 -#define op_minsw4 0x39 -#define op_minub8 0x3a -#define op_minuw4 0x3b -#define op_maxub8 0x3c -#define op_maxuw4 0x3d -#define op_maxsb8 0x3e -#define op_maxsw4 0x3f -#define op_ftoit 0x70 -#define op_ftois 0x78 - -/* - * - * Encoding of floating point instructions (pagg. C-5..6 op cit) - * - * Load and store operations use opcodes op_ldf..op_stt - */ - - /* any FLOAT, "function" opcodes (bits 5..11) */ - -#define op_cvtlq 0x010 -#define op_cpys 0x020 -#define op_cpysn 0x021 -#define op_cpyse 0x022 -#define op_mt_fpcr 0x024 -#define op_mf_fpcr 0x025 -#define op_fcmoveq 0x02a -#define op_fcmovne 0x02b -#define op_fcmovlt 0x02c -#define op_fcmovge 0x02d -#define op_fcmovle 0x02e -#define op_fcmovgt 0x02f -#define op_cvtql 0x030 -#define op_cvtql_v 0x130 -#define op_cvtql_sv 0x330 - - - /* ieee FLOAT, "function" opcodes (bits 5..11) */ - -#define op_adds_c 0x000 -#define op_subs_c 0x001 -#define op_muls_c 0x002 -#define op_divs_c 0x003 -#define op_addt_c 0x020 -#define op_subt_c 0x021 -#define op_mult_c 0x022 -#define op_divt_c 0x023 -#define op_cvtts_c 0x02c -#define op_cvttq_c 0x02f -#define op_cvtqs_c 0x03c -#define op_cvtqt_c 0x03e -#define op_adds_m 0x040 -#define op_subs_m 0x041 -#define op_muls_m 0x042 -#define op_divs_m 0x043 -#define op_addt_m 0x060 -#define op_subt_m 0x061 -#define op_mult_m 0x062 -#define op_divt_m 0x063 -#define op_cvtts_m 0x06c -#define op_cvtqs_m 0x07c -#define op_cvtqt_m 0x07e -#define op_adds 0x080 -#define op_subs 0x081 -#define op_muls 0x082 -#define op_divs 0x083 -#define op_addt 0x0a0 -#define op_subt 0x0a1 -#define op_mult 0x0a2 -#define op_divt 0x0a3 -#define op_cmptun 0x0a4 -#define op_cmpteq 0x0a5 -#define op_cmptlt 0x0a6 -#define op_cmptle 0x0a7 -#define op_cvtts 0x0ac -#define op_cvttq 0x0af -#define op_cvtqs 0x0bc -#define op_cvtqt 0x0be -#define op_adds_d 0x0c0 -#define op_subs_d 0x0c1 -#define op_muls_d 0x0c2 -#define op_divs_d 0x0c3 -#define op_addt_d 0x0e0 -#define op_subt_d 0x0e1 -#define op_mult_d 0x0e2 -#define op_divt_d 0x0e3 -#define op_cvtts_d 0x0ec -#define op_cvtqs_d 0x0fc -#define op_cvtqt_d 0x0fe -#define op_adds_uc 0x100 -#define op_subs_uc 0x101 -#define op_muls_uc 0x102 -#define op_divs_uc 0x103 -#define op_addt_uc 0x120 -#define op_subt_uc 0x121 -#define op_mult_uc 0x122 -#define op_divt_uc 0x123 -#define op_cvtts_uc 0x12c -#define op_cvttq_vc 0x12f -#define op_adds_um 0x140 -#define op_subs_um 0x141 -#define op_muls_um 0x142 -#define op_divs_um 0x143 -#define op_addt_um 0x160 -#define op_subt_um 0x161 -#define op_mult_um 0x162 -#define op_divt_um 0x163 -#define op_cvtts_um 0x16c -#define op_adds_u 0x180 -#define op_subs_u 0x181 -#define op_muls_u 0x182 -#define op_divs_u 0x183 -#define op_addt_u 0x1a0 -#define op_subt_u 0x1a1 -#define op_mult_u 0x1a2 -#define op_divt_u 0x1a3 -#define op_cvtts_u 0x1ac -#define op_cvttq_v 0x1af -#define op_adds_ud 0x1c0 -#define op_subs_ud 0x1c1 -#define op_muls_ud 0x1c2 -#define op_divs_ud 0x1c3 -#define op_addt_ud 0x1e0 -#define op_subt_ud 0x1e1 -#define op_mult_ud 0x1e2 -#define op_divt_ud 0x1e3 -#define op_cvtts_ud 0x1ec -#define op_adds_suc 0x500 -#define op_subs_suc 0x501 -#define op_muls_suc 0x502 -#define op_divs_suc 0x503 -#define op_addt_suc 0x520 -#define op_subt_suc 0x521 -#define op_mult_suc 0x522 -#define op_divt_suc 0x523 -#define op_cvtts_suc 0x52c -#define op_cvttq_svc 0x52f -#define op_adds_sum 0x540 -#define op_subs_sum 0x541 -#define op_muls_sum 0x542 -#define op_divs_sum 0x543 -#define op_addt_sum 0x560 -#define op_subt_sum 0x561 -#define op_mult_sum 0x562 -#define op_divt_sum 0x563 -#define op_cvtts_sum 0x56c -#define op_adds_su 0x580 -#define op_subs_su 0x581 -#define op_muls_su 0x582 -#define op_divs_su 0x583 -#define op_addt_su 0x5a0 -#define op_subt_su 0x5a1 -#define op_mult_su 0x5a2 -#define op_divt_su 0x5a3 -#define op_cmptun_su 0x5a4 -#define op_cmpteq_su 0x5a5 -#define op_cmptlt_su 0x5a6 -#define op_cmptle_su 0x5a7 -#define op_cvtts_su 0x5ac -#define op_cvttq_sv 0x5af -#define op_adds_sud 0x5c0 -#define op_subs_sud 0x5c1 -#define op_muls_sud 0x5c2 -#define op_divs_sud 0x5c3 -#define op_addt_sud 0x5e0 -#define op_subt_sud 0x5e1 -#define op_mult_sud 0x5e2 -#define op_divt_sud 0x5e3 -#define op_cvtts_sud 0x5ec -#define op_adds_suic 0x700 -#define op_subs_suic 0x701 -#define op_muls_suic 0x702 -#define op_divs_suic 0x703 -#define op_addt_suic 0x720 -#define op_subt_suic 0x721 -#define op_mult_suic 0x722 -#define op_divt_suic 0x723 -#define op_cvtts_suic 0x72c -#define op_cvttq_svic 0x72f -#define op_cvtqs_suic 0x73c -#define op_cvtqt_suic 0x73e -#define op_adds_suim 0x740 -#define op_subs_suim 0x741 -#define op_muls_suim 0x742 -#define op_divs_suim 0x743 -#define op_addt_suim 0x760 -#define op_subt_suim 0x761 -#define op_mult_suim 0x762 -#define op_divt_suim 0x763 -#define op_cvtts_suim 0x76c -#define op_cvtqs_suim 0x77c -#define op_cvtqt_suim 0x77e -#define op_adds_sui 0x780 -#define op_subs_sui 0x781 -#define op_muls_sui 0x782 -#define op_divs_sui 0x783 -#define op_addt_sui 0x7a0 -#define op_subt_sui 0x7a1 -#define op_mult_sui 0x7a2 -#define op_divt_sui 0x7a3 -#define op_cvtts_sui 0x7ac -#define op_cvttq_svi 0x7af -#define op_cvtqs_sui 0x7bc -#define op_cvtqt_sui 0x7be -#define op_adds_suid 0x7c0 -#define op_subs_suid 0x7c1 -#define op_muls_suid 0x7c2 -#define op_divs_suid 0x7c3 -#define op_addt_suid 0x7e0 -#define op_subt_suid 0x7e1 -#define op_mult_suid 0x7e2 -#define op_divt_suid 0x7e3 -#define op_cvtts_suid 0x7ec -#define op_cvtqs_suid 0x7fc -#define op_cvtqt_suid 0x7fe - - - /* vax FLOAT, "function" opcodes (bits 5..11) */ - -#define op_addf_c 0x000 -#define op_subf_c 0x001 -#define op_mulf_c 0x002 -#define op_divf_c 0x003 -#define op_cvtdg_c 0x01e -#define op_addg_c 0x020 -#define op_subg_c 0x021 -#define op_mulg_c 0x022 -#define op_divg_c 0x023 -#define op_cvtgf_c 0x02c -#define op_cvtgd_c 0x02d -#define op_cvtgqg_c 0x02f -#define op_cvtqf_c 0x03c -#define op_cvtqg_c 0x03e -#define op_addf 0x080 -#define op_subf 0x081 -#define op_mulf 0x082 -#define op_divf 0x083 -#define op_cvtdg 0x09e -#define op_addg 0x0a0 -#define op_subg 0x0a1 -#define op_mulg 0x0a2 -#define op_divg 0x0a3 -#define op_cmpgeq 0x0a5 -#define op_cmpglt 0x0a6 -#define op_cmpgle 0x0a7 -#define op_cvtgf 0x0ac -#define op_cvtgd 0x0ad -#define op_cvtgq 0x0af -#define op_cvtqf 0x0bc -#define op_cvtqg 0x0be -#define op_addf_uc 0x100 -#define op_subf_uc 0x101 -#define op_mulf_uc 0x102 -#define op_divf_uc 0x103 -#define op_cvtdg_uc 0x11e -#define op_addg_uc 0x120 -#define op_subg_uc 0x121 -#define op_mulg_uc 0x122 -#define op_divg_uc 0x123 -#define op_cvtgf_uc 0x12c -#define op_cvtgd_uc 0x12d -#define op_cvtgqg_vc 0x12f -#define op_addf_u 0x180 -#define op_subf_u 0x181 -#define op_mulf_u 0x182 -#define op_divf_u 0x183 -#define op_cvtdg_u 0x19e -#define op_addg_u 0x1a0 -#define op_subg_u 0x1a1 -#define op_mulg_u 0x1a2 -#define op_divg_u 0x1a3 -#define op_cvtgf_u 0x1ac -#define op_cvtgd_u 0x1ad -#define op_cvtgqg_v 0x1af -#define op_addf_sc 0x400 -#define op_subf_sc 0x401 -#define op_mulf_sc 0x402 -#define op_divf_sc 0x403 -#define op_cvtdg_sc 0x41e -#define op_addg_sc 0x420 -#define op_subg_sc 0x421 -#define op_mulg_sc 0x422 -#define op_divg_sc 0x423 -#define op_cvtgf_sc 0x42c -#define op_cvtgd_sc 0x42d -#define op_cvtgqg_sc 0x42f -#define op_cvtqf_sc 0x43c -#define op_cvtqg_sc 0x43e -#define op_addf_s 0x480 -#define op_subf_s 0x481 -#define op_mulf_s 0x482 -#define op_divf_s 0x483 -#define op_cvtdg_s 0x49e -#define op_addg_s 0x4a0 -#define op_subg_s 0x4a1 -#define op_mulg_s 0x4a2 -#define op_divg_s 0x4a3 -#define op_cmpgeq_s 0x4a5 -#define op_cmpglt_s 0x4a6 -#define op_cmpgle_s 0x4a7 -#define op_cvtgf_s 0x4ac -#define op_cvtgd_s 0x4ad -#define op_cvtgqg_s 0x4af -#define op_cvtqf_s 0x4bc -#define op_cvtqg_s 0x4be -#define op_addf_suc 0x500 -#define op_subf_suc 0x501 -#define op_mulf_suc 0x502 -#define op_divf_suc 0x503 -#define op_cvtdg_suc 0x51e -#define op_addg_suc 0x520 -#define op_subg_suc 0x521 -#define op_mulg_suc 0x522 -#define op_divg_suc 0x523 -#define op_cvtgf_suc 0x52c -#define op_cvtgd_suc 0x52d -#define op_cvtgqg_svc 0x52f -#define op_addf_su 0x580 -#define op_subf_su 0x581 -#define op_mulf_su 0x582 -#define op_divf_su 0x583 -#define op_cvtdg_su 0x59e -#define op_addg_su 0x5a0 -#define op_subg_su 0x5a1 -#define op_mulg_su 0x5a2 -#define op_divg_su 0x5a3 -#define op_cvtgf_su 0x5ac -#define op_cvtgd_su 0x5ad -#define op_cvtgqg_sv 0x5af - -#endif /* _ALPHA_INSTRUCTION_H_ */ diff --git a/usr.bin/pmdb/arch/alpha/alpha_trace.c b/usr.bin/pmdb/arch/alpha/alpha_trace.c deleted file mode 100644 index f143f61cd50..00000000000 --- a/usr.bin/pmdb/arch/alpha/alpha_trace.c +++ /dev/null @@ -1,337 +0,0 @@ -/* $OpenBSD: alpha_trace.c,v 1.7 2004/07/22 15:11:37 miod Exp $ */ -/* - * Copyright (c) 2002 Artur Grabowski <art@openbsd.org> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * Copyright (c) 1997 Niklas Hallqvist. All rights reserved. - * Copyright (c) 1997 Theo de Raadt. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include <sys/param.h> -#include <sys/ptrace.h> -#include <machine/reg.h> -#include <machine/frame.h> - -#include <stdio.h> -#include <string.h> - -#include "pmdb.h" -#include "alpha_instruction.h" -#include "symbol.h" - -struct opcode { - enum opc_fmt { OPC_PAL, OPC_RES, OPC_MEM, OPC_OP, OPC_BR } opc_fmt; - char *opc_name; - int opc_print; -}; - -#define inst_return(ins) (((ins) & 0xfc000000) == 0x68000000) - -const struct opcode opcode[] = { - { OPC_PAL, "call_pal", 0 }, /* 00 */ - { OPC_RES, "opc01", 0 }, /* 01 */ - { OPC_RES, "opc02", 0 }, /* 02 */ - { OPC_RES, "opc03", 0 }, /* 03 */ - { OPC_RES, "opc04", 0 }, /* 04 */ - { OPC_RES, "opc05", 0 }, /* 05 */ - { OPC_RES, "opc06", 0 }, /* 06 */ - { OPC_RES, "opc07", 0 }, /* 07 */ - { OPC_MEM, "lda", 1 }, /* 08 */ - { OPC_MEM, "ldah", 1 }, /* 09 */ - { OPC_RES, "opc0a", 0 }, /* 0A */ - { OPC_MEM, "ldq_u", 1 }, /* 0B */ - { OPC_RES, "opc0c", 0 }, /* 0C */ - { OPC_RES, "opc0d", 0 }, /* 0D */ - { OPC_RES, "opc0e", 0 }, /* 0E */ - { OPC_MEM, "stq_u", 1 }, /* 0F */ - { OPC_OP, "inta", 0 }, /* 10 */ - { OPC_OP, "intl", 0 }, /* 11 */ - { OPC_OP, "ints", 0 }, /* 12 */ - { OPC_OP, "intm", 0 }, /* 13 */ - { OPC_RES, "opc14", 0 }, /* 14 */ - { OPC_OP, "fltv", 1 }, /* 15 */ - { OPC_OP, "flti", 1 }, /* 16 */ - { OPC_OP, "fltl", 1 }, /* 17 */ - { OPC_MEM, "misc", 0 }, /* 18 */ - { OPC_PAL, "pal19", 0 }, /* 19 */ - { OPC_MEM, "jsr", 0 }, /* 1A */ - { OPC_PAL, "pal1b", 0 }, /* 1B */ - { OPC_RES, "opc1c", 0 }, /* 1C */ - { OPC_PAL, "pal1d", 0 }, /* 1D */ - { OPC_PAL, "pal1e", 0 }, /* 1E */ - { OPC_PAL, "pal1f", 0 }, /* 1F */ - { OPC_MEM, "ldf", 1 }, /* 20 */ - { OPC_MEM, "ldg", 1 }, /* 21 */ - { OPC_MEM, "lds", 1 }, /* 22 */ - { OPC_MEM, "ldt", 1 }, /* 23 */ - { OPC_MEM, "stf", 1 }, /* 24 */ - { OPC_MEM, "stg", 1 }, /* 25 */ - { OPC_MEM, "sts", 1 }, /* 26 */ - { OPC_MEM, "stt", 1 }, /* 27 */ - { OPC_MEM, "ldl", 1 }, /* 28 */ - { OPC_MEM, "ldq", 1 }, /* 29 */ - { OPC_MEM, "ldl_l", 1 }, /* 2A */ - { OPC_MEM, "ldq_l", 1 }, /* 2B */ - { OPC_MEM, "stl", 1 }, /* 2C */ - { OPC_MEM, "stq", 1 }, /* 2D */ - { OPC_MEM, "stl_c", 1 }, /* 2E */ - { OPC_MEM, "stq_c", 1 }, /* 2F */ - { OPC_BR, "br", 1 }, /* 30 */ - { OPC_BR, "fbeq", 1 }, /* 31 */ - { OPC_BR, "fblt", 1 }, /* 32 */ - { OPC_BR, "fble", 1 }, /* 33 */ - { OPC_BR, "bsr", 1 }, /* 34 */ - { OPC_BR, "fbne", 1 }, /* 35 */ - { OPC_BR, "fbge", 1 }, /* 36 */ - { OPC_BR, "fbgt", 1 }, /* 37 */ - { OPC_BR, "blbc", 1 }, /* 38 */ - { OPC_BR, "beq", 1 }, /* 39 */ - { OPC_BR, "blt", 1 }, /* 3A */ - { OPC_BR, "ble", 1 }, /* 3B */ - { OPC_BR, "blbs", 1 }, /* 3C */ - { OPC_BR, "bne", 1 }, /* 3D */ - { OPC_BR, "bge", 1 }, /* 3E */ - { OPC_BR, "bgt", 1 }, /* 3F */ -}; - -int -inst_load(int ins) -{ - alpha_instruction insn; - - insn.bits = ins; - - /* Loads. */ - if (insn.mem_format.opcode == op_ldbu || - insn.mem_format.opcode == op_ldq_u || - insn.mem_format.opcode == op_ldwu) - return (1); - if ((insn.mem_format.opcode >= op_ldf) && - (insn.mem_format.opcode <= op_ldt)) - return (1); - if ((insn.mem_format.opcode >= op_ldl) && - (insn.mem_format.opcode <= op_ldq_l)) - return (1); - - /* Prefetches. */ - if (insn.mem_format.opcode == op_special) { - /* Note: MB is treated as a store. */ - if ((insn.mem_format.displacement == (short)op_fetch) || - (insn.mem_format.displacement == (short)op_fetch_m)) - return (1); - } - - return (0); -} - -static __inline int sext(u_int); -static __inline int rega(u_int); -static __inline int regb(u_int); -static __inline int regc(u_int); -static __inline int disp(u_int); - -static __inline int -sext(x) - u_int x; -{ - return ((x & 0x8000) ? -(-x & 0xffff) : (x & 0xffff)); -} - -static __inline int -rega(x) - u_int x; -{ - return ((x >> 21) & 0x1f); -} - -static __inline int -regb(x) - u_int x; -{ - return ((x >> 16) & 0x1f); -} - -static __inline int -regc(x) - u_int x; -{ - return (x & 0x1f); -} - -static __inline int -disp(x) - u_int x; -{ - return (sext(x & 0xffff)); -} - -/* - * XXX There are a couple of problems with this code: - * - * The argument list printout code is likely to get confused. - * - * It relies on the conventions of gcc code generation. - * - * It uses heuristics to calculate the framesize, and might get it wrong. - * - * It doesn't yet use the framepointer if available. - * - * The address argument can only be used for pointing at trapframes - * since a frame pointer of its own serves no good on the alpha, - * you need a pc value too. - * - * The heuristics used for tracing through a trap relies on having - * symbols available. - */ -int -md_getframe(struct pstate *ps, int framec, struct md_frame *fram) -{ - reg frame; - int i, framesize; - reg pc, ra; - u_int inst; - char *name; - char namebuf[1024]; - reg offset; - reg slot[32]; - struct reg regs; - int count; - - bzero(slot, sizeof(slot)); - - if (process_getregs(ps, ®s)) - return (-1); - - for (i = 0; i < 32; i++) - slot[i] = -1; - - frame = regs.r_regs[R_SP]; - pc = regs.r_regs[R_ZERO]; /* Ieeek. on drugs. */ - ra = regs.r_regs[R_RA]; - - for (count = 0; count < framec + 1; count++) { - /* XXX - better out of bounds check needed. */ - if (pc < 0x1000 || pc == 0xffffffffffffffff) { - return -1; - } - - name = sym_name_and_offset(ps, pc, namebuf, - sizeof(namebuf), &offset); - if (!name) { - /* Limit the search for procedure start */ - offset = 65536; - } - - framesize = 0; - for (i = sizeof (int); i <= offset; i += sizeof (int)) { - if (process_read(ps, pc - i, &inst, sizeof(inst)) < 0) - return -1; - - /* - * If by chance we don't have any symbols we have to - * get out somehow anyway. Check for the preceding - * procedure return in that case. - */ - if (name == NULL && inst_return(inst)) - break; - - /* - * Disassemble to get the needed info for the frame. - */ - if ((inst & 0xffff0000) == 0x23de0000) { - /* lda sp,n(sp) */ - framesize -= disp(inst) / sizeof (u_long); - } else if ((inst & 0xfc1f0000) == 0xb41e0000) { - /* stq X,n(sp) */ - slot[rega(inst)] = frame + disp(inst); - } else if ((inst & 0xfc000fe0) == 0x44000400 && - rega(inst) == regb(inst)) { - /* bis X,X,Y (aka mov X,Y) */ - /* zero is hardwired */ - if (rega(inst) != 31) - slot[rega(inst)] = slot[regc(inst)]; - slot[regc(inst)] = 0; - /* - * XXX In here we might special case a frame - * pointer setup, i.e. mov sp, fp. - */ - } else if (inst_load(inst)) { - /* clobbers a register */ - slot[rega(inst)] = 0; - } else if (opcode[inst >> 26].opc_fmt == OPC_OP) { - /* clobbers a register */ - slot[regc(inst)] = 0; - } - /* - * XXX Recognize more reg clobbering instructions and - * set slot[reg] = 0 then too. - */ - } - - fram->pc = pc; - fram->fp = frame; - - /* Look for the return address if recorded. */ - if (slot[R_RA]) { - if (slot[R_RA] == -1) - ra = regs.r_regs[R_RA]; - else - if (process_read(ps, (off_t)slot[R_RA], - &ra, sizeof(ra)) < 0) - return -1; - } else { - break; - } - - /* Advance to the next frame. */ - frame += framesize * sizeof(u_long); - if (pc == ra) { - break; - } - pc = ra; - } - - return count == framec + 1 ? 0 : -1; -} diff --git a/usr.bin/pmdb/arch/alpha/pmdb_machdep.h b/usr.bin/pmdb/arch/alpha/pmdb_machdep.h deleted file mode 100644 index a25ae1149fc..00000000000 --- a/usr.bin/pmdb/arch/alpha/pmdb_machdep.h +++ /dev/null @@ -1,29 +0,0 @@ -/* $OpenBSD: pmdb_machdep.h,v 1.3 2003/01/27 08:21:34 art Exp $ */ -/* - * Copyright (c) 2002 Artur Grabowski <art@openbsd.org> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#define BREAKPOINT { 0x80, 0, 0, 0 } -#define BREAKPOINT_LEN 4 -#define BREAKPOINT_DECR_PC 4 diff --git a/usr.bin/pmdb/arch/amd64/Makefile.inc b/usr.bin/pmdb/arch/amd64/Makefile.inc deleted file mode 100644 index d8b9880fd19..00000000000 --- a/usr.bin/pmdb/arch/amd64/Makefile.inc +++ /dev/null @@ -1,3 +0,0 @@ -# $OpenBSD: Makefile.inc,v 1.2 2004/02/28 18:51:32 deraadt Exp $ - -SRCS+= amd64.c diff --git a/usr.bin/pmdb/arch/amd64/amd64.c b/usr.bin/pmdb/arch/amd64/amd64.c deleted file mode 100644 index ee3e35a9853..00000000000 --- a/usr.bin/pmdb/arch/amd64/amd64.c +++ /dev/null @@ -1,94 +0,0 @@ -/* $OpenBSD: amd64.c,v 1.1 2004/02/28 18:51:32 deraadt Exp $ */ - -/* - * Copyright (c) 2002 Federico Schwindt <fgsch@openbsd.org> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include <sys/param.h> -#include <sys/ptrace.h> -#include <machine/reg.h> -#include <machine/frame.h> -#include <string.h> -#include "pmdb.h" - -/* - * No frame for x86? - */ -struct frame { - long fp; - long pc; -}; - -static const char *md_reg_names[] = { - "%rdi", "%rsi", "%rdx", "%rcx", "%r8", "%r9", "%r10", "%r11", - "%r12", "%r13", "%r14", "%r15", "%rbp", "%rbx", "%rax", "%rsp", - "%rip", "%rflags", "%cs", "%ss", "%ds", "%es", "%fs", "%gs", -}; - -struct md_def md_def = { md_reg_names, 16, 8 }; - -void -md_def_init(void) -{ - /* no need to do anything */ -} - -int -md_getframe(struct pstate *ps, int frame, struct md_frame *fram) -{ - struct frame fr; - struct reg r; - int count; - - if (process_getregs(ps, &r) != 0) - return (-1); - - fr.fp = r.r_rbp; - fr.pc = r.r_rip; - for (count = 0; count < frame; count++) { - if (process_read(ps, fr.fp, &fr, sizeof(fr)) < 0) - return (-1); - - if (fr.pc < 0x1000) - return (-1); - } - - fram->pc = fr.pc; - fram->fp = fr.fp; - - return (0); -} - -int -md_getregs(struct pstate *ps, reg *regs) -{ - struct reg r; - - if (process_getregs(ps, &r) != 0) - return (-1); - - memcpy(regs, &r, sizeof(r)); - - return (0); -} diff --git a/usr.bin/pmdb/arch/amd64/pmdb_machdep.h b/usr.bin/pmdb/arch/amd64/pmdb_machdep.h deleted file mode 100644 index 48c77bda09a..00000000000 --- a/usr.bin/pmdb/arch/amd64/pmdb_machdep.h +++ /dev/null @@ -1,29 +0,0 @@ -/* $OpenBSD: pmdb_machdep.h,v 1.1 2004/01/29 12:44:40 mickey Exp $ */ -/* - * Copyright (c) 2002 Artur Grabowski <art@openbsd.org> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#define BREAKPOINT { 0xcc } -#define BREAKPOINT_LEN 1 -#define BREAKPOINT_DECR_PC 1 diff --git a/usr.bin/pmdb/arch/arm/Makefile.inc b/usr.bin/pmdb/arch/arm/Makefile.inc deleted file mode 100644 index 176665cf595..00000000000 --- a/usr.bin/pmdb/arch/arm/Makefile.inc +++ /dev/null @@ -1 +0,0 @@ -SRCS+=arm.c diff --git a/usr.bin/pmdb/arch/arm/arm.c b/usr.bin/pmdb/arch/arm/arm.c deleted file mode 100644 index bc0965bb294..00000000000 --- a/usr.bin/pmdb/arch/arm/arm.c +++ /dev/null @@ -1,92 +0,0 @@ -/* $OpenBSD: arm.c,v 1.1 2004/02/02 19:42:26 drahn Exp $ */ -/* - * Copyright (c) 2002 Dale Rahn <drahn@openbsd.org> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - - -#include <stddef.h> -#include <sys/param.h> -#include <sys/ptrace.h> -#include <machine/reg.h> -#include <machine/frame.h> -#include <string.h> -#include "pmdb.h" - -static const char *md_reg_names[] = { - "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", - "r8", "r9", "r10","r11","r12","sp", "lr", "pc", "cpsr" -}; - -struct md_def md_def = { md_reg_names, 16, 16}; - -void -md_def_init(void) -{ - /* no need to do anything */ -} - -int -md_getframe(struct pstate *ps, int frame, struct md_frame *fram) -{ - struct reg r; - reg fp, pc; - int i; - - if (process_getregs(ps, &r)) - return (-1); - fp = r.r_sp; - if (frame == 0) { - pc = r.r_pc; - goto out; - } - pc = r.r_lr; - for (i = 1; i < frame; i++) { - if (fp != (fp & ~7)) { /* should be 0xf */ - return -1; - } - if (process_read(ps, fp, &fp, sizeof(fp)) < 0) - return -1; - if (process_read(ps, fp+4, &pc, sizeof(pc)) < 0) - return -1; - if (fp == 0) { - return -1; - } - } -out: - fram->pc = pc; - fram->fp = fp; - fram->nargs = 0; - return 0; -} - -int -md_getregs(struct pstate *ps, reg *regs) -{ - struct reg md_reg; - if (process_getregs(ps, &md_reg)) - return -1; - memcpy(regs, &md_reg, 32 * sizeof(long)); - memcpy(®s[32], &md_reg.r_pc, 7 * sizeof(long)); - return 0; -} diff --git a/usr.bin/pmdb/arch/arm/pmdb_machdep.h b/usr.bin/pmdb/arch/arm/pmdb_machdep.h deleted file mode 100644 index 021fe0e7b6f..00000000000 --- a/usr.bin/pmdb/arch/arm/pmdb_machdep.h +++ /dev/null @@ -1,30 +0,0 @@ -/* $OpenBSD: pmdb_machdep.h,v 1.1 2004/02/02 19:42:26 drahn Exp $ */ -/* - * Copyright (c) 2002 Dale Rahn <drahn@openbsd.org> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* SWI */ -#define BREAKPOINT { 0xef, 0xaf, 0xff, 0xff } -#define BREAKPOINT_LEN 4 -#define BREAKPOINT_DECR_PC 4 diff --git a/usr.bin/pmdb/arch/hppa/Makefile.inc b/usr.bin/pmdb/arch/hppa/Makefile.inc deleted file mode 100644 index 561d7d459d0..00000000000 --- a/usr.bin/pmdb/arch/hppa/Makefile.inc +++ /dev/null @@ -1,3 +0,0 @@ -# $OpenBSD: Makefile.inc,v 1.2 2002/03/15 18:33:03 mickey Exp $ - -SRCS+=hppa.c diff --git a/usr.bin/pmdb/arch/hppa/hppa.c b/usr.bin/pmdb/arch/hppa/hppa.c deleted file mode 100644 index 321260265c1..00000000000 --- a/usr.bin/pmdb/arch/hppa/hppa.c +++ /dev/null @@ -1,106 +0,0 @@ -/* $OpenBSD: hppa.c,v 1.9 2012/08/29 21:52:45 kettenis Exp $ */ - -/* - * Copyright (c) 2002-2003 Michael Shalayeff - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING - * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - - -#include <sys/param.h> -#include <sys/ptrace.h> -#include <machine/reg.h> -#include <string.h> -#include "pmdb.h" - -static const char *md_reg_names[] = { - "%psw", "%r1", "%rp", "%r3", "%r4", "%r5", "%r6", "%r7", - "%r8", "%r9", "%r10", "%r11", "%r12", "%r13", "%r14", "%r15", - "%r16", "%r17", "%r18", "%r19", "%r20", "%r21", "%r22", "%r23", - "%r24", "%r25", "%r26", "%r27", "%r28", "%r29", "%r30", "%r31", - "%sar", "%pcsqh", "%pcsqt", "%pcoqh", "%pcoqt", - "%sr0", "%sr1", "%sr2", "%sr3", "%sr4", "%sr5", "%sr6", "%sr7", - "%cr26", "%cr27" -}; - -struct md_def md_def = { md_reg_names, 47, 35 }; - -void -md_def_init(void) -{ - /* no need to do anything */ -} - -int -md_getframe(struct pstate *ps, int frame, struct md_frame *fram) -{ - reg fr[16]; - struct reg r; - reg fp, pc, rp; - int i; - - if (process_getregs(ps, &r)) - return (-1); - - rp = r.r_regs[2]; - fp = r.r_regs[3]; - pc = r.r_pcoqh; - - for (i = 0; i < frame; i++) { - - if (!fp) - return (-1); - - if (process_read(ps, fp-15*4, &fr, sizeof(fr)) < 0) - return (-1); - - pc = rp; - fp = fr[15]; - rp = fr[10]; - } - fram->pc = pc; - fram->fp = fp; - - if (frame != 0) { - fram->nargs = 4; /* XXX real number is in the symtab */ - fram->args[3] = fr[3]; - fram->args[2] = fr[4]; - fram->args[1] = fr[5]; - fram->args[0] = fr[6]; - } - - return (0); -} - -int -md_getregs(struct pstate *ps, reg *regs) -{ - struct reg r; - - if (process_getregs(ps, &r)) - return (-1); - - memcpy(regs, &r, sizeof(r)); - - return (0); -} diff --git a/usr.bin/pmdb/arch/hppa/pmdb_machdep.h b/usr.bin/pmdb/arch/hppa/pmdb_machdep.h deleted file mode 100644 index ed5f32754ca..00000000000 --- a/usr.bin/pmdb/arch/hppa/pmdb_machdep.h +++ /dev/null @@ -1,31 +0,0 @@ -/* $OpenBSD: pmdb_machdep.h,v 1.3 2003/01/28 20:43:44 mickey Exp $ */ - -/* - * Copyright (c) 2002-2003 Michael Shalayeff - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING - * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#define BREAKPOINT { 0x00, 0x01, 0x00, 0x00 } -#define BREAKPOINT_LEN 4 -#define BREAKPOINT_DECR_PC 0 diff --git a/usr.bin/pmdb/arch/i386/Makefile.inc b/usr.bin/pmdb/arch/i386/Makefile.inc deleted file mode 100644 index a8691faaeaf..00000000000 --- a/usr.bin/pmdb/arch/i386/Makefile.inc +++ /dev/null @@ -1,3 +0,0 @@ -# $OpenBSD: Makefile.inc,v 1.2 2002/03/15 16:41:06 jason Exp $ - -SRCS+= i386.c diff --git a/usr.bin/pmdb/arch/i386/i386.c b/usr.bin/pmdb/arch/i386/i386.c deleted file mode 100644 index 547bae7e1fb..00000000000 --- a/usr.bin/pmdb/arch/i386/i386.c +++ /dev/null @@ -1,92 +0,0 @@ -/* $OpenBSD: i386.c,v 1.6 2004/02/17 00:52:22 jfb Exp $ */ -/* - * Copyright (c) 2002 Federico Schwindt <fgsch@openbsd.org> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include <sys/param.h> -#include <sys/ptrace.h> -#include <machine/reg.h> -#include <machine/frame.h> -#include <string.h> -#include "pmdb.h" - -/* - * No frame for x86? - */ -struct frame { - u_int32_t fp; - u_int32_t pc; -}; - -static const char *md_reg_names[] = { - "%eax", "%ecx", "%edx", "%ebx", "%esp", "%ebp", "%esi", "%edi", "%eip", - "%eflags", "%cs", "%ss", "%ds", "%es", "%fs", "%gs" -}; - -struct md_def md_def = { md_reg_names, 16, 8 }; - -void -md_def_init(void) -{ - /* no need to do anything */ -} - -int -md_getframe(struct pstate *ps, int frame, struct md_frame *fram) -{ - struct frame fr; - struct reg r; - int count; - - 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 (process_read(ps, (off_t)fr.fp, &fr, sizeof(fr)) < 0) - return (-1); - - if (fr.pc < 0x1000) - return (-1); - } - - fram->pc = (reg)fr.pc; - fram->fp = (reg)fr.fp; - - return (0); -} - -int -md_getregs(struct pstate *ps, reg *regs) -{ - struct reg r; - - if (process_getregs(ps, &r) != 0) - return (-1); - - memcpy(regs, &r, sizeof(r)); - - return (0); -} diff --git a/usr.bin/pmdb/arch/i386/pmdb_machdep.h b/usr.bin/pmdb/arch/i386/pmdb_machdep.h deleted file mode 100644 index 4928418fc74..00000000000 --- a/usr.bin/pmdb/arch/i386/pmdb_machdep.h +++ /dev/null @@ -1,29 +0,0 @@ -/* $OpenBSD: pmdb_machdep.h,v 1.3 2003/01/27 08:21:35 art Exp $ */ -/* - * Copyright (c) 2002 Artur Grabowski <art@openbsd.org> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#define BREAKPOINT { 0xcc } -#define BREAKPOINT_LEN 1 -#define BREAKPOINT_DECR_PC 1 diff --git a/usr.bin/pmdb/arch/m68k/Makefile.inc b/usr.bin/pmdb/arch/m68k/Makefile.inc deleted file mode 100644 index 3c2ddd281f7..00000000000 --- a/usr.bin/pmdb/arch/m68k/Makefile.inc +++ /dev/null @@ -1,3 +0,0 @@ -# $OpenBSD: Makefile.inc,v 1.1 2003/05/30 19:32:53 miod Exp $ - -SRCS+= m68k.c diff --git a/usr.bin/pmdb/arch/m68k/m68k.c b/usr.bin/pmdb/arch/m68k/m68k.c deleted file mode 100644 index b502ce080c0..00000000000 --- a/usr.bin/pmdb/arch/m68k/m68k.c +++ /dev/null @@ -1,86 +0,0 @@ -/* $OpenBSD: m68k.c,v 1.1 2003/05/30 19:32:53 miod Exp $ */ -/* - * Copyright (c) 2003, Miodrag Vallat. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include <sys/param.h> -#include <sys/ptrace.h> -#include <machine/reg.h> -#include <machine/frame.h> -#include "pmdb.h" - -static const char *md_reg_names[] = { - "%d0", "%d1", "%d2", "%d3", "%d4", "%d5", "%d6", "%d7", - "%a0", "%a1", "%a2", "%a3", "%a4", "%a5", "%a6", "%a7", - "%sr", "%pc" -}; - -struct md_def md_def = { md_reg_names, 18, 17 }; - -void -md_def_init(void) -{ - /* nothing to do */ -} - -int -md_getframe(struct pstate *ps, int framenum, struct md_frame *fram) -{ - struct frame fr; - struct reg r; - int count; - - if (process_getregs(ps, &r) != 0) - return (-1); - - fr.f_regs[15] = r.r_regs[15]; /* a7 */ - fr.f_pc = r.r_pc; - for (count = 0; count < framenum; count++) { - if (process_read(ps, fr.f_regs[15], &fr, sizeof(fr)) < 0) - return (-1); - - if (fr.f_pc < 0x1000) - return (-1); - } - - fram->pc = fr.f_pc; - fram->fp = fr.f_regs[15]; - - return (0); -} - -int -md_getregs(struct pstate *ps, reg *regs) -{ - struct reg r; - - if (process_getregs(ps, &r) != 0) - return (-1); - - memcpy(regs, &r, sizeof(r)); - - return (0); -} diff --git a/usr.bin/pmdb/arch/m68k/pmdb_machdep.h b/usr.bin/pmdb/arch/m68k/pmdb_machdep.h deleted file mode 100644 index a7b358f0882..00000000000 --- a/usr.bin/pmdb/arch/m68k/pmdb_machdep.h +++ /dev/null @@ -1,31 +0,0 @@ -/* $OpenBSD: pmdb_machdep.h,v 1.1 2003/05/30 19:32:53 miod Exp $ */ -/* - * Copyright (c) 2003, Miodrag Vallat. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - */ - -#define BREAKPOINT { 0x4e, 0x4f } -#define BREAKPOINT_LEN 2 -#define BREAKPOINT_DECR_PC 2 diff --git a/usr.bin/pmdb/arch/m88k/Makefile.inc b/usr.bin/pmdb/arch/m88k/Makefile.inc deleted file mode 100644 index 09fad97f3b0..00000000000 --- a/usr.bin/pmdb/arch/m88k/Makefile.inc +++ /dev/null @@ -1,3 +0,0 @@ -# $OpenBSD: Makefile.inc,v 1.1 2003/05/30 20:50:31 miod Exp $ - -SRCS+= m88k.c diff --git a/usr.bin/pmdb/arch/m88k/m88k.c b/usr.bin/pmdb/arch/m88k/m88k.c deleted file mode 100644 index 17547155298..00000000000 --- a/usr.bin/pmdb/arch/m88k/m88k.c +++ /dev/null @@ -1,96 +0,0 @@ -/* $OpenBSD: m88k.c,v 1.3 2006/11/19 09:27:21 miod Exp $ */ -/* - * Copyright (c) 2003, Miodrag Vallat. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include <sys/param.h> -#include <sys/ptrace.h> -#include <machine/reg.h> -#include <machine/pcb.h> -#include "pmdb.h" - -static const char *md_reg_names[] = { - "%r0", "%r1", "%r2", "%r3", "%r4", "%r5", "%r6", "%r7", - "%r8", "%r9", "%r10", "%r11", "%r12", "%r13", "%r14", "%r15", - "%r16", "%r17", "%r18", "%r19", "%r20", "%r21", "%r22", "%r23", - "%r24", "%r25", "%r26", "%r27", "%r28", "%r29", "%r30", "%sp", - "%epsr", "%fpsr", "%fpcr", - "%sxip", "%snip", "%sfip", - "%ssbr", - "%dmt0", "%dmd0", "%dma0", - "%dmt1", "%dmd1", "%dma1", - "%dmt2", "%dmd2", "%dma2", - "%fpecr", "%fphs1", "%fpls1", "%fphs2", "%fpls2", - "%fppt", "%fprh", "%fprl", "%fpit" -}; - -struct md_def md_def = { md_reg_names, 57, 35 }; - -void -md_def_init(void) -{ - /* nothing to do */ -} - -int -md_getframe(struct pstate *ps, int framenum, struct md_frame *fram) -{ - struct trapframe fr; - struct reg r; - int count; - - if (process_getregs(ps, &r) != 0) - return (-1); - - fr.tf_sp = r.r[31]; - fr.tf_sxip = r.sxip; - - for (count = 0; count < framenum; count++) { - if (process_read(ps, fr.tf_sp, &fr, sizeof(fr)) < 0) - return (-1); - - if (fr.tf_sxip < 0x1000) - return (-1); - } - - fram->pc = fr.tf_sxip; - fram->fp = fr.tf_sp; - - return (0); -} - -int -md_getregs(struct pstate *ps, reg *regs) -{ - struct reg r; - - if (process_getregs(ps, &r) != 0) - return (-1); - - memcpy(regs, &r, sizeof(r)); - - return (0); -} diff --git a/usr.bin/pmdb/arch/m88k/pmdb_machdep.h b/usr.bin/pmdb/arch/m88k/pmdb_machdep.h deleted file mode 100644 index 2a0afc25f7a..00000000000 --- a/usr.bin/pmdb/arch/m88k/pmdb_machdep.h +++ /dev/null @@ -1,31 +0,0 @@ -/* $OpenBSD: pmdb_machdep.h,v 1.1 2003/05/30 20:50:31 miod Exp $ */ -/* - * Copyright (c) 2003, Miodrag Vallat. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - */ - -#define BREAKPOINT { 0xf0, 0x00, 0xd0, 0x82 } -#define BREAKPOINT_LEN 4 -#define BREAKPOINT_DECR_PC 0 diff --git a/usr.bin/pmdb/arch/mips64/Makefile.inc b/usr.bin/pmdb/arch/mips64/Makefile.inc deleted file mode 100644 index 725deef9b76..00000000000 --- a/usr.bin/pmdb/arch/mips64/Makefile.inc +++ /dev/null @@ -1 +0,0 @@ -SRCS+=mips64.c diff --git a/usr.bin/pmdb/arch/mips64/mips64.c b/usr.bin/pmdb/arch/mips64/mips64.c deleted file mode 100644 index 1af5d0eee81..00000000000 --- a/usr.bin/pmdb/arch/mips64/mips64.c +++ /dev/null @@ -1,95 +0,0 @@ -/* $OpenBSD: mips64.c,v 1.2 2004/11/11 19:09:28 pefo Exp $ */ -/* - * Copyright (c) 2002 Dale Rahn <drahn@openbsd.org> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - - -#include <stddef.h> -#include <string.h> -#include <sys/param.h> -#include <sys/ptrace.h> -#include <machine/reg.h> -#include <machine/frame.h> -#include "pmdb.h" - -static const char *md_reg_names[] = { - "zero", "AT", "v0", "v1", "a0", "a1", "a2", "a3", - "a4", "a5", "a6","a7","t0","t1","t2","t3", - "s0","s1","s2","s3","s4","s5","s6","s7", - "t8","t9","k0","k1","gp","sp","s8","ra", - "sr", "mullo", "mulhi", "badvaddr", "cause", "pc", "ic", "cpl" - "$f0", "$f1", "$f2", "$f3", "$f4", "$f5", "$f6", "$f7", - "$f8", "$f9", "$f10", "$f11", "$f12", "$f13", "$f14", "$f15", - "$f16", "$f17", "$f18", "$f19", "$f20", "$f21", "$f22", "$f23", - "$f24", "$f25", "$f26", "$f27", "$f28", "$f29", "$f30", "$f31", - "fsr" -}; - -struct md_def md_def = { md_reg_names, NREGS, PC}; - -void -md_def_init(void) -{ - /* no need to do anything */ -} - -int -md_getframe(struct pstate *ps, int frame, struct md_frame *fram) -{ - struct reg r; - reg fp, pc; - - if (process_getregs(ps, &r)) - return (-1); - fp = r.r_regs[SP]; - if (frame == 0) { - pc = r.r_regs[PC]; - goto out; - } - pc = r.r_regs[RA]; - - /* XXX Digging out the frames are a little tricky - * especially with gcc3 which throws around the code - * quite a bit. We don't have a frame pointer and - * and does not know the size of the frame. - * Need to think about a strategy... - */ - if (frame > 1) - return -1; -out: - fram->pc = pc; - fram->fp = fp; - fram->nargs = 0; - return 0; -} - -int -md_getregs(struct pstate *ps, reg *regs) -{ - struct reg md_reg; - if (process_getregs(ps, &md_reg)) - return -1; - memcpy(regs, &md_reg, NREGS * sizeof(long)); - return 0; -} diff --git a/usr.bin/pmdb/arch/mips64/pmdb_machdep.h b/usr.bin/pmdb/arch/mips64/pmdb_machdep.h deleted file mode 100644 index 6ecea7c415f..00000000000 --- a/usr.bin/pmdb/arch/mips64/pmdb_machdep.h +++ /dev/null @@ -1,29 +0,0 @@ -/* $OpenBSD: pmdb_machdep.h,v 1.1 2004/11/11 18:47:14 pefo Exp $ */ -/* - * Copyright (c) 2002 Dale Rahn <drahn@openbsd.org> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#define BREAKPOINT { 0x02, 0x02, 0x00, 0x0d } -#define BREAKPOINT_LEN 4 -#define BREAKPOINT_DECR_PC 0 diff --git a/usr.bin/pmdb/arch/powerpc/Makefile.inc b/usr.bin/pmdb/arch/powerpc/Makefile.inc deleted file mode 100644 index aaab0f8524f..00000000000 --- a/usr.bin/pmdb/arch/powerpc/Makefile.inc +++ /dev/null @@ -1 +0,0 @@ -SRCS+=powerpc.c diff --git a/usr.bin/pmdb/arch/powerpc/pmdb_machdep.h b/usr.bin/pmdb/arch/powerpc/pmdb_machdep.h deleted file mode 100644 index 72d715dfab8..00000000000 --- a/usr.bin/pmdb/arch/powerpc/pmdb_machdep.h +++ /dev/null @@ -1,29 +0,0 @@ -/* $OpenBSD: pmdb_machdep.h,v 1.4 2003/01/27 12:45:29 drahn Exp $ */ -/* - * Copyright (c) 2002 Dale Rahn <drahn@openbsd.org> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#define BREAKPOINT { 0x7C, 0x81, 0x08, 0x08 } -#define BREAKPOINT_LEN 4 -#define BREAKPOINT_DECR_PC 4 diff --git a/usr.bin/pmdb/arch/powerpc/powerpc.c b/usr.bin/pmdb/arch/powerpc/powerpc.c deleted file mode 100644 index 4abee588332..00000000000 --- a/usr.bin/pmdb/arch/powerpc/powerpc.c +++ /dev/null @@ -1,97 +0,0 @@ -/* $OpenBSD: powerpc.c,v 1.4 2009/10/05 00:05:22 deraadt Exp $ */ -/* - * Copyright (c) 2002 Dale Rahn <drahn@openbsd.org> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - - -#include <sys/param.h> -#include <sys/ptrace.h> -#include <machine/reg.h> -#include <machine/frame.h> - -#include <stddef.h> -#include <string.h> - -#include "pmdb.h" - -static const char *md_reg_names[] = { - "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", - "r8", "r9", "r10","r11","r12","r13","r14","r15", - "r16","r17","r18","r19","r20","r21","r22","r23", - "r24","r25","r26","r27","r28","r29","r30","r31", - "pc", "ps", "cnd", "lr", "cnt", "xer", "mq" -}; - -struct md_def md_def = { md_reg_names, 39, 32}; - -void -md_def_init(void) -{ - /* no need to do anything */ -} - -int -md_getframe(struct pstate *ps, int frame, struct md_frame *fram) -{ - struct reg r; - reg fp, pc; - int i; - - if (process_getregs(ps, &r)) - return (-1); - fp = r.gpr[1]; - if (frame == 0) { - pc = r.pc; - goto out; - } - pc = r.lr; - for (i = 1; i < frame; i++) { - if (fp != (fp & ~7)) { /* should be 0xf */ - return -1; - } - if (process_read(ps, fp, &fp, sizeof(fp)) < 0) - return -1; - if (process_read(ps, fp+4, &pc, sizeof(pc)) < 0) - return -1; - if (fp == 0) { - return -1; - } - } -out: - fram->pc = pc; - fram->fp = fp; - fram->nargs = 0; - return 0; -} - -int -md_getregs(struct pstate *ps, reg *regs) -{ - struct reg md_reg; - if (process_getregs(ps, &md_reg)) - return -1; - memcpy(regs, &md_reg, 32 * sizeof(long)); - memcpy(®s[32], &md_reg.pc, 7 * sizeof(long)); - return 0; -} diff --git a/usr.bin/pmdb/arch/sh/Makefile.inc b/usr.bin/pmdb/arch/sh/Makefile.inc deleted file mode 100644 index 1e428eecd52..00000000000 --- a/usr.bin/pmdb/arch/sh/Makefile.inc +++ /dev/null @@ -1,3 +0,0 @@ -# $OpenBSD: Makefile.inc,v 1.1 2007/03/03 14:20:12 miod Exp $ - -SRCS+= sh.c diff --git a/usr.bin/pmdb/arch/sh/pmdb_machdep.h b/usr.bin/pmdb/arch/sh/pmdb_machdep.h deleted file mode 100644 index f229b2c5908..00000000000 --- a/usr.bin/pmdb/arch/sh/pmdb_machdep.h +++ /dev/null @@ -1,22 +0,0 @@ -/* $OpenBSD: pmdb_machdep.h,v 1.1 2007/03/03 14:20:12 miod Exp $ */ - -/* - * Copyright (c) 2007 Miodrag Vallat. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice, this permission notice, and the disclaimer below - * appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#define BREAKPOINT { 0xc3, 0xc3 } -#define BREAKPOINT_LEN 2 -#define BREAKPOINT_DECR_PC BREAKPOINT_LEN diff --git a/usr.bin/pmdb/arch/sh/sh.c b/usr.bin/pmdb/arch/sh/sh.c deleted file mode 100644 index 8573aec5b23..00000000000 --- a/usr.bin/pmdb/arch/sh/sh.c +++ /dev/null @@ -1,98 +0,0 @@ -/* $OpenBSD: sh.c,v 1.1 2007/03/03 14:20:12 miod Exp $ */ - -/* - * Copyright (c) 2007 Miodrag Vallat. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice, this permission notice, and the disclaimer below - * appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include <string.h> - -#include <sys/param.h> -#include <sys/ptrace.h> - -#include <machine/reg.h> - -#include "pmdb.h" - -static const char *md_reg_names[] = { - /* integer registers */ - "pc", "sr", "pr", "mach", "macl", - "r15", "r14", "r13", "r12", "r11", "r10", "r9", "r8", - "r7", "r6", "r5", "r4", "r3", "r2", "r1", "r0", -#ifdef notyet - /* floating point registers */ - "fr0", "fr1", "fr2", "fr3", "fr4", "fr5", "fr6", "fr7", - "fr8", "fr9", "fr10", "fr11", "fr12", "fr13", "fr14", "fr15", - "xf0", "xf1", "xf2", "xf3", "xf4", "xf5", "xf6", "xf7", - "xf8", "xf9", "xf10", "xf11", "xf12", "xf13", "xf14", "xf15", - "fpul", "fpscr" -#endif -}; - -struct md_def md_def = { md_reg_names, 21 /* + 34 */, 0 }; - -void -md_def_init() -{ -} - -int -md_getframe(struct pstate *ps, int frame, struct md_frame *f) -{ - struct reg regs; - - if (process_getregs(ps, ®s) != 0) - return (-1); - - f->pc = regs.r_spc; - f->fp = regs.r_r14; /* frame */ - if (frame == 0) { - f->nargs = 0; - } else { - f->nargs = 0; /* XXX for now */ - } - - return (0); -} - -int -md_getregs(struct pstate *ps, reg *r) -{ - struct reg regs; -#ifdef notyet - struct fpreg fpregs; - int rc; -#endif - - if (process_getregs(ps, ®s) != 0) - return (-1); - - bcopy(®s, r, sizeof(regs)); - -#ifdef notyet - switch (rc = process_getfpregs(ps, &fpregs)) { - case 0: - bcopy(&fpregs, r + sizeof(regs) / sizeof(reg), sizeof(fpregs)); - break; - case EINVAL: - bzero(r + sizeof(regs) / sizeof(reg), sizeof(fpregs)); - break; - default: - return (-1); - } -#endif - - return (0); -} diff --git a/usr.bin/pmdb/arch/sparc/Makefile.inc b/usr.bin/pmdb/arch/sparc/Makefile.inc deleted file mode 100644 index e5cb6738142..00000000000 --- a/usr.bin/pmdb/arch/sparc/Makefile.inc +++ /dev/null @@ -1,3 +0,0 @@ -# $OpenBSD: Makefile.inc,v 1.2 2002/03/15 18:33:03 mickey Exp $ - -SRCS+=sparc.c diff --git a/usr.bin/pmdb/arch/sparc/pmdb_machdep.h b/usr.bin/pmdb/arch/sparc/pmdb_machdep.h deleted file mode 100644 index ac694b8a43e..00000000000 --- a/usr.bin/pmdb/arch/sparc/pmdb_machdep.h +++ /dev/null @@ -1,29 +0,0 @@ -/* $OpenBSD: pmdb_machdep.h,v 1.3 2003/01/27 08:21:35 art Exp $ */ -/* - * Copyright (c) 2002 Artur Grabowski <art@openbsd.org> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#define BREAKPOINT { 0x91, 0xd0, 0x20, 0x01 } -#define BREAKPOINT_LEN 4 -#define BREAKPOINT_DECR_PC 0 diff --git a/usr.bin/pmdb/arch/sparc/sparc.c b/usr.bin/pmdb/arch/sparc/sparc.c deleted file mode 100644 index a9b957d341d..00000000000 --- a/usr.bin/pmdb/arch/sparc/sparc.c +++ /dev/null @@ -1,111 +0,0 @@ -/* $OpenBSD: sparc.c,v 1.6 2002/08/08 17:39:17 art Exp $ */ -/* - * Copyright (c) 2002 Federico Schwindt <fgsch@openbsd.org> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include <sys/param.h> -#include <sys/ptrace.h> -#include <machine/reg.h> -#include <machine/frame.h> -#include "pmdb.h" - -static const char *md_reg_names[] = { - "%pc", "%npc", /* %y */ - "%o0", "%o1", "%o2", "%o3", "%o4", "%o5", "%o6", "%o7", - "%g0", "%g1", "%g2", "%g3", "%g4", "%g5", "%g6", "%g7", -}; - -struct md_def md_def = { md_reg_names, 18, 0 }; - -#define next_frame(f) ((struct frame*)(f->fr_fp)) - -void -md_def_init(void) -{ - /* no need to do anything */ -} - -int -md_getframe(struct pstate *ps, int frame, struct md_frame *fram) -{ - struct frame fr; - struct reg r; - reg fp, pc; - int i; - - if (process_getregs(ps, &r)) - return (-1); - - if (frame == 0) { - pc = r.r_pc; - fp = r.r_out[6]; - if (process_read(ps, fp, &fr, sizeof(fr)) < 0) - return (-1); - } else { - fp = r.r_out[6]; - pc = r.r_out[7]; - } - - for (i = 1; i < frame; i++) { - if (fp < 8192 || (fp & 7) != 0) - return (-1); - - if (process_read(ps, fp, &fr, sizeof(fr)) < 0) - return (-1); - fp = (unsigned long)next_frame((&fr)); - pc = fr.fr_pc; - } - fram->pc = pc; - fram->fp = fp; - - fram->nargs = 6; /* XXX - don't know the real number */ - for (i = 0; i < 6; i++) { - fram->args[i] = fr.fr_arg[i]; - } - - return (0); -} - -int -md_getregs(struct pstate *ps, reg *regs) -{ - struct reg r; - int i; - - if (process_getregs(ps, &r)) - return (-1); - - regs[0] = r.r_pc; - regs[1] = r.r_npc; - - for (i = 0; i < 8; i++) { - regs[2 + i] = r.r_out[i]; - } - - for (i = 0; i < 8; i++) { - regs[10 + i] = r.r_global[i]; - } - - return (0); -} diff --git a/usr.bin/pmdb/arch/sparc64/Makefile.inc b/usr.bin/pmdb/arch/sparc64/Makefile.inc deleted file mode 100644 index d8e0700719d..00000000000 --- a/usr.bin/pmdb/arch/sparc64/Makefile.inc +++ /dev/null @@ -1,3 +0,0 @@ -# $OpenBSD: Makefile.inc,v 1.2 2002/03/15 18:33:03 mickey Exp $ - -SRCS+=sparc64.c diff --git a/usr.bin/pmdb/arch/sparc64/pmdb_machdep.h b/usr.bin/pmdb/arch/sparc64/pmdb_machdep.h deleted file mode 100644 index ac694b8a43e..00000000000 --- a/usr.bin/pmdb/arch/sparc64/pmdb_machdep.h +++ /dev/null @@ -1,29 +0,0 @@ -/* $OpenBSD: pmdb_machdep.h,v 1.3 2003/01/27 08:21:35 art Exp $ */ -/* - * Copyright (c) 2002 Artur Grabowski <art@openbsd.org> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#define BREAKPOINT { 0x91, 0xd0, 0x20, 0x01 } -#define BREAKPOINT_LEN 4 -#define BREAKPOINT_DECR_PC 0 diff --git a/usr.bin/pmdb/arch/sparc64/sparc64.c b/usr.bin/pmdb/arch/sparc64/sparc64.c deleted file mode 100644 index 707f5073a4a..00000000000 --- a/usr.bin/pmdb/arch/sparc64/sparc64.c +++ /dev/null @@ -1,127 +0,0 @@ -/* $OpenBSD: sparc64.c,v 1.6 2002/07/22 02:54:23 art Exp $ */ -/* - * Copyright (c) 2002 Artur Grabowski <art@openbsd.org> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include <sys/param.h> -#include <sys/ptrace.h> -#include <machine/reg.h> -#include <machine/frame.h> -#include "pmdb.h" - -static const char *md_reg_names[] = { - "%pc", "%npc", /* %y */ - "%o0", "%o1", "%o2", "%o3", "%o4", "%o5", "%o6", "%o7", - "%i0", "%i1", "%i2", "%i3", "%i4", "%i5", "%i6", "%i7", - "%g0", "%g1", "%g2", "%g3", "%g4", "%g5", "%g6", "%g7", - "%l0", "%l1", "%l2", "%l3", "%l4", "%l5", "%l6", "%l7", -}; - -struct md_def md_def = { md_reg_names, 34, 0 }; - -void -md_def_init(void) -{ - /* no need to do anything */ -} - -int -md_getframe(struct pstate *ps, int frame, struct md_frame *fram) -{ - struct frame64 fr; - struct reg r; - reg fp, pc; - reg *outs; - int i; - - if (process_getregs(ps, &r)) - return (-1); - - if (frame == 0) { - pc = r.r_pc; - fp = r.r_out[6] + BIAS; - /* - * XXX - we need some kind of heuristics here to decide - * if the function has done a save or not and then pick - * the in registers. the problem is just that there are - * no in registers in PT_GETREGS. - */ - outs = (reg *)&r.r_out; - goto out; - } - - fp = r.r_out[6] + BIAS; - pc = r.r_out[7]; - - for (i = 1; i < frame; i++) { - /* Too low or unaligned frame pointer? */ - if (fp < 8192 || (fp & 7) != 0) - return (-1); - - if (process_read(ps, fp, &fr, sizeof(fr)) < 0) - return (-1); - - fp = (unsigned long)v9next_frame((&fr)); - pc = fr.fr_pc; - - /* Too low or unaligned pc ? */ - if ((pc < 8192) || (pc & 3) != 0) - return (-1); - - outs = (reg *)&fr.fr_arg; - } - -out: - fram->pc = pc; - fram->fp = fp; - - fram->nargs = 6; /* XXX - don't know the real number */ - for (i = 0; i < 6; i++) { - fram->args[i] = fr.fr_arg[i]; - } - - return (0); -} - -int -md_getregs(struct pstate *ps, reg *regs) -{ - struct reg r; - int i; - - if (process_getregs(ps, &r)) - return (-1); - - regs[0] = r.r_pc; - regs[1] = r.r_npc; - - for (i = 0; i < 8; i++) { - regs[2 + i] = r.r_out[i]; - regs[10 + i] = r.r_in[i]; - regs[18 + i] = r.r_global[i]; - regs[26 + i] = r.r_local[i]; - } - - return (0); -} diff --git a/usr.bin/pmdb/arch/vax/Makefile.inc b/usr.bin/pmdb/arch/vax/Makefile.inc deleted file mode 100644 index e17a26caaaa..00000000000 --- a/usr.bin/pmdb/arch/vax/Makefile.inc +++ /dev/null @@ -1,3 +0,0 @@ -# $OpenBSD: Makefile.inc,v 1.1 2002/03/19 21:01:49 fgsch Exp $ - -SRCS+= vax.c diff --git a/usr.bin/pmdb/arch/vax/pmdb_machdep.h b/usr.bin/pmdb/arch/vax/pmdb_machdep.h deleted file mode 100644 index 72887f0b1e1..00000000000 --- a/usr.bin/pmdb/arch/vax/pmdb_machdep.h +++ /dev/null @@ -1,29 +0,0 @@ -/* $OpenBSD: pmdb_machdep.h,v 1.3 2003/05/30 19:33:36 miod Exp $ */ -/* - * Copyright (c) 2002 Federico Schwindt <fgsch@openbsd.org> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#define BREAKPOINT { 0x03 } -#define BREAKPOINT_LEN 1 -#define BREAKPOINT_DECR_PC 1 diff --git a/usr.bin/pmdb/arch/vax/vax.c b/usr.bin/pmdb/arch/vax/vax.c deleted file mode 100644 index aeac744ea17..00000000000 --- a/usr.bin/pmdb/arch/vax/vax.c +++ /dev/null @@ -1,83 +0,0 @@ -/* $OpenBSD: vax.c,v 1.5 2002/07/22 02:54:23 art Exp $ */ -/* - * Copyright (c) 2002 Federico Schwindt <fgsch@openbsd.org> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include <sys/param.h> -#include <sys/ptrace.h> -#include <machine/reg.h> -#include <machine/frame.h> -#include "pmdb.h" - -static const char *md_reg_names[] = { - "%r0", "%r1", "%r2", "%r3", "%r4", "%r5", "%r6", "%r7", "%r8", - "%r9", "%r10", "%r11", "%ap", "%fp", "%sp", "%pc", "%ps" -}; - -struct md_def md_def = { md_reg_names, 17, 16 }; - -void -md_def_init(void) -{ - /* no need to do anything */ -} - -int -md_getframe(struct pstate *ps, int frame, struct md_frame *fram) -{ - struct callsframe fr; - struct reg r; - int count; - - if (process_getregs(ps, &r)) - return (-1); - - fr.ca_fp = r.fp; - fr.ca_pc = r.pc; - for (count = 0; count < frame; count++) { - if (process_read(ps, fr.ca_fp, &fr, sizeof(fr)) < 0) - return (-1); - - if (fr.ca_pc < 0x1000) - return (-1); - } - - fram->pc = fr.ca_pc; - fram->fp = fr.ca_fp; - - return (0); -} - -int -md_getregs(struct pstate *ps, reg *regs) -{ - struct reg r; - - if (process_getregs(ps, &r)) - return (-1); - - memcpy(regs, &r, sizeof(r)); - - return (0); -} diff --git a/usr.bin/pmdb/break.c b/usr.bin/pmdb/break.c deleted file mode 100644 index 12978cef7ec..00000000000 --- a/usr.bin/pmdb/break.c +++ /dev/null @@ -1,304 +0,0 @@ -/* $OpenBSD: break.c,v 1.9 2009/10/28 09:24:45 sobrado Exp $ */ -/* - * Copyright (c) 2002 Artur Grabowski <art@openbsd.org> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include <sys/types.h> -#include <sys/ptrace.h> -#include <sys/wait.h> - -#include <stdlib.h> -#include <stdio.h> -#include <unistd.h> -#include <signal.h> -#include <err.h> -#include <errno.h> -#include <string.h> - -#include "pmdb.h" -#include "symbol.h" -#include "pmdb_machdep.h" -#include "break.h" - -struct callback { - TAILQ_ENTRY(callback) cb_list; - int (*cb_fun)(struct pstate *, void *); - void *cb_arg; -}; - -struct breakpoint { - TAILQ_ENTRY(breakpoint) bkpt_list; - TAILQ_HEAD(,callback) bkpt_cbs; /* list of all callbacks */ - char bkpt_old[BREAKPOINT_LEN]; /* old contents at bkpt */ - reg bkpt_pc; -}; - -static char bkpt_insn[BREAKPOINT_LEN] = BREAKPOINT; - -/* - * Find a breakpoint at this address. - */ -struct breakpoint * -bkpt_find_at_pc(struct pstate *ps, reg pc) -{ - struct breakpoint *bkpt; - - TAILQ_FOREACH(bkpt, &ps->ps_bkpts, bkpt_list) { - if (bkpt->bkpt_pc == pc) - break; - } - return (bkpt); -} - -/* - * Enable this breakpoint. - */ -static int -bkpt_enable(struct pstate *ps, struct breakpoint *bkpt) -{ - reg pc = bkpt->bkpt_pc; - - if (process_read(ps, pc, &bkpt->bkpt_old, BREAKPOINT_LEN) < 0) { - warn("Can't read process contents at 0x%lx", pc); - return (-1); - } - if (process_write(ps, pc, &bkpt_insn, BREAKPOINT_LEN) < 0) { - warn("Can't write breakpoint at 0x%lx, attempting backout.", - pc); - if (process_write(ps, pc, &bkpt->bkpt_old, BREAKPOINT_LEN) < 0) - warn("Backout failed, process unstable"); - return (-1); - } - return (0); -} - -/* - * Create a new breakpoint and enable it. - */ -int -bkpt_add_cb(struct pstate *ps, reg pc, int (*fun)(struct pstate *, void *), - void *arg) -{ - struct breakpoint *bkpt; - struct callback *cb; - - if ((bkpt = bkpt_find_at_pc(ps, pc)) == NULL) { - bkpt = emalloc(sizeof(*bkpt)); - TAILQ_INIT(&bkpt->bkpt_cbs); - TAILQ_INSERT_TAIL(&ps->ps_bkpts, bkpt, bkpt_list); - bkpt->bkpt_pc = pc; - if (bkpt_enable(ps, bkpt)) { - TAILQ_REMOVE(&ps->ps_bkpts, bkpt, bkpt_list); - free(bkpt); - return (-1); - } - } - - cb = emalloc(sizeof(*cb)); - cb->cb_fun = fun; - cb->cb_arg = arg; - TAILQ_INSERT_TAIL(&bkpt->bkpt_cbs, cb, cb_list); - - return (0); -} - -/* - * Disable and delete a breakpoint. - */ -void -bkpt_delete(struct pstate *ps, struct breakpoint *bkpt) -{ - TAILQ_REMOVE(&ps->ps_bkpts, bkpt, bkpt_list); - - if (process_write(ps, bkpt->bkpt_pc, &bkpt->bkpt_old, BREAKPOINT_LEN)) - warn("Breakpoint removal failed, process unstable"); - - free(bkpt); -} - -/* - * Normal standard breakpoint. Keep it. - */ -static int -bkpt_normal(struct pstate *ps, void *arg) -{ - return (BKPT_KEEP_STOP); -} - -/* - * Single-step callback for "stepping over" a breakpoint (we restore the - * breakpoint instruction to what it was, single-step over it and then - * call this function). - */ -static int -sstep_bkpt_readd(struct pstate *ps, void *arg) -{ - reg pc = (reg)arg; - - bkpt_add_cb(ps, pc, bkpt_normal, NULL); - - return (0); /* let the process continue */ -} - -/* - * Return 0 for stop, 1 for silent continue. - */ -int -bkpt_check(struct pstate *ps) -{ - struct breakpoint *bkpt; - struct callback *cb; - TAILQ_HEAD(,callback) sstep_cbs; - reg *rg, pc; - int ret; - int didsome = 0; - int stop = 0; - - /* Requeue all single-step callbacks because bkpts can add ssteps. */ - TAILQ_INIT(&sstep_cbs); - while ((cb = TAILQ_FIRST(&ps->ps_sstep_cbs)) != NULL) { - TAILQ_REMOVE(&ps->ps_sstep_cbs, cb, cb_list); - TAILQ_INSERT_TAIL(&sstep_cbs, cb, cb_list); - } - - /* - * The default is to stop. Unless we do some processing and none - * of the callbacks require a stop. - */ - rg = alloca(sizeof(*rg) * md_def.nregs); - if (rg == NULL) - err(1, "bkpt_check: Can't allocate stack space."); - - if (md_getregs(ps, rg)) - err(1, "bkpt_check: Can't get registers"); - - pc = rg[md_def.pcoff]; - pc -= BREAKPOINT_DECR_PC; - - bkpt = bkpt_find_at_pc(ps, pc); - if (bkpt == NULL) - goto sstep; - - ps->ps_npc = pc; - - while ((cb = TAILQ_FIRST(&bkpt->bkpt_cbs)) != NULL) { - didsome = 1; - TAILQ_REMOVE(&bkpt->bkpt_cbs, cb, cb_list); - ret = (*cb->cb_fun)(ps, cb->cb_arg); - free(cb); - switch (ret) { - case BKPT_DEL_STOP: - stop = 1; - case BKPT_DEL_CONT: - break; - case BKPT_KEEP_STOP: - stop = 1; - case BKPT_KEEP_CONT: - sstep_set(ps, sstep_bkpt_readd, (void *)bkpt->bkpt_pc); - break; - default: - errx(1, "unknown bkpt_fun return, internal error"); - } - } - - bkpt_delete(ps, bkpt); - -sstep: - - while ((cb = TAILQ_FIRST(&sstep_cbs)) != NULL) { - didsome = 1; - TAILQ_REMOVE(&sstep_cbs, cb, cb_list); - stop |= (*cb->cb_fun)(ps, cb->cb_arg); - free(cb); - } - ps->ps_flags &= ~PSF_STEP; - - return (didsome && !stop); -} - -int -cmd_bkpt_add(int argc, char **argv, void *arg) -{ - struct pstate *ps = arg; - char *ep, *bkpt_name; - reg pc; - - if (ps->ps_state != STOPPED && ps->ps_state != LOADED) { - fprintf(stderr, "Process not loaded and stopped %d\n", - ps->ps_state); - return (0); - } - - bkpt_name = argv[1]; - pc = strtol(bkpt_name, &ep, 0); - if (bkpt_name[0] == '\0' || *ep != '\0' || pc < 1) { - if (sym_lookup(ps, bkpt_name, &pc)) { - warnx("%s is not a valid pc", bkpt_name); - return (0); - } - } - - if (bkpt_add_cb(ps, pc, bkpt_normal, 0)) - warn("Can't set break point"); - - return (0); -} - -static int -sstep_normal(struct pstate *ps, void *arg) -{ - return (1); /* stop the command line. */ -} - -int -cmd_sstep(int argc, char **argv, void *arg) -{ - struct pstate *ps = arg; - - if (ps->ps_state != STOPPED) { - fprintf(stderr, "Process not loaded and stopped %d\n", - ps->ps_state); - return 0; - } - - if (sstep_set(ps, sstep_normal, NULL)) - warn("Can't set single step"); - - return (cmd_process_cont(argc, argv, arg)); -} - -int -sstep_set(struct pstate *ps, int (*fun)(struct pstate *, void *), void *arg) -{ - struct callback *cb; - - cb = emalloc(sizeof(*cb)); - cb->cb_fun = fun; - cb->cb_arg = arg; - TAILQ_INSERT_TAIL(&ps->ps_sstep_cbs, cb, cb_list); - - ps->ps_flags |= PSF_STEP; - - return (0); -} diff --git a/usr.bin/pmdb/break.h b/usr.bin/pmdb/break.h deleted file mode 100644 index c22e01751b0..00000000000 --- a/usr.bin/pmdb/break.h +++ /dev/null @@ -1,46 +0,0 @@ -/* $OpenBSD: break.h,v 1.2 2002/03/15 16:41:06 jason Exp $ */ -/* - * Copyright (c) 2002 Artur Grabowski <art@openbsd.org> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * Breakpoint handling. - */ -int bkpt_add_cb(struct pstate *, reg, int (*)(struct pstate *, void *), void *); -int bkpt_check(struct pstate *); -int cmd_bkpt_add(int, char **, void *); - -/* - * Single step handling. - */ -int sstep_set(struct pstate *, int (*)(struct pstate *, void *), void *); -int cmd_sstep(int, char **, void *); - -/* - * Return values from the bkpt_fun - */ -#define BKPT_DEL_STOP 1 /* delete this bkpt and stop */ -#define BKPT_DEL_CONT 2 /* delete this bkpt and continue */ -#define BKPT_KEEP_STOP 3 /* keep this bkpt and stop */ -#define BKPT_KEEP_CONT 4 /* keep this bkpt and cont */ diff --git a/usr.bin/pmdb/clit.c b/usr.bin/pmdb/clit.c deleted file mode 100644 index d22f6682f42..00000000000 --- a/usr.bin/pmdb/clit.c +++ /dev/null @@ -1,248 +0,0 @@ -/* $OpenBSD: clit.c,v 1.7 2011/07/08 23:42:27 nicm Exp $ */ -/* - * Copyright (c) 2002 Artur Grabowski <art@openbsd.org> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include <stdlib.h> -#include <stdio.h> -#include <histedit.h> -#include <err.h> -#include <string.h> - -#include "clit.h" - -extern char *__progname; - -char *prompt_add; - -static char * -prompt(EditLine *el) -{ - static char p[64]; - - snprintf(p, sizeof(p), "%s%s> ", __progname, - prompt_add ? prompt_add : ""); - - return p; -} - -/* - * Returns number of commands that (at least partially) match "name". - */ -static int -name_to_cmd(const char *name, struct clit *cmds, int ncmds, struct clit **res) -{ - int i, len, ret; - - len = strlen(name); - ret = 0; - - for (i = 0; i < ncmds; i++) { - if (strncmp(cmds[i].cmd, name, len) == 0) { - *res = &cmds[i]; - ret++; - } - } - - return ret; -} - -struct clitenv { - struct clit *cmds; - int ncmds; - EditLine *el; - History *hist; -}; - -int -cmd_help(int argc, char **argv, void *arg) -{ - struct clitenv *env = arg; - struct clit *cmds = env->cmds, *cmdp; - int ncmds = env->ncmds; - int i, res; - - if (argc > 1) { - res = name_to_cmd(argv[1], cmds, ncmds, &cmdp); - if (res == 1) { - printf("%s\t%s\n", cmdp->cmd, cmdp->help); - } else { - fprintf(stderr, "%s command: %s\n", - res == 0 ? "unknown" : "ambiguous", argv[1]); - } - - return 0; - } - for (i = 0; i < ncmds; i++) { - cmdp = &cmds[i]; - - printf("%s\t%s\n", cmdp->cmd, cmdp->help); - } - - return 0; -} - -/* - * XXX - there is no way to push external args into this function. - */ -unsigned char -complt(EditLine *el, int ch) -{ - const LineInfo *line; - char str[1024]; - int len, ret; - - line = el_line(el); - if (line->cursor != line->lastchar) - return CC_ERROR; - - len = line->lastchar - line->buffer; - - if (len >= 1023) - return CC_ERROR; - - memcpy(str, line->buffer, len); - str[len] = '\0'; - - ret = cmd_complt(str, sizeof(str)); - - el_push(el, &str[len]); - - return ret ? CC_ERROR : CC_REDISPLAY; -} - -void * -cmdinit(struct clit *cmds, int ncmds) -{ - struct clitenv *env; - HistEvent ev; - - if ((env = malloc(sizeof(*env))) == NULL) - err(1, "Can't init cmd interpreter."); - - env->cmds = cmds; - env->ncmds = ncmds; - - env->hist = history_init(); - history(env->hist, &ev, H_SETSIZE, 100); - - env->el = el_init(__progname, stdin, stdout, stderr); - - el_set(env->el, EL_EDITOR, "emacs"); - el_set(env->el, EL_PROMPT, prompt); - el_set(env->el, EL_HIST, history, env->hist); - el_set(env->el, EL_ADDFN, "complt", "complete", complt); - el_set(env->el, EL_BIND, "\t", "complt", NULL); - el_source(env->el, NULL); - - /* XXX - EL_SIGNAL ? */ - - return env; -} - -void -cmdend(void *arg) -{ - struct clitenv *env = arg; - - el_end(env->el); - history_end(env->hist); - - free(env); -} - -int -cmdloop(void *arg) -{ - struct clitenv *env = arg; - EditLine *el = env->el; - History *hist = env->hist; - const char *elline; - int cnt; - char **argv; - int maxargs = 16; /* XXX */ - int stop; - - stop = 0; - - if ((argv = calloc(sizeof(char *), maxargs)) == NULL) - err(1, "malloc"); - - while (!stop && (elline = el_gets(el, &cnt)) != NULL) { - char *line, *orgline; - struct clit *cmdp; - char **ap; - int argc, res; - HistEvent ev; - - memset(argv, 0, sizeof(char *) * maxargs); - - history(hist, &ev, H_ENTER, elline); - - orgline = line = strdup(elline); - if (line == NULL) - err(1, "strdup"); - - argc = 0; - for (ap = argv; (*ap = strsep(&line, " \t\n")) != NULL;) { - if (**ap != '\0') { - ++ap; - if (++argc == maxargs) - break; - } - } - if (argc == maxargs) { - fprintf(stderr, "Too many arguments\n"); - goto cmdout; - } - if (!argc) - goto cmdout; - - /* - * Editline commands. - */ - if (el_parse(el, argc, (const char **)argv) != -1) - goto cmdout; - - if ((res = name_to_cmd(argv[0], env->cmds, env->ncmds, - &cmdp)) == 1) { - if (argc - 1 > cmdp->maxargc) - fprintf(stderr, "Too many arguments\n"); - else if (argc - 1 < cmdp->minargc) - fprintf(stderr, "Too few arguments\n"); - else - stop = (*cmdp->handler)(argc, argv, - cmdp->arg ? cmdp->arg : env); - } else { - fprintf(stderr, "%s command: %s\n", - res == 0 ? "unknown" : "ambiguous", argv[0]); - } -cmdout: - free(orgline); - } - free(argv); - - return stop; -} - diff --git a/usr.bin/pmdb/clit.h b/usr.bin/pmdb/clit.h deleted file mode 100644 index 1b0551bdcb4..00000000000 --- a/usr.bin/pmdb/clit.h +++ /dev/null @@ -1,52 +0,0 @@ -/* $OpenBSD: clit.h,v 1.2 2002/03/15 16:41:06 jason Exp $ */ -/* - * Copyright (c) 2002 Artur Grabowski <art@openbsd.org> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -struct clit { - const char *cmd; - const char *help; - int minargc; - int maxargc; - int (*handler)(int argc, char **argv, void *); - void *arg; -}; - -char *prompt_add; - -int cmd_help(int, char **, void *); - -void *cmdinit(struct clit *, int); -int cmdloop(void *); -void cmdend(void *); - -/* - * This function must be defined by the calling code. Sorry, but there is - * no way to pass arguments to it or pass this function in some arguments. - * - * Fills in the possible completions into buf. Returns != 0 when there are - * no possible completions. May whack buf, but the "returned" - * string should be appended to the string that was in buf. - */ -int cmd_complt(char *buf, size_t buflen); diff --git a/usr.bin/pmdb/core.c b/usr.bin/pmdb/core.c deleted file mode 100644 index 45d9b76e25d..00000000000 --- a/usr.bin/pmdb/core.c +++ /dev/null @@ -1,200 +0,0 @@ -/* $OpenBSD: core.c,v 1.8 2007/08/01 15:44:37 deraadt Exp $ */ -/* - * Copyright (c) 2002 Jean-Francois Brousseau <krapht@secureops.com> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include <sys/param.h> -#include <sys/stat.h> -#include <sys/mman.h> - -#include <err.h> -#include <stdio.h> -#include <fcntl.h> -#include <string.h> -#include <stdlib.h> -#include <signal.h> -#include <unistd.h> - -#include "core.h" -#include "pmdb.h" -#include "symbol.h" - -int -read_core(const char *path, struct pstate *ps) -{ - struct corefile *cf; - void *core_map; - off_t c_off; - int i, cfd; - - cf = (struct corefile *)malloc(sizeof(*cf)); - if (cf == NULL) - err(1, "malloc"); - - cfd = open(path, O_RDONLY, 0600); - if (cfd < 0) - err(1, "open() failed on core file"); - - if (fstat(cfd, &(cf->cfstat)) < 0) - err(1, "fstat() failed on core"); - - if (cf->cfstat.st_mtimespec.tv_sec < ps->exec_stat.st_mtimespec.tv_sec) - warnx("executable is more recent than core file!"); - - core_map = mmap(NULL, cf->cfstat.st_size, PROT_READ, MAP_PRIVATE, - cfd, 0); - if (core_map == MAP_FAILED) - err(1, "mmap() failed on core"); - close(cfd); - - cf->chdr = (struct core *)core_map; - c_off = cf->chdr->c_hdrsize; - if (CORE_GETMAGIC(*(cf->chdr)) != COREMAGIC) - errx(1, "hey, that's not a core file"); - - printf("Core file generated from '%s' by signal %d (SIG%s)\n", - cf->chdr->c_name, cf->chdr->c_signo, - sys_signame[cf->chdr->c_signo]); - -#ifdef DEBUG - printf("Core: text=0x%lx, data=0x%lx, stack=0x%lx\n", - cf->chdr->c_tsize, cf->chdr->c_dsize, cf->chdr->c_ssize); -#endif - - cf->segs = (struct coreseg **)calloc(cf->chdr->c_nseg, - sizeof(cf->segs)); - if (cf->segs == NULL) - err(1, "calloc"); - - for (i = 0; i < cf->chdr->c_nseg; i++) { - cf->segs[i] = (struct coreseg *)(core_map + c_off); - if (CORE_GETMAGIC(*(cf->segs[i])) != CORESEGMAGIC) - errx(1, "invalid segment hdr for segment %d", i); - - if (CORE_GETFLAG(*(cf->segs[i])) & CORE_CPU) { - cf->regs = (struct reg *) - ((long) cf->segs[i] + cf->chdr->c_seghdrsize); - } - - if (CORE_GETFLAG(*(cf->segs[i])) & CORE_STACK) - cf->c_stack = cf->segs[i] + cf->chdr->c_seghdrsize; - - c_off += cf->chdr->c_seghdrsize + cf->segs[i]->c_size; - -#ifdef DEBUG - (void)printf("seg[%d]: midmag=0x%lx addr=0x%lx size=0x%lx\n", - i, cf->segs[i]->c_midmag, cf->segs[i]->c_addr, - cf->segs[i]->c_size); -#endif - } - - cf->path = (char *)path; - ps->ps_flags |= PSF_CORE; - ps->ps_core = cf; - - return (0); -} - -void -free_core(struct pstate *ps) -{ - struct corefile *cf = ps->ps_core; - - if (cf == NULL) - return; - - if (cf->segs != NULL) { - free(cf->segs); - cf->segs = NULL; - } - - if (cf->chdr != NULL) { - munmap(cf->chdr, cf->cfstat.st_size); - cf->chdr = NULL; - } - -} - -void -core_printregs(struct pstate *ps) -{ - struct corefile *cf = ps->ps_core; - reg *rg; - char buf[256]; - int i; - - rg = (reg *)cf->regs; - for (i = 0; i < md_def.nregs; i++) - printf("%s:\t0x%.*lx\t%s\n", md_def.md_reg_names[i], - (int)(sizeof(reg) * 2), (long) rg[i], - sym_print(ps, rg[i], buf, sizeof(buf))); -} - - -ssize_t -core_read(struct pstate *ps, off_t from, void *to, size_t size) -{ - struct coreseg *cs; - size_t read; - void *fp; - int i; - - 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; - if ((from + size) > (cs->c_addr + cs->c_size)) - read = (cs->c_addr + cs->c_size) - from; - fp = (void *)cs + sizeof(*cs) + - ((u_long)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) -{ - struct coreseg *cs; - size_t written; - void *fp; - int i; - - 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 = (void *)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 deleted file mode 100644 index 7fab21805b4..00000000000 --- a/usr.bin/pmdb/core.h +++ /dev/null @@ -1,47 +0,0 @@ -/* $OpenBSD: core.h,v 1.3 2003/03/28 23:33:27 mickey Exp $ */ -/* - * Copyright (c) 2002 Jean-Francois Brousseau <krapht@secureops.com> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include <sys/param.h> -#include <sys/core.h> -#include <sys/stat.h> - -struct pstate; - -struct corefile { - char *path; - struct stat cfstat; - struct core *chdr; /* core header */ - struct coreseg **segs; - struct reg *regs; - void *c_stack; /* pointer to the top of the stack */ -}; - -int read_core(const char *, struct pstate *); -void free_core(struct pstate *); -void core_printregs(struct pstate *); - -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 deleted file mode 100644 index 57cc27222ea..00000000000 --- a/usr.bin/pmdb/elf_syms.c +++ /dev/null @@ -1,414 +0,0 @@ -/* $OpenBSD: elf_syms.c,v 1.9 2007/07/24 21:08:49 deraadt Exp $ */ -/* - * Copyright (c) 2002 Artur Grabowski <art@openbsd.org> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <fcntl.h> -#include <string.h> -#include <err.h> - -#include <sys/param.h> -#include <sys/ptrace.h> -#include <sys/mman.h> - -#include <nlist.h> -#ifdef __NetBSD__ -#include <machine/elf_machdep.h> -#define ELFSIZE ARCH_ELFSIZE -#include <sys/exec_elf.h> -#else -#include <elf_abi.h> -#endif -#include <link.h> - -#include "pmdb.h" -#include "symbol.h" -#include "break.h" - -struct elf_symbol_handle { - struct sym_table esh_st; - int esh_fd; - char *esh_strtab; - Elf_Word esh_strsize; - Elf_Sym *esh_symtab; - Elf_Word esh_symsize; -}; - -#define ESH_TO_ST(esh) (&(esh)->esh_st) -#define ST_TO_ESH(st) ((struct elf_symbol_handle *)(st)) - -struct sym_table *elf_open(const char *); -void elf_close(struct sym_table *); -char *elf_name_and_off(struct sym_table *, reg, reg *); -int elf_lookup(struct pstate *, const char *, reg *); -void elf_update(struct pstate *); - -struct sym_ops elf_sops = { - elf_open, - elf_close, - elf_name_and_off, - elf_lookup, - elf_update -}; - -int -sym_check_elf(const char *name, struct pstate *ps) -{ - Elf_Ehdr ehdr; - int error = 0; - int fd; - - if ((fd = open(name, O_RDONLY)) < 0) - return (1); - - if (pread(fd, &ehdr, sizeof(Elf_Ehdr), 0) != sizeof(Elf_Ehdr)) - error = 1; - -#ifndef __NetBSD__ - if (!error && (!IS_ELF(ehdr) || - ehdr.e_ident[EI_CLASS] != ELF_TARG_CLASS || - ehdr.e_ident[EI_DATA] != ELF_TARG_DATA || - ehdr.e_ident[EI_VERSION] != ELF_TARG_VER || - ehdr.e_machine != ELF_TARG_MACH || - ehdr.e_version != ELF_TARG_VER)) - error = 1; -#endif - - close(fd); - - if (!error) - ps->ps_sops = &elf_sops; - - return (error); -} - -struct sym_table * -elf_open(const char *name) -{ - struct elf_symbol_handle *esh; - Elf_Off symoff, stroff; - Elf_Ehdr ehdr; - Elf_Shdr *shdr; - int i, fd; - - /* Just a sanity check */ - if (sizeof(reg) != sizeof(Elf_Addr)) - errx(1, "sym_open: sizeof(reg) != sizeof(Elf_Addr)"); - - if ((esh = malloc(sizeof(*esh))) == NULL) { - return (NULL); - } - - memset(esh, 0, sizeof(*esh)); - esh->esh_fd = -1; - - if ((fd = esh->esh_fd = open(name, O_RDONLY)) < 0) { - goto fail; - } - - if (pread(fd, &ehdr, sizeof(Elf_Ehdr), 0) != sizeof(Elf_Ehdr)) { - goto fail; - } -#ifndef __NetBSD__ - if (!IS_ELF(ehdr) || - ehdr.e_ident[EI_CLASS] != ELF_TARG_CLASS || - ehdr.e_ident[EI_DATA] != ELF_TARG_DATA || - ehdr.e_ident[EI_VERSION] != ELF_TARG_VER || - ehdr.e_machine != ELF_TARG_MACH || - ehdr.e_version != ELF_TARG_VER) { - goto fail; - } -#endif - - if ((shdr = (Elf_Shdr *)mmap(NULL, ehdr.e_shentsize * ehdr.e_shnum, - PROT_READ, MAP_SHARED, fd, ehdr.e_shoff)) == MAP_FAILED) { - goto fail; - } - - for (i = 0; i < ehdr.e_shnum; i++) { - if (shdr[i].sh_type == SHT_SYMTAB) { - symoff = shdr[i].sh_offset; - esh->esh_symsize = shdr[i].sh_size; - stroff = shdr[shdr[i].sh_link].sh_offset; - esh->esh_strsize = shdr[shdr[i].sh_link].sh_size; - break; - } - } - - munmap(shdr, ehdr.e_shentsize * ehdr.e_shnum); - - if (i == ehdr.e_shnum) { - goto fail; - } - - if (esh->esh_symsize) { - - if ((esh->esh_strtab = mmap(NULL, esh->esh_strsize, PROT_READ, - MAP_SHARED, fd, stroff)) == MAP_FAILED) { - goto fail; - } - - if ((esh->esh_symtab = mmap(NULL, esh->esh_symsize, PROT_READ, - MAP_SHARED, fd, symoff)) == MAP_FAILED) { - goto fail; - } - } - - return (ESH_TO_ST(esh)); -fail: - - elf_close(ESH_TO_ST(esh)); - return (NULL); -} - -void -elf_close(struct sym_table *st) -{ - struct elf_symbol_handle *esh = ST_TO_ESH(st); - - if (esh->esh_fd != -1) - close(esh->esh_fd); - - munmap(esh->esh_strtab, esh->esh_strsize); - munmap(esh->esh_symtab, esh->esh_symsize); - free(esh); -} - -char * -elf_name_and_off(struct sym_table *st, reg pc, reg *offs) -{ - struct elf_symbol_handle *esh = ST_TO_ESH(st); - Elf_Sym *s, *bests = NULL; - Elf_Addr bestoff = 0; - int nsyms, i; - char *symn; - - if (esh == NULL) - return (NULL); - -#define SYMVAL(S) (unsigned long)((S)->st_value + st->st_offs) - - nsyms = esh->esh_symsize / sizeof(Elf_Sym); - - bests = NULL; - for (i = 0; i < nsyms; i++) { - s = &esh->esh_symtab[i]; - - if (s->st_value == 0 || - s->st_shndx == 0 || - (ELF_ST_BIND(s->st_info) != STB_GLOBAL && - ELF_ST_BIND(s->st_info) != STB_WEAK && - ELF_ST_BIND(s->st_info) != STB_LOCAL)) - continue; - symn = &esh->esh_strtab[s->st_name]; - if (SYMVAL(s) <= pc && SYMVAL(s) > bestoff && - symn[0] != '\0' && strcmp(symn, "gcc2_compiled.")) { - bests = s; - bestoff = SYMVAL(s); - } - } - - if ((s = bests) == NULL) - return (NULL); - - *offs = pc - SYMVAL(s); - - return &esh->esh_strtab[s->st_name]; -} - -static Elf_Sym * -elf_lookup_table(struct elf_symbol_handle *esh, const char *name) -{ - int nsyms, i; - char *symn; - Elf_Sym *s = NULL; - - if (esh == NULL) - return (NULL); - - /* XXX - dumb, doesn't follow the rules (weak, hash, etc.). */ - nsyms = esh->esh_symsize / sizeof(Elf_Sym); - for (i = 0; i < nsyms; i++) { - s = &esh->esh_symtab[i]; - symn = &esh->esh_strtab[s->st_name]; - if (strcmp(name, symn) == 0) - break; - } - if (i == nsyms) - return (NULL); - - return (s); -} - -int -elf_lookup(struct pstate *ps, const char *name, reg *res) -{ - struct sym_table *st; - Elf_Sym *s = NULL; - - TAILQ_FOREACH(st, &ps->ps_syms, st_list) { - if ((s = elf_lookup_table(ST_TO_ESH(st), name)) != NULL) - break; - } - - if (s != NULL) { - *res = s->st_value + st->st_offs; - return (0); - } - - return (-1); -} - -#ifndef __NetBSD__ -struct elf_object_v1 { - Elf_Addr load_addr; - Elf_Addr load_offs; - char *load_name; - Elf_Dyn *load_dyn; - struct elf_object_v1 *next; - struct elf_object_v1 *prev; - void *load_list; - u_int32_t load_size; - u_long info[DT_NUM + DT_PROCNUM]; - struct elf_object_v1 *dep_next; - int status; - Elf_Phdr *phdrp; - int phdrc; - int refcount; - int obj_type; -#define EOBJ1_LDR 1 -#define EOBJ1_EXE 2 -#define EOBJ1_LIB 3 -#define EOBJ1_DLO 4 -}; -#endif - -/* - * dlopen breakpoint (XXX make this generic?) - */ -int -sym_bkpt(struct pstate *ps, void *arg) -{ - fprintf(stderr, "pmdb: shared lib changed\n"); - - sym_update(ps); - - return BKPT_KEEP_CONT; -} - -/* Is the ABI really so daft that it doesn't include the linking offset? */ -struct xlink_map { - struct link_map lm; - Elf_Addr a; -}; - -/* - * Called after execution started so that we can load any dynamic symbols. - */ -void -elf_update(struct pstate *ps) -{ -#ifndef __NetBSD__ - struct xlink_map xlm; -#define lm xlm.lm - struct r_debug rdeb; - reg addr; - Elf_Dyn dyn; - static int bkpt_set; - Elf_Sym *s; - - if ((s = elf_lookup_table(ST_TO_ESH(ps->ps_sym_exe), "_DYNAMIC")) == NULL) { - warnx("Can't find _DYNAMIC"); - return; - } - addr = s->st_value + ps->ps_sym_exe->st_offs; - - do { - if (process_read(ps, addr, &dyn, sizeof(dyn)) < 0) { - warnx("Can't read _DYNAMIC"); - return; - } - addr += sizeof(dyn); - } while (dyn.d_tag != 0 && dyn.d_tag != DT_DEBUG); - - if (dyn.d_tag == 0) { - warnx("Can't find DT_DEBUG"); - return; - } - - if (process_read(ps, dyn.d_un.d_ptr, &rdeb, sizeof(rdeb)) < 0) { - warnx("Can't read DT_DEBUG"); - return; - } - - if (rdeb.r_version != 1) { - warn("Can't handle debug map version %d", rdeb.r_version); - return; - } - if (rdeb.r_state != RT_CONSISTENT) { - warn("debug map not consistent: %d", rdeb.r_state); - return; - } - - if (!bkpt_set) { - if (bkpt_add_cb(ps, rdeb.r_brk, sym_bkpt, NULL)) - warn("sym_exec: can't set bkpt"); - bkpt_set = 1; - } - - addr = (Elf_Addr)rdeb.r_map; - while (addr != 0 && addr != -1) { - char fname[MAXPATHLEN]; - int i; - - if (process_read(ps, addr, &xlm, sizeof(xlm)) < 0) { - warnx("Can't read symbols..."); - return; - } - - addr = (Elf_Addr)lm.l_next; - - if (lm.l_name == NULL || lm.l_name == (char *)-1) - continue; - if (process_read(ps, (Elf_Addr)lm.l_name, fname, - sizeof(fname)) < 0) { - warnx("Can't read symbols..."); - return; - } - - /* sanity check the file name */ - for (i = 0; i < MAXPATHLEN; i++) - if (fname[i] == '\0') - break; - if (i == MAXPATHLEN) - continue; - - if (st_open(ps, fname, xlm.a) == NULL) - warn("symbol loading failed"); - } -#endif -} diff --git a/usr.bin/pmdb/pmdb.1 b/usr.bin/pmdb/pmdb.1 deleted file mode 100644 index d822d13110b..00000000000 --- a/usr.bin/pmdb/pmdb.1 +++ /dev/null @@ -1,153 +0,0 @@ -.\" $OpenBSD: pmdb.1,v 1.18 2011/12/24 08:46:48 jmc Exp $ -.\" -.\" Copyright (c) 2002 Artur Grabowski <art@openbsd.org> -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. The name of the author may not be used to endorse or promote products -.\" derived from this software without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, -.\" INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY -.\" AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL -.\" THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -.\" EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -.\" PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -.\" OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -.\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR -.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -.\" ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -.\" -.Dd $Mdocdate: December 24 2011 $ -.Dt PMDB 1 -.Os -.Sh NAME -.Nm pmdb -.Nd debugger -.Sh SYNOPSIS -.Nm pmdb -.Op Fl c Ar core -.Op Fl p Ar pid -.Ar program ... -.Sh DESCRIPTION -The -.Nm -utility can be used to see what is happening inside a running process or -to catch program crashes and examine the state at the time of the crash. -The only way to start -.Nm -at this moment is to specify the name of the program to be debugged and all -its arguments on the command line. -Optionally, -.Fl c -can be used to specify a core file to examine. -It is also possible to debug a process that is already running by specifying -the process's PID to the -.Fl p -flag. -This causes the process to be put in STOPPED state until execution -is resumed either by an explicit command to pmdb or by exiting pmdb. -The program is controlled from a command line which usually gives the -prompt "pmdb>". -.Sh PROCESS STATES -A loaded program can be in one of three possible states: -.Bl -tag -width RUNNING -.It LOADED -This is the initial state. -The program is not running, it can't be examined (because it doesn't have -any state). -The only thing that can be done to the process is to start it with the -.Ic run -command. -.It RUNNING -When a process is -.Ic RUNNING , -the only way to affect it is through signals sent to it. -Unless a signal is ignored with the -.Ic signal ignore -command, it will be caught by -.Nm -and the process will go into the -.Ic STOPPED -state. -.It STOPPED -A stopped process can be examined, changed and restarted with the -.Ic continue -command. -.El -.Sh COMMANDS -.Bl -tag -width continueXXXX -.It examine Ar symbol|address -Fetch and display in hex a word at -.Ar address -or -.Ar symbol . -.It regs -Show the contents of the processor registers at the moment the process was -.Ic STOPPED . -.It trace -Show the function call trace of the currently -.Ic STOPPED -process. -.It run -Start running a -.Ic LOADED -process. -.It continue -Continue a -.Ic STOPPED -process. -.It kill -Unconditionally kills the debugged process and puts it in the -.Ic LOADED -state. -.It signal Ar ignore|stop Ar signum|signame -Sets the signal state for the specified signal to either ignore it and -pass it to the process or to stop the process. -.It sigstate -Shows which signals are currently ignored. -.It setenv Ar var Ar val -Sets the environment variable -.Ar var -to the value -.Ar val . -.It break Ar symname|addr -Sets a breakpoint at the symbol -.Ar symname -or the numerical address -.Ar addr . -.It step -Resumes execution just like -.Ic continue , -but stops it again as soon as possible after executing at least -one instruction. -.It sym_load Ar fname Ar offs -Loads a symbol table from the file -.Ar fname -at the offset -.Ar offs . -.It help -Shows a short help. -.It quit -Kills the process (if necessary) and exits. -.It exit -Alias for -.Ic quit . -.El -.Sh SEE ALSO -.Xr core 5 -.Sh HISTORY -The -.Nm -debugger was written because the author believed that -.Xr gdb 1 -was too bloated and hairy to run on OpenBSD/sparc64. -.Sh BUGS -The command syntax is really poor and ad hoc at this moment. -Most of the command names and arguments will change -as soon as the command line interface is replaced. diff --git a/usr.bin/pmdb/pmdb.c b/usr.bin/pmdb/pmdb.c deleted file mode 100644 index d3ac2763a4e..00000000000 --- a/usr.bin/pmdb/pmdb.c +++ /dev/null @@ -1,473 +0,0 @@ -/* $OpenBSD: pmdb.c,v 1.22 2008/05/01 21:18:13 miod Exp $ */ -/* - * Copyright (c) 2002 Artur Grabowski <art@openbsd.org> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include <sys/types.h> -#include <sys/ptrace.h> -#include <sys/wait.h> - -#include <stdlib.h> -#include <stdio.h> -#include <unistd.h> -#include <signal.h> -#include <err.h> -#include <errno.h> -#include <string.h> -#include <paths.h> - -#include "pmdb.h" -#include "symbol.h" -#include "clit.h" -#include "break.h" -#include "core.h" - -static int cmd_show_registers(int, char **, void *); -static int cmd_show_backtrace(int, char **, void *); -static int cmd_examine(int, char **, void *); -static int cmd_quit(int, char **, void *); - -struct clit cmds[] = { - /* debugging info commands. */ - { "regs", "show registers", 0, 0, cmd_show_registers, (void *)-1 }, - { "trace", "show backtrace", 0, 0, cmd_show_backtrace, (void *)-1 }, - { "x", "examine memory", 1, 16, cmd_examine, (void *)-1 }, - - /* Process handling commands. */ - { "run", "run process", 0, 0, cmd_process_run, (void *)-1 }, - { "continue", "continue process", 0, 0, cmd_process_cont, (void *)-1 }, - { "kill", "kill process", 0, 0, cmd_process_kill, (void *)-1 }, - { "setenv", "set env variables", 2, 2, cmd_process_setenv, (void *)-1 }, - - /* signal handling commands. */ - { "signal", "ignore signal", 2, 2, cmd_signal_ignore, (void *)-1 }, - { "sigstate", "show signal state", 0, 0, cmd_signal_show, (void *)-1 }, - - /* breakpoints */ - { "break", "set breakpoint", 1, 1, cmd_bkpt_add, (void *)-1 }, - { "step", "single step one insn", 0, 0, cmd_sstep, (void *)-1 }, - - /* symbols */ - { "sym_load", "load symbol table", 2, 2, cmd_sym_load, (void *)-1 }, - - /* misc commands. */ - { "help", "print help", 0, 1, cmd_help, NULL }, - { "quit", "quit", 0, 0, cmd_quit, (void *)-1 }, - { "exit", "quit", 0, 0, cmd_quit, (void *)-1 }, -}; - -#define NCMDS sizeof(cmds)/sizeof(cmds[0]) - -void -usage(void) -{ - extern char *__progname; - - fprintf(stderr, "usage: %s [-c core] [-p pid] program ...\n", - __progname); - exit(1); -} - -int -main(int argc, char **argv) -{ - struct pstate ps; - int i, c; - int status; - void *cm; - char *pmenv, *core, *perr, execpath[MAXPATHLEN]; - int level; - pid_t pid; - - core = NULL; - pid = 0; - - while ((c = getopt(argc, argv, "c:p:")) != -1) { - switch(c) { - case 'c': - core = optarg; - break; - case 'p': - pid = (pid_t) strtol(optarg, &perr, 10); - if (*perr != '\0') - errx(1, "invalid PID"); - break; - case '?': - default: - usage(); - /* NOTREACHED */ - } - } - argc -= optind; - argv += optind; - - if (argc == 0) - usage(); - - if ((pmenv = getenv("IN_PMDB")) != NULL) { - level = atoi(pmenv); - level++; - } else - level = 0; - - if (level > 0) - asprintf(&prompt_add, "(%d)", level); - asprintf(&pmenv, "%d", level); - setenv("IN_PMDB", pmenv, 1); - if (pmenv) - free(pmenv); - - if (getexecpath(argv[0], execpath, sizeof(execpath)) == -1) { - err(1, "cannot find `%s'", argv[0]); - } - argv[0] = execpath; - - memset(&ps, 0, sizeof(ps)); - process_setargv(&ps, argc, argv); - - ps.ps_pid = pid; - ps.ps_state = NONE; - ps.ps_flags = 0; - ps.ps_signum = 0; - ps.ps_npc = 1; - TAILQ_INIT(&ps.ps_bkpts); - TAILQ_INIT(&ps.ps_sstep_cbs); - - signal(SIGINT, SIG_IGN); - - for (i = 0; i < NCMDS; i++) - if (cmds[i].arg == (void *)-1) - cmds[i].arg = &ps; - - md_def_init(); - init_sigstate(&ps); - - if ((core != NULL) && (read_core(core, &ps) < 0)) - warnx("failed to load core file"); - - if (process_load(&ps) < 0) - errx(1, "failed to load process"); - - cm = cmdinit(cmds, NCMDS); - while (ps.ps_state != TERMINATED) { - int signum; - int stopped; - int cont; - - if (ps.ps_state == STOPPED) { - sym_update(&ps); - } - - if (ps.ps_state != RUNNING && cmdloop(cm) == 0) { - cmd_quit(0, NULL, &ps); - } - - if (ps.ps_state == TERMINATED) - break; - - if (ps.ps_state == NONE || ps.ps_state == LOADED) - continue; - - if (wait(&status) == 0) - err(1, "wait"); - if (WIFEXITED(status)) { - if ((ps.ps_flags & PSF_KILL) == 0) { - ps.ps_state = NONE; - } else { - ps.ps_state = TERMINATED; - } - fprintf(stderr, "process exited with status %d\n", - WEXITSTATUS(status)); - continue; - } - if (WIFSIGNALED(status)) { - signum = WTERMSIG(status); - stopped = 0; - } else { - signum = WSTOPSIG(status); - stopped = 1; - } - cont = 0; - if (stopped) - cont = bkpt_check(&ps); - process_signal(&ps, signum, stopped, cont); - } - - cmdend(cm); - - sym_destroy(&ps); - - return (0); -} - - -static int -cmd_show_registers(int argc, char **argv, void *arg) -{ - struct pstate *ps = arg; - char buf[256]; - int i; - reg *rg; - - if (ps->ps_state != STOPPED) { - if (ps->ps_flags & PSF_CORE) { - /* dump registers from core */ - core_printregs(ps); - return (0); - } - fprintf(stderr, "process not stopped\n"); - return (0); - } - - rg = alloca(sizeof(*rg) * md_def.nregs); - - if (md_getregs(ps, rg)) - err(1, "can't get registers"); - for (i = 0; i < md_def.nregs; i++) - printf("%s:\t0x%.*lx\t%s\n", md_def.md_reg_names[i], - (int)(sizeof(reg) * 2), (long)rg[i], - sym_print(ps, rg[i], buf, sizeof(buf))); - return (0); -} - -static int -cmd_show_backtrace(int argc, char **argv, void *arg) -{ - struct pstate *ps = arg; - int i; - - if (ps->ps_state != STOPPED && !(ps->ps_flags & PSF_CORE)) { - fprintf(stderr, "process not stopped\n"); - return (0); - } - - /* no more than 100 frames */ - for (i = 0; i < 100; i++) { - struct md_frame mfr; - char namebuf[1024], *name; - reg offs; - int j; - - mfr.nargs = -1; - - if (md_getframe(ps, i, &mfr)) - break; - - name = sym_name_and_offset(ps, mfr.pc, namebuf, - sizeof(namebuf), &offs); - if (name == NULL) { - snprintf(namebuf, sizeof(namebuf), "0x%lx", mfr.pc); - name = namebuf; - offs = 0; - } - - printf("%s(", name); - for (j = 0; j < mfr.nargs; j++) { - printf("0x%lx", mfr.args[j]); - if (j < mfr.nargs - 1) - printf(", "); - } - if (offs == 0) { - printf(")\n"); - } else { - printf(")+0x%lx\n", offs); - } - } - - return (0); -} - -static int -cmd_quit(int argc, char **argv, void *arg) -{ - struct pstate *ps = arg; - - if ((ps->ps_flags & PSF_ATCH)) { - if ((ps->ps_flags & PSF_ATCH) && - ptrace(PT_DETACH, ps->ps_pid, NULL, 0) < 0) - err(1, "ptrace(PT_DETACH)"); - } else { - ps->ps_flags |= PSF_KILL; - - if (process_kill(ps)) - return (1); - } - - ps->ps_state = TERMINATED; - return (1); -} - -static int -cmd_examine(int argc, char **argv, void *arg) -{ - struct pstate *ps = arg; - char buf[256]; - reg addr, val; - int i; - - for (i = 1; argv[i]; i++) { - - addr = strtoul(argv[i], NULL, 0); - if (!addr) { /* assume it's a symbol */ - if (sym_lookup(ps, argv[i], &addr)) { - warn( "Can't find: %s", argv[i]); - return (0); - } - } - - if (process_read(ps, addr, &val, sizeof(val)) < 0) { - warn("Can't read process contents at 0x%lx", addr); - return (0); - } - - printf("%s:\t%s\n", argv[i], - sym_print(ps, val, buf, sizeof(buf))); - } - - return (0); -} - -/* - * Perform command completion. - * Pretty simple. if there are spaces in "buf", the last string is a symbol - * otherwise it's a command. - */ -int -cmd_complt(char *buf, size_t buflen) -{ - struct clit *match; - char *start; - int command; - int i, j, len; - int onlymatch; - - command = (strchr(buf, ' ') == NULL); - - if (!command) { - /* XXX - can't handle symbols yet. */ - return (-1); - } - - start = buf; - len = strlen(buf); - - match = NULL; - for (i = 0; i < sizeof(cmds) / sizeof(cmds[i]); i++) { - if (strncmp(start, cmds[i].cmd, len) == 0) { - struct clit *cmdp; - - cmdp = &cmds[i]; - if (match == NULL) { - onlymatch = 1; - match = cmdp; - strlcpy(buf, match->cmd, buflen); - continue; - } - onlymatch = 0; - for (j = len; j < buflen; j++) { - if (buf[j] != cmdp->cmd[j]) { - buf[j] = '\0'; - break; - } - if (cmdp->cmd[j] == '\0') - break; - } - } - } - - /* - * Be nice. If there could be arguments for this command and it's - * the only match append a space. - */ - if (match && onlymatch /*&& match->maxargc > 0*/) - strlcat(buf, " ", buflen); - - return (match && onlymatch) ? 0 : -1; -} - -/* - * The "standard" wrapper - */ -void * -emalloc(size_t sz) -{ - void *ret; - if ((ret = malloc(sz)) == NULL) - err(1, "malloc"); - return (ret); -} - - -/* - * Find the first valid path to the executable whose name is <ename>. - * The resulting path is stored in <dst>, up to <dlen> - 1 bytes, and is - * NUL-terminated. If <dst> is too small, the result will be truncated to - * fit, but getexecpath() will return -1. - * Returns 0 on success, -1 on failure. - */ - -int -getexecpath(const char *ename, char *dst, size_t dlen) -{ - char *envp, *pathenv, *pp, *pfp; - struct stat pstat; - - if (stat(ename, &pstat) == 0) { - if (strlcpy(dst, ename, dlen) >= dlen) - return (-1); - return (0); - } - - if (strchr(ename, '/') != NULL) { - /* don't bother looking in PATH */ - return (-1); - } - - envp = getenv("PATH"); - if (envp == NULL) - envp = _PATH_DEFPATH; - - pathenv = strdup(envp); - if (pathenv == NULL) { - warn("failed to allocate PATH buffer"); - return (-1); - } - - for (pp = pathenv; (pfp = strsep(&pp, ":")) != NULL; ) { - /* skip cwd, was already tested */ - if (*pfp == '\0') - continue; - - if (snprintf(dst, dlen, "%s/%s", pfp, ename) >= (int)dlen) - continue; - - if (stat(dst, &pstat) != -1) { - free(pathenv); - return (0); - } - } - - free(pathenv); - return (-1); -} diff --git a/usr.bin/pmdb/pmdb.h b/usr.bin/pmdb/pmdb.h deleted file mode 100644 index 98276c8700f..00000000000 --- a/usr.bin/pmdb/pmdb.h +++ /dev/null @@ -1,133 +0,0 @@ -/* $OpenBSD: pmdb.h,v 1.7 2003/08/18 17:55:57 jfb Exp $ */ -/* - * Copyright (c) 2002 Artur Grabowski <art@openbsd.org> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include <sys/signal.h> /* for NSIG */ -#include <sys/queue.h> -#include <sys/ptrace.h> -#include <sys/stat.h> - -#include <err.h> - -/* XXX - ugh, yuck, bleah. */ -#ifndef PT_STEP -#define PT_STEP PT_CONTINUE -#endif - -/* - * Process handling. - */ - -struct breakpoint; -struct callback; -struct corefile; -struct sym_table; -struct sym_ops; -struct reg; - -/* XXX - should be machdep some day. */ -typedef unsigned long reg; - -/* The state for a debugged process. */ -struct pstate { - pid_t ps_pid; - enum { NONE, LOADED, RUNNING, STOPPED, TERMINATED } ps_state; - int ps_argc; - char **ps_argv; - int ps_flags; - int ps_signum; - int ps_sigstate[NSIG]; - reg ps_npc; - TAILQ_HEAD(,sym_table) ps_syms; /* all symbols tables in a list */ - struct sym_table *ps_sym_exe; /* symbol table for the executable */ - struct sym_ops *ps_sops; /* operations on symbol tables */ - struct stat exec_stat; /* stat of the exec file */ - struct corefile *ps_core; /* core file data */ - TAILQ_HEAD(,breakpoint) ps_bkpts; /* breakpoints */ - TAILQ_HEAD(,callback) ps_sstep_cbs; /* single step actions */ -}; - -/* flags in ps_flags */ -#define PSF_SYMBOLS 0x02 /* basic symbols loaded */ -#define PSF_KILL 0x04 /* kill this process asap */ -#define PSF_STEP 0x08 /* next continue should sstep */ -#define PSF_CORE 0x10 /* core file loaded */ -#define PSF_ATCH 0x20 /* process attached with PT_ATTACH */ - -/* ps_sigstate */ -#define SS_STOP 0x00 -#define SS_IGNORE 0x01 - -/* misc helper functions */ -int getexecpath(const char *, char *, size_t); -int process_kill(struct pstate *); - -/* process.c */ -int process_load(struct pstate *); -int process_setargv(struct pstate *, int, char **); -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 *); -int cmd_process_setenv(int, char **, void *); - -/* signal.c */ -void init_sigstate(struct pstate *); -void process_signal(struct pstate *, int, int, int); -int cmd_signal_ignore(int, char **, void *); -int cmd_signal_show(int, char **, void *); - -/* - * Machine dependent stuff. - */ -/* register names */ -struct md_def { - const char **md_reg_names; /* array of register names */ - const int nregs; /* number of registers */ - const int pcoff; /* offset of the pc */ -}; -extern struct md_def md_def; -void md_def_init(void); - -#define MDF_MAX_ARGS 16 - -struct md_frame { - reg pc, fp; - int nargs; - reg args[MDF_MAX_ARGS]; -}; - -/* - * Return the registers for the process "ps" in the frame "frame". - */ -int md_getframe(struct pstate *, int, struct md_frame *); -int md_getregs(struct pstate *, reg *); - -/* misc */ -void *emalloc(size_t); diff --git a/usr.bin/pmdb/process.c b/usr.bin/pmdb/process.c deleted file mode 100644 index e6d28eb44dc..00000000000 --- a/usr.bin/pmdb/process.c +++ /dev/null @@ -1,302 +0,0 @@ -/* $OpenBSD: process.c,v 1.13 2003/08/18 17:55:57 jfb Exp $ */ -/* - * Copyright (c) 2002 Artur Grabowski <art@openbsd.org> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include <sys/types.h> -#include <sys/ptrace.h> -#include <sys/wait.h> -#include <sys/stat.h> - -#include <machine/reg.h> - -#include <err.h> -#include <errno.h> -#include <signal.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> - -#include "pmdb.h" -#include "core.h" -#include "symbol.h" -#include "break.h" - -int -process_load(struct pstate *ps) -{ - if (ps->ps_state == LOADED) - return (0); - - if (access(*ps->ps_argv, R_OK|X_OK) < 0) { - fprintf(stderr, "%s: %s.\n", *ps->ps_argv, - strerror(errno)); - return (1); - } - - 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) - err(1, "failed to ptrace process"); - ps->ps_state = STOPPED; - ps->ps_flags |= PSF_ATCH; - } - - return (0); -} - - -int -process_setargv(struct pstate *ps, int argc, char **argv) -{ - int i; - - if (ps->ps_argv != NULL) { - for (i = 0; i < ps->ps_argc; i++) - free(ps->ps_argv[i]); - free(ps->ps_argv); - } - - ps->ps_argv = (char **)calloc((argc + 1), sizeof(char *)); - if (ps->ps_argv == NULL) { - warn("failed to allocate argument vector"); - return (-1); - } - - ps->ps_argc = argc; - for (i = 0; i < argc; i++) { - ps->ps_argv[i] = strdup(argv[i]); - if (ps->ps_argv[i] == NULL) { - warn("failed to copy argument"); - return (-1); - } - } - - ps->ps_argv[i] = NULL; - 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; - } - - 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 RUNNING: - case STOPPED: - if (ptrace(PT_KILL, ps->ps_pid, NULL, 0) != 0) - err(1, "ptrace(PT_KILL)"); - return (1); - default: - return (0); - } -} - -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) < 0? - -1 : piod.piod_len); - } -} - -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) < 0? - -1 : piod.piod_len); - } -} - -int -process_getregs(struct pstate *ps, struct reg *r) -{ - - if (ps->ps_flags & PSF_CORE) { - memcpy(r, ps->ps_core->regs, sizeof(*r)); - - return (0); - } - - return (ptrace(PT_GETREGS, ps->ps_pid, (caddr_t)r, 0)); -} - -int -cmd_process_kill(int argc, char **argv, void *arg) -{ - struct pstate *ps = arg; - - process_kill(ps); - - return (1); -} - -int -process_bkpt_main(struct pstate *ps, void *arg) -{ - sym_update(ps); - - return (BKPT_DEL_CONT); -} - -int -cmd_process_run(int argc, char **argv, void *arg) -{ - struct pstate *ps = arg; - - if (ps->ps_state == NONE) { - reg main_addr; - - if (process_load(ps) != 0) - return (0); - - if (sym_lookup(ps, "main", &main_addr)) - warnx("no main"); - else if (bkpt_add_cb(ps, main_addr, process_bkpt_main, NULL)) - warn("no bkpt at main 0x%lx", main_addr); - } - - if (ps->ps_state != LOADED) { - fprintf(stderr, "Process already running.\n"); - return (0); - } - - process_run(ps); - /* - * XXX - there isn't really any difference between STOPPED and - * LOADED, we should probably get rid of one. - */ - ps->ps_state = STOPPED; - ps->ps_signum = 0; - - return (cmd_process_cont(argc, argv, arg)); -} - -int -cmd_process_cont(int argc, char **argv, void *arg) -{ - struct pstate *ps = arg; - int signum; - int req = (ps->ps_flags & PSF_STEP) ? PT_STEP : PT_CONTINUE; - - if (ps->ps_state != STOPPED) { - fprintf(stderr, "Process not loaded and stopped %d\n", - ps->ps_state); - return (0); - } - - /* Catch SIGINT and SIGTRAP, pass all other signals. */ - switch (ps->ps_signum) { - case SIGINT: - case SIGTRAP: - signum = 0; - break; - default: - signum = ps->ps_signum; - break; - } - - if (ptrace(req, ps->ps_pid, (caddr_t)ps->ps_npc, signum) != 0) { - err(1, "ptrace(%s)", req == PT_STEP ? "PT_STEP":"PT_CONTINUE"); - } - - ps->ps_state = RUNNING; - ps->ps_npc = 1; - - return (1); -} - -int -cmd_process_setenv(int argc, char **argv, void *arg) -{ - if (setenv(argv[1], argv[2], 1)) - err(1, "setenv"); - - return (0); -} diff --git a/usr.bin/pmdb/signal.c b/usr.bin/pmdb/signal.c deleted file mode 100644 index d985a4e4bc9..00000000000 --- a/usr.bin/pmdb/signal.c +++ /dev/null @@ -1,166 +0,0 @@ -/* $OpenBSD: signal.c,v 1.5 2008/06/01 18:38:29 sobrado Exp $ */ -/* - * Copyright (c) 2002 Artur Grabowski <art@openbsd.org> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include <stdlib.h> -#include <stdio.h> -#include <unistd.h> -#include <signal.h> -#include <string.h> -#include <sys/wait.h> - -#include "pmdb.h" - -void -init_sigstate(struct pstate *ps) -{ - int i; - - for (i = 1; i < NSIG; i++) - ps->ps_sigstate[i] = SS_STOP; - - /* XXX - add more default ignored signals. */ - ps->ps_sigstate[SIGALRM] = SS_IGNORE; - ps->ps_sigstate[SIGCHLD] = SS_IGNORE; -} - -void -process_signal(struct pstate *ps, int signum, int stopped, int force_ignore) -{ - int ignore, status; - - if (stopped && (ps->ps_sigstate[signum] == SS_IGNORE || force_ignore)) - ignore = 1; - else - ignore = 0; - - if (force_ignore && ignore) - signum = 0; - - ps->ps_signum = signum; - - if (!stopped) { - /* - * Process terminated. - */ - /* Let it be restarted if it wasn't a forced termination. */ - if ((ps->ps_flags & PSF_KILL) == 0) - ps->ps_state = NONE; - else - ps->ps_state = TERMINATED; - /* - * Wait for it as a parent. - * XXX - only if we're the real parent. - */ - wait(&status); - } else { - ps->ps_state = STOPPED; - } - - if (!ignore) { - fprintf(stderr, "PMDB %s child. signal: %s\n", - stopped ? "stopping" : "terminating", - sys_signame[signum]); - } else { - cmd_process_cont(0, NULL, ps); - } -} - -int -cmd_signal_ignore(int argc, char **argv, void *arg) -{ - struct pstate *ps = arg; - int signum; - long l; - char *ep; - char *signame = argv[2]; - int newstate; - - if (!strcmp(argv[1], "ignore")) { - newstate = SS_IGNORE; - } else if (!strcmp(argv[1], "stop")) { - newstate = SS_STOP; - } else { - goto usage; - } - - l = strtol(signame, &ep, 0); - if (signame[0] == '\0' || *ep != '\0' || l < 1 || l >= NSIG) { - if (!strncmp("SIG", signame, 3)) - signame += 3; - for (signum = 1; signum < NSIG; signum++) { - if (!strcmp(sys_signame[signum], signame)) - break; - } - } else { - signum = l; - } - - switch (signum) { - case SIGINT: - case SIGSTOP: - case SIGKILL: - fprintf(stderr, "%s can't be ignored\n", signame); - goto usage; - case NSIG: - fprintf(stderr, "%s is not a valid signal\n", signame); - goto usage; - default: - break; - } - - ps->ps_sigstate[signum] = newstate; - - return 0; -usage: - fprintf(stderr, "usage: signal ignore|stop signum|signame\n"); - return 0; -} - -int -cmd_signal_show(int argc, char **argv, void *arg) -{ - struct pstate *ps = arg; - int i; - - for (i = 1; i < NSIG; i++) { - char *state; - - switch (ps->ps_sigstate[i]) { - case SS_STOP: - state = "stop"; - break; - case SS_IGNORE: - state = "ignore"; - break; - default: - state = "error"; - break; - } - printf("%2d %-6s\t%s\n", i, sys_signame[i], state); - } - - return 0; -} diff --git a/usr.bin/pmdb/symbol.c b/usr.bin/pmdb/symbol.c deleted file mode 100644 index d30aae16ec4..00000000000 --- a/usr.bin/pmdb/symbol.c +++ /dev/null @@ -1,193 +0,0 @@ -/* $OpenBSD: symbol.c,v 1.7 2003/03/28 23:33:27 mickey Exp $ */ -/* - * Copyright (c) 2002 Artur Grabowski <art@openbsd.org> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <err.h> -#include <errno.h> - -#include "pmdb.h" -#include "symbol.h" - -/* - * Initialize the executable and the symbol table. - */ -void -sym_init_exec(struct pstate *ps, const char *name) -{ - ps->ps_sops = NULL; - ps->ps_sym_exe = NULL; - TAILQ_INIT(&ps->ps_syms); - -#ifdef PMDB_ELF - if (sym_check_elf(name, ps)) -#endif -#ifdef PMDB_AOUT - if (sym_check_aout(name, ps)) -#endif - warnx("sym_init_exec: %s is not a supported file format", name); - - if (ps->ps_sops) { - /* XXX - this 0 doesn't have to be correct.. */ - ps->ps_sym_exe = st_open(ps, name, 0); - if (ps->ps_sym_exe) - ps->ps_sym_exe->st_flags |= ST_EXEC; - } -} - -/* - * Destroy all symbol tables. - */ -void -sym_destroy(struct pstate *ps) -{ - struct sym_table *st; - - if (!(ps->ps_flags & PSF_SYMBOLS)) - return; - while ((st = TAILQ_FIRST(&ps->ps_syms)) != NULL) { - TAILQ_REMOVE(&ps->ps_syms, st, st_list); - (*ps->ps_sops->sop_close)(st); - } - ps->ps_sym_exe = NULL; -} - -/* - * We have reasons to believe that the symbol tables we have are not consistent - * with the running binary. Update. - */ -void -sym_update(struct pstate *ps) -{ - (*ps->ps_sops->sop_update)(ps); -} - -char * -sym_name_and_offset(struct pstate *ps, reg pc, char *nam, size_t len, reg *off) -{ - struct sym_table *st; - int bestoffisset = 0; - reg bestoff, noff; - char *res; - - TAILQ_FOREACH(st, &ps->ps_syms, st_list) { - res = (*ps->ps_sops->sop_name_and_off)(st, pc, &noff); - if (res == NULL) - continue; - if (noff < bestoff || !bestoffisset) { - bestoffisset = 1; - bestoff = noff; - strlcpy(nam, res, len); - } - } - - if (!bestoffisset || !strcmp(nam, "_end")) - return (NULL); - - *off = bestoff; - return (nam); -} - -int -sym_lookup(struct pstate *ps, const char *name, reg *res) -{ - /* - * We let the sop do the table walking itself since it might have - * preferences about what symbols to pick (weak and stuff). - */ - return ((*ps->ps_sops->sop_lookup)(ps, name, res)); -} - -char * -sym_print(struct pstate *ps, reg pc, char *buf, size_t buflen) -{ - char namebuf[1024], *name; - reg offs; - - name = sym_name_and_offset(ps, pc, namebuf, sizeof(namebuf), &offs); - if (name == NULL) { - snprintf(buf, buflen, "0x%lx", pc); - } else { - if (offs) - snprintf(buf, buflen, "%s+0x%lx(0x%lx)", - name, offs, pc); - else - snprintf(buf, buflen, "%s(0x%lx)", name, pc); - } - - return (buf); -} - -/* - * Open a symbol table and install it in the list. Don't do anything if - * it's already there. - */ -struct sym_table * -st_open(struct pstate *ps, const char *name, reg offs) -{ - struct sym_table *st; - - TAILQ_FOREACH(st, &ps->ps_syms, st_list) { - if (!strcmp(name, st->st_fname) && (st->st_offs == offs)) - return (st); - } - - warnx("Loading symbols from %s at 0x%lx", name, offs); - - if ((st = (*ps->ps_sops->sop_open)(name)) != NULL) { - TAILQ_INSERT_TAIL(&ps->ps_syms, st, st_list); - strlcpy(st->st_fname, name, sizeof(st->st_fname)); - st->st_offs = offs; - } - - return (st); -} - -/* - * Load a symbol table from file argv[1] at offset argv[2]. - */ -int -cmd_sym_load(int argc, char **argv, void *arg) -{ - struct pstate *ps = arg; - char *fname, *ep; - reg offs; - - fname = argv[1]; - errno = 0; - offs = strtol(argv[2], &ep, 0); - if (argv[2][0] == '\0' || *ep != '\0' || errno == ERANGE) { - fprintf(stderr, "%s is not a valid offset\n", argv[2]); - return (0); - } - - if (st_open(ps, fname, offs) == NULL) { - warnx("symbol loading failed"); - } - - return (0); -} diff --git a/usr.bin/pmdb/symbol.h b/usr.bin/pmdb/symbol.h deleted file mode 100644 index 1e266057dc4..00000000000 --- a/usr.bin/pmdb/symbol.h +++ /dev/null @@ -1,64 +0,0 @@ -/* $OpenBSD: symbol.h,v 1.4 2002/03/15 18:04:41 art Exp $ */ -/* - * Copyright (c) 2002 Artur Grabowski <art@openbsd.org> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include <sys/param.h> - -struct sym_table { - TAILQ_ENTRY(sym_table) st_list; - char st_fname[MAXPATHLEN]; - int st_flags; - reg st_offs; -}; - -/* Flags in st_flags */ -#define ST_EXEC 0x01 /* this is the executable */ - -struct sym_ops { - struct sym_table *(*sop_open)(const char *); - void (*sop_close)(struct sym_table *); - char *(*sop_name_and_off)(struct sym_table *, reg, reg *); - int (*sop_lookup)(struct pstate *, const char *, reg *); - void (*sop_update)(struct pstate *); -}; - -void sym_init_exec(struct pstate *, const char *); -void sym_destroy(struct pstate *); -void sym_update(struct pstate *); -char *sym_name_and_offset(struct pstate *, reg, char *, size_t, reg *); -int sym_lookup(struct pstate *, const char *, reg *); -char *sym_print(struct pstate *, reg, char *, size_t); - -/* Internal for symbol handlers only. */ -struct sym_table *st_open(struct pstate *, const char *, reg); - -#ifdef PMDB_ELF -int sym_check_elf(const char *, struct pstate *); -#endif -#ifdef PMDB_AOUT -int sym_check_aout(const char *, struct pstate *); -#endif - -int cmd_sym_load(int, char **, void *); |