--- Gnu-Mach/ddb/db_sym.c 2020/09/02 04:36:57 1.1.1.1 +++ Gnu-Mach/ddb/db_sym.c 2020/09/02 04:45:45 1.1.1.3 @@ -1,25 +1,25 @@ -/* +/* * Mach Operating System * Copyright (c) 1992,1991,1990 Carnegie Mellon University * All Rights Reserved. - * + * * Permission to use, copy, modify and distribute this software and its * documentation is hereby granted, provided that both the copyright * notice and this permission notice appear in all copies of the * software, derivative works or modified versions, and any portions * thereof, and that both notices appear in supporting documentation. - * + * * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. - * + * * Carnegie Mellon requests users of this software to return to - * + * * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU * School of Computer Science * Carnegie Mellon University * Pittsburgh PA 15213-3890 - * + * * any improvements or extensions that they make and grant Carnegie Mellon * the rights to redistribute these changes. */ @@ -28,12 +28,13 @@ * Date: 7/90 */ -#include "mach_kdb.h" #if MACH_KDB +#include #include -#include #include +#include +#include #include #include @@ -97,11 +98,11 @@ db_qualify(symname, symtabname) register char *s; s = tmp; - while (*s++ = *symtabname++) { + while ((*s++ = *symtabname++)) { } s[-1] = ':'; *s++ = ':'; - while (*s++ = *symname++) { + while ((*s++ = *symname++)) { } return tmp; } @@ -128,6 +129,8 @@ db_value_of_name(name, valuep) if (sym == DB_SYM_NULL) return (FALSE); db_symbol_values(0, sym, &name, valuep); + + db_free_symbol(sym); return (TRUE); } @@ -172,10 +175,11 @@ db_lookup(symstr) * Return on first match. */ for (i = symtab_start; i < symtab_end; i++) { - if (sp = X_db_lookup(&db_symtabs[i], symstr)) { + if ((sp = X_db_lookup(&db_symtabs[i], symstr))) { db_last_symtab = &db_symtabs[i]; return sp; } + db_free_symbol(sp); } return 0; } @@ -187,7 +191,7 @@ db_lookup(symstr) * handler supports qualified search with a file name or a line number. * It parses the symbol string, and call an object dependent routine * with parsed file name, symbol name and line number. - */ + */ db_sym_t db_sym_parse_and_lookup(func, symtab, symstr) db_sym_t (*func)(); @@ -195,7 +199,7 @@ db_sym_parse_and_lookup(func, symtab, sy char *symstr; { register char *p; - register n; + register int n; int n_name; int line_number; char *file_name = 0; @@ -247,7 +251,7 @@ db_sym_parse_and_lookup(func, symtab, sy sym_name = component[1]; } found = func(symtab, file_name, sym_name, line_number); - + out: while (--n >= 1) component[n][-1] = ':'; @@ -272,11 +276,16 @@ db_name_is_ambiguous(sym_name) return FALSE; for (i = 0; i < db_nsymtab; i++) { - if (X_db_lookup(&db_symtabs[i], sym_name)) { + db_sym_t sp; + if (sp = X_db_lookup(&db_symtabs[i], sym_name)) { if (found_once) + { + db_free_symbol(sp); return TRUE; + } found_once = TRUE; } + db_free_symbol(sp); } return FALSE; } @@ -290,8 +299,8 @@ db_sym_t db_search_in_task_symbol(); * * Logic change. If the task argument is non NULL and a * matching symbol is found in a symbol table which explictly - * specifies its map to be task->map, that symbol will have - * precedence over any symbol from a symbol table will a null + * specifies its map to be task->map, that symbol will have + * precedence over any symbol from a symbol table will a null * map. This allows overlapping kernel/user maps to work correctly. * */ @@ -309,12 +318,13 @@ db_search_task_symbol(val, strategy, off else { ret = db_search_in_task_symbol(val, strategy, offp, task); - /* - db_search_in_task_symbol will return success with - a very large offset when it should have failed. + /* + db_search_in_task_symbol will return success with + a very large offset when it should have failed. */ if (ret == DB_SYM_NULL || (*offp) > 0x1000000) { + db_free_symbol(ret); task = db_current_task(); ret = db_search_in_task_symbol(val, strategy, offp, task); } @@ -340,11 +350,11 @@ db_search_in_task_symbol(val, strategy, map_for_val = (task == TASK_NULL)? VM_MAP_NULL: task->map; newdiff = diff = ~0; db_last_symtab = (db_symtab_t *) 0; - for (sp = &db_symtabs[0], i = 0; i < db_nsymtab; sp++, i++) + for (sp = &db_symtabs[0], i = 0; i < db_nsymtab; sp++, i++) { newdiff = ~0; if ((vm_map_t)sp->map_pointer == VM_MAP_NULL || - (vm_map_t)sp->map_pointer == map_for_val) + (vm_map_t)sp->map_pointer == map_for_val) { sym = X_db_search_symbol(sp, val, strategy, (db_expr_t*)&newdiff); if (sym == DB_SYM_NULL) @@ -353,34 +363,37 @@ db_search_in_task_symbol(val, strategy, { /* first hit */ db_last_symtab = sp; diff = newdiff; + db_free_symbol(ret); ret = sym; continue; } - if ((vm_map_t) sp->map_pointer == VM_MAP_NULL && + if ((vm_map_t) sp->map_pointer == VM_MAP_NULL && (vm_map_t) db_last_symtab->map_pointer == VM_MAP_NULL && newdiff < diff ) { /* closer null map match */ db_last_symtab = sp; diff = newdiff; + db_free_symbol(ret); ret = sym; continue; - } - if ((vm_map_t) sp->map_pointer != VM_MAP_NULL && + } + if ((vm_map_t) sp->map_pointer != VM_MAP_NULL && (newdiff < 0x100000) && ((vm_map_t) db_last_symtab->map_pointer == VM_MAP_NULL || newdiff < diff )) - { /* update if new is in matching map and symbol is "close", - and - old is VM_MAP_NULL or old in is matching map but is further away + { /* update if new is in matching map and symbol is "close", + and + old is VM_MAP_NULL or old in is matching map but is further away */ db_last_symtab = sp; diff = newdiff; + db_free_symbol(ret); ret = sym; continue; - } + } } } - + *offp = diff; return ret; } @@ -432,7 +445,7 @@ db_symbol_values(stab, sym, namep, value * not accept symbols whose value is zero (and use plain hex). */ -unsigned int db_maxoff = 0x4000; +unsigned long db_maxoff = 0x4000; void db_task_printsym(off, strategy, task) @@ -449,8 +462,9 @@ db_task_printsym(off, strategy, task) cursym = db_search_task_symbol(off, strategy, &d, task); db_symbol_values(0, cursym, &name, &value); - if (name == 0 || d >= db_maxoff || value == 0) { + if (name == 0 || d >= db_maxoff || value == 0 || *name == 0) { db_printf("%#n", off); + db_free_symbol(cursym); return; } db_printf("%s", name); @@ -464,6 +478,7 @@ db_task_printsym(off, strategy, task) db_printf("]"); } } + db_free_symbol(cursym); } void @@ -486,6 +501,13 @@ db_line_at_pc( sym, filename, linenum, p FALSE; } +void db_free_symbol(db_sym_t s) +{ + return (db_last_symtab) ? + X_db_free_symbol( db_last_symtab, s) : + FALSE; +} + /* * Switch into symbol-table specific routines */ @@ -498,6 +520,8 @@ extern boolean_t coff_db_sym_init(), cof extern db_sym_t coff_db_lookup(), coff_db_search_symbol(); extern void coff_db_symbol_values(); +void dummy_db_free_symbol(sym_t) { } + struct db_sym_switch x_db[] = { /* BSD a.out format (really, sdb/dbx(1) symtabs) */ @@ -505,14 +529,14 @@ struct db_sym_switch x_db[] = { { 0,}, #else /* DB_NO_AOUT */ { aout_db_sym_init, aout_db_lookup, aout_db_search_symbol, - aout_db_line_at_pc, aout_db_symbol_values }, + aout_db_line_at_pc, aout_db_symbol_values, dummy_db_free_symbol }, #endif /* DB_NO_AOUT */ #ifdef DB_NO_COFF { 0,}, #else /* DB_NO_COFF */ { coff_db_sym_init, coff_db_lookup, coff_db_search_symbol, - coff_db_line_at_pc, coff_db_symbol_values }, + coff_db_line_at_pc, coff_db_symbol_values, dummy_db_free_symbol }, #endif /* DB_NO_COFF */ /* Machdep, not inited here */ @@ -520,4 +544,4 @@ struct db_sym_switch x_db[] = { }; -#endif MACH_KDB +#endif /* MACH_KDB */