authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2015-12-13 14:33:52-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2015-12-13 14:34:07-07:00
log3d8eb10897a86b2616c6a1aa843b7ebe4134ac51
treea45f80edca9f20943b1dd809c383eb3283ab0152
parent9ec892539ee19d39ed040ead628f04da2d11577e

fix incorrect debug info path to imports


4 files changed, 28 insertions(+), 24 deletions(-)

src/analyze.hpp+1
......@@ -152,6 +152,7 @@ struct CodeGen {
152152 bool insert_bootstrap_code;
153153 CodeGenBuildType build_type;
154154 LLVMTargetMachineRef target_machine;
155 LLVMZigDIFile *dummy_di_file;
155156 bool is_native_target;
156157 Buf *root_source_dir;
157158 Buf *root_out_name;
src/codegen.cpp+25-22
......@@ -1316,9 +1316,8 @@ static void define_builtin_types(CodeGen *g) {
13161316 g->builtin_types.entry_usize->di_type
13171317 };
13181318 LLVMZigDIScope *compile_unit_scope = LLVMZigCompileUnitToScope(g->compile_unit);
1319 LLVMZigDIFile *difile = nullptr; // TODO make sure this ok
13201319 entry->di_type = LLVMZigCreateDebugStructType(g->dbuilder, compile_unit_scope,
1321 "string", difile, 0, entry->size_in_bits, entry->align_in_bits, 0,
1320 "string", g->dummy_di_file, 0, entry->size_in_bits, entry->align_in_bits, 0,
13221321 nullptr, di_element_types, element_count, 0, nullptr, "");
13231322
13241323 g->type_table.put(&entry->name, entry);
......@@ -1386,21 +1385,20 @@ static void init(CodeGen *g, Buf *source_path) {
13861385 buf_ptr(producer), is_optimized, flags, runtime_version,
13871386 "", 0, !g->strip_debug_symbols);
13881387
1388 // This is for debug stuff that doesn't have a real file.
1389 g->dummy_di_file = nullptr; //LLVMZigCreateFile(g->dbuilder, "", "");
1390
13891391 define_builtin_types(g);
13901392
13911393}
13921394
1393static ImportTableEntry *codegen_add_code(CodeGen *g, Buf *source_path, Buf *source_code) {
1395static ImportTableEntry *codegen_add_code(CodeGen *g, Buf *src_dirname, Buf *src_basename, Buf *source_code) {
13941396 int err;
1395 Buf full_path = BUF_INIT;
1396 os_path_join(g->root_source_dir, source_path, &full_path);
1397
1398 Buf dirname = BUF_INIT;
1399 Buf basename = BUF_INIT;
1400 os_path_split(&full_path, &dirname, &basename);
1397 Buf *full_path = buf_alloc();
1398 os_path_join(src_dirname, src_basename, full_path);
14011399
14021400 if (g->verbose) {
1403 fprintf(stderr, "\nOriginal Source (%s):\n", buf_ptr(source_path));
1401 fprintf(stderr, "\nOriginal Source (%s):\n", buf_ptr(full_path));
14041402 fprintf(stderr, "----------------\n");
14051403 fprintf(stderr, "%s\n", buf_ptr(source_code));
14061404
......@@ -1418,7 +1416,7 @@ static ImportTableEntry *codegen_add_code(CodeGen *g, Buf *source_path, Buf *sou
14181416 err->line_end = -1;
14191417 err->column_end = -1;
14201418 err->msg = tokenization.err;
1421 err->path = source_path;
1419 err->path = full_path;
14221420 err->source = source_code;
14231421 err->line_offsets = tokenization.line_offsets;
14241422
......@@ -1436,7 +1434,7 @@ static ImportTableEntry *codegen_add_code(CodeGen *g, Buf *source_path, Buf *sou
14361434 ImportTableEntry *import_entry = allocate<ImportTableEntry>(1);
14371435 import_entry->source_code = source_code;
14381436 import_entry->line_offsets = tokenization.line_offsets;
1439 import_entry->path = source_path;
1437 import_entry->path = full_path;
14401438 import_entry->fn_table.init(32);
14411439 import_entry->root = ast_parse(source_code, tokenization.tokens, import_entry, g->err_color);
14421440 assert(import_entry->root);
......@@ -1444,8 +1442,8 @@ static ImportTableEntry *codegen_add_code(CodeGen *g, Buf *source_path, Buf *sou
14441442 ast_print(import_entry->root, 0);
14451443 }
14461444
1447 import_entry->di_file = LLVMZigCreateFile(g->dbuilder, buf_ptr(&basename), buf_ptr(&dirname));
1448 g->import_table.put(source_path, import_entry);
1445 import_entry->di_file = LLVMZigCreateFile(g->dbuilder, buf_ptr(src_basename), buf_ptr(src_dirname));
1446 g->import_table.put(full_path, import_entry);
14491447
14501448
14511449 assert(import_entry->root->type == NodeTypeRoot);
......@@ -1473,7 +1471,7 @@ static ImportTableEntry *codegen_add_code(CodeGen *g, Buf *source_path, Buf *sou
14731471 goto done_looking_at_imports;
14741472 }
14751473 }
1476 codegen_add_code(g, &top_level_decl->data.use.path, import_code);
1474 codegen_add_code(g, search_path, &top_level_decl->data.use.path, import_code);
14771475 found_it = true;
14781476 break;
14791477 }
......@@ -1500,20 +1498,25 @@ done_looking_at_imports:
15001498 return import_entry;
15011499}
15021500
1503void codegen_add_root_code(CodeGen *g, Buf *source_path, Buf *source_code) {
1504 init(g, source_path);
1501void codegen_add_root_code(CodeGen *g, Buf *src_dir, Buf *src_basename, Buf *source_code) {
1502 Buf source_path = BUF_INIT;
1503 os_path_join(src_dir, src_basename, &source_path);
1504 init(g, &source_path);
15051505
1506 g->root_import = codegen_add_code(g, source_path, source_code);
1506 g->root_import = codegen_add_code(g, src_dir, src_basename, source_code);
15071507
15081508 if (g->insert_bootstrap_code) {
1509 Buf *path_to_bootstrap_src = buf_sprintf("%s/bootstrap.zig", ZIG_STD_DIR);
1509 Buf *bootstrap_dir = buf_create_from_str(ZIG_STD_DIR);
1510 Buf *bootstrap_basename = buf_create_from_str("bootstrap.zig");
1511 Buf path_to_bootstrap_src = BUF_INIT;
1512 os_path_join(bootstrap_dir, bootstrap_basename, &path_to_bootstrap_src);
15101513 Buf *import_code = buf_alloc();
15111514 int err;
1512 if ((err = os_fetch_file_path(path_to_bootstrap_src, import_code))) {
1513 zig_panic("unable to open '%s': %s", buf_ptr(path_to_bootstrap_src), err_str(err));
1515 if ((err = os_fetch_file_path(&path_to_bootstrap_src, import_code))) {
1516 zig_panic("unable to open '%s': %s", buf_ptr(&path_to_bootstrap_src), err_str(err));
15141517 }
15151518
1516 codegen_add_code(g, path_to_bootstrap_src, import_code);
1519 codegen_add_code(g, bootstrap_dir, bootstrap_basename, import_code);
15171520 }
15181521
15191522 if (g->verbose) {
src/codegen.hpp+1-1
......@@ -34,7 +34,7 @@ void codegen_set_errmsg_color(CodeGen *codegen, ErrColor err_color);
3434void codegen_set_out_type(CodeGen *codegen, OutType out_type);
3535void codegen_set_out_name(CodeGen *codegen, Buf *out_name);
3636
37void codegen_add_root_code(CodeGen *g, Buf *source_path, Buf *source_code);
37void codegen_add_root_code(CodeGen *g, Buf *source_dir, Buf *source_basename, Buf *source_code);
3838
3939void codegen_link(CodeGen *g, const char *out_file);
4040
src/main.cpp+1-1
......@@ -144,7 +144,7 @@ static int build(const char *arg0, int argc, char **argv) {
144144 codegen_set_out_name(g, buf_create_from_str(b.out_name));
145145 codegen_set_verbose(g, b.verbose);
146146 codegen_set_errmsg_color(g, b.color);
147 codegen_add_root_code(g, &root_source_name, &root_source_code);
147 codegen_add_root_code(g, &root_source_dir, &root_source_name, &root_source_code);
148148 codegen_link(g, b.out_file);
149149
150150 return 0;