@@ -8,10 +8,10 @@ mod unwind;
8
8
use cranelift_codegen:: ir:: Endianness ;
9
9
use cranelift_codegen:: isa:: TargetIsa ;
10
10
use gimli:: write:: {
11
- Address , AttributeValue , DwarfUnit , FileId , LineProgram , LineString , Range , RangeList ,
12
- UnitEntryId ,
11
+ Address , AttributeValue , DwarfUnit , Expression , FileId , LineProgram , LineString , Range ,
12
+ RangeList , UnitEntryId ,
13
13
} ;
14
- use gimli:: { Encoding , Format , LineEncoding , RunTimeEndian } ;
14
+ use gimli:: { AArch64 , Encoding , Format , LineEncoding , Register , RiscV , RunTimeEndian , X86_64 } ;
15
15
use indexmap:: IndexSet ;
16
16
use rustc_session:: Session ;
17
17
@@ -28,6 +28,7 @@ pub(crate) struct DebugContext {
28
28
29
29
dwarf : DwarfUnit ,
30
30
unit_range_list : RangeList ,
31
+ stack_pointer_register : Register ,
31
32
32
33
should_remap_filepaths : bool ,
33
34
}
@@ -60,6 +61,15 @@ impl DebugContext {
60
61
Endianness :: Big => RunTimeEndian :: Big ,
61
62
} ;
62
63
64
+ let stack_pointer_register = match isa. triple ( ) . architecture {
65
+ target_lexicon:: Architecture :: Aarch64 ( _) => AArch64 :: SP ,
66
+ target_lexicon:: Architecture :: Riscv64 ( _) => RiscV :: SP ,
67
+ target_lexicon:: Architecture :: X86_64 | target_lexicon:: Architecture :: X86_64h => {
68
+ X86_64 :: RSP
69
+ }
70
+ _ => Register ( u16:: MAX ) ,
71
+ } ;
72
+
63
73
let mut dwarf = DwarfUnit :: new ( encoding) ;
64
74
65
75
let should_remap_filepaths = tcx. sess . should_prefer_remapped_for_codegen ( ) ;
@@ -111,6 +121,7 @@ impl DebugContext {
111
121
endian,
112
122
dwarf,
113
123
unit_range_list : RangeList ( Vec :: new ( ) ) ,
124
+ stack_pointer_register,
114
125
should_remap_filepaths,
115
126
}
116
127
}
@@ -135,6 +146,10 @@ impl DebugContext {
135
146
entry. set ( gimli:: DW_AT_name , AttributeValue :: StringRef ( name_id) ) ;
136
147
entry. set ( gimli:: DW_AT_linkage_name , AttributeValue :: StringRef ( name_id) ) ;
137
148
149
+ let mut frame_base_expr = Expression :: new ( ) ;
150
+ frame_base_expr. op_reg ( self . stack_pointer_register ) ;
151
+ entry. set ( gimli:: DW_AT_frame_base , AttributeValue :: Exprloc ( frame_base_expr) ) ;
152
+
138
153
entry. set ( gimli:: DW_AT_decl_file , AttributeValue :: FileIndex ( Some ( file_id) ) ) ;
139
154
entry. set ( gimli:: DW_AT_decl_line , AttributeValue :: Udata ( line) ) ;
140
155
entry. set ( gimli:: DW_AT_decl_column , AttributeValue :: Udata ( column) ) ;
0 commit comments