R.A. Epigonos et al.

[gdb] gdbを使ったインタラクティブプログラムのデバッグ

$ git reset --hard 7ff883ca9c0269177f3c21ffd8e997bd1b260f5e
$ git commit -a
$ git pull
Already up-to-date.
$ git branch -a -v
* master                                    4e17a18 [ahead 440] Merge branch 'master' of git://git.sv.gnu.org/weechat
  translation_ja                            3cdb8ae translation: update
  remotes/github/master                     ffb012a translation: update
  remotes/origin/0.3.1                      4c34d00 Version 0.3.1.1
  remotes/origin/0.3.9                      2429c9d Version 0.3.9.2
  remotes/origin/HEAD                       -> origin/master
  remotes/origin/branch-0-2-6               d486a02 Version 0.2.6.3
  remotes/origin/buffer-auto-renumber       c82633e core: use first gap for new buffer only if the buffer has no layout number
  remotes/origin/dynamic-nick-prefix-suffix 16cc0b6 core: make nick prefix/suffix dynamic (move options from irc plugin to core, add logger options) (bug #37531)
  remotes/origin/guile2                     0f143da guile: fix compilation with guile 2.0
  remotes/origin/layout_infolist_hdata      e2807e5 core: add variable "current_layout" in infolist "layout"
  remotes/origin/master                     c832116 irc: rename option irc.look.ban_mask_default to irc.network.ban_mask_default
  remotes/origin/perl-script-load           4a554d4 perl: fix compilation when multiplicity is disabled
  remotes/origin/scroll-beyond-end          354d96e core: fix filtered line displayed after /window scroll_beyond_end
  remotes/origin/secured-data               ade379a rmodifier: update default rmodifier for /secure (add option decrypt)
  remotes/origin/shared-strings             a4f7898 core: use shared strings for groups/nicks in nicklist
$ git branch fix-color-emphasize origin/master
Branch fix-color-emphasize set up to track remote branch master from origin.
$ git branch -a -v
  fix-color-emphasize                       c832116 irc: rename option irc.look.ban_mask_default to irc.network.ban_mask_default
* master                                    4e17a18 [ahead 440] Merge branch 'master' of git://git.sv.gnu.org/weechat
  translation_ja                            3cdb8ae translation: update
  remotes/github/master                     ffb012a translation: update
  remotes/origin/0.3.1                      4c34d00 Version 0.3.1.1
  remotes/origin/0.3.9                      2429c9d Version 0.3.9.2
  remotes/origin/HEAD                       -> origin/master
  remotes/origin/branch-0-2-6               d486a02 Version 0.2.6.3
  remotes/origin/buffer-auto-renumber       c82633e core: use first gap for new buffer only if the buffer has no layout number
  remotes/origin/dynamic-nick-prefix-suffix 16cc0b6 core: make nick prefix/suffix dynamic (move options from irc plugin to core, add logger options) (bug #37531)
  remotes/origin/guile2                     0f143da guile: fix compilation with guile 2.0
  remotes/origin/layout_infolist_hdata      e2807e5 core: add variable "current_layout" in infolist "layout"
  remotes/origin/master                     c832116 irc: rename option irc.look.ban_mask_default to irc.network.ban_mask_default
  remotes/origin/perl-script-load           4a554d4 perl: fix compilation when multiplicity is disabled
  remotes/origin/scroll-beyond-end          354d96e core: fix filtered line displayed after /window scroll_beyond_end
  remotes/origin/secured-data               ade379a rmodifier: update default rmodifier for /secure (add option decrypt)
  remotes/origin/shared-strings             a4f7898 core: use shared strings for groups/nicks in nicklist
$ git checkout fix-color-emphasize
Switched to branch 'fix-color-emphasize'
$ git branch -a -v
* fix-color-emphasize                       c832116 irc: rename option irc.look.ban_mask_default to irc.network.ban_mask_default
  master                                    4e17a18 [ahead 440] Merge branch 'master' of git://git.sv.gnu.org/weechat
  translation_ja                            3cdb8ae translation: update
  remotes/github/master                     ffb012a translation: update
  remotes/origin/0.3.1                      4c34d00 Version 0.3.1.1
  remotes/origin/0.3.9                      2429c9d Version 0.3.9.2
  remotes/origin/HEAD                       -> origin/master
  remotes/origin/branch-0-2-6               d486a02 Version 0.2.6.3
  remotes/origin/buffer-auto-renumber       c82633e core: use first gap for new buffer only if the buffer has no layout number
  remotes/origin/dynamic-nick-prefix-suffix 16cc0b6 core: make nick prefix/suffix dynamic (move options from irc plugin to core, add logger options) (bug #37531)
  remotes/origin/guile2                     0f143da guile: fix compilation with guile 2.0
  remotes/origin/layout_infolist_hdata      e2807e5 core: add variable "current_layout" in infolist "layout"
  remotes/origin/master                     c832116 irc: rename option irc.look.ban_mask_default to irc.network.ban_mask_default
  remotes/origin/perl-script-load           4a554d4 perl: fix compilation when multiplicity is disabled
  remotes/origin/scroll-beyond-end          354d96e core: fix filtered line displayed after /window scroll_beyond_end
  remotes/origin/secured-data               ade379a rmodifier: update default rmodifier for /secure (add option decrypt)
  remotes/origin/shared-strings             a4f7898 core: use shared strings for groups/nicks in nicklist
$ gdb -p `pgrep weechat`
GNU gdb (GDB) 7.4.1-debian
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Attaching to process 21634
(gdb)

gdbのコマンド

3箇所にbreakポイントを作り、ifでbreakする条件を設定する例。および表示する例。および削除する例。

(gdb) break gui_color_emphasize if strcmp(search,"") != 0
(gdb) break gui_chat_string_real_pos
(gdb) break gui_chat_string_pos
(gdb) info breakpoints
(gdb) delete breakpoints 1
(gdb) delete breakpoints 2
(gdb) delete breakpoints 3

1行進める例。次のbreakポイントまで進める例。関数の最後まで進める例。

(gdb) next
(gdb) continue
(gdb) finish

表示系。printは一回だけ表示。displayはbreakのたびに表示。

(gdb) print pos
(gdb) display pos

いちいち終了するとbeakポイントとか全てリセットされてしまうので、detachとattachを使う。

(gdb) detach
(gdb) attach 9999

成功する場合

C-r pi
0---------1---------2---------3---------4---------5---------
012345678901234567890123456789012345678901234567890123456789
WeeChat 0.4.3-dev [compiled on Dec  8 2013 17:14:34]
成功する場合の引数
gui_chat_string_pos"WeeChat 0.4.3-dev [compiled on Dec 8 2013 17:14:34]"22 bytes22 charsOK
gui_chat_string_real_pos"\031\061\061WeeChat 0.4.3-dev \031\062\070[\031\063\062compiled on Dec 8 2013 17:14:34\031\062\070]"22 chars31 bytesOK
gui_chat_string_pos"WeeChat 0.4.3-dev [compiled on Dec 8 2013 17:14:34]"24 bytes24 charsOK
gui_chat_string_real_pos"\031\061\061WeeChat 0.4.3-dev \031\062\070[\031\063\062compiled on Dec 8 2013 17:14:34\031\062\070]"24 chars33 bytesOK

デバッグ後の確認

0---------1---------2---------3---------4---------5---------
012345678901234567890123456789012345678901234567890123456789
WeeChat 0.4.3-dev [compiled on Dec 10 2013 22:56:15]
デバッグ後の確認
gui_chat_string_pos"WeeChat 0.4.3-dev [compiled on Dec 10 2013 22:56:15]"22 bytes22 charsOK
gui_chat_string_real_pos"\031\061\061WeeChat 0.4.3-dev \031\062\070[\031\063\062compiled on Dec 10 2013 22:56:15\031\062\070]"22 chars31 bytesOK
gui_chat_string_pos"WeeChat 0.4.3-dev [compiled on Dec 10 2013 22:56:15]"24 bytes24 charsOK
gui_chat_string_real_pos"\031\061\061WeeChat 0.4.3-dev \031\062\070[\031\063\062compiled on Dec 10 2013 22:56:15\031\062\070]"24 chars33 bytesOK

失敗する場合

C-r パイ
0---------1---------2---------3---------4---------5---------
012345678901234567890123456789012345678901234567890123456789
WeeChat 0.4.3-dev [コパイル日時 Dec  8 2013 17:14:34]
失敗する場合の引数
gui_chat_string_pos"WeeChat 0.4.3-dev [コンパイル日時 Dec 8 2013 17:14:34]"25 bytes21 charsOK
gui_chat_string_real_pos"\031\061\061WeeChat 0.4.3-dev \031\062\070[\031\063\062コンパイル日時 Dec 8 2013 17:14:34\031\062\070]"21 chars31 bytesNG (34 bytes)
gui_chat_string_pos"WeeChat 0.4.3-dev [コンパイル日時 Dec 8 2013 17:14:34]"31 bytes23 charsOK
gui_chat_string_real_pos"\031\061\061WeeChat 0.4.3-dev \031\062\070[\031\063\062コンパイル日時 Dec 8 2013 17:14:34\031\062\070]"23 chars34 bytesNG (40 bytes)

デバッグ後の確認

0---------1---------2---------3---------4---------5---------
012345678901234567890123456789012345678901234567890123456789
WeeChat 0.4.3-dev [コンパイル日時 Dec 10 2013 22:56:15]
デバッグ後の確認
gui_chat_string_pos"WeeChat 0.4.3-dev [コンパイル日時 Dec 10 2013 22:56:15]"25 bytes21 charsOK
gui_chat_string_real_pos"\031\061\061WeeChat 0.4.3-dev \031\062\070[\031\063\062コンパイル日時 Dec 10 2013 22:56:15\031\062\070]"21 chars34 bytesOK
gui_chat_string_pos"WeeChat 0.4.3-dev [コンパイル日時 Dec 10 2013 22:56:15]"31 bytes23 charsOK
gui_chat_string_real_pos"\031\061\061WeeChat 0.4.3-dev \031\062\070[\031\063\062コンパイル日時 Dec 10 2013 22:56:15\031\062\070]"23 chars40 bytesOK

ソーシャルブックマーク

  1. はてなブックマーク
  2. Google Bookmarks
  3. del.icio.us

ChangeLog

  1. Posted: 2010-08-24T15:50:36+09:00
  2. Modified: 2010-08-24T15:50:36+09:00
  3. Generated: 2024-12-16T23:09:15+09:00