Search code examples
bashshellandroid-ndkgdbndk-gdb

Pass gdb variable to a shell command excuted from gdb


I want to execute a shell command from gdb, this shell command needs an argument, and this argument is a gdb variable. How to make gdb interpret this variable before passing the command and argument to the shell interpreter ?

For example, in a gdb prompt:

(gdb) set $my_arg = 2
(gdb) shell echo $my_arg

I would like this to print 2 on stdout, but actually it does print a blank line.

Edit: I'm using ndk-gdb, which doesn't support python scripting.


Solution

  • With a new version of gdb, you can use "eval":

    (gdb) set $val = 2
    (gdb) eval "shell echo %d", $val
    2
    

    If you have an older version of gdb, then the best you can do is use "set logging" to write things to a file, then use shell utilities like sed to rewrite the file into the form you want.