2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
34 * Mach Operating System
35 * Copyright (c) 1991,1990 Carnegie Mellon University
36 * All Rights Reserved.
38 * Permission to use, copy, modify and distribute this software and its
39 * documentation is hereby granted, provided that both the copyright
40 * notice and this permission notice appear in all copies of the
41 * software, derivative works or modified versions, and any portions
42 * thereof, and that both notices appear in supporting documentation.
44 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
45 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
46 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
48 * Carnegie Mellon requests users of this software to return to
50 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
51 * School of Computer Science
52 * Carnegie Mellon University
53 * Pittsburgh PA 15213-3890
55 * any improvements or extensions that they make and grant Carnegie Mellon
56 * the rights to redistribute these changes.
61 * Author: David B. Golub, Carnegie Mellon University
65 #include <machine/db_machdep.h>
66 #include <string.h> /* For strcpy(), strcmp() */
67 #include <mach/std_types.h>
68 #include <kern/misc_protos.h> /* For printf() */
69 #include <ddb/db_sym.h>
70 #include <ddb/db_task_thread.h>
71 #include <ddb/db_command.h>
72 #include <ddb/db_output.h> /* For db_printf() */
74 #include <vm/vm_map.h> /* vm_map_t */
77 * Multiple symbol tables
79 * mach, bootstrap, name_server, default_pager, unix, 1 spare
81 #define MAXNOSYMTABS 6
83 db_symtab_t db_symtabs
[MAXNOSYMTABS
] = {{0}};
86 db_symtab_t
*db_last_symtab
;
88 unsigned long db_maxoff
= 0x4000;
90 unsigned long db_maxval
= (unsigned long)&end
;
91 natural_t db_minval
= 0x1000;
93 /* Prototypes for functions local to this file. XXX -- should be static!
95 static char *db_qualify(
97 register char *symtabname
);
104 boolean_t
db_symbol_is_ambiguous(char *name
);
106 void db_shorten_filename(char **filenamep
);
123 int (*compfun
)(char *, char *));
129 int (*compfun
)(char *, char *));
135 int (*compfun
)(char *, char *));
137 int no_print_completion(
140 int no_lookup_incomplete(
148 * Initialization routine for ddb.
158 * Add symbol table, with given name, to list of symbol tables.
168 unsigned long minsym
,
169 unsigned long maxsym
,
172 register db_symtab_t
*st
;
173 extern vm_map_t kernel_map
;
175 if (db_nsymtab
>= MAXNOSYMTABS
)
178 st
= &db_symtabs
[db_nsymtab
];
183 if (map_pointer
== (char *)kernel_map
||
184 (VM_MAX_ADDRESS
<= VM_MIN_KERNEL_ADDRESS
&&
185 VM_MIN_KERNEL_ADDRESS
<= minsym
))
188 st
->map_pointer
= map_pointer
;
189 strcpy(st
->name
, name
);
196 if (db_maxval
< maxsym
+ db_maxoff
)
197 db_maxval
= maxsym
+ db_maxoff
;
205 * db_qualify("vm_map", "ux") returns "ux::vm_map".
207 * Note: return value points to static data whose content is
208 * overwritten by each call... but in practice this seems okay.
213 register char *symtabname
)
215 static char tmp
[256];
219 while (*s
++ = *symtabname
++) {
223 while (*s
++ = *symname
++) {
235 if (!strcmp(src
, dst
))
238 return (!strcmp(src
+1,dst
));
249 sym
= db_lookup(name
);
250 if (sym
== DB_SYM_NULL
)
252 db_symbol_values(0, sym
, &name
, valuep
);
257 * Display list of possible completions for a symbol.
264 int symtab_start
= 0;
265 int symtab_end
= db_nsymtab
;
268 char *name
= (char *)0;
273 * Look for, remove, and remember any symbol table specifier.
275 for (cp
= symstr
; *cp
; cp
++) {
276 if (*cp
== ':' && cp
[1] == ':') {
278 for (i
= 0; i
< db_nsymtab
; i
++) {
279 if (! strcmp(symstr
, db_symtabs
[i
].name
)) {
293 * Look in the specified set of symbol tables.
294 * Return on first match.
296 for (i
= symtab_start
; i
< symtab_end
; i
++) {
297 if (X_db_print_completion(&db_symtabs
[i
], symstr
))
303 * Lookup a (perhaps incomplete) symbol.
304 * If the symbol has a qualifier (e.g., ux::vm_map),
305 * then only the specified symbol table will be searched;
306 * otherwise, all symbol tables will be searched.
309 db_lookup_incomplete(
314 int symtab_start
= 0;
315 int symtab_end
= db_nsymtab
;
318 char *name
= (char *)0;
323 * Look for, remove, and remember any symbol table specifier.
325 for (cp
= symstr
; *cp
; cp
++) {
326 if (*cp
== ':' && cp
[1] == ':') {
328 for (i
= 0; i
< db_nsymtab
; i
++) {
329 if (! strcmp(symstr
, db_symtabs
[i
].name
)) {
343 * Look in the specified set of symbol tables.
344 * Return on first match.
346 for (i
= symtab_start
; i
< symtab_end
; i
++) {
347 nsym
= X_db_lookup_incomplete(&db_symtabs
[i
], symstr
,
348 &name
, &len
, &toadd
);
351 len
= strlen(symstr
);
352 if (len
+ toadd
>= symlen
)
354 bcopy(&name
[len
], &symstr
[len
], toadd
);
355 symstr
[len
+ toadd
] = '\0';
365 * If the symbol has a qualifier (e.g., ux::vm_map),
366 * then only the specified symbol table will be searched;
367 * otherwise, all symbol tables will be searched.
370 db_lookup(char *symstr
)
374 int symtab_start
= 0;
375 int symtab_end
= db_nsymtab
;
379 * Look for, remove, and remember any symbol table specifier.
381 for (cp
= symstr
; *cp
; cp
++) {
382 if (*cp
== ':' && cp
[1] == ':') {
384 for (i
= 0; i
< db_nsymtab
; i
++) {
385 if (! strcmp(symstr
, db_symtabs
[i
].name
)) {
393 db_error("Invalid symbol table name\n");
399 * Look in the specified set of symbol tables.
400 * Return on first match.
402 for (i
= symtab_start
; i
< symtab_end
; i
++) {
403 if (sp
= X_db_lookup(&db_symtabs
[i
], symstr
)) {
404 db_last_symtab
= &db_symtabs
[i
];
412 * Print a symbol completion
415 db_sym_print_completion(
422 if (stab
!= db_symtabs
)
423 db_printf("%s::", stab
->name
);
430 db_printf(" [static from %s", fname
);
432 db_printf(":%d", line
);
439 * Common utility routine to parse a symbol string into a file
440 * name, a (possibly incomplete) symbol name without line number.
441 * This routine is called from aout_db_print_completion if the object
442 * dependent handler supports qualified search with a file name.
443 * It parses the symbol string, and call an object dependent routine
444 * with parsed file name and symbol name.
447 db_sym_parse_and_print_completion(
448 int (*func
)(db_symtab_t
*,
460 * disassemble the symbol into components: [file_name:]symbol
462 component
[0] = symstr
;
464 for (p
= symstr
, n
= 1; *p
; p
++) {
469 component
[n
++] = p
+1;
474 sym_name
= component
[0];
476 sym_name
= component
[1];
478 nsym
= func(symtab
, sym_name
);
482 component
[1][-1] = ':';
487 * Common utility routine to parse a symbol string into a file
488 * name, a (possibly incomplete) symbol name without line number.
489 * This routine is called from X_db_lookup_incomplete if the object
490 * dependent handler supports qualified search with a file name.
491 * It parses the symbol string, and call an object dependent routine
492 * with parsed file name and symbol name.
495 db_sym_parse_and_lookup_incomplete(
496 int (*func
)(db_symtab_t
*,
517 * disassemble the symbol into components: [file_name:]symbol
519 component
[0] = symstr
;
521 for (p
= symstr
, n
= 1; *p
; p
++) {
526 component
[n
++] = p
+1;
532 sym_name
= component
[0];
534 file_name
= component
[0];
535 sym_name
= component
[1];
537 nsym
= func(symtab
, file_name
, sym_name
, 0, (db_sym_t
*)0,
540 *toadd
= *len
- strlen(sym_name
);
543 component
[1][-1] = ':';
548 * Common utility routine to parse a symbol string into a file
549 * name, a symbol name and line number.
550 * This routine is called from aout_db_lookup if the object dependent
551 * handler supports qualified search with a file name or a line number.
552 * It parses the symbol string, and call an object dependent routine
553 * with parsed file name, symbol name and line number.
556 db_sym_parse_and_lookup(
557 int (*func
)(db_symtab_t
*, char *, char *, int,
558 db_sym_t
*, char **, int *),
569 db_sym_t found
= DB_SYM_NULL
;
572 * disassemble the symbol into components:
573 * [file_name:]symbol[:line_nubmer]
575 component
[0] = symstr
;
576 component
[1] = component
[2] = 0;
577 for (p
= symstr
, n
= 1; *p
; p
++) {
582 component
[n
++] = p
+1;
590 if (*p
>= '0' && *p
<= '9') {
593 for (line_number
= 0; *p
; p
++) {
594 if (*p
< '0' || *p
> '9')
596 line_number
= line_number
*10 + *p
- '0';
602 for (p
= component
[0]; *p
&& *p
!= '.'; p
++);
604 file_name
= component
[0];
608 sym_name
= component
[0];
611 file_name
= component
[0];
612 sym_name
= component
[1];
614 (void) func(symtab
, file_name
, sym_name
, line_number
, &found
,
615 (char **)0, (int *)0);
619 component
[n
][-1] = ':';
624 * Does this symbol name appear in more than one symbol table?
625 * Used by db_symbol_values to decide whether to qualify a symbol.
627 boolean_t db_qualify_ambiguous_names
= TRUE
;
630 db_symbol_is_ambiguous(char *name
)
634 boolean_t found_once
= FALSE
;
636 if (!db_qualify_ambiguous_names
)
639 for (i
= 0; i
< db_nsymtab
; i
++) {
640 if (X_db_lookup(&db_symtabs
[i
], name
)) {
650 * Find the closest symbol to val, and return its name
651 * and the difference between val and the symbol found.
653 unsigned int db_search_maxoff
= 0x4000;
655 db_search_task_symbol(
656 register db_addr_t val
,
657 db_strategy_t strategy
,
658 db_addr_t
*offp
, /* better be unsigned */
661 db_addr_t diff
, newdiff
;
664 db_sym_t ret
= DB_SYM_NULL
, sym
;
665 vm_map_t map_for_val
;
667 if (task
== TASK_NULL
)
668 task
= db_current_task();
669 map_for_val
= (task
== TASK_NULL
)? VM_MAP_NULL
: task
->map
;
673 for (sp
= &db_symtabs
[0], i
= 0;
676 if ((((vm_map_t
)sp
->map_pointer
== VM_MAP_NULL
) ||
677 ((vm_map_t
)sp
->map_pointer
== map_for_val
)) &&
678 ((sp
->maxsym
== 0) ||
679 ((val
>= (db_addr_t
)sp
->minsym
) &&
680 (val
<= (db_addr_t
)sp
->maxsym
)))) {
681 sym
= X_db_search_symbol(sp
, val
, strategy
,
682 (db_expr_t
*)&newdiff
);
683 if (newdiff
< diff
) {
687 if (diff
<= db_search_maxoff
)
692 if (ret
== DB_SYM_NULL
&& map_for_val
!= VM_MAP_NULL
) {
693 map_for_val
= VM_MAP_NULL
;
701 * Find the closest symbol to val, and return its name
702 * and the difference between val and the symbol found.
703 * Also return the filename and linenumber if available.
706 db_search_task_symbol_and_line(
707 register db_addr_t val
,
708 db_strategy_t strategy
,
715 db_addr_t diff
, newdiff
;
718 db_sym_t ret
= DB_SYM_NULL
, sym
;
719 vm_map_t map_for_val
;
725 if (task
== TASK_NULL
)
726 task
= db_current_task();
727 map_for_val
= (task
== TASK_NULL
)? VM_MAP_NULL
: task
->map
;
728 *filenamep
= (char *) 0;
732 filename
= (char *) 0;
734 newdiff
= diff
= ~0UL;
736 for (sp
= &db_symtabs
[0], i
= 0;
739 if ((((vm_map_t
)sp
->map_pointer
== VM_MAP_NULL
) ||
740 ((vm_map_t
)sp
->map_pointer
== map_for_val
)) &&
741 ((sp
->maxsym
== 0) ||
742 ((val
>= (db_addr_t
)sp
->minsym
) &&
743 (val
<= (db_addr_t
)sp
->maxsym
)))) {
745 sym
= X_db_search_by_addr(sp
, val
, &filename
, &func
,
746 &linenum
, (db_expr_t
*)&newdiff
,
748 if (sym
&& newdiff
< diff
) {
752 *filenamep
= filename
;
755 if (diff
<= db_search_maxoff
)
760 if (ret
== DB_SYM_NULL
&& map_for_val
!= VM_MAP_NULL
) {
761 map_for_val
= VM_MAP_NULL
;
766 db_shorten_filename(filenamep
);
771 * Return name and value of a symbol
783 if (sym
== DB_SYM_NULL
) {
788 stab
= db_last_symtab
;
790 X_db_symbol_values(stab
, sym
, &name
, &value
);
792 if (db_symbol_is_ambiguous(name
)) {
793 *namep
= db_qualify(name
, db_last_symtab
->name
);
803 * Print a the closest symbol to value
805 * After matching the symbol according to the given strategy
806 * we print it in the name+offset format, provided the symbol's
807 * value is close enough (eg smaller than db_maxoff).
808 * We also attempt to print [filename:linenum] when applicable
809 * (eg for procedure names).
811 * If we could not find a reasonable name+offset representation,
812 * then we just print the value in hex. Small values might get
813 * bogus symbol associations, e.g. 3 might get some absolute
814 * value like _INCLUDE_VERSION or something, therefore we do
815 * not accept symbols whose value is zero (and use plain hex).
821 db_strategy_t strategy
,
831 if (off
>= db_maxval
|| off
< db_minval
) {
832 db_printf("%#lln", (unsigned long long)off
);
835 cursym
= db_search_task_symbol(off
, strategy
, &d
, task
);
837 db_symbol_values(0, cursym
, &name
, &value
);
838 if (name
== 0 || d
>= db_maxoff
|| value
== 0) {
839 db_printf("%#lln",(unsigned long long) off
);
842 db_printf("%s", name
);
844 db_printf("+%llx", (unsigned long long)d
);
845 if (strategy
== DB_STGY_PROC
) {
846 if (db_line_at_pc(cursym
, &filename
, &linenum
, off
)) {
847 db_printf(" [%s", filename
);
849 db_printf(":%d", linenum
);
856 * Return symbol name for a given offset and
857 * change the offset to be relative to this symbol.
858 * Very usefull for xpr, when you want to log offsets
859 * in a user friendly way.
862 char null_sym
[] = "";
865 db_get_sym(db_expr_t
*off
)
872 cursym
= db_search_symbol(*off
, DB_STGY_ANY
, &d
);
873 db_symbol_values(0, cursym
, &name
, &value
);
884 db_strategy_t strategy
)
886 db_task_printsym(off
, strategy
, TASK_NULL
);
889 int db_short_filename
= 1;
892 db_shorten_filename(char **filenamep
)
898 for (cp
= cp_slash
= *filenamep
; *cp
; cp
++) {
902 if (*cp_slash
== '/')
903 *filenamep
= cp_slash
+1;
917 db_strategy_t strategy
= DB_STGY_PROC
;
919 if (off
>= db_maxval
|| off
< db_minval
) {
920 db_printf("%#lln", (unsigned long long)off
);
923 cursym
= db_search_task_symbol(off
, strategy
, &d
, task
);
925 db_symbol_values(0, cursym
, &name
, &value
);
926 if (name
== 0 || d
>= db_maxoff
|| value
== 0) {
929 if (db_line_at_pc(cursym
, &filename
, &linenum
, off
))
944 if (db_last_symtab
== 0)
946 if (X_db_line_at_pc( db_last_symtab
, sym
, filename
, linenum
, pc
)) {
947 if (db_short_filename
)
948 db_shorten_filename(filename
);
962 int (*compfun
)(char *, char *))
964 if (nbelts
<= 0 || eltsize
<= 0 || compfun
== 0) {
965 printf("qsort: invalid parameters\n");
968 qsort_recur(table
, table
+ nbelts
* eltsize
, eltsize
, compfun
);
971 qsort_checker(table
, nbelts
, eltsize
, compfun
);
984 for (; size
>= sizeof (int); size
-= sizeof (int), a
++, b
++) {
991 for (; size
> 0; size
--, aa
++, bb
++) {
998 /* rotate the three elements to the left */
1010 for (; size
>= sizeof (int); size
-= sizeof (int), a
++, b
++, c
++) {
1019 for (; size
> 0; size
--, aa
++, bb
++, cc
++) {
1032 int (*compfun
)(char *, char *))
1035 char *sameleft
, *sameright
;
1038 if (left
+ eltsize
- 1 >= right
) {
1042 /* partition element (reference for "same"ness */
1043 sameleft
= left
+ (((right
- left
) / eltsize
) / 2) * eltsize
;
1044 sameright
= sameleft
;
1047 j
= right
- eltsize
;
1050 while (i
< sameleft
) {
1053 comp
= (*compfun
)(i
, sameleft
);
1056 * Move to the "same" partition.
1059 * Shift the left part of the "same" partition to
1060 * the left, so that "same" elements stay in their
1063 sameleft
-= eltsize
;
1064 qsort_swap((int *) i
, (int *) sameleft
, eltsize
);
1065 } else if (comp
< 0) {
1067 * Stay in the "left" partition.
1072 * Should be moved to the "right" partition.
1073 * Wait until the next loop finds an appropriate
1074 * place to store this element.
1080 while (j
> sameright
) {
1083 comp
= (*compfun
)(sameright
, j
);
1086 * Move to the right of the "same" partition.
1088 sameright
+= eltsize
;
1089 qsort_swap((int *) sameright
, (int *) j
, eltsize
);
1090 } else if (comp
> 0) {
1092 * Move to the "left" partition.
1094 if (i
== sameleft
) {
1096 * Unfortunately, the "left" partition
1097 * has already been fully processed, so
1098 * we have to shift the "same" partition
1099 * to the right to free a "left" element.
1100 * This is done by moving the leftest same
1101 * to the right of the "same" partition.
1103 sameright
+= eltsize
;
1104 qsort_rotate((int *) sameleft
, (int*) sameright
,
1105 (int *) j
, eltsize
);
1106 sameleft
+= eltsize
;
1110 * Swap with the "left" partition element
1111 * waiting to be moved to the "right"
1114 qsort_swap((int *) i
, (int *) j
, eltsize
);
1117 * Go back to the 1st loop.
1124 * Stay in the "right" partition.
1130 if (i
!= sameleft
) {
1132 * The second loop completed (the"right" partition is ok),
1133 * but we have to go back to the first loop, and deal with
1134 * the element waiting for a place in the "right" partition.
1135 * Let's shift the "same" zone to the left.
1137 sameleft
-= eltsize
;
1138 qsort_rotate((int *) sameright
, (int *) sameleft
, (int *) i
,
1140 sameright
-= eltsize
;
1143 * Go back to 1st loop.
1149 * The partitions are correct now. Recur on the smallest side only.
1151 if (sameleft
- left
>= right
- (sameright
+ eltsize
)) {
1152 qsort_recur(sameright
+ eltsize
, right
, eltsize
, compfun
);
1154 * The "right" partition is now completely sorted.
1155 * The "same" partition is OK, so...
1156 * Ignore them, and start the loops again on the
1162 qsort_recur(left
, sameleft
, eltsize
, compfun
);
1164 * The "left" partition is now completely sorted.
1165 * The "same" partition is OK, so ...
1166 * Ignore them, and start the loops again on the
1167 * "right" partition.
1169 left
= sameright
+ eltsize
;
1179 int (*compfun
)(char *, char *))
1181 char *curr
, *prev
, *last
;
1184 curr
= prev
+ eltsize
;
1185 last
= table
+ (nbelts
* eltsize
);
1187 while (prev
< last
) {
1188 if ((*compfun
)(prev
, curr
) > 0) {
1189 printf("**** qsort_checker: error between 0x%x and 0x%x!!!\n", prev
, curr
);
1195 printf("qsort_checker: OK\n");
1198 int qsort_search_debug
= 0;
1201 db_qsort_limit_search(
1206 int (*compfun
)(char *, char *))
1208 register char *left
, *right
;
1209 char *oleft
, *oright
, *part
;
1213 oleft
= left
= *start
;
1214 oright
= right
= *end
;
1217 while (left
< right
) {
1219 part
= left
+ (((right
- left
) / eltsize
) / 2) * eltsize
;
1220 comp
= (*compfun
)(target
, part
);
1227 if (qsort_search_debug
> 1)
1228 printf(" [ Moved left from 0x%x to 0x%x]\n",
1230 } else if (comp
< 0) {
1234 if (qsort_search_debug
> 1)
1235 printf(" [ Moved right from 0x%x to 0x%x]\n",
1238 if (qsort_search_debug
> 1)
1239 printf(" [ FOUND! left=0x%x right=0x%x]\n",
1242 left
> *start
&& (*compfun
)(left
, part
) == 0;
1244 for (right
= part
+ eltsize
;
1245 right
< *end
&& (*compfun
)(right
, part
) == 0;
1253 if (qsort_search_debug
)
1254 printf("[ Limited from %x-%x to %x-%x in %d iters ]\n",
1255 *start
, *end
, oleft
, oright
, nbiter
);
1265 int (*compfun
)(char *, char *))
1271 end
= table
+ ((nbelts
-1) * eltsize
);
1274 for (p
= table
; p
< end
; p
+= eltsize
) {
1275 if ((*compfun
)(p
, p
+ eltsize
) > 0) {
1276 qsort_swap((int *) p
, (int *) (p
+ eltsize
),
1281 } while (sorted
== FALSE
);
1284 qsort_checker(table
, nbelts
, eltsize
, compfun
);
1287 vm_offset_t vm_min_inks_addr
= VM_MAX_KERNEL_ADDRESS
;
1293 /* save addr to demarcate kernel/inks boundary (1st time only) */
1294 if (vm_min_inks_addr
== VM_MAX_KERNEL_ADDRESS
) {
1295 vm_min_inks_addr
= base
;
1296 db_qualify_ambiguous_names
= TRUE
;
1303 char *clonee
, /* which symtab to clone */
1304 char *cloner
, /* in-kernel-server name */
1305 vm_offset_t base
) /* base address of cloner */
1307 db_symtab_t
*st
, *st_src
;
1311 extern void db_clone_offsetXXX(char *, long);
1313 if (db_nsymtab
>= MAXNOSYMTABS
) {
1314 db_printf("db_clone_symtab: Too Many Symbol Tables\n");
1318 db_install_inks(base
);
1320 st
= &db_symtabs
[db_nsymtab
]; /* destination symtab */
1321 if ((st_src
= db_symtab_cloneeXXX(clonee
)) == 0) {
1322 db_printf("db_clone_symtab: clonee (%s) not found\n", clonee
);
1325 /* alloc new symbols */
1326 size
= (vm_size_t
)(st_src
->end
- st_src
->private);
1327 memp
= (char *)kalloc( round_page(size
) );
1329 db_printf("db_clone_symtab: no memory for symtab\n");
1333 *st
= *st_src
; /* bulk copy src -> dest */
1334 strcpy(st
->name
, cloner
); /* new name */
1335 st
->private = memp
; /* copy symbols */
1336 bcopy((const char *)st_src
->private, st
->private, size
);
1337 st
->start
= memp
+ sizeof(int); /* fixup pointers to symtab */
1338 st
->end
= memp
+ *(int *)memp
;
1339 st
->map_pointer
= 0; /* no map because kernel-loaded */
1341 /* Offset symbols, leaving strings pointing into st_src */
1342 offset
= base
- st_src
->minsym
;
1343 st
->minsym
+= offset
;
1344 st
->maxsym
+= offset
;
1345 db_clone_offsetXXX(memp
, offset
);
1348 db_printf( "[ cloned symbol table for %s: range 0x%x to 0x%x %s]\n",
1349 st
->name
, st
->minsym
, st
->maxsym
,
1350 st
->sorted
? "(sorted) " : "");
1351 db_maxval
= (unsigned int)st
->maxsym
+ db_maxoff
;
1355 db_symtab_cloneeXXX(
1358 db_symtab_t
*st
, *st_src
;
1360 st
= &db_symtabs
[db_nsymtab
]; /* destination symtab */
1361 for (st_src
= &db_symtabs
[0]; st_src
< st
; ++st_src
)
1362 if (!strcmp(clonee
, st_src
->name
))
1364 return ((st_src
< st
) ? st_src
: 0);
1368 * Switch into symbol-table specific routines
1371 #if !defined(__alpha) && !defined(INTEL860)
1376 #include <ddb/db_aout.h>
1380 #include <ddb/db_coff.h>
1383 static void no_init(void)
1386 db_printf("Non-existent code for ddb init\n");
1389 static boolean_t
no_sym_init(
1395 db_printf("Non-existent code for init of symtab %s\n", name
);
1399 static db_sym_t
no_lookup(
1403 db_printf("Bogus lookup of symbol %s\n", symstr
);
1407 static db_sym_t
no_search(
1410 db_strategy_t strategy
,
1413 db_printf("Bogus search for offset %#llXn", (unsigned long long)off
);
1417 static boolean_t
no_line_at_pc(
1424 db_printf("Bogus search for pc %#llX\n", (unsigned long long)pc
);
1428 static void no_symbol_values(
1433 db_printf("Bogus symbol value resolution\n");
1434 if (namep
) *namep
= NULL
;
1435 if (valuep
) *valuep
= 0;
1438 static db_sym_t
no_search_by_addr(
1447 db_printf("Bogus search for address %#llX\n", (unsigned long long)off
);
1452 no_print_completion(
1456 db_printf("Bogus print completion: not supported\n");
1461 no_lookup_incomplete(
1468 db_printf("Bogus lookup incomplete: not supported\n");
1473 { no_init, no_sym_init, no_lookup, no_search, \
1474 no_line_at_pc, no_symbol_values, no_search_by_addr, \
1475 no_print_completion, no_lookup_incomplete}
1477 struct db_sym_switch x_db
[] = {
1479 /* BSD a.out format (really, sdb/dbx(1) symtabs) */
1482 #else /* DB_NO_AOUT */
1483 { aout_db_init
, aout_db_sym_init
, aout_db_lookup
, aout_db_search_symbol
,
1484 aout_db_line_at_pc
, aout_db_symbol_values
, aout_db_search_by_addr
,
1485 aout_db_print_completion
, aout_db_lookup_incomplete
},
1486 #endif /* DB_NO_AOUT */
1490 #else /* DB_NO_COFF */
1491 { coff_db_init
, coff_db_sym_init
, coff_db_lookup
, coff_db_search_symbol
,
1492 coff_db_line_at_pc
, coff_db_symbol_values
, coff_db_search_by_addr
,
1493 coff_db_print_completion
, coff_db_lookup_incomplete
},
1494 #endif /* DB_NO_COFF */
1496 /* Machdep, not inited here */