and gdb remote debugging
gdb
GDB, GNU debugger, called gdb (ddd), the program is an interactive tool, work in character mode.
GDB debugging tasks can be accomplished as follows
- Set breakpoints;
- Monitoring the value of program variables;
- Single-step execution of the program;
- Modify the value of a variable.
gdb installation
Open root user privileges: sudo -s
, Linux terminal in order to enter the following code.
apt-get update
apt-get install gdb
Do you want to continue? [Y/n] y
Use test:
write a simple hello.c
#include<stdio.h>
int main(){
printf("Hello World!\n");
}
Before you can use gdb debugger, you must use the -g
option to compile the source file.
- CFLAGS variables can be defined as the Makefile:
CFLAGS = -g
; - Or when using gcc compiler plus the -g option
gcc -g -o hello hello.c
.
Running normally use the following command gdb debugger:
gdb [文件名]
For example, using gdb debugging hello, first of all gcc -g -o hello hello.c
, thengdb hello
gdb debugger command
help NAME
: Displays help information for the specified command.
file FILE
: Load the specified executable file for debugging.
kill
: Terminate the program being debugged.
list
: Display source code segment.
break NUM
: Set a breakpoint on a specified line.
run
: Execution of the current program being debugged.
continue
: Continue the program being debugged.
step
: Performing a forward line of source code, under the conditions encountered functions into internal execution functions.
stepi
: Execute one machine instruction.
next
: Single-step execution of a sentence, not stepping into the function body.
nexti
: Single-step execution of an instruction, if the instruction is a function call, then stop until the function is called when the end of program execution.
set 变量 = 表达式
Or set 变量 := 表达式
: set the value of the variables.
display EXPR
Each time the program displays the value of the expression is stopped, the program defined by the variable expression composition.
print 变量或表达式
: The value of print variable or expression.
info break
: Displays the current breakpoint list, including the number of times to reach the breakpoint and so on.
info files
: Displays detailed debugging information file.
info func
: Displays all the function names.
info local
: When the display information in the local variables.
info prog
: Display the program being debugged execution state.
info var
: Display all global and static variable names.
delete 断点号
: Clear breakpoints or auto-display expressions.
disable 断点号列表(断点号之间用空格间隔开)
: Let the specified breakpoint failure.
enable 断点号列表
: And disable
contrary to restore breakpoints failure.
ignore 断点号 忽略次数
: Ignore breakpoints.
quit
: Quit gdb.
gdb debugging steps
The first step: with the -g
option compiler arm-linux -g -o hello hello.c
Step two: gdb program gdb hello
Step 3: Check the source list
Step four: Set a breakpoint at the main function break main
Step Five: Run run
Step Six: Debug step/next/break/cont/print/display
Step Seven: quitquit
Embedded Remote Debugging
In the development board running gdbserver
Executed on the PC side
ddd -debugger ./arm-linux-gdb greeting
Other development tools Liunx
CROSS disassembler arm-linux-objdump
arm-linux-objdump -D -S hello > out.s
: Output disassembled file to out.s
View elf file tool arm-linux-readelf
arm -linux-readelf -a hello
: View hello executable file.
arm-linux-readelf -d hello
: View executable files required shared libraries
Graphical development kits: CODE :: BLOCKS
after class homework
(1) assuming a temperature sensor in the file TempSensor.c take bubble sort algorithm to sort a temperature of 10, corresponding to the function name BubbleFun()
, and then removing the highest and lowest values, the temperature of the remaining eight values were averaged sum the temperature as measured at compile debug information is desired to add, it is necessary to add (compile option when -g ), in the debugging process, it is necessary to stop and start the program running in the BubbleFun()
entry to a function, write stream instruction sequence gdb debugger .
gcc -g -o TempSensor TempSensor.c
gdb TempSensor
list
break BubbleFun
run
(2) CODE :: BLOCKS is a ( graphic development kit ), underlying ( required ) arm-linux-gcc support the development kit.