Skip to content

Commit 0390f2b

Browse files
committed
remove outdated info on debugging
Closes rust-lang#1391 Also, do some small fixes/improvements while at it.
1 parent 67a564f commit 0390f2b

File tree

1 file changed

+37
-74
lines changed

1 file changed

+37
-74
lines changed

src/debugging-support-in-rustc.md

+37-74
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
<!-- toc -->
44

55
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].
910

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].
1113

1214
## Preliminaries
1315

@@ -44,17 +46,15 @@ You can also invent your own tags and attributes.
4446

4547
### GDB
4648

47-
We have our own fork of GDB - [https://github.com/rust-dev-tools/gdb]
48-
4949
#### Rust expression parser
5050

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.
5656

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
5858
that look like Rust syntax in the output. Or when you print a type as [ptype] in GDB,
5959
it also looks like Rust source code. Checkout the documentation in the [manual for GDB/Rust].
6060

@@ -64,17 +64,19 @@ Expression parser has a couple of extensions in it to facilitate features that y
6464
with Rust. Some limitations are listed in the [manual for GDB/Rust]. There is some special
6565
code in the DWARF reader in GDB to support the extensions.
6666

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:
6868

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.
7274

7375
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.
7880

7981
**TODO**: Figure out if the following should be mentioned in the GDB-Rust document rather than
8082
this guide page so there is no duplication. This is regarding the following comments:
@@ -89,49 +91,28 @@ implements the gdb @ extension.
8991
> @tromey do you think we should mention this part in the GDB-Rust document rather than this
9092
document so there is no duplication etc.?
9193

92-
#### Developer notes
93-
94-
* This work is now upstream. Bugs can be reported in [GDB Bugzilla].
95-
9694
### LLDB
9795

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-
10496
#### Rust expression parser
10597

10698
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.
118101

119102
#### Developer notes
120103

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.
124104
* LLDB has a plugin architecture but that does not work for language support.
125-
* LLDB is available via Rust build (`rustup`).
126105
* GDB generally works better on Linux.
127106

128-
## DWARF and Rustc
107+
## DWARF and `rustc`
129108

130109
[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.
135116

136117
We have some DWARF extensions that the Rust compiler emits and the debuggers understand that
137118
are _not_ in the DWARF standard.
@@ -169,26 +150,6 @@ This section is from the talk about certain aspects of development.
169150

170151
## What is missing
171152

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-
192153
### Code signing for LLDB debug server on macOS
193154

194155
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
235196
This is a kind of metadata that you construct and hand-off to LLVM. For the Rustc/LLVM hand-off
236197
some LLVM DI builder methods are called to construct representation of a type.
237198

238-
The steps of this process are as follows -
199+
The steps of this process are as follows:
239200

240201
1. LLVM needs changing.
241202

@@ -329,9 +290,11 @@ debugger because the debugger alone has access to the memory. Both GDB (gcc) and
329290
have this feature. LLDB uses Clang to compile code to JIT and GDB can do the same with GCC.
330291

331292
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.
335298

336299
[Tom Tromey discusses debugging support in rustc]: https://www.youtube.com/watch?v=elBxMRSNYr4
337300
[Debugging the Compiler]: compiler-debugging.md

0 commit comments

Comments
 (0)