The phpdbg of the powerful tool of PHP debugging

Source: Internet
Author: User
Tags spl php debugger php source code sapi string methods
The phpdbg of the powerful tool of PHP debugging

Phpdbg is a PHP SAPI module that allows you to control the operating environment of PHP without modifying the code and without compromising performance.

Phpdbg's goal is to be a lightweight, powerful and easy-to-use PHP debugging platform. Can be used in PHP5.4 and above versions. The php5.6 and above versions will be internally integrated.

Main functions:



– Single Step Commissioning

– Flexible down-Breakpoint mode (class method, function, file: line, memory address, opcode)

– The eval of PHP can be called directly

– You can view the code that is currently executing

– User space API (userland/user spaces)

– Easy Integration

– Support for specifying PHP configuration files

–jit Global Variables

–readline Support (optional), terminal operation more convenient

– Remote debug, using the Java GUI

– Easy to operate (see Help for details)

Installation

In order to use PHPDGB, you first need to download a PHP source package. Then download the PHPDGB source package, and put it in the PHP source package SAPI directory. Finally, you can execute the command to install it. The compile and install examples are as follows:

Suppose we have downloaded the PHP source package 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 version, PHPDBG has been integrated in the PHP code package, no need to download separately.

2, compile the parameters to remember to add –enable-phpdbg.

3, compile-time parameters, –with-readline can be added selectively. If not added, phpdbg's history and other functions cannot be used.

Basic Use

1. Parameter Introduction

Phpdbg is a PHP sapi that can debug PHP as a command-line method. Common parameters are as follows:

The following switches is 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 Don't print banner on startup

-R Jump straight to run

-e Enable step through eval ()

NOTE:PASSING-RR would cause phpdbg to quit after execution, rather than returning to the console

2. Common functions

We have previously introduced the GDB tool. In fact, phpdbg and gdb function in some places very similar. For example, you can set breakpoints, you can step through, and so on. Just the language they are debugging is different, GDB focuses on debugging the C or C + + language, while phpdbg focuses on debugging the PHP language. Below we will introduce some common debugging functions of phpdbg. The code to debug is as follows:

The file test_phpdbg_inc.php source code is as follows:

 
  



The source code for file test_phpdgb.php is as follows:

 
  Func (1); Func (); Phpdbg_inc_func ();? >



3. Start phpdbg

Phpdbg after the installation is successful, it will be in the bin directory of the installation directory. Go to 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[pleas E report bugs to 
 
  
   
  ]prompt>
 
  



To load the PHP script you want to debug, just 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've used other debugging tools before, you'll find phpdbg similar to them. However, you will often need to get help information when you use it early. The help command allows us to obtain assistance information.

......prompt> helpphpdbg is a lightweight, powerful and easy to use debugging platform for Php5.4+it supports the Follo Wing commands:information list   list PHP source ...



5. Set Breakpoints

The command to set breakpoints is the same as GDB. All are break, abbreviated in Form B. However, the specific command parameters are still different. In the same way as GDB's breakpoint commands, they can set breakpoints "by file name: line number" or line number. In addition to this, phpdbg also provides some ways to set breakpoints specific to PHP. For example, set breakpoints according to Opline, set breakpoints according to OpCode, and so on.

It is well known that the PHP code is eventually parsed into opcode and then executed by the PHP kernel. A PHP statement that may parse into multiple opcode. If you can set breakpoints by pressing opcode, we can more precisely track the program execution process. Let's take a look at the specific example of phapdbg setting breakpoints.

Press Opline to set breakpoints:

The opline here is the line number of the current code with the method entry as the starting point. As in the test_phpdgb.php file, line 18th of the code "$param = $param +" Baba ";" The Opline is 2.

......prompt> b func#2prompt> rdemo::__construct:5method func 2[breakpoint #0 resolved at func#2 (Opline 0x7f5b230a 2E38)][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 "func tion func $param \ n "; 00020:} ...



6. View Breakpoints

Like GDB, PHPDBG also 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 ....



