473,411 Members | 1,923 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

why GDB's bt shows only one main()

Hai, i am newbie to C , i compiled the following code and ran it in
GDB, with the break point at main.

#include <stdio.h>
int main()
{
static int i=0;
if (10 == i)
return ;
i++;
main();
printf("%d\n", i );
}

Whenever main is being called recursively , i did a "backstrace' , but
instead of showing many frames of main, i always shows only one frame
of main().. WHY?

Jan 5 '07 #1
3 1353
ra**********@gmail.com writes:
Hai, i am newbie to C , i compiled the following code and ran it in
GDB, with the break point at main.

#include <stdio.h>
int main()
{
static int i=0;
if (10 == i)
return ;
i++;
main();
printf("%d\n", i );
}

Whenever main is being called recursively , i did a "backstrace' , but
instead of showing many frames of main, i always shows only one frame
of main().. WHY?
No idea. That's not really a C question. Try a newsgroup that deals
with gdb, perhaps comp.unix.programmer.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Jan 5 '07 #2
ra**********@gmail.com wrote:
Hai, i am newbie to C , i compiled the following code and ran it in
GDB, with the break point at main.

#include <stdio.h>
int main()
{
static int i=0;
if (10 == i)
return ;
i++;
main();
printf("%d\n", i );
}

Whenever main is being called recursively , i did a "backstrace' , but
instead of showing many frames of main, i always shows only one frame
of main().. WHY?
This is the wrong group. Post to one of the gnu.* groups or
comp.unix.programmer or RTFM.

Hint: Check if you've enabled debugging support during compilation and
turn off all optimisation flags.

Jan 5 '07 #3
ra**********@gmail.com wrote:
>
Hai, i am newbie to C , i compiled the following code and ran it
in GDB, with the break point at main.

#include <stdio.h>
int main()
{
static int i=0;
if (10 == i)
return ;
i++;
main();
printf("%d\n", i );
}

Whenever main is being called recursively , i did a "backstrace',
but instead of showing many frames of main, i always shows only
one frame of main().. WHY?
Seems to do just what you asked it to do here:

[1] c:\c\junk>cat junk.c
#include <stdio.h>
int main()
{
static int i=0;
if (10 == i)
return ;
i++;
main();
printf("%d\n", i );
}

[1] c:\c\junk>cc junk.c
junk.c: In function `main':
junk.c:6: warning: `return' with no value, in function returning
non-void
junk.c:10: warning: control reaches end of non-void function

[1] c:\c\junk>.\a
10
10
10
10
10
10
10
10
10
10

Maybe if you fix the warnings and copy the printf statement to the
north side of the recursive call to main you will get a clue. Use
"int main(void)" in the definition of main.

GDB has nothing to do with this newsgroup.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>

Jan 5 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: davinci | last post by:
I had study it for a long time .but I didn't solve it .Ihad read <<Debuging with GDB>> But I didn't get something useful. include<iostream> #include<cstdlib> using std::isdigit; int main() { ...
2
by: O.R.Senthil Kumaran | last post by:
Hi list: Following is a piece of code: main(int argc, char** argv) { int rc, result; struct passwd *uidpwent; /* init resources */
1
by: sunil | last post by:
Hi, I am trying to print a variable port using print command , the port variable is coming as function arguement.See the snippet below. 680 printf("The port number is %d\n",port);...
1
by: seba | last post by:
Hi everybody, I'm trying to debud a c++ program using gdb, but I have this problem. $ gdb GNU gdb Red Hat Linux (6.5-15.fc6rh) (gdb) file ./newcall Reading symbols from...
2
by: Mahesh | last post by:
Hi, I encounted some problems using GDB with classes that use virtual inheritance. To illustrate this issue, I have created a simple test case. Here it goes. #include <iostream>
29
by: Pietro Cerutti | last post by:
Hello, here I have a strange problem with a real simple strtok example. The program is as follows: ### BEGIN STRTOK ### #include <string.h> #include <stdio.h>
8
by: FBM | last post by:
Hi there, I am puzzled with the behavior of my code.. I am working on a networking stuff, and debugging with eclipse (GNU gdb 6.6-debian).. The problem I am experiencing is the following: ...
0
by: shravagiparag | last post by:
Hello, I am developing a console application to invoke gdb session and log in the communication between my application and gdb. I opened gdb as a new process and tried to redirect the input and...
2
jwwicks
by: jwwicks | last post by:
C/C++ Programs and Debugging in Linux This tutorial will give you a basic idea how to debug a program in Linux using GDB. As you are aware Visual Studio doesn’t run on Linux so you have to use...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.