How to step in one function after the function be executed in gdb?


 
Thread Tools Search this Thread
Top Forums Programming How to step in one function after the function be executed in gdb?
# 1  
Old 10-27-2011
How to step in one function after the function be executed in gdb?

In gdb, I can call one function with command "call", but how can I step in the function? I don't want to restart the program, but the function had been executed, gdb will execute next statement, and I don't know how to recall the function.
# 2  
Old 10-27-2011
Use the shortcut "s" to step into the function.

--ahamed

---------- Post updated at 06:48 AM ---------- Previous update was at 06:45 AM ----------

Code:
root@bt:/tmp# gdb ./a.out
...
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /tmp/a.out...done.
(gdb) b main
Breakpoint 1 at 0x8048732: file run.cpp, line 16.
(gdb) run
Starting program: /tmp/a.out 

Breakpoint 1, main (argc=1, argv=0xbffff604) at run.cpp:16
16        callme();
(gdb) step
callme () at run.cpp:6
6        cout<<"callme()"<<endl;
(gdb)

--ahamed
# 3  
Old 10-27-2011
Thanks
Code:
#include <stdio.h>
void callme(){
    fputs( "hello\n", stdout );
}
void main() {
    fputs( "begin\n", stdout );
    callme();
    fputs( "end\n", stdout );
}

gdb :
Code:
(gdb) n
begin
24        callme();
(gdb) 
hello
25        fputs( "end\n", stdout );
(gdb) 
end
26    }
(gdb) call callme
$1 = {void ()} 0x80483e4 <callme>
(gdb) call callme()
hello

I can use command "call callme()" to test one function more, but how can I step in callme() after gdb have execute the statement "callme();" and gdb will execute next statement "fputs( "end\n", stdout );" .
I want to call callme() and then step in callme()
# 4  
Old 10-28-2011
You need to set a break point first on the callme() function and then do call callme.

Code:
root@bt:/tmp# gdb a.out
GNU gdb (GDB) 7.1-ubuntu
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i486-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /tmp/a.out...done.
(gdb) break callme
Breakpoint 1 at 0x80486da: file run.cpp, line 6.
(gdb) call callme
$1 = {void (void)} 0x80486d4 <callme>
(gdb) run
Starting program: /tmp/a.out 

Breakpoint 1, callme () at run.cpp:6
6        cout<<"callme1"<<endl;
(gdb)

--ahamed
# 5  
Old 10-31-2011
Thanks,
Code:
(gdb) call callme $1 = {void (void)} 0x80486d4 <callme>

gdb does not step in function after "call callme" .
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Function - Make your function return an exit status

Hi All, Good Day, seeking for your assistance on how to not perform my 2nd, 3rd,4th etc.. function if my 1st function is in else condition. #Body function1() { if then echo "exist" else echo "not exist" } #if not exist in function1 my all other function will not proceed.... (4 Replies)
Discussion started by: meister29
4 Replies

2. Shell Programming and Scripting

Will files, creaetd in one function of the same script will be recognized in another function?

Dear All. I have a script, which process files one by one. In the script I have two functions. one sftp files to different server the other from existing file create file with different name. My question is: Will sftp function recognize files names , which are created in another... (1 Reply)
Discussion started by: digioleg54
1 Replies

3. Shell Programming and Scripting

Help to Modify File Name in each function before calling another function.

I have a script which does gunzip, zip and untar. Input to the script is file name and file directory (where file is located) I am reading the input parameters as follows: FILENAME=$1 FILEDIR=$2 I have created 3 functions that are as follows: 1) gunzip file 2) unzip file... (2 Replies)
Discussion started by: pinnacle
2 Replies

4. Programming

Why does gdb stop at a different line than “i b” shows while returning from function?

Here is the program I am trying to debug: #include <stdio.h> int i = 5; int main(void) { int x = 3; display(x); return 0; } void display(int x) { for ( i=0; i<x; ++i ) { printf("i is %d.\n", i); } }This code is coming from here Peter's gdb Tutorial: Stepping... (2 Replies)
Discussion started by: ijustneeda
2 Replies

5. Shell Programming and Scripting

SHELL SCRIPT Function Calling Another Function Please Help...

This is my function which is creating three variables based on counter & writing these variable to database by calling another function writeRecord but only one record is getting wrote in DB.... Please advise ASAP...:confused: function InsertFtg { FTGSTR="" echo "Saurabh is GREAT $#" let... (2 Replies)
Discussion started by: omkar.sonawane
2 Replies

6. Shell Programming and Scripting

Return a value from called function to the calling function

I have two scripts. script1.sh looks -------------------------------- #!/bin/bash display() { echo "Welcome to Unix" } display ----------------------------- Script2.sh #!/bin/bash sh script1.sh //simply calling script1.sh ------------------------------ (1 Reply)
Discussion started by: mvictorvijayan
1 Replies

7. Programming

execl function at GDB

Hi, we would appreciate if any one answer the below query. void main() { printf(“ I am in main\n”); execl(“/HOME/source/file2”,” /HOME/source/file2”,1,0); printf(“after execl\n”); } How to step the file2 source code in GDB. (2 Replies)
Discussion started by: RAMESHPRABUDASS
2 Replies

8. Shell Programming and Scripting

How to find pid of PS which executed by perl system function

hello All, I need to invoke by perl script some program/command and monitor it for 5 minutes . In case it still running for more then 5 min I need to send a signal which will stop it. I implemeted this as shown below by using eval & alarm and I'd like to know if there is a better way to... (1 Reply)
Discussion started by: Alalush
1 Replies

9. Shell Programming and Scripting

Passing global variable to a function which is called by another function

Hi , I have three funcions f1, f2 and f3 . f1 calls f2 and f2 calls f3 . I have a global variable "period" which i want to pass to f3 . Can i pass the variable directly in the definition of f3 ? Pls help . sars (4 Replies)
Discussion started by: sars
4 Replies

10. Programming

How to get system() function executed cmd return value ?

Hi, How I can get system function executed command return value ? I want to know mv command success or not ? #include <stdio.h> main() { int ret; ret = system( "mv x.dat y.dat" ); printf( "system ret:\n", ret ); } (3 Replies)
Discussion started by: haiudhaya
3 Replies
Login or Register to Ask a Question