程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Vscode python/c++ mixed debug

編輯:Python

VSCode Python/C++ blend Debug

  • modify set_up.py take c++ Compiled into debug info Pattern
  • To configure launch.json
  • Get pid
  • Troubleshoot attaching to processes using GDB
  • Start debug
  • docker Use this process in

modify set_up.py take c++ Compiled into debug info Pattern

The main thing is to modify setup.py in ext_modules modular
Respectively in extra_compile_args and extra_link_args Add ’-g’, It is expressed here as debug Pattern , If you compile at this time , Back in c++ After the code, it will jump continuously , The reason is because c++ It will be optimized automatically when compiling , So we need to gcc Don't let it optimize when compiling , Therefore, you need to add ’-O0’, This will be correct debug c or c++ Code. .
After modification, the code is

ext_modules = [
Pybind11Extension("sampler_core",
['sampler_core.cpp'],
extra_compile_args = ['-fopenmp','-g','-O0'],
extra_link_args = ['-fopenmp','-g'],),
]

Then recompile it

To configure launch.json

First in vscode Install plug-in on C/C++ Extension Pack, And then put launch.json Revised as follows

{
// Use IntelliSense Learn about properties .
// Hover to see the description of an existing property .
// For more information , Please visit : https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Attach",
"type": "cppdbg",
"request": "attach",
"program": "/home/amax/anaconda3/envs/torch/bin/python", //-- Modify this column for your execution pytorch Of python route
"processId": "${command:pickProcess}",
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
},
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"justMyCode": false
}
]
}

Get pid

stay python call C++ Add breakpoints to your code ( You can also use it pdb In the code pdb.set_trace()), Use

  • os.getpid()
  • ps -ef | grep python

Troubleshoot attaching to processes using GDB

Use the first method in the web page to solve

Start debug

  • vscode c++ debug vector Show incomplete solutions
  • The easiest way :*(type(*)[size])array_name
  • There are other ways to open pretty-printer The way , It seems that you need to configure , Didn't try

docker Use this process in

Not yet ,zz Students should try to succeed


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved