2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_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. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
27 * Mach Operating System
28 * Copyright (c) 1991,1990 Carnegie Mellon University
29 * All Rights Reserved.
31 * Permission to use, copy, modify and distribute this software and its
32 * documentation is hereby granted, provided that both the copyright
33 * notice and this permission notice appear in all copies of the
34 * software, derivative works or modified versions, and any portions
35 * thereof, and that both notices appear in supporting documentation.
37 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
38 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
39 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
41 * Carnegie Mellon requests users of this software to return to
43 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
44 * School of Computer Science
45 * Carnegie Mellon University
46 * Pittsburgh PA 15213-3890
48 * any improvements or extensions that they make and grant Carnegie Mellon
49 * the rights to redistribute these changes.
54 * Author: David B. Golub, Carnegie Mellon University
58 #include <machine/db_machdep.h>
59 #include <string.h> /* For strcpy(), strcmp() */
60 #include <mach/std_types.h>
61 #include <kern/misc_protos.h> /* For printf() */
62 #include <ddb/db_sym.h>
63 #include <ddb/db_task_thread.h>
64 #include <ddb/db_command.h>
65 #include <ddb/db_output.h> /* For db_printf() */
67 #include <vm/vm_map.h> /* vm_map_t */
70 * Multiple symbol tables
72 * mach, bootstrap, name_server, default_pager, unix, 1 spare
74 #define MAXNOSYMTABS 6
76 db_symtab_t db_symtabs
[MAXNOSYMTABS
] = {{0}};
79 db_symtab_t
*db_last_symtab
;
81 unsigned long db_maxoff
= 0x4000;
83 unsigned long db_maxval
= (unsigned long)&end
;
84 natural_t db_minval
= 0x1000;
86 /* Prototypes for functions local to this file. XXX -- should be static!
88 static char *db_qualify(
90 register char *symtabname
);
97 boolean_t
db_symbol_is_ambiguous(char *name
);
99 void db_shorten_filename(char **filenamep
);
116 int (*compfun
)(char *, char *));
122 int (*compfun
)(char *, char *));
128 int (*compfun
)(char *, char *));
130 int no_print_completion(
133 int no_lookup_incomplete(
141 * Initialization routine for ddb.
151 * Add symbol table, with given name, to list of symbol tables.
161 unsigned long minsym
,
162 unsigned long maxsym
,
165 register db_symtab_t
*st
;
166 extern vm_map_t kernel_map
;
168 if (db_nsymtab
>= MAXNOSYMTABS
)
171 st
= &db_symtabs
[db_nsymtab
];
176 if (map_pointer
== (char *)kernel_map
||
177 (VM_MAX_ADDRESS
<= VM_MIN_KERNEL_ADDRESS
&&
178 VM_MIN_KERNEL_ADDRESS
<= minsym
))
181 st
->map_pointer
= map_pointer
;
182 strcpy(st
->name
, name
);
189 if (db_maxval
< maxsym
+ db_maxoff
)
190 db_maxval
= maxsym
+ db_maxoff
;
198 * db_qualify("vm_map", "ux") returns "ux::vm_map".
200 * Note: return value points to static data whose content is
201 * overwritten by each call... but in practice this seems okay.
206 register char *symtabname
)
208 static char tmp
[256];
212 while (*s
++ = *symtabname
++) {
216 while (*s
++ = *symname
++) {
228 if (!strcmp(src
, dst
))
231 return (!strcmp(src
+1,dst
));
242 sym
= db_lookup(name
);
243 if (sym
== DB_SYM_NULL
)
245 db_symbol_values(0, sym
, &name
, valuep
);
250 * Display list of possible completions for a symbol.
257 int symtab_start
= 0;
258 int symtab_end
= db_nsymtab
;
261 char *name
= (char *)0;
266 * Look for, remove, and remember any symbol table specifier.
268 for (cp
= symstr
; *cp
; cp
++) {
269 if (*cp
== ':' && cp
[1] == ':') {
271 for (i
= 0; i
< db_nsymtab
; i
++) {
272 if (! strcmp(symstr
, db_symtabs
[i
].name
)) {
286 * Look in the specified set of symbol tables.
287 * Return on first match.
289 for (i
= symtab_start
; i
< symtab_end
; i
++) {
290 if (X_db_print_completion(&db_symtabs
[i
], symstr
))
296 * Lookup a (perhaps incomplete) symbol.
297 * If the symbol has a qualifier (e.g., ux::vm_map),
298 * then only the specified symbol table will be searched;
299 * otherwise, all symbol tables will be searched.
302 db_lookup_incomplete(
307 int symtab_start
= 0;
308 int symtab_end
= db_nsymtab
;
311 char *name
= (char *)0;
316 * Look for, remove, and remember any symbol table specifier.
318 for (cp
= symstr
; *cp
; cp
++) {
319 if (*cp
== ':' && cp
[1] == ':') {
321 for (i
= 0; i
< db_nsymtab
; i
++) {
322 if (! strcmp(symstr
, db_symtabs
[i
].name
)) {
336 * Look in the specified set of symbol tables.
337 * Return on first match.
339 for (i
= symtab_start
; i
< symtab_end
; i
++) {
340 nsym
= X_db_lookup_incomplete(&db_symtabs
[i
], symstr
,
341 &name
, &len
, &toadd
);
344 len
= strlen(symstr
);
345 if (len
+ toadd
>= symlen
)
347 bcopy(&name
[len
], &symstr
[len
], toadd
);
348 symstr
[len
+ toadd
] = '\0';
358 * If the symbol has a qualifier (e.g., ux::vm_map),
359 * then only the specified symbol table will be searched;
360 * otherwise, all symbol tables will be searched.
363 db_lookup(char *symstr
)
367 int symtab_start
= 0;
368 int symtab_end
= db_nsymtab
;
372 * Look for, remove, and remember any symbol table specifier.
374 for (cp
= symstr
; *cp
; cp
++) {
375 if (*cp
== ':' && cp
[1] == ':') {
377 for (i
= 0; i
< db_nsymtab
; i
++) {
378 if (! strcmp(symstr
, db_symtabs
[i
].name
)) {
386 db_error("Invalid symbol table name\n");
392 * Look in the specified set of symbol tables.
393 * Return on first match.
395 for (i
= symtab_start
; i
< symtab_end
; i
++) {
396 if (sp
= X_db_lookup(&db_symtabs
[i
], symstr
)) {
397 db_last_symtab
= &db_symtabs
[i
];
405 * Print a symbol completion
408 db_sym_print_completion(
415 if (stab
!= db_symtabs
)
416 db_printf("%s::", stab
->name
);
423 db_printf(" [static from %s", fname
);
425 db_printf(":%d", line
);
432 * Common utility routine to parse a symbol string into a file
433 * name, a (possibly incomplete) symbol name without line number.
434 * This routine is called from aout_db_print_completion if the object
435 * dependent handler supports qualified search with a file name.
436 * It parses the symbol string, and call an object dependent routine
437 * with parsed file name and symbol name.
440 db_sym_parse_and_print_completion(
441 int (*func
)(db_symtab_t
*,
453 * disassemble the symbol into components: [file_name:]symbol
455 component
[0] = symstr
;
457 for (p
= symstr
, n
= 1; *p
; p
++) {
462 component
[n
++] = p
+1;
467 sym_name
= component
[0];
469 sym_name
= component
[1];
471 nsym
= func(symtab
, sym_name
);
475 component
[1][-1] = ':';
480 * Common utility routine to parse a symbol string into a file
481 * name, a (possibly incomplete) symbol name without line number.
482 * This routine is called from X_db_lookup_incomplete if the object
483 * dependent handler supports qualified search with a file name.
484 * It parses the symbol string, and call an object dependent routine
485 * with parsed file name and symbol name.
488 db_sym_parse_and_lookup_incomplete(
489 int (*func
)(db_symtab_t
*,
510 * disassemble the symbol into components: [file_name:]symbol
512 component
[0] = symstr
;
514 for (p
= symstr
, n
= 1; *p
; p
++) {
519 component
[n
++] = p
+1;
525 sym_name
= component
[0];
527 file_name
= component
[0];
528 sym_name
= component
[1];
530 nsym
= func(symtab
, file_name
, sym_name
, 0, (db_sym_t
*)0,
533 *toadd
= *len
- strlen(sym_name
);
536 component
[1][-1] = ':';
541 * Common utility routine to parse a symbol string into a file
542 * name, a symbol name and line number.
543 * This routine is called from aout_db_lookup if the object dependent
544 * handler supports qualified search with a file name or a line number.
545 * It parses the symbol string, and call an object dependent routine
546 * with parsed file name, symbol name and line number.
549 db_sym_parse_and_lookup(
550 int (*func
)(db_symtab_t
*, char *, char *, int,
551 db_sym_t
*, char **, int *),
562 db_sym_t found
= DB_SYM_NULL
;
565 * disassemble the symbol into components:
566 * [file_name:]symbol[:line_nubmer]
568 component
[0] = symstr
;
569 component
[1] = component
[2] = 0;
570 for (p
= symstr
, n
= 1; *p
; p
++) {
575 component
[n
++] = p
+1;
583 if (*p
>= '0' && *p
<= '9') {
586 for (line_number
= 0; *p
; p
++) {
587 if (*p
< '0' || *p
> '9')
589 line_number
= line_number
*10 + *p
- '0';
595 for (p
= component
[0]; *p
&& *p
!= '.'; p
++);
597 file_name
= component
[0];
601 sym_name
= component
[0];
604 file_name
= component
[0];
605 sym_name
= component
[1];
607 (void) func(symtab
, file_name
, sym_name
, line_number
, &found
,
608 (char **)0, (int *)0);
612 component
[n
][-1] = ':';
617 * Does this symbol name appear in more than one symbol table?
618 * Used by db_symbol_values to decide whether to qualify a symbol.
620 boolean_t db_qualify_ambiguous_names
= TRUE
;
623 db_symbol_is_ambiguous(char *name
)
627 boolean_t found_once
= FALSE
;
629 if (!db_qualify_ambiguous_names
)
632 for (i
= 0; i
< db_nsymtab
; i
++) {
633 if (X_db_lookup(&db_symtabs
[i
], name
)) {
643 * Find the closest symbol to val, and return its name
644 * and the difference between val and the symbol found.
646 unsigned int db_search_maxoff
= 0x4000;
648 db_search_task_symbol(
649 register db_addr_t val
,
650 db_strategy_t strategy
,
651 db_addr_t
*offp
, /* better be unsigned */
654 db_addr_t diff
, newdiff
;
657 db_sym_t ret
= DB_SYM_NULL
, sym
;
658 vm_map_t map_for_val
;
660 if (task
== TASK_NULL
)
661 task
= db_current_task();
662 map_for_val
= (task
== TASK_NULL
)? VM_MAP_NULL
: task
->map
;
666 for (sp
= &db_symtabs
[0], i
= 0;
669 if ((((vm_map_t
)sp
->map_pointer
== VM_MAP_NULL
) ||
670 ((vm_map_t
)sp
->map_pointer
== map_for_val
)) &&
671 ((sp
->maxsym
== 0) ||
672 ((val
>= (db_addr_t
)sp
->minsym
) &&
673 (val
<= (db_addr_t
)sp
->maxsym
)))) {
674 sym
= X_db_search_symbol(sp
, val
, strategy
,
675 (db_expr_t
*)&newdiff
);
676 if (newdiff
< diff
) {
680 if (diff
<= db_search_maxoff
)
685 if (ret
== DB_SYM_NULL
&& map_for_val
!= VM_MAP_NULL
) {
686 map_for_val
= VM_MAP_NULL
;
694 * Find the closest symbol to val, and return its name
695 * and the difference between val and the symbol found.
696 * Also return the filename and linenumber if available.
699 db_search_task_symbol_and_line(
700 register db_addr_t val
,
701 db_strategy_t strategy
,
708 db_addr_t diff
, newdiff
;
711 db_sym_t ret
= DB_SYM_NULL
, sym
;
712 vm_map_t map_for_val
;
718 if (task
== TASK_NULL
)
719 task
= db_current_task();
720 map_for_val
= (task
== TASK_NULL
)? VM_MAP_NULL
: task
->map
;
721 *filenamep
= (char *) 0;
725 filename
= (char *) 0;
727 newdiff
= diff
= ~0UL;
729 for (sp
= &db_symtabs
[0], i
= 0;
732 if ((((vm_map_t
)sp
->map_pointer
== VM_MAP_NULL
) ||
733 ((vm_map_t
)sp
->map_pointer
== map_for_val
)) &&
734 ((sp
->maxsym
== 0) ||
735 ((val
>= (db_addr_t
)sp
->minsym
) &&
736 (val
<= (db_addr_t
)sp
->maxsym
)))) {
738 sym
= X_db_search_by_addr(sp
, val
, &filename
, &func
,
739 &linenum
, (db_expr_t
*)&newdiff
,
741 if (sym
&& newdiff
< diff
) {
745 *filenamep
= filename
;
748 if (diff
<= db_search_maxoff
)
753 if (ret
== DB_SYM_NULL
&& map_for_val
!= VM_MAP_NULL
) {
754 map_for_val
= VM_MAP_NULL
;
759 db_shorten_filename(filenamep
);
764 * Return name and value of a symbol
776 if (sym
== DB_SYM_NULL
) {
781 stab
= db_last_symtab
;
783 X_db_symbol_values(stab
, sym
, &name
, &value
);
785 if (db_symbol_is_ambiguous(name
)) {
786 *namep
= db_qualify(name
, db_last_symtab
->name
);
796 * Print a the closest symbol to value
798 * After matching the symbol according to the given strategy
799 * we print it in the name+offset format, provided the symbol's
800 * value is close enough (eg smaller than db_maxoff).
801 * We also attempt to print [filename:linenum] when applicable
802 * (eg for procedure names).
804 * If we could not find a reasonable name+offset representation,
805 * then we just print the value in hex. Small values might get
806 * bogus symbol associations, e.g. 3 might get some absolute
807 * value like _INCLUDE_VERSION or something, therefore we do
808 * not accept symbols whose value is zero (and use plain hex).
814 db_strategy_t strategy
,
824 if (off
>= db_maxval
|| off
< db_minval
) {
825 db_printf("%#lln", (unsigned long long)off
);
828 cursym
= db_search_task_symbol(off
, strategy
, &d
, task
);
830 db_symbol_values(0, cursym
, &name
, &value
);
831 if (name
== 0 || d
>= db_maxoff
|| value
== 0) {
832 db_printf("%#lln",(unsigned long long) off
);
835 db_printf("%s", name
);
837 db_printf("+%llx", (unsigned long long)d
);
838 if (strategy
== DB_STGY_PROC
) {
839 if (db_line_at_pc(cursym
, &filename
, &linenum
, off
)) {
840 db_printf(" [%s", filename
);
842 db_printf(":%d", linenum
);
849 * Return symbol name for a given offset and
850 * change the offset to be relative to this symbol.
851 * Very usefull for xpr, when you want to log offsets
852 * in a user friendly way.
855 char null_sym
[] = "";
858 db_get_sym(db_expr_t
*off
)
865 cursym
= db_search_symbol(*off
, DB_STGY_ANY
, &d
);
866 db_symbol_values(0, cursym
, &name
, &value
);
877 db_strategy_t strategy
)
879 db_task_printsym(off
, strategy
, TASK_NULL
);
882 int db_short_filename
= 1;
885 db_shorten_filename(char **filenamep
)
891 for (cp
= cp_slash
= *filenamep
; *cp
; cp
++) {
895 if (*cp_slash
== '/')
896 *filenamep
= cp_slash
+1;
910 db_strategy_t strategy
= DB_STGY_PROC
;
912 if (off
>= db_maxval
|| off
< db_minval
) {
913 db_printf("%#lln", (unsigned long long)off
);
916 cursym
= db_search_task_symbol(off
, strategy
, &d
, task
);
918 db_symbol_values(0, cursym
, &name
, &value
);
919 if (name
== 0 || d
>= db_maxoff
|| value
== 0) {
922 if (db_line_at_pc(cursym
, &filename
, &linenum
, off
))
937 if (db_last_symtab
== 0)
939 if (X_db_line_at_pc( db_last_symtab
, sym
, filename
, linenum
, pc
)) {
940 if (db_short_filename
)
941 db_shorten_filename(filename
);
955 int (*compfun
)(char *, char *))
957 if (nbelts
<= 0 || eltsize
<= 0 || compfun
== 0) {
958 printf("qsort: invalid parameters\n");
961 qsort_recur(table
, table
+ nbelts
* eltsize
, eltsize
, compfun
);
964 qsort_checker(table
, nbelts
, eltsize
, compfun
);
977 for (; size
>= sizeof (int); size
-= sizeof (int), a
++, b
++) {
984 for (; size
> 0; size
--, aa
++, bb
++) {
991 /* rotate the three elements to the left */
1003 for (; size
>= sizeof (int); size
-= sizeof (int), a
++, b
++, c
++) {
1012 for (; size
> 0; size
--, aa
++, bb
++, cc
++) {
1025 int (*compfun
)(char *, char *))
1028 char *sameleft
, *sameright
;
1031 if (left
+ eltsize
- 1 >= right
) {
1035 /* partition element (reference for "same"ness */
1036 sameleft
= left
+ (((right
- left
) / eltsize
) / 2) * eltsize
;
1037 sameright
= sameleft
;
1040 j
= right
- eltsize
;
1043 while (i
< sameleft
) {
1046 comp
= (*compfun
)(i
, sameleft
);
1049 * Move to the "same" partition.
1052 * Shift the left part of the "same" partition to
1053 * the left, so that "same" elements stay in their
1056 sameleft
-= eltsize
;
1057 qsort_swap((int *) i
, (int *) sameleft
, eltsize
);
1058 } else if (comp
< 0) {
1060 * Stay in the "left" partition.
1065 * Should be moved to the "right" partition.
1066 * Wait until the next loop finds an appropriate
1067 * place to store this element.
1073 while (j
> sameright
) {
1076 comp
= (*compfun
)(sameright
, j
);
1079 * Move to the right of the "same" partition.
1081 sameright
+= eltsize
;
1082 qsort_swap((int *) sameright
, (int *) j
, eltsize
);
1083 } else if (comp
> 0) {
1085 * Move to the "left" partition.
1087 if (i
== sameleft
) {
1089 * Unfortunately, the "left" partition
1090 * has already been fully processed, so
1091 * we have to shift the "same" partition
1092 * to the right to free a "left" element.
1093 * This is done by moving the leftest same
1094 * to the right of the "same" partition.
1096 sameright
+= eltsize
;
1097 qsort_rotate((int *) sameleft
, (int*) sameright
,
1098 (int *) j
, eltsize
);
1099 sameleft
+= eltsize
;
1103 * Swap with the "left" partition element
1104 * waiting to be moved to the "right"
1107 qsort_swap((int *) i
, (int *) j
, eltsize
);
1110 * Go back to the 1st loop.
1117 * Stay in the "right" partition.
1123 if (i
!= sameleft
) {
1125 * The second loop completed (the"right" partition is ok),
1126 * but we have to go back to the first loop, and deal with
1127 * the element waiting for a place in the "right" partition.
1128 * Let's shift the "same" zone to the left.
1130 sameleft
-= eltsize
;
1131 qsort_rotate((int *) sameright
, (int *) sameleft
, (int *) i
,
1133 sameright
-= eltsize
;
1136 * Go back to 1st loop.
1142 * The partitions are correct now. Recur on the smallest side only.
1144 if (sameleft
- left
>= right
- (sameright
+ eltsize
)) {
1145 qsort_recur(sameright
+ eltsize
, right
, eltsize
, compfun
);
1147 * The "right" partition is now completely sorted.
1148 * The "same" partition is OK, so...
1149 * Ignore them, and start the loops again on the
1155 qsort_recur(left
, sameleft
, eltsize
, compfun
);
1157 * The "left" partition is now completely sorted.
1158 * The "same" partition is OK, so ...
1159 * Ignore them, and start the loops again on the
1160 * "right" partition.
1162 left
= sameright
+ eltsize
;
1172 int (*compfun
)(char *, char *))
1174 char *curr
, *prev
, *last
;
1177 curr
= prev
+ eltsize
;
1178 last
= table
+ (nbelts
* eltsize
);
1180 while (prev
< last
) {
1181 if ((*compfun
)(prev
, curr
) > 0) {
1182 printf("**** qsort_checker: error between 0x%x and 0x%x!!!\n", prev
, curr
);
1188 printf("qsort_checker: OK\n");
1191 int qsort_search_debug
= 0;
1194 db_qsort_limit_search(
1199 int (*compfun
)(char *, char *))
1201 register char *left
, *right
;
1202 char *oleft
, *oright
, *part
;
1206 oleft
= left
= *start
;
1207 oright
= right
= *end
;
1210 while (left
< right
) {
1212 part
= left
+ (((right
- left
) / eltsize
) / 2) * eltsize
;
1213 comp
= (*compfun
)(target
, part
);
1220 if (qsort_search_debug
> 1)
1221 printf(" [ Moved left from 0x%x to 0x%x]\n",
1223 } else if (comp
< 0) {
1227 if (qsort_search_debug
> 1)
1228 printf(" [ Moved right from 0x%x to 0x%x]\n",
1231 if (qsort_search_debug
> 1)
1232 printf(" [ FOUND! left=0x%x right=0x%x]\n",
1235 left
> *start
&& (*compfun
)(left
, part
) == 0;
1237 for (right
= part
+ eltsize
;
1238 right
< *end
&& (*compfun
)(right
, part
) == 0;
1246 if (qsort_search_debug
)
1247 printf("[ Limited from %x-%x to %x-%x in %d iters ]\n",
1248 *start
, *end
, oleft
, oright
, nbiter
);
1258 int (*compfun
)(char *, char *))
1264 end
= table
+ ((nbelts
-1) * eltsize
);
1267 for (p
= table
; p
< end
; p
+= eltsize
) {
1268 if ((*compfun
)(p
, p
+ eltsize
) > 0) {
1269 qsort_swap((int *) p
, (int *) (p
+ eltsize
),
1274 } while (sorted
== FALSE
);
1277 qsort_checker(table
, nbelts
, eltsize
, compfun
);
1280 vm_offset_t vm_min_inks_addr
= VM_MAX_KERNEL_ADDRESS
;
1286 /* save addr to demarcate kernel/inks boundary (1st time only) */
1287 if (vm_min_inks_addr
== VM_MAX_KERNEL_ADDRESS
) {
1288 vm_min_inks_addr
= base
;
1289 db_qualify_ambiguous_names
= TRUE
;
1296 char *clonee
, /* which symtab to clone */
1297 char *cloner
, /* in-kernel-server name */
1298 vm_offset_t base
) /* base address of cloner */
1300 db_symtab_t
*st
, *st_src
;
1304 extern void db_clone_offsetXXX(char *, long);
1306 if (db_nsymtab
>= MAXNOSYMTABS
) {
1307 db_printf("db_clone_symtab: Too Many Symbol Tables\n");
1311 db_install_inks(base
);
1313 st
= &db_symtabs
[db_nsymtab
]; /* destination symtab */
1314 if ((st_src
= db_symtab_cloneeXXX(clonee
)) == 0) {
1315 db_printf("db_clone_symtab: clonee (%s) not found\n", clonee
);
1318 /* alloc new symbols */
1319 size
= (vm_size_t
)(st_src
->end
- st_src
->private);
1320 memp
= (char *)kalloc( round_page(size
) );
1322 db_printf("db_clone_symtab: no memory for symtab\n");
1326 *st
= *st_src
; /* bulk copy src -> dest */
1327 strcpy(st
->name
, cloner
); /* new name */
1328 st
->private = memp
; /* copy symbols */
1329 bcopy((const char *)st_src
->private, st
->private, size
);
1330 st
->start
= memp
+ sizeof(int); /* fixup pointers to symtab */
1331 st
->end
= memp
+ *(int *)memp
;
1332 st
->map_pointer
= 0; /* no map because kernel-loaded */
1334 /* Offset symbols, leaving strings pointing into st_src */
1335 offset
= base
- st_src
->minsym
;
1336 st
->minsym
+= offset
;
1337 st
->maxsym
+= offset
;
1338 db_clone_offsetXXX(memp
, offset
);
1341 db_printf( "[ cloned symbol table for %s: range 0x%x to 0x%x %s]\n",
1342 st
->name
, st
->minsym
, st
->maxsym
,
1343 st
->sorted
? "(sorted) " : "");
1344 db_maxval
= (unsigned int)st
->maxsym
+ db_maxoff
;
1348 db_symtab_cloneeXXX(
1351 db_symtab_t
*st
, *st_src
;
1353 st
= &db_symtabs
[db_nsymtab
]; /* destination symtab */
1354 for (st_src
= &db_symtabs
[0]; st_src
< st
; ++st_src
)
1355 if (!strcmp(clonee
, st_src
->name
))
1357 return ((st_src
< st
) ? st_src
: 0);
1361 * Switch into symbol-table specific routines
1364 #if !defined(__alpha) && !defined(INTEL860)
1369 #include <ddb/db_aout.h>
1373 #include <ddb/db_coff.h>
1376 static void no_init(void)
1379 db_printf("Non-existent code for ddb init\n");
1382 static boolean_t
no_sym_init(
1388 db_printf("Non-existent code for init of symtab %s\n", name
);
1392 static db_sym_t
no_lookup(
1396 db_printf("Bogus lookup of symbol %s\n", symstr
);
1400 static db_sym_t
no_search(
1403 db_strategy_t strategy
,
1406 db_printf("Bogus search for offset %#llXn", (unsigned long long)off
);
1410 static boolean_t
no_line_at_pc(
1417 db_printf("Bogus search for pc %#llX\n", (unsigned long long)pc
);
1421 static void no_symbol_values(
1426 db_printf("Bogus symbol value resolution\n");
1427 if (namep
) *namep
= NULL
;
1428 if (valuep
) *valuep
= 0;
1431 static db_sym_t
no_search_by_addr(
1440 db_printf("Bogus search for address %#llX\n", (unsigned long long)off
);
1445 no_print_completion(
1449 db_printf("Bogus print completion: not supported\n");
1454 no_lookup_incomplete(
1461 db_printf("Bogus lookup incomplete: not supported\n");
1466 { no_init, no_sym_init, no_lookup, no_search, \
1467 no_line_at_pc, no_symbol_values, no_search_by_addr, \
1468 no_print_completion, no_lookup_incomplete}
1470 struct db_sym_switch x_db
[] = {
1472 /* BSD a.out format (really, sdb/dbx(1) symtabs) */
1475 #else /* DB_NO_AOUT */
1476 { aout_db_init
, aout_db_sym_init
, aout_db_lookup
, aout_db_search_symbol
,
1477 aout_db_line_at_pc
, aout_db_symbol_values
, aout_db_search_by_addr
,
1478 aout_db_print_completion
, aout_db_lookup_incomplete
},
1479 #endif /* DB_NO_AOUT */
1483 #else /* DB_NO_COFF */
1484 { coff_db_init
, coff_db_sym_init
, coff_db_lookup
, coff_db_search_symbol
,
1485 coff_db_line_at_pc
, coff_db_symbol_values
, coff_db_search_by_addr
,
1486 coff_db_print_completion
, coff_db_lookup_incomplete
},
1487 #endif /* DB_NO_COFF */
1489 /* Machdep, not inited here */