source: rtems/cpukit/score/src/heapwalk.c @ 6af81435

4.104.114.84.95
Last change on this file since 6af81435 was 93b4e6ef, checked in by Joel Sherrill <joel.sherrill@…>, on 11/02/99 at 21:05:17

Split Heap and Time of Day Handlers.

  • Property mode set to 100644
File size: 3.6 KB
Line 
1/*
2 *  Heap Handler
3 *
4 *  COPYRIGHT (c) 1989-1998.
5 *  On-Line Applications Research Corporation (OAR).
6 *  Copyright assigned to U.S. Government, 1994.
7 *
8 *  The license and distribution terms for this file may be
9 *  found in the file LICENSE in this distribution or at
10 *  http://www.OARcorp.com/rtems/license.html.
11 *
12 *  $Id$
13 */
14
15
16#include <rtems/system.h>
17#include <rtems/score/sysstate.h>
18#include <rtems/score/heap.h>
19
20/*PAGE
21 *
22 *  _Heap_Walk
23 *
24 *  This kernel routine walks the heap and verifies its correctness.
25 *
26 *  Input parameters:
27 *    the_heap  - pointer to heap header
28 *    source    - a numeric indicator of the invoker of this routine
29 *    do_dump   - when TRUE print the information
30 *
31 *  Output parameters: NONE
32 */
33
34#ifndef RTEMS_DEBUG
35
36void _Heap_Walk(
37  Heap_Control  *the_heap,
38  int            source,
39  boolean        do_dump
40)
41{
42}
43
44#else
45
46#include <stdio.h>
47#include <unistd.h>
48
49void _Heap_Walk(
50  Heap_Control  *the_heap,
51  int            source,
52  boolean        do_dump
53)
54{
55  Heap_Block *the_block  = 0;  /* avoid warnings */
56  Heap_Block *next_block = 0;  /* avoid warnings */
57  int         notdone = 1;
58  int         error = 0;
59  int         passes = 0;
60
61  /*
62   * We don't want to allow walking the heap until we have
63   * transferred control to the user task so we watch the
64   * system state.
65   */
66
67  if ( !_System_state_Is_up( _System_state_Get() ) )
68    return;
69
70  the_block = the_heap->start;
71
72  if (do_dump == TRUE) {
73    printf("\nPASS: %d  start @ 0x%p   final 0x%p,   first 0x%p  last 0x%p\n",
74            source, the_heap->start, the_heap->final,
75                  the_heap->first, the_heap->last
76          );
77  }
78
79  /*
80   * Handle the 1st block
81   */
82
83  if (the_block->back_flag != HEAP_DUMMY_FLAG) {
84    printf("PASS: %d  Back flag of 1st block isn't HEAP_DUMMY_FLAG\n", source);
85    error = 1;
86  }
87
88  while (notdone) {
89    passes++;
90    if (error && (passes > 10))
91        abort();
92   
93    if (do_dump == TRUE) {
94      printf("PASS: %d  Block @ 0x%p   Back %d,   Front %d",
95              source, the_block,
96              the_block->back_flag, the_block->front_flag);
97      if ( _Heap_Is_block_free(the_block) ) {
98        printf( "      Prev 0x%p,   Next 0x%p\n",
99                          the_block->previous, the_block->next);
100      } else {
101        printf("\n");
102      }
103    }
104
105    /*
106     * Handle the last block
107     */
108
109    if ( the_block->front_flag != HEAP_DUMMY_FLAG ) {
110      next_block = _Heap_Next_block(the_block);
111      if ( the_block->front_flag != next_block->back_flag ) {
112        error = 1;
113        printf("PASS: %d  Front and back flags don't match\n", source);
114        printf("         Current Block (%p):  Back - %d,  Front - %d",
115               the_block, the_block->back_flag, the_block->front_flag);
116        if (do_dump == TRUE) {
117          if (_Heap_Is_block_free(the_block)) {
118            printf("      Prev 0x%p,   Next 0x%p\n",
119                   the_block->previous, the_block->next);
120          } else {
121            printf("\n");
122          }
123        } else {
124          printf("\n");
125        }
126        printf("         Next Block (%p):     Back - %d,  Front - %d",
127               next_block, next_block->back_flag, next_block->front_flag);
128        if (do_dump == TRUE) {
129          if (_Heap_Is_block_free(next_block)) {
130            printf("      Prev 0x%p,   Next 0x%p\n",
131                   the_block->previous, the_block->next);
132          } else {
133            printf("\n");
134          }
135        } else {
136          printf("\n");
137        }
138      }
139    }
140
141    if (the_block->front_flag == HEAP_DUMMY_FLAG)
142      notdone = 0;
143    else
144      the_block = next_block;
145  }
146
147  if (error)
148      abort();
149}
150#endif
Note: See TracBrowser for help on using the repository browser.