14887Schin/* Handle COFF SVR3 shared libraries for GDB, the GNU Debugger. 24887Schin Copyright 1993, 1994, 1998, 1999, 2000 Free Software Foundation, Inc. 34887Schin 410898Sroland.mainz@nrubsig.org This file is part of GDB. 54887Schin 64887Schin This program is free software; you can redistribute it and/or modify 78462SApril.Chin@Sun.COM it under the terms of the GNU General Public License as published by 84887Schin the Free Software Foundation; either version 2 of the License, or 94887Schin (at your option) any later version. 104887Schin 114887Schin This program is distributed in the hope that it will be useful, 124887Schin but WITHOUT ANY WARRANTY; without even the implied warranty of 134887Schin MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 144887Schin GNU General Public License for more details. 154887Schin 164887Schin You should have received a copy of the GNU General Public License 174887Schin along with this program; if not, write to the Free Software 184887Schin Foundation, Inc., 59 Temple Place - Suite 330, 194887Schin Boston, MA 02111-1307, USA. */ 204887Schin 214887Schin 224887Schin#include "defs.h" 234887Schin 244887Schin#include "frame.h" 254887Schin#include "bfd.h" 264887Schin#include "gdbcore.h" 274887Schin#include "symtab.h" 284887Schin#include "symfile.h" 294887Schin#include "objfiles.h" 304887Schin 314887Schin/* 324887Schin 334887Schin GLOBAL FUNCTION 344887Schin 354887Schin coff_solib_add -- add a shared library files to the symtab list. We 364887Schin examine the `.lib' section of the exec file and determine the names of 374887Schin the shared libraries. 384887Schin 394887Schin This function is responsible for discovering those names and 404887Schin addresses, and saving sufficient information about them to allow 414887Schin their symbols to be read at a later time. 424887Schin 434887Schin SYNOPSIS 444887Schin 454887Schin void coff_solib_add (char *arg_string, int from_tty, 464887Schin struct target_ops *target, int readsyms) 474887Schin 484887Schin DESCRIPTION 494887Schin 504887Schin */ 514887Schin 524887Schinvoid 534887Schincoff_solib_add (char *arg_string, int from_tty, struct target_ops *target, int readsyms) 544887Schin{ 554887Schin asection *libsect; 564887Schin 574887Schin if (!readsyms) 584887Schin return; 594887Schin 604887Schin libsect = bfd_get_section_by_name (exec_bfd, ".lib"); 614887Schin 624887Schin if (libsect) 634887Schin { 644887Schin int libsize; 654887Schin unsigned char *lib; 664887Schin struct libent 674887Schin { 684887Schin bfd_byte len[4]; 694887Schin bfd_byte nameoffset[4]; 704887Schin }; 714887Schin 724887Schin libsize = bfd_section_size (exec_bfd, libsect); 734887Schin 744887Schin lib = (unsigned char *) alloca (libsize); 754887Schin 764887Schin bfd_get_section_contents (exec_bfd, libsect, lib, 0, libsize); 774887Schin 784887Schin while (libsize > 0) 794887Schin { 804887Schin struct libent *ent; 814887Schin struct objfile *objfile; 824887Schin int len, nameoffset; 834887Schin char *filename; 844887Schin 854887Schin ent = (struct libent *) lib; 864887Schin 874887Schin len = bfd_get_32 (exec_bfd, ent->len); 884887Schin 894887Schin nameoffset = bfd_get_32 (exec_bfd, ent->nameoffset); 904887Schin 914887Schin if (len <= 0) 924887Schin break; 934887Schin 944887Schin filename = (char *) ent + nameoffset * 4; 954887Schin 964887Schin objfile = symbol_file_add (filename, from_tty, 974887Schin NULL, /* no offsets */ 984887Schin 0, /* not mainline */ 994887Schin OBJF_SHARED); /* flags */ 1004887Schin 1014887Schin libsize -= len * 4; 1024887Schin lib += len * 4; 1034887Schin } 1044887Schin 1054887Schin /* Getting new symbols may change our opinion about what is 1064887Schin frameless. */ 1074887Schin reinit_frame_cache (); 1084887Schin } 1094887Schin} 1104887Schin 1114887Schin/* 1124887Schin 1134887Schin GLOBAL FUNCTION 1144887Schin 1154887Schin coff_solib_create_inferior_hook -- shared library startup support 1164887Schin 1174887Schin SYNOPSIS 1184887Schin 1194887Schin void coff_solib_create_inferior_hook() 1204887Schin 1214887Schin DESCRIPTION 1224887Schin 1234887Schin When gdb starts up the inferior, the kernel maps in the shared 1244887Schin libraries. We get here with the target stopped at it's first 1254887Schin instruction, and the libraries already mapped. At this point, this 1264887Schin function gets called via expansion of the macro 1274887Schin SOLIB_CREATE_INFERIOR_HOOK. 1284887Schin */ 1294887Schin 1304887Schinvoid 1314887Schincoff_solib_create_inferior_hook (void) 1324887Schin{ 1334887Schin coff_solib_add ((char *) 0, 0, (struct target_ops *) 0, auto_solib_add); 1344887Schin} 1354887Schin