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 14:00:07 +0200 Message-ID: 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="40144"; mail-complaints-to="usenet@ciao.gmane.io" To: 66575@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Oct 16 14:01:18 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 1qsMHc-000A9j-Rr for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 16 Oct 2023 14:01:16 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qsMH7-0007YM-38; Mon, 16 Oct 2023 08:00:45 -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 1qsMH0-0007Uf-IZ for bug-gnu-emacs@gnu.org; Mon, 16 Oct 2023 08:00:40 -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 1qsMH0-0006Uv-7S for bug-gnu-emacs@gnu.org; Mon, 16 Oct 2023 08:00:38 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qsMHO-0006vU-Kv for bug-gnu-emacs@gnu.org; Mon, 16 Oct 2023 08:01:02 -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 12:01:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 66575 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.169745765526599 (code B ref -1); Mon, 16 Oct 2023 12:01:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 16 Oct 2023 12:00:55 +0000 Original-Received: from localhost ([127.0.0.1]:55411 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qsMHH-0006uw-8I for submit@debbugs.gnu.org; Mon, 16 Oct 2023 08:00:55 -0400 Original-Received: from lists.gnu.org ([2001:470:142::17]:53606) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qsMHD-0006ua-1p for submit@debbugs.gnu.org; Mon, 16 Oct 2023 08:00:54 -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 1qsMGd-0007Rb-4w for bug-gnu-emacs@gnu.org; Mon, 16 Oct 2023 08:00:17 -0400 Original-Received: from mail-ej1-x62d.google.com ([2a00:1450:4864:20::62d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qsMGb-0006JR-4G for bug-gnu-emacs@gnu.org; Mon, 16 Oct 2023 08:00:14 -0400 Original-Received: by mail-ej1-x62d.google.com with SMTP id a640c23a62f3a-9ada2e6e75fso775741966b.2 for ; Mon, 16 Oct 2023 05:00:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697457611; x=1698062411; darn=gnu.org; h=mime-version:message-id:date:subject:to:from:from:to:cc:subject :date:message-id:reply-to; bh=PFawMLNC1yvW9Zht80p7HTVr6OWpghEkQarI9XrgGj0=; b=Rf9+8q8SX2EHyI4DX3q4LiQlB5fjFuUjZDLV8ZQnkRW+AVw0YUNIMv8TFF2E5B187f 0aGpG5pQt3ofFIVuwIoAZtV1PCY/ZFboOROdfAr+QVbNx7zvAdUGv1wH1upguYziCw36 bWlAZsh1qPwRCjYyh8pXAyZEF+7ZSdPQMQVvnYXNxYpyhNXKCO/VHtKAEJ2bhNHtLUg4 0u6AvtNonizC5T3B8BqdKLMdqmWwt3SXJlB2WhKYEIeVbkc3aRTz4rIhX38Ynf/tqoG1 LxTJeYbpxu+c+vRKQ44vNHclcpQL36DzLja0m0vi/sT8J0BvuPwSpYA6kPiPtJFvFwFv FelQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697457611; x=1698062411; h=mime-version:message-id:date:subject:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=PFawMLNC1yvW9Zht80p7HTVr6OWpghEkQarI9XrgGj0=; b=tzFhegwUwE34Dr/wRbAW34Vd5iHtBIQMqyxESIfwGtCOBwFzY1x4q9QVmwgvnddd4G y5BF74mMQs/mLQeczrji07crBJu3s6btcwRtoyK64Wunldq+B+eHX6tzj3zabEI4DEnT T0fgug8lt+YCCHQ+a/vPqV6iuqNnPI7KCJc/apaDA5e/4AY1W7Hc0zVwXfwMdFum6qHv zCTNCiHhibbvC4infNE1F3K7XpAgYfK3YsQ5JbwyjLaKTFhaBMdH3RJZtqtANyPl+Qs5 pePLKIq5YirtSOj4lwzyZ/qlFelgCDrfbirTTT+Oih4vs0sEOcDXvzcI8QJGNIvUzXCu OnJw== X-Gm-Message-State: AOJu0Yz/seQ/y2u5EtXR0SwJ4XSNqD4NxBOr0TKly+7qLkUSiatVaJ3m CZxzdFUliBz2EYu2QCloSq9LkRzrCUg= X-Google-Smtp-Source: AGHT+IGRbxDxfXxuPqdHqGhsv/ThtM2Ztz8Ko6UWzscWOWxRNjdY6lIE4g+AhewnsfnrVnN1GWYW3Q== X-Received: by 2002:a17:906:3298:b0:9ae:701a:6efa with SMTP id 24-20020a170906329800b009ae701a6efamr27109061ejw.69.1697457610754; Mon, 16 Oct 2023 05:00:10 -0700 (PDT) Original-Received: from Mini.fritz.box (p4fe3a7d3.dip0.t-ipconnect.de. [79.227.167.211]) by smtp.gmail.com with ESMTPSA id og41-20020a1709071de900b009adce1c97ccsm3852525ejc.53.2023.10.16.05.00.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 05:00:09 -0700 (PDT) Received-SPF: pass client-ip=2a00:1450:4864:20::62d; envelope-from=gerd.moellmann@gmail.com; helo=mail-ej1-x62d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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:272565 Archived-At: --=-=-= Content-Type: text/plain Tags: patch The attached patch implements LLDB support in Gud, based on gud-gdb. No MI support, because lldb-mi is no longer part of LLVM. It's probably not needless to emphasize that this is entirely my work alone :-). --=-=-= Content-Type: text/patch Content-Disposition: attachment; filename=0001-Gud-lldb-support.patch >From b1a721304fb285eae30405ab7d03c9b9fe200c8a 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 | 143 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 143 insertions(+) diff --git a/lisp/progmodes/gud.el b/lisp/progmodes/gud.el index d4b954a7203..e33c7942933 100644 --- a/lisp/progmodes/gud.el +++ b/lisp/progmodes/gud.el @@ -40,6 +40,7 @@ ;;; Code: (require 'comint) +(eval-when-compile (require 'rx)) (defvar gdb-active-process) (defvar gdb-define-alist) @@ -973,6 +974,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 +3842,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. Tehir +;; names are deducded 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 (any ":")))) + ":" + (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 --=-=-=--