{{{#!html
Emacs GDB ¸ðµå ÃÊ°£´Ü »ç¿ë¹ý
}}}
[[TableOfContents]]
=== Áغñ ===
GDB ¸ðµå ½ÇÇà ¹æ¹ý
{{{
M-x gdb
}}}
Emacs¿¡¼ È¿°úÀûÀÎ µð¹ö±ëÀ» Çϱâ À§Çؼ´Â Gdb Many Windows ¼³Á¤ »ç¿ëÀ» ÃßõÇÕ´Ï´Ù.
¹æ¹ý1.
{{{
M-x customize-browse or ¸Þ´º : Options -> Customize Emacs -> Browse Customization Groups ¿¡¼
Emacs -> Programming -> Tools -> Gdb -> Gdb Many Windows
Gdb Many Windows : on
State ¹öÆ° ´©¸£°í Save for Future Sessions
}}}
¹æ¹ý2.
{{{
.emacs ¼³Á¤ÆÄÀÏ¿¡
(setq gdb-many-windows t)
Ãß°¡
}}}
¹æ¹ý3.
{{{
M-x gdb ·Î GDB ¸ðµå ÁøÀÔ ÈÄ
¸Þ´º : Gud -> GDB-UI -> Display Other Windows ¿¡¼ Åä±Û
}}}
=== ECB(Emacs Code Browser)¿Í ·¹À̾ƿô Ãæµ¹ ÇØ°á ===
ECB¿Í Gdb Many Windows ¸ðµå°¡ Ãæµ¹ÇÏ¿© ·¹À̾ƿôÀÌ ÀÌ»óÇØÁý´Ï´Ù.[[br]]
ÇØ°á ¹æ¹ýÀ¸·Î´Â
¹æ¹ý1.
{{{
ECB°¡ È°¼ºÈµÇ¾î ÀÖÀ¸¸é M-x ecb-deactivate ÇÏ°í M-x gdb ¸¦ ½ÇÇàÇϼ¼¿ä.
}}}
¹æ¹ý2.
{{{
M-x make-frame (C-x 5 2) ·Î ÇÁ·¹ÀÓÀ» Çϳª ´õ ¸¸µé°í °Å±â¼ M-x gdb ¸¦ ½ÇÇàÇϼ¼¿ä.
}}}
¹æ¹ý3.[[br]]
¾Æ·¡ °°Àº ÇÔ¼ö¸¦ ¸¸µé¾î¼ .emacs ¼³Á¤ÆÄÀÏ¿¡ Ãß°¡ÈÄ »ç¿ëÇϼ¼¿ä.
{{{
(defun gdb-in-new-frame ()
(interactive)
(select-frame-set-input-focus (make-frame))
(call-interactively 'gdb) )
(global-set-key [(control c)(D)] 'gdb-in-new-frame)
}}}
=== GDB ¸ðµå Àüü ±¸¼º ===
attachment:EmacsGDBQuickNote/emacs-gdb.png
±×¸²¿¡ ³ª¿Â °¢ À©µµ¿ì âÀ» ¼³¸íÇÏÀÚ¸é ¾Æ·¡¿Í °°½À´Ï´Ù.
|| GUD buffer || Locals buffer ||
||||||
|||| Source buffer ||
||||||
|| Stack buffer || Breakpoints buffer ||
Âü°í:[[br]]
ÇöÀç(2009³â 11¿ù 21ÀÏ) ¹öÀü¿¡¼´Â IO buffer°¡ Çϳª ´õ ³ªÅ¸³².
ÁÖÀÇÇÏ¼Å¾ß ÇÒ °ÍÀº µ¿ÀÏÇÑ ¸í·É¿¡ GUD buffer¿¡¼´Â µÎ°¡Áö ´ÜÃàÅ°°¡ °¡´ÉÇÏ°í ¾î¶² buffer´Â °íÀ¯ÇÑ ´ÜÃàÅ°¸¦ °¡Áö°í ÀÖ½À´Ï´Ù.[[br]]
¿¹¸¦ µé¾î ºê·¹ÀÌÅ© Æ÷ÀÎÆ® ¼³Á¤(gud-break)Àº Àüü buffer¿¡¼ C-x C-a C-b ÀÌÁö¸¸ GUD buffer¿¡¼´Â C-c C-b µµ »ç¿ëÇÒ¼öµµ ÀÖ½À´Ï´Ù.[[br]]
¶ÇÇÑ Breakpoints buffer ¿¡´Â ºê·¹ÀÌÅ© Æ÷ÀÎÆ®¸¦ È°¼º/ºñÈ°¼º ÇÏ´Â SPC °°Àº °íÀ¯ÇÑ ´ÜÃàÅ°¸¦ °¡Áö°í ÀÖ½À´Ï´Ù.
±×¸®°í °¢ À©µµ¿ìâ¿¡ Æ÷Ä¿½º°¡ ÀÖ´Â »óÅÂ(À§ ±×¸²¿¡¼´Â GUD buffer °¡ ÇØ´ç)¿¡¼[[br]]
C-h m (describe-mode)ÇÏ½Ã¸é °¢ À©µµ¿ì â¿¡ ÇØ´çÇÏ´Â ¸ðµåÀÇ µµ¿ò¸»ÀÌ ³ª¿É´Ï´Ù.[[br]]
Âü°íÇϼż »ç¿ëÇÏ½Ã¸é µË´Ï´Ù.
=== ´ÜÃàÅ° Á¤¸® ===
¾Æ·¡ ´ÜÃàÅ°¿¡¼ ¾ÆÁÖ ±âº»ÀûÀÎ °ÍÀ» Á¤¸®Çϸé
||gud-break ||ºê·¹ÀÌÅ© Æ÷ÀÎÆ® ¼³Á¤ ||
||gud-remove ||ºê·¹ÀÌÅ© Æ÷ÀÎÆ® ÇØÁ¦ ||
||gud-next ||VSÀÇ Step Over ||
||gud-step ||VSÀÇ Step Into ||
||gud-finish ||VSÀÇ Step Out ||
ÀÌ Á¤µµ ÀÔ´Ï´Ù.[[br]]
±×¸®°í ¸¶¿ì½º¿Í Åø¹Ùµµ È°¿ëÇϼ¼¿ä.
Source buffer ´ÜÃàÅ°´Â À§ ±×¸²¿¡ ³ª¿Â ¸ðµç GDB ¸ðµå buffer¿¡¼ »ç¿ëÇÒ¼ö ÀÖ½À´Ï´Ù.[[br]]
½ÉÁö¾î GUD buffer¿¡¼µµ µË´Ï´Ù.[[br]]
´Ü GDB "run" ½ÇÇà Àü¿¡´Â Source buffer¿¡¼¸¸ ºê·¹ÀÌÅ© Æ÷ÀÎÆ® ¼³Á¤À» ÇÒ ¼ö ÀÖ½À´Ï´Ù.[[br]]
Âü°í·Î º¸Åë Source buffer¿¡¼ ¼Ò½ºÄڵ带 º¸¸é¼ µð¹ö±ëÇÏ´Â °ÍÀÌ ÆíÇÕ´Ï´Ù.
|| '''Source buffer(All buffer)''' || '''¸í·É¾î''' || '''GUD buffer''' ||
|| C-x C-a C-b (or C-x space) || gud-break || C-c C-b ||
|| C-x C-a C-d || gud-remove || C-c C-d ||
|| C-x C-a C-f || gud-finish || C-c C-f ||
|| C-x C-a TAB || gud-stepi || C-c TAB ||
|| C-x C-a C-j || gud-jump || C-c C-j ||
|| C-x C-a C-l || gud-refresh || C-c C-l ||
|| C-x C-a C-n || gud-next || C-c C-n ||
|| C-x C-a C-p || gud-print || C-c C-p ||
|| C-x C-a C-r || gud-cont || C-c C-r ||
|| C-x C-a C-s || gud-step || C-c C-s ||
|| C-x C-a C-t || gud-tbreak || C-c C-t ||
|| C-x C-a C-u || gud-until || C-c C-u ||
|| C-x C-a C-v || gud-pv || C-c C-v ||
|| C-x C-a C-w || gud-watch || C-c C-w ||
|| C-x C-a < || gud-up || C-c < ||
|| C-x C-a > || gud-down || C-c > ||
|| || comint-bol-or-process-mark || C-c C-a ||
|| || comint-interrupt-subjob || C-c C-c ||
|| || comint-show-maximum-output || C-c C-e ||
|| || comint-delete-output || C-c C-o ||
|| || comint-get-next-from-history || C-c C-x ||
|| || comint-stop-subjob || C-c C-z ||
|| || comint-quit-subjob || C-c C-\ ||
|| || comint-insert-previous-argument || C-c . ||
|| || comint-previous-matching-input-from-input || C-c M-r ||
|| || comint-next-matching-input-from-input || C-c M-s ||
|| '''Breakpoints buffer''' || '''¸í·É¾î''' ||
|| RET || gdb-goto-breakpoint ||
|| SPC || gdb-toggle-breakpoint ||
|| D || gdb-delete-breakpoint ||
|| - || negative-argument ||
|| 0 .. 9 || digit-argument ||
|| q || gdb-delete-frame-or-window ||
=== Emacs Ãʺ¸ÀÚ ºÐÀ» À§ÇÑ ´ÜÃàÅ° »ç¿ë¿¡ ´ëÇÑ Á¶¾ð ===
¿¹¸¦ µé¾î ¼³¸íÇÏÀÚ¸é ºê·¹ÀÌÅ© Æ÷ÀÎÆ® ¼³Á¤(gud-break)Àº Source buffer¿¡¼[[br]]
C-x C-a C-b Àε¥ ÀÌ°ÍÀ» °¢°¢ µû·Î µû·Î ÀÔ·ÂÇϼŵµ µÇÁö¸¸[[br]]
C(°è¼Ó ´©¸¥ »óÅÂ)-xa C-b ¶Ç´Â[[br]]
C(°è¼Ó ´©¸¥ »óÅÂ)-xab[[br]]
ÀÌ·± ½ÄÀ¸·Î Çϼŵµ µË´Ï´Ù.
Áï, ¾Æ·¡ ¼¼°¡Áö´Â ¸ðµÎ °°Àº °ÍÀÔ´Ï´Ù.[[br]]
|| C-x C-a C-b ||
|| C-xa C-b ||
|| C-xab ||
gud-break¿¡¼ C-b ´Â GUD buffer¿Í Source buffer¿¡¼ °øÅëÀ̱⠶§¹®¿¡[[br]]
Ç¥±â´Â À§¿¡ ÀÖ´Â °Íó·³ ÇÏ´õ¶óµµ ½Ç»ç¿ë¿¡¼´Â[[br]]
GUD buffer(C-c C-b), Source buffer(C-xa C-b) ÀÌ·± ¹æ½ÄÀÌ ´ÜÃàÅ° ¾Ï±â¿¡ ÆíÇÒ °ÍÀÔ´Ï´Ù.
=== ¸¶¿ì½º »ç¿ë¹ý ===
attachment:EmacsGDBQuickNote/emacs_gdb_fringe.png
|| ±âÈ£ || ¶æ ||
|| C || Ctrl Å° ||
|| Mouse-1 || ¸¶¿ì½º ¿ÞÂÊ ¹öÆ° ||
|| Mouse-3 || ¸¶¿ì½º ¿À¸¥ÂÊ ¹öÆ° ||
±×¸²¿¡ ³ª¿Â Source buffer °¡ÀåÀÚ¸®¿¡¼
||Mouse-1 ||ºê·¹ÀÌÅ© Æ÷ÀÎÆ® ¼³Á¤/ÇØÁ¦ ||
||C-Mouse-1 ||ºê·¹ÀÌÅ© Æ÷ÀÎÆ® È°¼º/ºñÈ°¼º ||
GDB "run" ¸í·É ½ÇÇà ÈÄ Source buffer °¡ÀåÀÚ¸®¿¡ ¼¼¸ð È»ìÇ¥ ³ª¿À¸é
||¼¼¸ð È»ìÇ¥ Mouse-1 Drag ||Mouse-1 ¹öÆ° ³õÀº ÀÚ¸®±îÁö ½ÇÇà ||
||Mouse-3 ||Mouse-3 ¹öÆ° Ŭ¸¯ÇÑ ÀÚ¸®±îÁö ½ÇÇà ||
||C-Mouse-3 ||Mouse-3 ¹öÆ° Ŭ¸¯ÇÑ ÀÚ¸®±îÁö Á¡ÇÁ(½ÇÇà ¾øÀ½) ||
=== ¸¶¿ì½º·Î ºê·¹ÀÌÅ© Æ÷ÀÎÆ® ¼³Á¤ÀÌ Àß ¾ÈµÇ´Â °æ¿ì ===
gdb¿¡ óÀ½ ÁøÀԽà µð¹ö±ëÇÒ ½ÇÇà ÆÄÀÏÀ» ·ÎµåÇÏÁö ¾Ê°í ÁøÀÔÈÄ¿¡ ½ÇÇà ÆÄÀÏÀ» ·ÎµåÇϸé[[br]]
¸¶¿ì½º·Î ºê·¹ÀÌÅ© Æ÷ÀÎÆ® ¼³Á¤ÀÌ ¾ÈµÇ´Â °æ¿ì°¡ ÀÖ½À´Ï´Ù.
¿¹µé µé¾î test.cc(main ÇÔ¼ö ÀÖ´Â)¶ó´Â ÆÄÀÏÀÌ ÀÖ°í ÄÄÆÄÀÏÀ» ¿Ï·áÇؼ [[br]]
test¶ó´Â ½ÇÇà ÆÄÀÏÀÌ ¸¸µé¾îÁ³´Ù¸é
{{{
M-x gdb ÈÄ¿¡
}}}
¹Ì´Ï¹öÆÛ¿¡ ¾Æ·¡ ó·³
{{{
Run gdb (like this): gdb --annotate=3 test
}}}
ÀÌ·± ½ÄÀ¸·Î ÇÏ¼Å¾ß ÇÕ´Ï´Ù.
±×·¸Áö ¾Ê°í ¸¸¾à test¸¦ À§¿¡¼ ó·³ gdb¿¡ ³Ñ°ÜÁÖ´Â °ÍÀ» ÀØÀ¸¼Å¼[[br]]
GUD buffer¿¡¼ "file test"Çϼ̴ٸé Å°º¸µå·Î ºê·¹ÀÌÅ© Æ÷ÀÎÆ®¸¦ Çѹø ¼³Á¤ÇØ Áּžß[[br]]
±× ´ÙÀ½ºÎÅÍ ¸¶¿ì½º·Îµµ ºê·¹ÀÌÅ© Æ÷ÀÎÆ® ¼³Á¤ÀÌ µË´Ï´Ù.
=== gud-run, gud-kill, gud-quit Å°¹ÙÀεù Ãß°¡ + ¥á ===
gud-run, gud-kill, gud-quit Àº Å°¹ÙÀεùÀÌ ¾ÈµÇ¾î Àִµ¥ ÇÊ¿äÇϽŠºÐÀº
¾Æ·¡¸¦ .emacs ¼³Á¤ÆÄÀÏ¿¡ Ãß°¡Çϼ¼¿ä.
{{{
(defun gdb-mode-additional-keys()
"Key bindings to add to `gdb-mode'."
(gud-def gud-run "run" "\C-g" "Run the program.")
(gud-def gud-kill "kill" "\C-k" "Kill the program.")
(gud-def gud-quit "quit" "\C-q" "Quit the program.")
)
(add-hook 'gdb-mode-hook 'gdb-mode-additional-keys)
}}}
À§ ¼³Á¤À» Ãß°¡ÇÏ½Ã¸é ¾Æ·¡ Å°¹ÙÀεùÀ» ¾²½Ç ¼ö ÀÖ½À´Ï´Ù.
|| '''GUD buffer''' || '''¸í·É¾î''' || '''Source buffer''' ||
|| C-c C-g || gud-run || C-x C-a C-g ||
|| C-c C-k || gud-kill || C-x C-a C-k ||
|| C-c C-q || gud-quit || C-x C-a C-q ||
±×¸®°í ¾Æ·¡ ¼Ò½ºÄÚµåó·³ gud-answer-with-yes, gud-answer-with-no ÇÔ¼ö¿Í Å°¹ÙÀεùÀ» ´õ Ãß°¡Çϸé[[br]]
Æ÷Ä¿½º°¡ GUD buffer¿¡ ¾ø´Â »óÅ¿¡¼ gud-kill¸¦ ½ÇÇàÈÄ ¾Æ·¡ ¸Þ¼¼Áö°¡ ³ª¿Í¼
{{{
Kill the program being debugged? (y or n)
}}}
"y or n"¸¦ ÀÔ·ÂÇÏ·¯ GUD buffer·Î À̵¿ÇؾßÇÏ´Â ºÒÆíÀ» ÁÙÀÏ ¼ö ÀÖ½À´Ï´Ù.[[br]]
¿¹µé µé¾î Source buffer¿¡¼ gud-kill(C-x C-a C-k)ÈÄ GUD buffer¿¡ "y or n" ÀÔ·ÂÇ϶ó´Â ¸Þ¼¼Áö°¡ ³ª¿À¸é[[br]]
Æ÷Ä¿½º°¡ Source buffer¿¡ ÀÖ´Â ±× »óÅ¿¡¼ (C-x C-a y)¸¦ ÀÔ·ÂÇϸé GUD buffer¿¡ "y"°¡ ÀԷµǴ °ÍÀÔ´Ï´Ù.
¶ÇÇÑ gdb-toggle-breakpoint-in-source-buffer ÇÔ¼ö¿Í Å°¹ÙÀεùÀ» Á»´õ Ãß°¡Çϸé[[br]]
Source buffer¿¡¼ C-x space ·Î ºê·¹ÀÌÅ© Æ÷ÀÎÆ®¸¦ Åä±ÛÇÒ¼ö ÀÖ½À´Ï´Ù.[[br]]
¹°·Ð ±âÁ¸¿¡ ÀÖ´ø gud-break(ºê·¹ÀÌÅ© Æ÷ÀÎÆ® ¼³Á¤) Å°¹ÙÀεù(C-x space)À» µ¤¾î¾¹´Ï´Ù.[[br]]
ÀÌÁ¡ ¼÷ÁöÇÏ½Ã°í ¿øÇϽô ºÐÀº ´Ù¸¥ Å°¹ÙÀεùÀ¸·Î ¹Ù²Ù¼¼¿ä.[[br]]
±×·¯³ª C-x C-a C-b (gud-break)´Â ±×´ë·Î ¾µ¼öÀֱ⠶§¹®¿¡ C-x space ´Â Åä±Û·Î ¾²½Ã´Â °ÍÀ» ÃßõÇÕ´Ï´Ù.
{{{
(defun gud-answer-with-yes()
(interactive)
(save-excursion
(set-buffer gud-comint-buffer)
(insert "y")
(comint-send-input)) )
(defun gud-answer-with-no()
(interactive)
(save-excursion
(set-buffer gud-comint-buffer)
(insert "n")
(comint-send-input)) )
(defun gdb-toggle-breakpoint-in-source-buffer ()
(interactive)
(if (eq (car (fringe-bitmaps-at-pos)) 'breakpoint)
(gud-remove nil)
(gud-break nil)) )
(defun gdb-mode-additional-keys()
"Key bindings to add to `gdb-mode'."
(gud-def gud-run "run" "\C-g" "Run the program.")
(gud-def gud-kill "kill" "\C-k" "Kill the program.")
(gud-def gud-quit "quit" "\C-q" "Quit the program.")
(global-set-key [(control x)(control a)(y)] 'gud-answer-with-yes)
(global-set-key [(control x)(control a)(n)] 'gud-answer-with-no)
(global-set-key [(control x)(?\ )] 'gdb-toggle-breakpoint-in-source-buffer)
)
(add-hook 'gdb-mode-hook 'gdb-mode-additional-keys)
}}}
=== gdb-many-windows »óÅ toggle Çϱâ ===
gdb-many-windows »óÅ¿¡¼ µð¹ö±ëÇÏ´Â °ÍÀÌ ÆíÇÏÁö¸¸[[br]]
°¡²û gdb-many-windows »óÅ°¡ ¾Æ´Ñ ½ÉÇÃÇÑ »óÅ¿¡¼ µð¹ö±ëÇÏ´Â °ÍÀÌ ÆíÇÒ ¼öµµ ÀÖÀ¸¹Ç·Î[[br]]
¾Æ·¡ ÇÔ¼ö¸¦ Ãß°¡Çؼ »ç¿ëÇϸé Æí¸®ÇÕ´Ï´Ù.
{{{
(defun gdb-many-windows-toggle-switch ()
(interactive)
(if gdb-many-windows
(gdb-many-windows nil)
(gdb-many-windows t)) )
}}}
À§ gdb-mode-additional-keys ÇÔ¼ö¿¡ ¾Æ·¡ Å°¹ÙÀεù Ãß°¡
{{{
(global-set-key [(control x)(control a)(*)] 'gdb-many-windows-toggle-switch)
}}}
=== ½Ç·Ê ½ºÅ©¸°¼¦(Screenshots) ===
attachment:EmacsGDBQuickNote/emacs-gdb-exam1.png
attachment:EmacsGDBQuickNote/emacs-gdb-exam2.png
À§Ã³·³ »ç¿ëÇÏ·Á¸é ¾Æ·¡ ¼Ò½º¸¦ ´Ù¿î·Îµå ¹Þ°í Àû´çÇÑ °÷¿¡ ¼³Ä¡ ÈÄ[[br]]
attachment:EmacsGDBQuickNote/gdb-snippets-rev2.tar.gz [[br]]
attachment:EmacsGDBQuickNote/gdb-snippets.tar.gz
.emacs ¿¡ ¾Æ·¡¸¦ Ãß°¡ÇØ ÁÝ´Ï´Ù.
{{{
(add-to-list 'load-path "¼³Ä¡/°æ·Î")
(load "gdb-snippets")
}}}
»ç¿ë¹ýÀº[[br]]
C-x C-a R registers¿Í locals buffer »çÀÌ Àüȯ[[br]]
C-x C-a T threads¿Í breakpoints buffer »çÀÌ Àüȯ[[br]]
C-x C-a A assembler buffer Åä±Û[[br]]
C-x C-a M memory buffer Åä±Û[[br]]
C-x C-a I io buffer Åä±Û
=== ¾î¼¸é °¡Àå Áß¿äÇÑ »çÇ× ===
ÄÄÆÄÀÏ ÇϽǶ§ ²À "-g" ¿É¼Ç ÀØÀ¸½Ã¸é ¾ÈµË´Ï´Ù.!
[[br]]
(!) [wiki:primewizard] - 20080803