·¢ÐÅÈË: lhh.bbs@argo.zsu.edu.cn (ÒÐÌì), ÐÅÇø: cnunix
±ê Ìâ: GDB (2)(ת¼Ä£
·¢ÐÅÕ¾: Yat-sen Channel BBS (Wed Jul 29 18:51:38 1998)
תÐÅÕ¾: Lilac!ustcnews!news.zsu.edu.cn!argo
³ö ´¦: argo.zsu.edu.cn
ÕâÀïÊÇGDBµÄÒ»¸öÀý×Ó£º
ÔÎÄÖÐÊÇʹÓÃÒ»¸ö½Ðm4µÄ³ÌÐò¡£µ«ºÜÒź¶ÎÒÕÒ²»µ½Õâ¸ö³ÌÐòµÄÔ´úÂ룬
ËùÒÔûÓа취À´°´ÕÕÔÎÄÀ´ËµÃ÷¡£²»¹ý·´ÕýÊǸöÀý×Ó£¬ÎÒ¾ÍÄÃÒ»¸ö²Ù×÷ϵͳµÄ
½ø³Ìµ÷¶ÈÔÂëÀ´ËµÃ÷°Ñ£¬Ô´úÂëÎһḽÔÚºóÃæ¡£
Ê×ÏÈÕâ¸ö³ÌÐò½Ðos.cÊÇÒ»¸öÄ£Äâ½ø³Ìµ÷¶ÈµÄÔ³ÌÐò(Ò²ÐíÊǸöÀϹŶÁË£º-))¡£
ÏÈ˵Ã÷Ò»ÏÂÈçºÎÈ¡µÃ°üÀ¨Ô´úÂë·ûºÅµÄ¿ÉÖ´ÐдúÂë¡£´ó¼ÒÓÐÐĵĻ°¿ÉÒÔÈ¥¿´Ò»ÏÂgccµÄ
manÎļþ(ÔÚshellÏ´òman gcc)¡£gcc -g <ÔÎļþ.c> -o <ÒªÉú³ÉµÄÎļþÃû>
-g µÄÒâ˼ÊÇÉú³É´øÔ´úÂëµ÷ÊÔ·ûºÅµÄ¿ÉÖ´ÐÐÎļþ¡£
-o µÄÒâ˼ÊÇÖ¸¶¨¿ÉÖ´ÐÐÎļþÃû¡£
(gcc µÄÃüÁîÐвÎÊýÓÐÒ»´ó¶Ñ£¬ÓÐÐËȤ¿ÉÒÔ×Ô¼ºÈ¥¿´¿´¡£)
·´ÕýÔÚlinuxÏ°Ños.cÓÃÒÔÉÏ·½·¨±àÒëÁ¬½ÓÒÔºó¾Í²úÉúÁ˿ɹ©gdbʹÓõĿÉÖ´ÐÐÎļþ¡£
ÎÒÓÃgcc -g os.c -o os£¬²úÉúµÄ¿ÉÖ´ÐÐÎĵµ½Ðos.
È»ºó´ògdb os,¾Í¿É½øÈëgdb£¬ÆÁÄ»Ìáʾ£º
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.16, Copyright 1995 Free Software Foundation, Inc...
(gdb)
(gdb)ÊÇÌáʾ·û£¬ÔÚÕâÌáʾ·ûÏ¿ÉÒÔÊäÈëÃüÁֱµ½Í˳ö¡£(Í˳öÃüÁîÊÇq/Q)
ΪÁ˾¡Á¿ºÍÔÎĵµËµÃ÷µÄÃüÁîÏà·û£¬¼´Ê¹ÔÚ±¾Àý×ÓÖÐûÓõÄÃüÁîÎÒÒ²½«ÑÝʾ¡£
Ê×ÏÈÎÒÃÇ¿ÉÒÔÉèÖÃgdbµÄÆÁÄ»´óС¡£¼üÈ룺
(gdb)set width 70
¾ÍÊǰѱê×¼ÆÁÄ»ÉèΪ70ÁС£
È»ºóÈÃÎÒÃÇÀ´ÉèÖöϵ㡣ÉèÖ÷½·¨ºÜ¼òµ¥:break»ò¼òµ¥´òbºóÃæ¼ÓÐкŻòº¯ÊýÃû
±ÈÈçÎÒÃÇ¿ÉÒÔÔÚmain º¯ÊýÉÏÉè¶Ïµã£º
(gdb)break main
»ò(gdb)b main
ϵͳÌáʾ£ºBreakpoint 1 at 0x8049552: file os.c, line 455.
È»ºóÎÒÃÇ¿ÉÒÔÔËÐÐÕâ¸ö³ÌÐò£¬µ±³ÌÐòÔËÐе½mainº¯Êýʱ³ÌÐò¾Í»áÍ£Ö¹·µ»Øµ½gdbµÄ
Ìáʾ·ûÏ¡£ÔËÐеÄÃüÁîÊÇrun»òr(gdbÖÐÓв»ÉÙalias,¿ÉÒÔ¿´Ò»ÏÂhelp,ÔÚgdbÏ´òhelp)
run ºóÃæ¿ÉÒÔ¸ú²ÎÊý£¬¾ÍÊÇΪ³ÌÐòÖ¸¶¨ÃüÁîÐвÎÊý¡£
±ÈÈçr abcd£¬Ôò³ÌÐò¾Í»áabcdÒÔ×÷Ϊ²ÎÊý¡£(ÕâÀïҪ˵Ã÷µÄÊÇ¿ÉÒÔÓÃset argsÀ´Ö¸¶¨²Î
Êý)¡£´òÈër»òrunºó£¬³ÌÐò¾Í¿ªÊ¼ÔËÐÐÖ±µ½½øÈëmainµÄÈë¿ÚÍ£Ö¹£¬ÏÔʾ£º
Starting program: <·¾¶>/os
Breakpoint 1, main () at os.c:455
455 Initial();
ÕâÀï455 Initial();Êǽ«ÒªÖ´ÐеÄÃüÁî»òº¯Êý¡£
gdbÌṩÁ½ÖÖ·½Ê½£º1.µ¥²½½øÈë,step into¾ÍÊǸú×Ùµ½º¯ÊýÄÚÀ²¡£ÃüÁîÊÇstep»òs
2.µ¥²½£¬next£¬¾ÍÊǼòµ¥µÄµ¥²½£¬²»»á½øÈ뺯Êý¡£ÃüÁîÊÇnext»òn
ÕâÁ½¸öÃüÁÓбðµÄÓ÷¨ÒÔºóÔÙ˵¡£
ÎÒÃÇÓÃnÃüÁ¼üÈë:
(gdb)n
Success forking process# 1 ,pid is 31474
Success forking process# 2 ,pid is 31475
Success forking process# 3 ,pid is 31476
Success forking process# 4 ,pid is 31477
Success forking process# 5 ,pid is 31478
Success forking process# 6 ,pid is 31479
Dispatching Algorithm : FIFO
********************************************************************************
PCB# PID Priority PC State
1 31474 24 0 WAITING
2 31475 19 0 WAITING
3 31476 16 0 WAITING
4 31477 23 0 WAITING
5 31478 22 0 WAITING
6 31479 20 0 WAITING
******************************************************************************
CPU : NO process running
IO : No process
Waiting CPU!!! 31474 31475 31476 31477 31478 31479
Waiting IO NONE
456 State=WAITING;
×îºóµÄÒ»ÐоÍÊÇÏÂÒ»¾äÒªÖ´ÐеÄÃüÁî¡£ÎÒÃÇÏÖÔÚÔÚÁíÒ»¸öº¯ÊýÉϼӶϵ㡣עÒâÎÒÃÇ
¿ÉÒÔÓÃl/listÃüÁîÀ´ÏÔʾԴúÂë¡£ÕâÀïÎÒÃǼüÈë
(gdb)l
451 main()
452 {
453 int message;
454
455 Initial();
456 State=WAITING;
457 printf("Use Control-C to halt \n");
458 signal(SIGALRM,AlarmMessage);
459 signal(SIGINT,InteruptMessage);
460 signal(SIGUSR2,IoMessage);
(gdb) l
461 alarm(TimeSlot);
462 for(;;)
463 {
464 message=GetMessage();
465 switch(message)
466 {
467 case INTERRUPT : printf("Use Control-C t;
468 break;
469 case CHILD_IO: WaitingIo();
470 break;
ÏÔʾÁËÔ´úÂ룬ÏÖÔÚÔÚAlarmMessageÉϼӶϵ㡣
(gdb) b AlarmMessage
Breakpoint 2 at 0x8048ee3: file os.c, line 259.
(gdb)
È»ºóÎÒÃǼÌÐøÔËÐгÌÐò¡£
(gdb)c
c»òcontinueÃüÁîÈÃÎÒÃǼÌÐø±»ÖжϵijÌÐò¡£ ÏÔʾ£º
Continuing.
Use Control-C to halt
Breakpoint 2, AlarmMessage () at os.c:259
259 ClearSignal();
×¢ÒâÎÒÃÇÏÂÒ»¾äÓï¾ä¾ÍÊÇClearSignal();
ÎÒÃÇÓÃs/step¸ú×Ù½øÈëÕâ¸öº¯Êý¿´¿´ËüÊǸÉʲôµÄ¡£
(gdb) s
ClearSignal () at os.c:227
227 signal(SIGINT,SIG_IGN);
ÓÃlÃüÁîÁгöÔ´úÂ룺
(gdb) l
222 }
223
224
225 void ClearSignal() /* Clear other signals */
226 {
227 signal(SIGINT,SIG_IGN);
228 signal(SIGALRM,SIG_IGN);
229 signal(SIGUSR2,SIG_IGN);
230 }
231
(gdb)
ÎÒÃÇ¿ÉÒÔÓÃsÃüÁî¼ÌÐø¸ú×Ù¡£ÏÖÔÚÈÃÎÒÃÇÀ´ÊÔÊÔbt»òbacktraceÃüÁî¡£Õâ¸öÃüÁî¿ÉÒÔ
ÏÔʾջÖеÄÄÚÈÝ¡£
(gdb) bt
#0 ClearSignal () at os.c:227
#1 0x8048ee8 in AlarmMessage () at os.c:259
#2 0xbffffaec in ?? ()
#3 0x80486ae in ___crt_dummy__ ()
(gdb)
´ó¼ÒÒ»¶¨ÄÜ¿´¶®ÏÔʾµÄÒâ˼¡£Õ»¶¥ÊÇAlarmMessage£¬½ÓÏÂÀ´µÄº¯ÊýûÓÐÃû×Ö--¾ÍÊÇ
ûÓÐÔ´úÂë·ûºÅ¡£ÕâÏÔʾÁ˺¯Êýµ÷ÓõÄǶÌס£
ºÃÁË£¬ÎÒÃǸú×ÙÁË°ëÌ컹ûÓмì²é¹ý±äÁ¿µÄÖµÄØ¡£¼ì²é±í´ïʽµÄÖµµÄÃüÁîÊÇp»òprint
¸ñʽÊÇp <±í´ïʽ>
444444ÈÃÎÒÃÇÀ´ÕÒÒ»¸ö±äÁ¿À´¿´¿´¡££º-)
(gdb)l 1
»¹¼ÇµÃlµÄ×÷ÓÃÂð£¿l»òlistÏÔʾԴúÂë·ûºÅ£¬l»òlist¼Ó<ÐкÅ>¾ÍÏÔʾ´Ó<ÐкÅ>¿ªÊ¼µÄ
Ô´úÂë¡£ºÃÁËÕÒµ½Ò»¸öÈÃÎÒÃÇÀ´¿´¿´WaitingQueueµÄÄÚÈÝ
(gdb) p WaitingQueue
$1 = {1, 2, 3, 4, 5, 6, 0}
(gdb)
WaitingQueueÊÇÒ»¸öÊý×飬gdb»¹Ö§³Ö½á¹¹µÄÏÔʾ£¬
(gdb) p Pcb
$2 = {{Pid = 0, State = 0, Prior = 0, pc = 0}, {Pid = 31474, State = 2,
Prior = 24, pc = 0}, {Pid = 31475, State = 2, Prior = 19, pc = 0}, {
Pid = 31476, State = 2, Prior = 16, pc = 0}, {Pid = 31477, State = 2,
Prior = 23, pc = 0}, {Pid = 31478, State = 2, Prior = 22, pc = 0}, {
Pid = 31479, State = 2, Prior = 20, pc = 0}}
(gdb)
ÕâÀï¿ÉÒÔ¶ÔÕÕÔ³ÌÐò¿´¿´¡£
ÔÎĵµÀïÊÇÒ»¸öµ÷ÊÔ¹ý³Ì£¬²»¹ýÎÒÏëÕâÀïÎÒÒѾ°ÑgdbµÄ³£Óù¦ÄܽéÉÜÁËÒ»±é£¬»ù±¾ÉÏ
¿ÉÒÔÓÃÀ´µ÷ÊÔ³ÌÐòÁË¡££º-)
--
¡ù À´Ô´:£®Yat-sen Channel argo.zsu.edu.cn£®[FROM: www.ee.zsu.edu.c]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
Ò³ÃæÖ´ÐÐʱ¼ä£º3.191ºÁÃë