1/*- 2 * Mach Operating System 3 * Copyright (c) 1991,1990 Carnegie Mellon University 4 * All Rights Reserved. 5 * 6 * Permission to use, copy, modify and distribute this software and its 7 * documentation is hereby granted, provided that both the copyright 8 * notice and this permission notice appear in all copies of the 9 * software, derivative works or modified versions, and any portions 10 * thereof, and that both notices appear in supporting documentation. 11 * 12 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS 13 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR 14 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 15 * 16 * Carnegie Mellon requests users of this software to return to 17 * 18 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 19 * School of Computer Science 20 * Carnegie Mellon University 21 * Pittsburgh PA 15213-3890 22 * 23 * any improvements or extensions that they make and grant Carnegie the 24 * rights to redistribute these changes. 25 */ 26/* 27 * Author: David B. Golub, Carnegie Mellon University 28 * Date: 7/90 29 */ 30 31#include <sys/cdefs.h>
| 1/*- 2 * Mach Operating System 3 * Copyright (c) 1991,1990 Carnegie Mellon University 4 * All Rights Reserved. 5 * 6 * Permission to use, copy, modify and distribute this software and its 7 * documentation is hereby granted, provided that both the copyright 8 * notice and this permission notice appear in all copies of the 9 * software, derivative works or modified versions, and any portions 10 * thereof, and that both notices appear in supporting documentation. 11 * 12 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS 13 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR 14 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 15 * 16 * Carnegie Mellon requests users of this software to return to 17 * 18 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 19 * School of Computer Science 20 * Carnegie Mellon University 21 * Pittsburgh PA 15213-3890 22 * 23 * any improvements or extensions that they make and grant Carnegie the 24 * rights to redistribute these changes. 25 */ 26/* 27 * Author: David B. Golub, Carnegie Mellon University 28 * Date: 7/90 29 */ 30 31#include <sys/cdefs.h>
|
32__FBSDID("$FreeBSD: head/sys/ddb/db_sym.c 206639 2010-04-14 23:06:07Z julian $");
| 32__FBSDID("$FreeBSD: head/sys/ddb/db_sym.c 273006 2014-10-12 18:01:52Z pfg $");
|
33 34#include <sys/param.h> 35#include <sys/pcpu.h> 36#include <sys/smp.h> 37#include <sys/systm.h> 38 39#include <net/vnet.h> 40 41#include <ddb/ddb.h> 42#include <ddb/db_sym.h> 43#include <ddb/db_variables.h> 44 45#include <opt_ddb.h> 46 47/* 48 * Multiple symbol tables 49 */ 50#ifndef MAXNOSYMTABS 51#define MAXNOSYMTABS 3 /* mach, ux, emulator */ 52#endif 53 54static db_symtab_t db_symtabs[MAXNOSYMTABS] = {{0,},}; 55static int db_nsymtab = 0; 56 57static db_symtab_t *db_last_symtab; /* where last symbol was found */ 58 59static c_db_sym_t db_lookup( const char *symstr); 60static char *db_qualify(c_db_sym_t sym, char *symtabname); 61static boolean_t db_symbol_is_ambiguous(c_db_sym_t sym); 62static boolean_t db_line_at_pc(c_db_sym_t, char **, int *, db_expr_t); 63 64static int db_cpu = -1; 65 66#ifdef VIMAGE 67static void *db_vnet = NULL; 68#endif 69 70/* 71 * Validate the CPU number used to interpret per-CPU variables so we can 72 * avoid later confusion if an invalid CPU is requested. 73 */ 74int 75db_var_db_cpu(struct db_variable *vp, db_expr_t *valuep, int op) 76{ 77 78 switch (op) { 79 case DB_VAR_GET: 80 *valuep = db_cpu; 81 return (1); 82 83 case DB_VAR_SET: 84 if (*(int *)valuep < -1 && *(int *)valuep > mp_maxid) { 85 db_printf("Invalid value: %d", *(int*)valuep); 86 return (0); 87 } 88 db_cpu = *(int *)valuep; 89 return (1); 90 91 default: 92 db_printf("db_var_db_cpu: unknown operation\n"); 93 return (0); 94 } 95} 96 97/* 98 * Read-only variable reporting the current CPU, which is what we use when 99 * db_cpu is set to -1. 100 */ 101int 102db_var_curcpu(struct db_variable *vp, db_expr_t *valuep, int op) 103{ 104 105 switch (op) { 106 case DB_VAR_GET: 107 *valuep = curcpu; 108 return (1); 109 110 case DB_VAR_SET: 111 db_printf("Read-only variable.\n"); 112 return (0); 113 114 default: 115 db_printf("db_var_curcpu: unknown operation\n"); 116 return (0); 117 } 118} 119 120#ifdef VIMAGE 121/* 122 * Validate the virtual network pointer used to interpret per-vnet global 123 * variable expansion. Right now we don't do much here, really we should 124 * walk the global vnet list to check it's an OK pointer. 125 */ 126int 127db_var_db_vnet(struct db_variable *vp, db_expr_t *valuep, int op) 128{ 129 130 switch (op) { 131 case DB_VAR_GET: 132 *valuep = (db_expr_t)db_vnet; 133 return (1); 134 135 case DB_VAR_SET: 136 db_vnet = *(void **)valuep; 137 return (1); 138 139 default: 140 db_printf("db_var_db_vnet: unknown operation\n"); 141 return (0); 142 } 143} 144 145/* 146 * Read-only variable reporting the current vnet, which is what we use when 147 * db_vnet is set to NULL. 148 */ 149int 150db_var_curvnet(struct db_variable *vp, db_expr_t *valuep, int op) 151{ 152 153 switch (op) { 154 case DB_VAR_GET: 155 *valuep = (db_expr_t)curvnet; 156 return (1); 157 158 case DB_VAR_SET: 159 db_printf("Read-only variable.\n"); 160 return (0); 161 162 default: 163 db_printf("db_var_curcpu: unknown operation\n"); 164 return (0); 165 } 166} 167#endif 168 169/* 170 * Add symbol table, with given name, to list of symbol tables. 171 */ 172void
| 33 34#include <sys/param.h> 35#include <sys/pcpu.h> 36#include <sys/smp.h> 37#include <sys/systm.h> 38 39#include <net/vnet.h> 40 41#include <ddb/ddb.h> 42#include <ddb/db_sym.h> 43#include <ddb/db_variables.h> 44 45#include <opt_ddb.h> 46 47/* 48 * Multiple symbol tables 49 */ 50#ifndef MAXNOSYMTABS 51#define MAXNOSYMTABS 3 /* mach, ux, emulator */ 52#endif 53 54static db_symtab_t db_symtabs[MAXNOSYMTABS] = {{0,},}; 55static int db_nsymtab = 0; 56 57static db_symtab_t *db_last_symtab; /* where last symbol was found */ 58 59static c_db_sym_t db_lookup( const char *symstr); 60static char *db_qualify(c_db_sym_t sym, char *symtabname); 61static boolean_t db_symbol_is_ambiguous(c_db_sym_t sym); 62static boolean_t db_line_at_pc(c_db_sym_t, char **, int *, db_expr_t); 63 64static int db_cpu = -1; 65 66#ifdef VIMAGE 67static void *db_vnet = NULL; 68#endif 69 70/* 71 * Validate the CPU number used to interpret per-CPU variables so we can 72 * avoid later confusion if an invalid CPU is requested. 73 */ 74int 75db_var_db_cpu(struct db_variable *vp, db_expr_t *valuep, int op) 76{ 77 78 switch (op) { 79 case DB_VAR_GET: 80 *valuep = db_cpu; 81 return (1); 82 83 case DB_VAR_SET: 84 if (*(int *)valuep < -1 && *(int *)valuep > mp_maxid) { 85 db_printf("Invalid value: %d", *(int*)valuep); 86 return (0); 87 } 88 db_cpu = *(int *)valuep; 89 return (1); 90 91 default: 92 db_printf("db_var_db_cpu: unknown operation\n"); 93 return (0); 94 } 95} 96 97/* 98 * Read-only variable reporting the current CPU, which is what we use when 99 * db_cpu is set to -1. 100 */ 101int 102db_var_curcpu(struct db_variable *vp, db_expr_t *valuep, int op) 103{ 104 105 switch (op) { 106 case DB_VAR_GET: 107 *valuep = curcpu; 108 return (1); 109 110 case DB_VAR_SET: 111 db_printf("Read-only variable.\n"); 112 return (0); 113 114 default: 115 db_printf("db_var_curcpu: unknown operation\n"); 116 return (0); 117 } 118} 119 120#ifdef VIMAGE 121/* 122 * Validate the virtual network pointer used to interpret per-vnet global 123 * variable expansion. Right now we don't do much here, really we should 124 * walk the global vnet list to check it's an OK pointer. 125 */ 126int 127db_var_db_vnet(struct db_variable *vp, db_expr_t *valuep, int op) 128{ 129 130 switch (op) { 131 case DB_VAR_GET: 132 *valuep = (db_expr_t)db_vnet; 133 return (1); 134 135 case DB_VAR_SET: 136 db_vnet = *(void **)valuep; 137 return (1); 138 139 default: 140 db_printf("db_var_db_vnet: unknown operation\n"); 141 return (0); 142 } 143} 144 145/* 146 * Read-only variable reporting the current vnet, which is what we use when 147 * db_vnet is set to NULL. 148 */ 149int 150db_var_curvnet(struct db_variable *vp, db_expr_t *valuep, int op) 151{ 152 153 switch (op) { 154 case DB_VAR_GET: 155 *valuep = (db_expr_t)curvnet; 156 return (1); 157 158 case DB_VAR_SET: 159 db_printf("Read-only variable.\n"); 160 return (0); 161 162 default: 163 db_printf("db_var_curcpu: unknown operation\n"); 164 return (0); 165 } 166} 167#endif 168 169/* 170 * Add symbol table, with given name, to list of symbol tables. 171 */ 172void
|
173db_add_symbol_table(start, end, name, ref) 174 char *start; 175 char *end; 176 char *name; 177 char *ref;
| 173db_add_symbol_table(char *start, char *end, char *name, char *ref)
|
178{ 179 if (db_nsymtab >= MAXNOSYMTABS) { 180 printf ("No slots left for %s symbol table", name); 181 panic ("db_sym.c: db_add_symbol_table"); 182 } 183 184 db_symtabs[db_nsymtab].start = start; 185 db_symtabs[db_nsymtab].end = end; 186 db_symtabs[db_nsymtab].name = name; 187 db_symtabs[db_nsymtab].private = ref; 188 db_nsymtab++; 189} 190 191/* 192 * db_qualify("vm_map", "ux") returns "unix:vm_map". 193 * 194 * Note: return value points to static data whose content is 195 * overwritten by each call... but in practice this seems okay. 196 */ 197static char *
| 174{ 175 if (db_nsymtab >= MAXNOSYMTABS) { 176 printf ("No slots left for %s symbol table", name); 177 panic ("db_sym.c: db_add_symbol_table"); 178 } 179 180 db_symtabs[db_nsymtab].start = start; 181 db_symtabs[db_nsymtab].end = end; 182 db_symtabs[db_nsymtab].name = name; 183 db_symtabs[db_nsymtab].private = ref; 184 db_nsymtab++; 185} 186 187/* 188 * db_qualify("vm_map", "ux") returns "unix:vm_map". 189 * 190 * Note: return value points to static data whose content is 191 * overwritten by each call... but in practice this seems okay. 192 */ 193static char *
|
198db_qualify(sym, symtabname) 199 c_db_sym_t sym; 200 register char *symtabname;
| 194db_qualify(c_db_sym_t sym, char *symtabname)
|
201{ 202 const char *symname; 203 static char tmp[256]; 204 205 db_symbol_values(sym, &symname, 0); 206 snprintf(tmp, sizeof(tmp), "%s:%s", symtabname, symname); 207 return tmp; 208} 209 210 211boolean_t
| 195{ 196 const char *symname; 197 static char tmp[256]; 198 199 db_symbol_values(sym, &symname, 0); 200 snprintf(tmp, sizeof(tmp), "%s:%s", symtabname, symname); 201 return tmp; 202} 203 204 205boolean_t
|
212db_eqname(src, dst, c) 213 const char *src; 214 const char *dst; 215 int c;
| 206db_eqname(const char *src, const char *dst, int c)
|
216{ 217 if (!strcmp(src, dst)) 218 return (TRUE); 219 if (src[0] == c) 220 return (!strcmp(src+1,dst)); 221 return (FALSE); 222} 223 224boolean_t
| 207{ 208 if (!strcmp(src, dst)) 209 return (TRUE); 210 if (src[0] == c) 211 return (!strcmp(src+1,dst)); 212 return (FALSE); 213} 214 215boolean_t
|
225db_value_of_name(name, valuep) 226 const char *name; 227 db_expr_t *valuep;
| 216db_value_of_name(const char *name, db_expr_t *valuep)
|
228{ 229 c_db_sym_t sym; 230 231 sym = db_lookup(name); 232 if (sym == C_DB_SYM_NULL) 233 return (FALSE); 234 db_symbol_values(sym, &name, valuep); 235 return (TRUE); 236} 237 238boolean_t
| 217{ 218 c_db_sym_t sym; 219 220 sym = db_lookup(name); 221 if (sym == C_DB_SYM_NULL) 222 return (FALSE); 223 db_symbol_values(sym, &name, valuep); 224 return (TRUE); 225} 226 227boolean_t
|
239db_value_of_name_pcpu(name, valuep) 240 const char *name; 241 db_expr_t *valuep;
| 228db_value_of_name_pcpu(const char *name, db_expr_t *valuep)
|
242{ 243 static char tmp[256]; 244 db_expr_t value; 245 c_db_sym_t sym; 246 int cpu; 247 248 if (db_cpu != -1) 249 cpu = db_cpu; 250 else 251 cpu = curcpu; 252 snprintf(tmp, sizeof(tmp), "pcpu_entry_%s", name); 253 sym = db_lookup(tmp); 254 if (sym == C_DB_SYM_NULL) 255 return (FALSE); 256 db_symbol_values(sym, &name, &value); 257 if (value < DPCPU_START || value >= DPCPU_STOP) 258 return (FALSE); 259 *valuep = (db_expr_t)((uintptr_t)value + dpcpu_off[cpu]); 260 return (TRUE); 261} 262 263boolean_t
| 229{ 230 static char tmp[256]; 231 db_expr_t value; 232 c_db_sym_t sym; 233 int cpu; 234 235 if (db_cpu != -1) 236 cpu = db_cpu; 237 else 238 cpu = curcpu; 239 snprintf(tmp, sizeof(tmp), "pcpu_entry_%s", name); 240 sym = db_lookup(tmp); 241 if (sym == C_DB_SYM_NULL) 242 return (FALSE); 243 db_symbol_values(sym, &name, &value); 244 if (value < DPCPU_START || value >= DPCPU_STOP) 245 return (FALSE); 246 *valuep = (db_expr_t)((uintptr_t)value + dpcpu_off[cpu]); 247 return (TRUE); 248} 249 250boolean_t
|
264db_value_of_name_vnet(name, valuep) 265 const char *name; 266 db_expr_t *valuep;
| 251db_value_of_name_vnet(const char *name, db_expr_t *valuep)
|
267{ 268#ifdef VIMAGE 269 static char tmp[256]; 270 db_expr_t value; 271 c_db_sym_t sym; 272 struct vnet *vnet; 273 274 if (db_vnet != NULL) 275 vnet = db_vnet; 276 else 277 vnet = curvnet; 278 snprintf(tmp, sizeof(tmp), "vnet_entry_%s", name); 279 sym = db_lookup(tmp); 280 if (sym == C_DB_SYM_NULL) 281 return (FALSE); 282 db_symbol_values(sym, &name, &value); 283 if (value < VNET_START || value >= VNET_STOP) 284 return (FALSE); 285 *valuep = (db_expr_t)((uintptr_t)value + vnet->vnet_data_base); 286 return (TRUE); 287#else 288 return (FALSE); 289#endif 290} 291 292/* 293 * Lookup a symbol. 294 * If the symbol has a qualifier (e.g., ux:vm_map), 295 * then only the specified symbol table will be searched; 296 * otherwise, all symbol tables will be searched. 297 */ 298static c_db_sym_t
| 252{ 253#ifdef VIMAGE 254 static char tmp[256]; 255 db_expr_t value; 256 c_db_sym_t sym; 257 struct vnet *vnet; 258 259 if (db_vnet != NULL) 260 vnet = db_vnet; 261 else 262 vnet = curvnet; 263 snprintf(tmp, sizeof(tmp), "vnet_entry_%s", name); 264 sym = db_lookup(tmp); 265 if (sym == C_DB_SYM_NULL) 266 return (FALSE); 267 db_symbol_values(sym, &name, &value); 268 if (value < VNET_START || value >= VNET_STOP) 269 return (FALSE); 270 *valuep = (db_expr_t)((uintptr_t)value + vnet->vnet_data_base); 271 return (TRUE); 272#else 273 return (FALSE); 274#endif 275} 276 277/* 278 * Lookup a symbol. 279 * If the symbol has a qualifier (e.g., ux:vm_map), 280 * then only the specified symbol table will be searched; 281 * otherwise, all symbol tables will be searched. 282 */ 283static c_db_sym_t
|
299db_lookup(symstr) 300 const char *symstr;
| 284db_lookup(const char *symstr)
|
301{ 302 c_db_sym_t sp; 303 register int i; 304 int symtab_start = 0; 305 int symtab_end = db_nsymtab; 306 register const char *cp; 307 308 /* 309 * Look for, remove, and remember any symbol table specifier. 310 */ 311 for (cp = symstr; *cp; cp++) { 312 if (*cp == ':') { 313 for (i = 0; i < db_nsymtab; i++) { 314 int n = strlen(db_symtabs[i].name); 315 316 if ( 317 n == (cp - symstr) && 318 strncmp(symstr, db_symtabs[i].name, n) == 0 319 ) { 320 symtab_start = i; 321 symtab_end = i + 1; 322 break; 323 } 324 } 325 if (i == db_nsymtab) { 326 db_error("invalid symbol table name"); 327 } 328 symstr = cp+1; 329 } 330 } 331 332 /* 333 * Look in the specified set of symbol tables. 334 * Return on first match. 335 */ 336 for (i = symtab_start; i < symtab_end; i++) { 337 sp = X_db_lookup(&db_symtabs[i], symstr); 338 if (sp) { 339 db_last_symtab = &db_symtabs[i]; 340 return sp; 341 } 342 } 343 return 0; 344} 345 346/* 347 * If TRUE, check across symbol tables for multiple occurrences 348 * of a name. Might slow things down quite a bit. 349 */ 350static volatile boolean_t db_qualify_ambiguous_names = FALSE; 351 352/* 353 * Does this symbol name appear in more than one symbol table? 354 * Used by db_symbol_values to decide whether to qualify a symbol. 355 */ 356static boolean_t
| 285{ 286 c_db_sym_t sp; 287 register int i; 288 int symtab_start = 0; 289 int symtab_end = db_nsymtab; 290 register const char *cp; 291 292 /* 293 * Look for, remove, and remember any symbol table specifier. 294 */ 295 for (cp = symstr; *cp; cp++) { 296 if (*cp == ':') { 297 for (i = 0; i < db_nsymtab; i++) { 298 int n = strlen(db_symtabs[i].name); 299 300 if ( 301 n == (cp - symstr) && 302 strncmp(symstr, db_symtabs[i].name, n) == 0 303 ) { 304 symtab_start = i; 305 symtab_end = i + 1; 306 break; 307 } 308 } 309 if (i == db_nsymtab) { 310 db_error("invalid symbol table name"); 311 } 312 symstr = cp+1; 313 } 314 } 315 316 /* 317 * Look in the specified set of symbol tables. 318 * Return on first match. 319 */ 320 for (i = symtab_start; i < symtab_end; i++) { 321 sp = X_db_lookup(&db_symtabs[i], symstr); 322 if (sp) { 323 db_last_symtab = &db_symtabs[i]; 324 return sp; 325 } 326 } 327 return 0; 328} 329 330/* 331 * If TRUE, check across symbol tables for multiple occurrences 332 * of a name. Might slow things down quite a bit. 333 */ 334static volatile boolean_t db_qualify_ambiguous_names = FALSE; 335 336/* 337 * Does this symbol name appear in more than one symbol table? 338 * Used by db_symbol_values to decide whether to qualify a symbol. 339 */ 340static boolean_t
|
357db_symbol_is_ambiguous(sym) 358 c_db_sym_t sym;
| 341db_symbol_is_ambiguous(c_db_sym_t sym)
|
359{ 360 const char *sym_name; 361 register int i; 362 register 363 boolean_t found_once = FALSE; 364 365 if (!db_qualify_ambiguous_names) 366 return FALSE; 367 368 db_symbol_values(sym, &sym_name, 0); 369 for (i = 0; i < db_nsymtab; i++) { 370 if (X_db_lookup(&db_symtabs[i], sym_name)) { 371 if (found_once) 372 return TRUE; 373 found_once = TRUE; 374 } 375 } 376 return FALSE; 377} 378 379/* 380 * Find the closest symbol to val, and return its name 381 * and the difference between val and the symbol found. 382 */ 383c_db_sym_t
| 342{ 343 const char *sym_name; 344 register int i; 345 register 346 boolean_t found_once = FALSE; 347 348 if (!db_qualify_ambiguous_names) 349 return FALSE; 350 351 db_symbol_values(sym, &sym_name, 0); 352 for (i = 0; i < db_nsymtab; i++) { 353 if (X_db_lookup(&db_symtabs[i], sym_name)) { 354 if (found_once) 355 return TRUE; 356 found_once = TRUE; 357 } 358 } 359 return FALSE; 360} 361 362/* 363 * Find the closest symbol to val, and return its name 364 * and the difference between val and the symbol found. 365 */ 366c_db_sym_t
|
384db_search_symbol( val, strategy, offp) 385 register db_addr_t val; 386 db_strategy_t strategy; 387 db_expr_t *offp;
| 367db_search_symbol(db_addr_t val, db_strategy_t strategy, db_expr_t *offp)
|
388{ 389 register 390 unsigned int diff; 391 size_t newdiff; 392 register int i; 393 c_db_sym_t ret = C_DB_SYM_NULL, sym; 394 395 newdiff = diff = ~0; 396 for (i = 0; i < db_nsymtab; i++) { 397 sym = X_db_search_symbol(&db_symtabs[i], val, strategy, &newdiff); 398 if (newdiff < diff) { 399 db_last_symtab = &db_symtabs[i]; 400 diff = newdiff; 401 ret = sym; 402 } 403 } 404 *offp = diff; 405 return ret; 406} 407 408/* 409 * Return name and value of a symbol 410 */ 411void
| 368{ 369 register 370 unsigned int diff; 371 size_t newdiff; 372 register int i; 373 c_db_sym_t ret = C_DB_SYM_NULL, sym; 374 375 newdiff = diff = ~0; 376 for (i = 0; i < db_nsymtab; i++) { 377 sym = X_db_search_symbol(&db_symtabs[i], val, strategy, &newdiff); 378 if (newdiff < diff) { 379 db_last_symtab = &db_symtabs[i]; 380 diff = newdiff; 381 ret = sym; 382 } 383 } 384 *offp = diff; 385 return ret; 386} 387 388/* 389 * Return name and value of a symbol 390 */ 391void
|
412db_symbol_values(sym, namep, valuep) 413 c_db_sym_t sym; 414 const char **namep; 415 db_expr_t *valuep;
| 392db_symbol_values(c_db_sym_t sym, const char **namep, db_expr_t *valuep)
|
416{ 417 db_expr_t value; 418 419 if (sym == DB_SYM_NULL) { 420 *namep = 0; 421 return; 422 } 423 424 X_db_symbol_values(db_last_symtab, sym, namep, &value); 425 426 if (db_symbol_is_ambiguous(sym)) 427 *namep = db_qualify(sym, db_last_symtab->name); 428 if (valuep) 429 *valuep = value; 430} 431 432 433/* 434 * Print a the closest symbol to value 435 * 436 * After matching the symbol according to the given strategy 437 * we print it in the name+offset format, provided the symbol's 438 * value is close enough (eg smaller than db_maxoff). 439 * We also attempt to print [filename:linenum] when applicable 440 * (eg for procedure names). 441 * 442 * If we could not find a reasonable name+offset representation, 443 * then we just print the value in hex. Small values might get 444 * bogus symbol associations, e.g. 3 might get some absolute 445 * value like _INCLUDE_VERSION or something, therefore we do 446 * not accept symbols whose value is "small" (and use plain hex). 447 */ 448 449db_expr_t db_maxoff = 0x10000; 450 451void
| 393{ 394 db_expr_t value; 395 396 if (sym == DB_SYM_NULL) { 397 *namep = 0; 398 return; 399 } 400 401 X_db_symbol_values(db_last_symtab, sym, namep, &value); 402 403 if (db_symbol_is_ambiguous(sym)) 404 *namep = db_qualify(sym, db_last_symtab->name); 405 if (valuep) 406 *valuep = value; 407} 408 409 410/* 411 * Print a the closest symbol to value 412 * 413 * After matching the symbol according to the given strategy 414 * we print it in the name+offset format, provided the symbol's 415 * value is close enough (eg smaller than db_maxoff). 416 * We also attempt to print [filename:linenum] when applicable 417 * (eg for procedure names). 418 * 419 * If we could not find a reasonable name+offset representation, 420 * then we just print the value in hex. Small values might get 421 * bogus symbol associations, e.g. 3 might get some absolute 422 * value like _INCLUDE_VERSION or something, therefore we do 423 * not accept symbols whose value is "small" (and use plain hex). 424 */ 425 426db_expr_t db_maxoff = 0x10000; 427 428void
|
452db_printsym(off, strategy) 453 db_expr_t off; 454 db_strategy_t strategy;
| 429db_printsym(db_expr_t off, db_strategy_t strategy)
|
455{ 456 db_expr_t d; 457 char *filename; 458 const char *name; 459 db_expr_t value; 460 int linenum; 461 c_db_sym_t cursym; 462 463 cursym = db_search_symbol(off, strategy, &d); 464 db_symbol_values(cursym, &name, &value); 465 if (name == 0) 466 value = off; 467 if (value >= DB_SMALL_VALUE_MIN && value <= DB_SMALL_VALUE_MAX) { 468 db_printf("%+#lr", (long)off); 469 return; 470 } 471 if (name == 0 || d >= (unsigned long)db_maxoff) { 472 db_printf("%#lr", (unsigned long)off); 473 return; 474 } 475#ifdef DDB_NUMSYM 476 db_printf("%#lr = %s", (unsigned long)off, name); 477#else 478 db_printf("%s", name); 479#endif 480 if (d) 481 db_printf("+%+#lr", (long)d); 482 if (strategy == DB_STGY_PROC) { 483 if (db_line_at_pc(cursym, &filename, &linenum, off)) 484 db_printf(" [%s:%d]", filename, linenum); 485 } 486} 487 488static boolean_t
| 430{ 431 db_expr_t d; 432 char *filename; 433 const char *name; 434 db_expr_t value; 435 int linenum; 436 c_db_sym_t cursym; 437 438 cursym = db_search_symbol(off, strategy, &d); 439 db_symbol_values(cursym, &name, &value); 440 if (name == 0) 441 value = off; 442 if (value >= DB_SMALL_VALUE_MIN && value <= DB_SMALL_VALUE_MAX) { 443 db_printf("%+#lr", (long)off); 444 return; 445 } 446 if (name == 0 || d >= (unsigned long)db_maxoff) { 447 db_printf("%#lr", (unsigned long)off); 448 return; 449 } 450#ifdef DDB_NUMSYM 451 db_printf("%#lr = %s", (unsigned long)off, name); 452#else 453 db_printf("%s", name); 454#endif 455 if (d) 456 db_printf("+%+#lr", (long)d); 457 if (strategy == DB_STGY_PROC) { 458 if (db_line_at_pc(cursym, &filename, &linenum, off)) 459 db_printf(" [%s:%d]", filename, linenum); 460 } 461} 462 463static boolean_t
|
489db_line_at_pc( sym, filename, linenum, pc) 490 c_db_sym_t sym; 491 char **filename; 492 int *linenum; 493 db_expr_t pc;
| 464db_line_at_pc(c_db_sym_t sym, char **filename, int *linenum, db_expr_t pc)
|
494{ 495 return X_db_line_at_pc( db_last_symtab, sym, filename, linenum, pc); 496} 497 498int
| 465{ 466 return X_db_line_at_pc( db_last_symtab, sym, filename, linenum, pc); 467} 468 469int
|
499db_sym_numargs(sym, nargp, argnames) 500 c_db_sym_t sym; 501 int *nargp; 502 char **argnames;
| 470db_sym_numargs(c_db_sym_t sym, int *nargp, char **argnames)
|
503{ 504 return X_db_sym_numargs(db_last_symtab, sym, nargp, argnames); 505}
| 471{ 472 return X_db_sym_numargs(db_last_symtab, sym, nargp, argnames); 473}
|