前一段领导开发了一个内核的模块,测试的过程中,发现导致MYSQL客户端无法连接服务器。

经过查询文档,追根溯源,终于找到了MYSQL实现链接客户端的代码,在源文件sql-common/client.c里的 CLI_MYSQL_REAL_CONNECT 函数。

但是代码很长,一时半会儿肯定看不明白。这个时候发现,发现代码当中有很多这样的代码:

DBUG_ENTER("mysql_real_connect");

说明只要以调试模式启动MYSQL,就可以跟踪代码的执行。

经过查询文档和测试,只要在 cmake 的时候,增加参数 cmake -WITH_DEBUG=1 就可以了。

然后启动一个MYSQL客户端程序之前,更改一个环境变量:

export MYSQL_DEBUG=d:t:O,/tmp/client.trace

好牛逼啊!我们不禁感叹。之余,学习了一下这个调试模式的具体实现:

在 CMakeList.txt 中,有这么一段代码:

IF(WITH_DEBUG)
SET(CMAKE_BUILD_TYPE "Debug" CACHE STRING ${BUILDTYPE_DOCSTRING} FORCE)
IF(NOT CMAKE_BUILD_TYPE
AND NOT CMAKE_GENERATOR MATCHES "Visual Studio"
AND NOT CMAKE_GENERATOR MATCHES "Xcode")
# This is the case of no CMAKE_BUILD_TYPE choosen, typical for VS and Xcode
# or if custom C flags are set. In VS and Xcode for non-Debug configurations
# DBUG_OFF is already correctly set. Use DBUG_OFF for Makefile based projects
# without build type too, unless user specifically requests DBUG.
IF(NOT CMAKE_C_FLAGS MATCHES "-DDBUG_ON")
ADD_DEFINITIONS(-DDBUG_OFF)
ENDIF()
ENDIF()

如果没有设置 CMAKE_BUILD_TYPE ,那么就会执行下面一段代码。如果这时候也没有设置一个名为-DDBUG_ON的CFLAGS的环境变量的话,就会增加一个CFLAGS:-DDBUG_OFF。

之后,当编译器编译的时候,根据编译器的参数增加的宏来决定 怎么定义 DBUG_ENTER 之类的函数是空代码,还是实际的报错代码。

/*
* These macros provide a user interface into functions in the
* dbug runtime support library. They isolate users from changes
* in the MACROS and/or runtime support.
*
* The symbols "__LINE__" and "__FILE__" are expanded by the
* preprocessor to the current source file line number and file
* name respectively.
*
* WARNING --- Because the DBUG_ENTER macro allocates space on
* the user function's stack, it must precede any executable
* statements in the user function.
*
*/
# ifdef DBUG_OFF
# define DBUG_ENTER(a1)
# define DBUG_RETURN(a1) return(a1)
# define DBUG_VOID_RETURN return
# define DBUG_EXECUTE(keyword,a1)
# define DBUG_PRINT(keyword,arglist)
# define DBUG_2(keyword,format) /* Obsolete */
# define DBUG_3(keyword,format,a1) /* Obsolete */
# define DBUG_4(keyword,format,a1,a2) /* Obsolete */
# define DBUG_5(keyword,format,a1,a2,a3) /* Obsolete */
# define DBUG_PUSH(a1)
# define DBUG_POP()
# define DBUG_PROCESS(a1)
# define DBUG_FILE (stderr)
# define DBUG_SETJMP setjmp
# define DBUG_LONGJMP longjmp
# define DBUG_DUMP(keyword,a1)
# else
# define DBUG_ENTER(a) \
auto char *_db_func_; auto char *_db_file_; auto int _db_level_; \
auto char **_db_framep_; \
_db_enter_ (a,__FILE__,__LINE__,&_db_func_,&_db_file_,&_db_level_, \
&_db_framep_)
# define DBUG_LEAVE \
(_db_return_ (__LINE__, &_db_func_, &_db_file_, &_db_level_))
# define DBUG_RETURN(a1) return (DBUG_LEAVE, (a1))
# define DBUG_VOID_RETURN {DBUG_LEAVE; return;}
# define DBUG_EXECUTE(keyword,a1) \
{if (_db_on_) {if (_db_keyword_ (keyword)) { a1 }}}
# define DBUG_PRINT(keyword,arglist) \
{if (_db_on_) {_db_pargs_(__LINE__,keyword); _db_doprnt_ arglist;}}
# define DBUG_2(keyword,format) \
DBUG_PRINT(keyword,(format)) /* Obsolete */
# define DBUG_3(keyword,format,a1) \
DBUG_PRINT(keyword,(format,a1)) /* Obsolete */
# define DBUG_4(keyword,format,a1,a2) \
DBUG_PRINT(keyword,(format,a1,a2)) /* Obsolete */
# define DBUG_5(keyword,format,a1,a2,a3) \
DBUG_PRINT(keyword,(format,a1,a2,a3)) /* Obsolete */
# define DBUG_PUSH(a1) _db_push_ (a1)
# define DBUG_POP() _db_pop_ ()
# define DBUG_PROCESS(a1) (_db_process_ = a1)
# define DBUG_FILE (_db_fp_)
# define DBUG_SETJMP(a1) (_db_setjmp_ (), setjmp (a1))
# define DBUG_LONGJMP(a1,a2) (_db_longjmp_ (), longjmp (a1, a2))
# define DBUG_DUMP(keyword,a1,a2) _db_dump_(__LINE__,keyword,a1,a2)
# endif

