xref: /illumos-gate/usr/src/cmd/mdb/common/mdb/mdb_nm.c (revision 24537d3e)
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
5659d8689SEdward Pilatowicz  * Common Development and Distribution License (the "License").
6659d8689SEdward Pilatowicz  * 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  */
217c478bd9Sstevel@tonic-gate /*
22659d8689SEdward Pilatowicz  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
26d75f3745SJohn Levon /*
27d75f3745SJohn Levon  * Copyright (c) 2018, Joyent, Inc.
28d75f3745SJohn Levon  */
29d75f3745SJohn Levon 
307c478bd9Sstevel@tonic-gate #include <sys/elf.h>
317c478bd9Sstevel@tonic-gate #include <sys/elf_SPARC.h>
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #include <libproc.h>
347c478bd9Sstevel@tonic-gate #include <libctf.h>
357c478bd9Sstevel@tonic-gate #include <stdlib.h>
367c478bd9Sstevel@tonic-gate #include <string.h>
377c478bd9Sstevel@tonic-gate #include <fcntl.h>
387c478bd9Sstevel@tonic-gate #include <errno.h>
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate #include <mdb/mdb_string.h>
417c478bd9Sstevel@tonic-gate #include <mdb/mdb_argvec.h>
427c478bd9Sstevel@tonic-gate #include <mdb/mdb_nv.h>
437c478bd9Sstevel@tonic-gate #include <mdb/mdb_fmt.h>
447c478bd9Sstevel@tonic-gate #include <mdb/mdb_target.h>
457c478bd9Sstevel@tonic-gate #include <mdb/mdb_err.h>
467c478bd9Sstevel@tonic-gate #include <mdb/mdb_debug.h>
477c478bd9Sstevel@tonic-gate #include <mdb/mdb_conf.h>
487c478bd9Sstevel@tonic-gate #include <mdb/mdb_module.h>
497c478bd9Sstevel@tonic-gate #include <mdb/mdb_modapi.h>
507c478bd9Sstevel@tonic-gate #include <mdb/mdb_stdlib.h>
517c478bd9Sstevel@tonic-gate #include <mdb/mdb_lex.h>
527c478bd9Sstevel@tonic-gate #include <mdb/mdb_io_impl.h>
537c478bd9Sstevel@tonic-gate #include <mdb/mdb_help.h>
547c478bd9Sstevel@tonic-gate #include <mdb/mdb_disasm.h>
557c478bd9Sstevel@tonic-gate #include <mdb/mdb_frame.h>
567c478bd9Sstevel@tonic-gate #include <mdb/mdb_evset.h>
577c478bd9Sstevel@tonic-gate #include <mdb/mdb_print.h>
587c478bd9Sstevel@tonic-gate #include <mdb/mdb_nm.h>
597c478bd9Sstevel@tonic-gate #include <mdb/mdb_set.h>
607c478bd9Sstevel@tonic-gate #include <mdb/mdb_demangle.h>
617c478bd9Sstevel@tonic-gate #include <mdb/mdb.h>
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate enum {
647c478bd9Sstevel@tonic-gate 	NM_FMT_INDEX	= 0x0001,			/* -f ndx */
657c478bd9Sstevel@tonic-gate 	NM_FMT_VALUE	= 0x0002,			/* -f val */
667c478bd9Sstevel@tonic-gate 	NM_FMT_SIZE	= 0x0004,			/* -f size */
677c478bd9Sstevel@tonic-gate 	NM_FMT_TYPE	= 0x0008,			/* -f type */
687c478bd9Sstevel@tonic-gate 	NM_FMT_BIND	= 0x0010,			/* -f bind */
697c478bd9Sstevel@tonic-gate 	NM_FMT_OTHER	= 0x0020,			/* -f oth */
707c478bd9Sstevel@tonic-gate 	NM_FMT_SHNDX	= 0x0040,			/* -f shndx */
717c478bd9Sstevel@tonic-gate 	NM_FMT_NAME	= 0x0080,			/* -f name */
727c478bd9Sstevel@tonic-gate 	NM_FMT_CTYPE	= 0x0100,			/* -f ctype */
737c478bd9Sstevel@tonic-gate 	NM_FMT_OBJECT	= 0x0200,			/* -f obj */
747c478bd9Sstevel@tonic-gate 
757c478bd9Sstevel@tonic-gate 	NM_FMT_CTFID	= 0x1000			/* -f ctfid */
767c478bd9Sstevel@tonic-gate };
777c478bd9Sstevel@tonic-gate 
787c478bd9Sstevel@tonic-gate enum {
797c478bd9Sstevel@tonic-gate 	NM_TYPE_NOTY	= 1 << STT_NOTYPE,		/* -t noty */
807c478bd9Sstevel@tonic-gate 	NM_TYPE_OBJT	= 1 << STT_OBJECT,		/* -t objt */
817c478bd9Sstevel@tonic-gate 	NM_TYPE_FUNC	= 1 << STT_FUNC,		/* -t func */
827c478bd9Sstevel@tonic-gate 	NM_TYPE_SECT	= 1 << STT_SECTION,		/* -t sect */
837c478bd9Sstevel@tonic-gate 	NM_TYPE_FILE	= 1 << STT_FILE,		/* -t file */
847c478bd9Sstevel@tonic-gate 	NM_TYPE_COMM	= 1 << STT_COMMON,		/* -t comm */
857c478bd9Sstevel@tonic-gate 	NM_TYPE_TLS	= 1 << STT_TLS,			/* -t tls */
867c478bd9Sstevel@tonic-gate 	NM_TYPE_REGI	= 1 << STT_SPARC_REGISTER	/* -t regi */
877c478bd9Sstevel@tonic-gate };
887c478bd9Sstevel@tonic-gate 
897c478bd9Sstevel@tonic-gate typedef struct {
907c478bd9Sstevel@tonic-gate 	GElf_Sym nm_sym;
917c478bd9Sstevel@tonic-gate 	const char *nm_name;
927c478bd9Sstevel@tonic-gate 	mdb_syminfo_t nm_si;
937c478bd9Sstevel@tonic-gate 	const char *nm_object;
947c478bd9Sstevel@tonic-gate 	ctf_file_t *nm_fp;
957c478bd9Sstevel@tonic-gate } nm_sym_t;
967c478bd9Sstevel@tonic-gate 
977c478bd9Sstevel@tonic-gate typedef struct {
987c478bd9Sstevel@tonic-gate 	ctf_file_t *nii_fp;
997c478bd9Sstevel@tonic-gate 
1007c478bd9Sstevel@tonic-gate 	uint_t nii_flags;
1017c478bd9Sstevel@tonic-gate 	uint_t nii_types;
1027c478bd9Sstevel@tonic-gate 	ulong_t nii_id;
1037c478bd9Sstevel@tonic-gate 	const char *nii_pfmt;
1047c478bd9Sstevel@tonic-gate 	const char *nii_ofmt;
1057c478bd9Sstevel@tonic-gate 
1067c478bd9Sstevel@tonic-gate 	const GElf_Sym *nii_symp;
1077c478bd9Sstevel@tonic-gate 
1087c478bd9Sstevel@tonic-gate 	nm_sym_t **nii_sympp;
1097c478bd9Sstevel@tonic-gate } nm_iter_info_t;
1107c478bd9Sstevel@tonic-gate 
1117c478bd9Sstevel@tonic-gate typedef struct {
1127c478bd9Sstevel@tonic-gate 	mdb_tgt_sym_f *ngs_cb;
1137c478bd9Sstevel@tonic-gate 	void *ngs_arg;
1147c478bd9Sstevel@tonic-gate 	mdb_syminfo_t ngs_si;
1157c478bd9Sstevel@tonic-gate 	const char *ngs_object;
1167c478bd9Sstevel@tonic-gate } nm_gelf_symtab_t;
1177c478bd9Sstevel@tonic-gate 
1187c478bd9Sstevel@tonic-gate typedef struct {
1197c478bd9Sstevel@tonic-gate 	uint_t noi_which;
1207c478bd9Sstevel@tonic-gate 	uint_t noi_type;
1217c478bd9Sstevel@tonic-gate 	mdb_tgt_sym_f *noi_cb;
1227c478bd9Sstevel@tonic-gate 	nm_iter_info_t *noi_niip;
1237c478bd9Sstevel@tonic-gate } nm_object_iter_t;
1247c478bd9Sstevel@tonic-gate 
1257c478bd9Sstevel@tonic-gate static const char *
nm_type2str(uchar_t info)1267c478bd9Sstevel@tonic-gate nm_type2str(uchar_t info)
1277c478bd9Sstevel@tonic-gate {
1287c478bd9Sstevel@tonic-gate 	switch (GELF_ST_TYPE(info)) {
1297c478bd9Sstevel@tonic-gate 	case STT_NOTYPE:
1307c478bd9Sstevel@tonic-gate 		return ("NOTY");
1317c478bd9Sstevel@tonic-gate 	case STT_OBJECT:
1327c478bd9Sstevel@tonic-gate 		return ("OBJT");
1337c478bd9Sstevel@tonic-gate 	case STT_FUNC:
1347c478bd9Sstevel@tonic-gate 		return ("FUNC");
1357c478bd9Sstevel@tonic-gate 	case STT_SECTION:
1367c478bd9Sstevel@tonic-gate 		return ("SECT");
1377c478bd9Sstevel@tonic-gate 	case STT_FILE:
1387c478bd9Sstevel@tonic-gate 		return ("FILE");
1397c478bd9Sstevel@tonic-gate 	case STT_COMMON:
1407c478bd9Sstevel@tonic-gate 		return ("COMM");
1417c478bd9Sstevel@tonic-gate 	case STT_TLS:
1427c478bd9Sstevel@tonic-gate 		return ("TLS");
1437c478bd9Sstevel@tonic-gate 	case STT_SPARC_REGISTER:
1447c478bd9Sstevel@tonic-gate 		return ("REGI");
1457c478bd9Sstevel@tonic-gate 	default:
1467c478bd9Sstevel@tonic-gate 		return ("?");
1477c478bd9Sstevel@tonic-gate 	}
1487c478bd9Sstevel@tonic-gate }
1497c478bd9Sstevel@tonic-gate 
1507c478bd9Sstevel@tonic-gate static const char *
nm_bind2str(uchar_t info)1517c478bd9Sstevel@tonic-gate nm_bind2str(uchar_t info)
1527c478bd9Sstevel@tonic-gate {
1537c478bd9Sstevel@tonic-gate 	switch (GELF_ST_BIND(info)) {
1547c478bd9Sstevel@tonic-gate 	case STB_LOCAL:
1557c478bd9Sstevel@tonic-gate 		return ("LOCL");
1567c478bd9Sstevel@tonic-gate 	case STB_GLOBAL:
1577c478bd9Sstevel@tonic-gate 		return ("GLOB");
1587c478bd9Sstevel@tonic-gate 	case STB_WEAK:
1597c478bd9Sstevel@tonic-gate 		return ("WEAK");
1607c478bd9Sstevel@tonic-gate 	default:
1617c478bd9Sstevel@tonic-gate 		return ("?");
1627c478bd9Sstevel@tonic-gate 	}
1637c478bd9Sstevel@tonic-gate }
1647c478bd9Sstevel@tonic-gate 
1657c478bd9Sstevel@tonic-gate static const char *
nm_sect2str(GElf_Half shndx)1667c478bd9Sstevel@tonic-gate nm_sect2str(GElf_Half shndx)
1677c478bd9Sstevel@tonic-gate {
1687c478bd9Sstevel@tonic-gate 	static char buf[16];
1697c478bd9Sstevel@tonic-gate 
1707c478bd9Sstevel@tonic-gate 	switch (shndx) {
1717c478bd9Sstevel@tonic-gate 	case SHN_UNDEF:
1727c478bd9Sstevel@tonic-gate 		return ("UNDEF");
1737c478bd9Sstevel@tonic-gate 	case SHN_ABS:
1747c478bd9Sstevel@tonic-gate 		return ("ABS");
1757c478bd9Sstevel@tonic-gate 	case SHN_COMMON:
1767c478bd9Sstevel@tonic-gate 		return ("COMMON");
1777c478bd9Sstevel@tonic-gate 	default:
1787c478bd9Sstevel@tonic-gate 		(void) mdb_iob_snprintf(buf, sizeof (buf), "%hu", shndx);
1797c478bd9Sstevel@tonic-gate 		return (buf);
1807c478bd9Sstevel@tonic-gate 	}
1817c478bd9Sstevel@tonic-gate }
1827c478bd9Sstevel@tonic-gate 
1837c478bd9Sstevel@tonic-gate static char *
nm_func_signature(ctf_file_t * fp,uint_t index,char * buf,size_t len)1847c478bd9Sstevel@tonic-gate nm_func_signature(ctf_file_t *fp, uint_t index, char *buf, size_t len)
1857c478bd9Sstevel@tonic-gate {
1867c478bd9Sstevel@tonic-gate 	int n;
1877c478bd9Sstevel@tonic-gate 	ctf_funcinfo_t f;
1887c478bd9Sstevel@tonic-gate 	ctf_id_t argv[32];
1897c478bd9Sstevel@tonic-gate 	char arg[32];
1907c478bd9Sstevel@tonic-gate 	char *start = buf;
1917c478bd9Sstevel@tonic-gate 	char *sep = "";
1927c478bd9Sstevel@tonic-gate 	int i;
1937c478bd9Sstevel@tonic-gate 
1947c478bd9Sstevel@tonic-gate 	if (ctf_func_info(fp, index, &f) == CTF_ERR)
1957c478bd9Sstevel@tonic-gate 		return (NULL);
1967c478bd9Sstevel@tonic-gate 
1977c478bd9Sstevel@tonic-gate 	if (ctf_type_name(fp, f.ctc_return, arg, sizeof (arg)) != NULL)
1987c478bd9Sstevel@tonic-gate 		n = mdb_snprintf(buf, len, "%s (*)(", arg);
1997c478bd9Sstevel@tonic-gate 	else
2007c478bd9Sstevel@tonic-gate 		n = mdb_snprintf(buf, len, "<%ld> (*)(", f.ctc_return);
2017c478bd9Sstevel@tonic-gate 
2027c478bd9Sstevel@tonic-gate 	if (len <= n)
2037c478bd9Sstevel@tonic-gate 		return (start);
2047c478bd9Sstevel@tonic-gate 
2057c478bd9Sstevel@tonic-gate 	buf += n;
2067c478bd9Sstevel@tonic-gate 	len -= n;
2077c478bd9Sstevel@tonic-gate 
2087c478bd9Sstevel@tonic-gate 	(void) ctf_func_args(fp, index, sizeof (argv) / sizeof (argv[0]), argv);
2097c478bd9Sstevel@tonic-gate 
2107c478bd9Sstevel@tonic-gate 	for (i = 0; i < f.ctc_argc; i++) {
2117c478bd9Sstevel@tonic-gate 		if (ctf_type_name(fp, argv[i], arg, sizeof (arg)) != NULL)
2127c478bd9Sstevel@tonic-gate 			n = mdb_snprintf(buf, len, "%s%s", sep, arg);
2137c478bd9Sstevel@tonic-gate 		else
2147c478bd9Sstevel@tonic-gate 			n = mdb_snprintf(buf, len, "%s<%ld>", sep, argv[i]);
2157c478bd9Sstevel@tonic-gate 
2167c478bd9Sstevel@tonic-gate 		if (len <= n)
2177c478bd9Sstevel@tonic-gate 			return (start);
2187c478bd9Sstevel@tonic-gate 
2197c478bd9Sstevel@tonic-gate 		buf += n;
2207c478bd9Sstevel@tonic-gate 		len -= n;
2217c478bd9Sstevel@tonic-gate 
2227c478bd9Sstevel@tonic-gate 		sep = ", ";
2237c478bd9Sstevel@tonic-gate 	}
2247c478bd9Sstevel@tonic-gate 
2257c478bd9Sstevel@tonic-gate 	if (f.ctc_flags & CTF_FUNC_VARARG) {
2267c478bd9Sstevel@tonic-gate 		n = mdb_snprintf(buf, len, "%s...", sep);
2277c478bd9Sstevel@tonic-gate 		if (len <= n)
2287c478bd9Sstevel@tonic-gate 			return (start);
2297c478bd9Sstevel@tonic-gate 		buf += n;
2307c478bd9Sstevel@tonic-gate 		len -= n;
2317c478bd9Sstevel@tonic-gate 	} else if (f.ctc_argc == 0) {
2327c478bd9Sstevel@tonic-gate 		n = mdb_snprintf(buf, len, "void");
2337c478bd9Sstevel@tonic-gate 		if (len <= n)
2347c478bd9Sstevel@tonic-gate 			return (start);
2357c478bd9Sstevel@tonic-gate 		buf += n;
2367c478bd9Sstevel@tonic-gate 		len -= n;
2377c478bd9Sstevel@tonic-gate 	}
2387c478bd9Sstevel@tonic-gate 
2397c478bd9Sstevel@tonic-gate 	(void) mdb_snprintf(buf, len, ")");
2407c478bd9Sstevel@tonic-gate 
2417c478bd9Sstevel@tonic-gate 	return (start);
2427c478bd9Sstevel@tonic-gate }
2437c478bd9Sstevel@tonic-gate 
2447c478bd9Sstevel@tonic-gate static void
nm_print_ctype(void * data)2457c478bd9Sstevel@tonic-gate nm_print_ctype(void *data)
2467c478bd9Sstevel@tonic-gate {
2477c478bd9Sstevel@tonic-gate 	nm_iter_info_t *niip = data;
2487c478bd9Sstevel@tonic-gate 	char buf[256];
2497c478bd9Sstevel@tonic-gate 	ctf_id_t id;
2507c478bd9Sstevel@tonic-gate 	char *str = NULL;
2517c478bd9Sstevel@tonic-gate 	uint_t index = niip->nii_id;
2527c478bd9Sstevel@tonic-gate 	ctf_file_t *fp = niip->nii_fp;
2537c478bd9Sstevel@tonic-gate 
2547c478bd9Sstevel@tonic-gate 	if (fp != NULL) {
2557c478bd9Sstevel@tonic-gate 		if (GELF_ST_TYPE(niip->nii_symp->st_info) == STT_FUNC)
2567c478bd9Sstevel@tonic-gate 			str = nm_func_signature(fp, index, buf, sizeof (buf));
2577c478bd9Sstevel@tonic-gate 		else if ((id = ctf_lookup_by_symbol(fp, index)) != CTF_ERR)
2587c478bd9Sstevel@tonic-gate 			str = ctf_type_name(fp, id, buf, sizeof (buf));
2597c478bd9Sstevel@tonic-gate 	}
2607c478bd9Sstevel@tonic-gate 
2617c478bd9Sstevel@tonic-gate 	if (str == NULL)
2627c478bd9Sstevel@tonic-gate 		str = "<unknown type>";
2637c478bd9Sstevel@tonic-gate 
2647c478bd9Sstevel@tonic-gate 	mdb_printf("%-50s", str);
2657c478bd9Sstevel@tonic-gate }
2667c478bd9Sstevel@tonic-gate 
2677c478bd9Sstevel@tonic-gate static void
nm_print_ctfid(void * data)2687c478bd9Sstevel@tonic-gate nm_print_ctfid(void *data)
2697c478bd9Sstevel@tonic-gate {
2707c478bd9Sstevel@tonic-gate 	nm_iter_info_t *niip = data;
2717c478bd9Sstevel@tonic-gate 	ctf_id_t id;
2727c478bd9Sstevel@tonic-gate 	uint_t index = niip->nii_id;
2737c478bd9Sstevel@tonic-gate 	ctf_file_t *fp = niip->nii_fp;
2747c478bd9Sstevel@tonic-gate 
2757c478bd9Sstevel@tonic-gate 	if (fp != NULL && (id = ctf_lookup_by_symbol(fp, index)) != CTF_ERR) {
2767c478bd9Sstevel@tonic-gate 		mdb_printf("%-9ld", id);
2777c478bd9Sstevel@tonic-gate 	} else {
2787c478bd9Sstevel@tonic-gate 		mdb_printf("%9s", "");
2797c478bd9Sstevel@tonic-gate 	}
2807c478bd9Sstevel@tonic-gate }
2817c478bd9Sstevel@tonic-gate 
2827c478bd9Sstevel@tonic-gate static void
nm_print_obj(void * data)2837c478bd9Sstevel@tonic-gate nm_print_obj(void *data)
2847c478bd9Sstevel@tonic-gate {
2857c478bd9Sstevel@tonic-gate 	const char *obj = (const char *)data;
2867c478bd9Sstevel@tonic-gate 
2877c478bd9Sstevel@tonic-gate 	if (obj == MDB_TGT_OBJ_EXEC)
2887c478bd9Sstevel@tonic-gate 		obj = "exec";
2897c478bd9Sstevel@tonic-gate 	else if (obj == MDB_TGT_OBJ_RTLD)
2907c478bd9Sstevel@tonic-gate 		obj = "rtld";
2917c478bd9Sstevel@tonic-gate 	else if (obj == MDB_TGT_OBJ_EVERY)
2927c478bd9Sstevel@tonic-gate 		obj = "";
2937c478bd9Sstevel@tonic-gate 
2947c478bd9Sstevel@tonic-gate 	mdb_printf("%-15s", obj);
2957c478bd9Sstevel@tonic-gate }
2967c478bd9Sstevel@tonic-gate 
2977c478bd9Sstevel@tonic-gate /*ARGSUSED*/
2987c478bd9Sstevel@tonic-gate static int
nm_print(void * data,const GElf_Sym * sym,const char * name,const mdb_syminfo_t * sip,const char * obj)2997c478bd9Sstevel@tonic-gate nm_print(void *data, const GElf_Sym *sym, const char *name,
3007c478bd9Sstevel@tonic-gate     const mdb_syminfo_t *sip, const char *obj)
3017c478bd9Sstevel@tonic-gate {
3027c478bd9Sstevel@tonic-gate 	nm_iter_info_t *niip = data;
3037c478bd9Sstevel@tonic-gate 
3047c478bd9Sstevel@tonic-gate 	if (!((1 << GELF_ST_TYPE(sym->st_info)) & niip->nii_types))
3057c478bd9Sstevel@tonic-gate 		return (0);
3067c478bd9Sstevel@tonic-gate 
3077c478bd9Sstevel@tonic-gate 	niip->nii_id = sip->sym_id;
3087c478bd9Sstevel@tonic-gate 	niip->nii_symp = sym;
3097c478bd9Sstevel@tonic-gate 
3107c478bd9Sstevel@tonic-gate 	mdb_table_print(niip->nii_flags, "|",
3117c478bd9Sstevel@tonic-gate 	    MDB_TBL_PRNT, NM_FMT_INDEX, "%5u", sip->sym_id,
3127c478bd9Sstevel@tonic-gate 	    MDB_TBL_FUNC, NM_FMT_OBJECT, nm_print_obj, obj,
3137c478bd9Sstevel@tonic-gate 	    MDB_TBL_PRNT, NM_FMT_VALUE, niip->nii_pfmt, sym->st_value,
3147c478bd9Sstevel@tonic-gate 	    MDB_TBL_PRNT, NM_FMT_SIZE, niip->nii_pfmt, sym->st_size,
3157c478bd9Sstevel@tonic-gate 	    MDB_TBL_PRNT, NM_FMT_TYPE, "%-5s", nm_type2str(sym->st_info),
3167c478bd9Sstevel@tonic-gate 	    MDB_TBL_PRNT, NM_FMT_BIND, "%-5s", nm_bind2str(sym->st_info),
3177c478bd9Sstevel@tonic-gate 	    MDB_TBL_PRNT, NM_FMT_OTHER, niip->nii_ofmt, sym->st_other,
3187c478bd9Sstevel@tonic-gate 	    MDB_TBL_PRNT, NM_FMT_SHNDX, "%-8s", nm_sect2str(sym->st_shndx),
3197c478bd9Sstevel@tonic-gate 	    MDB_TBL_FUNC, NM_FMT_CTFID, nm_print_ctfid, niip,
3207c478bd9Sstevel@tonic-gate 	    MDB_TBL_FUNC, NM_FMT_CTYPE, nm_print_ctype, niip,
3217c478bd9Sstevel@tonic-gate 	    MDB_TBL_PRNT, NM_FMT_NAME, "%s", name,
3227c478bd9Sstevel@tonic-gate 	    MDB_TBL_DONE);
3237c478bd9Sstevel@tonic-gate 
3247c478bd9Sstevel@tonic-gate 	mdb_printf("\n");
3257c478bd9Sstevel@tonic-gate 
3267c478bd9Sstevel@tonic-gate 	return (0);
3277c478bd9Sstevel@tonic-gate }
3287c478bd9Sstevel@tonic-gate 
3297c478bd9Sstevel@tonic-gate /*ARGSUSED*/
3307c478bd9Sstevel@tonic-gate static int
nm_any(void * data,const GElf_Sym * sym,const char * name,const mdb_syminfo_t * sip,const char * obj)3317c478bd9Sstevel@tonic-gate nm_any(void *data, const GElf_Sym *sym, const char *name,
3327c478bd9Sstevel@tonic-gate     const mdb_syminfo_t *sip, const char *obj)
3337c478bd9Sstevel@tonic-gate {
3347c478bd9Sstevel@tonic-gate 	return (nm_print(data, sym, name, sip, obj));
3357c478bd9Sstevel@tonic-gate }
3367c478bd9Sstevel@tonic-gate 
3377c478bd9Sstevel@tonic-gate /*ARGSUSED*/
3387c478bd9Sstevel@tonic-gate static int
nm_undef(void * data,const GElf_Sym * sym,const char * name,const mdb_syminfo_t * sip,const char * obj)3397c478bd9Sstevel@tonic-gate nm_undef(void *data, const GElf_Sym *sym, const char *name,
3407c478bd9Sstevel@tonic-gate     const mdb_syminfo_t *sip, const char *obj)
3417c478bd9Sstevel@tonic-gate {
3427c478bd9Sstevel@tonic-gate 	if (sym->st_shndx == SHN_UNDEF)
3437c478bd9Sstevel@tonic-gate 		return (nm_print(data, sym, name, sip, obj));
3447c478bd9Sstevel@tonic-gate 
3457c478bd9Sstevel@tonic-gate 	return (0);
3467c478bd9Sstevel@tonic-gate }
3477c478bd9Sstevel@tonic-gate 
3487c478bd9Sstevel@tonic-gate /*ARGSUSED*/
3497c478bd9Sstevel@tonic-gate static int
nm_asgn(void * data,const GElf_Sym * sym,const char * name,const mdb_syminfo_t * sip,const char * obj)3507c478bd9Sstevel@tonic-gate nm_asgn(void *data, const GElf_Sym *sym, const char *name,
3517c478bd9Sstevel@tonic-gate     const mdb_syminfo_t *sip, const char *obj)
3527c478bd9Sstevel@tonic-gate {
3537c478bd9Sstevel@tonic-gate 	const char *opts;
3547c478bd9Sstevel@tonic-gate 
3557c478bd9Sstevel@tonic-gate 	switch (GELF_ST_TYPE(sym->st_info)) {
3567c478bd9Sstevel@tonic-gate 	case STT_FUNC:
3577c478bd9Sstevel@tonic-gate 		opts = "-f";
3587c478bd9Sstevel@tonic-gate 		break;
3597c478bd9Sstevel@tonic-gate 	case STT_OBJECT:
3607c478bd9Sstevel@tonic-gate 		opts = "-o";
3617c478bd9Sstevel@tonic-gate 		break;
3627c478bd9Sstevel@tonic-gate 	default:
3637c478bd9Sstevel@tonic-gate 		opts = "";
3647c478bd9Sstevel@tonic-gate 	}
3657c478bd9Sstevel@tonic-gate 
3667c478bd9Sstevel@tonic-gate 	mdb_printf("%#llr::nmadd %s -s %#llr %s\n",
3677c478bd9Sstevel@tonic-gate 	    sym->st_value, opts, sym->st_size, name);
3687c478bd9Sstevel@tonic-gate 
3697c478bd9Sstevel@tonic-gate 	return (0);
3707c478bd9Sstevel@tonic-gate }
3717c478bd9Sstevel@tonic-gate 
3727c478bd9Sstevel@tonic-gate /*ARGSUSED*/
3737c478bd9Sstevel@tonic-gate static int
nm_cnt_any(void * data,const GElf_Sym * sym,const char * name,const mdb_syminfo_t * sip,const char * obj)3747c478bd9Sstevel@tonic-gate nm_cnt_any(void *data, const GElf_Sym *sym, const char *name,
3757c478bd9Sstevel@tonic-gate     const mdb_syminfo_t *sip, const char *obj)
3767c478bd9Sstevel@tonic-gate {
3777c478bd9Sstevel@tonic-gate 	size_t *cntp = (size_t *)data;
3787c478bd9Sstevel@tonic-gate 	(*cntp)++;
3797c478bd9Sstevel@tonic-gate 	return (0);
3807c478bd9Sstevel@tonic-gate }
3817c478bd9Sstevel@tonic-gate 
3827c478bd9Sstevel@tonic-gate /*ARGSUSED*/
3837c478bd9Sstevel@tonic-gate static int
nm_cnt_undef(void * data,const GElf_Sym * sym,const char * name,const mdb_syminfo_t * sip,const char * obj)3847c478bd9Sstevel@tonic-gate nm_cnt_undef(void *data, const GElf_Sym *sym, const char *name,
3857c478bd9Sstevel@tonic-gate     const mdb_syminfo_t *sip, const char *obj)
3867c478bd9Sstevel@tonic-gate {
3877c478bd9Sstevel@tonic-gate 	if (sym->st_shndx == SHN_UNDEF)
3887c478bd9Sstevel@tonic-gate 		return (nm_cnt_any(data, sym, name, sip, obj));
3897c478bd9Sstevel@tonic-gate 
3907c478bd9Sstevel@tonic-gate 	return (0);
3917c478bd9Sstevel@tonic-gate }
3927c478bd9Sstevel@tonic-gate 
3937c478bd9Sstevel@tonic-gate /*ARGSUSED*/
3947c478bd9Sstevel@tonic-gate static int
nm_get_any(void * data,const GElf_Sym * sym,const char * name,const mdb_syminfo_t * sip,const char * obj)3957c478bd9Sstevel@tonic-gate nm_get_any(void *data, const GElf_Sym *sym, const char *name,
3967c478bd9Sstevel@tonic-gate     const mdb_syminfo_t *sip, const char *obj)
3977c478bd9Sstevel@tonic-gate {
3987c478bd9Sstevel@tonic-gate 	nm_iter_info_t *niip = data;
3997c478bd9Sstevel@tonic-gate 	nm_sym_t **sympp = niip->nii_sympp;
4007c478bd9Sstevel@tonic-gate 
4017c478bd9Sstevel@tonic-gate 	(*sympp)->nm_sym = *sym;
4027c478bd9Sstevel@tonic-gate 	(*sympp)->nm_name = name;
4037c478bd9Sstevel@tonic-gate 	(*sympp)->nm_si = *sip;
4047c478bd9Sstevel@tonic-gate 	(*sympp)->nm_object = obj;
4057c478bd9Sstevel@tonic-gate 	(*sympp)->nm_fp = niip->nii_fp;
4067c478bd9Sstevel@tonic-gate 	(*sympp)++;
4077c478bd9Sstevel@tonic-gate 
4087c478bd9Sstevel@tonic-gate 	return (0);
4097c478bd9Sstevel@tonic-gate }
4107c478bd9Sstevel@tonic-gate 
4117c478bd9Sstevel@tonic-gate /*ARGSUSED*/
4127c478bd9Sstevel@tonic-gate static int
nm_get_undef(void * data,const GElf_Sym * sym,const char * name,const mdb_syminfo_t * sip,const char * obj)4137c478bd9Sstevel@tonic-gate nm_get_undef(void *data, const GElf_Sym *sym, const char *name,
4147c478bd9Sstevel@tonic-gate     const mdb_syminfo_t *sip, const char *obj)
4157c478bd9Sstevel@tonic-gate {
4167c478bd9Sstevel@tonic-gate 	if (sym->st_shndx == SHN_UNDEF)
4177c478bd9Sstevel@tonic-gate 		return (nm_get_any(data, sym, name, sip, obj));
4187c478bd9Sstevel@tonic-gate 
4197c478bd9Sstevel@tonic-gate 	return (0);
4207c478bd9Sstevel@tonic-gate }
4217c478bd9Sstevel@tonic-gate 
4227c478bd9Sstevel@tonic-gate static int
nm_compare_name(const void * lp,const void * rp)4237c478bd9Sstevel@tonic-gate nm_compare_name(const void *lp, const void *rp)
4247c478bd9Sstevel@tonic-gate {
4257c478bd9Sstevel@tonic-gate 	const nm_sym_t *lhs = (nm_sym_t *)lp;
4267c478bd9Sstevel@tonic-gate 	const nm_sym_t *rhs = (nm_sym_t *)rp;
4277c478bd9Sstevel@tonic-gate 
4287c478bd9Sstevel@tonic-gate 	return (strcmp(lhs->nm_name, rhs->nm_name));
4297c478bd9Sstevel@tonic-gate }
4307c478bd9Sstevel@tonic-gate 
4317c478bd9Sstevel@tonic-gate static int
nm_compare_val(const void * lp,const void * rp)4327c478bd9Sstevel@tonic-gate nm_compare_val(const void *lp, const void *rp)
4337c478bd9Sstevel@tonic-gate {
4347c478bd9Sstevel@tonic-gate 	const nm_sym_t *lhs = (nm_sym_t *)lp;
4357c478bd9Sstevel@tonic-gate 	const nm_sym_t *rhs = (nm_sym_t *)rp;
4367c478bd9Sstevel@tonic-gate 
4377c478bd9Sstevel@tonic-gate 	return (lhs->nm_sym.st_value < rhs->nm_sym.st_value ? -1 :
4387c478bd9Sstevel@tonic-gate 	    (lhs->nm_sym.st_value > rhs->nm_sym.st_value ? 1 : 0));
4397c478bd9Sstevel@tonic-gate }
4407c478bd9Sstevel@tonic-gate 
4417c478bd9Sstevel@tonic-gate static int
nm_gelf_symtab_cb(void * data,const GElf_Sym * symp,const char * name,uint_t id)4427c478bd9Sstevel@tonic-gate nm_gelf_symtab_cb(void *data, const GElf_Sym *symp, const char *name, uint_t id)
4437c478bd9Sstevel@tonic-gate {
4447c478bd9Sstevel@tonic-gate 	nm_gelf_symtab_t *ngsp = data;
4457c478bd9Sstevel@tonic-gate 
4467c478bd9Sstevel@tonic-gate 	ngsp->ngs_si.sym_id = id;
4477c478bd9Sstevel@tonic-gate 
4487c478bd9Sstevel@tonic-gate 	return (ngsp->ngs_cb(ngsp->ngs_arg, symp, name, &ngsp->ngs_si,
4497c478bd9Sstevel@tonic-gate 	    ngsp->ngs_object));
4507c478bd9Sstevel@tonic-gate }
4517c478bd9Sstevel@tonic-gate 
4527c478bd9Sstevel@tonic-gate static void
nm_gelf_symtab_iter(mdb_gelf_symtab_t * gst,const char * object,uint_t table,mdb_tgt_sym_f * cb,void * arg)4537c478bd9Sstevel@tonic-gate nm_gelf_symtab_iter(mdb_gelf_symtab_t *gst, const char *object, uint_t table,
4547c478bd9Sstevel@tonic-gate     mdb_tgt_sym_f *cb, void *arg)
4557c478bd9Sstevel@tonic-gate {
4567c478bd9Sstevel@tonic-gate 	nm_gelf_symtab_t ngs;
4577c478bd9Sstevel@tonic-gate 
4587c478bd9Sstevel@tonic-gate 	ngs.ngs_cb = cb;
4597c478bd9Sstevel@tonic-gate 	ngs.ngs_arg = arg;
4607c478bd9Sstevel@tonic-gate 
4617c478bd9Sstevel@tonic-gate 	ngs.ngs_si.sym_table = table;
4627c478bd9Sstevel@tonic-gate 	ngs.ngs_object = object;
4637c478bd9Sstevel@tonic-gate 
4647c478bd9Sstevel@tonic-gate 	mdb_gelf_symtab_iter(gst, nm_gelf_symtab_cb, &ngs);
4657c478bd9Sstevel@tonic-gate }
4667c478bd9Sstevel@tonic-gate 
4677c478bd9Sstevel@tonic-gate static int nm_symbol_iter(const char *, uint_t, uint_t, mdb_tgt_sym_f *,
4687c478bd9Sstevel@tonic-gate     nm_iter_info_t *);
4697c478bd9Sstevel@tonic-gate 
4707c478bd9Sstevel@tonic-gate /*ARGSUSED*/
4717c478bd9Sstevel@tonic-gate static int
nm_object_iter_cb(void * data,const mdb_map_t * mp,const char * name)4727c478bd9Sstevel@tonic-gate nm_object_iter_cb(void *data, const mdb_map_t *mp, const char *name)
4737c478bd9Sstevel@tonic-gate {
4747c478bd9Sstevel@tonic-gate 	nm_object_iter_t *noip = data;
4757c478bd9Sstevel@tonic-gate 
476659d8689SEdward Pilatowicz 	/*
477659d8689SEdward Pilatowicz 	 * Since we're interating over all the objects in a target,
478659d8689SEdward Pilatowicz 	 * don't return an error if we hit an object that we can't
479659d8689SEdward Pilatowicz 	 * get symbol data for.
480659d8689SEdward Pilatowicz 	 */
481659d8689SEdward Pilatowicz 	if (nm_symbol_iter(name, noip->noi_which, noip->noi_type,
482659d8689SEdward Pilatowicz 	    noip->noi_cb, noip->noi_niip) != 0)
483659d8689SEdward Pilatowicz 		mdb_warn("unable to dump symbol data for: %s\n", name);
484659d8689SEdward Pilatowicz 	return (0);
4857c478bd9Sstevel@tonic-gate }
4867c478bd9Sstevel@tonic-gate 
4877c478bd9Sstevel@tonic-gate int
nm_symbol_iter(const char * object,uint_t which,uint_t type,mdb_tgt_sym_f * cb,nm_iter_info_t * niip)4887c478bd9Sstevel@tonic-gate nm_symbol_iter(const char *object, uint_t which, uint_t type,
4897c478bd9Sstevel@tonic-gate     mdb_tgt_sym_f *cb, nm_iter_info_t *niip)
4907c478bd9Sstevel@tonic-gate {
4917c478bd9Sstevel@tonic-gate 	mdb_tgt_t *t = mdb.m_target;
4927c478bd9Sstevel@tonic-gate 
4937c478bd9Sstevel@tonic-gate 	if (object == MDB_TGT_OBJ_EVERY) {
4947c478bd9Sstevel@tonic-gate 		nm_object_iter_t noi;
4957c478bd9Sstevel@tonic-gate 
4967c478bd9Sstevel@tonic-gate 		noi.noi_which = which;
4977c478bd9Sstevel@tonic-gate 		noi.noi_type = type;
4987c478bd9Sstevel@tonic-gate 		noi.noi_cb = cb;
4997c478bd9Sstevel@tonic-gate 		noi.noi_niip = niip;
5007c478bd9Sstevel@tonic-gate 
5017c478bd9Sstevel@tonic-gate 		return (mdb_tgt_object_iter(t, nm_object_iter_cb, &noi));
5027c478bd9Sstevel@tonic-gate 	}
5037c478bd9Sstevel@tonic-gate 
5047c478bd9Sstevel@tonic-gate 	niip->nii_fp = mdb_tgt_name_to_ctf(t, object);
5057c478bd9Sstevel@tonic-gate 
5067c478bd9Sstevel@tonic-gate 	return (mdb_tgt_symbol_iter(t, object, which, type, cb, niip));
5077c478bd9Sstevel@tonic-gate }
5087c478bd9Sstevel@tonic-gate 
5097c478bd9Sstevel@tonic-gate /*ARGSUSED*/
5107c478bd9Sstevel@tonic-gate int
cmd_nm(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)5117c478bd9Sstevel@tonic-gate cmd_nm(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
5127c478bd9Sstevel@tonic-gate {
5137c478bd9Sstevel@tonic-gate 	enum {
5147c478bd9Sstevel@tonic-gate 		NM_DYNSYM	= 0x0001,	/* -D (use dynsym) */
5157c478bd9Sstevel@tonic-gate 		NM_DEC		= 0x0002,	/* -d (decimal output) */
5167c478bd9Sstevel@tonic-gate 		NM_GLOBAL	= 0x0004,	/* -g (globals only) */
5177c478bd9Sstevel@tonic-gate 		NM_NOHDRS	= 0x0008,	/* -h (suppress header) */
5187c478bd9Sstevel@tonic-gate 		NM_OCT		= 0x0010,	/* -o (octal output) */
5197c478bd9Sstevel@tonic-gate 		NM_UNDEF	= 0x0020,	/* -u (undefs only) */
5207c478bd9Sstevel@tonic-gate 		NM_HEX		= 0x0040,	/* -x (hex output) */
5217c478bd9Sstevel@tonic-gate 		NM_SORT_NAME	= 0x0080,	/* -n (sort by name) */
5227c478bd9Sstevel@tonic-gate 		NM_SORT_VALUE	= 0x0100,	/* -v (sort by value) */
5237c478bd9Sstevel@tonic-gate 		NM_PRVSYM	= 0x0200,	/* -P (use private symtab) */
5247c478bd9Sstevel@tonic-gate 		NM_PRTASGN	= 0x0400	/* -p (print in asgn syntax) */
5257c478bd9Sstevel@tonic-gate 	};
5267c478bd9Sstevel@tonic-gate 
5277c478bd9Sstevel@tonic-gate 	mdb_subopt_t opt_fmt_opts[] = {
5287c478bd9Sstevel@tonic-gate 		{ NM_FMT_INDEX, "ndx" },
5297c478bd9Sstevel@tonic-gate 		{ NM_FMT_VALUE, "val" },
5307c478bd9Sstevel@tonic-gate 		{ NM_FMT_SIZE, "sz" },
5317c478bd9Sstevel@tonic-gate 		{ NM_FMT_TYPE, "type" },
5327c478bd9Sstevel@tonic-gate 		{ NM_FMT_BIND, "bind" },
5337c478bd9Sstevel@tonic-gate 		{ NM_FMT_OTHER, "oth" },
5347c478bd9Sstevel@tonic-gate 		{ NM_FMT_SHNDX, "shndx" },
5357c478bd9Sstevel@tonic-gate 		{ NM_FMT_NAME, "name" },
5367c478bd9Sstevel@tonic-gate 		{ NM_FMT_CTYPE, "ctype" },
5377c478bd9Sstevel@tonic-gate 		{ NM_FMT_OBJECT, "obj" },
5387c478bd9Sstevel@tonic-gate 		{ NM_FMT_CTFID, "ctfid" },
5397c478bd9Sstevel@tonic-gate 		{ 0, NULL }
5407c478bd9Sstevel@tonic-gate 	};
5417c478bd9Sstevel@tonic-gate 
5427c478bd9Sstevel@tonic-gate 	mdb_subopt_t opt_type_opts[] = {
5437c478bd9Sstevel@tonic-gate 		{ NM_TYPE_NOTY, "noty" },
5447c478bd9Sstevel@tonic-gate 		{ NM_TYPE_OBJT, "objt" },
5457c478bd9Sstevel@tonic-gate 		{ NM_TYPE_FUNC, "func" },
5467c478bd9Sstevel@tonic-gate 		{ NM_TYPE_SECT, "sect" },
5477c478bd9Sstevel@tonic-gate 		{ NM_TYPE_FILE, "file" },
5487c478bd9Sstevel@tonic-gate 		{ NM_TYPE_COMM, "comm" },
5497c478bd9Sstevel@tonic-gate 		{ NM_TYPE_TLS, "tls" },
5507c478bd9Sstevel@tonic-gate 		{ NM_TYPE_REGI, "regi" },
5517c478bd9Sstevel@tonic-gate 		{ 0, NULL }
5527c478bd9Sstevel@tonic-gate 	};
5537c478bd9Sstevel@tonic-gate 
5547c478bd9Sstevel@tonic-gate 	uint_t optf = 0;
5557c478bd9Sstevel@tonic-gate 	uint_t opt_fmt;
5567c478bd9Sstevel@tonic-gate 	uint_t opt_types;
5577c478bd9Sstevel@tonic-gate 	int i;
5587c478bd9Sstevel@tonic-gate 
5597c478bd9Sstevel@tonic-gate 	mdb_tgt_sym_f *callback;
5607c478bd9Sstevel@tonic-gate 	uint_t which, type;
5617c478bd9Sstevel@tonic-gate 
5627c478bd9Sstevel@tonic-gate 	char *object = (char *)MDB_TGT_OBJ_EVERY;
5637c478bd9Sstevel@tonic-gate 	int hwidth;
5647c478bd9Sstevel@tonic-gate 	size_t nsyms = 0;
5657c478bd9Sstevel@tonic-gate 
566*24537d3eSToomas Soome 	nm_sym_t *syms = NULL, *symp;
5677c478bd9Sstevel@tonic-gate 
5687c478bd9Sstevel@tonic-gate 	nm_iter_info_t nii;
5697c478bd9Sstevel@tonic-gate 
5707c478bd9Sstevel@tonic-gate 	/* default output columns */
5717c478bd9Sstevel@tonic-gate 	opt_fmt = NM_FMT_VALUE | NM_FMT_SIZE | NM_FMT_TYPE | NM_FMT_BIND |
5727c478bd9Sstevel@tonic-gate 	    NM_FMT_OTHER | NM_FMT_SHNDX | NM_FMT_NAME;
5737c478bd9Sstevel@tonic-gate 
5747c478bd9Sstevel@tonic-gate 	/* default output types */
5757c478bd9Sstevel@tonic-gate 	opt_types = NM_TYPE_NOTY | NM_TYPE_OBJT | NM_TYPE_FUNC | NM_TYPE_SECT |
5767c478bd9Sstevel@tonic-gate 	    NM_TYPE_FILE | NM_TYPE_COMM | NM_TYPE_TLS | NM_TYPE_REGI;
5777c478bd9Sstevel@tonic-gate 
5787c478bd9Sstevel@tonic-gate 	i = mdb_getopts(argc, argv,
5797c478bd9Sstevel@tonic-gate 	    'D', MDB_OPT_SETBITS, NM_DYNSYM, &optf,
5807c478bd9Sstevel@tonic-gate 	    'P', MDB_OPT_SETBITS, NM_PRVSYM, &optf,
5817c478bd9Sstevel@tonic-gate 	    'd', MDB_OPT_SETBITS, NM_DEC, &optf,
5827c478bd9Sstevel@tonic-gate 	    'g', MDB_OPT_SETBITS, NM_GLOBAL, &optf,
5837c478bd9Sstevel@tonic-gate 	    'h', MDB_OPT_SETBITS, NM_NOHDRS, &optf,
5847c478bd9Sstevel@tonic-gate 	    'n', MDB_OPT_SETBITS, NM_SORT_NAME, &optf,
5857c478bd9Sstevel@tonic-gate 	    'o', MDB_OPT_SETBITS, NM_OCT, &optf,
5867c478bd9Sstevel@tonic-gate 	    'p', MDB_OPT_SETBITS, NM_PRTASGN | NM_NOHDRS, &optf,
5877c478bd9Sstevel@tonic-gate 	    'u', MDB_OPT_SETBITS, NM_UNDEF, &optf,
5887c478bd9Sstevel@tonic-gate 	    'v', MDB_OPT_SETBITS, NM_SORT_VALUE, &optf,
5897c478bd9Sstevel@tonic-gate 	    'x', MDB_OPT_SETBITS, NM_HEX, &optf,
5907c478bd9Sstevel@tonic-gate 	    'f', MDB_OPT_SUBOPTS, opt_fmt_opts, &opt_fmt,
5917c478bd9Sstevel@tonic-gate 	    't', MDB_OPT_SUBOPTS, opt_type_opts, &opt_types,
5927c478bd9Sstevel@tonic-gate 	    NULL);
5937c478bd9Sstevel@tonic-gate 
5947c478bd9Sstevel@tonic-gate 	if (i != argc) {
5957c478bd9Sstevel@tonic-gate 		if (flags & DCMD_ADDRSPEC)
5967c478bd9Sstevel@tonic-gate 			return (DCMD_USAGE);
5977c478bd9Sstevel@tonic-gate 
5987c478bd9Sstevel@tonic-gate 		if (argc != 0 && (argc - i) == 1) {
5997c478bd9Sstevel@tonic-gate 			if (argv[i].a_type != MDB_TYPE_STRING ||
6007c478bd9Sstevel@tonic-gate 			    argv[i].a_un.a_str[0] == '-')
6017c478bd9Sstevel@tonic-gate 				return (DCMD_USAGE);
6027c478bd9Sstevel@tonic-gate 			else
6037c478bd9Sstevel@tonic-gate 				object = (char *)argv[i].a_un.a_str;
6047c478bd9Sstevel@tonic-gate 		} else
6057c478bd9Sstevel@tonic-gate 			return (DCMD_USAGE);
6067c478bd9Sstevel@tonic-gate 	}
6077c478bd9Sstevel@tonic-gate 
6087c478bd9Sstevel@tonic-gate 	if ((optf & (NM_DEC | NM_HEX | NM_OCT)) == 0) {
6097c478bd9Sstevel@tonic-gate 		switch (mdb.m_radix) {
6107c478bd9Sstevel@tonic-gate 		case 8:
6117c478bd9Sstevel@tonic-gate 			optf |= NM_OCT;
6127c478bd9Sstevel@tonic-gate 			break;
6137c478bd9Sstevel@tonic-gate 		case 10:
6147c478bd9Sstevel@tonic-gate 			optf |= NM_DEC;
6157c478bd9Sstevel@tonic-gate 			break;
6167c478bd9Sstevel@tonic-gate 		default:
6177c478bd9Sstevel@tonic-gate 			optf |= NM_HEX;
6187c478bd9Sstevel@tonic-gate 		}
6197c478bd9Sstevel@tonic-gate 	}
6207c478bd9Sstevel@tonic-gate 
6217c478bd9Sstevel@tonic-gate 	switch (optf & (NM_DEC | NM_HEX | NM_OCT)) {
6227c478bd9Sstevel@tonic-gate 	case NM_DEC:
6237c478bd9Sstevel@tonic-gate #ifdef _LP64
6247c478bd9Sstevel@tonic-gate 		nii.nii_pfmt = "%-20llu";
6257c478bd9Sstevel@tonic-gate 		nii.nii_ofmt = "%-5u";
6267c478bd9Sstevel@tonic-gate 		hwidth = 20;
6277c478bd9Sstevel@tonic-gate #else
6287c478bd9Sstevel@tonic-gate 		nii.nii_pfmt = "%-10llu";
6297c478bd9Sstevel@tonic-gate 		nii.nii_ofmt = "%-5u";
6307c478bd9Sstevel@tonic-gate 		hwidth = 10;
6317c478bd9Sstevel@tonic-gate #endif
6327c478bd9Sstevel@tonic-gate 		break;
6337c478bd9Sstevel@tonic-gate 	case NM_HEX:
6347c478bd9Sstevel@tonic-gate #ifdef _LP64
6357c478bd9Sstevel@tonic-gate 		nii.nii_pfmt = "0x%016llx";
6367c478bd9Sstevel@tonic-gate 		nii.nii_ofmt = "0x%-3x";
6377c478bd9Sstevel@tonic-gate 		hwidth = 18;
6387c478bd9Sstevel@tonic-gate #else
6397c478bd9Sstevel@tonic-gate 		nii.nii_pfmt = "0x%08llx";
6407c478bd9Sstevel@tonic-gate 		nii.nii_ofmt = "0x%-3x";
6417c478bd9Sstevel@tonic-gate 		hwidth = 10;
6427c478bd9Sstevel@tonic-gate #endif
6437c478bd9Sstevel@tonic-gate 		break;
6447c478bd9Sstevel@tonic-gate 	case NM_OCT:
6457c478bd9Sstevel@tonic-gate #ifdef _LP64
6467c478bd9Sstevel@tonic-gate 		nii.nii_pfmt = "%-22llo";
6477c478bd9Sstevel@tonic-gate 		nii.nii_ofmt = "%-5o";
6487c478bd9Sstevel@tonic-gate 		hwidth = 22;
6497c478bd9Sstevel@tonic-gate #else
6507c478bd9Sstevel@tonic-gate 		nii.nii_pfmt = "%-11llo";
6517c478bd9Sstevel@tonic-gate 		nii.nii_ofmt = "%-5o";
6527c478bd9Sstevel@tonic-gate 		hwidth = 11;
6537c478bd9Sstevel@tonic-gate #endif
6547c478bd9Sstevel@tonic-gate 		break;
6557c478bd9Sstevel@tonic-gate 	default:
6567c478bd9Sstevel@tonic-gate 		mdb_warn("-d/-o/-x options are mutually exclusive\n");
6577c478bd9Sstevel@tonic-gate 		return (DCMD_USAGE);
6587c478bd9Sstevel@tonic-gate 	}
6597c478bd9Sstevel@tonic-gate 
6607c478bd9Sstevel@tonic-gate 	if (object != MDB_TGT_OBJ_EVERY && (optf & NM_PRVSYM)) {
6617c478bd9Sstevel@tonic-gate 		mdb_warn("-P/object options are mutually exclusive\n");
6627c478bd9Sstevel@tonic-gate 		return (DCMD_USAGE);
6637c478bd9Sstevel@tonic-gate 	}
6647c478bd9Sstevel@tonic-gate 
6657c478bd9Sstevel@tonic-gate 	if ((flags & DCMD_ADDRSPEC) && (optf & NM_PRVSYM)) {
6667c478bd9Sstevel@tonic-gate 		mdb_warn("-P/address options are mutually exclusive\n");
6677c478bd9Sstevel@tonic-gate 		return (DCMD_USAGE);
6687c478bd9Sstevel@tonic-gate 	}
6697c478bd9Sstevel@tonic-gate 
6707c478bd9Sstevel@tonic-gate 	if (!(optf & NM_NOHDRS)) {
6717c478bd9Sstevel@tonic-gate 		mdb_printf("%<u>");
6727c478bd9Sstevel@tonic-gate 		mdb_table_print(opt_fmt, " ",
6737c478bd9Sstevel@tonic-gate 		    MDB_TBL_PRNT, NM_FMT_INDEX, "Index",
6747c478bd9Sstevel@tonic-gate 		    MDB_TBL_PRNT, NM_FMT_OBJECT, "%-15s", "Object",
6757c478bd9Sstevel@tonic-gate 		    MDB_TBL_PRNT, NM_FMT_VALUE, "%-*s", hwidth, "Value",
6767c478bd9Sstevel@tonic-gate 		    MDB_TBL_PRNT, NM_FMT_SIZE, "%-*s", hwidth, "Size",
6777c478bd9Sstevel@tonic-gate 		    MDB_TBL_PRNT, NM_FMT_TYPE, "%-5s", "Type",
6787c478bd9Sstevel@tonic-gate 		    MDB_TBL_PRNT, NM_FMT_BIND, "%-5s", "Bind",
6797c478bd9Sstevel@tonic-gate 		    MDB_TBL_PRNT, NM_FMT_OTHER, "%-5s", "Other",
6807c478bd9Sstevel@tonic-gate 		    MDB_TBL_PRNT, NM_FMT_SHNDX, "%-8s", "Shndx",
6817c478bd9Sstevel@tonic-gate 		    MDB_TBL_PRNT, NM_FMT_CTFID, "%-9s", "CTF ID",
6827c478bd9Sstevel@tonic-gate 		    MDB_TBL_PRNT, NM_FMT_CTYPE, "%-50s", "C Type",
6837c478bd9Sstevel@tonic-gate 		    MDB_TBL_PRNT, NM_FMT_NAME, "%s", "Name",
6847c478bd9Sstevel@tonic-gate 		    MDB_TBL_DONE);
6857c478bd9Sstevel@tonic-gate 
6867c478bd9Sstevel@tonic-gate 		mdb_printf("%</u>\n");
6877c478bd9Sstevel@tonic-gate 	}
6887c478bd9Sstevel@tonic-gate 
6897c478bd9Sstevel@tonic-gate 	nii.nii_flags = opt_fmt;
6907c478bd9Sstevel@tonic-gate 	nii.nii_types = opt_types;
6917c478bd9Sstevel@tonic-gate 
6927c478bd9Sstevel@tonic-gate 	if (optf & NM_DYNSYM)
6937c478bd9Sstevel@tonic-gate 		which = MDB_TGT_DYNSYM;
6947c478bd9Sstevel@tonic-gate 	else
6957c478bd9Sstevel@tonic-gate 		which = MDB_TGT_SYMTAB;
6967c478bd9Sstevel@tonic-gate 
6977c478bd9Sstevel@tonic-gate 	if (optf & NM_GLOBAL)
6987c478bd9Sstevel@tonic-gate 		type = MDB_TGT_BIND_GLOBAL | MDB_TGT_TYPE_ANY;
6997c478bd9Sstevel@tonic-gate 	else
7007c478bd9Sstevel@tonic-gate 		type = MDB_TGT_BIND_ANY | MDB_TGT_TYPE_ANY;
7017c478bd9Sstevel@tonic-gate 
7027c478bd9Sstevel@tonic-gate 	if (flags & DCMD_ADDRSPEC)
7037c478bd9Sstevel@tonic-gate 		optf |= NM_SORT_NAME; /* use sorting path if only one symbol */
7047c478bd9Sstevel@tonic-gate 
7057c478bd9Sstevel@tonic-gate 	if (optf & (NM_SORT_NAME | NM_SORT_VALUE)) {
7067c478bd9Sstevel@tonic-gate 		char name[MDB_SYM_NAMLEN];
7077c478bd9Sstevel@tonic-gate 		GElf_Sym sym;
7087c478bd9Sstevel@tonic-gate 		mdb_syminfo_t si;
7097c478bd9Sstevel@tonic-gate 
7107c478bd9Sstevel@tonic-gate 		if (optf & NM_UNDEF)
7117c478bd9Sstevel@tonic-gate 			callback = nm_cnt_undef;
7127c478bd9Sstevel@tonic-gate 		else
7137c478bd9Sstevel@tonic-gate 			callback = nm_cnt_any;
7147c478bd9Sstevel@tonic-gate 
7157c478bd9Sstevel@tonic-gate 		if (flags & DCMD_ADDRSPEC) {
7167c478bd9Sstevel@tonic-gate 			const mdb_map_t *mp;
7177c478bd9Sstevel@tonic-gate 			/* gather relevant data for the specified addr */
7187c478bd9Sstevel@tonic-gate 
7197c478bd9Sstevel@tonic-gate 			nii.nii_fp = mdb_tgt_addr_to_ctf(mdb.m_target, addr);
7207c478bd9Sstevel@tonic-gate 
7217c478bd9Sstevel@tonic-gate 			if (mdb_tgt_lookup_by_addr(mdb.m_target, addr,
7227c478bd9Sstevel@tonic-gate 			    MDB_SYM_FUZZY, name, sizeof (name), &sym,
7237c478bd9Sstevel@tonic-gate 			    &si) == -1) {
7247c478bd9Sstevel@tonic-gate 				mdb_warn("%lr", addr);
7257c478bd9Sstevel@tonic-gate 				return (DCMD_ERR);
7267c478bd9Sstevel@tonic-gate 			}
7277c478bd9Sstevel@tonic-gate 
7287c478bd9Sstevel@tonic-gate 			if ((mp = mdb_tgt_addr_to_map(mdb.m_target, addr))
7297c478bd9Sstevel@tonic-gate 			    != NULL) {
7307c478bd9Sstevel@tonic-gate 				object = mdb_alloc(strlen(mp->map_name) + 1,
7317c478bd9Sstevel@tonic-gate 				    UM_SLEEP | UM_GC);
7327c478bd9Sstevel@tonic-gate 
7337c478bd9Sstevel@tonic-gate 				(void) strcpy(object, mp->map_name);
7347c478bd9Sstevel@tonic-gate 
7357c478bd9Sstevel@tonic-gate 				/*
7367c478bd9Sstevel@tonic-gate 				 * Try to find a better match for the syminfo.
7377c478bd9Sstevel@tonic-gate 				 */
7387c478bd9Sstevel@tonic-gate 				(void) mdb_tgt_lookup_by_name(mdb.m_target,
7397c478bd9Sstevel@tonic-gate 				    object, name, &sym, &si);
7407c478bd9Sstevel@tonic-gate 			}
7417c478bd9Sstevel@tonic-gate 
7427c478bd9Sstevel@tonic-gate 			(void) callback(&nsyms, &sym, name, &si, object);
7437c478bd9Sstevel@tonic-gate 
7447c478bd9Sstevel@tonic-gate 		} else if (optf & NM_PRVSYM) {
7457c478bd9Sstevel@tonic-gate 			nsyms = mdb_gelf_symtab_size(mdb.m_prsym);
7467c478bd9Sstevel@tonic-gate 		} else {
7477c478bd9Sstevel@tonic-gate 			(void) mdb_tgt_symbol_iter(mdb.m_target, object,
7487c478bd9Sstevel@tonic-gate 			    which, type, callback, &nsyms);
7497c478bd9Sstevel@tonic-gate 		}
7507c478bd9Sstevel@tonic-gate 
7517c478bd9Sstevel@tonic-gate 		if (nsyms == 0)
7527c478bd9Sstevel@tonic-gate 			return (DCMD_OK);
7537c478bd9Sstevel@tonic-gate 
7547c478bd9Sstevel@tonic-gate 		syms = symp = mdb_alloc(sizeof (nm_sym_t) * nsyms,
7557c478bd9Sstevel@tonic-gate 		    UM_SLEEP | UM_GC);
7567c478bd9Sstevel@tonic-gate 
7577c478bd9Sstevel@tonic-gate 		nii.nii_sympp = &symp;
7587c478bd9Sstevel@tonic-gate 
7597c478bd9Sstevel@tonic-gate 		if (optf & NM_UNDEF)
7607c478bd9Sstevel@tonic-gate 			callback = nm_get_undef;
7617c478bd9Sstevel@tonic-gate 		else
7627c478bd9Sstevel@tonic-gate 			callback = nm_get_any;
7637c478bd9Sstevel@tonic-gate 
7647c478bd9Sstevel@tonic-gate 		if (flags & DCMD_ADDRSPEC) {
7657c478bd9Sstevel@tonic-gate 			(void) callback(&nii, &sym, name, &si, object);
7667c478bd9Sstevel@tonic-gate 		} else if (optf & NM_PRVSYM) {
7677c478bd9Sstevel@tonic-gate 			nm_gelf_symtab_iter(mdb.m_prsym, object, MDB_TGT_PRVSYM,
7687c478bd9Sstevel@tonic-gate 			    callback, &nii);
7697c478bd9Sstevel@tonic-gate 		} else if (nm_symbol_iter(object, which, type, callback,
7707c478bd9Sstevel@tonic-gate 		    &nii) == -1) {
7717c478bd9Sstevel@tonic-gate 			mdb_warn("failed to iterate over symbols");
7727c478bd9Sstevel@tonic-gate 			return (DCMD_ERR);
7737c478bd9Sstevel@tonic-gate 		}
7747c478bd9Sstevel@tonic-gate 
7757c478bd9Sstevel@tonic-gate 		if (optf & NM_SORT_NAME)
7767c478bd9Sstevel@tonic-gate 			qsort(syms, nsyms, sizeof (nm_sym_t), nm_compare_name);
7777c478bd9Sstevel@tonic-gate 		else
7787c478bd9Sstevel@tonic-gate 			qsort(syms, nsyms, sizeof (nm_sym_t), nm_compare_val);
7797c478bd9Sstevel@tonic-gate 	}
7807c478bd9Sstevel@tonic-gate 
7817c478bd9Sstevel@tonic-gate 	if ((optf & (NM_PRVSYM | NM_PRTASGN)) == (NM_PRVSYM | NM_PRTASGN))
7827c478bd9Sstevel@tonic-gate 		callback = nm_asgn;
7837c478bd9Sstevel@tonic-gate 	else if (optf & NM_UNDEF)
7847c478bd9Sstevel@tonic-gate 		callback = nm_undef;
7857c478bd9Sstevel@tonic-gate 	else
7867c478bd9Sstevel@tonic-gate 		callback = nm_any;
7877c478bd9Sstevel@tonic-gate 
7887c478bd9Sstevel@tonic-gate 	if (optf & (NM_SORT_NAME | NM_SORT_VALUE)) {
7897c478bd9Sstevel@tonic-gate 		for (symp = syms; nsyms-- != 0; symp++) {
7907c478bd9Sstevel@tonic-gate 			nii.nii_fp = symp->nm_fp;
7917c478bd9Sstevel@tonic-gate 
792d75f3745SJohn Levon 			(void) callback(&nii, &symp->nm_sym, symp->nm_name,
7937c478bd9Sstevel@tonic-gate 			    &symp->nm_si, symp->nm_object);
7947c478bd9Sstevel@tonic-gate 		}
7957c478bd9Sstevel@tonic-gate 
7967c478bd9Sstevel@tonic-gate 	} else {
7977c478bd9Sstevel@tonic-gate 		if (optf & NM_PRVSYM) {
7987c478bd9Sstevel@tonic-gate 			nm_gelf_symtab_iter(mdb.m_prsym, object, MDB_TGT_PRVSYM,
7997c478bd9Sstevel@tonic-gate 			    callback, &nii);
8007c478bd9Sstevel@tonic-gate 
8017c478bd9Sstevel@tonic-gate 		} else if (nm_symbol_iter(object, which, type, callback, &nii)
8027c478bd9Sstevel@tonic-gate 		    == -1) {
8037c478bd9Sstevel@tonic-gate 			mdb_warn("failed to iterate over symbols");
8047c478bd9Sstevel@tonic-gate 			return (DCMD_ERR);
8057c478bd9Sstevel@tonic-gate 		}
8067c478bd9Sstevel@tonic-gate 	}
8077c478bd9Sstevel@tonic-gate 
8087c478bd9Sstevel@tonic-gate 	return (DCMD_OK);
8097c478bd9Sstevel@tonic-gate }
8107c478bd9Sstevel@tonic-gate 
8117c478bd9Sstevel@tonic-gate int
cmd_nmadd(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)8127c478bd9Sstevel@tonic-gate cmd_nmadd(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
8137c478bd9Sstevel@tonic-gate {
8147c478bd9Sstevel@tonic-gate 	uintptr_t opt_e = 0, opt_s = 0;
8157c478bd9Sstevel@tonic-gate 	uint_t opt_f = FALSE, opt_o = FALSE;
8167c478bd9Sstevel@tonic-gate 
8177c478bd9Sstevel@tonic-gate 	GElf_Sym sym;
8187c478bd9Sstevel@tonic-gate 	int i;
8197c478bd9Sstevel@tonic-gate 
8207c478bd9Sstevel@tonic-gate 	if (!(flags & DCMD_ADDRSPEC))
8217c478bd9Sstevel@tonic-gate 		return (DCMD_USAGE);
8227c478bd9Sstevel@tonic-gate 
8237c478bd9Sstevel@tonic-gate 	i = mdb_getopts(argc, argv,
8247c478bd9Sstevel@tonic-gate 	    'f', MDB_OPT_SETBITS, TRUE, &opt_f,
8257c478bd9Sstevel@tonic-gate 	    'o', MDB_OPT_SETBITS, TRUE, &opt_o,
8267c478bd9Sstevel@tonic-gate 	    'e', MDB_OPT_UINTPTR, &opt_e,
8277c478bd9Sstevel@tonic-gate 	    's', MDB_OPT_UINTPTR, &opt_s, NULL);
8287c478bd9Sstevel@tonic-gate 
8297c478bd9Sstevel@tonic-gate 	if (i != (argc - 1) || argv[i].a_type != MDB_TYPE_STRING ||
8307c478bd9Sstevel@tonic-gate 	    argv[i].a_un.a_str[0] == '-' || argv[i].a_un.a_str[0] == '+')
8317c478bd9Sstevel@tonic-gate 		return (DCMD_USAGE);
8327c478bd9Sstevel@tonic-gate 
8337c478bd9Sstevel@tonic-gate 	if (opt_e && opt_e < addr) {
8347c478bd9Sstevel@tonic-gate 		mdb_warn("end (%p) is less than start address (%p)\n",
8357c478bd9Sstevel@tonic-gate 		    (void *)opt_e, (void *)addr);
8367c478bd9Sstevel@tonic-gate 		return (DCMD_USAGE);
8377c478bd9Sstevel@tonic-gate 	}
8387c478bd9Sstevel@tonic-gate 
8397c478bd9Sstevel@tonic-gate 	if (mdb_gelf_symtab_lookup_by_name(mdb.m_prsym,
8407c478bd9Sstevel@tonic-gate 	    argv[i].a_un.a_str, &sym, NULL) == -1) {
8417c478bd9Sstevel@tonic-gate 		bzero(&sym, sizeof (sym));
8427c478bd9Sstevel@tonic-gate 		sym.st_info = GELF_ST_INFO(STB_GLOBAL, STT_NOTYPE);
8437c478bd9Sstevel@tonic-gate 	}
8447c478bd9Sstevel@tonic-gate 
8457c478bd9Sstevel@tonic-gate 	if (opt_f)
8467c478bd9Sstevel@tonic-gate 		sym.st_info = GELF_ST_INFO(STB_GLOBAL, STT_FUNC);
8477c478bd9Sstevel@tonic-gate 	if (opt_o)
8487c478bd9Sstevel@tonic-gate 		sym.st_info = GELF_ST_INFO(STB_GLOBAL, STT_OBJECT);
8497c478bd9Sstevel@tonic-gate 	if (opt_e)
8507c478bd9Sstevel@tonic-gate 		sym.st_size = (GElf_Xword)(opt_e - addr);
8517c478bd9Sstevel@tonic-gate 	if (opt_s)
8527c478bd9Sstevel@tonic-gate 		sym.st_size = (GElf_Xword)(opt_s);
8537c478bd9Sstevel@tonic-gate 	sym.st_value = (GElf_Addr)addr;
8547c478bd9Sstevel@tonic-gate 
8557c478bd9Sstevel@tonic-gate 	mdb_gelf_symtab_insert(mdb.m_prsym, argv[i].a_un.a_str, &sym);
8567c478bd9Sstevel@tonic-gate 
8577c478bd9Sstevel@tonic-gate 	mdb_iob_printf(mdb.m_out, "added %s, value=%llr size=%llr\n",
8587c478bd9Sstevel@tonic-gate 	    argv[i].a_un.a_str, sym.st_value, sym.st_size);
8597c478bd9Sstevel@tonic-gate 
8607c478bd9Sstevel@tonic-gate 	return (DCMD_OK);
8617c478bd9Sstevel@tonic-gate }
8627c478bd9Sstevel@tonic-gate 
8637c478bd9Sstevel@tonic-gate /*ARGSUSED*/
8647c478bd9Sstevel@tonic-gate int
cmd_nmdel(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)8657c478bd9Sstevel@tonic-gate cmd_nmdel(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
8667c478bd9Sstevel@tonic-gate {
8677c478bd9Sstevel@tonic-gate 	const char *name;
8687c478bd9Sstevel@tonic-gate 	GElf_Sym sym;
8697c478bd9Sstevel@tonic-gate 	uint_t id;
8707c478bd9Sstevel@tonic-gate 
8717c478bd9Sstevel@tonic-gate 	if (argc != 1 || argv->a_type != MDB_TYPE_STRING ||
8727c478bd9Sstevel@tonic-gate 	    argv->a_un.a_str[0] == '-' || (flags & DCMD_ADDRSPEC))
8737c478bd9Sstevel@tonic-gate 		return (DCMD_USAGE);
8747c478bd9Sstevel@tonic-gate 
8757c478bd9Sstevel@tonic-gate 	name = argv->a_un.a_str;
8767c478bd9Sstevel@tonic-gate 
8777c478bd9Sstevel@tonic-gate 	if (mdb_gelf_symtab_lookup_by_name(mdb.m_prsym, name, &sym, &id) == 0) {
8787c478bd9Sstevel@tonic-gate 		mdb_gelf_symtab_delete(mdb.m_prsym, name, &sym);
8797c478bd9Sstevel@tonic-gate 		mdb_printf("deleted %s, value=%llr size=%llr\n",
8807c478bd9Sstevel@tonic-gate 		    name, sym.st_value, sym.st_size);
8817c478bd9Sstevel@tonic-gate 		return (DCMD_OK);
8827c478bd9Sstevel@tonic-gate 	}
8837c478bd9Sstevel@tonic-gate 
8847c478bd9Sstevel@tonic-gate 	mdb_warn("symbol '%s' not found in private symbol table\n", name);
8857c478bd9Sstevel@tonic-gate 	return (DCMD_ERR);
8867c478bd9Sstevel@tonic-gate }
8877c478bd9Sstevel@tonic-gate 
8887c478bd9Sstevel@tonic-gate void
nm_help(void)8897c478bd9Sstevel@tonic-gate nm_help(void)
8907c478bd9Sstevel@tonic-gate {
8917c478bd9Sstevel@tonic-gate 	mdb_printf("-D         print .dynsym instead of .symtab\n"
8927c478bd9Sstevel@tonic-gate 	    "-P         print private symbol table instead of .symtab\n"
8937c478bd9Sstevel@tonic-gate 	    "-d         print value and size in decimal\n"
8947c478bd9Sstevel@tonic-gate 	    "-g         only print global symbols\n"
8957c478bd9Sstevel@tonic-gate 	    "-h         suppress header line\n"
8967c478bd9Sstevel@tonic-gate 	    "-n         sort symbols by name\n"
8977c478bd9Sstevel@tonic-gate 	    "-o         print value and size in octal\n"
8987c478bd9Sstevel@tonic-gate 	    "-p         print symbols as a series of ::nmadd commands\n"
8997c478bd9Sstevel@tonic-gate 	    "-u         only print undefined symbols\n"
9007c478bd9Sstevel@tonic-gate 	    "-v         sort symbols by value\n"
9017c478bd9Sstevel@tonic-gate 	    "-x         print value and size in hexadecimal\n"
9027c478bd9Sstevel@tonic-gate 	    "-f format  use specified format\n"
9037c478bd9Sstevel@tonic-gate 	    "           ndx, val, sz, type, bind, oth, shndx, "
9047c478bd9Sstevel@tonic-gate 	    "name, ctype, obj\n"
9057c478bd9Sstevel@tonic-gate 	    "-t types   display symbols with the specified types\n"
9067c478bd9Sstevel@tonic-gate 	    "           noty, objt, func, sect, file, regi\n"
9077c478bd9Sstevel@tonic-gate 	    "obj        specify object whose symbol table should be used\n");
9087c478bd9Sstevel@tonic-gate }
9097c478bd9Sstevel@tonic-gate 
9107c478bd9Sstevel@tonic-gate void
nmadd_help(void)9117c478bd9Sstevel@tonic-gate nmadd_help(void)
9127c478bd9Sstevel@tonic-gate {
9137c478bd9Sstevel@tonic-gate 	mdb_printf("-f       set type of symbol to STT_FUNC\n"
9147c478bd9Sstevel@tonic-gate 	    "-o       set type of symbol to STT_OBJECT\n"
9157c478bd9Sstevel@tonic-gate 	    "-e end   set size of symbol to end - start address\n"
9167c478bd9Sstevel@tonic-gate 	    "-s size  set size of symbol to explicit value\n"
9177c478bd9Sstevel@tonic-gate 	    "name     specify symbol name to add\n");
9187c478bd9Sstevel@tonic-gate }
919