Through the above display, we can know. The type of breakpoint is also displayed in the display result of info break. #后面的数字是断点号. We can delete breakpoints based on the breakpoint number.

7. Delete Breakpoints

Not the same as the GDB command. The phpdbg delete Breakpoint 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 Code

phpdbg the command to view the code is also list. But compared to GDB, the way you use it is a bit more.

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

phpdbg single step execution with only one command step. Similar to GDB's step command. is a line of execution code. Note that the phpdbg does not have a next command.

....prompt> S[breakpoint #0 resolved at func#2 (opline 0x152ba40)][l19      0x152ba70 zend_add_string     C2   @0< c3/>./test_phpdbg.php]>00019:   echo "function func $param \ n";; 00020:} 00021: ....



Continue execution

Like GDB, phpdbg's continuation command is also continue, abbreviated as 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, variable values are dynamically modified during debugging to see the effect of the execution.

The above is the whole content of this article, easy to play debugging tool phpdbg, I hope you like.

Extended Reading

Advanced knowledge of PHP series of technical Articles to organize the collection

The phpdbg of a powerful tool for 1PHP commissioning

2PHP Performance Analysis (i): Xhprof & Xhgui Introduction

3 Now write PHP, you should know these

4PHP FastCGI and mod_php

5PHP performance analysis and experimentation: microscopic analysis of performance

6PHP configuration file php.ini Chinese translation (full)

7PHP command-line command usage guide

8 How to hide the PHP version number on a Linux system server

9PHP Socket Programming Detailed

A summary of the series functions of sockets in 10php

11 correct PHP matches regular expressions for UTF-8 Chinese

12PHP Performance Analysis tool Xhprof installation Tutorial

1300 degrees engineer to say the implementation principle and performance analysis of PHP function (III.)

1400 degrees engineer the implementation principle and performance analysis of PHP function (II.)

1500 degrees engineer the implementation principle and performance analysis of PHP function (i.)

16php file system permissions issues and workarounds when running in fastcgi mode

Streams in 17PHP detailed introduction

18PHP SPL standard library data structure queue (Splqueue) and Priority queue (Splpriorityqueue)

19XSS Attack Knowledge Primer Finishing

Data structure doubly linked list of 20PHP SPL standard library (spldoublylinkedlist)

21PHP SPL standard library data structure fixed length array (splfixedarray)

22php method of implementing plug-in mechanism using reflection

23php compression and decompression of string methods

24PHP Self-brought session hidden Trouble (session file exclusive lock causes blocking)

The difference between 25Cookie and session-a good article to summarize

26 Recommended 11 PHP frameworks for Developers

27xhprof Installation && Use

Analysis of multi-thread instances in 28PHP multiple threads

29PHP implementing multi-process parallel task handlers using QPM

30PHP multi-process processing parallel Processing Task instance

Analysis of pipeline communication example of 31PHP multithreading programming

32PHP Daemon Process Instance

33php query MySQL Large amount of data caused by memory shortage solution

34PHP Exception Handling

35php ways to turn on multiple processes

How does 36HHVM improve PHP performance?

24 Cool PHP Libraries that 37PHP developers should know about (micro-framework)

38php using Iconv to solve the problem of Chinese truncation

Support Path_info detailed under 39nginx

40PHP implementation of the Get_headers function with timeout function

Get IP and geolocation class sharing in 41PHP

42 using Xdebug to analyze PHP programs to identify performance bottlenecks

43PHP developers should know 5 tips for Composer

The method of using session in 44php to prevent users from illegally logging in the background

45PHP Dependency management Tools composer Getting Started tutorial

46PHP implements the method of saving browsing history page URLs to cookies

Use Imagick to generate PSD file thumbnail tutorial in 47PHP

48 friends net about QQ related PHP code (study QQ excellent information)

49PHP callback function How to use and precautions

50PHP session may cause concurrency problems

51smarty Custom Function Htmlcheckboxes Usage instance

52php data collection from the Central Meteorological Observatory coverage of the National Weather code example

53session mechanism and related application of Session

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.