Skip to content

Commit d50b928

Browse files
committed
fix debugging for opt 27+
1 parent 65a0123 commit d50b928

File tree

12 files changed

+86
-4
lines changed

12 files changed

+86
-4
lines changed
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/bin/bash
2+
#
3+
# Script to compile Erlang debugger beam files with a specific SDK
4+
# and store them in a specified directory.
5+
#
6+
# Usage:
7+
# ./compile_with_sdk.sh <erlang_path> <output_directory>
8+
#
9+
# Example:
10+
# ./compile_with_sdk.sh /opt/homebrew/opt/erlang@26/bin/erlc beams/otp_pre_27
11+
# ./compile_with_sdk.sh /opt/homebrew/Cellar/erlang/27.2.4/bin/erlc beams/otp_27_plus
12+
#
13+
14+
set -e
15+
16+
# Check arguments
17+
if [ "$#" -lt 2 ]; then
18+
echo "Usage: $0 <erlang_path> <output_directory>"
19+
echo "Example: $0 /opt/homebrew/opt/erlang@26/bin/erlc beams/otp_pre_27"
20+
exit 1
21+
fi
22+
23+
ERLC_PATH="$1"
24+
OUTPUT_DIR="$2"
25+
26+
# Validate erlc path
27+
if [ ! -f "$ERLC_PATH" ]; then
28+
echo "Error: Erlang compiler not found at $ERLC_PATH"
29+
exit 1
30+
fi
31+
32+
# Get script directory
33+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
34+
35+
# If output directory is relative, make it relative to SCRIPT_DIR
36+
if [[ "$OUTPUT_DIR" != /* ]]; then
37+
OUTPUT_DIR="$SCRIPT_DIR/../$OUTPUT_DIR"
38+
fi
39+
40+
# Files to compile
41+
ERL_FILES=("debugnode.erl" "remote_debugger.erl" "remote_debugger_listener.erl" "remote_debugger_notifier.erl")
42+
43+
# Ensure output directory exists
44+
mkdir -p "$OUTPUT_DIR"
45+
46+
# Detect Erlang version
47+
ERLANG_VERSION=$("${ERLC_PATH%erlc}erl" -version 2>&1 || echo "Unknown")
48+
echo "Using Erlang version: $ERLANG_VERSION"
49+
echo "Compiler path: $ERLC_PATH"
50+
echo "Output directory: $OUTPUT_DIR"
51+
52+
# Compile the files
53+
echo "Compiling Erlang files..."
54+
cd "$SCRIPT_DIR"
55+
$ERLC_PATH -o "$OUTPUT_DIR" "${ERL_FILES[@]}"
56+
57+
echo "Compilation complete."
58+
echo "Compiled files in output directory:"
59+
ls -la "$OUTPUT_DIR"
60+
echo -e "\nDone!"

src/org/intellij/erlang/debugger/xdebug/ErlangXDebugProcess.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@
5858
import org.intellij.erlang.psi.ErlangFile;
5959
import org.intellij.erlang.runconfig.ErlangRunConfigurationBase;
6060
import org.intellij.erlang.runconfig.ErlangRunningState;
61+
import org.intellij.erlang.sdk.ErlangSdkRelease;
62+
import org.intellij.erlang.sdk.ErlangSdkType;
6163
import org.intellij.erlang.utils.ErlangModulesUtil;
6264
import org.jetbrains.annotations.NotNull;
6365
import org.jetbrains.annotations.Nullable;
@@ -374,14 +376,16 @@ private OSProcessHandler runDebugTarget() throws ExecutionException {
374376
return erlangProcessHandler;
375377
}
376378

377-
private static void setUpErlangDebuggerCodePath(GeneralCommandLine commandLine) throws ExecutionException {
379+
private void setUpErlangDebuggerCodePath(GeneralCommandLine commandLine) throws ExecutionException {
378380
LOG.debug("Setting up debugger environment.");
379381
try {
380382
String[] beams = {"debugnode.beam", "remote_debugger.beam", "remote_debugger_listener.beam", "remote_debugger_notifier.beam"};
381383
File tempDirectory = FileUtil.createTempDirectory("intellij_erlang_debugger_", null);
382384
LOG.debug("Debugger beams will be put to: " + tempDirectory.getPath());
385+
String beamSubdir = resolveBeamDirectory();
386+
LOG.debug("Using beam files from: " + beamSubdir + " directory");
383387
for (String beam : beams) {
384-
copyBeamTo(beam, tempDirectory);
388+
copyBeamTo(beamSubdir, beam, tempDirectory);
385389
}
386390
LOG.debug("Debugger beams were copied successfully.");
387391
commandLine.addParameters("-pa", tempDirectory.getPath());
@@ -391,8 +395,15 @@ private static void setUpErlangDebuggerCodePath(GeneralCommandLine commandLine)
391395
}
392396
}
393397

394-
private static void copyBeamTo(String beamName, File directory) throws IOException {
395-
try (var inputStream = ResourceUtil.getResourceAsStream(ErlangXDebugProcess.class.getClassLoader(), "/debugger/beams", beamName)) {
398+
private @NotNull String resolveBeamDirectory() {
399+
ErlangSdkRelease release = ErlangSdkType.getRelease(myRunningState.getModule());
400+
if (release.isNewerOrEqualTo(ErlangSdkRelease.V_27_0)) return "otp_27_plus";
401+
return "otp_pre_27";
402+
}
403+
404+
private static void copyBeamTo(String prefix, String beamName, File directory) throws IOException {
405+
try (var inputStream = ResourceUtil.getResourceAsStream(ErlangXDebugProcess.class.getClassLoader(),
406+
"/debugger/beams/" + prefix, beamName)) {
396407
if (inputStream == null) {
397408
throw new IOException("Failed to locate debugger module: " + beamName);
398409
}

src/org/intellij/erlang/sdk/ErlangSdkRelease.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ public boolean isNewerThan(@NotNull ErlangSdkRelease other) {
6767
return VersionComparatorUtil.compare(myErtsVersion, other.myErtsVersion) > 0;
6868
}
6969

70+
public boolean isNewerOrEqualTo(@NotNull ErlangSdkRelease other) {
71+
return VersionComparatorUtil.compare(myErtsVersion, other.myErtsVersion) >= 0;
72+
}
73+
7074
public boolean needBifCompletion(@NotNull String moduleName) {
7175
return V_R16A.isNewerThan(this) || "lager".equals(moduleName) || moduleName.isEmpty();
7276
}

src/org/intellij/erlang/sdk/ErlangSdkType.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,13 @@ public static ErlangSdkRelease getRelease(@Nullable Project project) {
232232
return release != null ? release : ErlangSdkRelease.DefaultRelease;
233233
}
234234

235+
@NotNull
236+
public static ErlangSdkRelease getRelease(@Nullable Module module) {
237+
if (module == null) return ErlangSdkRelease.DefaultRelease;
238+
ErlangSdkRelease byModuleSdk = getRelease(ModuleRootManager.getInstance(module).getSdk());
239+
return byModuleSdk != null ? byModuleSdk : getRelease(module.getProject());
240+
}
241+
235242
@TestOnly
236243
@NotNull
237244
public static Sdk createMockSdk(@NotNull String sdkHome, @NotNull ErlangSdkRelease version) {

0 commit comments

Comments
 (0)