时间:2021-07-01 10:21:17 帮助过:26人阅读
#10 0x0000000000cb47fe in do_command (thd=0x7f32512b7000)and check thread_id item of this structure.
at /usr/src/debug/percona-server-5.7.18-15/percona-server-5.7.18-15/sql/sql_parse.cc:960
(gdb) thread 2I prefer to double check my suggestions before making them, so I immediately tried this with my CentOS 6.9 VM running recent Percona Server 5.7.x by default since that times when I worked at Percona:
[Switching to thread 2 (Thread 0x7f7f5ce02b00 (LWP 9232))]
#0 pthread_cond_timedwait@@GLIBC_2.3.2 ()
at ../nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S:238
238 ../nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S: No such file or directory.
(gdb) p do_command::thd->thread_id
$9 = 14
[root@centos ~]# gdb -p `pidof mysqld`As you can see I started to check threads one by one and apply that good old trick. Thread 1 had no frame executing do_command(), but I did not gave up and proceeded to the next thread, as I knew I had at least one active connection (I checked the output of SHOW PROCESSLIST). There I had a surprise, no way to get thread_id of thd. I used tab completion, so I know that thread_id (variable or method) exists, but attempt to call it also failed as you can see.
GNU gdb (GDB) Red Hat Enterprise Linux (7.2-92.el6)
...
Loaded symbols for /usr/lib64/mysql/plugin/tokudb_backup.so
0x00007f550ad35383 in poll () from /lib64/libc.so.6
Missing separate debuginfos, use: debuginfo-install glibc-2.12-1.209.el6_9.2.x86_64 jemalloc-3.6.0-1.el6.x86_64 keyutils-libs-1.4-5.el6.x86_64 krb5-libs-1.10.3-65.el6.x86_64 libaio-0.3.107-10.el6.x86_64 libcom_err-1.41.12-23.el6.x86_64 libgcc-4.4.7-18.el6.x86_64 libselinux-2.0.94-7.el6.x86_64 libstdc++-4.4.7-18.el6.x86_64 nss-softokn-freebl-3.14.3-23.3.el6_8.x86_64 numactl-2.0.9-2.el6.x86_64 openssl-1.0.1e-57.el6.x86_64 zlib-1.2.3-29.el6.x86_64
(gdb) thread 1
[Switching to thread 1 (Thread 0x7f550d2b2820 (LWP 1978))]#0 0x00007f550ad35383 in poll () from /lib64/libc.so.6
(gdb) p do_command::thd->thread_id
No frame is currently executing in block do_command(THD*).
(gdb) thread 2
[Switching to thread 2 (Thread 0x7f54d837b700 (LWP 2183))]#0 0x00007f550ad35383 in poll () from /lib64/libc.so.6
(gdb) p do_command::thd->thread_id
Cannot take address of method thread_id.
(gdb) call do_command::thd->thread_id()
Cannot evaluate function -- may be inlined
[root@centos mysql-server]# grep -n "class THD" sql/*.hI found the following there:
sql/debug_sync.h:27:class THD;
sql/derror.h:24:class THD;
sql/event_data_objects.h:40:class THD;
...
sql/sql_class.h:1412:class THD :public MDL_context_owner,
sql/sql_class.h:4175: raise_error() or raise_warning() methods provided by class THD.
sql/sql_cmd.h:25:class THD;
...
class THD :public MDL_context_owner,So, in MySQL 5.7 thread_id() is, indeed, a method that was inlined, and essentially it returns private m_thread_id item. Benefits of C++... I had highlighted Global_THD_manager singleton also as during my next gdb sessions I had found out that simple global list of threads is also gone and in 5.7 everything is done via that Global_THD_manager. This is a topic for some other post, though.
public Query_arena,
public Open_tables_state
{
...
private:
my_thread_id m_thread_id;public:
...
/**
Assign a value to m_thread_id by calling
Global_THD_manager::get_new_thread_id().
*/
void set_new_thread_id();
my_thread_id thread_id() const { return m_thread_id; }...
...So, I know that specific thread 7 was for a session with Id 86 in the output of SHOW PROCESSLIST, and (from m_main_security_ctx, also a new name for old things in 5.7) I know it was a session of myuser connecting locally.
(gdb) thread 7[Switching to thread 7 (Thread 0x7f54d8236700 (LWP 2275))]#0 0x00007f550ad35383 in poll () from /lib64/libc.so.6
(gdb) p do_command::thd->m_thread_id
$1 = 86
(gdb) p do_command::thd->m_main_security_ctx
$3 = {m_user = {m_ptr = 0x7f5500fdaf90 "myuser", m_length = 6,
m_charset = 0x1ded640, m_alloced_length = 8, m_is_alloced = true},
m_host = {m_ptr = 0x7f54d98ab090 "localhost", m_length = 9,
m_charset = 0x1ded640, m_alloced_length = 16, m_is_alloced = true},
m_ip = {m_ptr = 0x7f54f0eb0210 "127.0.0.1", m_length = 9,
m_charset = 0x1ded640, m_alloced_length = 16, m_is_alloced = true},
m_host_or_ip = {m_ptr = 0x7f54d98ab090 "localhost", m_length = 9,
m_charset = 0x1ded640, m_alloced_length = 0, m_is_alloced = false},
m_external_user = {m_ptr = 0x15167ab "", m_length = 0,
m_charset = 0x1ded640, m_alloced_length = 0, m_is_alloced = false},
m_priv_user = "myuser", ‘\000‘ <repeats 89 times>, m_priv_user_length = 6,
m_proxy_user = ‘\000‘ <repeats 161 times>, m_proxy_user_length = 0,
m_priv_host = "localhost", ‘\000‘ <repeats 51 times>,
m_priv_host_length = 9, m_master_access = 1589248, m_db_access = 0,
m_password_expired = false}
...
How to Find Processlist Thread id in gdb !!!!!GDB 使用
标签:lte openssl parse efault log style manage dir inline