Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 24 Apr 2004 18:29:56 -0700 (PDT)
From:      Marcel Moolenaar <marcel@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 51679 for review
Message-ID:  <200404250129.i3P1TuZV078585@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=51679

Change 51679 by marcel@marcel_nfs on 2004/04/24 18:29:55

	Remove the DDB_NOKLDSYM option. The DDB debugger will use both
	the ELF sybol table as well as the kernel linker for symbol
	resolution. The ELF symbol table will take precedence. This
	may need to be changed...
	
	Have ksym_start and ksym_end defined by DDB and declared
	extern in all other cases.
	
	Remove db_elf.c and db_kld.c

Affected files ...

.. //depot/projects/gdb/sys/alpha/alpha/machdep.c#8 edit
.. //depot/projects/gdb/sys/amd64/amd64/machdep.c#7 edit
.. //depot/projects/gdb/sys/conf/NOTES#15 edit
.. //depot/projects/gdb/sys/ddb/db_elf.c#3 delete
.. //depot/projects/gdb/sys/ddb/db_kld.c#3 delete
.. //depot/projects/gdb/sys/ddb/db_main.c#4 edit
.. //depot/projects/gdb/sys/i386/i386/machdep.c#5 edit
.. //depot/projects/gdb/sys/ia64/ia64/machdep.c#7 edit
.. //depot/projects/gdb/sys/pc98/i386/machdep.c#5 edit
.. //depot/projects/gdb/sys/powerpc/powerpc/machdep.c#5 edit
.. //depot/projects/gdb/sys/sparc64/sparc64/machdep.c#6 edit

Differences ...

==== //depot/projects/gdb/sys/alpha/alpha/machdep.c#8 (text+ko) ====

@@ -91,6 +91,7 @@
 __FBSDID("$FreeBSD: src/sys/alpha/alpha/machdep.c,v 1.219 2004/04/01 20:56:43 jhb Exp $");
 
 #include "opt_compat.h"
+#include "opt_ddb.h"
 #include "opt_kstack_pages.h"
 #include "opt_msgbuf.h"
 #include "opt_maxmem.h"
@@ -168,9 +169,8 @@
 static char cpu_model[128];
 SYSCTL_STRING(_hw, HW_MODEL, model, CTLFLAG_RD, cpu_model, 0, "");
 
-#ifdef KDB
-/* start and end of kernel symbol table */
-void	*ksym_start, *ksym_end;
+#ifdef DDB
+extern vm_offset_t ksym_start, ksym_end;
 #endif
 
 int	alpha_unaligned_print = 1;	/* warn about unaligned accesses */
@@ -604,9 +604,9 @@
 	 * stack).
 	 */
 	kernstart = trunc_page(kernel_text) - 2 * PAGE_SIZE;
-#ifdef KDB
-	ksym_start = (void *)bootinfo.ssym;
-	ksym_end   = (void *)bootinfo.esym;
+#ifdef DDB
+	ksym_start = bootinfo.ssym;
+	ksym_end   = bootinfo.esym;
 	kernend = (vm_offset_t)round_page(ksym_end);
 #else
 	kernend = (vm_offset_t)round_page(_end);
@@ -930,11 +930,6 @@
 	/*
 	 * Look at arguments passed to us and compute boothowto.
 	 */
