gpt4 book ai didi

c++ - 如何使用 CMake 在调试器中将 follow-fork-mode 设置为子模式

转载 作者:可可西里 更新时间:2023-11-01 17:56:42 25 4
gpt4 key购买 nike

我有 Linux 系统,我使用 Clion IDE 编写程序,其中使用 CMake。我在程序中有一部分想要调试子进程我从这个论坛上读了一些主题,但我仍然不知道如何或在哪里可以打开此功能:

gdb debugging child process after fork (follow-fork-mode child configured)

How do I debug the child process after fork() in gdb?

我刚刚尝试将标志 CMAKE_CXX_FLAGS_DEBUG 设置为 set follow-fork-mode child 但 CMake 给我错误。下面的屏幕截图包含用于编译和调试我的程序的所有标志。那么我必须在什么地方设置这个功能。

enter image description here

..::编辑::..

我相信这是个好方法。我认为你的提示很有用,但我有下一个问题。使用您的说明后,我的代码在线崩溃

pid_t newProcessForClient = fork();

声明是:

(gdb) set follow-fork-mode child [New process 31667] warning: File "/lib32/libthread_db-1.0.so" auto-loading has been declined by your `auto-load safe-path' set to "$debugdir:$datadir/auto-load". warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available. [Switching to process 31667] Continuing with signal SIGABRT.

Program terminated with signal SIGABRT, Aborted. The program no longer exists.

最佳答案

调试设置与cmake无关。 CMAKE_CXX_FLAGS_DEBUG 声明编译器的调试标志。但是,您需要告诉调试器set follow-fork-mode child。为此,您需要执行以下步骤:

  1. 在程序开始处设置一个断点(即父程序,而不是子程序)

  2. 在调试器中启动程序。

  3. 转到 clion 中的调试器控制台(标签为 gdb 的选项卡)并输入 set follow-fork-mode childset auto-load safe-路径/
  4. 继续调试

命令set auto-load safe-path/ 应该根据 documentation 切换自动加载限制。的 gdb。

关于c++ - 如何使用 CMake 在调试器中将 follow-fork-mode 设置为子模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34121840/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com