public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* C++ SEGMENT fault and vtable issues
@ 2012-10-14 21:20 Arthur Schwarz
  2012-10-15 10:15 ` Jonathan Wakely
  0 siblings, 1 reply; 3+ messages in thread
From: Arthur Schwarz @ 2012-10-14 21:20 UTC (permalink / raw)
  To: gcc-help

Product Version = NetBeans IDE 7.2 (Build 201207171143)
Operating System = Windows 7 version 6.1 running on x86
Java; VM; Vendor = 1.7.0_03
Runtime = Java HotSpot(TM) Client VM 22.1-b02

Cygwin gcc 4.5.3
             gdb 4.5.3

I have a problem with my C++ application. I have tried to find what is wrong in 
my code and am unsuccessful, and amm hping that you can identify the issue.

The code fails (for different reasons) in two locations:
[code]
  SlipHeader* oldHeader;
   delete oldHeader;     // SEGMENT fault; custom defined delete

  SlipHeader* header;
  stringstream pretty;
  pretty << header->toString(); // call to pure virtual function
[/code]

The sequence of events is:
1:  The first time through the code there is no exception.
2:  The second time through the code there is an exception

In the first case, the address pointed to by oldHeader is within the range of 
values which should not produce a segment fault. I do my own 
allocation/dallocation. During allocation I get a block of memory. The address 
pointed to is within the block. gdb doesn't provide any support in debugging so 
I can't get any support other than the assumption that at the time the delete is 
executed oldHeader points to or is the cause of the fault.

In the second instance I've looked at the vtable address and it is the same for 
both the failed instance and the successfully executing instance.

I've looked at my code (step by naughty step) to try to find when the transition 
from legitimate to illegitimate occurs and can not find any difference (to 
warrant the errors).

So, does anyone have any thoughts as to what I might have done wrong and how to 
find what I have done wrong? I've wored around the problem but I just know it's 
going to pop up elsewhere - I'm writing regression tests and these errors just 
popped up.

thanks
art

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

* Re: C++ SEGMENT fault and vtable issues
  2012-10-14 21:20 C++ SEGMENT fault and vtable issues Arthur Schwarz
@ 2012-10-15 10:15 ` Jonathan Wakely
  2012-10-17  5:58   ` Arthur Schwarz
  0 siblings, 1 reply; 3+ messages in thread
From: Jonathan Wakely @ 2012-10-15 10:15 UTC (permalink / raw)
  To: Arthur Schwarz; +Cc: gcc-help

On 14 October 2012 20:29, Arthur Schwarz wrote:
> Product Version = NetBeans IDE 7.2 (Build 201207171143)
> Operating System = Windows 7 version 6.1 running on x86
> Java; VM; Vendor = 1.7.0_03
> Runtime = Java HotSpot(TM) Client VM 22.1-b02

I doubt your IDE or JVM is relevant.


> Cygwin gcc 4.5.3
>              gdb 4.5.3
>
> I have a problem with my C++ application. I have tried to find what is wrong in
> my code and am unsuccessful, and amm hping that you can identify the issue.
>
> The code fails (for different reasons) in two locations:
> [code]
>   SlipHeader* oldHeader;
>    delete oldHeader;     // SEGMENT fault; custom defined delete
>
>   SlipHeader* header;
>   stringstream pretty;
>   pretty << header->toString(); // call to pure virtual function
> [/code]

Clearly this isn't the real code, because oldHeader and header are
never initialized.  If you show the real code, preferably reduced to
the minimum necessary to demonstrate the problem, then someone might
be able to suggest where to look for the bug.

It sounds like using an object after it's been deleted or some other
memory/lifetime issue.  On GNU/Linux I'd use valgrind to check for
that sort of problem.  There are tools to do a similar job on Windows,
but the only one I've tried is far inferior to valgrind and isn't free
(as in beer or freedom) so I won't recommend it.

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

* Re: C++ SEGMENT fault and vtable issues
  2012-10-15 10:15 ` Jonathan Wakely
@ 2012-10-17  5:58   ` Arthur Schwarz
  0 siblings, 0 replies; 3+ messages in thread
From: Arthur Schwarz @ 2012-10-17  5:58 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: gcc-help

Hi Jonathan;

I haven't been ignoring you (no sir). I just started to try to pare down the 
code so that the 'experience' is highlighted, and at the same time, make some 
coordinated changes to the original code. without understanding why, the 
original code now works correctly (or seems to). There are still some unsolved 
problems which I am quite confused over, but, time (and space) being what they 
are, I'm going to try to finish my regression tests before the cows come home. 
So, sigh. all is lost.

Thank you for taking the time to reply. I would really have liked to find the 
root cause of the issues that I saw, but, I'd rather finish the project. 


art



----- Original Message ----
From: Jonathan Wakely <jwakely.gcc@gmail.com>
To: Arthur Schwarz <aschwarz1309@att.net>
Cc: gcc-help@gcc.gnu.org
Sent: Sun, October 14, 2012 4:19:13 PM
Subject: Re: C++ SEGMENT fault and vtable issues

On 14 October 2012 20:29, Arthur Schwarz wrote:
> Product Version = NetBeans IDE 7.2 (Build 201207171143)
> Operating System = Windows 7 version 6.1 running on x86
> Java; VM; Vendor = 1.7.0_03
> Runtime = Java HotSpot(TM) Client VM 22.1-b02

I doubt your IDE or JVM is relevant.


> Cygwin gcc 4.5.3
>              gdb 4.5.3
>
> I have a problem with my C++ application. I have tried to find what is wrong 
in
> my code and am unsuccessful, and amm hping that you can identify the issue.
>
> The code fails (for different reasons) in two locations:
> [code]
>   SlipHeader* oldHeader;
>    delete oldHeader;     // SEGMENT fault; custom defined delete
>
>   SlipHeader* header;
>   stringstream pretty;
>   pretty << header->toString(); // call to pure virtual function
> [/code]

Clearly this isn't the real code, because oldHeader and header are
never initialized.  If you show the real code, preferably reduced to
the minimum necessary to demonstrate the problem, then someone might
be able to suggest where to look for the bug.

It sounds like using an object after it's been deleted or some other
memory/lifetime issue.  On GNU/Linux I'd use valgrind to check for
that sort of problem.  There are tools to do a similar job on Windows,
but the only one I've tried is far inferior to valgrind and isn't free
(as in beer or freedom) so I won't recommend it.

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

end of thread, other threads:[~2012-10-16 22:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-10-14 21:20 C++ SEGMENT fault and vtable issues Arthur Schwarz
2012-10-15 10:15 ` Jonathan Wakely
2012-10-17  5:58   ` Arthur Schwarz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).