(gdb)printf Hello %d, 7Hello 7(gdb)set $MyVar = printf Hello %d, 7 // ???How to save the result of printf Hello %d, 7 to $MyVar?
How to save the result of printf to a variable in GDB?
scripting;debugging;gdb
eval does a printf of its arguments and then runs it as a command. So you can take your printf argument list, insert set $MyVar = at the beginning, and eval it.(gdb) eval set $MyVar = \Hello %d\, 7(gdb) print $MyVar$2 = Hello 7