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

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>
            久久精品国产2020观看福利| 亚洲欧洲一区二区在线观看| 99精品黄色片免费大全| 欧美日韩福利在线观看| 亚洲午夜久久久久久久久电影院 | 欧美电影在线观看| 蜜臀久久99精品久久久久久9| 亚洲激情电影在线| 亚洲人成在线观看| 国产精品萝li| 久久精视频免费在线久久完整在线看 | 亚洲成人在线视频播放 | 免费永久网站黄欧美| 欧美电影在线观看完整版| 性久久久久久久久| 精品av久久707| 亚洲国产精品va在线观看黑人| 欧美日韩一区二区国产| 欧美在线你懂的| 欧美1区免费| 小嫩嫩精品导航| 老司机亚洲精品| 免费国产一区二区| 亚洲一区视频在线| 亚洲福利久久| 国产精品成人播放| 欧美成人久久| 国产女同一区二区| 亚洲韩国精品一区| 国产亚洲欧美一区| 久久国产黑丝| 欧美日韩国产一级| 老司机免费视频一区二区三区| 欧美日本精品一区二区三区| 久久九九免费视频| 欧美日韩中文字幕综合视频| 毛片一区二区三区| 国产日韩av高清| 亚洲另类自拍| 在线观看欧美激情| 午夜精品久久久久影视| 一区二区三区精品视频| 久久在线视频| 久久国产福利| 国产精品香蕉在线观看| 亚洲免费观看在线视频| 中日韩在线视频| 亚洲精选一区| 欧美大秀在线观看| 麻豆精品精华液| 国产一区av在线| 亚洲性夜色噜噜噜7777| 国产精品亚洲精品| 亚洲每日更新| 一区二区欧美日韩| 免费欧美日韩| 欧美国产欧美亚洲国产日韩mv天天看完整 | 久久成人免费电影| 国产毛片一区二区| 99re视频这里只有精品| 一本一本久久a久久精品综合妖精 一本一本久久a久久精品综合麻豆 | 欧美成人亚洲| 在线日韩欧美视频| 亚洲欧洲综合另类| 亚洲国产婷婷综合在线精品| 久久久噜噜噜久噜久久| 久久全球大尺度高清视频| 国产亚洲在线观看| 亚洲欧美日韩一区| 久久精品国产亚洲aⅴ| 国产视频一区免费看| 午夜精品视频在线观看| 欧美另类99xxxxx| 欧美激情日韩| 日韩视频永久免费观看| 欧美日韩mv| 一本不卡影院| 先锋亚洲精品| 国内精品久久久久久久影视蜜臀 | 亚洲激情在线| 一区二区三区欧美成人| 欧美午夜精品一区| 亚洲一区二区黄| 91久久在线视频| 欧美激情亚洲激情| 亚洲一二三级电影| 久久综合九色99| 亚洲国产老妈| 国产精品多人| 久久精品国产一区二区三区| 欧美xart系列高清| 亚洲视频在线观看一区| 国产精品网站在线观看| 久久精品首页| 亚洲精品精选| 久久精品一区中文字幕| 亚洲一区精品电影| 你懂的国产精品| 亚洲图片在线| 狠狠久久亚洲欧美专区| 欧美噜噜久久久xxx| 午夜精品久久久久久久99热浪潮| 欧美va天堂va视频va在线| 亚洲一区二区在线看| 伊人成年综合电影网| 欧美三级网址| 久久综合亚洲社区| 亚洲影视九九影院在线观看| 亚洲第一成人在线| 久久激情中文| 国产精品99久久久久久久vr| 国产综合18久久久久久| 欧美涩涩网站| 免费在线成人av| 久久精品99国产精品酒店日本| 亚洲精品女人| 久久精品中文| 亚洲欧美日韩精品| 亚洲美女毛片| 尤物在线精品| 亚洲人成亚洲人成在线观看| 欧美中日韩免费视频| 亚洲色图自拍| 亚洲精品一区二区三区在线观看| 国产一区二区三区久久 | 欧美激情在线观看| 久久综合网络一区二区| 久久激情久久| 午夜在线观看欧美| 亚洲一区国产视频| 亚洲视频免费| 99国产精品久久久久久久成人热| 亚洲第一福利视频| 欧美粗暴jizz性欧美20| 久久久www成人免费无遮挡大片| 亚洲一区欧美一区| 亚洲视频免费看| 一区二区三区av| 日韩亚洲视频在线| 日韩视频在线你懂得| 日韩视频免费大全中文字幕| 最新日韩欧美| 日韩亚洲不卡在线| 一本色道久久综合精品竹菊| 亚洲毛片av在线| 日韩午夜在线电影| 午夜精品剧场| 久久精品人人爽| 久久久久久69| 欧美亚洲免费高清在线观看| 久久视频一区| 午夜精品视频网站| 亚洲主播在线观看| 午夜国产不卡在线观看视频| 午夜精品久久久久久久99热浪潮| 亚洲欧美日韩中文视频| 香蕉尹人综合在线观看| 欧美一区二区视频观看视频| 欧美一区二视频| 久久久人成影片一区二区三区| 久久综合免费视频影院| 欧美大片一区二区| 亚洲免费观看高清在线观看 | 91久久国产综合久久91精品网站| 在线免费精品视频| 亚洲久色影视| 亚洲国产一区二区三区高清| 久久精品免费| 久久裸体艺术| 欧美福利视频网站| 日韩视频免费在线观看| 中文欧美字幕免费| 久久成人免费网| 欧美国产激情二区三区| 国产精品嫩草久久久久| 国内精品久久久久影院薰衣草| 亚洲日本欧美天堂| 先锋影音国产一区| 欧美大片免费观看| 亚洲视频在线观看| 久久九九全国免费精品观看| 欧美日韩精品免费观看视频完整| 国产精品亚发布| 亚洲国产婷婷| 久久精品91| 亚洲精品美女久久7777777| 午夜精品视频在线观看| 亚洲欧美日本日韩| 欧美激情精品| 亚洲淫性视频| 欧美日韩 国产精品| 激情久久影院| 亚洲精品一区二区三| 中文在线资源观看视频网站免费不卡| 午夜精品久久久久久99热| 欧美va天堂| 国产亚洲欧美一区| 亚洲欧美变态国产另类| 亚洲国产精品传媒在线观看 | 在线视频你懂得一区二区三区|