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

edit and less fail for stdlib functions in distribution binaries #26314

Closed
RalphAS opened this issue Mar 4, 2018 · 14 comments · Fixed by #32763
Closed

edit and less fail for stdlib functions in distribution binaries #26314

RalphAS opened this issue Mar 4, 2018 · 14 comments · Fixed by #32763
Labels
help wanted Indicates that a maintainer wants help on an issue or pull request priority This should be addressed urgently regression Regression in behavior compared to a previous version stdlib Julia's standard library

Comments

@RalphAS
Copy link

RalphAS commented Mar 4, 2018

The trouble is that file names in stdlib methods are (inappropriate) absolute paths:

julia> ml=methods(edit)
# 5 methods for generic function "edit":
[1] edit(path::AbstractString) in InteractiveUtils at 
/buildworker/worker/package_linux64/build/usr/share/julia/site/v0.7/InteractiveUtils/src/editless.jl:37
#etc.

julia> less(edit,(AbstractString,))
/buildworker/worker/package_linux64/build/usr/share/julia/site/v0.7/InteractiveUtils/src/editless.jl: 
No such file or directory

We can cheat:

julia> ml.ms[1].file=Symbol("../site/v0.7/InteractiveUtils/src/editless.jl");
julia> less(edit,(AbstractString,)) # this works

This is troublesome for those of us who want to consult "The Real Documentation" but didn't build from source.

(edited to fit more useful issue title)

@RalphAS RalphAS changed the title File names in stdlib methods are absolute paths edit and less fail for stdlib functions in distribution binaries Jun 2, 2018
@RalphAS
Copy link
Author

RalphAS commented Jun 3, 2018

Note that this problem can be circumvented by locally rebuilding the system image.

@vtjnash vtjnash added regression Regression in behavior compared to a previous version stdlib Julia's standard library labels Aug 28, 2018
@vtjnash
Copy link
Sponsor Member

vtjnash commented Aug 28, 2018

If we want to kill this with a bazooka, see rust-lang/rust#38322 (comment) and -fdebug-prefix-map

@vtjnash vtjnash added the help wanted Indicates that a maintainer wants help on an issue or pull request label Aug 28, 2018
@vtjnash
Copy link
Sponsor Member

vtjnash commented Oct 10, 2018

dup #21921 (probably)

@RalphAS
Copy link
Author

RalphAS commented Oct 12, 2018

The distinction from #21921 is that in out-of-tree builds stdlib gets good file references but base is problematic, whereas in official binary distributions it's the other way around. The file fields for base methods are handled specially, perhaps something similar could be done for stdlib.

@vtjnash vtjnash added the priority This should be addressed urgently label Oct 26, 2018
@carstenbauer

This comment has been minimized.

@carstenbauer
Copy link
Member

Since this has been marked as priority, what are the chances that we'll have correct paths in 1.1.0? Can this be added in 1.1.1? Isn't it technically breaking? In my opinion this is really important and it'd be a shame if we'd had to wait for 4 more month.

@tkf
Copy link
Member

tkf commented Dec 5, 2018

Here is a quick monkey-patch you can do in ~/.julia/config/startup.jl to fix it (originally tkf/InteractiveCodeSearch.jl#3 (comment))

"""
Original `Base.find_source_file`.
"""
function _find_source_file_orig(path::AbstractString)
    (isabspath(path) || isfile(path)) && return path
    base_path = joinpath(Sys.BINDIR::String, Base.DATAROOTDIR, "julia", "base", path)
    return isfile(base_path) ? base_path : nothing
end

function Base.find_source_file(path::AbstractString)
    found = _find_source_file_orig(path)
    if found isa AbstractString && ! isfile(found)
        for m in methods(Pkg.add)
            exfile = try
                String(m.file)
            catch err
                continue
            end
            idx = findlast(joinpath(Base.Filesystem.path_separator,
                                    "share", "julia"), exfile)
            if idx isa Nothing
                continue
            end
            prefix = exfile[1:idx[1]]
            if startswith(path, prefix)
                # e.g., relpath = "share/julia/stdlib/v0.7/..."
                relpath = path[length(prefix)+1:end]
                return joinpath(Base.Sys.BINDIR, "..", relpath)
            end
        end
    end
    return found
end

@carstenbauer
Copy link
Member

@tkf: This doesn't seem to work:

julia> using Statistics

julia> @which mean(rand(3))
mean(A::AbstractArray) in Statistics at C:\cygwin\home\Administrator\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.0\Statistics\src\Statistics.jl:128

@tkf
Copy link
Member

tkf commented Dec 5, 2018

It looks like which does not call find_source_file. My hack probably works only with @less and @edit. Also, not sure if it works in Windows.

staticfloat added a commit to JuliaCI/julia-buildbot that referenced this issue Dec 5, 2018
staticfloat added a commit to JuliaCI/julia-buildbot that referenced this issue Dec 5, 2018
staticfloat added a commit to JuliaCI/julia-buildbot that referenced this issue Dec 5, 2018
staticfloat added a commit to JuliaCI/julia-buildbot that referenced this issue Dec 5, 2018
@vtjnash
Copy link
Sponsor Member

vtjnash commented Dec 5, 2018

Additional notes:

For LLDB, this can be corrected for by running settings set target.source-map /path/to/julia/build /path/to/julia/install. For macOS, this can be automated by creating a small text file with the content described at http://lldb.llvm.org/symbols.html. Otherwise, it would need to be put in a ~/.lldbinit file. On GDB, the equivalent command is set substitute-path /path/to/julia/build /path/to/julia/install and also may be automated by creating a ~/.gdbinit file or /usr/lib/debug/julia.gdb file.

@c42f c42f changed the title edit and less fail for stdlib functions in distribution binaries edit and less fail for stdlib functions in distribution binaries Dec 6, 2018
@oschulz
Copy link
Contributor

oschulz commented Aug 1, 2019

This still seems to be an issue (tried with v1.2-rc2 and v1.3, using the official binaries on 64-bit Linux). I guess this needs more than JuliaDebug/JuliaInterpreter.jl#144 and #31388 ?

Is there a chance to fix this in v1.2 or v1.3? It's possible to work around it (via symlink or so), I usually do, but that's kinda hard to sell that to novice users when introducing them to Julia (and showing them how easy it is to see how things work inside). :-)

@StefanKarpinski
Copy link
Sponsor Member

JuliaInterpreter/Debugger seems to have their own fix for this. Would either of @timholy or @KristofferC possibly know if that fix could be used on base itself?

@carstenbauer
Copy link
Member

kinda hard to sell that to novice users when introducing them to Julia (and showing them how easy it is to see how things work inside)

+1 from me. The possibility to use @which and co. in front of a class to show them how easy it is to inspect Julia internals is typically a "wow" moment. I really hope this gets fixed soon!

@KristofferC
Copy link
Sponsor Member

We could probably use the same trick here. Will try it out and report back.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Indicates that a maintainer wants help on an issue or pull request priority This should be addressed urgently regression Regression in behavior compared to a previous version stdlib Julia's standard library
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants