Bug #98281 gdb mysqld result crash
Submitted: 18 Jan 2020 13:36 Modified: 18 Jan 2020 14:15
Reporter: zhanghe zhang Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:8.0 OS:Ubuntu (19.10)
Assigned to: CPU Architecture:x86
Tags: debug, gdb

[18 Jan 2020 13:36] zhanghe zhang
Description:
when i use mtr debug mysqld, set breakpoint on any C++ functions, will cause mysqld crash

scrapy@scrapy:~/mysql$ gdb bin/mysqld
GNU gdb (Ubuntu 8.2.91.20190405-0ubuntu3) 8.2.91.20190405-git
Copyright (C) 2019 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-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"...
Reading symbols from bin/mysqld...
(gdb) rbreak SELECT_LEX::.*
段错误 (核心已转储)

How to repeat:
shell> gdb bin/mysqld

shell> rbreak SELECT_LEX::.*

Suggested fix:
can't find root cause.
[18 Jan 2020 14:15] MySQL Verification Team
The message translates to:  "Segfault (core dumped)"

Don't think it's a MySQL bug if gdb crashes.  Try upgrading gdb or use another OS and check how it goes.

gdb needed 5G of RAM to set all these breakpoints.  

$ gdb ./bin/mysqld
GNU gdb (GDB) Fedora 8.3-7.fc30
Copyright (C) 2019 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-redhat-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"...
SIGINT is used by the debugger.
Are you sure you want to change it? (y or n) [answered Y; input not from terminal]
Reading symbols from ./bin/mysqld...
(gdb) rbreak SELECT_LEX::.*
Breakpoint 1 at 0xe7eae0: file ../../mysqlcom-8.0.19/sql/sql_lex.cc, line 2016.
void SELECT_LEX::SELECT_LEX(Item*, Item*);
Breakpoint 2 at 0xe826d0: file ../../mysqlcom-8.0.19/sql/sql_list.h, line 572.
bool SELECT_LEX::accept(Select_lex_visitor*);
Breakpoint 3 at 0xe7f560: file ../../mysqlcom-8.0.19/sql/sql_lex.cc, line 2437.
bool SELECT_LEX::add_ftfunc_to_list(Item_func_match*);
Breakpoint 4 at 0xe7f4b0: file ../../mysqlcom-8.0.19/sql/sql_lex.cc, line 2433.
bool SELECT_LEX::add_item_to_list(Item*);
Breakpoint 5 at 0xe7f4a0: file ../../mysqlcom-8.0.19/sql/sql_lex.cc, line 2427.
void SELECT_LEX::add_order_to_list(ORDER*);
<snip>
Breakpoint 116 at 0xeddbb0: file /opt/rh/devtoolset-8/root/usr/include/c++/8/bits/stl_heap.h, line 214.
static void std::__adjust_heap<Item_exists_subselect**, long int, Item_exists_subselect*, __gnu_cxx::__ops::_Iter_comp_iter<SELECT_LEX::flatten_subqueries(THD*)::<lambda(Item_exists_subselect*, Item_exists_subselect*)> > >(Item_exists_subselect **, long, long, Item_exists_subselect *);
(gdb) 

--------------------------

FWIW the top of my ~/.gdbinit file looks like this:

handle SIGUSR1 nostop print
handle SIGUSR2 nostop print
handle SIGWAITING nostop print
handle SIGLWP nostop print
handle SIGPIPE nostop print
handle SIGALRM nostop print
handle SIGHUP nostop print
handle SIGTERM nostop print
handle SIGINT stop print

set print vtbl on
set print asm-demangle on
set print demangle on
set print union on
set print sevenbit-strings off
set print null-stop
set print frame-arguments scalars
set print array-indexes on
set print array on
set print address on
set filename-display relative
set history filename gdb_history.txt
set history size 3200000
set history save on
set pagination off
set logging overwrite on
set logging on
set print elements 4096
set print pretty on
set print object on
set auto-load safe-path /

set arg --no-defaults --default-authentication-plugin=mysql_native_password --gdb --console --skip-log-bin --skip-log-slave-updates  --skip-name-resolve --basedir=. --datadir=./data --innodb-flush-log-at-trx-commit=0   --server-id=1 --performance-schema-instrument="%=ON"