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

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>
            老司机凹凸av亚洲导航| 欧美不卡激情三级在线观看| 亚洲少妇一区| 亚洲伊人网站| 欧美中文在线免费| 欧美成人精品一区二区| 日韩视频在线你懂得| 中文国产一区| 久久综合九色九九| 一区二区毛片| 欧美www视频| 亚洲视频一区| 小处雏高清一区二区三区| 欧美高清视频一区| 国产在线精品自拍| 一区二区三区蜜桃网| 免费在线日韩av| 亚洲综合色激情五月| 欧美精品亚洲| 在线不卡中文字幕播放| 亚洲性感激情| 亚洲欧洲日本在线| 亚洲香蕉伊综合在人在线视看| 中文精品视频| 樱桃成人精品视频在线播放| 一本久久a久久免费精品不卡| 国产日韩欧美在线播放不卡| 日韩亚洲欧美一区二区三区| 亚洲视频久久| 亚洲国产精品一区二区第四页av | 国内精品模特av私拍在线观看| 麻豆精品一区二区av白丝在线| 欧美日韩高清免费| 亚洲大胆av| 久久久亚洲国产天美传媒修理工| 一本色道久久综合| 在线观看亚洲专区| 亚洲午夜视频在线观看| 国产精品久久久久久久7电影| 亚洲全黄一级网站| 欧美激情一区二区三区全黄 | 午夜精品一区二区三区在线视 | 亚洲电影一级黄| 亚洲欧美日韩视频二区| 国产日韩欧美在线播放| 日韩视频免费| 欧美视频日韩视频在线观看| 国产精品99久久久久久白浆小说| 久久综合色播五月| 怡红院av一区二区三区| 99精品久久久| 国产三级精品三级| 一片黄亚洲嫩模| 亚洲免费观看视频| 一区二区三区鲁丝不卡| 91久久极品少妇xxxxⅹ软件| 久久精品一区蜜桃臀影院| 狠狠色丁香婷婷综合| 欧美aⅴ一区二区三区视频| 国产日韩欧美三级| 亚洲男人影院| 欧美在线观看日本一区| 欧美一区二区三区日韩视频| 亚洲第一黄色| 久久―日本道色综合久久| 亚洲精品欧美极品| 亚洲一区二区在线| 亚洲一区视频| 久久精品理论片| 久久婷婷国产综合尤物精品| 国产一区二区三区自拍| 最新国产成人av网站网址麻豆| 在线看成人片| 欧美国产成人精品| 亚洲精品123区| 中文网丁香综合网| 国产精品视频yy9099| 男人插女人欧美| 亚洲国产婷婷香蕉久久久久久| 亚洲午夜在线| 久久精品国产亚洲aⅴ| 欧美久久一区| 免费观看成人www动漫视频| 国产精品成人v| 欧美77777| 99精品欧美一区二区三区| 欧美日韩大片| 午夜精品久久久久| 欧美91福利在线观看| 一区二区三区视频免费在线观看| 国产精品第13页| 欧美一级精品大片| 欧美不卡在线| 亚洲天堂偷拍| 国内精品视频在线播放| 快射av在线播放一区| 99国产精品久久久久老师| 欧美有码视频| 亚洲日本va午夜在线影院| 欧美丝袜第一区| 久久久国产精彩视频美女艺术照福利| 亚洲国产高清高潮精品美女| 禁久久精品乱码| 欧美一区二区三区免费视| 欧美激情一区二区三区在线视频观看| 在线亚洲国产精品网站| 国外成人免费视频| 欧美日本一区| 欧美一区二区三区视频免费播放| 亚洲国产欧美在线人成| 亚洲国产片色| 国产精品影音先锋| 午夜精品久久| 最新国产成人av网站网址麻豆 | 亚洲精品一区二区三区樱花| 国产精品美女久久久| 中文国产亚洲喷潮| 欧美国产视频在线| 亚欧成人在线| 国产精品永久免费| 欧美日韩爆操| 老鸭窝亚洲一区二区三区| 亚洲一区二区三区在线视频| 91久久亚洲| 欧美二区在线看| 亚洲日韩欧美一区二区在线| 国内一区二区三区| 国产精品美女www爽爽爽视频| 欧美韩日一区| 美女脱光内衣内裤视频久久网站| 欧美大片在线看| 久久精品国产第一区二区三区最新章节 | 午夜精品影院在线观看| 一本色道久久综合亚洲精品不| 亚洲国产精品久久久久秋霞蜜臀 | 欧美主播一区二区三区美女 久久精品人| 乱中年女人伦av一区二区| 亚洲欧洲在线播放| 亚洲大片av| 亚洲成人在线| 亚洲高清自拍| 亚洲国产va精品久久久不卡综合| 激情久久婷婷| 在线看片日韩| 亚洲日韩视频| 亚洲精选视频免费看| 亚洲精品国产精品乱码不99按摩| 亚洲成色www8888| 亚洲国产影院| 亚洲人成在线观看| 亚洲青色在线| 亚洲色图制服丝袜| 亚洲视频在线一区| 性久久久久久久| 久久九九99视频| 亚洲视频在线观看网站| 这里只有精品丝袜| 亚洲男女自偷自拍图片另类| 亚洲高清视频的网址| 亚洲黄色免费网站| 日韩一级不卡| 香蕉精品999视频一区二区| 久久国内精品视频| 女人香蕉久久**毛片精品| 亚洲二区在线观看| 亚洲色图自拍| 欧美一区二区三区精品 | 99伊人成综合| 亚洲欧美一区二区三区极速播放| 欧美一区=区| 欧美a级大片| 欧美一区二区三区四区夜夜大片 | 99热免费精品在线观看| 这里只有视频精品| 久久精品一区四区| 欧美激情国产精品| 国产精品久久久久永久免费观看| 国产午夜精品麻豆| 99re6这里只有精品视频在线观看| 午夜精品久久久99热福利| 一道本一区二区| 亚洲免费高清视频| 久久爱www久久做| 欧美国产一区二区在线观看 | 久久国产精彩视频| 欧美激情一区在线观看| 亚洲欧美在线x视频| 牛人盗摄一区二区三区视频| 国产精品视频99| 亚洲美女淫视频| 久久久亚洲午夜电影| 99国产精品久久久久久久成人热 | 亚洲国产天堂久久国产91| 亚洲一区二区三区中文字幕| 欧美成人乱码一区二区三区| 国产日韩在线播放| 亚洲性感激情| 亚洲国产日韩一区| 久久久av水蜜桃| 国产精品亚洲不卡a|