-
-#ifdef KADB
-	boothowto |= RB_KDB;
-#endif
-/*	boothowto |= RB_KDB | RB_GDB; */
 	for (p = bootinfo.boot_flags; p && *p != '\0'; p++) {
 		/*
 		 * Note that we'd really like to differentiate case here,

==== //depot/projects/gdb/sys/amd64/amd64/machdep.c#7 (text+ko) ====

@@ -141,6 +141,10 @@
 static int  set_fpcontext(struct thread *td, const mcontext_t *mcp);
 SYSINIT(cpu, SI_SUB_CPU, SI_ORDER_FIRST, cpu_startup, NULL)
 
+#ifdef DDB
+extern vm_offset_t ksym_start, ksym_end;
+#endif
+
 int	_udatasel, _ucodesel, _ucode32sel;
 u_long	atdevbase;
 
@@ -1214,6 +1218,11 @@
 	atpic_startup();
 #endif
 
+#ifdef DDB
+	ksym_start = bootinfo.bi_symtab;
+	ksym_end = bootinfo.bi_esymtab;
+#endif
+
 	kdb_init();
 
 #ifdef KDB
@@ -1774,12 +1783,12 @@
         return 0;
 }
 
-#ifdef DDB
+#ifdef KDB
 
 /*
  * Provide inb() and outb() as functions.  They are normally only
  * available as macros calling inlined functions, thus cannot be
- * called inside DDB.
+ * called from the debugger
  *
  * The actual code is stolen from <machine/cpufunc.h>, and de-inlined.
  */
@@ -1818,4 +1827,4 @@
 	__asm __volatile("outb %0,%%dx" : : "a" (al), "d" (port));
 }
 
-#endif /* DDB */
+#endif /* KDB */

==== //depot/projects/gdb/sys/conf/NOTES#15 (text+ko) ====

@@ -251,14 +251,6 @@
 options 	DDB
 
 #
-# Use direct symbol lookup routines for ddb instead of the kernel linker
-# ones, so that symbols (mostly) work before the kernel linker has been
-# initialized.  This is not the default because it breaks ddb's lookup of
-# symbols in loaded modules.
-#
-#!options 	DDB_NOKLDSYM
-
-#
 # Print the numerical value of symbols in addition to the symbolic
 # representation.
 #

==== //depot/projects/gdb/sys/ddb/db_main.c#4 (text+ko) ====

@@ -50,9 +50,8 @@
 
 KDB_BACKEND(ddb, db_init, db_trace, db_trap);
 
-extern jmp_buf  db_jmpbuf;
-
 db_regs_t ddb_regs;
