GDB (API)
/home/stan/gdb/src/gdb/dwarf2-frame.c
Go to the documentation of this file.
00001 /* Frame unwinder for frames with DWARF Call Frame Information.
00002 
00003    Copyright (C) 2003-2013 Free Software Foundation, Inc.
00004 
00005    Contributed by Mark Kettenis.
00006 
00007    This file is part of GDB.
00008 
00009    This program is free software; you can redistribute it and/or modify
00010    it under the terms of the GNU General Public License as published by
00011    the Free Software Foundation; either version 3 of the License, or
00012    (at your option) any later version.
00013 
00014    This program is distributed in the hope that it will be useful,
00015    but WITHOUT ANY WARRANTY; without even the implied warranty of
00016    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017    GNU General Public License for more details.
00018 
00019    You should have received a copy of the GNU General Public License
00020    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
00021 
00022 #include "defs.h"
00023 #include "dwarf2expr.h"
00024 #include "dwarf2.h"
00025 #include "frame.h"
00026 #include "frame-base.h"
00027 #include "frame-unwind.h"
00028 #include "gdbcore.h"
00029 #include "gdbtypes.h"
00030 #include "symtab.h"
00031 #include "objfiles.h"
00032 #include "regcache.h"
00033 #include "value.h"
00034 
00035 #include "gdb_assert.h"
00036 #include "gdb_string.h"
00037 
00038 #include "complaints.h"
00039 #include "dwarf2-frame.h"
00040 #include "ax.h"
00041 #include "dwarf2loc.h"
00042 #include "exceptions.h"
00043 #include "dwarf2-frame-tailcall.h"
00044 
00045 struct comp_unit;
00046 
00047 /* Call Frame Information (CFI).  */
00048 
00049 /* Common Information Entry (CIE).  */
00050 
00051 struct dwarf2_cie
00052 {
00053   /* Computation Unit for this CIE.  */
00054   struct comp_unit *unit;
00055 
00056   /* Offset into the .debug_frame section where this CIE was found.
00057      Used to identify this CIE.  */
00058   ULONGEST cie_pointer;
00059 
00060   /* Constant that is factored out of all advance location
00061      instructions.  */
00062   ULONGEST code_alignment_factor;
00063 
00064   /* Constants that is factored out of all offset instructions.  */
00065   LONGEST data_alignment_factor;
00066 
00067   /* Return address column.  */
00068   ULONGEST return_address_register;
00069 
00070   /* Instruction sequence to initialize a register set.  */
00071   const gdb_byte *initial_instructions;
00072   const gdb_byte *end;
00073 
00074   /* Saved augmentation, in case it's needed later.  */
00075   char *augmentation;
00076 
00077   /* Encoding of addresses.  */
00078   gdb_byte encoding;
00079 
00080   /* Target address size in bytes.  */
00081   int addr_size;
00082 
00083   /* Target pointer size in bytes.  */
00084   int ptr_size;
00085 
00086   /* True if a 'z' augmentation existed.  */
00087   unsigned char saw_z_augmentation;
00088 
00089   /* True if an 'S' augmentation existed.  */
00090   unsigned char signal_frame;
00091 
00092   /* The version recorded in the CIE.  */
00093   unsigned char version;
00094 
00095   /* The segment size.  */
00096   unsigned char segment_size;
00097 };
00098 
00099 struct dwarf2_cie_table
00100 {
00101   int num_entries;
00102   struct dwarf2_cie **entries;
00103 };
00104 
00105 /* Frame Description Entry (FDE).  */
00106 
00107 struct dwarf2_fde
00108 {
00109   /* CIE for this FDE.  */
00110   struct dwarf2_cie *cie;
00111 
00112   /* First location associated with this FDE.  */
00113   CORE_ADDR initial_location;
00114 
00115   /* Number of bytes of program instructions described by this FDE.  */
00116   CORE_ADDR address_range;
00117 
00118   /* Instruction sequence.  */
00119   const gdb_byte *instructions;
00120   const gdb_byte *end;
00121 
00122   /* True if this FDE is read from a .eh_frame instead of a .debug_frame
00123      section.  */
00124   unsigned char eh_frame_p;
00125 };
00126 
00127 struct dwarf2_fde_table
00128 {
00129   int num_entries;
00130   struct dwarf2_fde **entries;
00131 };
00132 
00133 /* A minimal decoding of DWARF2 compilation units.  We only decode
00134    what's needed to get to the call frame information.  */
00135 
00136 struct comp_unit
00137 {
00138   /* Keep the bfd convenient.  */
00139   bfd *abfd;
00140 
00141   struct objfile *objfile;
00142 
00143   /* Pointer to the .debug_frame section loaded into memory.  */
00144   const gdb_byte *dwarf_frame_buffer;
00145 
00146   /* Length of the loaded .debug_frame section.  */
00147   bfd_size_type dwarf_frame_size;
00148 
00149   /* Pointer to the .debug_frame section.  */
00150   asection *dwarf_frame_section;
00151 
00152   /* Base for DW_EH_PE_datarel encodings.  */
00153   bfd_vma dbase;
00154 
00155   /* Base for DW_EH_PE_textrel encodings.  */
00156   bfd_vma tbase;
00157 };
00158 
00159 static struct dwarf2_fde *dwarf2_frame_find_fde (CORE_ADDR *pc,
00160                                                  CORE_ADDR *out_offset);
00161 
00162 static int dwarf2_frame_adjust_regnum (struct gdbarch *gdbarch, int regnum,
00163                                        int eh_frame_p);
00164 
00165 static CORE_ADDR read_encoded_value (struct comp_unit *unit, gdb_byte encoding,
00166                                      int ptr_len, const gdb_byte *buf,
00167                                      unsigned int *bytes_read_ptr,
00168                                      CORE_ADDR func_base);
00169 
00170 
00171 /* Structure describing a frame state.  */
00172 
00173 struct dwarf2_frame_state
00174 {
00175   /* Each register save state can be described in terms of a CFA slot,
00176      another register, or a location expression.  */
00177   struct dwarf2_frame_state_reg_info
00178   {
00179     struct dwarf2_frame_state_reg *reg;
00180     int num_regs;
00181 
00182     LONGEST cfa_offset;
00183     ULONGEST cfa_reg;
00184     enum {
00185       CFA_UNSET,
00186       CFA_REG_OFFSET,
00187       CFA_EXP
00188     } cfa_how;
00189     const gdb_byte *cfa_exp;
00190 
00191     /* Used to implement DW_CFA_remember_state.  */
00192     struct dwarf2_frame_state_reg_info *prev;
00193   } regs;
00194 
00195   /* The PC described by the current frame state.  */
00196   CORE_ADDR pc;
00197 
00198   /* Initial register set from the CIE.
00199      Used to implement DW_CFA_restore.  */
00200   struct dwarf2_frame_state_reg_info initial;
00201 
00202   /* The information we care about from the CIE.  */
00203   LONGEST data_align;
00204   ULONGEST code_align;
00205   ULONGEST retaddr_column;
00206 
00207   /* Flags for known producer quirks.  */
00208 
00209   /* The ARM compilers, in DWARF2 mode, assume that DW_CFA_def_cfa
00210      and DW_CFA_def_cfa_offset takes a factored offset.  */
00211   int armcc_cfa_offsets_sf;
00212 
00213   /* The ARM compilers, in DWARF2 or DWARF3 mode, may assume that
00214      the CFA is defined as REG - OFFSET rather than REG + OFFSET.  */
00215   int armcc_cfa_offsets_reversed;
00216 };
00217 
00218 /* Store the length the expression for the CFA in the `cfa_reg' field,
00219    which is unused in that case.  */
00220 #define cfa_exp_len cfa_reg
00221 
00222 /* Assert that the register set RS is large enough to store gdbarch_num_regs
00223    columns.  If necessary, enlarge the register set.  */
00224 
00225 static void
00226 dwarf2_frame_state_alloc_regs (struct dwarf2_frame_state_reg_info *rs,
00227                                int num_regs)
00228 {
00229   size_t size = sizeof (struct dwarf2_frame_state_reg);
00230 
00231   if (num_regs <= rs->num_regs)
00232     return;
00233 
00234   rs->reg = (struct dwarf2_frame_state_reg *)
00235     xrealloc (rs->reg, num_regs * size);
00236 
00237   /* Initialize newly allocated registers.  */
00238   memset (rs->reg + rs->num_regs, 0, (num_regs - rs->num_regs) * size);
00239   rs->num_regs = num_regs;
00240 }
00241 
00242 /* Copy the register columns in register set RS into newly allocated
00243    memory and return a pointer to this newly created copy.  */
00244 
00245 static struct dwarf2_frame_state_reg *
00246 dwarf2_frame_state_copy_regs (struct dwarf2_frame_state_reg_info *rs)
00247 {
00248   size_t size = rs->num_regs * sizeof (struct dwarf2_frame_state_reg);
00249   struct dwarf2_frame_state_reg *reg;
00250 
00251   reg = (struct dwarf2_frame_state_reg *) xmalloc (size);
00252   memcpy (reg, rs->reg, size);
00253 
00254   return reg;
00255 }
00256 
00257 /* Release the memory allocated to register set RS.  */
00258 
00259 static void
00260 dwarf2_frame_state_free_regs (struct dwarf2_frame_state_reg_info *rs)
00261 {
00262   if (rs)
00263     {
00264       dwarf2_frame_state_free_regs (rs->prev);
00265 
00266       xfree (rs->reg);
00267       xfree (rs);
00268     }
00269 }
00270 
00271 /* Release the memory allocated to the frame state FS.  */
00272 
00273 static void
00274 dwarf2_frame_state_free (void *p)
00275 {
00276   struct dwarf2_frame_state *fs = p;
00277 
00278   dwarf2_frame_state_free_regs (fs->initial.prev);
00279   dwarf2_frame_state_free_regs (fs->regs.prev);
00280   xfree (fs->initial.reg);
00281   xfree (fs->regs.reg);
00282   xfree (fs);
00283 }
00284 
00285 
00286 /* Helper functions for execute_stack_op.  */
00287 
00288 static CORE_ADDR
00289 read_reg (void *baton, int reg)
00290 {
00291   struct frame_info *this_frame = (struct frame_info *) baton;
00292   struct gdbarch *gdbarch = get_frame_arch (this_frame);
00293   int regnum;
00294   gdb_byte *buf;
00295 
00296   regnum = gdbarch_dwarf2_reg_to_regnum (gdbarch, reg);
00297 
00298   buf = alloca (register_size (gdbarch, regnum));
00299   get_frame_register (this_frame, regnum, buf);
00300 
00301   /* Convert the register to an integer.  This returns a LONGEST
00302      rather than a CORE_ADDR, but unpack_pointer does the same thing
00303      under the covers, and this makes more sense for non-pointer
00304      registers.  Maybe read_reg and the associated interfaces should
00305      deal with "struct value" instead of CORE_ADDR.  */
00306   return unpack_long (register_type (gdbarch, regnum), buf);
00307 }
00308 
00309 static void
00310 read_mem (void *baton, gdb_byte *buf, CORE_ADDR addr, size_t len)
00311 {
00312   read_memory (addr, buf, len);
00313 }
00314 
00315 /* Execute the required actions for both the DW_CFA_restore and
00316 DW_CFA_restore_extended instructions.  */
00317 static void
00318 dwarf2_restore_rule (struct gdbarch *gdbarch, ULONGEST reg_num,
00319                      struct dwarf2_frame_state *fs, int eh_frame_p)
00320 {
00321   ULONGEST reg;
00322 
00323   gdb_assert (fs->initial.reg);
00324   reg = dwarf2_frame_adjust_regnum (gdbarch, reg_num, eh_frame_p);
00325   dwarf2_frame_state_alloc_regs (&fs->regs, reg + 1);
00326 
00327   /* Check if this register was explicitly initialized in the
00328   CIE initial instructions.  If not, default the rule to
00329   UNSPECIFIED.  */
00330   if (reg < fs->initial.num_regs)
00331     fs->regs.reg[reg] = fs->initial.reg[reg];
00332   else
00333     fs->regs.reg[reg].how = DWARF2_FRAME_REG_UNSPECIFIED;
00334 
00335   if (fs->regs.reg[reg].how == DWARF2_FRAME_REG_UNSPECIFIED)
00336     complaint (&symfile_complaints, _("\
00337 incomplete CFI data; DW_CFA_restore unspecified\n\
00338 register %s (#%d) at %s"),
00339                        gdbarch_register_name
00340                        (gdbarch, gdbarch_dwarf2_reg_to_regnum (gdbarch, reg)),
00341                        gdbarch_dwarf2_reg_to_regnum (gdbarch, reg),
00342                        paddress (gdbarch, fs->pc));
00343 }
00344 
00345 /* Virtual method table for execute_stack_op below.  */
00346 
00347 static const struct dwarf_expr_context_funcs dwarf2_frame_ctx_funcs =
00348 {
00349   read_reg,
00350   read_mem,
00351   ctx_no_get_frame_base,
00352   ctx_no_get_frame_cfa,
00353   ctx_no_get_frame_pc,
00354   ctx_no_get_tls_address,
00355   ctx_no_dwarf_call,
00356   ctx_no_get_base_type,
00357   ctx_no_push_dwarf_reg_entry_value,
00358   ctx_no_get_addr_index
00359 };
00360 
00361 static CORE_ADDR
00362 execute_stack_op (const gdb_byte *exp, ULONGEST len, int addr_size,
00363                   CORE_ADDR offset, struct frame_info *this_frame,
00364                   CORE_ADDR initial, int initial_in_stack_memory)
00365 {
00366   struct dwarf_expr_context *ctx;
00367   CORE_ADDR result;
00368   struct cleanup *old_chain;
00369 
00370   ctx = new_dwarf_expr_context ();
00371   old_chain = make_cleanup_free_dwarf_expr_context (ctx);
00372   make_cleanup_value_free_to_mark (value_mark ());
00373 
00374   ctx->gdbarch = get_frame_arch (this_frame);
00375   ctx->addr_size = addr_size;
00376   ctx->ref_addr_size = -1;
00377   ctx->offset = offset;
00378   ctx->baton = this_frame;
00379   ctx->funcs = &dwarf2_frame_ctx_funcs;
00380 
00381   dwarf_expr_push_address (ctx, initial, initial_in_stack_memory);
00382   dwarf_expr_eval (ctx, exp, len);
00383 
00384   if (ctx->location == DWARF_VALUE_MEMORY)
00385     result = dwarf_expr_fetch_address (ctx, 0);
00386   else if (ctx->location == DWARF_VALUE_REGISTER)
00387     result = read_reg (this_frame, value_as_long (dwarf_expr_fetch (ctx, 0)));
00388   else
00389     {
00390       /* This is actually invalid DWARF, but if we ever do run across
00391          it somehow, we might as well support it.  So, instead, report
00392          it as unimplemented.  */
00393       error (_("\
00394 Not implemented: computing unwound register using explicit value operator"));
00395     }
00396 
00397   do_cleanups (old_chain);
00398 
00399   return result;
00400 }
00401 
00402 
00403 /* Execute FDE program from INSN_PTR possibly up to INSN_END or up to inferior
00404    PC.  Modify FS state accordingly.  Return current INSN_PTR where the
00405    execution has stopped, one can resume it on the next call.  */
00406 
00407 static const gdb_byte *
00408 execute_cfa_program (struct dwarf2_fde *fde, const gdb_byte *insn_ptr,
00409                      const gdb_byte *insn_end, struct gdbarch *gdbarch,
00410                      CORE_ADDR pc, struct dwarf2_frame_state *fs)
00411 {
00412   int eh_frame_p = fde->eh_frame_p;
00413   unsigned int bytes_read;
00414   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
00415 
00416   while (insn_ptr < insn_end && fs->pc <= pc)
00417     {
00418       gdb_byte insn = *insn_ptr++;
00419       uint64_t utmp, reg;
00420       int64_t offset;
00421 
00422       if ((insn & 0xc0) == DW_CFA_advance_loc)
00423         fs->pc += (insn & 0x3f) * fs->code_align;
00424       else if ((insn & 0xc0) == DW_CFA_offset)
00425         {
00426           reg = insn & 0x3f;
00427           reg = dwarf2_frame_adjust_regnum (gdbarch, reg, eh_frame_p);
00428           insn_ptr = safe_read_uleb128 (insn_ptr, insn_end, &utmp);
00429           offset = utmp * fs->data_align;
00430           dwarf2_frame_state_alloc_regs (&fs->regs, reg + 1);
00431           fs->regs.reg[reg].how = DWARF2_FRAME_REG_SAVED_OFFSET;
00432           fs->regs.reg[reg].loc.offset = offset;
00433         }
00434       else if ((insn & 0xc0) == DW_CFA_restore)
00435         {
00436           reg = insn & 0x3f;
00437           dwarf2_restore_rule (gdbarch, reg, fs, eh_frame_p);
00438         }
00439       else
00440         {
00441           switch (insn)
00442             {
00443             case DW_CFA_set_loc:
00444               fs->pc = read_encoded_value (fde->cie->unit, fde->cie->encoding,
00445                                            fde->cie->ptr_size, insn_ptr,
00446                                            &bytes_read, fde->initial_location);
00447               /* Apply the objfile offset for relocatable objects.  */
00448               fs->pc += ANOFFSET (fde->cie->unit->objfile->section_offsets,
00449                                   SECT_OFF_TEXT (fde->cie->unit->objfile));
00450               insn_ptr += bytes_read;
00451               break;
00452 
00453             case DW_CFA_advance_loc1:
00454               utmp = extract_unsigned_integer (insn_ptr, 1, byte_order);
00455               fs->pc += utmp * fs->code_align;
00456               insn_ptr++;
00457               break;
00458             case DW_CFA_advance_loc2:
00459               utmp = extract_unsigned_integer (insn_ptr, 2, byte_order);
00460               fs->pc += utmp * fs->code_align;
00461               insn_ptr += 2;
00462               break;
00463             case DW_CFA_advance_loc4:
00464               utmp = extract_unsigned_integer (insn_ptr, 4, byte_order);
00465               fs->pc += utmp * fs->code_align;
00466               insn_ptr += 4;
00467               break;
00468 
00469             case DW_CFA_offset_extended:
00470               insn_ptr = safe_read_uleb128 (insn_ptr, insn_end, &reg);
00471               reg = dwarf2_frame_adjust_regnum (gdbarch, reg, eh_frame_p);
00472               insn_ptr = safe_read_uleb128 (insn_ptr, insn_end, &utmp);
00473               offset = utmp * fs->data_align;
00474               dwarf2_frame_state_alloc_regs (&fs->regs, reg + 1);
00475               fs->regs.reg[reg].how = DWARF2_FRAME_REG_SAVED_OFFSET;
00476               fs->regs.reg[reg].loc.offset = offset;
00477               break;
00478 
00479             case DW_CFA_restore_extended:
00480               insn_ptr = safe_read_uleb128 (insn_ptr, insn_end, &reg);
00481               dwarf2_restore_rule (gdbarch, reg, fs, eh_frame_p);
00482               break;
00483 
00484             case DW_CFA_undefined:
00485               insn_ptr = safe_read_uleb128 (insn_ptr, insn_end, &reg);
00486               reg = dwarf2_frame_adjust_regnum (gdbarch, reg, eh_frame_p);
00487               dwarf2_frame_state_alloc_regs (&fs->regs, reg + 1);
00488               fs->regs.reg[reg].how = DWARF2_FRAME_REG_UNDEFINED;
00489               break;
00490 
00491             case DW_CFA_same_value:
00492               insn_ptr = safe_read_uleb128 (insn_ptr, insn_end, &reg);
00493               reg = dwarf2_frame_adjust_regnum (gdbarch, reg, eh_frame_p);
00494               dwarf2_frame_state_alloc_regs (&fs->regs, reg + 1);
00495               fs->regs.reg[reg].how = DWARF2_FRAME_REG_SAME_VALUE;
00496               break;
00497 
00498             case DW_CFA_register:
00499               insn_ptr = safe_read_uleb128 (insn_ptr, insn_end, &reg);
00500               reg = dwarf2_frame_adjust_regnum (gdbarch, reg, eh_frame_p);
00501               insn_ptr = safe_read_uleb128 (insn_ptr, insn_end, &utmp);
00502               utmp = dwarf2_frame_adjust_regnum (gdbarch, utmp, eh_frame_p);
00503               dwarf2_frame_state_alloc_regs (&fs->regs, reg + 1);
00504               fs->regs.reg[reg].how = DWARF2_FRAME_REG_SAVED_REG;
00505               fs->regs.reg[reg].loc.reg = utmp;
00506               break;
00507 
00508             case DW_CFA_remember_state:
00509               {
00510                 struct dwarf2_frame_state_reg_info *new_rs;
00511 
00512                 new_rs = XMALLOC (struct dwarf2_frame_state_reg_info);
00513                 *new_rs = fs->regs;
00514                 fs->regs.reg = dwarf2_frame_state_copy_regs (&fs->regs);
00515                 fs->regs.prev = new_rs;
00516               }
00517               break;
00518 
00519             case DW_CFA_restore_state:
00520               {
00521                 struct dwarf2_frame_state_reg_info *old_rs = fs->regs.prev;
00522 
00523                 if (old_rs == NULL)
00524                   {
00525                     complaint (&symfile_complaints, _("\
00526 bad CFI data; mismatched DW_CFA_restore_state at %s"),
00527                                paddress (gdbarch, fs->pc));
00528                   }
00529                 else
00530                   {
00531                     xfree (fs->regs.reg);
00532                     fs->regs = *old_rs;
00533                     xfree (old_rs);
00534                   }
00535               }
00536               break;
00537 
00538             case DW_CFA_def_cfa:
00539               insn_ptr = safe_read_uleb128 (insn_ptr, insn_end, &reg);
00540               fs->regs.cfa_reg = reg;
00541               insn_ptr = safe_read_uleb128 (insn_ptr, insn_end, &utmp);
00542 
00543               if (fs->armcc_cfa_offsets_sf)
00544                 utmp *= fs->data_align;
00545 
00546               fs->regs.cfa_offset = utmp;
00547               fs->regs.cfa_how = CFA_REG_OFFSET;
00548               break;
00549 
00550             case DW_CFA_def_cfa_register:
00551               insn_ptr = safe_read_uleb128 (insn_ptr, insn_end, &reg);
00552               fs->regs.cfa_reg = dwarf2_frame_adjust_regnum (gdbarch, reg,
00553                                                              eh_frame_p);
00554               fs->regs.cfa_how = CFA_REG_OFFSET;
00555               break;
00556 
00557             case DW_CFA_def_cfa_offset:
00558               insn_ptr = safe_read_uleb128 (insn_ptr, insn_end, &utmp);
00559 
00560               if (fs->armcc_cfa_offsets_sf)
00561                 utmp *= fs->data_align;
00562 
00563               fs->regs.cfa_offset = utmp;
00564               /* cfa_how deliberately not set.  */
00565               break;
00566 
00567             case DW_CFA_nop:
00568               break;
00569 
00570             case DW_CFA_def_cfa_expression:
00571               insn_ptr = safe_read_uleb128 (insn_ptr, insn_end, &utmp);
00572               fs->regs.cfa_exp_len = utmp;
00573               fs->regs.cfa_exp = insn_ptr;
00574               fs->regs.cfa_how = CFA_EXP;
00575               insn_ptr += fs->regs.cfa_exp_len;
00576               break;
00577 
00578             case DW_CFA_expression:
00579               insn_ptr = safe_read_uleb128 (insn_ptr, insn_end, &reg);
00580               reg = dwarf2_frame_adjust_regnum (gdbarch, reg, eh_frame_p);
00581               dwarf2_frame_state_alloc_regs (&fs->regs, reg + 1);
00582               insn_ptr = safe_read_uleb128 (insn_ptr, insn_end, &utmp);
00583               fs->regs.reg[reg].loc.exp = insn_ptr;
00584               fs->regs.reg[reg].exp_len = utmp;
00585               fs->regs.reg[reg].how = DWARF2_FRAME_REG_SAVED_EXP;
00586               insn_ptr += utmp;
00587               break;
00588 
00589             case DW_CFA_offset_extended_sf:
00590               insn_ptr = safe_read_uleb128 (insn_ptr, insn_end, &reg);
00591               reg = dwarf2_frame_adjust_regnum (gdbarch, reg, eh_frame_p);
00592               insn_ptr = safe_read_sleb128 (insn_ptr, insn_end, &offset);
00593               offset *= fs->data_align;
00594               dwarf2_frame_state_alloc_regs (&fs->regs, reg + 1);
00595               fs->regs.reg[reg].how = DWARF2_FRAME_REG_SAVED_OFFSET;
00596               fs->regs.reg[reg].loc.offset = offset;
00597               break;
00598 
00599             case DW_CFA_val_offset:
00600               insn_ptr = safe_read_uleb128 (insn_ptr, insn_end, &reg);
00601               dwarf2_frame_state_alloc_regs (&fs->regs, reg + 1);
00602               insn_ptr = safe_read_uleb128 (insn_ptr, insn_end, &utmp);
00603               offset = utmp * fs->data_align;
00604               fs->regs.reg[reg].how = DWARF2_FRAME_REG_SAVED_VAL_OFFSET;
00605               fs->regs.reg[reg].loc.offset = offset;
00606               break;
00607 
00608             case DW_CFA_val_offset_sf:
00609               insn_ptr = safe_read_uleb128 (insn_ptr, insn_end, &reg);
00610               dwarf2_frame_state_alloc_regs (&fs->regs, reg + 1);
00611               insn_ptr = safe_read_sleb128 (insn_ptr, insn_end, &offset);
00612               offset *= fs->data_align;
00613               fs->regs.reg[reg].how = DWARF2_FRAME_REG_SAVED_VAL_OFFSET;
00614               fs->regs.reg[reg].loc.offset = offset;
00615               break;
00616 
00617             case DW_CFA_val_expression:
00618               insn_ptr = safe_read_uleb128 (insn_ptr, insn_end, &reg);
00619               dwarf2_frame_state_alloc_regs (&fs->regs, reg + 1);
00620               insn_ptr = safe_read_uleb128 (insn_ptr, insn_end, &utmp);
00621               fs->regs.reg[reg].loc.exp = insn_ptr;
00622               fs->regs.reg[reg].exp_len = utmp;
00623               fs->regs.reg[reg].how = DWARF2_FRAME_REG_SAVED_VAL_EXP;
00624               insn_ptr += utmp;
00625               break;
00626 
00627             case DW_CFA_def_cfa_sf:
00628               insn_ptr = safe_read_uleb128 (insn_ptr, insn_end, &reg);
00629               fs->regs.cfa_reg = dwarf2_frame_adjust_regnum (gdbarch, reg,
00630                                                              eh_frame_p);
00631               insn_ptr = safe_read_sleb128 (insn_ptr, insn_end, &offset);
00632               fs->regs.cfa_offset = offset * fs->data_align;
00633               fs->regs.cfa_how = CFA_REG_OFFSET;
00634               break;
00635 
00636             case DW_CFA_def_cfa_offset_sf:
00637               insn_ptr = safe_read_sleb128 (insn_ptr, insn_end, &offset);
00638               fs->regs.cfa_offset = offset * fs->data_align;
00639               /* cfa_how deliberately not set.  */
00640               break;
00641 
00642             case DW_CFA_GNU_window_save:
00643               /* This is SPARC-specific code, and contains hard-coded
00644                  constants for the register numbering scheme used by
00645                  GCC.  Rather than having a architecture-specific
00646                  operation that's only ever used by a single
00647                  architecture, we provide the implementation here.
00648                  Incidentally that's what GCC does too in its
00649                  unwinder.  */
00650               {
00651                 int size = register_size (gdbarch, 0);
00652 
00653                 dwarf2_frame_state_alloc_regs (&fs->regs, 32);
00654                 for (reg = 8; reg < 16; reg++)
00655                   {
00656                     fs->regs.reg[reg].how = DWARF2_FRAME_REG_SAVED_REG;
00657                     fs->regs.reg[reg].loc.reg = reg + 16;
00658                   }
00659                 for (reg = 16; reg < 32; reg++)
00660                   {
00661                     fs->regs.reg[reg].how = DWARF2_FRAME_REG_SAVED_OFFSET;
00662                     fs->regs.reg[reg].loc.offset = (reg - 16) * size;
00663                   }
00664               }
00665               break;
00666 
00667             case DW_CFA_GNU_args_size:
00668               /* Ignored.  */
00669               insn_ptr = safe_read_uleb128 (insn_ptr, insn_end, &utmp);
00670               break;
00671 
00672             case DW_CFA_GNU_negative_offset_extended:
00673               insn_ptr = safe_read_uleb128 (insn_ptr, insn_end, &reg);
00674               reg = dwarf2_frame_adjust_regnum (gdbarch, reg, eh_frame_p);
00675               insn_ptr = safe_read_uleb128 (insn_ptr, insn_end, &utmp);
00676               offset = utmp * fs->data_align;
00677               dwarf2_frame_state_alloc_regs (&fs->regs, reg + 1);
00678               fs->regs.reg[reg].how = DWARF2_FRAME_REG_SAVED_OFFSET;
00679               fs->regs.reg[reg].loc.offset = -offset;
00680               break;
00681 
00682             default:
00683               internal_error (__FILE__, __LINE__,
00684                               _("Unknown CFI encountered."));
00685             }
00686         }
00687     }
00688 
00689   if (fs->initial.reg == NULL)
00690     {
00691       /* Don't allow remember/restore between CIE and FDE programs.  */
00692       dwarf2_frame_state_free_regs (fs->regs.prev);
00693       fs->regs.prev = NULL;
00694     }
00695 
00696   return insn_ptr;
00697 }
00698 
00699 
00700 /* Architecture-specific operations.  */
00701 
00702 /* Per-architecture data key.  */
00703 static struct gdbarch_data *dwarf2_frame_data;
00704 
00705 struct dwarf2_frame_ops
00706 {
00707   /* Pre-initialize the register state REG for register REGNUM.  */
00708   void (*init_reg) (struct gdbarch *, int, struct dwarf2_frame_state_reg *,
00709                     struct frame_info *);
00710 
00711   /* Check whether the THIS_FRAME is a signal trampoline.  */
00712   int (*signal_frame_p) (struct gdbarch *, struct frame_info *);
00713 
00714   /* Convert .eh_frame register number to DWARF register number, or
00715      adjust .debug_frame register number.  */
00716   int (*adjust_regnum) (struct gdbarch *, int, int);
00717 };
00718 
00719 /* Default architecture-specific register state initialization
00720    function.  */
00721 
00722 static void
00723 dwarf2_frame_default_init_reg (struct gdbarch *gdbarch, int regnum,
00724                                struct dwarf2_frame_state_reg *reg,
00725                                struct frame_info *this_frame)
00726 {
00727   /* If we have a register that acts as a program counter, mark it as
00728      a destination for the return address.  If we have a register that
00729      serves as the stack pointer, arrange for it to be filled with the
00730      call frame address (CFA).  The other registers are marked as
00731      unspecified.
00732 
00733      We copy the return address to the program counter, since many
00734      parts in GDB assume that it is possible to get the return address
00735      by unwinding the program counter register.  However, on ISA's
00736      with a dedicated return address register, the CFI usually only
00737      contains information to unwind that return address register.
00738 
00739      The reason we're treating the stack pointer special here is
00740      because in many cases GCC doesn't emit CFI for the stack pointer
00741      and implicitly assumes that it is equal to the CFA.  This makes
00742      some sense since the DWARF specification (version 3, draft 8,
00743      p. 102) says that:
00744 
00745      "Typically, the CFA is defined to be the value of the stack
00746      pointer at the call site in the previous frame (which may be
00747      different from its value on entry to the current frame)."
00748 
00749      However, this isn't true for all platforms supported by GCC
00750      (e.g. IBM S/390 and zSeries).  Those architectures should provide
00751      their own architecture-specific initialization function.  */
00752 
00753   if (regnum == gdbarch_pc_regnum (gdbarch))
00754     reg->how = DWARF2_FRAME_REG_RA;
00755   else if (regnum == gdbarch_sp_regnum (gdbarch))
00756     reg->how = DWARF2_FRAME_REG_CFA;
00757 }
00758 
00759 /* Return a default for the architecture-specific operations.  */
00760 
00761 static void *
00762 dwarf2_frame_init (struct obstack *obstack)
00763 {
00764   struct dwarf2_frame_ops *ops;
00765   
00766   ops = OBSTACK_ZALLOC (obstack, struct dwarf2_frame_ops);
00767   ops->init_reg = dwarf2_frame_default_init_reg;
00768   return ops;
00769 }
00770 
00771 /* Set the architecture-specific register state initialization
00772    function for GDBARCH to INIT_REG.  */
00773 
00774 void
00775 dwarf2_frame_set_init_reg (struct gdbarch *gdbarch,
00776                            void (*init_reg) (struct gdbarch *, int,
00777                                              struct dwarf2_frame_state_reg *,
00778                                              struct frame_info *))
00779 {
00780   struct dwarf2_frame_ops *ops = gdbarch_data (gdbarch, dwarf2_frame_data);
00781 
00782   ops->init_reg = init_reg;
00783 }
00784 
00785 /* Pre-initialize the register state REG for register REGNUM.  */
00786 
00787 static void
00788 dwarf2_frame_init_reg (struct gdbarch *gdbarch, int regnum,
00789                        struct dwarf2_frame_state_reg *reg,
00790                        struct frame_info *this_frame)
00791 {
00792   struct dwarf2_frame_ops *ops = gdbarch_data (gdbarch, dwarf2_frame_data);
00793 
00794   ops->init_reg (gdbarch, regnum, reg, this_frame);
00795 }
00796 
00797 /* Set the architecture-specific signal trampoline recognition
00798    function for GDBARCH to SIGNAL_FRAME_P.  */
00799 
00800 void
00801 dwarf2_frame_set_signal_frame_p (struct gdbarch *gdbarch,
00802                                  int (*signal_frame_p) (struct gdbarch *,
00803                                                         struct frame_info *))
00804 {
00805   struct dwarf2_frame_ops *ops = gdbarch_data (gdbarch, dwarf2_frame_data);
00806 
00807   ops->signal_frame_p = signal_frame_p;
00808 }
00809 
00810 /* Query the architecture-specific signal frame recognizer for
00811    THIS_FRAME.  */
00812 
00813 static int
00814 dwarf2_frame_signal_frame_p (struct gdbarch *gdbarch,
00815                              struct frame_info *this_frame)
00816 {
00817   struct dwarf2_frame_ops *ops = gdbarch_data (gdbarch, dwarf2_frame_data);
00818 
00819   if (ops->signal_frame_p == NULL)
00820     return 0;
00821   return ops->signal_frame_p (gdbarch, this_frame);
00822 }
00823 
00824 /* Set the architecture-specific adjustment of .eh_frame and .debug_frame
00825    register numbers.  */
00826 
00827 void
00828 dwarf2_frame_set_adjust_regnum (struct gdbarch *gdbarch,
00829                                 int (*adjust_regnum) (struct gdbarch *,
00830                                                       int, int))
00831 {
00832   struct dwarf2_frame_ops *ops = gdbarch_data (gdbarch, dwarf2_frame_data);
00833 
00834   ops->adjust_regnum = adjust_regnum;
00835 }
00836 
00837 /* Translate a .eh_frame register to DWARF register, or adjust a .debug_frame
00838    register.  */
00839 
00840 static int
00841 dwarf2_frame_adjust_regnum (struct gdbarch *gdbarch,
00842                             int regnum, int eh_frame_p)
00843 {
00844   struct dwarf2_frame_ops *ops = gdbarch_data (gdbarch, dwarf2_frame_data);
00845 
00846   if (ops->adjust_regnum == NULL)
00847     return regnum;
00848   return ops->adjust_regnum (gdbarch, regnum, eh_frame_p);
00849 }
00850 
00851 static void
00852 dwarf2_frame_find_quirks (struct dwarf2_frame_state *fs,
00853                           struct dwarf2_fde *fde)
00854 {
00855   struct symtab *s;
00856 
00857   s = find_pc_symtab (fs->pc);
00858   if (s == NULL)
00859     return;
00860 
00861   if (producer_is_realview (s->producer))
00862     {
00863       if (fde->cie->version == 1)
00864         fs->armcc_cfa_offsets_sf = 1;
00865 
00866       if (fde->cie->version == 1)
00867         fs->armcc_cfa_offsets_reversed = 1;
00868 
00869       /* The reversed offset problem is present in some compilers
00870          using DWARF3, but it was eventually fixed.  Check the ARM
00871          defined augmentations, which are in the format "armcc" followed
00872          by a list of one-character options.  The "+" option means
00873          this problem is fixed (no quirk needed).  If the armcc
00874          augmentation is missing, the quirk is needed.  */
00875       if (fde->cie->version == 3
00876           && (strncmp (fde->cie->augmentation, "armcc", 5) != 0
00877               || strchr (fde->cie->augmentation + 5, '+') == NULL))
00878         fs->armcc_cfa_offsets_reversed = 1;
00879 
00880       return;
00881     }
00882 }
00883 
00884 
00885 void
00886 dwarf2_compile_cfa_to_ax (struct agent_expr *expr, struct axs_value *loc,
00887                           struct gdbarch *gdbarch,
00888                           CORE_ADDR pc,
00889                           struct dwarf2_per_cu_data *data)
00890 {
00891   struct dwarf2_fde *fde;
00892   CORE_ADDR text_offset;
00893   struct dwarf2_frame_state fs;
00894   int addr_size;
00895 
00896   memset (&fs, 0, sizeof (struct dwarf2_frame_state));
00897 
00898   fs.pc = pc;
00899 
00900   /* Find the correct FDE.  */
00901   fde = dwarf2_frame_find_fde (&fs.pc, &text_offset);
00902   if (fde == NULL)
00903     error (_("Could not compute CFA; needed to translate this expression"));
00904 
00905   /* Extract any interesting information from the CIE.  */
00906   fs.data_align = fde->cie->data_alignment_factor;
00907   fs.code_align = fde->cie->code_alignment_factor;
00908   fs.retaddr_column = fde->cie->return_address_register;
00909   addr_size = fde->cie->addr_size;
00910 
00911   /* Check for "quirks" - known bugs in producers.  */
00912   dwarf2_frame_find_quirks (&fs, fde);
00913 
00914   /* First decode all the insns in the CIE.  */
00915   execute_cfa_program (fde, fde->cie->initial_instructions,
00916                        fde->cie->end, gdbarch, pc, &fs);
00917 
00918   /* Save the initialized register set.  */
00919   fs.initial = fs.regs;
00920   fs.initial.reg = dwarf2_frame_state_copy_regs (&fs.regs);
00921 
00922   /* Then decode the insns in the FDE up to our target PC.  */
00923   execute_cfa_program (fde, fde->instructions, fde->end, gdbarch, pc, &fs);
00924 
00925   /* Calculate the CFA.  */
00926   switch (fs.regs.cfa_how)
00927     {
00928     case CFA_REG_OFFSET:
00929       {
00930         int regnum = gdbarch_dwarf2_reg_to_regnum (gdbarch, fs.regs.cfa_reg);
00931 
00932         if (regnum == -1)
00933           error (_("Unable to access DWARF register number %d"),
00934                  (int) fs.regs.cfa_reg); /* FIXME */
00935         ax_reg (expr, regnum);
00936 
00937         if (fs.regs.cfa_offset != 0)
00938           {
00939             if (fs.armcc_cfa_offsets_reversed)
00940               ax_const_l (expr, -fs.regs.cfa_offset);
00941             else
00942               ax_const_l (expr, fs.regs.cfa_offset);
00943             ax_simple (expr, aop_add);
00944           }
00945       }
00946       break;
00947 
00948     case CFA_EXP:
00949       ax_const_l (expr, text_offset);
00950       dwarf2_compile_expr_to_ax (expr, loc, gdbarch, addr_size,
00951                                  fs.regs.cfa_exp,
00952                                  fs.regs.cfa_exp + fs.regs.cfa_exp_len,
00953                                  data);
00954       break;
00955 
00956     default:
00957       internal_error (__FILE__, __LINE__, _("Unknown CFA rule."));
00958     }
00959 }
00960 
00961 
00962 struct dwarf2_frame_cache
00963 {
00964   /* DWARF Call Frame Address.  */
00965   CORE_ADDR cfa;
00966 
00967   /* Set if the return address column was marked as unavailable
00968      (required non-collected memory or registers to compute).  */
00969   int unavailable_retaddr;
00970 
00971   /* Set if the return address column was marked as undefined.  */
00972   int undefined_retaddr;
00973 
00974   /* Saved registers, indexed by GDB register number, not by DWARF
00975      register number.  */
00976   struct dwarf2_frame_state_reg *reg;
00977 
00978   /* Return address register.  */
00979   struct dwarf2_frame_state_reg retaddr_reg;
00980 
00981   /* Target address size in bytes.  */
00982   int addr_size;
00983 
00984   /* The .text offset.  */
00985   CORE_ADDR text_offset;
00986 
00987   /* If not NULL then this frame is the bottom frame of a TAILCALL_FRAME
00988      sequence.  If NULL then it is a normal case with no TAILCALL_FRAME
00989      involved.  Non-bottom frames of a virtual tail call frames chain use
00990      dwarf2_tailcall_frame_unwind unwinder so this field does not apply for
00991      them.  */
00992   void *tailcall_cache;
00993 };
00994 
00995 /* A cleanup that sets a pointer to NULL.  */
00996 
00997 static void
00998 clear_pointer_cleanup (void *arg)
00999 {
01000   void **ptr = arg;
01001 
01002   *ptr = NULL;
01003 }
01004 
01005 static struct dwarf2_frame_cache *
01006 dwarf2_frame_cache (struct frame_info *this_frame, void **this_cache)
01007 {
01008   struct cleanup *reset_cache_cleanup, *old_chain;
01009   struct gdbarch *gdbarch = get_frame_arch (this_frame);
01010   const int num_regs = gdbarch_num_regs (gdbarch)
01011                        + gdbarch_num_pseudo_regs (gdbarch);
01012   struct dwarf2_frame_cache *cache;
01013   struct dwarf2_frame_state *fs;
01014   struct dwarf2_fde *fde;
01015   volatile struct gdb_exception ex;
01016   CORE_ADDR entry_pc;
01017   LONGEST entry_cfa_sp_offset;
01018   int entry_cfa_sp_offset_p = 0;
01019   const gdb_byte *instr;
01020 
01021   if (*this_cache)
01022     return *this_cache;
01023 
01024   /* Allocate a new cache.  */
01025   cache = FRAME_OBSTACK_ZALLOC (struct dwarf2_frame_cache);
01026   cache->reg = FRAME_OBSTACK_CALLOC (num_regs, struct dwarf2_frame_state_reg);
01027   *this_cache = cache;
01028   reset_cache_cleanup = make_cleanup (clear_pointer_cleanup, this_cache);
01029 
01030   /* Allocate and initialize the frame state.  */
01031   fs = XZALLOC (struct dwarf2_frame_state);
01032   old_chain = make_cleanup (dwarf2_frame_state_free, fs);
01033 
01034   /* Unwind the PC.
01035 
01036      Note that if the next frame is never supposed to return (i.e. a call
01037      to abort), the compiler might optimize away the instruction at
01038      its return address.  As a result the return address will
01039      point at some random instruction, and the CFI for that
01040      instruction is probably worthless to us.  GCC's unwinder solves
01041      this problem by substracting 1 from the return address to get an
01042      address in the middle of a presumed call instruction (or the
01043      instruction in the associated delay slot).  This should only be
01044      done for "normal" frames and not for resume-type frames (signal
01045      handlers, sentinel frames, dummy frames).  The function
01046      get_frame_address_in_block does just this.  It's not clear how
01047      reliable the method is though; there is the potential for the
01048      register state pre-call being different to that on return.  */
01049   fs->pc = get_frame_address_in_block (this_frame);
01050 
01051   /* Find the correct FDE.  */
01052   fde = dwarf2_frame_find_fde (&fs->pc, &cache->text_offset);
01053   gdb_assert (fde != NULL);
01054 
01055   /* Extract any interesting information from the CIE.  */
01056   fs->data_align = fde->cie->data_alignment_factor;
01057   fs->code_align = fde->cie->code_alignment_factor;
01058   fs->retaddr_column = fde->cie->return_address_register;
01059   cache->addr_size = fde->cie->addr_size;
01060 
01061   /* Check for "quirks" - known bugs in producers.  */
01062   dwarf2_frame_find_quirks (fs, fde);
01063 
01064   /* First decode all the insns in the CIE.  */
01065   execute_cfa_program (fde, fde->cie->initial_instructions,
01066                        fde->cie->end, gdbarch,
01067                        get_frame_address_in_block (this_frame), fs);
01068 
01069   /* Save the initialized register set.  */
01070   fs->initial = fs->regs;
01071   fs->initial.reg = dwarf2_frame_state_copy_regs (&fs->regs);
01072 
01073   if (get_frame_func_if_available (this_frame, &entry_pc))
01074     {
01075       /* Decode the insns in the FDE up to the entry PC.  */
01076       instr = execute_cfa_program (fde, fde->instructions, fde->end, gdbarch,
01077                                    entry_pc, fs);
01078 
01079       if (fs->regs.cfa_how == CFA_REG_OFFSET
01080           && (gdbarch_dwarf2_reg_to_regnum (gdbarch, fs->regs.cfa_reg)
01081               == gdbarch_sp_regnum (gdbarch)))
01082         {
01083           entry_cfa_sp_offset = fs->regs.cfa_offset;
01084           entry_cfa_sp_offset_p = 1;
01085         }
01086     }
01087   else
01088     instr = fde->instructions;
01089 
01090   /* Then decode the insns in the FDE up to our target PC.  */
01091   execute_cfa_program (fde, instr, fde->end, gdbarch,
01092                        get_frame_address_in_block (this_frame), fs);
01093 
01094   TRY_CATCH (ex, RETURN_MASK_ERROR)
01095     {
01096       /* Calculate the CFA.  */
01097       switch (fs->regs.cfa_how)
01098         {
01099         case CFA_REG_OFFSET:
01100           cache->cfa = read_reg (this_frame, fs->regs.cfa_reg);
01101           if (fs->armcc_cfa_offsets_reversed)
01102             cache->cfa -= fs->regs.cfa_offset;
01103           else
01104             cache->cfa += fs->regs.cfa_offset;
01105           break;
01106 
01107         case CFA_EXP:
01108           cache->cfa =
01109             execute_stack_op (fs->regs.cfa_exp, fs->regs.cfa_exp_len,
01110                               cache->addr_size, cache->text_offset,
01111                               this_frame, 0, 0);
01112           break;
01113 
01114         default:
01115           internal_error (__FILE__, __LINE__, _("Unknown CFA rule."));
01116         }
01117     }
01118   if (ex.reason < 0)
01119     {
01120       if (ex.error == NOT_AVAILABLE_ERROR)
01121         {
01122           cache->unavailable_retaddr = 1;
01123           do_cleanups (old_chain);
01124           discard_cleanups (reset_cache_cleanup);
01125           return cache;
01126         }
01127 
01128       throw_exception (ex);
01129     }
01130 
01131   /* Initialize the register state.  */
01132   {
01133     int regnum;
01134 
01135     for (regnum = 0; regnum < num_regs; regnum++)
01136       dwarf2_frame_init_reg (gdbarch, regnum, &cache->reg[regnum], this_frame);
01137   }
01138 
01139   /* Go through the DWARF2 CFI generated table and save its register
01140      location information in the cache.  Note that we don't skip the
01141      return address column; it's perfectly all right for it to
01142      correspond to a real register.  If it doesn't correspond to a
01143      real register, or if we shouldn't treat it as such,
01144      gdbarch_dwarf2_reg_to_regnum should be defined to return a number outside
01145      the range [0, gdbarch_num_regs).  */
01146   {
01147     int column;         /* CFI speak for "register number".  */
01148 
01149     for (column = 0; column < fs->regs.num_regs; column++)
01150       {
01151         /* Use the GDB register number as the destination index.  */
01152         int regnum = gdbarch_dwarf2_reg_to_regnum (gdbarch, column);
01153 
01154         /* If there's no corresponding GDB register, ignore it.  */
01155         if (regnum < 0 || regnum >= num_regs)
01156           continue;
01157 
01158         /* NOTE: cagney/2003-09-05: CFI should specify the disposition
01159            of all debug info registers.  If it doesn't, complain (but
01160            not too loudly).  It turns out that GCC assumes that an
01161            unspecified register implies "same value" when CFI (draft
01162            7) specifies nothing at all.  Such a register could equally
01163            be interpreted as "undefined".  Also note that this check
01164            isn't sufficient; it only checks that all registers in the
01165            range [0 .. max column] are specified, and won't detect
01166            problems when a debug info register falls outside of the
01167            table.  We need a way of iterating through all the valid
01168            DWARF2 register numbers.  */
01169         if (fs->regs.reg[column].how == DWARF2_FRAME_REG_UNSPECIFIED)
01170           {
01171             if (cache->reg[regnum].how == DWARF2_FRAME_REG_UNSPECIFIED)
01172               complaint (&symfile_complaints, _("\
01173 incomplete CFI data; unspecified registers (e.g., %s) at %s"),
01174                          gdbarch_register_name (gdbarch, regnum),
01175                          paddress (gdbarch, fs->pc));
01176           }
01177         else
01178           cache->reg[regnum] = fs->regs.reg[column];
01179       }
01180   }
01181 
01182   /* Eliminate any DWARF2_FRAME_REG_RA rules, and save the information
01183      we need for evaluating DWARF2_FRAME_REG_RA_OFFSET rules.  */
01184   {
01185     int regnum;
01186 
01187     for (regnum = 0; regnum < num_regs; regnum++)
01188       {
01189         if (cache->reg[regnum].how == DWARF2_FRAME_REG_RA
01190             || cache->reg[regnum].how == DWARF2_FRAME_REG_RA_OFFSET)
01191           {
01192             struct dwarf2_frame_state_reg *retaddr_reg =
01193               &fs->regs.reg[fs->retaddr_column];
01194 
01195             /* It seems rather bizarre to specify an "empty" column as
01196                the return adress column.  However, this is exactly
01197                what GCC does on some targets.  It turns out that GCC
01198                assumes that the return address can be found in the
01199                register corresponding to the return address column.
01200                Incidentally, that's how we should treat a return
01201                address column specifying "same value" too.  */
01202             if (fs->retaddr_column < fs->regs.num_regs
01203                 && retaddr_reg->how != DWARF2_FRAME_REG_UNSPECIFIED
01204                 && retaddr_reg->how != DWARF2_FRAME_REG_SAME_VALUE)
01205               {
01206                 if (cache->reg[regnum].how == DWARF2_FRAME_REG_RA)
01207                   cache->reg[regnum] = *retaddr_reg;
01208                 else
01209                   cache->retaddr_reg = *retaddr_reg;
01210               }
01211             else
01212               {
01213                 if (cache->reg[regnum].how == DWARF2_FRAME_REG_RA)
01214                   {
01215                     cache->reg[regnum].loc.reg = fs->retaddr_column;
01216                     cache->reg[regnum].how = DWARF2_FRAME_REG_SAVED_REG;
01217                   }
01218                 else
01219                   {
01220                     cache->retaddr_reg.loc.reg = fs->retaddr_column;
01221                     cache->retaddr_reg.how = DWARF2_FRAME_REG_SAVED_REG;
01222                   }
01223               }
01224           }
01225       }
01226   }
01227 
01228   if (fs->retaddr_column < fs->regs.num_regs
01229       && fs->regs.reg[fs->retaddr_column].how == DWARF2_FRAME_REG_UNDEFINED)
01230     cache->undefined_retaddr = 1;
01231 
01232   do_cleanups (old_chain);
01233 
01234   /* Try to find a virtual tail call frames chain with bottom (callee) frame
01235      starting at THIS_FRAME.  */
01236   dwarf2_tailcall_sniffer_first (this_frame, &cache->tailcall_cache,
01237                                  (entry_cfa_sp_offset_p
01238                                   ? &entry_cfa_sp_offset : NULL));
01239 
01240   discard_cleanups (reset_cache_cleanup);
01241   return cache;
01242 }
01243 
01244 static enum unwind_stop_reason
01245 dwarf2_frame_unwind_stop_reason (struct frame_info *this_frame,
01246                                  void **this_cache)
01247 {
01248   struct dwarf2_frame_cache *cache
01249     = dwarf2_frame_cache (this_frame, this_cache);
01250 
01251   if (cache->unavailable_retaddr)
01252     return UNWIND_UNAVAILABLE;
01253 
01254   if (cache->undefined_retaddr)
01255     return UNWIND_OUTERMOST;
01256 
01257   return UNWIND_NO_REASON;
01258 }
01259 
01260 static void
01261 dwarf2_frame_this_id (struct frame_info *this_frame, void **this_cache,
01262                       struct frame_id *this_id)
01263 {
01264   struct dwarf2_frame_cache *cache =
01265     dwarf2_frame_cache (this_frame, this_cache);
01266 
01267   if (cache->unavailable_retaddr)
01268     return;
01269 
01270   if (cache->undefined_retaddr)
01271     return;
01272 
01273   (*this_id) = frame_id_build (cache->cfa, get_frame_func (this_frame));
01274 }
01275 
01276 static struct value *
01277 dwarf2_frame_prev_register (struct frame_info *this_frame, void **this_cache,
01278                             int regnum)
01279 {
01280   struct gdbarch *gdbarch = get_frame_arch (this_frame);
01281   struct dwarf2_frame_cache *cache =
01282     dwarf2_frame_cache (this_frame, this_cache);
01283   CORE_ADDR addr;
01284   int realnum;
01285 
01286   /* Non-bottom frames of a virtual tail call frames chain use
01287      dwarf2_tailcall_frame_unwind unwinder so this code does not apply for
01288      them.  If dwarf2_tailcall_prev_register_first does not have specific value
01289      unwind the register, tail call frames are assumed to have the register set
01290      of the top caller.  */
01291   if (cache->tailcall_cache)
01292     {
01293       struct value *val;
01294       
01295       val = dwarf2_tailcall_prev_register_first (this_frame,
01296                                                  &cache->tailcall_cache,
01297                                                  regnum);
01298       if (val)
01299         return val;
01300     }
01301 
01302   switch (cache->reg[regnum].how)
01303     {
01304     case DWARF2_FRAME_REG_UNDEFINED:
01305       /* If CFI explicitly specified that the value isn't defined,
01306          mark it as optimized away; the value isn't available.  */
01307       return frame_unwind_got_optimized (this_frame, regnum);
01308 
01309     case DWARF2_FRAME_REG_SAVED_OFFSET:
01310       addr = cache->cfa + cache->reg[regnum].loc.offset;
01311       return frame_unwind_got_memory (this_frame, regnum, addr);
01312 
01313     case DWARF2_FRAME_REG_SAVED_REG:
01314       realnum
01315         = gdbarch_dwarf2_reg_to_regnum (gdbarch, cache->reg[regnum].loc.reg);
01316       return frame_unwind_got_register (this_frame, regnum, realnum);
01317 
01318     case DWARF2_FRAME_REG_SAVED_EXP:
01319       addr = execute_stack_op (cache->reg[regnum].loc.exp,
01320                                cache->reg[regnum].exp_len,
01321                                cache->addr_size, cache->text_offset,
01322                                this_frame, cache->cfa, 1);
01323       return frame_unwind_got_memory (this_frame, regnum, addr);
01324 
01325     case DWARF2_FRAME_REG_SAVED_VAL_OFFSET:
01326       addr = cache->cfa + cache->reg[regnum].loc.offset;
01327       return frame_unwind_got_constant (this_frame, regnum, addr);
01328 
01329     case DWARF2_FRAME_REG_SAVED_VAL_EXP:
01330       addr = execute_stack_op (cache->reg[regnum].loc.exp,
01331                                cache->reg[regnum].exp_len,
01332                                cache->addr_size, cache->text_offset,
01333                                this_frame, cache->cfa, 1);
01334       return frame_unwind_got_constant (this_frame, regnum, addr);
01335 
01336     case DWARF2_FRAME_REG_UNSPECIFIED:
01337       /* GCC, in its infinite wisdom decided to not provide unwind
01338          information for registers that are "same value".  Since
01339          DWARF2 (3 draft 7) doesn't define such behavior, said
01340          registers are actually undefined (which is different to CFI
01341          "undefined").  Code above issues a complaint about this.
01342          Here just fudge the books, assume GCC, and that the value is
01343          more inner on the stack.  */
01344       return frame_unwind_got_register (this_frame, regnum, regnum);
01345 
01346     case DWARF2_FRAME_REG_SAME_VALUE:
01347       return frame_unwind_got_register (this_frame, regnum, regnum);
01348 
01349     case DWARF2_FRAME_REG_CFA:
01350       return frame_unwind_got_address (this_frame, regnum, cache->cfa);
01351 
01352     case DWARF2_FRAME_REG_CFA_OFFSET:
01353       addr = cache->cfa + cache->reg[regnum].loc.offset;
01354       return frame_unwind_got_address (this_frame, regnum, addr);
01355 
01356     case DWARF2_FRAME_REG_RA_OFFSET:
01357       addr = cache->reg[regnum].loc.offset;
01358       regnum = gdbarch_dwarf2_reg_to_regnum
01359         (gdbarch, cache->retaddr_reg.loc.reg);
01360       addr += get_frame_register_unsigned (this_frame, regnum);
01361       return frame_unwind_got_address (this_frame, regnum, addr);
01362 
01363     case DWARF2_FRAME_REG_FN:
01364       return cache->reg[regnum].loc.fn (this_frame, this_cache, regnum);
01365 
01366     default:
01367       internal_error (__FILE__, __LINE__, _("Unknown register rule."));
01368     }
01369 }
01370 
01371 /* Proxy for tailcall_frame_dealloc_cache for bottom frame of a virtual tail
01372    call frames chain.  */
01373 
01374 static void
01375 dwarf2_frame_dealloc_cache (struct frame_info *self, void *this_cache)
01376 {
01377   struct dwarf2_frame_cache *cache = dwarf2_frame_cache (self, &this_cache);
01378 
01379   if (cache->tailcall_cache)
01380     dwarf2_tailcall_frame_unwind.dealloc_cache (self, cache->tailcall_cache);
01381 }
01382 
01383 static int
01384 dwarf2_frame_sniffer (const struct frame_unwind *self,
01385                       struct frame_info *this_frame, void **this_cache)
01386 {
01387   /* Grab an address that is guarenteed to reside somewhere within the
01388      function.  get_frame_pc(), with a no-return next function, can
01389      end up returning something past the end of this function's body.
01390      If the frame we're sniffing for is a signal frame whose start
01391      address is placed on the stack by the OS, its FDE must
01392      extend one byte before its start address or we could potentially
01393      select the FDE of the previous function.  */
01394   CORE_ADDR block_addr = get_frame_address_in_block (this_frame);
01395   struct dwarf2_fde *fde = dwarf2_frame_find_fde (&block_addr, NULL);
01396 
01397   if (!fde)
01398     return 0;
01399 
01400   /* On some targets, signal trampolines may have unwind information.
01401      We need to recognize them so that we set the frame type
01402      correctly.  */
01403 
01404   if (fde->cie->signal_frame
01405       || dwarf2_frame_signal_frame_p (get_frame_arch (this_frame),
01406                                       this_frame))
01407     return self->type == SIGTRAMP_FRAME;
01408 
01409   if (self->type != NORMAL_FRAME)
01410     return 0;
01411 
01412   /* Preinitializa the cache so that TAILCALL_FRAME can find the record by
01413      dwarf2_tailcall_sniffer_first.  */
01414   dwarf2_frame_cache (this_frame, this_cache);
01415 
01416   return 1;
01417 }
01418 
01419 static const struct frame_unwind dwarf2_frame_unwind =
01420 {
01421   NORMAL_FRAME,
01422   dwarf2_frame_unwind_stop_reason,
01423   dwarf2_frame_this_id,
01424   dwarf2_frame_prev_register,
01425   NULL,
01426   dwarf2_frame_sniffer,
01427   dwarf2_frame_dealloc_cache
01428 };
01429 
01430 static const struct frame_unwind dwarf2_signal_frame_unwind =
01431 {
01432   SIGTRAMP_FRAME,
01433   dwarf2_frame_unwind_stop_reason,
01434   dwarf2_frame_this_id,
01435   dwarf2_frame_prev_register,
01436   NULL,
01437   dwarf2_frame_sniffer,
01438 
01439   /* TAILCALL_CACHE can never be in such frame to need dealloc_cache.  */
01440   NULL
01441 };
01442 
01443 /* Append the DWARF-2 frame unwinders to GDBARCH's list.  */
01444 
01445 void
01446 dwarf2_append_unwinders (struct gdbarch *gdbarch)
01447 {
01448   /* TAILCALL_FRAME must be first to find the record by
01449      dwarf2_tailcall_sniffer_first.  */
01450   frame_unwind_append_unwinder (gdbarch, &dwarf2_tailcall_frame_unwind);
01451 
01452   frame_unwind_append_unwinder (gdbarch, &dwarf2_frame_unwind);
01453   frame_unwind_append_unwinder (gdbarch, &dwarf2_signal_frame_unwind);
01454 }
01455 
01456 
01457 /* There is no explicitly defined relationship between the CFA and the
01458    location of frame's local variables and arguments/parameters.
01459    Therefore, frame base methods on this page should probably only be
01460    used as a last resort, just to avoid printing total garbage as a
01461    response to the "info frame" command.  */
01462 
01463 static CORE_ADDR
01464 dwarf2_frame_base_address (struct frame_info *this_frame, void **this_cache)
01465 {
01466   struct dwarf2_frame_cache *cache =
01467     dwarf2_frame_cache (this_frame, this_cache);
01468 
01469   return cache->cfa;
01470 }
01471 
01472 static const struct frame_base dwarf2_frame_base =
01473 {
01474   &dwarf2_frame_unwind,
01475   dwarf2_frame_base_address,
01476   dwarf2_frame_base_address,
01477   dwarf2_frame_base_address
01478 };
01479 
01480 const struct frame_base *
01481 dwarf2_frame_base_sniffer (struct frame_info *this_frame)
01482 {
01483   CORE_ADDR block_addr = get_frame_address_in_block (this_frame);
01484 
01485   if (dwarf2_frame_find_fde (&block_addr, NULL))
01486     return &dwarf2_frame_base;
01487 
01488   return NULL;
01489 }
01490 
01491 /* Compute the CFA for THIS_FRAME, but only if THIS_FRAME came from
01492    the DWARF unwinder.  This is used to implement
01493    DW_OP_call_frame_cfa.  */
01494 
01495 CORE_ADDR
01496 dwarf2_frame_cfa (struct frame_info *this_frame)
01497 {
01498   while (get_frame_type (this_frame) == INLINE_FRAME)
01499     this_frame = get_prev_frame (this_frame);
01500   /* This restriction could be lifted if other unwinders are known to
01501      compute the frame base in a way compatible with the DWARF
01502      unwinder.  */
01503   if (!frame_unwinder_is (this_frame, &dwarf2_frame_unwind)
01504       && !frame_unwinder_is (this_frame, &dwarf2_tailcall_frame_unwind))
01505     error (_("can't compute CFA for this frame"));
01506   if (get_frame_unwind_stop_reason (this_frame) == UNWIND_UNAVAILABLE)
01507     throw_error (NOT_AVAILABLE_ERROR,
01508                  _("can't compute CFA for this frame: "
01509                    "required registers or memory are unavailable"));
01510   return get_frame_base (this_frame);
01511 }
01512 
01513 const struct objfile_data *dwarf2_frame_objfile_data;
01514 
01515 static unsigned int
01516 read_1_byte (bfd *abfd, const gdb_byte *buf)
01517 {
01518   return bfd_get_8 (abfd, buf);
01519 }
01520 
01521 static unsigned int
01522 read_4_bytes (bfd *abfd, const gdb_byte *buf)
01523 {
01524   return bfd_get_32 (abfd, buf);
01525 }
01526 
01527 static ULONGEST
01528 read_8_bytes (bfd *abfd, const gdb_byte *buf)
01529 {
01530   return bfd_get_64 (abfd, buf);
01531 }
01532 
01533 static ULONGEST
01534 read_initial_length (bfd *abfd, const gdb_byte *buf,
01535                      unsigned int *bytes_read_ptr)
01536 {
01537   LONGEST result;
01538 
01539   result = bfd_get_32 (abfd, buf);
01540   if (result == 0xffffffff)
01541     {
01542       result = bfd_get_64 (abfd, buf + 4);
01543       *bytes_read_ptr = 12;
01544     }
01545   else
01546     *bytes_read_ptr = 4;
01547 
01548   return result;
01549 }
01550 
01551 
01552 /* Pointer encoding helper functions.  */
01553 
01554 /* GCC supports exception handling based on DWARF2 CFI.  However, for
01555    technical reasons, it encodes addresses in its FDE's in a different
01556    way.  Several "pointer encodings" are supported.  The encoding
01557    that's used for a particular FDE is determined by the 'R'
01558    augmentation in the associated CIE.  The argument of this
01559    augmentation is a single byte.  
01560 
01561    The address can be encoded as 2 bytes, 4 bytes, 8 bytes, or as a
01562    LEB128.  This is encoded in bits 0, 1 and 2.  Bit 3 encodes whether
01563    the address is signed or unsigned.  Bits 4, 5 and 6 encode how the
01564    address should be interpreted (absolute, relative to the current
01565    position in the FDE, ...).  Bit 7, indicates that the address
01566    should be dereferenced.  */
01567 
01568 static gdb_byte
01569 encoding_for_size (unsigned int size)
01570 {
01571   switch (size)
01572     {
01573     case 2:
01574       return DW_EH_PE_udata2;
01575     case 4:
01576       return DW_EH_PE_udata4;
01577     case 8:
01578       return DW_EH_PE_udata8;
01579     default:
01580       internal_error (__FILE__, __LINE__, _("Unsupported address size"));
01581     }
01582 }
01583 
01584 static CORE_ADDR
01585 read_encoded_value (struct comp_unit *unit, gdb_byte encoding,
01586                     int ptr_len, const gdb_byte *buf,
01587                     unsigned int *bytes_read_ptr,
01588                     CORE_ADDR func_base)
01589 {
01590   ptrdiff_t offset;
01591   CORE_ADDR base;
01592 
01593   /* GCC currently doesn't generate DW_EH_PE_indirect encodings for
01594      FDE's.  */
01595   if (encoding & DW_EH_PE_indirect)
01596     internal_error (__FILE__, __LINE__, 
01597                     _("Unsupported encoding: DW_EH_PE_indirect"));
01598 
01599   *bytes_read_ptr = 0;
01600 
01601   switch (encoding & 0x70)
01602     {
01603     case DW_EH_PE_absptr:
01604       base = 0;
01605       break;
01606     case DW_EH_PE_pcrel:
01607       base = bfd_get_section_vma (unit->abfd, unit->dwarf_frame_section);
01608       base += (buf - unit->dwarf_frame_buffer);
01609       break;
01610     case DW_EH_PE_datarel:
01611       base = unit->dbase;
01612       break;
01613     case DW_EH_PE_textrel:
01614       base = unit->tbase;
01615       break;
01616     case DW_EH_PE_funcrel:
01617       base = func_base;
01618       break;
01619     case DW_EH_PE_aligned:
01620       base = 0;
01621       offset = buf - unit->dwarf_frame_buffer;
01622       if ((offset % ptr_len) != 0)
01623         {
01624           *bytes_read_ptr = ptr_len - (offset % ptr_len);
01625           buf += *bytes_read_ptr;
01626         }
01627       break;
01628     default:
01629       internal_error (__FILE__, __LINE__,
01630                       _("Invalid or unsupported encoding"));
01631     }
01632 
01633   if ((encoding & 0x07) == 0x00)
01634     {
01635       encoding |= encoding_for_size (ptr_len);
01636       if (bfd_get_sign_extend_vma (unit->abfd))
01637         encoding |= DW_EH_PE_signed;
01638     }
01639 
01640   switch (encoding & 0x0f)
01641     {
01642     case DW_EH_PE_uleb128:
01643       {
01644         uint64_t value;
01645         const gdb_byte *end_buf = buf + (sizeof (value) + 1) * 8 / 7;
01646 
01647         *bytes_read_ptr += safe_read_uleb128 (buf, end_buf, &value) - buf;
01648         return base + value;
01649       }
01650     case DW_EH_PE_udata2:
01651       *bytes_read_ptr += 2;
01652       return (base + bfd_get_16 (unit->abfd, (bfd_byte *) buf));
01653     case DW_EH_PE_udata4:
01654       *bytes_read_ptr += 4;
01655       return (base + bfd_get_32 (unit->abfd, (bfd_byte *) buf));
01656     case DW_EH_PE_udata8:
01657       *bytes_read_ptr += 8;
01658       return (base + bfd_get_64 (unit->abfd, (bfd_byte *) buf));
01659     case DW_EH_PE_sleb128:
01660       {
01661         int64_t value;
01662         const gdb_byte *end_buf = buf + (sizeof (value) + 1) * 8 / 7;
01663 
01664         *bytes_read_ptr += safe_read_sleb128 (buf, end_buf, &value) - buf;
01665         return base + value;
01666       }
01667     case DW_EH_PE_sdata2:
01668       *bytes_read_ptr += 2;
01669       return (base + bfd_get_signed_16 (unit->abfd, (bfd_byte *) buf));
01670     case DW_EH_PE_sdata4:
01671       *bytes_read_ptr += 4;
01672       return (base + bfd_get_signed_32 (unit->abfd, (bfd_byte *) buf));
01673     case DW_EH_PE_sdata8:
01674       *bytes_read_ptr += 8;
01675       return (base + bfd_get_signed_64 (unit->abfd, (bfd_byte *) buf));
01676     default:
01677       internal_error (__FILE__, __LINE__,
01678                       _("Invalid or unsupported encoding"));
01679     }
01680 }
01681 
01682 
01683 static int
01684 bsearch_cie_cmp (const void *key, const void *element)
01685 {
01686   ULONGEST cie_pointer = *(ULONGEST *) key;
01687   struct dwarf2_cie *cie = *(struct dwarf2_cie **) element;
01688 
01689   if (cie_pointer == cie->cie_pointer)
01690     return 0;
01691 
01692   return (cie_pointer < cie->cie_pointer) ? -1 : 1;
01693 }
01694 
01695 /* Find CIE with the given CIE_POINTER in CIE_TABLE.  */
01696 static struct dwarf2_cie *
01697 find_cie (struct dwarf2_cie_table *cie_table, ULONGEST cie_pointer)
01698 {
01699   struct dwarf2_cie **p_cie;
01700 
01701   /* The C standard (ISO/IEC 9899:TC2) requires the BASE argument to
01702      bsearch be non-NULL.  */
01703   if (cie_table->entries == NULL)
01704     {
01705       gdb_assert (cie_table->num_entries == 0);
01706       return NULL;
01707     }
01708 
01709   p_cie = bsearch (&cie_pointer, cie_table->entries, cie_table->num_entries,
01710                    sizeof (cie_table->entries[0]), bsearch_cie_cmp);
01711   if (p_cie != NULL)
01712     return *p_cie;
01713   return NULL;
01714 }
01715 
01716 /* Add a pointer to new CIE to the CIE_TABLE, allocating space for it.  */
01717 static void
01718 add_cie (struct dwarf2_cie_table *cie_table, struct dwarf2_cie *cie)
01719 {
01720   const int n = cie_table->num_entries;
01721 
01722   gdb_assert (n < 1
01723               || cie_table->entries[n - 1]->cie_pointer < cie->cie_pointer);
01724 
01725   cie_table->entries =
01726       xrealloc (cie_table->entries, (n + 1) * sizeof (cie_table->entries[0]));
01727   cie_table->entries[n] = cie;
01728   cie_table->num_entries = n + 1;
01729 }
01730 
01731 static int
01732 bsearch_fde_cmp (const void *key, const void *element)
01733 {
01734   CORE_ADDR seek_pc = *(CORE_ADDR *) key;
01735   struct dwarf2_fde *fde = *(struct dwarf2_fde **) element;
01736 
01737   if (seek_pc < fde->initial_location)
01738     return -1;
01739   if (seek_pc < fde->initial_location + fde->address_range)
01740     return 0;
01741   return 1;
01742 }
01743 
01744 /* Find the FDE for *PC.  Return a pointer to the FDE, and store the
01745    inital location associated with it into *PC.  */
01746 
01747 static struct dwarf2_fde *
01748 dwarf2_frame_find_fde (CORE_ADDR *pc, CORE_ADDR *out_offset)
01749 {
01750   struct objfile *objfile;
01751 
01752   ALL_OBJFILES (objfile)
01753     {
01754       struct dwarf2_fde_table *fde_table;
01755       struct dwarf2_fde **p_fde;
01756       CORE_ADDR offset;
01757       CORE_ADDR seek_pc;
01758 
01759       fde_table = objfile_data (objfile, dwarf2_frame_objfile_data);
01760       if (fde_table == NULL)
01761         {
01762           dwarf2_build_frame_info (objfile);
01763           fde_table = objfile_data (objfile, dwarf2_frame_objfile_data);
01764         }
01765       gdb_assert (fde_table != NULL);
01766 
01767       if (fde_table->num_entries == 0)
01768         continue;
01769 
01770       gdb_assert (objfile->section_offsets);
01771       offset = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
01772 
01773       gdb_assert (fde_table->num_entries > 0);
01774       if (*pc < offset + fde_table->entries[0]->initial_location)
01775         continue;
01776 
01777       seek_pc = *pc - offset;
01778       p_fde = bsearch (&seek_pc, fde_table->entries, fde_table->num_entries,
01779                        sizeof (fde_table->entries[0]), bsearch_fde_cmp);
01780       if (p_fde != NULL)
01781         {
01782           *pc = (*p_fde)->initial_location + offset;
01783           if (out_offset)
01784             *out_offset = offset;
01785           return *p_fde;
01786         }
01787     }
01788   return NULL;
01789 }
01790 
01791 /* Add a pointer to new FDE to the FDE_TABLE, allocating space for it.  */
01792 static void
01793 add_fde (struct dwarf2_fde_table *fde_table, struct dwarf2_fde *fde)
01794 {
01795   if (fde->address_range == 0)
01796     /* Discard useless FDEs.  */
01797     return;
01798 
01799   fde_table->num_entries += 1;
01800   fde_table->entries =
01801       xrealloc (fde_table->entries,
01802                 fde_table->num_entries * sizeof (fde_table->entries[0]));
01803   fde_table->entries[fde_table->num_entries - 1] = fde;
01804 }
01805 
01806 #define DW64_CIE_ID 0xffffffffffffffffULL
01807 
01808 /* Defines the type of eh_frames that are expected to be decoded: CIE, FDE
01809    or any of them.  */
01810 
01811 enum eh_frame_type
01812 {
01813   EH_CIE_TYPE_ID = 1 << 0,
01814   EH_FDE_TYPE_ID = 1 << 1,
01815   EH_CIE_OR_FDE_TYPE_ID = EH_CIE_TYPE_ID | EH_FDE_TYPE_ID
01816 };
01817 
01818 static const gdb_byte *decode_frame_entry (struct comp_unit *unit,
01819                                            const gdb_byte *start,
01820                                            int eh_frame_p,
01821                                            struct dwarf2_cie_table *cie_table,
01822                                            struct dwarf2_fde_table *fde_table,
01823                                            enum eh_frame_type entry_type);
01824 
01825 /* Decode the next CIE or FDE, entry_type specifies the expected type.
01826    Return NULL if invalid input, otherwise the next byte to be processed.  */
01827 
01828 static const gdb_byte *
01829 decode_frame_entry_1 (struct comp_unit *unit, const gdb_byte *start,
01830                       int eh_frame_p,
01831                       struct dwarf2_cie_table *cie_table,
01832                       struct dwarf2_fde_table *fde_table,
01833                       enum eh_frame_type entry_type)
01834 {
01835   struct gdbarch *gdbarch = get_objfile_arch (unit->objfile);
01836   const gdb_byte *buf, *end;
01837   LONGEST length;
01838   unsigned int bytes_read;
01839   int dwarf64_p;
01840   ULONGEST cie_id;
01841   ULONGEST cie_pointer;
01842   int64_t sleb128;
01843   uint64_t uleb128;
01844 
01845   buf = start;
01846   length = read_initial_length (unit->abfd, buf, &bytes_read);
01847   buf += bytes_read;
01848   end = buf + length;
01849 
01850   /* Are we still within the section?  */
01851   if (end > unit->dwarf_frame_buffer + unit->dwarf_frame_size)
01852     return NULL;
01853 
01854   if (length == 0)
01855     return end;
01856 
01857   /* Distinguish between 32 and 64-bit encoded frame info.  */
01858   dwarf64_p = (bytes_read == 12);
01859 
01860   /* In a .eh_frame section, zero is used to distinguish CIEs from FDEs.  */
01861   if (eh_frame_p)
01862     cie_id = 0;
01863   else if (dwarf64_p)
01864     cie_id = DW64_CIE_ID;
01865   else
01866     cie_id = DW_CIE_ID;
01867 
01868   if (dwarf64_p)
01869     {
01870       cie_pointer = read_8_bytes (unit->abfd, buf);
01871       buf += 8;
01872     }
01873   else
01874     {
01875       cie_pointer = read_4_bytes (unit->abfd, buf);
01876       buf += 4;
01877     }
01878 
01879   if (cie_pointer == cie_id)
01880     {
01881       /* This is a CIE.  */
01882       struct dwarf2_cie *cie;
01883       char *augmentation;
01884       unsigned int cie_version;
01885 
01886       /* Check that a CIE was expected.  */
01887       if ((entry_type & EH_CIE_TYPE_ID) == 0)
01888         error (_("Found a CIE when not expecting it."));
01889 
01890       /* Record the offset into the .debug_frame section of this CIE.  */
01891       cie_pointer = start - unit->dwarf_frame_buffer;
01892 
01893       /* Check whether we've already read it.  */
01894       if (find_cie (cie_table, cie_pointer))
01895         return end;
01896 
01897       cie = (struct dwarf2_cie *)
01898         obstack_alloc (&unit->objfile->objfile_obstack,
01899                        sizeof (struct dwarf2_cie));
01900       cie->initial_instructions = NULL;
01901       cie->cie_pointer = cie_pointer;
01902 
01903       /* The encoding for FDE's in a normal .debug_frame section
01904          depends on the target address size.  */
01905       cie->encoding = DW_EH_PE_absptr;
01906 
01907       /* We'll determine the final value later, but we need to
01908          initialize it conservatively.  */
01909       cie->signal_frame = 0;
01910 
01911       /* Check version number.  */
01912       cie_version = read_1_byte (unit->abfd, buf);
01913       if (cie_version != 1 && cie_version != 3 && cie_version != 4)
01914         return NULL;
01915       cie->version = cie_version;
01916       buf += 1;
01917 
01918       /* Interpret the interesting bits of the augmentation.  */
01919       cie->augmentation = augmentation = (char *) buf;
01920       buf += (strlen (augmentation) + 1);
01921 
01922       /* Ignore armcc augmentations.  We only use them for quirks,
01923          and that doesn't happen until later.  */
01924       if (strncmp (augmentation, "armcc", 5) == 0)
01925         augmentation += strlen (augmentation);
01926 
01927       /* The GCC 2.x "eh" augmentation has a pointer immediately
01928          following the augmentation string, so it must be handled
01929          first.  */
01930       if (augmentation[0] == 'e' && augmentation[1] == 'h')
01931         {
01932           /* Skip.  */
01933           buf += gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT;
01934           augmentation += 2;
01935         }
01936 
01937       if (cie->version >= 4)
01938         {
01939           /* FIXME: check that this is the same as from the CU header.  */
01940           cie->addr_size = read_1_byte (unit->abfd, buf);
01941           ++buf;
01942           cie->segment_size = read_1_byte (unit->abfd, buf);
01943           ++buf;
01944         }
01945       else
01946         {
01947           cie->addr_size = gdbarch_dwarf2_addr_size (gdbarch);
01948           cie->segment_size = 0;
01949         }
01950       /* Address values in .eh_frame sections are defined to have the
01951          target's pointer size.  Watchout: This breaks frame info for
01952          targets with pointer size < address size, unless a .debug_frame
01953          section exists as well.  */
01954       if (eh_frame_p)
01955         cie->ptr_size = gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT;
01956       else
01957         cie->ptr_size = cie->addr_size;
01958 
01959       buf = gdb_read_uleb128 (buf, end, &uleb128);
01960       if (buf == NULL)
01961         return NULL;
01962       cie->code_alignment_factor = uleb128;
01963 
01964       buf = gdb_read_sleb128 (buf, end, &sleb128);
01965       if (buf == NULL)
01966         return NULL;
01967       cie->data_alignment_factor = sleb128;
01968 
01969       if (cie_version == 1)
01970         {
01971           cie->return_address_register = read_1_byte (unit->abfd, buf);
01972           ++buf;
01973         }
01974       else
01975         {
01976           buf = gdb_read_uleb128 (buf, end, &uleb128);
01977           if (buf == NULL)
01978             return NULL;
01979           cie->return_address_register = uleb128;
01980         }
01981 
01982       cie->return_address_register
01983         = dwarf2_frame_adjust_regnum (gdbarch,
01984                                       cie->return_address_register,
01985                                       eh_frame_p);
01986 
01987       cie->saw_z_augmentation = (*augmentation == 'z');
01988       if (cie->saw_z_augmentation)
01989         {
01990           uint64_t length;
01991 
01992           buf = gdb_read_uleb128 (buf, end, &length);
01993           if (buf == NULL)
01994             return NULL;
01995           cie->initial_instructions = buf + length;
01996           augmentation++;
01997         }
01998 
01999       while (*augmentation)
02000         {
02001           /* "L" indicates a byte showing how the LSDA pointer is encoded.  */
02002           if (*augmentation == 'L')
02003             {
02004               /* Skip.  */
02005               buf++;
02006               augmentation++;
02007             }
02008 
02009           /* "R" indicates a byte indicating how FDE addresses are encoded.  */
02010           else if (*augmentation == 'R')
02011             {
02012               cie->encoding = *buf++;
02013               augmentation++;
02014             }
02015 
02016           /* "P" indicates a personality routine in the CIE augmentation.  */
02017           else if (*augmentation == 'P')
02018             {
02019               /* Skip.  Avoid indirection since we throw away the result.  */
02020               gdb_byte encoding = (*buf++) & ~DW_EH_PE_indirect;
02021               read_encoded_value (unit, encoding, cie->ptr_size,
02022                                   buf, &bytes_read, 0);
02023               buf += bytes_read;
02024               augmentation++;
02025             }
02026 
02027           /* "S" indicates a signal frame, such that the return
02028              address must not be decremented to locate the call frame
02029              info for the previous frame; it might even be the first
02030              instruction of a function, so decrementing it would take
02031              us to a different function.  */
02032           else if (*augmentation == 'S')
02033             {
02034               cie->signal_frame = 1;
02035               augmentation++;
02036             }
02037 
02038           /* Otherwise we have an unknown augmentation.  Assume that either
02039              there is no augmentation data, or we saw a 'z' prefix.  */
02040           else
02041             {
02042               if (cie->initial_instructions)
02043                 buf = cie->initial_instructions;
02044               break;
02045             }
02046         }
02047 
02048       cie->initial_instructions = buf;
02049       cie->end = end;
02050       cie->unit = unit;
02051 
02052       add_cie (cie_table, cie);
02053     }
02054   else
02055     {
02056       /* This is a FDE.  */
02057       struct dwarf2_fde *fde;
02058 
02059       /* Check that an FDE was expected.  */
02060       if ((entry_type & EH_FDE_TYPE_ID) == 0)
02061         error (_("Found an FDE when not expecting it."));
02062 
02063       /* In an .eh_frame section, the CIE pointer is the delta between the
02064          address within the FDE where the CIE pointer is stored and the
02065          address of the CIE.  Convert it to an offset into the .eh_frame
02066          section.  */
02067       if (eh_frame_p)
02068         {
02069           cie_pointer = buf - unit->dwarf_frame_buffer - cie_pointer;
02070           cie_pointer -= (dwarf64_p ? 8 : 4);
02071         }
02072 
02073       /* In either case, validate the result is still within the section.  */
02074       if (cie_pointer >= unit->dwarf_frame_size)
02075         return NULL;
02076 
02077       fde = (struct dwarf2_fde *)
02078         obstack_alloc (&unit->objfile->objfile_obstack,
02079                        sizeof (struct dwarf2_fde));
02080       fde->cie = find_cie (cie_table, cie_pointer);
02081       if (fde->cie == NULL)
02082         {
02083           decode_frame_entry (unit, unit->dwarf_frame_buffer + cie_pointer,
02084                               eh_frame_p, cie_table, fde_table,
02085                               EH_CIE_TYPE_ID);
02086           fde->cie = find_cie (cie_table, cie_pointer);
02087         }
02088 
02089       gdb_assert (fde->cie != NULL);
02090 
02091       fde->initial_location =
02092         read_encoded_value (unit, fde->cie->encoding, fde->cie->ptr_size,
02093                             buf, &bytes_read, 0);
02094       buf += bytes_read;
02095 
02096       fde->address_range =
02097         read_encoded_value (unit, fde->cie->encoding & 0x0f,
02098                             fde->cie->ptr_size, buf, &bytes_read, 0);
02099       buf += bytes_read;
02100 
02101       /* A 'z' augmentation in the CIE implies the presence of an
02102          augmentation field in the FDE as well.  The only thing known
02103          to be in here at present is the LSDA entry for EH.  So we
02104          can skip the whole thing.  */
02105       if (fde->cie->saw_z_augmentation)
02106         {
02107           uint64_t length;
02108 
02109           buf = gdb_read_uleb128 (buf, end, &length);
02110           if (buf == NULL)
02111             return NULL;
02112           buf += length;
02113           if (buf > end)
02114             return NULL;
02115         }
02116 
02117       fde->instructions = buf;
02118       fde->end = end;
02119 
02120       fde->eh_frame_p = eh_frame_p;
02121 
02122       add_fde (fde_table, fde);
02123     }
02124 
02125   return end;
02126 }
02127 
02128 /* Read a CIE or FDE in BUF and decode it. Entry_type specifies whether we
02129    expect an FDE or a CIE.  */
02130 
02131 static const gdb_byte *
02132 decode_frame_entry (struct comp_unit *unit, const gdb_byte *start,
02133                     int eh_frame_p,
02134                     struct dwarf2_cie_table *cie_table,
02135                     struct dwarf2_fde_table *fde_table,
02136                     enum eh_frame_type entry_type)
02137 {
02138   enum { NONE, ALIGN4, ALIGN8, FAIL } workaround = NONE;
02139   const gdb_byte *ret;
02140   ptrdiff_t start_offset;
02141 
02142   while (1)
02143     {
02144       ret = decode_frame_entry_1 (unit, start, eh_frame_p,
02145                                   cie_table, fde_table, entry_type);
02146       if (ret != NULL)
02147         break;
02148 
02149       /* We have corrupt input data of some form.  */
02150 
02151       /* ??? Try, weakly, to work around compiler/assembler/linker bugs
02152          and mismatches wrt padding and alignment of debug sections.  */
02153       /* Note that there is no requirement in the standard for any
02154          alignment at all in the frame unwind sections.  Testing for
02155          alignment before trying to interpret data would be incorrect.
02156 
02157          However, GCC traditionally arranged for frame sections to be
02158          sized such that the FDE length and CIE fields happen to be
02159          aligned (in theory, for performance).  This, unfortunately,
02160          was done with .align directives, which had the side effect of
02161          forcing the section to be aligned by the linker.
02162 
02163          This becomes a problem when you have some other producer that
02164          creates frame sections that are not as strictly aligned.  That
02165          produces a hole in the frame info that gets filled by the 
02166          linker with zeros.
02167 
02168          The GCC behaviour is arguably a bug, but it's effectively now
02169          part of the ABI, so we're now stuck with it, at least at the
02170          object file level.  A smart linker may decide, in the process
02171          of compressing duplicate CIE information, that it can rewrite
02172          the entire output section without this extra padding.  */
02173 
02174       start_offset = start - unit->dwarf_frame_buffer;
02175       if (workaround < ALIGN4 && (start_offset & 3) != 0)
02176         {
02177           start += 4 - (start_offset & 3);
02178           workaround = ALIGN4;
02179           continue;
02180         }
02181       if (workaround < ALIGN8 && (start_offset & 7) != 0)
02182         {
02183           start += 8 - (start_offset & 7);
02184           workaround = ALIGN8;
02185           continue;
02186         }
02187 
02188       /* Nothing left to try.  Arrange to return as if we've consumed
02189          the entire input section.  Hopefully we'll get valid info from
02190          the other of .debug_frame/.eh_frame.  */
02191       workaround = FAIL;
02192       ret = unit->dwarf_frame_buffer + unit->dwarf_frame_size;
02193       break;
02194     }
02195 
02196   switch (workaround)
02197     {
02198     case NONE:
02199       break;
02200 
02201     case ALIGN4:
02202       complaint (&symfile_complaints, _("\
02203 Corrupt data in %s:%s; align 4 workaround apparently succeeded"),
02204                  unit->dwarf_frame_section->owner->filename,
02205                  unit->dwarf_frame_section->name);
02206       break;
02207 
02208     case ALIGN8:
02209       complaint (&symfile_complaints, _("\
02210 Corrupt data in %s:%s; align 8 workaround apparently succeeded"),
02211                  unit->dwarf_frame_section->owner->filename,
02212                  unit->dwarf_frame_section->name);
02213       break;
02214 
02215     default:
02216       complaint (&symfile_complaints,
02217                  _("Corrupt data in %s:%s"),
02218                  unit->dwarf_frame_section->owner->filename,
02219                  unit->dwarf_frame_section->name);
02220       break;
02221     }
02222 
02223   return ret;
02224 }
02225 
02226 static int
02227 qsort_fde_cmp (const void *a, const void *b)
02228 {
02229   struct dwarf2_fde *aa = *(struct dwarf2_fde **)a;
02230   struct dwarf2_fde *bb = *(struct dwarf2_fde **)b;
02231 
02232   if (aa->initial_location == bb->initial_location)
02233     {
02234       if (aa->address_range != bb->address_range
02235           && aa->eh_frame_p == 0 && bb->eh_frame_p == 0)
02236         /* Linker bug, e.g. gold/10400.
02237            Work around it by keeping stable sort order.  */
02238         return (a < b) ? -1 : 1;
02239       else
02240         /* Put eh_frame entries after debug_frame ones.  */
02241         return aa->eh_frame_p - bb->eh_frame_p;
02242     }
02243 
02244   return (aa->initial_location < bb->initial_location) ? -1 : 1;
02245 }
02246 
02247 void
02248 dwarf2_build_frame_info (struct objfile *objfile)
02249 {
02250   struct comp_unit *unit;
02251   const gdb_byte *frame_ptr;
02252   struct dwarf2_cie_table cie_table;
02253   struct dwarf2_fde_table fde_table;
02254   struct dwarf2_fde_table *fde_table2;
02255   volatile struct gdb_exception e;
02256 
02257   cie_table.num_entries = 0;
02258   cie_table.entries = NULL;
02259 
02260   fde_table.num_entries = 0;
02261   fde_table.entries = NULL;
02262 
02263   /* Build a minimal decoding of the DWARF2 compilation unit.  */
02264   unit = (struct comp_unit *) obstack_alloc (&objfile->objfile_obstack,
02265                                              sizeof (struct comp_unit));
02266   unit->abfd = objfile->obfd;
02267   unit->objfile = objfile;
02268   unit->dbase = 0;
02269   unit->tbase = 0;
02270 
02271   if (objfile->separate_debug_objfile_backlink == NULL)
02272     {
02273       /* Do not read .eh_frame from separate file as they must be also
02274          present in the main file.  */
02275       dwarf2_get_section_info (objfile, DWARF2_EH_FRAME,
02276                                &unit->dwarf_frame_section,
02277                                &unit->dwarf_frame_buffer,
02278                                &unit->dwarf_frame_size);
02279       if (unit->dwarf_frame_size)
02280         {
02281           asection *got, *txt;
02282 
02283           /* FIXME: kettenis/20030602: This is the DW_EH_PE_datarel base
02284              that is used for the i386/amd64 target, which currently is
02285              the only target in GCC that supports/uses the
02286              DW_EH_PE_datarel encoding.  */
02287           got = bfd_get_section_by_name (unit->abfd, ".got");
02288           if (got)
02289             unit->dbase = got->vma;
02290 
02291           /* GCC emits the DW_EH_PE_textrel encoding type on sh and ia64
02292              so far.  */
02293           txt = bfd_get_section_by_name (unit->abfd, ".text");
02294           if (txt)
02295             unit->tbase = txt->vma;
02296 
02297           TRY_CATCH (e, RETURN_MASK_ERROR)
02298             {
02299               frame_ptr = unit->dwarf_frame_buffer;
02300               while (frame_ptr < unit->dwarf_frame_buffer + unit->dwarf_frame_size)
02301                 frame_ptr = decode_frame_entry (unit, frame_ptr, 1,
02302                                                 &cie_table, &fde_table,
02303                                                 EH_CIE_OR_FDE_TYPE_ID);
02304             }
02305 
02306           if (e.reason < 0)
02307             {
02308               warning (_("skipping .eh_frame info of %s: %s"),
02309                        objfile_name (objfile), e.message);
02310 
02311               if (fde_table.num_entries != 0)
02312                 {
02313                   xfree (fde_table.entries);
02314                   fde_table.entries = NULL;
02315                   fde_table.num_entries = 0;
02316                 }
02317               /* The cie_table is discarded by the next if.  */
02318             }
02319 
02320           if (cie_table.num_entries != 0)
02321             {
02322               /* Reinit cie_table: debug_frame has different CIEs.  */
02323               xfree (cie_table.entries);
02324               cie_table.num_entries = 0;
02325               cie_table.entries = NULL;
02326             }
02327         }
02328     }
02329 
02330   dwarf2_get_section_info (objfile, DWARF2_DEBUG_FRAME,
02331                            &unit->dwarf_frame_section,
02332                            &unit->dwarf_frame_buffer,
02333                            &unit->dwarf_frame_size);
02334   if (unit->dwarf_frame_size)
02335     {
02336       int num_old_fde_entries = fde_table.num_entries;
02337 
02338       TRY_CATCH (e, RETURN_MASK_ERROR)
02339         {
02340           frame_ptr = unit->dwarf_frame_buffer;
02341           while (frame_ptr < unit->dwarf_frame_buffer + unit->dwarf_frame_size)
02342             frame_ptr = decode_frame_entry (unit, frame_ptr, 0,
02343                                             &cie_table, &fde_table,
02344                                             EH_CIE_OR_FDE_TYPE_ID);
02345         }
02346       if (e.reason < 0)
02347         {
02348           warning (_("skipping .debug_frame info of %s: %s"),
02349                    objfile_name (objfile), e.message);
02350 
02351           if (fde_table.num_entries != 0)
02352             {
02353               fde_table.num_entries = num_old_fde_entries;
02354               if (num_old_fde_entries == 0)
02355                 {
02356                   xfree (fde_table.entries);
02357                   fde_table.entries = NULL;
02358                 }
02359               else
02360                 {
02361                   fde_table.entries = xrealloc (fde_table.entries,
02362                                                 fde_table.num_entries *
02363                                                 sizeof (fde_table.entries[0]));
02364                 }
02365             }
02366           fde_table.num_entries = num_old_fde_entries;
02367           /* The cie_table is discarded by the next if.  */
02368         }
02369     }
02370 
02371   /* Discard the cie_table, it is no longer needed.  */
02372   if (cie_table.num_entries != 0)
02373     {
02374       xfree (cie_table.entries);
02375       cie_table.entries = NULL;   /* Paranoia.  */
02376       cie_table.num_entries = 0;  /* Paranoia.  */
02377     }
02378 
02379   /* Copy fde_table to obstack: it is needed at runtime.  */
02380   fde_table2 = (struct dwarf2_fde_table *)
02381     obstack_alloc (&objfile->objfile_obstack, sizeof (*fde_table2));
02382 
02383   if (fde_table.num_entries == 0)
02384     {
02385       fde_table2->entries = NULL;
02386       fde_table2->num_entries = 0;
02387     }
02388   else
02389     {
02390       struct dwarf2_fde *fde_prev = NULL;
02391       struct dwarf2_fde *first_non_zero_fde = NULL;
02392       int i;
02393 
02394       /* Prepare FDE table for lookups.  */
02395       qsort (fde_table.entries, fde_table.num_entries,
02396              sizeof (fde_table.entries[0]), qsort_fde_cmp);
02397 
02398       /* Check for leftovers from --gc-sections.  The GNU linker sets
02399          the relevant symbols to zero, but doesn't zero the FDE *end*
02400          ranges because there's no relocation there.  It's (offset,
02401          length), not (start, end).  On targets where address zero is
02402          just another valid address this can be a problem, since the
02403          FDEs appear to be non-empty in the output --- we could pick
02404          out the wrong FDE.  To work around this, when overlaps are
02405          detected, we prefer FDEs that do not start at zero.
02406 
02407          Start by finding the first FDE with non-zero start.  Below
02408          we'll discard all FDEs that start at zero and overlap this
02409          one.  */
02410       for (i = 0; i < fde_table.num_entries; i++)
02411         {
02412           struct dwarf2_fde *fde = fde_table.entries[i];
02413 
02414           if (fde->initial_location != 0)
02415             {
02416               first_non_zero_fde = fde;
02417               break;
02418             }
02419         }
02420 
02421       /* Since we'll be doing bsearch, squeeze out identical (except
02422          for eh_frame_p) fde entries so bsearch result is predictable.
02423          Also discard leftovers from --gc-sections.  */
02424       fde_table2->num_entries = 0;
02425       for (i = 0; i < fde_table.num_entries; i++)
02426         {
02427           struct dwarf2_fde *fde = fde_table.entries[i];
02428 
02429           if (fde->initial_location == 0
02430               && first_non_zero_fde != NULL
02431               && (first_non_zero_fde->initial_location
02432                   < fde->initial_location + fde->address_range))
02433             continue;
02434 
02435           if (fde_prev != NULL
02436               && fde_prev->initial_location == fde->initial_location)
02437             continue;
02438 
02439           obstack_grow (&objfile->objfile_obstack, &fde_table.entries[i],
02440                         sizeof (fde_table.entries[0]));
02441           ++fde_table2->num_entries;
02442           fde_prev = fde;
02443         }
02444       fde_table2->entries = obstack_finish (&objfile->objfile_obstack);
02445 
02446       /* Discard the original fde_table.  */
02447       xfree (fde_table.entries);
02448     }
02449 
02450   set_objfile_data (objfile, dwarf2_frame_objfile_data, fde_table2);
02451 }
02452 
02453 /* Provide a prototype to silence -Wmissing-prototypes.  */
02454 void _initialize_dwarf2_frame (void);
02455 
02456 void
02457 _initialize_dwarf2_frame (void)
02458 {
02459   dwarf2_frame_data = gdbarch_data_register_pre_init (dwarf2_frame_init);
02460   dwarf2_frame_objfile_data = register_objfile_data ();
02461 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines