如何调试PHP的内部c代码? [英] How to debug into internal c code of PHP?

查看:96
本文介绍了如何调试PHP的内部c代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我一直在使用PHP已经有好几年了,但从来不知道底层的c脚本。 p>

有没有办法进入?

解决方案

对Zend PHP做了一些黑客攻击。我觉得这是过于聪明的一些人,有些人就像在中故意混淆的一样。 PHP的源代码是一种心灵改变(或破坏性)的物质,取决于你在解密非常隐秘的宏时的好处。这是我对核心的印象。



然而,编写扩展名为很轻松,一旦你得到了Zend的帮助者,大多数具有高级初学者/中级知识的人可以通过一个基本的扩展。还有很多例子。 PHP的最好的部分之一是构建系统的组织方式,添加新的东西是相对无痛的。有一点工作和耐心,几乎任何C图书馆都很容易扩展到PHP。



如果你不精通C(和什么边界滥用预处理器),一瞥PHP核心是不要给你更多的洞察力,也不是一个好的参考,如果你自己学习C。



移动:



不要让任何我所说的话,还有什么别的话不鼓励您可以从抓取代码并寻找自己。话虽如此,调试方式如下:




  • Valgrind(除非你使用了很多压制)并不是很有帮助。 PHP(据我所知)使用拱形优化的读取,类似于新版本的glibc。即它将读取32位,即使它只吞下8位和尾随NULL。


  • 我从来没有发现GDB对PHP非常有帮助。很多魔法都是非常难以追踪的宏。


  • 您将很快看到Zend错误记录功能及其版本的断言。使用这些,printf()调试几乎没用,除非你调试一个CLI应用程序。


  • 垃圾收集可以让你看到奇怪的事情,当使用像valgrind的地块。 PHP中的分析堆使用是我尚未发现的一种艺术。




最后,我想说总是很高兴看到有人在他们的语言的引擎盖下看。 SO可以使用一些有助于使PHP核心隐藏的问题,所以请随时发布更多内容:)



另外,请记住,Zend不是只是假设使 php 。尽管与Zend的兼容性是至关重要的,如果您希望通过它,每个人都可以自由地做自己的事情。


Has anyone here tried it or is it possible?

I've been using PHP for quite a few years but never know exactly the underlying c scripts.

Is there a way to go into it?

解决方案

I've done a bit of hacking on Zend PHP. I find it to be overly clever , some people go as far as calling it deliberately obfuscated in plain view. The source code to PHP is a mind altering (or breaking) substance, depending on how good you are at deciphering very cryptic macros. That's my impression of the core.

Writing extensions, however, is a breeze once you get the hang of the Zend helpers, most people with advanced-beginner / intermediate knowledge of C could get through a basic extension. There's also plenty of examples. One of the best parts of PHP is how organized the build system is, dropping in new stuff is relatively painless. With a little work and patience, almost any C library is rather easily extended to PHP.

If you aren't well versed in C (and what borders on abuse of the preprocessor), a glance at the PHP core is not going to give you much insight, nor is it a good thing to reference if you are learning C on your own.

Moving On:

Don't let anything I've said, or what anyone else has to say discourage you from grabbing the code and looking for yourself. That being said, as for debugging goes:

  • Valgrind (unless you use a lot of suppressions) is not very helpful. PHP (to the best of my knowledge) uses arch optimized reads, similar to new versions of glibc. I.e. its going to read 32 bits even if it only swallows 8 bits and a trailing NULL.

  • I have never found GDB to be very helpful with PHP. A lot of the magic is in macros that are very hard to trace.

  • You will quickly see the Zend error logging functions, and their version of assertions. Use those, printf() debugging is pretty much useless unless your debugging a CLI app.

  • Garbage collection can make you see odd things when using tools like valgrind's massif. Profiling heap use in PHP is an art I have not yet discovered.

Finally, I'd like to say its always nice to see someone take a look under the hood of their language. SO could use some questions that helps de-mystify the PHP core, so please feel free to post more as you go :)

Also, remember, Zend isn't the only forge that makes php. While compatibility with Zend is paramount if you hope for it to be adopted, everyone is still free to do their own thing.

这篇关于如何调试PHP的内部c代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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