Skip to content

fix: Handle global array/struct variable paths in debug.c generation#24

Closed
thiagoralves wants to merge 1 commit into
developmentfrom
fix/global-array-debug-path
Closed

fix: Handle global array/struct variable paths in debug.c generation#24
thiagoralves wants to merge 1 commit into
developmentfrom
fix/global-array-debug-path

Conversation

@thiagoralves
Copy link
Copy Markdown

Summary

  • 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

Changes

For paths starting with CONFIG and containing .value. access patterns, the path is now correctly constructed as CONFIG0__VARNAME.value.xxx

Test plan

  • Create a project with a global variable of type ARRAY [1..10] OF DINT
  • Compile the project
  • Verify the generated debug.c references CONFIG0__GLOBALVAR.value.table[x] instead of GLOBALVAR__value.table[x]
  • Test with global Function Block instances (e.g., TON, PID)
  • Test with global ARRAY of Function Blocks

Fix Details

The fix handles three cases for global variables:

  1. Global ARRAY variables (e.g., ARRAY [1..10] OF DINT) - paths like CONFIG0.GLOBALVAR.value.table[0] now correctly become CONFIG0__GLOBALVAR.value.table[0]
  2. Global Function Block instances (e.g., TON, PID) - these already worked via the config_FBs registration
  3. Global ARRAY of Function Blocks - FB element paths and their children are now correctly handled

🤖 Generated with Claude Code

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>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jan 10, 2026

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 CONFIG and 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.

Comment thread ProjectController.py
# 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]
Copy link

Copilot AI Jan 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:])

Copilot uses AI. Check for mistakes.
Comment thread ProjectController.py
# 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"):
Copy link

Copilot AI Jan 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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\"):

Suggested change
if parts[0].startswith("CONFIG") and parts[2].startswith("value"):
if len(parts) >= 3 and parts[0].startswith("CONFIG") and parts[2].startswith("value"):

Copilot uses AI. Check for mistakes.
@thiagoralves thiagoralves deleted the fix/global-array-debug-path branch January 10, 2026 05:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants