Dain.Bora.Net  ver 2.0  
About Me
ÇÁ·ÎÇÊ
³ªÀÇ °¡Á·
¿ë's X-file
¼÷'s X-file
´ÙÀÎȨÇÇ ver 1.0
¼ÒÁßÇÑ »ç¶÷µé
°¡Á·µé
Ä£±¸µé
Á÷À嵿·áµé
´ÙÀÎ&°ÇÈñ
´ÙÀÎÀÌ À̾߱â
°ÇÈñ À̾߱â
¾ö¸¶ À̾߱â
±â¾ï¼ÓÀ¸·Î
°¡Á·µé°ú ÇÔ²²
Áñ°Å¿î Ãß¾ïµé
»çÁø & ¹°»ýÈ°
µðÄ« À̾߱â
ÇູÇÑ ¹°»ýÈ°
Æ÷Åä°¶·¯¸®
°Ô½ÃÆÇ
ºÎ½º·¯±âµé
ÀÚ·á½Ç
ÁÁÀº±Û
½ºÅ͵ð
¹æ¸í·Ï
¸Ô°íÀÚ°í³î°í
°¡º¼¸¸ÇÑ°÷
¸Ô°í½ÍÀº°Í
¸µÅ©
Ä«¿îÅÍ
¿À´Ã : 1
Àüü : 43897
³¯ÀÚ : 2024/12/04

Category Category
[Á¤º¸º¸¾È][Á¤º¸º¸¾ÈÀü¹®°¡][¸®´ª½º]GDB»ç¿ë¹ý
# C/C++   2011-05-12 10:17
ÀÌ»ó¿ë
[Á¤º¸º¸¾È][Á¤º¸º¸¾ÈÀü¹®°¡][¸®´ª½º]GDB»ç¿ë¹ý

GDB »ç¿ë¹ý

DebuggingÀ̶õ

DebuggingÀº bug, Áï, ÄÄÇ»ÅÍ ÇÁ·Î±×·¥ »óÀÇ ³í¸®Àû ¿À·ù¸¦ ã¾Æ ÇØ°áÇÏ´Â °úÁ¤ÀÌ´Ù.



Debugging ¹æ¹ý

l        ÇÁ·Î±×·¥ ¼Ò½º¸¦ ´«À¸·Î µû¶ó°¡¸ç, ¸Ó¸®·Î ½ÇÇà½ÃÄÑ ³í¸®Àû ¿À·ù¸¦ ã¾Æ³½´Ù. ÀÌ°ÍÀº ÇÁ·Î±×·¡¸Ó·Î ÇÏ¿©±Ý Á¤¸» ¸¹Àº ¿¡³ÊÁö¸¦ ¼ÒºñÇÏ°Ô Çϸç, ÀÚ½ÅÀÌ ÀÛ¼ºÇÑ ÇÁ·Î±×·¥ÀÎ °æ¿ì ¼±ÀÔ°ßÀ¸·Î ÀÎÇØ ¿À·ù¸¦ ã¾Æ³»±â Èûµç °æ¿ì°¡ ¸¹´Ù.

l        ÇÁ·Î±×·¥ÀÇ Áß°£ Áß°£¿¡ ¡®printf¡¯¸¦ »ç¿ëÇÏ¿© ½ÇÇà »óŸ¦ Ãâ·ÂÇϵµ·Ï ÇÑ´Ù. ÀÌ·¸°Ô ÇÔÀ¸·Î½á º¯¼ö¿¡ À߸øµÈ °ªÀÌ µé¾î°¡´ÂÁö ¿©ºÎ¸¦ »ç¶÷ÀÌ Á÷Á¢ °è»êÇÏ´Â °Íº¸´Ù Á» ´õ ½±°Ô ¾Ë ¼ö ÀÖ´Ù.

l        Debugging tool (¿¹, gdb, dbx, xdbx µî)À» ÀÌ¿ëÇÑ´Ù. Debugging toolµéÀº ÇÁ·Î±×·¥ÀÌ ½ÇÇà ÁßÀÏ ¶§, º¯¼öµéÀÇ °ªÀ̳ª ¼öÇàµÇ´Â statementÀ» º¸¿©ÁÖ¸ç, ÇÊ¿ä¿¡ µû¶ó º¯¼ö °ªÀ» º¯°æÇÏ¿© ½ÇÇèÀ» ÇØ º¼ ¼ö ÀÖµµ·Ï ÇØÁØ´Ù.



gdb (GNU Debugger)

