Skip to content

Commit f3bb03b

Browse files
authored
Merge pull request #20 from SamP20/master
Fixes for various gotchas and general tidying up
2 parents 3e55281 + cf05e7d commit f3bb03b

File tree

1 file changed

+29
-20
lines changed

1 file changed

+29
-20
lines changed

src/overview.md

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,43 +39,43 @@ continue
3939

4040
### Useful Commands
4141

42-
- `target extended-remote ADDR` connects to a remote target
43-
- `break LOCATION` or `b LOCATION` sets a breakpoint, for example `b main` sets a breakpoint on the entry to main
42+
- `target extended-remote ADDR` connects to a remote target.
43+
- `break LOCATION` or `b LOCATION` sets a breakpoint, for example `b main` sets a breakpoint on the entry to main.
4444
- `print VARIABLE` or `p VARIABLE` prints the value of a variable at the point you are inspecting, `p\x VARIABLE` prints it in hex.
45-
- `delete N` or `d N` deletes a breakpoint by index
46-
- `continue` or `c` continues to the next breakpoint
47-
- `step` or `s` steps through execution line by line
48-
- `backtrace` or `bt` prints a backtrace from the point you are currently inspecting
49-
- `load` flashes the current binary to the device
50-
- `run` re-starts an application
51-
- `layout LAYOUT` switches to different views, useful options are `SRC` for source, `REGS` for registers, `ASM` for assembly
52-
- `quit` or `q` gets you out, though you may have to interrupt with `ctrl+c` if the application is currently running
45+
- `delete N` or `d N` deletes a breakpoint by index.
46+
- `continue` or `c` continues to the next breakpoint.
47+
- `step` or `s` steps through execution line by line.
48+
- `backtrace` or `bt` prints a backtrace from the point you are currently inspecting.
49+
- `load` flashes the current binary to the device.
50+
- `run` re-starts an application.
51+
- `layout LAYOUT` switches to different views, useful options are `SRC` for source, `REGS` for registers, `ASM` for assembly.
52+
- `quit` or `q` gets you out, though you may have to interrupt with `ctrl+c` if the application is currently running.
53+
- `source FILENAME` runs the commands specified in `FILENAME`.
54+
- `set substitute-path SRC DST` substitutes paths that start with `SRC` with `DST`. This is useful for stepping into the rust sources as explained later.
5355

5456
You can invoke gdb with the source layout loaded by passing the `--tui` argument in the command line, note that `tui` mode starts with the source view selected so normal control keys will scroll the source view instead of the terminal, you can move through previous and next commands with `ctrl+P` and `ctrl+N` respectively, or use `ctrl+x o` to move focus between the source and terminal views and use your arrow keys and page-up/page-down as normal.
5557

56-
In general gdb will interpret the shortest series of characters required to uniquely identify a command as that command, for example `tar` instead of `target`.
58+
In general gdb will interpret the shortest series of characters required to uniquely identify a command as that command, for example `tar` instead of `target`.
59+
60+
When trying to step into the rust sources you may get an error that files with paths similar to `/rustc/e305df1846a6d985315917ae0c81b74af8b4e641/...` cannot be found. This is because the rust sources are compiled on a build server in the directory `/rustc/{commit_hash}`. To find this commit hash you can use the command `rustc -Vv`. The `set substitute-path` command can then be used to substitute this with your `{RUST_SRC_PATH}/lib/rustlib/src/rust` (`RUST_SRC_PATH` can be found from the output of `rustc --print=sysroot`). For example:
61+
62+
```set substitute-path /rustc/e305df1846a6d985315917ae0c81b74af8b4e641 "C:/Users/username/.rustup/toolchains/nightly-x86_64-pc-windows-msvc/lib/rustlib/src/rust"```
5763

5864
### VSCode Integration
5965

60-
The [Native Debug] extension can be used to debug Rust code directly in the editor. To use it you will need to add a launch configuration to your `.vscode/launch.json` file. Below is an example that connects to a Segger JLink server on port 2331. If you are using OpenOCD this port is most likely 3333.
66+
The [Native Debug] extension can be used to debug Rust code directly in the editor. To use it you will need to add a launch configuration to your `.vscode/launch.json` file. Below is an example that starts gdb and executes the commands specified in `debug.gdb`:
6167

6268
```
6369
"configurations": [
6470
{
65-
"name": "JLink Remote",
71+
"name": "Remote debug",
6672
"type": "gdb",
6773
"request": "launch",
6874
"cwd": "${workspaceRoot}",
6975
"target": "${workspaceRoot}/target/thumbv7em-none-eabihf/debug/hello",
7076
"gdbpath" : "arm-none-eabi-gdb",
7177
"autorun": [
72-
"target remote :2331",
73-
"set remotetimeout 5",
74-
"set print asm-demangle on",
75-
"monitor semihosting enable", // This is specific to JLinkGDBServer
76-
"monitor semihosting IOClient 2", // This is specific to JLinkGDBServer
77-
"load",
78-
"monitor reset", // This is important for interrupts to work properly!
78+
"source -v debug.gdb",
7979
]
8080
}
8181
]
@@ -90,6 +90,13 @@ Before launching the debugger in VSCode you must ensure that JLinkGDBServer, Ope
9090

9191
[Native Debug]: https://marketplace.visualstudio.com/items?itemName=webfreak.debug
9292

93+
94+
## Cargo run integration
95+
96+
The `cargo run` command can be configured to start the debugger. To use this, simply add the following to the appropriate target in your `.cargo/config`:
97+
98+
```runner = "arm-none-eabi-gdb -q -x debug.gdb"```
99+
93100
## Interfaces / Protocols
94101

95102
When it comes to talking to micro controllers, there are two common interfaces JTAG (Joint Test Action Group) and SWD (Serial Wire Debug).
@@ -184,6 +191,8 @@ It is also possible to pass scripts to JLinkExe with the `--CommanderScript` opt
184191

185192
To debug with the JLink device you run the `JLinkGDBServer` command with the specified device, speed, and interface. For example, `JLinkGDBServer -device DEVICE -speed 4000 -if SWD`. You can then launch a GDB instance with the appropriate command for your target (eg. `arm-none-eabi-gdb BINARY.elf`) and connect to the GDB server using `target remote localhost:2331` (specifying the default JLinkGDBServer port).
186193

194+
A common gotcha with JLinkGDBServer is interrupts not firing. If you experience this issue then add `monitor reset` to the end of your GDB initialization commands. You can also enable semihosting and print to stdout with `monitor semihosting enable` and `monitor semihosting IOClient 2` respectively.
195+
187196
### [ARM DAPLink]
188197

189198
DAPLink is a project by ARM to develop an open source cortex debug probe, this provides a set of interfaces to simplify programming and debugging and can be implemented on nearly any USB-capable hardware. DAPLink provides a set of endpoints including a CMSIS-DAP interface for debugging, a USB disk for drag-and-drop programming, and an optional serial port for communication with the target system. This USB disk approach is useful for programming of devices in-field as it requires no additonal software, however is not always reliable for development use.

0 commit comments

Comments
 (0)