Home | History | Annotate | Line # | Download | only in ddb
      1 /*	$NetBSD: db_sym.h,v 1.25 2012/02/10 02:14:23 christos Exp $	*/
      2 
      3 /*
      4  * Mach Operating System
      5  * Copyright (c) 1991,1990 Carnegie Mellon University
      6  * All Rights Reserved.
      7  *
      8  * Permission to use, copy, modify and distribute this software and its
      9  * documentation is hereby granted, provided that both the copyright
     10  * notice and this permission notice appear in all copies of the
     11  * software, derivative works or modified versions, and any portions
     12  * thereof, and that both notices appear in supporting documentation.
     13  *
     14  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     15  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
     16  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     17  *
     18  * Carnegie Mellon requests users of this software to return to
     19  *
     20  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     21  *  School of Computer Science
     22  *  Carnegie Mellon University
     23  *  Pittsburgh PA 15213-3890
     24  *
     25  * any improvements or extensions that they make and grant Carnegie the
     26  * rights to redistribute these changes.
     27  *
     28  * 	Author: Alessandro Forin, Carnegie Mellon University
     29  *	Date:	8/90
     30  */
     31 #include <sys/ksyms.h>
     32 
     33 typedef vaddr_t db_sym_t;
     34 #define	DB_SYM_NULL	((db_sym_t)0)
     35 typedef int		db_strategy_t;	/* search strategy */
     36 
     37 #define	DB_STGY_ANY	(KSYMS_ANY|KSYMS_CLOSEST)    /* anything goes */
     38 #define DB_STGY_XTRN	(KSYMS_EXTERN|KSYMS_CLOSEST) /* only external symbols */
     39 #define DB_STGY_PROC	(KSYMS_PROC|KSYMS_CLOSEST)   /* only procedures */
     40 
     41 #ifndef _KERNEL
     42 /*
     43  * These structures and functions are not used in the kernel, but only
     44  * in crash(8).
     45  */
     46 typedef struct {
     47 	const char	*name;		/* symtab name */
     48 	char		*start;		/* symtab location */
     49 	char		*end;
     50 	char		*private;	/* optional machdep pointer */
     51 } db_symtab_t;
     52 
     53 /*
     54  * Internal db_forall function calling convention:
     55  *
     56  * (*db_forall_func)(stab, sym, name, suffix, prefix, arg);
     57  *
     58  * stab is the symbol table, symbol the (opaque) symbol pointer,
     59  * name the name of the symbol, suffix a string representing
     60  * the type, prefix an initial ignorable function prefix (e.g. "_"
     61  * in a.out), and arg an opaque argument to be passed in.
     62  */
     63 typedef void (db_forall_func_t)
     64 	(db_symtab_t *, db_sym_t, char *, char *, int, void *);
     65 
     66 /*
     67  * A symbol table may be in one of many formats.  All symbol tables
     68  * must be of the same format as the master kernel symbol table.
     69  */
     70 typedef struct {
     71 	const char     *sym_format;
     72 	bool		(*sym_init)(int, void *, void *, const char *);
     73 	db_sym_t	(*sym_lookup)(db_symtab_t *, const char *);
     74 	db_sym_t	(*sym_search)(db_symtab_t *, db_addr_t, db_strategy_t,
     75 			    db_expr_t *);
     76 	void		(*sym_value)(db_symtab_t *, db_sym_t, const char **,
     77 			    db_expr_t *);
     78 	bool		(*sym_line_at_pc)(db_symtab_t *, db_sym_t, char **,
     79 			    int *, db_expr_t);
     80 	bool		(*sym_numargs)(db_symtab_t *, db_sym_t, int *, char **);
     81 	void		(*sym_forall)(db_symtab_t *,
     82 			    db_forall_func_t *db_forall_func, void *);
     83 } db_symformat_t;
     84 #endif
     85 
     86 extern unsigned int db_maxoff;		/* like gdb's "max-symbolic-offset" */
     87 
     88 /*
     89  * Functions exported by the symtable module
     90  */
     91 bool		db_eqname(const char *, const char *, int);
     92 					/* strcmp, modulo leading char */
     93 
     94 bool		db_value_of_name(const char *, db_expr_t *);
     95 					/* find symbol value given name */
     96 
     97 void		db_sifting(char *, int);
     98 				/* print partially matching symbol names */
     99 
    100 db_sym_t	db_search_symbol(db_addr_t, db_strategy_t, db_expr_t *);
    101 					/* find symbol given value */
    102 
    103 void		db_symbol_values(db_sym_t, const char **, db_expr_t *);
    104 					/* return name and value of symbol */
    105 
    106 #define db_find_sym_and_offset(val,namep,offp)	\
    107 	db_symbol_values(db_search_symbol(val,DB_STGY_ANY,offp),namep,0)
    108 					/* find name&value given approx val */
    109 
    110 #define db_find_xtrn_sym_and_offset(val,namep,offp)	\
    111 	db_symbol_values(db_search_symbol(val,DB_STGY_XTRN,offp),namep,0)
    112 					/* ditto, but no locals */
    113 
    114 void		db_symstr(char *, size_t, db_expr_t, db_strategy_t);
    115 void		db_printsym(db_expr_t, db_strategy_t,
    116     void(*)(const char *, ...) __printflike(1, 2));
    117 					/* print closest symbol to a value */
    118 bool		db_sym_numargs(db_sym_t, int *, char **);
    119