In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "how to understand the debugging module PHPDBG of PHP". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to understand the debugging module PHPDBG of PHP".
PHPDBG is a SAPI module of PHP that can control the running environment of PHP without modifying the code and without affecting performance.
The goal of PHPDBG is to become a lightweight, powerful, easy-to-use PHP debugging platform. Can be used in PHP5.4 and above. There will be internal integration on php5.6 and above.
Main functions:
-single-step debugging
-flexible breakpoint approach (class methods, functions, files: lines, memory addresses, opcode)
-the eval of php can be called directly
-you can view the currently executed code
-user space API (userland/user space)
-easy integration
-support for specifying php profile
-JIT global variable
-readline support (optional), the terminal operation is more convenient
-remote debug, using java GUI
-easy to operate (see help for details)
Installation
In order to use phpdgb, you first need to download a source package for php. Then download the phpdgb source package and put it in the sapi directory of the php source package. Finally, you can execute the command to install. An example of compilation and installation is as follows:
Suppose we have downloaded the source package for php and placed it in the / home/php directory.
# cd / home/php/sapi#git clone https://github.com/krakjoe/phpdbg#cd.. / #. / buildconf-- force#./config.nice#make-j8#make install-phpdbg
Note:
1. If your php version is php5.6 or higher, phpdbg has been integrated into the php code package and does not need to be downloaded separately.
2. Remember to add-enable-phpdbg to the compilation parameters.
3. Compile-time parameters,-with-readline can be added selectively. If you do not add, phpdbg's history and other features cannot be used.
Basic use
1. Parameter introduction
Phpdbg is a sapi of php that can debug php on the command line. The common parameters are as follows:
The following switches are implemented (just like cli SAPI):
-n ignore php ini
-c search for php ini in path
-z load zend extension
-d define php ini entry
The following switches change the default behaviour of phpdbg:
-v disables quietness
-s enabled stepping
-e sets execution context
-b boring-disables use of colour on the console
-I ignore .phpdbginit (default init file)
-I override .phpgdbinit location (implies-I)
-O set oplog output file
-q do not print banner on startup
-r jump straight to run
-E enable step through eval ()
Note: passing-rr will cause phpdbg to quit after execution, rather than returning to the console
2. Common functions
We introduced the gdb tool earlier. In fact, phpdbg and gdb functions are very similar in some places. For example, breakpoints can be set, step-by-step execution, and so on. It's just that they debug in different languages. Gdb focuses on debugging c or C++ language, while phpdbg focuses on debugging php language. Below we will introduce some common debugging functions of phpdbg. The code to debug is as follows:
The source code of the file test_phpdbg_inc.php is as follows:
The source code of the file test_phpdgb.php is as follows:
3. Start phpdbg
After the phpdbg installation is successful, it will be located in the bin directory of the installation directory. Enter the bin directory and enter phpdbg directly. As follows:
# phpdeg [Welcome to phpdbg, the interactive PHP debugger, v0.4.0] To get help using phpdbg type "help" and press enter [Please report bugs to] prompt >
To load the php script you want to debug, simply execute the exec command. As follows:
# phpdbg.prompt > exec. / test_phpdbg.php
Of course, we can also specify the e parameter when starting phpdbg. As follows:
# phpdbg-e. / test_phpdbg.php
4. View help information
If you have used other debugging tools before, you will find that phpdbg is similar to them. However, at the beginning of your use, you will often need to get help. We can get help information through the help command.
Prompt > helpphpdbg is a lightweight, powerful and easy to use debugging platform for PHP5.4+It supports the following commands:Information list list PHP source.
5. Set breakpoints
The command to set breakpoints is the same as gdb. All are break, abbreviated as b. However, the specific command parameters are still different. Similar to gdb's breakpoint command, they can be set "by file name: line number" or line number. In addition, phpdbg provides some ways to set breakpoints specific to php. For example, setting breakpoints according to opline, setting breakpoints according to opcode, etc.
It is well known that php code is eventually parsed into opcode and then executed by the php kernel one by one. A php statement that may resolve to multiple opcode. If we can set breakpoints by opcode, we can track the execution of the program more accurately. Let's take a look at a concrete example of setting a breakpoint by phapdbg.
Press opline to set the breakpoint:
The opline we are talking about here is the line number of the current code, starting with the method entry. As in the test_phpdgb.php file, the opline of the code "$param = $param +" baba ";" in line 18 is 2.
Prompt > b func#2prompt > rdemo::__construct:5method func 2 [Breakpoint # 0 resolved at func#2 (opline 0x7f5b230a2e38)] [Breakpoint # 0 resolved at func#2 (opline 0x7f5b230a2e38)] [Breakpoint # 0 resolved at func#2 (opline 0x7f5b230a2e38)] [Breakpoint # 0 in func () # 2 at. / test_phpdbg.php:18, hits: 1] > 00018: $param = $param + "baba"; 00019: echo "function func $param\ n"; 00020:}.
6. View breakpoints
Like gdb, phpdbg uses the info break command to view breakpoints. Examples are as follows:
.. prompt > info break---File Breakpoints:#1 / home/hailong.xhl/test_phpdbg.php:10- -Opline Breakpoints:#0 7ff3219e1df0 (function breakpoint)-Function opline Breakpoints:#0 func opline 2....
From the above display, we can know. The type of breakpoint is also shown in the display result of info break. The number after # is the breakpoint. We can delete breakpoints according to the breakpoint number.
7. Delete breakpoints
Not the same as the gdb command. The delete breakpoint of phpdbg is not the delete command, but the break del command. Examples are as follows:
Prompt > break del 1 [Deleted breakpoint # 1] prompt >.
The number 1 after break del is the breakpoint number.
8. View the code
The command for phpdbg to view the code is also list. But compared with gdb, it is used in a variety of ways.
Displays the code for the specified function:
Prompt > l f func 00017: $param = "ali"; 00018: $param = $param + "baba"; 00019: echo "function func $param\ n"; 00020:} 00021:prompt >.
Single-step execution
The single step execution of phpdbg has only one command, step. It's similar to gdb's step command. It's all line-by-line execution code. Note that there is no next command for phpdbg.
Prompt > s [Breakpoint # 0 resolved at func#2 (opline 0x152ba40)] [L19 0x152ba70 ZEND_ADD_STRING C2 @ 0. / test_phpdbg.php] > 00019: echo "function func $param\ n"; 00020:} 00021.
Continue to execute
Like gdb, the continuing command for phpdbg is continue, abbreviated to c.
Execute php code
This is a feature of phpdbg. You can use the ev command to execute arbitrary php code during debugging. Such as:
Prompt > ev $var = "val"; valprompt > ev var_dump ($var); string (3) "val".
In this way, you can dynamically modify the value of the variable during debugging to see the execution effect.
Thank you for reading, the above is the content of "how to understand the debugging module PHPDBG of PHP". After the study of this article, I believe you have a deeper understanding of how to understand the debugging module PHPDBG of PHP, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.