aboutsummaryrefslogtreecommitdiff
path: root/gdb/rs6000-tdep.c
diff options
context:
space:
mode:
authorJoel Brobecker <brobecker@adacore.com>2018-11-01 16:46:05 -0500
committerJoel Brobecker <brobecker@adacore.com>2018-11-01 17:46:58 -0400
commit1cc62f2e4443384e300586683aa1f8197c81cbc5 (patch)
tree234cc464d3db0d4978ed6c4c16be49d8830331ad /gdb/rs6000-tdep.c
parente1c3a3737536c57e43d4ad693341717e326f4e17 (diff)
downloadgdb-1cc62f2e4443384e300586683aa1f8197c81cbc5.zip
gdb-1cc62f2e4443384e300586683aa1f8197c81cbc5.tar.gz
gdb-1cc62f2e4443384e300586683aa1f8197c81cbc5.tar.bz2
rs6000-tdep.c:skip_prologue avoid negative left shift
the rs6000-tdep.c::skip_prologue function has the following code: unsigned int all_mask = ~((1U << fdata->saved_gpr) - 1); /* Not a recognized prologue instruction. Handle optimizer code motions into the prologue by continuing the search if we have no valid frame yet or if the return address is not yet saved in the frame. Also skip instructions if some of the GPRs expected to be saved are not yet saved. */ if (fdata->frameless == 0 && fdata->nosavedpc == 0 && (fdata->gpr_mask & all_mask) == all_mask) break; The problem is that fdata->saved_gpr is initialized to -1, and so, if no instruction is found in the function's prologue that causes us to set that field to a non-negative value, the sanitizer crashes with the following message: rs6000-tdep.c:1965:34: runtime error: shift exponent -1 is negative This patch fixes the issue the by only doing the shift if saved_gpr is not negative. When saved_gpr is negative, we actually don't need the shift. gdb/ChangeLog: * rs6000-tdep.c (skip_prologue): Fix potential negative left shifting. Tested on ppc-linux native. Also tested on ppc-elf (baremetal) using AdaCore's testsuite.
Diffstat (limited to 'gdb/rs6000-tdep.c')
-rw-r--r--gdb/rs6000-tdep.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/gdb/rs6000-tdep.c b/gdb/rs6000-tdep.c
index 504de36..67c7a36 100644
--- a/gdb/rs6000-tdep.c
+++ b/gdb/rs6000-tdep.c
@@ -1975,16 +1975,19 @@ skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc, CORE_ADDR lim_pc,
else
{
- unsigned int all_mask = ~((1U << fdata->saved_gpr) - 1);
-
/* Not a recognized prologue instruction.
Handle optimizer code motions into the prologue by continuing
the search if we have no valid frame yet or if the return
address is not yet saved in the frame. Also skip instructions
if some of the GPRs expected to be saved are not yet saved. */
if (fdata->frameless == 0 && fdata->nosavedpc == 0
- && (fdata->gpr_mask & all_mask) == all_mask)
- break;
+ && fdata->saved_gpr != -1)
+ {
+ unsigned int all_mask = ~((1U << fdata->saved_gpr) - 1);
+
+ if ((fdata->gpr_mask & all_mask) == all_mask)
+ break;
+ }
if (op == 0x4e800020 /* blr */
|| op == 0x4e800420) /* bctr */