I have the following code:
write(fd[1], user_id, sizeof(user_id));
Is it possible to use gdb to see the contents of the buffer written to by this command? Using x or print just gives the memory address, not the contents of the buffer in that address.
(gdb) x write
0x7ffff7af4140 <__GI___libc_write>: 0xb1058d48
Since the fd[1] refers to stdout, this request should be equivalent to checking the status of the stdout buffer.
Additional info: user_id is a char array. fd[1] means write is writing to stdout (fd[0] refers to stdin). This is line 44 of a program, and I am accessing it with a breakpoint.
Let suppose you are interested in a variable user_id
which is present at line 44
of file myfile.c
of a program myprogram
write(fd[1], user_id, sizeof(user_id)); //line 44 of myfile.c
You must execute this :
gdb myprogram
Set breakpoint in gdb:
b myfile.c:44
Run program (After this command the breakpoint will be reached):
run
Print your variable value:
p user_id
似乎没有这样的 GDB 功能。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.