1130812Smarcel/* Handle COFF SVR3 shared libraries for GDB, the GNU Debugger. 2130812Smarcel Copyright 1993, 1994, 1998, 1999, 2000 Free Software Foundation, Inc. 3130812Smarcel 4130812Smarcel This file is part of GDB. 5130812Smarcel 6130812Smarcel This program is free software; you can redistribute it and/or modify 7130812Smarcel it under the terms of the GNU General Public License as published by 8130812Smarcel the Free Software Foundation; either version 2 of the License, or 9130812Smarcel (at your option) any later version. 10130812Smarcel 11130812Smarcel This program is distributed in the hope that it will be useful, 12130812Smarcel but WITHOUT ANY WARRANTY; without even the implied warranty of 13130812Smarcel MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14130812Smarcel GNU General Public License for more details. 15130812Smarcel 16130812Smarcel You should have received a copy of the GNU General Public License 17130812Smarcel along with this program; if not, write to the Free Software 18130812Smarcel Foundation, Inc., 59 Temple Place - Suite 330, 19130812Smarcel Boston, MA 02111-1307, USA. */ 20130812Smarcel 21130812Smarcel 22130812Smarcel#include "defs.h" 23130812Smarcel 24130812Smarcel#include "frame.h" 25130812Smarcel#include "bfd.h" 26130812Smarcel#include "gdbcore.h" 27130812Smarcel#include "symtab.h" 28130812Smarcel#include "symfile.h" 29130812Smarcel#include "objfiles.h" 30130812Smarcel 31130812Smarcel/* 32130812Smarcel 33130812Smarcel GLOBAL FUNCTION 34130812Smarcel 35130812Smarcel coff_solib_add -- add a shared library files to the symtab list. We 36130812Smarcel examine the `.lib' section of the exec file and determine the names of 37130812Smarcel the shared libraries. 38130812Smarcel 39130812Smarcel This function is responsible for discovering those names and 40130812Smarcel addresses, and saving sufficient information about them to allow 41130812Smarcel their symbols to be read at a later time. 42130812Smarcel 43130812Smarcel SYNOPSIS 44130812Smarcel 45130812Smarcel void coff_solib_add (char *arg_string, int from_tty, 46130812Smarcel struct target_ops *target, int readsyms) 47130812Smarcel 48130812Smarcel DESCRIPTION 49130812Smarcel 50130812Smarcel */ 51130812Smarcel 52130812Smarcelvoid 53130812Smarcelcoff_solib_add (char *arg_string, int from_tty, struct target_ops *target, int readsyms) 54130812Smarcel{ 55130812Smarcel asection *libsect; 56130812Smarcel 57130812Smarcel if (!readsyms) 58130812Smarcel return; 59130812Smarcel 60130812Smarcel libsect = bfd_get_section_by_name (exec_bfd, ".lib"); 61130812Smarcel 62130812Smarcel if (libsect) 63130812Smarcel { 64130812Smarcel int libsize; 65130812Smarcel unsigned char *lib; 66130812Smarcel struct libent 67130812Smarcel { 68130812Smarcel bfd_byte len[4]; 69130812Smarcel bfd_byte nameoffset[4]; 70130812Smarcel }; 71130812Smarcel 72130812Smarcel libsize = bfd_section_size (exec_bfd, libsect); 73130812Smarcel 74130812Smarcel lib = (unsigned char *) alloca (libsize); 75130812Smarcel 76130812Smarcel bfd_get_section_contents (exec_bfd, libsect, lib, 0, libsize); 77130812Smarcel 78130812Smarcel while (libsize > 0) 79130812Smarcel { 80130812Smarcel struct libent *ent; 81130812Smarcel struct objfile *objfile; 82130812Smarcel int len, nameoffset; 83130812Smarcel char *filename; 84130812Smarcel 85130812Smarcel ent = (struct libent *) lib; 86130812Smarcel 87130812Smarcel len = bfd_get_32 (exec_bfd, ent->len); 88130812Smarcel 89130812Smarcel nameoffset = bfd_get_32 (exec_bfd, ent->nameoffset); 90130812Smarcel 91130812Smarcel if (len <= 0) 92130812Smarcel break; 93130812Smarcel 94130812Smarcel filename = (char *) ent + nameoffset * 4; 95130812Smarcel 96130812Smarcel objfile = symbol_file_add (filename, from_tty, 97130812Smarcel NULL, /* no offsets */ 98130812Smarcel 0, /* not mainline */ 99130812Smarcel OBJF_SHARED); /* flags */ 100130812Smarcel 101130812Smarcel libsize -= len * 4; 102130812Smarcel lib += len * 4; 103130812Smarcel } 104130812Smarcel 105130812Smarcel /* Getting new symbols may change our opinion about what is 106130812Smarcel frameless. */ 107130812Smarcel reinit_frame_cache (); 108130812Smarcel } 109130812Smarcel} 110130812Smarcel 111130812Smarcel/* 112130812Smarcel 113130812Smarcel GLOBAL FUNCTION 114130812Smarcel 115130812Smarcel coff_solib_create_inferior_hook -- shared library startup support 116130812Smarcel 117130812Smarcel SYNOPSIS 118130812Smarcel 119130812Smarcel void coff_solib_create_inferior_hook() 120130812Smarcel 121130812Smarcel DESCRIPTION 122130812Smarcel 123130812Smarcel When gdb starts up the inferior, the kernel maps in the shared 124130812Smarcel libraries. We get here with the target stopped at it's first 125130812Smarcel instruction, and the libraries already mapped. At this point, this 126130812Smarcel function gets called via expansion of the macro 127130812Smarcel SOLIB_CREATE_INFERIOR_HOOK. 128130812Smarcel */ 129130812Smarcel 130130812Smarcelvoid 131130812Smarcelcoff_solib_create_inferior_hook (void) 132130812Smarcel{ 133130812Smarcel coff_solib_add ((char *) 0, 0, (struct target_ops *) 0, auto_solib_add); 134130812Smarcel} 135