Debug.jl icon indicating copy to clipboard operation
Debug.jl copied to clipboard

Debug macro makes function disappear inside an iprofile block

Open mattcbro opened this issue 10 years ago • 6 comments

Consider the following code in badprofile.jl

using IProfile
using Debug

@iprofile begin

# add the debug macro makes the function disappear if inside an iprofile block
@debug function imgone()
    print("I'm Here\n")
    @bp
end

end

Observe what happens if you try to use this code. julia> require("badprofile")

julia> imgone() ERROR: imgone not defined

julia>

Now suppose I remove the @debug macro from imgone. I then get the correct behavior julia> require("badprofile")

julia> imgone() I'm Here

There is some kind of nasty interaction between these macros in the two packages. Now it may be unreasonable to do debugging inside a profiling block, however one is supposed to be able to turn the profiler off without messing with the iprofile begin and end block.

Not sure if this is a debug problem or iprofile problem or both. This is not a show stopper by any means, but if it's intended behavior perhaps it should be documented or something.

mattcbro avatar Sep 14 '15 04:09 mattcbro

Sorry forgot to mention that I'm using Julia 0.3.11 on x86_64-linux-gnu.

mattcbro avatar Sep 14 '15 04:09 mattcbro

Indeed, it seems like a nasty interaction. As far as I can tell, the only thing that @debug will do with the function is to wrap it in an esc() and a few begin blocks. But maybe it won't even get that far. @timholy: Do you remember what @iprofile will do when it encounters a macro invocation? Or an esc expression?

toivoh avatar Sep 15 '15 18:09 toivoh

It's been so long since I've thought about IProfile, I don't remember much of anything about it.

In these situations, macroexpand is your friend for anyone who feels like digging into this.

timholy avatar Sep 15 '15 20:09 timholy

There are a few other interactions with debug that I've wondered about along similiar lines. I notice issues when putting breakpoints in functions that are called through pmap or @parallel and so forth.

I think the REPL breaks down with IO on separate threads. For similar reasons debug doesn't seem to work inside IJulia.

As for Iprofile, I kind of like how it works. It's easier to understand for me.

mattcbro avatar Sep 17 '15 02:09 mattcbro

Yes, anyone who'd like to, please feel free to dig into this! I don't think I will be able to prioritize it myself.

toivoh avatar Sep 24 '15 14:09 toivoh

@mattcbro: That's a few issues in one message :) Regarding parellel execution: The instrumentation that Debug creates was never designed to work with code that could be sent to and executed in another process (or thread for that matter). My recommendation would be to wrap any code that might run anywhere else than the current thread with @notrap, see #71.

The IO trouble seems to be inherited from Julia's readline(). If that get fixed then it should get fixed for Debug too. See #52.

toivoh avatar Sep 24 '15 14:09 toivoh