#include <bfd.h>#include "bucomm.h"#include <libiberty.h>#include "debug.h"#include "budbg.h"Include dependency graph for rddbg.c:

Go to the source code of this file.
Classes | |
| struct | saved_stab |
Defines | |
| #define | SAVE_STABS_COUNT (16) |
Functions | |
| static boolean read_section_stabs_debugging_info | PARAMS ((bfd *, asymbol **, long, PTR, boolean *)) |
| static boolean read_ieee_debugging_info | PARAMS ((bfd *, PTR, boolean *)) |
| static void save_stab | PARAMS ((int, int, bfd_vma, const char *)) |
| static void stab_context | PARAMS ((void)) |
| PTR | read_debugging_info (bfd *abfd, asymbol **syms, long symcount) |
| static boolean | read_section_stabs_debugging_info (bfd *abfd, asymbol **syms, long symcount, PTR dhandle, boolean *pfound) |
| static boolean | read_symbol_stabs_debugging_info (bfd *abfd, asymbol **syms, long symcount, PTR dhandle, boolean *pfound) |
| static boolean | read_ieee_debugging_info (bfd *abfd, PTR dhandle, boolean *pfound) |
| static void | save_stab (int type, int desc, bfd_vma value, const char *string) |
| static void | stab_context () |
| static void | free_saved_stabs () |
Variables | |
| static struct saved_stab | saved_stabs [SAVE_STABS_COUNT] |
| static int | saved_stabs_index |
| #define SAVE_STABS_COUNT (16) |
Definition at line 376 of file rddbg.c.
Referenced by free_saved_stabs(), save_stab(), and stab_context().
| static void free_saved_stabs | ( | ) | [static] |
Definition at line 448 of file rddbg.c.
References free, NULL, SAVE_STABS_COUNT, saved_stabs, and saved_stab::string.
Referenced by read_section_stabs_debugging_info(), and read_symbol_stabs_debugging_info().
00449 { 00450 int i; 00451 00452 for (i = 0; i < SAVE_STABS_COUNT; i++) 00453 { 00454 if (saved_stabs[i].string != NULL) 00455 { 00456 free (saved_stabs[i].string); 00457 saved_stabs[i].string = NULL; 00458 } 00459 } 00460 00461 saved_stabs_index = 0; 00462 }
Here is the caller graph for this function:

