¸®´ª½º °ü·Ã °Á¶õ |
---|
Á¦¸ñ | GDB °Á #3 1998/07/10 (17:16) |
À̸§ | ±èÈ¿¿ø |
¹øÈ£ | 48 |
Á¶È¸ | 284 |
º»¹® |
¡º¸®´ª½º Çдç-¸®´ª½º °Á / ¿¬Àç (go LINUX)¡» 338¹ø Á¦ ¸ñ:gdb °ÁÂ<3> ¿Ã¸°ÀÌ:»ýüÁ¹º´(À¯¼öÇà ) 96/10/06 20:06 ÀÐÀ½:1478 °ü·ÃÀÚ·á ¾øÀ½ ----------------------------------------------------------------------------- ÈÞ ½Ä ³¡ && °è¼Ó µð¹ö±ëÇϱâ ****************************** ¹æ±Ý Àü±îÁö read ÇÔ¼ö ¾Õ±îÁö µð¹ö±ëÇÏ°í ÈÞ½ÄÇß´Ù. ´Ù½Ã ÀÛ¾÷À» Çϴµ¥ ¾Õ¿¡¼ Çß´ø ÀÏÀ» ¹Ýº¹ÇÏÁö ¾Ê°í, readÇÔ¼ö¿¡ breakpoint¸¦ Àâ°í ½Í´Ù. ±×·¯¸é ´ÙÀ½°ú °°ÀÌ ÇØ º¸ÀÚ. ------------------------------------------------------------- hacker:~/temp/src# gdb score GDB is free software and you are welcome to 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. GDB 4.15.1 (i486-slackware-linux), Copyright 1995 Free Software Foundation, Inc... (gdb) b read Breakpoint 1 at 0x80486dc: file read.c, line 10. (gdb) run sample.inp sample.out Starting program: /root/temp/src/score sample.inp sample.out Breakpoint 1, read (infile=0x80499a8, score=0x8049a00) at read.c:10 10 SCORE *iscore = NULL; (gdb) s 13 while(fgets(line,80,infile) != NULL) { (gdb) s 14 if( strncmp(line,"#",1) == 0) (gdb) p line $1 = "# ÀÌ ÈÀÏÀº À¯ ¼öÇ྾°¡ ¿¬½À¿ëÀ¸·Î ¸¸µç °ÍÀÔ´Ï´Ù.\n \000¿\036;\000@\000\232\004\b$÷ÿ¿\004÷ÿ¿\225Ë\ 003@\000\232\004\b\000\000\000" (gdb) ----<¼³¸í>--------------------------------------------------- (gdb)b read ¿¡¼ º¼ ¼ö ÀÖµíÀÌ Æ¯Á¤ ÇÔ¼ö¸¦ µð¹ö±ëÇϰųª, breakpoint¸¦ ƯÁ¤ÇÔ¼ö¿¡ Àâ°í ½ÍÀ¸¸é, b(reak) [function name]ó·³ Ä¡¸é µÈ´Ù. Áö±ÝÀº read ÇÔ¼ö³»·Î µé¾î¿Ô´Ù. Áö±ÝºÎÅÍ input file¿¡¼ data¸¦ ÀÐ¾î µéÀÌ´Â °úÁ¤ÀÌ´Ù. read (infile=0x80499a8, score=0x8049a00)¿¡¼ º¸¸é, infileÀÇ ÁÖ¼Ò¿Í scoreÀÇ ÁÖ¼Ò°¡ ³ª¿Â´Ù. ¿Ö ±×·²±î? read(FILE *infile, SCORE * score)¿¡¼ º¸¸é ¾Ë ¼ö ÀÖµíÀÌ pointer·Ð ¼±¾ðÀ» Çؼ, ÁÖ¼Ò·Î Àü´ÞµÈ´Ù. ÁÖ¼Ò·Î Àü´ÞµÉ¶§ÀÇ ÀåÁ¡°ú ´ÜÁ¡Àº ..? fgets´Â (f : file, get, s : string)·Î ÀÌÇØ ÇÏÀÚ. Áï ÈÀÏ¿¡¼ ÇÑ ÁÙ stringÀ» ¾ò´Â´Ù¶ó´Â ÂÊÀ¸·Î... p lineÀ¸·Î È®ÀÎ Çغ¸´Ï±î, Á¤¸»·Î ù¹ø° lineÀÇ ³»¿ëÀÌ º¸ÀδÙ. ------------------------------------------------------------- (gdb) b 25 Breakpoint 2 at 0x8048739: file read.c, line 25. (gdb) c Continuing. Breakpoint 2, read (infile=0x80499a8, score=0x8049a00) at read.c:25 25 sscanf(line,"%d %s %d %d %d", (gdb) p line $2 = " 1 À¯¼öÇà 100 100 100\n\000\n\000Î ¸¸µç °ÍÀÔ´Ï´Ù.\n \000¿\036;\000@\000\232\004\b$÷ÿ¿\004÷ÿ¿\225Ë\003@ \000\232\004\b\000\000\000" (gdb) s 28 } (gdb) p iscore $3 = (SCORE *) 0x8049a00 (gdb) p *iscore $4 = {name = "À¯¼öÇà\000\000\000", num = 1, korea = 100, math = 100, engl = 100, sum = 0, aver = 0, next = 0x0} (gdb) p score $5 = (SCORE *) 0x8049a00 (gdb) p *score $6 = {name = "À¯¼öÇà\000\000\000", num = 1, korea = 100, math = 100, engl = 100, sum = 0, aver = 0, next = 0x0} (gdb) ----<¼³¸í >--------------------------------------------- breakpoint¸¦ 25¹ø° ¶óÀÎÀ¸·Î ¼³Á¤Çß´Ù. ±×¸®°í, c ·Î ½ÇÇà½ÃÅ°¸é, 25¹ø° ¶óÀο¡¼ ½ÇÇàÀÌ ¸ØÃè´Ù. ÀÌ ¶§, line¿¡ ÀúÀåµÈ ³»¿ëÀ» º¸·Á°í, p lineÀ» ÃÆ°í, stepÀ» ÅëÇؼ sscanf¸¦ ½ÇÇà ½ÃÄ×´Ù. sscanf´Â s :string, scanf·Î ÀÌÇØÇÏÀÚ. string¿¡¼ scanfÇѴٴ°ÍÀÌ´Ù. ½ÇÁ¦·Î sscanf(line, " *******", ******); ó·³ stringÀÎ lineÀÌ ÇÔ¼ö³»¿¡ ÀÖ´Ù. iscore¿Í scoreÀÇ ÁÖ¼Ò°¡ °°´Ù. °í·Î ÀúÀåµÈ data ³»¿ëµµ °°´Ù. pointerÀÇ ±â´ÉÀ» »ìÀÛ ¿³º¼ ¼ö ÀÖ´Â ±âȸ´Ù. ------------------------------------------------------- (gdb) b write Breakpoint 3 at 0x8048773: file write.c, line 12. (gdb) c Continuing. Breakpoint 2, read (infile=0x80499a8, score=0x8049a00) at read.c:25 25 sscanf(line,"%d %s %d %d %d", (gdb) info b Num Type Disp Enb Address What 1 breakpoint keep y 0x080486dc in read at read.c:10 breakpoint already hit 1 time 2 breakpoint keep y 0x08048739 in read at read.c:25 breakpoint already hit 2 times 3 breakpoint keep y 0x08048773 in write at write.c:12 (gdb) d 2 (gdb) info b Num Type Disp Enb Address What 1 breakpoint keep y 0x080486dc in read at read.c:10 breakpoint already hit 1 time 3 breakpoint keep y 0x08048773 in write at write.c:12 (gdb) -----<¼³¸í>-------------------------------------- À̹øÀº ¼³Á¤µÈ breakpoint°¡ ¿ØÁö ºÎ´ã½º·¯¿ï ¶§°¡ ÀÖÀ» ¶§ ó¸®ÇÏ´Â ¹æ¹ýÀÌ´Ù. À§¿¡¼ b write ó·³ write ÇÔ¼ö¿¡ breakpoint¸¦ Àâ°í c·Î ½ÇÇà½ÃÄ״µ¥ Àü¿¡ ¼³Á¤Çß´ø breakpoint¿¡¼ ½ÇÇàÀÌ ¸ØÃè´Ù. ÀÌ breakpoint¸¦ ¾ø¾Ö±â À§Çؼ± info breakpoints¸¦ Ä¡¸éµÈ´Ù.( ¾àÀÚ·Î info b) ±×·¯¸é breakpoint¿¡ ÇÒ´çµÈ ¹øÈ£°¡ ÀÖ°í ÁÖ¼Ò¿Í ¾îµð¿¡¼ ¹«¾ùÀ» breakÇß´ÂÁö ¸Þ¼¼Áö°¡ ³ª¿Â´Ù. ¼³Á¤À» Ãë¼ÒÇÏ°í ½ÍÀº °÷Àº 2¹ø breakpoint À̹ǷÎ, delete 2 (¾àÀÚ·Î d 2)·Î Ä£´Ù. Á¤¸»·Î ¼³Á¤ÀÌ ÇØÁ¦µÇ¾ú´ÂÁö È®ÀÎ Çغ¸ÀÚ. info b .... ----------------------------------------------- ÀÌ°ÍÀ¸·Î µð¹ö±ë °Á¸¦ ¸¶Ä¡°íÀÚ ÇÑ´Ù. ´Ù¸¸ ºÎŹÇÒ °ÍÀº »ý°¢ÇÑ ¾î¶²°ÍÀ» ½ÇÇà½ÃÅ°°íÀÚ Çϳª ¸í·É¾î¸¦ ¸ð¸¦ ¶§, Áï, À§¿¡¼Ã³·³ ¼³Á¤µÈ breakpoint ¸¦ Á¦°ÅÇÏ°í ½Í´Ù´Â »ý°¢ÀÌ µé¸é, help( ¾àÀÚ·Î h)¸¦ Ä¡¸é, ------------------------------------ (gdb) h List of classes of commands: running -- Running the program stack -- Examining the stack data -- Examining data breakpoints -- Making program stop at certain points files -- Specifying and examining files status -- Status inquiries support -- Support facilities user-defined -- User-defined commands aliases -- Aliases of other commands obscure -- Obscure features internals -- Maintenance commands Type "help" followed by a class name for a list of commands in that class. Type "help" followed by command name for full documentation. Command name abbreviations are allowed if unambiguous. (gdb) ---------------------------------------------- °ú °°ÀÌ ³ª¿Â´Ù. status°¡ ±Ã±ÝÇϹǷÎ, ---------------------------------------------- (gdb) h status Status inquiries. List of commands: show -- Generic command for showing things about the debugger info -- Generic command for showing things about the program being debugged Type "help" followed by command name for full documentation. Command name abbreviations are allowed if unambiguous. (gdb) ------------------------------------------------- ¶Ç »õ·Î¿î ¼³¸í¹®ÀÌ ³ª¿Â´Ù. À̹ø¿¡ h info·Î Ä¡ÀÚ. ¿©·¯ºÐÀº h show³ª ´Ù¸¥ °ÍÀÇ ¸í·É¾î¸¦ ´«¿©°Ü º¸¾Æ¶ó. ÇÊ¿äÇÒ¶§ »ç¿ëµÉ ¼ö ÀÖ´Â ¸í·É¾î¸¦ ãÀ» ¼ö ÀÖ´Ù. -------------------------------------------------- " info breakpoints -- Status of user-settable breakpoints info files -- Names of targets and files being debugged info target -- Names of targets and files being debugged Type "help info" followed by info subcommand name for full documentation. Command name abbreviations are allowed if unambiguous. (gdb) ------------------------------------------------- À§¿¡ º¸ÀÌ´Â °Íó·³ info breakpoints´Â »ç¿ëÀÚ°¡ ¸¸µç breakpointsÀÇ status º¸ÀÌ´Â ¸í·É¾î¶ó´Â °ÍÀ» ¾Ë ¼ö ÀÖ´Ù. À§ ¹æ¹ýó·³ ¾ÕÀ¸·Î »ç¿ëÇØ ÁÖ±æ ¹Ù¶õ´Ù. À̹ø °Á¸¦ ÅëÇؼ ¸¹Àº °ÍÀ» º¸¿© ÁÙ·Á°í ÇßÁö¸¸, ¼ÖÁ÷È÷ ³ªµµ Ãʺ¸ÀÚ ¶ó ¸¹Àº °ÍÀ» º¸ÀÌÁö ¸ø ÇÏ°í µÎ¼ ¾øÀÌ ¼¼úÇÑ°Í °°´Ù. |