Skip to content

Commit 31b1c48

Browse files
committed
add details for GDB auto-load
1 parent 1fe679e commit 31b1c48

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/attributes/debugger.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ struct FancyRect {
3838
}
3939

4040
fn main() {
41-
let mut fancy_rect = FancyRect::new(10.0, 10.0, 5.0, 5.0);
41+
let fancy_rect = FancyRect::new(10.0, 10.0, 5.0, 5.0);
42+
Ok(())
4243
}
4344
```
4445

@@ -84,7 +85,12 @@ GDB supports the use of a structured Python script, called a *pretty printer*, t
8485
These scripts are embedded using the `gdb_script_file` meta item.
8586
For detailed information on pretty printers, refer to GDB's [pretty print documentation].
8687

87-
Consider a crate with this directory structure:
88+
Embedded pretty printers are not automatically loaded when debugging a binary under GDB.
89+
There are two ways to enable auto-loading embedded pretty printers:
90+
1. Launch GDB with extra arguments to explicitly add a directory or binary to the auto-load safe path: `gdb -iex "set auto-load safe-path path/to/binary" path/to/binary` (For more information, see GDB's [auto-loading documentation])
91+
1. Create a file named `gdbinit` under `$HOME/.config/gdb` (you may need to create the directory if it doesn't already exist). Add the following line to that file: `add-auto-load-safe-path path/to/binary`.
92+
93+
Consider a crate called `foobar` with this directory structure:
8894

8995
```text
9096
/Cargo.toml
@@ -107,7 +113,8 @@ mod person {
107113
use person::Person;
108114

109115
fn main() {
110-
let person = Person::new(String::from("Bob"), 10);
116+
let bob = Person::new(String::from("Bob"), 10);
117+
Ok(())
111118
}
112119
```
113120

@@ -131,20 +138,21 @@ def lookup(val):
131138
lookup_tag = val.type.tag
132139
if lookup_tag is None:
133140
return None
134-
if "person::Person" == lookup_tag:
141+
if "foobar::person::Person" == lookup_tag:
135142
return PersonPrinter(val)
136143

137144
return None
138145

139146
gdb.current_objfile().pretty_printers.append(lookup)
140147
```
141148

142-
When the crate's debug executable is passed into GDB, `print person` will display:
149+
When the crate's debug executable is passed into GDB, `print bob` will display:
143150

144151
```
145152
"Bob" is 10 years old.
146153
```
147154

155+
[auto-loading documentation]: https://sourceware.org/gdb/onlinedocs/gdb/Auto_002dloading-safe-path.html
148156
[attributes]: ../attributes.md
149157
[Natvis documentation]: https://docs.microsoft.com/en-us/visualstudio/debugger/create-custom-views-of-native-objects
150158
[pretty print documentation]: https://sourceware.org/gdb/onlinedocs/gdb/Pretty-Printing.html

0 commit comments

Comments
 (0)