Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 24 Jul 2004 17:29:56 GMT
From:      Marcel Moolenaar <marcel@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 58051 for review
Message-ID:  <200407241729.i6OHTuT6099015@repoman.freebsd.org>

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

Change 58051 by marcel@marcel_nfs on 2004/07/24 17:29:34

	Basic support on i386. The machine specific file is really
	trivial, so it's easy to add new machines. What's lacking
	in general is:
	o  Loading of kernel modules,
	o  Printing of the panic string,
	o  Setting of the source search directories.

Affected files ...

.. //depot/projects/gdb/gnu/usr.bin/gdb/kgdb/Makefile#2 edit
.. //depot/projects/gdb/gnu/usr.bin/gdb/kgdb/kgdb.h#2 edit
.. //depot/projects/gdb/gnu/usr.bin/gdb/kgdb/kthr.c#2 edit
.. //depot/projects/gdb/gnu/usr.bin/gdb/kgdb/main.c#2 edit
.. //depot/projects/gdb/gnu/usr.bin/gdb/kgdb/trgt.c#1 add
.. //depot/projects/gdb/gnu/usr.bin/gdb/kgdb/trgt_i386.c#1 add

Differences ...

==== //depot/projects/gdb/gnu/usr.bin/gdb/kgdb/Makefile#2 (text+ko) ====

@@ -1,7 +1,8 @@
 # $FreeBSD$
 
 PROG=	kgdb
-SRCS=	kthr.c main.c
+SRCS=	kthr.c main.c trgt.c trgt_${MACHINE_ARCH}.c
+WARNS?=	2
 
 BULIBS= ${OBJ_BU}/libbfd/libbfd.a ${OBJ_BU}/libopcodes/libopcodes.a \
 	${OBJ_BU}/libiberty/libiberty.a

==== //depot/projects/gdb/gnu/usr.bin/gdb/kgdb/kgdb.h#2 (text+ko) ====

@@ -30,18 +30,20 @@
 extern kvm_t *kvm;
 extern int verbose;
 
-struct pcb;
-
 struct kthr {
 	struct kthr	*next;
 	uintptr_t	kaddr;
-	uintptr_t	td_kstack;
-	struct pcb	*td_pcb;
-	int		td_tid;
+	uintptr_t	kstack;
+	uintptr_t	pcb;
+	int		tid;
 };
 
 extern struct kthr *curkthr;
 
+void kgdb_target(void);
+void kgdb_trgt_fetch_registers(int);
+void kgdb_trgt_store_registers(int);
+
 struct kthr *kgdb_thr_first(void);
 struct kthr *kgdb_thr_init(void);
 struct kthr *kgdb_thr_lookup(int);

==== //depot/projects/gdb/gnu/usr.bin/gdb/kgdb/kthr.c#2 (text+ko) ====

@@ -37,16 +37,28 @@
 #include <stdio.h>
 #include <stdlib.h>
 
-#include <machine/pcb.h>
-
 #include "kgdb.h"
 
-struct pcb *dumppcb;
-int dumptid;
+static uintptr_t dumppcb;
+static int dumptid;
 
 static struct kthr *first;
 struct kthr *curkthr;
 
