如何使用gdb在php脚本中设置断点 [英] How to set breakpoints in a php script using gdb

查看:133
本文介绍了如何使用gdb在php脚本中设置断点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过控制台用GDB调试一个php脚本,但我无法设置断点。这就是我所做的。
我创建了一个包含以下内容的脚本:

 <?php 
echo1 ;
回显1;
回显1;
回显1;
回显1;
回显1;
回显1;

这是我的试验性调试版本

 #gdb php -d CANCELLAMI.php 
GNU gdb(Ubuntu / Linaro 7.4-2012.04-0ubuntu2.1)7.4-2012.04
版权所有(C)2012免费Software Foundation,Inc.
许可证GPLv3 +:GNU GPL版本3或更高版本< http://gnu.org/licenses/gpl.html>
这是免费软件:您可以自由更改和重新分配它。
在法律允许的范围内,不存在任何担保。有关详细信息,请键入显示复制
和显示保修。
这个GDB被配置为x86_64-linux-gnu。
有关错误报告的说明,请参阅:
< http://bugs.launchpad.net/gdb-linaro/> ...

警告:/ root / CANCELLAMI.php不是一个目录。
读取/usr/bin/php...中的符号(没有找到调试符号)...完成。

现在我处于gdb中,我在第2行放置了一个断点。

 (gdb)break CANCELLAMI.php:2 
没有加载符号表。使用文件命令。
在将来的共享库加载时使断点处于待处理状态? (y或[n])y
断点1(CANCELLAMI.php:2)未决。

但是,如果我运行CANCELLAMI脚本



<$ p $ b $ (gdb)运行CANCELLAMI.php
启动程序:/ usr / bin / php CANCELLAMI.php
[使用libthread_db启用线程调试]
使用主机libthread_db库/lib/x86_64-linux-gnu/libthread_db.so.1。
11111111 [下1(进程30216)正常退出]

执行整个脚本。 解决方案

简短回答:如果你想调试PHP脚本,可以使用 xdebug






目前,gdb只能真正调试编译语言。它有许多关于可执行文件格式,调试信息格式,如何展开堆栈帧以及低级类似的知识。它没有的是一种将这些东西与解释器中的高层次结构相关联的方法。

现在,如果你知道,可以用这种方式调试脚本足以说明翻译。你可以通过解释器并理解它在做什么。我之前做过这件事 - 这是可行的,但不完全令人愉快。如果你试图在由某个特定脚本触发的解释器中发现一个错误,这真的很难做到。



偶尔会出现这样的想法:gdb可以调试脚本。这是一个好主意,但它的工作量相当大。据我所知,目前没有人正在研究它。


I am trying to debug a php scripts via console with GDB but I am not able to set breakpoints. This is what I've done. I've created a script with this content:

<?php
echo "1";
echo "1";
echo "1";
echo "1";
echo "1";
echo "1";
echo "1";

And this is my temptative to debug it

# gdb php -d CANCELLAMI.php 
GNU gdb (Ubuntu/Linaro 7.4-2012.04-0ubuntu2.1) 7.4-2012.04
Copyright (C) 2012 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-linux-gnu".
For bug reporting instructions, please see:
<http://bugs.launchpad.net/gdb-linaro/>...

warning: /root/CANCELLAMI.php is not a directory.
Reading symbols from /usr/bin/php...(no debugging symbols found)...done.

Now that I am inside gdb, I put a breakpoint in line 2.

(gdb) break CANCELLAMI.php:2
No symbol table is loaded.  Use the "file" command.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 1 (CANCELLAMI.php:2) pending.

But if I run CANCELLAMI script

(gdb) run CANCELLAMI.php 
Starting program: /usr/bin/php CANCELLAMI.php
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
11111111[Inferior 1 (process 30216) exited normally]

the whole script is executed.

解决方案

Short answer: If you want to debug PHP scripts use xdebug.


Currently, gdb can only really debug compiled languages. It has a lot of knowledge baked in about executable file formats, debug info formats, how to unwind stack frames, and low-level stuff like that. What it doesn't have is a way to associate these things with higher-level constructs in interpreters.

Now, it is possible to debug scripts this way, if you know enough about the interpreter. You can step through the interpreter and understand what it is doing. I've done this before -- it is doable but not exactly pleasant. It's hard enough that it's only really worth doing if you are trying to find a bug in the interpreter triggered by some particular script.

Occasionally the idea arises that gdb could debug scripts. This is a good idea, but it is a reasonably large amount of work. As far as I know, nobody is currently working on it.

这篇关于如何使用gdb在php脚本中设置断点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