Skip to content

Commit 9391d18

Browse files
committed
处理remote-gdb层级结构
1 parent 72b9ea9 commit 9391d18

File tree

3 files changed

+42
-46
lines changed

3 files changed

+42
-46
lines changed

docs/faq/remote-gdb.mdx

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,34 @@ title: "How to do remote debugging"
44
type: explainer
55
---
66

7-
### Description
87

9-
During the process of program development, it is often necessary to configure various development environments. If there are differences in environment dependencies between local and online, it may cause some unknown bugs. It is recommended to use **Docker**.
10-
11-
In the daily development process, project code is often stored on a remote host. We usually use SSH to connect to the remote host from our local machine for development.
12-
13-
So, how can we enter the remote host's Docker container for code debugging? In this section, we will take the widely used **vscode** as an example to introduce how to use vscode to remotely access the Docker container for c++/python development/debugging. For other IDEs, interested users can Google it.
8+
In this section, we will introduce how to use vscode to remotely access the Docker container for c++/python development/debugging.
149

1510
To complete this, there are two main steps:
16-
Step 1: Configure the Docker on the remote host
17-
Step 2: Configure vscode
11+
- Step 1: Configure the Docker on the remote host
12+
- Step 2: Configure vscode
1813

19-
The specific operations for each step are detailed below!
2014

21-
### Step 1: Configure Docker on the remote host
22-
#### 1. Start Docker
15+
## Step 1: Configure Docker on the remote host
16+
### 1. Start Docker
2317
To allow vscode to SSH into the Docker container, we need to assign a port number when starting the Docker container. The specific startup method is as follows: (8022 is the host port, which can be modified to avoid conflicts. 22 is the fixed port inside Docker and can be left as default.)
2418

2519
```bash
2620
docker_image_name=nvcr.io/nvidia/pytorch:22.12-py3
2721
docker run -it --gpus all --ipc=host --ulimit memlock=-1 --ulimit stack=67108864 -p 8022:22 -v `pwd`:/workspace --name="any_names" --cap-add=SYS_PTRACE $docker_image_name bash
2822
```
2923

30-
#### 2. Add password inside Docker
24+
### 2. Add password inside Docker
3125
`passwd`
3226

33-
#### 3. Install openssh
27+
### 3. Install openssh
3428

3529
```bash
3630
apt-get update
3731
apt-get install -y openssh-server openssh-client vim
3832
```
3933

40-
#### Modify system configuration
34+
### Modify system configuration
4135

4236

4337

@@ -57,13 +51,13 @@ Start the service: `/etc/init.d/ssh start` or `/etc/init.d/ssh restart`
5751

5852
After starting the service, you can perform connection verification: `ssh -p 22 root@127.0.0.1`. If the startup fails, it will report a "Connection refused" error. If successful, it will prompt you to enter a password and display a "Welcome" message.
5953

60-
#### 5. Install debugging tools inside Docker
54+
### 5. Install debugging tools inside Docker
6155

6256
```bash
6357
apt-get install gdb
6458
```
6559

66-
#### Compile torchpipe in debug mode
60+
### 6. Compile torchpipe in debug mode
6761

6862

6963
Change directory to torchpipe:
@@ -77,10 +71,10 @@ DEBUG=1 NCATCH_SUB=1 pip3 install -e .
7771
```
7872

7973

80-
### Step 2: Configure vscode
74+
## Step 2: Configure vscode
8175

8276

83-
#### 1. Connect vscode to remote Docker
77+
### 1. Connect vscode to remote Docker
8478

8579
Configure the ssh config file as follows, **note that User is root**, start vscode, install the Remote-SSH plugin, and configure the config as follows:
8680

@@ -91,23 +85,20 @@ Host docker_debug #docker_debug can be any name
9185
Port 8022 #the port number in Step 1
9286
```
9387

