If I'm correct, you wonder why the following condition is never satisfied, and the corresponding printf never executes:
if( iter >= start && iter <= fin )
fprintf( stdout, ">>>>%p\n", iter );
As far as I know, the code register void* base asm("ebp");
places the base
variable in the EBP register. Although, it seems that it is merely a recommendation for compilers to place it there and therefore can get ignored - from gcc docs:
This option does not guarantee that GCC generates code that has this variable in the register you specify at all times.
Thus, obtaining the EBP value is not guaranteed.
But it doesn't seem to be the case here.
iter
starts from the base
value, that is a pointer to wherever the void print_roots( void )
was called from (I may be wrong here, but it doesn't matter much - it points at some place in the stack). It iterates by increasing it's value until it equals MAIN_BASE
, that points to a stack, where the int main(int argc, char** argv)
function stores something about itself. Between these two values the local variables of the main
function are expected to be found (x1
and x2
), that point to someplace in the heap (where some hnode->loc
points to).
The following code defines the values of the start
and fin
variables:
nTemp = head;
if( nTemp )
start = nTemp -> loc;
while( nTemp && nTemp -> used)
nTemp = nTemp -> next;
fin = nTemp -> loc + nTemp -> size;
So, start
and fin
point to the heap (since any hnode
in the list is a pointer to the heap), while iter
points to the stack. That's why the condition iter >= start && iter <= fin
is never satisfied.