[Dwarf-Discuss] Dwarf-Discuss Digest, Vol 34, Issue 4

Bishop, John E john.e.bishop@intel.com
Mon Mar 29 14:26:46 GMT 2010

Ron Brender asks:

> I ask because it is important to sort out what it means for a variable 
> to "have a value" outside its scope.

Consider the result of inlining and code motion on this source

  int f() {
     int x;

  int g() {
     [more code]

Then you could get instructions which could be characterized thusly:

  A:  [ instructions which use reg2 for variable "x" in routine "f"]
  B:  [ instructions which are part of "g" but don't use reg2]
  C:  [ more instructions from "f" which use reg2 for "x" ]

So in range A and C "x" is in scope and live and in reg2; in range B it
is out of scope but live and in reg2.

Ron also says:

> How can a change to a variable possibly occur when it is not in scope? 

Inlineing or value propagation could do this:

Caller does:

    h( &x );

Callee does:

    int h( int *px ) 
        *px = 0;

A optimizing compiler could cause this to be an assignment of zero to reg2
while tagging the instruction which does that as belonging to "h" and thus
while "x" is out of scope.

Ron also says:

> One also has to wonder how GDB (or any other debugger) will implement 
> watchpoints on a variable allocated in a register.

The "standard" method is "single-step and test".  That could be enhanced
when the variable is not live by continuing forward to the next live range.


More information about the Dwarf-discuss mailing list