From: "Andreas Eibach" <a.eibach@gmx.net>
To: "Shelby Cain" <scain1@austin.rr.com>
Cc: <cygwin@sourceware.cygnus.com>
Subject: Problems in using gdb to catch the seg fault (was: Re: Greetings...)
Date: Tue, 03 Oct 2000 12:47:00 -0000 [thread overview]
Message-ID: <04e301c02c61$eeec7e60$ad8106d5@default> (raw)
In-Reply-To: <005301c029a2$c74b1040$1605a018@austin.rr.com>
> 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
prev parent reply other threads:[~2000-10-03 12:47 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2000-09-28 16:20 Greetings Shelby Cain
2000-10-03 12:47 ` Andreas Eibach [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='04e301c02c61$eeec7e60$ad8106d5@default' \
--to=a.eibach@gmx.net \
--cc=cygwin@sourceware.cygnus.com \
--cc=scain1@austin.rr.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).