@@ -42,14 +42,14 @@ pub(crate) struct DebugContext {
4242 created_files : FxHashMap < ( StableSourceFileId , SourceFileHash ) , FileId > ,
4343 stack_pointer_register : Register ,
4444 namespace_map : DefIdMap < UnitEntryId > ,
45- array_size_type : UnitEntryId ,
45+ array_size_type : Option < UnitEntryId > ,
4646
4747 filename_display_preference : FileNameDisplayPreference ,
4848 embed_source : bool ,
4949}
5050
5151pub ( crate ) struct FunctionDebugContext {
52- entry_id : UnitEntryId ,
52+ entry_id : Option < UnitEntryId > ,
5353 function_source_loc : ( FileId , u64 , u64 ) ,
5454 source_loc_set : IndexSet < ( FileId , u64 , u64 ) > ,
5555}
@@ -154,18 +154,23 @@ impl DebugContext {
154154 root. set ( gimli:: DW_AT_low_pc , AttributeValue :: Address ( Address :: Constant ( 0 ) ) ) ;
155155 }
156156
157- let array_size_type = dwarf. unit . add ( dwarf. unit . root ( ) , gimli:: DW_TAG_base_type ) ;
158- let array_size_type_entry = dwarf. unit . get_mut ( array_size_type) ;
159- array_size_type_entry. set (
160- gimli:: DW_AT_name ,
161- AttributeValue :: StringRef ( dwarf. strings . add ( "__ARRAY_SIZE_TYPE__" ) ) ,
162- ) ;
163- array_size_type_entry
164- . set ( gimli:: DW_AT_encoding , AttributeValue :: Encoding ( gimli:: DW_ATE_unsigned ) ) ;
165- array_size_type_entry. set (
166- gimli:: DW_AT_byte_size ,
167- AttributeValue :: Udata ( isa. frontend_config ( ) . pointer_bytes ( ) . into ( ) ) ,
168- ) ;
157+ let array_size_type = if tcx. sess . opts . debuginfo == DebugInfo :: LineTablesOnly {
158+ None
159+ } else {
160+ let array_size_type = dwarf. unit . add ( dwarf. unit . root ( ) , gimli:: DW_TAG_base_type ) ;
161+ let array_size_type_entry = dwarf. unit . get_mut ( array_size_type) ;
162+ array_size_type_entry. set (
163+ gimli:: DW_AT_name ,
164+ AttributeValue :: StringRef ( dwarf. strings . add ( "__ARRAY_SIZE_TYPE__" ) ) ,
165+ ) ;
166+ array_size_type_entry
167+ . set ( gimli:: DW_AT_encoding , AttributeValue :: Encoding ( gimli:: DW_ATE_unsigned ) ) ;
168+ array_size_type_entry. set (
169+ gimli:: DW_AT_byte_size ,
170+ AttributeValue :: Udata ( isa. frontend_config ( ) . pointer_bytes ( ) . into ( ) ) ,
171+ ) ;
172+ Some ( array_size_type)
173+ } ;
169174
170175 Some ( DebugContext {
171176 endian,
@@ -217,6 +222,14 @@ impl DebugContext {
217222 ) -> FunctionDebugContext {
218223 let ( file_id, line, column) = self . get_span_loc ( tcx, function_span, function_span) ;
219224
225+ if tcx. sess . opts . debuginfo == DebugInfo :: LineTablesOnly {
226+ return FunctionDebugContext {
227+ entry_id : None ,
228+ function_source_loc : ( file_id, line, column) ,
229+ source_loc_set : IndexSet :: new ( ) ,
230+ } ;
231+ }
232+
220233 let scope = self . item_namespace ( tcx, tcx. parent ( instance. def_id ( ) ) ) ;
221234
222235 let mut name = String :: new ( ) ;
@@ -274,7 +287,7 @@ impl DebugContext {
274287 }
275288
276289 FunctionDebugContext {
277- entry_id,
290+ entry_id : Some ( entry_id ) ,
278291 function_source_loc : ( file_id, line, column) ,
279292 source_loc_set : IndexSet :: new ( ) ,
280293 }
@@ -288,6 +301,10 @@ impl DebugContext {
288301 def_id : DefId ,
289302 data_id : DataId ,
290303 ) {
304+ if tcx. sess . opts . debuginfo == DebugInfo :: LineTablesOnly {
305+ return ;
306+ }
307+
291308 let DefKind :: Static { nested, .. } = tcx. def_kind ( def_id) else { bug ! ( ) } ;
292309 if nested {
293310 return ;
@@ -353,10 +370,12 @@ impl FunctionDebugContext {
353370 . 0
354371 . push ( Range :: StartLength { begin : address_for_func ( func_id) , length : u64:: from ( end) } ) ;
355372
356- let func_entry = debug_context. dwarf . unit . get_mut ( self . entry_id ) ;
357- // Gdb requires both DW_AT_low_pc and DW_AT_high_pc. Otherwise the DW_TAG_subprogram is skipped.
358- func_entry. set ( gimli:: DW_AT_low_pc , AttributeValue :: Address ( address_for_func ( func_id) ) ) ;
359- // Using Udata for DW_AT_high_pc requires at least DWARF4
360- func_entry. set ( gimli:: DW_AT_high_pc , AttributeValue :: Udata ( u64:: from ( end) ) ) ;
373+ if let Some ( entry_id) = self . entry_id {
374+ let entry = debug_context. dwarf . unit . get_mut ( entry_id) ;
375+ // Gdb requires both DW_AT_low_pc and DW_AT_high_pc. Otherwise the DW_TAG_subprogram is skipped.
376+ entry. set ( gimli:: DW_AT_low_pc , AttributeValue :: Address ( address_for_func ( func_id) ) ) ;
377+ // Using Udata for DW_AT_high_pc requires at least DWARF4
378+ entry. set ( gimli:: DW_AT_high_pc , AttributeValue :: Udata ( u64:: from ( end) ) ) ;
379+ }
361380 }
362381}
0 commit comments