在启用PyCharm插件的情况下使用CLion逐步执行C

在启用PyCharm插件的情况下使用CLion逐步执行C

本文介绍了在启用PyCharm插件的情况下使用CLion逐步执行C ++代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

启用PyCharm插件后,我在CLion中遇到问题.这就是我要做的:

I am having a problem in CLion when the PyCharm plugin is enabled. This is what I do:

  1. 从外壳程序运行Python程序.该程序创建了多个进程(例如worker),其中Python代码调用了我要调试的C ++代码.
  2. 从CLion,附加到原始的主Python进程.
  3. 在一个或多个创建的进程中遇到C ++断点后,逐步执行代码.

通常,这可以正常工作.但是,如果启用了PyCharm插件,CLion似乎会以不同的方式对待主进程,并且不会遇到我的任何C ++断点.

Usually, this works fine. But if I have the PyCharm plugin enabled, CLion seems to treat the main process differently, and does not hit any of my C++ breakpoints.

有没有人知道即使启用了PyCharm插件,我也可以如何使C ++断点工作?

Does anyone know how I can get the C++ breakpoints to work, even when the PyCharm plugin is enabled?

推荐答案

我刚刚找到了适合我甚至您自己需求的解决方案.

I just found a solution that suits my needs, and maybe yours.

已在Clion 2019.3上使用Ubuntu 18.04,Python 3和GDB进行了测试.我有一个生成C ++进程的Python进程,并且我想调试两者.条件是要知道子进程的名称或PID,并有时间手动将其附加到子进程(例如主进程中的等待用户键",或派生后的某个断点).

This has been tested on Clion 2019.3 with Ubuntu 18.04, Python 3 and GDB.I have a Python process that spawns a C++ process, and I want to debug both.The condition is to know the name or PID of the child, and to have time to manually attach to the child process (so like a "wait user key" in the master process, or a breakpoint somewhere after the fork).

根据本指南,在Ubuntu上,您需要临时或永久允许附加到外部本地进程.

According to this guide, on Ubuntu you either need to temporary or permanently allow attaching to a foreign, local process.

回声0 |sudo tee/proc/sys/kernel/yama/ptrace_scope

echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope

要永久禁用此限制,请打开文件/etc/sysctl.d/10-ptrace.conf用于编辑和更改行kernel.yama.ptrace_scope = 1到kernel.yama.ptrace_scope =0.要应用更改后,输入sudo service procps restart或重新启动系统,根据您的选择.

To disable this restriction permanently, open the file /etc/sysctl.d/10-ptrace.conf for editing and change the line kernel.yama.ptrace_scope = 1 to kernel.yama.ptrace_scope = 0. To apply the changes, enter sudo service procps restart or restart your system, at your choice.

然后:

  • 为您的Python脚本创建运行配置
  • 在需要的地方放置断点
  • 以调试模式运行Python脚本
  • 等待它分叉并在等待条件/断点处中断
  • 运行->附加以处理...
  • 输入PID或C ++子代的名称
  • 瞧,您可以控制主进程和子进程

不幸的是,我不知道如何使它自动化,但是在我的项目中效果很好,因为这两个进程交换消息,所以当我阻止一个进程时,另一个进程正在等待数据,并且我有时间手动附加到该进程.

Unfortunately, I don't know how to automate it, but that works fine in my project because the two processes exchange messages so when I block one, the other is waiting for data and I have time to manually attach to it.

作为旁注,这可能也是有关此问题的答案StackOverflow .

As a side note, this is probably an answer also for this question on StackOverflow.

这篇关于在启用PyCharm插件的情况下使用CLion逐步执行C ++代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 00:10
查看更多