@@ -22,13 +22,14 @@ function get_function_in_module_or_Main(m::Module, f::Symbol)
22
22
m = Main
23
23
end
24
24
f = getfield (m, f)
25
- return f isa Function ? f : nothing
25
+ return ( f isa Function || f isa Type) ? f : nothing
26
26
end
27
27
28
28
function add_breakpoint! (state:: DebuggerState , cmd:: AbstractString )
29
29
cmd = strip (cmd)
30
- bp_error (err) = (printstyled (stderr , err, " \n " , color = Base. error_color ()); false )
31
- undef_func (m, f) = bp_error (" $f in " * (m != = Main ? " $m or" : " " ) * " Main is either not a function or not defined" )
30
+ bp_error () = (@error " Empty breakpoint expression" ; false )
31
+ bp_error (err) = (@error err; false )
32
+ undef_func (m, expr) = bp_error (" Expression $(expr) in " * (m != = Main ? " $m or" : " " ) * " Main did not evaluate to a function or type" )
32
33
isempty (cmd) && return bp_error ()
33
34
frame = active_frame (state)
34
35
@@ -71,36 +72,28 @@ function add_breakpoint!(state::DebuggerState, cmd::AbstractString)
71
72
m = moduleof (frame)
72
73
has_args = false
73
74
if location_expr isa Symbol
74
- fsym = location_expr
75
- f = get_function_in_module_or_Main (m, fsym)
75
+ f = get_function_in_module_or_Main (m, location_expr)
76
76
else
77
- # check that the expr is a chain of getproperty calls
78
- expr = fsym = location_expr
77
+ expr = location_expr
79
78
if isexpr (expr, :call )
80
79
has_args = true
81
80
expr = expr. args[1 ]
82
81
end
83
- while expr isa Expr
84
- if expr. head == Symbol (" ." ) && length (expr. args) == 2 && expr. args[2 ] isa QuoteNode
85
- expr = expr. args[1 ]
86
- else
87
- @goto not_a_function
88
- end
89
- end
90
82
for m in (moduleof (frame), Main)
91
83
try
92
- f_eval = Base. eval (m, has_args ? location_expr . args[ 1 ] : location_expr )
93
- if f_eval isa Function
84
+ f_eval = Base. eval (m, expr )
85
+ if f_eval isa Function || f_eval isa Type
94
86
f = f_eval
95
87
break
96
88
end
97
- catch
89
+ catch e
90
+ bp_error (" error when evaluating expression $(expr) in module $m " )
98
91
end
99
92
end
100
93
end
101
- f === nothing && return undef_func (m, fsym )
94
+ f === nothing && return undef_func (m, location_expr )
102
95
if ! has_args
103
- @info " added breakpoint for function $f " * (line === nothing ? " " : " :$line " )
96
+ @info string ( " added breakpoint for " , f isa Function ? " function" : " type " , " $f " , (line === nothing ? " " : " :$line " ) )
104
97
breakpoint (f, line, cond_expr)
105
98
return true
106
99
end
0 commit comments