From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Gerd =?UTF-8?Q?M=C3=B6llmann?= Newsgroups: gmane.emacs.bugs Subject: bug#66575: [PATCH] Gud lldb support Date: Mon, 16 Oct 2023 16:09:38 +0200 Message-ID: References: <7A4E9221-C0A4-4A98-A80A-5FD58C95C014@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="15122"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 66575@debbugs.gnu.org To: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Oct 16 16:10:54 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qsOJ3-0003oE-Dp for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 16 Oct 2023 16:10:53 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qsOIp-0002SY-6c; Mon, 16 Oct 2023 10:10:39 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qsOIn-0002SG-66 for bug-gnu-emacs@gnu.org; Mon, 16 Oct 2023 10:10:37 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qsOIm-0001GZ-Te for bug-gnu-emacs@gnu.org; Mon, 16 Oct 2023 10:10:36 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qsOJB-0003AM-MX for bug-gnu-emacs@gnu.org; Mon, 16 Oct 2023 10:11:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Gerd =?UTF-8?Q?M=C3=B6llmann?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 16 Oct 2023 14:11:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 66575 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 66575-submit@debbugs.gnu.org id=B66575.169746541412102 (code B ref 66575); Mon, 16 Oct 2023 14:11:01 +0000 Original-Received: (at 66575) by debbugs.gnu.org; 16 Oct 2023 14:10:14 +0000 Original-Received: from localhost ([127.0.0.1]:57465 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qsOIP-000398-Uw for submit@debbugs.gnu.org; Mon, 16 Oct 2023 10:10:14 -0400 Original-Received: from mail-ej1-x636.google.com ([2a00:1450:4864:20::636]:58824) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qsOIN-00038t-Vw for 66575@debbugs.gnu.org; Mon, 16 Oct 2023 10:10:12 -0400 Original-Received: by mail-ej1-x636.google.com with SMTP id a640c23a62f3a-99c3c8adb27so715123766b.1 for <66575@debbugs.gnu.org>; Mon, 16 Oct 2023 07:09:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697465380; x=1698070180; darn=debbugs.gnu.org; h=mime-version:user-agent:message-id:date:references:in-reply-to :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=tUl7k4tNz2d4S/iELzuKp0YXHlYwDyk+YvlOnf9bwOo=; b=HBtX97y++KQDcSWjGXUkeU+sFah7jkahaqnZ3FnFhm//tAZcWA1Juslyhd8jA+1jPK Aa6QlgnMWGwapTJPUcgYYCgcpTVZwp4wsvvUnygVojo4Vux08Rs2vRxo2WopnrPk8VZ/ jmFD85PDDibaRRDSBn+Y7LXfZokvMBiZfa2nTIni7GQVgptAKoyZSBiFnZ4RJi3+cPzZ bjTqtYoOALbS5xWZR/2e0bBJF59qZz1f9SMDhvrjhiJzTw4TNrMVHCBi8ZZqRxwhIlvs Ub1su0nwTk3CPSvmUONBAa7N+M3Jok9AyYE2YtMp//rzUV7xtWE7wrbwRPvNzrKzRR4s 4dMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697465380; x=1698070180; h=mime-version:user-agent:message-id:date:references:in-reply-to :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=tUl7k4tNz2d4S/iELzuKp0YXHlYwDyk+YvlOnf9bwOo=; b=YLV5jjM08bCnrgR997enmoP8wB63lP/U92NcZKtsiOqRmtIC/QjJTrkI88FeuU2san uQe0ASgscRDd0wdfFjaZcXnk3Hulg7orvMnmzowCKRF6E5WU8wslSOJKtg1nmVa6e8DP /qCEwJlWPnNADXNobDaiwGUMrb41tMXnMoZHVtzBmYKXYCwA4SOujJ8UAsgM67XHcAhM M+mnz6qkLX3XnKwLI5Mfql2O5JSZxmgegFNVPwxtrEBOOEz43f//Z1LLLnN2bFxU+Rbd mlQNqNf3oSJRineZ1rJ/MbufrWapCGpOODq36e9rmr/56Ain+DIzjQSqiDZSEbyCKCHo 3xgw== X-Gm-Message-State: AOJu0Yz8gjWZHvMY2Q0Cq7yfyM0mKPC806Pec0qtSqwQEgZlfHlBW3qH l8xtKFewe2uLPa8cpuv3bCCJbvC4YUE= X-Google-Smtp-Source: AGHT+IGOLASTKt5Ik0Ucpz/B45rhTy1NfhTbR8yh4Zn3i6ZR4FN8gM9EtfhqS3jzYm6s1YQcb+rY2w== X-Received: by 2002:a17:907:7d92:b0:9be:946d:bd43 with SMTP id oz18-20020a1709077d9200b009be946dbd43mr6000011ejc.0.1697465380053; Mon, 16 Oct 2023 07:09:40 -0700 (PDT) Original-Received: from Mini.fritz.box (p4fe3a7d3.dip0.t-ipconnect.de. [79.227.167.211]) by smtp.gmail.com with ESMTPSA id t18-20020a1709063e5200b009a0955a7ad0sm4115112eji.128.2023.10.16.07.09.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 07:09:39 -0700 (PDT) In-Reply-To: <7A4E9221-C0A4-4A98-A80A-5FD58C95C014@gmail.com> ("Mattias =?UTF-8?Q?Engdeg=C3=A5rd?="'s message of "Mon, 16 Oct 2023 15:30:23 +0200") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:272572 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Mattias Engdeg=C3=A5rd writes: >> No MI support, because lldb-mi is no longer part of LLVM. > > So what is the currently blessed way to communicate with LLDB? Don't really know, I'm afraid. > I only have comments about trivialities here; someone else should deal > with the serious stuff. > >> +(eval-when-compile (require 'rx)) > > There is usually no need to import rx explicitly. The necessary macros > and functions are autoloaded. > >> +;; because gud-symbol uses their values if they are present. Tehir >> +;; names are deducded from the minor-mode name. > > 'Their', 'deduced'. > >> + ;; frame #0: ...) at emacs.c:1310:9 [opt] >> + (string-match (rx (and line-start (0+ blank) "frame" >> + (0+ not-newline) " at " >> + (group (1+ (not (any ":")))) >> + ":" > > > (You can write (not ":") instead of (not (any ":")) if you like.) Both Fixed in the attached patch. I also found another spelling error in an option passed to 'breakpoint set -joint...'. > If th=C3=B1e file name can have an absolute directory part, then it may r= un > into trouble on Windows (C:\Some\Dir\File.c). I guess I'll leave that as an exercise for someone having Windows :-). > > Sad that we throw away the column number here, but perhaps that's just > a limitation of gud.el. Indeed. > > Anyway, a big step up from not having any support at all. Thank you! =F0=9F=91=8D > > Would you include a NEWS entry as well? When I get this into master, yes of course. I'm not yet convinced of that :-). --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Gud-lldb-support.patch Content-Description: patch version 2 >From 8cbbe82f715876a26736f1380908b0ebb3356f19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gerd=20M=C3=B6llmann?= Date: Mon, 16 Oct 2023 13:54:02 +0200 Subject: [PATCH] Gud lldb support * lisp/progmodes/gud.el (lldb): New function. --- lisp/progmodes/gud.el | 142 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 142 insertions(+) diff --git a/lisp/progmodes/gud.el b/lisp/progmodes/gud.el index d4b954a7203..cff2d7034e4 100644 --- a/lisp/progmodes/gud.el +++ b/lisp/progmodes/gud.el @@ -973,6 +973,7 @@ gud-gdb-fetch-lines-filter (setq gud-gdb-fetch-lines-string string) ""))) + ;; gdb speedbar functions ;; Part of the macro expansion of dframe-with-attached-buffer. @@ -3840,6 +3841,147 @@ gud-tooltip-tips (gud-basic-call cmd)) expr)))))))) + +;; 'gud-lldb-history' and 'gud-gud-lldb-command-name' are required +;; because gud-symbol uses their values if they are present. Their +;; names are deduced from the minor-mode name. +(defvar gud-lldb-history nil) + +(defcustom gud-gud-lldb-command-name "lldb" + "Default command to run an executable under LLDB in text command mode." + :type 'string) + +(defun gud-lldb-marker-filter (string) + "Deduce interesting stuff from output STRING." + (cond (;; Process 72668 stopped + ;; * thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1 + ;; frame #0: ...) at emacs.c:1310:9 [opt] + (string-match (rx (and line-start (0+ blank) "frame" + (0+ not-newline) " at " + (group (1+ (not ":"))) + ":" + (group (1+ digit)))) + string) + (setq gud-last-frame + (cons (match-string 1 string) + (string-to-number (match-string 2 string))))) + (;; Process 72874 exited with status = 9 (0x00000009) killed + (string-match (rx "Process " (1+ digit) " exited with status") + string) + (setq gud-last-last-frame nil) + (setq gud-overlay-arrow-position nil))) + string) + +;;;###autoload +(defun lldb (command-line) + "Run lldb passing it COMMAND-LINE as arguments. +If COMMAND-LINE names a program FILE to debug, lldb will run in +a buffer named *gud-FILE*, and the directory containing FILE +becomes the initial working directory and source-file directory +for your debugger. If you don't want `default-directory' to +change to the directory of FILE, specify FILE without leading +directories, in which case FILE should reside either in the +directory of the buffer from which this command is invoked, or +it can be found by searching PATH. + +If COMMAND-LINE requests that lldb attaches to a process PID, lldb +will run in *gud-PID*, otherwise it will run in *gud*; in these +cases the initial working directory is the `default-directory' of +the buffer in which this command was invoked." + (interactive (list (gud-query-cmdline 'lldb))) + + (when (and gud-comint-buffer + (buffer-name gud-comint-buffer) + (get-buffer-process gud-comint-buffer) + (with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gud-lldb))) + (gdb-restore-windows) + ;; FIXME: Copied from gud-gdb, but what does that even say? + (error "Multiple debugging requires restarting in text command mode")) + + (gud-common-init command-line nil 'gud-lldb-marker-filter) + (setq-local gud-minor-mode 'lldb) + + (gud-def gud-break + "breakpoint set --joint-specifier %f:%l" + "\C-b" + "Set breakpoint at current line.") + (gud-def gud-tbreak + "_regexp-break %f:%l" + "\C-t" + "Set temporary breakpoint at current line.") + (gud-def gud-remove + "breakpoint clear --line %l --file %f" + "\C-d" + "Remove breakpoint at current line") + (gud-def gud-step "thread step-in --count %p" + "\C-s" + "Step one source line with display.") + (gud-def gud-stepi + "thread step-inst --count %p" + "\C-i" + "Step one instruction with display.") + (gud-def gud-next + "thread step-over --count %p" + "\C-n" + "Step one line (skip functions).") + (gud-def gud-nexti + "thread step-inst-over --count %p" + nil + "Step one instruction (skip functions).") + (gud-def gud-cont + "process continue --ignore-count %p" + "\C-r" + "Continue with display.") + (gud-def gud-finish + "thread step-out" + "\C-f" + "Finish executing current function.") + (gud-def gud-jump + (progn + (gud-call "_regexp-break %f:%l" arg) + (gud-call "_regexp-jump %f:%l")) + "\C-j" + "Set execution address to current line.") + (gud-def gud-up + "_regexp-up up %p" + "<" + "Up N stack frames (numeric arg).") + (gud-def gud-down + "_regexp-down %p" + ">" + "Down N stack frames (numeric arg).") + (gud-def gud-print + "dwim-print %e" + "\C-p" + "Evaluate C expression at point.") + (gud-def gud-pstar + "dwim-print *%e" + nil + "Evaluate C dereferenced pointer expression at point.") + + ;; For debugging Emacs only. + (gud-def gud-pv + "xprint %e" + "\C-v" + "Print the value of the lisp variable.") + + (gud-def gud-until + "thread until %l" + "\C-u" + "Continue to current line.") + (gud-def gud-run + ;; Extension for process launch --tty? + "process launch -X true" + nil + "Run the program.") + + (gud-set-repeat-map-property 'gud-gdb-repeat-map) + (setq comint-prompt-regexp "^(lldb) *") + (setq paragraph-start comint-prompt-regexp) + (setq gud-running nil) + (setq gud-filter-pending-text nil) + (run-hooks 'gud-lldb-mode-hook)) + (provide 'gud) ;;; gud.el ends here -- 2.42.0 --=-=-=--