aboutsummaryrefslogtreecommitdiff
path: root/gdb/i386-tdep.c
diff options
context:
space:
mode:
authorSergio Durigan Junior <sergiodj@redhat.com>2014-02-20 18:49:09 -0300
committerSergio Durigan Junior <sergiodj@redhat.com>2014-02-20 18:49:09 -0300
commitd7b30f6729ecf47b932b17f77123663e6a21bdd6 (patch)
tree2eb1758a4ee655272f0a251e1521f4fe1b333362 /gdb/i386-tdep.c
parent3bc32da325e4bf048220a1228a8a6fa65a15225f (diff)
downloadgdb-d7b30f6729ecf47b932b17f77123663e6a21bdd6.zip
gdb-d7b30f6729ecf47b932b17f77123663e6a21bdd6.tar.gz
gdb-d7b30f6729ecf47b932b17f77123663e6a21bdd6.tar.bz2
Fix for PR tdep/16397: SystemTap SDT probe support for x86 doesn't work with "triplet operands"
This is the continuation of what Joel proposed on: <https://sourceware.org/ml/gdb-patches/2013-12/msg00977.html> Now that I have already submitted and pushed the patch to split i386_stap_parse_special_token into two smaller functions, it is indeed simpler to understand this patch. It occurs because, on x86, triplet displacement operands are allowed (like "-4+8-20(%rbp)"), and the current parser for this expression is buggy. It does not correctly extract the register name from the expression, which leads to incorrect evaluation. The parser was also being very "generous" with the expression, so I included a few more checks to ensure that we're indeed dealing with a triplet displacement operand. This patch also includes testcases for the two different kind of expressions that can be encountered on x86: the triplet displacement (explained above) and the three-argument displacement (as in "(%rbx,%ebx,-8)"). The tests are obviously arch-dependent and are placed under gdb.arch/. Message-ID: <m3mwj1j12v.fsf@redhat.com> URL: <https://sourceware.org/ml/gdb-patches/2014-01/msg00310.html> gdb/ 2014-02-20 Sergio Durigan Junior <sergiodj@redhat.com> PR tdep/16397 * i386-tdep.c (i386_stap_parse_special_token_triplet): Check if a number comes after the + or - signs. Adjust length of register name to be extracted. gdb/testsuite/ 2014-02-20 Sergio Durigan Junior <sergiodj@redhat.com> PR tdep/16397 * gdb.arch/amd64-stap-special-operands.exp: New file. * gdb.arch/amd64-stap-three-arg-disp.S: Likewise. * gdb.arch/amd64-stap-three-arg-disp.c: Likewise. * gdb.arch/amd64-stap-triplet.S: Likewise. * gdb.arch/amd64-stap-triplet.c: Likewise.
Diffstat (limited to 'gdb/i386-tdep.c')
-rw-r--r--gdb/i386-tdep.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/gdb/i386-tdep.c b/gdb/i386-tdep.c
index 57f18cb..bb414b6 100644
--- a/gdb/i386-tdep.c
+++ b/gdb/i386-tdep.c
@@ -3694,6 +3694,9 @@ i386_stap_parse_special_token_triplet (struct gdbarch *gdbarch,
got_minus[0] = 1;
}
+ if (!isdigit ((unsigned char) *s))
+ return 0;
+
displacements[0] = strtol (s, &endp, 10);
s = endp;
@@ -3712,6 +3715,9 @@ i386_stap_parse_special_token_triplet (struct gdbarch *gdbarch,
got_minus[1] = 1;
}
+ if (!isdigit ((unsigned char) *s))
+ return 0;
+
displacements[1] = strtol (s, &endp, 10);
s = endp;
@@ -3730,6 +3736,9 @@ i386_stap_parse_special_token_triplet (struct gdbarch *gdbarch,
got_minus[2] = 1;
}
+ if (!isdigit ((unsigned char) *s))
+ return 0;
+
displacements[2] = strtol (s, &endp, 10);
s = endp;
@@ -3745,7 +3754,7 @@ i386_stap_parse_special_token_triplet (struct gdbarch *gdbarch,
if (*s++ != ')')
return 0;
- len = s - start;
+ len = s - start - 1;
regname = alloca (len + 1);
strncpy (regname, start, len);