gdb´Â C, C++, Modula-2·Î ±¸ÇöµÈ ÇÁ·Î±×·¥À» µð¹ö±×ÇÒ ¼ö ÀÖ´Â µµ±¸ÀÌ´Ù. ¹ö±×¸¦ Àâ´Â °É µ½±â À§ÇØ gdb´Â ´ÙÀ½°ú °°Àº ÀÛ¾÷µéÀ» °¡´ÉÇÏ°Ô ÇÑ´Ù ÇÁ·Î±×·¥ÀÇ Çൿ¿¡ ¿µÇâÀ» ÁÙ ¼ö ÀÖ´Â °¢Á¾ Á¶°ÇÀ» ¼³Á¤ÇÑ ÈÄ, ÇÁ·Î±×·¥À» ½ÃÀÛÇÑ´Ù
l        Æ¯Á¤ Á¶°ÇÀ» ¸¸³ª¸é ÇÁ·Î±×·¥À» Á¤Áö½ÃŲ´Ù
l        ÇÁ·Î±×·¥ÀÌ Á¤ÁöµÆÀ» ¶§ ¹«½¼ ÀÏÀÌ ÀϾ´ÂÁö °Ë»çÇÑ´Ù
l        ÇÁ·Î±×·¥ ³»ºÎ ¼³Á¤À» ¹Ù²Ù¾î¼­ ¹ö±×¸¦ ¼öÁ¤ÇÔÀ¸·Î½á ´Ù¸¥ ¹ö±×¸¦ °è¼Ó ã¾Æ³ª°£´Ù.

</PRE>
gdb ½ÇÇà

$ gdb [prog [core|procID]]

l         prog: µð¹ö±ëÇÒ ÇÁ·Î±×·¥

l         core: ÇÁ·Î±×·¥ ½ÇÇà Áß¿¡ ¡°segmentation fault¡± µîÀÇ ¿À·ù¿¡ ÀÇÇØ ºñÁ¤»óÀûÀ¸·Î Á¾·áÇÒ ¶§ »ý¼ºµÇ´Â ÆÄÀÏ·Î, ±×¶§ÀÇ ½Ã½ºÅÛÀÇ ³»ºÎ »óŸ¦ ±×´ë·Î ÀúÀåÇØ ³õÀº °ÍÀÌ´Ù. ÀÌ ÆÄÀÏÀ» ÀÎÀÚ·Î ÁÖ¸é ½ÇÇàÆÄÀÏÀÌ ºñÁ¤»óÀûÀ¸·Î Á¾·áµÈ °÷ÀÌ ¼Ò½ºÄÚµåÀÇ ¾î´À ºÎºÐÀÎÁö¸¦ Ç¥½ÃÇØ ÁØ´Ù.

l         procID: ÀÌ¹Ì ½ÇÇàÁßÀÎ ÇÁ·Î±×·¥À» debuggingÇÏ·Á¸é ÇØ´ç processÀÇ id (PID)¸¦ ÁÖ¸é µÇ´Âµ¥, ÀÌ ¶§ ÁÖÀÇ ÇÒ °ÍÀº PID¿Í °°Àº À̸§ÀÇ ÆÄÀÏÀÌ ÀÖÀ» °æ¿ì gdb°¡ coreÆÄÀÏ·Î ¿©±â°Ô µÇ´Â Á¡ÀÌ´Ù.

ÁÖÀÇ: DebuggingÇÏ°íÀÚ ÇÏ´Â ½ÇÇàÆÄÀÏÀº gcc¿¡¼­ –g ¿É¼ÇÀ» ÁÖ¾î compileÇÔÀ¸·Î½á gdb°¡ ÇÊ¿ä·Î ÇÏ´Â ºÎ°¡ Á¤º¸µéÀÌ Ãß°¡µÈ °ÍÀ» »ç¿ëÇØ¾ß Á¦´ë·Î debuggingÀ» ¼öÇàÇÒ ¼ö ÀÖ´Ù.



gdb ¸í·É¾î

gdb¸¦ ½ÇÇàÇÏ¿© gdb prompt ¡®(gdb) ¡¯°¡ Ç¥½ÃµÈ »óÅ¿¡¼­ gdb ¸í·É¾î¸¦ »ç¿ëÇÏ¿© µð¹ö±ëÀ» ÁøÇàÇÑ´Ù.

Âü°í: class¿Í commandÀÇ Ãà¾àÇüµµ Áö¿øµÈ´Ù. (¿¹, ¡®run¡¯¸í·É¾î¸¦ Ãà¾àÇü ¡®r¡¯·Î ´ë½ÅÇÒ ¼ö ÀÖ´Ù.)

l         µµ¿ò¸» (help)

help [class|command]

µµ¿ò¸», ¸í·É¾î ºÐ·ù ¸ñ·Ï Ãâ·Â, ÇØ´ç class¿¡ ¼ÓÇÑ ¸í·É¾î ¸ñ·Ï Ç¥½Ã, ÇØ´ç command¿¡ ´ëÇÑ µµ¿ò¸» Ç¥½Ã

l         ÇÁ·Î±×·¥ ¼öÇà (running)

kill

µð¹ö±ë ÁßÀÎ ÇÁ·Î±×·¥ÀÇ ½ÇÇàÀ» °­Á¦·Î Á¾·á½ÃŲ´Ù.

run [args]

µð¹ö±ëÇÒ ÇÁ·Î±×·¥ÀÇ ¼öÇàÀ» ½ÃÀÛÇÑ´Ù. ÇÁ·Î±×·¥ ½ÇÇà¿¡ ÇÊ¿äÇÑ argument (args)¸¦ ÁöÁ¤ÇÒ ¼ö ÀÖ´Ù. args¸¦ ÁöÁ¤ÇÏÁö ¾ÊÀ¸¸é ¹Ù·Î ÀÌÀüÀÇ run½ÇÇàÀ̳ª ¡°set args¡±¸í·É¿¡ ÀÇÇØ ¹Ì¸® ÁÖ¾îÁø argument¸¦ »ç¿ëÇÑ´Ù. ÀÔÃâ·Â ¹æÇâ ÀçÁöÁ¤ (¡°>¡±, ¡°<¡±, ¡°>>¡±)À» »ç¿ëÇÒ ¼ö ÀÖ´Ù.

set args [args]

ÇÁ·Î±×·¥ÀÌ ½ÃÀÛµÉ ¶§, µð¹ö±ëÇÒ ÇÁ·Î±×·¥¿¡ Àü´ÞÇÒ argument¸¦ ¼³Á¤ÇÑ´Ù.

next [n]

¸ØÃçÁø ÇÁ·Î±×·¥¿¡¼­ ÇÁ·Î±×·¥ÀÇ ´ÙÀ½ n(default=1)°³ÀÇ ¹®ÀåÀ» ¼öÇàÇÑ ÈÄ ¸ØÃá´Ù. ÇÔ¼öÀÏ °æ¿ì, ÇÔ¼ö Àüü¸¦ ¼öÇàÇÑ´Ù.

step [n]

¸ØÃçÁø ÇÁ·Î±×·¥¿¡¼­ ÇÁ·Î±×·¥ÀÇ ´ÙÀ½ n(default=1)°³ÀÇ ¹®ÀåÀ» ¼öÇàÇÑ ÈÄ ¸ØÃá´Ù. ÇÔ¼öÀÏ °æ¿ì, ÇÔ¼ö ³»ºÎ·Î µé¾î°¡ ÇÑ ¹®À徿 ¼öÇàÇÑ´Ù.

continue [n]

½Ã±×³Î(Ctrl-C)À̳ª breakpoint µî¿¡ ÀÇÇØ ¸ØÃçÁø ÇÁ·Î±×·¥ÀÇ ¼öÇàÀ» °è¼ÓÇÑ´Ù. nÀÌ ÁöÁ¤µÉ °æ¿ì, ÀÌÈÄ n-1¹øÀÇ breakpoint´Â ¹«½ÃÇÏ°í, n¹ø° breakpoint¿¡¼­ ¼öÇàÀ» ¸ØÃá´Ù.

until [[file:]n|function]

ÇÁ·Î±×·¥ÀÌ ÇöÀç ¶óÀκ¸´Ù Å« ¶óÀÎÀ̳ª ¶Ç´Â ÁöÁ¤µÈ ¶óÀÎÀ̳ª ¾îµå·¹½º ¶Ç´Â ÇÔ¼ö¿¡ µµ´ÞÇÒ ¶§±îÁö ¼öÇàÇÑ´Ù(break ¸í·É°ú µ¿ÀÏÇÑ argument). ¶ÇÇÑ, ÇöÀç stack frameÀ» ºüÁ®³ª¿Ã ¶§µµ ¸ØÃá´Ù. loop¸¦ Áö³¯ ¶§, ù¹ø° loop¼öÇà¿¡¼­´Â next¸í·É°ú µ¿ÀÏÇÏÁö¸¸ µÎ¹ø° loop¼öÇàºÎÅÍ´Â ±× loop¸¦ ¹þ¾î³¯ ¶§±îÁö ¸ØÃßÁö ¾Ê´Â´Ù.

l         ½ºÅà °Ë»ç (stack)

½ºÅÃÀº ½ºÅà ÇÁ·¹ÀÓÀ¸·Î ±¸¼ºµÈ´Ù. gdb´Â ½ºÅà ÇÁ·¹ÀÓ¿¡ ¹øÈ£¸¦ ÁöÁ¤Çϴµ¥, °¡Àå ¾ÈÂÊ¿¡ ÀÖ´Â(ÇöÀç ½ÇÇàÁßÀÎ) ÇÁ·¹ÀÓ¿¡ ´ëÇØ 0¹øºÎÅÍ ¹øÈ£¸¦ ºÎ¿©ÇÑ´Ù. gdb´Â Ç×»ó ÇÑ ÇÁ·¹ÀÓÀ» ¼±ÅÃµÈ ÇÁ·¹ÀÓÀ¸·Î °£ÁÖÇϸç, ¼±ÅÃµÈ ÇÁ·¹ÀÓ¿¡ ´ëÇÏ¿© º¯¼ö °ª º¸±â°¡ ÀÌ·ç¾îÁø´Ù. ¾Æ·¡ ¸í·É¾îµé¿¡¼­ ¼ýÀÚ³ª ¾îµå·¹½º¸¦ »ç¿ëÇÏ¿© ´Ù¸¥ ÇÁ·¹ÀÓÀ» ÁöÁ¤ÇÒ ¼öµµ ÀÖ´Ù.

bt (¶Ç´Â backtrace ¶Ç´Â where) [[-]N]

