当前位置:网站首页>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
边栏推荐
- Host computer development (Architecture Design of firmware download software)
- 在 localStorage 中上传和检索存储图像
- 面试必刷算法TOP101之单调栈 TOP31
- WWDC2022最大的亮点: MetalFX
- Br backup test
- c#高級編程-特性篇
- 2022-06-12:在N*N的正方形棋盘中,有N*N个棋子,那么每个格子正好可以拥有一个棋子。 但是现在有些棋子聚集到一个格子上了,比如: 2 0 3 0 1 0 3 0 0 如上的二维数组代表,一
- 【微弱瞬态信号检测】混沌背景下微弱瞬态信号的SVM检测方法的matlab仿真
- Periodontitis investigation (ongoing)
- C # using multithreading
猜你喜欢
Uploading and retrieving stored images in localstorage
Reflection of C # Foundation
What is the essence of social e-commerce disruption? How can businesses get more traffic?
百货中心供应链管理系统
MongoDB系列之SQL和NoSQL的区别
2022-06-12:在N*N的正方形棋盤中,有N*N個棋子,那麼每個格子正好可以擁有一個棋子。 但是現在有些棋子聚集到一個格子上了,比如: 2 0 3 0 1 0 3 0 0 如上的二維數組代錶,一
Yolov5 analysis | parameters and performance indicators
Micro isolation (MSG)
不间断管理设计
WWDC2022最大的亮点: MetalFX
随机推荐
Ticdc introduction
通过函数seaborn.cubehelix_palette生成顺序调色板
Word document export
ISIS的vsys(虚拟系统)
Local file upload FTP or remote directory
RT-Thread 模拟器 simulator LVGL控件:switch 开关按钮控件
在 localStorage 中上传和检索存储图像
Tidb implementation plan -- III
Can flush open a stock account? Is it safe?
It's called the next generation monitoring system. Let's see how awesome it is
DM Experiment 6: filter replication
16、 IO stream (II)
考研英语
In the era of membership based social e-commerce, how do businesses build their own private domain traffic pool?
WWDC2022最大的亮点: MetalFX
[Tencent Alibaba's most comprehensive collection of test questions] (four sides: three rounds of technology +1 round of HR)
What is the essence of social e-commerce disruption? How can businesses get more traffic?
Why is the new e-commerce outlet mode so popular? What is the specific mode?
Periodontitis investigation (ongoing)
Application of DS18B20 temperature sensor based on FPGA