From: Luis Machado <lgustavo@codesourcery.com>
To: <gdb-patches@sourceware.org>
Subject: [PATCH] Fixup gdb.python/py-value.exp for bare-metal aarch64-elf
Date: Thu, 06 Oct 2016 16:27:00 -0000 [thread overview]
Message-ID: <1475771231-1739-1-git-send-email-lgustavo@codesourcery.com> (raw)
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 there. So we need to make sure
argv is sane before accessing argv[0].
After fixing that, i noticed we were assuming a value of 1 for argc, which is
also not true, as i see 0 in my tests.
The following patch fixes up the test program to check for a NULL argv and also
touches the testcase itself to expect either 0 or 1 for argc depending on the
presence of argv, which is something we check early in the test.
This gives me full passes for aarch64-elf when running gdb.python/py-value.exp
and doesn't regress things on x86-64.
Ok?
gdb/testsuite/ChangeLog:
2016-10-06 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): Adjust initial
argc value based on the existence of argv.
---
gdb/testsuite/ChangeLog | 6 ++++++
gdb/testsuite/gdb.python/py-value.c | 6 +++++-
gdb/testsuite/gdb.python/py-value.exp | 13 +++++++++++--
3 files changed, 22 insertions(+), 3 deletions(-)
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index d4ae9df..e1d689a 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2016-10-06 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): Adjust initial
+ argc value based on the existence of argv.
+
2016-10-03 Antoine Tremblay <antoine.tremblay@ericsson.com>
2016-10-03 Simon Marchi <simon.marchi@ericsson.com>
diff --git a/gdb/testsuite/gdb.python/py-value.c b/gdb/testsuite/gdb.python/py-value.c
index 586a0fd..8408e1e 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,10 @@ main (int argc, char *argv[])
const char *sn = 0;
struct str *xstr;
+ /* Prevent gcc from optimizing argv[] out. */
+ if (argv != NULL)
+ cp = argv[0];
+
s.a = 3;
s.b = 5;
u.a = 7;
diff --git a/gdb/testsuite/gdb.python/py-value.exp b/gdb/testsuite/gdb.python/py-value.exp
index 57a9ba1..bb802bf 100644
--- a/gdb/testsuite/gdb.python/py-value.exp
+++ b/gdb/testsuite/gdb.python/py-value.exp
@@ -274,10 +274,19 @@ proc test_value_in_inferior {} {
gdb_test "python argc_notlazy.fetch_lazy()"
gdb_test "python print (argc_lazy.is_lazy)" "True"
gdb_test "python print (argc_notlazy.is_lazy)" "False"
- gdb_test "print argc" " = 1" "sanity check argc"
+
+ # If argv is not available, then argc is likely not available as well, thus
+ # we expect it to be 0.
+ set argc_value 0
+ if { $has_argv0 } {
+ set argc_value 1
+ }
+
+ gdb_test "print argc" " = $argc_value" "sanity check argc"
+
gdb_test "python print (argc_lazy.is_lazy)" "\r\nTrue"
gdb_test_no_output "set argc=2"
- gdb_test "python print (argc_notlazy)" "\r\n1"
+ gdb_test "python print (argc_notlazy)" "\r\n$argc_value"
gdb_test "python print (argc_lazy)" "\r\n2"
gdb_test "python print (argc_lazy.is_lazy)" "False"
--
2.7.4
next reply other threads:[~2016-10-06 16:27 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-06 16:27 Luis Machado [this message]
2016-10-07 10:23 ` Yao Qi
2016-10-07 11:42 ` Luis Machado
2016-10-07 12:09 ` Luis Machado
2016-10-07 14:48 ` Yao Qi
2016-10-07 15:07 ` Luis Machado
2016-10-07 16:52 ` Yao Qi
2016-10-07 17:00 ` Luis Machado
2016-10-10 17:04 ` Luis Machado
2016-10-11 8:18 ` Yao Qi
2016-10-07 18:21 ` Kevin Buettner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1475771231-1739-1-git-send-email-lgustavo@codesourcery.com \
--to=lgustavo@codesourcery.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox