Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [patch] ada: Fix rashes on gdbarch garbage
@ 2011-03-21 10:46 Jan Kratochvil
  2011-03-21 15:06 ` Joel Brobecker
  0 siblings, 1 reply; 3+ messages in thread
From: Jan Kratochvil @ 2011-03-21 10:46 UTC (permalink / raw)
  To: Joel Brobecker; +Cc: gdb-patches

Hi Joel,

for gdb.ada/str_ref_cmp.exp on x86_64-fedora15-linux-gnu it turns:

(gdb) print String_Var (1 .. 3) = "Hel"
ERROR: Process no longer exists
UNRESOLVED: gdb.ada/str_ref_cmp.exp: print String_Var (1 .. 3) = "Hel"
->
(gdb) print String_Var (1 .. 3) = "Hel"
$1 = false
(gdb) FAIL: gdb.ada/str_ref_cmp.exp: print String_Var (1 .. 3) = "Hel"

GDB crashes the former way without this fix on:
	gcc-gnat-4.6.0-0.14.fc15.x86_64
	gcc-gnat-4.5.1-4.fc14.x86_64

I cannot test FSF gcc <=4.5 myself as its Ada build errors out for me on:
	uintp.adb:242:22: expect type "Hnum" defined at line 91

GDB PASSes on these GNATs even without this fix but that is not the point:
	GNAT 4.7.0 20110320 (experimental)
	GNAT 4.6.0 20110320 (prerelease)

This is only a suggestion, I do not know much about the ada-* code.


Thanks,
Jan


gdb/
2011-03-20  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* ada-lang.c (replace_operator_with_call): Copy also GDBARCH.

--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -3661,6 +3661,7 @@ replace_operator_with_call (struct expression **expp, int pc, int nargs,
 
   newexp->nelts = exp->nelts + 7 - oplen;
   newexp->language_defn = exp->language_defn;
+  newexp->gdbarch = exp->gdbarch;
   memcpy (newexp->elts, exp->elts, EXP_ELEM_TO_BYTES (pc));
   memcpy (newexp->elts + pc + 7, exp->elts + pc + oplen,
           EXP_ELEM_TO_BYTES (exp->nelts - pc - oplen));


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

* Re: [patch] ada: Fix rashes on gdbarch garbage
  2011-03-21 10:46 [patch] ada: Fix rashes on gdbarch garbage Jan Kratochvil
@ 2011-03-21 15:06 ` Joel Brobecker
  2011-03-21 15:39   ` Jan Kratochvil
  0 siblings, 1 reply; 3+ messages in thread
From: Joel Brobecker @ 2011-03-21 15:06 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: gdb-patches

Hi Jan,

Thanks for the investigative work!

> gdb/
> 2011-03-20  Jan Kratochvil  <jan.kratochvil@redhat.com>
> 
> 	* ada-lang.c (replace_operator_with_call): Copy also GDBARCH.

This change looks definitely correct to me, so I've checked it in.
It's strange that I am not able to reproduce it, even after I changed
the xmalloc to xzalloc...

To prevent any further fields from being undefined, I have also
checked the following patch in.

gdb/ChangeLog:

	* ada-lang.c (replace_operator_with_call): Use xzalloc instead
	of xmalloc.

Tested on x86_64-linux.

-- 
Joel


commit 6cb8c1c196651db26b01653b688547a203089162
Author: Joel Brobecker <brobecker@adacore.com>
Date:   Mon Mar 21 07:36:17 2011 -0700

    use xzalloc in ada-lang.c:replace_operator_with_call
    
    This is to make sure that we cannot have a field with an undefined
    value (currently, we are not setting the gdbarch).
    
    gdb/ChangeLog:
    
    	* ada-lang.c (replace_operator_with_call): Use xzalloc instead
    	of xmalloc.

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 64d8391..d79197e 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2012-03-21  Joel Brobecker  <brobecker@adacore.com>
+
+	* ada-lang.c (replace_operator_with_call): Use xzalloc instead
+	of xmalloc.
+
 2012-03-18  Pedro Alves  <pedro@codesourcery.com>
 
 	* frame.c (frame_unwind_register): Throw an error if unwinding the
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 3746edc..93711cf 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -3659,7 +3659,7 @@ replace_operator_with_call (struct expression **expp, int pc, int nargs,
   /* A new expression, with 6 more elements (3 for funcall, 4 for function
      symbol, -oplen for operator being replaced).  */
   struct expression *newexp = (struct expression *)
-    xmalloc (sizeof (struct expression)
+    xzalloc (sizeof (struct expression)
              + EXP_ELEM_TO_BYTES ((*expp)->nelts + 7 - oplen));
   struct expression *exp = *expp;
 


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

* Re: [patch] ada: Fix rashes on gdbarch garbage
  2011-03-21 15:06 ` Joel Brobecker
@ 2011-03-21 15:39   ` Jan Kratochvil
  0 siblings, 0 replies; 3+ messages in thread
From: Jan Kratochvil @ 2011-03-21 15:39 UTC (permalink / raw)
  To: Joel Brobecker; +Cc: gdb-patches

Hi Joel,

On Mon, 21 Mar 2011 15:47:16 +0100, Joel Brobecker wrote:
> To prevent any further fields from being undefined, I have also
> checked the following patch in.
> 
> gdb/ChangeLog:
> 
> 	* ada-lang.c (replace_operator_with_call): Use xzalloc instead
> 	of xmalloc.

The downside is valgrind will no longer complain like it did in the reported
case.  Still I agree it is probably better for users this way.


Thanks,
Jan


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

end of thread, other threads:[~2011-03-21 14:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-21 10:46 [patch] ada: Fix rashes on gdbarch garbage Jan Kratochvil
2011-03-21 15:06 ` Joel Brobecker
2011-03-21 15:39   ` Jan Kratochvil

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