1 /* rddbg.c -- Read debugging information into a generic form.
2 Copyright (C) 1995 Free Software Foundation, Inc.
3 Written by Ian Lance Taylor <ian@cygnus.com>.
5 This file is part of GNU Binutils.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
22 /* This file reads debugging information into a generic form. This
23 file knows how to dig the debugging information out of an object
28 #include "libiberty.h"
32 static boolean read_section_stabs_debugging_info
33 PARAMS ((bfd *, PTR, boolean *));
35 /* Read debugging information from a BFD. Returns a generic debugging
39 read_debugging_info (abfd)
45 dhandle = debug_init ();
49 /* All we know about right now is stabs in sections. */
51 if (! read_section_stabs_debugging_info (abfd, dhandle, &found))
56 fprintf (stderr, "%s: no recognized debugging information\n",
57 bfd_get_filename (abfd));
64 /* Read stabs in sections debugging information from a BFD. */
67 read_section_stabs_debugging_info (abfd, dhandle, pfound)
75 const char *strsecname;
76 } names[] = { { ".stab", ".stabstr" } };
83 for (i = 0; i < sizeof names / sizeof names[0]; i++)
85 asection *sec, *strsec;
87 sec = bfd_get_section_by_name (abfd, names[i].secname);
88 strsec = bfd_get_section_by_name (abfd, names[i].strsecname);
89 if (sec != NULL && strsec != NULL)
91 bfd_size_type stabsize, strsize;
92 bfd_byte *stabs, *strings;
94 bfd_size_type stroff, next_stroff;
96 stabsize = bfd_section_size (abfd, sec);
97 stabs = (bfd_byte *) xmalloc (stabsize);
98 if (! bfd_get_section_contents (abfd, sec, stabs, 0, stabsize))
100 fprintf (stderr, "%s: %s: %s\n",
101 bfd_get_filename (abfd), names[i].secname,
102 bfd_errmsg (bfd_get_error ()));
106 strsize = bfd_section_size (abfd, strsec);
107 strings = (bfd_byte *) xmalloc (strsize);
108 if (! bfd_get_section_contents (abfd, strsec, strings, 0, strsize))
110 fprintf (stderr, "%s: %s: %s\n",
111 bfd_get_filename (abfd), names[i].strsecname,
112 bfd_errmsg (bfd_get_error ()));
118 shandle = start_stab (dhandle);
127 for (stab = stabs; stab < stabs + stabsize; stab += 12)
135 /* This code presumes 32 bit values. */
137 strx = bfd_get_32 (abfd, stab);
138 type = bfd_get_8 (abfd, stab + 4);
139 other = bfd_get_8 (abfd, stab + 5);
140 desc = bfd_get_16 (abfd, stab + 6);
141 value = bfd_get_32 (abfd, stab + 8);
145 /* Special type 0 stabs indicate the offset to the
146 next string table. */
147 stroff = next_stroff;
148 next_stroff += value;
155 s = (char *) strings + stroff + strx;
156 while (s[strlen (s) - 1] == '\\'
157 && stab + 12 < stabs + stabsize)
160 s[strlen (s) - 1] = '\0';
164 + bfd_get_32 (abfd, stab)),
165 (const char *) NULL);
171 if (! parse_stab (dhandle, shandle, type, desc, value, s))
174 /* Don't free f, since I think the stabs code
175 expects strings to hang around. This should be
176 straightened out. FIXME. */
182 /* Don't free strings, since I think the stabs code expects
183 the strings to hang around. This should be straightened
190 if (! finish_stab (dhandle, shandle))