Skip to content

Commit e93f52a

Browse files
authored
Merge pull request #88 from JuliaDebug/teh/codetracking
Integrate with CodeTracking and support line numbers when setting breakpoints
2 parents 28af3b3 + 465de2b commit e93f52a

File tree

10 files changed

+230
-53
lines changed

10 files changed

+230
-53
lines changed

Manifest.toml

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,44 @@
33
[[Base64]]
44
uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
55

6-
[[Dates]]
7-
deps = ["Printf"]
8-
uuid = "ade2ca70-3891-5945-98fb-dc099432e06a"
6+
[[CodeTracking]]
7+
deps = ["Test", "UUIDs"]
8+
git-tree-sha1 = "591b73b37c92ed7d55d3a14e266829c21aa3a7eb"
9+
uuid = "da1fd8a2-8d9e-5ec2-8556-3022fb5608a2"
10+
version = "0.3.0"
11+
12+
[[Distributed]]
13+
deps = ["Random", "Serialization", "Sockets"]
14+
uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b"
915

1016
[[InteractiveUtils]]
1117
deps = ["Markdown"]
1218
uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
1319

20+
[[Logging]]
21+
uuid = "56ddb016-857b-54e1-b83d-db4d58db5568"
22+
1423
[[Markdown]]
1524
deps = ["Base64"]
1625
uuid = "d6f4376e-aef5-505a-96c1-9c027394607a"
1726

18-
[[Printf]]
19-
deps = ["Unicode"]
20-
uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7"
27+
[[Random]]
28+
deps = ["Serialization"]
29+
uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
30+
31+
[[SHA]]
32+
uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce"
33+
34+
[[Serialization]]
35+
uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
36+
37+
[[Sockets]]
38+
uuid = "6462fe0b-24de-5631-8697-dd941f90decc"
39+
40+
[[Test]]
41+
deps = ["Distributed", "InteractiveUtils", "Logging", "Random"]
42+
uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
2143

22-
[[Unicode]]
23-
uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"
44+
[[UUIDs]]
45+
deps = ["Random", "SHA"]
46+
uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"

Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ uuid = "aa1ae85d-cabe-5617-a682-6adf51b2e16a"
33
version = "0.1.1"
44

55
[deps]
6+
CodeTracking = "da1fd8a2-8d9e-5ec2-8556-3022fb5608a2"
67
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
78
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
89
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"

docs/Manifest.toml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
[[Base64]]
44
uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
55

6+
[[CodeTracking]]
7+
deps = ["Test", "UUIDs"]
8+
git-tree-sha1 = "591b73b37c92ed7d55d3a14e266829c21aa3a7eb"
9+
uuid = "da1fd8a2-8d9e-5ec2-8556-3022fb5608a2"
10+
version = "0.3.0"
11+
612
[[Dates]]
713
deps = ["Printf"]
814
uuid = "ade2ca70-3891-5945-98fb-dc099432e06a"
@@ -19,16 +25,16 @@ version = "0.6.0"
1925

2026
[[Documenter]]
2127
deps = ["Base64", "DocStringExtensions", "InteractiveUtils", "LibGit2", "Logging", "Markdown", "Pkg", "REPL", "Random", "Test", "Unicode"]
22-
git-tree-sha1 = "de745be4b00336588ab3269d5f43517e5c012973"
28+
git-tree-sha1 = "a8c41ba3d0861240dbec942ee1d0f86c57c37c1c"
2329
uuid = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
24-
version = "0.21.1"
30+
version = "0.21.5"
2531

2632
[[InteractiveUtils]]
2733
deps = ["Markdown"]
2834
uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
2935

3036
[[JuliaInterpreter]]
31-
deps = ["InteractiveUtils"]
37+
deps = ["CodeTracking", "InteractiveUtils", "Random", "UUIDs"]
3238
path = ".."
3339
uuid = "aa1ae85d-cabe-5617-a682-6adf51b2e16a"
3440
version = "0.1.1"

docs/Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
[deps]
2+
CodeTracking = "da1fd8a2-8d9e-5ec2-8556-3022fb5608a2"
23
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
34
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
45
JuliaInterpreter = "aa1ae85d-cabe-5617-a682-6adf51b2e16a"
56
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
7+
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"

