Skip to content

Commit d500162

Browse files
ddscharfejonahgraham
authored andcommitted
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
1 parent af9b7b5 commit d500162

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/editors/AbstractDebugTextHover.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,25 @@ private void computeMacroArgumentExtent(IASTName name, Position pos) {
347347
if (nameOffset < startOffset && nameOffset > macroOffset) {
348348
startOffset = nameOffset;
349349
}
350+
} else if (name.getNodeLocations() != null && name.getNodeLocations().length == 1
351+
&& name.getNodeLocations()[0] instanceof IASTMacroExpansionLocation expansionLocation) {
352+
// Node is completely generated within a macro expansion
353+
IASTPreprocessorMacroExpansion expansion = expansionLocation.getExpansion();
354+
if (expansion != null) {
355+
IASTName[] nestedMacroReferences = expansion.getNestedMacroReferences();
356+
357+
if (nestedMacroReferences != null && nestedMacroReferences.length == 1) {
358+
IASTImageLocation imageLocation = nestedMacroReferences[0].getImageLocation();
359+
360+
if (imageLocation != null) {
361+
final int nameOffset = imageLocation.getNodeOffset();
362+
// offset should be inside macro expansion
363+
if (nameOffset < startOffset && nameOffset > macroOffset) {
364+
startOffset = nameOffset;
365+
}
366+
}
367+
}
368+
}
350369
}
351370
}
352371
}

0 commit comments

Comments
 (0)