@@ -85,43 +85,6 @@ continuation, storing all state needed to continue traversal at the type members
85
85
been registered with the cache. (This implementation approach might be a tad over-engineered and
86
86
may change in the future)
87
87
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
-
125
88
*/
126
89
127
90
@@ -688,16 +651,7 @@ pub fn create_function_debug_context(cx: &mut CrateContext,
688
651
( function_name. clone ( ) , file_metadata)
689
652
} ;
690
653
691
- // Clang sets this parameter to the opening brace of the function's block, so let's do this too.
692
- let scope_line = span_start ( cx, top_level_block. span ) . line ;
693
-
694
- // The is_local_to_unit flag indicates whether a function is local to the current compilation
695
- // unit (i.e. if it is *static* in the C-sense). The *reachable* set should provide a good
696
- // approximation of this, as it contains everything that might leak out of the current crate
697
- // (by being externally visible or by being inlined into something externally visible). It might
698
- // better to use the `exported_items` set from `driver::CrateAnalysis` in the future, but (atm)
699
- // this set is not available in the translation pass.
700
- let is_local_to_unit = !cx. reachable . contains ( & fn_ast_id) ;
654
+ let scope_line = get_scope_line ( cx, top_level_block, loc. line ) ;
701
655
702
656
let fn_metadata = function_name. with_c_str ( |function_name| {
703
657
linkage_name. with_c_str ( |linkage_name| {
@@ -710,7 +664,7 @@ pub fn create_function_debug_context(cx: &mut CrateContext,
710
664
file_metadata,
711
665
loc. line as c_uint ,
712
666
function_type_metadata,
713
- is_local_to_unit ,
667
+ false ,
714
668
true ,
715
669
scope_line as c_uint ,
716
670
FlagPrototyped as c_uint ,
@@ -733,9 +687,6 @@ pub fn create_function_debug_context(cx: &mut CrateContext,
733
687
let arg_pats = fn_decl. inputs . map ( |arg_ref| arg_ref. pat ) ;
734
688
populate_scope_map ( cx, arg_pats, top_level_block, fn_metadata, & mut fn_debug_context. scope_map ) ;
735
689
736
- // Clear the debug location so we don't assign them in the function prelude
737
- set_debug_location ( cx, UnknownLocation ) ;
738
-
739
690
return FunctionDebugContext ( fn_debug_context) ;
740
691
741
692
fn get_function_signature ( cx : & mut CrateContext ,
@@ -886,6 +837,21 @@ pub fn create_function_debug_context(cx: &mut CrateContext,
886
837
887
838
return create_DIArray ( DIB ( cx) , template_params) ;
888
839
}
840
+
841
+ fn get_scope_line ( cx : & CrateContext ,
842
+ top_level_block : & ast:: Block ,
843
+ default : uint )
844
+ -> uint {
845
+ match * top_level_block {
846
+ ast:: Block { stmts : ref statements, .. } if statements. len ( ) > 0 => {
847
+ span_start ( cx, statements[ 0 ] . span ) . line
848
+ }
849
+ ast:: Block { expr : Some ( @ref expr) , .. } => {
850
+ span_start ( cx, expr. span ) . line
851
+ }
852
+ _ => default
853
+ }
854
+ }
889
855
}
890
856
891
857
//=-------------------------------------------------------------------------------------------------
@@ -2162,8 +2128,7 @@ fn set_debug_location(cx: &mut CrateContext, debug_location: DebugLocation) {
2162
2128
let metadata_node;
2163
2129
2164
2130
match debug_location {
2165
- KnownLocation { scope, line, .. } => {
2166
- let col = 0 ; // Always set the column to zero like Clang and GCC
2131
+ KnownLocation { scope, line, col } => {
2167
2132
debug ! ( "setting debug location to {} {}" , line, col) ;
2168
2133
let elements = [ C_i32 ( line as i32 ) , C_i32 ( col as i32 ) , scope, ptr:: null ( ) ] ;
2169
2134
unsafe {
@@ -2279,14 +2244,7 @@ fn populate_scope_map(cx: &mut CrateContext,
2279
2244
} )
2280
2245
}
2281
2246
2282
- // Clang creates a separate scope for function bodies, so let's do this too
2283
- with_new_scope ( cx,
2284
- fn_entry_block. span ,
2285
- & mut scope_stack,
2286
- scope_map,
2287
- |cx, scope_stack, scope_map| {
2288
- walk_block ( cx, fn_entry_block, scope_stack, scope_map) ;
2289
- } ) ;
2247
+ walk_block ( cx, fn_entry_block, & mut scope_stack, scope_map) ;
2290
2248
2291
2249
// local helper functions for walking the AST.
2292
2250
fn with_new_scope ( cx : & mut CrateContext ,
0 commit comments