2023-02-14

[개발노트] embedded linux vscode remote gdb

vscode로 편집만 하던 리눅스 app을 원격 디버깅 해보기.

sudo apt install build-essential gdb gdb-multiarch

vscode 로 폴더 열기.

.vscode 폴더에 3개의 파일 만들기.

launch.json

{
"version": "0.2.0",
"configurations": [
{
"name": "GDB-Debug",
"type": "cppdbg",
"request": "launch",
"program": "${config:BINARY}",
"args": [],
"stopAtEntry": true,
"cwd": "${workspaceFolder}",
"environment": [],
"console": "integratedTerminal",
"MIMode": "gdb",
"targetArchitecture": "arm",
"preLaunchTask": "deploy",
"setupCommands": [
{
"description": "Pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true,
}
],
"miDebuggerPath": "/usr/bin/gdb-multiarch",
"miDebuggerServerAddress": "${config:TARGET_IP}:${config:DEBUG_PORT}",
}
]
}

settings.json

{
"TARGET_IP":"192.168.25.53",
"DEBUG_PORT":"6666",
"BINARY":"s1app3",

"SDK_DIR":"/home/happycpu/work/wrlinux/sdk/environment-setup-cortexa7t2hf-neon-vfpv4-wrs-linux-gnueabi",
}

tasks.json

{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "cross-compile",
"type": "shell",
"command": "sh",
"args": [
"cross-compile.sh",
"${config:SDK_DIR}",
],
"problemMatcher": [],
"group": {
"kind": "build",
"isDefault": true
}
},
{
"label": "deploy",
"isBackground": true,
"type": "shell",
"command": "sh",
"args": [
"deploy.sh",
"${config:TARGET_IP}",
"${config:DEBUG_PORT}",
"${config:BINARY}"
],
"problemMatcher": {
"base": "$gcc",
"background": {
"activeOnStart": true,
"beginsPattern": "${config:BINARY}",
"endsPattern": "Listening on port [0-9]{4}"
}
},
"dependsOn": [
"cross-compile"
],
},
]
}


스크립트파일2개 추가.

cross-compile.sh

#!/bin/bash
SDK_DIR="$1"

. ${SDK_DIR}
cmake .
make clean; make -j$(nproc)

*yocto 의 sdk를 source 하여주는 행위와 cmake파일 생성하고 make까지 함.


deploy.sh

#!/bin/bash
DEST_IP="$1"
DEBUG_PORT="$2"
BINARY="$3"
DEST_DIR="/root"

# kill gdbserver on tx8m and delete old binary
ssh root@${DEST_IP} "sh -c '/usr/bin/killall -q gdbserver; rm -rf ${DEST_DIR}/${BINARY} exit 0'"

# send binary to target
scp ${BINARY} root@${DEST_IP}:${DEST_DIR}/${BINARY}

# start gdbserver on target
ssh -t root@${DEST_IP} "sh -c 'cd ${DEST_DIR}; gdbserver localhost:${DEBUG_PORT} ${BINARY}'"

*DEST_DIR은 타겟보드의 실행파일 위치.


[원문]https://karo-electronics.github.io/docs/software-documentation/vscode/index.html#





댓글 없음:

댓글 쓰기

암호화 + base64 하고 쉘스크립트.

 #!/bin/bash # IV와 UserKey를 설정합니다 (아스키 문자열을 그대로 사용). IV="0123456789abcdef"  UserKey="0123456789abcdef" # IV와 UserKey를 16...