青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

EverSpring working shop

To pursue creative ideas based on nature.

統計

留言簿(1)

他山之石

閱讀排行榜

評論排行榜

GDB Tutorial for beginners (From network, i am reading also.)

QUOTE

      The  purpose  of a debugger such as GDB is to allow you to see what is
      going on ‘‘inside’’ another program while it executes—or what  another
      program was doing at the moment it crashed.
                                                                               
      GDB  can do four main kinds of things (plus other things in support of
      these) to help you catch bugs in the act:
                                                                               
          ·  Start your program, specifying anything that might  affect  its
              behavior.
                                                                               
          ·  Make your program stop on specified conditions.
                                                                               
          ·  Examine what has happened, when your program has stopped.
                                                                               
          ·  Change  things in your program, so you can experiment with cor-
              recting the effects of  one  bug  and  go  on  to  learn  about
              another.
--GDB Manpage


The first thing you need to do to start debugging your program is to compile it with debugging symbols, this is accomplished with the -g flag:
gcc filename.c -g -o filename
g++ filename.cpp -g -o filename


Lets start with a simple program that gets a line of text from the user, and prints it out backwards to the screen:


CODE

#include <stdio.h>
                                                                                                                                                             
int main(){

char input[50];
int i=0;

scanf("%s",input);

for(i=strlen(input);i>=0;i--)
   { printf("%c",input[i]);}
printf("\n");

return 0;
}



compile and start the debugger with:
gcc -g debug.c
gdb ./a.out

You should now be in the debugger.


There are 8 main commands that you will mostly be using in your debugging session

1.) break
2.) run
3.) print
4.) next
5.) step
6.) continue
7.) display
8.) where



1.) The Break Command:
gdb will remeber the line numbers of your source file. This will let us easily set up break points in the program. A break point, is a line in the code where you want execution to pause. Once you pause execution you will be able to examine variables, and walk through the program, and other things of that nature.
Continueing with our example lets set up a break point at line 6, just before we declare int i=0;

QUOTE

(gdb) break 6
Breakpoint 1 at 0x80483ec: file debug.c, line 6.
(gdb)




2.) The Run Command
Run will begin inital execution of your program. This will run your program as you normally would outside of the debugger, until it reaches a break point line.
At this moment, you will have been returned to the gdb command prompt.
(Using run again after your prgram has been started, will ask to terminate the current execution and start over)

From our example:

QUOTE

(gdb) run
Starting program: /u/khan/tmp/a.out
                                                                               
Breakpoint 1, main () at debug.c:6
6      int i=0;
(gdb)



3.)The Print Command
Print will let you see the values of data in your program. It takes an argument of the variable name.
In our example, we are paused right before we declare and intitalize i. Lets look what the value of i is now:

QUOTE

(gdb) print i
$1 = -1075457232
(gdb)


i contains junk, we havent put anything into it yet.


4. & 5.) Next and Step
Next and Step do basically the same thing, step line by line through the program. The difference is that next steps over a function call, and step will step into it.

Now in our example, we will step to the beginning of the next instruction

QUOTE

(gdb) step
8      scanf("%s",input);
(gdb)


before we execute the scanf, lets check the value of i again:
QUOTE
(gdb) print i
$2 = 0
(gdb)


i is now equal to 0, like it should be.

Now lets use next to move into the scanf statement:
QUOTE

(gdb) next


What happened here? We werent returned to the gdb prompt. Well the program is inside scanf, waiting for us to input something.
Input string here, and press enter:


6.) The Continue Command
Continue will pick up execution of the program after it has reached a break point.

Lets continue to the end of the program now:
QUOTE

(gdb) continue
Continuing.
tupni

Program exited normally.
(gdb)


Here we've reached the end of our program, you can see that it printed in resevese "input" which was what I fed it in scanf.


7.) The Display Command
display will show a vaiables contents each step of the way in your program. Lets start over in our example. Delete the breakpoint at line 6
QUOTE

(gdb) del break 1

This deletes our first breakpoint at line 6.

Now lets set a new breakpoint at line 11, the printf statement inside the for loop
QUOTE

(gdb) break 11
Breakpoint 3 at 0x8048421: file debug.c, line 11.
(gdb)


Run the program again, and enter the input, when it returns to the gdb command prompt we will display input[i] and watch it through the for loop

QUOTE

Breakpoint 3, main () at debug.c:11
11      { printf("%c",input[i]);}
(gdb) display input[i]
1: input[i] = 0 '\0'
(gdb) next
10      for(i=strlen(input);i>=0;i--)
1: input[i] = 0 '\0'
(gdb) next

Breakpoint 3, main () at debug.c:11
11      { printf("%c",input[i]);}
1: input[i] = 116 't'
(gdb) next
10      for(i=strlen(input);i>=0;i--)
1: input[i] = 116 't'
(gdb) next

