Skip to content

Commit 9606d96

Browse files
committed
Add debug logging to core hooks
A debug log can help to understand what's gone wrong in certain cases, such as when a separate Julia processes is used during precompilation.
1 parent 8caab54 commit 9606d96

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/hooks.jl

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
_debug_log = nothing
2+
13
# Adaptor for the API/ABI expected by the Julia runtime code.
24
function core_parser_hook(code, filename, lineno, offset, options)
35
try
@@ -8,6 +10,15 @@ function core_parser_hook(code, filename, lineno, offset, options)
810
(ptr,len) = code
911
code = String(unsafe_wrap(Array, ptr, len))
1012
end
13+
if !isnothing(_debug_log)
14+
print(_debug_log, """
15+
#-#-#-------------------------------
16+
# ENTER filename=$filename, lineno=$lineno, offset=$offset, options=$options"
17+
#-#-#-------------------------------
18+
""")
19+
write(_debug_log, code)
20+
end
21+
1122
io = IOBuffer(code)
1223
seek(io, offset)
1324

@@ -37,6 +48,14 @@ function core_parser_hook(code, filename, lineno, offset, options)
3748
# of one cancel here.
3849
last_offset = last_byte(stream)
3950

51+
if !isnothing(_debug_log)
52+
println(_debug_log, """
53+
#-#-#-
54+
# EXIT last_offset=$last_offset
55+
#-#-#-
56+
""")
57+
end
58+
4059
# Rewrap result in an svec for use by the C code
4160
return Core.svec(ex, last_offset)
4261
catch exc
@@ -67,6 +86,14 @@ flisp parser for all parsing work.
6786
That is, JuliaSyntax will be used for `include()` `Meta.parse()`, the REPL, etc.
6887
"""
6988
function enable_in_core!(enable=true)
89+
debug_filename = get(ENV, "JULIA_SYNTAX_DEBUG_FILE", nothing)
90+
global _debug_log
91+
if enable && !isnothing(debug_filename)
92+
_debug_log = open(debug_filename, "w")
93+
elseif !enable && !isnothing(_debug_log)
94+
close(_debug_log)
95+
_debug_log = nothing
96+
end
7097
parser = enable ? core_parser_hook : Core.Compiler.fl_parse
7198
Base.eval(Core, :(_parse = $parser))
7299
nothing

0 commit comments

Comments
 (0)