Kim Kyoungmin
Kim Kyoungmin

Reputation: 13

gdb script, assign functions' return value in user variable

I would like to assign the "info sharedlibrary" value to a variable in user define function.

Such as,

define customFunction

    set $i = info sharedlibrary

end

But it seems impossible in gdb And also i cannot use python script too...

Is there any way to do this??

Thank you

ps. I trying to do this because i want to print only selected library's instructions.

Upvotes: 0

Views: 540

Answers (1)

Tom Tromey
Tom Tromey

Reputation: 22519

You don't mention why you can't use a Python function. That's by far the simplest way to program gdb.

However, if you really must do it, and really must avoid Python, there is a way. It's gross! But it does work. It's like this:

  • Use the various set logging commands to redirect output to a temporary file.
  • Invoke the command you want.
  • Use set logging again to disable logging.
  • Use the shell command to run sed or perl or what-have-you on this temporary file to turn it into a sequence of gdb commands, say commands to set a variable, or commands to print exactly the output you want.
  • source the resulting file

Upvotes: 1

Related Questions