Use gdb to understand: pass by value / pass by pointer / pass by reference

1. Commonly used gdb commands
1) Display code - list
list displays 10 lines of code
list 1 Displays 1-10 lines, then type list or press Enter to display the following 10 lines of code
list 1,20 Displays 1-20 lines

2) Set a breakpoint - break
break 15 Set a breakpoint on line 15
break func Set a breakpoint at the entry of function func()
info break Display breakpoint information
delete 1 Delete breakpoint

3)
Single-step execution - next/n
single-step tracking - step/s
s: Execute a line of source code, if there is a function call in this line of code, enter the function;
n: Execute a line of source code, in this line of code function calls are also executed.

continue - continue

4) Print the variable value - print
print a

5) View the function stack - backtrace/bt
bt n Display the top n frame (frame)
of the stack bt -n Display the bottom n frame (frame)
frame n Display the information of the nth frame
info args View the parameter names and values ​​in the stack frame of a function
info locals View the value of local variables in a function stack frame

exit function - finish
exit gdb - quit

 

2. Use gdb to understand: pass by value/pass by pointer/pass by reference
https://www.cnblogs.com/zjutzz/p/6818799.html

Summarize:

void myfun( int a)     // pass value, generate copy 
void myfun( int & a)    // pass reference, do not generate copy 
void myfun( int * a)    // pass address, generate copy, which is essentially a pass by value , this value is the address

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324775770&siteId=291194637