Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [Patch] x % 0 hangs
@ 2004-06-26  9:23 David Lecomber
  0 siblings, 0 replies; 9+ messages in thread
From: David Lecomber @ 2004-06-26  9:23 UTC (permalink / raw)
  To: gdb-patches

Hi

On my x86, gdb does not enjoy evaluating x % 0 or x / 0 for any x: it
hangs.

Although there may be some systems that can healthily respond to this, I
propose a trivial patch - unless someone is going to tell me there's an
option to stop the hanging, or respond differently to the signal.

2004-06-26    <david@streamline-computing.com>

	* valarith.c: check for zero in division and remainder
	evaluation.

Index: valarith.c
===================================================================
RCS file: /cvs/src/src/gdb/valarith.c,v
retrieving revision 1.22
diff -u -p -r1.22 valarith.c
--- valarith.c  1 Apr 2004 12:08:30 -0000       1.22
+++ valarith.c  26 Jun 2004 09:21:31 -0000
@@ -1040,7 +1040,10 @@ value_binop (struct value *arg1, struct
              break;
  
            case BINOP_DIV:
-             v = v1 / v2;
+             if (v2 != 0)
+               v = v1 / v2;
+             else
+               error ("Cannot perform division: division by zero");
               break;
  
             case BINOP_EXP:
@@ -1050,7 +1053,10 @@ value_binop (struct value *arg1, struct
              break;
  
            case BINOP_REM:
-             v = v1 % v2;
+             if (v2 != 0)
+               v = v1 % v2;
+             else
+               error ("Cannot perform remainer: division by zero");
              break;
  
            case BINOP_MOD:



^ permalink raw reply	[flat|nested] 9+ messages in thread
* Re: [Patch] x % 0 hangs
@ 2004-06-26 15:44 Michael Elizabeth Chastain
  2004-06-26 22:52 ` Mark Kettenis
  0 siblings, 1 reply; 9+ messages in thread
From: Michael Elizabeth Chastain @ 2004-06-26 15:44 UTC (permalink / raw)
  To: david, gdb-patches

I like your patch, although I can't approve it.

There is a PR for this:

  http://sources.redhat.com/gdb/bugs/1056
  divide by zero hangs gdb

Could you a line to your ChangeLog like this:

2004-06-26    <david@streamline-computing.com>

	Partial fix for PR cli/1056.
	* valarith.c: check for zero in division and remainder
	evaluation.

> Although there may be some systems that can healthily respond to this, I
> propose a trivial patch - unless someone is going to tell me there's an
> option to stop the hanging, or respond differently to the signal.

Someone still has to dive into the signal handling design and fix the
lower-level problem, which is analyzed in the PR.  Briefly, the problem
is that gdb defers the its response to the signal and returns from the
signal handler, but returning from the signal handler for SIGFPE can
re-execute the same instruction that hung.

But I'm all for patching value_binop and providing a friendly
error message for BINOP_DIV and BINOP_REM.  That's the most common
place a gdb user would generate a SIGFPE.

Michael C


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

end of thread, other threads:[~2004-07-17  2:43 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-06-26  9:23 [Patch] x % 0 hangs David Lecomber
2004-06-26 15:44 Michael Elizabeth Chastain
2004-06-26 22:52 ` Mark Kettenis
2004-06-26 23:19   ` Andrew Cagney
2004-06-27 15:06     ` Ian Lance Taylor
2004-06-27 17:15       ` Mark Kettenis
2004-06-28 14:25         ` Andrew Cagney
2004-06-29 23:35           ` Mark Kettenis
2004-07-17  2:43             ` Andrew Cagney

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