Commit ed82f183 authored by malenov's avatar malenov
Browse files

fix bug in current_stack monitoring

parent 1e2783c9
Loading
Loading
Loading
Loading
Loading
+12 −7
Original line number Diff line number Diff line
@@ -582,6 +582,7 @@ typedef struct
allocator_record *allocation_list = NULL;

static int16_t *ptr_base_stack = 0; /* Pointer to the bottom of stack (base pointer). Stack grows up. */
static int16_t *ptr_current_stack = 0; /* Pointer to the current stack pointer */
static int16_t *ptr_max_stack = 0;     /* Pointer to the maximum stack pointer (the farest point from the bottom of stack) */
static int32_t wc_stack_frame = 0;     /* Frame corresponding to the worst-case stack usage */
static int32_t wc_ram_size, wc_ram_frame;
@@ -615,6 +616,7 @@ void reset_mem( Counting_Size cnt_size )
    /* initialize stack pointers */
    ptr_base_stack = &something;
    ptr_max_stack = ptr_base_stack;
    ptr_current_stack = ptr_base_stack;

    Stat_Cnt_Size = cnt_size;

@@ -702,6 +704,7 @@ void reset_stack( void )
    /* initialize/reset stack pointers */
    ptr_base_stack = &something;
    ptr_max_stack = ptr_base_stack;
    ptr_current_stack = ptr_base_stack;

    return;
}
@@ -717,6 +720,8 @@ int push_stack( const char *filename, const char *fctname )
    int16_t something;
    int32_t current_stack_size;

    ptr_current_stack = &something;

    (void) *filename; /* to avoid compilation warning */

    /* Is there room to save the caller's information? */
@@ -738,16 +743,16 @@ int push_stack( const char *filename, const char *fctname )
    stack_callers[0][current_calls].function_name[MAX_FUNCTION_NAME_LENGTH] = 0; /* Nul Terminate */

    /* Save the Stack Pointer */
    stack_callers[0][current_calls].stack_ptr = &something;
    stack_callers[0][current_calls].stack_ptr = ptr_current_stack;

    /* Increase Stack Calling Tree Level */
    current_calls++;

    /* Is this the First Time or the Worst Case? */
    if ( &something < ptr_max_stack || ptr_max_stack == NULL )
    if ( ptr_current_stack < ptr_max_stack || ptr_max_stack == NULL )
    { /* Yes */
        /* Save Info about it */
        ptr_max_stack = &something;
        ptr_max_stack = ptr_current_stack;

        wc_stack_frame = update_cnt; /* current frame number is stored in the variable update_cnt and updated in the function update_wmops() */
        strncpy( location_max_stack, fctname, sizeof( location_max_stack ) - 1 );
@@ -764,7 +769,7 @@ int push_stack( const char *filename, const char *fctname )
    }

    /* Check, if This is the New Worst-Case RAM (stack + heap) */
    current_stack_size = (int32_t) ( ( ( ptr_base_stack - ptr_max_stack ) * sizeof( int16_t ) ) );
    current_stack_size = (int32_t) ( ( ( ptr_base_stack - ptr_current_stack ) * sizeof( int16_t ) ) );
    if ( current_stack_size + current_heap_size > wc_ram_size )
    {
        wc_ram_size = current_stack_size + current_heap_size;
@@ -950,7 +955,7 @@ void *mem_alloc(
    current_heap_size += ptr_record->block_size;

    /* Check, if this is the new Worst-Case RAM (stack + heap) */
    current_stack_size = (int32_t) ( ( ( ptr_base_stack - ptr_max_stack ) * sizeof( int16_t ) ) );
    current_stack_size = ( int32_t )( ( ( ptr_base_stack - ptr_current_stack ) * sizeof( int16_t ) ) );
    if ( current_stack_size + current_heap_size > wc_ram_size )
    {
        wc_ram_size = current_stack_size + current_heap_size;