[cs631apue] setting variables in gdb
Jan Schaumann
jschauma at stevens.edu
Mon Oct 17 22:54:25 EDT 2022
Hello,
Here's the correct example of setting a variable using
gdb(1) by example of our simple-ls.c program:
https://stevens.netmeister.org/631/apue-code/05/gdb-examples/simple-ls.c
cc -g simple-ls.c
touch file
su root -c "chown 12345 file"
gdb ./a.out
(gdb) break printOwner
(gdb) run .
continue until printOwner is called with "file" as the
argument, then hit 'n' until you are past
pwd = getpwuid(sb.st_uid);
(gdb) p pwd
$1 = (struct passwd *) 0x0
(gdb) call (struct passwd *)getpwnam("root")
$2 = (struct passwd *) 0xfc04120dba58
(gdb) set pwd = $2
(gdb) next
Give it a try!
-Jan
More information about the cs631apue
mailing list