開始試著用 GDB 來檢查追蹤程式流程和記憶體分配,跟著 GDB 來學習…
透過 GDB 來觀察 merge_soft 程式 https://github.com/Lukechin/mergesort_doubly_linked_list/blob/master/mergesort.c
首先使用 GDB 蹤程式前,需要在編譯階段增加 ”-g” 參數來產生 debugging info
我們先編譯 merge_soft.c 並產生含有 debugging info 的執行檔 ”merge_soft”
b <line_number>
- setting breakpoint at <line_number>
info b
- print breakpoints information
disable b <break_number>
- disable target breakpoint
continue
- run after code…
Next
- run next instruct (no entry sub function)
Step
- run next instruct (entry sub funxtion)
List
- list the source code and each execution’s corresponding line number
Backtrace
- show trace of all function calls in stack
Info frame
- List address, language, address of arguments/local variables and which registers were saved in frame.
x &variable
- show the address and value of a local variable (in hex format)
x address
- print binary representation of 4 bytes of memory pointed to by address.