Skip to content

Commit eac16c9

Browse files
---
yaml --- r: 88654 b: refs/heads/snap-stage3 c: d35fff8 h: refs/heads/master v: v3
1 parent 5ad1615 commit eac16c9

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: deeca5d586bfaa4aa60246f671a8d611d38f6248
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 89b47d5557b52e0da7b95e70ed61f76db152664b
4+
refs/heads/snap-stage3: d35fff89944f583f4f96b384e3f5d075503e0d36
55
refs/heads/try: b160761e35efcd1207112b3b782c06633cf441a8
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/librustc/middle/trans/debuginfo.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,43 @@ continuation, storing all state needed to continue traversal at the type members
8585
been registered with the cache. (This implementation approach might be a tad over-engineered and
8686
may change in the future)
8787
88+
89+
## Source Locations and Line Information
90+
In addition to data type descriptions the debugging information must also allow to map machine code
91+
locations back to source code locations in order to be useful. This functionality is also handled in
92+
this module. The following functions allow to control source mappings:
93+
94+
+ set_source_location()
95+
+ clear_source_location()
96+
+ start_emitting_source_locations()
97+
98+
`set_source_location()` allows to set the current source location. All IR instructions created after
99+
a call to this function will be linked to the given source location, until another location is
100+
specified with `set_source_location()` or the source location is cleared with
101+
`clear_source_location()`. In the later case, subsequent IR instruction will not be linked to any
102+
source location. As you can see, this is a stateful API (mimicking the one in LLVM), so be careful
103+
with source locations set by previous calls. It's probably best to not rely on any specific state
104+
being present at a given point in code.
105+
106+
One topic that deserves some extra attention is *function prologues*. At the beginning of a
107+
function's machine code there are typically a few instructions for loading argument values into
108+
allocas and checking if there's enough stack space for the function to execute. This *prologue* is
109+
not visible in the source code and LLVM puts a special PROLOGUE END marker into the line table at
110+
the first non-prologue instruction of the function. In order to find out where the prologue ends,
111+
LLVM looks for the first instruction in the function body that is linked to a source location. So,
112+
when generating prologue instructions we have to make sure that we don't emit source location
113+
information until the 'real' function body begins. For this reason, source location emission is
114+
disabled by default for any new function being translated and is only activated after a call to the
115+
third function from the list above, `start_emitting_source_locations()`. This function should be
116+
called right before regularly starting to translate the top-level block of the given function.
117+
118+
There is one exception to the above rule: `llvm.dbg.declare` instruction must be linked to the
119+
source location of the variable being declared. For function parameters these `llvm.dbg.declare`
120+
instructions typically occur in the middle of the prologue, however, they are ignored by LLVM's
121+
prologue detection. The `create_argument_metadata()` and related functions take care of linking the
122+
`llvm.dbg.declare` instructions to the correct source locations even while source location emission
123+
is still disabled, so there is no need to do anything special with source location handling here.
124+
88125
*/
89126

90127

0 commit comments

Comments
 (0)