¸ðµç ½ºÅà ÇÁ·¹ÀÓÀ̳ª °¡Àå ¾ÈÂÊ¿¡ ÀÖ´Â N°³ÀÇ ÇÁ·¹ÀÓ¿¡ ´ëÇÑ backtrace¸¦ Ãâ·ÂÇÑ´Ù. argument°¡ À½¼ö(-N)ÀÏ ¶§, °¡Àå ¹Ù±ùÂÊ¿¡ ÀÖ´Â N°³ÀÇ ÇÁ·¹ÀÓÀ» Ãâ·ÂÇÑ´Ù.

frame [N]

½ºÅà ÇÁ·¹ÀÓÀ» ¼±ÅÃÇÏ°í Ãâ·ÂÇÑ´Ù. NÀº ¼±ÅÃÇÒ ÇÁ·¹ÀÓ ¹øÈ£(ȤÀº ÇÁ·¹ÀÓÀÇ ÁÖ¼Ò)¸¦ °¡¸®Å²´Ù. Argument°¡ ¾øÀ¸¸é ÇöÀç ¼±ÅÃµÈ ÇÁ·¹ÀÓÀ» Ãâ·ÂÇÑ´Ù.

up [N]

ÇöÀç ¼±ÅÃµÈ ÇÁ·¹ÀÓÀ» È£ÃâÇÑ ½ºÅà ÇÁ·¹ÀÓ (caller)À» ¼±ÅÃÇÏ°í Ãâ·ÂÇÑ´Ù. NÀº ¸î °³ÀÇ ÇÁ·¹ÀÓ À§·Î ¿Ã¶ó°¡¾ß ÇÒÁö¸¦ ¸»ÇØÁØ´Ù.

down [N]

ÇöÀç ¼±ÅÃµÈ ÇÁ·¹ÀÓ¿¡ ÀÇÇØ È£ÃâµÈ ½ºÅà ÇÁ·¹ÀÓ (callee)À» ¼±ÅÃÇÏ°í Ãâ·ÂÇÑ´Ù. NÀº ¸î °³ÀÇ ÇÁ·¹ÀÓ ¾Æ·¡·Î ³»·Á°¡¾ß ÇÒÁö¸¦ ¸»ÇØÁØ´Ù.

return [rvalue]

¼±ÅÃµÈ ½ºÅà ÇÁ·¹ÀÓÀ¸·Î ÇÏ¿©±Ý È£ÃâÀÚ (caller)¿¡°Ô·Î ¸®ÅÏÇÏ°Ô ÇÑ´Ù. ½ÇÇàÀº ÇöÀç ¼±ÅÃµÈ °Íº¸´Ù À§¿¡ ÀÖ´Â ÇÁ·¹ÀÓ (caller)¿¡¼­ °è¼ÓµÉ °ÍÀÌ´Ù. rvalue´Â ¸®ÅÏ °ªÀ» ÁöÁ¤ÇÑ´Ù.

set variable [variable] = [exp]

[variable]ÀÇ °ªÀ» [exp] °è»ê °á°ú·Î ´ëÄ¡ÇÑ´Ù. set variable ´ë½Å set¸¸ ½áµµ µÈ´Ù.



l         µ¥ÀÌÅÍ °Ë»ç (data)

whatis EXP

expression! EXPÀÇ data ŸÀÔÀ» Ãâ·ÂÇÑ´Ù.

ptype TYPE

ŸÀÔ TYPEÀÇ Á¤ÀǸ¦ Ãâ·ÂÇÑ´Ù.

print [EXP]

expression! EXPÀÇ °ªÀ» Ãâ·ÂÇÑ´Ù. EXP¿¡ »ç¿ëµÉ ¼ö ÀÖ´Â º¯¼ö´Â ¼±ÅÃµÈ ÇÁ·¹ÀÓ¿¡ ÀÖ´Â º¯¼öÀ̰ųª Àü¿ª º¯¼öÀÌ´Ù.

printf  [¡°format string¡±, arg1, arg2, arg3, ..., argn]

printf Çü½ÄÀ¸·Î Ãâ·ÂÇÑ´Ù.

display [EXP]

expression! EXPÀÇ °ªÀ» ÇÁ·Î±×·¥ÀÌ ¸ØÃâ ¶§¸¶´Ù Ãâ·ÂÇÑ´Ù.

delete display (¶Ç´Â undisplay) [N ¡¦]

ÇÁ·Î±×·¥ÀÌ Á¤ÁöÇÒ ¶§¸¶´Ù Ãâ·ÂµÇ´Â ¸î¸î expression!À» Ãë¼ÒÇÑ´Ù. NÀº Ãë¼ÒÇÒ expression!ÀÇ ¹øÈ£¸¦ ÁöÁ¤ÇÑ´Ù. Argument°¡ ¾øÀ¸¸é ¸ðµç ÀÚµ¿ Ãâ·Â expression!À» Ãë¼ÒÇÑ´Ù.

disable display [N ¡¦]

