1 /*	$OpenBSD: pmdb.h,v 1.7 2003/08/18 17:55:57 jfb Exp $	*/
2 /*
3  * Copyright (c) 2002 Artur Grabowski <art@openbsd.org>
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. The name of the author may not be used to endorse or promote products
13  *    derived from this software without specific prior written permission.
14  *
15  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
16  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
17  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
18  * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19  * EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  */
26 
27 #include <sys/signal.h>		/* for NSIG */
28 #include <sys/queue.h>
29 #include <sys/ptrace.h>
30 #include <sys/stat.h>
31 
32 #include <err.h>
33 
34 /* XXX - ugh, yuck, bleah. */
35 #ifndef PT_STEP
36 #define PT_STEP PT_CONTINUE
37 #endif
38 
39 /*
40  * Process handling.
41  */
42 
43 struct breakpoint;
44 struct callback;
45 struct corefile;
46 struct sym_table;
47 struct sym_ops;
48 struct reg;
49 
50 /* XXX - should be machdep some day. */
51 typedef unsigned long reg;
52 
53 /* The state for a debugged process. */
54 struct pstate {
55 	pid_t ps_pid;
56 	enum { NONE, LOADED, RUNNING, STOPPED, TERMINATED } ps_state;
57 	int ps_argc;
58 	char **ps_argv;
59 	int ps_flags;
60 	int ps_signum;
61 	int ps_sigstate[NSIG];
62 	reg ps_npc;
63 	TAILQ_HEAD(,sym_table) ps_syms;	/* all symbols tables in a list */
64 	struct sym_table *ps_sym_exe;	/* symbol table for the executable */
65 	struct sym_ops *ps_sops;	/* operations on symbol tables */
66 	struct stat exec_stat;		/* stat of the exec file */
67 	struct corefile *ps_core;	/* core file data */
68 	TAILQ_HEAD(,breakpoint) ps_bkpts; /* breakpoints */
69 	TAILQ_HEAD(,callback) ps_sstep_cbs; /* single step actions */
70 };
71 
72 /* flags in ps_flags */
73 #define PSF_SYMBOLS	0x02		/* basic symbols loaded */
74 #define PSF_KILL	0x04		/* kill this process asap */
75 #define PSF_STEP	0x08		/* next continue should sstep */
76 #define PSF_CORE	0x10		/* core file loaded */
77 #define PSF_ATCH	0x20		/* process attached with PT_ATTACH */
78 
79 /* ps_sigstate */
80 #define SS_STOP		0x00
81 #define SS_IGNORE	0x01
82 
83 /* misc helper functions */
84 int getexecpath(const char *, char *, size_t);
85 int process_kill(struct pstate *);
86 
87 /* process.c */
88 int process_load(struct pstate *);
89 int process_setargv(struct pstate *, int, char **);
90 int process_run(struct pstate *);
91 int process_read(struct pstate *, off_t, void *, size_t);
92 int process_write(struct pstate *, off_t, void *, size_t);
93 int process_getregs(struct pstate *, struct reg *);
94 
95 int cmd_process_run(int, char **, void *);
96 int cmd_process_cont(int, char **, void *);
97 int cmd_process_kill(int, char **, void *);
98 int cmd_process_setenv(int, char **, void *);
99 
100 /* signal.c */
101 void init_sigstate(struct pstate *);
102 void process_signal(struct pstate *, int, int, int);
103 int cmd_signal_ignore(int, char **, void *);
104 int cmd_signal_show(int, char **, void *);
105 
106 /*
107  * Machine dependent stuff.
108  */
109 /* register names */
110 struct md_def {
111 	const char **md_reg_names;	/* array of register names */
112 	const int nregs;		/* number of registers */
113 	const int pcoff;		/* offset of the pc */
114 };
115 extern struct md_def md_def;
116 void md_def_init(void);
117 
118 #define MDF_MAX_ARGS	16
119 
120 struct md_frame {
121 	reg pc, fp;
122 	int nargs;
123 	reg args[MDF_MAX_ARGS];
124 };
125 
126 /*
127  * Return the registers for the process "ps" in the frame "frame".
128  */
129 int md_getframe(struct pstate *, int, struct md_frame *);
130 int md_getregs(struct pstate *, reg *);
131 
132 /* misc */
133 void *emalloc(size_t);
134