Re: What are the procedures to use self declared convenience functions in GDB?

Simon Marchi
2020-11-18T20:39:20Z

On 2020-11-18 12:18 a.m., Nagmat Nazar wrote:
> Dear Simon,
>
> I have written convenience function as on explanation:
> https://sourceware.org/gdb/onlinedocs/gdb/Functions-In-Python.html
> greet.py
> ```
>
> class Greet (gdb.Function):
> """Return string to greet someone.
> Takes a name as argument."""
>
> def __init__ (self):
> super (Greet, self).__init__ ("greet")
>
> def invoke (self, name):
> return "Hello, %s!" % name.string ()
>
> Greet ()
>
> ```
> image.png
>
> I have placed greet.py into ~/gdb/python/lib/gdb/function/, but as you see on the picture it still gives error. What else shall I do in order to use this function?
>
> Kind regards
> Nagmat

Just putting the file in ~/gdb/python/lib/gdb/function/ won't magically load it.

You should either use the source command inside GDB (or in a .gdbinit) or the -x switch when starting GDB.

Simon