public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
From: Andrew Burgess <aburgess@redhat.com>
To: Simon Sobisch <simonsobisch@gnu.org>
Cc: gdb@sourceware.org
Subject: Re: How to recognize `exec-interrupt` via Python events
Date: Tue, 7 Dec 2021 11:08:33 +0000	[thread overview]
Message-ID: <20211207110833.GF123597@redhat.com> (raw)
In-Reply-To: <74ce7f64-4368-aee4-1150-28cbd9cc6ae1@gnu.org>

* Simon Sobisch via Gdb <gdb@sourceware.org> [2021-12-06 21:11:23 +0100]:

> It is possible that I've just overlooked something, but I can't seem to get
> an event triggered at all:
> 
> 	gdb.events.stop.connect(stop_handler)
> 
> is triggered after each step/next, a expected; also on signals including
> SIGINT, also when pressing CTRL+C when the inferior is running, type can be
> checked with
> 
> 	if type(event) is gdb.StopEvent
> 
> When the MI frontend (Vim in this case, but this should also apply to Emacs
> and others) executes `-exec-step` or `-exec-next` the event is triggered,
> when the inferior is running and a breakpoint/watchpint is triggered, too.
> But when the inferior is running and `-exec-interrupt` is triggered then the
> python code seems to not get an event at all - do I need to connect to a
> different event registry?

Maybe I'm not understanding your problem description, here's my
session trying to reproduce the issue:

##### START #####

$$$ cat test.c
#include <unistd.h>

int
main ()
{
  while (1)
    sleep (1);
  return 0;
}
$$$ gcc -g3 -O0 -o test.x test.c
$$$ cat stop-event.py 
import gdb

def stop_handler(event):
    print("stop event: %s" % event)

gdb.events.stop.connect(stop_handler)
$$$ gdb --version
GNU gdb (GDB) 11.1
Copyright (C) 2021 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
$$$ gdb -q -i mi test.x
=thread-group-added,id="i1"
=cmd-param-changed,param="print pretty",value="on"
~"Reading symbols from test.x...\n"
(gdb) 
-gdb-set mi-async on
^done
(gdb) 
source stop-event.py
&"source stop-event.py\n"
^done
(gdb) 
-exec-run
=thread-group-started,id="i1",pid="2623705"
=thread-created,id="1",group-id="i1"
=library-loaded,id="/lib64/ld-linux-x86-64.so.2",target-name="/lib64/ld-linux-x86-64.so.2",host-name="/lib64/ld-linux-x86-64.so.2",symbols-loaded="0",thread-group="i1",ranges=[{from="0x00007ffff7fd3110",to="0x00007ffff7ff2bb4"}]
^running
*running,thread-id="all"
(gdb) 
=library-loaded,id="/lib64/libc.so.6",target-name="/lib64/libc.so.6",host-name="/lib64/libc.so.6",symbols-loaded="0",thread-group="i1",ranges=[{from="0x00007ffff7df36b0",to="0x00007ffff7f40c5f"}]
-exec-interrupt
^done
(gdb) 
~"\nProgram"
~" received signal SIGINT, Interrupt.\n"
~"0x00007ffff7e9c1e7 in nanosleep () from /lib64/libc.so.6\n"
*stopped,reason="signal-received",signal-name="SIGINT",signal-meaning="Interrupt",frame={addr="0x00007ffff7e9c1e7",func="nanosleep",args=[],from="/lib64/libc.so.6",arch="i386:x86-64"},thread-id="1",stopped-threads="all",core="9"
~"stop event: <gdb.SignalEvent object at 0x7f6a502fcbd0>\n"
quit
&"quit\n"
=thread-exited,id="1",group-id="i1"
=thread-group-exited,id="i1"
$$$ 

##### END #####

Notice, the 6th line from the end of the session:

    ~"stop event: <gdb.SignalEvent object at 0x7f6a502fcbd0>\n"

This is the stop event arriving after the -exec-interrupt.  This was
with gdb 11.1, but I also tested 10.2, 9.2, and 8.3.1, all gave the
same results.

Could you provide an example .py file, and a precise sequence of MI
commands that reproduce the issue you're seeing.

Thanks,
Andrew


      reply	other threads:[~2021-12-07 11:08 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-06 20:11 Simon Sobisch
2021-12-07 11:08 ` Andrew Burgess [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211207110833.GF123597@redhat.com \
    --to=aburgess@redhat.com \
    --cc=gdb@sourceware.org \
    --cc=simonsobisch@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).