VS code
"request": "launch",
"program": "${fileDirname}/qtest", //改成我們指定的指定 qtest 執行檔名稱路徑
"preLaunchTask": "gcc build active file",
"miDebuggerPath": "/usr/bin/gdb"
修改後如下
launch.json
{
// 使用 IntelliSense 以得知可用的屬性。
// 暫留以檢視現有屬性的描述。
// 如需詳細資訊,請瀏覽: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "gcc - 建置及偵錯使用中的檔案",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/qtest", //指定 qtest 執行檔名稱路徑
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "啟用 gdb 的美化顯示",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
}
]
}
How to debug C code with GDB in VSCode (Linux)
在 lab0-c 中,直接使用 gdb 對 qtest 除錯會遇到 SIGALRM 導致超時。而透過 python scripts/debug.py -d
則可以啟動已經忽略 SIGALRM 的 gdb。同理我們也能在 .vscode/launch.json
的 setupCommands
設定:
"setupCommands": [
{
"description": "Ignore SIGALRM signal",
"text": "handle SIGALRM ignore",
"ignoreFailures": true
},
{
"text": "backtrace",
"ignoreFailures": true
},
]
巨集在前處理期間就被展開,故 gdb 無法像函式一樣使用它們。這對於常用的巨集 (e.g., container_of
) 稍有不便。我們當然能夠在 gdb 裡面暴力打出所有已知資訊,透過類似:
(gdb) p (struct my_container *)((char *)my_member_ptr - offsetof(struct my_container, member))
獲得我們要的 debug 資訊,但我們也能透過 python 的 gdb package 去實作實用的函式,進而降低使用時的複雜度。如果你也想使用客製化且能使用 VSCode 除錯介面的 gdb,請參考 〈Linux2025q1: Toolchain Write-Up〉 和 commit cb104ee。裡面介紹了如何實作 container_of
等功能,讓你 debug 更輕鬆。
or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Syncing