ÇÁ·Î±×·¥ÀÌ Á¤ÁöÇÒ ¶§¸¶´Ù Ãâ·ÂµÇ´Â ¸î¸î expression!À» disableÇÑ´Ù. NÀº disableÇÒ expression!ÀÇ ¹øÈ£¸¦ ÁöÁ¤ÇÑ´Ù. Argument°¡ ¾øÀ¸¸é ¸ðµç ÀÚµ¿ Ãâ·Â expression!À» disableÇÑ´Ù.

enable display [N ¡¦]

ÇÁ·Î±×·¥ÀÌ Á¤ÁöÇÒ ¶§¸¶´Ù Ãâ·ÂµÇ´Â ¸î¸î expression!À» enableÇÑ´Ù. NÀº enableÇÒ expression!ÀÇ ¹øÈ£¸¦ ÁöÁ¤ÇÑ´Ù. Argument°¡ ¾øÀ¸¸é ¸ðµç ÀÚµ¿ Ãâ·Â expression!À» enableÇÑ´Ù.

l         ƯÁ¤ ÁöÁ¡¿¡¼­ ÇÁ·Î±×·¥ Á¤Áö (breakpoints)

watch [EXP]

expression! EXP¿¡ ´ëÇÑ watchpoint¸¦ ¼³Á¤ÇÑ´Ù. EXPÀÇ °ªÀÌ º¯ÇÒ ¶§¸¶´Ù ÇÁ·Î±×·¥ÀÇ ¼öÇàÀ» ¸ØÃá´Ù.

break [[file:]n|function]

ƯÁ¤ ¶óÀÎ(n)À̳ª ÇÔ¼ö(function)¿¡ breakpoint¸¦ ¼³Á¤ÇÑ´Ù. Argument°¡ ¾øÀ¸¸é ÇöÀç ¼öÇà À§Ä¡¿¡ breakpoint¸¦ ¼³Á¤ÇÑ´Ù. ÇÁ·Î±×·¥ÀÌ ¼öÇà Áß¿¡ ÁöÁ¤µÈ breakpoint¿¡ µµÂøÇÏ¸é ¼öÇàÀ» ¸ØÃá´Ù.

clear [[file:]n|function]

ƯÁ¤ ¶óÀÎ(n)À̳ª ÇÔ¼ö(function)¿¡ ¼³Á¤µÈ breakpoint¸¦ Á¦°ÅÇÑ´Ù. Argument°¡ ¾øÀ¸¸é ÇöÀç ¼öÇà À§Ä¡¿¡ ¼³Á¤µÈ ¸ðµç breakpoint¸¦ Á¦°ÅÇÑ´Ù.

delete [N ¡¦]

¸î¸î breakpoint³ª ÀÚµ¿ Ãâ·Â expression!À» Á¦°ÅÇÑ´Ù. NÀº Á¦°ÅÇÒ breakpoint ¹øÈ£¸¦ °¡¸®Å²´Ù. Argument°¡ ¾øÀ¸¸é ¸ðµç breakpoint¸¦ Á¦°ÅÇÑ´Ù.

disable [N ¡¦]

¸î¸î breakpoint¸¦ disable½ÃŲ´Ù. NÀº disableÇÒ breakpoint¸¦ °¡¸®Å²´Ù. Argument°¡ ¾øÀ¸¸é ¸ðµç breakpoint¸¦ disable½ÃŲ´Ù. disableµÈ breakpoint´Â enable¿¡ ÀÇÇØ ´Ù½Ã µ¿ÀÛÇϵµ·Ï ÇÒ ¼ö ÀÖ´Ù.

enable [N ¡¦]

¸î¸î breakpoint¸¦ enable½ÃŲ´Ù. NÀº enableÇÒ breakpoint¸¦ °¡¸®Å²´Ù.