Breakpoint 3, main () at debug.c:11
11      { printf("%c",input[i]);}
1: input[i] = 117 'u'
(gdb) next
10      for(i=strlen(input);i>=0;i--)
1: input[i] = 117 'u'
(gdb) next

Breakpoint 3, main () at debug.c:11
11      { printf("%c",input[i]);}
1: input[i] = 112 'p'
(gdb) next
10      for(i=strlen(input);i>=0;i--)
1: input[i] = 112 'p'
(gdb) next

Breakpoint 3, main () at debug.c:11
11      { printf("%c",input[i]);}
1: input[i] = 110 'n'
(gdb) next
10      for(i=strlen(input);i>=0;i--)
1: input[i] = 110 'n'
(gdb) next

Breakpoint 3, main () at debug.c:11
11      { printf("%c",input[i]);}
1: input[i] = 105 'i'
(gdb) next
10      for(i=strlen(input);i>=0;i--)
1: input[i] = 105 'i'
(gdb) next
12      printf("\n");
1: input[i] = -1 '\uffff'
(gdb)

Here we stepped through the loop, always looking at what input[i] was equal to.


9.)The Where Command
The where command prints a backtrace of all stack frames. This may not make much since but it is useful in seeing where our program crashes.

Lets modify our program just a little so that it will crash:
CODE

#include <stdio.h>
                                                                                                                                                             
int main(){

char *input;
int i=0;

scanf("%s",input);

for(i=strlen(input);i>=0;i--)
   { printf("%c",input[i]);}
printf("\n");

return 0;
}


Here we've changed input to be a pointer to a char.

Recompile and run gdb on it again.

and see what happens when it crashes

QUOTE


(gdb) r
Starting program: /u/khan/tmp/a.out
AAA

Program received signal SIGSEGV, Segmentation fault.
0x009ef267 in _IO_vfscanf_internal () from /lib/tls/libc.so.6
(gdb) where
#0  0x009ef267 in _IO_vfscanf_internal () from /lib/tls/libc.so.6
#1  0x009f3808 in scanf () from /lib/tls/libc.so.6
#2  0x08048403 in main () at debug.c:8
(gdb)



We see at the bottom, three frames,
#2, the top most shows where we crashed at.

use the up command to move up the stack
QUOTE

(gdb) up
#1  0x009f3808 in scanf () from /lib/tls/libc.so.6
(gdb) up
#2  0x08048403 in main () at debug.c:8
8      scanf("%s",input);
(gdb)

Here we see line #8
8 scanf("%s",input);

The line we crashed at.




These are the basics to gdb, you can now find where a program crashed, watch variables, and step through line by line of your program.

For more info check out the info page
info gdb

