1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
use self::InternalDebugLocation::*;
use super::utils::{debug_context, span_start};
use super::metadata::UNKNOWN_COLUMN_NUMBER;
use super::FunctionDebugContext;
use llvm;
use llvm::debuginfo::DIScope;
use builder::Builder;
use libc::c_uint;
use std::ptr;
use syntax_pos::{Span, Pos};
pub fn set_source_location(
debug_context: &FunctionDebugContext, builder: &Builder, scope: DIScope, span: Span
) {
let function_debug_context = match *debug_context {
FunctionDebugContext::DebugInfoDisabled => return,
FunctionDebugContext::FunctionWithoutDebugInfo => {
set_debug_location(builder, UnknownLocation);
return;
}
FunctionDebugContext::RegularContext(ref data) => data
};
let dbg_loc = if function_debug_context.source_locations_enabled.get() {
debug!("set_source_location: {}", builder.sess().codemap().span_to_string(span));
let loc = span_start(builder.ccx, span);
InternalDebugLocation::new(scope, loc.line, loc.col.to_usize())
} else {
UnknownLocation
};
set_debug_location(builder, dbg_loc);
}
pub fn start_emitting_source_locations(dbg_context: &FunctionDebugContext) {
match *dbg_context {
FunctionDebugContext::RegularContext(ref data) => {
data.source_locations_enabled.set(true)
},
_ => { }
}
}
#[derive(Copy, Clone, PartialEq)]
pub enum InternalDebugLocation {
KnownLocation { scope: DIScope, line: usize, col: usize },
UnknownLocation
}
impl InternalDebugLocation {
pub fn new(scope: DIScope, line: usize, col: usize) -> InternalDebugLocation {
KnownLocation {
scope: scope,
line: line,
col: col,
}
}
}
pub fn set_debug_location(builder: &Builder, debug_location: InternalDebugLocation) {
let metadata_node = match debug_location {
KnownLocation { scope, line, .. } => {
let col = UNKNOWN_COLUMN_NUMBER;
debug!("setting debug location to {} {}", line, col);
unsafe {
llvm::LLVMRustDIBuilderCreateDebugLocation(
debug_context(builder.ccx).llcontext,
line as c_uint,
col as c_uint,
scope,
ptr::null_mut())
}
}
UnknownLocation => {
debug!("clearing debug location ");
ptr::null_mut()
}
};
unsafe {
llvm::LLVMSetCurrentDebugLocation(builder.llbuilder, metadata_node);
}
}