Mirror of the gdb mailing list
 help / color / mirror / Atom feed
From: Steven Johnson <sjohnson@sakuraindustries.com>
To: Daniel Jacobowitz <drow@false.org>
Cc: gdb@sources.redhat.com
Subject: Re: Unwinding stack past main() when it has another name
Date: Thu, 16 Jun 2005 22:46:00 -0000	[thread overview]
Message-ID: <42B336A4.40704@sakuraindustries.com> (raw)
In-Reply-To: <20050616220527.GA9960@nevyn.them.org>

Daniel Jacobowitz wrote:

>On Fri, Jun 17, 2005 at 08:22:13AM -1100, Steven Johnson wrote:
>  
>
>>Daniel Jacobowitz wrote:
>>
>>    
>>
>>>The fact that we stop at _start is a feature, so hopefully you can rely
>>>on that in the future.
>>>
>>>For some non-C languages we get the name of the main function from
>>>debug information, but for C it's always main()
>>>
>>>
>>>      
>>>
>>This isnt always the case for embedded targets.  There is no RULE that C 
>>programs must have a main() function.  It may be that most do by 
>>convention, but they dont have to.  In fact, main() can be a pain for 
>>small embedded targets because it wants a return value and arguments, 
>>which mean nothing for a program that isnt "launched" by a user on 
>>demand, but the C compiler detects the special function name main() and 
>>objects if it doesnt have the standard format.  Programs dont even need 
>>to have an entry point called _start.  It all depends on how you set up 
>>your link map.
>>    
>>
>
>In fact you're wrong: there is a rule that C programs must have a
>main() function.  It's in the language standard.
>  
>
I stand corrected.  It is in fact in the standard as you say.  I have 
just been so exposed to code (written by many people) where the first C 
function that runs isnt called "main" it seemed to be a convention 
rather than a rule.  But as you say, many tool chains, gcc included 
allow for a program to not have a "main" function if you get in and 
modify the startup code and link map, which you often do for embedded 
targets, and doing so is not "standard" C.

>The fact that many embedded toolchains allow you to do things
>differently is outside the boundaries of the language standard, and if
>you don't have a main() your backtraces will stop at your entry point,
>determined from the ELF file.  GDB'll do the best it can.
>
>  
>
I wasnt suggesting GDB was broken in this regard, I was simply pointing 
out that not all (what Ive always considered to be) "C" programs have a 
main() function.

Steven


  reply	other threads:[~2005-06-16 22:46 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-06-15 12:46 Hamish Rodda
2005-06-15 14:16 ` Daniel Jacobowitz
2005-06-15 15:14   ` Hamish Rodda
2005-06-15 16:37     ` Daniel Jacobowitz
2005-06-16  7:42       ` Hamish Rodda
2005-06-16 13:23         ` Daniel Jacobowitz
2005-06-16 21:22           ` Steven Johnson
2005-06-16 22:05             ` Daniel Jacobowitz
2005-06-16 22:46               ` Steven Johnson [this message]
2005-06-17 11:21               ` Richard Earnshaw
2005-06-18 13:13                 ` Eli Zaretskii
2005-06-16 23:36             ` Mark Kettenis

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=42B336A4.40704@sakuraindustries.com \
    --to=sjohnson@sakuraindustries.com \
    --cc=drow@false.org \
    --cc=gdb@sources.redhat.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