php 扩展 输出,鸟哥,求助,写了个扩展,在执行完函数正确输出后segment fault了...

这篇博客详细记录了一次PHP内存泄漏调试的过程。在执行format_converter函数时,由于尝试访问无效地址的字符串`s`导致了strlen函数错误。通过(gdb)bt调试堆栈,发现错误发生在php_message_handler_for_zend和zend_mm_check_leaks等关键函数中,揭示了PHP内存管理的问题。博主探讨了如何更有效地定位和解决此类问题。
摘要由CSDN通过智能技术生成

(gdb) bt

#0 strlen () at ../sysdeps/x86_64/strlen.S:106

#1 0x00000000007be335 in format_converter (odp=0x7fff6e1d0f90, fmt=0xd5a491 "s(%d) : Freeing 0x%.8lX (%zu bytes), script=%s\n", ap=0x7fff6e1d0ff0)

at /home/jihanzhuang/Downloads/php-7.0.8/main/snprintf.c:993

#2 0x00000000007bedcf in strx_printv (ccp=0x7fff6e1d0fec,

buf=0x7fff6e1d1360 "[Sat Aug 13 21:02:14 2016] Script: '/home/jihanzhuang/code/Pinyin/tests/pinyin.php'\n", len=512,

format=0xd5a490 "%s(%d) : Freeing 0x%.8lX (%zu bytes), script=%s\n", ap=0x7fff6e1d0ff0) at /home/jihanzhuang/Downloads/php-7.0.8/main/snprintf.c:1248

#3 0x00000000007bf07a in ap_php_snprintf (buf=0x7fff6e1d1360 "[Sat Aug 13 21:02:14 2016] Script: '/home/jihanzhuang/code/Pinyin/tests/pinyin.php'\n", len=512,

format=0xd5a490 "%s(%d) : Freeing 0x%.8lX (%zu bytes), script=%s\n") at /home/jihanzhuang/Downloads/php-7.0.8/main/snprintf.c:1293

#4 0x00000000007b9768 in php_message_handler_for_zend (message=4, data=0x7fff6e1d2410) at /home/jihanzhuang/Downloads/php-7.0.8/main/main.c:1444

#5 0x0000000000851cad in zend_message_dispatcher (message=4, data=0x7fff6e1d2410) at /home/jihanzhuang/Downloads/php-7.0.8/Zend/zend.c:998

#6 0x000000000081cf06 in zend_mm_check_leaks (heap=0x7f2a6c000040) at /home/jihanzhuang/Downloads/php-7.0.8/Zend/zend_alloc.c:2129

#7 0x000000000081d268 in zend_mm_shutdown (heap=0x7f2a6c000040, full=0, silent=0) at /home/jihanzhuang/Downloads/php-7.0.8/Zend/zend_alloc.c:2201

#8 0x000000000081e113 in shutdown_memory_manager (silent=0, full_shutdown=0) at /home/jihanzhuang/Downloads/php-7.0.8/Zend/zend_alloc.c:2637

#9 0x00000000007ba6e0 in php_request_shutdown (dummy=0x0) at /home/jihanzhuang/Downloads/php-7.0.8/main/main.c:1856

#10 0x000000000091b7ec in do_cli (argc=2, argv=0x1b55310) at /home/jihanzhuang/Downloads/php-7.0.8/sapi/cli/php_cli.c:1141

#11 0x000000000091c068 in main (argc=2, argv=0x1b55310) at /home/jihanzhuang/Downloads/php-7.0.8/sapi/cli/php_cli.c:1344

## core文件的信息,是在format_converter函数中,s是不能访问的地址,程序直接strlen导致的错误。

(gdb) list

case 's':

case 'v':

s = va_arg(ap, char *);

if (s != NULL) {

s_len = strlen(s);

if (adjust_precision && precision < s_len) {

s_len = precision;

}

}

请问有什么办法可以更好地排查问题。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值