Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

GA

2023/11/21

MySQL 8.0.35で旧McAfeeのmysql-auditをビルドしてみる

【2023/11/21 15:58】タイトルが8.0.32だったけど8.0.35でした…

TL;DR

  • ビルドしてみただけ。動作確認はしていない

  • MySQL 8.0.35はあらかじめビルドしてある


そのまま素直にビルドできなくなっているのでパッチを3つ用意した


$ git clone git@github.com:yoku0825/mysql-audit.git

$ cd mysql-audit/

$ git checkout support_8035

$ bash bootstrap.sh

bootstrap.sh: line 2: autoreconf: command not found

autoreconfがない…Oracle Linux 8では autoconf パッケージらしい(最後に明示的にインストールしたのはだいぶ前なのでパッケージ名がどうだったか覚えてない…)


$ cat /etc/os-release

NAME="Oracle Linux Server"

VERSION="8.8"

$ dnf provides */bin/autoreconf

..

autoconf-2.69-27.el8.noarch : A GNU tool for automatically configuring source code
Repo        : ol8_appstream
Matched from:
Filename    : /usr/bin/autoreconf

autoconf-2.69-29.el8.noarch : A GNU tool for automatically configuring source code
Repo        : ol8_appstream
Matched from:
Filename    : /usr/bin/autoreconf

$ sudo dnf install autoconf

今度は aclocal がないって怒られた。

