Finding unexpected storage overwrite errors in C
During program run time, some storage might unexpectedly change
its value and you want to find out when and where this happens. Consider
this example where function
set_i
changes more than
the caller expects it to change. struct s { int i; int j;};
struct s a = { 0, 0 };
⁄* function sets only field i *⁄
void set_i(struct s * p, int k)
{
p–>i = k;
p–>j = k; ⁄* error, it unexpectedly sets field j also *⁄
}
main() {
set_i(&a,123);
}
Find the address of a
with the command
LIST &(a.j) ;
Suppose the result is 0x7042A04
.
To set a breakpoint that watches for a change in storage values starting
at that address for the next 4 bytes, issue the command: AT CHANGE %STORAGE(0x7042A04,4)
When
the program is run, z/OS® Debugger will
halt if the value in this storage changes.