2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
26 * Mach Operating System
27 * Copyright (c) 1991,1990 Carnegie Mellon University
28 * All Rights Reserved.
30 * Permission to use, copy, modify and distribute this software and its
31 * documentation is hereby granted, provided that both the copyright
32 * notice and this permission notice appear in all copies of the
33 * software, derivative works or modified versions, and any portions
34 * thereof, and that both notices appear in supporting documentation.
36 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
37 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
38 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
40 * Carnegie Mellon requests users of this software to return to
42 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
43 * School of Computer Science
44 * Carnegie Mellon University
45 * Pittsburgh PA 15213-3890
47 * any improvements or extensions that they make and grant Carnegie Mellon
48 * the rights to redistribute these changes.
53 * Author: David B. Golub, Carnegie Mellon University
57 #include <machine/db_machdep.h>
58 #include <string.h> /* For strcpy(), strcmp() */
59 #include <mach/std_types.h>
60 #include <kern/misc_protos.h> /* For printf() */
61 #include <ddb/db_sym.h>
62 #include <ddb/db_task_thread.h>
63 #include <ddb/db_command.h>
64 #include <ddb/db_output.h> /* For db_printf() */
66 #include <vm/vm_map.h> /* vm_map_t */
69 * Multiple symbol tables
71 * mach, bootstrap, name_server, default_pager, unix, 1 spare
73 #define MAXNOSYMTABS 6
75 db_symtab_t db_symtabs
[MAXNOSYMTABS
] = {{0}};
78 db_symtab_t
*db_last_symtab
;
80 unsigned long db_maxoff
= 0x4000;
82 unsigned long db_maxval
= (unsigned long)&end
;
83 natural_t db_minval
= 0x1000;
85 /* Prototypes for functions local to this file. XXX -- should be static!
87 static char *db_qualify(
89 register char *symtabname
);
96 boolean_t
db_symbol_is_ambiguous(char *name
);
98 void db_shorten_filename(char **filenamep
);
115 int (*compfun
)(char *, char *));
121 int (*compfun
)(char *, char *));
127 int (*compfun
)(char *, char *));
129 int no_print_completion(
132 int no_lookup_incomplete(
140 * Initialization routine for ddb.
150 * Add symbol table, with given name, to list of symbol tables.
160 unsigned long minsym
,
161 unsigned long maxsym
,
164 register db_symtab_t
*st
;
165 extern vm_map_t kernel_map
;
167 if (db_nsymtab
>= MAXNOSYMTABS
)
170 st
= &db_symtabs
[db_nsymtab
];
175 if (map_pointer
== (char *)kernel_map
||
176 (VM_MAX_ADDRESS
<= VM_MIN_KERNEL_ADDRESS
&&
177 VM_MIN_KERNEL_ADDRESS
<= minsym
))
180 st
->map_pointer
= map_pointer
;
181 strcpy(st
->name
, name
);
188 if (db_maxval
< maxsym
+ db_maxoff
)
189 db_maxval
= maxsym
+ db_maxoff
;
197 * db_qualify("vm_map", "ux") returns "ux::vm_map".
199 * Note: return value points to static data whose content is
200 * overwritten by each call... but in practice this seems okay.
205 register char *symtabname
)
207 static char tmp
[256];
211 while (*s
++ = *symtabname
++) {
215 while (*s
++ = *symname
++) {
227 if (!strcmp(src
, dst
))
230 return (!strcmp(src
+1,dst
));
241 sym
= db_lookup(name
);
242 if (sym
== DB_SYM_NULL
)
244 db_symbol_values(0, sym
, &name
, valuep
);
249 * Display list of possible completions for a symbol.
256 int symtab_start
= 0;
257 int symtab_end
= db_nsymtab
;
260 char *name
= (char *)0;
265 * Look for, remove, and remember any symbol table specifier.
267 for (cp
= symstr
; *cp
; cp
++) {
268 if (*cp
== ':' && cp
[1] == ':') {
270 for (i
= 0; i
< db_nsymtab
; i
++) {
271 if (! strcmp(symstr
, db_symtabs
[i
].name
)) {
285 * Look in the specified set of symbol tables.
286 * Return on first match.
288 for (i
= symtab_start
; i
< symtab_end
; i
++) {
289 if (X_db_print_completion(&db_symtabs
[i
], symstr
))
295 * Lookup a (perhaps incomplete) symbol.
296 * If the symbol has a qualifier (e.g., ux::vm_map),
297 * then only the specified symbol table will be searched;
298 * otherwise, all symbol tables will be searched.
301 db_lookup_incomplete(
306 int symtab_start
= 0;
307 int symtab_end
= db_nsymtab
;
310 char *name
= (char *)0;
315 * Look for, remove, and remember any symbol table specifier.
317 for (cp
= symstr
; *cp
; cp
++) {
318 if (*cp
== ':' && cp
[1] == ':') {
320 for (i
= 0; i
< db_nsymtab
; i
++) {
321 if (! strcmp(symstr
, db_symtabs
[i
].name
)) {
335 * Look in the specified set of symbol tables.
336 * Return on first match.
338 for (i
= symtab_start
; i
< symtab_end
; i
++) {
339 nsym
= X_db_lookup_incomplete(&db_symtabs
[i
], symstr
,
340 &name
, &len
, &toadd
);
343 len
= strlen(symstr
);
344 if (len
+ toadd
>= symlen
)
346 bcopy(&name
[len
], &symstr
[len
], toadd
);
347 symstr
[len
+ toadd
] = '\0';
357 * If the symbol has a qualifier (e.g., ux::vm_map),
358 * then only the specified symbol table will be searched;
359 * otherwise, all symbol tables will be searched.
362 db_lookup(char *symstr
)
366 int symtab_start
= 0;
367 int symtab_end
= db_nsymtab
;
371 * Look for, remove, and remember any symbol table specifier.
373 for (cp
= symstr
; *cp
; cp
++) {
374 if (*cp
== ':' && cp
[1] == ':') {
376 for (i
= 0; i
< db_nsymtab
; i
++) {
377 if (! strcmp(symstr
, db_symtabs
[i
].name
)) {
385 db_error("Invalid symbol table name\n");
391 * Look in the specified set of symbol tables.
392 * Return on first match.
394 for (i
= symtab_start
; i
< symtab_end
; i
++) {
395 if (sp
= X_db_lookup(&db_symtabs
[i
], symstr
)) {
396 db_last_symtab
= &db_symtabs
[i
];
404 * Print a symbol completion
407 db_sym_print_completion(
414 if (stab
!= db_symtabs
)
415 db_printf("%s::", stab
->name
);
422 db_printf(" [static from %s", fname
);
424 db_printf(":%d", line
);
431 * Common utility routine to parse a symbol string into a file
432 * name, a (possibly incomplete) symbol name without line number.
433 * This routine is called from aout_db_print_completion if the object
434 * dependent handler supports qualified search with a file name.
435 * It parses the symbol string, and call an object dependent routine
436 * with parsed file name and symbol name.
439 db_sym_parse_and_print_completion(
440 int (*func
)(db_symtab_t
*,
452 * disassemble the symbol into components: [file_name:]symbol
454 component
[0] = symstr
;
456 for (p
= symstr
, n
= 1; *p
; p
++) {
461 component
[n
++] = p
+1;
466 sym_name
= component
[0];
468 sym_name
= component
[1];
470 nsym
= func(symtab
, sym_name
);
474 component
[1][-1] = ':';
479 * Common utility routine to parse a symbol string into a file
480 * name, a (possibly incomplete) symbol name without line number.
481 * This routine is called from X_db_lookup_incomplete if the object
482 * dependent handler supports qualified search with a file name.
483 * It parses the symbol string, and call an object dependent routine
484 * with parsed file name and symbol name.
487 db_sym_parse_and_lookup_incomplete(
488 int (*func
)(db_symtab_t
*,
509 * disassemble the symbol into components: [file_name:]symbol
511 component
[0] = symstr
;
513 for (p
= symstr
, n
= 1; *p
; p
++) {
518 component
[n
++] = p
+1;
524 sym_name
= component
[0];
526 file_name
= component
[0];
527 sym_name
= component
[1];
529 nsym
= func(symtab
, file_name
, sym_name
, 0, (db_sym_t
*)0,
532 *toadd
= *len
- strlen(sym_name
);
535 component
[1][-1] = ':';
540 * Common utility routine to parse a symbol string into a file
541 * name, a symbol name and line number.
542 * This routine is called from aout_db_lookup if the object dependent
543 * handler supports qualified search with a file name or a line number.
544 * It parses the symbol string, and call an object dependent routine
545 * with parsed file name, symbol name and line number.
548 db_sym_parse_and_lookup(
549 int (*func
)(db_symtab_t
*, char *, char *, int,
550 db_sym_t
*, char **, int *),
561 db_sym_t found
= DB_SYM_NULL
;
564 * disassemble the symbol into components:
565 * [file_name:]symbol[:line_nubmer]
567 component
[0] = symstr
;
568 component
[1] = component
[2] = 0;
569 for (p
= symstr
, n
= 1; *p
; p
++) {
574 component
[n
++] = p
+1;
582 if (*p
>= '0' && *p
<= '9') {
585 for (line_number
= 0; *p
; p
++) {
586 if (*p
< '0' || *p
> '9')
588 line_number
= line_number
*10 + *p
- '0';
594 for (p
= component
[0]; *p
&& *p
!= '.'; p
++);
596 file_name
= component
[0];
600 sym_name
= component
[0];
603 file_name
= component
[0];
604 sym_name
= component
[1];
606 (void) func(symtab
, file_name
, sym_name
, line_number
, &found
,
607 (char **)0, (int *)0);
611 component
[n
][-1] = ':';
616 * Does this symbol name appear in more than one symbol table?
617 * Used by db_symbol_values to decide whether to qualify a symbol.
619 boolean_t db_qualify_ambiguous_names
= TRUE
;
622 db_symbol_is_ambiguous(char *name
)
626 boolean_t found_once
= FALSE
;
628 if (!db_qualify_ambiguous_names
)
631 for (i
= 0; i
< db_nsymtab
; i
++) {
632 if (X_db_lookup(&db_symtabs
[i
], name
)) {
642 * Find the closest symbol to val, and return its name
643 * and the difference between val and the symbol found.
645 unsigned int db_search_maxoff
= 0x4000;
647 db_search_task_symbol(
648 register db_addr_t val
,
649 db_strategy_t strategy
,
650 db_addr_t
*offp
, /* better be unsigned */
653 db_addr_t diff
, newdiff
;
656 db_sym_t ret
= DB_SYM_NULL
, sym
;
657 vm_map_t map_for_val
;
659 if (task
== TASK_NULL
)
660 task
= db_current_task();
661 map_for_val
= (task
== TASK_NULL
)? VM_MAP_NULL
: task
->map
;
665 for (sp
= &db_symtabs
[0], i
= 0;
668 if ((((vm_map_t
)sp
->map_pointer
== VM_MAP_NULL
) ||
669 ((vm_map_t
)sp
->map_pointer
== map_for_val
)) &&
670 ((sp
->maxsym
== 0) ||
671 ((val
>= (db_addr_t
)sp
->minsym
) &&
672 (val
<= (db_addr_t
)sp
->maxsym
)))) {
673 sym
= X_db_search_symbol(sp
, val
, strategy
,
674 (db_expr_t
*)&newdiff
);
675 if (newdiff
< diff
) {
679 if (diff
<= db_search_maxoff
)
684 if (ret
== DB_SYM_NULL
&& map_for_val
!= VM_MAP_NULL
) {
685 map_for_val
= VM_MAP_NULL
;
693 * Find the closest symbol to val, and return its name
694 * and the difference between val and the symbol found.
695 * Also return the filename and linenumber if available.
698 db_search_task_symbol_and_line(
699 register db_addr_t val
,
700 db_strategy_t strategy
,
707 db_addr_t diff
, newdiff
;
710 db_sym_t ret
= DB_SYM_NULL
, sym
;
711 vm_map_t map_for_val
;
717 if (task
== TASK_NULL
)
718 task
= db_current_task();
719 map_for_val
= (task
== TASK_NULL
)? VM_MAP_NULL
: task
->map
;
720 *filenamep
= (char *) 0;
724 filename
= (char *) 0;
726 newdiff
= diff
= ~0UL;
728 for (sp
= &db_symtabs
[0], i
= 0;
731 if ((((vm_map_t
)sp
->map_pointer
== VM_MAP_NULL
) ||
732 ((vm_map_t
)sp
->map_pointer
== map_for_val
)) &&
733 ((sp
->maxsym
== 0) ||
734 ((val
>= (db_addr_t
)sp
->minsym
) &&
735 (val
<= (db_addr_t
)sp
->maxsym
)))) {
737 sym
= X_db_search_by_addr(sp
, val
, &filename
, &func
,
738 &linenum
, (db_expr_t
*)&newdiff
,
740 if (sym
&& newdiff
< diff
) {
744 *filenamep
= filename
;
747 if (diff
<= db_search_maxoff
)
752 if (ret
== DB_SYM_NULL
&& map_for_val
!= VM_MAP_NULL
) {
753 map_for_val
= VM_MAP_NULL
;
758 db_shorten_filename(filenamep
);
763 * Return name and value of a symbol
775 if (sym
== DB_SYM_NULL
) {
780 stab
= db_last_symtab
;
782 X_db_symbol_values(stab
, sym
, &name
, &value
);
784 if (db_symbol_is_ambiguous(name
)) {
785 *namep
= db_qualify(name
, db_last_symtab
->name
);
795 * Print a the closest symbol to value
797 * After matching the symbol according to the given strategy
798 * we print it in the name+offset format, provided the symbol's
799 * value is close enough (eg smaller than db_maxoff).
800 * We also attempt to print [filename:linenum] when applicable
801 * (eg for procedure names).
803 * If we could not find a reasonable name+offset representation,
804 * then we just print the value in hex. Small values might get
805 * bogus symbol associations, e.g. 3 might get some absolute
806 * value like _INCLUDE_VERSION or something, therefore we do
807 * not accept symbols whose value is zero (and use plain hex).
813 db_strategy_t strategy
,
823 if (off
>= db_maxval
|| off
< db_minval
) {
824 db_printf("%#lln", (unsigned long long)off
);
827 cursym
= db_search_task_symbol(off
, strategy
, &d
, task
);
829 db_symbol_values(0, cursym
, &name
, &value
);
830 if (name
== 0 || d
>= db_maxoff
|| value
== 0) {
831 db_printf("%#lln",(unsigned long long) off
);
834 db_printf("%s", name
);
836 db_printf("+%llx", (unsigned long long)d
);
837 if (strategy
== DB_STGY_PROC
) {
838 if (db_line_at_pc(cursym
, &filename
, &linenum
, off
)) {
839 db_printf(" [%s", filename
);
841 db_printf(":%d", linenum
);
848 * Return symbol name for a given offset and
849 * change the offset to be relative to this symbol.
850 * Very usefull for xpr, when you want to log offsets
851 * in a user friendly way.
854 char null_sym
[] = "";
857 db_get_sym(db_expr_t
*off
)
864 cursym
= db_search_symbol(*off
, DB_STGY_ANY
, &d
);
865 db_symbol_values(0, cursym
, &name
, &value
);
876 db_strategy_t strategy
)
878 db_task_printsym(off
, strategy
, TASK_NULL
);
881 int db_short_filename
= 1;
884 db_shorten_filename(char **filenamep
)
890 for (cp
= cp_slash
= *filenamep
; *cp
; cp
++) {
894 if (*cp_slash
== '/')
895 *filenamep
= cp_slash
+1;
909 db_strategy_t strategy
= DB_STGY_PROC
;
911 if (off
>= db_maxval
|| off
< db_minval
) {
912 db_printf("%#lln", (unsigned long long)off
);
915 cursym
= db_search_task_symbol(off
, strategy
, &d
, task
);
917 db_symbol_values(0, cursym
, &name
, &value
);
918 if (name
== 0 || d
>= db_maxoff
|| value
== 0) {
921 if (db_line_at_pc(cursym
, &filename
, &linenum
, off
))
936 if (db_last_symtab
== 0)
938 if (X_db_line_at_pc( db_last_symtab
, sym
, filename
, linenum
, pc
)) {
939 if (db_short_filename
)
940 db_shorten_filename(filename
);
954 int (*compfun
)(char *, char *))
956 if (nbelts
<= 0 || eltsize
<= 0 || compfun
== 0) {
957 printf("qsort: invalid parameters\n");
960 qsort_recur(table
, table
+ nbelts
* eltsize
, eltsize
, compfun
);
963 qsort_checker(table
, nbelts
, eltsize
, compfun
);
976 for (; size
>= sizeof (int); size
-= sizeof (int), a
++, b
++) {
983 for (; size
> 0; size
--, aa
++, bb
++) {
990 /* rotate the three elements to the left */
1002 for (; size
>= sizeof (int); size
-= sizeof (int), a
++, b
++, c
++) {
1011 for (; size
> 0; size
--, aa
++, bb
++, cc
++) {
1024 int (*compfun
)(char *, char *))
1027 char *sameleft
, *sameright
;
1030 if (left
+ eltsize
- 1 >= right
) {
1034 /* partition element (reference for "same"ness */
1035 sameleft
= left
+ (((right
- left
) / eltsize
) / 2) * eltsize
;
1036 sameright
= sameleft
;
1039 j
= right
- eltsize
;
1042 while (i
< sameleft
) {
1045 comp
= (*compfun
)(i
, sameleft
);
1048 * Move to the "same" partition.
1051 * Shift the left part of the "same" partition to
1052 * the left, so that "same" elements stay in their
1055 sameleft
-= eltsize
;
1056 qsort_swap((int *) i
, (int *) sameleft
, eltsize
);
1057 } else if (comp
< 0) {
1059 * Stay in the "left" partition.
1064 * Should be moved to the "right" partition.
1065 * Wait until the next loop finds an appropriate
1066 * place to store this element.
1072 while (j
> sameright
) {
1075 comp
= (*compfun
)(sameright
, j
);
1078 * Move to the right of the "same" partition.
1080 sameright
+= eltsize
;
1081 qsort_swap((int *) sameright
, (int *) j
, eltsize
);
1082 } else if (comp
> 0) {
1084 * Move to the "left" partition.
1086 if (i
== sameleft
) {
1088 * Unfortunately, the "left" partition
1089 * has already been fully processed, so
1090 * we have to shift the "same" partition
1091 * to the right to free a "left" element.
1092 * This is done by moving the leftest same
1093 * to the right of the "same" partition.
1095 sameright
+= eltsize
;
1096 qsort_rotate((int *) sameleft
, (int*) sameright
,
1097 (int *) j
, eltsize
);
1098 sameleft
+= eltsize
;
1102 * Swap with the "left" partition element
1103 * waiting to be moved to the "right"
1106 qsort_swap((int *) i
, (int *) j
, eltsize
);
1109 * Go back to the 1st loop.
1116 * Stay in the "right" partition.
1122 if (i
!= sameleft
) {
1124 * The second loop completed (the"right" partition is ok),
1125 * but we have to go back to the first loop, and deal with
1126 * the element waiting for a place in the "right" partition.
1127 * Let's shift the "same" zone to the left.
1129 sameleft
-= eltsize
;
1130 qsort_rotate((int *) sameright
, (int *) sameleft
, (int *) i
,
1132 sameright
-= eltsize
;
1135 * Go back to 1st loop.
1141 * The partitions are correct now. Recur on the smallest side only.
1143 if (sameleft
- left
>= right
- (sameright
+ eltsize
)) {
1144 qsort_recur(sameright
+ eltsize
, right
, eltsize
, compfun
);
1146 * The "right" partition is now completely sorted.
1147 * The "same" partition is OK, so...
1148 * Ignore them, and start the loops again on the
1154 qsort_recur(left
, sameleft
, eltsize
, compfun
);
1156 * The "left" partition is now completely sorted.
1157 * The "same" partition is OK, so ...
1158 * Ignore them, and start the loops again on the
1159 * "right" partition.
1161 left
= sameright
+ eltsize
;
1171 int (*compfun
)(char *, char *))
1173 char *curr
, *prev
, *last
;
1176 curr
= prev
+ eltsize
;
1177 last
= table
+ (nbelts
* eltsize
);
1179 while (prev
< last
) {
1180 if ((*compfun
)(prev
, curr
) > 0) {
1181 printf("**** qsort_checker: error between 0x%x and 0x%x!!!\n", prev
, curr
);
1187 printf("qsort_checker: OK\n");
1190 int qsort_search_debug
= 0;
1193 db_qsort_limit_search(
1198 int (*compfun
)(char *, char *))
1200 register char *left
, *right
;
1201 char *oleft
, *oright
, *part
;
1205 oleft
= left
= *start
;
1206 oright
= right
= *end
;
1209 while (left
< right
) {
1211 part
= left
+ (((right
- left
) / eltsize
) / 2) * eltsize
;
1212 comp
= (*compfun
)(target
, part
);
1219 if (qsort_search_debug
> 1)
1220 printf(" [ Moved left from 0x%x to 0x%x]\n",
1222 } else if (comp
< 0) {
1226 if (qsort_search_debug
> 1)
1227 printf(" [ Moved right from 0x%x to 0x%x]\n",
1230 if (qsort_search_debug
> 1)
1231 printf(" [ FOUND! left=0x%x right=0x%x]\n",
1234 left
> *start
&& (*compfun
)(left
, part
) == 0;
1236 for (right
= part
+ eltsize
;
1237 right
< *end
&& (*compfun
)(right
, part
) == 0;
1245 if (qsort_search_debug
)
1246 printf("[ Limited from %x-%x to %x-%x in %d iters ]\n",
1247 *start
, *end
, oleft
, oright
, nbiter
);
1257 int (*compfun
)(char *, char *))
1263 end
= table
+ ((nbelts
-1) * eltsize
);
1266 for (p
= table
; p
< end
; p
+= eltsize
) {
1267 if ((*compfun
)(p
, p
+ eltsize
) > 0) {
1268 qsort_swap((int *) p
, (int *) (p
+ eltsize
),
1273 } while (sorted
== FALSE
);
1276 qsort_checker(table
, nbelts
, eltsize
, compfun
);
1279 vm_offset_t vm_min_inks_addr
= VM_MAX_KERNEL_ADDRESS
;
1285 /* save addr to demarcate kernel/inks boundary (1st time only) */
1286 if (vm_min_inks_addr
== VM_MAX_KERNEL_ADDRESS
) {
1287 vm_min_inks_addr
= base
;
1288 db_qualify_ambiguous_names
= TRUE
;
1295 char *clonee
, /* which symtab to clone */
1296 char *cloner
, /* in-kernel-server name */
1297 vm_offset_t base
) /* base address of cloner */
1299 db_symtab_t
*st
, *st_src
;
1303 extern void db_clone_offsetXXX(char *, long);
1305 if (db_nsymtab
>= MAXNOSYMTABS
) {
1306 db_printf("db_clone_symtab: Too Many Symbol Tables\n");
1310 db_install_inks(base
);
1312 st
= &db_symtabs
[db_nsymtab
]; /* destination symtab */
1313 if ((st_src
= db_symtab_cloneeXXX(clonee
)) == 0) {
1314 db_printf("db_clone_symtab: clonee (%s) not found\n", clonee
);
1317 /* alloc new symbols */
1318 size
= (vm_size_t
)(st_src
->end
- st_src
->private);
1319 memp
= (char *)kalloc( round_page(size
) );
1321 db_printf("db_clone_symtab: no memory for symtab\n");
1325 *st
= *st_src
; /* bulk copy src -> dest */
1326 strcpy(st
->name
, cloner
); /* new name */
1327 st
->private = memp
; /* copy symbols */
1328 bcopy((const char *)st_src
->private, st
->private, size
);
1329 st
->start
= memp
+ sizeof(int); /* fixup pointers to symtab */
1330 st
->end
= memp
+ *(int *)memp
;
1331 st
->map_pointer
= 0; /* no map because kernel-loaded */
1333 /* Offset symbols, leaving strings pointing into st_src */
1334 offset
= base
- st_src
->minsym
;
1335 st
->minsym
+= offset
;
1336 st
->maxsym
+= offset
;
1337 db_clone_offsetXXX(memp
, offset
);
1340 db_printf( "[ cloned symbol table for %s: range 0x%x to 0x%x %s]\n",
1341 st
->name
, st
->minsym
, st
->maxsym
,
1342 st
->sorted
? "(sorted) " : "");
1343 db_maxval
= (unsigned int)st
->maxsym
+ db_maxoff
;
1347 db_symtab_cloneeXXX(
1350 db_symtab_t
*st
, *st_src
;
1352 st
= &db_symtabs
[db_nsymtab
]; /* destination symtab */
1353 for (st_src
= &db_symtabs
[0]; st_src
< st
; ++st_src
)
1354 if (!strcmp(clonee
, st_src
->name
))
1356 return ((st_src
< st
) ? st_src
: 0);
1360 * Switch into symbol-table specific routines
1363 #if !defined(__alpha) && !defined(INTEL860)
1368 #include <ddb/db_aout.h>
1372 #include <ddb/db_coff.h>
1375 static void no_init(void)
1378 db_printf("Non-existent code for ddb init\n");
1381 static boolean_t
no_sym_init(
1387 db_printf("Non-existent code for init of symtab %s\n", name
);
1391 static db_sym_t
no_lookup(
1395 db_printf("Bogus lookup of symbol %s\n", symstr
);
1399 static db_sym_t
no_search(
1402 db_strategy_t strategy
,
1405 db_printf("Bogus search for offset %#llXn", (unsigned long long)off
);
1409 static boolean_t
no_line_at_pc(
1416 db_printf("Bogus search for pc %#llX\n", (unsigned long long)pc
);
1420 static void no_symbol_values(
1425 db_printf("Bogus symbol value resolution\n");
1426 if (namep
) *namep
= NULL
;
1427 if (valuep
) *valuep
= 0;
1430 static db_sym_t
no_search_by_addr(
1439 db_printf("Bogus search for address %#llX\n", (unsigned long long)off
);
1444 no_print_completion(
1448 db_printf("Bogus print completion: not supported\n");
1453 no_lookup_incomplete(
1460 db_printf("Bogus lookup incomplete: not supported\n");
1465 { no_init, no_sym_init, no_lookup, no_search, \
1466 no_line_at_pc, no_symbol_values, no_search_by_addr, \
1467 no_print_completion, no_lookup_incomplete}
1469 struct db_sym_switch x_db
[] = {
1471 /* BSD a.out format (really, sdb/dbx(1) symtabs) */
1474 #else /* DB_NO_AOUT */
1475 { aout_db_init
, aout_db_sym_init
, aout_db_lookup
, aout_db_search_symbol
,
1476 aout_db_line_at_pc
, aout_db_symbol_values
, aout_db_search_by_addr
,
1477 aout_db_print_completion
, aout_db_lookup_incomplete
},
1478 #endif /* DB_NO_AOUT */
1482 #else /* DB_NO_COFF */
1483 { coff_db_init
, coff_db_sym_init
, coff_db_lookup
, coff_db_search_symbol
,
1484 coff_db_line_at_pc
, coff_db_symbol_values
, coff_db_search_by_addr
,
1485 coff_db_print_completion
, coff_db_lookup_incomplete
},
1486 #endif /* DB_NO_COFF */
1488 /* Machdep, not inited here */