Debug view variables shows wrong on struct

Sysprogs forums Forums VisualGDB Debug view variables shows wrong on struct

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #21722
    Jensa
    Participant

    Hi,

    I’ve noticed a bug in the latest build that I’m not sure was present earlier.
    When you have a struct member with the same name as a local variable when you hoover over the struct member while debugging you’ll see the value of the local variable instead of the struct member.
    I was going crazy with my debugging until I realized it showed wrong that 🙂

    See attached picture while hoovering over the ‘var’ member of test_struct.

    Attachments:
    You must be logged in to view attached files.
    #21726
    support
    Keymaster

    Hi,

    Normally this is something handled by the toolchain/gdb. Could you please double-check that running the “print test_struct.var” command in the gdb session shows the same wrong output? If yes, please check if your code is built without optimization. Debugging optimized code is always inaccurate as gcc often eliminates unused variables and reuses fragments of the code.

    #21737
    Jensa
    Participant

    Hi,

    The “print test_struct.var” command does print the correct output of the test_struct.var member and not the local var variable:

    &"print test_struct.var\n"
    $1 = 22

    The GUI does still however show the local var variable value when you hover over the ‘.var’ member. When you hoover over the test_struct variable though it shows the correct value of the var member and also the ‘Autos’ and ‘Locals’ windows shows it correct. It’s just that when you hoover over the “var” part of the “test_struct.var” code that it shows wrong. It also as you can see shows the variable name as “var” only and not “test_struct.var” which it usually does when it shows the correct struct member value.

    Optimization is set to “Disabled (-O0)”. I haven’t done any changes from the default project template for a linux application and run the Debug configuration of that.

    #21741
    support
    Keymaster

    Hi,

    Thanks for checking this. If the “print” command works, this is likely an issue between VisualGDB and gdb, so we should be able to fix it easily.

    Please create a diagnostic gdb log showing the incorrect value obtained via the “watch” window and the correct value for the same variable obtained via the “print” command and we should be able to see what is going on.

    #21746
    Jensa
    Participant

    Hi,

    The “Watch” window shows the correct value as well. I think the issue is that when you hoover over the “var” part of “test_struct.var” it doesn’t recognize it as a member of the test_struct struct but just shows the local variable “var” instead.

    I changed the code a bit to show more clearly what I mean. When I hoover over the “no_var” part of “test_struct.no_var” member the popup window shows “test_struct.no_var | 0x0000016”. But when I hoover over the “var” part of “test_struct.var” it just shows “var | 0x0000000a”. No “test_struct.” before “var”.

    New code:

    #include <iostream>
    
    using namespace std;
    
    typedef struct {
      int var;
      int no_var;
    } TestStruct;
    
    TestStruct foo( int var )
    {
      TestStruct test_struct;
      test_struct.var = 22;
      test_struct.no_var = 22;
    
      test_struct.var = var;
      test_struct.no_var = var;
    
      return test_struct;
    }
    
    int main( int argc, char * argv[] )
    {
      TestStruct test_struct = foo( 10 );
      return 0;
    }
    
    Attachments:
    You must be logged in to view attached files.
    #21765
    support
    Keymaster

    Hi,

    Thanks for narrowing it down. It looks like a combination of our language service and the debug engine was indeed causing a rather strange race condition inside the VS editor, that resulted in evaluating the incorrect expression.

    We have changed the expression finding logic in a way that no longer triggers the problem in this build: http://sysprogs.com/files/tmp/VisualGDB-5.4.4.2406.msi

    #21783
    Jensa
    Participant

    Hi,

    That did indeed solve it.

    Thanks!

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.