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

Debug the Java Sieve Project as native-image. #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

JaroslavTulach
Copy link
Collaborator

@JaroslavTulach JaroslavTulach commented Apr 8, 2021

Since d9a30a9 we are able to build and execute the generated sieve native executable:
obrazek
Make sure the project is set to use GraalVM 20.3 with native-image exectable installed and that you select the native-image configuration in the toolbar choicebox.

After Build, or Clean and Build select Run and the native executable is going to be properly executed:
obrazek

The question for the pull request is: Can we also get Debug working?

CCing @sdedic & @entlicher & @jlahoda

@JaroslavTulach
Copy link
Collaborator Author

Right now (with 4ffdc70) invoking Debug Project results in

cd /home/devel/NetBeansProjects/sieve/java/algorithm; JAVA_HOME=/home/devel/bin/jdk-8 /home/devel/NetBeansProjects/netbeans/nbbuild/netbeans/java/maven/bin/mvn -Dexec.vmArgs= -Dexec.appArgs= -Pnative-image,native-image exec:exec@debug
Scanning for projects...

-----------------< org.apidesign.demo:sieve-algorithm >-----------------
Building Sieve Implementation 1.0-SNAPSHOT
-------------------------------[ bundle ]-------------------------------

--- exec-maven-plugin:1.6.0:exec (debug) @ sieve-algorithm ---
=thread-group-added,id="i1"
~"GNU gdb (Debian 10.1-2) 10.1.90.20210103-git\n"
~"Copyright (C) 2021 Free Software Foundation, Inc.\n"
~"License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\nThis is free software: you are free to change and redistribute it.\nThere is NO WARRANTY, to the extent permitted by law."
~"\nType \"show copying\" and \"show warranty\" for details.\n"
~"This GDB was configured as \"x86_64-linux-gnu\".\n"
~"Type \"show configuration\" for configuration details.\n"
~"For bug reporting instructions, please see:\n"
~"<https://www.gnu.org/software/gdb/bugs/>.\n"
~"Find the GDB manual and other documentation resources online at:\n    <http://www.gnu.org/software/gdb/documentation/>."
~"\n\n"
~"For help, type \"help\".\n"
~"Type \"apropos word\" to search for commands related to \"word\"...\n"
&"\nwarning: "
&"/home/devel/NetBeansProjects/ttrace/zipkin/graal-enterprise/substratevm-enterprise/svmhelpers.py: Adresá�\231 nebo soubor neexistuje\n"
~"Reading symbols from /home/devel/NetBeansProjects/sieve/java/algorithm/target/sieve...\n"
~"Reading symbols from /home/devel/NetBeansProjects/sieve/java/algorithm/target/sieve.debug...\n"
&"warning: Unsupported auto-load script at offset 0 in section .debug_gdb_scripts\nof file "
&"/home/devel/NetBeansProjects/sieve/java/algorithm/target/sieve.debug.\nUse `info auto-load "
&"python-scripts [REGEXP]' to list them.\n"
(gdb) 

that's not fully correct. @entlicher how do you want to establish connection between gdb and the IDE? Is socket the option?

@JaroslavTulach
Copy link
Collaborator Author

I am able to connect Java to gdb with the help of socat:

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

import org.newsclub.net.unix.AFUNIXServerSocket;
import org.newsclub.net.unix.AFUNIXSocketAddress;

public final class SimpleTestServer {
    public static void main(String[] args) throws IOException {
        final File socketFile = new File(new File(System.getProperty("java.io.tmpdir")), "gdb.sock");
        try (AFUNIXServerSocket server = AFUNIXServerSocket.newInstance()) {
            server.bind(new AFUNIXSocketAddress(socketFile));
            System.out.println("Server is waiting for connection: " + server);
            try (Socket sock = server.accept()) {
                try (InputStream is = sock.getInputStream(); //
                    OutputStream os = sock.getOutputStream()) {
                    os.write("run".getBytes("UTF-8"));
                    os.flush();
                }
            }
        }
    }
}

and then the Java part can send run command to

$ socat /tmp/gdb.sock - | gdb target/sieve

However I am not able to achieve the same without socat utility yet.

@jtulach jtulach force-pushed the master branch 2 times, most recently from 736a251 to d2e9fc8 Compare April 25, 2022 09:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant