aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.python/py-value.c
diff options
context:
space:
mode:
authorLuis Machado <lgustavo@codesourcery.com>2016-10-12 10:10:03 -0500
committerLuis Machado <lgustavo@codesourcery.com>2016-10-12 10:10:03 -0500
commit4dac951e11030b43b17f52df8bdfa7432e4bf73c (patch)
tree6fc502ccf004ba3bd3dc1ab5053c78747678b56b /gdb/testsuite/gdb.python/py-value.c
parent4a2f4826907de97b089295000a67d2497aa94c99 (diff)
downloadgdb-4dac951e11030b43b17f52df8bdfa7432e4bf73c.zip
gdb-4dac951e11030b43b17f52df8bdfa7432e4bf73c.tar.gz
gdb-4dac951e11030b43b17f52df8bdfa7432e4bf73c.tar.bz2
Fixup gdb.python/py-value.exp for bare-metal aarch64-elf
I noticed that testing aarch64-elf gdb with a physical board ran into issues with gdb.python/py-value.exp. Further investigation showed that we were actually trying to dereference a NULL pointer (argv) when trying to access argv[0]. Being bare-metal, argv is not guaranteed to be valid. So we need to make sure argv is sane before accessing argv[0]. The following patch fixes up the test program to check for a NULL argv and also improves the testcase a bit so it doesn't have to work with a hardcoded argc value. Regression-tested on x86-64 Ubuntu 16.04. gdb/testsuite/ChangeLog: 2016-10-12 Luis Machado <lgustavo@codesourcery.com> * gdb.python/py-value.c (main): Check if argv is NULL before using it. * gdb.python/py-value.exp (test_value_in_inferior): Don't use hardcoded argc values. Add 1 to argc so we guarantee distinct initial/modified argc values.
Diffstat (limited to 'gdb/testsuite/gdb.python/py-value.c')
-rw-r--r--gdb/testsuite/gdb.python/py-value.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/gdb/testsuite/gdb.python/py-value.c b/gdb/testsuite/gdb.python/py-value.c
index 586a0fd..8a8ace6 100644
--- a/gdb/testsuite/gdb.python/py-value.c
+++ b/gdb/testsuite/gdb.python/py-value.c
@@ -82,7 +82,7 @@ char **save_argv;
int
main (int argc, char *argv[])
{
- char *cp = argv[0]; /* Prevent gcc from optimizing argv[] out. */
+ char *cp;
struct s s;
union u u;
PTR x = &s;
@@ -99,6 +99,14 @@ main (int argc, char *argv[])
const char *sn = 0;
struct str *xstr;
+ /* Prevent gcc from optimizing argv[] out. */
+
+ /* We also check for a NULL argv in case we are dealing with a target
+ executing in a freestanding environment, therefore there are no
+ guarantees about argc or argv. */
+ if (argv != NULL)
+ cp = argv[0];
+
s.a = 3;
s.b = 5;
u.a = 7;