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

Investigate the possibility of implementing a bridge between GDB and JDI #142

Open
Noisyfox opened this issue Aug 11, 2021 · 12 comments
Open

Comments

@Noisyfox
Copy link
Member

Currently Native-Image can generate debugging information that can be used by GDB:
https://www.graalvm.org/reference-manual/native-image/DebugInfo/

And some common debugging features are supported, including:

  • break points configured by file and line, or by method name
  • single stepping by line including both into and over function calls
  • stack backtraces (not including frames detailing inlined code)
  • printing of primitive values
  • structured (field by field) printing of Java objects
  • casting/printing objects at different levels of generality
  • access through object networks via path expressions
  • reference by name to methods and static field data

If we could create a translator between GDB and JDWP, then we could be able to use a java debugger to debug a native-image executable.

@Noisyfox Noisyfox added this to the 2.0.0 milestone Aug 11, 2021
@Noisyfox Noisyfox self-assigned this Aug 11, 2021
@Noisyfox Noisyfox added this to To do in MOE 2.x Aug 11, 2021
@Noisyfox Noisyfox moved this from To do to In progress in MOE 2.x Aug 11, 2021
@Noisyfox
Copy link
Member Author

Apparently the debug info is not available for LLVM backend.

@Berstanio
Copy link

Berstanio commented Aug 11, 2021

Apparently the debug info is not available for LLVM backend.

What do you mean or where do you take this from? What I saw in the code and what I tested, debug info is included with the llvm backend too. I can attach gdb to a programm, set breakpoints etc.

@Noisyfox
Copy link
Member Author

Noisyfox commented Aug 13, 2021

Apparently the debug info is not available for LLVM backend.

What do you mean or where do you take this from? What I saw in the code and what I tested, debug info is included with the llvm backend too. I can attach gdb to a programm, set breakpoints etc.

But there is no debug information about the original Java code, e.g., the file path, line numbers etc.

@Berstanio
Copy link

Berstanio commented Aug 13, 2021

//EDIT
Oh I found a mistake. I was just lucky that I got a example test case where this was working good. With another test with another programm it seems that the debug info is pretty buggy. But this should be something that can be fixed with the llvm backend because it is as I think just a bug. So some parts of my first response are outdated.
//EDIT END

But there is no debug information about the original Java code, e.g., the file path, line numbers etc.

Yes, the original source code files is just put into a "sources" folder. But this is also true for non llvm-backend. But line numbers and file path, method names etc. are saved. e.g. I can run "break de/berstanio/x/x.java:50" and it works without the "sources" folder or any other source files. And why should we need the original source code included anyway? We would see the source code over e.g. Android Studio. And in GDB the original source code is just used to print the source code line afaik.

@Noisyfox
Copy link
Member Author

I can run "break de/berstanio/x/x.java:50" and it works without the "sources" folder or any other source files.

Are you sure this works for LLVM backend?

@Berstanio
Copy link

Berstanio commented Aug 13, 2021

Yes but it only works partially as I know found out. What I missed on my testing was that I just tested to set the breakpoint on the first instruction on the method which is working on the llvm backend (I later thought that the other breakpoints weren't working were just a bug). But the other debug infos are gathered over the "sourceMapping" field in the CompilationResult class. And here only the standard "CompilationsResultBuilder" puts in informations, currently not the llvm backend. Therefor setting the breakpoint on the first instruction of the method works, on other places sadly currently not.

@Noisyfox
Copy link
Member Author

Are you able to set breakpoint based on the file and line number?

@Berstanio
Copy link

Yes, but only for the first line of a method.

@Berstanio
Copy link

Berstanio commented Aug 13, 2021

Btw. I now looked deeper in the code and I'm pretty confident that implementing the complete debbuging feature to the llvm backend should be quite simple.
How wrong I was, type info emition is way more complicated than I thought.

@Berstanio
Copy link

Berstanio commented Jun 20, 2022

In case you haven't seen it already:
https://blog.jetbrains.com/idea/2022/06/intellij-idea-2022-2-eap-5/
https://plugins.jetbrains.com/plugin/19237-graalvm-native-debugger
"Experimental GraalVM Native Debugger for Java"
Looks interesting @Noisyfox !

@Berstanio
Copy link

Berstanio commented Oct 10, 2022

It seems that the llvm debugging is pushed forward by oracle/graal#4964
It is currently function wise at the same level as my WIP

@Berstanio
Copy link

Seems graal native-image team is working on something like that themselves now: oracle/graal#5648

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: In progress
MOE 2.x
In progress
Development

No branches or pull requests

2 participants