delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2000/10/03/15:48:26

Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT sources DOT redhat DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT sources DOT redhat DOT com>
List-Help: <mailto:cygwin-help AT sources DOT redhat DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT sources DOT redhat DOT com
Delivered-To: mailing list cygwin AT sources DOT redhat DOT com
Message-ID: <04e301c02c61$eeec7e60$ad8106d5@default>
From: "Andreas Eibach" <a DOT eibach AT gmx DOT net>
To: "Shelby Cain" <scain1 AT austin DOT rr DOT com>
Cc: <cygwin AT sourceware DOT cygnus DOT com>
References: <005301c029a2$c74b1040$1605a018 AT austin DOT rr DOT com>
Subject: Problems in using gdb to catch the seg fault (was: Re: Greetings...)
Date: Mon, 2 Oct 2000 13:14:28 +0200
MIME-Version: 1.0
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 5.50.4133.2400
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400


> I'm used to using tools like gcc, gdb, make,
> etc in a mixed environment of Solaris and Linux.
>
> My problem is taking a simple program like so:


[1]> int main()
[2]> {
[3]>     char * foo = 0;
[4]>     crashme(foo);
[5]> }
[6]>
[7]> int crashme(char * cp);
[8]> {
[9]>     strcpy(cp, "KABOOM!!");
[10]> }
[11]>

AARGHH...
Well I'm no C professional, but I can say there's something odd about your
code.
To put this another way: I've _never_ _seen_ _this_!

You can be quite happy that this is not considered a crime you could be
arrested for
*grin*
Why do people need to crash programs _intentionally_ - just for fun?
OH BOY...;)

I've added line numbers to be able to better refer to specific lines.

Rule Of Thumb:
 - NEVER program any function without a prototype!!

- Line [7] IS a *prototype*, but where's the *function*??

 [7]> int crashme(char * cp);

You MUST  NOT  set a semicolon if you want to _code_ the function.
So:
 void function(char * parm)  /* no semicolon!! */
 {

 }

And WHY do you define the function as INT if you don't want a return value??
This can't be reasonable.
If you insist to use an INT function you must call  it this way:

  int dummy;

 dummy = crashme(foo);

 And crashme() must contain return <something>;
 So do declare the function as VOID if you don't want return values!

-----

So use this code if you want to "debug" your "program":

/* _prototype_ of function = DECLARATION */

void crashme (char *);

 int main(void)
 {
    char * foo = 0;
    crashme(foo);
 }

/* _implementation_ of function = DEFINITION, don't confuse these! */

void crashme(char * cp) /* no semicolon!! */
 {
    strcpy(cp, "KABOOM!!");
 }

--------

Let's test it now.
I know it still _crashes_ now (that's what you wanted, eh? :P )
because if the program  was written correctly,
main() had got a char[] vector and not foo would've passed to
crashme(), but &foo (the address).

Andreas

NB: I got a correctly dumped core now.




--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe AT sourceware DOT cygnus DOT com

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019