Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix stack pointer retrieval in jl_backtrace_from_here #42585

Merged
merged 29 commits into from
Nov 18, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
2635252
Take pointer after grow
tkf Oct 10, 2021
2990b77
Align stack and instruction pointers
tkf Oct 10, 2021
6ca4eb5
Can we just always (up)cast pointers to UInt64?
tkf Oct 10, 2021
ac3468d
Alternative/proper fix; use WORD_SIZE
tkf Oct 10, 2021
458cb89
Actually allocate nbytes
tkf Oct 11, 2021
7a338ae
Skip closure-based tests on ARM etc.
tkf Oct 11, 2021
4eb674d
Don't use closure
tkf Oct 11, 2021
e4a1edd
Pass a function as Any
tkf Oct 11, 2021
fcae973
Further simplify llvmcall
tkf Oct 11, 2021
a935c7a
Revert "Further simplify llvmcall"
tkf Oct 11, 2021
d284a34
Revert "Pass a function as Any"
tkf Oct 11, 2021
b51e198
Move _reformat_sp to test suite and fix the typos
tkf Oct 13, 2021
24c2aa1
Use llvm.frameaddress
tkf Oct 13, 2021
03e5129
Merge branch 'master' into fix-sp
tkf Oct 14, 2021
4fcda37
Use inferencebarrier to be extra sure
tkf Oct 14, 2021
9270661
Revert "Use inferencebarrier to be extra sure"
tkf Oct 14, 2021
778def1
Revert "Use llvm.frameaddress"
tkf Oct 14, 2021
d0cedca
Merge branch 'master' into fix-sp
tkf Oct 31, 2021
6194475
Use llvm.frameaddress
tkf Oct 13, 2021
0a07e32
Use Int32 as LangRef mentions
tkf Oct 31, 2021
9e80b08
Update test/backtrace.jl
tkf Nov 13, 2021
715c673
Call llvm.frameaddress using Intrinsics.llvmcall
tkf Nov 13, 2021
de860b2
Directly invoke llvmcall in withframeaddress
tkf Nov 13, 2021
e37c0d5
Put back missing `@eval`
tkf Nov 14, 2021
3f8868a
Add dummy frames
tkf Nov 14, 2021
4b6a27f
Revert "Add dummy frames"
tkf Nov 15, 2021
66ff7e9
Check `sp[1] < ptr1`, not `sp[2] < ptr1`
tkf Nov 15, 2021
4c62333
Merge branch 'master' into fix-sp
tkf Nov 16, 2021
df9d96d
Merge branch 'master' into fix-sp
tkf Nov 17, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Move _reformat_sp to test suite and fix the typos
  • Loading branch information
tkf committed Oct 13, 2021
commit b51e1987ef3dcb3aba329011de1e66c07253f693
44 changes: 0 additions & 44 deletions base/error.jl
Original file line number Diff line number Diff line change
Expand Up @@ -99,50 +99,6 @@ function _reformat_bt(bt::Array{Ptr{Cvoid},1}, bt2::Array{Any,1})
ret
end

"""
_reformat_sp(bt_data...) -> sp::Vector{Ptr{Cvoid}}

Convert the output `bt_data` of `jl_backtrace_from_here` with `returnsp` flag set to a
vector of valid stack pointers `sp`; i.e., `sp` is a subset of `bt_data[3]`.

This function is used only in test.
"""
function _reformat_sp(
bt_raw::Array{Ptr{Cvoid},1},
bt2::Array{Any,1},
sp_raw::Array{Ptr{Cvoid},1},
)
bt = _reformat_bt(bt_raw, bt2)
sp = empty!(similar(sp_raw))
i = j = 0
while true
# Advacne `i` such that `bt[i] isa Ptr{Cvoid}` (native poitner).
local ip
while true
if i == lastindex(bt)
return sp
end
i += 1
x = bt[i]
if x isa Ptr{Cvoid}
ip = x
break
end
end
# Advance `j` such that `bt_raw[j] == bt[i]` to find a valid stack pointer.
while true
if j == lastindex(bt_raw)
return sp
end
j += 1
if bt_raw[j] == ip
push!(sp, sp_raw[j])
break
end
end
end
end

"""
backtrace()

Expand Down
46 changes: 45 additions & 1 deletion test/backtrace.jl
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,50 @@ let code = """
@test occursin("InterpreterIP in top-level CodeInfo for Main.A", bt_str)
end

"""
_reformat_sp(bt_data...) -> sp::Vector{Ptr{Cvoid}}

Convert the output `bt_data` of `jl_backtrace_from_here` with `returnsp` flag set to a
vector of valid stack pointers `sp`; i.e., `sp` is a subset of `bt_data[3]`.

See also `Base._reformat_bt`.
"""
function _reformat_sp(
bt_raw::Array{Ptr{Cvoid},1},
bt2::Array{Any,1},
sp_raw::Array{Ptr{Cvoid},1},
)
bt = Base._reformat_bt(bt_raw, bt2)
sp = empty!(similar(sp_raw))
i = j = 0
while true
# Advance `i` such that `bt[i] isa Ptr{Cvoid}` (native pointer).
local ip
while true
if i == lastindex(bt)
return sp
end
i += 1
x = bt[i]
if x isa Ptr{Cvoid}
ip = x
break
end
end
# Advance `j` such that `bt_raw[j] == bt[i]` to find a valid stack pointer.
while true
if j == lastindex(bt_raw)
return sp
end
j += 1
if bt_raw[j] == ip
push!(sp, sp_raw[j])
break
end
end
end
end

"""
withalloca(f, nbytes)

Expand Down Expand Up @@ -321,7 +365,7 @@ end

@testset "stack pointers" begin
ptr1, ptr2, bt_data = sandwiched_backtrace()
sp = Base._reformat_sp(bt_data...)
sp = _reformat_sp(bt_data...)
@test ptr2 < sp[1] < ptr1
tkf marked this conversation as resolved.
Show resolved Hide resolved
@test all(diff(Int128.(UInt.(sp))) .> 0)
end