Can't debug when with longjmp

J

JS

I have this code:

#include <setjmp.h>
#include <stdio.h>

jmp_buf ex;

static int foo (int a, int b)
{
if (!b)
longjmp (ex, 1); /* THROW */
else
return a/b;
}

int main (void)
{
int x = 0, y = 1, z = 0;
if (setjmp (ex) == 0) /* TRY : longjmp branches back to here */
{
x = foo(y, z);
}
else /* CATCH */
{
printf ("Exception: attempt to divide by zero\n");
}
}


It compiles fine and I am also able to run the .exe file. But when I debug
the code it stops when it comes to longjmp. I use eclipse with Cygwin gcc,
gdb, make etc.

Is there something special to do when debugging with longjmp and setjmp?

JS
 
J

Jack Klein

I have this code:

#include <setjmp.h>
#include <stdio.h>

jmp_buf ex;

static int foo (int a, int b)
{
if (!b)
longjmp (ex, 1); /* THROW */
else
return a/b;
}

int main (void)
{
int x = 0, y = 1, z = 0;
if (setjmp (ex) == 0) /* TRY : longjmp branches back to here */
{
x = foo(y, z);
}
else /* CATCH */
{
printf ("Exception: attempt to divide by zero\n");
}
}


It compiles fine and I am also able to run the .exe file. But when I debug
the code it stops when it comes to longjmp. I use eclipse with Cygwin gcc,
gdb, make etc.

Is there something special to do when debugging with longjmp and setjmp?

The C standard does not define the workings of debuggers, or even
require that such things exist. Try one of the gnu.gcc.* groups for
questions about gnu's debugger.
 
D

Daniel Haude

On Thu, 24 Mar 2005 12:02:12 +0100,
JS <dsa> wrote
in Msg. said:
It compiles fine and I am also able to run the .exe file. But when I debug
the code it stops when it comes to longjmp. I use eclipse with Cygwin gcc,
gdb, make etc.

Is there something special to do when debugging with longjmp and setjmp?

Try debugging not using a debugger, but by sprinkling your code with
diagnostic printf()s. That's how I debug almost all my code.

--Daniel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,161
Messages
2,570,892
Members
47,427
Latest member
HildredDic

Latest Threads

Top