Skip to content

Commit cbbb690

Browse files
authored
Remove dead code, increase code coverage (#86)
* fix printing to the correct io * remove dead code * more code coverage
1 parent 727417f commit cbbb690

File tree

6 files changed

+421
-67
lines changed

6 files changed

+421
-67
lines changed

src/LineNumbers.jl

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ struct SourceFile
77
data::Vector{UInt8}
88
offsets::Vector{UInt64}
99
end
10-
Base.length(file::SourceFile) = length(file.offsets)
1110

1211
function SourceFile(data::AbstractString)
1312
offsets = UInt64[0]
@@ -28,53 +27,6 @@ function compute_line(file::SourceFile, offset::Integer)
2827
ind <= length(file.offsets) && file.offsets[ind] == offset ? ind : ind - 1
2928
end
3029

31-
function Base.getindex(file::SourceFile, line::Int)
32-
if line == length(file.offsets)
33-
return file.data[(file.offsets[end]+1):end]
34-
else
35-
# - 1 to skip the '\n'
36-
return file.data[(file.offsets[line]+1):(file.offsets[line+1]-1)]
37-
end
38-
end
39-
Base.getindex(file::SourceFile, arr::AbstractArray) = [file[x] for x in arr]
4030

41-
# LineBreaking
42-
43-
"""
44-
Indexing adaptor to map from a flat byte offset to a `[line][offset]` pair.
45-
Optionally, off may specify a byte offset relative to which the line number and
46-
offset should be computed
47-
"""
48-
struct LineBreaking{T}
49-
off::UInt64
50-
file::SourceFile
51-
obj::T
52-
end
53-
54-
function indtransform(lb::LineBreaking, x::Int)
55-
offline = compute_line(lb.file, lb.off)
56-
line = compute_line(lb.file, x)
57-
lineoffset = lb.file.offsets[line]
58-
off = x - lineoffset + 1
59-
if lineoffset < lb.off
60-
off -= lb.off - lineoffset
61-
end
62-
(line - offline + 1), off
63-
end
64-
65-
function Base.getindex(lb::LineBreaking, x::Int)
66-
l, o = indtransform(lb, x)
67-
lb.obj[l][o]
68-
end
69-
70-
function Base.setindex!(lb::LineBreaking, y, x::Int)
71-
l, o = indtransform(lb, x)
72-
lb.obj[l][o] = y
73-
end
74-
function Base.setindex!(lb::LineBreaking, y, x::AbstractArray)
75-
for i in x
76-
lb[i] = y
77-
end
78-
end
7931

8032
end # module

src/commands.jl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,17 @@ function show_breakpoint(io::IO, bp::BreakpointRef)
1818
else
1919
print(outbuf, "Breaking on error: ")
2020
end
21+
code = bp.framecode
22+
if code.scope isa Method
23+
scope_str = sprint(locdesc, code)
24+
else
25+
scope_str = repr(code.scope)
26+
end
2127
if checkbounds(Bool, bp.framecode.breakpoints, bp.stmtidx)
2228
lineno = linenumber(bp.framecode, bp.stmtidx)
23-
print(outbuf, bp.framecode.scope, ", line ", lineno)
29+
print(outbuf, scope_str, ", line ", lineno)
2430
else
25-
print(outbuf, bp.framecode.scope, ", %", bp.stmtidx)
31+
print(outbuf, scope_str, ", %", bp.stmtidx)
2632
end
2733
if bp.err !== nothing
2834
print(outbuf, ", ", bp.err)

src/locationinfo.jl

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -52,22 +52,26 @@ const _print_full_path = Ref(true)
5252
function locdesc(frame::Frame)
5353
sprint() do io
5454
if frame.framecode.scope isa Method
55-
meth = frame.framecode.scope
56-
argnames = frame.framecode.src.slotnames[2:meth.nargs]
57-
spectypes = Any[Any for i=1:length(argnames)]
58-
print(io, meth.name,'(')
59-
first = true
60-
for (argname, argT) in zip(argnames, spectypes)
61-
first || print(io, ", ")
62-
first = false
63-
print(io, argname)
64-
!(argT === Any) && print(io, "::", argT)
65-
end
66-
path = _print_full_path[] ? meth.file : string(basename(String(meth.file)), ":", meth.line)
67-
path = CodeTracking.replace_buildbot_stdlibpath(String(path))
68-
print(io, ") at ", path)
55+
locdesc(io, frame.framecode)
6956
else
70-
println("not yet implemented")
57+
println(io, "not yet implemented")
7158
end
7259
end
7360
end
61+
62+
function locdesc(io, framecode::FrameCode)
63+
meth = framecode.scope
64+
argnames = framecode.src.slotnames[2:meth.nargs]
65+
spectypes = Any[Any for i=1:length(argnames)]
66+
print(io, meth.name,'(')
67+
first = true
68+
for (argname, argT) in zip(argnames, spectypes)
69+
first || print(io, ", ")
70+
first = false
71+
print(io, argname)
72+
!(argT === Any) && print(io, "::", argT)
73+
end
74+
path = _print_full_path[] ? meth.file : string(basename(String(meth.file)), ":", meth.line)
75+
path = CodeTracking.replace_buildbot_stdlibpath(String(path))
76+
print(io, ") at ", path)
77+
end

src/printing.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ end
55
Base.show(io::IO, x::Suppressed) = print(io, "<suppressed ", x.item, '>')
66

77
function print_var(io::IO, var::JuliaInterpreter.Variable)
8-
print(" | ")
8+
print(io, " | ")
99
T = typeof(var.value)
1010
local val
1111
try

test/ui.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ function my_gcd(a::T, b::T) where T<:Union{Int8,UInt8,Int16,UInt16,Int32,UInt32,
99
k = min(za, zb)
1010
u = unsigned(abs(a >> za))
1111
v = unsigned(abs(b >> zb))
12+
Debugger.@bp
1213
while u != v
1314
if u > v
1415
u, v = v, u
@@ -66,7 +67,8 @@ end
6667
UP_ARROW = "\e[A"
6768

6869
run_terminal_test(@make_frame(my_gcd(10, 20)),
69-
["n\n","`", "a\n", UP_ARROW, UP_ARROW, CTRL_C, EOT],
70+
["n\n","`", "my_gc\t\n", "a\n", UP_ARROW, UP_ARROW, UP_ARROW, CTRL_C,
71+
"bt\n", "st\n", "c\n", "c\n"],
7072
"ui/history_gcd.multiout")
7173

7274
if v"1.1">= VERSION < v"1.2"

0 commit comments

Comments
 (0)