1.1

VSCode + GDBServer 远程调试C/C++流水账

VSCode + GDBServer 远程调试C/C++流水账

配置了一个开发环境,写个流水账供日后查阅

工程文件

main.c

#include <stdio.h>

void main()
{
	printf("hw\n");
	return;
}

Makefile

# C compiler options
CC	= gcc
#CC	= x86_64-w64-mingw32-gcc
CFLAGS=         
RELEASE	= release.elf
DEBUG	= debug.elf
LIBS = 
INC	= 

# Source files
SRCS = main.c

# Make everything
all:	$(RELEASE) 
debug: $(DEBUG)
# Make the application
$(RELEASE): $(OBJS)
	$(CC) -o $(RELEASE) $(SRCS) $(LIBS) $(CFLAGS)

$(DEBUG): $(OBJS)
	$(CC) -g -ggdb3 -o $(DEBUG) $(SRCS) $(LIBS) $(CFLAGS)
	gdbserver :1234 $(DEBUG)

#
# Clean all object files...
#
clean:
	$(RM) $(DEBUG) $(RELEASE) 

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
	"version": "0.2.0",
	"configurations": [
		{
			"name": "GDB Launch",
			"type": "cppdbg",
			"request": "launch",
			"program": "${workspaceFolder}/debug.elf",
			"args": [],
			"stopAtEntry": false,
			"cwd": "${workspaceFolder}",
			"environment": [],
			"externalConsole": false,
			"MIMode": "gdb",
			"logging": {
				"moduleLoad": true,
				"engineLogging": true,
				"trace": true
			},
			"setupCommands": [
				{
					"description": "Enable pretty-printing for gdb",
					"text": "-enable-pretty-printing",
					"ignoreFailures": true
				}
			],
			"linux": {
				"miDebuggerPath": "/usr/bin/gdb",
			},
			//"preLaunchTask": "RunGDBServer",
			"miDebuggerServerAddress": "127.0.0.1:1234"
		}
	]
}

RunDebug.sh

make debug
gdbserver :1234 debug.elf

操作步骤:

  1. 运行RunDebug.sh生成调试文件,以及运行gdbserver
  2. 在VSCode里按F5开始调试
posted @ 2021-01-05 19:33  asml  阅读(1854)  评论(0编辑  收藏  举报
@.@