$ bash bootstrap.sh
autoreconf: Entering directory `.'
autoreconf: configure.ac: not using Gettext
autoreconf: running: aclocal  --output=aclocal.m4t
Can't exec "aclocal": No such file or directory at /usr/share/autoconf/Autom4te/FileUtils.pm line 326.
autoreconf: failed to run aclocal: No such file or directory

$ dnf provides */bin/aclocal
..
automake-1.16.1-6.el8.noarch : A GNU tool for automatically creating Makefiles
Repo        : ol8_appstream
Matched from:
Filename    : /usr/bin/aclocal

automake-1.16.1-7.el8.noarch : A GNU tool for automatically creating Makefiles
Repo        : ol8_appstream
Matched from:
Filename    : /usr/bin/aclocal

$ sudo dnf install automake

その次はlibtoolが無い。

$ bash bootstrap.sh
..
configure.ac:83: error: possibly undefined macro: AC_PROG_LIBTOOL
      If this token and others are legitimate, please use m4_pattern_allow.
      See the Autoconf documentation.
autoreconf: /usr/bin/autoconf failed with exit status: 1

$ sudo dnf install libtool

取り敢えずbootstrapまで終わった。

$ bash bootstrap.sh
autoreconf: Entering directory `.'
autoreconf: configure.ac: not using Gettext
autoreconf: running: aclocal --force
autoreconf: configure.ac: tracing
autoreconf: running: libtoolize --copy --force
libtoolize: putting auxiliary files in AC_CONFIG_AUX_DIR, 'config-aux'.
libtoolize: copying file 'config-aux/ltmain.sh'
libtoolize: Consider adding 'AC_CONFIG_MACRO_DIRS([m4])' to configure.ac,
libtoolize: and rerunning libtoolize and aclocal.
libtoolize: Consider adding '-I m4' to ACLOCAL_AMFLAGS in Makefile.am.
autoreconf: running: /usr/bin/autoconf --force
autoreconf: running: /usr/bin/autoheader --force
autoreconf: running: automake --add-missing --copy --force-missing
configure.ac:82: installing 'config-aux/compile'
configure.ac:7: installing 'config-aux/config.guess'
configure.ac:7: installing 'config-aux/config.sub'
configure.ac:41: installing 'config-aux/install-sh'
configure.ac:41: installing 'config-aux/missing'
src/Makefile.am: installing 'config-aux/depcomp'
autoreconf: Leaving directory `.'

configure スクリプトの中身はいつも --help で見る派。よくあるパターンでソースコードの場所を指定する。

$ ./configure --help

..

$ mkdir /home/yoku0825/audit_plugin
$ ./configure --with-mysql=/home/yoku0825/mysql/src/mysql-8.0.35 --with-mysql-plugindir=/home/yoku0825/audit_plugin
..
checking for mysql source code... configure: error: Failed to find required header file include/mysql_version.h in /usr/mysql/src/mysql-8.0.35, check the path and make sure you've run './configure ..<options>.. && cd include && make' in MySQL 5.1 sources dir or 'cmake . && make' in MySQL 5.5 sources dir.

ソースコードのディレクトリじゃなくてビルドしたディレクトリが必要だったらしい。 (8.0からインソースビルドするにはMySQLのcmakeに -DFORCE_INSOURCE_BUILD=ON が必要)

$ ./configure --with-mysql=/home/yoku0825/mysql/src/build_8.0.35  --with-mysql-plugindir=/home/yoku0825/audit_plugin
..
checking for mysql source code... configure: error: Failed to find required header file include/my_dir.h in /usr/mysql/src/build_8.0.35, check the path and make sure you've run './configure ..<options>.. && cd include && make' in MySQL 5.1 sources dir or 'cmake . && make' in MySQL 5.5 sources dir.

また違うファイルがつかめずに転けた。これインソースビルドしないとダメなんだろうか…。ということでインソースビルドしたディレクトリを用意。

$ ./configure --with-mysql=/home/yoku0825/mysql/src/insource_build_8.0.35/ --with-mysql-plugindir=/home/yoku0825/audit_plugin
..
Version: 1.0.0-99999 Symbol version: 1_0_0_99999
no

checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating Makefile
config.status: creating src/Makefile
config.status: creating yajl/Makefile
config.status: creating yajl/src/Makefile
config.status: creating udis86/Makefile
config.status: creating udis86/libudis86/Makefile
config.status: creating include/_config.h
config.status: executing depfiles commands
config.status: executing libtool commands

/usr/bin/rm: cannot remove 'libtoolT': No such file or directory
configure: CPPFLAGS:  -g -O2 -DDBUG_OFF -DNDEBUG -Werror -Wall -DMYSQL_AUDIT_PLUGIN_VERSION='"1.0.0"' -DMYSQL_AUDIT_PLUGIN_REVISION='"99999"' '-DMYSQL_AUDIT_PLUGIN_SYMBOL_VERSION()=extern const char audit_plugin_version_1_0_0_99999'

configureは成功した。

$ make
..
Making all in udis86
make[1]: Entering directory '/home/yoku0825/git/mysql-audit/udis86'
Making all in libudis86
make[2]: Entering directory '/home/yoku0825/git/mysql-audit/udis86/libudis86'
python ./opgen.py
  File "./opgen.py", line 259
    print "error: no mnemonic given in <instruction>."
                                                     ^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print("error: no mnemonic given in <instruction>.")?
make[2]: *** [Makefile:662: itab.c] Error 1
make[2]: Leaving directory '/home/yoku0825/git/mysql-audit/udis86/libudis86'
make[1]: *** [Makefile:371: all-recursive] Error 1
make[1]: Leaving directory '/home/yoku0825/git/mysql-audit/udis86'
make: *** [Makefile:426: all-recursive] Error 1

print ".." が print("..") でなければならないのはPython3のアレだとして、切り分けのためにPython 2.7に取り替えてみた。

$ python
Python 3.6.8 (default, Jun 14 2023, 10:42:30)

$ sudo dnf install python2
$ sudo alternatives --config python

There are 4 programs which provide 'python'.

  Selection    Command
-----------------------------------------------
*  1           /usr/libexec/no-python
   2           /usr/bin/python3.9
 + 3           /usr/bin/python3
   4           /usr/bin/python2

Enter to keep the current selection[+], or type selection number: 4

$ python --version
Python 2.7.18

$ make
..
/usr/mysql/src/insource_build_8.0.35/sql/query_term.h:630:12: error: 'if constexpr' only available with -std=c++17 or -std=gnu++17 [-Werror]
         if constexpr (visit_leaves == VL_VISIT_LEAVES)                                                                                                                                                                     ^~~~~~~~~                                                                                                   

cc1plus: all warnings being treated as errors
make[1]: *** [Makefile:480: hot_patch.lo] Error 1
make[1]: Leaving directory '/home/yoku0825/git/mysql-audit/src'
make: *** [Makefile:426: all-recursive] Error 1

エラーが変わったのでどうやらこの opgen.py はこれで良い(?)らしい。新しいのは -std=c++17 で対処できそうなのでconfigureしなおし。

$ CPPFLAGS="-std=c++17" ./configure --with-mysql=/home/yoku0825/mysql/src/insource_build_8.0.35/ --with-mysql-plugindir=/home/yoku0825/audit_plugin
$ make
..
/home/yoku0825/git/mysql-audit/pcre/missing: line 81: aclocal-1.15: command not found
WARNING: 'aclocal-1.15' is missing on your system.
         You should only need it if you modified 'acinclude.m4' or
         'configure.ac' or m4 files included by 'configure.ac'.
         The 'aclocal' program is part of the GNU Automake package:
         <http://www.gnu.org/software/automake>
         It also requires GNU Autoconf, GNU m4 and Perl in order to run:
         <http://www.gnu.org/software/autoconf>
         <http://www.gnu.org/software/m4/>
         <http://www.perl.org/>
make[2]: *** [Makefile:1357: aclocal.m4] Error 127
make[2]: Leaving directory '/home/yoku0825/git/mysql-audit/pcre'
make[1]: *** [Makefile:715: ../pcre/libpcre.la] Error 2
make[1]: Leaving directory '/home/yoku0825/git/mysql-audit/src'
make: *** [Makefile:426: all-recursive] Error 1

今更aclocal-1.15を欲しがられる。boostrap.shの時点で言ってくれてもいいのよ…。

$ /usr/bin/aclocal --version
aclocal (GNU automake) 1.16.1
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv2+: GNU GPL version 2 or later <https://gnu.org/licenses/gpl-2.0.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Tom Tromey <tromey@redhat.com>
       and Alexandre Duret-Lutz <adl@gnu.org>.

ちなみにこれCentOS7だとaclocal-1.13なのでやっぱり嫌がられる。

$ sudo ln -s /usr/bin/aclocal-1.16 /usr/bin/aclocal-1.15
$ sudo ln -s /usr/bin/automake-1.16 /usr/bin/automake-1.15

1.13 -> 1.15へのリンクは憚られたけど、1.16 -> 1.15なら互換性あるかなと軽く思い込んでシンボリックリンクで済ませてしまう()

$ make
..
libtool: link: rm -fr .libs/libaudit_plugin.lax
libtool: link: ( cd ".libs" && rm -f "libaudit_plugin.la" && ln -s "../libaudit_plugin.la" "libaudit_plugin.la" )
make[1]: Leaving directory '/home/yoku0825/git/mysql-audit/src'
make[1]: Entering directory '/home/yoku0825/git/mysql-audit'
make[1]: Nothing to be done for 'all-am'.
make[1]: Leaving directory '/home/yoku0825/git/mysql-audit'

$ make install
..

$ ll /home/yoku0825/audit_plugin/
total 17040
-rw-r--r--. 1 yoku0825 yoku0825 12445670 Nov 21 04:57 libaudit_plugin.a
-rwxr-xr-x. 1 yoku0825 yoku0825      996 Nov 21 04:57 libaudit_plugin.la
lrwxrwxrwx. 1 yoku0825 yoku0825       24 Nov 21 04:57 libaudit_plugin.so -> libaudit_plugin.so.0.0.0
lrwxrwxrwx. 1 yoku0825 yoku0825       24 Nov 21 04:57 libaudit_plugin.so.0 -> libaudit_plugin.so.0.0.0
-rwxr-xr-x. 1 yoku0825 yoku0825  4994296 Nov 21 04:57 libaudit_plugin.so.0.0.0

出来上がった。

$ bash ./offset-extract/offset-extract.sh /usr/mysql/8.0.35/bin/mysqld
//offsets for: /usr/mysql/8.0.35/bin/mysqld (8.0.35)
{"8.0.35","d9bdda3fe1822230d5b5d265b9359ffc", 9496, 9536, 4952, 6436, 1288, 0, 0, 32, 64, 160, 1376, 9636, 6056, 4248, 4256, 4260, 7720, 1576, 32, 8680, 8720, 8704, 12880, 140, 664, 320},

あとはこれで.soファイルをコピーしてmy.cnfを編集してINSTALL PLUGINしたりすれば一応動きそう

2023/11/08

SHOW PROCESSLISTとinformation_schema.processlistとperformance_schema.processlistと

TL;DR

呼び出し元エントリーポイントリスト関数
SHOW PROCESSLIST (option=OFF)mysqld_list_processesGlobal_THD_manager::do_for_all_thd_copy
information_schema.processlistfill_schema_processlistGlobal_THD_manager::do_for_all_thd_copy
performance_schema.processlisttable_processlist::make_rowtable_processlist::read_row_values
SHOW PROCESSLIST (option=ON)table_processlist::make_rowtable_processlist::read_row_values

MySQL 8.2.0で information_schema.processlist がdeprecatedになり、今までの SHOW PROCESSLIST も performance_schema.processlist からのSELECTに書き換えられる予定だというリリースノートがあった。

https://dev.mysql.com/doc/relnotes/mysql/8.2/en/news-8-2-0.html

前からオラクル青山のセミナーとかで「SHOW PROCESSLISTやinformation_schema.processlistはmutex取るからオススメしない、performance_schemaのthreadsやprocesslistがオススメ」って言われていた(現地で聞いた気がするのでたぶん2020以前だと思うんだけど)

MySQL 5.7.39とそれ以降から performance_schema_show_processlist=ONにすると SHOW PROCESSLIST は performance_schema.processlist からのSELECTに内部的にディスパッチされる。

(8.2.0でそもそもinformation_schema.processlistが非推奨でperformance_schema.processlistが当然のデフォルトになるようなので、この変数自体も8.2.0とそれ以降では非推奨)

ネイティブな ( デフォルトの performance_schema_show_processlist=OFF のままの) SHOW PROCESSLIST

(gdb) bt
+bt
#0  mysqld_list_processes(THD*, char const*, bool, bool) () at /home/yoku0825/mysql-8.0.35/sql/sql_show.cc:2961
#1  0x0000000000e41602 in Sql_cmd_show_processlist::execute_inner(THD*) () at /home/yoku0825/mysql-8.0.35/sql/sql_class.h:1276
#2  0x0000000000e200c4 in Sql_cmd_dml::execute(THD*) () at /home/yoku0825/mysql-8.0.35/sql/sql_select.cc:793
#3  0x0000000000dc63a1 in mysql_execute_command(THD*, bool) () at /home/yoku0825/mysql-8.0.35/sql/sql_parse.cc:4719
#4  0x0000000000dca030 in dispatch_sql_command(THD*, Parser_state*) () at /home/yoku0825/mysql-8.0.35/sql/sql_parse.cc:5368
#5  0x0000000000dcb39e in dispatch_command(THD*, COM_DATA const*, enum_server_command) () at /home/yoku0825/mysql-8.0.35/sql/sql_parse.cc:2054
#6  0x0000000000dcd727 in do_command (thd=thd@entry=0x7fec74000d20) at /home/yoku0825/mysql-8.0.35/sql/sql_parse.cc:1439
#7  0x0000000000f24500 in handle_connection (arg=arg@entry=0x6cc4830) at /home/yoku0825/mysql-8.0.35/sql/conn_handler/connection_handler_per_thread.cc:302
#8  0x00000000024f91b5 in pfs_spawn_thread (arg=0x6be2d20) at /home/yoku0825/mysql-8.0.35/storage/perfschema/pfs.cc:3042
#9  0x00007fecd4b28ea5 in start_thread (arg=0x7fecc0657700) at pthread_create.c:307
#10 0x00007fecd3142b0d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:111

SELECT * FROM information_schema.processlist

(gdb) bt
+bt
#0  fill_schema_processlist (thd=0x7fec74000d20, tables=0x7fec7400d630) at /home/yoku0825/mysql-8.0.35/sql/sql_show.cc:3212
#1  0x0000000000e38db5 in do_fill_information_schema_table(THD*, Table_ref*, Item*) () at /home/yoku0825/mysql-8.0.35/sql/sql_show.cc:4904
#2  0x0000000001305a4d in MaterializeInformationSchemaTableIterator::Init (this=0x7fec74020118) at /home/yoku0825/mysql-8.0.35/sql/iterators/row_iterator.h:227
#3  0x0000000000e9f65c in Query_expression::ExecuteIteratorQuery(THD*) () at /opt/rh/devtoolset-11/root/usr/include/c++/11/bits/unique_ptr.h:421
#4  0x0000000000e9fa7c in Query_expression::execute(THD*) () at /home/yoku0825/mysql-8.0.35/sql/sql_union.cc:1823
#5  0x0000000000e200c4 in Sql_cmd_dml::execute(THD*) () at /home/yoku0825/mysql-8.0.35/sql/sql_select.cc:793
#6  0x0000000000dc63a1 in mysql_execute_command(THD*, bool) () at /home/yoku0825/mysql-8.0.35/sql/sql_parse.cc:4719
#7  0x0000000000dca030 in dispatch_sql_command(THD*, Parser_state*) () at /home/yoku0825/mysql-8.0.35/sql/sql_parse.cc:5368
#8  0x0000000000dcb39e in dispatch_command(THD*, COM_DATA const*, enum_server_command) () at /home/yoku0825/mysql-8.0.35/sql/sql_parse.cc:2054
#9  0x0000000000dcd727 in do_command (thd=thd@entry=0x7fec74000d20) at /home/yoku0825/mysql-8.0.35/sql/sql_parse.cc:1439
#10 0x0000000000f24500 in handle_connection (arg=arg@entry=0x6cc4830) at /home/yoku0825/mysql-8.0.35/sql/conn_handler/connection_handler_per_thread.cc:302
#11 0x00000000024f91b5 in pfs_spawn_thread (arg=0x6be2d20) at /home/yoku0825/mysql-8.0.35/storage/perfschema/pfs.cc:3042
#12 0x00007fecd4b28ea5 in start_thread (arg=0x7fecc0657700) at pthread_create.c:307
#13 0x00007fecd3142b0d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:111

SELECT * FROM performance_schema.processlist

(gdb) bt
+bt
#0  table_processlist::make_row(PFS_thread*) () at /home/yoku0825/mysql-8.0.35/storage/perfschema/table_processlist.cc:157
#1  0x00000000024ef861 in rnd_next (buf=0x7fec740b9480 "\377", this=0x7fec740b7de0) at /home/yoku0825/mysql-8.0.35/storage/perfschema/ha_perfschema.cc:1722
#2  ha_perfschema::rnd_next (this=0x7fec740b7de0, buf=0x7fec740b9480 "\377") at /home/yoku0825/mysql-8.0.35/storage/perfschema/ha_perfschema.cc:1713
#3  0x0000000001040b2c in handler::ha_rnd_next (this=0x7fec740b7de0, buf=0x7fec740b9480 "\377") at /home/yoku0825/mysql-8.0.35/sql/handler.cc:2971
#4  0x000000000119467b in TableScanIterator::Read (this=0x7fec740a83f8) at /home/yoku0825/mysql-8.0.35/sql/iterators/row_iterator.h:245
#5  0x0000000000e9f6e3 in Query_expression::ExecuteIteratorQuery(THD*) () at /opt/rh/devtoolset-11/root/usr/include/c++/11/bits/unique_ptr.h:421
#6  0x0000000000e9fa7c in Query_expression::execute(THD*) () at /home/yoku0825/mysql-8.0.35/sql/sql_union.cc:1823
#7  0x0000000000e200c4 in Sql_cmd_dml::execute(THD*) () at /home/yoku0825/mysql-8.0.35/sql/sql_select.cc:793
#8  0x0000000000dc63a1 in mysql_execute_command(THD*, bool) () at /home/yoku0825/mysql-8.0.35/sql/sql_parse.cc:4719
#9  0x0000000000dca030 in dispatch_sql_command(THD*, Parser_state*) () at /home/yoku0825/mysql-8.0.35/sql/sql_parse.cc:5368
#10 0x0000000000dcb39e in dispatch_command(THD*, COM_DATA const*, enum_server_command) () at /home/yoku0825/mysql-8.0.35/sql/sql_parse.cc:2054
#11 0x0000000000dcd727 in do_command (thd=thd@entry=0x7fec74000d20) at /home/yoku0825/mysql-8.0.35/sql/sql_parse.cc:1439
#12 0x0000000000f24500 in handle_connection (arg=arg@entry=0x6cc4830) at /home/yoku0825/mysql-8.0.35/sql/conn_handler/connection_handler_per_thread.cc:302
#13 0x00000000024f91b5 in pfs_spawn_thread (arg=0x6be2d20) at /home/yoku0825/mysql-8.0.35/storage/perfschema/pfs.cc:3042
#14 0x00007fecd4b28ea5 in start_thread (arg=0x7fecc0657700) at pthread_create.c:307
#15 0x00007fecd3142b0d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:111

performance_schema_show_processlist=ON にした SHOW PROCESSLIST

(gdb) bt
+bt
#0  table_processlist::make_row(PFS_thread*) () at /home/yoku0825/mysql-8.0.35/storage/perfschema/table_processlist.cc:157
#1  0x00000000024ef861 in rnd_next (buf=0x7fec740b9480 "\377", this=0x7fec740b7de0) at /home/yoku0825/mysql-8.0.35/storage/perfschema/ha_perfschema.cc:1722
#2  ha_perfschema::rnd_next (this=0x7fec740b7de0, buf=0x7fec740b9480 "\377") at /home/yoku0825/mysql-8.0.35/storage/perfschema/ha_perfschema.cc:1713
#3  0x0000000001040b2c in handler::ha_rnd_next (this=0x7fec740b7de0, buf=0x7fec740b9480 "\377") at /home/yoku0825/mysql-8.0.35/sql/handler.cc:2971
#4  0x000000000119467b in TableScanIterator::Read (this=0x7fec740c39c0) at /home/yoku0825/mysql-8.0.35/sql/iterators/row_iterator.h:245
#5  0x0000000001309f12 in MaterializeIterator<DummyIteratorProfiler>::MaterializeQueryBlock (this=this@entry=0x7fec740c3aa0, query_block=
      Python Exception <class 'gdb.error'> There is no member or method named _M_head_impl.:
@0x7fec740c3a50: {subquery_iterator = , select_number = 2, join = 0x7fec740c1fe0, disable_deduplication_by_hash_field = false, copy_items = true, m_total_operands = 0, m_operand_idx = 0, m_first_distinct = 0, temp_table_param = 0x7fec740c2150, is_recursive_reference = false, recursive_reader = 0x0}, stored_rows=stored_rows@entry=0x7fecc0654880)
    at /opt/rh/devtoolset-11/root/usr/include/c++/11/bits/unique_ptr.h:421
#6  0x000000000130af13 in MaterializeIterator<DummyIteratorProfiler>::Init (this=0x7fec740c3aa0) at /home/yoku0825/mysql-8.0.35/sql/iterators/composite_iterators.cc:928
#7  0x0000000000e9f65c in Query_expression::ExecuteIteratorQuery(THD*) () at /opt/rh/devtoolset-11/root/usr/include/c++/11/bits/unique_ptr.h:421
#8  0x0000000000e9fa7c in Query_expression::execute(THD*) () at /home/yoku0825/mysql-8.0.35/sql/sql_union.cc:1823
#9  0x0000000000e200c4 in Sql_cmd_dml::execute(THD*) () at /home/yoku0825/mysql-8.0.35/sql/sql_select.cc:793
#10 0x0000000000dc63a1 in mysql_execute_command(THD*, bool) () at /home/yoku0825/mysql-8.0.35/sql/sql_parse.cc:4719
#11 0x0000000000dca030 in dispatch_sql_command(THD*, Parser_state*) () at /home/yoku0825/mysql-8.0.35/sql/sql_parse.cc:5368
#12 0x0000000000dcb39e in dispatch_command(THD*, COM_DATA const*, enum_server_command) () at /home/yoku0825/mysql-8.0.35/sql/sql_parse.cc:2054
#13 0x0000000000dcd727 in do_command (thd=thd@entry=0x7fec74000d20) at /home/yoku0825/mysql-8.0.35/sql/sql_parse.cc:1439
#14 0x0000000000f24500 in handle_connection (arg=arg@entry=0x6cc4830) at /home/yoku0825/mysql-8.0.35/sql/conn_handler/connection_handler_per_thread.cc:302
#15 0x00000000024f91b5 in pfs_spawn_thread (arg=0x6be2d20) at /home/yoku0825/mysql-8.0.35/storage/perfschema/pfs.cc:3042
#16 0x00007fecd4b28ea5 in start_thread (arg=0x7fecc0657700) at pthread_create.c:307
#17 0x00007fecd3142b0d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:111

2023/11/06

ソースビルドのmysqldでthdがgdbで掴めない (MINIMAL_RELWITHDEBINFO=ON)

TL;DR

  • 8.0.29とそれ以降でソースビルドをしてる人だけだと思う
  • cmake する時に -DMINIMAL_RELWITHDEBINFO=OFF する

gdbでmysqldにアタッチした時に色々見つからなくて困った。thdとか全然見えない。

$ gdb -p $(pidof mysqld)
(gdb) b PT_show_processlist::make_cmd
+b PT_show_processlist::make_cmd
Breakpoint 1 at 0x122eaec: file /home/yoku0825/mysql-8.0.35/sql/parse_tree_nodes.cc, line 2722.
(gdb) c
+c
Continuing.
[Switching to Thread 0x7fe5dc2e9700 (LWP 13041)]

Breakpoint 1, PT_show_processlist::make_cmd () at /home/yoku0825/mysql-8.0.35/sql/parse_tree_nodes.cc:2722
2722  lex->sql_command = m_sql_command;
(gdb) n
+n
2725  bool use_pfs = pfs_processlist_enabled;
(gdb) n
+n
2727  m_sql_cmd.set_use_pfs(use_pfs);
(gdb) p use_pfs
+p use_pfs
No symbol "use_pfs" in current context.
(gdb) n
+n
2728  if (use_pfs) {
(gdb) p use_pfs
+p use_pfs
No symbol "use_pfs" in current context.
(gdb) n
+n
2729    if (build_processlist_query(m_pos, thd, m_sql_cmd.verbose()))
(gdb) n
+n
2733  return &m_sql_cmd;
(gdb) p m_sql_cmd
+p m_sql_cmd
No symbol "m_sql_cmd" in current context.
(gdb) p thd->s m_sql_cmd
+p thd->m_sql_cmd
No symbol "thd" in current context.

おかしいなあと思ってたけど、何気なく cmake3 -LA | grep -i relwith ってやったら MINIMAL_RELWITHDEBINFO なんていかにも怪しいオプションがONになっているのを見つけた。

$ cmake3 -LA | grep -i relwith
..
CMAKE_ASM_FLAGS_RELWITHDEBINFO:STRING=-O2 -g -DNDEBUG
CMAKE_BUILD_TYPE:STRING=RelWithDebInfo
CMAKE_CXX_FLAGS_RELWITHDEBINFO:STRING=-O2 -g -DNDEBUG
CMAKE_C_FLAGS_RELWITHDEBINFO:STRING=-O2 -g -DNDEBUG
CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO:STRING=
CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO:STRING=
CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO:STRING=
CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO:STRING=
MINIMAL_RELWITHDEBINFO:BOOL=ON

OFFにしてコンパイルし直す。

$ cmake3 -DMINIMAL_RELWITHDEBINFO=OFF .
$ make

見えるようになった。

(gdb) b PT_show_processlist::make_cmd
+b PT_show_processlist::make_cmd
Breakpoint 1 at 0x122eaf9: file /home/yoku0825/mysql-8.0.35/sql/parse_tree_nodes.cc, line 2725.
(gdb) c
+c
Continuing.
[Switching to Thread 0x7fce486f6700 (LWP 29941)]

Breakpoint 1, PT_show_processlist::make_cmd (this=0x7fce0c00b000, thd=0x7fce0c010580) at /home/yoku0825/mysql-8.0.35/sql/parse_tree_nodes.cc:2725
2725      bool use_pfs = pfs_processlist_enabled;
(gdb) bt
+bt
#0  PT_show_processlist::make_cmd (this=0x7fce0c00b000, thd=0x7fce0c010580) at /home/yoku0825/mysql-8.0.35/sql/parse_tree_nodes.cc:2725
#1  0x0000000000d9c5a7 in LEX::make_sql_cmd (this=0x7fce0c013990, parse_tree=<optimized out>) at /home/yoku0825/mysql-8.0.35/sql/sql_lex.cc:4949
#2  0x0000000000d3618a in THD::sql_parser (this=this@entry=0x7fce0c010580) at /home/yoku0825/mysql-8.0.35/sql/sql_class.cc:3066
#3  0x0000000000dc50b5 in parse_sql (thd=thd@entry=0x7fce0c010580, parser_state=parser_state@entry=0x7fce486f4ae0, creation_ctx=creation_ctx@entry=0x0) at /home/yoku0825/mysql-8.0.35/sql/sql_parse.cc:7132
#4  0x0000000000dc9d5d in dispatch_sql_command(THD*, Parser_state*) () at /home/yoku0825/mysql-8.0.35/sql/sql_parse.cc:5265
#5  0x0000000000dcb39e in dispatch_command(THD*, COM_DATA const*, enum_server_command) () at /home/yoku0825/mysql-8.0.35/sql/sql_parse.cc:2054
#6  0x0000000000dcd727 in do_command (thd=thd@entry=0x7fce0c010580) at /home/yoku0825/mysql-8.0.35/sql/sql_parse.cc:1439
#7  0x0000000000f24500 in handle_connection (arg=arg@entry=0x73d11f0) at /home/yoku0825/mysql-8.0.35/sql/conn_handler/connection_handler_per_thread.cc:302
#8  0x00000000024f91b5 in pfs_spawn_thread (arg=0x74b0b10) at /home/yoku0825/mysql-8.0.35/storage/perfschema/pfs.cc:3042
#9  0x00007fce78163ea5 in start_thread () from /lib64/libpthread.so.0
#10 0x00007fce7677db0d in clone () from /lib64/libc.so.6
(gdb) p use_pfs
+p use_pfs
$1 = <optimized out>
(gdb) p thd
+p thd
$2 = (THD *) 0x7fce0c010580