New debugging method(OT?)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • vashwath@rediffmail.com

    #1

    New debugging method(OT?)

    Probably OT, but I did not get any suitable group to discuss this as
    this post also has question regarding malloc.
    For my current project I am inserting the following statements
    randomly.
    {
    int x = 0;
    if (x == 1)
    exit(0);
    }
    I can exit by setting x to 1(Using Debugger) at anytime I want.I found
    that if there is any mistake in the like dynamic array overflow, The
    program will exit with SIGSEGV.If there is nothing wrong with code
    until exiting, the program will exit normally.I know this does not work
    always, but I am able to find certain mistakes.

    Now, Have a look at the following piece of code.

    {
    int x = 0;
    if (x == 1)/*I can exit when ever I want by setting x to 1 using
    debugger*/
    exit(0); /*Here the program is exiting normally*/
    }
    some_var = malloc(some size);
    {
    int x = 0;
    if (x == 1)
    exit(0);/*Here the program is exiting with SIGSEGV*/
    }

    When the exit statement is executed after malloc the program is exiting
    with SIGSEGV, but if the exit statement is executed just before malloc,
    it is exiting normally.Does this mean there is some problem with
    malloc(I don't think so:))?Or what is causing this strange behavior?

    I am using gcc on Linux for compilation.

  • Flash Gordon

    #2
    Re: New debugging method(OT?)

    vashwath@rediff mail.com wrote:

    <snip>
    [color=blue]
    > When the exit statement is executed after malloc the program is exiting
    > with SIGSEGV, but if the exit statement is executed just before malloc,
    > it is exiting normally.Does this mean there is some problem with
    > malloc(I don't think so:))?Or what is causing this strange behavior?[/color]

    You are almost certainly correct in thinking malloc is *not* the
    problem. The problem is almost certainly that you have gone of the end
    of a buffer (either end) and overwritten some data critical to the
    correct operation of malloc, thus *you* are causing malloc to fail.
    However, it could be something you have done 23487972354 lines earlier.

    Of course, if you had checked the comp.lang.c FAQ you would have seen
    lots of information on this.




    Lots of other questions in the FAQ apply as well.
    [color=blue]
    > I am using gcc on Linux for compilation.[/color]

    <OT>
    Try using valgrind, but don't ask for help on it here since we only deal
    with standard C not all the multifarious tools that are available.
    </OT>
    --
    Flash Gordon
    Living in interesting times.
    Although my email address says spam, it is real and I read it.

    Comment

    Working...