summaryrefslogtreecommitdiff
path: root/docs/nnfw/howto/RemoteDebuggingForVSCode.md
blob: c83a09bd56f25c587ddb93a5d204dbd1d40a4774 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# Remote Debugging for Visual Studio Code

This document describes how to debug nnfw on arm devices using visual studio code.

## Install gdb-multiarch on build host

1. Install `gdb-multiarch`

```bash
$ sudo apt install gdb-multiarch
```

## Configure VS code on build host

1. Install `Native Debug` extension on VS code

2. Setup GDB environment on VS code

- Debug -> Add configuration -> GDB: Connect to gdbserver
- Change configuration as below
  - Change `<TARGET_IP>` to IP of your target
  - The default port number for gdbserver is 2345. You can change this number.
  - You can change `executable` configuration from `tflite_run` to other binaries you want to debug.

```json
{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "gdb",
            "request": "attach",
            "name": "Attach to gdbserver",
            "gdbpath": "/usr/bin/gdb-multiarch",
            "executable": "./Product/armv7l-linux.debug/out/bin/tflite_run",
            "target": "<TARGET_IP>:2345",
            "remote": true,
            "printCalls": true,
            "cwd": "${workspaceRoot}",
            "valuesFormatting": "parseText"
        }
    ]
}
```

## Install gdbserver and debugging symbols at target

You need to setup a target device for remote debugging.

1. Install `gdbserver`
```bash
$ sudo apt install gdbserver
```

2. Install `libc6-dbg` and copy debugging symbols
```bash
$ sudo apt install libc6-dbg
$ sudo mkdir -p /lib/.debug
$ sudo ln -s /usr/lib/debug/lib/arm-linux-gnueabihf/ld-2.27.so /lib/.debug
```

## Run remote debugging

1. Start gdbserver on target

```bash
gdbserver --multi :<PORT> <BINARY_PATH> <EXECUTION_ARGUMENTS>
```

Example
```bash
gdbserver --multi :2345 Product/armv7l-linux.debug/out/bin/tflite_run ../models/slice_test.tflite
```

2. Connect to gdbserver using VS code

- Setup breakpoints on any code you want.

- Click F5 to start remote debugging.

- Program will execute and exit if no breakpoint exists.

## Optional: Setup rootfs on build host

When debugging starts, `gdb` downloads shared libraries that nnfw uses from the target device.
This process makes `gdb` to wait for shared library download to finish for every debugging start.

To reduce shared library loading, you can setup an arm root file system on your build host and use it.

1. Create arm root file system

Following [CrossBuildForArm](docs/nnfw/howto/CrossBuildForArm.md) to create an arm root file system.

You can use an arm root file system created for arm cross-compile.

2. Install `libc6-dbg` on arm root file system

`<ROOTF_DIR>` should point ARM root file system.

Default path is `tools/cross/rootfs/arm` folder.

```bash
$ sudo chroot <ROOTFS_DIR>
$ apt install libc6-dbg
$ exit
```

3. Create symbolic link of nnfw on arm rootfs

`gdb` will use source code folder at sysroot.

```bash
$ ln -s <NNFW_DIR> <ROOTFS_DIR>/<NNFW_DIR>
```
Example
```bash
$ ln -s /home/user/nnfw /home/user/nnfw/tools/cross/rootfs/arm/home/user/nnfw
```

4. Setup `.gdbinit` file on nnfw folder

`gdb` will use `<ROOTFS_DIR>` to find arm related symbols.

```bash
set sysroot <ROOTFS_DIR>
set debug-file-directory <ROOTFS_DIR>/usr/lib/debug
```

# Troubleshooting

### Unable to open 'unordered_map.h'

If you are using docker to build nnfw, you should download and decompress gcc-linaro at `/opt` folder

```bash
wget https://releases.linaro.org/components/toolchain/binaries/6.3-2017.02/arm-linux-gnueabihf/gcc-linaro-6.3.1-2017.02-x86_64_arm-linux-gnueabihf.tar.xz -O gcc-hardfp.tar.xz
sudo tar -xf gcc-hardfp.tar.xz -C /opt/ && sudo rm -rf gcc-hardfp.tar.xz
```

### Skip STL files

Step into (F11) will debug STL files such as `unordered_map` or `vector`.

To skip those files from debugging, you can add below line to `.gdbinit` file.

```bash
skip -gfile /opt/gcc-linaro-6.3.1-2017.02-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/include/c++/6.3.1/bits/*
```