xref: /dflybsd-src/contrib/binutils-2.27/binutils/rddbg.c (revision e656dc90e3d65d744d534af2f5ea88cf8101ebcf)
1*a9fa9459Szrj /* rddbg.c -- Read debugging information into a generic form.
2*a9fa9459Szrj    Copyright (C) 1995-2016 Free Software Foundation, Inc.
3*a9fa9459Szrj    Written by Ian Lance Taylor <ian@cygnus.com>.
4*a9fa9459Szrj 
5*a9fa9459Szrj    This file is part of GNU Binutils.
6*a9fa9459Szrj 
7*a9fa9459Szrj    This program is free software; you can redistribute it and/or modify
8*a9fa9459Szrj    it under the terms of the GNU General Public License as published by
9*a9fa9459Szrj    the Free Software Foundation; either version 3 of the License, or
10*a9fa9459Szrj    (at your option) any later version.
11*a9fa9459Szrj 
12*a9fa9459Szrj    This program is distributed in the hope that it will be useful,
13*a9fa9459Szrj    but WITHOUT ANY WARRANTY; without even the implied warranty of
14*a9fa9459Szrj    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15*a9fa9459Szrj    GNU General Public License for more details.
16*a9fa9459Szrj 
17*a9fa9459Szrj    You should have received a copy of the GNU General Public License
18*a9fa9459Szrj    along with this program; if not, write to the Free Software
19*a9fa9459Szrj    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
20*a9fa9459Szrj    02110-1301, USA.  */
21*a9fa9459Szrj 
22*a9fa9459Szrj 
23*a9fa9459Szrj /* This file reads debugging information into a generic form.  This
24*a9fa9459Szrj    file knows how to dig the debugging information out of an object
25*a9fa9459Szrj    file.  */
26*a9fa9459Szrj 
27*a9fa9459Szrj #include "sysdep.h"
28*a9fa9459Szrj #include "bfd.h"
29*a9fa9459Szrj #include "libiberty.h"
30*a9fa9459Szrj #include "bucomm.h"
31*a9fa9459Szrj #include "debug.h"
32*a9fa9459Szrj #include "budbg.h"
33*a9fa9459Szrj 
34*a9fa9459Szrj static bfd_boolean read_section_stabs_debugging_info
35*a9fa9459Szrj   (bfd *, asymbol **, long, void *, bfd_boolean *);
36*a9fa9459Szrj static bfd_boolean read_symbol_stabs_debugging_info
37*a9fa9459Szrj   (bfd *, asymbol **, long, void *, bfd_boolean *);
38*a9fa9459Szrj static bfd_boolean read_ieee_debugging_info (bfd *, void *, bfd_boolean *);
39*a9fa9459Szrj static void save_stab (int, int, bfd_vma, const char *);
40*a9fa9459Szrj static void stab_context (void);
41*a9fa9459Szrj static void free_saved_stabs (void);
42*a9fa9459Szrj 
43*a9fa9459Szrj /* Read debugging information from a BFD.  Returns a generic debugging
44*a9fa9459Szrj    pointer.  */
45*a9fa9459Szrj 
46*a9fa9459Szrj void *
read_debugging_info(bfd * abfd,asymbol ** syms,long symcount,bfd_boolean no_messages)47*a9fa9459Szrj read_debugging_info (bfd *abfd, asymbol **syms, long symcount, bfd_boolean no_messages)
48*a9fa9459Szrj {
49*a9fa9459Szrj   void *dhandle;
50*a9fa9459Szrj   bfd_boolean found;
51*a9fa9459Szrj 
52*a9fa9459Szrj   dhandle = debug_init ();
53*a9fa9459Szrj   if (dhandle == NULL)
54*a9fa9459Szrj     return NULL;
55*a9fa9459Szrj 
56*a9fa9459Szrj   if (! read_section_stabs_debugging_info (abfd, syms, symcount, dhandle,
57*a9fa9459Szrj 					   &found))
58*a9fa9459Szrj     return NULL;
59*a9fa9459Szrj 
60*a9fa9459Szrj   if (bfd_get_flavour (abfd) == bfd_target_aout_flavour)
61*a9fa9459Szrj     {
62*a9fa9459Szrj       if (! read_symbol_stabs_debugging_info (abfd, syms, symcount, dhandle,
63*a9fa9459Szrj 					      &found))
64*a9fa9459Szrj 	return NULL;
65*a9fa9459Szrj     }
66*a9fa9459Szrj 
67*a9fa9459Szrj   if (bfd_get_flavour (abfd) == bfd_target_ieee_flavour)
68*a9fa9459Szrj     {
69*a9fa9459Szrj       if (! read_ieee_debugging_info (abfd, dhandle, &found))
70*a9fa9459Szrj 	return NULL;
71*a9fa9459Szrj     }
72*a9fa9459Szrj 
73*a9fa9459Szrj   /* Try reading the COFF symbols if we didn't find any stabs in COFF
74*a9fa9459Szrj      sections.  */
75*a9fa9459Szrj   if (! found
76*a9fa9459Szrj       && bfd_get_flavour (abfd) == bfd_target_coff_flavour
77*a9fa9459Szrj       && symcount > 0)
78*a9fa9459Szrj     {
79*a9fa9459Szrj       if (! parse_coff (abfd, syms, symcount, dhandle))
80*a9fa9459Szrj 	return NULL;
81*a9fa9459Szrj       found = TRUE;
82*a9fa9459Szrj     }
83*a9fa9459Szrj 
84*a9fa9459Szrj   if (! found)
85*a9fa9459Szrj     {
86*a9fa9459Szrj       if (! no_messages)
87*a9fa9459Szrj 	non_fatal (_("%s: no recognized debugging information"),
88*a9fa9459Szrj 		   bfd_get_filename (abfd));
89*a9fa9459Szrj       return NULL;
90*a9fa9459Szrj     }
91*a9fa9459Szrj 
92*a9fa9459Szrj   return dhandle;
93*a9fa9459Szrj }
94*a9fa9459Szrj 
95*a9fa9459Szrj /* Read stabs in sections debugging information from a BFD.  */
96*a9fa9459Szrj 
97*a9fa9459Szrj static bfd_boolean
read_section_stabs_debugging_info(bfd * abfd,asymbol ** syms,long symcount,void * dhandle,bfd_boolean * pfound)98*a9fa9459Szrj read_section_stabs_debugging_info (bfd *abfd, asymbol **syms, long symcount,
99*a9fa9459Szrj 				   void *dhandle, bfd_boolean *pfound)
100*a9fa9459Szrj {
101*a9fa9459Szrj   static struct
102*a9fa9459Szrj     {
103*a9fa9459Szrj       const char *secname;
104*a9fa9459Szrj       const char *strsecname;
105*a9fa9459Szrj     }
106*a9fa9459Szrj   names[] =
107*a9fa9459Szrj     {
108*a9fa9459Szrj       { ".stab", ".stabstr" },
109*a9fa9459Szrj       { "LC_SYMTAB.stabs", "LC_SYMTAB.stabstr" },
110*a9fa9459Szrj       { "$GDB_SYMBOLS$", "$GDB_STRINGS$" }
111*a9fa9459Szrj     };
112*a9fa9459Szrj   unsigned int i;
113*a9fa9459Szrj   void *shandle;
114*a9fa9459Szrj 
115*a9fa9459Szrj   *pfound = FALSE;
116*a9fa9459Szrj   shandle = NULL;
117*a9fa9459Szrj 
118*a9fa9459Szrj   for (i = 0; i < sizeof names / sizeof names[0]; i++)
119*a9fa9459Szrj     {
120*a9fa9459Szrj       asection *sec, *strsec;
121*a9fa9459Szrj 
122*a9fa9459Szrj       sec = bfd_get_section_by_name (abfd, names[i].secname);
123*a9fa9459Szrj       strsec = bfd_get_section_by_name (abfd, names[i].strsecname);
124*a9fa9459Szrj       if (sec != NULL && strsec != NULL)
125*a9fa9459Szrj 	{
126*a9fa9459Szrj 	  bfd_size_type stabsize, strsize;
127*a9fa9459Szrj 	  bfd_byte *stabs, *strings;
128*a9fa9459Szrj 	  bfd_byte *stab;
129*a9fa9459Szrj 	  bfd_size_type stroff, next_stroff;
130*a9fa9459Szrj 
131*a9fa9459Szrj 	  stabsize = bfd_section_size (abfd, sec);
132*a9fa9459Szrj 	  stabs = (bfd_byte *) xmalloc (stabsize);
133*a9fa9459Szrj 	  if (! bfd_get_section_contents (abfd, sec, stabs, 0, stabsize))
134*a9fa9459Szrj 	    {
135*a9fa9459Szrj 	      fprintf (stderr, "%s: %s: %s\n",
136*a9fa9459Szrj 		       bfd_get_filename (abfd), names[i].secname,
137*a9fa9459Szrj 		       bfd_errmsg (bfd_get_error ()));
138*a9fa9459Szrj 	      return FALSE;
139*a9fa9459Szrj 	    }
140*a9fa9459Szrj 
141*a9fa9459Szrj 	  strsize = bfd_section_size (abfd, strsec);
142*a9fa9459Szrj 	  strings = (bfd_byte *) xmalloc (strsize + 1);
143*a9fa9459Szrj 	  if (! bfd_get_section_contents (abfd, strsec, strings, 0, strsize))
144*a9fa9459Szrj 	    {
145*a9fa9459Szrj 	      fprintf (stderr, "%s: %s: %s\n",
146*a9fa9459Szrj 		       bfd_get_filename (abfd), names[i].strsecname,
147*a9fa9459Szrj 		       bfd_errmsg (bfd_get_error ()));
148*a9fa9459Szrj 	      return FALSE;
149*a9fa9459Szrj 	    }
150*a9fa9459Szrj 	  /* Zero terminate the strings table, just in case.  */
151*a9fa9459Szrj 	  strings [strsize] = 0;
152*a9fa9459Szrj 	  if (shandle == NULL)
153*a9fa9459Szrj 	    {
154*a9fa9459Szrj 	      shandle = start_stab (dhandle, abfd, TRUE, syms, symcount);
155*a9fa9459Szrj 	      if (shandle == NULL)
156*a9fa9459Szrj 		return FALSE;
157*a9fa9459Szrj 	    }
158*a9fa9459Szrj 
159*a9fa9459Szrj 	  *pfound = TRUE;
160*a9fa9459Szrj 
161*a9fa9459Szrj 	  stroff = 0;
162*a9fa9459Szrj 	  next_stroff = 0;
163*a9fa9459Szrj 	  /* PR 17512: file: 078-60391-0.001:0.1.  */
164*a9fa9459Szrj 	  for (stab = stabs; stab <= (stabs + stabsize) - 12; stab += 12)
165*a9fa9459Szrj 	    {
166*a9fa9459Szrj 	      unsigned int strx;
167*a9fa9459Szrj 	      int type;
168*a9fa9459Szrj 	      int other ATTRIBUTE_UNUSED;
169*a9fa9459Szrj 	      int desc;
170*a9fa9459Szrj 	      bfd_vma value;
171*a9fa9459Szrj 
172*a9fa9459Szrj 	      /* This code presumes 32 bit values.  */
173*a9fa9459Szrj 
174*a9fa9459Szrj 	      strx = bfd_get_32 (abfd, stab);
175*a9fa9459Szrj 	      type = bfd_get_8 (abfd, stab + 4);
176*a9fa9459Szrj 	      other = bfd_get_8 (abfd, stab + 5);
177*a9fa9459Szrj 	      desc = bfd_get_16 (abfd, stab + 6);
178*a9fa9459Szrj 	      value = bfd_get_32 (abfd, stab + 8);
179*a9fa9459Szrj 
180*a9fa9459Szrj 	      if (type == 0)
181*a9fa9459Szrj 		{
182*a9fa9459Szrj 		  /* Special type 0 stabs indicate the offset to the
183*a9fa9459Szrj 		     next string table.  */
184*a9fa9459Szrj 		  stroff = next_stroff;
185*a9fa9459Szrj 		  next_stroff += value;
186*a9fa9459Szrj 		}
187*a9fa9459Szrj 	      else
188*a9fa9459Szrj 		{
189*a9fa9459Szrj 		  size_t len;
190*a9fa9459Szrj 		  char *f, *s;
191*a9fa9459Szrj 
192*a9fa9459Szrj 		  if (stroff + strx >= strsize)
193*a9fa9459Szrj 		    {
194*a9fa9459Szrj 		      fprintf (stderr, _("%s: %s: stab entry %ld is corrupt, strx = 0x%x, type = %d\n"),
195*a9fa9459Szrj 			       bfd_get_filename (abfd), names[i].secname,
196*a9fa9459Szrj 			       (long) (stab - stabs) / 12, strx, type);
197*a9fa9459Szrj 		      continue;
198*a9fa9459Szrj 		    }
199*a9fa9459Szrj 
200*a9fa9459Szrj 		  s = (char *) strings + stroff + strx;
201*a9fa9459Szrj 		  f = NULL;
202*a9fa9459Szrj 
203*a9fa9459Szrj 		  /* PR 17512: file: 002-87578-0.001:0.1.
204*a9fa9459Szrj 		     It is possible to craft a file where, without the 'strlen (s) > 0',
205*a9fa9459Szrj 		     an attempt to read the byte before 'strings' would occur.  */
206*a9fa9459Szrj 		  while ((len = strlen (s)) > 0
207*a9fa9459Szrj 			 && s[len  - 1] == '\\'
208*a9fa9459Szrj 			 && stab + 12 < stabs + stabsize)
209*a9fa9459Szrj 		    {
210*a9fa9459Szrj 		      char *p;
211*a9fa9459Szrj 
212*a9fa9459Szrj 		      stab += 12;
213*a9fa9459Szrj 		      p = s + len - 1;
214*a9fa9459Szrj 		      *p = '\0';
215*a9fa9459Szrj 		      strx = stroff + bfd_get_32 (abfd, stab);
216*a9fa9459Szrj 		      if (strx >= strsize)
217*a9fa9459Szrj 			{
218*a9fa9459Szrj 			  fprintf (stderr, _("%s: %s: stab entry %ld is corrupt\n"),
219*a9fa9459Szrj 				   bfd_get_filename (abfd), names[i].secname,
220*a9fa9459Szrj 				   (long) (stab - stabs) / 12);
221*a9fa9459Szrj 			  break;
222*a9fa9459Szrj 			}
223*a9fa9459Szrj 		      else
224*a9fa9459Szrj 			s = concat (s, (char *) strings + strx,
225*a9fa9459Szrj 				    (const char *) NULL);
226*a9fa9459Szrj 
227*a9fa9459Szrj 		      /* We have to restore the backslash, because, if
228*a9fa9459Szrj 			 the linker is hashing stabs strings, we may
229*a9fa9459Szrj 			 see the same string more than once.  */
230*a9fa9459Szrj 		      *p = '\\';
231*a9fa9459Szrj 
232*a9fa9459Szrj 		      if (f != NULL)
233*a9fa9459Szrj 			free (f);
234*a9fa9459Szrj 		      f = s;
235*a9fa9459Szrj 		    }
236*a9fa9459Szrj 
237*a9fa9459Szrj 		  save_stab (type, desc, value, s);
238*a9fa9459Szrj 
239*a9fa9459Szrj 		  if (! parse_stab (dhandle, shandle, type, desc, value, s))
240*a9fa9459Szrj 		    {
241*a9fa9459Szrj 		      stab_context ();
242*a9fa9459Szrj 		      free_saved_stabs ();
243*a9fa9459Szrj 		      return FALSE;
244*a9fa9459Szrj 		    }
245*a9fa9459Szrj 
246*a9fa9459Szrj 		  /* Don't free f, since I think the stabs code
247*a9fa9459Szrj 		     expects strings to hang around.  This should be
248*a9fa9459Szrj 		     straightened out.  FIXME.  */
249*a9fa9459Szrj 		}
250*a9fa9459Szrj 	    }
251*a9fa9459Szrj 
252*a9fa9459Szrj 	  free_saved_stabs ();
253*a9fa9459Szrj 	  free (stabs);
254*a9fa9459Szrj 
255*a9fa9459Szrj 	  /* Don't free strings, since I think the stabs code expects
256*a9fa9459Szrj 	     the strings to hang around.  This should be straightened
257*a9fa9459Szrj 	     out.  FIXME.  */
258*a9fa9459Szrj 	}
259*a9fa9459Szrj     }
260*a9fa9459Szrj 
261*a9fa9459Szrj   if (shandle != NULL)
262*a9fa9459Szrj     {
263*a9fa9459Szrj       if (! finish_stab (dhandle, shandle))
264*a9fa9459Szrj 	return FALSE;
265*a9fa9459Szrj     }
266*a9fa9459Szrj 
267*a9fa9459Szrj   return TRUE;
268*a9fa9459Szrj }
269*a9fa9459Szrj 
270*a9fa9459Szrj /* Read stabs in the symbol table.  */
271*a9fa9459Szrj 
272*a9fa9459Szrj static bfd_boolean
read_symbol_stabs_debugging_info(bfd * abfd,asymbol ** syms,long symcount,void * dhandle,bfd_boolean * pfound)273*a9fa9459Szrj read_symbol_stabs_debugging_info (bfd *abfd, asymbol **syms, long symcount,
274*a9fa9459Szrj 				  void *dhandle, bfd_boolean *pfound)
275*a9fa9459Szrj {
276*a9fa9459Szrj   void *shandle;
277*a9fa9459Szrj   asymbol **ps, **symend;
278*a9fa9459Szrj 
279*a9fa9459Szrj   shandle = NULL;
280*a9fa9459Szrj   symend = syms + symcount;
281*a9fa9459Szrj   for (ps = syms; ps < symend; ps++)
282*a9fa9459Szrj     {
283*a9fa9459Szrj       symbol_info i;
284*a9fa9459Szrj 
285*a9fa9459Szrj       bfd_get_symbol_info (abfd, *ps, &i);
286*a9fa9459Szrj 
287*a9fa9459Szrj       if (i.type == '-')
288*a9fa9459Szrj 	{
289*a9fa9459Szrj 	  const char *s;
290*a9fa9459Szrj 	  char *f;
291*a9fa9459Szrj 
292*a9fa9459Szrj 	  if (shandle == NULL)
293*a9fa9459Szrj 	    {
294*a9fa9459Szrj 	      shandle = start_stab (dhandle, abfd, FALSE, syms, symcount);
295*a9fa9459Szrj 	      if (shandle == NULL)
296*a9fa9459Szrj 		return FALSE;
297*a9fa9459Szrj 	    }
298*a9fa9459Szrj 
299*a9fa9459Szrj 	  *pfound = TRUE;
300*a9fa9459Szrj 
301*a9fa9459Szrj 	  s = i.name;
302*a9fa9459Szrj 	  f = NULL;
303*a9fa9459Szrj 	  while (s[strlen (s) - 1] == '\\'
304*a9fa9459Szrj 		 && ps + 1 < symend)
305*a9fa9459Szrj 	    {
306*a9fa9459Szrj 	      char *sc, *n;
307*a9fa9459Szrj 
308*a9fa9459Szrj 	      ++ps;
309*a9fa9459Szrj 	      sc = xstrdup (s);
310*a9fa9459Szrj 	      sc[strlen (sc) - 1] = '\0';
311*a9fa9459Szrj 	      n = concat (sc, bfd_asymbol_name (*ps), (const char *) NULL);
312*a9fa9459Szrj 	      free (sc);
313*a9fa9459Szrj 	      if (f != NULL)
314*a9fa9459Szrj 		free (f);
315*a9fa9459Szrj 	      f = n;
316*a9fa9459Szrj 	      s = n;
317*a9fa9459Szrj 	    }
318*a9fa9459Szrj 
319*a9fa9459Szrj 	  save_stab (i.stab_type, i.stab_desc, i.value, s);
320*a9fa9459Szrj 
321*a9fa9459Szrj 	  if (! parse_stab (dhandle, shandle, i.stab_type, i.stab_desc,
322*a9fa9459Szrj 			    i.value, s))
323*a9fa9459Szrj 	    {
324*a9fa9459Szrj 	      stab_context ();
325*a9fa9459Szrj 	      free_saved_stabs ();
326*a9fa9459Szrj 	      return FALSE;
327*a9fa9459Szrj 	    }
328*a9fa9459Szrj 
329*a9fa9459Szrj 	  /* Don't free f, since I think the stabs code expects
330*a9fa9459Szrj 	     strings to hang around.  This should be straightened out.
331*a9fa9459Szrj 	     FIXME.  */
332*a9fa9459Szrj 	}
333*a9fa9459Szrj     }
334*a9fa9459Szrj 
335*a9fa9459Szrj   free_saved_stabs ();
336*a9fa9459Szrj 
337*a9fa9459Szrj   if (shandle != NULL)
338*a9fa9459Szrj     {
339*a9fa9459Szrj       if (! finish_stab (dhandle, shandle))
340*a9fa9459Szrj 	return FALSE;
341*a9fa9459Szrj     }
342*a9fa9459Szrj 
343*a9fa9459Szrj   return TRUE;
344*a9fa9459Szrj }
345*a9fa9459Szrj 
346*a9fa9459Szrj /* Read IEEE debugging information.  */
347*a9fa9459Szrj 
348*a9fa9459Szrj static bfd_boolean
read_ieee_debugging_info(bfd * abfd,void * dhandle,bfd_boolean * pfound)349*a9fa9459Szrj read_ieee_debugging_info (bfd *abfd, void *dhandle, bfd_boolean *pfound)
350*a9fa9459Szrj {
351*a9fa9459Szrj   asection *dsec;
352*a9fa9459Szrj   bfd_size_type size;
353*a9fa9459Szrj   bfd_byte *contents;
354*a9fa9459Szrj 
355*a9fa9459Szrj   /* The BFD backend puts the debugging information into a section
356*a9fa9459Szrj      named .debug.  */
357*a9fa9459Szrj 
358*a9fa9459Szrj   dsec = bfd_get_section_by_name (abfd, ".debug");
359*a9fa9459Szrj   if (dsec == NULL)
360*a9fa9459Szrj     return TRUE;
361*a9fa9459Szrj 
362*a9fa9459Szrj   size = bfd_section_size (abfd, dsec);
363*a9fa9459Szrj   contents = (bfd_byte *) xmalloc (size);
364*a9fa9459Szrj   if (! bfd_get_section_contents (abfd, dsec, contents, 0, size))
365*a9fa9459Szrj     return FALSE;
366*a9fa9459Szrj 
367*a9fa9459Szrj   if (! parse_ieee (dhandle, abfd, contents, size))
368*a9fa9459Szrj     return FALSE;
369*a9fa9459Szrj 
370*a9fa9459Szrj   free (contents);
371*a9fa9459Szrj 
372*a9fa9459Szrj   *pfound = TRUE;
373*a9fa9459Szrj 
374*a9fa9459Szrj   return TRUE;
375*a9fa9459Szrj }
376*a9fa9459Szrj 
377*a9fa9459Szrj /* Record stabs strings, so that we can give some context for errors.  */
378*a9fa9459Szrj 
379*a9fa9459Szrj #define SAVE_STABS_COUNT (16)
380*a9fa9459Szrj 
381*a9fa9459Szrj struct saved_stab
382*a9fa9459Szrj {
383*a9fa9459Szrj   int type;
384*a9fa9459Szrj   int desc;
385*a9fa9459Szrj   bfd_vma value;
386*a9fa9459Szrj   char *string;
387*a9fa9459Szrj };
388*a9fa9459Szrj 
389*a9fa9459Szrj static struct saved_stab saved_stabs[SAVE_STABS_COUNT];
390*a9fa9459Szrj static int saved_stabs_index;
391*a9fa9459Szrj 
392*a9fa9459Szrj /* Save a stabs string.  */
393*a9fa9459Szrj 
394*a9fa9459Szrj static void
save_stab(int type,int desc,bfd_vma value,const char * string)395*a9fa9459Szrj save_stab (int type, int desc, bfd_vma value, const char *string)
396*a9fa9459Szrj {
397*a9fa9459Szrj   if (saved_stabs[saved_stabs_index].string != NULL)
398*a9fa9459Szrj     free (saved_stabs[saved_stabs_index].string);
399*a9fa9459Szrj   saved_stabs[saved_stabs_index].type = type;
400*a9fa9459Szrj   saved_stabs[saved_stabs_index].desc = desc;
401*a9fa9459Szrj   saved_stabs[saved_stabs_index].value = value;
402*a9fa9459Szrj   saved_stabs[saved_stabs_index].string = xstrdup (string);
403*a9fa9459Szrj   saved_stabs_index = (saved_stabs_index + 1) % SAVE_STABS_COUNT;
404*a9fa9459Szrj }
405*a9fa9459Szrj 
406*a9fa9459Szrj /* Provide context for an error.  */
407*a9fa9459Szrj 
408*a9fa9459Szrj static void
stab_context(void)409*a9fa9459Szrj stab_context (void)
410*a9fa9459Szrj {
411*a9fa9459Szrj   int i;
412*a9fa9459Szrj 
413*a9fa9459Szrj   fprintf (stderr, _("Last stabs entries before error:\n"));
414*a9fa9459Szrj   fprintf (stderr, "n_type n_desc n_value  string\n");
415*a9fa9459Szrj 
416*a9fa9459Szrj   i = saved_stabs_index;
417*a9fa9459Szrj   do
418*a9fa9459Szrj     {
419*a9fa9459Szrj       struct saved_stab *stabp;
420*a9fa9459Szrj 
421*a9fa9459Szrj       stabp = saved_stabs + i;
422*a9fa9459Szrj       if (stabp->string != NULL)
423*a9fa9459Szrj 	{
424*a9fa9459Szrj 	  const char *s;
425*a9fa9459Szrj 
426*a9fa9459Szrj 	  s = bfd_get_stab_name (stabp->type);
427*a9fa9459Szrj 	  if (s != NULL)
428*a9fa9459Szrj 	    fprintf (stderr, "%-6s", s);
429*a9fa9459Szrj 	  else if (stabp->type == 0)
430*a9fa9459Szrj 	    fprintf (stderr, "HdrSym");
431*a9fa9459Szrj 	  else
432*a9fa9459Szrj 	    fprintf (stderr, "%-6d", stabp->type);
433*a9fa9459Szrj 	  fprintf (stderr, " %-6d ", stabp->desc);
434*a9fa9459Szrj 	  fprintf_vma (stderr, stabp->value);
435*a9fa9459Szrj 	  if (stabp->type != 0)
436*a9fa9459Szrj 	    fprintf (stderr, " %s", stabp->string);
437*a9fa9459Szrj 	  fprintf (stderr, "\n");
438*a9fa9459Szrj 	}
439*a9fa9459Szrj       i = (i + 1) % SAVE_STABS_COUNT;
440*a9fa9459Szrj     }
441*a9fa9459Szrj   while (i != saved_stabs_index);
442*a9fa9459Szrj }
443*a9fa9459Szrj 
444*a9fa9459Szrj /* Free the saved stab strings.  */
445*a9fa9459Szrj 
446*a9fa9459Szrj static void
free_saved_stabs(void)447*a9fa9459Szrj free_saved_stabs (void)
448*a9fa9459Szrj {
449*a9fa9459Szrj   int i;
450*a9fa9459Szrj 
451*a9fa9459Szrj   for (i = 0; i < SAVE_STABS_COUNT; i++)
452*a9fa9459Szrj     {
453*a9fa9459Szrj       if (saved_stabs[i].string != NULL)
454*a9fa9459Szrj 	{
455*a9fa9459Szrj 	  free (saved_stabs[i].string);
456*a9fa9459Szrj 	  saved_stabs[i].string = NULL;
457*a9fa9459Szrj 	}
458*a9fa9459Szrj     }
459*a9fa9459Szrj 
460*a9fa9459Szrj   saved_stabs_index = 0;
461*a9fa9459Szrj }
462