Date: Sun, 21 Mar 2004 18:12:56 -0800 (PST) From: Marcel Moolenaar <marcel@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 49490 for review Message-ID: <200403220212.i2M2CuS3078609@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=49490 Change 49490 by marcel@marcel_nfs on 2004/03/21 18:12:41 Turn DDB into a backend. Add db_main.c for this. Move db_trap() from db_trap.c to db_main.c. It doesn't need its own file and fits better in db_main.c now. Do not compile db_kld.c and db_elf.c. Both contain db_init(), but only one of them takes effect (controlled by DDB_NOKLDSYM). Desupport DDB_NOKLDSYM. I don't see any reason why the kernel's symbol table and the linker cannot be used at the same time. DDB support multiple symbol tables, so we can always start with the kernel's symbol tables and add the kernel when it's ready. Currently only i386 compiles. It doesn't quite work, but I'm more concerned with the structure anyway at this time. More to come... Affected files ... .. //depot/projects/gdb/sys/conf/files#9 edit .. //depot/projects/gdb/sys/conf/options#8 edit .. //depot/projects/gdb/sys/ddb/db_main.c#1 add .. //depot/projects/gdb/sys/ddb/db_output.c#3 edit .. //depot/projects/gdb/sys/ddb/ddb.h#3 edit .. //depot/projects/gdb/sys/i386/i386/db_interface.c#5 edit .. //depot/projects/gdb/sys/i386/i386/trap.c#5 edit .. //depot/projects/gdb/sys/i386/isa/clock.c#2 edit .. //depot/projects/gdb/sys/kern/kern_mutex.c#3 edit .. //depot/projects/gdb/sys/kern/kern_synch.c#6 edit .. //depot/projects/gdb/sys/kern/subr_prf.c#3 edit .. //depot/projects/gdb/sys/kern/tty_cons.c#4 edit Differences ... ==== //depot/projects/gdb/sys/conf/files#9 (text+ko) ==== @@ -224,24 +224,22 @@ opencrypto/rmd160.c optional ipsec crypto/sha1.c optional ipsec crypto/sha2/sha2.c optional ipsec -ddb/db_access.c optional ddb -ddb/db_break.c optional ddb -ddb/db_command.c optional ddb -ddb/db_elf.c optional ddb -ddb/db_examine.c optional ddb -ddb/db_expr.c optional ddb -ddb/db_input.c optional ddb -ddb/db_kld.c optional ddb -ddb/db_lex.c optional ddb -ddb/db_output.c optional ddb -ddb/db_print.c optional ddb -ddb/db_ps.c optional ddb -ddb/db_run.c optional ddb -ddb/db_sym.c optional ddb -ddb/db_trap.c optional ddb -ddb/db_variables.c optional ddb -ddb/db_watch.c optional ddb -ddb/db_write_cmd.c optional ddb +ddb/db_access.c optional ddb +ddb/db_break.c optional ddb +ddb/db_command.c optional ddb +ddb/db_examine.c optional ddb +ddb/db_expr.c optional ddb +ddb/db_input.c optional ddb +ddb/db_lex.c optional ddb +ddb/db_main.c optional ddb +ddb/db_output.c optional ddb +ddb/db_print.c optional ddb +ddb/db_ps.c optional ddb +ddb/db_run.c optional ddb +ddb/db_sym.c optional ddb +ddb/db_variables.c optional ddb +ddb/db_watch.c optional ddb +ddb/db_write_cmd.c optional ddb dev/aac/aac.c optional aac dev/aac/aac_debug.c optional aac dev/aac/aac_disk.c optional aac ==== //depot/projects/gdb/sys/conf/options#8 (text+ko) ==== @@ -73,7 +73,6 @@ # Debugging options. DDB -DDB_NOKLDSYM opt_ddb.h DDB_NUMSYM opt_ddb.h GDB GDBSPEED opt_gdb.h ==== //depot/projects/gdb/sys/ddb/db_output.c#3 (text+ko) ==== @@ -38,6 +38,7 @@ #include <sys/param.h> #include <sys/systm.h> #include <sys/cons.h> +#include <sys/kdb.h> #include <sys/kernel.h> #include <sys/sysctl.h> @@ -112,9 +113,9 @@ * If not in the debugger or the user requests it, output data to * both the console and the message buffer. */ - if (!db_active || ddb_use_printf) { + if (!kdb_active || ddb_use_printf) { printf("%c", c); - if (!db_active) + if (!kdb_active) return; if (c == '\r' || c == '\n') db_check_interrupt(); ==== //depot/projects/gdb/sys/ddb/ddb.h#3 (text+ko) ==== @@ -83,11 +83,9 @@ struct vm_map; -#ifdef ALT_BREAK_TO_DEBUGGER -int db_alt_break(int, int *); -#endif void db_check_interrupt(void); void db_clear_watchpoints(void); +void db_cpu_trap(int, int, struct trapframe *); db_addr_t db_disasm(db_addr_t loc, boolean_t altfmt); /* instruction disassembler */ void db_error(const char *s); @@ -109,13 +107,13 @@ void db_skip_to_eol(void); boolean_t db_stop_at_pc(boolean_t *is_breakpoint); #define db_strcpy strcpy -void db_trap(int type, int code); int db_value_of_name(const char *name, db_expr_t *valuep); void db_write_bytes(vm_offset_t addr, size_t size, char *data); /* machine-dependent */ void db_stack_thread(db_expr_t addr, boolean_t have_addr, db_expr_t count, char *modif); -void db_init(void); + +void _db_init(void); db_cmdfcn_t db_breakpoint_cmd; db_cmdfcn_t db_continue_cmd; ==== //depot/projects/gdb/sys/i386/i386/db_interface.c#5 (text+ko) ==== @@ -48,20 +48,6 @@ #include <ddb/ddb.h> -#include <machine/setjmp.h> - -static jmp_buf *db_nofault = 0; -extern jmp_buf db_jmpbuf; - -#if 0 -extern void gdb_handle_exception(db_regs_t *, int, int); -static jmp_buf db_global_jmpbuf; -#endif - -int db_active; -db_regs_t ddb_regs; - - static __inline u_short rss(void) { @@ -75,162 +61,15 @@ return ss; } -#if 0 -/* - * ddb_trap - field a TRACE or BPT trap - */ -int -ddb_trap(int type, int code, struct i386_saved_state *regs) +void +db_cpu_trap(int type, int code, struct trapframe *tf) { - u_int ef; - volatile int ddb_mode = !(boothowto & RB_GDB); - - /* - * XXX try to do nothing if the console is in graphics mode. - * Handle trace traps (and hardware breakpoints...) by ignoring - * them except for forgetting about them. Return 0 for other - * traps to say that we haven't done anything. The trap handler - * will usually panic. We should handle breakpoint traps for - * our breakpoints by disarming our breakpoints and fixing up - * %eip. - */ - if (cnunavailable() != 0 && ddb_mode) { - if (type == T_TRCTRAP) { - regs->tf_eflags &= ~PSL_T; - return (1); - } - return (0); + /* If in kernel mode, esp and ss are not saved, so dummy them up. */ + if (ISPL(tf->tf_cs) == 0) { + tf->tf_esp = (int)&tf->tf_esp; + tf->tf_ss = rss(); } - - ef = read_eflags(); - disable_intr(); - -#ifdef SMP -#ifdef CPUSTOP_ON_DDBBREAK - -#if defined(VERBOSE_CPUSTOP_ON_DDBBREAK) - db_printf("\nCPU%d stopping CPUs: 0x%08x...", PCPU_GET(cpuid), - PCPU_GET(other_cpus)); -#endif /* VERBOSE_CPUSTOP_ON_DDBBREAK */ - - /* We stop all CPUs except ourselves (obviously) */ - stop_cpus(PCPU_GET(other_cpus)); - -#if defined(VERBOSE_CPUSTOP_ON_DDBBREAK) - db_printf(" stopped.\n"); -#endif /* VERBOSE_CPUSTOP_ON_DDBBREAK */ - -#endif /* CPUSTOP_ON_DDBBREAK */ -#endif /* SMP */ - - switch (type) { - case T_BPTFLT: /* breakpoint */ - case T_TRCTRAP: /* debug exception */ - break; - - default: - /* - * XXX this is almost useless now. In most cases, - * trap_fatal() has already printed a much more verbose - * message. However, it is dangerous to print things in - * trap_fatal() - printf() might be reentered and trap. - * The debugger should be given control first. - */ - if (ddb_mode) - db_printf("kernel: type %d trap, code=%x\n", type, code); - - if (db_nofault) { - jmp_buf *no_fault = db_nofault; - db_nofault = 0; - longjmp(*no_fault, 1); - } - } - - /* - * This handles unexpected traps in ddb commands, including calls to - * non-ddb functions. db_nofault only applies to memory accesses by - * internal ddb commands. - */ - if (db_active) - longjmp(db_global_jmpbuf, 1); - - /* - * XXX We really should switch to a local stack here. - */ - ddb_regs = *regs; - - /* - * If in kernel mode, esp and ss are not saved, so dummy them up. - */ - if (ISPL(regs->tf_cs) == 0) { - ddb_regs.tf_esp = (int)®s->tf_esp; - ddb_regs.tf_ss = rss(); - } - - (void) setjmp(db_global_jmpbuf); - if (ddb_mode) { - if (!db_active) - cndbctl(TRUE); - db_active = 1; - db_trap(type, code); - cndbctl(FALSE); - } else { - db_active = 1; - gdb_handle_exception(&ddb_regs, type, code); - } - db_active = 0; - - regs->tf_eip = ddb_regs.tf_eip; - regs->tf_eflags = ddb_regs.tf_eflags; - regs->tf_eax = ddb_regs.tf_eax; - regs->tf_ecx = ddb_regs.tf_ecx; - regs->tf_edx = ddb_regs.tf_edx; - regs->tf_ebx = ddb_regs.tf_ebx; - - /* - * If in user mode, the saved ESP and SS were valid, restore them. - */ - if (ISPL(regs->tf_cs)) { - regs->tf_esp = ddb_regs.tf_esp; - regs->tf_ss = ddb_regs.tf_ss & 0xffff; - } - - regs->tf_ebp = ddb_regs.tf_ebp; - regs->tf_esi = ddb_regs.tf_esi; - regs->tf_edi = ddb_regs.tf_edi; - regs->tf_es = ddb_regs.tf_es & 0xffff; - regs->tf_fs = ddb_regs.tf_fs & 0xffff; - regs->tf_cs = ddb_regs.tf_cs & 0xffff; - regs->tf_ds = ddb_regs.tf_ds & 0xffff; - -#ifdef SMP -#ifdef CPUSTOP_ON_DDBBREAK - -#if defined(VERBOSE_CPUSTOP_ON_DDBBREAK) - db_printf("\nCPU%d restarting CPUs: 0x%08x...", PCPU_GET(cpuid), - stopped_cpus); -#endif /* VERBOSE_CPUSTOP_ON_DDBBREAK */ - - /* Restart all the CPUs we previously stopped */ - if (stopped_cpus != PCPU_GET(other_cpus) && smp_started != 0) { - db_printf("whoa, other_cpus: 0x%08x, stopped_cpus: 0x%08x\n", - PCPU_GET(other_cpus), stopped_cpus); - panic("stop_cpus() failed"); - } - restart_cpus(stopped_cpus); - -#if defined(VERBOSE_CPUSTOP_ON_DDBBREAK) - db_printf(" restarted.\n"); -#endif /* VERBOSE_CPUSTOP_ON_DDBBREAK */ - -#endif /* CPUSTOP_ON_DDBBREAK */ -#endif /* SMP */ - - write_eflags(ef); - - return (1); } -#endif /* * Read bytes from kernel address space for debugger. @@ -240,13 +79,13 @@ { char *src; - db_nofault = &db_jmpbuf; + /* db_nofault = &db_jmpbuf; */ src = (char *)addr; while (size-- > 0) *data++ = *src++; - db_nofault = 0; + /* db_nofault = 0; */ } /* @@ -263,7 +102,7 @@ pt_entry_t *ptep1 = NULL; pt_entry_t oldmap1 = 0; - db_nofault = &db_jmpbuf; + /* db_nofault = &db_jmpbuf; */ if (addr > trunc_page((vm_offset_t)btext) - size && addr < round_page((vm_offset_t)etext)) { @@ -297,7 +136,7 @@ while (size-- > 0) *dst++ = *data++; - db_nofault = 0; + /* db_nofault = 0; */ if (ptep0) { *ptep0 = oldmap0; ==== //depot/projects/gdb/sys/i386/i386/trap.c#5 (text+ko) ==== @@ -189,8 +189,8 @@ atomic_add_int(&cnt.v_trap, 1); type = frame.tf_trapno; -#ifdef DDB - if (db_active) { +#ifdef KDB + if (kdb_active) { eva = (type == T_PAGEFLT ? rcr2() : 0); trap_fatal(&frame, eva); goto out; @@ -807,8 +807,8 @@ printf("Idle\n"); } -#ifdef DDB - if ((debugger_on_panic || db_active) && kdb_trap(type, 0, frame)) +#ifdef KDB + if ((debugger_on_panic || kdb_active) && kdb_trap(type, 0, frame)) return; #endif printf("trap number = %d\n", type); ==== //depot/projects/gdb/sys/i386/isa/clock.c#2 (text+ko) ==== @@ -58,6 +58,7 @@ #include <sys/systm.h> #include <sys/bus.h> #include <sys/lock.h> +#include <sys/kdb.h> #include <sys/mutex.h> #include <sys/proc.h> #include <sys/time.h> @@ -457,8 +458,8 @@ * locking for many reasons, but it calls here for at least atkbd * input. */ -#ifdef DDB - if (db_active) +#ifdef KDB + if (kdb_active) prev_tick = 0; else #endif @@ -489,8 +490,8 @@ / 1000000; while (ticks_left > 0) { -#ifdef DDB - if (db_active) { +#ifdef KDB + if (kdb_active) { inb(0x84); tick = prev_tick + 1; } else ==== //depot/projects/gdb/sys/kern/kern_mutex.c#3 (text+ko) ==== @@ -42,6 +42,7 @@ #include <sys/param.h> #include <sys/systm.h> #include <sys/bus.h> +#include <sys/kdb.h> #include <sys/kernel.h> #include <sys/ktr.h> #include <sys/lock.h> @@ -580,11 +581,7 @@ } if (i < 60000000) DELAY(1); -#ifdef DDB - else if (!db_active) { -#else - else { -#endif + else if (!kdb_active) { printf("spin lock %s held by %p for > 5 seconds\n", m->mtx_object.lo_name, (void *)m->mtx_lock); #ifdef WITNESS ==== //depot/projects/gdb/sys/kern/kern_synch.c#6 (text+ko) ==== @@ -47,6 +47,7 @@ #include <sys/param.h> #include <sys/systm.h> #include <sys/condvar.h> +#include <sys/kdb.h> #include <sys/kernel.h> #include <sys/ktr.h> #include <sys/lock.h> @@ -334,16 +335,14 @@ td->td_generation++; /* bump preempt-detect counter */ -#ifdef DDB /* * Don't perform context switches from the debugger. */ - if (db_active) { + if (kdb_active) { mtx_unlock_spin(&sched_lock); db_print_backtrace(); db_error("Context switches not allowed in the debugger"); } -#endif /* * Check if the process exceeds its cpu resource allocation. If ==== //depot/projects/gdb/sys/kern/subr_prf.c#3 (text+ko) ==== @@ -46,6 +46,7 @@ #include <sys/param.h> #include <sys/systm.h> #include <sys/lock.h> +#include <sys/kdb.h> #include <sys/mutex.h> #include <sys/sx.h> #include <sys/kernel.h> @@ -339,10 +340,8 @@ /* Don't use the tty code after a panic or while in ddb. */ if (panicstr) consdirect = 1; -#ifdef DDB - if (db_active) + if (kdb_active) consdirect = 1; -#endif if (consdirect) { if (c != '\0') cnputc(c); ==== //depot/projects/gdb/sys/kern/tty_cons.c#4 (text+ko) ==== @@ -48,6 +48,7 @@ #include <sys/conf.h> #include <sys/cons.h> #include <sys/fcntl.h> +#include <sys/kdb.h> #include <sys/kernel.h> #include <sys/malloc.h> #include <sys/msgbuf.h> @@ -566,16 +567,12 @@ return (-1); STAILQ_FOREACH(cnd, &cn_devlist, cnd_next) { cn = cnd->cnd_cn; -#ifdef DDB - if (!db_active || !(cn->cn_flags & CN_FLAG_NODEBUG)) { -#endif + if (!kdb_active || !(cn->cn_flags & CN_FLAG_NODEBUG)) { c = cn->cn_checkc(cn); if (c != -1) { return (c); } -#ifdef DDB } -#endif } return (-1); } @@ -591,21 +588,13 @@ return; STAILQ_FOREACH(cnd, &cn_devlist, cnd_next) { cn = cnd->cnd_cn; -#ifdef DDB - if (!db_active || !(cn->cn_flags & CN_FLAG_NODEBUG)) { -#endif + if (!kdb_active || !(cn->cn_flags & CN_FLAG_NODEBUG)) { if (c == '\n') cn->cn_putc(cn, '\r'); cn->cn_putc(cn, c); -#ifdef DDB } -#endif } -#ifdef DDB - if (console_pausing && !db_active && (c == '\n')) { -#else - if (console_pausing && (c == '\n')) { -#endif + if (console_pausing && c == '\n' && !kdb_active) { for (cp = console_pausestr; *cp != '\0'; cp++) cnputc(*cp); if (cngetc() == '.')
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200403220212.i2M2CuS3078609>