[問題] 不用recompile就可決定是否加debug info
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
Linux
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
問題(Question):
來源:Linux程式設計教學手冊第十章 Debugging
方法:Debugging without Recompiling
描述:
Before we move on, it's worth mentioning that there's
a way of using the printf function to help with debugging without using
the #ifdef DEBUG technique, which requires a program to be
recompiled before it can be used.
The method is to add a global variable as a debug flag,
allow a -d option at the command line, which allows the user
to switch debugging on even after the program has been released, and
add a debug logging function. Now you can intersperse things like this
in the program code:
if (debug) {
sprintf(msg, ...)
write_debug(msg)
}
補充說明(Supplement):
一直搞不懂要怎麼用
是gcc -o program source_code.c
然後執行時 , 在命令列加-d要怎麼用呢?
我的嘗試如下:
(1)在file.c宣告一個全域變數
比如
int debug = 0;
...
(2)把檔案編譯完成後,下./program -d debug=1
不能使用…不知怎麼用才對,謝謝指教
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.34.225.172
※ 編輯: phyllispig 來自: 114.34.225.172 (11/18 00:42)
→
11/18 00:45, , 1F
11/18 00:45, 1F
→
11/18 00:46, , 2F
11/18 00:46, 2F
→
11/18 00:50, , 3F
11/18 00:50, 3F
→
11/18 00:51, , 4F
11/18 00:51, 4F
→
11/18 00:51, , 5F
11/18 00:51, 5F
→
11/18 00:53, , 6F
11/18 00:53, 6F
→
11/18 00:57, , 7F
11/18 00:57, 7F
※ 編輯: phyllispig 來自: 114.34.225.172 (11/18 00:58)
→
11/18 13:34, , 8F
11/18 13:34, 8F
→
11/18 14:04, , 9F
11/18 14:04, 9F
→
11/18 16:32, , 10F
11/18 16:32, 10F
→
11/18 16:57, , 11F
11/18 16:57, 11F
推
11/18 18:25, , 12F
11/18 18:25, 12F
→
11/18 18:25, , 13F
11/18 18:25, 13F
討論串 (同標題文章)
完整討論串 (本文為第 1 之 2 篇):