shenkonghui / issue

问题记录
0 stars 0 forks source link

mysql源码问题集合 #154

Open shenkonghui opened 2 years ago

shenkonghui commented 2 years ago

使用THD对象提示“不允许指针指向不完整的类类型 "THD"C/C++(393)” bpc_thd->xxx 语句

#include "sql_class.h"

THD *bpc_thd = NULL;

void test(){
    struct st_mysql_const_lex_string new_db;
    const char *db = "test";
    new_db.str = db;
    new_db.length = strlen(db);
    bpc_thd->reset_db(new_db);
}

需要增加以下定义才行

#ifndef MYSQL_SERVER
#define MYSQL_SERVER
#endif
shenkonghui commented 2 years ago

安装插件失败

ERROR 1126 (HY000): Can't open shared library '/usr/lib64/mysql/plugin/recycle_bin.so' (errno: 2 /usr/lib64/mysql/plugin/recycle_bin.so: undefined symbol: _Z21filename_to_tablenamePKcPcmb)

列出符号清单,仔细发现最后变量_Z21filename_to_tablenamePKcPcm最后一位少了个"b"

bash-4.2# nm  -D mysqld |grep filename_to_tablename
0000000000d2f7b0 T _Z21filename_to_tablenamePKcPcm

filename_to_tablename代表变量的名称 前缀是返回值类型缩写 后缀是参数类型缩写 pointer(P) const(K) char(c) ...

查看filename_to_tablename函数的定义,最后一位b代表bool,如果没有定义了NDEBUG,则增加一个参数

size_t filename_to_tablename(const char *from, char *to, size_t to_length
#ifndef NDEBUG
                           , bool stay_quiet
#endif /* NDEBUG */
                           )

增加NDEBUG的定义

#ifndef NDEBUG
#define NDEBUG
#endif

再次执行,安装成功

mysql> INSTALL PLUGIN recycle_bin SONAME "recycle_bin.so";
Query OK, 0 rows affected (0.68 sec)
shenkonghui commented 2 years ago

mysql崩溃, 查看堆栈

(gdb) bt
#0  0x00007fffd42807fe in Diagnostics_area::is_error (this=0x0)
    at /root/src/mysql-server-mysql-5.7.35/sql/sql_error.h:374

发现是thd->get_stmt_da() 为空指针引起的

bool err= bdq_backup_thd->get_stmt_da()->is_error();

get_stmt_da() 返回Diagnostics_area对象,用于内核诊断

自己编译的mysqld文件没有问题,采用社区的mysql dokcer镜像报错误. 怀疑使用了NDEBUG宏,导致了无法使用诊断功能, 其他方法依赖该宏,只能注释掉get_stmt_da

shenkonghui commented 2 years ago

mysql崩溃

Thread 28 "mysqld" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fffe291d700 (LWP 23615)]
0x0000000000ca61f0 in lex_one_token(YYSTYPE*, THD*) ()
Missing separate debuginfos, use: debuginfo-install keyutils-libs-1.5.8-3.el7.x86_64 krb5-libs-1.15.1-51.el7_9.x86_64 libaio-0.3.109-13.el7.x86_64 libcom_err-1.42.9-19.el7.x86_64 libgcc-4.8.5-44.el7.x86_64 libselinux-2.5-15.el7.x86_64 libstdc++-4.8.5-44.el7.x86_64 nss-softokn-freebl-3.53.1-6.el7_9.x86_64 numactl-libs-2.0.12-5.el7.x86_64 openssl-libs-1.0.2k-22.el7_9.x86_64 pcre-8.32-17.el7.x86_64 zlib-1.2.7-19.el7_9.x86_64
(gdb) bt
#0  0x0000000000ca61f0 in lex_one_token(YYSTYPE*, THD*) ()
#1  0x0000000000ca814f in MYSQLlex(YYSTYPE*, YYLTYPE*, THD*) ()
#2  0x0000000000dae60c in MYSQLparse(THD*) ()
#3  0x0000000000cd08f4 in parse_sql(THD*, Parser_state*, Object_creation_ctx*) ()
#4  0x00007fffd427ea6f in bdq_backup (
    drop_query=0x7fffb40191b0 "DROP TABLE `t1` /* generated by server */", 
    db=0x7fffb40194c0 "test_hello", backup_dir=0x1db9d80 <home_dir_buff> "/root", 
    back_len=65)
    at /root/src/mysql-server-mysql-5.7.35/plugin/MySQL-Plugin-Recycle-Bin/src/bdq_plugin.cc:402
#5  0x00007fffd427f18c in bdq_read_event (param=0x7fffe291c900, 
    packet=0x7fffb4014db1 "0\343\331a\002\001", len=127, event_buf=0x7fffe291cab0, 
    event_len=0x7fffe291cac0)
    at /root/src/mysql-server-mysql-5.7.35/plugin/MySQL-Plugin-Recycle-Bin/src/bdq_plugin.cc:660
#6  0x0000000000c37a39 in Binlog_relay_IO_delegate::after_read_event(THD*, Master_info*, char const*, unsigned long, char const**, unsigned long*) ()
#7  0x0000000000ec6ddc in handle_slave_io ()
#8  0x00000000012852e4 in pfs_spawn_thread ()
#9  0x00007ffff7bc6ea5 in start_thread () from /lib64/libpthread.so.0
#10 0x00007ffff5fa99fd in clone () from /lib64/libc.so.6

只能定位到lex_one_token函数,无法更加精确到哪一行