condition [<?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" /><?XML:NAMESPACE PREFIX = ST1 />N  COND]

breakpoint N¿¡¼­ COND°¡ trueÀÏ ¶§¸¸ ¸ØÃßµµ·Ï ¸í½ÃÇÑ´Ù.



l         °Ë»çÇÒ ÆÄÀÏ (files)

cd [DIR]

ÀÛ¾÷ µð·ºÅ丮¸¦ DIR·Î ¼³Á¤ÇÑ´Ù

pwd

ÀÛ¾÷ µð·ºÅ丮¸¦ Ãâ·ÂÇÑ´Ù.

core-file [FILE]

FILEÀ» core dump ÆÄÀÏ·Î »ç¿ëÇÑ´Ù.

file [FILE]

FILEÀ» µð¹ö±ëÇÒ ÇÁ·Î±×·¥À¸·Î »ç¿ëÇÑ´Ù.

list [[file:]n|function][, [file:]n|function]

ÁöÁ¤µÈ ÇÔ¼ö³ª ¶óÀÎ ¾ÕµÚÀÇ 11¶óÀÎÀ» Ãâ·ÂÇÑ´Ù. ÄÞ¸¶·Î ºÐ¸®µÈ µÎ °³ÀÇ Argument´Â Ãâ·ÂÇÒ ½ÃÀÛ ¶óÀΰú ³¡ ¶óÀÎÀ» °¡¸®Å²´Ù. Argument°¡ ¾øÀ¸¸é ¾Õ¼­ Ãâ·ÂµÈ ¶óÀÎ ÀÌÈÄÀÇ 10°³ ¶óÀÎÀ» Ãâ·ÂÇÑ´Ù. ¡°list –¡±´Â ¾Õ¼­ Ãâ·ÂµÈ ¶óÀÎ ÀÌÀüÀÇ 10°³ ¶óÀÎÀ» Ãâ·ÂÇÑ´Ù.

l         »óÅ Á¶È¸ (status)

info

µð¹ö±ë ÁßÀÎ ÇÁ·Î±×·¥¿¡ ´ëÇÑ ¿©·¯°¡Áö¸¦ º¸¿© ÁÖ±â À§ÇÑ Æ÷°ýÀûÀÎ ¸í·É¾î

info breakpoints (¶Ç´Â info watchpoints) [N]

¼³Á¤µÈ breakpointÀÇ »óŸ¦ º¸¿©ÁØ´Ù. NÀº ƯÁ¤ breakpoint ¹øÈ£¸¦ °¡¸®Å²´Ù. Argument°¡ ¾øÀ¸¸é ¸ðµç breakpointÀÇ »óŸ¦ º¸¿© ÁØ´Ù.

info args

ÇöÀç ½ºÅà ÇÁ·¹ÀÓÀÇ ÀÎÀÚ º¯¼ö¸¦ º¸¿©ÁØ´Ù.

info display

ÇÁ·Î±×·¥ÀÌ ¸ØÃâ ¶§ Ãâ·ÂÇÒ expression!µéÀ» º¸¿©ÁØ´Ù.

l         Áö¿øµµ±¸ (support)

help [class|command]

µµ¿ò¸», ¸í·É¾î ºÐ·ù ¸ñ·Ï Ãâ·Â, ÇØ´ç class¿¡ ¼ÓÇÑ ¸í·É¾î ¸ñ·Ï Ç¥½Ã, ÇØ´ç command¿¡ ´ëÇÑ µµ¿ò¸» Ç¥½Ã

quit

gdb¸¦ Á¾·áÇÑ´Ù.

make [args]

¡®make¡¯¸¦ ½ÇÇàÇÑ´Ù.



gdb »ç¿ë ¿¹Á¦

gdb »ç¿ë¹ýÀ» ÀÍÈ÷±â À§ÇØ bug°¡ ÀÖ´Â °£´ÜÇÑ ÇÁ·Î±×·¥À» gdb¸¦ »ç¿ëÇÏ¿© µð¹ö±ëÇØ º¸ÀÚ. ¸ÕÀú, /afs/p/class/cse/yjsuh/csed103F2004/lab/lecture_note/bug.c¸¦ °¢ÀÚÀÇ µð·ºÅ丮·Î º¹»çÇÑ´Ù.

$ mkdir debug; cd debug

$ cp /afs/p/class/cse/yjsuh/csed103F2004/lab/lecture_note/bug.c ./



bug.c ¼Ò½º ÄÚµå´Â ´ÙÀ½°ú °°´Ù.

#include <stdio.h>



int score[5];





int sum(int cnt)

{

   int i;

   int sum;



   for(i = 0; i < cnt; i++)

      sum += score[i];



   return sum;

}





int main()

{

   int cnt=0;



   printf("input scores. input -1 to finish.\n");

   while(1)

   {

      printf("score%d? ", cnt+1);

      scanf("%d", score[cnt]);

      if(score[cnt] == -1)

         break;

      cnt++;

   }



   printf("%d scores read.\n", cnt);



   printf("--- result ---\n");

   printf("sum: %d   avg: %d\n", sum(cnt), sum(cnt)/cnt);



   return 0;

}




º» ¼Ò½º ÄÚµå´Â ÀÓÀÇÀÇ °³¼öÀÇ Á¡¼ö¸¦ ÀÔ·Â ¹Þ¾Æ ÃÑÁ¡°ú Æò±ÕÀ» Ãâ·ÂÇØ ÁÖ´Â ÇÁ·Î±×·¥ÀÌ´Ù. À̸¦ ÄÄÆÄÀÏÇÏ¿© ½ÇÇà Çغ¸¸é segmentation fault ¿À·ù°¡ ³ª¸ç coreÆÄÀÏÀÌ »ý¼ºµÇ¸ç Á¾·áµÈ´Ù. »ý¼ºµÈ core ÆÄÀÏÀ» ¹ÙÅÁÀ¸·Î µð¹ö±ëÀ» ÇÑ´Ù. À̶§ ÄÄÆÄÀϽà –g ¿É¼ÇÀ» ½áÁÖ¾î¾ß µð¹ö±ë Á¤º¸¸¦ º¼ ¼ö ÀÖ´Ù. ±½Àº ±Û¾¾°¡ »ç¿ëÀÚ°¡ ÀÔ·ÂÇÑ ºÎºÐÀÌ´Ù.



vision/endovert ~/gdb {298} gcc -g bug.c

vision/endovert ~/gdb {299} a.out

input scores. input -1 to finish.

score1? 100

Segmentation fault (core dumped)

vision/endovert ~/gdb {300} gdb

GNU gdb 5.0

Copyright 2000 Free Software Foundation, Inc.

GDB is free software, covered by the GNU General Public License, and you are

welcome to change it and/or distribute copies of it under certain conditions.

Type "show copying" to see the conditions.

There is absolutely no warranty for GDB.  Type "show warranty" for details.

This GDB was configured as "alpha-dec-osf4.0d".

(gdb) file a.out

Reading symbols from a.out...done.

(gdb) core core

Core was generated by `a.out'.

Program terminated with signal 11, Segmentation fault.

Reading symbols from /usr/shlib/libc.so...done.

#0  0x3ff800e1e4c in _doscan () from /usr/shlib/libc.so

(gdb) bt

#0  0x3ff800e1e4c in _doscan () from /usr/shlib/libc.so

#1  0x3ff8018ea80 in scanf () from /usr/shlib/libc.so

#2  0x120001384 in main () at bug.c:26

(gdb) list 26

21

22         printf("input scores. input -1 to finish.\n");

23         while(1)

24         {

25            printf("score%d? ", cnt+1);

26            scanf("%d", score[cnt]);

27            if(score[cnt] == -1)

28               break;

29            cnt++;

30         }

(gdb) quit

vision/endovert ~/gdb {301}


bt°á°ú¸¦ º¸¸é 26¹ø° Çà¿¡¼­ core dump°¡ ÀϾ °ÍÀ» º¼ ¼ö ÀÖ´Ù. 26¹ø ÇàÀ» º¸¸é scanfÀÇ ÀÎÀÚ·Î ³ÖÀº º¯¼ö score[cnt] ¾Õ¿¡ &°¡ ºüÁ³À½À» ¾Ë ¼ö ÀÖ´Ù. °íÃļ­ ´Ù½Ã ÄÄÆÄÀÏ Çغ»´Ù. À̹ø¿£ °á°ú°ªÀÌ ÀÌ»óÇÏ°Ô ³ª¿Â´Ù. ´Ù½Ã gdb¸¦ »ç¿ëÇÏ¿© ´Ù½Ã µð¹ö±ëÇغ»´Ù.

vision/endovert ~/gdb {303} gcc -g bug.c

vision/endovert ~/gdb {304} a.out

input scores. input -1 to finish.

score1? 100

score2? 100

score3? 100

score4? -1

3 scores read.

--- result ---

sum: 301   avg: 200

vision/endovert ~/gdb {305} gdb a.out

GNU gdb 5.0

Copyright 2000 Free Software Foundation, Inc.

GDB is free software, covered by the GNU General Public License, and you are

welcome to change it and/or distribute copies of it under certain conditions.

Type "show copying" to see the conditions.

There is absolutely no warranty for GDB.  Type "show warranty" for details.

This GDB was configured as "alpha-dec-osf4.0d"...

(gdb) break sum

Breakpoint 1 at 0x120001268: file bug.c, line 7.

(gdb) run

Starting program: /afs/postech.ac.kr/home/std/endovert/gdb/a.out

input scores. input -1 to finish.

score1? 50

score2? 50

score3? 50

score4? -1

3 scores read.

--- result ---



Breakpoint 1, sum (cnt=0) at bug.c:7

7       {

(gdb) l

2

3       int score[5];

4

5

6       int sum(int cnt)

7       {

8          int i;

9          int sum;

10

11         for(i = 0; i < cnt; i++)

(gdb) print sum

$1 = 1

(gdb) next

11         for(i = 0; i < cnt; i++)

(gdb) step

12            sum += score[i];

(gdb) display sum

1: sum = 1

(gdb) s

11         for(i = 0; i < cnt; i++)

1: sum = 51

(gdb) s

12            sum += score[i];

1: sum = 51

(gdb) s

11         for(i = 0; i < cnt; i++)

1: sum = 101

(gdb) set sum = 100

(gdb) print sum

$2 = 100

(gdb) s

12            sum += score[i];

1: sum = 100

(gdb) s

11         for(i = 0; i < cnt; i++)

1: sum = 150

(gdb) s

14         return sum;

1: sum = 150

(gdb) s

15      }

1: sum = 150

(gdb) info display

Auto-display expression!s now in effect:

Num Enb Expression!

1:   y  sum

(gdb) delete display 1

(gdb) continue

Continuing.



Breakpoint 1, sum (cnt=3) at bug.c:7

7       {

(gdb) bt

#0  sum (cnt=3) at bug.c:7

#1  0x120001414 in main () at bug.c:35

(gdb) l 35

30         }

31

32         printf("%d scores read.\n", cnt);

33

34         printf("--- result ---\n");

35         printf("sum: %d   avg: %d\n", sum(cnt), sum(cnt)/cnt);

36

37         return 0;

38      }

39

(gdb) s

11         for(i = 0; i < cnt; i++)

(gdb) print sum

$3 = 150

(gdb) p i

$4 = 3

(gdb) s

12            sum += score[i];

(gdb) print sum

$5 = 150

(gdb) print i

$6 = 0

(gdb) return 150

Make sum return now? (y or n) y

#0  0x120001414 in main () at bug.c:35

35         printf("sum: %d   avg: %d\n", sum(cnt), sum(cnt)/cnt);

(gdb) c

Continuing.

sum: 150   avg: 50



Program exited normally.

(gdb) info break

Num Type           Disp Enb Address    What

1   breakpoint     keep y   0x120001268 in sum at bug.c:7

        breakpoint already hit 2 times

(gdb) delete 1

(gdb) info break

No breakpoints or watchpoints.

(gdb) q

vision/endovert ~/gdb {306}


ÇÕÀ» °è»êÇÏ´Â sumÇÔ¼ö¿¡ breakpoint¸¦ °É°í ½ÇÇà ½ÃÄѺ¸¸é ÃʱâÀÇ sumÀÇ °ªÀÌ 0ÀÌ ¾Æ´Ñ ´Ù¸¥ °ª (ÀÌ °æ¿ì 1)ÀÌ ³ª¿ÈÀ» º¼ ¼ö ÀÖ´Ù. sum°ªÀÌ 0À¸·Î ÃʱâÈ­ µÇµµ·Ï ¼Ò½º¸¦ °íÄ£´Ù.


Name       Pass       Secret Code   Resize  
List
   [C/C++] [Á¤º¸º¸¾È][Á¤º¸º¸¾ÈÀü¹®°¡][¸®´ª½º]GDB»ç¿ë¹ý  ÀÌ»ó¿ë 2011.05.12 678
27    [º¸¾È] À¥ º¸¾È [3] ÀÌ»ó¿ë 2008.05.28 2883
26    [ÀÚ¹Ù½ºÅ©¸³Æ®] JavasScript ÃÑ Á¤¸® [5] ÀÌ»ó¿ë 2007.04.10 1341
25    [¸®´ª½º/À¯´Ð½º] rrdtool ¼³Ä¡ [1] ÀÌ»ó¿ë 2007.02.27 1954
24    [°øÅë] Open Source Æз¯´ÙÀÓ ½¬ÇÁÆ® [146] ÀÌ»ó¿ë 2007.02.27 1402
23    [ÀÚ¹Ù½ºÅ©¸³Æ®] Table Row »èÁ¦Çϱâ [74] ÀÌ»ó¿ë 2006.12.01 1029
22    [¸®´ª½º/À¯´Ð½º] swatch¸¦ ÀÌ¿ëÇØ ·Î±×ÆÄÀÏÀ» ½Ç½Ã°£À¸·Î ¸ð´ÏÅÍÇØ º¸ÀÚ. [1] ÀÌ»ó¿ë 2006.08.29 1068
21    [¸®´ª½º/À¯´Ð½º] cfengine À» ÀÌ¿ëÇÏ¿© ¿©·¯´ëÀÇ ½Ã½ºÅÛ°ü¸® ÀÚµ¿È­ Çϱâ [1] ÀÌ»ó¿ë 2006.08.04 1862
20    [¸®´ª½º/À¯´Ð½º] Content Management Systems (CMS) - OpenSource  ÀÌ»ó¿ë 2006.08.04 2047
19    [À¥] Web 2.0À̶õ ¹«¾ùÀΰ¡ [1] ÀÌ»ó¿ë 2006.08.02 975
18    [À¥] [PHPA] using PHP Accelerator [2] ÀÌ»ó¿ë 2006.02.16 9368
17    [°øÅë] Á¤±Ô Ç¥Çö½Ä  ÀÌ»ó¿ë 2006.01.05 810
16    [¸®´ª½º/À¯´Ð½º] SELinux ?  ÀÌ»ó¿ë 2006.01.04 947
15    [¸®´ª½º/À¯´Ð½º] apache2.0 + tomcat5.x ¼³Ä¡Çϱâ [1] ÀÌ»ó¿ë 2005.11.21 2563
14    [DB] mysql ¼³Ä¡ °¡ÀÌµå  ÀÌ»ó¿ë 2005.11.20 1059
13    [³×Æ®¿÷] Catalyst 4000-L3 Switch ±¸Á¶¿Í setting [206] ÀÌ»ó¿ë 2005.11.08 64235
12    [³×Æ®¿÷] ³×Æ®¿öÅ© Áø´Ü ¸í·É¾î(À©µµ¿ì) [1] ÀÌ»ó¿ë 2005.11.08 1404
11    [³×Æ®¿÷] DNS ¿î¿µ ÀÚ·á  ÀÌ»ó¿ë 2005.11.08 850
10    [³×Æ®¿÷] Cisco 6509 ¿î¿µ ¸Þ´º¾ó [1] ÀÌ»ó¿ë 2005.11.08 4732
9    [¸®´ª½º/À¯´Ð½º] GD ¼³Ä¡ÇØ º¸ÀÚ...  ÀÌ»ó¿ë 2005.09.29 1836
List   1 [2]  
Copyright 1999-2024 Zeroboard / skin by eggnara