This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

[RFA] mipsread.c: Replace alloca with xmalloc.


This fits in nicely with the recent alloca discussion.
Although I do like alloca, it shows the perils of using it. A few years ago
when I wrote this code, dynamic sections in executables were small,
so it seemed save to use alloca, but:

While debugging a large executable with many shared libraries on
Digital Unix, mipsread.c:read_alphacoff_dynamic_symtab reached the default
stack limit of 2 MB and GDB dumped core on me.

The patch below gets rid of the alloca calls in mipsread.c.

	* mipsread.c (read_alphacoff_dynamic_symtab):  Replace alloca calls
	with xmalloc calls and cleanups.

*** ./mipsread.c.orig	Sat Aug  5 11:37:28 2000
--- ./mipsread.c	Mon Nov  6 12:44:27 2000
***************
*** 243,248 ****
--- 243,249 ----
    int got_entry_size = 8;
    int dt_mips_local_gotno = -1;
    int dt_mips_gotsym = -1;
+   struct cleanup *cleanups;
  
  
    /* We currently only know how to handle alpha dynamic symbols.  */
***************
*** 262,271 ****
    str_secsize = bfd_get_section_size_before_reloc (si.str_sect);
    dyninfo_secsize = bfd_get_section_size_before_reloc (si.dyninfo_sect);
    got_secsize = bfd_get_section_size_before_reloc (si.got_sect);
!   sym_secptr = alloca (sym_secsize);
!   str_secptr = alloca (str_secsize);
!   dyninfo_secptr = alloca (dyninfo_secsize);
!   got_secptr = alloca (got_secsize);
  
    if (!bfd_get_section_contents (abfd, si.sym_sect, sym_secptr,
  				 (file_ptr) 0, sym_secsize))
--- 263,276 ----
    str_secsize = bfd_get_section_size_before_reloc (si.str_sect);
    dyninfo_secsize = bfd_get_section_size_before_reloc (si.dyninfo_sect);
    got_secsize = bfd_get_section_size_before_reloc (si.got_sect);
!   sym_secptr = xmalloc (sym_secsize);
!   cleanups = make_cleanup (free, sym_secptr);
!   str_secptr = xmalloc (str_secsize);
!   make_cleanup (free, str_secptr);
!   dyninfo_secptr = xmalloc (dyninfo_secsize);
!   make_cleanup (free, dyninfo_secptr);
!   got_secptr = xmalloc (got_secsize);
!   make_cleanup (free, got_secptr);
  
    if (!bfd_get_section_contents (abfd, si.sym_sect, sym_secptr,
  				 (file_ptr) 0, sym_secsize))
***************
*** 418,423 ****
--- 423,430 ----
  
        prim_record_minimal_symbol (name, sym_value, ms_type, objfile);
      }
+ 
+   do_cleanups (cleanups);
  }
  
  /* Initialization */

-- 
Peter Schauer			pes@regent.e-technik.tu-muenchen.de

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]