From gbrown@gbronline.com  Fri Dec 12 00:52:28 2003
Return-Path: <gbrown@gbronline.com>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 2994F16A4CE
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 12 Dec 2003 00:52:28 -0800 (PST)
Received: from mail2.gbronline.com (mail2.gbronline.com [12.145.226.11])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 26D1D43D2D
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 12 Dec 2003 00:52:27 -0800 (PST)
	(envelope-from gbrown@gbronline.com)
Received: from gbrown@gbronline.com [69.9.73.54] by mail2.gbronline.com with ESMTP
  (SMTPD32-8.04) id A1C65AF006A; Fri, 12 Dec 2003 02:52:22 -0600
Message-Id: <20031212025246.SM01044@gbrown@gbronline.com>
Date: Fri, 12 Dec 2003 02:52:28 -0600
From: George B.Rown <gbrown@gbronline.com>
To: undisclosed-recipients: ;
Subject: debugging a kernel module in load/attach routines

>Number:         60174
>Category:       kern
>Synopsis:       debugging a kernel module in load/attach routines
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Dec 12 01:00:36 PST 2003
>Closed-Date:    
>Last-Modified:  Mon Feb 21 18:51:11 UTC 2011
>Originator:     George B. Rown
>Release:        FreeBSD 5.1-RELEASE i386
>Organization:
gbrown
>Environment:
 
System: FreeBSD george 5.1-RELEASE FreeBSD 5.1-RELEASE i386
 
> Description:
 
     to debug a kernel module in the load/attach routines, one needs to know its base
     address -- before, eg., "kldstat" can show on the target, after "kldload" returns.
     A simple method is to save this base address in a global variable, and print its
     value in kgdb at a hard-coded "Debugger" call in the load/attach routine to debug
     (then to run a perl script to calculate the add-symbol command value from objdump).
 
> Fix:
 
 
 --- /usr/src/sys/kern/kern_linker.c     Mon Mar  3 14:53:35 2003
 +++ ~/src/sys/kern/kern_linker.c      Tue Dec  9 16:45:23 2003
 @@ -313,6 +313,8 @@
 
  SYSINIT(linker_kernel, SI_SUB_KLD, SI_ORDER_ANY, linker_init_kernel_modules, 0)
 
 +caddr_t loaded_module_base;
 +
  static int
  linker_load_file(const char *filename, linker_file_t *result)
  {
 @@ -351,6 +353,8 @@
                 if (error != ENOENT)
                         foundfile = 1;
                 if (lf) {
 +                       loaded_module_base = lf->address;
 +
                         linker_file_register_modules(lf);
                         linker_file_register_sysctls(lf);
                         linker_file_sysinit(lf);
>Description:
>How-To-Repeat:
>Fix:
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: gnats-admin->freebsd-bugs 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Fri Dec 12 22:30:30 PST 2003 
Responsible-Changed-Why:  
Rescue this port from the "pending" category (confidential had 
been mistakenly set to "yes"). 

http://www.freebsd.org/cgi/query-pr.cgi?pr=60174 
Responsible-Changed-From-To: freebsd-bugs->marcel 
Responsible-Changed-By: marcel 
Responsible-Changed-When: Sat Jul 17 02:17:51 GMT 2004 
Responsible-Changed-Why:  
This may be a case we should handle better in general. Since I'm 
working on kgdb anyway, see if I can improve it in one big swoop. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=60174 
Responsible-Changed-From-To: marcel->freebsd-bugs 
Responsible-Changed-By: marcel 
Responsible-Changed-When: Mon Feb 21 18:50:56 UTC 2011 
Responsible-Changed-Why:  
Assign back to the pool. I haven't been working on it and it's unlikely 
I will in the near future.  

http://www.freebsd.org/cgi/query-pr.cgi?pr=60174 
>Unformatted:
