Created
November 15, 2012 08:09
-
-
Save DreamLinuxer/4077328 to your computer and use it in GitHub Desktop.
GDB script example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Reading symbols from ~/gist/gist-4077328/gdb_test...done. | |
Breakpoint 1 at 0x4005cf: file gdb_test.c, line 7. | |
Breakpoint 1, output (val=91652772) at gdb_test.c:7 | |
7 printf("OUTPUT: %X\n",val); | |
#0 output (val=91652772) at gdb_test.c:7 | |
#1 0x0000000000400632 in rand_output (prev=4294967295, mid=1073741824, mask=2147483647) at gdb_test.c:16 | |
#2 0x000000000040066a in main () at gdb_test.c:23 | |
Breakpoint 1, output (val=4481602) at gdb_test.c:7 | |
7 printf("OUTPUT: %X\n",val); | |
#0 output (val=4481602) at gdb_test.c:7 | |
#1 0x0000000000400632 in rand_output (prev=31378967, mid=8388608, mask=16777215) at gdb_test.c:16 | |
#2 0x0000000000400626 in rand_output (prev=54019494, mid=16777216, mask=33554431) at gdb_test.c:14 | |
#3 0x0000000000400626 in rand_output (prev=131004178, mid=33554432, mask=67108863) at gdb_test.c:14 | |
#4 0x0000000000400626 in rand_output (prev=211331964, mid=67108864, mask=134217727) at gdb_test.c:14 | |
#5 0x0000000000400626 in rand_output (prev=403325717, mid=134217728, mask=268435455) at gdb_test.c:14 | |
#6 0x0000000000400626 in rand_output (prev=602224003, mid=268435456, mask=536870911) at gdb_test.c:14 | |
#7 0x0000000000400626 in rand_output (prev=1661342506, mid=536870912, mask=1073741823) at gdb_test.c:14 | |
#8 0x0000000000400626 in rand_output (prev=4294967295, mid=1073741824, mask=2147483647) at gdb_test.c:14 | |
#9 0x000000000040066a in main () at gdb_test.c:23 | |
Breakpoint 1, output (val=187268169) at gdb_test.c:7 | |
7 printf("OUTPUT: %X\n",val); | |
#0 output (val=187268169) at gdb_test.c:7 | |
#1 0x0000000000400632 in rand_output (prev=4294967295, mid=1073741824, mask=2147483647) at gdb_test.c:16 | |
#2 0x000000000040066a in main () at gdb_test.c:23 | |
Breakpoint 1, output (val=289668203) at gdb_test.c:7 | |
7 printf("OUTPUT: %X\n",val); | |
#0 output (val=289668203) at gdb_test.c:7 | |
#1 0x0000000000400632 in rand_output (prev=4294967295, mid=1073741824, mask=2147483647) at gdb_test.c:16 | |
#2 0x000000000040066a in main () at gdb_test.c:23 | |
OUTPUT: 57682A4 | |
OUTPUT: 446242 | |
OUTPUT: B297C49 | |
OUTPUT: 1143FC6B | |
[Inferior 1 (process 23466) exited normally] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set breakpoint pending on | |
set pagination off | |
b output | |
command | |
bt | |
c | |
end | |
r | |
q |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
#include<stdlib.h> | |
#include<stdint.h> | |
#include<time.h> | |
void output(uint32_t val) | |
{ | |
printf("OUTPUT: %X\n",val); | |
} | |
void rand_output(uint32_t prev,uint32_t mid,uint32_t mask) | |
{ | |
uint32_t r; | |
r=rand()&mask; | |
if(r>mid) | |
rand_output(r,mid>>1,mask>>1); | |
else | |
output(r); | |
} | |
int main() | |
{ | |
int i; | |
srand(time(NULL)); | |
for(i=0;i<4;++i) | |
rand_output(0xFFFFFFFF,0x40000000,0x7FFFFFFF); | |
return 0; | |
} |
the first parameter of rand_output seems never used.
The parameter exists because I want to show all the intermediate random values in gdb.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
the first parameter of rand_output seems never used.