-
Notifications
You must be signed in to change notification settings - Fork 13
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
Printing program context #37
Comments
I would definitely like to add it. The question is how :) |
Great! I've done some poking around with the augmented AST and I've found all the information we need to reconstruct the code. There is one issue though in that we only have the AST for the source lines that the I think it is possible to write a |
You can traverse down the tree already - see |
As you can see in my updated post above I figured out how to move down the tree. I think refactoring that code would be very useful. I'll hold off on doing anything until you've done that, as anything I do now will be a hack. I don't think this will be too hard to incorporate and will make julia debugging incredibly easier. Thanks. |
I've looked at the AST printing code in show.jl and it doesn't seem like it would be too hard to adapt it to work with the augmented AST. Adding the ability to only print lines in a certain range also seems straightforward (maybe a bit tedious though). Let me know what your plans are with the show.jl printing code and I'll be happy to start hacking away on the augmented AST version. |
I noticed that if you put a I'm thinking that a The I'm not sure how well this will play with modules, but one could always just debug a module as a bunch of functions and wrap the result in a module. I'm going to play with this a bit as I would like to switch to julia for my research code after my current project and having this kind of debugging functionality is what I need. Any feedback or advice is greatly appreciated though. Thanks. |
Sorry for the silence. I've been starting to look at refactoring the pretty printing code, but I'm not able to amass very much time for this project right now. Looking at the implementation of It might not be so hard write a |
No problem, I just had some free cycles and ran into a large enough problem with python yesterday that would have been trivial with julia that I wanted to think about this a bit more. No rush on refactoring either. I agree, there are problems with the Looking at debuggers for LLVM languages it seems like LLVM has some debugging features, like being able to tell you what lines in a source file an instruction corresponds to. The core guys may need to expose some low-level parts of the language in order for a source level debugger to be created. To be honest, at some point a larger discussion needs to probably happen with Jeff, Stefan, and the rest of the community about how to build a source level debugger. I think what you have created here is great, but I think something as full featured as gdb, pdb or the Matlab debugger will require some low-level integration into the language. Given that people seem to be writing more complex programs with julia this may need to happen sooner than later. Anyways, you bring up some excellent points regarding macros. Macros are probably better debugged in a LISP-like manner, where Debug.jl is already very good and just printing the AST will work. However, more data analysis-type code that probably uses fewer macros may be better served by a source level debugger. |
Thinking about this some more, I have come round to that printing verbatim source lines is actually a good idea. User commands are processed in the function |
Great, I think that the strategy you outlined of opening the file and printing some lines will be a good first pass at this. It seems like a lot of nodes in the decorated AST don't have a file associated with them even though the corresponding node in the AST does. It would be helpful if the file information made it through to the decorated AST for these cases. Additionally, all nodes that are trapped during debugging should probably have a corresponding file and line number, we should always know where the code we're trapped at is (unless it's like a ccall). I tried to figure out why the file information wasn't making it through for all nodes in the AST but haven't figured it out yet. Thanks. Just for reference, I've been putting the following code in a text file to use for testing: using Debug
@debug begin
function f(x,y)
w = x*y
g(y)
end
function g(y)
t = 0.
for i in 1:5
t += i*pi
end
return t
end
@bp
println(f(2,3))
println(f(1,1))
println(f(2,2))
end |
Sorry, I forgot to tell you that Julia only inserts source file info for functions right now. Does it work if you single step through a function? The current approach is intended to take the source file info from line nodes in I could probably add a step that assigns the source file that a function is defined in to the surrounding top level code. And yes, you need to |
I have a preliminary version of printing program context while debugging in the The code to check out is in UI.jl. I added a Unfortunately, context is only printed for nodes that have a valid file, which as you say are only lines in functions. As you can see in the test code above, I wrap everything in a Is adding file information to other nodes in the tree something that can be done in the Debug package, or is it something that needs to be added to the julia parser. I actually just did a simple find-and-replace in the parser to always add a I also added a |
I looked a little bit at your branch, it looks good by what I could tell. It would be nice to print an error message when the file could not be opened though, like I checked, and it seems to me that breakpoint nodes do get a file, if they're inside a function. It's an easy change to not stop at breakpoint nodes, but that would make it much harder to use the ignore breakpoint feature right now. There should really be convenient ways to navigate the augmented AST, so that you can e.g. disable a breakpoint even if you are not standing on it. Then I think that it would make more sense not to stop at them. Regarding more file info, I definitely think that the best solution would be if the julia parser could include it from the beginning. The only thing I can do in the Also, have you been editing your posts after you submitted them? I usually read my github notifications in my email, but when I came here, there seemed to be parts that I hadn't read. |
Sounds good. I'll clean up my code a bit and submit a pull request. I'll Yes, I have been editing my posts. Not sure why I thought they'd get On Tue, Mar 5, 2013 at 2:46 PM, toivoh [email protected] wrote:
|
Sounds great! |
I think that we can close this now that #40 is merged. |
I'm wondering if it would be possible to print program context while debugging like in pdb and adding an "l" (lowercase L) command to print some program lines around the current line.
I played around a bit and see that the AST is available so some program context could potentially be displayed. However, it would be really useful if the raw code could be attached before the julia parser converted it to the AST.
This would make debugging much easier when one doesn't have a text editor open.
If this is something you'd like to add I'd be happy to help.
The text was updated successfully, but these errors were encountered: