summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHenrik Mattsson <henrik.mattsson@delphix.com>2013-03-11 10:48:46 -0800
committerChristopher Siden <chris.siden@delphix.com>2013-03-11 11:48:47 -0700
commit72a1114bccf02392ab254b9615412236f3b63256 (patch)
tree13c155fac1110918a3437d25a1183b9c64a7e8fb
parentbe6fd75a69ae679453d9cda5bff3326111e6d1ca (diff)
downloadillumos-joyent-72a1114bccf02392ab254b9615412236f3b63256.tar.gz
3602 mdb should tab complete global symbols
Reviewed by: Matt Amdur <matt.amdur@delphix.com> Reviewed by: Adam Leventhal <ahl@delphix.com> Reviewed by: Carlos Cardenas <cardenas12@gmail.com> Reviewed by: Robert Mustacchi <rm@joyent.com> Approved by: Dan McDonald <danmcd@nexenta.com>
-rw-r--r--usr/src/cmd/mdb/common/mdb/mdb_tab.c35
-rw-r--r--usr/src/cmd/mdb/common/mdb/mdb_tab.h4
2 files changed, 34 insertions, 5 deletions
diff --git a/usr/src/cmd/mdb/common/mdb/mdb_tab.c b/usr/src/cmd/mdb/common/mdb/mdb_tab.c
index e2694f1d91..0fc5b3644e 100644
--- a/usr/src/cmd/mdb/common/mdb/mdb_tab.c
+++ b/usr/src/cmd/mdb/common/mdb/mdb_tab.c
@@ -19,7 +19,7 @@
* CDDL HEADER END
*/
/*
- * Copyright (c) 2012 by Delphix. All rights reserved.
+ * Copyright (c) 2013 by Delphix. All rights reserved.
* Copyright (c) 2012 Joyent, Inc. All rights reserved.
*/
/*
@@ -43,6 +43,7 @@
#include <mdb/mdb_print.h>
#include <mdb/mdb_nv.h>
#include <mdb/mdb_tab.h>
+#include <mdb/mdb_target.h>
#include <mdb/mdb.h>
#include <ctype.h>
@@ -282,7 +283,11 @@ mdb_tab_command(mdb_tab_cookie_t *mcp, const char *buf)
*/
ret = tab_parse_buf(data, &dcmd, &argc, &argv, &flags);
+ /*
+ * Match against global symbols if the input is not a dcmd
+ */
if (ret != 0) {
+ (void) mdb_tab_complete_global(mcp, buf);
goto out;
}
@@ -293,8 +298,9 @@ mdb_tab_command(mdb_tab_cookie_t *mcp, const char *buf)
/*
* When argc is zero it indicates that we are trying to tab complete
- * a dcmd. Note, that if there isn't the start of a dcmd, i.e. ::, then
- * we will have already bailed in the call to tab_parse_buf.
+ * a dcmd or a global symbol. Note, that if there isn't the start of
+ * a dcmd, i.e. ::, then we will have already bailed in the call to
+ * tab_parse_buf.
*/
if (cp == NULL && argc != 0) {
goto out;
@@ -482,6 +488,29 @@ mdb_tab_fini(mdb_tab_cookie_t *mcp)
{
}
+/*ARGSUSED*/
+static int
+tab_complete_global(void *arg, const GElf_Sym *sym, const char *name,
+ const mdb_syminfo_t *sip, const char *obj)
+{
+ mdb_tab_cookie_t *mcp = arg;
+ mdb_tab_insert(mcp, name);
+ return (0);
+}
+
+/*
+ * This function tab completes against all loaded global symbols.
+ */
+int
+mdb_tab_complete_global(mdb_tab_cookie_t *mcp, const char *name)
+{
+ mdb_tab_setmbase(mcp, name);
+ (void) mdb_tgt_symbol_iter(mdb.m_target, MDB_TGT_OBJ_EVERY,
+ MDB_TGT_SYMTAB, MDB_TGT_BIND_GLOBAL | MDB_TGT_TYPE_OBJECT |
+ MDB_TGT_TYPE_FUNC, tab_complete_global, mcp);
+ return (0);
+}
+
/*
* This function takes a ctf id and determines whether or not the associated
* type should be considered as a potential match for the given tab
diff --git a/usr/src/cmd/mdb/common/mdb/mdb_tab.h b/usr/src/cmd/mdb/common/mdb/mdb_tab.h
index c3a28b2d40..9a433ad75c 100644
--- a/usr/src/cmd/mdb/common/mdb/mdb_tab.h
+++ b/usr/src/cmd/mdb/common/mdb/mdb_tab.h
@@ -19,7 +19,7 @@
* CDDL HEADER END
*/
/*
- * Copyright (c) 2012 by Delphix. All rights reserved.
+ * Copyright (c) 2013 by Delphix. All rights reserved.
* Copyright (c) 2012 Joyent, Inc. All rights reserved.
*/
/*
@@ -55,7 +55,7 @@ extern size_t mdb_tab_size(mdb_tab_cookie_t *);
extern const char *mdb_tab_match(mdb_tab_cookie_t *);
extern void mdb_tab_print(mdb_tab_cookie_t *);
extern void mdb_tab_fini(mdb_tab_cookie_t *);
-
+extern int mdb_tab_complete_global(mdb_tab_cookie_t *, const char *);
extern int mdb_tab_complete_dcmd(mdb_tab_cookie_t *, const char *);
extern int mdb_tab_complete_walker(mdb_tab_cookie_t *, const char *);
extern int mdb_tab_complete_member_by_id(mdb_tab_cookie_t *, mdb_ctf_id_t,