94-
:::tip For users in China
95-
f you find the network speed too slow, please refer to [Offline installation of vscode server](https://zhuanlan.zhihu.com/p/426876766) and its top comments.
96-
:::
9788

9889

9990

100-
#### 2. Install Extensions in VS Code
91+
### 2. Install Extensions in VS Code
10192
In the extension marketplace:
10293

10394
- Search for and install the corresponding language extension for C++
10495

10596
- Search for and install the corresponding language extension for Python
10697

107-
#### 3. Configure VS Code
98+
### 3. Configure VS Code
10899
Click `run - open configurations`, and complete the configuration of the launch.json file according to the following scenario.
109100

110-
##### 3.1 Scenario One: Debugging Only Python Code
101+
#### 3.1 Scenario One: Debugging Only Python Code
111102

112103
**Configuration File:**
113104

@@ -142,7 +133,7 @@ pdb.set_trace()
142133
```
143134

144135

145-
##### 3.2 Scenario 2: Debugging Only C++ Code
136+
#### 3.2 Scenario 2: Debugging Only C++ Code
146137

147138
**Configuration File**
148139

@@ -174,7 +165,7 @@ pdb.set_trace()
174165

175166
You can directly execute your Python file, such as python3 a.py, and then start "(gdb) Attach" to bind to the Python process. If the Python process exits too quickly, you can sleep for a period of time to begin debugging.
176167

177-
##### 3.3 Scenario 3: Debugging Python and C++ Together
168+
#### 3.3 Scenario 3: Debugging Python and C++ Together
178169

179170
[Reference: Example debugging mixed Python C++ in VS Code](https://nadiah.org/2020/03/01/example-debug-mixed-python-c-in-visual-studio-code/)
180171

@@ -240,7 +231,7 @@ Trace the stack after a crash: bt
240231

241232

242233

243-
#### 4. VSCode Header File Autocomplete (Optional)
234+
### 4. VSCode Header File Autocomplete (Optional)
244235
Update the project configuration in `./.vscode/c_cpp_properties.json` by adding the appropriate header file paths.
245236
```json
246237
{

i18n/zh/docusaurus-plugin-content-docs/current/faq/remote-gdb.mdx

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,40 @@ title: "如何进行远程调试"
44
type: explainer
55
---
66

7-
### 说明
8-
7+
98
在程序开发过程中,经常需要我们去配置各种开发环境,并且如果本地与线上存在环境依赖的不同,还可能导致出现一些不知原因的bug,比较推荐使用的便是**Docker**
109

1110
在日常开发过程中,项目代码往往存放在远程的主机中,我们通常利用本地机器通过SSH连接到远程主机进行开发。
1211

1312
那么,如何进入到远程主机docker内部进行代码调试呢?本节以使用较为广泛的**vscode**为例,介绍如何通过vscode远程到docker容器内部进行c++/python部分的开发/调试工作。其他的IDE,感兴趣的用户可以自行Google。
1413

1514
要完成这个主要有两步骤:
16-
步骤一、配置远程主机的docker
17-
步骤二、配置vscode
15+
16+
- 步骤一、配置远程主机的docker
17+
- 步骤二、配置vscode
1818

1919
下面详细介绍每一步的具体操作!
2020

2121

22-
### 步骤一:远程主机docker配置
23-
#### 1. 启动docker
22+
## 步骤一:远程主机docker配置
23+
### 1. 启动docker
2424
为了能够让vscode能够ssh连接到docker中,我们需要在启动docker容器的时候为其分配端口号。具体的启动方式如下:(8022为宿主端口,可修改,防止冲突。22为docker内的固定端口,默认即可)
2525

2626
```bash
2727
docker_image_name=nvcr.io/nvidia/pytorch:22.12-py3
2828
docker run -it --gpus all --ipc=host --ulimit memlock=-1 --ulimit stack=67108864 -p 8022:22 -v `pwd`:/workspace --name="any_names" --cap-add=SYS_PTRACE $docker_image_name bash
2929
```
3030

31-
#### 2. docker内增加密码
31+
### 2. docker内增加密码
3232
`passwd`
3333

34-
#### 3. 安装openssh
34+
### 3. 安装openssh
3535
```bash
3636
apt-get update
3737
apt-get install -y openssh-server openssh-client vim
3838
```
3939

40-
#### 4. 修改系统配置
40+
### 4. 修改系统配置
4141
```bash
4242
vim /etc/ssh/sshd_config
4343
```
@@ -52,12 +52,12 @@ PubkeyAuthentication yes
5252
启动服务后可以进行连接验证:`ssh -p 22 root@127.0.0.1`,如果启动失败,会报Connection refused的错误,成功则会让你输入密码,并有Welcome字样提示。
5353

5454

55-
#### 5. docker内安装调试工具
55+
### 5. docker内安装调试工具
5656
```bash
5757
apt-get install gdb
5858
```
5959

60-
#### 6. 编译torchpipe为debug模式
60+
### 6. 编译torchpipe为debug模式
6161

6262
进入到torchpipe目录
6363

@@ -69,9 +69,9 @@ DEBUG=1 NCATCH_SUB=1 pip3 install -e .
6969
```
7070

7171

72-
### 步骤二:vscode配置
72+
## 步骤二:vscode配置
7373

74-
#### 1. vscode连接远程docker
74+
### 1. vscode连接远程docker
7575

7676
按如下方式配置ssh的config文件,**注意User为root**,启动vscode,安装Remote-SSH插件,配置config如下:
7777

@@ -85,19 +85,19 @@ Host docker_debug #docker_debug为名字,随便起
8585
:::tip 国内用户
8686
如果觉得网速过慢,参考 [离线安装vscode server](https://zhuanlan.zhihu.com/p/426876766) 及其置顶评论。
8787
:::
88-
#### 2. vscode安装扩展
88+
### 2. vscode安装扩展
8989
在扩展商店内:
9090

9191
- 搜索 c++ 安装相应语言扩展
9292

9393
- 搜索 python 安装相应语言扩展
9494

95-
#### 3. vscode配置
95+
### 3. vscode配置
9696

9797
点击 `run - open configurations`, 按照如下场景完成配置文件launch.json的配置。
9898

9999

100-
##### 3.1 情境一:仅调试Python部分代码
100+
#### 3.1 情境一:仅调试Python部分代码
101101

102102
**配置文件:**
103103

@@ -134,7 +134,7 @@ pdb.set_trace()
134134

135135

136136

137-
##### 3.2 情境二:仅调试C++部分代码
137+
#### 3.2 情境二:仅调试C++部分代码
138138

139139
**配置文件**
140140

@@ -168,7 +168,7 @@ pdb.set_trace()
168168

169169

170170

171-
##### 3.3 情境三:python和C++联调
171+
#### 3.3 情境三:python和C++联调
172172

173173
[参考链接: Example debugging mixed Python C++ in VS Code](https://nadiah.org/2020/03/01/example-debug-mixed-python-c-in-visual-studio-code/)
174174

@@ -236,7 +236,7 @@ run your.py
236236

237237

238238

239-
#### 4. vscode头文件补全(可选)
239+
### 4. vscode头文件补全(可选)
240240
修改 项目配置 `./.vscode/c_cpp_properties.json`
241241
补充相应头文件路径
242242
```json

static/images/logo_gpt.svg

Lines changed: 5 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)