gdb mysql_GDB 调试 Mysql 实战(二)GDB 调试打印

背景

在 https://mengkang.net/1328.html 实验中,我们通过optimizer_trace发现group by会使用intermediate_tmp_table,而且里面的的row_length是20,抱着"打破砂锅问到底"的求学精神,所以想通过 gdb 调试源码的方式看这个row_length为什么是20.

通过row_length关键字,我定位到了mysql 5.7 源码里面的sql/sql_tmp_table.cc文件

a82fade4c0d1fe9dc8551cee777b381f.png

实际操作

查找 mysql pid

[root@localhost ~]# ps -ef|grep mysql

root 3739 1 0 09:36 ? 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/var/lib/mysql --pid-file=/var/lib/mysql/localhost.localdomain.pid

mysql 3894 3739 0 09:36 ? 00:00:01 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/var/lib/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/var/log/mariadb/mariadb.log --pid-file=/var/lib/mysql/localhost.localdomain.pid --socket=/var/lib/mysql/mysql.sock

root 3956 3940 0 09:48 pts/1 00:00:00 mysql -uroot -px xxxx

root 4002 3985 0 10:11 pts/2 00:00:00 grep --color=auto mysql

启动 gdb

[root@localhost ~]# gdb

GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-114.el7

Copyright (C) 2013 Free Software Foundation, Inc.

License GPLv3+: GNU GPL version 3 or later

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".

For bug reporting instructions, please see:

.

attach pid

(gdb) attach 3894

设置断点

(gdb) b trace_tmp_table

Breakpoint 1 at 0x15e1eeb: file /root/newdb/mysql-server/sql/sql_tmp_table.cc, line 2300.

或者

(gdb) b /root/newdb/mysql-server/sql/sql_tmp_table.cc:2306

Breakpoint 1 at 0x15e1f8e: file /root/newdb/mysql-server/sql/sql_tmp_table.cc, line 2306.

客户端连接

[root@localhost ~]# mysql -uroot -p1234

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值