当前位置:网站首页>How to use clion to debug a project built by the make tool
How to use clion to debug a project built by the make tool
2022-06-13 07:07:00 【guangsu.】
How to use Clion Debugging use make Projects built with tools
Background introduction
CLion Support usage only Cmake Tools build project , But there are many projects that use make Build ( such as php Core source code /redis Source code ).
So how to put a make Project import to CLion in , Turn into CMake How to build , So we can use CLion Read about some open source software , We used the familiar Ladybug to debug the breakpoint
review CMake And make The relationship between
make Is to help build ( Build is a general term for a series of operation processes of compiling and generating executable programs )C/C++ Project tools ,
It can parse makefile The content in , according to makefile Medium rule Determine the order of compilation , Dependency relationship ,
The same set of source code on different platforms makefile The content is different , So in Centos Upper makefile It may take a lot of changes before you can Ubuntu Upper use .CMake Is responsible for generating for different platforms makefile,
CMake Generate makefile Rely on a called CMakeLists.txt The file of , The contents of this file also control the compilation order / Dependent on rule.CMakeLists.txt It can be used across platforms , and makefile It can't be used across platforms .
development environment
[[email protected] ~]$ cat /etc/centos-release
CentOS Linux release 7.7.1908 (Core)
[[email protected] ~]$ gcc -v
gcc version 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)
[[email protected] ~]$ gdb -v
GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-115.el7
[[email protected] ~]$ make -v
GNU Make 3.82
cmake It's using CLion It comes with the kit
CLion The version is clion2020.1
Solution analysis ( With php Source code for example )
When not in use CLion Before , This is how we compile it
wget https://www.php.net/distributions/php-7.1.0.tar.gz
tar -zxvf php-7.1.0.tar.gz
cd php-7.1.0.tar.gz
# Use official detection shell Script generation makefile
./configure --prefix=/home/sujianhui/php_debug/ --enable-fpm --enable-debug
make
make install
# Used in terminal gdb Debugging the source code
gdb /home/sujianhui/php_debug/bin/php
My goal is simple , Just want to use CLion Breakpoint debugging php Kernel source code , Easy to read , Only with a purpose can we have a solution , There are probably two ways to solve this problem
- contrast ./configure Command generated makefile, Backward generation CMakeLists.txt
- Use ./configure Generated makefile, No need to use CMake Generate a new makefile
The first way of thinking , It will soon be pass fall , This will not only take a long time , And it's easy to go wrong , Do more harm than good
The second way of thinking , Need to put CMakeLists.txt In the middle of makefile Of this link rule Replace with php The source code comes with configure Detect script generation , It works in principle
Practice
1 CLion -> File -> New CMake Project From Source Open the unzipped source directory , This step CLion A... Will be created in the root directory of the new project CMakeLists.txt file ,cmake-build-debug Folder
2 vim CMakeLists.txt, Change to the following format
cmake_minimum_required(VERSION 3.16)
project(php_7_1_0)
set(CMAKE_CXX_STANDARD 14)
# Definition php Source path , Here you can change it according to your real path
set(PHP_SOURCE /home/sujianhui/CLionProjects/php-7.1.0)
set(PHP_BIN_OUTPUT /home/sujianhui/CLionProjects/output/php7_1/)
# introduce php The required extended source code , This is also changed according to your own needs
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}/ext)
include_directories(${PHP_SOURCE})
# Be careful --enable-debug You have to add , Otherwise, breakpoint debugging will lack debugging symbol information
add_custom_target(makefile COMMAND ./configure --prefix=${PHP_BIN_OUTPUT} --enable-fpm --enable-debug && make
WORKING_DIRECTORY ${PHP_SOURCE})
add_custom_target(learn_extend COMMAND sudo ${PHP_BIN_OUTPUT}bin/phpize && ./configure --with-php-config=${PHP_BIN_OUTPUT}/bin/php-config && make
WORKING_DIRECTORY ${PHP_SOURCE})
In the above
add_custom_target(makefile COMMAND ./configure --prefix=${PHP_BIN_OUTPUT} --enable-fpm --enable-debug && make
WORKING_DIRECTORY ${PHP_SOURCE})
What a command does is execute ./configure Script generation makefile, Replace the complex that should have appeared cmake rule, After configuring this step , You will find that the ladybug has lit up
3 Click on CLion The left side of the little Ladybug in the upper navigation bar Edit Configurations, Select... From the pop-up box CMake Applications Under the makefile target To configure
# This parameter specifies when clicking the navigation bar run( Trigonometry icon) Button , Which executable to execute , Here I have chosen build Post generated php, amount to gdb $(PHP_BIN_OUTPUT)/bin/php
Executable : choice $(PHP_BIN_OUTPUT)/bin/php
# This parameter is formulated when clicking on the navigation LAN run Button , Parameters passed into the executable , Equivalent to the gdb bash In the implementation of : r /home/sujianhui/php/1.php (1.php It's a random one php file )
Programs Arguments : -f /home/sujianhui/php/1.php
# What is specified in this column is when clicking run After button , Before the real executable program is executed , Actions to be performed , Default added build operation , Each time run/debug Before , Will be forced to re Build once , This configuration depends on your personal needs
Before Launch : Get rid of Build
4 CLion Open in sapi/cli/php_cli.c , stay main The beginning of the function ( I am here 1192 That's ok ) To set breakpoints , Click on the ladybug , If it's normal , Breakpoints are already in effect
Summary
It is normal to encounter various problems during configuration , If you need this , First you have to understand the idea of the solution , Then follow this idea to solve various problems in the configuration process .
For example, you may encounter Build Time multicore compilation warning The problem of …
CLion In the navigation column Build run Debug The difference between
- Build : ./configure Generate makefile ,make Tool parsing makefile Compile , install , Until the binary executable file is generated
- run : Execute it. Build Generated binary , For example, after we compile and install php After the source , We usually look at which modules are enabled , And then we'll be at shell In the implementation of
php -m, This is it. run - Debug : Run a in debug mode to ,debug In essence, it detects child processes for the parent process ( Riru gdb Parent process ,gdb The process being debugged is a child process )
Debug Of Setting Path by : File -> Setting -> Build,Execution,Deployment -> CMake In the pop-up window , Here you can set some Debug Time parameters
Reference material
There are pictures in this one , There is something wrong with my local environment , There are no screenshots , For reference
https://blog.csdn.net/weixin_44056915/article/details/102859556
边栏推荐
- 在 localStorage 中上传和检索存储图像
- Ml: introduction to stability analysis of machine learning model and detailed introduction to common solutions
- 个人js学习笔记
- How to seize the bonus of social e-commerce through brand play to achieve growth and profit?
- 面试必刷算法TOP101之单调栈 TOP31
- Br backup test
- 线程池中的 工作线程如何被回收
- 玄武云科技通过上市聆讯:业绩波动明显,陈永辉等三人为控股股东
- Tidb dashboard modify port
- 2022-06-12:在N*N的正方形棋盘中,有N*N个棋子,那么每个格子正好可以拥有一个棋子。 但是现在有些棋子聚集到一个格子上了,比如: 2 0 3 0 1 0 3 0 0 如上的二维数组代表,一
猜你喜欢

Tidb dashboard modify port

AIO Introduction (VIII)

Nfv basic overview
![[Markov chain Monte Carlo] Markov chain Monte Carlo method sampling prior distribution](/img/8a/e6423168e110a168bc3cc6407628f6.png)
[Markov chain Monte Carlo] Markov chain Monte Carlo method sampling prior distribution

Br tool backup recovery

Smart finance is upgraded again, and jinglianwen technology provides data collection and labeling services

2022-06-12:在N*N的正方形棋盘中,有N*N个棋子,那么每个格子正好可以拥有一个棋子。 但是现在有些棋子聚集到一个格子上了,比如: 2 0 3 0 1 0 3 0 0 如上的二维数组代表,一

Fe of mL: introduction to vintage curve /vintage analysis, calculation logic and detailed introduction to case application

Upper computer development (detailed design of firmware download software)

RT-Thread 模拟器 simulator LVGL控件:switch 开关按钮控件
随机推荐
【騰訊阿裏最全面試題集錦】(四面:3輪技術+1輪HR)
That is, after the negative impact of gcat advertising e-commerce, is there no stable advertising e-commerce platform?
同花顺可以开股票账户吗?安全吗?
Database connection under WinForm
快速排序
【RS-422与RS-485】RS-422与RS-485串行接口标准
Local file upload FTP or remote directory
在 localStorage 中上传和检索存储图像
Br backup test
Chain 2+1 reward, what kind of mode is beautiful everyday seconds?
Evolution in the digital age
【ViveFocus使用WaveVR插件获取手柄操作事件】
Related operations under Oracle Database
Byte (nine)
树莓派高级开发——“IO口驱动代码的编写“ 包含总线地址、物理_虚拟地址、BCM2835芯片手册知识
汇编语言基础:寄存器和寻址方式
Tidb grafana reverse proxy
2022-06-12:在N*N的正方形棋盘中,有N*N个棋子,那么每个格子正好可以拥有一个棋子。 但是现在有些棋子聚集到一个格子上了,比如: 2 0 3 0 1 0 3 0 0 如上的二维数组代表,一
杭州网上开户是安全的吗?
RT-Thread 模拟器 simulator LVGL控件:slider 控件