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

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 閱讀(874) 評論(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>
            免费h精品视频在线播放| 亚洲精华国产欧美| 欧美一区二区视频在线| 国产免费观看久久黄| 欧美综合77777色婷婷| 欧美一区激情| 亚洲高清中文字幕| 亚洲国产片色| 国产精品久久久久久久久久免费看| 午夜在线视频观看日韩17c| 亚洲女人小视频在线观看| 狠狠久久亚洲欧美专区| 亚洲电影一级黄| 国产精品久久久久三级| 久久视频这里只有精品| 欧美韩国日本一区| 欧美一级淫片aaaaaaa视频| 久久久久国产成人精品亚洲午夜| 亚洲国产精品123| 99视频热这里只有精品免费| 国产女主播在线一区二区| 欧美88av| 国产精品日韩欧美一区二区| 欧美1区3d| 国产精品视频一二| 亚洲电影免费观看高清完整版在线| 欧美日韩免费在线观看| 久久免费视频在线观看| 欧美日韩系列| 另类春色校园亚洲| 国产精品免费网站在线观看| 免费影视亚洲| 国产精品一区二区视频 | 欧美视频福利| 久久男人av资源网站| 欧美日韩国产黄| 久久久亚洲影院你懂的| 欧美涩涩视频| 欧美国产高清| 国产一区二区三区在线观看精品 | 亚洲一区二区三区免费观看| 久久黄色小说| 午夜天堂精品久久久久| 欧美久久久久久久久久| 你懂的网址国产 欧美| 国产欧美日韩精品一区| 99re8这里有精品热视频免费 | 亚洲欧美日韩另类| 农村妇女精品| 免费欧美日韩| 黑丝一区二区三区| 午夜国产一区| 欧美亚洲一区二区三区| 欧美私人啪啪vps| 日韩视频久久| 日韩视频免费在线| 欧美国产日韩一区二区三区| 免费成人性网站| 激情成人综合网| 久久福利影视| 久久青草欧美一区二区三区| 国产色产综合色产在线视频| 亚洲一区二区三区在线视频| 中文在线不卡| 国产精品成人va在线观看| 亚洲精品在线观| 国产精品99久久久久久久久久久久 | 香蕉av福利精品导航| 国产精品www| 正在播放日韩| 欧美一区=区| 国产视频一区在线观看一区免费| 亚洲午夜在线观看| 久久av一区二区| 国产亚洲人成a一在线v站| 欧美一区二区三区喷汁尤物| 久久蜜桃资源一区二区老牛 | 国产精品成av人在线视午夜片| 日韩视频二区| 欧美一二三区在线观看| 国产美女诱惑一区二区| 久久精品伊人| 亚洲国产欧美一区| 亚洲天堂偷拍| 国产一区二区三区四区在线观看 | 国产欧美日韩精品一区| 久久精品av麻豆的观看方式| 欧美成人国产| 99综合视频| 国产毛片一区| 免费人成网站在线观看欧美高清| 亚洲精品偷拍| 久久精品国产91精品亚洲| 亚洲国产日韩一级| 国产精品初高中精品久久| 亚洲资源av| 欧美日韩在线一区二区三区| 亚洲免费观看视频| 久久婷婷久久| 日韩午夜精品视频| 国产日韩亚洲欧美| 欧美黄色大片网站| 亚洲永久网站| 亚洲国产另类久久久精品极度| 亚洲天堂成人| 亚洲国产经典视频| 国产精品日韩欧美一区二区| 久久综合九色欧美综合狠狠| 一区二区三区回区在观看免费视频 | 欧美天堂亚洲电影院在线观看 | 久久综合亚州| 亚洲一区二区免费| 亚洲电影免费观看高清完整版| 亚洲欧美视频在线观看视频| 一色屋精品视频免费看| 欧美午夜一区二区福利视频| 久久在线免费视频| 香蕉久久国产| a91a精品视频在线观看| 欧美成人精品1314www| 欧美一级视频一区二区| 一区二区欧美日韩视频| 在线观看一区二区精品视频| 国产精品一页| 欧美性视频网站| 欧美人在线观看| 欧美成人一区二区三区片免费| 欧美在线观看视频| 亚洲欧美视频在线观看视频| 亚洲毛片在线免费观看| 亚洲福利视频免费观看| 久久久精彩视频| 欧美在线免费观看视频| 亚洲综合欧美| 亚洲午夜av在线| 一区二区三区视频在线播放| 91久久亚洲| 亚洲激情电影中文字幕| 国内精品久久国产| 国产三级精品三级| 国产情人节一区| 国产女优一区| 国产日韩精品电影| 国产性做久久久久久| 国产精品一区二区三区成人| 国产精品成人播放| 国产精品美女一区二区在线观看| 欧美日一区二区在线观看| 欧美日韩亚洲免费| 欧美色欧美亚洲另类七区| 欧美午夜女人视频在线| 国产精品免费看久久久香蕉| 国产精品久久九九| 国产啪精品视频| 国内揄拍国内精品少妇国语| 伊人婷婷久久| 亚洲免费观看在线观看| 亚洲午夜精品国产| 性欧美18~19sex高清播放| 久久av老司机精品网站导航| 久久精品一本久久99精品| 乱中年女人伦av一区二区| 欧美承认网站| 亚洲精品色婷婷福利天堂| 亚洲视频在线观看视频| 欧美一级久久久| 久久人人爽人人| 欧美日韩久久精品| 国产亚洲综合精品| 亚洲精品欧洲| 午夜欧美电影在线观看| 美女亚洲精品| 99精品久久免费看蜜臀剧情介绍| 亚洲主播在线观看| 巨胸喷奶水www久久久免费动漫| 欧美片在线观看| 国产视频在线观看一区| 亚洲欧洲日韩综合二区| 午夜视频一区| 欧美黄色网络| 午夜精品理论片| 欧美日韩爆操| 一色屋精品视频在线看| 亚洲深夜福利视频| 美女视频黄免费的久久| 亚洲视频精品| 欧美成年网站| 国产综合av| 亚洲免费视频在线观看| 欧美激情一区二区| 午夜欧美视频| 欧美午夜精品久久久久久浪潮| 红桃视频国产一区| 香蕉久久a毛片| 亚洲精品在线三区| 另类综合日韩欧美亚洲| 国产精品中文字幕在线观看| 日韩小视频在线观看专区| 久久综合中文字幕| 亚洲欧美日韩第一区|