How to debug PHP internal code?

Has anyone here tried this or is it possible?

I have been using PHP for several years, but I don’t know exactly which c scripts.

Is there any way to get into it?

+4
source share
3 answers

I hacked Zend PHP a bit. I find it overly clever , some people reach it deliberately obfuscated in plain view . PHP source code is a mind that modifies (or violates) substance, depending on how good you are at decoding very mysterious macros. This is my impression of the core.

Writing extensions, however, is a breeze , when you get the hang of Zend helpers, most people with advanced / intermediate C knowledge can go through the basic extension. There are also many examples. One of the best parts of PHP is how the build system is organized, but in the new materials it’s relatively painless. With a little work and patience, almost any C library is fairly easy to extend to PHP.

If you are not well versed in C (and that limits the abuse of the preprocessor), a look at the PHP core will not give you much insight, and you should not refer well if you study C on your own.

Moving:

Don't let anything I say, or that anyone else has to say, keep you from capturing code and looking for yourself. This is said for debugging:

  • Valgrind (unless you use a lot of suppressions) doesn't help much. PHP (as far as I know) uses summary optimized reads similar to the newer versions of glibc. That is, it will read 32 bits, even if it swallows only 8 bits and trailing NULL.

  • I never found that GDB really helps PHP. Magic in macros that are very difficult to track.

  • You will quickly see the Zend error logging features and their version of statements. Using these, printf () debugging is almost useless unless you are debugging a CLI application.

  • Garbage collection can make you see strange things when using tools like valgrind massif. Using profiling heaps in PHP is an art that I haven't discovered yet.

Finally, I would like to say that it is always nice to see someone looking under the hood of their tongue. SO may use some questions that help to de-mystify the PHP core, so please feel free to post more when you go :)

Also, remember, Zend is not the only forge that php does . While compatibility with Zend is paramount, if you hope it will be accepted, everyone is still free to do their own thing.

+7
source

I never debugged PHP C code (or extensions), but sometimes I called backtraces in case of failures in PHP extensions.

This page can help, about which: Creating gtb backtrace .

From now on, perhaps you can go further ...

+1
source

From some of your questions, it sounds like you don’t know that PHP is open source, you can download the full source code and view all the functions of C. If you want to use the backtracking and debugging function, you need to do what Pascal MARTIN said .

0
source

Source: https://habr.com/ru/post/1304964/


All Articles