Mysql的Debug模式实现的更多相关文章

  1. MySQL 编译安装并且开启DEBUG模式

    因为想分析下mysql中一些操作的内部执行过程,单纯的看源码太枯燥了,所以决定结合mysql的执行过程来分析,mysql作为一款成熟的数据库软件,在设计的时候就考虑到了调试的问题,只是想开启调试模式的 ...

  2. tomcat的debug模式启动不了

    这个问题可能是由于eclipse和tomcat的交互而产生的,在以debug模式启动tomcat时,发生了读取文件错误,eclipse自动设置了断点,导致tomcat不能正常启动.解决方法如下,打开b ...

  3. Debug模式下编译溢出问题

    问题: 代码在Debug模式下编译报出内存溢出的错误,而Release模式下则没有. 由于Debug模式下包含调试信息,并且不作任何优化.而Release模式进行了各种优化,内存检测等操作均省去,使得 ...

  4. Debug模式,不能进入打断点的类,反而进入代理类里

    有史以来,第一次,遇到这个问题, 设置好断点,Debug模式开启项目,,没有进入原来打好的断点类,反而,进入的是和断点类相同名字(但是图标不同)的一个类里, 不能真正的调试,调试变得很麻烦, 解决方案 ...

  5. Android studio debug模式获取变量的值

    打断点.debug模式运行,Console界面旁边的Debugger界面,或者在变量上右键add to watches

  6. IDEA 13 无法进入debug 模式解决方案

    1.最近在idea中使用tomcat开发项目,像往常一样打开tomcat进行debug,但奇怪的事情出现了,项目根本不进断点.后查找原因,估计idea的加载参数方式是:先加载tomcat中设置的参数, ...

  7. 以Debug模式启动JBoss

    JBoss服务器的启动方法: 假设JBoss的安装目录为$JBOSS_HOME,Windows以及Linux环境下的Debug模式的启动方法分别为:Windows环境:找到Windows下的JBoss ...

  8. Xcode中使用debug模式和release模式

    在开发过程中,我们经常需要用到NSLog输出一些信息,甚至有的开发过程,必须在控制台查看输出,有经验的程序员通过控制台输出就能知道整个数据交互的一个流程.但是一个发布的程序,里面带有太多的NSLog输 ...

  9. myeclipse的debug模式中breakpoint窗口怎么调出来

    myeclipse的debug模式中breakpoint窗口怎么调出来? 解决办法: window-->show view-->breakpoints.   如下:

随机推荐

  1. MSSQL数库备份与还原脚本(多个库时很方便)

    每次通过 Management Studio 的界面操作备份或还原数据库,对于单个数据库还好,要是一次要做多个.那就还是用脚本快些,下面有两段脚本分享一下. ===================== ...

  2. ASP.NET MVC Controller向View传值方式总结

    Controller向View传值方式总结 总结发现ASP.NET MVC中Controller向View传值的方式共有6种,分别是: ViewBag ViewData TempData 向普通Vie ...

  3. firebreath注册接口

    对firebreath文档进行翻译,顺便做个笔记,原地址:http://www.firebreath.org/display/documentation/JSAPIAuto 综述: 你可能会对需要转换 ...

  4. ssh生成密钥(供git使用)

    我们在使用git远程更新时候,需要设置好远程密钥,以使我们能够远程更新代码到代码库中.现在我们就来做一下这件事情(ssh模式下) ssh-keygen  -t rsa -c “hcu5555@hotm ...

  5. USACO Section 4.2 The Perfect Stall(二分图匹配)

    二分图的最大匹配.我是用最大流求解.加个源点s和汇点t:s和每只cow.每个stall和t 连一条容量为1有向边,每只cow和stall(that the cow is willing to prod ...

  6. Hibernate学习之Hibernate流程

    Hibernate的核心组件 在基于MVC设计模式的JAVA WEB应用中,Hibernate可以作为模型层/数据访问层.它通过配置文件(hibernate.properties或hibernate. ...

  7. hadoop搭建杂记:Linux下hadoop的安装配置

    VirtualBox搭建伪分布式模式:hadoop的下载与配置 VirtualBox搭建伪分布式模式:hadoop的下载与配置 由于个人机子略渣,无法部署XWindow环境,直接用的Shell来操作, ...

  8. JSON.parse这个是啥?

    var jsontext = '{"firstname":"Jesper","surname":"Aaberg",&qu ...

  9. C# 控件包

    http://www.cnblogs.com/Keep-Silence-/archive/2013/01/22/2871694.html

  10. 随机数、continue、break

    arc4random() — 返回一个随机数(无符号整型).  如果要随机一个 [a, b]范围内的整数  公式:arc4random() % (b - a + 1) + a; #include &l ...