public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug cli/30353] New: [gdb/cli] segfault on -eiex "set editing off"
@ 2023-04-14 10:06 vries at gcc dot gnu.org
  2023-04-14 10:09 ` [Bug cli/30353] " vries at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: vries at gcc dot gnu.org @ 2023-04-14 10:06 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=30353

            Bug ID: 30353
           Summary: [gdb/cli] segfault on -eiex "set editing off"
           Product: gdb
           Version: HEAD
            Status: NEW
          Severity: normal
          Priority: P2
         Component: cli
          Assignee: unassigned at sourceware dot org
          Reporter: vries at gcc dot gnu.org
  Target Milestone: ---

...
$ gdb -eiex "set editing off"
Fatal signal: Segmentation fault
----- Backtrace -----
0x596514 gdb_internal_backtrace_1
        /data/vries/gdb/src/gdb/bt-utils.c:122
0x5965b7 _Z22gdb_internal_backtracev
        /data/vries/gdb/src/gdb/bt-utils.c:168
0x78809a handle_fatal_signal
        /data/vries/gdb/src/gdb/event-top.c:956
0x788206 handle_sigsegv
        /data/vries/gdb/src/gdb/event-top.c:1029
0x7f1ed10578bf ???
0x893970 _Z31interp_supports_command_editingP6interp
        /data/vries/gdb/src/gdb/interps.c:330
0x787111 _Z19change_line_handleri
        /data/vries/gdb/src/gdb/event-top.c:292
0xc5554b set_editing
        /data/vries/gdb/src/gdb/top.c:2141
0x60c3ee _Z14do_set_commandPKciP16cmd_list_element
        /data/vries/gdb/src/gdb/cli/cli-setshow.c:458
0xc52731 _Z15execute_commandPKci
        /data/vries/gdb/src/gdb/top.c:679
0x90c813 catch_command_errors
        /data/vries/gdb/src/gdb/main.c:517
0x90ca1f execute_cmdargs
        /data/vries/gdb/src/gdb/main.c:616
0x90d33f captured_main_1
        /data/vries/gdb/src/gdb/main.c:1042
0x90df1d captured_main
        /data/vries/gdb/src/gdb/main.c:1308
0x90dfbc _Z8gdb_mainP18captured_main_args
        /data/vries/gdb/src/gdb/main.c:1337
0x41a9bd main
        /data/vries/gdb/src/gdb/gdb.c:32
...

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug cli/30353] [gdb/cli] segfault on -eiex "set editing off"
  2023-04-14 10:06 [Bug cli/30353] New: [gdb/cli] segfault on -eiex "set editing off" vries at gcc dot gnu.org
@ 2023-04-14 10:09 ` vries at gcc dot gnu.org
  2023-04-17  9:31 ` vries at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: vries at gcc dot gnu.org @ 2023-04-14 10:09 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=30353

--- Comment #1 from Tom de Vries <vries at gcc dot gnu.org> ---
Segfault happens because we dereference nullptr interp:
...
Thread 1 "gdb" received signal SIGSEGV, Segmentation fault.
0x0000000000893970 in interp_supports_command_editing (interp=0x0) at
  /data/vries/gdb/src/gdb/interps.c:330
330       return interp->supports_command_editing ();
...

Called from here:
...
(gdb) up
#1  0x0000000000787112 in change_line_handler (editing=0) at
/data/vries/gdb/src/gdb/event-top.c:292
292       if (!interp_supports_command_editing (top_level_interpreter ())
....

Called from here:
...
(gdb) up
#2  0x0000000000c5554c in set_editing (args=0x0, from_tty=1, c=0x2ab07a0)
    at /data/vries/gdb/src/gdb/top.c:2141
2141      change_line_handler (set_editing_cmd_var);
...

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug cli/30353] [gdb/cli] segfault on -eiex "set editing off"
  2023-04-14 10:06 [Bug cli/30353] New: [gdb/cli] segfault on -eiex "set editing off" vries at gcc dot gnu.org
  2023-04-14 10:09 ` [Bug cli/30353] " vries at gcc dot gnu.org
@ 2023-04-17  9:31 ` vries at gcc dot gnu.org
  2023-04-17  9:46 ` vries at gcc dot gnu.org
  2023-04-21  8:00 ` vries at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: vries at gcc dot gnu.org @ 2023-04-17  9:31 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=30353

--- Comment #2 from Tom de Vries <vries at gcc dot gnu.org> ---
The easiest way to fix this is:
...
diff --git a/gdb/event-top.c b/gdb/event-top.c
index 53ddd515be7..f6e92655b0d 100644
--- a/gdb/event-top.c
+++ b/gdb/event-top.c
@@ -287,7 +287,13 @@ change_line_handler (int editing)
   if (ui != main_ui)
     return;

-  /* Don't try enabling editing if the interpreter doesn't support it
+  if (top_level_interpreter () == nullptr || command_interp () == nullptr)
+    {
+      gdb_printf ("Cannot set editing to on or off, no interpreter yet.\n");
+      return;
+    }
+
+    /* Don't try enabling editing if the interpreter doesn't support it
      (e.g., MI).  */
   if (!interp_supports_command_editing (top_level_interpreter ())
       || !interp_supports_command_editing (command_interp ()))
...
which gives us:
...
$ gdb -eiex "set editing off"
Cannot set editing to on or off, no interpreter yet.
(gdb) 
...

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug cli/30353] [gdb/cli] segfault on -eiex "set editing off"
  2023-04-14 10:06 [Bug cli/30353] New: [gdb/cli] segfault on -eiex "set editing off" vries at gcc dot gnu.org
  2023-04-14 10:09 ` [Bug cli/30353] " vries at gcc dot gnu.org
  2023-04-17  9:31 ` vries at gcc dot gnu.org
@ 2023-04-17  9:46 ` vries at gcc dot gnu.org
  2023-04-21  8:00 ` vries at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: vries at gcc dot gnu.org @ 2023-04-17  9:46 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=30353

--- Comment #3 from Tom de Vries <vries at gcc dot gnu.org> ---
(In reply to Tom de Vries from comment #2)
> The easiest way to fix this is:

Alternatively, we could allow it to be set, and deal with it later when
interpreters are started.

I'm not sure how that would work though.  My naive idea is that  
current_ui->command_editing is just set unconditionally, and that interpreters
deal with that setting accordingly, depending on whether they support it or
not.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug cli/30353] [gdb/cli] segfault on -eiex "set editing off"
  2023-04-14 10:06 [Bug cli/30353] New: [gdb/cli] segfault on -eiex "set editing off" vries at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2023-04-17  9:46 ` vries at gcc dot gnu.org
@ 2023-04-21  8:00 ` vries at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: vries at gcc dot gnu.org @ 2023-04-21  8:00 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=30353

--- Comment #4 from Tom de Vries <vries at gcc dot gnu.org> ---
In the docs we have:
...
Only set or source commands should be placed into an early initialization file,
and the only set commands that can be used are those that control how GDB
starts up.
...

Hmm, so does "set editing off" "control how GDB starts up"?

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-04-21  8:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-14 10:06 [Bug cli/30353] New: [gdb/cli] segfault on -eiex "set editing off" vries at gcc dot gnu.org
2023-04-14 10:09 ` [Bug cli/30353] " vries at gcc dot gnu.org
2023-04-17  9:31 ` vries at gcc dot gnu.org
2023-04-17  9:46 ` vries at gcc dot gnu.org
2023-04-21  8:00 ` vries at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).