changeset 14132:20cdcfea8015

3985 want mdb api function for iterating object symbols Reviewed by: Robert Mustacchi <rm@joyent.com> Reviewed by: Adam Leventhal <ahl@delphix.com Reviewed by: Matthew Ahrens <mahrens@delphix.com> Approved by: Dan McDonald <danmcd@nexenta.com>
author Dave Pacheco <dap@joyent.com>
date Mon, 14 Nov 2011 15:57:40 -0800
parents 15f2242812c8
children 4caa3904e52a
files usr/src/cmd/mdb/common/mdb/mdb_modapi.c usr/src/cmd/mdb/common/mdb/mdb_modapi.h usr/src/cmd/mdb/common/mdb/mdb_target.h usr/src/cmd/mdb/common/modules/conf/mapfile-extern
diffstat 4 files changed, 85 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/usr/src/cmd/mdb/common/mdb/mdb_modapi.c	Sun Aug 04 08:48:11 2013 -0700
+++ b/usr/src/cmd/mdb/common/mdb/mdb_modapi.c	Mon Nov 14 15:57:40 2011 -0800
@@ -822,6 +822,55 @@
 }
 
 /*
+ * Private callback structure for implementing mdb_symbol_iter, below.
+ */
+typedef struct {
+	mdb_symbol_cb_t si_cb;
+	void *si_arg;
+	int si_rval;
+} symbol_iter_arg_t;
+
+/*ARGSUSED*/
+static int
+mdb_symbol_cb(void *data, const GElf_Sym *gsym, const char *name,
+    const mdb_syminfo_t *sip, const char *obj)
+{
+	symbol_iter_arg_t *arg = data;
+	mdb_symbol_t sym;
+
+	if (arg->si_rval != 0)
+		return (0);
+
+	bzero(&sym, sizeof (sym));
+	sym.sym_name = name;
+	sym.sym_object = obj;
+	sym.sym_sym = gsym;
+	sym.sym_table = sip->sym_table;
+	sym.sym_id = sip->sym_id;
+
+	arg->si_rval = arg->si_cb(&sym, arg->si_arg);
+
+	return (0);
+}
+
+int
+mdb_symbol_iter(const char *obj, uint_t which, uint_t type,
+    mdb_symbol_cb_t cb, void *data)
+{
+	symbol_iter_arg_t arg;
+
+	arg.si_cb = cb;
+	arg.si_arg = data;
+	arg.si_rval = 0;
+
+	if (mdb_tgt_symbol_iter(mdb.m_target, obj, which, type,
+	    mdb_symbol_cb, &arg) != 0)
+		return (-1);
+
+	return (arg.si_rval);
+}
+
+/*
  * Private structure and function for implementing mdb_dumpptr on top
  * of mdb_dump_internal
  */
--- a/usr/src/cmd/mdb/common/mdb/mdb_modapi.h	Sun Aug 04 08:48:11 2013 -0700
+++ b/usr/src/cmd/mdb/common/mdb/mdb_modapi.h	Mon Nov 14 15:57:40 2011 -0800
@@ -180,6 +180,14 @@
 	uintptr_t obj_size;		/* in memory size of object in bytes */
 } mdb_object_t;
 
+typedef struct mdb_symbol {
+	const char *sym_name;		/* name of symbol */
+	const char *sym_object;		/* name of containing object */
+	const GElf_Sym *sym_sym;	/* ELF symbol information */
+	uint_t sym_table;		/* symbol table id */
+	uint_t sym_id;			/* symbol identifier */
+} mdb_symbol_t;
+
 extern int mdb_pwalk(const char *, mdb_walk_cb_t, void *, uintptr_t);
 extern int mdb_walk(const char *, mdb_walk_cb_t, void *);
 
@@ -296,6 +304,28 @@
 typedef int (*mdb_object_cb_t)(mdb_object_t *, void *);
 extern int mdb_object_iter(mdb_object_cb_t, void *);
 
+#define	MDB_SYMTAB		1	/* Normal symbol table (.symtab) */
+#define	MDB_DYNSYM		2	/* Dynamic symbol table (.dynsym) */
+
+#define	MDB_BIND_LOCAL		0x0001	/* Local (static-scope) symbols */
+#define	MDB_BIND_GLOBAL		0x0002	/* Global symbols */
+#define	MDB_BIND_WEAK		0x0004	/* Weak binding symbols */
+#define	MDB_BIND_ANY		0x0007	/* Any of the above */
+
+#define	MDB_TYPE_NOTYPE		0x0100	/* Symbol has no type */
+#define	MDB_TYPE_OBJECT		0x0200	/* Symbol refers to data */
+#define	MDB_TYPE_FUNC		0x0400	/* Symbol refers to text */
+#define	MDB_TYPE_SECT		0x0800	/* Symbol refers to a section */
+#define	MDB_TYPE_FILE		0x1000	/* Symbol refers to a source file */
+#define	MDB_TYPE_COMMON		0x2000	/* Symbol refers to a common block */
+#define	MDB_TYPE_TLS		0x4000	/* Symbol refers to TLS */
+
+#define	MDB_TYPE_ANY		0x7f00	/* Any of the above */
+
+typedef int (*mdb_symbol_cb_t)(mdb_symbol_t *, void *);
+extern int mdb_symbol_iter(const char *, uint_t, uint_t, mdb_symbol_cb_t,
+    void *);
+
 #define	MDB_STATE_IDLE		0	/* Target is idle (not running yet) */
 #define	MDB_STATE_RUNNING	1	/* Target is currently executing */
 #define	MDB_STATE_STOPPED	2	/* Target is stopped */
--- a/usr/src/cmd/mdb/common/mdb/mdb_target.h	Sun Aug 04 08:48:11 2013 -0700
+++ b/usr/src/cmd/mdb/common/mdb/mdb_target.h	Mon Nov 14 15:57:40 2011 -0800
@@ -27,8 +27,6 @@
 #ifndef	_MDB_TARGET_H
 #define	_MDB_TARGET_H
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 #include <sys/utsname.h>
 #include <sys/types.h>
 #include <gelf.h>
@@ -232,7 +230,11 @@
 
 /*
  * Values for selecting symbols of interest by binding and type.  These flags
- * can be used to construct a bitmask to pass to mdb_tgt_symbol_iter():
+ * can be used to construct a bitmask to pass to mdb_tgt_symbol_iter().  The
+ * module API has its own slightly different names for these values.  If you are
+ * adding a new flag here, you should consider exposing it in the module API.
+ * If you are changing these flags and their meanings, you will need to update
+ * the module API implementation to account for those changes.
  */
 #define	MDB_TGT_BIND_LOCAL	0x0001	/* Local (static-scope) symbols */
 #define	MDB_TGT_BIND_GLOBAL	0x0002	/* Global symbols */
--- a/usr/src/cmd/mdb/common/modules/conf/mapfile-extern	Sun Aug 04 08:48:11 2013 -0700
+++ b/usr/src/cmd/mdb/common/modules/conf/mapfile-extern	Mon Nov 14 15:57:40 2011 -0800
@@ -148,6 +148,7 @@
 		mdb_set_pipe			{ FLAGS = EXTERN };
 		mdb_snprintf			{ FLAGS = EXTERN };
 		mdb_strtoull			{ FLAGS = EXTERN };
+		mdb_symbol_iter			{ FLAGS = EXTERN };
 		mdb_tgt_notsup			{ FLAGS = EXTERN };
 		mdb_vnode2path			{ FLAGS = EXTERN };
 		mdb_vread			{ FLAGS = EXTERN };