[prog] Segmentation fault :-(
Conor Daly
c.daly at met.ie
Tue Sep 24 09:44:48 EST 2002
On Tue, Sep 24, 2002 at 06:06:57PM +1000 or thereabouts, Jacinta Richardson wrote:
>
> Something else to try is to add the following:
>
> /* at the top of your program */
> #include <assert.h>
>
> /* then */
> if (GetStatus() != SOCK_HS_SUCCESS)
> {
> assert(data != NULL);
> return BaseSocket::Receive(data, dataLen, flags);
> }
>
> assert.h provides the assert function. If the test is false it'll kill
> your program and provide you a useful error message. I found it a very
> handy debugging technique. Much tidier than:
> if(data == NULL)
> {
> fprintf(STDERR, "data is NULL at line 1234\n";
> exit(1);
> }
> especially because it saves you from worrying about moving line numbers.
> ;)
Another thing to remember, IIRC, is that printf() and fprintf() are often
asynchronous. The printf() inside the "BaseSocket::Receive()" function may
happen but the program segfaults _before_ the buffer is flushed to the
console. I'm not entirely sure about that but I seem to remember suffering
for it in the past... Adding a fflush(stdout); after the printf() might
help there. However, AIUI, assert() is not subject to the same limitation.
I was going to post this link to the list anyhow but it seems relevant here.
http://www.iol.ie/~padraiga/backtrace.c
backtrace.c is a little something that traps (user specified) signals and
syslogs (CRIT) the last 7 function calls and tries to dump core. Apparently it
has little/no overhead when running and is therefore suitable for inclusion
in release versions. It requires glibc.
Conor
--
Conor Daly
Met Eireann, Glasnevin Hill, Dublin 9, Ireland
Ph +353 1 8064276 Fax +353 1 8064247
------------------------------------
bofh.irmet.ie running RedHat Linux 9:37am up 11 days, 22:20, 9 users, load average: 0.00, 0.03, 0.08
**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.
This footnote also confirms that this email message has been swept
for the presence of computer viruses.
**********************************************************************
More information about the Programming
mailing list