X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/43866e378188c25dd1e2208016ab3cbeb086ae6c..21362eb3e66fd2c787aee132bce100a44d71a99c:/osfmk/ddb/db_sym.c diff --git a/osfmk/ddb/db_sym.c b/osfmk/ddb/db_sym.c index c0d3f5f12..970862301 100644 --- a/osfmk/ddb/db_sym.c +++ b/osfmk/ddb/db_sym.c @@ -1,16 +1,19 @@ /* - * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved. * - * @APPLE_LICENSE_HEADER_START@ - * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. + * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ * * This file contains Original Code and/or Modifications of Original Code * as defined in and that are subject to the Apple Public Source License * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * compliance with the License. The rights granted to you under the License + * may not be used to create, or enable the creation or redistribution of, + * unlawful or unlicensed copies of an Apple operating system, or to + * circumvent, violate, or enable the circumvention or violation of, any + * terms of an Apple operating system software license agreement. + * + * Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER @@ -20,327 +23,11 @@ * Please see the License for the specific language governing rights and * limitations under the License. * - * @APPLE_LICENSE_HEADER_END@ + * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ */ /* * @OSF_COPYRIGHT@ */ -/* - * HISTORY - * - * Revision 1.1.1.1 1998/09/22 21:05:48 wsanchez - * Import of Mac OS X kernel (~semeria) - * - * Revision 1.1.1.1 1998/03/07 02:26:09 wsanchez - * Import of OSF Mach kernel (~mburg) - * - * Revision 1.3.22.8 1996/07/31 09:07:24 paire - * Merged with nmk20b7_shared (1.3.47.1) - * [96/07/24 paire] - * - * Revision 1.3.47.1 1996/06/13 12:36:08 bernadat - * Do not assume anymore that VM_MIN_KERNEL_ADDRESS - * is greater or equal than VM_MAX_ADDRESS. - * [96/05/23 bernadat] - * - * Revision 1.3.22.7 1996/01/09 19:16:15 devrcs - * Added db_task_getlinenum() function. (steved) - * Make db_maxval & db_minval long int's for Alpha. - * Changed declarations of 'register foo' to 'register int foo'. - * [1995/12/01 21:42:29 jfraser] - * - * Merged '64-bit safe' changes from DEC alpha port. - * [1995/11/21 18:03:41 jfraser] - * - * Revision 1.3.22.6 1995/02/28 01:58:46 dwm - * Merged with changes from 1.3.22.5 - * [1995/02/28 01:53:47 dwm] - * - * mk6 CR1120 - Merge mk6pro_shared into cnmk_shared - * remove a couple local protos, now in .h file (for better or worse) - * [1995/02/28 01:12:51 dwm] - * - * Revision 1.3.22.5 1995/02/23 21:43:43 alanl - * Move TR_INIT to model_dep.c (MACH_TR and MACH_KDB shouldn't - * be bound). - * [95/02/16 travos] - * - * Prepend a "db_" to qsort and qsort_limit_search - * (collisions with the real qsort in stdlib.h) - * [95/02/14 travos] - * - * Added X_db_init for object independent formats. - * [95/01/24 sjs] - * - * Merge with DIPC2_SHARED. - * [1995/01/05 13:32:53 alanl] - * - * Revision 1.3.30.2 1994/12/22 20:36:15 bolinger - * Fix ri-osc CR881: enable freer use of symbol table of collocated - * tasks. No point in requiring task to be named for symbols to be - * usable. Also fixed glitch in use of symtab cloning. - * [1994/12/22 20:34:55 bolinger] - * - * Revision 1.3.30.1 1994/11/04 09:53:14 dwm - * mk6 CR668 - 1.3b26 merge - * add arg to *_db_search_by_addr() from mk6 - * * Revision 1.3.4.9 1994/05/13 15:57:14 tmt - * Add hooks for catching calls to uninstalled symbol tables. - * Add XXX_search_by_addr() vectors. - * * Revision 1.3.4.8 1994/05/12 21:59:00 tmt - * Fix numerous db_sym_t/char * mixups. - * Fix and enable db_qualify_ambiguous_names. - * Make dif and newdiff unsigned in symbol searches. - * * Revision 1.3.4.7 1994/05/06 18:39:52 tmt - * Merged osc1.3dec/shared with osc1.3b19 - * Fix function prototype declarations. - * Merge Alpha changes into osc1.312b source code. - * String protos. - * Handle multiple, coexisting symbol table types. - * 64bit cleanup. - * Revision 1.3.4.5 1993/10/20 18:58:55 gm - * CR9704: Removed symbol load printf. - * * End1.3merge - * [1994/11/04 08:50:02 dwm] - * - * Revision 1.3.22.5 1995/02/23 21:43:43 alanl - * Move TR_INIT to model_dep.c (MACH_TR and MACH_KDB shouldn't - * be bound). - * [95/02/16 travos] - * - * Prepend a "db_" to qsort and qsort_limit_search - * (collisions with the real qsort in stdlib.h) - * [95/02/14 travos] - * - * Added X_db_init for object independent formats. - * [95/01/24 sjs] - * - * Merge with DIPC2_SHARED. - * [1995/01/05 13:32:53 alanl] - * - * Revision 1.3.30.2 1994/12/22 20:36:15 bolinger - * Fix ri-osc CR881: enable freer use of symbol table of collocated - * tasks. No point in requiring task to be named for symbols to be - * usable. Also fixed glitch in use of symtab cloning. - * [1994/12/22 20:34:55 bolinger] - * - * Revision 1.3.30.1 1994/11/04 09:53:14 dwm - * mk6 CR668 - 1.3b26 merge - * add arg to *_db_search_by_addr() from mk6 - * * Revision 1.3.4.9 1994/05/13 15:57:14 tmt - * Add hooks for catching calls to uninstalled symbol tables. - * Add XXX_search_by_addr() vectors. - * * Revision 1.3.4.8 1994/05/12 21:59:00 tmt - * Fix numerous db_sym_t/char * mixups. - * Fix and enable db_qualify_ambiguous_names. - * Make dif and newdiff unsigned in symbol searches. - * * Revision 1.3.4.7 1994/05/06 18:39:52 tmt - * Merged osc1.3dec/shared with osc1.3b19 - * Fix function prototype declarations. - * Merge Alpha changes into osc1.312b source code. - * String protos. - * Handle multiple, coexisting symbol table types. - * 64bit cleanup. - * Revision 1.3.4.5 1993/10/20 18:58:55 gm - * CR9704: Removed symbol load printf. - * * End1.3merge - * [1994/11/04 08:50:02 dwm] - * - * Revision 1.3.22.3 1994/09/23 01:21:37 ezf - * change marker to not FREE - * [1994/09/22 21:10:58 ezf] - * - * Revision 1.3.22.2 1994/06/26 22:58:24 bolinger - * Suppress symbol table range output when table is unsorted, since output - * is meaningless in this case. - * [1994/06/23 20:19:02 bolinger] - * - * Revision 1.3.22.1 1994/06/11 21:12:19 bolinger - * Merge up to NMK17.2. - * [1994/06/11 20:02:31 bolinger] - * - * Revision 1.3.17.1 1994/02/08 10:58:40 bernadat - * Check result of X_db_line_at_pc() before - * invoking db_shorten_filename(). - * [93/11/30 bernadat] - * - * Installed ddb_init() routine in a symbol-independent file to call - * symbol-dependent and machine-dependent initialization routines. - * [93/08/27 paire] - * - * Fixed db_shorten_filename() to gobble the last slash. - * Modified db_search_task_symbol_and_line() interface to return - * the number of a function arguments. - * [93/08/19 paire] - * - * Added new arguments to db_sym_print_completion() call. - * [93/08/18 paire] - * - * Added db_lookup_incomplete(), db_sym_parse_and_lookup_incomplete(), - * db_sym_print_completion() and db_completion_print() for support of - * symbol completion. - * [93/08/14 paire] - * [94/02/07 bernadat] - * - * Revision 1.3.15.4 1994/06/08 19:11:23 dswartz - * Preemption merge. - * [1994/06/08 19:10:24 dswartz] - * - * Revision 1.3.20.2 1994/06/01 21:34:39 klj - * Initial preemption code base merge - * - * Revision 1.3.15.3 1994/02/10 02:28:15 bolinger - * Fix db_add_symbol_table() to increase db_maxval if highest-addressed - * symbol in new symtab is greater than its current value. - * [1994/02/09 21:42:12 bolinger] - * - * Revision 1.3.15.2 1994/02/03 21:44:23 bolinger - * Update db_maxval when a symbol table is cloned for kernel-loaded - * server. - * [1994/02/03 20:47:22 bolinger] - * - * Revision 1.3.15.1 1994/02/03 02:41:58 dwm - * Add short-term kludge to provide symbolic info on INKServer. - * [1994/02/03 02:31:17 dwm] - * - * Revision 1.3.4.4 1993/08/11 20:38:11 elliston - * Add ANSI Prototypes. CR #9523. - * [1993/08/11 03:33:59 elliston] - * - * Revision 1.3.4.3 1993/07/27 18:28:09 elliston - * Add ANSI prototypes. CR #9523. - * [1993/07/27 18:12:57 elliston] - * - * Revision 1.3.4.2 1993/06/09 02:20:50 gm - * CR9176 - ANSI C violations: trailing tokens on CPP - * directives, extra semicolons after decl_ ..., asm keywords - * [1993/06/07 18:57:31 jeffc] - * - * Added to OSF/1 R1.3 from NMK15.0. - * [1993/06/02 20:57:10 jeffc] - * - * Revision 1.3 1993/04/19 16:03:09 devrcs - * Protect db_line_at_pc() against null db_last_symtab. - * [1993/02/11 15:37:16 barbou] - * - * Changes from MK78: - * Upped MAXNOSYMTABS from 3 to 5. Now there is space for kernel, - * bootstrap, server, and emulator symbols - plus one for future - * expansion. - * [92/03/21 danner] - * Changed CHAR arg of db_eqname to UNSIGNED. - * Made arg types proper for db_line_at_pc(). - * [92/05/16 jfriedl] - * [92/12/18 bruel] - * - * Sort large symbol tables to speedup lookup. - * Improved symbol lookup (use of max_offset, dichotomic search) - * [barbou@gr.osf.org] - * - * db_add_symbol_table now takes 3 additional arguments. Machine - * dependant modules must provide them. [barbou@gr.osf.org] - * [92/12/03 bernadat] - * - * Revision 1.2 1992/11/25 01:04:42 robert - * integrate changes below for norma_14 - * [1992/11/13 19:22:44 robert] - * - * Revision 1.1 1992/09/30 02:01:25 robert - * Initial revision - * - * $EndLog$ - */ -/* CMU_HIST */ -/* - * Revision 2.10.4.1 92/02/18 18:38:53 jeffreyh - * Added db_get_sym(). Simple interface to get symbol names - * knowing the offset. - * [91/12/20 bernadat] - * - * Do not look for symbol names if address - * is to small or to large, otherwise get - * random names like INCLUDE_VERSION+?? - * [91/06/25 bernadat] - * - * Revision 2.10 91/10/09 16:02:30 af - * Revision 2.9.2.1 91/10/05 13:07:27 jeffreyh - * Changed symbol table name qualification syntax from "xxx:yyy" - * to "xxx::yyy" to allow "file:func:line" in "yyy" part. - * "db_sym_parse_and_lookup" is also added for "yyy" part parsing. - * Replaced db_search_symbol with db_search_task_symbol, and moved - * it to "db_sym.h" as a macro. - * Added db_task_printsym, and changed db_printsym to call it. - * Added include "db_task_thread.h". - * Fixed infinite recursion of db_symbol_values. - * [91/08/29 tak] - * - * Revision 2.9.2.1 91/10/05 13:07:27 jeffreyh - * Changed symbol table name qualification syntax from "xxx:yyy" - * to "xxx::yyy" to allow "file:func:line" in "yyy" part. - * "db_sym_parse_and_lookup" is also added for "yyy" part parsing. - * Replaced db_search_symbol with db_search_task_symbol, and moved - * it to "db_sym.h" as a macro. - * Added db_task_printsym, and changed db_printsym to call it. - * Added include "db_task_thread.h". - * Fixed infinite recursion of db_symbol_values. - * [91/08/29 tak] - * - * Revision 2.9 91/07/31 17:31:14 dbg - * Add task pointer and space for string storage to symbol table - * descriptor. - * [91/07/31 dbg] - * - * Revision 2.8 91/07/09 23:16:08 danner - * Changed a printf. - * [91/07/08 danner] - * - * Revision 2.7 91/05/14 15:35:54 mrt - * Correcting copyright - * - * Revision 2.6 91/03/16 14:42:40 rpd - * Changed the default db_maxoff to 4K. - * [91/03/10 rpd] - * - * Revision 2.5 91/02/05 17:07:07 mrt - * Changed to new Mach copyright - * [91/01/31 16:19:17 mrt] - * - * Revision 2.4 90/10/25 14:44:05 rwd - * Changed db_printsym to print unsigned. - * [90/10/19 rpd] - * - * Revision 2.3 90/09/09 23:19:56 rpd - * Avoid totally incorrect guesses of symbol names for small values. - * [90/08/30 17:39:48 af] - * - * Revision 2.2 90/08/27 21:52:18 dbg - * Removed nlist.h. Fixed some type declarations. - * Qualifier character is ':'. - * [90/08/20 dbg] - * Modularized symtab info into a new db_symtab_t type. - * Modified db_add_symbol_table and others accordingly. - * Defined db_sym_t, a new (opaque) type used to represent - * symbols. This should support all sort of future symtable - * formats. Functions like db_qualify take a db_sym_t now. - * New db_symbol_values() function to explode the content - * of a db_sym_t. - * db_search_symbol() replaces db_find_sym_and_offset(), which is - * now a macro defined in our (new) header file. This new - * function accepts more restrictive searches, which are - * entirely delegated to the symtab-specific code. - * Accordingly, db_printsym() accepts a strategy parameter. - * New db_line_at_pc() function. - * Renamed misleading db_eqsym into db_eqname. - * [90/08/20 10:47:06 af] - * - * Created. - * [90/07/25 dbg] - * - * Revision 2.1 90/07/26 16:43:52 dbg - * Created. - * - */ -/* CMU_ENDHIST */ /* * Mach Operating System * Copyright (c) 1991,1990 Carnegie Mellon University @@ -969,7 +656,7 @@ db_search_task_symbol( db_addr_t *offp, /* better be unsigned */ task_t task) { - unsigned long diff, newdiff; + db_addr_t diff, newdiff; register int i; db_symtab_t *sp; db_sym_t ret = DB_SYM_NULL, sym; @@ -979,16 +666,16 @@ db_search_task_symbol( task = db_current_task(); map_for_val = (task == TASK_NULL)? VM_MAP_NULL: task->map; again: - newdiff = diff = ~0UL; + newdiff = diff = -1; db_last_symtab = 0; for (sp = &db_symtabs[0], i = 0; i < db_nsymtab; sp++, i++) { - if (((vm_map_t)sp->map_pointer == VM_MAP_NULL || - (vm_map_t)sp->map_pointer == map_for_val) && - (sp->maxsym == 0 || - ((unsigned long) val >= sp->minsym && - (unsigned long) val <= sp->maxsym))) { + if ((((vm_map_t)sp->map_pointer == VM_MAP_NULL) || + ((vm_map_t)sp->map_pointer == map_for_val)) && + ((sp->maxsym == 0) || + ((val >= (db_addr_t)sp->minsym) && + (val <= (db_addr_t)sp->maxsym)))) { sym = X_db_search_symbol(sp, val, strategy, (db_expr_t *)&newdiff); if (newdiff < diff) { @@ -1023,7 +710,7 @@ db_search_task_symbol_and_line( task_t task, int *argsp) { - unsigned long diff, newdiff; + db_addr_t diff, newdiff; register int i; db_symtab_t *sp; db_sym_t ret = DB_SYM_NULL, sym; @@ -1047,24 +734,25 @@ db_search_task_symbol_and_line( for (sp = &db_symtabs[0], i = 0; i < db_nsymtab; sp++, i++) { - if (((vm_map_t)sp->map_pointer == VM_MAP_NULL || - (vm_map_t)sp->map_pointer == map_for_val) && - (sp->maxsym == 0 || - ((unsigned long) val >= sp->minsym && - (unsigned long) val <= sp->maxsym))) { - sym = X_db_search_by_addr(sp, val, &filename, &func, - &linenum, (db_expr_t *)&newdiff, - &args); - if (sym && newdiff < diff) { - db_last_symtab = sp; - diff = newdiff; - ret = sym; - *filenamep = filename; - *linenump = linenum; - *argsp = args; - if (diff <= db_search_maxoff) - break; - } + if ((((vm_map_t)sp->map_pointer == VM_MAP_NULL) || + ((vm_map_t)sp->map_pointer == map_for_val)) && + ((sp->maxsym == 0) || + ((val >= (db_addr_t)sp->minsym) && + (val <= (db_addr_t)sp->maxsym)))) { + + sym = X_db_search_by_addr(sp, val, &filename, &func, + &linenum, (db_expr_t *)&newdiff, + &args); + if (sym && newdiff < diff) { + db_last_symtab = sp; + diff = newdiff; + ret = sym; + *filenamep = filename; + *linenump = linenum; + *argsp = args; + if (diff <= db_search_maxoff) + break; + } } } if (ret == DB_SYM_NULL && map_for_val != VM_MAP_NULL) { @@ -1127,11 +815,11 @@ db_symbol_values( void db_task_printsym( - db_expr_t off, + db_addr_t off, db_strategy_t strategy, task_t task) { - db_addr_t d; + db_expr_t d; char *filename; char *name; db_expr_t value; @@ -1139,19 +827,19 @@ db_task_printsym( db_sym_t cursym; if (off >= db_maxval || off < db_minval) { - db_printf("%#n", off); + db_printf("%#lln", (unsigned long long)off); return; } cursym = db_search_task_symbol(off, strategy, &d, task); db_symbol_values(0, cursym, &name, &value); if (name == 0 || d >= db_maxoff || value == 0) { - db_printf("%#n", off); + db_printf("%#lln",(unsigned long long) off); return; } db_printf("%s", name); if (d) - db_printf("+0x%x", d); + db_printf("+%llx", (unsigned long long)d); if (strategy == DB_STGY_PROC) { if (db_line_at_pc(cursym, &filename, &linenum, off)) { db_printf(" [%s", filename); @@ -1227,7 +915,7 @@ db_task_getlinenum( db_strategy_t strategy = DB_STGY_PROC; if (off >= db_maxval || off < db_minval) { - db_printf("%#n", off); + db_printf("%#lln", (unsigned long long)off); return(-1); } cursym = db_search_task_symbol(off, strategy, &d, task); @@ -1618,7 +1306,6 @@ db_clone_symtabXXX( char * memp; vm_size_t size; long offset; - extern vm_offset_t kalloc(vm_size_t); extern void db_clone_offsetXXX(char *, long); if (db_nsymtab >= MAXNOSYMTABS) { @@ -1721,7 +1408,7 @@ static db_sym_t no_search( db_strategy_t strategy, db_expr_t *diffp) { - db_printf("Bogus search for offset %#Xn", off); + db_printf("Bogus search for offset %#llXn", (unsigned long long)off); return DB_SYM_NULL; } @@ -1732,7 +1419,7 @@ static boolean_t no_line_at_pc( int *line, db_expr_t pc) { - db_printf("Bogus search for pc %#X\n", pc); + db_printf("Bogus search for pc %#llX\n", (unsigned long long)pc); return FALSE; } @@ -1755,7 +1442,7 @@ static db_sym_t no_search_by_addr( db_expr_t *diffp, int *args) { - db_printf("Bogus search for address %#X\n", off); + db_printf("Bogus search for address %#llX\n", (unsigned long long)off); return DB_SYM_NULL; }