1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2  * Copyright by The HDF Group.                                               *
3  * Copyright by the Board of Trustees of the University of Illinois.         *
4  * All rights reserved.                                                      *
5  *                                                                           *
6  * This file is part of HDF5.  The full HDF5 copyright notice, including     *
7  * terms governing use, modification, and redistribution, is contained in    *
8  * the files COPYING and Copyright.html.  COPYING can be found at the root   *
9  * of the source code distribution tree; Copyright.html can be found at the  *
10  * root level of an installed copy of the electronic HDF5 document set and   *
11  * is linked from the top-level documents page.  It can also be found at     *
12  * http://hdfgroup.org/HDF5/doc/Copyright.html.  If you do not have          *
13  * access to either file, you may request a copy from help@hdfgroup.org.     *
14  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 /* Programmer:  Quincey Koziol <koziol@ncsa.uiuc.edu>
17  *              Wednesday, July 9, 2003
18  *
19  * Purpose:	Local Heap object debugging functions.
20  */
21 #define H5HL_PACKAGE		/* Suppress error about including H5HLpkg */
22 
23 
24 #include "H5private.h"		/* Generic Functions			*/
25 #include "H5Eprivate.h"		/* Error handling		        */
26 #include "H5HLpkg.h"		/* Local heaps				*/
27 #include "H5Iprivate.h"		/* ID Functions		                */
28 #include "H5MMprivate.h"	/* Memory management			*/
29 
30 
31 /*-------------------------------------------------------------------------
32  * Function:	H5HL_debug
33  *
34  * Purpose:	Prints debugging information about a heap.
35  *
36  * Return:	Non-negative on success/Negative on failure
37  *
38  * Programmer:	Robb Matzke
39  *		matzke@llnl.gov
40  *		Aug  1 1997
41  *
42  * Modifications:
43  *		Robb Matzke, 1999-07-28
44  *		The ADDR argument is passed by value.
45  *
46  *              John Mainzer, 6/17/05
47  *              Modified the function to use the new dirtied parameter of
48  *              of H5AC_unprotect() instead of modifying the is_dirty
49  *              field of the cache info.
50  *
51  *-------------------------------------------------------------------------
52  */
53 herr_t
H5HL_debug(H5F_t * f,hid_t dxpl_id,haddr_t addr,FILE * stream,int indent,int fwidth)54 H5HL_debug(H5F_t *f, hid_t dxpl_id, haddr_t addr, FILE * stream, int indent, int fwidth)
55 {
56     H5HL_t		*h = NULL;
57     int			free_block;
58     H5HL_free_t		*freelist;
59     uint8_t		*marker = NULL;
60     size_t		amount_free = 0;
61     herr_t              ret_value = SUCCEED;       /* Return value */
62 
63     FUNC_ENTER_NOAPI(FAIL)
64 
65     /* check arguments */
66     HDassert(f);
67     HDassert(H5F_addr_defined(addr));
68     HDassert(stream);
69     HDassert(indent >= 0);
70     HDassert(fwidth >= 0);
71 
72     if(NULL == (h = (H5HL_t *)H5HL_protect(f, dxpl_id, addr, H5AC_READ)))
73         HGOTO_ERROR(H5E_HEAP, H5E_CANTLOAD, FAIL, "unable to load heap")
74 
75     HDfprintf(stream, "%*sLocal Heap...\n", indent, "");
76     HDfprintf(stream, "%*s%-*s %lu\n", indent, "", fwidth,
77 	    "Header size (in bytes):",
78 	    (unsigned long)h->prfx_size);
79     HDfprintf(stream, "%*s%-*s %a\n", indent, "", fwidth,
80 	      "Address of heap data:",
81 	      h->dblk_addr);
82     HDfprintf(stream, "%*s%-*s %Zu\n", indent, "", fwidth,
83 	    "Data bytes allocated for heap:",
84             h->dblk_size);
85 
86     /*
87      * Traverse the free list and check that all free blocks fall within
88      * the heap and that no two free blocks point to the same region of
89      * the heap.  */
90     if(NULL == (marker = (uint8_t *)H5MM_calloc(h->dblk_size)))
91 	HGOTO_ERROR(H5E_HEAP, H5E_CANTALLOC, FAIL, "memory allocation failed")
92 
93     HDfprintf(stream, "%*sFree Blocks (offset, size):\n", indent, "");
94     for(free_block = 0, freelist = h->freelist; freelist; freelist = freelist->next, free_block++) {
95         char temp_str[32];
96 
97         HDsnprintf(temp_str, sizeof(temp_str), "Block #%d:", free_block);
98 	HDfprintf(stream, "%*s%-*s %8Zu, %8Zu\n", indent+3, "", MAX(0,fwidth-9),
99 		temp_str,
100 		freelist->offset, freelist->size);
101 	if((freelist->offset + freelist->size) > h->dblk_size)
102 	    HDfprintf(stream, "***THAT FREE BLOCK IS OUT OF BOUNDS!\n");
103 	else {
104             int	overlap = 0;
105             size_t i;
106 
107 	    for(i = 0; i < freelist->size; i++) {
108 		if(marker[freelist->offset + i])
109 		    overlap++;
110 		marker[freelist->offset + i] = 1;
111 	    } /* end for */
112 	    if(overlap)
113 		HDfprintf(stream, "***THAT FREE BLOCK OVERLAPPED A PREVIOUS ONE!\n");
114 	    else
115 		amount_free += freelist->size;
116 	} /* end for */
117     } /* end for */
118 
119     if(h->dblk_size)
120 	HDfprintf(stream, "%*s%-*s %.2f%%\n", indent, "", fwidth,
121 		"Percent of heap used:",
122 		((double)100.0f * (double)(h->dblk_size - amount_free) / (double)h->dblk_size));
123 
124     /*
125      * Print the data in a VMS-style octal dump.
126      */
127     H5_buffer_dump(stream, indent, h->dblk_image, marker, (size_t)0, h->dblk_size);
128 
129 done:
130     if(h && H5HL_unprotect(h) < 0)
131 	HDONE_ERROR(H5E_OHDR, H5E_PROTECT, FAIL, "unable to release object header")
132     H5MM_xfree(marker);
133 
134     FUNC_LEAVE_NOAPI(ret_value)
135 } /* end H5HL_debug() */
136 
137