+vm_offset_t ksym_start, ksym_end;
 
 boolean_t
 X_db_line_at_pc(db_symtab_t *symtab, c_db_sym_t sym, char **file, int *line,
@@ -64,23 +63,76 @@
 c_db_sym_t
 X_db_lookup(db_symtab_t *symtab, const char *symbol)
 {
-	c_linker_sym_t sym;
+	c_linker_sym_t lsym;
+	Elf_Sym *sym;
 
-	return (c_db_sym_t)((!linker_ddb_lookup(symbol, &sym)) ? sym : NULL);
+	if (symtab->private == NULL) {
+		return ((c_db_sym_t)((!linker_ddb_lookup(symbol, &lsym))
+			? lsym : NULL));
+	} else {
+		sym = (Elf_Sym *)symtab->start;
+		while ((char *)sym < symtab->end) {
+			if (sym->st_name != 0 &&
+			    !strcmp(symtab->private + sym->st_name, symbol))
+				return ((c_db_sym_t)sym);
+			sym++;
+		}
+	}
+	return (NULL);
 }
 
 c_db_sym_t
 X_db_search_symbol(db_symtab_t *symtab, db_addr_t off, db_strategy_t strat,
     db_expr_t *diffp)
 {
-	c_linker_sym_t sym;
-	long diff;
+	c_linker_sym_t lsym;
+	Elf_Sym *sym, *match;
+	unsigned long diff;
+
+	if (symtab->private == NULL) {
+		if (!linker_ddb_search_symbol((caddr_t)off, &lsym, &diff)) {
+			*diffp = (db_expr_t)diff;
+			return ((c_db_sym_t)lsym);
+		}
+		return (NULL);
+	}
 
-	if (!linker_ddb_search_symbol((caddr_t)off, &sym, &diff)) {
-		*diffp = (db_expr_t)diff;
-		return (c_db_sym_t) sym;
+	diff = ~0UL;
+	match = NULL;
+	for (sym = (Elf_Sym*)symtab->start; (char*)sym < symtab->end; sym++) {
+		if (sym->st_name == 0)
+			continue;
+		if (off < sym->st_value)
+			continue;
+		if (ELF_ST_TYPE(sym->st_info) != STT_OBJECT &&
+		    ELF_ST_TYPE(sym->st_info) != STT_FUNC &&
+		    ELF_ST_TYPE(sym->st_info) != STT_NOTYPE)
+			continue;
+		if ((off - sym->st_value) > diff)
+			continue;
+		if ((off - sym->st_value) < diff) {
+			diff = off - sym->st_value;
+			match = sym;
+		} else {
+			if (match == NULL)
+				match = sym;
+			else if (ELF_ST_BIND(match->st_info) == STB_LOCAL &&
+			    ELF_ST_BIND(sym->st_info) != STB_LOCAL)
+				match = sym;
+		}
+		if (diff == 0) {
+			if (strat == DB_STGY_PROC &&
+			    ELF_ST_TYPE(sym->st_info) == STT_FUNC &&
+			    ELF_ST_BIND(sym->st_info) != STB_LOCAL)
+				break;
+			if (strat == DB_STGY_ANY &&
+			    ELF_ST_BIND(sym->st_info) != STB_LOCAL)
+				break;
+		}
 	}
-	return 0;
+
+	*diffp = (match == NULL) ? off : diff;
+	return ((c_db_sym_t)match);
 }
 
 boolean_t
@@ -94,20 +146,40 @@
 X_db_symbol_values(db_symtab_t *symtab, c_db_sym_t sym, const char **namep,
     db_expr_t *valp)
 {
-	c_linker_sym_t lsym = (c_linker_sym_t)sym;
 	linker_symval_t lval;
 
-	linker_ddb_symbol_values(lsym, &lval);
-	if (namep)
-		*namep = (const char*)lval.name;
-	if (valp)
-		*valp = (db_expr_t)lval.value;
+	if (symtab->private == NULL) {
+		linker_ddb_symbol_values((c_linker_sym_t)sym, &lval);
+		if (namep != NULL)
+			*namep = (const char*)lval.name;
+		if (valp != NULL)
+			*valp = (db_expr_t)lval.value;
+	} else {
+		if (namep != NULL)
+			*namep = (const char *)symtab->private +
+			    ((const Elf_Sym *)sym)->st_name;
+		if (valp != NULL)
+			*valp = (db_expr_t)((const Elf_Sym *)sym)->st_value;
+	}
 }
 
 static int
 db_init(void)
 {
-	db_add_symbol_table(0, 0, "kernel", 0);
+	uintptr_t symtab, strtab;
+	Elf_Size tabsz, strsz;
+
+	if (ksym_end > ksym_start && ksym_start != 0) {
+		symtab = ksym_start;
+		tabsz = *((Elf_Size*)symtab)++;
+		strtab = symtab + tabsz;
+		strsz = *((Elf_Size*)strtab)++;
+		if (strtab + strsz <= ksym_end) {
+			db_add_symbol_table((char *)symtab,
+			    (char *)(symtab + tabsz), "elf", (char *)strtab);
+		}
+	}
+	db_add_symbol_table(NULL, NULL, "kld", NULL);
 	return (1);	/* We're the default debugger. */
 }
 
@@ -120,6 +192,8 @@
 static int
 db_trap(int type, int code)
 {
+	jmp_buf jb;
+	void *prev_jb;
 	boolean_t bkpt, watchpt;
 
 	/*
@@ -146,9 +220,11 @@
 		else
 			db_printf("Stopped at\t");
 		db_dot = PC_REGS(DDB_REGS);
-		if (setjmp(db_jmpbuf) == 0)
+		prev_jb = kdb_jmpbuf(jb);
+		if (setjmp(jb) == 0)
 			db_print_loc_and_inst(db_dot);
 		db_command_loop();
+		(void)kdb_jmpbuf(prev_jb);
 	}
 
 	db_restart_at_pc(watchpt);

==== //depot/projects/gdb/sys/i386/i386/machdep.c#5 (text+ko) ====

@@ -160,6 +160,10 @@
 #endif /* CPU_ENABLE_SSE */
 SYSINIT(cpu, SI_SUB_CPU, SI_ORDER_FIRST, cpu_startup, NULL)
 
+#ifdef DDB
+extern vm_offset_t ksym_start, ksym_end;
+#endif
+
 int	_udatasel, _ucodesel;
 u_int	atdevbase, basemem;
 
@@ -2099,6 +2103,11 @@
 	atpic_startup();
 #endif
 
+#ifdef DDB
+	ksym_start = bootinfo.bi_symtab;
+	ksym_end = bootinfo.bi_esymtab;
+#endif
+
 	kdb_init();
 
 #ifdef KDB
@@ -2842,12 +2851,12 @@
 }
 #endif
 
-#ifdef DDB
+#ifdef KDB
 
 /*
  * Provide inb() and outb() as functions.  They are normally only
  * available as macros calling inlined functions, thus cannot be
- * called inside DDB.
+ * called from the debugger.
  *
  * The actual code is stolen from <machine/cpufunc.h>, and de-inlined.
  */
@@ -2886,4 +2895,4 @@
 	__asm __volatile("outb %0,%%dx" : : "a" (al), "d" (port));
 }
 
-#endif /* DDB */
+#endif /* KDB */

==== //depot/projects/gdb/sys/ia64/ia64/machdep.c#7 (text+ko) ====

@@ -127,8 +127,7 @@
     "The CPU family name");
 
 #ifdef DDB
