91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

GDB調試MySQL

發布時間:2020-08-06 16:40:05 來源:ITPUB博客 閱讀:227 作者:javenzhen 欄目:MySQL數據庫
GDB主要幫助你完成下面四個方面的功能:
1、啟動你的程序,可以按照你的自定義的要求隨心所欲的運行程序。
2、可讓被調試的程序在你所指定的調置的斷點處停住。(斷點可以是條件表達式)
3、當程序被停住時,可以檢查此時你的程序中所發生的事。
4、你可以改變你的程序,將一個BUG產生的影響修正從而測試其他BUG。

在學習Oracle的時候使用GDB調試,主要是關于學習Oracle的閂鎖原理,那么,為什么要用GDB調試MySQL
1.識別故障
2.場景重現
3.創建測試案例確認BUG
4.定位缺陷根源
5.測試和創建補丁修復BUG

下面開始學習GDB調試MySQL
1、安裝編譯MySQL需要的軟件包
yum install -y cmake make gcc gcc-c++ ncurses-devel bison gdb

2、編譯MySQL
# git clone https://github.com/mysql/mysql-server.git
# cd mysql-server
# git checkout mysql-5.7.19
# cd BUILD; cmake .. -DDOWNLOAD_BOOST=1 -DWITH_DEBUG=1 -DWITH_UNIT_TESTS=off
# make
# make install

3、連接MySQL程序
3.1、查看MySQL進程ID
[root@debug ~]# ps -ef | grep mysql
root     24589     1  0 07:58 ?        00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql
mysql    24794 24589  0 07:58 ?        00:00:01 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/usr/local/mysql/data/mysql-debug.log --pid-file=debug.pid --socket=/tmp/mysql.sock --port=3306
root     25009 24993  0 11:29 pts/2    00:00:00 grep mysql

3.2、GDB使用attach連接MySQL進程ID
[root@debug ~]# gdb
GNU gdb (GDB) Red Hat Enterprise Linux (7.2-92.el6)
Copyright (C) 2010 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".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
(gdb) attach 24794
Attaching to process 24794
Reading symbols from /usr/local/mysql/bin/mysqld...done.
Reading symbols from /lib64/libpthread.so.0...(no debugging symbols found)...done.
[New LWP 24969]
[New LWP 24824]
[New LWP 24821]
[New LWP 24820]
[New LWP 24819]
[New LWP 24818]
[New LWP 24817]
[New LWP 24816]
[New LWP 24815]
[New LWP 24814]
[New LWP 24813]
[New LWP 24812]
[New LWP 24811]
[New LWP 24810]
[New LWP 24809]
[New LWP 24808]
[New LWP 24806]
[New LWP 24805]
[New LWP 24804]
[New LWP 24803]
[New LWP 24802]
[New LWP 24801]
[New LWP 24800]
[New LWP 24799]
[New LWP 24798]
[New LWP 24797]
[New LWP 24796]
[New LWP 24795]
[Thread debugging using libthread_db enabled]
Loaded symbols for /lib64/libpthread.so.0
Reading symbols from /lib64/libcrypt.so.1...(no debugging symbols found)...done.
Loaded symbols for /lib64/libcrypt.so.1
Reading symbols from /lib64/libdl.so.2...(no debugging symbols found)...done.
Loaded symbols for /lib64/libdl.so.2
Reading symbols from /lib64/librt.so.1...(no debugging symbols found)...done.
Loaded symbols for /lib64/librt.so.1
Reading symbols from /usr/lib64/libstdc++.so.6...(no debugging symbols found)...done.
Loaded symbols for /usr/lib64/libstdc++.so.6
Reading symbols from /lib64/libm.so.6...(no debugging symbols found)...done.
Loaded symbols for /lib64/libm.so.6
Reading symbols from /lib64/libgcc_s.so.1...(no debugging symbols found)...done.
Loaded symbols for /lib64/libgcc_s.so.1
Reading symbols from /lib64/libc.so.6...(no debugging symbols found)...done.
Loaded symbols for /lib64/libc.so.6
Reading symbols from /lib64/ld-linux-x86-64.so.2...(no debugging symbols found)...done.
Loaded symbols for /lib64/ld-linux-x86-64.so.2
Reading symbols from /lib64/libfreebl3.so...(no debugging symbols found)...done.
Loaded symbols for /lib64/libfreebl3.so
Reading symbols from /lib64/libnss_files.so.2...(no debugging symbols found)...done.
Loaded symbols for /lib64/libnss_files.so.2
0x00007f8801dfd383 in poll () from /lib64/libc.so.6
Missing separate debuginfos, use: debuginfo-install glibc-2.12-1.209.el6_9.2.x86_64 libgcc-4.4.7-18.el6.x86_64 libstdc++-4.4.7-18.el6.x86_64 nss-softokn-freebl-3.14.3-23.el6_7.x86_64

