17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5dc0093f4Seschrock  * Common Development and Distribution License (the "License").
6dc0093f4Seschrock  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
21c9a6ea2eSBryan Cantrill 
227c478bd9Sstevel@tonic-gate /*
23c9a6ea2eSBryan Cantrill  * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
242a12f85aSJeremy Jones  * Copyright (c) 2013 by Delphix. All rights reserved.
25*3b442230SJordan Paige Hendricks  * Copyright 2019 Joyent, Inc.
267c478bd9Sstevel@tonic-gate  */
287c478bd9Sstevel@tonic-gate #ifndef	_MDB_MODAPI_H
297c478bd9Sstevel@tonic-gate #define	_MDB_MODAPI_H
317c478bd9Sstevel@tonic-gate /*
327c478bd9Sstevel@tonic-gate  * MDB Module API
337c478bd9Sstevel@tonic-gate  *
347c478bd9Sstevel@tonic-gate  * The debugger provides a set of interfaces for use in writing loadable
357c478bd9Sstevel@tonic-gate  * debugger modules.  Modules that call functions not listed in this header
367c478bd9Sstevel@tonic-gate  * file may not be compatible with future versions of the debugger.
377c478bd9Sstevel@tonic-gate  */
397c478bd9Sstevel@tonic-gate #include <sys/types.h>
404870e0a7SRichard PALO #include <sys/null.h>
417c478bd9Sstevel@tonic-gate #include <gelf.h>
437c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
447c478bd9Sstevel@tonic-gate extern "C" {
457c478bd9Sstevel@tonic-gate #endif
477c478bd9Sstevel@tonic-gate /*
484870e0a7SRichard PALO  * Make sure that TRUE, FALSE, MIN, and MAX have the usual definitions
497c478bd9Sstevel@tonic-gate  * so module writers can depend on these macros and defines.
504870e0a7SRichard PALO  * Make sure NULL is available to module writers by including <sys/null.h>.
517c478bd9Sstevel@tonic-gate  */
537c478bd9Sstevel@tonic-gate #ifndef TRUE
547c478bd9Sstevel@tonic-gate #define	TRUE	1
557c478bd9Sstevel@tonic-gate #endif
577c478bd9Sstevel@tonic-gate #ifndef FALSE
587c478bd9Sstevel@tonic-gate #define	FALSE	0
597c478bd9Sstevel@tonic-gate #endif
617c478bd9Sstevel@tonic-gate #ifndef MIN
627c478bd9Sstevel@tonic-gate #define	MIN(x, y) ((x) < (y) ? (x) : (y))
637c478bd9Sstevel@tonic-gate #endif
657c478bd9Sstevel@tonic-gate #ifndef MAX
667c478bd9Sstevel@tonic-gate #define	MAX(x, y) ((x) > (y) ? (x) : (y))
677c478bd9Sstevel@tonic-gate #endif
69d70f65dfSToomas Soome #define	MDB_API_VERSION	5	/* Current API version number */
717c478bd9Sstevel@tonic-gate /*
727c478bd9Sstevel@tonic-gate  * Debugger command function flags:
737c478bd9Sstevel@tonic-gate  */
747c478bd9Sstevel@tonic-gate #define	DCMD_ADDRSPEC	0x01	/* Dcmd invoked with explicit address */
757c478bd9Sstevel@tonic-gate #define	DCMD_LOOP	0x02	/* Dcmd invoked in loop with ,cnt syntax */
767c478bd9Sstevel@tonic-gate #define	DCMD_LOOPFIRST	0x04	/* Dcmd invoked as first iteration of LOOP */
777c478bd9Sstevel@tonic-gate #define	DCMD_PIPE	0x08	/* Dcmd invoked with input from pipe */
787c478bd9Sstevel@tonic-gate #define	DCMD_PIPE_OUT	0x10	/* Dcmd invoked with output set to pipe */
807c478bd9Sstevel@tonic-gate #define	DCMD_HDRSPEC(fl)	(((fl) & DCMD_LOOPFIRST) || !((fl) & DCMD_LOOP))
823b6e0a59SMatt Amdur /*
833b6e0a59SMatt Amdur  * Debugger tab command function flags
843b6e0a59SMatt Amdur  */
853b6e0a59SMatt Amdur #define	DCMD_TAB_SPACE	0x01	/* Tab cb invoked with trailing space */
863b6e0a59SMatt Amdur 
877c478bd9Sstevel@tonic-gate /*
887c478bd9Sstevel@tonic-gate  * Debugger command function return values:
897c478bd9Sstevel@tonic-gate  */
907c478bd9Sstevel@tonic-gate #define	DCMD_OK		0	/* Dcmd completed successfully */
917c478bd9Sstevel@tonic-gate #define	DCMD_ERR	1	/* Dcmd failed due to an error */
927c478bd9Sstevel@tonic-gate #define	DCMD_USAGE	2	/* Dcmd usage error; abort and print usage */
937c478bd9Sstevel@tonic-gate #define	DCMD_NEXT	3	/* Invoke next dcmd in precedence list */
947c478bd9Sstevel@tonic-gate #define	DCMD_ABORT	4	/* Dcmd failed; abort current loop or pipe */
967c478bd9Sstevel@tonic-gate #define	OFFSETOF(s, m)		(size_t)(&(((s *)0)->m))
987c478bd9Sstevel@tonic-gate extern int mdb_prop_postmortem;	/* Are we looking at a static dump? */
997c478bd9Sstevel@tonic-gate extern int mdb_prop_kernel;	/* Are we looking at a kernel? */
1017c478bd9Sstevel@tonic-gate typedef enum {
1027c478bd9Sstevel@tonic-gate 	MDB_TYPE_STRING,	/* a_un.a_str is valid */
1037c478bd9Sstevel@tonic-gate 	MDB_TYPE_IMMEDIATE,	/* a_un.a_val is valid */
1047c478bd9Sstevel@tonic-gate 	MDB_TYPE_CHAR		/* a_un.a_char is valid */
1057c478bd9Sstevel@tonic-gate } mdb_type_t;
1077c478bd9Sstevel@tonic-gate typedef struct mdb_arg {
1087c478bd9Sstevel@tonic-gate 	mdb_type_t a_type;
1097c478bd9Sstevel@tonic-gate 	union {
1107c478bd9Sstevel@tonic-gate 		const char *a_str;
1117c478bd9Sstevel@tonic-gate 		uintmax_t a_val;
1127c478bd9Sstevel@tonic-gate 		char a_char;
1137c478bd9Sstevel@tonic-gate 	} a_un;
1147c478bd9Sstevel@tonic-gate } mdb_arg_t;
1163b6e0a59SMatt Amdur typedef struct mdb_tab_cookie mdb_tab_cookie_t;
1177c478bd9Sstevel@tonic-gate typedef int mdb_dcmd_f(uintptr_t, uint_t, int, const mdb_arg_t *);
1183b6e0a59SMatt Amdur typedef int mdb_dcmd_tab_f(mdb_tab_cookie_t *, uint_t, int,
1193b6e0a59SMatt Amdur     const mdb_arg_t *);
1217c478bd9Sstevel@tonic-gate typedef struct mdb_dcmd {
1227c478bd9Sstevel@tonic-gate 	const char *dc_name;		/* Command name */
1237c478bd9Sstevel@tonic-gate 	const char *dc_usage;		/* Usage message (optional) */
1247c478bd9Sstevel@tonic-gate 	const char *dc_descr;		/* Description */
1257c478bd9Sstevel@tonic-gate 	mdb_dcmd_f *dc_funcp;		/* Command function */
1267c478bd9Sstevel@tonic-gate 	void (*dc_help)(void);		/* Command help function (or NULL) */
1273b6e0a59SMatt Amdur 	mdb_dcmd_tab_f *dc_tabp;	/* Tab completion function */
1287c478bd9Sstevel@tonic-gate } mdb_dcmd_t;
1307c478bd9Sstevel@tonic-gate #define	WALK_ERR	-1		/* Walk fatal error (terminate walk) */
1317c478bd9Sstevel@tonic-gate #define	WALK_NEXT	0		/* Walk should continue to next step */
1327c478bd9Sstevel@tonic-gate #define	WALK_DONE	1		/* Walk is complete (no errors) */
1347c478bd9Sstevel@tonic-gate typedef int (*mdb_walk_cb_t)(uintptr_t, const void *, void *);
1367c478bd9Sstevel@tonic-gate typedef struct mdb_walk_state {
1377c478bd9Sstevel@tonic-gate 	mdb_walk_cb_t walk_callback;	/* Callback to issue */
1387c478bd9Sstevel@tonic-gate 	void *walk_cbdata;		/* Callback private data */
1397c478bd9Sstevel@tonic-gate 	uintptr_t walk_addr;		/* Current address */
1407c478bd9Sstevel@tonic-gate 	void *walk_data;		/* Walk private data */
1417c478bd9Sstevel@tonic-gate 	void *walk_arg;			/* Walk private argument */
1427c478bd9Sstevel@tonic-gate 	const void *walk_layer;		/* Data from underlying layer */
1437c478bd9Sstevel@tonic-gate } mdb_walk_state_t;
1457c478bd9Sstevel@tonic-gate typedef struct mdb_walker {
1467c478bd9Sstevel@tonic-gate 	const char *walk_name;		/* Walk type name */
1477c478bd9Sstevel@tonic-gate 	const char *walk_descr;		/* Walk description */
1487c478bd9Sstevel@tonic-gate 	int (*walk_init)(mdb_walk_state_t *);	/* Walk constructor */
1497c478bd9Sstevel@tonic-gate 	int (*walk_step)(mdb_walk_state_t *);	/* Walk iterator */
1507c478bd9Sstevel@tonic-gate 	void (*walk_fini)(mdb_walk_state_t *);	/* Walk destructor */
1517c478bd9Sstevel@tonic-gate 	void *walk_init_arg;		/* Walk constructor argument */
1527c478bd9Sstevel@tonic-gate } mdb_walker_t;
1547c478bd9Sstevel@tonic-gate typedef struct mdb_modinfo {
1557c478bd9Sstevel@tonic-gate 	ushort_t mi_dvers;		/* Debugger version number */
1567c478bd9Sstevel@tonic-gate 	const mdb_dcmd_t *mi_dcmds;	/* NULL-terminated list of dcmds */
1577c478bd9Sstevel@tonic-gate 	const mdb_walker_t *mi_walkers;	/* NULL-terminated list of walks */
1587c478bd9Sstevel@tonic-gate } mdb_modinfo_t;
1607c478bd9Sstevel@tonic-gate typedef struct mdb_bitmask {
1617c478bd9Sstevel@tonic-gate 	const char *bm_name;		/* String name to print */
1627c478bd9Sstevel@tonic-gate 	u_longlong_t bm_mask;		/* Mask for bits */
1637c478bd9Sstevel@tonic-gate 	u_longlong_t bm_bits;		/* Result required for value & mask */
1647c478bd9Sstevel@tonic-gate } mdb_bitmask_t;
1667c478bd9Sstevel@tonic-gate typedef struct mdb_pipe {
1677c478bd9Sstevel@tonic-gate 	uintptr_t *pipe_data;		/* Array of pipe values */
1687c478bd9Sstevel@tonic-gate 	size_t pipe_len;		/* Array length */
1697c478bd9Sstevel@tonic-gate } mdb_pipe_t;
171c9a6ea2eSBryan Cantrill typedef struct mdb_object {
172c9a6ea2eSBryan Cantrill 	const char *obj_name;		/* name of object */
173c9a6ea2eSBryan Cantrill 	const char *obj_fullname;	/* full name of object */
174c9a6ea2eSBryan Cantrill 	uintptr_t obj_base;		/* base address of object */
175c9a6ea2eSBryan Cantrill 	uintptr_t obj_size;		/* in memory size of object in bytes */
176c9a6ea2eSBryan Cantrill } mdb_object_t;
177c9a6ea2eSBryan Cantrill 
178ac58c5dbSDave Pacheco typedef struct mdb_symbol {
179ac58c5dbSDave Pacheco 	const char *sym_name;		/* name of symbol */
180ac58c5dbSDave Pacheco 	const char *sym_object;		/* name of containing object */
181ac58c5dbSDave Pacheco 	const GElf_Sym *sym_sym;	/* ELF symbol information */
182ac58c5dbSDave Pacheco 	uint_t sym_table;		/* symbol table id */
183ac58c5dbSDave Pacheco 	uint_t sym_id;			/* symbol identifier */
184ac58c5dbSDave Pacheco } mdb_symbol_t;
185ac58c5dbSDave Pacheco 
1867c478bd9Sstevel@tonic-gate extern int mdb_pwalk(const char *, mdb_walk_cb_t, void *, uintptr_t);
1877c478bd9Sstevel@tonic-gate extern int mdb_walk(const char *, mdb_walk_cb_t, void *);
1897c478bd9Sstevel@tonic-gate extern int mdb_pwalk_dcmd(const char *, const char *,
1907c478bd9Sstevel@tonic-gate 	int, const mdb_arg_t *, uintptr_t);
1927c478bd9Sstevel@tonic-gate extern int mdb_walk_dcmd(const char *, const char *, int, const mdb_arg_t *);
1947c478bd9Sstevel@tonic-gate extern int mdb_layered_walk(const char *, mdb_walk_state_t *);
1967c478bd9Sstevel@tonic-gate extern int mdb_call_dcmd(const char *, uintptr_t,
1977c478bd9Sstevel@tonic-gate 	uint_t, int, const mdb_arg_t *);
1997c478bd9Sstevel@tonic-gate extern int mdb_add_walker(const mdb_walker_t *);
2007c478bd9Sstevel@tonic-gate extern int mdb_remove_walker(const char *);
2027c478bd9Sstevel@tonic-gate extern ssize_t mdb_vread(void *, size_t, uintptr_t);
2037c478bd9Sstevel@tonic-gate extern ssize_t mdb_vwrite(const void *, size_t, uintptr_t);
2052a12f85aSJeremy Jones extern ssize_t mdb_aread(void *, size_t, uintptr_t, void *);
2062a12f85aSJeremy Jones extern ssize_t mdb_awrite(const void *, size_t, uintptr_t, void *);
2072a12f85aSJeremy Jones 
2087c478bd9Sstevel@tonic-gate extern ssize_t mdb_fread(void *, size_t, uintptr_t);
2097c478bd9Sstevel@tonic-gate extern ssize_t mdb_fwrite(const void *, size_t, uintptr_t);
2117c478bd9Sstevel@tonic-gate extern ssize_t mdb_pread(void *, size_t, uint64_t);
2127c478bd9Sstevel@tonic-gate extern ssize_t mdb_pwrite(const void *, size_t, uint64_t);
2147c478bd9Sstevel@tonic-gate extern ssize_t mdb_readstr(char *, size_t, uintptr_t);
2157c478bd9Sstevel@tonic-gate extern ssize_t mdb_writestr(const char *, uintptr_t);
2177c478bd9Sstevel@tonic-gate extern ssize_t mdb_readsym(void *, size_t, const char *);
2187c478bd9Sstevel@tonic-gate extern ssize_t mdb_writesym(const void *, size_t, const char *);
2207c478bd9Sstevel@tonic-gate extern ssize_t mdb_readvar(void *, const char *);
2217c478bd9Sstevel@tonic-gate extern ssize_t mdb_writevar(const void *, const char *);
2237c478bd9Sstevel@tonic-gate #define	MDB_SYM_NAMLEN	1024			/* Recommended max name len */
2257c478bd9Sstevel@tonic-gate #define	MDB_SYM_FUZZY	0			/* Match closest address */
2267c478bd9Sstevel@tonic-gate #define	MDB_SYM_EXACT	1			/* Match exact address only */
2287c478bd9Sstevel@tonic-gate #define	MDB_OBJ_EXEC	((const char *)0L)	/* Primary executable file */
2297c478bd9Sstevel@tonic-gate #define	MDB_OBJ_RTLD	((const char *)1L)	/* Run-time link-editor */
2307c478bd9Sstevel@tonic-gate #define	MDB_OBJ_EVERY	((const char *)-1L)	/* All known symbols */
2327c478bd9Sstevel@tonic-gate extern int mdb_lookup_by_name(const char *, GElf_Sym *);
2337c478bd9Sstevel@tonic-gate extern int mdb_lookup_by_obj(const char *, const char *, GElf_Sym *);
2347c478bd9Sstevel@tonic-gate extern int mdb_lookup_by_addr(uintptr_t, uint_t, char *, size_t, GElf_Sym *);
236c9a6ea2eSBryan Cantrill typedef uintptr_t mdb_tid_t;
237c9a6ea2eSBryan Cantrill typedef uint64_t mdb_reg_t;
238c9a6ea2eSBryan Cantrill 
239c9a6ea2eSBryan Cantrill extern int mdb_getareg(mdb_tid_t, const char *, mdb_reg_t *);
240c9a6ea2eSBryan Cantrill 
2417c478bd9Sstevel@tonic-gate #define	MDB_OPT_SETBITS	1			/* Set specified flag bits */
2427c478bd9Sstevel@tonic-gate #define	MDB_OPT_CLRBITS	2			/* Clear specified flag bits */
2437c478bd9Sstevel@tonic-gate #define	MDB_OPT_STR	3			/* const char * argument */
2447c478bd9Sstevel@tonic-gate #define	MDB_OPT_UINTPTR	4			/* uintptr_t argument */
2457c478bd9Sstevel@tonic-gate #define	MDB_OPT_UINT64	5			/* uint64_t argument */
2467c478bd9Sstevel@tonic-gate #define	MDB_OPT_UINTPTR_SET	6		/* boolean_t+uintptr_t args */
248*3b442230SJordan Paige Hendricks extern int mdb_getopts(int, const mdb_arg_t *, ...) __sentinel(0);
2507c478bd9Sstevel@tonic-gate extern u_longlong_t mdb_strtoull(const char *);
2527c478bd9Sstevel@tonic-gate #define	UM_NOSLEEP	0x0	/* Do not call failure handler; may fail */
2537c478bd9Sstevel@tonic-gate #define	UM_SLEEP	0x1	/* Can block for memory; will always succeed */
2547c478bd9Sstevel@tonic-gate #define	UM_GC		0x2	/* Garbage-collect this block automatically */
2567c478bd9Sstevel@tonic-gate extern void *mdb_alloc(size_t, uint_t);
2577c478bd9Sstevel@tonic-gate extern void *mdb_zalloc(size_t, uint_t);
2587c478bd9Sstevel@tonic-gate extern void mdb_free(void *, size_t);
260d70f65dfSToomas Soome #define	MDB_NICENUM_BUFLEN 6
261d70f65dfSToomas Soome 
262d70f65dfSToomas Soome extern int mdb_snprintfrac(char *, int, uint64_t, uint64_t, int);
263d70f65dfSToomas Soome extern void mdb_nicenum(uint64_t, char *);
264d70f65dfSToomas Soome 
2657c478bd9Sstevel@tonic-gate extern size_t mdb_snprintf(char *, size_t, const char *, ...);
2667c478bd9Sstevel@tonic-gate extern void mdb_printf(const char *, ...);
2677c478bd9Sstevel@tonic-gate extern void mdb_warn(const char *, ...);
2687c478bd9Sstevel@tonic-gate extern void mdb_flush(void);
27069bb4bb4Scarlsonj extern int mdb_ffs(uintmax_t);
2727c478bd9Sstevel@tonic-gate extern void mdb_nhconvert(void *, const void *, size_t);
2747c478bd9Sstevel@tonic-gate #define	MDB_DUMP_RELATIVE	0x0001	/* Start numbering at 0 */
2757c478bd9Sstevel@tonic-gate #define	MDB_DUMP_ALIGN		0x0002	/* Enforce paragraph alignment */
2767c478bd9Sstevel@tonic-gate #define	MDB_DUMP_PEDANT		0x0004	/* Full-width addresses */
2777c478bd9Sstevel@tonic-gate #define	MDB_DUMP_ASCII		0x0008	/* Display ASCII values */
2787c478bd9Sstevel@tonic-gate #define	MDB_DUMP_HEADER		0x0010	/* Display a header */
2797c478bd9Sstevel@tonic-gate #define	MDB_DUMP_TRIM		0x0020	/* Trim at boundaries */
2807c478bd9Sstevel@tonic-gate #define	MDB_DUMP_SQUISH		0x0040	/* Eliminate redundant lines */
2817c478bd9Sstevel@tonic-gate #define	MDB_DUMP_NEWDOT		0x0080	/* Update dot when done */
2827c478bd9Sstevel@tonic-gate #define	MDB_DUMP_ENDIAN		0x0100	/* Adjust for endianness */
2837c478bd9Sstevel@tonic-gate #define	MDB_DUMP_WIDTH(x)	((((x) - 1) & 0xf) << 16) /* paragraphs/line */
2847c478bd9Sstevel@tonic-gate #define	MDB_DUMP_GROUP(x)	((((x) - 1) & 0xff) << 20) /* bytes/group */
2867c478bd9Sstevel@tonic-gate typedef ssize_t (*mdb_dumpptr_cb_t)(void *, size_t, uintptr_t, void *);
2877c478bd9Sstevel@tonic-gate typedef ssize_t (*mdb_dump64_cb_t)(void *, size_t, uint64_t, void *);
2897c478bd9Sstevel@tonic-gate extern int mdb_dumpptr(uintptr_t, size_t, uint_t, mdb_dumpptr_cb_t, void *);
2907c478bd9Sstevel@tonic-gate extern int mdb_dump64(uint64_t, uint64_t, uint_t, mdb_dump64_cb_t, void *);
2927c478bd9Sstevel@tonic-gate extern const char *mdb_one_bit(int, int, int);
2937c478bd9Sstevel@tonic-gate extern const char *mdb_inval_bits(int, int, int);
2957c478bd9Sstevel@tonic-gate extern ulong_t mdb_inc_indent(ulong_t);
2967c478bd9Sstevel@tonic-gate extern ulong_t mdb_dec_indent(ulong_t);
2987c478bd9Sstevel@tonic-gate extern int mdb_eval(const char *);
2997c478bd9Sstevel@tonic-gate extern void mdb_set_dot(uintmax_t);
3007c478bd9Sstevel@tonic-gate extern uintmax_t mdb_get_dot(void);
3027c478bd9Sstevel@tonic-gate extern void mdb_get_pipe(mdb_pipe_t *);
3037c478bd9Sstevel@tonic-gate extern void mdb_set_pipe(const mdb_pipe_t *);
3057c478bd9Sstevel@tonic-gate extern ssize_t mdb_get_xdata(const char *, void *, size_t);
307c9a6ea2eSBryan Cantrill typedef int (*mdb_object_cb_t)(mdb_object_t *, void *);
308c9a6ea2eSBryan Cantrill extern int mdb_object_iter(mdb_object_cb_t, void *);
309c9a6ea2eSBryan Cantrill 
310ac58c5dbSDave Pacheco #define	MDB_SYMTAB		1	/* Normal symbol table (.symtab) */
311ac58c5dbSDave Pacheco #define	MDB_DYNSYM		2	/* Dynamic symbol table (.dynsym) */
312ac58c5dbSDave Pacheco 
313ac58c5dbSDave Pacheco #define	MDB_BIND_LOCAL		0x0001	/* Local (static-scope) symbols */
314ac58c5dbSDave Pacheco #define	MDB_BIND_GLOBAL		0x0002	/* Global symbols */
315ac58c5dbSDave Pacheco #define	MDB_BIND_WEAK		0x0004	/* Weak binding symbols */
316ac58c5dbSDave Pacheco #define	MDB_BIND_ANY		0x0007	/* Any of the above */
317ac58c5dbSDave Pacheco 
318ac58c5dbSDave Pacheco #define	MDB_TYPE_NOTYPE		0x0100	/* Symbol has no type */
319ac58c5dbSDave Pacheco #define	MDB_TYPE_OBJECT		0x0200	/* Symbol refers to data */
320ac58c5dbSDave Pacheco #define	MDB_TYPE_FUNC		0x0400	/* Symbol refers to text */
321ac58c5dbSDave Pacheco #define	MDB_TYPE_SECT		0x0800	/* Symbol refers to a section */
322ac58c5dbSDave Pacheco #define	MDB_TYPE_FILE		0x1000	/* Symbol refers to a source file */
323ac58c5dbSDave Pacheco #define	MDB_TYPE_COMMON		0x2000	/* Symbol refers to a common block */
324ac58c5dbSDave Pacheco #define	MDB_TYPE_TLS		0x4000	/* Symbol refers to TLS */
325ac58c5dbSDave Pacheco 
326ac58c5dbSDave Pacheco #define	MDB_TYPE_ANY		0x7f00	/* Any of the above */
327ac58c5dbSDave Pacheco 
328ac58c5dbSDave Pacheco typedef int (*mdb_symbol_cb_t)(mdb_symbol_t *, void *);
329ac58c5dbSDave Pacheco extern int mdb_symbol_iter(const char *, uint_t, uint_t, mdb_symbol_cb_t,
330ac58c5dbSDave Pacheco     void *);
331ac58c5dbSDave Pacheco 
3327c478bd9Sstevel@tonic-gate #define	MDB_STATE_IDLE		0	/* Target is idle (not running yet) */
3337c478bd9Sstevel@tonic-gate #define	MDB_STATE_RUNNING	1	/* Target is currently executing */
3347c478bd9Sstevel@tonic-gate #define	MDB_STATE_STOPPED	2	/* Target is stopped */
3357c478bd9Sstevel@tonic-gate #define	MDB_STATE_UNDEAD	3	/* Target is undead (zombie) */
3367c478bd9Sstevel@tonic-gate #define	MDB_STATE_DEAD		4	/* Target is dead (core dump) */
3377c478bd9Sstevel@tonic-gate #define	MDB_STATE_LOST		5	/* Target lost by debugger */
3397c478bd9Sstevel@tonic-gate extern int mdb_get_state(void);
3417c478bd9Sstevel@tonic-gate #define	MDB_CALLBACK_STCHG	1
3427c478bd9Sstevel@tonic-gate #define	MDB_CALLBACK_PROMPT	2
3447c478bd9Sstevel@tonic-gate typedef void (*mdb_callback_f)(void *);
3467c478bd9Sstevel@tonic-gate extern void *mdb_callback_add(int, mdb_callback_f, void *);
3477c478bd9Sstevel@tonic-gate extern void mdb_callback_remove(void *);
3493b6e0a59SMatt Amdur #define	MDB_TABC_ALL_TYPES	0x1	/* Include array types in type output */
3503b6e0a59SMatt Amdur #define	MDB_TABC_MEMBERS	0x2	/* Tab comp. types with members */
3513b6e0a59SMatt Amdur #define	MDB_TABC_NOPOINT	0x4	/* Tab comp. everything but pointers */
3523b6e0a59SMatt Amdur #define	MDB_TABC_NOARRAY	0x8	/* Don't include array data in output */
3533b6e0a59SMatt Amdur 
3543b6e0a59SMatt Amdur /*
3553b6e0a59SMatt Amdur  * Module's interaction path
3563b6e0a59SMatt Amdur  */
3573b6e0a59SMatt Amdur extern void mdb_tab_insert(mdb_tab_cookie_t *, const char *);
3583b6e0a59SMatt Amdur extern void mdb_tab_setmbase(mdb_tab_cookie_t *, const char *);
3593b6e0a59SMatt Amdur 
3603b6e0a59SMatt Amdur /*
3613b6e0a59SMatt Amdur  * Tab completion utility functions for modules.
3623b6e0a59SMatt Amdur  */
3633b6e0a59SMatt Amdur extern int mdb_tab_complete_type(mdb_tab_cookie_t *, const char *, uint_t);
3643b6e0a59SMatt Amdur extern int mdb_tab_complete_member(mdb_tab_cookie_t *, const char *,
3653b6e0a59SMatt Amdur     const char *);
3663b6e0a59SMatt Amdur extern int mdb_tab_typename(int *, const mdb_arg_t **, char *buf, size_t len);
3673b6e0a59SMatt Amdur 
3683b6e0a59SMatt Amdur /*
3693b6e0a59SMatt Amdur  * Tab completion functions for common signatures.
3703b6e0a59SMatt Amdur  */
3713b6e0a59SMatt Amdur extern int mdb_tab_complete_mt(mdb_tab_cookie_t *, uint_t, int,
3723b6e0a59SMatt Amdur     const mdb_arg_t *);
3733b6e0a59SMatt Amdur 
374dc0093f4Seschrock extern size_t strlcat(char *, const char *, size_t);
3757c478bd9Sstevel@tonic-gate extern char *strcat(char *, const char *);
3767c478bd9Sstevel@tonic-gate extern char *strcpy(char *, const char *);
3777c478bd9Sstevel@tonic-gate extern char *strncpy(char *, const char *, size_t);
3797c478bd9Sstevel@tonic-gate /* Need to be consistent with <string.h> C++ definitions */
3807c478bd9Sstevel@tonic-gate #if __cplusplus >= 199711L
3817c478bd9Sstevel@tonic-gate extern const char *strchr(const char *, int);
3827c478bd9Sstevel@tonic-gate #ifndef	_STRCHR_INLINE
3837c478bd9Sstevel@tonic-gate #define	_STRCHR_INLINE
3847c478bd9Sstevel@tonic-gate extern "C++" {
strchr(char * __s,int __c)3857c478bd9Sstevel@tonic-gate 	inline char *strchr(char *__s, int __c) {
3867c478bd9Sstevel@tonic-gate 		return (char *)strchr((const char *)__s, __c);
3877c478bd9Sstevel@tonic-gate 	}
3887c478bd9Sstevel@tonic-gate }
3897c478bd9Sstevel@tonic-gate #endif	/* _STRCHR_INLINE */
3907c478bd9Sstevel@tonic-gate extern const char *strrchr(const char *, int);
3917c478bd9Sstevel@tonic-gate #ifndef	_STRRCHR_INLINE
3927c478bd9Sstevel@tonic-gate #define	_STRRCHR_INLINE
3937c478bd9Sstevel@tonic-gate extern	"C++" {
strrchr(char * __s,int __c)3947c478bd9Sstevel@tonic-gate 	inline char *strrchr(char *__s, int __c) {
3957c478bd9Sstevel@tonic-gate 		return (char *)strrchr((const char *)__s, __c);
3967c478bd9Sstevel@tonic-gate 	}
3977c478bd9Sstevel@tonic-gate }
3987c478bd9Sstevel@tonic-gate #endif	/* _STRRCHR_INLINE */
3997c478bd9Sstevel@tonic-gate extern const char *strstr(const char *, const char *);
4007c478bd9Sstevel@tonic-gate #ifndef	_STRSTR_INLINE
4017c478bd9Sstevel@tonic-gate #define	_STRSTR_INLINE
4027c478bd9Sstevel@tonic-gate extern "C++" {
strstr(char * __s1,const char * __s2)4037c478bd9Sstevel@tonic-gate 	inline char *strstr(char *__s1, const char *__s2) {
4047c478bd9Sstevel@tonic-gate 		return (char *)strstr((const char *)__s1, __s2);
4057c478bd9Sstevel@tonic-gate 	}
4067c478bd9Sstevel@tonic-gate }
4077c478bd9Sstevel@tonic-gate #endif	/* _STRSTR_INLINE */
4087c478bd9Sstevel@tonic-gate #else
4097c478bd9Sstevel@tonic-gate extern char *strchr(const char *, int);
4107c478bd9Sstevel@tonic-gate extern char *strrchr(const char *, int);
4117c478bd9Sstevel@tonic-gate extern char *strstr(const char *, const char *);
4127c478bd9Sstevel@tonic-gate #endif	/* __cplusplus >= 199711L */
4147c478bd9Sstevel@tonic-gate extern int strcmp(const char *, const char *);
4157c478bd9Sstevel@tonic-gate extern int strncmp(const char *, const char *, size_t);
4167c478bd9Sstevel@tonic-gate extern int strcasecmp(const char *, const char *);
4177c478bd9Sstevel@tonic-gate extern int strncasecmp(const char *, const char *, size_t);
4197c478bd9Sstevel@tonic-gate extern size_t strlen(const char *);
4217c478bd9Sstevel@tonic-gate extern int bcmp(const void *, const void *, size_t);
4227c478bd9Sstevel@tonic-gate extern void bcopy(const void *, void *, size_t);
4237c478bd9Sstevel@tonic-gate extern void bzero(void *, size_t);
4257c478bd9Sstevel@tonic-gate extern void *memcpy(void *, const void *, size_t);
4267c478bd9Sstevel@tonic-gate extern void *memmove(void *, const void *, size_t);
4277c478bd9Sstevel@tonic-gate extern int memcmp(const void *, const void *, size_t);
4287c478bd9Sstevel@tonic-gate /* Need to be consistent with <string.h> C++ definitions */
4297c478bd9Sstevel@tonic-gate #if __cplusplus >= 199711L
4307c478bd9Sstevel@tonic-gate extern const void *memchr(const void *, int, size_t);
4317c478bd9Sstevel@tonic-gate #ifndef _MEMCHR_INLINE
4327c478bd9Sstevel@tonic-gate #define	_MEMCHR_INLINE
4337c478bd9Sstevel@tonic-gate extern "C++" {
memchr(void * __s,int __c,size_t __n)4347c478bd9Sstevel@tonic-gate 	inline void *memchr(void * __s, int __c, size_t __n) {
4357c478bd9Sstevel@tonic-gate 		return (void *)memchr((const void *)__s, __c, __n);
4367c478bd9Sstevel@tonic-gate 	}
4377c478bd9Sstevel@tonic-gate }
4387c478bd9Sstevel@tonic-gate #endif  /* _MEMCHR_INLINE */
4397c478bd9Sstevel@tonic-gate #else
4407c478bd9Sstevel@tonic-gate extern void *memchr(const void *, int, size_t);
4417c478bd9Sstevel@tonic-gate #endif /* __cplusplus >= 199711L */
4427c478bd9Sstevel@tonic-gate extern void *memset(void *, int, size_t);
4437c478bd9Sstevel@tonic-gate extern void *memccpy(void *, const void *, int, size_t);
4457c478bd9Sstevel@tonic-gate extern void *bsearch(const void *, const void *, size_t, size_t,
4467c478bd9Sstevel@tonic-gate     int (*)(const void *, const void *));
4487c478bd9Sstevel@tonic-gate extern void qsort(void *, size_t, size_t,
4497c478bd9Sstevel@tonic-gate     int (*)(const void *, const void *));
4517c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
4527c478bd9Sstevel@tonic-gate }
4537c478bd9Sstevel@tonic-gate #endif
4557c478bd9Sstevel@tonic-gate #endif	/* _MDB_MODAPI_H */