Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix static variable not showing #435

Merged
merged 1 commit into from
Aug 26, 2024

Conversation

HenryRiley0
Copy link
Contributor

the static member of Class People does not show
Log

GDB -> App: {"token":17,"outOfBandRecord":[],"resultRecords":{"resultClass":"done","results":[["value","{stu = {name = 0x0, age = 0, score = 0}, pt = {name = 0x0, learntime = 0}, static borth = 10}"]]}}
-gdb-exit

image

does not show:
2

fixed:
fixed

@GitMensch
Copy link
Collaborator

so the issue is that the variable rename is returned including the "static" modifier, right? What about other modifiers?
concerning the regex: instead of including a space, it seems more reasonable to add a non-matching optional group with the possible modifiers, so currently (static )? up front instead of adding the space. [that's optional, but not "non-matching", but should be able to tweaked more after verified it works instead of the space-adding)

@HenryRiley0
Copy link
Contributor Author

HenryRiley0 commented Aug 22, 2024

i tested 'register、const、mutable、volatile、static', only static variable will return a modifier. it seems only static variable will has a modifier,for emphasize the variable's life time is different from loacal vairable. like below:

image

18-stack-list-variables --thread 1 --frame 0 --simple-values
GDB -> App: {"token":18,"outOfBandRecord":[],"resultRecords":{"resultClass":"done","results":[["variables",[[["name","regVar"],["type","int"],["value","10"]],[["name","p1"],["type","People"]],[["name","constVar"],["type","const int"],["value","20"]],[["name","volatileVar"],["type","volatile int"],["value","30"]],[["name","testObj"],["type","Test"]]]]]}}
19-data-evaluate-expression "p1"
GDB -> App: {"token":19,"outOfBandRecord":[],"resultRecords":{"resultClass":"done","results":[["value","{static borth = 10}"]]}}
20-data-evaluate-expression "testObj"
GDB -> App: {"token":20,"outOfBandRecord":[],"resultRecords":{"resultClass":"done","results":[["value","{mutableVar = 1}"]]}}

static variable and 'anonymous union' variable name has a space. if dont have a space "static borth = 10" and "anonymous union" will test fail.

gdb_expansion.ts

const resultRegex = /^([a-zA-Z_\-][a-zA-Z0-9_\-]*|\[\d+\])\s*=\s*/;

	parseResult = (pushToStack: boolean = false) => {
		value = value.trim();
		const variableMatch = resultRegex.exec(value);
		if (!variableMatch)
			return undefined;
		value = value.substring(variableMatch[0].length).trim();

@GitMensch
Copy link
Collaborator

GitMensch commented Aug 22, 2024

what about something like:

const resultRegex = /\s*(static )?([a-zA-Z_\-][a-zA-Z0-9_\-]*|\[\d+\])\s*=\s*/;

	parseResult = (pushToStack: boolean = false) => {
		const variableMatch = resultRegex.exec(value);
		if (!variableMatch)
			return undefined;
		value = variableMatch[1];

although from the output presented, we can drop the leading \s* and replace the others by a single space.

@HenryRiley0
Copy link
Contributor Author

what about something like:

const resultRegex = /\s*(static )?([a-zA-Z_\-][a-zA-Z0-9_\-]*|\[\d+\])\s*=\s*/;

	parseResult = (pushToStack: boolean = false) => {
		const variableMatch = resultRegex.exec(value);
		if (!variableMatch)
			return undefined;
		value = variableMatch[1];

although from the output presented, we can drop the leading \s* and replace the others by a single space.

thanks for you adivce, modified resultRegex, works fine.
image
image

Copy link
Collaborator

@GitMensch GitMensch left a comment

Choose a reason for hiding this comment

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

Thanks for the update! some things are still unclear to me, please go on.

src/backend/gdb_expansion.ts Outdated Show resolved Hide resolved
src/mibase.ts Outdated
Comment on lines 437 to 439
if(typeof id == "string" && id.includes("static ")) {
id = id.replace("static ", "");
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

please move that to the place where that id with type string is actually used in this function, this both the review and following the code later an easier task

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks, i moved this handle to 'typeof id == "string" ' branch

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah, I see. I suggest to just use const string name = id.replace(/^static /, ""); (replace also checks for the include) + using name instead of id in the two places below - this way you can also leave the "id" definition as is.
I'll pull that afterwards, so we can go to the next PR.

Thanks for your work on this!

@GitMensch GitMensch changed the title 1. fix static variable donot show issue fix static variable not showing Aug 23, 2024
@HenryRiley0 HenryRiley0 force-pushed the static_variable branch 2 times, most recently from f3ee5d6 to 908b51f Compare August 23, 2024 09:40
src/mibase.ts Outdated
@@ -531,6 +531,7 @@ export class MI2DebugSession extends DebugSession {
this.sendErrorResponse(response, 1, `Could not expand variable: ${err}`);
}
} else if (typeof id == "string") {
id.replace(/^static /, "");
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wasn't aware that this changes the content of the id object and that this can be done to a const

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wasn't aware that this changes the content of the id object and that this can be done to a const

The code is useless; const variables do not have a const modifier.

@codecov-commenter
Copy link

codecov-commenter commented Aug 26, 2024

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 19.88%. Comparing base (1b9f13e) to head (6f48d86).
Report is 8 commits behind head on master.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #435      +/-   ##
==========================================
- Coverage   20.47%   19.88%   -0.60%     
==========================================
  Files          14       14              
  Lines        1807     1866      +59     
  Branches      392      406      +14     
==========================================
+ Hits          370      371       +1     
- Misses       1392     1450      +58     
  Partials       45       45              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@GitMensch GitMensch merged commit b7ada8c into WebFreak001:master Aug 26, 2024
5 checks passed
@GitMensch
Copy link
Collaborator

Nice simple one in the end! We should add some automated testing for that, but I am currently not sure how that works -so I've merged it.
If you can add tests, please do so.

@HenryRiley0
Copy link
Contributor Author

Nice simple one in the end! We should add some automated testing for that, but I am currently not sure how that works -so I've merged it. If you can add tests, please do so.

ok, i will add static tests

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.

3 participants