public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug python/31362] New: generic cli command hooks in python
@ 2024-02-09 20:03 andreas at henning dot onl
  2024-02-09 20:05 ` [Bug python/31362] " andreas at henning dot onl
  0 siblings, 1 reply; 2+ messages in thread
From: andreas at henning dot onl @ 2024-02-09 20:03 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=31362

            Bug ID: 31362
           Summary: generic cli command hooks in python
           Product: gdb
           Version: unknown
            Status: UNCONFIRMED
          Severity: minor
          Priority: P2
         Component: python
          Assignee: unassigned at sourceware dot org
          Reporter: andreas at henning dot onl
  Target Milestone: ---

It looks like that currently it is not possible to create generic cli command
hooks within python.


Observation

When I create a command class deriving from `gdb.Command`[1] with an
appropriate name i.e `hook-print` the python defined command class instance is
not triggered automatically when I invoke the command for which the hook is
meant to be triggered (i.e. `print`). I still can successfully invoke the
python defined command within gdb cli by hand.


Possible hints

It looks to me that hooks are only "managed" in `gdb/cli/cli_*` code
(especially in `cli_script.c:do_define_command()`[2]). With managed I mean
where it is checked if a command is a hook and where hooks are connected to the
commands the hooks are intended for.
It looks like that those checks are not performed for python defined commands
(e.g. `do_define_command` is not invoked for python commands).


Wish

It would be great if python defined commands with appropriate names (i.g.
`hook-cmd` or `hookpost-cmd`) would behave in similar fashion to
cli/tty/gdbinit defined hooks.


Workaround 1:

Define a hook within cli/tty/gdbinit and Invoke the desired python
functionality within created cli/tty/gdbinit hook.

Example:
```gdbinit/cli
define hook-print
python_defined_command
end
```

Workaround 2:
Define a "cli hook" within python utilizing `gdb.execute`[3].

Example:
```python
gdb.execute("define hook-print\npython_defined_command\nend")
```


Links
[1] -
https://sourceware.org/gdb/current/onlinedocs/gdb.html/CLI-Commands-In-Python.html#CLI-Commands-In-Python
[1] -
https://sourceware.org/git/?p=binutils-gdb.git;a=blob;f=gdb/cli/cli-script.c;h=f06724af325af1645978b9db60299834c39bbc1e;hb=HEAD#l1479
[3] -
https://sourceware.org/gdb/current/onlinedocs/gdb.html/Basic-Python.html#index-gdb_002eexecute

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug python/31362] generic cli command hooks in python
  2024-02-09 20:03 [Bug python/31362] New: generic cli command hooks in python andreas at henning dot onl
@ 2024-02-09 20:05 ` andreas at henning dot onl
  0 siblings, 0 replies; 2+ messages in thread
From: andreas at henning dot onl @ 2024-02-09 20:05 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=31362

Andreas Henning <andreas at henning dot onl> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andreas at henning dot onl

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-02-09 20:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-09 20:03 [Bug python/31362] New: generic cli command hooks in python andreas at henning dot onl
2024-02-09 20:05 ` [Bug python/31362] " andreas at henning dot onl

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).