fix: Handle global array/struct variable paths in debug.c generation#24
fix: Handle global array/struct variable paths in debug.c generation#24thiagoralves wants to merge 1 commit into
Conversation
Fix incorrect C path generation for global variables with array or struct access patterns. Previously, paths like CONFIG0.GLOBALVAR.value.table[0] were incorrectly converted to GLOBALVAR__value.table[0], causing compilation errors because the variable is actually declared as CONFIG0__GLOBALVAR. The fix now correctly handles: - Global ARRAY variables (e.g., ARRAY [1..10] OF DINT) - Global Function Block instances (e.g., TON, PID) - Global ARRAY of Function Blocks (e.g., ARRAY [1..2] OF TON) For paths starting with CONFIG and containing .value. access patterns, the path is now correctly constructed as CONFIG0__VARNAME.value.xxx Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
This PR fixes incorrect C path generation for global variables that use array or struct access patterns in the debug.c file. Previously, paths like CONFIG0.GLOBALVAR.value.table[0] were incorrectly converted to GLOBALVAR__value.table[0], causing compilation errors since the actual variable declaration is CONFIG0__GLOBALVAR.
Changes:
- Added logic to detect and correctly handle global array/struct variables at the CONFIG level
- Paths starting with
CONFIGand containing.value.access patterns now correctly preserve the CONFIG prefix in the generated C path
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # These should become: CONFIG0__VARNAME.value.table[x] or CONFIG0__VARNAME.value.fieldname | ||
| if parts[0].startswith("CONFIG") and parts[2].startswith("value"): | ||
| # Global array or struct access - keep CONFIG prefix | ||
| attrs["C_path"] = parts[0] + "__" + parts[1] + "." + parts[2] |
There was a problem hiding this comment.
The C path construction only includes the first three parts (CONFIG0__VARNAME.value), but doesn't append any remaining parts from the original path. For paths like CONFIG0.VARNAME.value.table[0].field, this would incorrectly produce CONFIG0__VARNAME.value instead of CONFIG0__VARNAME.value.table[0].field. The fix should concatenate all parts from index 2 onwards: attrs[\"C_path\"] = parts[0] + \"__\" + parts[1] + \".\" + \".\".join(parts[2:])
| # Check if this is a global array/struct variable at CONFIG level | ||
| # Pattern: CONFIG0.VARNAME.value.table[x] or CONFIG0.VARNAME.value.fieldname | ||
| # These should become: CONFIG0__VARNAME.value.table[x] or CONFIG0__VARNAME.value.fieldname | ||
| if parts[0].startswith("CONFIG") and parts[2].startswith("value"): |
There was a problem hiding this comment.
This condition assumes parts has at least 3 elements, but there's no length check before accessing parts[2]. If parts has fewer than 3 elements, this will raise an IndexError. Add a length check: if len(parts) >= 3 and parts[0].startswith(\"CONFIG\") and parts[2].startswith(\"value\"):
| if parts[0].startswith("CONFIG") and parts[2].startswith("value"): | |
| if len(parts) >= 3 and parts[0].startswith("CONFIG") and parts[2].startswith("value"): |
Summary
CONFIG0.GLOBALVAR.value.table[0]were incorrectly converted toGLOBALVAR__value.table[0], causing compilation errors because the variable is actually declared asCONFIG0__GLOBALVARChanges
For paths starting with
CONFIGand containing.value.access patterns, the path is now correctly constructed asCONFIG0__VARNAME.value.xxxTest plan
ARRAY [1..10] OF DINTdebug.creferencesCONFIG0__GLOBALVAR.value.table[x]instead ofGLOBALVAR__value.table[x]Fix Details
The fix handles three cases for global variables:
ARRAY [1..10] OF DINT) - paths likeCONFIG0.GLOBALVAR.value.table[0]now correctly becomeCONFIG0__GLOBALVAR.value.table[0]TON,PID) - these already worked via theconfig_FBsregistration🤖 Generated with Claude Code