You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/faq/remote-gdb.mdx
+18-27Lines changed: 18 additions & 27 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,40 +4,34 @@ title: "How to do remote debugging"
4
4
type: explainer
5
5
---
6
6
7
-
### Description
8
7
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.
14
9
15
10
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
18
13
19
-
The specific operations for each step are detailed below!
20
14
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
23
17
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.)
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
28
22
```
29
23
30
-
####2. Add password inside Docker
24
+
### 2. Add password inside Docker
31
25
`passwd`
32
26
33
-
####3. Install openssh
27
+
### 3. Install openssh
34
28
35
29
```bash
36
30
apt-get update
37
31
apt-get install -y openssh-server openssh-client vim
38
32
```
39
33
40
-
####Modify system configuration
34
+
### Modify system configuration
41
35
42
36
43
37
@@ -57,13 +51,13 @@ Start the service: `/etc/init.d/ssh start` or `/etc/init.d/ssh restart`
57
51
58
52
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.
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:
86
80
@@ -91,23 +85,20 @@ Host docker_debug #docker_debug can be any name
91
85
Port 8022 #the port number in Step 1
92
86
```
93
87
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
-
:::
97
88
98
89
99
90
100
-
####2. Install Extensions in VS Code
91
+
### 2. Install Extensions in VS Code
101
92
In the extension marketplace:
102
93
103
94
- Search for and install the corresponding language extension for C++
104
95
105
96
- Search for and install the corresponding language extension for Python
106
97
107
-
####3. Configure VS Code
98
+
### 3. Configure VS Code
108
99
Click `run - open configurations`, and complete the configuration of the launch.json file according to the following scenario.
109
100
110
-
#####3.1 Scenario One: Debugging Only Python Code
101
+
#### 3.1 Scenario One: Debugging Only Python Code
111
102
112
103
**Configuration File:**
113
104
@@ -142,7 +133,7 @@ pdb.set_trace()
142
133
```
143
134
144
135
145
-
#####3.2 Scenario 2: Debugging Only C++ Code
136
+
#### 3.2 Scenario 2: Debugging Only C++ Code
146
137
147
138
**Configuration File**
148
139
@@ -174,7 +165,7 @@ pdb.set_trace()
174
165
175
166
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.
176
167
177
-
#####3.3 Scenario 3: Debugging Python and C++ Together
168
+
#### 3.3 Scenario 3: Debugging Python and C++ Together
178
169
179
170
[Reference: Example debugging mixed Python C++ in VS Code](https://nadiah.org/2020/03/01/example-debug-mixed-python-c-in-visual-studio-code/)
180
171
@@ -240,7 +231,7 @@ Trace the stack after a crash: bt
240
231
241
232
242
233
243
-
####4. VSCode Header File Autocomplete (Optional)
234
+
### 4. VSCode Header File Autocomplete (Optional)
244
235
Update the project configuration in `./.vscode/c_cpp_properties.json` by adding the appropriate header file paths.
0 commit comments