Docker环境
参考我另一篇文章: [C/C++开发] Clion利用Docker开发和调试Linux C/C++程序
下载PHP源码
https://www.php.net/distributions/php-7.4.7.tar.gz
编译PHP源码
记得要开启debug模式
./configure --prefix=/usr/local/php74 --enable-debug
配置Clion
CMakeLists.txt参考
cmake_minimum_required(VERSION 3.16) project(PHP_7_4_7) set(CMAKE_CXX_STANDARD 14) set(PHP_SOURCE /System/Volumes/Data/Software/Project/pipi/test/php-7.4.7) include_directories(${PHP_SOURCE}/main) include_directories(${PHP_SOURCE}/Zend) include_directories(${PHP_SOURCE}/sapi) include_directories(${PHP_SOURCE}/pear) include_directories(${PHP_SOURCE}/TSRM) include_directories(${PHP_SOURCE}) add_custom_target(PHP_7_4_7 COMMAND make && make install WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}) add_executable(PHP_7_4_7_exec sapi/cli/php_cli.c)
Debug配置
容器内启动gdbserver
进入容器
docker exec -it mydevubuntu /bin/bash
启动gdbserver
gdbserver :2223 /usr/local/php74/bin/php
注意!这里有个坑,就是每次调试完,下一次要调试的时候,要先退出上一次的gdbserver才行,要不然断点不会进来!