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