-
Notifications
You must be signed in to change notification settings - Fork 536
Setting up Remote Debugging Environment
-
Click on
Extensionson the left side -
Search and install
"remote development"
-
Click on
Extensions -
Search and install
"C/C++ Extension Pack"
-
Setting up SSH for connecting to remote Linux environment
-
Open 'Command Palette'(
Ctrl+Shift+P), typessh, and selectRemote-SSH: Add New SSH Host...
-
Enter in the format
[username]@[remote Linux IP].
-
It doesn't matter which option you choose; in this case, we select the top option.

-
-
Viewing code stored in the remote Linux environment on local VSCode
-
Open 'Command Palette'(
Ctrl+Shift+P), typesshand selectRemote-SSH: Add New SSH Host...
-
Select the IP of the remote Linux environment you added earlier.

-
Enter the account password for the remote Linux environment.

-

{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [{
"name" : "uftrace debugging",
"type" : "cppdbg",
"request" : "launch",
"program" : "${workspaceRoot}/uftrace",
"args" : [],
"stopAtEntry" : true,
"cwd" : "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "/usr/bin/gdb",
"setupCommands": [{
"description": "gdb pretty print",
"text" : "-enable-pretty-printing",
"ignoreFailures": true
}]
}]
}-
“args”
-
"args"is an option used to input arguments when executing the program. - This option can be used to input Command lists like
record, live, ...that can be entered when executinguftrace.
-
-
“stopAtEntry”
-
“stopAtEntry”is an option that makes the program stop at the entry point (main function) even without setting a breakpoint. It's useful when starting without breakpoints.
-
-
Set
“stopAtEntry”totrueand pressF5on the keyboard to start debugging. As shown in the screen below, you can see that it stops at the first part of themain()function ofuftrace
-
You can proceed with debugging by clicking the debugging buttons at the top of the screen or using the following shortcuts:
- Continue (F5) : Run the program until it hits a breakpoint
- Step Over (F10) : Step over functions
- Step Into (F11) : Step into functions
- Step Out (Shift + F11) : Step out of the current function
- Restart (Ctrl + Shift + F5) : Restart the program being debugged
- Stop (Shift + F5) : Stop the program being debugged
-
As shown in the picture below, you can check the current value of variables by hovering the mouse cursor over the variable name or in the
VARIABLESsection on the left side of the VSCode screen.
-
Currently, even if you run the debugging, since no agruments corresponding to the
uftracecommand have been given, the program will terminate after following a few lines.
-
Move to where the source code of
uftraceis located in the terminal window and execute the following command:$ gcc -pg -g -o t-abc tests/s-abc.c $ ls -l t-abc -rwxrwxr-x 1 minseop minseop 18168 Sep 28 17:09 t-abc
- The
-pgoption is for using the tracing function usingmcount()ofuftrace, and the-goption is for the debugger we will use to utilize debugging information.
- The
-
Here, we will debug the process of tracing the target program using the
livecommand among various commands ofuftrace -
The target program build above was build with the executable file name
t-abe, and the command to trace it with thelivecommand ofuftraceis as follows:$ uftrace live t-abc
-
You can put the
live t-abcpart above command into"args", and the entire content oflaunch.jsonis as follows:"args" : ["live", "t-abc"]
{ // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [{ "name" : "uftrace debugging", "type" : "cppdbg", "request" : "launch", "program" : "${workspaceRoot}/uftrace", "args" : ["live", "t-abc"], "stopAtEntry" : true, "cwd" : "${workspaceFolder}", "environment": [], "externalConsole": false, "MIMode": "gdb", "miDebuggerPath": "/usr/bin/gdb", "setupCommands": [{ "description": "gdb pretty print", "text" : "-enable-pretty-printing", "ignoreFailures": true }] }] }- If you want to proceed with tracing using the
recordcommand, you can change"live"to"record".
- If you want to proceed with tracing using the
-
Due to the
launch.jsonset above, this time if you follow it line by line, you can see that it follows to thecommand_live()function in thecmds/live.cfile. -
If you keep following line by line, you can see that
uftraceterminates earlier than expected after following a few lines. This is normal, and it will be explained separetely below.
- If you debug as above, you can see that it ends too early compared to the scale of uftrace code, and the reason for this is as follows.
-
As you may have noticed while following, you can see that
uftraceinternally executes thefork()funcion to run a child process, and GDB does not follow the code of the child process created byfork()without separate settings. -
To make GDB follow the code of the child process created by
fork(), a separate settingset follow-fork-mode chlidis needed, and inVSCode, you can set this option by adding an item tosetupCommandoflaunch.jsonas follow:"setupCommands": [{ ... }, { "description": "The new process is debugged after a fork. The parent process runs unimpeded.", "text": "-gdb-set follow-fork-mode child", "ignoreFailures": true }]
{ // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [{ "name" : "uftrace debugging", "type" : "cppdbg", "request" : "launch", "program" : "${workspaceRoot}/uftrace", "args" : ["record", "t-abc"], "stopAtEntry" : true, "cwd" : "${workspaceFolder}", "environment": [], "externalConsole": false, "MIMode": "gdb", "miDebuggerPath": "/usr/bin/gdb", "setupCommands": [{ "description": "gdb pretty print", "text" : "-enable-pretty-printing", "ignoreFailures": true }, { "description": "The new process is debugged after a fork. The parent process runs unimpeded.", "text": "-gdb-set follow-fork-mode child", "ignoreFailures": true }] }] }
-
-
Set a breakpoint at the
mcount_startup()function insidemcount_init(), which is the starting point oflibmcount.
-
Then, press the
F5key to start the debugger and follow along, and you can see that it stops at the breakpoint you set as shown below.
-
After this, you can debug by following the
libmcountcode as desired.
-
If the debugger stops at a different location than the breakpoint after modifying the source code inside the
libmcountdirectory, you can use the following solution. -
This issue occurs when uftrace has been previously installed on the system suing the
make installcommand. In such cases, while the debugger references the latest modified source code, it still uses thelibmcount.sofile from the system installation rather than the updated version. -
Add
"--libmcount-path=."toargsas shown below:"args" : ["live", "--libmcount-path=.", "t-abc"]
-
The launch.json file applying the above content is as follows.
{ // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [{ "name" : "uftrace debugging", "type" : "cppdbg", "request" : "launch", "program" : "${workspaceRoot}/uftrace", "args" : ["live", "--libmcount-path=.", "t-abc"], "stopAtEntry" : true, "cwd" : "${workspaceFolder}", "environment": [], "externalConsole": false, "MIMode": "gdb", "miDebuggerPath": "/usr/bin/gdb", "setupCommands": [{ "description": "gdb pretty print", "text" : "-enable-pretty-printing", "ignoreFailures": true }] }] }
- Home
- Tutorial
- Development
- Practical Use Cases
- GCC
- Clang/LLVM
- Node.js
- Chromium
- MySQL/InnoDB
- FFmpeg
- CPython
- POCO
- Telegram
- yara
- RustPython
- cURL
- bpftrace
- SpiderMonkey
- Apache HTTP Server
- GStreamer
- Squid
- TCPDUMP
- OpenCV
- Libav
- Wireshark
- LXC
- Git
- Radare2
- uftrace on Android
- deno
- parallel sort algorithm
- LevelDB/RocksDB (YCSB)
- Redis
- libjpeg‐turbo (JPEG)
- JM (H.264/AVC)
- HM (HEVC)
- VTM (VVC)
- CUDA
- Erlang/OTP BEAM
- uftrace on Yocto
- TTCN3