Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH] Initialise data to appease valgrind
@ 2006-06-23 13:09 Andrew STUBBS
  2006-07-06 13:34 ` Daniel Jacobowitz
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew STUBBS @ 2006-06-23 13:09 UTC (permalink / raw)
  To: GDB Patches

[-- Attachment #1: Type: text/plain, Size: 799 bytes --]

When 'set debug expression 1' is used the debug code prints the full
contents of the expression 'elts' as a hex/ASCII dump. Unfortunately
this is a union so parts of it are potentially uninitialised.

This is not normally a problem (although displaying random data doesn't
sound like a good idea to me - especially for autotester etc.), but when
run under valgrind it causes a lot of output which hides the real problems.

The attached patch initialises the union before using it to ensure that
the whole thing is initialised. I suppose that it is not necessary to
initialise it in all the cases I have covered - the data fills the union
anyway, but it is safer this way and I imagine the compiler will do the
right thing in any case.

Tested with no regressions.

Andrew Stubbs

:ADDPATCH parse.c:

[-- Attachment #2: debug-expression.patch --]
[-- Type: text/plain, Size: 1693 bytes --]

2006-06-23  Andrew Stubbs  <andrew.stubbs@st.com>

	* parse.c (write_exp_elt_opcode, write_exp_elt_sym, write_exp_elt_block
	write_exp_elt_longcst, write_exp_elt_dblcst, write_exp_elt_type,
	write_exp_elt_intern): Zero initialize tmp.


Index: src/gdb/parse.c
===================================================================
--- src.orig/gdb/parse.c	2006-06-23 11:21:56.000000000 +0100
+++ src/gdb/parse.c	2006-06-23 11:29:35.000000000 +0100
@@ -191,6 +191,7 @@ void
 write_exp_elt_opcode (enum exp_opcode expelt)
 {
   union exp_element tmp;
+  memset (&tmp, 0, sizeof (union exp_element));
 
   tmp.opcode = expelt;
 
@@ -201,6 +202,7 @@ void
 write_exp_elt_sym (struct symbol *expelt)
 {
   union exp_element tmp;
+  memset (&tmp, 0, sizeof (union exp_element));
 
   tmp.symbol = expelt;
 
@@ -211,6 +213,7 @@ void
 write_exp_elt_block (struct block *b)
 {
   union exp_element tmp;
+  memset (&tmp, 0, sizeof (union exp_element));
   tmp.block = b;
   write_exp_elt (tmp);
 }
@@ -219,6 +222,7 @@ void
 write_exp_elt_longcst (LONGEST expelt)
 {
   union exp_element tmp;
+  memset (&tmp, 0, sizeof (union exp_element));
 
   tmp.longconst = expelt;
 
@@ -229,6 +233,7 @@ void
 write_exp_elt_dblcst (DOUBLEST expelt)
 {
   union exp_element tmp;
+  memset (&tmp, 0, sizeof (union exp_element));
 
   tmp.doubleconst = expelt;
 
@@ -239,6 +244,7 @@ void
 write_exp_elt_type (struct type *expelt)
 {
   union exp_element tmp;
+  memset (&tmp, 0, sizeof (union exp_element));
 
   tmp.type = expelt;
 
@@ -249,6 +255,7 @@ void
 write_exp_elt_intern (struct internalvar *expelt)
 {
   union exp_element tmp;
+  memset (&tmp, 0, sizeof (union exp_element));
 
   tmp.internalvar = expelt;
 


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Initialise data to appease valgrind
  2006-06-23 13:09 [PATCH] Initialise data to appease valgrind Andrew STUBBS
@ 2006-07-06 13:34 ` Daniel Jacobowitz
  2006-07-06 14:07   ` Andrew STUBBS
  0 siblings, 1 reply; 3+ messages in thread
From: Daniel Jacobowitz @ 2006-07-06 13:34 UTC (permalink / raw)
  To: Andrew STUBBS; +Cc: GDB Patches

On Fri, Jun 23, 2006 at 01:00:53PM +0100, Andrew STUBBS wrote:
> 2006-06-23  Andrew Stubbs  <andrew.stubbs@st.com>
> 
> 	* parse.c (write_exp_elt_opcode, write_exp_elt_sym, write_exp_elt_block
> 	write_exp_elt_longcst, write_exp_elt_dblcst, write_exp_elt_type,
> 	write_exp_elt_intern): Zero initialize tmp.

:REVIEWMAIL:

OK, thanks.


-- 
Daniel Jacobowitz
CodeSourcery


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Initialise data to appease valgrind
  2006-07-06 13:34 ` Daniel Jacobowitz
@ 2006-07-06 14:07   ` Andrew STUBBS
  0 siblings, 0 replies; 3+ messages in thread
From: Andrew STUBBS @ 2006-07-06 14:07 UTC (permalink / raw)
  To: GDB Patches

Daniel Jacobowitz wrote:
> On Fri, Jun 23, 2006 at 01:00:53PM +0100, Andrew STUBBS wrote:
>> 2006-06-23  Andrew Stubbs  <andrew.stubbs@st.com>
>>
>> 	* parse.c (write_exp_elt_opcode, write_exp_elt_sym, write_exp_elt_block
>> 	write_exp_elt_longcst, write_exp_elt_dblcst, write_exp_elt_type,
>> 	write_exp_elt_intern): Zero initialize tmp.
> 
> :REVIEWMAIL:
> 
> OK, thanks.

Thanks, committed.

Andrew


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2006-07-06 14:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-06-23 13:09 [PATCH] Initialise data to appease valgrind Andrew STUBBS
2006-07-06 13:34 ` Daniel Jacobowitz
2006-07-06 14:07   ` Andrew STUBBS

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox