unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Debugging M-x gdb
@ 2023-03-26 18:09 Manuel Giraud via Emacs development discussions.
  2023-03-26 18:23 ` Eli Zaretskii
  0 siblings, 1 reply; 8+ messages in thread
From: Manuel Giraud via Emacs development discussions. @ 2023-03-26 18:09 UTC (permalink / raw)
  To: emacs-devel

Hi,

I don't know if I should file a bug report for this so I'm trying here.

Whenever I try to debug Emacs with M-x gdb, I see the following
behaviour.  In the *gud-emacs* buffer, I enter "set args -Q" and then
"run"... then I exit the debugged Emacs and now the Emacs from where I
called (gdb) starts taking a full CPU.  I had to enter "quit" into the
*gud-emacs* buffer to stop this (return to normal CPU usage).

I'd really like to debug this issue but don't really where to start.  I
have tried to profile-start/profile-report but I don't get much clue out
of it.  How could I proceed?
-- 
Manuel Giraud



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

* Re: Debugging M-x gdb
  2023-03-26 18:09 Debugging M-x gdb Manuel Giraud via Emacs development discussions.
@ 2023-03-26 18:23 ` Eli Zaretskii
  2023-03-31  8:09   ` Manuel Giraud via Emacs development discussions.
  0 siblings, 1 reply; 8+ messages in thread
From: Eli Zaretskii @ 2023-03-26 18:23 UTC (permalink / raw)
  To: Manuel Giraud; +Cc: emacs-devel

> Date: Sun, 26 Mar 2023 20:09:31 +0200
> From:  Manuel Giraud via "Emacs development discussions." <emacs-devel@gnu.org>
> I don't know if I should file a bug report for this so I'm trying here.
> 
> Whenever I try to debug Emacs with M-x gdb, I see the following
> behaviour.  In the *gud-emacs* buffer, I enter "set args -Q" and then
> "run"... then I exit the debugged Emacs and now the Emacs from where I
> called (gdb) starts taking a full CPU.  I had to enter "quit" into the
> *gud-emacs* buffer to stop this (return to normal CPU usage).
> 
> I'd really like to debug this issue but don't really where to start.  I
> have tried to profile-start/profile-report but I don't get much clue out
> of it.  How could I proceed?

Are you sure it's Emacs that consumes high CPU, and not GDB? what does
'top' or similar command says about which process consumes CPU?

If it's indeed Emacs, then when Emacs starts consuming high CPU,
attach GDB to it, then type this:

  (gdb) source /path/to/emacs/src/.gdbinit
  (gdb) thread apply all bt

and post everything this produces with a bug report sent via
report-emacs-bug.

Thanks.

P.S. In which Emacs version does that happen, and with which version
of GDB?



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

* Re: Debugging M-x gdb
  2023-03-26 18:23 ` Eli Zaretskii
@ 2023-03-31  8:09   ` Manuel Giraud via Emacs development discussions.
  2023-03-31 10:55     ` Eli Zaretskii
  0 siblings, 1 reply; 8+ messages in thread
From: Manuel Giraud via Emacs development discussions. @ 2023-03-31  8:09 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel

Eli Zaretskii <eliz@gnu.org> writes:

>> Date: Sun, 26 Mar 2023 20:09:31 +0200
>> From:  Manuel Giraud via "Emacs development discussions." <emacs-devel@gnu.org>
>> I don't know if I should file a bug report for this so I'm trying here.
>> 
>> Whenever I try to debug Emacs with M-x gdb, I see the following
>> behaviour.  In the *gud-emacs* buffer, I enter "set args -Q" and then
>> "run"... then I exit the debugged Emacs and now the Emacs from where I
>> called (gdb) starts taking a full CPU.  I had to enter "quit" into the
>> *gud-emacs* buffer to stop this (return to normal CPU usage).
>> 
>> I'd really like to debug this issue but don't really where to start.  I
>> have tried to profile-start/profile-report but I don't get much clue out
>> of it.  How could I proceed?
>
> Are you sure it's Emacs that consumes high CPU, and not GDB? what does
> 'top' or similar command says about which process consumes CPU?

Hi Eli,

I finally had time to test this.  So yes, it is the emacs process (I
looked with M-x proced) that takes up to 95% of one CPU.

> If it's indeed Emacs, then when Emacs starts consuming high CPU,
> attach GDB to it, then type this:
>
>   (gdb) source /path/to/emacs/src/.gdbinit
>   (gdb) thread apply all bt

