From ec92004f95c084527fcff50653aeb76ba9453b5f Mon Sep 17 00:00:00 2001 From: Joel Brobecker Date: Wed, 18 Apr 2012 00:25:09 +0000 Subject: [PATCH] pspace != NULL failed assertion on ppc-aix This patch fixes the following problem: % gdb foo (gdb) b main /[...]/progspace.c:216: internal-error: set_current_program_space: Assertion `pspace != NULL' failed. A problem internal to GDB has been detected, further debugging may prove unreliable. Quit this debugging session? (y or n) The problem happens when we try to get the program space from a minimal symbol. For that, we go through the minimal symbol's obj_section->objfile->pspace. But the minimal symbol's obj_section is not set, and thus we somehow get a NULL program space. And the reason why the obj_section is not set is because the XCOFF reader did not pass the bfd_section when calling minsyms.c's prim_record_minimal_symbol_and_info. gdb/ChangeLog: * xcoffread.c (xcoff_secnum_to_sections): New function. (secnum_to_section, secnum_to_bfd_section): Reimplement using xcoff_secnum_to_sections. Rename "secnum" parameter into "n_scnum". (RECORD_MINIMAL_SYMBOL): Delete. (record_minimal_symbol): New function. (scan_xcoff_symtab): Replace uses of RECORD_MINIMAL_SYMBOL by call to record_minimal_symbol and set misc_func_recorded to 1. Set last_csect_sec to the XCOFF section index instead of GDB's section_offset index. Update calls to prim_record_minimal_symbol_and_info to pass the BFD section as well. --- gdb/ChangeLog | 15 ++++++ gdb/xcoffread.c | 143 ++++++++++++++++++++++++++++++++++---------------------- 2 files changed, 103 insertions(+), 55 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index e065689..0da4042 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,20 @@ 2012-04-17 Joel Brobecker + * xcoffread.c (xcoff_secnum_to_sections): New function. + (secnum_to_section, secnum_to_bfd_section): Reimplement + using xcoff_secnum_to_sections. Rename "secnum" parameter + into "n_scnum". + (RECORD_MINIMAL_SYMBOL): Delete. + (record_minimal_symbol): New function. + (scan_xcoff_symtab): Replace uses of RECORD_MINIMAL_SYMBOL + by call to record_minimal_symbol and set misc_func_recorded + to 1. Set last_csect_sec to the XCOFF section index instead + of GDB's section_offset index. Update calls to + prim_record_minimal_symbol_and_info to pass the BFD section + as well. + +2012-04-17 Joel Brobecker + * xcoffread.c (read_xcoff_symtab): Delete variables last_csect_val and last_csect_sec and associated code. diff --git a/gdb/xcoffread.c b/gdb/xcoffread.c index fcabddb..1a1b5de 100644 --- a/gdb/xcoffread.c +++ b/gdb/xcoffread.c @@ -272,36 +272,53 @@ find_targ_sec (bfd *abfd, asection *sect, void *obj) } } -/* Return the section number (SECT_OFF_*) that CS points to. */ -static int -secnum_to_section (int secnum, struct objfile *objfile) -{ - int off = SECT_OFF_TEXT (objfile); +/* Search all BFD sections for the section whose target_index is + equal to N_SCNUM. Set *BFD_SECT to that section. The section's + associated index in the objfile's section_offset table is also + stored in *SECNUM. - asection *sect = NULL; + If no match is found, *BFD_SECT is set to NULL, and *SECNUM + is set to the text section's number. */ + +static void +xcoff_secnum_to_sections (int n_scnum, struct objfile *objfile, + asection **bfd_sect, int *secnum) +{ struct find_targ_sec_arg args; - args.targ_index = secnum; - args.resultp = &off; - args.bfd_sect = § + + args.targ_index = n_scnum; + args.resultp = secnum; + args.bfd_sect = bfd_sect; args.objfile = objfile; + + *bfd_sect = NULL; + *secnum = SECT_OFF_TEXT (objfile); + bfd_map_over_sections (objfile->obfd, find_targ_sec, &args); - return off; } -/* Return the BFD section that CS points to. */ +/* Return the section number (SECT_OFF_*) that N_SCNUM points to. */ + +static int +secnum_to_section (int n_scnum, struct objfile *objfile) +{ + int secnum; + asection *ignored; + + xcoff_secnum_to_sections (n_scnum, objfile, &ignored, &secnum); + return secnum; +} + +/* Return the BFD section that N_SCNUM points to. */ + static asection * -secnum_to_bfd_section (int secnum, struct objfile *objfile) +secnum_to_bfd_section (int n_scnum, struct objfile *objfile) { - int off = SECT_OFF_TEXT (objfile); + int ignored; + asection *bfd_sect; - asection *sect = NULL; - struct find_targ_sec_arg args; - args.targ_index = secnum; - args.resultp = &off; - args.bfd_sect = § - args.objfile = objfile; - bfd_map_over_sections (objfile->obfd, find_targ_sec, &args); - return sect; + xcoff_secnum_to_sections (n_scnum, objfile, &bfd_sect, &ignored); + return bfd_sect; } /* add a given stab string into given stab vector. */ @@ -877,21 +894,34 @@ enter_line_range (struct subfile *subfile, unsigned beginoffset, This function can read past the end of the symbol table (into the string table) but this does no harm. */ -/* Reading symbol table has to be fast! Keep the followings as macros, rather - than functions. */ - -#define RECORD_MINIMAL_SYMBOL(NAME, ADDR, TYPE, SECTION, OBJFILE) \ -{ \ - const char *namestr; \ - \ - namestr = (NAME); \ - if (namestr[0] == '.') ++namestr; \ - prim_record_minimal_symbol_and_info (namestr, (ADDR), (TYPE), \ - (SECTION), (asection *)NULL, \ - (OBJFILE)); \ - misc_func_recorded = 1; \ -} +/* Create a new minimal symbol (using prim_record_minimal_symbol_and_info). + + Arguments are: + + NAME - the symbol's name (but if NAME starts with a period, that + leading period is discarded). + ADDRESS - the symbol's address. + MS_TYPE - the symbol's type. + N_SCNUM - the symbol's XCOFF section number. + OBJFILE - the objfile associated with the minimal symbol. */ + +static void +record_minimal_symbol (const char *name, CORE_ADDR address, + enum minimal_symbol_type ms_type, + int n_scnum, + struct objfile *objfile) +{ + struct find_targ_sec_arg args; + int secnum; + asection *bfd_sect; + if (name[0] == '.') + ++name; + + xcoff_secnum_to_sections (n_scnum, objfile, &bfd_sect, &secnum); + prim_record_minimal_symbol_and_info (name, address, ms_type, + secnum, bfd_sect, objfile); +} /* xcoff has static blocks marked in `.bs', `.es' pairs. They cannot be nested. At any given time, a symbol can only be in one static block. @@ -2277,10 +2307,10 @@ scan_xcoff_symtab (struct objfile *objfile) if (!misc_func_recorded) { - RECORD_MINIMAL_SYMBOL + record_minimal_symbol (last_csect_name, last_csect_val, - mst_text, last_csect_sec, - objfile); + mst_text, last_csect_sec, objfile); + misc_func_recorded = 1; } if (pst != NULL) @@ -2312,8 +2342,7 @@ scan_xcoff_symtab (struct objfile *objfile) { last_csect_name = namestring; last_csect_val = symbol.n_value; - last_csect_sec = - secnum_to_section (symbol.n_scnum, objfile); + last_csect_sec = symbol.n_scnum; } if (pst != NULL) { @@ -2337,7 +2366,8 @@ scan_xcoff_symtab (struct objfile *objfile) (namestring, symbol.n_value, sclass == C_HIDEXT ? mst_file_data : mst_data, secnum_to_section (symbol.n_scnum, objfile), - NULL, objfile); + secnum_to_bfd_section (symbol.n_scnum, objfile), + objfile); break; case XMC_TC0: @@ -2371,11 +2401,13 @@ scan_xcoff_symtab (struct objfile *objfile) if (first_fun_line_offset == 0 && symbol.n_numaux > 1) first_fun_line_offset = main_aux[0].x_sym.x_fcnary.x_fcn.x_lnnoptr; - RECORD_MINIMAL_SYMBOL - (namestring, symbol.n_value, - sclass == C_HIDEXT ? mst_file_text : mst_text, - secnum_to_section (symbol.n_scnum, objfile), - objfile); + { + record_minimal_symbol + (namestring, symbol.n_value, + sclass == C_HIDEXT ? mst_file_text : mst_text, + symbol.n_scnum, objfile); + misc_func_recorded = 1; + } break; case XMC_GL: @@ -2386,11 +2418,10 @@ scan_xcoff_symtab (struct objfile *objfile) mst_solib_trampoline symbol. When we lookup mst symbols, we will choose mst_text over mst_solib_trampoline. */ - RECORD_MINIMAL_SYMBOL + record_minimal_symbol (namestring, symbol.n_value, - mst_solib_trampoline, - secnum_to_section (symbol.n_scnum, objfile), - objfile); + mst_solib_trampoline, symbol.n_scnum, objfile); + misc_func_recorded = 1; break; case XMC_DS: @@ -2413,7 +2444,8 @@ scan_xcoff_symtab (struct objfile *objfile) (namestring, symbol.n_value, sclass == C_HIDEXT ? mst_file_data : mst_data, secnum_to_section (symbol.n_scnum, objfile), - NULL, objfile); + secnum_to_bfd_section (symbol.n_scnum, objfile), + objfile); break; } break; @@ -2430,7 +2462,8 @@ scan_xcoff_symtab (struct objfile *objfile) (namestring, symbol.n_value, sclass == C_HIDEXT ? mst_file_bss : mst_bss, secnum_to_section (symbol.n_scnum, objfile), - NULL, objfile); + secnum_to_bfd_section (symbol.n_scnum, objfile), + objfile); break; } break; @@ -2456,9 +2489,9 @@ scan_xcoff_symtab (struct objfile *objfile) it as a function. This will take care of functions like strcmp() compiled by xlc. */ - RECORD_MINIMAL_SYMBOL - (last_csect_name, last_csect_val, - mst_text, last_csect_sec, objfile); + record_minimal_symbol (last_csect_name, last_csect_val, + mst_text, last_csect_sec, objfile); + misc_func_recorded = 1; } if (pst) -- 2.7.4