cell stack_frame_size_for_address(cell addr) const { cell natural_frame_size = stack_frame_size(); // The first instruction in a code block is the prolog safepoint, // and a leaf procedure code block will record a frame size of zero. // If we're seeing a stack frame in either of these cases, it's a // fake "leaf frame" set up by the signal handler. if (natural_frame_size == 0 || addr == entry_point()) return LEAF_FRAME_SIZE; return natural_frame_size; }
void test_two_level_stack(void) { names_stack *stack; unsigned int check_num; check_num = 0; stack = stack_new(); stack_enter(stack); check_depth(check_num++, stack, "foo", 0); check_depth(check_num++, stack, "bar", 0); check_depth(check_num++, stack, "baz", 0); check_unsigned_int(stack_frame_size(stack), 0); stack_name_add(stack, "foo"); stack_name_add(stack, "bar"); check_depth(check_num++, stack, "foo", 1); check_depth(check_num++, stack, "bar", 2); check_depth(check_num++, stack, "baz", 0); check_unsigned_ints(stack_frame_size(stack), 2, "1"); stack_enter(stack); check_unsigned_ints(stack_frame_size(stack), 0, "2"); stack_name_add(stack, "baz"); check_unsigned_ints(stack_frame_size(stack), 1, "3"); stack_name_add(stack, "foo"); check_unsigned_ints(stack_frame_size(stack), 2, "4"); check_depth(check_num++, stack, "foo", 2); check_depth(check_num++, stack, "bar", 0); check_depth(check_num++, stack, "baz", 1); stack_leave(stack); check_unsigned_ints(stack_frame_size(stack), 2, "5"); check_depth(check_num++, stack, "foo", 1); check_depth(check_num++, stack, "bar", 2); check_depth(check_num++, stack, "baz", 0); stack_leave(stack); check_unsigned_ints(stack_frame_size(stack), 0, "6"); check_depth(check_num++, stack, "foo", 0); check_depth(check_num++, stack, "bar", 0); check_depth(check_num++, stack, "baz", 0); stack_destroy(stack); }