Skip to content

Commit 75a192a

Browse files
committed
gdb stdout fu ++
1 parent 3bfda51 commit 75a192a

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

gdb/run

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
# run watch.out
99

1010
f="${1%.*}"
11-
gdb -batch -x "${f}.gdb" "${f}.out"
11+
gdb -batch -nh -x "${f}.gdb" "${f}.out"

gdb/stdout.c

+13-2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,22 @@
33
http://stackoverflow.com/questions/1538463/how-can-i-put-a-breakpoint-on-something-is-printed-to-the-terminal-in-gdb
44
*/
55

6+
#define _XOPEN_SOURCE 700
67
#include <stdio.h>
78
#include <stdlib.h>
9+
#include <unistd.h>
810

911
int main() {
10-
puts("a");
11-
puts("b");
12+
write(STDOUT_FILENO, "asdf1", 5);
13+
write(STDOUT_FILENO, "qwer1", 5);
14+
write(STDOUT_FILENO, "zxcv1", 5);
15+
write(STDOUT_FILENO, "qwer2", 5);
16+
printf("as");
17+
printf("df");
18+
printf("qw");
19+
printf("er");
20+
printf("zx");
21+
printf("cv");
22+
fflush(stdout);
1223
return EXIT_SUCCESS;
1324
}

gdb/stdout.gdb

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ start
22
define stdout
33
catch syscall write
44
commands
5-
x/s $rsi
6-
backtrace
5+
printf "rsi = %s\n", $rsi
6+
bt
77
continue
88
end
9-
# Stop if it contains arg0.
10-
condition 2 $rdi == 1 && strstr((char *)$rsi, "$arg0") != NULL
9+
condition $bpnum $rdi == 1 && strstr((char *)$rsi, "$arg0") != NULL
1110
end
12-
stdout b
11+
stdout qwer
12+
i b
1313
continue

0 commit comments

Comments
 (0)