@@ -6956,15 +6956,20 @@ static std::pair<std::unique_ptr<Module>, jl_llvm_functions_t>
69566956 return (!jl_is_submodule (mod, jl_base_module) &&
69576957 !jl_is_submodule (mod, jl_core_module));
69586958 };
6959+ auto in_tracked_path = [] (StringRef file) {
6960+ return jl_options.tracked_path != NULL && file.startswith (jl_options.tracked_path );
6961+ };
69596962 bool mod_is_user_mod = in_user_mod (ctx.module );
6963+ bool mod_is_tracked = in_tracked_path (ctx.file );
69606964 struct DebugLineTable {
69616965 DebugLoc loc;
69626966 StringRef file;
69636967 ssize_t line;
69646968 bool is_user_code;
6969+ bool is_tracked; // falls within an explicitly set file or directory
69656970 unsigned inlined_at;
69666971 bool operator ==(const DebugLineTable &other) const {
6967- return other.loc == loc && other.file == file && other.line == line && other.is_user_code == is_user_code && other.inlined_at == inlined_at;
6972+ return other.loc == loc && other.file == file && other.line == line && other.is_user_code == is_user_code && other.is_tracked == is_tracked && other. inlined_at == inlined_at;
69686973 }
69696974 };
69706975 std::vector<DebugLineTable> linetable;
@@ -6977,6 +6982,7 @@ static std::pair<std::unique_ptr<Module>, jl_llvm_functions_t>
69776982 topinfo.file = ctx.file ;
69786983 topinfo.line = toplineno;
69796984 topinfo.is_user_code = mod_is_user_mod;
6985+ topinfo.is_tracked = mod_is_tracked;
69806986 topinfo.inlined_at = 0 ;
69816987 topinfo.loc = topdebugloc;
69826988 for (size_t i = 0 ; i < nlocs; i++) {
@@ -6990,13 +6996,14 @@ static std::pair<std::unique_ptr<Module>, jl_llvm_functions_t>
69906996 info.line = jl_unbox_long (jl_fieldref (locinfo, 3 ));
69916997 info.inlined_at = jl_unbox_long (jl_fieldref (locinfo, 4 ));
69926998 assert (info.inlined_at <= i);
6999+ info.file = jl_symbol_name (filesym);
7000+ if (info.file .empty ())
7001+ info.file = " <missing>" ;
69937002 if (module == ctx.module )
69947003 info.is_user_code = mod_is_user_mod;
69957004 else
69967005 info.is_user_code = in_user_mod (module );
6997- info.file = jl_symbol_name (filesym);
6998- if (info.file .empty ())
6999- info.file = " <missing>" ;
7006+ info.is_tracked = in_tracked_path (info.file );
70007007 if (ctx.debug_enabled ) {
70017008 StringRef fname;
70027009 if (jl_is_method_instance (method))
@@ -7110,13 +7117,15 @@ static std::pair<std::unique_ptr<Module>, jl_llvm_functions_t>
71107117 cursor = -1 ;
71117118 };
71127119
7113- auto do_coverage = [&] (bool in_user_code) {
7120+ auto do_coverage = [&] (bool in_user_code, bool is_tracked ) {
71147121 return (coverage_mode == JL_LOG_ALL ||
7115- (coverage_mode == JL_LOG_USER && in_user_code));
7122+ (in_user_code && coverage_mode == JL_LOG_USER) ||
7123+ (is_tracked && coverage_mode == JL_LOG_PATH));
71167124 };
7117- auto do_malloc_log = [&] (bool in_user_code) {
7125+ auto do_malloc_log = [&] (bool in_user_code, bool is_tracked ) {
71187126 return (malloc_log_mode == JL_LOG_ALL ||
7119- (malloc_log_mode == JL_LOG_USER && in_user_code));
7127+ (in_user_code && malloc_log_mode == JL_LOG_USER) ||
7128+ (is_tracked && malloc_log_mode == JL_LOG_PATH));
71207129 };
71217130 std::vector<unsigned > current_lineinfo, new_lineinfo;
71227131 auto coverageVisitStmt = [&] (size_t dbg) {
@@ -7135,15 +7144,15 @@ static std::pair<std::unique_ptr<Module>, jl_llvm_functions_t>
71357144 if (newdbg != current_lineinfo[dbg]) {
71367145 current_lineinfo[dbg] = newdbg;
71377146 const auto &info = linetable.at (newdbg);
7138- if (do_coverage (info.is_user_code ))
7147+ if (do_coverage (info.is_user_code , info. is_tracked ))
71397148 coverageVisitLine (ctx, info.file , info.line );
71407149 }
71417150 }
71427151 new_lineinfo.clear ();
71437152 };
71447153 auto mallocVisitStmt = [&] (unsigned dbg, Value *sync) {
7145- if (!do_malloc_log (mod_is_user_mod) || dbg == 0 ) {
7146- if (do_malloc_log (true ) && sync)
7154+ if (!do_malloc_log (mod_is_user_mod, mod_is_tracked ) || dbg == 0 ) {
7155+ if (do_malloc_log (true , mod_is_tracked ) && sync)
71477156 ctx.builder .CreateCall (prepare_call (sync_gc_total_bytes_func), {sync});
71487157 return ;
71497158 }
@@ -7154,7 +7163,7 @@ static std::pair<std::unique_ptr<Module>, jl_llvm_functions_t>
71547163 if (coverage_mode != JL_LOG_NONE) {
71557164 // record all lines that could be covered
71567165 for (const auto &info : linetable)
7157- if (do_coverage (info.is_user_code ))
7166+ if (do_coverage (info.is_user_code , info. is_tracked ))
71587167 jl_coverage_alloc_line (info.file , info.line );
71597168 }
71607169
@@ -7209,15 +7218,15 @@ static std::pair<std::unique_ptr<Module>, jl_llvm_functions_t>
72097218 }
72107219
72117220 Value *sync_bytes = nullptr ;
7212- if (do_malloc_log (true ))
7221+ if (do_malloc_log (true , mod_is_tracked ))
72137222 sync_bytes = ctx.builder .CreateCall (prepare_call (diff_gc_total_bytes_func), {});
72147223 { // coverage for the function definition line number
72157224 const auto &topinfo = linetable.at (0 );
72167225 if (linetable.size () > 1 ) {
72177226 if (topinfo == linetable.at (1 ))
72187227 current_lineinfo.push_back (1 );
72197228 }
7220- if (do_coverage (topinfo.is_user_code ))
7229+ if (do_coverage (topinfo.is_user_code , topinfo. is_tracked ))
72217230 coverageVisitLine (ctx, topinfo.file , topinfo.line );
72227231 }
72237232
0 commit comments