9
9
This program is free software; you can redistribute it and/or modify
10
10
it under the terms of the GNU General Public License as published by
11
the Free Software Foundation; either version 2 of the License, or
11
the Free Software Foundation; either version 3 of the License, or
12
12
(at your option) any later version.
14
14
This program is distributed in the hope that it will be useful,
17
17
GNU General Public License for more details.
19
19
You should have received a copy of the GNU General Public License
20
along with this program; if not, write to the Free Software
21
Foundation, Inc., 51 Franklin Street, Fifth Floor,
22
Boston, MA 02110-1301, USA. */
20
along with this program. If not, see <http://www.gnu.org/licenses/>. */
25
23
#include "dwarf2expr.h"
138
145
LONGEST data_align;
139
146
ULONGEST code_align;
140
147
ULONGEST retaddr_column;
149
/* Flags for known producer quirks. */
151
/* The ARM compilers, in DWARF2 mode, assume that DW_CFA_def_cfa
152
and DW_CFA_def_cfa_offset takes a factored offset. */
153
int armcc_cfa_offsets_sf;
155
/* The ARM compilers, in DWARF2 or DWARF3 mode, may assume that
156
the CFA is defined as REG - OFFSET rather than REG + OFFSET. */
157
int armcc_cfa_offsets_reversed;
143
160
/* Store the length the expression for the CFA in the `cfa_reg' field,
144
161
which is unused in that case. */
145
162
#define cfa_exp_len cfa_reg
147
/* Assert that the register set RS is large enough to store NUM_REGS
164
/* Assert that the register set RS is large enough to store gdbarch_num_regs
148
165
columns. If necessary, enlarge the register set. */
298
315
else if ((insn & 0xc0) == DW_CFA_offset)
300
317
reg = insn & 0x3f;
302
reg = dwarf2_frame_eh_frame_regnum (gdbarch, reg);
318
reg = dwarf2_frame_adjust_regnum (gdbarch, reg, eh_frame_p);
303
319
insn_ptr = read_uleb128 (insn_ptr, insn_end, &utmp);
304
320
offset = utmp * fs->data_align;
305
321
dwarf2_frame_state_alloc_regs (&fs->regs, reg + 1);
311
327
gdb_assert (fs->initial.reg);
312
328
reg = insn & 0x3f;
314
reg = dwarf2_frame_eh_frame_regnum (gdbarch, reg);
329
reg = dwarf2_frame_adjust_regnum (gdbarch, reg, eh_frame_p);
315
330
dwarf2_frame_state_alloc_regs (&fs->regs, reg + 1);
316
331
if (reg < fs->initial.num_regs)
317
332
fs->regs.reg[reg] = fs->initial.reg[reg];
322
337
complaint (&symfile_complaints, _("\
323
338
incomplete CFI data; DW_CFA_restore unspecified\n\
324
339
register %s (#%d) at 0x%s"),
325
REGISTER_NAME(DWARF2_REG_TO_REGNUM(reg)),
326
DWARF2_REG_TO_REGNUM(reg), paddr (fs->pc));
340
gdbarch_register_name
341
(current_gdbarch, gdbarch_dwarf2_reg_to_regnum
342
(current_gdbarch, reg)),
343
gdbarch_dwarf2_reg_to_regnum (current_gdbarch, reg),
353
371
case DW_CFA_offset_extended:
354
372
insn_ptr = read_uleb128 (insn_ptr, insn_end, ®);
356
reg = dwarf2_frame_eh_frame_regnum (gdbarch, reg);
373
reg = dwarf2_frame_adjust_regnum (gdbarch, reg, eh_frame_p);
357
374
insn_ptr = read_uleb128 (insn_ptr, insn_end, &utmp);
358
375
offset = utmp * fs->data_align;
359
376
dwarf2_frame_state_alloc_regs (&fs->regs, reg + 1);
364
381
case DW_CFA_restore_extended:
365
382
gdb_assert (fs->initial.reg);
366
383
insn_ptr = read_uleb128 (insn_ptr, insn_end, ®);
368
reg = dwarf2_frame_eh_frame_regnum (gdbarch, reg);
384
reg = dwarf2_frame_adjust_regnum (gdbarch, reg, eh_frame_p);
369
385
dwarf2_frame_state_alloc_regs (&fs->regs, reg + 1);
370
386
fs->regs.reg[reg] = fs->initial.reg[reg];
373
389
case DW_CFA_undefined:
374
390
insn_ptr = read_uleb128 (insn_ptr, insn_end, ®);
376
reg = dwarf2_frame_eh_frame_regnum (gdbarch, reg);
391
reg = dwarf2_frame_adjust_regnum (gdbarch, reg, eh_frame_p);
377
392
dwarf2_frame_state_alloc_regs (&fs->regs, reg + 1);
378
393
fs->regs.reg[reg].how = DWARF2_FRAME_REG_UNDEFINED;
381
396
case DW_CFA_same_value:
382
397
insn_ptr = read_uleb128 (insn_ptr, insn_end, ®);
384
reg = dwarf2_frame_eh_frame_regnum (gdbarch, reg);
398
reg = dwarf2_frame_adjust_regnum (gdbarch, reg, eh_frame_p);
385
399
dwarf2_frame_state_alloc_regs (&fs->regs, reg + 1);
386
400
fs->regs.reg[reg].how = DWARF2_FRAME_REG_SAME_VALUE;
389
403
case DW_CFA_register:
390
404
insn_ptr = read_uleb128 (insn_ptr, insn_end, ®);
392
reg = dwarf2_frame_eh_frame_regnum (gdbarch, reg);
405
reg = dwarf2_frame_adjust_regnum (gdbarch, reg, eh_frame_p);
393
406
insn_ptr = read_uleb128 (insn_ptr, insn_end, &utmp);
395
utmp = dwarf2_frame_eh_frame_regnum (gdbarch, utmp);
407
utmp = dwarf2_frame_adjust_regnum (gdbarch, utmp, eh_frame_p);
396
408
dwarf2_frame_state_alloc_regs (&fs->regs, reg + 1);
397
409
fs->regs.reg[reg].how = DWARF2_FRAME_REG_SAVED_REG;
398
410
fs->regs.reg[reg].loc.reg = utmp;
430
442
case DW_CFA_def_cfa:
431
443
insn_ptr = read_uleb128 (insn_ptr, insn_end, &fs->cfa_reg);
432
444
insn_ptr = read_uleb128 (insn_ptr, insn_end, &utmp);
446
if (fs->armcc_cfa_offsets_sf)
447
utmp *= fs->data_align;
433
449
fs->cfa_offset = utmp;
434
450
fs->cfa_how = CFA_REG_OFFSET;
437
453
case DW_CFA_def_cfa_register:
438
454
insn_ptr = read_uleb128 (insn_ptr, insn_end, &fs->cfa_reg);
440
fs->cfa_reg = dwarf2_frame_eh_frame_regnum (gdbarch,
455
fs->cfa_reg = dwarf2_frame_adjust_regnum (gdbarch, fs->cfa_reg,
442
457
fs->cfa_how = CFA_REG_OFFSET;
445
460
case DW_CFA_def_cfa_offset:
446
461
insn_ptr = read_uleb128 (insn_ptr, insn_end, &utmp);
463
if (fs->armcc_cfa_offsets_sf)
464
utmp *= fs->data_align;
447
466
fs->cfa_offset = utmp;
448
467
/* cfa_how deliberately not set. */
461
480
case DW_CFA_expression:
462
481
insn_ptr = read_uleb128 (insn_ptr, insn_end, ®);
464
reg = dwarf2_frame_eh_frame_regnum (gdbarch, reg);
482
reg = dwarf2_frame_adjust_regnum (gdbarch, reg, eh_frame_p);
465
483
dwarf2_frame_state_alloc_regs (&fs->regs, reg + 1);
466
484
insn_ptr = read_uleb128 (insn_ptr, insn_end, &utmp);
467
485
fs->regs.reg[reg].loc.exp = insn_ptr;
473
491
case DW_CFA_offset_extended_sf:
474
492
insn_ptr = read_uleb128 (insn_ptr, insn_end, ®);
476
reg = dwarf2_frame_eh_frame_regnum (gdbarch, reg);
493
reg = dwarf2_frame_adjust_regnum (gdbarch, reg, eh_frame_p);
477
494
insn_ptr = read_sleb128 (insn_ptr, insn_end, &offset);
478
495
offset *= fs->data_align;
479
496
dwarf2_frame_state_alloc_regs (&fs->regs, reg + 1);
512
529
case DW_CFA_def_cfa_sf:
513
530
insn_ptr = read_uleb128 (insn_ptr, insn_end, &fs->cfa_reg);
515
fs->cfa_reg = dwarf2_frame_eh_frame_regnum (gdbarch,
531
fs->cfa_reg = dwarf2_frame_adjust_regnum (gdbarch, fs->cfa_reg,
517
533
insn_ptr = read_sleb128 (insn_ptr, insn_end, &offset);
518
534
fs->cfa_offset = offset * fs->data_align;
519
535
fs->cfa_how = CFA_REG_OFFSET;
555
571
insn_ptr = read_uleb128 (insn_ptr, insn_end, &utmp);
574
case DW_CFA_GNU_negative_offset_extended:
575
insn_ptr = read_uleb128 (insn_ptr, insn_end, ®);
576
reg = dwarf2_frame_adjust_regnum (gdbarch, reg, eh_frame_p);
577
insn_ptr = read_uleb128 (insn_ptr, insn_end, &offset);
578
offset *= fs->data_align;
579
dwarf2_frame_state_alloc_regs (&fs->regs, reg + 1);
580
fs->regs.reg[reg].how = DWARF2_FRAME_REG_SAVED_OFFSET;
581
fs->regs.reg[reg].loc.offset = -offset;
559
585
internal_error (__FILE__, __LINE__, _("Unknown CFI encountered."));
583
609
int (*signal_frame_p) (struct gdbarch *, struct frame_info *);
585
/* Convert .eh_frame register number to DWARF register number. */
586
int (*eh_frame_regnum) (struct gdbarch *, int);
611
/* Convert .eh_frame register number to DWARF register number, or
612
adjust .debug_frame register number. */
613
int (*adjust_regnum) (struct gdbarch *, int, int);
589
616
/* Default architecture-specific register state initialization
691
718
return ops->signal_frame_p (gdbarch, next_frame);
694
/* Set the architecture-specific mapping of .eh_frame register numbers to
695
DWARF register numbers. */
721
/* Set the architecture-specific adjustment of .eh_frame and .debug_frame
698
dwarf2_frame_set_eh_frame_regnum (struct gdbarch *gdbarch,
699
int (*eh_frame_regnum) (struct gdbarch *,
725
dwarf2_frame_set_adjust_regnum (struct gdbarch *gdbarch,
726
int (*adjust_regnum) (struct gdbarch *,
702
729
struct dwarf2_frame_ops *ops = gdbarch_data (gdbarch, dwarf2_frame_data);
704
ops->eh_frame_regnum = eh_frame_regnum;
731
ops->adjust_regnum = adjust_regnum;
707
/* Translate a .eh_frame register to DWARF register. */
734
/* Translate a .eh_frame register to DWARF register, or adjust a .debug_frame
710
dwarf2_frame_eh_frame_regnum (struct gdbarch *gdbarch, int regnum)
738
dwarf2_frame_adjust_regnum (struct gdbarch *gdbarch, int regnum, int eh_frame_p)
712
740
struct dwarf2_frame_ops *ops = gdbarch_data (gdbarch, dwarf2_frame_data);
714
if (ops->eh_frame_regnum == NULL)
742
if (ops->adjust_regnum == NULL)
716
return ops->eh_frame_regnum (gdbarch, regnum);
744
return ops->adjust_regnum (gdbarch, regnum, eh_frame_p);
748
dwarf2_frame_find_quirks (struct dwarf2_frame_state *fs,
749
struct dwarf2_fde *fde)
751
static const char *arm_idents[] = {
752
"ARM C Compiler, ADS",
753
"Thumb C Compiler, ADS",
754
"ARM C++ Compiler, ADS",
755
"Thumb C++ Compiler, ADS",
756
"ARM/Thumb C/C++ Compiler, RVCT"
762
s = find_pc_symtab (fs->pc);
763
if (s == NULL || s->producer == NULL)
766
for (i = 0; i < ARRAY_SIZE (arm_idents); i++)
767
if (strncmp (s->producer, arm_idents[i], strlen (arm_idents[i])) == 0)
769
if (fde->cie->version == 1)
770
fs->armcc_cfa_offsets_sf = 1;
772
if (fde->cie->version == 1)
773
fs->armcc_cfa_offsets_reversed = 1;
775
/* The reversed offset problem is present in some compilers
776
using DWARF3, but it was eventually fixed. Check the ARM
777
defined augmentations, which are in the format "armcc" followed
778
by a list of one-character options. The "+" option means
779
this problem is fixed (no quirk needed). If the armcc
780
augmentation is missing, the quirk is needed. */
781
if (fde->cie->version == 3
782
&& (strncmp (fde->cie->augmentation, "armcc", 5) != 0
783
|| strchr (fde->cie->augmentation + 5, '+') == NULL))
784
fs->armcc_cfa_offsets_reversed = 1;
770
842
frame_unwind_address_in_block does just this. It's not clear how
771
843
reliable the method is though; there is the potential for the
772
844
register state pre-call being different to that on return. */
773
fs->pc = frame_unwind_address_in_block (next_frame);
845
fs->pc = frame_unwind_address_in_block (next_frame, NORMAL_FRAME);
775
847
/* Find the correct FDE. */
776
848
fde = dwarf2_frame_find_fde (&fs->pc);
781
853
fs->code_align = fde->cie->code_alignment_factor;
782
854
fs->retaddr_column = fde->cie->return_address_register;
856
/* Check for "quirks" - known bugs in producers. */
857
dwarf2_frame_find_quirks (fs, fde);
784
859
/* First decode all the insns in the CIE. */
785
860
execute_cfa_program (fde->cie->initial_instructions,
786
861
fde->cie->end, next_frame, fs, fde->eh_frame_p);
823
901
return address column; it's perfectly all right for it to
824
902
correspond to a real register. If it doesn't correspond to a
825
903
real register, or if we shouldn't treat it as such,
826
DWARF2_REG_TO_REGNUM should be defined to return a number outside
827
the range [0, NUM_REGS). */
904
gdbarch_dwarf2_reg_to_regnum should be defined to return a number outside
905
the range [0, gdbarch_num_regs). */
829
907
int column; /* CFI speak for "register number". */
831
909
for (column = 0; column < fs->regs.num_regs; column++)
833
911
/* Use the GDB register number as the destination index. */
834
int regnum = DWARF2_REG_TO_REGNUM (column);
912
int regnum = gdbarch_dwarf2_reg_to_regnum (current_gdbarch, column);
836
914
/* If there's no corresponding GDB register, ignore it. */
837
915
if (regnum < 0 || regnum >= num_regs)
927
1005
if (cache->undefined_retaddr)
930
(*this_id) = frame_id_build (cache->cfa, frame_func_unwind (next_frame));
1008
(*this_id) = frame_id_build (cache->cfa,
1009
frame_func_unwind (next_frame, NORMAL_FRAME));
1013
dwarf2_signal_frame_this_id (struct frame_info *next_frame, void **this_cache,
1014
struct frame_id *this_id)
1016
struct dwarf2_frame_cache *cache =
1017
dwarf2_frame_cache (next_frame, this_cache);
1019
if (cache->undefined_retaddr)
1022
(*this_id) = frame_id_build (cache->cfa,
1023
frame_func_unwind (next_frame, SIGTRAMP_FRAME));
1075
1163
CORE_ADDR pc = cache->reg[regnum].loc.offset;
1077
regnum = DWARF2_REG_TO_REGNUM (cache->retaddr_reg.loc.reg);
1165
regnum = gdbarch_dwarf2_reg_to_regnum
1166
(current_gdbarch, cache->retaddr_reg.loc.reg);
1078
1167
pc += frame_unwind_register_unsigned (next_frame, regnum);
1079
store_typed_address (valuep, builtin_type_void_func_ptr, pc);
1168
pack_long (valuep, register_type (gdbarch, regnum), pc);
1105
1194
/* Grab an address that is guarenteed to reside somewhere within the
1106
1195
function. frame_pc_unwind(), for a no-return next function, can
1107
end up returning something past the end of this function's body. */
1108
CORE_ADDR block_addr = frame_unwind_address_in_block (next_frame);
1196
end up returning something past the end of this function's body.
1197
If the frame we're sniffing for is a signal frame whose start
1198
address is placed on the stack by the OS, its FDE must
1199
extend one byte before its start address or we will miss it. */
1200
CORE_ADDR block_addr = frame_unwind_address_in_block (next_frame,
1109
1202
struct dwarf2_fde *fde = dwarf2_frame_find_fde (&block_addr);
1584
1682
cie_version = read_1_byte (unit->abfd, buf);
1585
1683
if (cie_version != 1 && cie_version != 3)
1685
cie->version = cie_version;
1589
1688
/* Interpret the interesting bits of the augmentation. */
1590
augmentation = (char *) buf;
1689
cie->augmentation = augmentation = (char *) buf;
1591
1690
buf += (strlen (augmentation) + 1);
1692
/* Ignore armcc augmentations. We only use them for quirks,
1693
and that doesn't happen until later. */
1694
if (strncmp (augmentation, "armcc", 5) == 0)
1695
augmentation += strlen (augmentation);
1593
1697
/* The GCC 2.x "eh" augmentation has a pointer immediately
1594
1698
following the augmentation string, so it must be handled
1617
1721
cie->return_address_register = read_unsigned_leb128 (unit->abfd, buf,
1620
cie->return_address_register
1621
= dwarf2_frame_eh_frame_regnum (current_gdbarch,
1622
cie->return_address_register);
1723
cie->return_address_register
1724
= dwarf2_frame_adjust_regnum (current_gdbarch,
1725
cie->return_address_register,
1624
1728
buf += bytes_read;
1674
1778
augmentation++;
1677
/* Otherwise we have an unknown augmentation.
1678
Bail out unless we saw a 'z' prefix. */
1781
/* Otherwise we have an unknown augmentation. Assume that either
1782
there is no augmentation data, or we saw a 'z' prefix. */
1681
if (cie->initial_instructions == NULL)
1684
/* Skip unknown augmentations. */
1685
buf = cie->initial_instructions;
1785
if (cie->initial_instructions)
1786
buf = cie->initial_instructions;