aboutsummaryrefslogtreecommitdiff
path: root/src/analyze.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2016-02-07 01:53:38 -0700
committerAndrew Kelley <superjoe30@gmail.com>2016-02-07 01:53:38 -0700
commit642b38a5774c45271a709029de5827d6d305f8b3 (patch)
tree90f56469fb1904fed067f23f7b49b7081461396b /src/analyze.cpp
parent7f6b0ba6eafd566a5a9243286ba59fc0e4587d30 (diff)
downloadzig-642b38a5774c45271a709029de5827d6d305f8b3.tar.gz
zig-642b38a5774c45271a709029de5827d6d305f8b3.zip
add debug info for slices
closes #47
Diffstat (limited to 'src/analyze.cpp')
-rw-r--r--src/analyze.cpp47
1 files changed, 40 insertions, 7 deletions
diff --git a/src/analyze.cpp b/src/analyze.cpp
index e37885f353..18012fa7a2 100644
--- a/src/analyze.cpp
+++ b/src/analyze.cpp
@@ -467,16 +467,49 @@ static TypeTableEntry *get_slice_type(CodeGen *g, TypeTableEntry *child_type, bo
slice_type_common_init(g, child_type, is_const, entry);
- LLVMZigDIType *di_element_types[] = {
- pointer_type->di_type,
- g->builtin_types.entry_isize->di_type,
- };
+
LLVMZigDIScope *compile_unit_scope = LLVMZigCompileUnitToScope(g->compile_unit);
+ LLVMZigDIFile *di_file = nullptr;
+ unsigned line = 0;
+ entry->di_type = LLVMZigCreateReplaceableCompositeType(g->dbuilder,
+ LLVMZigTag_DW_structure_type(), buf_ptr(&entry->name),
+ compile_unit_scope, di_file, line);
+
+ uint64_t ptr_debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, pointer_type->type_ref);
+ uint64_t ptr_debug_align_in_bits = 8*LLVMABISizeOfType(g->target_data_ref, pointer_type->type_ref);
+ uint64_t ptr_offset_in_bits = 8*LLVMOffsetOfElement(g->target_data_ref, entry->type_ref, 0);
+
+ TypeTableEntry *isize_type = g->builtin_types.entry_isize;
+ uint64_t len_debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, isize_type->type_ref);
+ uint64_t len_debug_align_in_bits = 8*LLVMABISizeOfType(g->target_data_ref, isize_type->type_ref);
+ uint64_t len_offset_in_bits = 8*LLVMOffsetOfElement(g->target_data_ref, entry->type_ref, 1);
+
uint64_t debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, entry->type_ref);
uint64_t debug_align_in_bits = 8*LLVMABISizeOfType(g->target_data_ref, entry->type_ref);
- entry->di_type = LLVMZigCreateDebugStructType(g->dbuilder, compile_unit_scope,
- buf_ptr(&entry->name), g->dummy_di_file, 0, debug_size_in_bits, debug_align_in_bits, 0,
- nullptr, di_element_types, element_count, 0, nullptr, "");
+
+ LLVMZigDIType *di_element_types[] = {
+ LLVMZigCreateDebugMemberType(g->dbuilder, LLVMZigTypeToScope(entry->di_type),
+ "ptr", di_file, line,
+ ptr_debug_size_in_bits,
+ ptr_debug_align_in_bits,
+ ptr_offset_in_bits,
+ 0, child_type->di_type),
+ LLVMZigCreateDebugMemberType(g->dbuilder, LLVMZigTypeToScope(entry->di_type),
+ "len", di_file, line,
+ len_debug_size_in_bits,
+ len_debug_align_in_bits,
+ len_offset_in_bits,
+ 0, child_type->di_type),
+ };
+ LLVMZigDIType *replacement_di_type = LLVMZigCreateDebugStructType(g->dbuilder,
+ compile_unit_scope,
+ buf_ptr(&entry->name),
+ di_file, line, debug_size_in_bits, debug_align_in_bits, 0,
+ nullptr, di_element_types, 2, 0, nullptr, "");
+
+ LLVMZigReplaceTemporary(g->dbuilder, entry->di_type, replacement_di_type);
+ entry->di_type = replacement_di_type;
+
entry->data.structure.complete = true;