Get structs to work in debug information
This commit is contained in:
		
							parent
							
								
									c0b02f8a45
								
							
						
					
					
						commit
						f952651a66
					
				| @ -502,9 +502,23 @@ impl DebugTypeHolder { | ||||
|                 } | ||||
|                 DebugTypeData::Struct(st) => { | ||||
|                     let mut elements = st | ||||
|                         .elements | ||||
|                         .fields | ||||
|                         .iter() | ||||
|                         .map(|e| *debug.types.get(e).unwrap()) | ||||
|                         .map(|field| { | ||||
|                             LLVMDIBuilderCreateMemberType( | ||||
|                                 debug.builder, | ||||
|                                 *debug.programs.get(&st.scope).unwrap(), | ||||
|                                 into_cstring(field.name.clone()).as_ptr(), | ||||
|                                 field.name.len(), | ||||
|                                 debug.file_ref, | ||||
|                                 field.location.line, | ||||
|                                 field.size_bits, | ||||
|                                 0, | ||||
|                                 1, | ||||
|                                 field.flags.as_llvm(), | ||||
|                                 *debug.types.get(&field.ty).unwrap(), | ||||
|                             ) | ||||
|                         }) | ||||
|                         .collect::<Vec<_>>(); | ||||
|                     LLVMDIBuilderCreateStructType( | ||||
|                         debug.builder, | ||||
|  | ||||
| @ -9,9 +9,10 @@ use crate::{ | ||||
|     CmpPredicate, Instr, InstructionData, TerminatorKind, | ||||
|     builder::*, | ||||
|     debug_information::{ | ||||
|         DebugArrayType, DebugBasicType, DebugLocation, DebugLocationValue, DebugMetadataHolder, | ||||
|         DebugMetadataValue, DebugPointerType, DebugProgramValue, DebugScopeValue, DebugStructType, | ||||
|         DebugSubprogramType, DebugTypeData, DebugTypeHolder, DebugTypeValue, | ||||
|         DebugArrayType, DebugBasicType, DebugFieldType, DebugLocation, DebugLocationValue, | ||||
|         DebugMetadataHolder, DebugMetadataValue, DebugPointerType, DebugProgramValue, | ||||
|         DebugScopeValue, DebugStructType, DebugSubprogramType, DebugTypeData, DebugTypeHolder, | ||||
|         DebugTypeValue, | ||||
|     }, | ||||
| }; | ||||
| 
 | ||||
| @ -267,7 +268,19 @@ impl Debug for DebugStructType { | ||||
|             .field("location", &self.location) | ||||
|             .field("size_bit", &self.size_bits) | ||||
|             .field("flags", &self.flags) | ||||
|             .field("elements", &self.elements) | ||||
|             .field("elements", &self.fields) | ||||
|             .finish() | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| impl Debug for DebugFieldType { | ||||
|     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||||
|         f.debug_struct(&format!("Field({})", self.name)) | ||||
|             .field("location", &self.location) | ||||
|             .field("size_bits", &self.size_bits) | ||||
|             .field("offset", &self.offset) | ||||
|             .field("flags", &self.flags) | ||||
|             .field("ty", &self.ty) | ||||
|             .finish() | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -295,7 +295,17 @@ pub struct DebugStructType { | ||||
|     pub location: DebugLocation, | ||||
|     pub size_bits: u64, | ||||
|     pub flags: DwarfFlags, | ||||
|     pub elements: Vec<DebugTypeValue>, | ||||
|     pub fields: Vec<DebugFieldType>, | ||||
| } | ||||
| 
 | ||||
| #[derive(Clone)] | ||||
| pub struct DebugFieldType { | ||||
|     pub name: String, | ||||
|     pub location: DebugLocation, | ||||
|     pub size_bits: u64, | ||||
|     pub offset: u64, | ||||
|     pub flags: DwarfFlags, | ||||
|     pub ty: DebugTypeValue, | ||||
| } | ||||
| 
 | ||||
| #[derive(Clone)] | ||||
|  | ||||
| @ -4,11 +4,11 @@ use reid_lib::{ | ||||
|     builder::{InstructionValue, TypeValue}, | ||||
|     compile::CompiledModule, | ||||
|     debug_information::{ | ||||
|         DebugArrayType, DebugBasicType, DebugFileData, DebugInformation, DebugLocalVariable, | ||||
|         DebugLocation, DebugMetadata, DebugMetadataValue, DebugParamVariable, DebugPointerType, | ||||
|         DebugProgramValue, DebugRecordKind, DebugScopeValue, DebugStructType, DebugSubprogramData, | ||||
|         DebugSubprogramOptionals, DebugSubprogramType, DebugTypeData, DebugTypeValue, | ||||
|         DwarfEncoding, DwarfFlags, InstructionDebugRecordData, | ||||
|         DebugArrayType, DebugBasicType, DebugFieldType, DebugFileData, DebugInformation, | ||||
|         DebugLocalVariable, DebugLocation, DebugMetadata, DebugMetadataValue, DebugParamVariable, | ||||
|         DebugPointerType, DebugProgramValue, DebugRecordKind, DebugScopeValue, DebugStructType, | ||||
|         DebugSubprogramData, DebugSubprogramOptionals, DebugSubprogramType, DebugTypeData, | ||||
|         DebugTypeValue, DwarfEncoding, DwarfFlags, InstructionDebugRecordData, | ||||
|     }, | ||||
|     Block, CmpPredicate, ConstValue, Context, CustomTypeKind, Function, FunctionFlags, Instr, | ||||
|     Module, NamedStruct, TerminatorKind as Term, Type, | ||||
| @ -1044,24 +1044,26 @@ impl TypeKind { | ||||
| 
 | ||||
|                 match &typedef.kind { | ||||
|                     TypeDefinitionKind::Struct(struct_type) => { | ||||
|                         let (elements, sizes): (Vec<_>, Vec<_>) = struct_type | ||||
|                             .0 | ||||
|                             .iter() | ||||
|                             .map(|t| { | ||||
|                                 ( | ||||
|                                     t.1.clone().get_debug_type_hard( | ||||
|                                         scope, | ||||
|                                         debug_info, | ||||
|                                         debug_types, | ||||
|                                         type_values, | ||||
|                                         types, | ||||
|                                         tokens, | ||||
|                                     ), | ||||
|                                     t.1.size_of(), | ||||
|                                 ) | ||||
|                             }) | ||||
|                             .unzip(); | ||||
|                         let size_bits: u64 = sizes.iter().sum(); | ||||
|                         let mut fields = Vec::new(); | ||||
|                         let mut size_bits = 0; | ||||
|                         for field in &struct_type.0 { | ||||
|                             fields.push(DebugFieldType { | ||||
|                                 name: field.0.clone(), | ||||
|                                 location: field.2.into_debug(tokens).unwrap(), | ||||
|                                 size_bits: field.1.size_of(), | ||||
|                                 offset: size_bits, | ||||
|                                 flags: DwarfFlags, | ||||
|                                 ty: field.1.get_debug_type_hard( | ||||
|                                     scope, | ||||
|                                     debug_info, | ||||
|                                     debug_types, | ||||
|                                     type_values, | ||||
|                                     types, | ||||
|                                     tokens, | ||||
|                                 ), | ||||
|                             }); | ||||
|                             size_bits += field.1.size_of(); | ||||
|                         } | ||||
|                         { | ||||
|                             DebugTypeData::Struct(DebugStructType { | ||||
|                                 name: name.clone(), | ||||
| @ -1069,7 +1071,7 @@ impl TypeKind { | ||||
|                                 location: typedef.meta.into_debug(tokens).unwrap(), | ||||
|                                 size_bits, | ||||
|                                 flags: DwarfFlags, | ||||
|                                 elements, | ||||
|                                 fields, | ||||
|                             }) | ||||
|                         } | ||||
|                     } | ||||
|  | ||||
| @ -1,8 +1,7 @@ | ||||
| // Arithmetic, function calls and imports! | ||||
| 
 | ||||
| struct Test { | ||||
|     field: i32, | ||||
|     second: [u32; 4] | ||||
|   field : i32, second : [u32; 4] | ||||
| } | ||||
| 
 | ||||
| fn test() -> [Test; 1] { | ||||
| @ -14,15 +13,15 @@ fn test() -> [Test; 1] { | ||||
| } | ||||
| 
 | ||||
| fn main() -> u32 { | ||||
|     let mut value = test(); | ||||
|   let mut value = test(); | ||||
| 
 | ||||
|     let val1 = 0; | ||||
|     let val2 = 1; | ||||
|   let val1 = 0; | ||||
|   let val2 = 1; | ||||
| 
 | ||||
|     // value[val1].second[val2 + 1] = 99; | ||||
|   // value[val1].second[val2 + 1] = 99; | ||||
| 
 | ||||
|     let mut b = value[val1]; | ||||
|     b.second[2] = 99; | ||||
|   let mut b = value[val1]; | ||||
|   b.second[2] = 99; | ||||
| 
 | ||||
|     return value[val1].second[2]; | ||||
|   return value[val1].second[2]; | ||||
| } | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user