The background,

According to the July 2020 programming rankings, PHP is still in the top 10, indicating that PHP is still the best language in the world. PHP has a lot of advantages, as long as the right scenario, work can be used. In order to better understand the language, these days to learn PHP source code. Online information, many people directly use GDB debugging on Linux, personal experience is very poor, easy to hit the wrong command, so the configuration of Clion, visual debugging PHP7 source code. This step is recorded here, including the potholes.

2. Configuration Procedure

1. Download Clion

www.jetbrains.com/clion/ Trial for 30 days, conditional purchase

2. Compile PHP source code

A. Download the code

The version number is 7.1.10 www.php.net/distributio…

B. Configure MAC addresses
  • Install Xcode and ensure that the cmake command is available
  • Install the libiconv
The brew install libiconv configuration environment variable echo 'export PATH = "/ usr/local/opt/libiconv/bin: $PATH"' > > ~ /. ZSHRC export LDFLAGS="-L/usr/local/opt/libiconv/lib" export CPPFLAGS="-I/usr/local/opt/libiconv/include"Copy the code
  • Compile php7
mkdir php7
./configure --prefix=~/php7 --enable-fpm --enable-debug --with-iconv=/usr/local/opt/libiconv
Copy the code

— prefix: compiled file storage path – with – iconv: their installation libiconv path, MAC’s own incompatible with PHP, you need to use their own

  • Modify the Makefile file

Find -liconv, delete -liconv, and the result looks like this

EXTRA_LIBS = -lresolv -lm -lxml2 -lz -licucore -lm -lxml2 -lz -licucore -lm -lxml2 -lz -licucore -lm -lxml2 -lz -licucore -lm -lxml2 -lz -licucore -lm -lxml2 -lz -licucore -lm /usr/local/opt/libiconv/lib/libiconv.dylib
Copy the code

After they delete – liconv/usr/local/opt/libiconv/lib/libiconv dylib in the final

  • Make
  • Make install

3. Configure Clion

  • Import the project as shown below

  • After CMakeLists is imported, Clion will automatically generate cMakelists. TXT, which should be changed according to its own path, as shown in the following example
cmake_minimum_required(VERSION 3.15)
project(php_7_1_10)

set(CMAKE_CXX_STANDARD 14)

set(PHP_SOURCE ~/php-test/php-7.1.10)

