EmacsGDB Quick Note
Emacs GDB ¸ðµå ÃÊ°£´Ü »ç¿ë¹ý
Contents
1. Áغñ ¶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 ¿¡¼ Åä±Û 2. ECB(Emacs Code Browser)¿Í ·¹À̾ƿô Ãæµ¹ ÇØ°á ¶ECB¿Í Gdb Many Windows ¸ðµå°¡ Ãæµ¹ÇÏ¿© ·¹À̾ƿôÀÌ ÀÌ»óÇØÁý´Ï´Ù.
ÇØ°á ¹æ¹ýÀ¸·Î´Â ¹æ¹ý1.
ECB°¡ È°¼ºÈµÇ¾î ÀÖÀ¸¸é M-x ecb-deactivate ÇÏ°í M-x gdb ¸¦ ½ÇÇàÇϼ¼¿ä. ¹æ¹ý2.
M-x make-frame (C-x 5 2) ·Î ÇÁ·¹ÀÓÀ» Çϳª ´õ ¸¸µé°í °Å±â¼ M-x gdb ¸¦ ½ÇÇàÇϼ¼¿ä. ¹æ¹ý3.
¾Æ·¡ °°Àº ÇÔ¼ö¸¦ ¸¸µé¾î¼ .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) 3. GDB ¸ðµå Àüü ±¸¼º ¶[PNG image (28.41 KB)] ±×¸²¿¡ ³ª¿Â °¢ À©µµ¿ì âÀ» ¼³¸íÇÏÀÚ¸é ¾Æ·¡¿Í °°½À´Ï´Ù.
ÇöÀç(2009³â 11¿ù 21ÀÏ) ¹öÀü¿¡¼´Â IO buffer°¡ Çϳª ´õ ³ªÅ¸³². ÁÖÀÇÇÏ¼Å¾ß ÇÒ °ÍÀº µ¿ÀÏÇÑ ¸í·É¿¡ GUD buffer¿¡¼´Â µÎ°¡Áö ´ÜÃàÅ°°¡ °¡´ÉÇÏ°í ¾î¶² buffer´Â °íÀ¯ÇÑ ´ÜÃàÅ°¸¦ °¡Áö°í ÀÖ½À´Ï´Ù.
¿¹¸¦ µé¾î ºê·¹ÀÌÅ© Æ÷ÀÎÆ® ¼³Á¤(gud-break)Àº Àüü buffer¿¡¼ C-x C-a C-b ÀÌÁö¸¸ GUD buffer¿¡¼´Â C-c C-b µµ »ç¿ëÇÒ¼öµµ ÀÖ½À´Ï´Ù. ¶ÇÇÑ Breakpoints buffer ¿¡´Â ºê·¹ÀÌÅ© Æ÷ÀÎÆ®¸¦ È°¼º/ºñÈ°¼º ÇÏ´Â SPC °°Àº °íÀ¯ÇÑ ´ÜÃàÅ°¸¦ °¡Áö°í ÀÖ½À´Ï´Ù. ±×¸®°í °¢ À©µµ¿ìâ¿¡ Æ÷Ä¿½º°¡ ÀÖ´Â »óÅÂ(À§ ±×¸²¿¡¼´Â GUD buffer °¡ ÇØ´ç)¿¡¼
C-h m (describe-mode)ÇÏ½Ã¸é °¢ À©µµ¿ì â¿¡ ÇØ´çÇÏ´Â ¸ðµåÀÇ µµ¿ò¸»ÀÌ ³ª¿É´Ï´Ù. Âü°íÇϼż »ç¿ëÇÏ½Ã¸é µË´Ï´Ù. 4. ´ÜÃàÅ° Á¤¸® ¶¾Æ·¡ ´ÜÃàÅ°¿¡¼ ¾ÆÁÖ ±âº»ÀûÀÎ °ÍÀ» Á¤¸®Çϸé
±×¸®°í ¸¶¿ì½º¿Í Åø¹Ùµµ È°¿ëÇϼ¼¿ä. Source buffer ´ÜÃàÅ°´Â À§ ±×¸²¿¡ ³ª¿Â ¸ðµç GDB ¸ðµå buffer¿¡¼ »ç¿ëÇÒ¼ö ÀÖ½À´Ï´Ù.
½ÉÁö¾î GUD buffer¿¡¼µµ µË´Ï´Ù. ´Ü GDB "run" ½ÇÇà Àü¿¡´Â Source buffer¿¡¼¸¸ ºê·¹ÀÌÅ© Æ÷ÀÎÆ® ¼³Á¤À» ÇÒ ¼ö ÀÖ½À´Ï´Ù. Âü°í·Î º¸Åë Source buffer¿¡¼ ¼Ò½ºÄڵ带 º¸¸é¼ µð¹ö±ëÇÏ´Â °ÍÀÌ ÆíÇÕ´Ï´Ù.
5. Emacs Ãʺ¸ÀÚ ºÐÀ» À§ÇÑ ´ÜÃàÅ° »ç¿ë¿¡ ´ëÇÑ Á¶¾ð ¶¿¹¸¦ µé¾î ¼³¸íÇÏÀÚ¸é ºê·¹ÀÌÅ© Æ÷ÀÎÆ® ¼³Á¤(gud-break)Àº Source buffer¿¡¼
C-x C-a C-b Àε¥ ÀÌ°ÍÀ» °¢°¢ µû·Î µû·Î ÀÔ·ÂÇϼŵµ µÇÁö¸¸ C(°è¼Ó ´©¸¥ »óÅÂ)-xa C-b ¶Ç´Â C(°è¼Ó ´©¸¥ »óÅÂ)-xab ÀÌ·± ½ÄÀ¸·Î Çϼŵµ µË´Ï´Ù. Áï, ¾Æ·¡ ¼¼°¡Áö´Â ¸ðµÎ °°Àº °ÍÀÔ´Ï´Ù.
gud-break¿¡¼ C-b ´Â GUD buffer¿Í Source buffer¿¡¼ °øÅëÀ̱⠶§¹®¿¡ Ç¥±â´Â À§¿¡ ÀÖ´Â °Íó·³ ÇÏ´õ¶óµµ ½Ç»ç¿ë¿¡¼´Â GUD buffer(C-c C-b), Source buffer(C-xa C-b) ÀÌ·± ¹æ½ÄÀÌ ´ÜÃàÅ° ¾Ï±â¿¡ ÆíÇÒ °ÍÀÔ´Ï´Ù. 6. ¸¶¿ì½º »ç¿ë¹ý ¶[PNG image (1.48 KB)]
±×¸²¿¡ ³ª¿Â Source buffer °¡ÀåÀÚ¸®¿¡¼
GDB "run" ¸í·É ½ÇÇà ÈÄ Source buffer °¡ÀåÀÚ¸®¿¡ ¼¼¸ð È»ìÇ¥ ³ª¿À¸é
7. ¸¶¿ì½º·Î ºê·¹ÀÌÅ© Æ÷ÀÎÆ® ¼³Á¤ÀÌ Àß ¾ÈµÇ´Â °æ¿ì ¶gdb¿¡ óÀ½ ÁøÀԽà µð¹ö±ëÇÒ ½ÇÇà ÆÄÀÏÀ» ·ÎµåÇÏÁö ¾Ê°í ÁøÀÔÈÄ¿¡ ½ÇÇà ÆÄÀÏÀ» ·ÎµåÇϸé
¸¶¿ì½º·Î ºê·¹ÀÌÅ© Æ÷ÀÎÆ® ¼³Á¤ÀÌ ¾ÈµÇ´Â °æ¿ì°¡ ÀÖ½À´Ï´Ù. ¿¹µé µé¾î test.cc(main ÇÔ¼ö ÀÖ´Â)¶ó´Â ÆÄÀÏÀÌ ÀÖ°í ÄÄÆÄÀÏÀ» ¿Ï·áÇؼ
test¶ó´Â ½ÇÇà ÆÄÀÏÀÌ ¸¸µé¾îÁ³´Ù¸é M-x gdb ÈÄ¿¡¹Ì´Ï¹öÆÛ¿¡ ¾Æ·¡ ó·³ Run gdb (like this): gdb --annotate=3 testÀÌ·± ½ÄÀ¸·Î ÇÏ¼Å¾ß ÇÕ´Ï´Ù. ±×·¸Áö ¾Ê°í ¸¸¾à test¸¦ À§¿¡¼ ó·³ gdb¿¡ ³Ñ°ÜÁÖ´Â °ÍÀ» ÀØÀ¸¼Å¼
GUD buffer¿¡¼ "file test"Çϼ̴ٸé Å°º¸µå·Î ºê·¹ÀÌÅ© Æ÷ÀÎÆ®¸¦ Çѹø ¼³Á¤ÇØ ÁÖ¼Å¾ß ±× ´ÙÀ½ºÎÅÍ ¸¶¿ì½º·Îµµ ºê·¹ÀÌÅ© Æ÷ÀÎÆ® ¼³Á¤ÀÌ µË´Ï´Ù. 8. 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-answer-with-yes, gud-answer-with-no ÇÔ¼ö¿Í Å°¹ÙÀεùÀ» ´õ Ãß°¡Çϸé Æ÷Ä¿½º°¡ GUD buffer¿¡ ¾ø´Â »óÅ¿¡¼ gud-kill¸¦ ½ÇÇàÈÄ ¾Æ·¡ ¸Þ¼¼Áö°¡ ³ª¿Í¼ Kill the program being debugged? (y or n)"y or n"¸¦ ÀÔ·ÂÇÏ·¯ GUD buffer·Î À̵¿ÇؾßÇÏ´Â ºÒÆíÀ» ÁÙÀÏ ¼ö ÀÖ½À´Ï´Ù. ¿¹µé µé¾î Source buffer¿¡¼ gud-kill(C-x C-a C-k)ÈÄ GUD buffer¿¡ "y or n" ÀÔ·ÂÇ϶ó´Â ¸Þ¼¼Áö°¡ ³ª¿À¸é Æ÷Ä¿½º°¡ Source buffer¿¡ ÀÖ´Â ±× »óÅ¿¡¼ (C-x C-a y)¸¦ ÀÔ·ÂÇϸé GUD buffer¿¡ "y"°¡ ÀԷµǴ °ÍÀÔ´Ï´Ù. ¶ÇÇÑ gdb-toggle-breakpoint-in-source-buffer ÇÔ¼ö¿Í Å°¹ÙÀεùÀ» Á»´õ Ãß°¡Çϸé
Source buffer¿¡¼ C-x space ·Î ºê·¹ÀÌÅ© Æ÷ÀÎÆ®¸¦ Åä±ÛÇÒ¼ö ÀÖ½À´Ï´Ù. ¹°·Ð ±âÁ¸¿¡ ÀÖ´ø gud-break(ºê·¹ÀÌÅ© Æ÷ÀÎÆ® ¼³Á¤) Å°¹ÙÀεù(C-x space)À» µ¤¾î¾¹´Ï´Ù. ÀÌÁ¡ ¼÷ÁöÇÏ½Ã°í ¿øÇϽô ºÐÀº ´Ù¸¥ Å°¹ÙÀεùÀ¸·Î ¹Ù²Ù¼¼¿ä. ±×·¯³ª 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) 9. gdb-many-windows »óÅ toggle Çϱ⠶gdb-many-windows »óÅ¿¡¼ µð¹ö±ëÇÏ´Â °ÍÀÌ ÆíÇÏÁö¸¸
°¡²û gdb-many-windows »óÅ°¡ ¾Æ´Ñ ½ÉÇÃÇÑ »óÅ¿¡¼ µð¹ö±ëÇÏ´Â °ÍÀÌ ÆíÇÒ ¼öµµ ÀÖÀ¸¹Ç·Î ¾Æ·¡ ÇÔ¼ö¸¦ Ãß°¡Çؼ »ç¿ëÇϸé Æí¸®ÇÕ´Ï´Ù. (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) 10. ½Ç·Ê ½ºÅ©¸°¼¦(Screenshots) ¶[PNG image (47.3 KB)] [PNG image (47.44 KB)] À§Ã³·³ »ç¿ëÇÏ·Á¸é ¾Æ·¡ ¼Ò½º¸¦ ´Ù¿î·Îµå ¹Þ°í Àû´çÇÑ °÷¿¡ ¼³Ä¡ ÈÄ
gdb-snippets-rev2.tar.gz (2.25 KB) gdb-snippets.tar.gz (2.24 KB) .emacs ¿¡ ¾Æ·¡¸¦ Ãß°¡ÇØ ÁÝ´Ï´Ù.
(add-to-list 'load-path "¼³Ä¡/°æ·Î") (load "gdb-snippets")»ç¿ë¹ýÀº C-x C-a R registers¿Í locals buffer »çÀÌ Àüȯ C-x C-a T threads¿Í breakpoints buffer »çÀÌ Àüȯ C-x C-a A assembler buffer Åä±Û C-x C-a M memory buffer Åä±Û C-x C-a I io buffer Åä±Û |
He who has a shady past knows that nice guys finish last. |