0

Is there any way to extract variables that are being passed to a particular function as parameters in a given c code?

For an example,

main()
{
int a = 10;
float b = 2.0f;

funcA(a,b);

}

Need is to extract the information that variable a & variable b are passed to funcA in a given C code.

Is there a way to extract these information using gdb and it's function breakpoints?

IrAM
  • 1,720
  • 5
  • 18
Macow tdy
  • 59
  • 6

1 Answers1

0

when you are in any function typing frame will give you parameters information of function.

Below are some other commands you can use to get to know more about local variables and parameters.

info locals
frame
info args

more gdb commands

sample :

(gdb) b main                                                                                                                      
Note: breakpoint 1 also set at pc 0x40053e.                                                                                       
Breakpoint 2 at 0x40053e: file main.c, line 6.                                                                                    
(gdb) r                                                                                                                           
Starting program: /home/a.out                                                                                                     
                                                                                                                                  
Breakpoint 1, main () at main.c:6                                                                                                 
6           int a = 10;                                                                                                           
(gdb) n                                                                                                                           
7           float b = 2.0f;                                                                                                       
(gdb) info locals                                                                                                                 
a = 10 
b = 0                                                                                                                             
x = 0                                                                                                                             
(gdb) frame                                                                                                                       
#0  main () at main.c:7                                                                                                           
7           float b = 2.0f;                                                                                                       
(gdb) next                                                                                                                        
9           int x = funcA(a,b);                                                                                                   
(gdb) step                                                                                                                        
funcA (a=10, b=2) at main.c:16                                                                                                    
16          int sum = 0;                                                                                                          
(gdb) frame                                                                                                                       
#0  funcA (a=10, b=2) at main.c:16                                                                                                
16          int sum = 0;                                                                                                          
(gdb) info args                                                                                                                   
a = 10                                                                                                                            
b = 2                                                                                                                             
(gdb) info locals                                                                                                                 
sum = 0                                                                                                                           
(gdb) p a                                                                                                                         
$1 = 10                                                                                                                           
(gdb) print b                                                                                                                     
$2 = 2                                                                                                                            
(gdb)
IrAM
  • 1,720
  • 5
  • 18