This chapter discusses Memory Advisor's ability to find and report errors in accessing memory that is either on the stack or is global data.
Note: This chapter applies to OMT mode only.
Memory Advisor Error Messages
Stack Errors
Global Data Errors
Unsafe Data Areas
Maximizing Data Error Detection on SunOS and Solaris
foo()
{
char buf[10];
if( buf[2] == 'a' ) /* uninitialized read */
...
Memory Advisor detects the following errors for data declared on the stack:
foo()
{
int buf[16];
int i;
i = 0;
while(1)
buf[i++] = 0;
}
int bar(int count)
{
int i;
/* Memory Advisor will report an error here because i is
uninitialized. */
return count + i;
}
char * wax()
{
char buf[10];
strcpy(buf, "test");
return &buf[0]; /* Memory Advisor will report an error here */
}
char buf1[5]; char buf2[5]; buf1[6] = 'a';
Memory Advisor cannot detect addresses that are so far out of the current stack frame that they appear to be valid references into another stack frame. Memory Advisor marks a small boundary area on either side of every stack frame as out of bounds. If your program attempts to cross these boundaries, Memory Advisor will complain. If, however, you reference data through a pointer whose value is within a valid stack frame, Memory Advisor will not complain. You cannot change the size of the stack boundary area. Again, if you suspect this kind of data corruption, set a watchpoint at the address being corrupted.
Memory Advisor detects the following errors for global data:
Memory Advisor detects overwrites of global data. For example:
char name[16];
void init_var()
{
int i;
for(i=0; i<=16; i++)
name[i] = 0;
}
int buf[5];
int buf1[5];
void init_buf()
{
buf1[15] = 7;
}
Compilers generate certain references to data that are extremely difficult to interpret at the object code level. These references are called section-based relocations. If Memory Advisor interprets these data references incorrectly, your program's behavior will be unpredictable. Consequently, when Memory Advisor encounters section-based relocations in your program, it will not insert data boundaries. The problem with section-based relocations is analogous to the example above of contiguous data areas on the stack, in which it is not possible to determine whether a given address corresponds to buf1[6] or buf2[1]. With section-based relocations, it is not possible to determine whether a data reference is to one data area or another. If Memory Advisor inserts data boundaries between data areas, it must update all data references accordingly. It cannot do this if it cannot interpret what these references mean. To determine if Memory Advisor is not inserting data boundaries into a particular object file, you can run the memadvise command with the -v2 command-line option. As Memory Advisor processes the object file, it will indicate whether it found any section-based relocations. If Memory Advisor does not process the file because it is up to date, you can force Memory Advisor to process it with the -f command-line option. At your own risk, you can force Memory Advisor to insert data boundaries in object files with section-based relocations by using the -du command-line option, although we strongly discourage this.
Maximizing Data Error Detection on SunOS and Solaris
Copyright ©1996 PLATINUM technology, inc. All rights reserved.