Mailing-List: contact cygwin-help@sourceware.cygnus.com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe@sources.redhat.com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin@sources.redhat.com>
List-Help: <mailto:cygwin-help@sources.redhat.com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner@sources.redhat.com
Delivered-To: mailing list cygwin@sources.redhat.com
Message-ID: <04e301c02c61$eeec7e60$ad8106d5@default>
From: "Andreas Eibach" <a.eibach@gmx.net>
To: "Shelby Cain" <scain1@austin.rr.com>
Cc: <cygwin@sourceware.cygnus.com>
References: <005301c029a2$c74b1040$1605a018@austin.rr.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
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
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@sourceware.cygnus.com

