From 90c177a1cbd640dd56e20de1f3d540442ceac22b Mon Sep 17 00:00:00 2001 From: Olya Gupalo Date: Mon, 16 Dec 2024 13:45:16 +0200 Subject: [PATCH 1/2] Review and move javagdbnative demo to archive --- archive/javagdbnative/README.MD | 27 ++++++++++ .../javagdbnative}/pom.xml | 9 ++-- .../src/main/java/javagdb/App.java | 0 javagdbnative/README.MD | 50 ------------------- 4 files changed, 30 insertions(+), 56 deletions(-) create mode 100644 archive/javagdbnative/README.MD rename {javagdbnative => archive/javagdbnative}/pom.xml (89%) rename {javagdbnative => archive/javagdbnative}/src/main/java/javagdb/App.java (100%) delete mode 100644 javagdbnative/README.MD diff --git a/archive/javagdbnative/README.MD b/archive/javagdbnative/README.MD new file mode 100644 index 000000000..6d4c47166 --- /dev/null +++ b/archive/javagdbnative/README.MD @@ -0,0 +1,27 @@ +# Native Image Debugging from Java Source Code + +This demo is intended to demonstrate how to debug a Java application, built into a native executable, using the [Debug Info Feature in Native Image](https://www.graalvm.org/latest/reference-manual/native-image/debugging-and-diagnostics/DebugInfo/). + +> Prerequisites: Linux OS with 10.2 or later + +## Build a Native Executable with Debug Information + +1. Clone Download or clone the GraalVM Demos repository: + ```bash + git clone https://github.com/graalvm/graalvm-demos + ``` + +2. Navigate to the example directory: + ```bash + cd graalvm-demos/archive/javagdbnative + ``` + +3. Compile and build the application with Maven: + ```shell + mvn -Pnative -DskipTests package + ``` + The command packages a Java application into a runnable JAR file, and then builds a native executable of it. + The `-g` option that is passed to the `native-image` tool in _pom.xml_ causes debug information to be generated. + Next to the native executable, you see the _.debug_ file that contains debug information, and the _sources_ directory containing Java source files, which the debugger uses to show sources for line information. + +Now you can debug your native executable with GDB as shown in [this guide](https://www.graalvm.org/latest/reference-manual/native-image/guides/debug-native-image-process/). \ No newline at end of file diff --git a/javagdbnative/pom.xml b/archive/javagdbnative/pom.xml similarity index 89% rename from javagdbnative/pom.xml rename to archive/javagdbnative/pom.xml index 0683895b6..f12ead876 100644 --- a/javagdbnative/pom.xml +++ b/archive/javagdbnative/pom.xml @@ -9,8 +9,6 @@ 1.0-SNAPSHOT javagdbnative - - https://github.com/graalvm/graalvm-demos UTF-8 @@ -36,7 +34,7 @@ org.graalvm.buildtools native-maven-plugin - 0.9.7 + 0.10.4 test-native @@ -57,8 +55,7 @@ javagdb javagdb.App - --no-fallback - --verbose + --verbose -g -O0 @@ -67,5 +64,5 @@ - + diff --git a/javagdbnative/src/main/java/javagdb/App.java b/archive/javagdbnative/src/main/java/javagdb/App.java similarity index 100% rename from javagdbnative/src/main/java/javagdb/App.java rename to archive/javagdbnative/src/main/java/javagdb/App.java diff --git a/javagdbnative/README.MD b/javagdbnative/README.MD deleted file mode 100644 index c06b3ec67..000000000 --- a/javagdbnative/README.MD +++ /dev/null @@ -1,50 +0,0 @@ -# Native Image Debugging from Java Source Code - -This demo is intended to be used to demonstrate how to debug a Java application, built into a native executable, using the [GraalVM Tools for Java extension for Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=oracle-labs-graalvm.graalvm). - ->Note: The extension is no longer in active development and is in maintenance mode. The latest version of the documentation that includes the GraalVM Tools for Java extension support is [GraalVM for JDK 17 (23.0.0)](https://www.graalvm.org/jdk17/tools/vscode/graalvm-extension/). - -## Prerequisites - -1. Linux OS with GDB 10.1 -2. Visual Studio Code -3. [GraalVM Tools for Java](https://marketplace.visualstudio.com/items?itemName=oracle-labs-graalvm.graalvm): Open Visual Studio Code, navigate to Extensions activity panel in the left-hand side Activity Bar (or use the Ctrl+Shift+X hot keys combination). Search for “GraalVM” in the search field. Find "GraalVM Tools for Java", press Install. Reload will be required. -4. [GraalVM runtime environment in VS Code](https://www.graalvm.org/jdk17/tools/vscode/graalvm-extension/#set-default-java-runtime): Navigate to Gr activity panel in VS Code and install some of the latest GraalVM __Enterprise Edition__ versions available from the list. -5. [Native Image](https://www.graalvm.org/jdk17/tools/vscode/graalvm-extension/#native-image-support): Upon GraalVM's installation completion, the “Install Optional GraalVM Components” window pops up in the right bottom corner. Install Native Image. - -## Building the Sample - -1. Clone Download or clone the GraalVM Demos repository: - ```bash - git clone https://github.com/graalvm/graalvm-demos - ``` - -2. Open the demo folder, _graalvm/demos/javagdbnative_, in VS Code. - -3. Open VS Code Terminal window and run following command: - ```shell - mvn -Pnative -DskipTests package - ``` - -The `mvn -Pnative -DskipTests package` command will package a Java application into a runnable JAR file, and then build a native executable of it. - -## Debugging the Sample - -1. Select Run and Debug activity panel in VSCode -2. Add a new launch configuration named **Native Image: launch** into launch.json which should look like this: - ```json - { - "type": "nativeimage", - "request": "launch", - "name": "Launch Native Image", - "nativeImagePath": "${workspaceFolder}/target/javagdb", - "args": "100" - } - ``` -3. Then run debugger using **Launch Native Image** from **RUN...** menu. It will start debugging a native image binary in VSCode using Java source code. - - -### References - -- [GraalVM Tools for Java](https://www.graalvm.org/jdk17/tools/vscode/graalvm-extension/) -- [Native Image Debug Info Feature](https://www.graalvm.org/jdk17/reference-manual/native-image/debugging-and-diagnostics/DebugInfo/) \ No newline at end of file From f9b9ebbbfb4b23c40781285ba919d52aa58dd7db Mon Sep 17 00:00:00 2001 From: Olya Gupalo Date: Mon, 16 Dec 2024 13:53:20 +0200 Subject: [PATCH 2/2] Update CI workflow to not run montly; Remove javagdbnative entry from top-level README --- ...dbnative.yml => archive-javagdbnative.yml} | 23 ++++++++----------- README.md | 4 ---- archive/javagdbnative/pom.xml | 4 ++-- 3 files changed, 11 insertions(+), 20 deletions(-) rename .github/workflows/{javagdbnative.yml => archive-javagdbnative.yml} (55%) diff --git a/.github/workflows/javagdbnative.yml b/.github/workflows/archive-javagdbnative.yml similarity index 55% rename from .github/workflows/javagdbnative.yml rename to .github/workflows/archive-javagdbnative.yml index dd1a52e17..6a619fbd4 100644 --- a/.github/workflows/javagdbnative.yml +++ b/.github/workflows/archive-javagdbnative.yml @@ -1,37 +1,32 @@ -name: javagdbnative +name: archive/javagdbnative on: push: paths: - - 'javagdbnative/**' - - '.github/workflows/javagdbnative.yml' + - 'archive/javagdbnative/**' + - '.github/workflows/archive-javagdbnative.yml' pull_request: paths: - - 'javagdbnative/**' - - '.github/workflows/javagdbnative.yml' - schedule: - - cron: "0 0 1 * *" # run every month + - 'archive/javagdbnative/**' + - '.github/workflows/archive-javagdbnative.yml' workflow_dispatch: permissions: contents: read jobs: run: - name: Run 'javagdbnative' + name: Run 'archive/javagdbnative' runs-on: ubuntu-latest timeout-minutes: 15 - strategy: - matrix: - java-version: ['17', 'dev'] steps: - uses: actions/checkout@v4 - uses: graalvm/setup-graalvm@v1 with: - java-version: ${{ matrix.java-version }} + java-version: '21' distribution: 'graalvm' github-token: ${{ secrets.GITHUB_TOKEN }} cache: 'maven' native-image-job-reports: 'true' - - name: Run 'javagdbnative' + - name: Run 'archive/javagdbnative' run: | - cd javagdbnative + cd archive/javagdbnative mvn -Pnative -DskipTests --no-transfer-progress package ./target/javagdb diff --git a/README.md b/README.md index 73157cf45..e37cb960f 100644 --- a/README.md +++ b/README.md @@ -59,10 +59,6 @@ cd graalvm-demos native-netty-plot
native-netty-plot A web server application, using the Netty framework, to demonstrate the use of isolates with Native Image
Technologies: Native Image, Maven, Netty
Reference: Instant Netty Startup using GraalVM Native Image Generation - - javagdbnative
javagdbnative - Demonstrates how to debug a Java application, built into a native executable in VS Code
Technologies: Native Image, Maven, GraalVM Tools for Java
Reference: Native Image Debugging in VS Code - native-image/add-logging
add-logging Demonstrates how to initialize Loggers with Native Image at the executable build or run time
Technologies: Native Image
Reference: Add Logging to a Native Executable diff --git a/archive/javagdbnative/pom.xml b/archive/javagdbnative/pom.xml index f12ead876..dc5286421 100644 --- a/archive/javagdbnative/pom.xml +++ b/archive/javagdbnative/pom.xml @@ -12,8 +12,8 @@ UTF-8 - 1.8 - 1.8 + 21 + 21