From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id E523B3858D38 for ; Sat, 13 Apr 2024 09:09:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E523B3858D38 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org E523B3858D38 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712999402; cv=none; b=qkCEs+KJ4WH8exGrba3VsXi0qmsKgdG4VKL5OvuQl1x5qnwEzgfZAwo3cUHYdmB3UARSYSndWtomh2A+wilxxj/ndM9CegHoPexsfFJsIWlrqNLN8umg1IQHCC3/D2hBUdqaGbpUyGc3ajyjoDYdvBQLMcJn6Rb0JmQEvSskUjI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712999402; c=relaxed/simple; bh=QPbGRCbdfEuW6j9RZmgKQxU4oArM+L+s6KZRzp9KUM8=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=rxfMM6mDGEgia7y8PlRCNVg6+8I854X7C8UVojcQynb30EGrwQzf5g09T0PBGQO8/h3aYHMtOk/TQNX6zLcdGyRuAFq9zRWtWUjU6tLN7zFpPkMl8jr08+QsBNed2CefE2pYVzdIqZN4uczKQogv/wqbA+2m2FC00thNYVE1f5s= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712999397; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mkThckmNgyiZbXbHBb2yCDP5C+SsCcm2f5kWyYdW2aA=; b=RCfsDl3dfft/+xf3GvtH0e4ZJo3B5YT2deXMD6je2DFalQZR2JZv9G6FiI9Kq4tucLuuA3 R9wcqSwCf90Lys86ZaVNBS4fUI3/45uhkAtaTGxv2Geu63WH5M9kH1pVftFAIxOew/W5z6 68C+FFwhLtedU5kiBC2U7PxW6g3WYJ4= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-163-Vk7I6mrnMQu0l0ogfGvn_g-1; Sat, 13 Apr 2024 05:09:55 -0400 X-MC-Unique: Vk7I6mrnMQu0l0ogfGvn_g-1 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-3473168c856so509245f8f.1 for ; Sat, 13 Apr 2024 02:09:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712999394; x=1713604194; h=content-transfer-encoding:mime-version: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=7Fbf/fHevMbWtl5aew4f56uqjtxGFKXViJa+J8axvZw=; b=OMbaOLKV/S46czmsjw0T7LMDM9JwnKDgyX8Lker9LfmZ2uyxr99XMl542TjVzLfsod beBloX6vg+w+WY11LE3yCuQwZoPjm8sJ6N2P5avCjb7654/c7HHmw8jT9e/WPPHeKAYJ 25joDt8BGW5xJ70HVwhHQ3p2V3SI0PWsjpDcDfo1Zu9x9Uk4lDalgtBWrxZxFp0V+5em mDdjztBYcnMK9mkMp2mlL+k46jYr30e0TOtdhos2BdmcAbNR3SEi94ts8pwSibqxBYQU KTPnvnH7120apo4A6gO+2JTxsfP2UNviSLb+rPHh0fxjar4NBGhH9k9h+rcdG9Hn7lRI mutA== X-Forwarded-Encrypted: i=1; AJvYcCWZyua2gDzQ4hrQ+3LNJqg0fllWbvi1KrTslwYoYWQ2t8Tqgam2mjV3u7Z30B620+6xIhvivOYVeGHWCvJJc/JN/qtJBoUhNihxZQ== X-Gm-Message-State: AOJu0YwdWooHYskZiqnWzqGMYSqHbuGoqr89sRd73jp7KuNUCm1ShYRm JZUTsacgKjR/Xr5ys0z6sIQjzD3YWuliwP3sXB9xTCJ4RSHccQo5HVz7YDgg5Fs5FhA7S0fdKh7 coFF6cC7Jq87PBA3U0qN/kpAtgPjBRr/90M3AIM4I/giiagNrKLjbWdZAKRw= X-Received: by 2002:a5d:588c:0:b0:341:d912:1fec with SMTP id n12-20020a5d588c000000b00341d9121fecmr3929091wrf.49.1712999394469; Sat, 13 Apr 2024 02:09:54 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEesLOpnzLeJFJonvrY2LktQHp19erEZIPNpiD0oiQ8n19CNc5b7tLU9IukmngHjVb1IWOhnQ== X-Received: by 2002:a5d:588c:0:b0:341:d912:1fec with SMTP id n12-20020a5d588c000000b00341d9121fecmr3929061wrf.49.1712999393709; Sat, 13 Apr 2024 02:09:53 -0700 (PDT) Received: from localhost (185.223.159.143.dyn.plus.net. [143.159.223.185]) by smtp.gmail.com with ESMTPSA id j18-20020a5d6052000000b00343d1d09550sm6124348wrt.60.2024.04.13.02.09.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Apr 2024 02:09:53 -0700 (PDT) From: Andrew Burgess To: Eli Zaretskii Cc: lsix@lancelotsix.com, gdb-patches@sourceware.org Subject: Re: [PATCH 2/6] gdb: move display of completion results into completion_result class In-Reply-To: <86zftxrcpx.fsf@gnu.org> References: <86v855dyls.fsf@gnu.org> <20240330233038.sol5j3cp7vsym4uz@octopus> <86v853ar3c.fsf@gnu.org> <87v84m4hps.fsf@redhat.com> <867ch2s9rw.fsf@gnu.org> <87le5i440e.fsf@redhat.com> <86zftxrcpx.fsf@gnu.org> Date: Sat, 13 Apr 2024 10:09:52 +0100 Message-ID: <87cyqt4oin.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-5.5 required=5.0 tests=BAYES_00,BODY_8BITS,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Eli Zaretskii writes: >> From: Andrew Burgess >> Cc: lsix@lancelotsix.com, gdb-patches@sourceware.org >> Date: Fri, 12 Apr 2024 23:20:33 +0100 >>=20 >> OK, so now the bad news. >>=20 >> My patched GDB doesn't "just work" with emacs. >>=20 >> Remember though, an unpatched GDB doesn't work either when trying to >> complete a filename with spaces in, so it's not that I've made things >> worse. >>=20 >> I tracked at least one bug down to this function in gud.el: >>=20 >> (defun gud-gdb-completion-at-point () >> "Return the data to complete the GDB command before point." >> (let ((end (point)) >> (start >> (save-excursion >> (skip-chars-backward "^ " (comint-line-beginning-position)) >> (point)))) >> ;; FIXME: `gud-gdb-run-command-fetch-lines' has some nasty side-ef= fects on >> ;; the buffer (via `gud-delete-prompt-marker'): it removes the pro= mpt and >> ;; then re-adds it later, thus messing up markers and overlays alo= ng the >> ;; way (bug#18282). >> ;; We use an "insert-before" marker for `start', since it's typica= lly right >> ;; after the prompt, which works around the problem, but is a hack= (and >> ;; comes with other downsides, e.g. if completion adds text at `st= art'). >> (list (copy-marker start t) end >> (completion-table-dynamic >> (apply-partially gud-gdb-completion-function >> (buffer-substring (comint-line-beginning-p= osition) >> start)))))) >> =20 >> This is trying to figure out everything before the completion word on >> the current line and doing the apply-partial with this context on >> gud-gdb-completion-function. >>=20 >> So if we are completing 'file /tmp/abc' then we'd end up doing: >>=20 >> (apply-partial gud-gdb-completion-function "file ") >>=20 >> The completion context is calculated as running from the start of the >> line up to 'start', which is calculated in the 'let'. And 'start' is >> calculated by starting from 'point' and moving backward to the first >> whitespace. >>=20 >> That's not going to work for completing any line that contains a space. >>=20 >> I think this function would need to get smarter to understand about >> escaping and quoting. > > Yes. Would you mind submitting a bug report about that, using the > command "M-x report-emacs-bug"? I absolutely will file the bug report once this series (or whatever this series becomes) is merged. However, I wanted to see if there were additional bugs hiding in the emacs code, these might indicate changes that need to be made (or not made) on the GDB side. So the good news is, that with a little hacking I managed to get emacs working! Disclaimer: My emacs lisp knowledge is pretty weak, so please consider this a proof of concept rather than code I'm actually suggesting should be merged into emacs. When I file the bug I'll include this code again, but by adding it here we can hopefully see what needs to change. The new and updated emacs code is at the end of this email if anyone wants to play with emacs and this new completion. Drop this new code into a file, load the emacs 'gdb' mode, then eval the new code. This adds some new functions, and replaces one existing function. With this in place I now get completion for filenames containing whitespace. Given this directory tree: /tmp/eee/ =E2=94=9C=E2=94=80=E2=94=80 aa bb =E2=94=82 =E2=94=9C=E2=94=80=E2=94=80 f1 =E2=94=82 =E2=94=94=E2=94=80=E2=94=80 f2 =E2=94=94=E2=94=80=E2=94=80 aa cc =E2=94=9C=E2=94=80=E2=94=80 g1 =E2=94=94=E2=94=80=E2=94=80 g2 (gdb) file /tmp/eee/aa =3D> file /tmp/eee/aa\ Possible completions are:=09=09<--- These are offered in a new buffer. /tmp/eee/aa\ bb/=09=09=09<--- I select this entry. /tmp/eee/aa\ cc/ =3D> file /tmp/eee/aa\ bb/ =3D> file /tmp/eee/aa\ bb/f Possible completions are:=09=09<--- These are offered in a new buffer. /tmp/eee/aa\ bb/f1 /tmp/eee/aa\ bb/f2=09=09=09<--- I select this entry. =3D> file /tmp/eee/aa\ bb/f2 ... gdb tries to load the file ... And if also works with quoting: (gdb) file "/tmp/eee/a =3D> file "/tmp/eee/aa Possible completions are:=09=09<--- These are offered in a new buffer. "/tmp/eee/aa bb/ "/tmp/eee/aa cc/=09=09=09<--- I select this entry. =3D> file "/tmp/eee/aa cc/ =3D> file "/tmp/eee/aa cc/g Possible completions are:=09=09<--- These are offered in a new buffer. "/tmp/eee/aa cc/g1"=09=09=09<--- I select this entry. "/tmp/eee/aa cc/g2" =3D> file "/tmp/eee/aa cc/g1" ... gdb tries to load the file ... As I said, I'm not claiming that emacs is "fixed", but I think I've shown what needs to be done to get this working, and also I've satisfied myself that everything can be made to work. Thanks, Andrew --- ;; New function: Return true if the character at POS is escaped, that ;; is, is the character as POS preceeded by a backslash. (defun gud-gdb-is-char-escaped (pos) (char-equal ?\\ (char-before pos))) ;; New function: Move point forward as skip-chars-forward does, ;; passing CHARS and LIMIT to skip-chars-forward. However, after ;; calling skip-chars-forward, if the character we are looking at is ;; escaped (with a backslash) then skip that character, and call ;; skip-chars-forward again. (defun gud-gdb-skip-to-unquoted (chars limit) (while (and (< (point) limit) (progn (skip-chars-forward chars limit) (if (gud-gdb-is-char-escaped (point)) (progn (forward-char) t) nil))))) ;; New function: Move point forward skipping over a 'word'. A word ;; can be quoted, starts with a single or double quote, in which case ;; the corresponding quote marks the end of the word. Or a word can ;; be unquoted, in which case the word ends at the next white space. ;; ;; Never move forward past LIMIT. ;; ;; In an unquoted word white space can be escaped. ;; ;; In a double quoted word, double quotes can be escaped. (defun gud-gdb-forward-maybe-quoted-word (limit) (cond ((char-equal ?\' (char-after)) (progn (forward-char) (skip-chars-forward "^'" limit))) ((char-equal ?\" (char-after)) (progn (forward-char) (gud-gdb-skip-to-unquoted "^\"" limit))) (t (progn (gud-gdb-skip-to-unquoted "^[:space:]" limit))))) ;; Assuming point is at the start of a line, return the position for ;; the start of a completion word. The point will be moved by calling ;; this function. ;; ;; Never search past LIMIT. ;; ;; The completion word is the last word on the line, the word might be ;; quoted though. (defun gud-gdb-find-completion-word (limit) (let ((completion-word-start nil)) (while (< (point) limit) (setf completion-word-start (point)) (gud-gdb-forward-maybe-quoted-word limit) (skip-chars-forward " " limit)) completion-word-start)) ;; This replaces an existing emacs function. I've changed the logic ;; for finding the completion word. (defun gud-gdb-completion-at-point () "Return the data to complete the GDB command before point." (let* ((end (point)) (start (save-excursion (goto-char (comint-line-beginning-position)) (gud-gdb-find-completion-word end)))) ;; FIXME: `gud-gdb-run-command-fetch-lines' has some nasty side-effects= on ;; the buffer (via `gud-delete-prompt-marker'): it removes the prompt a= nd ;; then re-adds it later, thus messing up markers and overlays along th= e ;; way (bug#18282). ;; We use an "insert-before" marker for `start', since it's typically r= ight ;; after the prompt, which works around the problem, but is a hack (and ;; comes with other downsides, e.g. if completion adds text at `start')= . (list (copy-marker start t) end (completion-table-dynamic (apply-partially gud-gdb-completion-function (buffer-substring (comint-line-beginning-positi= on) start))))))