Bug 23544

Summary: Segmentation fault when executing: python gdb.execute("interp mi '-break-list'")
Product: gdb Reporter: ovparvu
Component: pythonAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED FIXED    
Severity: normal CC: krinkodot22, ssbssa, tromey
Priority: P2    
Version: HEAD   
Target Milestone: ---   
Host: Target:
Build: Last reconfirmed: 2018-08-17 00:00:00

Description ovparvu 2018-08-17 11:02:55 UTC
For reproducibility purposes details about the host and the sequence of executed commands is given below. As a side note gdb was compiled with python support.

$ neofetch
            .-/+oossssoo+/-.               user@pc 
        `:+ssssssssssssssssss+:`           --------------- 
      -+ssssssssssssssssssyyssss+-         OS: Ubuntu 18.04.1 LTS x86_64 
    .ossssssssssssssssssdMMMNysssso.       Host: <Sanitized>
   /ssssssssssshdmmNNmmyNMMMMhssssss/      Kernel: 4.15.0-30-generic 
  +ssssssssshmydMMMMMMMNddddyssssssss+     Uptime: <Sanitized>
 /sssssssshNMMMyhhyyyyhmNMMMNhssssssss/    Packages: <Sanitized>
.ssssssssdMMMNhsssssssssshNMMMdssssssss.   Shell: bash 4.4.19 
+sssshhhyNMMNyssssssssssssyNMMMysssssss+   Resolution: <Sanitized>
ossyNMMMNyMMhsssssssssssssshmmmhssssssso   DE: <Sanitized> 
ossyNMMMNyMMhsssssssssssssshmmmhssssssso   WM: <Sanitized> 
+sssshhhyNMMNyssssssssssssyNMMMysssssss+   WM Theme: <Sanitized> 
.ssssssssdMMMNhsssssssssshNMMMdssssssss.   Theme: <Sanitized>
 /sssssssshNMMMyhhyyyyhdNMMMNhssssssss/    Icons: <Sanitized>
  +sssssssssdmydMMMMMMMMddddyssssssss+     Terminal: terminator 
   /ssssssssssshdmNNNNmyNMMMMhssssss/      CPU: <Sanitized>
    .ossssssssssssssssssdMMMNysssso.       GPU: <Sanitized>
      -+sssssssssssssssssyyyssss+-         GPU: <Sanitized>
        `:+ssssssssssssssssss+:`           Memory: <Sanitized>
            .-/+oossssoo+/-. 

$ <Sanitized>/gdb
GNU gdb (GDB) 8.2.50.20180816-git
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-pc-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word".
(gdb) python gdb.execute("pwd")
Working directory /tmp.
(gdb) interp mi '-break-list'
^done,BreakpointTable={nr_rows="0",nr_cols="6",hdr=[{width="7",alignment="-1",col_name="number",colhdr="Num"},{width="14",alignment="-1",col_name="type",colhdr="Type"},{width="4",alignment="-1",col_name="disp",colhdr="Disp"},{width="3",alignment="-1",col_name="enabled",colhdr="Enb"},{width="10",alignment="-1",col_name="addr",colhdr="Address"},{width="40",alignment="2",col_name="what",colhdr="What"}],body=[]}
(gdb) python gdb.execute("interp mi '-break-list'")
Segmentation fault
Comment 1 Tom Tromey 2018-08-17 17:06:35 UTC
Thanks.

It's easy to fix this, but I'm finding it challenging to write a
test case, because two gdb prompts are printed and gdb_test doesn't
like that:

(gdb) python gdb.execute("interp mi -break-list")
^done,BreakpointTable={nr_rows="0",nr_cols="6",hdr=[{width="7",alignment="-1",col_name="number",colhdr="Num"},{width="14",alignment="-1",col_name="type",colhdr="Type"},{width="4",alignment="-1",col_name="disp",colhdr="Disp"},{width="3",alignment="-1",col_name="enabled",colhdr="Enb"},{width="10",alignment="-1",col_name="addr",colhdr="Address"},{width="40",alignment="2",col_name="what",colhdr="What"}],body=[]}
(gdb) (gdb) 
^^^^^^^^^^^  this is bad


I am not sure what's going on there yet.
Comment 2 Tom Tromey 2018-08-17 17:15:24 UTC
The prompt seems to indicate some deeper problem, because with
my patch to avoid the crash, after the command gdb gets a bit
wedged -- I can't type to it.
Comment 3 Tom Tromey 2018-08-21 14:35:13 UTC
See bug #21388
Comment 4 krinkodot22 2019-04-07 05:20:38 UTC
This appears to have been introduced in gdb 8.2. Previous gdb versions (I've tested 7.12.1, 8.0.1, and 8.1.1) hit the bad CLI behaviour of bug #21388, but not a segfault.

And it's not just 'interp mi -break-list' that triggers the segfault/CLI badness, but any interp/interpreter-exec command.
Comment 5 Hannes Domani 2022-01-05 16:36:51 UTC
Looks like it's fixed since at least gdb 10.1, maybe someone else knows the details?
Comment 6 Tom Tromey 2022-08-12 19:39:21 UTC
Seems to be fixed.