Results 1 to 1 of 1
HI
I am reading “Beginning Linux Programming"(3rd Edition). There is a code named debug4.c:
Code:
/* 1 */ typedef struct {
/* 2 */ char data[4096];
/* 3 */ int ...
- 07-22-2010 #1Just Joined!
- Join Date
- Jul 2010
- Posts
- 1
Need help: gdb breakpoint problem
HI
I am reading “Beginning Linux Programming"(3rd Edition). There is a code named debug4.c:
The book says, can set a breakpoint at line 20 in GDB, and the program will hit the breakpoint many times. But as I test it in Fedora 10, it can hit the breakpoint only once. Strangely, if I use step commands, the program can hit the 20 line where the breakpoint is set.Code:/* 1 */ typedef struct { /* 2 */ char data[4096]; /* 3 */ int key; /* 4 */ } item; /* 5 */ /* 6 */ item array[] = { /* 7 */ {"bill", 3}, /* 8 */ {"neil", 4}, /* 9 */ {"john", 2}, /* 10 */ {"rick", 5}, /* 11 */ {"alex", 1}, /* 12 */ }; /* 13 */ /* 14 */ sort(a,n) /* 15 */ item *a; /* 16 */ { /* 17 */ int i = 0, j = 0; /* 18 */ int s = 1; /* 19 */ /* 20 */ for(; i < n && s != 0; i++) { /* 21 */ s = 0; /* 22 */ for(j = 0; j < n-1; j++) { /* 23 */ if(a[j].key > a[j+1].key) { /* 24 */ item t = a[j]; /* 25 */ a[j] = a[j+1]; /* 26 */ a[j+1] = t; /* 27 */ s++; /* 28 */ } /* 29 */ } /* 30 */ n--; /* 31 */ } /* 32 */ } /* 33 */ /* 34 */ main() /* 35 */ { /* 36 */ int i; /* 37 */ sort(array,5); /* 38 */ for(i = 0; i < 5; i++) /* 39 */ printf("array[%d] = {%s, %d}\n", /* 40 */ i, array[i].data, array[i].key); /* 41 */ }
the GDB displays:
I am so confused. Does anybody know why? I am a linux newbie.Code:(gdb) break 20 Breakpoint 1 at 0x80483e4: file debug4.c, line 20. (gdb) run Starting program: /beginning_linux_programming_3rd_edition/code/chapter10/debug4 Breakpoint 1, sort (a=0x8049860, n=5) at debug4.c:20 20 /* 20 */ for(; i < n && s != 0; i++) { Missing separate debuginfos, use: debuginfo-install glibc-2.9-2.i686 (gdb) c Continuing. array[0] = {john, 2} array[1] = {alex, 1} array[2] = {bill, 3} array[3] = {neil, 4} array[4] = {rick, 5} Program exited with code 025. (gdb) run Starting program: /beginning_linux_programming_3rd_edition/code/chapter10/debug4 Breakpoint 1, sort (a=0x8049860, n=5) at debug4.c:20 20 /* 20 */ for(; i < n && s != 0; i++) { (gdb) step 21 /* 21 */ s = 0; (gdb) 22 /* 22 */ for(j = 0; j < n-1; j++) { (gdb) 23 /* 23 */ if(a[j].key > a[j+1].key) { (gdb) 22 /* 22 */ for(j = 0; j < n-1; j++) { (gdb) 23 /* 23 */ if(a[j].key > a[j+1].key) { (gdb) 24 /* 24 */ item t = a[j]; (gdb) 25 /* 25 */ a[j] = a[j+1]; (gdb) 26 /* 26 */ a[j+1] = t; (gdb) 27 /* 27 */ s++; (gdb) 22 /* 22 */ for(j = 0; j < n-1; j++) { (gdb) 23 /* 23 */ if(a[j].key > a[j+1].key) { (gdb) 22 /* 22 */ for(j = 0; j < n-1; j++) { (gdb) 23 /* 23 */ if(a[j].key > a[j+1].key) { (gdb) 24 /* 24 */ item t = a[j]; (gdb) 25 /* 25 */ a[j] = a[j+1]; (gdb) 26 /* 26 */ a[j+1] = t; (gdb) 27 /* 27 */ s++; (gdb) 22 /* 22 */ for(j = 0; j < n-1; j++) { (gdb) 30 /* 30 */ n--; (gdb) 20 /* 20 */ for(; i < n && s != 0; i++) { (gdb)
By the way, my english is not very good. But I am studying hard


Reply With Quote