Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src Add a "sifting" command to ddb (named from the Sun OpenPROM ...



details:   https://anonhg.NetBSD.org/src/rev/0fd3c244cb6a
branches:  trunk
changeset: 486440:0fd3c244cb6a
user:      jhawk <jhawk%NetBSD.org@localhost>
date:      Mon May 22 14:49:10 2000 +0000

description:
Add a "sifting" command to ddb (named from the Sun OpenPROM command of
the same name); it searches the symbol table(s) for all symbols matching
a given substring, and prints.

Extremely useful for when you forget that critical symbol name.

Also, with /F support (cf. "ls -F") to print a char indicating the
symbol type.

diffstat:

 share/man/man4/ddb.4 |   38 +++++++++++++++-
 sys/ddb/db_aout.c    |   50 ++++++++++++++++++++-
 sys/ddb/db_command.c |   37 ++++++++++++++-
 sys/ddb/db_command.h |    3 +-
 sys/ddb/db_elf.c     |   47 +++++++++++++++++++-
 sys/ddb/db_sym.c     |  123 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 sys/ddb/db_sym.h     |   21 ++++++++-
 7 files changed, 312 insertions(+), 7 deletions(-)

diffs (truncated from 487 to 300 lines):

diff -r ee175aac68f9 -r 0fd3c244cb6a share/man/man4/ddb.4
--- a/share/man/man4/ddb.4      Mon May 22 12:42:46 2000 +0000
+++ b/share/man/man4/ddb.4      Mon May 22 14:49:10 2000 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: ddb.4,v 1.45 2000/05/22 11:46:07 jhawk Exp $
+.\"    $NetBSD: ddb.4,v 1.46 2000/05/22 14:49:11 jhawk Exp $
 .\"
 .\" Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -587,6 +587,42 @@
 .It Ic "show watches"
 Display all watchpoints.
 .It Xo
+.Ic sifting Ns Op Cm /F
+.Ar string
+.Xc
+Search the symbol tables for all symbols of which
+.Ar string
+is a substring, and display them. If
+.Cm /F
+is specified, a character is displayed immediately after each symbol
+name indicating the type of symbol.
+.Pp
+For
+.Ns Xr a.out 5 -format
+symbol tables, 
+absolute symbols display
+.Sy @ ,
+text segment symbols display
+.Sy * ,
+data segment symbols display
+.Sy + ,
+.Tn BSS
+segment symbols display
+.Sy - ,
+and filename symbols display
+.Sy / .
+For
+.Tn ELF Ns -format
+symbol tables,
+object symbols display
+.Sy + ,
+function symbols display
+.Sy * ,
+section symbols display
+.Sy & ,
+and file symbols display
+.Sy / .
+.It Xo
 .Ic step Ns Op Cm /p
 .Op Cm , Ns Ar count
 .Xc
diff -r ee175aac68f9 -r 0fd3c244cb6a sys/ddb/db_aout.c
--- a/sys/ddb/db_aout.c Mon May 22 12:42:46 2000 +0000
+++ b/sys/ddb/db_aout.c Mon May 22 14:49:10 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: db_aout.c,v 1.27 2000/03/30 11:31:26 augustss Exp $    */
+/*     $NetBSD: db_aout.c,v 1.28 2000/05/22 14:49:10 jhawk Exp $       */
 
 /* 
  * Mach Operating System
@@ -51,6 +51,8 @@
                    char **, int *, db_expr_t));
 boolean_t      db_aout_sym_numargs __P((db_symtab_t *, db_sym_t, int *,
                    char **));
+void           db_aout_forall __P((db_symtab_t *,
+                   db_forall_func_t db_forall_func, void *));
 
 db_symformat_t db_symformat_aout = {
        "a.out",
@@ -60,6 +62,7 @@
        db_aout_symbol_values,
        db_aout_line_at_pc,
        db_aout_sym_numargs,
+       db_aout_forall
 };
 
 /*
@@ -346,4 +349,49 @@
        }
        return FALSE;
 }
+
+void
+db_aout_forall(stab, db_forall_func, arg)
+       db_symtab_t             *stab;
+       db_forall_func_t        db_forall_func;
+       void                    *arg;
+{
+       static char suffix[2];
+       struct nlist *sp, *ep;
+
+       sp = (struct nlist *)stab->start;
+       ep = (struct nlist *)stab->end;
+
+       for (; sp < ep; sp++) {
+           if (sp->n_un.n_name == 0)
+               continue;
+           if ((sp->n_type & N_STAB) == 0 && sp->n_un.n_name != 0) {
+                   suffix[1] = '\0';
+                   switch(sp->n_type & N_TYPE) {
+                   case N_ABS:
+                           suffix[0] = '@';
+                           break;
+                   case N_TEXT:
+                           suffix[0] = '*';
+                           break;
+                   case N_DATA:
+                           suffix[0] = '+';
+                           break;
+                   case N_BSS:
+                           suffix[0] = '-';
+                           break;
+                   case N_FN:
+                           suffix[0] = '/';
+                           break;
+                   default:
+                           suffix[0] = '\0';
+                   }
+                   (*db_forall_func)(stab, (db_sym_t)sp, sp->n_un.n_name,
+                       suffix, '_', arg);
+           }
+       }
+       return;
+}
+
+       
 #endif /* DB_AOUT_SYMBOLS */
diff -r ee175aac68f9 -r 0fd3c244cb6a sys/ddb/db_command.c
--- a/sys/ddb/db_command.c      Mon May 22 12:42:46 2000 +0000
+++ b/sys/ddb/db_command.c      Mon May 22 14:49:10 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: db_command.c,v 1.40 2000/05/20 03:08:41 jhawk Exp $    */
+/*     $NetBSD: db_command.c,v 1.41 2000/05/22 14:49:10 jhawk Exp $    */
 
 /* 
  * Mach Operating System
@@ -481,6 +481,7 @@
        { "search",     db_search_cmd,          CS_OWN|CS_SET_DOT, NULL },
        { "set",        db_set_cmd,             CS_OWN,         NULL },
        { "show",       NULL,                   0,              db_show_cmds },
+       { "sifting",    db_sifting_cmd,         CS_OWN,         NULL },
        { "step",       db_single_step_cmd,     0,              NULL },
        { "sync",       db_sync_cmd,            CS_OWN,         NULL },
        { "trace",      db_stack_trace_cmd,     0,              NULL },
@@ -646,6 +647,40 @@
 }
 
 void
+db_sifting_cmd(addr, have_addr, count, omodif)
+       db_expr_t       addr;
+       int             have_addr;
+       db_expr_t       count;
+       char *          omodif;
+{
+       int     mode, t;
+
+       t = db_read_token();
+       if (t == tSLASH) {
+               t = db_read_token();
+               if (t != tIDENT) {
+                       bad_modifier:
+                       db_printf("Bad modifier\n");
+                       db_flush_lex();
+                       return;
+               }
+               if (!strcmp(db_tok_string, "F"))
+                       mode = 'F';
+               else
+                       goto bad_modifier;
+               t = db_read_token();
+       } else
+               mode = 0;
+
+       if (t==tIDENT)
+               db_sifting(db_tok_string, mode);
+       else {
+               db_printf("Bad argument (non-string)\n");
+               db_flush_lex();
+       }
+}
+
+void
 db_sync_cmd(addr, have_addr, count, modif)
        db_expr_t       addr;
        int             have_addr;
diff -r ee175aac68f9 -r 0fd3c244cb6a sys/ddb/db_command.h
--- a/sys/ddb/db_command.h      Mon May 22 12:42:46 2000 +0000
+++ b/sys/ddb/db_command.h      Mon May 22 14:49:10 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: db_command.h,v 1.15 2000/04/10 02:22:13 chs Exp $      */
+/*     $NetBSD: db_command.h,v 1.16 2000/05/22 14:49:10 jhawk Exp $    */
 
 /* 
  * Mach Operating System
@@ -48,6 +48,7 @@
 void db_error __P((char *));
 void db_fncall __P((db_expr_t, int, db_expr_t, char *));
 void db_reboot_cmd __P((db_expr_t, int, db_expr_t, char *));
+void db_sifting_cmd __P((db_expr_t, int, db_expr_t, char *));
 void db_sync_cmd __P((db_expr_t, int, db_expr_t, char *));
 
 db_addr_t      db_dot;         /* current location */
diff -r ee175aac68f9 -r 0fd3c244cb6a sys/ddb/db_elf.c
--- a/sys/ddb/db_elf.c  Mon May 22 12:42:46 2000 +0000
+++ b/sys/ddb/db_elf.c  Mon May 22 14:49:10 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: db_elf.c,v 1.10 1999/10/25 13:55:06 kleink Exp $       */
+/*     $NetBSD: db_elf.c,v 1.11 2000/05/22 14:49:10 jhawk Exp $        */
 
 /*-
  * Copyright (c) 1997 The NetBSD Foundation, Inc.
@@ -75,6 +75,8 @@
                    char **, int *, db_expr_t));
 boolean_t      db_elf_sym_numargs __P((db_symtab_t *, db_sym_t, int *,
                    char **));
+void           db_elf_forall __P((db_symtab_t *,
+                   db_forall_func_t db_forall_func, void *));
 
 db_symformat_t db_symformat_elf = {
        "ELF",
@@ -84,6 +86,7 @@
        db_elf_symbol_values,
        db_elf_line_at_pc,
        db_elf_sym_numargs,
+       db_elf_forall
 };
 
 /*
@@ -397,4 +400,46 @@
         */
        return (FALSE);
 }
