• AVR Freaks

Hot!Watch window variables constantly out of scope

Author
dom11990
New Member
  • Total Posts : 14
  • Reward points : 0
  • Joined: 2013/01/12 14:29:00
  • Location: 0
  • Status: offline
2019/09/22 13:33:45 (permalink)
0

Watch window variables constantly out of scope

 
I'm trying to debug some code and I constantly have the issue of "variable out of scope". Can someone explain what this means? What do I have to do to see the contents of the variable? It is being modified literally in the line above! Any help would be greatly appreciated. I have gcc optimizations off, in case it matters..

Attachment(s)

Attachments are not available: Download requirements not met
#1

9 Replies Related Threads

    ric
    Super Member
    • Total Posts : 23851
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: Watch window variables constantly out of scope 2019/09/22 13:36:31 (permalink)
    +1 (1)
    You don't reveal which compiler. I assume it's XC32.
    Is that variable ever used? If you've only started writing this code, and not used this variable yet, it may have been optimised out, even without max optimisation enabled.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #2
    Jim Nickerson
    User 452
    • Total Posts : 6258
    • Reward points : 0
    • Joined: 2003/11/07 12:35:10
    • Location: San Diego, CA
    • Status: offline
    Re: Watch window variables constantly out of scope 2019/09/23 06:26:37 (permalink)
    +1 (1)
    you could make the variable global
    #3
    paulmtcuk
    Starting Member
    • Total Posts : 43
    • Reward points : 0
    • Joined: 2007/08/23 05:16:51
    • Location: 0
    • Status: offline
    Re: Watch window variables constantly out of scope 2019/09/23 06:42:29 (permalink)
    +1 (1)
    try
     
    • "Favor accurate debug over optimization." in compiler Optimizations settings (available in XC8, maybe others)
    • just watching "data" instead of "data->lan_cmd_buffer_fill"
    • putting a Nop() after the line you want to break on, and break on the Nop() instead. 
    • refrain from making data "static" -- I seemed to have had the same trouble with watching static variables
     
     
     
    #4
    Antipodean
    Super Member
    • Total Posts : 1752
    • Reward points : 0
    • Joined: 2008/12/09 10:19:08
    • Location: Didcot, United Kingdom
    • Status: offline
    Re: Watch window variables constantly out of scope 2019/09/23 09:20:41 (permalink)
    +2 (2)
    JANickerson
    you could make the variable global

    Yeah, sounds like they are attempting to watch automatic variables in a function.
     

    Do not use my alias in your message body when replying, your message will disappear ...

    Alan
    #5
    Jim Nickerson
    User 452
    • Total Posts : 6258
    • Reward points : 0
    • Joined: 2003/11/07 12:35:10
    • Location: San Diego, CA
    • Status: offline
    Re: Watch window variables constantly out of scope 2019/09/23 11:47:13 (permalink)
    0
    I find it interesting to watch variables on the stack these days
    #6
    Nikolay_Po
    Super Member
    • Total Posts : 1896
    • Reward points : 0
    • Joined: 2012/04/01 13:49:27
    • Location: Russia, Novorossiysk
    • Status: offline
    Re: Watch window variables constantly out of scope 2019/09/23 22:27:44 (permalink)
    0
    For sure, make the variable volatile. Volatile qualifier will ensure the variable existence for a debugger at any level of optimization.
    You may keep the variable local and if it will be declared as volatile it will not be "optimized". But to watch local variable you need to pause the execution exactly inside of certain block where the variable is declared.
    #7
    dom11990
    New Member
    • Total Posts : 14
    • Reward points : 0
    • Joined: 2013/01/12 14:29:00
    • Location: 0
    • Status: offline
    Re: Watch window variables constantly out of scope 2019/09/24 13:24:37 (permalink)
    0
    Upon further inspection, I see that I gave very little information in my initial post... thank you for the responses.
     
    I'm on MP Lab X v5.25, using XC32 v2.1.
     
    The variable I am trying to watch is part of a struct (data) that is dynamically allocated during the init phase of my task. I've tried making the appropriate elements volatile in the struct definition, however, the issue persists.
     
    The variable is assigned during the initialization phase of the task and there are certain points in the while loop where I am able to see (the correct) contents. It just seems that when I'm in this case (maybe others too haven't checked) it is "out of scope". If I let the code run to the top of the switch statement (on the next loop iteration) I can again see the contents. However, at this point it is too late :)
     
    I want to avoid making the variable global. This seems like a hack to me. I want to debug the code as it running in the same configuration in which it will run on release. The memory location that is referenced by the data pointer is valid and "alive", why can't I see it without manually going to the memory view? At this point I would be happy just to understand what it means with "out of scope". Clearly the variable is NOT out of scope as it was accesses in the same context one line above.
     
    thanks for any and all help!
     
    cheers
    dom
    #8
    Jim Nickerson
    User 452
    • Total Posts : 6258
    • Reward points : 0
    • Joined: 2003/11/07 12:35:10
    • Location: San Diego, CA
    • Status: offline
    Re: Watch window variables constantly out of scope 2019/09/25 07:36:15 (permalink)
    0
    You could look at the asm listing and maybe set a breakpoint in the program memory once you identify when the memory location is accessed in the program memory code.
    #9
    Jim Nickerson
    User 452
    • Total Posts : 6258
    • Reward points : 0
    • Joined: 2003/11/07 12:35:10
    • Location: San Diego, CA
    • Status: offline
    Re: Watch window variables constantly out of scope 2019/09/25 08:10:33 (permalink)
    0
    I place a Nop just prior to the variable I am interested that is out of scope.
    Window, Target Memory View, Execution view
    Now I can step through the instructions in execution memory and observe where the variable on the stack or in a register is and look at the value.
    Sometimes MpLab X has trouble with stack variables in structures.
    Frequently for my own ease I make them global till I have fixed my software bug and then return to using them on the stack.
    #10
    Jump to:
    © 2019 APG vNext Commercial Version 4.5