WebFreak001 / code-debug

Native debugging for VSCode
The Unlicense
409 stars 115 forks source link

fix static variable not showing #435

Closed HenryRiley0 closed 2 months ago

HenryRiley0 commented 3 months ago

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 commented 3 months ago

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 commented 3 months ago

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 commented 3 months ago

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 commented 3 months ago

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

codecov-commenter commented 2 months ago

:warning: 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 :white_check_mark:

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

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

Additional details and impacted files ```diff @@ 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 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

GitMensch commented 2 months ago

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 commented 2 months ago

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