如何在 VSCode 中调试 FreePascal
当我使用 VSCode 为 Pascal 语言编写代码时,我安装了一些扩展来调试我的程序。我使用 Native Debug 进行调试。我在网上查阅了一些教程,但没有成功。告诉我这里有什么错误。
我的 json 文件:
launch.json
{
"version": "0.2.0",
"configurations": [
{
"type": "gdb",
"request": "launch",
"name": "Debug",
"target": "${fileBasenameNoExtension}",
"cwd": "${workspaceFolder}",
// "terminal": "",
"valuesFormatting": "parseText",
"MIMode": "gdb",
"miDebuggerPath": "C:\\FPC\\3.2.2\\bin\\i386-win32\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "fpc: Build Debug",
"postDebugTask": "fpc: Clean Files"
},
]
}
和 < strong>tasks.json
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{ // shortcut: cmd+shift+B (run build task)
"label" : "fpc: Build Debug",
"type" : "shell",
"group": {
"kind": "build",
"isDefault": true
},
"command": "fpc",
"args": [
"${file}", // source code file
"-Px86_64", // target platform 64-bit
"-Mobjfpc", // object pascal mode
"-S2cahi", // pascal syntax setting
"-Croti", // generated code setting
"-O1", // code optimization setting
"-glpsw3", // debug info setting
"-godwarfcpp", // dwarf mode setting
"-v" // verbose message
],
"problemMatcher": []
},
{ // shortcut: none
"label" : "fpc: Build Release",
"type" : "shell",
"group" : "build",
"command": "fpc",
"args": [
"${file}", // source code file
"-Px86_64", // target platform 64-bit
"-Mobjfpc", // object pascal mode
"-S2cahi", // pascal syntax setting
"-Croti", // generated code setting
"-O3", // code optimization setting
"-XXs", // executable setting
"-v" // verbose message
],
"problemMatcher": []
},
{ // shortcut: none
"label": "fpc: Syntax Check",
"type": "shell",
"group": "build",
"command": "fpc",
"args": [
"${file}", // source code file
"-Px86_64", // target platform 64-bit
"-Mobjfpc", // object pascal mode
"-S2cahi", // pascal syntax setting
"-s", // syntax check mode
"-v" // verbose message
],
"problemMatcher": []
},
{ // shortcut: cmd+shift+R (run test task)
"label": "fpc: Execute Binary",
"type": "shell",
"group": {
"kind": "test",
"isDefault": true
},
"command": "${fileBasenameNoExtension}",
"args": [],
"problemMatcher": []
},
{ // shortcut: none
"label": "fpc: Clean Files",
"type": "shell",
"command": "rm",
"args": [
"${fileBasenameNoExtension}", // executable file
"${fileDirname}/*.a", // generated linker file
"${fileDirname}/*.o", // generated object file
"${fileDirname}/*.exe",
"${fileDirname}/*.s", // generated assembler file
"${fileDirname}/*.ppu", // generated unit file
"${fileDirname}/*.dwarf", // generated dwarf debug file
"*.res", // generated resource file
"ppas.bat", // generated build script file
],
"problemMatcher": []
}
]
}
我使用的是 Windows 操作系统。帮我。
As I use VSCode to code for Pascal language and I have installed some extensions to debug my program. I use Native Debug for debugging. I have consulted several tutorials on the net but with no success. Tell me what is the error here.
My json files:
launch.json
{
"version": "0.2.0",
"configurations": [
{
"type": "gdb",
"request": "launch",
"name": "Debug",
"target": "${fileBasenameNoExtension}",
"cwd": "${workspaceFolder}",
// "terminal": "",
"valuesFormatting": "parseText",
"MIMode": "gdb",
"miDebuggerPath": "C:\\FPC\\3.2.2\\bin\\i386-win32\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "fpc: Build Debug",
"postDebugTask": "fpc: Clean Files"
},
]
}
and tasks.json
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{ // shortcut: cmd+shift+B (run build task)
"label" : "fpc: Build Debug",
"type" : "shell",
"group": {
"kind": "build",
"isDefault": true
},
"command": "fpc",
"args": [
"${file}", // source code file
"-Px86_64", // target platform 64-bit
"-Mobjfpc", // object pascal mode
"-S2cahi", // pascal syntax setting
"-Croti", // generated code setting
"-O1", // code optimization setting
"-glpsw3", // debug info setting
"-godwarfcpp", // dwarf mode setting
"-v" // verbose message
],
"problemMatcher": []
},
{ // shortcut: none
"label" : "fpc: Build Release",
"type" : "shell",
"group" : "build",
"command": "fpc",
"args": [
"${file}", // source code file
"-Px86_64", // target platform 64-bit
"-Mobjfpc", // object pascal mode
"-S2cahi", // pascal syntax setting
"-Croti", // generated code setting
"-O3", // code optimization setting
"-XXs", // executable setting
"-v" // verbose message
],
"problemMatcher": []
},
{ // shortcut: none
"label": "fpc: Syntax Check",
"type": "shell",
"group": "build",
"command": "fpc",
"args": [
"${file}", // source code file
"-Px86_64", // target platform 64-bit
"-Mobjfpc", // object pascal mode
"-S2cahi", // pascal syntax setting
"-s", // syntax check mode
"-v" // verbose message
],
"problemMatcher": []
},
{ // shortcut: cmd+shift+R (run test task)
"label": "fpc: Execute Binary",
"type": "shell",
"group": {
"kind": "test",
"isDefault": true
},
"command": "${fileBasenameNoExtension}",
"args": [],
"problemMatcher": []
},
{ // shortcut: none
"label": "fpc: Clean Files",
"type": "shell",
"command": "rm",
"args": [
"${fileBasenameNoExtension}", // executable file
"${fileDirname}/*.a", // generated linker file
"${fileDirname}/*.o", // generated object file
"${fileDirname}/*.exe",
"${fileDirname}/*.s", // generated assembler file
"${fileDirname}/*.ppu", // generated unit file
"${fileDirname}/*.dwarf", // generated dwarf debug file
"*.res", // generated resource file
"ppas.bat", // generated build script file
],
"problemMatcher": []
}
]
}
I am using windows operating system. help me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

我的猜测是,您使用 64 位 FPC(目标),但 VSCode 中仅安装了 32 位 GDB(请参阅 launch.json 中的 miDebuggerPath)。看看是否可以将 nativedebug 指向 64 位 GDB。
如果需要,您可以在此处找到与 Lazarus 一起使用的 64 位 gdb:https://sourceforge.net/projects/lazarus/files/Lazarus%20Windows%2064%20bits/Alternative%20GDB/
My guess is that you use a 64-bit FPC (target), but only have a 32-bit GDB (see miDebuggerPath in launch.json) installed in your VSCode. See if you can point nativedebug to a 64-bit GDB.
If needed, you can find 64-bit gdb's for use with Lazarus here: https://sourceforge.net/projects/lazarus/files/Lazarus%20Windows%2064%20bits/Alternative%20GDB/