Skip to content

Commit

Permalink
Revert API breaking name change lookupat->lookup from #33190
Browse files Browse the repository at this point in the history
With return->call address tanslation done inside jl_unw_stepn, there
should largely be no need to make this API breaking change, as all
backtrace addresses which the user has access to will already be
translated and can be passed directly into `StackTraces.lookup()`, as
was done previously.

There's one possible exception to this rule: If the user were looking up
the debug info for a pointer to a C function *not* obtained from a
backtrace, they previously would have had to use
`StackTraces.lookup(ptr+1)` to "undo" the the `ptr-1` translation that
`StackTraces.lookup` used to perform prior to #33190.  This seems like
an edge case however and probably not worth breaking the API over.
  • Loading branch information
c42f committed Sep 25, 2019
1 parent 6bc2065 commit 8ba936f
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 29 deletions.
2 changes: 1 addition & 1 deletion base/client.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ end

# deprecated function--preserved for DocTests.jl
function ip_matches_func(ip, func::Symbol)
for fr in StackTraces.lookupat(ip)
for fr in StackTraces.lookup(ip)
if fr === StackTraces.UNKNOWN || fr.from_c
return false
end
Expand Down
2 changes: 1 addition & 1 deletion base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ function firstcaller(bt::Vector, funcsyms)
# Identify the calling line
found = false
for ip in bt
lkups = StackTraces.lookupat(ip)
lkups = StackTraces.lookup(ip)
for lkup in lkups
if lkup == StackTraces.UNKNOWN || lkup.from_c
continue
Expand Down
2 changes: 1 addition & 1 deletion base/errorshow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ function process_backtrace(t::Vector, limit::Int=typemax(Int); skipC = true)
if lkups isa StackFrame
lkups = [lkups]
else
lkups = StackTraces.lookupat(lkups)
lkups = StackTraces.lookup(lkups)
end
for lkup in lkups
if lkup === StackTraces.UNKNOWN
Expand Down
10 changes: 5 additions & 5 deletions base/stacktraces.jl
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ An alias for `Vector{StackFrame}` provided for convenience; returned by calls to
const StackTrace = Vector{StackFrame}

const empty_sym = Symbol("")
const UNKNOWN = StackFrame(empty_sym, empty_sym, -1, nothing, true, false, 0) # === lookupat(C_NULL)
const UNKNOWN = StackFrame(empty_sym, empty_sym, -1, nothing, true, false, 0) # === lookup(C_NULL)


#=
Expand All @@ -96,13 +96,13 @@ end


"""
lookupat(pointer::Ptr{Cvoid}) -> Vector{StackFrame}
lookup(pointer::Ptr{Cvoid}) -> Vector{StackFrame}
Given a pointer to an execution context (usually generated by a call to `backtrace`), looks
up stack frame context information. Returns an array of frame information for all functions
inlined at that point, innermost function first.
"""
function lookupat(pointer::Ptr{Cvoid})
function lookup(pointer::Ptr{Cvoid})
infos = ccall(:jl_lookup_code_address, Any, (Ptr{Cvoid}, Cint), pointer, false)
pointer = convert(UInt64, pointer)
isempty(infos) && return [StackFrame(empty_sym, empty_sym, -1, nothing, true, false, pointer)] # this is equal to UNKNOWN
Expand All @@ -117,7 +117,7 @@ end

const top_level_scope_sym = Symbol("top-level scope")

function lookupat(ip::Base.InterpreterIP)
function lookup(ip::Base.InterpreterIP)
if ip.code isa Core.MethodInstance && ip.code.def isa Method
codeinfo = ip.code.uninferred
func = ip.code.def.name
Expand Down Expand Up @@ -188,7 +188,7 @@ trace, `stacktrace` first calls `backtrace`.
function stacktrace(trace::Vector{<:Union{Base.InterpreterIP,Ptr{Cvoid}}}, c_funcs::Bool=false)
stack = StackTrace()
for ip in trace
for frame in lookupat(ip)
for frame in lookup(ip)
# Skip frames that come from C calls.
if c_funcs || !frame.from_c
push!(stack, frame)
Expand Down
4 changes: 2 additions & 2 deletions doc/src/base/stacktraces.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ Base.StackTraces.stacktrace
```

The following methods and types in `Base.StackTraces` are not exported and need to be called e.g.
as `StackTraces.lookupat(ptr)`.
as `StackTraces.lookup(ptr)`.

```@docs
Base.StackTraces.lookupat
Base.StackTraces.lookup
Base.StackTraces.remove_frames!
```
4 changes: 2 additions & 2 deletions doc/src/manual/stacktraces.md
Original file line number Diff line number Diff line change
Expand Up @@ -300,12 +300,12 @@ julia> stacktrace(trace, true)
```

Individual pointers returned by [`backtrace`](@ref) can be translated into [`StackTraces.StackFrame`](@ref)
s by passing them into [`StackTraces.lookupat`](@ref):
s by passing them into [`StackTraces.lookup`](@ref):

