博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
gdb 调试 sysbench
阅读量:7065 次
发布时间:2019-06-28

本文共 7027 字,大约阅读时间需要 23 分钟。

前几天在写这篇文档的时候,发现sysbench对PostgreSQL libpq绑定变量使用的支持并不好。

《让 sysbench 支持 PostgreSQL 服务端绑定变量》
那么怎样跟踪出错的代码呢?
通过gdb跟踪是一种手段,但是sysbench在测试PostgreSQL libpq绑定时立即就退出。 通过pid来跟踪不太恰当,可以使用gdb的run指令来跟踪(之前没有仔细研究过gdb,还好有RDS PG内核团队小鲜肉给的方法,靠谱的团队,有问题立即就能找到靠谱的人)。
例如调试data程序

gdb date(gdb) runStarting program: /bin/date [Thread debugging using libthread_db enabled]Thu Apr 28 22:32:24 CST 2016Program exited normally.

run后面加参数,实际上就是data命令加参数的效果一样

gdb date(gdb) run +%F%tStarting program: /bin/date +%F%t[Thread debugging using libthread_db enabled]2016-04-28Program exited normally.

对于sysbench_pg,因为出错就立即退出,所以需要先加断点,然后再run,例如我们大概已经分析到sysbench_pg一定会运行的函数,设为断点,然后用单步调试。

(gdb) break [
:]
(gdb) break [
:]

例子 :

gdb ./sysbench_pg(gdb) b sb_lua_db_execute或(gdb) b script_lua.c:sb_lua_db_executeBreakpoint 1 at 0x40f130: file script_lua.c, line 851.(gdb) run --test=lua/oltp_pg1.lua   --db-driver=pgsql   --pgsql-host=$PGDATA   --pgsql-port=1921   --pgsql-user=postgres   --pgsql-password=postgres   --pgsql-db=postgres   --oltp-tables-count=1   --oltp-table-size=1000000   --num-threads=1  --max-time=120  --max-requests=0 --report-interval=1 run[Thread debugging using libthread_db enabled]sysbench 0.5:  multi-threaded system evaluation benchmarkRunning the test with following options:Number of threads: 1Report intermediate results every 1 second(s)Random number generator seed is 0 and will be ignored[New Thread 0x7ffff7e6c700 (LWP 10898)][New Thread 0x7ffff7e5b700 (LWP 10899)]Threads started![Switching to Thread 0x7ffff7e5b700 (LWP 10899)]Breakpoint 1, sb_lua_db_execute (L=0x8ab080) at script_lua.c:851851     script_lua.c: No such file or directory.        in script_lua.cMissing separate debuginfos, use: debuginfo-install glibc-2.12-1.80.2.alios6.x86_64 libaio-0.3.107-10.1.alios6.x86_64(gdb) n863     in script_lua.c(gdb) ssb_lua_get_context (L=0x8ab080) at script_lua.c:11091109    in script_lua.c

查看对应的代码 :

