LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Debugger's Symbol scope resolution

The CVI 7.1 debugger seems to have problems showing me the correct value of a variable when my program hits a breakpoint inside of a function that contains a variable with the same name as a global (module level scope) variable. Is there a way to specify to the debugger which variable to display when the same name is used for two different variables, where one has global scope and the other has local (function level) scope?
0 Kudos
Message 1 of 6
(3,432 Views)
I never use overloaded variable names. If you can't come up with unique naming conventions for both scopes, try something like capitalization of some letters in the global variable and no capitalization in the local variable. The compiler will treat these correctly as two different variables. Sounds like a bug...

Orlan
0 Kudos
Message 2 of 6
(3,420 Views)
Hello,

I created a small example that demonstrates breaking program execution and examining the contents of a global variable and a variable with the same name that is only in scope during a function call.

Each variable is displayed in a separate area of the watch window. The global variable is labeled "foo {globTest_dbg.exe} and the variable whose scope is limited to the testLocal function call is labeled "foo {testLocal, globTest.c, globTest_dbg.exe}". The variables are displayed independently in the watch window.

If you right click on the labels of either watch expression and select "Edit Watch Expression..." you can see how the watch points each of the two individual variables.

Scott Y.
NI
0 Kudos
Message 3 of 6
(3,400 Views)
Hi Scott,

Normally I wouldn't overload variable names like this but I'm working on a
sizeable legacy module (>4000 lines) and I'd rather keep any changes that I
make to the bare minimum (I'm wary of side-affects).

Your simple example works fine but there's a glitch when I try to do
something similar in my program. I can specify the global variable and local
variable with the same name (called "tc" in this case) in the watch window,
specifying "tc {graph.c, graph_dbg.exe}" for the global variable and "tc
{XPThresholds, graph.c, graph_dbg.exe}" for the local one and the Watch
Window seems to add them OK. However, both variables get updated
simultaneously with the same value whenever one instance or the other is
manually changed (e.g. via right-click->edit value).

Nick


"Scott Y" <x@no.email> wrote in message news:216901@exchange.ni.com...
> Hello,<br><br>I created a small example that demonstrates breaking program
execution and examining the contents of a global variable and a variable
with the same name that is only in scope during a function call.<br><br>Each
variable is displayed in a separate area of the watch window. The global
variable is labeled "foo {globTest_dbg.exe} and the variable whose scope is
limited to the testLocal function call is labeled "foo {testLocal,
globTest.c, globTest_dbg.exe}". The variables are displayed independently in
the watch window.<br><br>If you right click on the labels of either watch
expression and select "Edit Watch Expression..." you can see how the watch
points each of the two individual variables.<br><br>Scott Y.<br>NI
>
>
> GlobTest.zip:
> http://forums.ni.com/attachments/ni/180/16024/1/GlobTest.zip


0 Kudos
Message 4 of 6
(3,392 Views)
Hi Nick,

It seems odd that this would behave differently in your application and in mine. Can you tell me a little more about the datatype of your 'tc' variable?

Is it possible that this variable is really a memory pointer of, and two different instances of the pointer are pointing to the same memory location?

If this is not the case, I would be interested to see a small example that demonstrates this behavior.

Scott Y
NI
0 Kudos
Message 5 of 6
(3,374 Views)
I see my mistake. There was only one "tc" variable (a double) and its a
global. What confused me was that the Watch Window let me add that same
variable as one having local scope. I modified your example (attached) to
illustrate this. In main(), only "tc" watch point with global scope
specified is updated. Then, when you step into the function XPThresholds(),
the "tc" watch point that was specified with local scope also updates.
That's what lead me to think there was a local instance of "tc" when there
really wasn't (somebody else wrote this code and it has lots of variables).
Seems a bit odd to me but maybe there's a reason why the Watch Window allows
specifying the same global variable as having both local and global scope.
Thanks,
Nick

"Scott Y" <x@no.email> wrote in message news:218091@exchange.ni.com...
> Hi Nick,<br><br>It seems odd that this would behave differently in your
application and in mine. Can you tell me a little more about the datatype of
your 'tc' variable?<br><br>Is it possible that this variable is really a
memory pointer of, and two different instances of the pointer are pointing
to the same memory location?<br><br>If this is not the case, I would be
interested to see a small example that demonstrates this
behavior.<br><br>Scott Y<br>NI



0 Kudos
Message 6 of 6
(3,369 Views)