include_directories(${PHP_SOURCE}/ext/bcmath)
include_directories(${PHP_SOURCE}/ext/bcmath/libbcmath)
include_directories(${PHP_SOURCE}/ext/bcmath/libbcmath/src)
include_directories(${PHP_SOURCE}/ext/bz2)
include_directories(${PHP_SOURCE}/ext/calendar)
include_directories(${PHP_SOURCE}/ext/com_dotnet)
include_directories(${PHP_SOURCE}/ext/ctype)
include_directories(${PHP_SOURCE}/ext/curl)
include_directories(${PHP_SOURCE}/ext/date)
include_directories(${PHP_SOURCE}/ext/date/lib)
include_directories(${PHP_SOURCE}/ext/dba)
include_directories(${PHP_SOURCE}/ext/dba/libcdb)
include_directories(${PHP_SOURCE}/ext/dba/libflatfile)
include_directories(${PHP_SOURCE}/ext/dba/libinifile)
include_directories(${PHP_SOURCE}/ext/dom)
include_directories(${PHP_SOURCE}/ext/enchant)
include_directories(${PHP_SOURCE}/ext/exif)
include_directories(${PHP_SOURCE}/ext/fileinfo)
include_directories(${PHP_SOURCE}/ext/fileinfo/libmagic)
include_directories(${PHP_SOURCE}/ext/filter)
include_directories(${PHP_SOURCE}/ext/ftp)
include_directories(${PHP_SOURCE}/ext/gd)
include_directories(${PHP_SOURCE}/ext/gd/libgd)
include_directories(${PHP_SOURCE}/ext/gettext)
include_directories(${PHP_SOURCE}/ext/gmp)
include_directories(${PHP_SOURCE}/ext/hash)
include_directories(${PHP_SOURCE}/ext/iconv)
include_directories(${PHP_SOURCE}/ext/imap)
include_directories(${PHP_SOURCE}/ext/interbase)
include_directories(${PHP_SOURCE}/ext/intl)
include_directories(${PHP_SOURCE}/ext/intl/breakiterator)
include_directories(${PHP_SOURCE}/ext/intl/calendar)
include_directories(${PHP_SOURCE}/ext/intl/collator)
include_directories(${PHP_SOURCE}/ext/intl/common)
include_directories(${PHP_SOURCE}/ext/intl/converter)
include_directories(${PHP_SOURCE}/ext/intl/dateformat)
include_directories(${PHP_SOURCE}/ext/intl/formatter)
include_directories(${PHP_SOURCE}/ext/intl/grapheme)
include_directories(${PHP_SOURCE}/ext/intl/idn)
include_directories(${PHP_SOURCE}/ext/intl/locale)
include_directories(${PHP_SOURCE}/ext/intl/msgformat)
include_directories(${PHP_SOURCE}/ext/intl/normalizer)
include_directories(${PHP_SOURCE}/ext/intl/resourcebundle)
include_directories(${PHP_SOURCE}/ext/intl/spoofchecker)
include_directories(${PHP_SOURCE}/ext/intl/timezone)
include_directories(${PHP_SOURCE}/ext/intl/transliterator)
include_directories(${PHP_SOURCE}/ext/intl/uchar)
include_directories(${PHP_SOURCE}/ext/json)
include_directories(${PHP_SOURCE}/ext/ldap)
include_directories(${PHP_SOURCE}/ext/libxml)
include_directories(${PHP_SOURCE}/ext/mbstring)
include_directories(${PHP_SOURCE}/ext/mbstring/libmbfl/filters)
include_directories(${PHP_SOURCE}/ext/mbstring/libmbfl/mbfl)
include_directories(${PHP_SOURCE}/ext/mbstring/libmbfl/nls)
include_directories(${PHP_SOURCE}/ext/mbstring/oniguruma)
include_directories(${PHP_SOURCE}/ext/mbstring/oniguruma/win32)
include_directories(${PHP_SOURCE}/ext/mcrypt)
include_directories(${PHP_SOURCE}/ext/mysqli)
include_directories(${PHP_SOURCE}/ext/mysqlnd)
include_directories(${PHP_SOURCE}/ext/oci8)
include_directories(${PHP_SOURCE}/ext/odbc)
include_directories(${PHP_SOURCE}/ext/opcache)
include_directories(${PHP_SOURCE}/ext/opcache/Optimizer)
include_directories(${PHP_SOURCE}/ext/openssl)
include_directories(${PHP_SOURCE}/ext/pcntl)
include_directories(${PHP_SOURCE}/ext/pcre)
include_directories(${PHP_SOURCE}/ext/pcre/pcrelib)
include_directories(${PHP_SOURCE}/ext/pcre/pcrelib/sljit)
include_directories(${PHP_SOURCE}/ext/pdo)
include_directories(${PHP_SOURCE}/ext/pdo_dblib)
include_directories(${PHP_SOURCE}/ext/pdo_firebird)
include_directories(${PHP_SOURCE}/ext/pdo_mysql)
include_directories(${PHP_SOURCE}/ext/pdo_oci)
include_directories(${PHP_SOURCE}/ext/pdo_odbc)
include_directories(${PHP_SOURCE}/ext/pdo_pgsql)
include_directories(${PHP_SOURCE}/ext/pdo_sqlite)
include_directories(${PHP_SOURCE}/ext/pgsql)
include_directories(${PHP_SOURCE}/ext/phar)
include_directories(${PHP_SOURCE}/ext/posix)
include_directories(${PHP_SOURCE}/ext/pspell)
include_directories(${PHP_SOURCE}/ext/readline)
include_directories(${PHP_SOURCE}/ext/recode)
include_directories(${PHP_SOURCE}/ext/reflection)
include_directories(${PHP_SOURCE}/ext/session)
include_directories(${PHP_SOURCE}/ext/shmop)
include_directories(${PHP_SOURCE}/ext/simplexml)
include_directories(${PHP_SOURCE}/ext/skeleton)
include_directories(${PHP_SOURCE}/ext/snmp)
include_directories(${PHP_SOURCE}/ext/soap)
include_directories(${PHP_SOURCE}/ext/sockets)
include_directories(${PHP_SOURCE}/ext/spl)
include_directories(${PHP_SOURCE}/ext/sqlite3)
include_directories(${PHP_SOURCE}/ext/sqlite3/libsqlite)
include_directories(${PHP_SOURCE}/ext/standard)
include_directories(${PHP_SOURCE}/ext/sysvmsg)
include_directories(${PHP_SOURCE}/ext/sysvsem)
include_directories(${PHP_SOURCE}/ext/sysvshm)
include_directories(${PHP_SOURCE}/ext/tidy)
include_directories(${PHP_SOURCE}/ext/tokenizer)
include_directories(${PHP_SOURCE}/ext/wddx)
include_directories(${PHP_SOURCE}/ext/xml)
include_directories(${PHP_SOURCE}/ext/xmlreader)
include_directories(${PHP_SOURCE}/ext/xmlrpc)
include_directories(${PHP_SOURCE}/ext/xmlrpc/libxmlrpc)
include_directories(${PHP_SOURCE}/ext/xmlwriter)
include_directories(${PHP_SOURCE}/ext/xsl)
include_directories(${PHP_SOURCE}/ext/zip)
include_directories(${PHP_SOURCE}/ext/zip/lib)
include_directories(${PHP_SOURCE}/ext/zlib)
include_directories(${PHP_SOURCE}/main)
include_directories(${PHP_SOURCE}/main/streams)
include_directories(${PHP_SOURCE}/netware)
include_directories(${PHP_SOURCE}/sapi/apache2handler)
include_directories(${PHP_SOURCE}/sapi/cli)
include_directories(${PHP_SOURCE}/sapi/embed)
include_directories(${PHP_SOURCE}/sapi/fpm/fpm)
include_directories(${PHP_SOURCE}/sapi/fpm/fpm/events)
include_directories(${PHP_SOURCE}/sapi/litespeed)
include_directories(${PHP_SOURCE}/sapi/phpdbg)
include_directories(${PHP_SOURCE}/TSRM)
include_directories(${PHP_SOURCE}/win32)
include_directories(${PHP_SOURCE}/Zend)
include_directories(${PHP_SOURCE})

add_custom_target(makefile COMMAND make && make install WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
Copy the code
  • The configuration profile

The upper right corner generates the following configuration (the makefile after overwriting CMakelist)

Click On Edit Configurations to configure the following:

  • 1, create CMake Applicaiton

If you don’t have it, you can create it from the template

  • 2. Select the target configured in CMakelist
  • 3. Find the path of the compiled file and select the generated binary file
  • 4, PHP file path parameters to run

-f ~/test/test.php

  • 5, the working directory, PHP test file parent directory

~/test/test.php

  • 6. Finally, click Apply and click OK

4. Run tests

  • Add a breakpoint in the following screenshot (sapi->cli->php_cli.c), which is the main entry of the command line

  • If the breakpoint is not successful, change the Debugger to try:

preference->Build,Exexuction… ->Toolchains-> Toolchains-> Toolchains-> Toolchains

  • The effect diagram of successful operation is as follows:

Third, summary

The simple summary is to download the PHP source code, compile it, then configure clion, and debug it in Clion. In this way, you can debug code conveniently. During the debugging process, you can view the jump process of the code, improving the reading efficiency.