New bee question
James Youngman
jay at gnu.org
Sun Aug 30 14:26:34 CEST 2009
On Sat, Aug 29, 2009 at 9:21 AM, Alban Nonymous<alban.nonymous at gmail.com> wrote:
> Dear GMP,
>
> I am new user of GMP and I am new to writing programs.
> My program gets signal 11 and signal 4.
See "man 7 signal".
> What are typical
> error with programming GMP?
The same as for any other C program. Your fatal signals are caused
by software bugs. Almost certainly these are in your program, but
it's not totally impossible they're in GMP (though nobody else has
reported a problem; I'm pretty certain they're in your code).
As for what might have caused this, SIGILL is caused by executing an
invalid instruction. This normally happens when your program
scribbles all over the stack and a return instruction catapaults the
program counter into something that isn't actually machine code (e.g.
your program is trying to execute data). SIGSEGV is in practice a
little more general. Your program is trying to access a memory
address where nothing has ever existed. This typically is also caused
by your program scribbling on the stack or overwriting other data
structures or accessing a pointer before the pointer has been
initialised to point somewhere useful.
As for what to do to find the problem, the most powerful technique is
bisection. Start by using a version control system (like GIT or RCS)
so that you can access previous versions of your code easily. Then,
using a version of your program that fails, try removing every part of
the program you can, in order to find the smallest program the
exhibits your problem. Then stare very hard at what remains...
Since you're new to programming, it's quite likely though that you may
not be able to see the bug just by looking at it, even in a minimal
program. You may find a debugger helpful (I use "M-x gdb" in Emacs).
Here is a short list of things you might check for:
1. Using a GMP variable without first calling the appropriate
...init() function (for example mpz_init*() for variables of type
mpz_t).
2. Using a char* variable that doesn't point to anything (i.e. which
isn't initialised from the result of malloc)
Hope this helps,
James.
More information about the gmp-discuss
mailing list