GNU bug report logs - #56495
29.0.50; Support for debugging Emacs with LLDB

Previous Next

Package: emacs;

Reported by: Gerd Möllmann <gerd.moellmann <at> gmail.com>

Date: Mon, 11 Jul 2022 08:14:02 UTC

Severity: wishlist

Tags: patch

Found in version 29.0.50

Fixed in version 29.1

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 56495 in the body.
You can then email your comments to 56495 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#56495; Package emacs. (Mon, 11 Jul 2022 08:14:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Gerd Möllmann <gerd.moellmann <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Mon, 11 Jul 2022 08:14:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Gerd Möllmann <gerd.moellmann <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 29.0.50; Support for debugging Emacs with LLDB
Date: Mon, 11 Jul 2022 10:13:35 +0200
[Message part 1 (text/plain, inline)]
My system, macOS with Apple M1 chip, is currently not supported by GDB.
To quote gdb-devel, "lldb is the way to go" to debug Emacs for me.

Attached patch adds rather limited support for that.  Limited by

- the fact that I don't know LLDB,
- that I don't know LLDB's Python API,
- that I'm not a Python programmer,
- that the Python API documentation is pretty lacking in itself,
- that I didn't implement support for ENABLE_CHECKING and what else
  might change Lisp_Object layout

So please bear with me.

Anyway, at least displaying some Lisp_Objects with 'p obj' seems to
work, and 'xbacktrace' seems to be working.

YMMV.