+static uintptr_t
+lookup(const char *sym)
+{
+	struct nlist nl[2];
+
+	nl[0].n_name = (char *)(uintptr_t)sym;
+	nl[1].n_name = NULL;
+	if (kvm_nlist(kvm, nl) != 0) {
+		warnx("kvm_nlist(%s): %s", sym, kvm_geterr(kvm));
+		return (0);
+	}
+	return (nl[0].n_value);
+}
+
 struct kthr *
 kgdb_thr_first(void)
 {
@@ -56,46 +68,42 @@
 struct kthr *
 kgdb_thr_init(void)
 {
-	struct nlist nl[3];
 	struct proc p;
 	struct thread td;
-	struct kthr *thr;
-	uintptr_t paddr, tdaddr;
+	struct kthr *kt;
+	uintptr_t addr, paddr;
+
+	addr = lookup("_allproc");
+	if (addr == 0)
+		return (NULL);
+	kvm_read(kvm, addr, &paddr, sizeof(paddr));
 
-	nl[0].n_name = (char *)(uintptr_t)"_allproc";
-	nl[1].n_name = NULL;
-	if (kvm_nlist(kvm, nl) != 0) {
-		warnx(kvm_geterr(kvm));
+	dumppcb = lookup("_dumppcb");
+	if (dumppcb == 0)
 		return (NULL);
-	}
-	kvm_read(kvm, nl[0].n_value, &paddr, sizeof(paddr));
 
-	nl[0].n_name = (char *)(uintptr_t)"_dumppcb";
-	nl[1].n_name = (char *)(uintptr_t)"_dumptid";
-	nl[2].n_name = NULL;
-	if (kvm_nlist(kvm, nl) != 0) {
-		warnx(kvm_geterr(kvm));
-		dumppcb = NULL;
+	addr = lookup("_dumptid");
+	if (addr != 0)
+		kvm_read(kvm, addr, &dumptid, sizeof(dumptid));
+	else
 		dumptid = -1;
-	} else {
-		dumppcb = (struct pcb *)(nl[0].n_value);
-		kvm_read(kvm, nl[1].n_value, &dumptid, sizeof(dumptid));
-	}
 
 	while (paddr != 0) {
-		kvm_read(kvm, paddr, &p, sizeof(p));
-		tdaddr = (uintptr_t)TAILQ_FIRST(&p.p_threads);
-		while (tdaddr != 0) {
-			kvm_read(kvm, tdaddr, &td, sizeof(td));
-			thr = malloc(sizeof(*thr));
-			thr->next = first;
-			thr->kaddr = tdaddr;
-			thr->td_pcb = (td.td_tid == dumptid) ? dumppcb :
-			    td.td_pcb;
-			thr->td_kstack = td.td_kstack;
-			thr->td_tid = td.td_tid;
-			first = thr;
-			tdaddr = (uintptr_t)TAILQ_NEXT(&td, td_plist);
+		if (kvm_read(kvm, paddr, &p, sizeof(p)) != sizeof(p))
+			warnx("kvm_read: %s", kvm_geterr(kvm));
+		addr = (uintptr_t)TAILQ_FIRST(&p.p_threads);
+		while (addr != 0) {
+			if (kvm_read(kvm, addr, &td, sizeof(td)) != sizeof(td))
+				warnx("kvm_read: %s", kvm_geterr(kvm));
+			kt = malloc(sizeof(*kt));
+			kt->next = first;
+			kt->kaddr = addr;
+			kt->pcb = (td.td_tid == dumptid) ? dumppcb :
+			    (uintptr_t)td.td_pcb;
+			kt->kstack = td.td_kstack;
+			kt->tid = td.td_tid;
+			first = kt;
+			addr = (uintptr_t)TAILQ_NEXT(&td, td_plist);
 		}
 		paddr = (uintptr_t)LIST_NEXT(&p, p_list);
 	}
@@ -108,26 +116,26 @@
 struct kthr *
 kgdb_thr_lookup(int tid)
 {
-	struct kthr *thr;
+	struct kthr *kt;
 
-	thr = first;
-	while (thr != NULL && thr->td_tid != tid)
-		thr = thr->next;
-	return (thr);
+	kt = first;
+	while (kt != NULL && kt->tid != tid)
+		kt = kt->next;
+	return (kt);
 }
 
 struct kthr *
-kgdb_thr_next(struct kthr *thr)
+kgdb_thr_next(struct kthr *kt)
 {
-	return (thr->next);
+	return (kt->next);
 }
 
 struct kthr *
-kgdb_thr_select(struct kthr *thr)
+kgdb_thr_select(struct kthr *kt)
 {
 	struct kthr *pcur;
 
 	pcur = curkthr;
-	curkthr = thr;
+	curkthr = kt;
 	return (pcur);
 }

==== //depot/projects/gdb/gnu/usr.bin/gdb/kgdb/main.c#2 (text+ko) ====

@@ -48,10 +48,14 @@
 
 /* libgdb stuff. */
 #include <defs.h>
+#include <frame.h>
+#include <inferior.h>
+#include <interps.h>
+#include <cli-out.h>
 #include <main.h>
+#include <target.h>
 #include <top.h>
 
-extern void (*pre_init_ui_hook)(void);
 extern void (*init_ui_hook)(char *);
 
 extern void symbol_file_add_main (char *args, int from_tty);
@@ -67,6 +71,8 @@
 static char *kernel;
 static char *vmcore;
 
+static void (*kgdb_new_objfile_chain)(struct objfile * objfile);
+
 static void
 usage(void)
 {
@@ -150,13 +156,52 @@
 }
 
 static void
+kgdb_new_objfile(struct objfile *objfile)
+{
+#if 0
+	printf("XXX: %s(%p)\n", __func__, objfile);
+	if (objfile != NULL) {
+		goto out;
+	}
+
+out:
+#endif
+	if (kgdb_new_objfile_chain != NULL)
+		kgdb_new_objfile_chain(objfile);
+}
+
+static void
+kgdb_interp_command_loop(void *data)
+{
+	static int once = 0;
+
+	if (!once) {
+		symbol_file_add_main (kernel, 0);
+		print_stack_frame(get_current_frame(), -1, 0);
+		once = 1;
+	}
+	command_loop();
+}
+
+static void
 kgdb_init(char *argv0 __unused)
 {
+	static struct interp_procs procs = {
+		NULL,
+		NULL,
+		NULL,
+		NULL,
+		NULL,
+		kgdb_interp_command_loop
+	};
+	struct interp *kgdb;
+	kgdb = interp_new("kgdb", NULL, cli_out_new(gdb_stdout), &procs);
+	interp_add(kgdb);
+
 	set_prompt("(kgdb) ");
-
-	/* Push our target onto the stack. */
-
-	symbol_file_add_main (kernel, 0);
+	kgdb_target();
+	kgdb_new_objfile_chain = target_new_objfile_hook;
+	target_new_objfile_hook = kgdb_new_objfile;
 }
 
 int
@@ -166,14 +211,6 @@
 	char *s;
 	int ch;
 
-	memset (&args, 0, sizeof args);
-	args.argc = 1;
-	args.argv = argv;
-	args.use_windows = 0;
-	args.interpreter_p = "console";
-
-	init_ui_hook = kgdb_init;
-
 	dumpnr = -1;
 
 	strlcpy(crashdir, "/var/crash", sizeof(crashdir));
@@ -203,8 +240,6 @@
 			usage();
 		}
 	}
-	argc -= optind;
-	argv += optind;
 
 	if (verbose > 1)
 		warnx("using %s as the crash directory", crashdir);
@@ -212,17 +247,15 @@
 	if (dumpnr >= 0)
 		use_dump(dumpnr);
 
-	if (argc > 0) {
+	if (argc > optind) {
 		if (kernel != NULL)
 			free(kernel);
-		kernel = strdup(*argv++);
-		argc--;
+		kernel = strdup(argv[optind++]);
 	}
-	while (argc > 0) {
+	while (argc > optind) {
 		if (vmcore != NULL)
 			errx(1, "multiple core files specified");
-		vmcore = strdup(*argv++);
-		argc--;
+		vmcore = strdup(argv[optind++]);
 	}
 
 	if (kernel == NULL)
@@ -243,5 +276,13 @@
 
 	kgdb_thr_init();
 
+	memset (&args, 0, sizeof args);
+	args.argc = 1;
+	args.argv = argv;
+	args.use_windows = 0;
+	args.interpreter_p = "kgdb";
+
+	init_ui_hook = kgdb_init;
+
 	return (gdb_main(&args));
 }



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