docs/src/dev_reference.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ JuliaInterpreter.Compiled
2828
JuliaInterpreter.step_expr!
2929
JuliaInterpreter.finish!
3030
JuliaInterpreter.finish_and_return!
31+
JuliaInterpreter.finish_stack!
3132
JuliaInterpreter.get_return
3233
JuliaInterpreter.next_until!
3334
JuliaInterpreter.through_methoddef_or_done!
@@ -36,12 +37,24 @@ JuliaInterpreter.evaluate_foreigncall!
3637
JuliaInterpreter.maybe_evaluate_builtin
3738
```
3839

40+
## Breakpoints
41+
42+
```@docs
43+
@breakpoint
44+
breakpoint
45+
enable
46+
disable
47+
remove
48+
```
49+
3950
## Types
4051

4152
```@docs
4253
JuliaInterpreter.JuliaStackFrame
4354
JuliaInterpreter.JuliaFrameCode
4455
JuliaInterpreter.JuliaProgramCounter
56+
JuliaInterpreter.BreakpointState
57+
JuliaInterpreter.BreakpointRef
4558
```
4659

4760
## Internal storage
@@ -57,4 +70,7 @@ JuliaInterpreter.compiled_methods
5770
```@docs
5871
JuliaInterpreter.@lookup
5972
JuliaInterpreter.iswrappercall
73+
JuliaInterpreter.isdocexpr
74+
JuliaInterpreter.isglobalref
75+
JuliaInterpreter.statementnumber
6076
```

src/JuliaInterpreter.jl

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ using UUIDs
1010
# in Base and stdlib
1111
using Random.DSFMT
1212
using InteractiveUtils
13+
using CodeTracking
1314

1415
export @interpret, Compiled, JuliaStackFrame,
1516
Breakpoints, breakpoint, @breakpoint, breakpoints, enable, disable, remove
@@ -390,7 +391,7 @@ julia> framecode, frameargs, lenv, argtypes = JuliaInterpreter.prepare_call(myme
390391
julia> framecode
391392
JuliaInterpreter.JuliaFrameCode(mymethod(x::Array{T,1}) where T in Main at none:1, CodeInfo(
392393
1 ─ return 1
393-
), Core.TypeMapEntry[#undef], BitSet([]), false, false, true)
394+
), Union{Compiled, TypeMapEntry}[#undef], JuliaInterpreter.BreakpointState[#undef], BitSet([]), false, false, true)
394395
395396
julia> frameargs
396397
2-element Array{Any,1}:
@@ -915,9 +916,9 @@ mymethod (generic function with 1 method)
915916
916917
julia> JuliaInterpreter.enter_call_expr(:(\$mymethod(1)))
917918
JuliaStackFrame(JuliaInterpreter.JuliaFrameCode(mymethod(x) in Main at none:1, CodeInfo(
918-
1 ─ %1 = (\$(QuoteNode(+)))(x, 1)
919+
1 ─ %1 = ($(QuoteNode(+)))(x, 1)
919920
└── return %1
920-
), Core.TypeMapEntry[#undef, #undef], BitSet([1]), false, false, true), Union{Nothing, Some{Any}}[Some(mymethod), Some(1)], Any[#undef, #undef], Any[], Int64[], Base.RefValue{Any}(nothing), Base.RefValue{JuliaInterpreter.JuliaProgramCounter}(JuliaProgramCounter(1)), Dict{Symbol,Int64}(), Any[])
921+
), Union{Compiled, TypeMapEntry}[#undef, #undef], JuliaInterpreter.BreakpointState[#undef, #undef], BitSet([1]), false, false, true), Union{Nothing, Some{Any}}[Some(mymethod), Some(1)], Any[#undef, #undef], Any[], Int64[], Base.RefValue{Any}(nothing), Base.RefValue{JuliaInterpreter.JuliaProgramCounter}(JuliaProgramCounter(1)), Dict(Symbol("#self#")=>1,:x=>2), Any[])
921922
922923
julia> mymethod(x::Vector{T}) where T = 1
923924
mymethod (generic function with 2 methods)
@@ -930,7 +931,7 @@ julia> a = [1.0, 2.0]
930931
julia> JuliaInterpreter.enter_call_expr(:(\$mymethod(\$a)))
931932
JuliaStackFrame(JuliaInterpreter.JuliaFrameCode(mymethod(x::Array{T,1}) where T in Main at none:1, CodeInfo(
932933
1 ─ return 1
933-
), Core.TypeMapEntry[#undef], BitSet([]), false, false, true), Union{Nothing, Some{Any}}[Some(mymethod), Some([1.0, 2.0])], Any[#undef], Any[Float64], Int64[], Base.RefValue{Any}(nothing), Base.RefValue{JuliaInterpreter.JuliaProgramCounter}(JuliaProgramCounter(1)), Dict{Symbol,Int64}(), Any[])
934+
), Union{Compiled, TypeMapEntry}[#undef], JuliaInterpreter.BreakpointState[#undef], BitSet([]), false, false, true), Union{Nothing, Some{Any}}[Some(mymethod), Some([1.0, 2.0])], Any[#undef], Any[Float64], Int64[], Base.RefValue{Any}(nothing), Base.RefValue{JuliaInterpreter.JuliaProgramCounter}(JuliaProgramCounter(1)), Dict(Symbol("#self#")=>1,:x=>2), Any[])
934935
```
935936
936937
See [`enter_call`](@ref) for a similar approach not based on expressions.
@@ -958,15 +959,15 @@ julia> JuliaInterpreter.enter_call(mymethod, 1)
958959
JuliaStackFrame(JuliaInterpreter.JuliaFrameCode(mymethod(x) in Main at none:1, CodeInfo(
959960
1 ─ %1 = ($(QuoteNode(+)))(x, 1)
960961
└── return %1
961-
), Core.TypeMapEntry[#undef, #undef], BitSet([1]), false, false, true), Union{Nothing, Some{Any}}[Some(mymethod), Some(1)], Any[#undef, #undef], Any[], Int64[], Base.RefValue{Any}(nothing), Base.RefValue{JuliaInterpreter.JuliaProgramCounter}(JuliaProgramCounter(1)), Dict{Symbol,Int64}(), Any[])
962+
), Union{Compiled, TypeMapEntry}[#undef, #undef], JuliaInterpreter.BreakpointState[#undef, #undef], BitSet([1]), false, false, true), Union{Nothing, Some{Any}}[Some(mymethod), Some(1)], Any[#undef, #undef], Any[], Int64[], Base.RefValue{Any}(nothing), Base.RefValue{JuliaInterpreter.JuliaProgramCounter}(JuliaProgramCounter(1)), Dict(Symbol("#self#")=>1,:x=>2), Any[])
962963
963964
julia> mymethod(x::Vector{T}) where T = 1
964965
mymethod (generic function with 2 methods)
965966
966967
julia> JuliaInterpreter.enter_call(mymethod, [1.0, 2.0])
967968
JuliaStackFrame(JuliaInterpreter.JuliaFrameCode(mymethod(x::Array{T,1}) where T in Main at none:1, CodeInfo(
968969
1 ─ return 1
969-
), Core.TypeMapEntry[#undef], BitSet([]), false, false, true), Union{Nothing, Some{Any}}[Some(mymethod), Some([1.0, 2.0])], Any[#undef], Any[Float64], Int64[], Base.RefValue{Any}(nothing), Base.RefValue{JuliaInterpreter.JuliaProgramCounter}(JuliaProgramCounter(1)), Dict{Symbol,Int64}(), Any[])
970+
), Union{Compiled, TypeMapEntry}[#undef], JuliaInterpreter.BreakpointState[#undef], BitSet([]), false, false, true), Union{Nothing, Some{Any}}[Some(mymethod), Some([1.0, 2.0])], Any[#undef], Any[Float64], Int64[], Base.RefValue{Any}(nothing), Base.RefValue{JuliaInterpreter.JuliaProgramCounter}(JuliaProgramCounter(1)), Dict(Symbol("#self#")=>1,:x=>2), Any[])
970971
```
971972
972973
For a `@generated` function you can use `enter_call((f, true), args...; kwargs...)`
@@ -1084,7 +1085,8 @@ macro interpret(arg)
10841085
push!(stack, frame)
10851086
return stack, BreakpointRef(frame.code, 1)
10861087
end
1087-
finish_and_return!(stack, frame)
1088+
ret = finish_and_return!(stack, frame)
1089+
isa(ret, BreakpointRef) ? (stack, ret) : ret
10881090
end
10891091
end
10901092

0 commit comments

Comments
 (0)