| static void stab_context PARAMS | ( | (void) | ) | [static] |
| static void save_stab PARAMS | ( | (int, int, bfd_vma, const char *) | ) | [static] |
| static boolean read_ieee_debugging_info PARAMS | ( | (bfd *, PTR, boolean *) | ) | [static] |
| static boolean read_section_stabs_debugging_info PARAMS | ( | (bfd *, asymbol **, long, PTR, boolean *) | ) | [static] |
| PTR read_debugging_info | ( | bfd * | abfd, | |
| asymbol ** | syms, | |||
| long | symcount | |||
| ) |
Definition at line 45 of file rddbg.c.
References debug_init(), dhandle, NULL, read_ieee_debugging_info(), read_section_stabs_debugging_info(), and read_symbol_stabs_debugging_info().
Referenced by pstack_install_segv_action().
00049 { 00050 PTR dhandle; 00051 boolean found; 00052 00053 dhandle = debug_init (); 00054 if (dhandle == NULL) 00055 return NULL; 00056 00057 if (! read_section_stabs_debugging_info (abfd, syms, symcount, dhandle, 00058 &found)) 00059 return NULL; 00060 00061 if (bfd_get_flavour (abfd) == bfd_target_aout_flavour) 00062 { 00063 if (! read_symbol_stabs_debugging_info (abfd, syms, symcount, dhandle, 00064 &found)) 00065 return NULL; 00066 } 00067 00068 if (bfd_get_flavour (abfd) == bfd_target_ieee_flavour) 00069 { 00070 if (! read_ieee_debugging_info (abfd, dhandle, &found)) 00071 return NULL; 00072 } 00073 00074 /* Try reading the COFF symbols if we didn't find any stabs in COFF 00075 sections. */ 00076 if (! found 00077 && bfd_get_flavour (abfd) == bfd_target_coff_flavour 00078 && symcount > 0) 00079 { 00080 #if 0 00081 /* 00082 * JZ: Do we need coff? 00083 */ 00084 if (! parse_coff (abfd, syms, symcount, dhandle)) 00085 #else 00086 fprintf (stderr, "%s: COFF support temporarily disabled\n", 00087 bfd_get_filename (abfd)); 00088 return NULL; 00089 #endif 00090 return NULL; 00091 found = true; 00092 } 00093 00094 if (! found) 00095 { 00096 fprintf (stderr, "%s: no recognized debugging information\n", 00097 bfd_get_filename (abfd)); 00098 return NULL; 00099 } 00100 00101 return dhandle; 00102 }
Here is the call graph for this function:

Here is the caller graph for this function:

| static boolean read_ieee_debugging_info | ( | bfd * | abfd, | |
| PTR | dhandle, | |||
| boolean * | pfound | |||
| ) | [static] |
Definition at line 343 of file rddbg.c.
References free, NULL, parse_ieee(), and xmalloc().
Referenced by read_debugging_info().
00347 { 00348 asection *dsec; 00349 bfd_size_type size; 00350 bfd_byte *contents; 00351 00352 /* The BFD backend puts the debugging information into a section 00353 named .debug. */ 00354 00355 dsec = bfd_get_section_by_name (abfd, ".debug"); 00356 if (dsec == NULL) 00357 return true; 00358 00359 size = bfd_section_size (abfd, dsec); 00360 contents = (bfd_byte *) xmalloc (size); 00361 if (! bfd_get_section_contents (abfd, dsec, contents, 0, size)) 00362 return false; 00363 00364 if (! parse_ieee (dhandle, abfd, contents, size)) 00365 return false; 00366 00367 free (contents); 00368 00369 *pfound = true; 00370 00371 return true; 00372 }
Here is the call graph for this function:

Here is the caller graph for this function:

| static boolean read_section_stabs_debugging_info | ( | bfd * | abfd, | |
| asymbol ** | syms, | |||
| long | symcount, | |||
| PTR | dhandle, | |||
| boolean * | pfound | |||
| ) | [static] |
Definition at line 107 of file rddbg.c.
References f, finish_stab(), free, free_saved_stabs(), NULL, p, parse_stab(), save_stab(), sec, stab_context(), start_stab(), strlen(), value, and xmalloc().
Referenced by read_debugging_info().
00113 { 00114 static struct 00115 { 00116 const char *secname; 00117 const char *strsecname; 00118 } names[] = { { ".stab", ".stabstr" } }; 00119 unsigned int i; 00120 PTR shandle; 00121 00122 *pfound = false; 00123 shandle = NULL; 00124 00125 for (i = 0; i < sizeof names / sizeof names[0]; i++) 00126 { 00127 asection *sec, *strsec; 00128 00129 sec = bfd_get_section_by_name (abfd, names[i].secname); 00130 strsec = bfd_get_section_by_name (abfd, names[i].strsecname); 00131 if (sec != NULL && strsec != NULL) 00132 { 00133 bfd_size_type stabsize, strsize; 00134 bfd_byte *stabs, *strings; 00135 bfd_byte *stab; 00136 bfd_size_type stroff, next_stroff; 00137 00138 stabsize = bfd_section_size (abfd, sec); 00139 stabs = (bfd_byte *) xmalloc (stabsize); 00140 if (! bfd_get_section_contents (abfd, sec, stabs, 0, stabsize)) 00141 { 00142 fprintf (stderr, "%s: %s: %s\n", 00143 bfd_get_filename (abfd), names[i].secname, 00144 bfd_errmsg (bfd_get_error ())); 00145 return false; 00146 } 00147 00148 strsize = bfd_section_size (abfd, strsec); 00149 strings = (bfd_byte *) xmalloc (strsize); 00150 if (! bfd_get_section_contents (abfd, strsec, strings, 0, strsize)) 00151 { 00152 fprintf (stderr, "%s: %s: %s\n", 00153 bfd_get_filename (abfd), names[i].strsecname, 00154 bfd_errmsg (bfd_get_error ())); 00155 return false; 00156 } 00157 00158 if (shandle == NULL) 00159 { 00160 shandle = start_stab (dhandle, abfd, true, syms, symcount); 00161 if (shandle == NULL) 00162 return false; 00163 } 00164 00165 *pfound = true; 00166 00167 stroff = 0; 00168 next_stroff = 0; 00169 for (stab = stabs; stab < stabs + stabsize; stab += 12) 00170 { 00171 bfd_size_type strx; 00172 int type; 00173 int other; 00174 int desc; 00175 bfd_vma value; 00176 00177 /* This code presumes 32 bit values. */ 00178 00179 strx = bfd_get_32 (abfd, stab); 00180 type = bfd_get_8 (abfd, stab + 4); 00181 other = bfd_get_8 (abfd, stab + 5); 00182 desc = bfd_get_16 (abfd, stab + 6); 00183 value = bfd_get_32 (abfd, stab + 8); 00184 00185 if (type == 0) 00186 { 00187 /* Special type 0 stabs indicate the offset to the 00188 next string table. */ 00189 stroff = next_stroff; 00190 next_stroff += value; 00191 } 00192 else 00193 { 00194 char *f, *s; 00195 00196 f = NULL; 00197 s = (char *) strings + stroff + strx; 00198 while (s[strlen (s) - 1] == '\\' 00199 && stab + 12 < stabs + stabsize) 00200 { 00201 char *p; 00202 00203 stab += 12; 00204 p = s + strlen (s) - 1; 00205 *p = '\0'; 00206 s = concat (s, 00207 ((char *) strings 00208 + stroff 00209 + bfd_get_32 (abfd, stab)), 00210 (const char *) NULL); 00211 00212 /* We have to restore the backslash, because, if 00213 the linker is hashing stabs strings, we may 00214 see the same string more than once. */ 00215 *p = '\\'; 00216 00217 if (f != NULL) 00218 free (f); 00219 f = s; 00220 } 00221 00222 save_stab (type, desc, value, s); 00223 00224 if (! parse_stab (dhandle, shandle, type, desc, value, s)) 00225 { 00226 #if 0 00227 /* 00228 * JZ: skip the junk. 00229 */ 00230 stab_context (); 00231 free_saved_stabs (); 00232 return false; 00233 #endif 00234 } 00235 00236 /* Don't free f, since I think the stabs code 00237 expects strings to hang around. This should be 00238 straightened out. FIXME. */ 00239 } 00240 } 00241 00242 free_saved_stabs (); 00243 free (stabs); 00244 00245 /* Don't free strings, since I think the stabs code expects 00246 the strings to hang around. This should be straightened 00247 out. FIXME. */ 00248 } 00249 } 00250 00251 if (shandle != NULL) 00252 { 00253 if (! finish_stab (dhandle, shandle)) 00254 return false; 00255 } 00256 00257 return true; 00258 }
Here is the call graph for this function:

Here is the caller graph for this function:

| static boolean read_symbol_stabs_debugging_info | ( | bfd * | abfd, | |
| asymbol ** | syms, | |||
| long | symcount, | |||
| PTR | dhandle, | |||
| boolean * | pfound | |||
| ) | [static] |
Definition at line 263 of file rddbg.c.
References f, finish_stab(), free, free_saved_stabs(), n, NULL, parse_stab(), save_stab(), stab_context(), start_stab(), and strlen().
Referenced by read_debugging_info().
00269 { 00270 PTR shandle; 00271 asymbol **ps, **symend; 00272 00273 shandle = NULL; 00274 symend = syms + symcount; 00275 for (ps = syms; ps < symend; ps++) 00276 { 00277 symbol_info i; 00278 00279 bfd_get_symbol_info (abfd, *ps, &i); 00280 00281 if (i.type == '-') 00282 { 00283 const char *s; 00284 char *f; 00285 00286 if (shandle == NULL) 00287 { 00288 shandle = start_stab (dhandle, abfd, false, syms, symcount); 00289 if (shandle == NULL) 00290 return false; 00291 } 00292 00293 *pfound = true; 00294 00295 s = i.name; 00296 f = NULL; 00297 while (s[strlen (s) - 1] == '\\' 00298 && ps + 1 < symend) 00299 { 00300 char *sc, *n; 00301 00302 ++ps; 00303 sc = xstrdup (s); 00304 sc[strlen (sc) - 1] = '\0'; 00305 n = concat (sc, bfd_asymbol_name (*ps), (const char *) NULL); 00306 free (sc); 00307 if (f != NULL) 00308 free (f); 00309 f = n; 00310 s = n; 00311 } 00312 00313 save_stab (i.stab_type, i.stab_desc, i.value, s); 00314 00315 if (! parse_stab (dhandle, shandle, i.stab_type, i.stab_desc, 00316 i.value, s)) 00317 { 00318 stab_context (); 00319 free_saved_stabs (); 00320 return false; 00321 } 00322 00323 /* Don't free f, since I think the stabs code expects 00324 strings to hang around. This should be straightened out. 00325 FIXME. */ 00326 } 00327 } 00328 00329 free_saved_stabs (); 00330 00331 if (shandle != NULL) 00332 { 00333 if (! finish_stab (dhandle, shandle)) 00334 return false; 00335 } 00336 00337 return true; 00338 }
Here is the call graph for this function:

Here is the caller graph for this function:

| static void save_stab | ( | int | type, | |
| int | desc, | |||
| bfd_vma | value, | |||
| const char * | string | |||
| ) | [static] |
Definition at line 392 of file rddbg.c.
References saved_stab::desc, free, NULL, SAVE_STABS_COUNT, saved_stabs, saved_stab::string, saved_stab::type, and saved_stab::value.
Referenced by read_section_stabs_debugging_info(), and read_symbol_stabs_debugging_info().
00397 { 00398 if (saved_stabs[saved_stabs_index].string != NULL) 00399 free (saved_stabs[saved_stabs_index].string); 00400 saved_stabs[saved_stabs_index].type = type; 00401 saved_stabs[saved_stabs_index].desc = desc; 00402 saved_stabs[saved_stabs_index].value = value; 00403 saved_stabs[saved_stabs_index].string = xstrdup (string); 00404 saved_stabs_index = (saved_stabs_index + 1) % SAVE_STABS_COUNT; 00405 }
Here is the caller graph for this function:

| static void stab_context | ( | ) | [static] |
Definition at line 410 of file rddbg.c.
References saved_stab::desc, NULL, SAVE_STABS_COUNT, saved_stabs, saved_stab::string, saved_stab::type, and saved_stab::value.
Referenced by read_section_stabs_debugging_info(), and read_symbol_stabs_debugging_info().
00411 { 00412 int i; 00413 00414 fprintf (stderr, "Last stabs entries before error:\n"); 00415 fprintf (stderr, "n_type n_desc n_value string\n"); 00416 00417 i = saved_stabs_index; 00418 do 00419 { 00420 struct saved_stab *stabp; 00421 00422 stabp = saved_stabs + i; 00423 if (stabp->string != NULL) 00424 { 00425 const char *s; 00426 00427 s = bfd_get_stab_name (stabp->type); 00428 if (s != NULL) 00429 fprintf (stderr, "%-6s", s); 00430 else if (stabp->type == 0) 00431 fprintf (stderr, "HdrSym"); 00432 else 00433 fprintf (stderr, "%-6d", stabp->type); 00434 fprintf (stderr, " %-6d ", stabp->desc); 00435 fprintf_vma (stderr, stabp->value); 00436 if (stabp->type != 0) 00437 fprintf (stderr, " %s", stabp->string); 00438 fprintf (stderr, "\n"); 00439 } 00440 i = (i + 1) % SAVE_STABS_COUNT; 00441 } 00442 while (i != saved_stabs_index); 00443 }
Here is the caller graph for this function:

struct saved_stab saved_stabs[SAVE_STABS_COUNT] [static] |
Definition at line 386 of file rddbg.c.
Referenced by free_saved_stabs(), save_stab(), and stab_context().
int saved_stabs_index [static] |
1.4.7

