3
3
<!-- toc -->
4
4
5
5
This document explains the state of debugging tools support in the Rust compiler (rustc).
6
- The document gives an overview of debugging tools like GDB, LLDB etc. and infrastructure
7
- around Rust compiler to debug Rust code. If you want to learn how to debug the Rust compiler
8
- itself, then you must see [ Debugging the Compiler] page.
6
+ It gives an overview of GDB, LLDB,
7
+ as well as infrastructure around Rust compiler to debug Rust code.
8
+ If you want to learn how to debug the Rust compiler itself,
9
+ see [ Debugging the Compiler] .
9
10
10
- The material is gathered from YouTube video [ Tom Tromey discusses debugging support in rustc] .
11
+ The material is gathered from the video,
12
+ [ Tom Tromey discusses debugging support in rustc] .
11
13
12
14
## Preliminaries
13
15
@@ -44,17 +46,15 @@ You can also invent your own tags and attributes.
44
46
45
47
### GDB
46
48
47
- We have our own fork of GDB - [ https://github.com/rust-dev-tools/gdb ]
48
-
49
49
#### Rust expression parser
50
50
51
- To be able to show debug output we need an expression parser.
52
- This (GDB) expression parser is written in [ Bison] and is only a subset of Rust expressions.
53
- This means that this parser can parse only a subset of Rust expressions.
54
- GDB parser was written from scratch and has no relation to any other parser.
55
- For example, this parser is not related to Rustc's parser .
51
+ To be able to show debug output, we need an expression parser.
52
+ This (GDB) expression parser is written in [ Bison] ,
53
+ and can parse only a subset of Rust expressions.
54
+ GDB parser was written from scratch and has no relation to any other parser,
55
+ including that of rustc .
56
56
57
- GDB has Rust like value and type output. It can print values and types in a way
57
+ GDB has Rust- like value and type output. It can print values and types in a way
58
58
that look like Rust syntax in the output. Or when you print a type as [ ptype] in GDB,
59
59
it also looks like Rust source code. Checkout the documentation in the [ manual for GDB/Rust] .
60
60
@@ -64,17 +64,19 @@ Expression parser has a couple of extensions in it to facilitate features that y
64
64
with Rust. Some limitations are listed in the [ manual for GDB/Rust] . There is some special
65
65
code in the DWARF reader in GDB to support the extensions.
66
66
67
- A couple of examples of DWARF reader support needed are as follows -
67
+ A couple of examples of DWARF reader support needed are as follows:
68
68
69
- 1 . Enum: Needed for support for enum types. The Rustc writes the information about enum into
70
- DWARF and GDB reads the DWARF to understand where is the tag field or is there a tag
71
- field or is the tag slot shared with non-zero optimization etc.
69
+ 1 . Enum: Needed for support for enum types.
70
+ The Rust compiler writes the information about enum into DWARF,
71
+ and GDB reads the DWARF to understand where is the tag field,
72
+ or if there is a tag field,
73
+ or if the tag slot is shared with non-zero optimization etc.
72
74
73
75
2 . Dissect trait objects: DWARF extension where the trait object's description in the DWARF
74
- also points to a stub description of the corresponding vtable which in turn points to the
75
- concrete type for which this trait object exists. This means that you can do a ` print *object `
76
- for that trait object, and GDB will understand how to find the correct type of the payload in
77
- the trait object.
76
+ also points to a stub description of the corresponding vtable which in turn points to the
77
+ concrete type for which this trait object exists. This means that you can do a ` print *object `
78
+ for that trait object, and GDB will understand how to find the correct type of the payload in
79
+ the trait object.
78
80
79
81
** TODO** : Figure out if the following should be mentioned in the GDB-Rust document rather than
80
82
this guide page so there is no duplication. This is regarding the following comments:
@@ -89,49 +91,28 @@ implements the gdb @ extension.
89
91
> @tromey do you think we should mention this part in the GDB-Rust document rather than this
90
92
document so there is no duplication etc.?
91
93
92
- #### Developer notes
93
-
94
- * This work is now upstream. Bugs can be reported in [ GDB Bugzilla] .
95
-
96
94
### LLDB
97
95
98
- Fork of LLVM project - [ https://github.com/rust-lang/llvm-project ]
99
-
100
- LLDB currently only works on macOS because of a dependency issue. This issue was easier to
101
- solve for macOS as compared to Linux. However, Tom has a possible solution which can enable
102
- us to ship LLDB everywhere.
103
-
104
96
#### Rust expression parser
105
97
106
98
This expression parser is written in C++. It is a type of [ Recursive Descent parser] .
107
- Implements slightly less of the Rust language than GDB. LLDB has Rust like value and type output.
108
-
109
- #### Parser extensions
110
-
111
- There is some special code in the DWARF reader in LLDB to support the extensions.
112
- A couple of examples of DWARF reader support needed are as follows -
113
-
114
- 1 . Enum: Needed for support for enum types. The Rustc writes the information about
115
- enum into DWARF and LLDB reads the DWARF to understand where is the tag field or
116
- is there a tag field or is the tag slot shared with non-zero optimization etc.
117
- In other words, it has enum support as well.
99
+ It implements slightly less of the Rust language than GDB.
100
+ LLDB has Rust-like value and type output.
118
101
119
102
#### Developer notes
120
103
121
- * None of the LLDB work is upstream. This [ rust-lang/lldb wiki page] explains a few details.
122
- * The reason for forking LLDB is that LLDB recently removed all the other language plugins
123
- due to lack of maintenance.
124
104
* LLDB has a plugin architecture but that does not work for language support.
125
- * LLDB is available via Rust build (` rustup ` ).
126
105
* GDB generally works better on Linux.
127
106
128
- ## DWARF and Rustc
107
+ ## DWARF and ` rustc `
129
108
130
109
[ DWARF] is the standard way compilers generate debugging information that debuggers read.
131
- It is _ the_ debugging format on macOS and Linux. It is a multi-language, extensible format
132
- and is mostly good enough for Rust's purposes. Hence, the current implementation reuses DWARF's
133
- concepts. This is true even if some of the concepts in DWARF do not align with Rust
134
- semantically because generally there can be some kind of mapping between the two.
110
+ It is _ the_ debugging format on macOS and Linux.
111
+ It is a multi-language and extensible format,
112
+ and is mostly good enough for Rust's purposes.
113
+ Hence, the current implementation reuses DWARF's concepts.
114
+ This is true even if some of the concepts in DWARF do not align with Rust semantically because,
115
+ generally, there can be some kind of mapping between the two.
135
116
136
117
We have some DWARF extensions that the Rust compiler emits and the debuggers understand that
137
118
are _ not_ in the DWARF standard.
@@ -169,26 +150,6 @@ This section is from the talk about certain aspects of development.
169
150
170
151
## What is missing
171
152
172
- ### Shipping GDB in Rustup
173
-
174
- Tracking issue: [ https://github.com/rust-lang/rust/issues/34457 ]
175
-
176
- Shipping GDB requires change to Rustup delivery system. To manage Rustup build size and
177
- times we need to build GDB separately, on its own and somehow provide the artifacts produced
178
- to be included in the final build. However, if we can ship GDB with rustup, it will simplify
179
- the development process by having compiler emit new debug info which can be readily consumed.
180
-
181
- Main issue in achieving this is setting up dependencies. One such dependency is Python. That
182
- is why we have our own fork of GDB because one of the drivers is patched on Rust's side to
183
- check the correct version of Python (Python 2.7 in this case. * Note: Python3 is not chosen
184
- for this purpose because Python's stable ABI is limited and is not sufficient for GDB's needs.
185
- See [ https://docs.python.org/3/c-api/stable.html ] * ).
186
-
187
- This is to keep updates to debugger as fast as possible as we make changes to the debugging symbols.
188
- In essence, to ship the debugger as soon as new debugging info is added. GDB only releases
189
- every six months or so. However, the changes that are
190
- not related to Rust itself should ideally be first merged to upstream eventually.
191
-
192
153
### Code signing for LLDB debug server on macOS
193
154
194
155
According to Wikipedia, [ System Integrity Protection] is
@@ -235,7 +196,7 @@ This is why we need to change LLVM first because that is emitted first and not D
235
196
This is a kind of metadata that you construct and hand-off to LLVM. For the Rustc/LLVM hand-off
236
197
some LLVM DI builder methods are called to construct representation of a type.
237
198
238
- The steps of this process are as follows -
199
+ The steps of this process are as follows:
239
200
240
201
1 . LLVM needs changing.
241
202
@@ -329,9 +290,11 @@ debugger because the debugger alone has access to the memory. Both GDB (gcc) and
329
290
have this feature. LLDB uses Clang to compile code to JIT and GDB can do the same with GCC.
330
291
331
292
Both debuggers expression evaluation implement both a superset and a subset of Rust.
332
- They implement just the expression language but they also add some extensions like GDB has
333
- convenience variables. Therefore, if you are taking this route then you not only need
334
- to do this bridge but may have to add some mode to let the compiler understand some extensions.
293
+ They implement just the expression language,
294
+ but they also add some extensions like GDB has convenience variables.
295
+ Therefore, if you are taking this route,
296
+ then you not only need to do this bridge,
297
+ but may have to add some mode to let the compiler understand some extensions.
335
298
336
299
[ Tom Tromey discusses debugging support in rustc ] : https://www.youtube.com/watch?v=elBxMRSNYr4
337
300
[ Debugging the Compiler ] : compiler-debugging.md
0 commit comments