3602 mdb should tab complete global symbols
Reviewed by: Matt Amdur <
[email protected]>
Reviewed by: Adam Leventhal <
[email protected]>
Reviewed by: Carlos Cardenas <
[email protected]>
Reviewed by: Robert Mustacchi <
[email protected]>
Approved by: Dan McDonald <
[email protected]>
--- a/usr/src/cmd/mdb/common/mdb/mdb_tab.c Fri Mar 08 10:41:28 2013 -0800
+++ b/usr/src/cmd/mdb/common/mdb/mdb_tab.c Mon Mar 11 10:48:46 2013 -0800
@@ -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 @@
*/
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 @@
/*
* 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 @@
{
}
+/*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
--- a/usr/src/cmd/mdb/common/mdb/mdb_tab.h Fri Mar 08 10:41:28 2013 -0800
+++ b/usr/src/cmd/mdb/common/mdb/mdb_tab.h Mon Mar 11 10:48:46 2013 -0800
@@ -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 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,