Skip to content

Commit

Permalink
Extract macro argument location
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ddscharfe authored and jonahgraham committed Jan 30, 2023
1 parent af9b7b5 commit d500162
Showing 1 changed file with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,25 @@ private void computeMacroArgumentExtent(IASTName name, Position pos) {
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;
}
}
}
}
}
}
}
Expand Down

0 comments on commit d500162

Please sign in to comment.