I've tried this recipe (all Emacs with -Q) but "thread apply all bt"
does not produce any output.

> and post everything this produces with a bug report sent via
> report-emacs-bug.
>
> Thanks.
>
> P.S. In which Emacs version does that happen, and with which version
> of GDB?

I've just tested it with a the main branch head for Emacs and GDB is
version 9.2.

Thanks.
-- 
Manuel Giraud



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

* Re: Debugging M-x gdb
  2023-03-31  8:09   ` Manuel Giraud via Emacs development discussions.
@ 2023-03-31 10:55     ` Eli Zaretskii
  2023-03-31 13:58       ` Manuel Giraud via Emacs development discussions.
  0 siblings, 1 reply; 8+ messages in thread
From: Eli Zaretskii @ 2023-03-31 10:55 UTC (permalink / raw)
  To: Manuel Giraud; +Cc: emacs-devel

> From: Manuel Giraud <manuel@ledu-giraud.fr>
> Cc: emacs-devel@gnu.org
> Date: Fri, 31 Mar 2023 10:09:39 +0200
> 
> > If it's indeed Emacs, then when Emacs starts consuming high CPU,
> > attach GDB to it, then type this:
> >
> >   (gdb) source /path/to/emacs/src/.gdbinit
> >   (gdb) thread apply all bt
> 
> I've tried this recipe (all Emacs with -Q) but "thread apply all bt"
> does not produce any output.

Doesn't produce any output after attaching GDB to the Emacs process
which consumes CPU?  That's not possible.  Please show all the
commands you did, starting from invoking Emacs that will later consume
CPU, including commands inside Emacs and outside it.

Note that the GDB you attach to Emacs should be a new GDB process, not
the one you ran inside Emacs.



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

* Re: Debugging M-x gdb
  2023-03-31 10:55     ` Eli Zaretskii
@ 2023-03-31 13:58       ` Manuel Giraud via Emacs development discussions.
  2023-03-31 14:28         ` Eli Zaretskii
  0 siblings, 1 reply; 8+ messages in thread
From: Manuel Giraud via Emacs development discussions. @ 2023-03-31 13:58 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel

Eli Zaretskii <eliz@gnu.org> writes:

[...]

> Doesn't produce any output after attaching GDB to the Emacs process
> which consumes CPU?  That's not possible.  Please show all the
> commands you did, starting from invoking Emacs that will later consume
> CPU, including commands inside Emacs and outside it.
>
> Note that the GDB you attach to Emacs should be a new GDB process, not
> the one you ran inside Emacs.

Disclaimer: I'm using OpenBSD.  'egdb' is the somewhat recent
version (9.2) from packages (there is an old bundled gdb but it does not
support -i=mi).  In the mean time, I've found that this shows with other
executables I would try to debug from Emacs: I'm usin xclock here.
'~/bin/emacs-debug' is Emacs compiled with the following options:

         CFLAGS="-O0 -g3" ./configure \
	 --bindir=$HOME/bin --program-suffix=-debug \
 	 --enable-checking="yes,glyphs" \
	 --enable-check-lisp-object-type

Here is my recipe:

* From a xterm:
       egdb ~/bin/emacs-debug
       (gdb) source ~/emacs-repo/src/.gdbinit
       (gdb) set args -Q
       (gdb) run

* Into this Emacs:

       M-x gdb
       Run gdb (like this): egdb -i=mi /usr/X11R6/bin/xclock
       Enable querying debuginfod servers for this session? (y or n) n
       M-x gdb-many-windows

* Into this Emacs *gud-xclock* buffer:
       (gdb) run    # then from another terminal: pkill xclock
       [Inferior 1 (process 76899) exited with code 01]

Now Emacs starts spinning the CPU.

* Into the first xterm with GDB:

       (gdb) thread apply all bt

... nothing (even after quitting the Emacs *gud-xclock* buffer and
that the CPU goes back to normal).
-- 
Manuel Giraud



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