```julia-repl
julia> pointer = backtrace()[1];
julia> frame = StackTraces.lookupat(pointer)
julia> frame = StackTraces.lookup(pointer)
1-element Array{Base.StackTraces.StackFrame,1}:
jl_apply_generic at gf.c:2167
Expand Down
5 changes: 2 additions & 3 deletions stdlib/Profile/src/Profile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ Profiling support, main entry point is the [`@profile`](@ref) macro.
"""
module Profile

import Base.StackTraces: lookupat, UNKNOWN, show_spec_linfo, StackFrame
import Base.StackTraces: lookup, UNKNOWN, show_spec_linfo, StackFrame

# deprecated functions: use `getdict` instead
lookup(ip::UInt) = lookupat(convert(Ptr{Cvoid}, ip))
lookup(ip::Ptr{Cvoid}) = lookupat(ip)
lookup(ip::UInt) = lookup(convert(Ptr{Cvoid}, ip))

export @profile

Expand Down
2 changes: 1 addition & 1 deletion stdlib/Test/src/Test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const DISPLAY_FAILED = (

# Backtrace utility functions
function ip_has_file_and_func(ip, file, funcs)
return any(fr -> (string(fr.file) == file && fr.func in funcs), StackTraces.lookupat(ip))
return any(fr -> (string(fr.file) == file && fr.func in funcs), StackTraces.lookup(ip))
end

function scrub_backtrace(bt)
Expand Down
18 changes: 9 additions & 9 deletions test/backtrace.jl
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license

import Base.StackTraces: lookupat
import Base.StackTraces: lookup

# Test location information for inlined code (ref issues #1334 #12544)
module test_inline_bt
using Test
import ..lookupat
import ..lookup

function get_bt_frames(functionname, bt)
for i = 1:length(bt)
lkup = lookupat(bt[i])
lkup = lookup(bt[i])
lkup[end].func == functionname && return lkup
end
return StackTraces.StackFrame[]
Expand Down Expand Up @@ -96,13 +96,13 @@ end

module BackTraceTesting
using Test
import ..lookupat
import ..lookup

@inline bt2() = backtrace()
@inline bt1() = bt2()
bt() = bt1()

lkup = map(lookupat, bt())
lkup = map(lookup, bt())
hasbt = hasbt2 = false
for sfs in lkup
for sf in sfs
Expand All @@ -121,7 +121,7 @@ function btmacro()
ret = @timed backtrace()
ret[1]
end
lkup = map(lookupat, btmacro())
lkup = map(lookup, btmacro())
hasme = hasbtmacro = false
for sfs in lkup
for sf in sfs
Expand All @@ -146,7 +146,7 @@ bt = eval(quote
catch_backtrace()
end
end)
lkup = map(lookupat, bt)
lkup = map(lookup, bt)
hastoplevel = false
for sfs in lkup
for sf in sfs
Expand Down Expand Up @@ -174,7 +174,7 @@ let bt, found = false
@testset begin
bt = backtrace()
end
for frame in map(lookupat, bt)
for frame in map(lookup, bt)
if frame[1].line == @__LINE__() - 3 && frame[1].file == Symbol(@__FILE__)
found = true; break
end
Expand All @@ -186,7 +186,7 @@ end
let bt, found = false
@info ""
bt = backtrace()
for frame in map(lookupat, bt)
for frame in map(lookup, bt)
if frame[1].line == @__LINE__() - 2 && frame[1].file == Symbol(@__FILE__)
found = true; break
end
Expand Down
2 changes: 1 addition & 1 deletion test/compiler/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -894,7 +894,7 @@ function break_21369()
i = 1
local fr
while true
fr = Base.StackTraces.lookupat(bt[i])[end]
fr = Base.StackTraces.lookup(bt[i])[end]
if !fr.from_c && fr.func !== :error
break
end
Expand Down
2 changes: 1 addition & 1 deletion test/meta.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ h_noinlined() = g_noinlined()

function foundfunc(bt, funcname)
for b in bt
for lkup in StackTraces.lookupat(b)
for lkup in StackTraces.lookup(b)
if lkup.func == funcname
return true
end
Expand Down
4 changes: 2 additions & 2 deletions test/stacktraces.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ let (default, with_c, without_c) = (stacktrace(), stacktrace(true), stacktrace(f
@test isempty(filter(frame -> frame.from_c, without_c))
end

@test StackTraces.lookupat(C_NULL) == [StackTraces.UNKNOWN] == StackTraces.lookupat(C_NULL + 1) == StackTraces.lookupat(C_NULL - 1)
@test StackTraces.lookup(C_NULL) == [StackTraces.UNKNOWN] == StackTraces.lookup(C_NULL + 1) == StackTraces.lookup(C_NULL - 1)

let ct = current_task()
# After a task switch, there should be nothing in catch_backtrace
Expand Down Expand Up @@ -118,7 +118,7 @@ let li = typeof(fieldtype).name.mt.cache.func::Core.MethodInstance,
end

let ctestptr = cglobal((:ctest, "libccalltest")),
ctest = StackTraces.lookupat(ctestptr)
ctest = StackTraces.lookup(ctestptr)

@test length(ctest) == 1
@test ctest[1].func === :ctest
Expand Down

0 comments on commit 8ba936f

Please sign in to comment.