2017年3月12日 星期日

[GDB] C/C++ Debugger

GNU Debugger

GDB 是 GNU Project Debugger的縮寫

是適合用在 Linux/MAC 上面的除錯工具

入門教學

首先,開始debug之前,請務必在command line 下指令時,在gcc或是g++後面加上 '-g' 這段文字[1]


下面是CS50所分享的使用教學影片

GDB1

GDB2
[1] 關於除錯(Debugging)選項 "-g"
要使用 gdb 那麼首先,在你 compile 程式的時候, 要加上 -g 的選項. (可以用-g, -g2, -g3具體請看 man gcc)。 
通常如果程式不會很大,在 compile 的時候我都是用 -g3 的,因為如果你用到了 inline 的 function, 用 -g 去 compile 就無法去 debug inline function了.這時候就用到 -g2, -g3了,g後面的數字越大,也就是說 可以 debug 的級別越高.最高級別就是 -g3. --- Debugging with GDB (入門篇)

g++ - is using the “-g” flag for production builds a good idea? 

How Does The Debugging Option -g Change the Binary Executable?
"-g tells the compiler to store symbol table information in the executable. Among other things, this includes:
  • symbol names
  • type info for symbols
  • files and line numbers where the symbols came from
Debuggers use this information to output meaningful names for symbols and to associate instructions with particular lines in the source."

沒有留言:

張貼留言

/* 載入prettify的autoloader */ /* 載入JQuery */