Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Daniel Jacobowitz <drow@false.org>
To: gdb-patches@sourceware.org
Subject: [commit] Reference some unused variables in the testsuite
Date: Thu, 12 Nov 2009 19:34:00 -0000	[thread overview]
Message-ID: <20091112193440.GA30558@caradoc.them.org> (raw)

Another testing improvement for ARM RealView.  This compiler strips unused code even
at -O0 (somewhat similar to --gc-sections).  Specifically:

  * Unused local variables will be discarded, but the usage does not
  have to be terribly sophisticated (constvars.c).

  * The standard library does not always pull in malloc.  If you want
  to be able to call malloc from the debugger you need to make sure
  the program references malloc (break.c).

  * If you link two files together, but one is never the target of a
  relocation, then that file won't make it into the output (hang1.cc).

Tested on arm-none-eabi and x86_64-linux.  Checked in.

2009-11-12  Daniel Jacobowitz  <dan@codesourcery.com>

	gdb/testsuite/
	* gdb.base/break.c (need_malloc): New.
	* gdb.base/constvars.c (main): Reference crass and crisp.
	* gdb.base/gdb1821.c (main): Reference bar.
	* gdb.cp/gdb1355.cc (main): Reference s1.
	* gdb.cp/hang1.cc (dummy2, dummy3): Declare.
	(main): Call them.
	* gdb.cp/hang2.cc (dummy2): Define.
	* gdb.cp/hang3.cc (dummy3): Define.
	* gdb.cp/m-data.cc (main): Reference shadow.

---
 gdb/testsuite/gdb.base/break.c     |    7 +++++++
 gdb/testsuite/gdb.base/constvars.c |    4 ++++
 gdb/testsuite/gdb.base/gdb1821.c   |    2 +-
 gdb/testsuite/gdb.cp/gdb1355.cc    |    3 ++-
 gdb/testsuite/gdb.cp/hang1.cc      |    5 ++++-
 gdb/testsuite/gdb.cp/hang2.cc      |    5 +++++
 gdb/testsuite/gdb.cp/hang3.cc      |    5 +++++
 gdb/testsuite/gdb.cp/m-data.cc     |    2 +-
 8 files changed, 29 insertions(+), 4 deletions(-)

Index: gdb-mainline/gdb/testsuite/gdb.base/break.c
===================================================================
--- gdb-mainline.orig/gdb/testsuite/gdb.base/break.c	2009-01-03 00:43:31.000000000 -0800
+++ gdb-mainline/gdb/testsuite/gdb.base/break.c	2009-11-11 09:04:38.000000000 -0800
@@ -62,6 +62,13 @@ extern void marker3 ();
 extern void marker4 ();
 #endif
 
+/* We're used by a test that requires malloc, so make sure it is in
+   the executable.  */
+void *need_malloc ()
+{
+  return malloc (1);
+}
+
 /*
  *	This simple classical example of recursion is useful for
  *	testing stack backtraces and such.
Index: gdb-mainline/gdb/testsuite/gdb.base/constvars.c
===================================================================
--- gdb-mainline.orig/gdb/testsuite/gdb.base/constvars.c	2006-11-10 00:23:07.000000000 -0800
+++ gdb-mainline/gdb/testsuite/gdb.base/constvars.c	2009-11-11 09:04:38.000000000 -0800
@@ -172,6 +172,10 @@ main (void)
   struct crass { char * const ptr; } crass = { lamprey };
   struct crisp { char * const *ptr; } crisp = { &lamprey };
 
+  /* Reference the structs so that they are not discarded.  */
+  struct crass *creed = &crass;
+  struct crisp *crow = &crisp;
+
   /* misc. references */
   /*
   const char           & radiation = laconic;
Index: gdb-mainline/gdb/testsuite/gdb.base/gdb1821.c
===================================================================
--- gdb-mainline.orig/gdb/testsuite/gdb.base/gdb1821.c	2007-08-24 00:22:59.000000000 -0700
+++ gdb-mainline/gdb/testsuite/gdb.base/gdb1821.c	2009-11-11 09:04:38.000000000 -0800
@@ -20,4 +20,4 @@
 struct foo { double x__0, y__0, z__1; } bar;
 
 
-int main(void) { return 0; }
+int main(void) { return (int) bar.x__0; }
Index: gdb-mainline/gdb/testsuite/gdb.cp/gdb1355.cc
===================================================================
--- gdb-mainline.orig/gdb/testsuite/gdb.cp/gdb1355.cc	2003-09-17 17:04:39.000000000 -0700
+++ gdb-mainline/gdb/testsuite/gdb.cp/gdb1355.cc	2009-11-11 09:04:38.000000000 -0800
@@ -31,5 +31,6 @@ struct mystruct s1 =
 
 int main ()
 {
-  return 0;
+  /* Reference s1 so that it is included.  */
+  return s1.m_int - 117;
 }
Index: gdb-mainline/gdb/testsuite/gdb.cp/hang1.cc
===================================================================
--- gdb-mainline.orig/gdb/testsuite/gdb.cp/hang1.cc	2008-04-30 11:28:23.000000000 -0700
+++ gdb-mainline/gdb/testsuite/gdb.cp/hang1.cc	2009-11-11 09:04:38.000000000 -0800
@@ -1,3 +1,6 @@
 #include "hang.H"
 
-int main (int argc, char **argv) { return 0; }
+extern int dummy2 (void);
+extern int dummy3 (void);
+
+int main (int argc, char **argv) { return dummy2() + dummy3(); }
Index: gdb-mainline/gdb/testsuite/gdb.cp/hang2.cc
===================================================================
--- gdb-mainline.orig/gdb/testsuite/gdb.cp/hang2.cc	2008-04-30 11:28:23.000000000 -0700
+++ gdb-mainline/gdb/testsuite/gdb.cp/hang2.cc	2009-11-11 09:04:38.000000000 -0800
@@ -6,3 +6,8 @@ struct B
 };
 
 int var_in_b = 1729;
+
+int dummy2 (void)
+{
+  return var_in_b;
+}
Index: gdb-mainline/gdb/testsuite/gdb.cp/hang3.cc
===================================================================
--- gdb-mainline.orig/gdb/testsuite/gdb.cp/hang3.cc	2008-04-30 11:28:23.000000000 -0700
+++ gdb-mainline/gdb/testsuite/gdb.cp/hang3.cc	2009-11-11 09:04:38.000000000 -0800
@@ -2,3 +2,8 @@
 
 const struct B *const_B_ptr;
 int var_in_hang3 = 42;
+
+int dummy3 (void)
+{
+  return var_in_hang3;
+}
Index: gdb-mainline/gdb/testsuite/gdb.cp/m-data.cc
===================================================================
--- gdb-mainline.orig/gdb/testsuite/gdb.cp/m-data.cc	2003-08-22 20:55:59.000000000 -0700
+++ gdb-mainline/gdb/testsuite/gdb.cp/m-data.cc	2009-11-11 09:04:38.000000000 -0800
@@ -60,5 +60,5 @@ int main()
   C theC (1);				// breakpoint: first-constructs-done
   theC.marker ();
   
-  return 0;
+  return shadow;
 }

-- 
Daniel Jacobowitz
CodeSourcery


             reply	other threads:[~2009-11-12 19:34 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-12 19:34 Daniel Jacobowitz [this message]
2009-11-12 19:40 ` Joel Brobecker

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=20091112193440.GA30558@caradoc.them.org \
    --to=drow@false.org \
    --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