added my responsibility for the `cpm' port
[unix-history] / sys / ddb / db_aout.c
index d1c848f..e256f21 100644 (file)
@@ -23,7 +23,7 @@
  * any improvements or extensions that they make and grant Carnegie the
  * rights to redistribute these changes.
  *
  * any improvements or extensions that they make and grant Carnegie the
  * rights to redistribute these changes.
  *
- *     $Id$
+ *     $Id: db_aout.c,v 1.5 1994/01/03 07:54:08 davidg Exp $
  */
 
 /*
  */
 
 /*
  */
 
 #include "param.h"
  */
 
 #include "param.h"
+#include "systm.h"
 #include "proc.h"
 #include "proc.h"
-#include <machine/db_machdep.h>                /* data types */
+#include "ddb/ddb.h"
 #include <ddb/db_sym.h>
 
 #ifndef        DB_NO_AOUT
 
 #define _AOUT_INCLUDE_
 #include "nlist.h"
 #include <ddb/db_sym.h>
 
 #ifndef        DB_NO_AOUT
 
 #define _AOUT_INCLUDE_
 #include "nlist.h"
+#include "stab.h"
 
 /*
  * An a.out symbol table as loaded into the kernel debugger:
 
 /*
  * An a.out symbol table as loaded into the kernel debugger:
         ep = (struct nlist *)((char *)sp + *(symtab)))
 
 #ifndef        SYMTAB_SPACE
         ep = (struct nlist *)((char *)sp + *(symtab)))
 
 #ifndef        SYMTAB_SPACE
-#define SYMTAB_SPACE 63000
+#define SYMTAB_SPACE 73000
 #endif /*SYMTAB_SPACE*/
 
 int db_symtabsize = SYMTAB_SPACE;
 char db_symtab[SYMTAB_SPACE] = { 1 };
 
 #endif /*SYMTAB_SPACE*/
 
 int db_symtabsize = SYMTAB_SPACE;
 char db_symtab[SYMTAB_SPACE] = { 1 };
 
+void
 X_db_sym_init(symtab, esymtab, name)
        int *   symtab;         /* pointer to start of symbol table */
        char *  esymtab;        /* pointer to end of string table,
 X_db_sym_init(symtab, esymtab, name)
        int *   symtab;         /* pointer to start of symbol table */
        char *  esymtab;        /* pointer to end of string table,
@@ -163,13 +166,17 @@ X_db_search_symbol(symtab, off, strategy, diffp)
        for (; sp < ep; sp++) {
            if (sp->n_un.n_name == 0)
                continue;
        for (; sp < ep; sp++) {
            if (sp->n_un.n_name == 0)
                continue;
-           if ((sp->n_type & N_STAB) != 0)
+           if ((sp->n_type & N_STAB) != 0 || (sp->n_type & N_TYPE) == N_FN)
                continue;
            if (off >= sp->n_value) {
                if (off - sp->n_value < diff) {
                    diff = off - sp->n_value;
                    symp = sp;
                continue;
            if (off >= sp->n_value) {
                if (off - sp->n_value < diff) {
                    diff = off - sp->n_value;
                    symp = sp;
-                   if (diff == 0)
+                   if (diff == 0 &&
+                               (strategy == DB_STGY_PROC &&
+                                       sp->n_type == (N_TEXT|N_EXT)   ||
+                               strategy == DB_STGY_ANY &&
+                                       (sp->n_type & N_EXT)))
                        break;
                }
                else if (off - sp->n_value == diff) {
                        break;
                }
                else if (off - sp->n_value == diff) {
@@ -208,27 +215,127 @@ X_db_symbol_values(sym, namep, valuep)
            *valuep = sp->n_value;
 }
 
            *valuep = sp->n_value;
 }
 
+
 boolean_t
 boolean_t
-X_db_line_at_pc()
+X_db_line_at_pc(symtab, cursym, filename, linenum, off)
+       db_symtab_t *   symtab;
+       db_sym_t        cursym;
+       char            **filename;
+       int             *linenum;
+       db_expr_t       off;
 {
 {
+       register struct nlist   *sp, *ep;
+       register struct nlist   *sym = (struct nlist *)cursym;
+       unsigned long           sodiff = -1UL, lndiff = -1UL, ln = 0;
+       char                    *fname = NULL;
+
+       sp = (struct nlist *)symtab->start;
+       ep = (struct nlist *)symtab->end;
+
+/* XXX - gcc specific */
+#define NEWSRC(str)    ((str) != NULL && \
+                       (str)[0] == 'g' && strcmp((str), "gcc_compiled.") == 0)
+
+       for (; sp < ep; sp++) {
+
+           /*
+            * Prevent bogus linenumbers in case module not compiled
+            * with debugging options
+            */
+#if 0
+           if (sp->n_value <= off && (off - sp->n_value) <= sodiff &&
+               NEWSRC(sp->n_un.n_name)) {
+#endif
+           if ((sp->n_type & N_TYPE) == N_FN || NEWSRC(sp->n_un.n_name)) { 
+               sodiff = lndiff = -1UL;
+               ln = 0;
+               fname = NULL;
+           }
+
+           if (sp->n_type == N_SO) {
+               if (sp->n_value <= off && (off - sp->n_value) < sodiff) {
+                       sodiff = off - sp->n_value;
+                       fname = sp->n_un.n_name;
+               }
+               continue;
+           }
+
+           if (sp->n_type != N_SLINE)
+               continue;
+
+           if (sp->n_value > off)
+               break;
+
+           if (off - sp->n_value < lndiff) {
+               lndiff = off - sp->n_value;
+               ln = sp->n_desc;
+           }
+       }
+
+       if (fname != NULL && ln != 0) {
+               *filename = fname;
+               *linenum = ln;
+               return TRUE;
+       }
+
        return (FALSE);
 }
 
        return (FALSE);
 }
 
+boolean_t
+X_db_sym_numargs(symtab, cursym, nargp, argnamep)
+       db_symtab_t *   symtab;
+       db_sym_t        cursym;
+       int             *nargp;
+       char            **argnamep;
+{
+       register struct nlist   *sp, *ep;
+       u_long                  addr;
+       int                     maxnarg = *nargp, nargs = 0;
+
+       if (cursym == NULL)
+               return FALSE;
+
+       addr = ((struct nlist *)cursym)->n_value;
+       sp = (struct nlist *)symtab->start;
+       ep = (struct nlist *)symtab->end;
+
+       for (; sp < ep; sp++) {
+           if (sp->n_type == N_FUN && sp->n_value == addr) {
+               while (++sp < ep && sp->n_type == N_PSYM) {
+                       if (nargs >= maxnarg)
+                               break;
+                       nargs++;
+                       *argnamep++ = sp->n_un.n_name?sp->n_un.n_name:"???";
+                       {
+                       /* XXX - remove trailers */
+                       char *cp = *(argnamep-1);
+                       while (*cp != '\0' && *cp != ':') cp++;
+                       if (*cp == ':') *cp = '\0';
+                       }
+               }
+               *nargp = nargs;
+               return TRUE;
+           }
+       }
+       return FALSE;
+}
+
 /*
  * Initialization routine for a.out files.
  */
 /*
  * Initialization routine for a.out files.
  */
-kdb_init()
+void
+kdb_init(void)
 {
 #if 0
        extern char     *esym;
        extern int      end;
 
        if (esym > (char *)&end) {
 {
 #if 0
        extern char     *esym;
        extern int      end;
 
        if (esym > (char *)&end) {
-           X_db_sym_init((int *)&end, esym, "mach");
+           X_db_sym_init((int *)&end, esym, "386bsd");
        }
 #endif
 
        }
 #endif
 
-       X_db_sym_init (db_symtab, 0, "mach");
+       X_db_sym_init (db_symtab, 0, "386bsd");
 }
 
 #if 0
 }
 
 #if 0