$vi sysbench/scripting/script_lua.c:set nu:11091108 sb_lua_ctxt_t *sb_lua_get_context(lua_State *L)1109 {

打印当前环境的变量值

(gdb) p L$1 = (lua_State *) 0x8ab080(gdb) p *L$2 = {next = 0x7ffff00097b0, tt = 8 '\b', marked = 97 'a', status = 0 '\000', top = 0x8ab3a0, base = 0x8ab390, l_G = 0x8ab138, ci = 0x8a20a0, savedpc = 0x8b6d78, stack_last = 0x8ab560, stack = 0x8ab2f0, end_ci = 0x8a2168,   base_ci = 0x8a2050, stacksize = 45, size_ci = 8, nCcalls = 1, hookmask = 0 '\000', allowhook = 1 '\001', basehookcount = 0, hookcount = 0, hook = 0, l_gt = {value = {gc = 0x8aa560, p = 0x8aa560, n = 9086304, b = 9086304}, tt = 5},   env = {value = {gc = 0x8af150, p = 0x8af150, n = 9105744, b = 9105744}, tt = 5}, openupval = 0x0, gclist = 0x0, errorJmp = 0x7ffff7e5ac20, errfunc = 0}(gdb) p *L->savedpc$3 = 147525

一路回车,在这个位置抛出异常

sb_lua_db_execute (L=0x8ab080) at script_lua.c:943943     script_lua.c: No such file or directory.        in script_lua.c(gdb) 942     in script_lua.c(gdb) 943     in script_lua.c(gdb) 946     in script_lua.c(gdb) 945     in script_lua.c(gdb) 946     in script_lua.c(gdb) 948     in script_lua.c(gdb) lua_error (L=0x8ab080) at lapi.c:957957     lapi.c: No such file or directory.        in lapi.c(gdb) 960     in lapi.c(gdb) luaG_errormsg (L=0x8ab080) at ldebug.c:600600     ldebug.c: No such file or directory.        in ldebug.c(gdb) 601     in ldebug.c(gdb) 610     in ldebug.c(gdb) 609     in ldebug.c(gdb) 610     in ldebug.c(gdb) 609     in ldebug.c(gdb) luaD_throw (L=0x8ab080, errcode=2) at ldo.c:9494      ldo.c: No such file or directory.        in ldo.c(gdb) 95      in ldo.c(gdb) 94      in ldo.c(gdb) 95      in ldo.c(gdb) 96      in ldo.c(gdb) 97      in ldo.c(gdb) FATAL: failed to execute function `event': (null)[Thread 0x7ffff7e5b700 (LWP 11124) exited][Thread 0x7ffff7e6c700 (LWP 11123) exited]

重来一遍,直接跟踪行号

gdb ./sysbench_pgGNU gdb (GDB) Red Hat Enterprise Linux (7.2-50.1.alios6)Copyright (C) 2010 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:
...Reading symbols from /home/dege.zzz/sysbench/sysbench_pg...done.(gdb) b script_lua.c:943Breakpoint 1 at 0x40f2cd: file script_lua.c, line 943.(gdb) run --test=lua/oltp_pg1.lua --db-driver=pgsql --pgsql-host=$PGDATA --pgsql-port=1921 --pgsql-user=postgres --pgsql-password=postgres --pgsql-db=postgres --oltp-tables-count=1 --oltp-table-size=1000000 --num-threads=1 --max-time=120 --max-requests=0 --report-interval=1 runStarting program: /home/dege.zzz/sysbench/sysbench_pg --test=lua/oltp_pg1.lua --db-driver=pgsql --pgsql-host=$PGDATA --pgsql-port=1921 --pgsql-user=postgres --pgsql-password=postgres --pgsql-db=postgres --oltp-tables-count=1 --oltp-table-size=1000000 --num-threads=1 --max-time=120 --max-requests=0 --report-interval=1 run[Thread debugging using libthread_db enabled]sysbench 0.5: multi-threaded system evaluation benchmarkRunning the test with following options:Number of threads: 1Report intermediate results every 1 second(s)Random number generator seed is 0 and will be ignored[New Thread 0x7ffff7e6c700 (LWP 11347)][New Thread 0x7ffff7e5b700 (LWP 11348)]Threads started!FATAL: query execution failed: -268398832[Switching to Thread 0x7ffff7e5b700 (LWP 11348)]Breakpoint 1, sb_lua_db_execute (L=0x8ab080) at script_lua.c:943943 script_lua.c: No such file or directory. in script_lua.cMissing separate debuginfos, use: debuginfo-install glibc-2.12-1.80.2.alios6.x86_64 libaio-0.3.107-10.1.alios6.x86_64(gdb) n942 in script_lua.c

对应的代码

应该是在类型处理时出现了问题。

908   /* Rebind if needed */ 909   if (needs_rebind) 910   { 911     binds = (db_bind_t *)calloc(stmt->nparams, sizeof(db_bind_t)); 912     if (binds == NULL) 913       luaL_error(L, "Memory allocation failure"); 914  915     for (i = 0; i < stmt->nparams; i++) 916     { 917       param = stmt->params + i; 918       binds[i].type = param->type; 919       binds[i].is_null = &param->is_null; 920       if (*binds[i].is_null != 0) 921         continue; 922       switch (param->type) 923       { 924         case DB_TYPE_INT: 925           binds[i].buffer = param->buf; 926           break; 927         case DB_TYPE_CHAR: 928           binds[i].buffer = param->buf; 929           binds[i].data_len = &stmt->params[i].buflen; 930           binds[i].is_null = 0; 931           break; 932         default: 933           luaL_error(L, "Unsupported variable type"); 934       } 935     } 937     if (db_bind_param(stmt->ptr, binds, stmt->nparams)) 938       luaL_error(L, "db_bind_param() failed"); 939     free(binds); 940   } 941  942   ptr = db_execute(stmt->ptr); 943   if (ptr == NULL) 944   { 945     stmt->rs = NULL; 946     if (ctxt->con->db_errno == SB_DB_ERROR_DEADLOCK) 947       lua_pushnumber(L, SB_DB_RESTART_TRANSACTION);

gdb的详细用法可以参考gdb手册。

转载地址:http://tksll.baihongyu.com/

你可能感兴趣的文章
Akka2使用探索6(Futures)——实现并发和异步
查看>>
【持续更新】jQuery 实用技巧
查看>>
大象也能起舞,Citrix X1计划让你对笔记本电脑say good bye
查看>>
Nginx 之常见报错问题解决
查看>>
linux 防爆破方法
查看>>
2、通过ipmitool工具修改IPMI的WEB密码
查看>>
云盘关闭,教你用蒲公英搭建私有云
查看>>
Spring Cloud 入门教程5、服务容错监控:Hystrix Dashboard
查看>>
很好的学习平台
查看>>
hibernate学习笔记3
查看>>
SQL Server 2005 日常运维检查操作手册
查看>>
利用jquery和jsonp来获取跨站数据,并实现cookie共享
查看>>
我的友情链接
查看>>
Linux的epoll模型
查看>>
使用X Manager远程CentOS 7服务器(XDMCP)
查看>>
写sql语句时将时间格式“20110725”转化为格式2012年07月25日
查看>>
[Hadoop in China 2011] 蒋建平:探秘基于Hadoop的华为共有云
查看>>
heartbeat高可用+lvsDR
查看>>
方丈被害子女有没有权利继承遗产?
查看>>
java入门第一季5、6
查看>>