From 3594dce68aaa5ec36f3594170596199afe52059a Mon Sep 17 00:00:00 2001 From: Jonah Graham Date: Tue, 21 Jan 2025 12:47:33 -0500 Subject: [PATCH] Fix for GDB 13 "script" field in breakpoint "script" field of a breakpoint used to be output as a tuple (<= GDB 12), though it is a list. There are cases of flags that can be applied to get old or new behaviour too. This code handles both cases transparently. See https://sourceware.org/bugzilla/show_bug.cgi?id=24285 Part of #816 --- .../service/command/output/MIBreakpoint.java | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MIBreakpoint.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MIBreakpoint.java index 1b224b946b3..df3287c07d2 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MIBreakpoint.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MIBreakpoint.java @@ -626,8 +626,8 @@ public class MIBreakpoint { // Only supported starting with GDB 6.8 pending = true; } else if (var.equals("script")) { //$NON-NLS-1$ - if (value instanceof MITuple) { - parseCommands((MITuple) value); + if (value instanceof MITuple || value instanceof MIList) { + parseCommands(value); } } else if (var.equals("thread-groups")) { //$NON-NLS-1$ if (value instanceof MIList) { @@ -639,8 +639,20 @@ public class MIBreakpoint { } } - void parseCommands(MITuple tuple) { - MIValue[] values = tuple.getMIValues(); + void parseCommands(MIValue miValue) { + // "script" field of a breakpoint used to be output as a tuple (<= GDB 12), + // though it is a list. There are cases of flags that can be applied to + // get old or new behaviour too. + // This code handles both cases transparently. + // See https://sourceware.org/bugzilla/show_bug.cgi?id=24285 + MIValue[] values; + if (miValue instanceof MITuple tuple) { + values = tuple.getMIValues(); + } else if (miValue instanceof MIList list) { + values = list.getMIValues(); + } else { + throw new IllegalStateException("miValue must be tuple or list"); //$NON-NLS-1$ + } StringBuilder cmds = new StringBuilder(); for (int i = 0; i < values.length; i++) { MIValue value = values[i];