2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
29 * Mach Operating System
30 * Copyright (c) 1991,1990 Carnegie Mellon University
31 * All Rights Reserved.
33 * Permission to use, copy, modify and distribute this software and its
34 * documentation is hereby granted, provided that both the copyright
35 * notice and this permission notice appear in all copies of the
36 * software, derivative works or modified versions, and any portions
37 * thereof, and that both notices appear in supporting documentation.
39 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
40 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
41 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
43 * Carnegie Mellon requests users of this software to return to
45 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
46 * School of Computer Science
47 * Carnegie Mellon University
48 * Pittsburgh PA 15213-3890
50 * any improvements or extensions that they make and grant Carnegie Mellon
51 * the rights to redistribute these changes.
56 * Author: David B. Golub, Carnegie Mellon University
60 #include <machine/db_machdep.h>
61 #include <string.h> /* For strcpy(), strcmp() */
62 #include <mach/std_types.h>
63 #include <kern/misc_protos.h> /* For printf() */
64 #include <ddb/db_sym.h>
65 #include <ddb/db_task_thread.h>
66 #include <ddb/db_command.h>
67 #include <ddb/db_output.h> /* For db_printf() */
69 #include <vm/vm_map.h> /* vm_map_t */
72 * Multiple symbol tables
74 * mach, bootstrap, name_server, default_pager, unix, 1 spare
76 #define MAXNOSYMTABS 6
78 db_symtab_t db_symtabs
[MAXNOSYMTABS
] = {{0}};
81 db_symtab_t
*db_last_symtab
;
83 unsigned long db_maxoff
= 0x4000;
85 unsigned long db_maxval
= (unsigned long)&end
;
86 natural_t db_minval
= 0x1000;
88 /* Prototypes for functions local to this file. XXX -- should be static!
90 static char *db_qualify(
92 register char *symtabname
);
99 boolean_t
db_symbol_is_ambiguous(char *name
);
101 void db_shorten_filename(char **filenamep
);
118 int (*compfun
)(char *, char *));
124 int (*compfun
)(char *, char *));
130 int (*compfun
)(char *, char *));
132 int no_print_completion(
135 int no_lookup_incomplete(
143 * Initialization routine for ddb.
153 * Add symbol table, with given name, to list of symbol tables.
163 unsigned long minsym
,
164 unsigned long maxsym
,
167 register db_symtab_t
*st
;
168 extern vm_map_t kernel_map
;
170 if (db_nsymtab
>= MAXNOSYMTABS
)
173 st
= &db_symtabs
[db_nsymtab
];
178 if (map_pointer
== (char *)kernel_map
||
179 (VM_MAX_ADDRESS
<= VM_MIN_KERNEL_ADDRESS
&&
180 VM_MIN_KERNEL_ADDRESS
<= minsym
))
183 st
->map_pointer
= map_pointer
;
184 strcpy(st
->name
, name
);
191 if (db_maxval
< maxsym
+ db_maxoff
)
192 db_maxval
= maxsym
+ db_maxoff
;
200 * db_qualify("vm_map", "ux") returns "ux::vm_map".
202 * Note: return value points to static data whose content is
203 * overwritten by each call... but in practice this seems okay.
208 register char *symtabname
)
210 static char tmp
[256];
214 while (*s
++ = *symtabname
++) {
218 while (*s
++ = *symname
++) {
230 if (!strcmp(src
, dst
))
233 return (!strcmp(src
+1,dst
));
244 sym
= db_lookup(name
);
245 if (sym
== DB_SYM_NULL
)
247 db_symbol_values(0, sym
, &name
, valuep
);
252 * Display list of possible completions for a symbol.
259 int symtab_start
= 0;
260 int symtab_end
= db_nsymtab
;
263 char *name
= (char *)0;
268 * Look for, remove, and remember any symbol table specifier.
270 for (cp
= symstr
; *cp
; cp
++) {
271 if (*cp
== ':' && cp
[1] == ':') {
273 for (i
= 0; i
< db_nsymtab
; i
++) {
274 if (! strcmp(symstr
, db_symtabs
[i
].name
)) {
288 * Look in the specified set of symbol tables.
289 * Return on first match.
291 for (i
= symtab_start
; i
< symtab_end
; i
++) {
292 if (X_db_print_completion(&db_symtabs
[i
], symstr
))
298 * Lookup a (perhaps incomplete) symbol.
299 * If the symbol has a qualifier (e.g., ux::vm_map),
300 * then only the specified symbol table will be searched;
301 * otherwise, all symbol tables will be searched.
304 db_lookup_incomplete(
309 int symtab_start
= 0;
310 int symtab_end
= db_nsymtab
;
313 char *name
= (char *)0;
318 * Look for, remove, and remember any symbol table specifier.
320 for (cp
= symstr
; *cp
; cp
++) {
321 if (*cp
== ':' && cp
[1] == ':') {
323 for (i
= 0; i
< db_nsymtab
; i
++) {
324 if (! strcmp(symstr
, db_symtabs
[i
].name
)) {
338 * Look in the specified set of symbol tables.
339 * Return on first match.
341 for (i
= symtab_start
; i
< symtab_end
; i
++) {
342 nsym
= X_db_lookup_incomplete(&db_symtabs
[i
], symstr
,
343 &name
, &len
, &toadd
);
346 len
= strlen(symstr
);
347 if (len
+ toadd
>= symlen
)
349 bcopy(&name
[len
], &symstr
[len
], toadd
);
350 symstr
[len
+ toadd
] = '\0';
360 * If the symbol has a qualifier (e.g., ux::vm_map),
361 * then only the specified symbol table will be searched;
362 * otherwise, all symbol tables will be searched.
365 db_lookup(char *symstr
)
369 int symtab_start
= 0;
370 int symtab_end
= db_nsymtab
;
374 * Look for, remove, and remember any symbol table specifier.
376 for (cp
= symstr
; *cp
; cp
++) {
377 if (*cp
== ':' && cp
[1] == ':') {
379 for (i
= 0; i
< db_nsymtab
; i
++) {
380 if (! strcmp(symstr
, db_symtabs
[i
].name
)) {
388 db_error("Invalid symbol table name\n");
394 * Look in the specified set of symbol tables.
395 * Return on first match.
397 for (i
= symtab_start
; i
< symtab_end
; i
++) {
398 if (sp
= X_db_lookup(&db_symtabs
[i
], symstr
)) {
399 db_last_symtab
= &db_symtabs
[i
];
407 * Print a symbol completion
410 db_sym_print_completion(
417 if (stab
!= db_symtabs
)
418 db_printf("%s::", stab
->name
);
425 db_printf(" [static from %s", fname
);
427 db_printf(":%d", line
);
434 * Common utility routine to parse a symbol string into a file
435 * name, a (possibly incomplete) symbol name without line number.
436 * This routine is called from aout_db_print_completion if the object
437 * dependent handler supports qualified search with a file name.
438 * It parses the symbol string, and call an object dependent routine
439 * with parsed file name and symbol name.
442 db_sym_parse_and_print_completion(
443 int (*func
)(db_symtab_t
*,
455 * disassemble the symbol into components: [file_name:]symbol
457 component
[0] = symstr
;
459 for (p
= symstr
, n
= 1; *p
; p
++) {
464 component
[n
++] = p
+1;
469 sym_name
= component
[0];
471 sym_name
= component
[1];
473 nsym
= func(symtab
, sym_name
);
477 component
[1][-1] = ':';
482 * Common utility routine to parse a symbol string into a file
483 * name, a (possibly incomplete) symbol name without line number.
484 * This routine is called from X_db_lookup_incomplete if the object
485 * dependent handler supports qualified search with a file name.
486 * It parses the symbol string, and call an object dependent routine
487 * with parsed file name and symbol name.
490 db_sym_parse_and_lookup_incomplete(
491 int (*func
)(db_symtab_t
*,
512 * disassemble the symbol into components: [file_name:]symbol
514 component
[0] = symstr
;
516 for (p
= symstr
, n
= 1; *p
; p
++) {
521 component
[n
++] = p
+1;
527 sym_name
= component
[0];
529 file_name
= component
[0];
530 sym_name
= component
[1];
532 nsym
= func(symtab
, file_name
, sym_name
, 0, (db_sym_t
*)0,
535 *toadd
= *len
- strlen(sym_name
);
538 component
[1][-1] = ':';
543 * Common utility routine to parse a symbol string into a file
544 * name, a symbol name and line number.
545 * This routine is called from aout_db_lookup if the object dependent
546 * handler supports qualified search with a file name or a line number.
547 * It parses the symbol string, and call an object dependent routine
548 * with parsed file name, symbol name and line number.
551 db_sym_parse_and_lookup(
552 int (*func
)(db_symtab_t
*, char *, char *, int,
553 db_sym_t
*, char **, int *),
564 db_sym_t found
= DB_SYM_NULL
;
567 * disassemble the symbol into components:
568 * [file_name:]symbol[:line_nubmer]
570 component
[0] = symstr
;
571 component
[1] = component
[2] = 0;
572 for (p
= symstr
, n
= 1; *p
; p
++) {
577 component
[n
++] = p
+1;
585 if (*p
>= '0' && *p
<= '9') {
588 for (line_number
= 0; *p
; p
++) {
589 if (*p
< '0' || *p
> '9')
591 line_number
= line_number
*10 + *p
- '0';
597 for (p
= component
[0]; *p
&& *p
!= '.'; p
++);
599 file_name
= component
[0];
603 sym_name
= component
[0];
606 file_name
= component
[0];
607 sym_name
= component
[1];
609 (void) func(symtab
, file_name
, sym_name
, line_number
, &found
,
610 (char **)0, (int *)0);
614 component
[n
][-1] = ':';
619 * Does this symbol name appear in more than one symbol table?
620 * Used by db_symbol_values to decide whether to qualify a symbol.
622 boolean_t db_qualify_ambiguous_names
= TRUE
;
625 db_symbol_is_ambiguous(char *name
)
629 boolean_t found_once
= FALSE
;
631 if (!db_qualify_ambiguous_names
)
634 for (i
= 0; i
< db_nsymtab
; i
++) {
635 if (X_db_lookup(&db_symtabs
[i
], name
)) {
645 * Find the closest symbol to val, and return its name
646 * and the difference between val and the symbol found.
648 unsigned int db_search_maxoff
= 0x4000;
650 db_search_task_symbol(
651 register db_addr_t val
,
652 db_strategy_t strategy
,
653 db_addr_t
*offp
, /* better be unsigned */
656 unsigned long diff
, newdiff
;
659 db_sym_t ret
= DB_SYM_NULL
, sym
;
660 vm_map_t map_for_val
;
662 if (task
== TASK_NULL
)
663 task
= db_current_task();
664 map_for_val
= (task
== TASK_NULL
)? VM_MAP_NULL
: task
->map
;
666 newdiff
= diff
= ~0UL;
668 for (sp
= &db_symtabs
[0], i
= 0;
671 if (((vm_map_t
)sp
->map_pointer
== VM_MAP_NULL
||
672 (vm_map_t
)sp
->map_pointer
== map_for_val
) &&
674 ((unsigned long) val
>= sp
->minsym
&&
675 (unsigned long) val
<= sp
->maxsym
))) {
676 sym
= X_db_search_symbol(sp
, val
, strategy
,
677 (db_expr_t
*)&newdiff
);
678 if (newdiff
< diff
) {
682 if (diff
<= db_search_maxoff
)
687 if (ret
== DB_SYM_NULL
&& map_for_val
!= VM_MAP_NULL
) {
688 map_for_val
= VM_MAP_NULL
;
696 * Find the closest symbol to val, and return its name
697 * and the difference between val and the symbol found.
698 * Also return the filename and linenumber if available.
701 db_search_task_symbol_and_line(
702 register db_addr_t val
,
703 db_strategy_t strategy
,
710 unsigned long diff
, newdiff
;
713 db_sym_t ret
= DB_SYM_NULL
, sym
;
714 vm_map_t map_for_val
;
720 if (task
== TASK_NULL
)
721 task
= db_current_task();
722 map_for_val
= (task
== TASK_NULL
)? VM_MAP_NULL
: task
->map
;
723 *filenamep
= (char *) 0;
727 filename
= (char *) 0;
729 newdiff
= diff
= ~0UL;
731 for (sp
= &db_symtabs
[0], i
= 0;
734 if (((vm_map_t
)sp
->map_pointer
== VM_MAP_NULL
||
735 (vm_map_t
)sp
->map_pointer
== map_for_val
) &&
737 ((unsigned long) val
>= sp
->minsym
&&
738 (unsigned long) val
<= sp
->maxsym
))) {
739 sym
= X_db_search_by_addr(sp
, val
, &filename
, &func
,
740 &linenum
, (db_expr_t
*)&newdiff
,
742 if (sym
&& newdiff
< diff
) {
746 *filenamep
= filename
;
749 if (diff
<= db_search_maxoff
)
754 if (ret
== DB_SYM_NULL
&& map_for_val
!= VM_MAP_NULL
) {
755 map_for_val
= VM_MAP_NULL
;
760 db_shorten_filename(filenamep
);
765 * Return name and value of a symbol
777 if (sym
== DB_SYM_NULL
) {
782 stab
= db_last_symtab
;
784 X_db_symbol_values(stab
, sym
, &name
, &value
);
786 if (db_symbol_is_ambiguous(name
)) {
787 *namep
= db_qualify(name
, db_last_symtab
->name
);
797 * Print a the closest symbol to value
799 * After matching the symbol according to the given strategy
800 * we print it in the name+offset format, provided the symbol's
801 * value is close enough (eg smaller than db_maxoff).
802 * We also attempt to print [filename:linenum] when applicable
803 * (eg for procedure names).
805 * If we could not find a reasonable name+offset representation,
806 * then we just print the value in hex. Small values might get
807 * bogus symbol associations, e.g. 3 might get some absolute
808 * value like _INCLUDE_VERSION or something, therefore we do
809 * not accept symbols whose value is zero (and use plain hex).
815 db_strategy_t strategy
,
825 if (off
>= db_maxval
|| off
< db_minval
) {
826 db_printf("%#n", off
);
829 cursym
= db_search_task_symbol(off
, strategy
, &d
, task
);
831 db_symbol_values(0, cursym
, &name
, &value
);
832 if (name
== 0 || d
>= db_maxoff
|| value
== 0) {
833 db_printf("%#n", off
);
836 db_printf("%s", name
);
838 db_printf("+0x%x", d
);
839 if (strategy
== DB_STGY_PROC
) {
840 if (db_line_at_pc(cursym
, &filename
, &linenum
, off
)) {
841 db_printf(" [%s", filename
);
843 db_printf(":%d", linenum
);
850 * Return symbol name for a given offset and
851 * change the offset to be relative to this symbol.
852 * Very usefull for xpr, when you want to log offsets
853 * in a user friendly way.
856 char null_sym
[] = "";
859 db_get_sym(db_expr_t
*off
)
866 cursym
= db_search_symbol(*off
, DB_STGY_ANY
, &d
);
867 db_symbol_values(0, cursym
, &name
, &value
);
878 db_strategy_t strategy
)
880 db_task_printsym(off
, strategy
, TASK_NULL
);
883 int db_short_filename
= 1;
886 db_shorten_filename(char **filenamep
)
892 for (cp
= cp_slash
= *filenamep
; *cp
; cp
++) {
896 if (*cp_slash
== '/')
897 *filenamep
= cp_slash
+1;
911 db_strategy_t strategy
= DB_STGY_PROC
;
913 if (off
>= db_maxval
|| off
< db_minval
) {
914 db_printf("%#n", off
);
917 cursym
= db_search_task_symbol(off
, strategy
, &d
, task
);
919 db_symbol_values(0, cursym
, &name
, &value
);
920 if (name
== 0 || d
>= db_maxoff
|| value
== 0) {
923 if (db_line_at_pc(cursym
, &filename
, &linenum
, off
))
938 if (db_last_symtab
== 0)
940 if (X_db_line_at_pc( db_last_symtab
, sym
, filename
, linenum
, pc
)) {
941 if (db_short_filename
)
942 db_shorten_filename(filename
);
956 int (*compfun
)(char *, char *))
958 if (nbelts
<= 0 || eltsize
<= 0 || compfun
== 0) {
959 printf("qsort: invalid parameters\n");
962 qsort_recur(table
, table
+ nbelts
* eltsize
, eltsize
, compfun
);
965 qsort_checker(table
, nbelts
, eltsize
, compfun
);
978 for (; size
>= sizeof (int); size
-= sizeof (int), a
++, b
++) {
985 for (; size
> 0; size
--, aa
++, bb
++) {
992 /* rotate the three elements to the left */
1004 for (; size
>= sizeof (int); size
-= sizeof (int), a
++, b
++, c
++) {
1013 for (; size
> 0; size
--, aa
++, bb
++, cc
++) {
1026 int (*compfun
)(char *, char *))
1029 char *sameleft
, *sameright
;
1032 if (left
+ eltsize
- 1 >= right
) {
1036 /* partition element (reference for "same"ness */
1037 sameleft
= left
+ (((right
- left
) / eltsize
) / 2) * eltsize
;
1038 sameright
= sameleft
;
1041 j
= right
- eltsize
;
1044 while (i
< sameleft
) {
1047 comp
= (*compfun
)(i
, sameleft
);
1050 * Move to the "same" partition.
1053 * Shift the left part of the "same" partition to
1054 * the left, so that "same" elements stay in their
1057 sameleft
-= eltsize
;
1058 qsort_swap((int *) i
, (int *) sameleft
, eltsize
);
1059 } else if (comp
< 0) {
1061 * Stay in the "left" partition.
1066 * Should be moved to the "right" partition.
1067 * Wait until the next loop finds an appropriate
1068 * place to store this element.
1074 while (j
> sameright
) {
1077 comp
= (*compfun
)(sameright
, j
);
1080 * Move to the right of the "same" partition.
1082 sameright
+= eltsize
;
1083 qsort_swap((int *) sameright
, (int *) j
, eltsize
);
1084 } else if (comp
> 0) {
1086 * Move to the "left" partition.
1088 if (i
== sameleft
) {
1090 * Unfortunately, the "left" partition
1091 * has already been fully processed, so
1092 * we have to shift the "same" partition
1093 * to the right to free a "left" element.
1094 * This is done by moving the leftest same
1095 * to the right of the "same" partition.
1097 sameright
+= eltsize
;
1098 qsort_rotate((int *) sameleft
, (int*) sameright
,
1099 (int *) j
, eltsize
);
1100 sameleft
+= eltsize
;
1104 * Swap with the "left" partition element
1105 * waiting to be moved to the "right"
1108 qsort_swap((int *) i
, (int *) j
, eltsize
);
1111 * Go back to the 1st loop.
1118 * Stay in the "right" partition.
1124 if (i
!= sameleft
) {
1126 * The second loop completed (the"right" partition is ok),
1127 * but we have to go back to the first loop, and deal with
1128 * the element waiting for a place in the "right" partition.
1129 * Let's shift the "same" zone to the left.
1131 sameleft
-= eltsize
;
1132 qsort_rotate((int *) sameright
, (int *) sameleft
, (int *) i
,
1134 sameright
-= eltsize
;
1137 * Go back to 1st loop.
1143 * The partitions are correct now. Recur on the smallest side only.
1145 if (sameleft
- left
>= right
- (sameright
+ eltsize
)) {
1146 qsort_recur(sameright
+ eltsize
, right
, eltsize
, compfun
);
1148 * The "right" partition is now completely sorted.
1149 * The "same" partition is OK, so...
1150 * Ignore them, and start the loops again on the
1156 qsort_recur(left
, sameleft
, eltsize
, compfun
);
1158 * The "left" partition is now completely sorted.
1159 * The "same" partition is OK, so ...
1160 * Ignore them, and start the loops again on the
1161 * "right" partition.
1163 left
= sameright
+ eltsize
;
1173 int (*compfun
)(char *, char *))
1175 char *curr
, *prev
, *last
;
1178 curr
= prev
+ eltsize
;
1179 last
= table
+ (nbelts
* eltsize
);
1181 while (prev
< last
) {
1182 if ((*compfun
)(prev
, curr
) > 0) {
1183 printf("**** qsort_checker: error between 0x%x and 0x%x!!!\n", prev
, curr
);
1189 printf("qsort_checker: OK\n");
1192 int qsort_search_debug
= 0;
1195 db_qsort_limit_search(
1200 int (*compfun
)(char *, char *))
1202 register char *left
, *right
;
1203 char *oleft
, *oright
, *part
;
1207 oleft
= left
= *start
;
1208 oright
= right
= *end
;
1211 while (left
< right
) {
1213 part
= left
+ (((right
- left
) / eltsize
) / 2) * eltsize
;
1214 comp
= (*compfun
)(target
, part
);
1221 if (qsort_search_debug
> 1)
1222 printf(" [ Moved left from 0x%x to 0x%x]\n",
1224 } else if (comp
< 0) {
1228 if (qsort_search_debug
> 1)
1229 printf(" [ Moved right from 0x%x to 0x%x]\n",
1232 if (qsort_search_debug
> 1)
1233 printf(" [ FOUND! left=0x%x right=0x%x]\n",
1236 left
> *start
&& (*compfun
)(left
, part
) == 0;
1238 for (right
= part
+ eltsize
;
1239 right
< *end
&& (*compfun
)(right
, part
) == 0;
1247 if (qsort_search_debug
)
1248 printf("[ Limited from %x-%x to %x-%x in %d iters ]\n",
1249 *start
, *end
, oleft
, oright
, nbiter
);
1259 int (*compfun
)(char *, char *))
1265 end
= table
+ ((nbelts
-1) * eltsize
);
1268 for (p
= table
; p
< end
; p
+= eltsize
) {
1269 if ((*compfun
)(p
, p
+ eltsize
) > 0) {
1270 qsort_swap((int *) p
, (int *) (p
+ eltsize
),
1275 } while (sorted
== FALSE
);
1278 qsort_checker(table
, nbelts
, eltsize
, compfun
);
1281 vm_offset_t vm_min_inks_addr
= VM_MAX_KERNEL_ADDRESS
;
1287 /* save addr to demarcate kernel/inks boundary (1st time only) */
1288 if (vm_min_inks_addr
== VM_MAX_KERNEL_ADDRESS
) {
1289 vm_min_inks_addr
= base
;
1290 db_qualify_ambiguous_names
= TRUE
;
1297 char *clonee
, /* which symtab to clone */
1298 char *cloner
, /* in-kernel-server name */
1299 vm_offset_t base
) /* base address of cloner */
1301 db_symtab_t
*st
, *st_src
;
1305 extern vm_offset_t
kalloc(vm_size_t
);
1306 extern void db_clone_offsetXXX(char *, long);
1308 if (db_nsymtab
>= MAXNOSYMTABS
) {
1309 db_printf("db_clone_symtab: Too Many Symbol Tables\n");
1313 db_install_inks(base
);
1315 st
= &db_symtabs
[db_nsymtab
]; /* destination symtab */
1316 if ((st_src
= db_symtab_cloneeXXX(clonee
)) == 0) {
1317 db_printf("db_clone_symtab: clonee (%s) not found\n", clonee
);
1320 /* alloc new symbols */
1321 size
= (vm_size_t
)(st_src
->end
- st_src
->private);
1322 memp
= (char *)kalloc( round_page_32(size
) );
1324 db_printf("db_clone_symtab: no memory for symtab\n");
1328 *st
= *st_src
; /* bulk copy src -> dest */
1329 strcpy(st
->name
, cloner
); /* new name */
1330 st
->private = memp
; /* copy symbols */
1331 bcopy((const char *)st_src
->private, st
->private, size
);
1332 st
->start
= memp
+ sizeof(int); /* fixup pointers to symtab */
1333 st
->end
= memp
+ *(int *)memp
;
1334 st
->map_pointer
= 0; /* no map because kernel-loaded */
1336 /* Offset symbols, leaving strings pointing into st_src */
1337 offset
= base
- st_src
->minsym
;
1338 st
->minsym
+= offset
;
1339 st
->maxsym
+= offset
;
1340 db_clone_offsetXXX(memp
, offset
);
1343 db_printf( "[ cloned symbol table for %s: range 0x%x to 0x%x %s]\n",
1344 st
->name
, st
->minsym
, st
->maxsym
,
1345 st
->sorted
? "(sorted) " : "");
1346 db_maxval
= (unsigned int)st
->maxsym
+ db_maxoff
;
1350 db_symtab_cloneeXXX(
1353 db_symtab_t
*st
, *st_src
;
1355 st
= &db_symtabs
[db_nsymtab
]; /* destination symtab */
1356 for (st_src
= &db_symtabs
[0]; st_src
< st
; ++st_src
)
1357 if (!strcmp(clonee
, st_src
->name
))
1359 return ((st_src
< st
) ? st_src
: 0);
1363 * Switch into symbol-table specific routines
1366 #if !defined(__alpha) && !defined(INTEL860)
1371 #include <ddb/db_aout.h>
1375 #include <ddb/db_coff.h>
1378 static void no_init(void)
1381 db_printf("Non-existent code for ddb init\n");
1384 static boolean_t
no_sym_init(
1390 db_printf("Non-existent code for init of symtab %s\n", name
);
1394 static db_sym_t
no_lookup(
1398 db_printf("Bogus lookup of symbol %s\n", symstr
);
1402 static db_sym_t
no_search(
1405 db_strategy_t strategy
,
1408 db_printf("Bogus search for offset %#Xn", off
);
1412 static boolean_t
no_line_at_pc(
1419 db_printf("Bogus search for pc %#X\n", pc
);
1423 static void no_symbol_values(
1428 db_printf("Bogus symbol value resolution\n");
1429 if (namep
) *namep
= NULL
;
1430 if (valuep
) *valuep
= 0;
1433 static db_sym_t
no_search_by_addr(
1442 db_printf("Bogus search for address %#X\n", off
);
1447 no_print_completion(
1451 db_printf("Bogus print completion: not supported\n");
1456 no_lookup_incomplete(
1463 db_printf("Bogus lookup incomplete: not supported\n");
1468 { no_init, no_sym_init, no_lookup, no_search, \
1469 no_line_at_pc, no_symbol_values, no_search_by_addr, \
1470 no_print_completion, no_lookup_incomplete}
1472 struct db_sym_switch x_db
[] = {
1474 /* BSD a.out format (really, sdb/dbx(1) symtabs) */
1477 #else /* DB_NO_AOUT */
1478 { aout_db_init
, aout_db_sym_init
, aout_db_lookup
, aout_db_search_symbol
,
1479 aout_db_line_at_pc
, aout_db_symbol_values
, aout_db_search_by_addr
,
1480 aout_db_print_completion
, aout_db_lookup_incomplete
},
1481 #endif /* DB_NO_AOUT */
1485 #else /* DB_NO_COFF */
1486 { coff_db_init
, coff_db_sym_init
, coff_db_lookup
, coff_db_search_symbol
,
1487 coff_db_line_at_pc
, coff_db_symbol_values
, coff_db_search_by_addr
,
1488 coff_db_print_completion
, coff_db_lookup_incomplete
},
1489 #endif /* DB_NO_COFF */
1491 /* Machdep, not inited here */