+
+void
+db_elf_forall(stab, db_forall_func, arg)
+       db_symtab_t *stab;
+       db_forall_func_t db_forall_func;
+       void *arg;
+{
+       char *strtab;
+       static char suffix[2];
+       Elf_Sym *symp, *symtab_start, *symtab_end;
+
+       symtab_start = STAB_TO_SYMSTART(stab);
+       symtab_end = STAB_TO_SYMEND(stab);
+
+       strtab = db_elf_find_strtab(stab);
+       if (strtab == NULL)
+               return;
+
+       for (symp = symtab_start; symp < symtab_end; symp++)
+               if (symp->st_name != 0) {
+                       suffix[1] = '\0';
+                       switch (ELFDEFNNAME(ST_TYPE)(symp->st_info)) {
+                       case STT_OBJECT:
+                               suffix[0] = '+';
+                               break;
+                       case STT_FUNC:
+                               suffix[0] = '*';
+                               break;
+                       case STT_SECTION:
+                               suffix[0] = '&';
+                               break;
+                       case STT_FILE:
+                               suffix[0] = '/';
+                               break;
+                       default:
+                               suffix[0] = '\0';
+                       }
+                       (*db_forall_func)(stab, (db_sym_t)symp,
+                           strtab + symp->st_name, suffix, 0, arg);
+               }
+       return;
+}
 #endif /* DB_ELF_SYMBOLS */
diff -r ee175aac68f9 -r 0fd3c244cb6a sys/ddb/db_sym.c
--- a/sys/ddb/db_sym.c  Mon May 22 12:42:46 2000 +0000
+++ b/sys/ddb/db_sym.c  Mon May 22 14:49:10 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: db_sym.c,v 1.19 2000/03/30 11:31:27 augustss Exp $     */
+/*     $NetBSD: db_sym.c,v 1.20 2000/05/22 14:49:10 jhawk Exp $        */
 
 /* 
  * Mach Operating System
@@ -32,6 +32,7 @@
 
 #include <machine/db_machdep.h>
 
+#include <ddb/db_lex.h>
 #include <ddb/db_sym.h>
 #include <ddb/db_output.h>
 #include <ddb/db_extern.h>
@@ -53,6 +54,7 @@
 db_symtab_t    *db_last_symtab;
 
 static char *db_qualify __P((db_sym_t, const char *));
+static db_forall_func_t db_sift;
 
 /*



Home | Main Index | Thread Index | Old Index