4、設置斷點
4.1、查看插入語句的源碼sql_insert.cc的423行的函數Sql_cmd_insert::mysql_insert
bool Sql_cmd_insert::mysql_insert(THD *thd,TABLE_LIST *table_list)
{
  DBUG_ENTER("mysql_insert");

  LEX *const lex= thd->lex;
  int error, res;
  bool err= true;
  bool transactional_table, joins_freed= FALSE;
  bool changed;
  bool is_locked= false;
  ulong counter= 0;
  ulonglong id;

4.2、在session1中的gdb設置insert的斷點
(gdb) b Sql_cmd_insert::mysql_insert
Breakpoint 1 at 0x17bd1b9: file /root/mysql-server/sql/sql_insert.cc, line 423.

4.3、查看斷點信息,從下往上看,使用到了多個MySQL函數。
(gdb) bt
#0  0x00007f8801dfd383 in poll () from /lib64/libc.so.6
#1  0x00000000016c1155 in Mysqld_socket_listener::listen_for_connection_event (this=0x45d8870)
    at /root/mysql-server/sql/conn_handler/socket_connection.cc:852
#2  0x0000000000ece89c in Connection_acceptor<Mysqld_socket_listener>::connection_event_loop (this=0x45b5ec0)
    at /root/mysql-server/sql/conn_handler/connection_acceptor.h:66
#3  0x0000000000ec6226 in mysqld_main (argc=17, argv=0x3ab4248) at /root/mysql-server/sql/mysqld.cc:5045
#4  0x0000000000ebd2d4 in main (argc=9, argv=0x7fffb2aa7408) at /root/mysql-server/sql/main.cc:25

4.4、在設置了斷點之后,在另一個session2中登錄數據庫,發現無法登錄,hung住了,在gdb中執行next(執行下一步代碼),可以看到在socket_connection.cc源碼第859行無法繼續,代碼大致是說要獲取系統的socket,還有一些監聽信息,由于太多了,直接在gdb中執行continue(到下一個可執行的代碼),此時session2已經登錄成功。
(gdb) n
Single stepping until exit from function poll,
which has no line number information.
Mysqld_socket_listener::listen_for_connection_event (this=0x45d8870) at /root/mysql-server/sql/conn_handler/socket_connection.cc:859
859       if (retval < 0 && socket_errno != SOCKET_EINTR)
(gdb) n
871       if (retval < 0 || abort_loop)
(gdb) n
876       MYSQL_SOCKET listen_sock= MYSQL_INVALID_SOCKET;
(gdb) n
877       bool is_unix_socket= false;
(gdb) n
879       for (uint i= 0; i < m_socket_map.size(); ++i)
(gdb) n
881         if (m_poll_info.m_fds[i].revents & POLLIN)
(gdb) n
879       for (uint i= 0; i < m_socket_map.size(); ++i)
(gdb) n
881         if (m_poll_info.m_fds[i].revents & POLLIN)
(gdb) n
883           listen_sock= m_poll_info.m_pfs_fds[i];
(gdb) n
884           is_unix_socket= m_socket_map[listen_sock];
(gdb) n
885           break;
(gdb) n
904       for (uint retry= 0; retry < MAX_ACCEPT_RETRY; retry++)
(gdb) n
906         socket_len_t length= sizeof(struct sockaddr_storage);
(gdb) n
908                                           (struct sockaddr *)(&cAddr), &length);
(gdb) n
909         if (mysql_socket_getfd(connect_sock) != INVALID_SOCKET ||
(gdb) n
… ...
(gdb) c
Continuing.

4.5、session2此時的select操作都是一切正常的
[root@localhost:(none)][11:41:15am] MySQL-> use test;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
[root@localhost:test][11:49:12am] MySQL-> show tables;
+----------------+
| Tables_in_test |
+----------------+
| t              |
| t1             |
+----------------+
2 rows in set (0.00 sec)

[root@localhost:test][11:49:16am] MySQL-> select * from t;
+------+------+
| id   | name |
+------+------+
|    1 | aaa  |
|    2 | aaa  |
|    3 | aaa  |
|    4 | aaa  |
+------+------+
4 rows in set (0.00 sec)

4.6、session2做insert操作的時候,又一次hung住了,session1打印出了斷點的信息,在mysql_insert:423行,直到執行continue,session2才能正常插入數據。
(gdb) c
Continuing.
[Switching to Thread 0x7f87e00b4700 (LWP 24824)]

Breakpoint 1, Sql_cmd_insert::mysql_insert (this=0x7f87f40147b8, thd=0x7f87f401bc60, table_list=0x7f87f4013fe0)
    at /root/mysql-server/sql/sql_insert.cc:423
423       DBUG_ENTER("mysql_insert");
(gdb) n
425       LEX *const lex= thd->lex;
(gdb) n
427       bool err= true;
(gdb) c
Continuing.









向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

石林| 陈巴尔虎旗| 大连市| 惠水县| 珠海市| 比如县| 宁国市| 独山县| 新余市| 宜丰县| 洮南市| 绩溪县| 平遥县| 资源县| 长春市| 普宁市| 星座| 龙陵县| 邮箱| 藁城市| 建德市| 封开县| 囊谦县| 道真| 两当县| 和平区| 莎车县| 库伦旗| 呼伦贝尔市| 仁化县| 大邑县| 仁怀市| 志丹县| 武宣县| 安陆市| 会昌县| 常熟市| 克什克腾旗| 北京市| 南江县| 沂南县|