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

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 閱讀(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>
            亚洲片在线观看| 欧美极品在线播放| 亚洲电影免费观看高清完整版在线 | 欧美呦呦网站| 欧美一级播放| 久久一二三国产| 欧美大片免费观看| 欧美日韩免费在线| 国产视频综合在线| 亚洲黄色成人久久久| 亚洲一区亚洲二区| 毛片基地黄久久久久久天堂| 亚洲精品国产精品乱码不99按摩 | 亚洲欧美日本国产有色| 欧美一区二区性| 欧美+亚洲+精品+三区| 欧美日韩亚洲天堂| 精品二区久久| 一区二区三区视频在线| 亚洲尤物视频在线| 久久久国产一区二区三区| 亚洲国产婷婷综合在线精品| 亚洲综合色视频| 麻豆freexxxx性91精品| 欧美日韩亚洲一区三区| 黄色成人在线观看| 亚洲一区二区三区色| 玖玖玖国产精品| 亚洲一区二区三区中文字幕在线| 久久日韩粉嫩一区二区三区| 欧美日韩在线一二三| 狠狠色伊人亚洲综合网站色| 在线亚洲国产精品网站| 玖玖玖国产精品| 亚洲欧美国产va在线影院| 欧美激情在线狂野欧美精品| 国产亚洲一区二区三区| 亚洲免费中文| 亚洲人成人99网站| 久久九九久精品国产免费直播| 欧美日韩妖精视频| 亚洲一区二区三区在线播放| 免费不卡中文字幕视频| 亚洲图片欧洲图片av| 欧美高清视频一区二区| 黄色av日韩| 久久九九全国免费精品观看| 一区二区高清| 欧美久久久久久久久久| 在线日韩欧美| 免费不卡视频| 久久久五月婷婷| 国产综合自拍| 久久这里有精品15一区二区三区| 亚洲一二三区在线| 国产精品久久9| 亚洲欧美韩国| 亚洲女同精品视频| 国产欧美日本一区二区三区| 欧美与欧洲交xxxx免费观看| 中国av一区| 国产精品久久久久久久久借妻 | 欧美在线免费观看| 亚洲资源在线观看| 国产一区二区三区高清播放| 欧美一区二区三区免费观看视频 | 亚洲视频中文字幕| 国产精品久久久久久亚洲毛片| 一本久道综合久久精品| 99视频精品全部免费在线| 欧美婷婷在线| 欧美中文字幕在线播放| 欧美一区二区视频在线观看| 有坂深雪在线一区| 亚洲国产三级| 欧美性大战xxxxx久久久| 久久aⅴ乱码一区二区三区| 久久av红桃一区二区小说| 在线欧美日韩| 一本色道久久综合亚洲精品小说| 国产精品久久999| 久久成人国产精品| 毛片一区二区三区| 中文日韩在线视频| 午夜久久一区| 亚洲成人资源| 一区二区日韩| 国产亚洲欧洲997久久综合| 老鸭窝亚洲一区二区三区| 欧美交受高潮1| 欧美中文字幕在线| 欧美xx69| 久久精品亚洲| 欧美日韩国产限制| 久久青草福利网站| 欧美日韩三级| 久久婷婷一区| 欧美视频在线观看一区| 久久久久久久性| 欧美精品久久久久久久免费观看| 久久xxxx精品视频| 国产精品久久久久久久app| 久久蜜桃精品| 欧美日韩极品在线观看一区| 久久久久久久久蜜桃| 欧美日韩国内自拍| 欧美成年人在线观看| 国产精品天天摸av网| 亚洲观看高清完整版在线观看| 国产精品亚洲视频| 亚洲精品久久久久久久久久久久久| 国产日韩久久| 在线亚洲一区二区| 亚洲欧洲日本专区| 久久精品欧美日韩| 亚洲一区国产一区| 欧美不卡高清| 麻豆91精品| 国产欧美精品xxxx另类| 99视频国产精品免费观看| 亚洲精品一二三区| 美女亚洲精品| 欧美福利网址| 国内揄拍国内精品久久| 亚洲欧美日韩另类| 小黄鸭精品aⅴ导航网站入口| 欧美日韩视频第一区| 亚洲精品久久久久久久久久久久| 亚洲黄色有码视频| 浪潮色综合久久天堂| 久久男女视频| 极品中文字幕一区| 久久久午夜视频| 免播放器亚洲| 一区二区三区在线视频观看| 欧美亚洲综合久久| 久久久国产91| 又紧又大又爽精品一区二区| 久久精品中文字幕一区| 久久久久久久波多野高潮日日| 国产欧美丝祙| 亚洲欧美国产视频| 久久精品亚洲乱码伦伦中文| 国产亚洲一区在线播放| 欧美中文字幕第一页| 久久综合99re88久久爱| 一区二区三区在线观看欧美 | 欧美在线亚洲一区| 久久只有精品| 在线精品观看| 麻豆国产精品777777在线| 亚洲大片在线观看| 日韩视频免费大全中文字幕| 欧美人交a欧美精品| 亚洲一级片在线观看| 欧美中文字幕视频| 亚洲电影免费观看高清完整版| 噜噜噜在线观看免费视频日韩 | 亚洲精品在线观| 亚洲在线观看免费| 黄色精品一区二区| 欧美极品在线播放| 午夜激情久久久| 欧美激情一区二区三区在线视频观看 | 亚洲成色777777女色窝| 欧美极品一区| 午夜日韩在线| 亚洲国产精品久久久久婷婷老年 | 欧美亚洲一级| 精品二区久久| 欧美午夜激情在线| 久久久久欧美| 中文在线资源观看网站视频免费不卡 | 免费成人激情视频| 亚洲少妇一区| 欧美激情第六页| 欧美在线短视频| 日韩午夜在线视频| 国产免费成人av| 欧美激情视频在线播放| 午夜精品一区二区三区在线播放| 欧美激情a∨在线视频播放| 午夜精品一区二区三区电影天堂 | 欧美国产免费| 午夜日韩在线观看| 99国产精品国产精品久久| 老司机精品导航| 午夜在线精品| 9国产精品视频| 狠狠狠色丁香婷婷综合久久五月| 欧美日本在线| 欧美fxxxxxx另类| 欧美在线啊v| 亚洲一区三区视频在线观看| 欧美国产1区2区| 久久综合狠狠| 欧美一区二区视频免费观看| 日韩视频专区| 亚洲国产精品女人久久久| 国产私拍一区|