From d5001624cb35ff2dbdf3651129e8afe10937d66d Mon Sep 17 00:00:00 2001 From: Dominic Scharfe Date: Mon, 30 Jan 2023 08:31:52 -0500 Subject: [PATCH] Extract macro argument location The previous commit in this series addresses the NPE that can be hit. This code covers the case of the OP in #251 to actually find the correct expression to pass to GDB. Improvement to #251 --- .../ui/editors/AbstractDebugTextHover.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/editors/AbstractDebugTextHover.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/editors/AbstractDebugTextHover.java index 8f13ce25b8f..91e36cf0025 100644 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/editors/AbstractDebugTextHover.java +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/editors/AbstractDebugTextHover.java @@ -347,6 +347,25 @@ public abstract class AbstractDebugTextHover implements ICEditorTextHover, IText if (nameOffset < startOffset && nameOffset > macroOffset) { startOffset = nameOffset; } + } else if (name.getNodeLocations() != null && name.getNodeLocations().length == 1 + && name.getNodeLocations()[0] instanceof IASTMacroExpansionLocation expansionLocation) { + // Node is completely generated within a macro expansion + IASTPreprocessorMacroExpansion expansion = expansionLocation.getExpansion(); + if (expansion != null) { + IASTName[] nestedMacroReferences = expansion.getNestedMacroReferences(); + + if (nestedMacroReferences != null && nestedMacroReferences.length == 1) { + IASTImageLocation imageLocation = nestedMacroReferences[0].getImageLocation(); + + if (imageLocation != null) { + final int nameOffset = imageLocation.getNodeOffset(); + // offset should be inside macro expansion + if (nameOffset < startOffset && nameOffset > macroOffset) { + startOffset = nameOffset; + } + } + } + } } } }