-/* start and end of kernel symbol table */
-void	*ksym_start, *ksym_end;
+extern vm_offset_t ksym_start, ksym_end;
 #endif
 
 static void cpu_startup(void *);
@@ -587,8 +586,8 @@
 	 */
 	kernstart = trunc_page(kernel_text);
 #ifdef DDB
-	ksym_start = (void *)bootinfo.bi_symtab;
-	ksym_end = (void *)bootinfo.bi_esymtab;
+	ksym_start = bootinfo.bi_symtab;
+	ksym_end = bootinfo.bi_esymtab;
 	kernend = (vm_offset_t)round_page(ksym_end);
 #else
 	kernend = (vm_offset_t)round_page(_end);

==== //depot/projects/gdb/sys/pc98/i386/machdep.c#5 (text+ko) ====

@@ -167,6 +167,10 @@
 int	need_post_dma_flush;	/* If 1, use invd after DMA transfer. */
 #endif
 
+#ifdef DDB
+extern vm_offset_t ksym_start, ksym_end;
+#endif
+
 int	_udatasel, _ucodesel;
 u_int	atdevbase, basemem;
 
@@ -2165,6 +2169,11 @@
 	atpic_startup();
 #endif
 
+#ifdef DDB
+	ksym_start = bootinfo.bi_symtab;
+	ksym_end = bootinfo.bi_esymtab;
+#endif
+
 	kdb_init();
 
 #ifdef KDB
@@ -2803,12 +2812,12 @@
         return 0;
 }
 
-#ifdef DDB
+#ifdef KDB
 
 /*
  * Provide inb() and outb() as functions.  They are normally only
  * available as macros calling inlined functions, thus cannot be
- * called inside DDB.
+ * called from the debugger.
  *
  * The actual code is stolen from <machine/cpufunc.h>, and de-inlined.
  */
@@ -2847,4 +2856,4 @@
 	__asm __volatile("outb %0,%%dx" : : "a" (al), "d" (port));
 }
 
-#endif /* DDB */
+#endif /* KDB */

==== //depot/projects/gdb/sys/powerpc/powerpc/machdep.c#5 (text+ko) ====

@@ -135,8 +135,7 @@
 	   CTLFLAG_RD, &cacheline_size, 0, "");
 
 #ifdef DDB
-/* start and end of kernel symbol table */
-void		*ksym_start, *ksym_end;
+extern vm_offset_t ksym_start, ksym_end;
 #endif /* DDB */
 
 static void	cpu_startup(void *);

==== //depot/projects/gdb/sys/sparc64/sparc64/machdep.c#6 (text+ko) ====

@@ -110,6 +110,10 @@
 
 typedef int ofw_vec_t(void *);
 
+#ifdef DDB
+extern vm_offset_t ksym_start, ksym_end;
+#endif
+
 struct tlb_entry *kernel_tlbs;
 int kernel_tlb_slots;
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200404250129.i3P1TuZV078585>