posted on 2007-10-12 22:02 everspring79 閱讀(870) 評論(0)  編輯 收藏 引用 所屬分類: Tools

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            国内精品久久久久久久果冻传媒| 美日韩精品免费观看视频| 欧美日韩日本国产亚洲在线| 99视频一区二区| 日韩视频精品| 国产精品香蕉在线观看| 欧美专区在线观看| 久久免费精品视频| 亚洲茄子视频| 亚洲一区二区日本| 合欧美一区二区三区| 欧美激情在线观看| 欧美日韩一区二区三区在线看 | 亚洲国产精品久久久久秋霞不卡| 久久国内精品自在自线400部| 精东粉嫩av免费一区二区三区| 欧美高清你懂得| 欧美日韩一区在线观看| 久久久.com| 欧美风情在线观看| 欧美一区二区三区在线观看视频| 久久精品久久综合| 亚洲深夜福利视频| 久久精品视频在线| 中文日韩在线| 久久综合九色综合网站| 亚洲免费影视第一页| 久久综合九色欧美综合狠狠| 亚洲欧美激情一区二区| 狂野欧美一区| 久久aⅴ乱码一区二区三区| 欧美va日韩va| 久久人人爽国产| 国产精品av久久久久久麻豆网| 裸体丰满少妇做受久久99精品 | 免费视频一区二区三区在线观看| 午夜日韩在线观看| 欧美国产日韩免费| 米奇777超碰欧美日韩亚洲| 国产精品成人v| 亚洲第一主播视频| 好看不卡的中文字幕| 亚洲小视频在线观看| 99ri日韩精品视频| 久久只有精品| 久久激情五月丁香伊人| 欧美日韩在线一区二区| 亚洲第一伊人| 91久久国产综合久久91精品网站| 午夜一区不卡| 欧美亚洲免费电影| 欧美午夜视频在线观看| 亚洲人午夜精品| 亚洲激情在线| 美女脱光内衣内裤视频久久影院| 久久久久久久久久看片| 国产日韩一区在线| 亚洲一区三区视频在线观看| 亚洲一级在线| 国产精品久久久一区麻豆最新章节 | 国内激情久久| 久久www成人_看片免费不卡| 欧美一区二区三区成人| 国产精品久久网| 亚洲一区二区三区乱码aⅴ蜜桃女| 999在线观看精品免费不卡网站| 久久综合九色九九| 亚洲国产影院| 最新日韩欧美| 欧美福利电影网| 亚洲日本欧美在线| 亚洲午夜电影网| 欧美日韩精品免费观看视一区二区| 欧美aⅴ一区二区三区视频| 伊人久久大香线蕉av超碰演员| 久久婷婷激情| 久久久国产成人精品| 国产欧美日韩不卡免费| 亚洲欧美在线播放| 久久一区精品| 国产自产精品| 另类激情亚洲| 亚洲美女色禁图| 亚洲尤物在线| 国产综合久久| 欧美福利在线| 亚洲欧美bt| 欧美成年人视频| 日韩视频在线一区二区| 欧美午夜不卡视频| 亚洲一区影院| 美脚丝袜一区二区三区在线观看 | 国产精品国产三级欧美二区| 亚洲欧美中文另类| 久久国产精品久久精品国产| 影音先锋成人资源站| 欧美大片网址| 亚洲无吗在线| 免费h精品视频在线播放| 亚洲国产99精品国自产| 国产精品久久久久久超碰| 欧美一区二区在线视频| 91久久亚洲| 久久久久久国产精品mv| 夜夜嗨av一区二区三区网页| 国产麻豆日韩欧美久久| 免费91麻豆精品国产自产在线观看| 一区二区三区视频在线观看| 久久人人看视频| 亚洲欧美乱综合| 亚洲精品免费在线| 国产日韩欧美在线播放不卡| 欧美人与禽猛交乱配| 久久精品理论片| 亚洲在线观看免费| 亚洲免费成人av| 亚洲成人在线网站| 久久久亚洲高清| 欧美一区三区三区高中清蜜桃| 日韩午夜激情| 亚洲国产精品久久久久婷婷老年| 国产精品一区二区三区久久| 欧美另类69精品久久久久9999| 久久嫩草精品久久久久| 午夜精品www| 9久草视频在线视频精品| 亚洲电影av| 免费在线看一区| 另类成人小视频在线| 久久电影一区| 欧美中文字幕不卡| 亚洲欧美日韩视频二区| 亚洲一区二区三区四区中文| 日韩一区二区精品葵司在线| 亚洲人成网站777色婷婷| 精品91在线| 亚洲精品国久久99热| 亚洲福利av| 亚洲国产精品久久久| 亚洲国产一区二区三区高清| 亚洲成人中文| 日韩视频二区| 亚洲午夜精品一区二区三区他趣 | 欧美激情网友自拍| 亚洲国产日韩欧美在线图片| 久久久久久**毛片大全| 在线亚洲一区观看| 美日韩精品视频免费看| 久久亚洲私人国产精品va| 久久免费国产精品| 免费日韩一区二区| 欧美激情精品| 欧美三级视频在线播放| 国产精品日韩欧美一区二区三区| 国产精品免费久久久久久| 国产精品一香蕉国产线看观看| 国产欧美精品日韩精品| 狠狠色狠狠色综合| 91久久精品视频| 亚洲午夜免费福利视频| 久久av一区二区三区| 另类激情亚洲| 亚洲美女毛片| 欧美一级二级三级蜜桃| 久久精品成人一区二区三区蜜臀 | 亚洲欧美日韩精品一区二区| 欧美一级网站| 欧美激情第二页| 国产精品看片你懂得| 韩国三级电影久久久久久| 亚洲欧洲日韩综合二区| 亚洲欧美变态国产另类| 久久久久久久久久久久久久一区| 亚洲大片一区二区三区| 中文精品视频| 久久在线观看视频| 欧美日韩中文字幕在线视频| 国产亚洲a∨片在线观看| 亚洲国产一成人久久精品| 亚洲欧美美女| 欧美1区2区3区| 亚洲一区二区影院| 乱码第一页成人| 国产精品永久| 99成人精品| 鲁大师成人一区二区三区| 日韩一级黄色片| 久久亚洲国产精品一区二区| 欧美午夜精品理论片a级大开眼界| 国内一区二区三区| 欧美粗暴jizz性欧美20| 国产伦精品一区二区三区视频孕妇 | 一区二区欧美日韩| 久久资源av| 国产精品综合色区在线观看| 亚洲人成人一区二区在线观看| 久久精品国产在热久久| 一区二区av| 欧美日本免费| 亚洲精品中文字|