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

EverSpring working shop

To pursue creative ideas based on nature.

統(tǒng)計

留言簿(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 閱讀(871) 評論(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>
            欧美系列电影免费观看| 美乳少妇欧美精品| 欧美日韩在线视频一区| 亚洲精品乱码久久久久久蜜桃麻豆| 欧美jjzz| 欧美国产精品| 亚洲午夜一区二区| 欧美一级大片在线观看| 精品999成人| 亚洲国产欧美日韩另类综合| 一个人看的www久久| 免费成人av在线看| 免费欧美日韩国产三级电影| 日韩一级大片在线| 99在线精品视频在线观看| 国产精品一区二区黑丝| 久久在线免费观看| 老司机午夜精品视频在线观看| 亚洲图片在区色| 久久全国免费视频| 夜夜嗨av色一区二区不卡| 中文av一区特黄| 国产亚洲一区二区三区| 亚洲高清自拍| 国产精品日韩高清| 亚洲激情校园春色| 国产一区二区欧美| 91久久久在线| 国产热re99久久6国产精品| 欧美大片91| 国产日韩av一区二区| 亚洲国产人成综合网站| 国产亚洲精品一区二区| 亚洲欧洲一区二区天堂久久| 国产日韩欧美日韩大片| 亚洲欧洲一二三| 一区二区视频免费在线观看 | 国产精品丝袜91| 亚洲国产精品一区在线观看不卡| 国产精品亚洲产品| 99国产成+人+综合+亚洲欧美| 亚洲成人在线视频播放| 香蕉成人久久| 欧美一级大片在线观看| 欧美理论电影在线播放| 欧美福利视频| 在线观看欧美精品| 久久国产精品99国产精| 午夜精品视频在线观看一区二区| 欧美激情久久久久久| 狂野欧美激情性xxxx| 国产区欧美区日韩区| 一区二区福利| 亚洲影院在线| 欧美日韩在线观看一区二区| 亚洲黑丝在线| 亚洲人成在线观看| 欧美成人69| 亚洲国产三级网| 亚洲精品视频啊美女在线直播| 久久久噜噜噜久噜久久| 麻豆久久精品| 亚洲成色777777在线观看影院| 欧美在线一级va免费观看| 欧美一区二区三区视频免费播放| 国产精品―色哟哟| 亚洲午夜在线视频| 午夜精品国产| 国产综合亚洲精品一区二| 欧美一级艳片视频免费观看| 久久精品免费| 激情亚洲网站| 麻豆成人在线| 亚洲精品裸体| 午夜国产不卡在线观看视频| 国产精品日韩欧美大师| 午夜精品一区二区三区在线播放| 久久成人精品| 在线电影欧美日韩一区二区私密| 久久尤物视频| 亚洲激情偷拍| 亚洲欧美成人| 国产一区二区三区久久久久久久久| 欧美一区二区三区久久精品| 韩国成人理伦片免费播放| 另类激情亚洲| 亚洲免费观看视频| 国产精品久久久久久久久| 亚洲欧美一区二区原创| 久热精品视频| 在线视频亚洲一区| 国产日韩欧美在线播放不卡| 久久精视频免费在线久久完整在线看| 欧美va亚洲va日韩∨a综合色| 日韩写真在线| 国产深夜精品福利| 欧美1级日本1级| 亚洲一区二区三区色| 久久一日本道色综合久久| 日韩一级裸体免费视频| 国产精品制服诱惑| 免费欧美网站| 欧美一区二区三区免费大片| 亚洲欧洲综合| 久久精品夜色噜噜亚洲aⅴ| 亚洲精品视频在线观看网站| 国产精品久久久久久户外露出| 久久精品国产2020观看福利| 亚洲精品国产无天堂网2021| 久久久最新网址| 亚洲视频一起| 亚洲国产老妈| 国产人成精品一区二区三| 欧美激情免费在线| 久久九九国产精品| 中文久久精品| 亚洲看片一区| 欧美成年人视频| 久久久精品视频成人| 亚洲在线视频网站| 亚洲精品影视在线观看| 国内精品久久久久影院 日本资源| 欧美精品在欧美一区二区少妇| 久久激情五月丁香伊人| 亚洲已满18点击进入久久| 亚洲欧洲一区二区三区| 欧美激情国产高清| 玖玖玖国产精品| 久久九九精品99国产精品| 亚洲欧美一区二区三区久久| 一区二区欧美精品| 亚洲精品黄色| 亚洲人线精品午夜| 亚洲欧洲视频| 亚洲国产日韩综合一区| 亚洲第一黄网| 亚洲国产高清aⅴ视频| 一区二区三区在线视频免费观看| 国产亚洲一本大道中文在线| 国产精品综合不卡av| 国产精品女人网站| 国产欧美精品国产国产专区| 国产精品久久久久久户外露出| 欧美日韩视频在线第一区| 欧美日韩网址| 欧美性片在线观看| 国产乱码精品一区二区三| 国产精品一区视频网站| 国产日韩欧美在线播放| 国产无一区二区| 合欧美一区二区三区| 在线观看一区二区视频| 亚洲黄色免费| 一本色道久久综合亚洲精品小说| 在线视频欧美一区| 性欧美videos另类喷潮| 久久久久九九视频| 蜜桃久久精品乱码一区二区| 欧美福利在线观看| 亚洲人成精品久久久久| 一本久久a久久免费精品不卡| 亚洲私人影院在线观看| 亚洲性感激情| 中文国产成人精品久久一| 亚洲夜间福利| 久久国产福利国产秒拍| 久久精品欧美| 亚洲福利视频三区| 一本色道久久综合狠狠躁的推荐| 亚洲天堂第二页| 久久久久免费观看| 欧美日韩精品免费观看视一区二区| 欧美体内she精视频| 一区二区三区在线免费观看| 日韩一区二区精品在线观看| 亚洲欧美另类在线观看| 免费一级欧美片在线播放| 99视频热这里只有精品免费| 午夜精品在线| 欧美精品一区二区三区高清aⅴ| 国产精品久久久久久久久久久久| 国内免费精品永久在线视频| 日韩午夜电影av| 久久激情五月丁香伊人| 亚洲欧洲精品一区二区| 欧美在线免费播放| 欧美日韩www| 在线免费不卡视频| 欧美一区三区二区在线观看| 欧美激情在线免费观看| 亚洲与欧洲av电影| 欧美激情va永久在线播放| 国产网站欧美日韩免费精品在线观看 | 久久一本综合频道| 一区二区国产精品| 美国成人直播| 国产亚洲精品久久久久婷婷瑜伽| 亚洲性感美女99在线| 欧美国产亚洲视频| 久久av在线看|