* Re: Debugging M-x gdb
  2023-03-31 13:58       ` Manuel Giraud via Emacs development discussions.
@ 2023-03-31 14:28         ` Eli Zaretskii
  2023-03-31 17:25           ` Manuel Giraud via Emacs development discussions.
  0 siblings, 1 reply; 8+ messages in thread
From: Eli Zaretskii @ 2023-03-31 14:28 UTC (permalink / raw)
  To: Manuel Giraud; +Cc: emacs-devel

> From: Manuel Giraud <manuel@ledu-giraud.fr>
> Cc: emacs-devel@gnu.org
> Date: Fri, 31 Mar 2023 15:58:38 +0200
> 
> * From a xterm:
>        egdb ~/bin/emacs-debug
>        (gdb) source ~/emacs-repo/src/.gdbinit
>        (gdb) set args -Q
>        (gdb) run
> 
> * Into this Emacs:
> 
>        M-x gdb
>        Run gdb (like this): egdb -i=mi /usr/X11R6/bin/xclock
>        Enable querying debuginfod servers for this session? (y or n) n
>        M-x gdb-many-windows
> 
> * Into this Emacs *gud-xclock* buffer:
>        (gdb) run    # then from another terminal: pkill xclock
>        [Inferior 1 (process 76899) exited with code 01]
> 
> Now Emacs starts spinning the CPU.
> 
> * Into the first xterm with GDB:
> 
>        (gdb) thread apply all bt
> 
> ... nothing (even after quitting the Emacs *gud-xclock* buffer and
> that the CPU goes back to normal).

You didn't attach GDB to Emacs.  Instead, you started Emacs under GDB.

You should do it like this:

  * From exterm:

     $ ~/bin/emacs-debug &

  * From Emacs:

       M-x gdb
       Run gdb (like this): egdb -i=mi /usr/X11R6/bin/xclock
       Enable querying debuginfod servers for this session? (y or n) n
       M-x gdb-many-windows

  * Into this Emacs *gud-xclock* buffer:
       (gdb) run    # then from another terminal: pkill xclock
       [Inferior 1 (process 76899) exited with code 01]

Now Emacs starts spinning the CPU.

  * Into the first xterm:

     $ egdb -p PID

where PID is the process ID of the Emacs process that spins the CPU.
Then at the prompt of this GDB:

     (gdb) thread apply all bt



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

* Re: Debugging M-x gdb
  2023-03-31 14:28         ` Eli Zaretskii
@ 2023-03-31 17:25           ` Manuel Giraud via Emacs development discussions.
  2023-03-31 18:04             ` Eli Zaretskii
  0 siblings, 1 reply; 8+ messages in thread
From: Manuel Giraud via Emacs development discussions. @ 2023-03-31 17:25 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel

Eli Zaretskii <eliz@gnu.org> writes:

[...]

> You didn't attach GDB to Emacs.  Instead, you started Emacs under GDB.

Ok I tried this but hit another road block:
ptrace: Operation not permitted.

If I'm doing all this a root, the "thread apply all bt" returns "Cannot
access memory" errors.  I think I can give up now :(
-- 
Manuel Giraud



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

* Re: Debugging M-x gdb
  2023-03-31 17:25           ` Manuel Giraud via Emacs development discussions.
@ 2023-03-31 18:04             ` Eli Zaretskii
  0 siblings, 0 replies; 8+ messages in thread
From: Eli Zaretskii @ 2023-03-31 18:04 UTC (permalink / raw)
  To: Manuel Giraud; +Cc: emacs-devel

> From: Manuel Giraud <manuel@ledu-giraud.fr>
> Cc: emacs-devel@gnu.org
> Date: Fri, 31 Mar 2023 19:25:05 +0200
> 
> Eli Zaretskii <eliz@gnu.org> writes:
> 
> [...]
> 
> > You didn't attach GDB to Emacs.  Instead, you started Emacs under GDB.
> 
> Ok I tried this but hit another road block:
> ptrace: Operation not permitted.

Sigh...  You can still try to get the information with your original
steps (where I said you didn't attach GDB), if you first interrupt
Emacs from GDB.  How to do that is described in etc/DEBUG, under
"Getting control to the debugger", where it describes the "handle
SIGINT" technique.



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

end of thread, other threads:[~2023-03-31 18:04 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-26 18:09 Debugging M-x gdb Manuel Giraud via Emacs development discussions.
2023-03-26 18:23 ` Eli Zaretskii
2023-03-31  8:09   ` Manuel Giraud via Emacs development discussions.
2023-03-31 10:55     ` Eli Zaretskii
2023-03-31 13:58       ` Manuel Giraud via Emacs development discussions.
2023-03-31 14:28         ` Eli Zaretskii
2023-03-31 17:25           ` Manuel Giraud via Emacs development discussions.
2023-03-31 18:04             ` Eli Zaretskii

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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).