Subject: bin/2375: gdb -k doesn't use specified executable for kvm_open()
To: None <gnats-bugs@NetBSD.ORG>
From: None <mhitch@gemini.oscs.montana.edu>
List: netbsd-bugs
Date: 05/05/1996 11:46:23
>Number:         2375
>Category:       bin
>Synopsis:       gdb -k doesn't use specified executable for kvm_open()
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun May  5 14:20:02 1996
>Last-Modified:
>Originator:     Michael L. Hitch
>Organization:
	Montana State University
>Release:        1.1
>Environment:
System: NetBSD amiga2.oscs.montana.edu 1.1B NetBSD 1.1B (ZEUS) #960504-0: Sat May 4 12:18:19 MDT 1996 mhitch@amiga2.oscs.montana.edu:/tmp/sys/arch/amiga/compile/ZEUS amiga


>Description:
	When debugging a kernel coredump file, gdb uses the kvm_* routines
	to access the corefile.  The kvm_open() call does not use the
	specified executable file, so the kvm routines will use "/netbsd"
	to initialize.  If the corefile was created with a different
	kernel, kvread() may be unable to correctly locate the specified
	address.  The kvm routines will be using "/netbsd" for symbols
	internally, resulting in the wrong addresses within the corefile
	when trying to map virtual addresses to locations in the corefile.
>How-To-Repeat:
	Create a coredump using a different kernel (i.e. a differently
	configured kernel) and try to run gdb -k using the resulting
	coredump and kernel files.  When gdb attempts to read the pcb,
	it may fail because kvread() doesn't get the correct location
	in the corefile.
>Fix:
	Include the filename of the executable in the kvm_open() call:

diff -c /usr/src/gnu/usr.bin/gdb/gdb/kcorelow.c ./kcorelow.c
*** /usr/src/gnu/usr.bin/gdb/gdb/kcorelow.c	Fri Oct 13 18:23:11 1995
--- ./kcorelow.c	Sun May  5 10:15:33 1996
***************
*** 180,186 ****
  
  	old_chain = make_cleanup (free, filename);
  
! 	core_kd = kvm_open (NULL, filename, NULL,
  			    write_files? O_RDWR: O_RDONLY, 0);
  	if (core_kd == NULL)
  		perror_with_name (filename);
--- 180,186 ----
  
  	old_chain = make_cleanup (free, filename);
  
! 	core_kd = kvm_open (bfd_get_filename(exec_bfd), filename, NULL,
  			    write_files? O_RDWR: O_RDONLY, 0);
  	if (core_kd == NULL)
  		perror_with_name (filename);

>Audit-Trail:
>Unformatted: