Subject: Re: bug#69327: 29.2.50; Emacs crashes when running gdb with comint-prompt-read-only

From: Knut Anders Hatlen <[email-masked]>
Date: Fri, 23 Feb 2024 21:16:50 +0100

Eli Zaretskii <[email-masked]> writes:

>> From: Knut Anders Hatlen <[email-masked]>
>> Date: Fri, 23 Feb 2024 10:12:25 +0000
>> 
>> Then run emacs -Q and evaluate:
>> 
>> (progn
>>   (setopt gdb-debuginfod-enable-setting nil
>>           comint-prompt-read-only t)
>>   (gdb "gdb -i=mi a.out")
>>   (insert "r")
>>   (comint-send-input)
>>   (sit-for 2)
>>   (gdb "gdb -i=mi b.out"))
>
> Does gdb-mi.el really support several debugging sessions in parallel?

I'm not sure, but I don't think so. But I sometimes forget that I
already have a debugging session running in Emacs, and start a new one.
I would be fine with getting an error if it's not supported. But
preferably not a crash. :)

>> According to git bisect, it has crashed since the
>> gdb-debuginfod-enable-setting option was introduced in:
>> 
>> commit ab417c8a6eeb7df7ccce3e5f8416f48544a5174e
>> Author: Eli Zaretskii <[email-masked]>
>> Date:   Tue Mar 7 14:39:27 2023 +0200
>> 
>>     Fix problem with debuginfod queries in "M-x gdb"
>>     
>>     * lisp/progmodes/gdb-mi.el (gdb-debuginfod-enable-setting): New
>>     defcustom.
>>     (gdb-debuginfod-message): New function.
>>     (gdb-init-1): Initialize gdb-debuginfod-enable.  Ask the user
>>     about debuginfod queries and display any error messages.
>>     (Bug#61973)
>>     
>>     * etc/NEWS: Announce the change.
>
> Does replacing defvar with defvar-local for
> gdb-debuginfod-enable-setting helps to resolve the problem?

I assume you meant gdb-debuginfod-enable (the defvar), not
gdb-debuginfod-enable-setting (the defcustom)? Unfortunately, no, it
didn't seem to change anything. (For completeness, I also tried to
change the defcustom to defvar-local, even though I don't think that's
what you requested. That didn't help either.)

> If not, please tell what are the errors that Emacs wants to report,
> here:
>
>   #10685 0x00005555557a971b in read_process_output_error_handler (error_val=<optimized out>) at ../../src/process.c:6140
>   #10686 0x000055555575462c in internal_condition_case_1 (bfun=bfun@entry=0x5555557a97a0 <read_process_output_call>, arg=XIL(0x7fffef130093), handlers=handlers@entry=XIL(0x90), hfun=hfun@entry=0x5555557a96e0 <read_process_output_error_handler>) at ../../src/eval.c:1557
> 	  val = <optimized out>
> 	  c = 0x555555ebab70
>   #10687 0x00005555557ac215 in read_and_dispose_of_process_output (coding=<optimized out>, nbytes=157, chars=0x7fffffffc420 "=cmd-param-changed,param=\"debuginfod enabled\",value=\"off\"\n~\"Reading symbols from b.out...\\n\"\n~\"(No debugging symbols found in b.out)\\n\"\n(gdb) \n1^done\n(gdb) \nater <https://urldefense.com/v3/__http://gnu.org/licenses/gpl.html__;!!ACWV5N9M2RV99hQ!L1QMwwawGjh56jglEvTNy8xaiRP1Yrb2WvksE8JcbvnoIbAgcTriclAWSIQjJEZ0LLxIF3V4Tr-L$ >\\nTh"..., p=0x5555561b66f8) at ../../src/process.c:6354
>
> and here:
>
>   #10679 0x00005555557a971b in read_process_output_error_handler (error_val=<optimized out>) at ../../src/process.c:6140
>   #10680 0x000055555575462c in internal_condition_case_1 (bfun=bfun@entry=0x5555557a97a0 <read_process_output_call>, arg=XIL(0x7fffef12d703), handlers=handlers@entry=XIL(0x90), hfun=hfun@entry=0x5555557a96e0 <read_process_output_error_handler>) at ../../src/eval.c:1557
> 	  val = <optimized out>
> 	  c = 0x555555ebab70
>   #10681 0x00005555557ac215 in read_and_dispose_of_process_output (coding=<optimized out>, nbytes=14, chars=0x7fffffffae40 "1^done\n(gdb) \n", p=0x5555561b66f8) at ../../src/process.c:6354
>
> I'm asking about the value of error_val with which
> read_process_output_error_handler is called in these two frames.  It
> is possible that you will need to rebuild Emacs without optimizations,
> to be able to show these values.  The error_val argument is a Lisp
> object, so please use the "pp" command to show it (if GDB says it
> doesn't know about "pp", you need to "source .gdbinit" where .gdbinit
> is the file that comes with the Emacs source tarball, in the 'src'
> directory).

It apparently tries to report "error in process filter: Text is
read-only" in all of the read_process_output_error_handler() frames that
I looked at. error_val contains the same in all of them:

(gdb) pp error_val
(text-read-only)

>> When setting comint-prompt-read-only to nil, it seems to behave fine
>> regardless of which value gdb-debuginfod-enable-setting has.
>
> Why are you setting comint-prompt-read-only non-nil?

It's just a preference of mine. I like that the prompt is preserved even
if I hit backspace a few times too many, or hit C-k in the wrong spot,
in M-x shell or M-x gdb. Makes it feel a little more similar to running
a shell in a terminal, without going all the way to term or vterm.

Thanks,

-- 
Knut Anders