SlideShare a Scribd company logo
1 of 7
Download to read offline
DBUG



a c program debugging package,



by Fred Fish.



http://sourceforge.net/projects/dbug



mysql 使用 dbug 来调试跟踪源代码
Section 1:dbug 的基本介绍

dbug example:

#include <dbug.h>



int main ()

{

    int result, i;

    DBUG_ENTER ("main");

    for (i=0,result=0; i != 100; i++) {

        DBUG_PRINT ("info", ("i : %dn", i);

        result += i;

    }

    DBUG_RETURN (0);

}
dbug package提供的一些方法(仅列出最常用的):

1. DBUG_ENTER

  进入函数时调用,参数是一个字符串.且必须要有一个

  DBUG_RETURN相配对.

  EX: DBUG_ENTER ("main");



2. DBUG_RETURN

  退出某个函数时调用,参数是返回值.

  EX: DBUG_RETURN (value);

  EX:DBUG_VOID_RETURN; (无返回值时)



3. DBUG_PRINT

  最常用,输出信息.两个参数,第一个参数是一个keyword,第二个参

  数是printf的format string.

  EX: DBUG_PRINT ("eof", ("end of file found"));

  EX: DBUG_PRINT ("type", ("type is %x", type));

  EX: DBUG_PRINT ("stp", ("%x -> %s", stp, stp ->

name));
Section 2:mysql 中使用 dbug

mysql 中如何使用 debug 跟踪调试代码.

1. 编译的时候加上—debug 参数: ./configure –with-debug

2. mysql 默认已经在代码中的很多地方都加上了 DBUG_XXX 了,而且

  很详细.比如在很多函数的入口加上了 DBUG_ENTER(“函数名”),在

  一些地方 DBUG_PRINT()打印输入重要变量的值.当然你也可以自己

  在需要的地方添加 DBUG_XX,来观察你所关心的信息.(添加完了记

  得重新 make)

3. 启动 mysql 的时候加上参数:mysqld_safe --debug&

4. 启动后,mysql 默认在/tmp/下生成 mysqld.trace 文件,记录了所有的

  dbug 跟踪信息.这个文件是会动态更新的.
trace 文件示例:

T@1   : >init_tmpdir

T@1   : | enter: pathlist: NULL

T@1   : | >init_dynamic_array

T@1   : | | >my_malloc

T@1   : | | | my: size: 8 my_flags: 0

T@1   : | | | exit: ptr: 0x6aed620

T@1   : | | <my_malloc

T@1   : | <init_dynamic_array

T@1   : | >cleanup_dirname

T@1   : | | enter: from: '/tmp'

T@1   : | | exit: to: '/tmp'

T@1   : | <cleanup_dirname

T@1   : | >my_malloc

T@1   : | | my: size: 5 my_flags: 16

T@1   : | | exit: ptr: 0x6aed640

T@1   : | <my_malloc

T@1   : <init_tmpdir
注:

1. T@n 的意思是表明这是在第 n 个线程中.

2. >init_tmpdir 中的>的意思是进入函数.

3. <init_tmpdir 中的<的意思是退出函数.

4. 树形结构,清晰

5. mysqld_safe& --debug 会产生很多的信息,可以加上命令关注我们

     所关心的:

     mysqld_safe

     --debug=d,info,error,query,general,where,taobao:O,/tmp/mysqld.trac

     e&

     上面的 infoerror 等是一些 tag,表明我们只需要查看这些 tag 标记

     的输出.比如我在某个地方:

     DBUG_PRINT( “taobao” , (”x is : %d” , x) );

     这个 DBUG 的 tag 是 taobao,那么我们用上面的方法启动 mysqld 后,

     就可以在 mysqld.trace 文件中看到这个 DBUG_PRINT 了.
参考:

DBUG User Manual

Creating                 Trace                  Files                :

http://dev.mysql.com/doc/refman/5.0/en/making-trace-files.html




                                                        周旻钧@taobao

                                               http://www.sa-unix.com

                                                             2010.9.19

More Related Content

What's hot

cfm to php training
cfm to php training cfm to php training
cfm to php training Chonpin HSU
 
Python入門:5大概念初心者必備 2021/11/18
Python入門:5大概念初心者必備 2021/11/18Python入門:5大概念初心者必備 2021/11/18
Python入門:5大概念初心者必備 2021/11/18Derek Lee
 
Python入門:5大概念初心者必備
Python入門:5大概念初心者必備Python入門:5大概念初心者必備
Python入門:5大概念初心者必備Derek Lee
 
網頁設計 - 資料庫存取
網頁設計 - 資料庫存取網頁設計 - 資料庫存取
網頁設計 - 資料庫存取Vincent Chi
 
Mongodb
MongodbMongodb
Mongodbbj
 
Uc home二次开发参考手册
Uc home二次开发参考手册Uc home二次开发参考手册
Uc home二次开发参考手册charleenchen1990
 
第十一章解答
第十一章解答第十一章解答
第十一章解答jiannrong
 
那 Angular 那 AJAX 那 RESTful
那 Angular 那 AJAX 那 RESTful那 Angular 那 AJAX 那 RESTful
那 Angular 那 AJAX 那 RESTful功豪 魏
 
Mastering Mustache
Mastering MustacheMastering Mustache
Mastering Mustachetinyhill
 
Node.js开发体验
Node.js开发体验Node.js开发体验
Node.js开发体验QLeelulu
 
Bash shell script 教學
Bash shell script 教學Bash shell script 教學
Bash shell script 教學Ming-Sian Lin
 
PHP & MySQL 教學
PHP & MySQL 教學PHP & MySQL 教學
PHP & MySQL 教學Bo-Yi Wu
 
PHP Coding Standard and 50+ Programming Skills
PHP Coding Standard and 50+ Programming SkillsPHP Coding Standard and 50+ Programming Skills
PHP Coding Standard and 50+ Programming SkillsHo Kim
 
Mysql 高级优化之 理解查询执行
Mysql 高级优化之 理解查询执行Mysql 高级优化之 理解查询执行
Mysql 高级优化之 理解查询执行nigel889
 
Php for fe
Php for fePhp for fe
Php for fejay li
 

What's hot (20)

nodeMCU IOT教學02 - Lua語言
nodeMCU IOT教學02 - Lua語言nodeMCU IOT教學02 - Lua語言
nodeMCU IOT教學02 - Lua語言
 
Python串列資料應用
Python串列資料應用Python串列資料應用
Python串列資料應用
 
cfm to php training
cfm to php training cfm to php training
cfm to php training
 
Python入門:5大概念初心者必備 2021/11/18
Python入門:5大概念初心者必備 2021/11/18Python入門:5大概念初心者必備 2021/11/18
Python入門:5大概念初心者必備 2021/11/18
 
Python入門:5大概念初心者必備
Python入門:5大概念初心者必備Python入門:5大概念初心者必備
Python入門:5大概念初心者必備
 
網頁設計 - 資料庫存取
網頁設計 - 資料庫存取網頁設計 - 資料庫存取
網頁設計 - 資料庫存取
 
Mongodb
MongodbMongodb
Mongodb
 
Uc home二次开发参考手册
Uc home二次开发参考手册Uc home二次开发参考手册
Uc home二次开发参考手册
 
Python元組,字典,集合
Python元組,字典,集合Python元組,字典,集合
Python元組,字典,集合
 
第十一章解答
第十一章解答第十一章解答
第十一章解答
 
那 Angular 那 AJAX 那 RESTful
那 Angular 那 AJAX 那 RESTful那 Angular 那 AJAX 那 RESTful
那 Angular 那 AJAX 那 RESTful
 
Mastering Mustache
Mastering MustacheMastering Mustache
Mastering Mustache
 
Node.js开发体验
Node.js开发体验Node.js开发体验
Node.js开发体验
 
Bash shell script 教學
Bash shell script 教學Bash shell script 教學
Bash shell script 教學
 
PHP & MySQL 教學
PHP & MySQL 教學PHP & MySQL 教學
PHP & MySQL 教學
 
PHP Coding Standard and 50+ Programming Skills
PHP Coding Standard and 50+ Programming SkillsPHP Coding Standard and 50+ Programming Skills
PHP Coding Standard and 50+ Programming Skills
 
Python 3-條件判斷
Python 3-條件判斷Python 3-條件判斷
Python 3-條件判斷
 
Mysql 高级优化之 理解查询执行
Mysql 高级优化之 理解查询执行Mysql 高级优化之 理解查询执行
Mysql 高级优化之 理解查询执行
 
Php for fe
Php for fePhp for fe
Php for fe
 
PHP
PHPPHP
PHP
 

Viewers also liked

Alapítsunk iskolát!
Alapítsunk iskolát!Alapítsunk iskolát!
Alapítsunk iskolát!VAdrika9014
 
สารสนเทศกับการท่องเที่ยว
สารสนเทศกับการท่องเที่ยวสารสนเทศกับการท่องเที่ยว
สารสนเทศกับการท่องเที่ยวnongmai06027
 
Quadern de problemes1
Quadern de problemes1Quadern de problemes1
Quadern de problemes1lcervel2
 
Szabadidős tevékenységek vizsgálata a Berzsenyi Dániel Gimnáziumban
Szabadidős tevékenységek vizsgálata a Berzsenyi Dániel GimnáziumbanSzabadidős tevékenységek vizsgálata a Berzsenyi Dániel Gimnáziumban
Szabadidős tevékenységek vizsgálata a Berzsenyi Dániel GimnáziumbanVAdrika9014
 
ดอกไม้ในจีน
ดอกไม้ในจีนดอกไม้ในจีน
ดอกไม้ในจีนnongmai06027
 
Les 7 cabretes i el llop
Les 7 cabretes i el llopLes 7 cabretes i el llop
Les 7 cabretes i el lloplcervel2
 
Comprensio lectora
Comprensio lectoraComprensio lectora
Comprensio lectoralcervel2
 
Ayahuasca: its preparation and effects
Ayahuasca: its preparation and effectsAyahuasca: its preparation and effects
Ayahuasca: its preparation and effectsNathaniel D. Horowitz
 
ELT Methodology Differences bet l1 and l2
ELT Methodology Differences bet l1 and l2ELT Methodology Differences bet l1 and l2
ELT Methodology Differences bet l1 and l2Geoffrey Geography
 
Sun safety – skin safety, sunburn prevention, sun safety, sunscreen advice ip...
Sun safety – skin safety, sunburn prevention, sun safety, sunscreen advice ip...Sun safety – skin safety, sunburn prevention, sun safety, sunscreen advice ip...
Sun safety – skin safety, sunburn prevention, sun safety, sunscreen advice ip...AppsolutelyiPhone
 

Viewers also liked (17)

The power of networks power point
The power of networks  power pointThe power of networks  power point
The power of networks power point
 
The way to work
The way to workThe way to work
The way to work
 
Alapítsunk iskolát!
Alapítsunk iskolát!Alapítsunk iskolát!
Alapítsunk iskolát!
 
สารสนเทศกับการท่องเที่ยว
สารสนเทศกับการท่องเที่ยวสารสนเทศกับการท่องเที่ยว
สารสนเทศกับการท่องเที่ยว
 
The way to work
The way to workThe way to work
The way to work
 
99 Francs
99 Francs99 Francs
99 Francs
 
interkultural communication
interkultural communicationinterkultural communication
interkultural communication
 
Quadern de problemes1
Quadern de problemes1Quadern de problemes1
Quadern de problemes1
 
Szabadidős tevékenységek vizsgálata a Berzsenyi Dániel Gimnáziumban
Szabadidős tevékenységek vizsgálata a Berzsenyi Dániel GimnáziumbanSzabadidős tevékenységek vizsgálata a Berzsenyi Dániel Gimnáziumban
Szabadidős tevékenységek vizsgálata a Berzsenyi Dániel Gimnáziumban
 
The 2007-8 Writers' Strike
The 2007-8 Writers' StrikeThe 2007-8 Writers' Strike
The 2007-8 Writers' Strike
 
99 francs
99 francs99 francs
99 francs
 
ดอกไม้ในจีน
ดอกไม้ในจีนดอกไม้ในจีน
ดอกไม้ในจีน
 
Les 7 cabretes i el llop
Les 7 cabretes i el llopLes 7 cabretes i el llop
Les 7 cabretes i el llop
 
Comprensio lectora
Comprensio lectoraComprensio lectora
Comprensio lectora
 
Ayahuasca: its preparation and effects
Ayahuasca: its preparation and effectsAyahuasca: its preparation and effects
Ayahuasca: its preparation and effects
 
ELT Methodology Differences bet l1 and l2
ELT Methodology Differences bet l1 and l2ELT Methodology Differences bet l1 and l2
ELT Methodology Differences bet l1 and l2
 
Sun safety – skin safety, sunburn prevention, sun safety, sunscreen advice ip...
Sun safety – skin safety, sunburn prevention, sun safety, sunscreen advice ip...Sun safety – skin safety, sunburn prevention, sun safety, sunscreen advice ip...
Sun safety – skin safety, sunburn prevention, sun safety, sunscreen advice ip...
 

Similar to dbug in mysql

由一个简单的程序谈起――之二
由一个简单的程序谈起――之二由一个简单的程序谈起――之二
由一个简单的程序谈起――之二yiditushe
 
Php应用程序常见安全问题解析
Php应用程序常见安全问题解析Php应用程序常见安全问题解析
Php应用程序常见安全问题解析mysqlops
 
Learning python in the motion picture industry by will zhou
Learning python in the motion picture industry   by will zhouLearning python in the motion picture industry   by will zhou
Learning python in the motion picture industry by will zhouWill Zhou
 
Oraliux+mysql5单机多实例安装文档
Oraliux+mysql5单机多实例安装文档Oraliux+mysql5单机多实例安装文档
Oraliux+mysql5单机多实例安装文档xuebao_zx
 
mysql dbug
mysql dbugmysql dbug
mysql dbugTim Chou
 
[系列活動] 手把手教你R語言資料分析實務
[系列活動] 手把手教你R語言資料分析實務[系列活動] 手把手教你R語言資料分析實務
[系列活動] 手把手教你R語言資料分析實務台灣資料科學年會
 
Practical data analysis in R: from data collection to data insight
Practical data analysis in R: from data collection to data insight Practical data analysis in R: from data collection to data insight
Practical data analysis in R: from data collection to data insight Chun-Min Chang
 
Practical Data Analysis in R
Practical Data Analysis in RPractical Data Analysis in R
Practical Data Analysis in RChun-Ming Chang
 
Spring 2.x 中文
Spring 2.x 中文Spring 2.x 中文
Spring 2.x 中文Guo Albert
 
Django development
Django developmentDjango development
Django developmentloveyudu
 
六步教你学会简单Rmi
六步教你学会简单Rmi六步教你学会简单Rmi
六步教你学会简单Rmiyiditushe
 
Lucene 全文检索实践
Lucene 全文检索实践Lucene 全文检索实践
Lucene 全文检索实践yiditushe
 
希望科技研发部变量命名及编码规范
希望科技研发部变量命名及编码规范希望科技研发部变量命名及编码规范
希望科技研发部变量命名及编码规范Hongjian Wang
 
Aisanux安装光盘分析
Aisanux安装光盘分析Aisanux安装光盘分析
Aisanux安装光盘分析Guangyao Cheng
 
Mongo db技术交流
Mongo db技术交流Mongo db技术交流
Mongo db技术交流liuts
 
Ch1 系统启动
Ch1 系统启动Ch1 系统启动
Ch1 系统启动guest4d1b8c
 
MySQL源码分析.01.代码结构与基本流程
MySQL源码分析.01.代码结构与基本流程MySQL源码分析.01.代码结构与基本流程
MySQL源码分析.01.代码结构与基本流程Lixun Peng
 
HITCON CTF 2014 BambooFox 解題心得分享
HITCON CTF 2014 BambooFox 解題心得分享HITCON CTF 2014 BambooFox 解題心得分享
HITCON CTF 2014 BambooFox 解題心得分享Chong-Kuan Chen
 
Django
DjangoDjango
DjangoTao He
 

Similar to dbug in mysql (20)

由一个简单的程序谈起――之二
由一个简单的程序谈起――之二由一个简单的程序谈起――之二
由一个简单的程序谈起――之二
 
Php应用程序常见安全问题解析
Php应用程序常见安全问题解析Php应用程序常见安全问题解析
Php应用程序常见安全问题解析
 
Learning python in the motion picture industry by will zhou
Learning python in the motion picture industry   by will zhouLearning python in the motion picture industry   by will zhou
Learning python in the motion picture industry by will zhou
 
Oraliux+mysql5单机多实例安装文档
Oraliux+mysql5单机多实例安装文档Oraliux+mysql5单机多实例安装文档
Oraliux+mysql5单机多实例安装文档
 
mysql dbug
mysql dbugmysql dbug
mysql dbug
 
Php
Php Php
Php
 
[系列活動] 手把手教你R語言資料分析實務
[系列活動] 手把手教你R語言資料分析實務[系列活動] 手把手教你R語言資料分析實務
[系列活動] 手把手教你R語言資料分析實務
 
Practical data analysis in R: from data collection to data insight
Practical data analysis in R: from data collection to data insight Practical data analysis in R: from data collection to data insight
Practical data analysis in R: from data collection to data insight
 
Practical Data Analysis in R
Practical Data Analysis in RPractical Data Analysis in R
Practical Data Analysis in R
 
Spring 2.x 中文
Spring 2.x 中文Spring 2.x 中文
Spring 2.x 中文
 
Django development
Django developmentDjango development
Django development
 
六步教你学会简单Rmi
六步教你学会简单Rmi六步教你学会简单Rmi
六步教你学会简单Rmi
 
Lucene 全文检索实践
Lucene 全文检索实践Lucene 全文检索实践
Lucene 全文检索实践
 
希望科技研发部变量命名及编码规范
希望科技研发部变量命名及编码规范希望科技研发部变量命名及编码规范
希望科技研发部变量命名及编码规范
 
Aisanux安装光盘分析
Aisanux安装光盘分析Aisanux安装光盘分析
Aisanux安装光盘分析
 
Mongo db技术交流
Mongo db技术交流Mongo db技术交流
Mongo db技术交流
 
Ch1 系统启动
Ch1 系统启动Ch1 系统启动
Ch1 系统启动
 
MySQL源码分析.01.代码结构与基本流程
MySQL源码分析.01.代码结构与基本流程MySQL源码分析.01.代码结构与基本流程
MySQL源码分析.01.代码结构与基本流程
 
HITCON CTF 2014 BambooFox 解題心得分享
HITCON CTF 2014 BambooFox 解題心得分享HITCON CTF 2014 BambooFox 解題心得分享
HITCON CTF 2014 BambooFox 解題心得分享
 
Django
DjangoDjango
Django
 

dbug in mysql

  • 1. DBUG a c program debugging package, by Fred Fish. http://sourceforge.net/projects/dbug mysql 使用 dbug 来调试跟踪源代码
  • 2. Section 1:dbug 的基本介绍 dbug example: #include <dbug.h> int main () { int result, i; DBUG_ENTER ("main"); for (i=0,result=0; i != 100; i++) { DBUG_PRINT ("info", ("i : %dn", i); result += i; } DBUG_RETURN (0); }
  • 3. dbug package提供的一些方法(仅列出最常用的): 1. DBUG_ENTER 进入函数时调用,参数是一个字符串.且必须要有一个 DBUG_RETURN相配对. EX: DBUG_ENTER ("main"); 2. DBUG_RETURN 退出某个函数时调用,参数是返回值. EX: DBUG_RETURN (value); EX:DBUG_VOID_RETURN; (无返回值时) 3. DBUG_PRINT 最常用,输出信息.两个参数,第一个参数是一个keyword,第二个参 数是printf的format string. EX: DBUG_PRINT ("eof", ("end of file found")); EX: DBUG_PRINT ("type", ("type is %x", type)); EX: DBUG_PRINT ("stp", ("%x -> %s", stp, stp -> name));
  • 4. Section 2:mysql 中使用 dbug mysql 中如何使用 debug 跟踪调试代码. 1. 编译的时候加上—debug 参数: ./configure –with-debug 2. mysql 默认已经在代码中的很多地方都加上了 DBUG_XXX 了,而且 很详细.比如在很多函数的入口加上了 DBUG_ENTER(“函数名”),在 一些地方 DBUG_PRINT()打印输入重要变量的值.当然你也可以自己 在需要的地方添加 DBUG_XX,来观察你所关心的信息.(添加完了记 得重新 make) 3. 启动 mysql 的时候加上参数:mysqld_safe --debug& 4. 启动后,mysql 默认在/tmp/下生成 mysqld.trace 文件,记录了所有的 dbug 跟踪信息.这个文件是会动态更新的.
  • 5. trace 文件示例: T@1 : >init_tmpdir T@1 : | enter: pathlist: NULL T@1 : | >init_dynamic_array T@1 : | | >my_malloc T@1 : | | | my: size: 8 my_flags: 0 T@1 : | | | exit: ptr: 0x6aed620 T@1 : | | <my_malloc T@1 : | <init_dynamic_array T@1 : | >cleanup_dirname T@1 : | | enter: from: '/tmp' T@1 : | | exit: to: '/tmp' T@1 : | <cleanup_dirname T@1 : | >my_malloc T@1 : | | my: size: 5 my_flags: 16 T@1 : | | exit: ptr: 0x6aed640 T@1 : | <my_malloc T@1 : <init_tmpdir
  • 6. 注: 1. T@n 的意思是表明这是在第 n 个线程中. 2. >init_tmpdir 中的>的意思是进入函数. 3. <init_tmpdir 中的<的意思是退出函数. 4. 树形结构,清晰 5. mysqld_safe& --debug 会产生很多的信息,可以加上命令关注我们 所关心的: mysqld_safe --debug=d,info,error,query,general,where,taobao:O,/tmp/mysqld.trac e& 上面的 infoerror 等是一些 tag,表明我们只需要查看这些 tag 标记 的输出.比如我在某个地方: DBUG_PRINT( “taobao” , (”x is : %d” , x) ); 这个 DBUG 的 tag 是 taobao,那么我们用上面的方法启动 mysqld 后, 就可以在 mysqld.trace 文件中看到这个 DBUG_PRINT 了.
  • 7. 参考: DBUG User Manual Creating Trace Files : http://dev.mysql.com/doc/refman/5.0/en/making-trace-files.html 周旻钧@taobao http://www.sa-unix.com 2010.9.19