VSCode Remote-ssh ARM GDB 远程调试
- 一:VSCode增加配置文件
- 1.Predefined variables
- 2.配置文件
- 二:配置gdbserver
- 三:VSCode调试程序
- 三:gdb连接gdbserver调试
- 四:Remote 'g' packet reply is too long
一:VSCode增加配置文件
1.Predefined variables
${userHome} - the path of the user's home folder
${workspaceFolder} - the path of the folder opened in VS Code
${workspaceFolderBasename} - the name of the folder opened in VS Code without any slashes (/)
${file} - the current opened file
${fileWorkspaceFolder} - the current opened file's workspace folder
${relativeFile} - the current opened file relative to workspaceFolder
${relativeFileDirname} - the current opened file's dirname relative to workspaceFolder
${fileBasename} - the current opened file's basename
${fileBasenameNoExtension} - the current opened file's basename with no file extension
${fileExtname} - the current opened file's extension
${fileDirname} - the current opened file's folder path
${fileDirnameBasename} - the current opened file's folder name
${cwd} - the task runner's current working directory upon the startup of VS Code
${lineNumber} - the current selected line number in the active file
${selectedText} - the current selected text in the active file
${execPath} - the path to the running VS Code executable
${defaultBuildTask} - the name of the default build task
${pathSeparator} - the character used by the operating system to separate components in file paths
${/} - shorthand for ${pathSeparator}
2.配置文件
.vscode/tasks.json
{
//编译使用文件
"tasks": [
{
"label": "arm build", //任务的名字叫Build,注意是大小写区分的,等会在launch.json中(preLaunchTask)调用这个名字
"type": "shell",
"command": "make", //编译命令
"args": [], //编译参数
"problemMatcher": [
"$gcc" //使用gcc捕获错误
],
"options": {
"cwd": "${workspaceFolder}" //vs code 打开的文件夹路径
},
"group": {
"kind": "build",
"isDefault": true
// 任务分组,因为是tasks而不是task,意味着可以连着执行很多任务
// 在build组的任务们,可以通过在Command Palette(F1) 输入run build task来运行
// 当然,如果任务分组是test,你就可以用run test task来运行
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
.vscode/launch.json
{
// 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
// 调试使用文件
// ${workspaceFolder} :表示当前workspace文件夹路径,也即/home/Coding/Test
// ${workspaceRootFolderName}:表示workspace的文件夹名,也即Test
// ${file}:文件自身的绝对路径,也即/home/Coding/Test/.vscode/tasks.json
// ${relativeFile}:文件在workspace中的路径,也即.vscode/tasks.json
// ${fileBasenameNoExtension}:当前文件的文件名,不带后缀,也即tasks
// ${fileBasename}:当前文件的文件名,tasks.json
// ${fileDirname}:文件所在的文件夹路径,也即/home/Coding/Test/.vscode
// ${fileExtname}:当前文件的后缀,也即.json
// ${lineNumber}:当前文件光标所在的行号
// ${env:PATH}:系统中的环境变量
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch", //这个应该是F1中出现的名字
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/taskManager", //需要运行的程序
"args": [], //程序执行需要传入的参数
"stopAtEntry": false, //true时,打开控制台以后停止,暂时不执行程序
"cwd": "${workspaceFolder}", //当前工作路径
"environment": [],
"externalConsole": false, //使用外部控制台
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: make build project", //执行编译任务,内容对应task.json中label选项。//在launch之前运行的任务名,这个名字一定要跟tasks.json中的任务名字大小写一致
"miDebuggerPath": "/usr/bin/gdb", //调试指令
"miDebuggerServerAddress": "192.168.6.160:9001"//gdb server
}
]
}
二:配置gdbserver
gdbserver ip:port 程序
三:VSCode调试程序
三:gdb连接gdbserver调试
gdb
target remote ip:port
四:Remote ‘g’ packet reply is too long
重新编译gdb/gdbserver
修改gdb/remote.c文件,屏蔽process_g_packet函数中的下列两行:
if (buf_len > 2 * rsa->sizeof_g_packet)
error (_(“Remote ‘g’ packet reply is too long: %s”), rs->buf);
在其后添加:
if (buf_len > 2 * rsa->sizeof_g_packet) {
rsa->sizeof_g_packet = buf_len ;
for (i = 0; i < gdbarch_num_regs (gdbarch); i++)
{
if (rsa->regs[i].pnum == -1)
continue;
if (rsa->regs[i].offset >= rsa->sizeof_g_packet)
rsa->regs[i].in_g_packet = 0;
else
rsa->regs[i].in_g_packet = 1;
}
}