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