xref: /titanic_50/usr/src/cmd/mdb/common/mdb/mdb.h (revision 94d05f6c7f329fdf908da99ab50b37d3d33f9fe5)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_MDB_H
27 #define	_MDB_H
28 
29 #include <mdb/mdb_nv.h>
30 #include <mdb/mdb_io.h>
31 #include <mdb/mdb_gelf.h>
32 #include <mdb/mdb_addrvec.h>
33 #include <mdb/mdb_argvec.h>
34 #include <mdb/mdb_target.h>
35 #include <mdb/mdb_disasm.h>
36 #include <mdb/mdb_demangle.h>
37 #include <mdb/mdb_module.h>
38 #include <mdb/mdb_modapi.h>
39 #include <mdb/mdb_list.h>
40 #include <mdb/mdb_vcb.h>
41 #ifdef _KMDB
42 #include <kmdb/kmdb_wr.h>
43 #endif
44 
45 #ifdef	__cplusplus
46 extern "C" {
47 #endif
48 
49 #define	MDB_ERR_PARSE	1	/* Error occurred in lexer or parser */
50 #define	MDB_ERR_NOMEM	2	/* Failed to allocate needed memory */
51 #define	MDB_ERR_PAGER	3	/* User quit current command from pager */
52 #define	MDB_ERR_SIGINT	4	/* User interrupt: abort current command */
53 #define	MDB_ERR_QUIT	5	/* User request: quit debugger */
54 #define	MDB_ERR_ASSERT	6	/* Assertion failure: abort current command */
55 #define	MDB_ERR_API	7	/* API function error: abort current command */
56 #define	MDB_ERR_ABORT	8	/* User abort or resume: abort to top level */
57 #define	MDB_ERR_OUTPUT	9	/* Write to m_out failed: abort to top level */
58 
59 #define	MDB_ERR_IS_FATAL(err)	\
60 	((err) == MDB_ERR_QUIT || (err) == MDB_ERR_ABORT || \
61 	(err) == MDB_ERR_OUTPUT)
62 
63 #define	MDB_DEF_RADIX	16	/* Default output radix */
64 #define	MDB_DEF_NARGS	6	/* Default # of arguments in stack trace */
65 #define	MDB_DEF_HISTLEN	128	/* Default length of command history */
66 #define	MDB_DEF_SYMDIST	0x8000	/* Default symbol distance for addresses */
67 #define	MDB_DEF_ARRMEM	32	/* Default number of array members to print */
68 #define	MDB_DEF_ARRSTR	1024	/* Default number of array chars to print */
69 
70 #define	MDB_ARR_NOLIMIT	-1UL	/* No limit on number of array elements */
71 
72 #define	MDB_FL_PSYM	0x00001	/* Print dot as symbol + offset when possible */
73 #define	MDB_FL_LOG	0x00002	/* Logging is enabled */
74 #define	MDB_FL_NOMODS	0x00004	/* Skip automatic mdb module loading */
75 #define	MDB_FL_USECUP	0x00008	/* Use terminal cup initialization sequences */
76 #define	MDB_FL_ADB	0x00010	/* Enable stricter adb(1) compatibility */
77 #define	MDB_FL_SHOWLMID	0x00020	/* Always show link map id with symbol names */
78 #define	MDB_FL_IGNEOF	0x00040	/* Ignore EOF as a synonym for ::quit */
79 #define	MDB_FL_REPLAST	0x00080	/* Naked newline repeats previous command */
80 #define	MDB_FL_PAGER	0x00100	/* Enable pager by default */
81 #define	MDB_FL_LATEST	0x00200	/* Replace version string with "latest" */
82 #define	MDB_FL_VCREATE	0x00400	/* Victim process was created by debugger */
83 #define	MDB_FL_JOBCTL	0x00800	/* Victim process jobctl stopped on same tty */
84 #define	MDB_FL_DEMANGLE	0x01000	/* Demangle symbols as part of %a processing */
85 #define	MDB_FL_EXEC	0x02000	/* Debugger exec'd by a previous instance */
86 #define	MDB_FL_NOCTF	0x04000	/* Skip automatic CTF data loading */
87 #define	MDB_FL_BPTNOSYMSTOP 0x08000 /* Stop on deferred bkpts for unk symbols */
88 #define	MDB_FL_TERMGUESS 0x10000 /* m_termtype derived from userland */
89 #define	MDB_FL_READBACK	0x20000	/* Read value back after write */
90 #ifdef _KMDB
91 #define	MDB_FL_NOUNLOAD	0x40000	/* Don't allow debugger unload */
92 #endif
93 #define	MDB_FL_LMRAW	0x80000	/* Show unresolved link map object names */
94 
95 #define	MDB_FL_VOLATILE	0x0001	/* Mask of all volatile flags to save/restore */
96 
97 #define	MDB_EM_ASK	0	/* Ask what to do on an exec */
98 #define	MDB_EM_STOP	1	/* Stop after an exec */
99 #define	MDB_EM_FOLLOW	2	/* Follow an exec */
100 
101 #define	MDB_FM_ASK	0	/* Ask what to do on a fork */
102 #define	MDB_FM_PARENT	1	/* Follow parent process on a fork */
103 #define	MDB_FM_CHILD	2	/* Follow child process on a fork */
104 
105 #define	MDB_PROMPTLEN	35	/* Maximum prompt length */
106 
107 struct kmdb_promif;
108 
109 typedef struct mdb {
110 	uint_t m_tgtflags;	/* Target open flags (see mdb_target.h) */
111 	uint_t m_flags;		/* Miscellaneous flags (see above) */
112 	uint_t m_debug;		/* Debugging flags (see mdb_debug.h) */
113 	int m_radix;		/* Default radix for output formatting */
114 	int m_nargs;		/* Default number of arguments in stack trace */
115 	int m_histlen;		/* Length of command history */
116 	size_t m_symdist;	/* Distance from sym for addr match (0=smart) */
117 	const char *m_pname;	/* Program basename from argv[0] */
118 	char m_promptraw[MDB_PROMPTLEN + 1]; /* Un-expanded prompt */
119 	char m_prompt[MDB_PROMPTLEN + 1]; /* Prompt for interactive mode */
120 	size_t m_promptlen;	/* Length of prompt in bytes */
121 	const char *m_shell;	/* Shell for ! commands and pipelines */
122 	char *m_root;		/* Root for path construction */
123 	char *m_ipathstr;	/* Path string for include path */
124 	char *m_lpathstr;	/* Path string for library path */
125 	const char **m_ipath;	/* Path for $< and $<< macro files */
126 	size_t m_ipathlen;	/* Length of underlying ipath buffer */
127 	const char **m_lpath;	/* Path for :: loadable modules */
128 	size_t m_lpathlen;	/* Length of underlying lpath buffer */
129 	mdb_modinfo_t m_rminfo;	/* Root debugger module information */
130 	mdb_module_t m_rmod;	/* Root debugger module (builtins) */
131 	mdb_module_t *m_mhead;	/* Head of module list (in load order) */
132 	mdb_module_t *m_mtail;	/* Tail of module list (in load order) */
133 	mdb_list_t m_tgtlist;	/* List of active target backends */
134 	mdb_tgt_t *m_target;	/* Current debugger target backend */
135 	mdb_nv_t m_disasms;	/* Hash of available disassemblers */
136 	mdb_disasm_t *m_disasm;	/* Current disassembler backend */
137 	char *m_defdisasm;	/* Deferred diassembler selection */
138 	mdb_nv_t m_modules;	/* Name/value hash for loadable modules */
139 	mdb_nv_t m_dcmds;	/* Name/value hash for extended commands */
140 	mdb_nv_t m_walkers;	/* Name/value hash for walk operations */
141 	mdb_nv_t m_nv;		/* Name/value hash for named variables */
142 	mdb_var_t *m_dot;	/* Variable reference for '.' */
143 	uintmax_t m_incr;	/* Current increment */
144 	uintmax_t m_raddr;	/* Most recent address specified to a dcmd */
145 	uintmax_t m_dcount;	/* Most recent count specified to a dcmd */
146 	mdb_var_t *m_rvalue;	/* Most recent value printed */
147 	mdb_var_t *m_roffset;	/* Most recent offset from an instruction */
148 	mdb_var_t *m_proffset;	/* Previous value of m_roffset */
149 	mdb_var_t *m_rcount;	/* Most recent count on $< dcmd */
150 	mdb_iob_t *m_in;	/* Input stream */
151 	mdb_iob_t *m_out;	/* Output stream */
152 	mdb_iob_t *m_err;	/* Error stream */
153 	mdb_iob_t *m_null;	/* Null stream */
154 	char *m_termtype;	/* Interactive mode terminal type */
155 	mdb_io_t *m_term;	/* Terminal for interactive mode */
156 	mdb_io_t *m_log;	/* Log file i/o backend (NULL if not logging) */
157 	mdb_module_t *m_lmod;	/* Pointer to loading module, if in load */
158 	mdb_list_t m_lastc;	/* Last executed command list */
159 	mdb_gelf_symtab_t *m_prsym;   /* Private symbol table */
160 	mdb_demangler_t *m_demangler; /* Demangler (see <mdb/mdb_demangle.h>) */
161 	mdb_list_t m_flist;	/* Stack of execution frames */
162 	struct mdb_frame *volatile m_frame; /* Current stack frame */
163 	struct mdb_frame *volatile m_fmark; /* Stack marker for pager */
164 	uint_t m_fid;		/* Next frame identifier number to assign */
165 	uint_t m_depth;		/* Depth of m_frame stack */
166 	volatile uint_t m_intr;	/* Don't allow SIGINT if set */
167 	volatile uint_t m_pend;	/* Pending SIGINT count */
168 	pid_t m_pgid;		/* Debugger process group id */
169 	uint_t m_rdvers;	/* Librtld_db version number */
170 	uint_t m_ctfvers;	/* Libctf version number */
171 	ulong_t m_armemlim;	/* Limit on number of array members to print */
172 	ulong_t m_arstrlim;	/* Limit on number of array chars to print */
173 	uchar_t m_execmode;	/* Follow exec behavior */
174 	uchar_t m_forkmode;	/* Follow fork behavior */
175 	char **m_env;		/* Current environment */
176 	mdb_list_t m_cblist;	/* List of callbacks */
177 	mdb_nv_t m_macaliases;	/* Name/value hash of ADB macro aliases */
178 #ifdef _KMDB
179 	struct dpi_ops *m_dpi;	/* DPI ops vector */
180 	struct kdi *m_kdi;	/* KDI ops vector */
181 	size_t m_pagesize;	/* Base page size for this machine */
182 	caddr_t m_dseg;		/* Debugger segment address */
183 	size_t m_dsegsz;	/* Debugger segment size */
184 	mdb_nv_t m_dmodctl;	/* dmod name -> kmdb_modctl hash */
185 	kmdb_wr_t *m_drvwrhead;	/* Driver work request queue */
186 	kmdb_wr_t *m_drvwrtail;	/* Driver work request queue */
187 	kmdb_wr_t *m_dbgwrhead;	/* Debugger request queue */
188 	kmdb_wr_t *m_dbgwrtail;	/* Debugger request queue */
189 	struct cons_polledio *m_pio; /* Polled I/O struct from kernel */
190 	struct kmdb_promif *m_promif; /* Debugger/PROM interface state */
191 #endif
192 } mdb_t;
193 
194 #ifdef _MDB_PRIVATE
195 mdb_t mdb;
196 #else
197 extern mdb_t mdb;
198 #endif
199 
200 #ifdef _MDB
201 
202 #define	MDB_CONFIG_ENV_VAR "_MDB_CONFIG"
203 
204 extern void mdb_create(const char *, const char *);
205 extern void mdb_destroy(void);
206 
207 extern int mdb_call_idcmd(mdb_idcmd_t *, uintmax_t, uintmax_t, uint_t,
208     mdb_argvec_t *, mdb_addrvec_t *, mdb_vcb_t *);
209 
210 extern int mdb_call(uintmax_t, uintmax_t, uint_t);
211 extern int mdb_run(void);
212 
213 extern const char *mdb_get_prompt(void);
214 extern int mdb_set_prompt(const char *);
215 extern void mdb_set_ipath(const char *);
216 extern void mdb_set_lpath(const char *);
217 
218 extern const char **mdb_path_alloc(const char *, size_t *);
219 extern const char **mdb_path_dup(const char *[], size_t, size_t *);
220 extern void mdb_path_free(const char *[], size_t);
221 
222 extern uintmax_t mdb_dot_incr(const char *);
223 extern uintmax_t mdb_dot_decr(const char *);
224 
225 extern mdb_iwalker_t *mdb_walker_lookup(const char *);
226 extern mdb_idcmd_t *mdb_dcmd_lookup(const char *);
227 extern void mdb_dcmd_usage(const mdb_idcmd_t *, mdb_iob_t *);
228 
229 extern void mdb_pservice_init(void);
230 
231 extern void mdb_intr_enable(void);
232 extern void mdb_intr_disable(void);
233 
234 extern char *mdb_get_config(void);
235 extern void mdb_set_config(const char *);
236 
237 extern mdb_module_t *mdb_get_module(void);
238 
239 #endif /* _MDB */
240 
241 #ifdef	__cplusplus
242 }
243 #endif
244 
245 #endif	/* _MDB_H */
246