[0001-Support-for-debugging-Emacs-with-LLDB.patch (application/octet-stream, attachment)]
[signature.asc (application/pgp-signature, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#56495; Package emacs. (Mon, 11 Jul 2022 09:19:01 GMT) Full text and rfc822 format available.

Message #8 received at 56495 <at> debbugs.gnu.org (full text, mbox):

From: Robert Pluim <rpluim <at> gmail.com>
To: Gerd Möllmann <gerd.moellmann <at> gmail.com>
Cc: 56495 <at> debbugs.gnu.org
Subject: Re: bug#56495: 29.0.50; Support for debugging Emacs with LLDB
Date: Mon, 11 Jul 2022 11:18:23 +0200
>>>>> On Mon, 11 Jul 2022 10:13:35 +0200, Gerd Möllmann <gerd.moellmann <at> gmail.com> said:

    Gerd> My system, macOS with Apple M1 chip, is currently not supported by GDB.
    Gerd> To quote gdb-devel, "lldb is the way to go" to debug Emacs for me.

    Gerd> Attached patch adds rather limited support for that.  Limited by

    Gerd> - the fact that I don't know LLDB,
    Gerd> - that I don't know LLDB's Python API,
    Gerd> - that I'm not a Python programmer,
    Gerd> - that the Python API documentation is pretty lacking in itself,
    Gerd> - that I didn't implement support for ENABLE_CHECKING and what else
    Gerd>   might change Lisp_Object layout

    Gerd> So please bear with me.

Itʼs better than what we have now, so thanks

    Gerd> Anyway, at least displaying some Lisp_Objects with 'p obj' seems to
    Gerd> work, and 'xbacktrace' seems to be working.

    Gerd> YMMV.

Iʼve got:
    lldb -v
    lldb-1300.0.42.3
    Swift version 5.5.2-dev

(this is an Intel macbook, not an M1)

Iʼm getting this:

    lldb emacs
    error: unknown or ambiguous option
    error: unknown or ambiguous option
    Emacs debugging support has been installed.
    (lldb) target create "emacs"
    Current executable set to ʼ/Users/rpluim/repos/emacs/src/emacsʼ
    (x86_64).

which I can fix by doing this:

diff --git a/etc/emacs_lldb.py b/etc/emacs_lldb.py
index 3a9f17e020..ebf14d44c2 100644
--- a/etc/emacs_lldb.py
+++ b/etc/emacs_lldb.py
@@ -144,7 +144,6 @@ def define_command (debugger, function):
     lldb_command = function.__name__
          python_function = __name__ + "." + function.__name__
               debugger.HandleCommand(f"command script add "
-                           f"--overwrite "
                            f"--function {python_function} "
                            f"{lldb_command}")

Robert
-- 




Added tag(s) patch. Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Mon, 11 Jul 2022 09:51:01 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#56495; Package emacs. (Mon, 11 Jul 2022 10:43:02 GMT) Full text and rfc822 format available.

Message #13 received at 56495 <at> debbugs.gnu.org (full text, mbox):

From: Gerd Möllmann <gerd.moellmann <at> gmail.com>
To: Robert Pluim <rpluim <at> gmail.com>
Cc: 56495 <at> debbugs.gnu.org
Subject: Re: bug#56495: 29.0.50; Support for debugging Emacs with LLDB
Date: Mon, 11 Jul 2022 12:42:04 +0200
[Message part 1 (text/plain, inline)]

> On 2022-07-11,, at 11:18 , Robert Pluim <rpluim <at> gmail.com> wrote:
> 
>>>>>> On Mon, 11 Jul 2022 10:13:35 +0200, Gerd Möllmann <gerd.moellmann <at> gmail.com> said:
> Iʼve got:
>    lldb -v
>    lldb-1300.0.42.3
>    Swift version 5.5.2-dev

Thanks.

Looks like Apple's LLDB from the Xcode command-line tools.

Mine says "lldb version 14.0.6", and comes from "brew install llvm".  (Which I need for 'llvm-vscode', which I need for 'dap-mode', which I need for debugging with LLDB inside of Emacs, which is because of <known long story here>, and <another, shorter story here>).

I need '--overwrite' because it allows me to reload the code in a running LLDB.  Apple's LLDB seems to '--overwrite' by default, while mine gives an error:

  cannot add command: user command exists and force replace not set

\o/

Maybe I can somehow pythonese if '--overwrite' is supported or not.


> (this is an Intel macbook, not an M1)
> 
> Iʼm getting this:
> 
>    lldb emacs
>    error: unknown or ambiguous option
>    error: unknown or ambiguous option
>    Emacs debugging support has been installed.
>    (lldb) target create "emacs"
>    Current executable set to ʼ/Users/rpluim/repos/emacs/src/emacsʼ
>    (x86_64).
> 
> which I can fix by doing this:
> 
> diff --git a/etc/emacs_lldb.py b/etc/emacs_lldb.py
> index 3a9f17e020..ebf14d44c2 100644
> --- a/etc/emacs_lldb.py
> +++ b/etc/emacs_lldb.py
> @@ -144,7 +144,6 @@ def define_command (debugger, function):
>     lldb_command = function.__name__
>          python_function = __name__ + "." + function.__name__
>               debugger.HandleCommand(f"command script add "
> -                           f"--overwrite "
>                            f"--function {python_function} "
>                            f"{lldb_command}")
> 
> Robert
> --

[Message part 2 (text/html, inline)]
[signature.asc (application/pgp-signature, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#56495; Package emacs. (Mon, 11 Jul 2022 10:57:01 GMT) Full text and rfc822 format available.

Message #16 received at 56495 <at> debbugs.gnu.org (full text, mbox):

From: Robert Pluim <rpluim <at> gmail.com>
To: Gerd Möllmann <gerd.moellmann <at> gmail.com>
Cc: 56495 <at> debbugs.gnu.org
Subject: Re: bug#56495: 29.0.50; Support for debugging Emacs with LLDB
Date: Mon, 11 Jul 2022 12:56:35 +0200
>>>>> On Mon, 11 Jul 2022 12:42:04 +0200, Gerd Möllmann <gerd.moellmann <at> gmail.com> said:

    >> On 2022-07-11,, at 11:18 , Robert Pluim <rpluim <at> gmail.com> wrote:
    >> 
    >>>>>>> On Mon, 11 Jul 2022 10:13:35 +0200, Gerd Möllmann <gerd.moellmann <at> gmail.com> said:
    >> Iʼve got:
    >> lldb -v
    >> lldb-1300.0.42.3
    >> Swift version 5.5.2-dev

    Gerd> Thanks.

    Gerd> Looks like Apple's LLDB from the Xcode command-line tools.

    Gerd> Mine says "lldb version 14.0.6", and comes from "brew install llvm".
    Gerd> (Which I need for 'llvm-vscode', which I need for 'dap-mode', which I
    Gerd> need for debugging with LLDB inside of Emacs, which is because of
    Gerd> <known long story here>, and <another, shorter story here>).

I have lldb 13.0.1 from llvm here as well, but it gives me the same
error.

    Gerd> I need '--overwrite' because it allows me to reload the code in a
    Gerd> running LLDB.  Apple's LLDB seems to '--overwrite' by default, while
    Gerd> mine gives an error:

    Gerd>   cannot add command: user command exists and force replace not set

But if I 'command script import emacs_lldb' in my llvm lldb, I get no
errors. Maybe itʼs a version 14 thing.

    Gerd> \o/

🤷 indeed

    Gerd> Maybe I can somehow pythonese if '--overwrite' is supported or not.

I donʼt think itʼs a big deal, and lldb version dependent checks will
invariably be out of date. Maybe just stick in a comment?

Robert
-- 




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#56495; Package emacs. (Mon, 11 Jul 2022 11:21:02 GMT) Full text and rfc822 format available.

Message #19 received at 56495 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Gerd Möllmann <gerd.moellmann <at> gmail.com>
Cc: 56495 <at> debbugs.gnu.org
Subject: Re: bug#56495: 29.0.50; Support for debugging Emacs with LLDB
Date: Mon, 11 Jul 2022 14:19:56 +0300
> From: Gerd Möllmann <gerd.moellmann <at> gmail.com>
> Date: Mon, 11 Jul 2022 10:13:35 +0200
> 
> Attached patch adds rather limited support for that.  Limited by
> 
> - the fact that I don't know LLDB,
> - that I don't know LLDB's Python API,
> - that I'm not a Python programmer,
> - that the Python API documentation is pretty lacking in itself,
> - that I didn't implement support for ENABLE_CHECKING and what else
>   might change Lisp_Object layout
> 
> So please bear with me.
> 
> Anyway, at least displaying some Lisp_Objects with 'p obj' seems to
> work, and 'xbacktrace' seems to be working.

Thanks.  Feel free to install when you think this is ready.

Maybe also add a few words in etc/DEBUG about this.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#56495; Package emacs. (Mon, 11 Jul 2022 11:28:01 GMT) Full text and rfc822 format available.

Message #22 received at 56495 <at> debbugs.gnu.org (full text, mbox):

From: Gerd Möllmann <gerd.moellmann <at> gmail.com>
To: Robert Pluim <rpluim <at> gmail.com>
Cc: 56495 <at> debbugs.gnu.org
Subject: Re: bug#56495: 29.0.50; Support for debugging Emacs with LLDB
Date: Mon, 11 Jul 2022 13:27:22 +0200
[Message part 1 (text/plain, inline)]

> On 2022-07-11,, at 12:56 , Robert Pluim <rpluim <at> gmail.com> wrote:
> 
> But if I 'command script import emacs_lldb' in my llvm lldb, I get no
> errors. Maybe itʼs a version 14 thing.

Looks like it is.

> I donʼt think itʼs a big deal, and lldb version dependent checks will
> invariably be out of date. Maybe just stick in a comment?

This seems to work for me with Apple's LLDB and the one from LLVM:

def define_command (debugger, function):
    lldb_command = function.__name__
    python_function = __name__ + "." + function.__name__
    interpreter = debugger.GetCommandInterpreter()
    def define(overwrite):
        res = lldb.SBCommandReturnObject()
        interpreter.HandleCommand(f"command script add "
                                  f"{overwrite} "
                                  f"--function {python_function} "
                                  f"{lldb_command}",
                                  res)
        return res.Succeeded()
    if not define("--overwrite"):
        define("")

Could you please try it with your LLDBs?

It relies on runtime-availability of the '--overwrite', only.

[signature.asc (application/pgp-signature, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#56495; Package emacs. (Mon, 11 Jul 2022 11:33:02 GMT) Full text and rfc822 format available.

Message #25 received at 56495 <at> debbugs.gnu.org (full text, mbox):

From: Gerd Möllmann <gerd.moellmann <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 56495 <at> debbugs.gnu.org
Subject: Re: bug#56495: 29.0.50; Support for debugging Emacs with LLDB
Date: Mon, 11 Jul 2022 13:31:56 +0200
[Message part 1 (text/plain, inline)]
> On 2022-07-11,, at 13:19 , Eli Zaretskii <eliz <at> gnu.org> wrote:
> Thanks.  Feel free to install when you think this is ready.
> 
> Maybe also add a few words in etc/DEBUG about this.

Thanks, will do.

[signature.asc (application/pgp-signature, attachment)]

Severity set to 'wishlist' from 'normal' Request was from Stefan Kangas <stefan <at> marxist.se> to control <at> debbugs.gnu.org. (Mon, 11 Jul 2022 12:10:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#56495; Package emacs. (Mon, 11 Jul 2022 12:29:02 GMT) Full text and rfc822 format available.

Message #30 received at 56495 <at> debbugs.gnu.org (full text, mbox):

From: Robert Pluim <rpluim <at> gmail.com>
To: Gerd Möllmann <gerd.moellmann <at> gmail.com>
Cc: 56495 <at> debbugs.gnu.org
Subject: Re: bug#56495: 29.0.50; Support for debugging Emacs with LLDB
Date: Mon, 11 Jul 2022 14:28:15 +0200
>>>>> On Mon, 11 Jul 2022 13:27:22 +0200, Gerd Möllmann <gerd.moellmann <at> gmail.com> said:

    Gerd> Could you please try it with your LLDBs?

Works for me on the Apple and llvm lldbs, thanks

Robert
-- 




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#56495; Package emacs. (Tue, 12 Jul 2022 03:05:03 GMT) Full text and rfc822 format available.

Message #33 received at 56495 <at> debbugs.gnu.org (full text, mbox):

From: Richard Stallman <rms <at> gnu.org>
To: Gerd Möllmann <gerd.moellmann <at> gmail.com>
Cc: 56495 <at> debbugs.gnu.org
Subject: Re: bug#56495: 29.0.50; Support for debugging Emacs with LLDB
Date: Mon, 11 Jul 2022 23:04:24 -0400
[[[ To any NSA and FBI agents reading my email: please consider    ]]]
[[[ whether defending the US Constitution against all enemies,     ]]]
[[[ foreign or domestic, requires you to follow Snowden's example. ]]]

I an unhappy with duplicating code in our sources for the sake of
supporting a competitor for GDB, that being for the sake of MacOS.
Duplicating code leads to extra maintenance work.

As I recall, GNU Emacs does not support MacOS anyway -- there is a
separate, modified version of Emacs for that.  This duplicate code
should go into that modified version.  The maintainers of that
version presumably think it is worth making an effort to
improve MacOS support -- so let them do the work.

-- 
Dr Richard Stallman (https://stallman.org)
Chief GNUisance of the GNU Project (https://gnu.org)
Founder, Free Software Foundation (https://fsf.org)
Internet Hall-of-Famer (https://internethalloffame.org)






Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#56495; Package emacs. (Tue, 12 Jul 2022 03:17:01 GMT) Full text and rfc822 format available.

Message #36 received at 56495 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Kangas <stefankangas <at> gmail.com>
To: rms <at> gnu.org,
 Gerd Möllmann <gerd.moellmann <at> gmail.com>
Cc: 56495 <at> debbugs.gnu.org
Subject: Re: bug#56495: 29.0.50; Support for debugging Emacs with LLDB
Date: Mon, 11 Jul 2022 22:15:55 -0500
Richard Stallman <rms <at> gnu.org> writes:

> As I recall, GNU Emacs does not support MacOS anyway

GNU Emacs supports "MacOS X 10.6 or newer" (etc/MACHINES).




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#56495; Package emacs. (Tue, 12 Jul 2022 08:05:02 GMT) Full text and rfc822 format available.

Message #39 received at 56495 <at> debbugs.gnu.org (full text, mbox):

From: Gerd Möllmann <gerd.moellmann <at> gmail.com>
To: rms <at> gnu.org
Cc: 56495 <at> debbugs.gnu.org
Subject: Re: bug#56495: 29.0.50; Support for debugging Emacs with LLDB
Date: Tue, 12 Jul 2022 10:04:11 +0200
[Message part 1 (text/plain, inline)]

> On 2022-07-12,, at 5:04 , Richard Stallman <rms <at> gnu.org> wrote:

> As I recall, GNU Emacs does not support MacOS anyway -- there is a
> separate, modified version of Emacs for that.  This duplicate code
> should go into that modified version.  The maintainers of that
> version presumably think it is worth making an effort to
> improve MacOS support -- so let them do the work.
> 

(As Stefan explained - macOS is supported. EFQ.  You probably think of Aquamacs, which AFAIU is a kind of fork of Emacs that started in the early 2000s.  I don't know much more about it.  They will be assimilated.)

I'd also rather use GDB because of Emacs' .gdbinit.  The problem is GDB: it supports macOS on amd64, but not on arm64 (patches welcome, says gdb-devel), and arm64 is what I have.

So, for now, I've added 'xbacktrace' and 'pr' (safe_debug_print()) for LLDB. Both could be useful for people investigating bugs, I think, as a bare minimum.

For anyone listening and interested:

I've looked at the GDB sources for the first time today.  GDB supports arm64 on other platforms, and it supports macOS with amd64, so it might not be too hard to add something for someone who knows what he is doing.  So far, I'm not that someone, and I don't want to spend a ton of time on programming anyway these days, so I won't promise to do anything.

[signature.asc (application/pgp-signature, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#56495; Package emacs. (Thu, 14 Jul 2022 03:11:02 GMT) Full text and rfc822 format available.

Message #42 received at 56495 <at> debbugs.gnu.org (full text, mbox):

From: Richard Stallman <rms <at> gnu.org>
To: Stefan Kangas <stefankangas <at> gmail.com>
Cc: gerd.moellmann <at> gmail.com, 56495 <at> debbugs.gnu.org
Subject: Re: bug#56495: 29.0.50; Support for debugging Emacs with LLDB
Date: Wed, 13 Jul 2022 23:10:36 -0400
[[[ To any NSA and FBI agents reading my email: please consider    ]]]
[[[ whether defending the US Constitution against all enemies,     ]]]
[[[ foreign or domestic, requires you to follow Snowden's example. ]]]

  > GNU Emacs supports "MacOS X 10.6 or newer" (etc/MACHINES).

I stand corrected.  Thanks.

-- 
Dr Richard Stallman (https://stallman.org)
Chief GNUisance of the GNU Project (https://gnu.org)
Founder, Free Software Foundation (https://fsf.org)
Internet Hall-of-Famer (https://internethalloffame.org)






Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#56495; Package emacs. (Mon, 05 Sep 2022 19:17:02 GMT) Full text and rfc822 format available.

Message #45 received at 56495 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Robert Pluim <rpluim <at> gmail.com>
Cc: Gerd Möllmann <gerd.moellmann <at> gmail.com>,
 56495 <at> debbugs.gnu.org
Subject: Re: bug#56495: 29.0.50; Support for debugging Emacs with LLDB
Date: Mon, 05 Sep 2022 21:16:49 +0200
Robert Pluim <rpluim <at> gmail.com> writes:

>     Gerd> Could you please try it with your LLDBs?
>
> Works for me on the Apple and llvm lldbs, thanks

This was two months ago, and it looks like this was added at the time:

commit 7af425f87bf9866c60ac134cbb6aa9eb0c61f8af
Author:     Gerd Möllmann <gerd <at> gnu.org>
AuthorDate: Sun Jul 10 13:35:32 2022 +0200

    Support for debugging Emacs with LLDB

So I'm closing this bug report now.




bug marked as fixed in version 29.1, send any further explanations to 56495 <at> debbugs.gnu.org and Gerd Möllmann <gerd.moellmann <at> gmail.com> Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Mon, 05 Sep 2022 19:18:01 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Tue, 04 Oct 2022 11:24:10 GMT) Full text and rfc822 format available.

This bug report was last modified 1 year and 198 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.