Print this page
3946 ::gcore
Reviewed by: Adam Leventhal <ahl@delphix.com>
Reviewed by: Matthew Ahrens <mahrens@delphix.com>


   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  */



  25 
  26 #pragma ident   "%Z%%M% %I%     %E% SMI"
  27 
  28 #include <sys/avl.h>
  29 
  30 #include <mdb/mdb_modapi.h>
  31 
  32 struct aw_info {
  33         void *aw_buff;          /* buffer to hold tree element */
  34         avl_tree_t aw_tree;     /* copy of avl_tree_t being walked */
  35         uintptr_t aw_end;       /* last node in specified range */
  36         const char *aw_elem_name;
  37         int (*aw_elem_check)(void *, uintptr_t, void *);
  38         void *aw_elem_check_arg;
  39 };
  40 
  41 /*
  42  * common code used to find the addr of the the leftmost child below
  43  * an AVL node
  44  */
  45 static uintptr_t
  46 avl_leftmostchild(uintptr_t addr, void *buff, size_t offset, size_t size,
  47     const char *elem_name)


 265         return (WALK_NEXT);
 266 }
 267 
 268 /*
 269  * Release the memory allocated for the walk
 270  */
 271 void
 272 avl_walk_fini(mdb_walk_state_t *wsp)
 273 {
 274         struct aw_info *aw;
 275 
 276         aw = (struct aw_info *)wsp->walk_data;
 277 
 278         if (aw == NULL)
 279                 return;
 280 
 281         if (aw->aw_buff != NULL)
 282                 mdb_free(aw->aw_buff, aw->aw_tree.avl_size);
 283 
 284         mdb_free(aw, sizeof (struct aw_info));






















 285 }


   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  */
  25 /*
  26  * Copyright (c) 2013 by Delphix. All rights reserved.
  27  */
  28 


  29 #include <sys/avl.h>
  30 
  31 #include <mdb/mdb_modapi.h>
  32 
  33 struct aw_info {
  34         void *aw_buff;          /* buffer to hold tree element */
  35         avl_tree_t aw_tree;     /* copy of avl_tree_t being walked */
  36         uintptr_t aw_end;       /* last node in specified range */
  37         const char *aw_elem_name;
  38         int (*aw_elem_check)(void *, uintptr_t, void *);
  39         void *aw_elem_check_arg;
  40 };
  41 
  42 /*
  43  * common code used to find the addr of the the leftmost child below
  44  * an AVL node
  45  */
  46 static uintptr_t
  47 avl_leftmostchild(uintptr_t addr, void *buff, size_t offset, size_t size,
  48     const char *elem_name)


 266         return (WALK_NEXT);
 267 }
 268 
 269 /*
 270  * Release the memory allocated for the walk
 271  */
 272 void
 273 avl_walk_fini(mdb_walk_state_t *wsp)
 274 {
 275         struct aw_info *aw;
 276 
 277         aw = (struct aw_info *)wsp->walk_data;
 278 
 279         if (aw == NULL)
 280                 return;
 281 
 282         if (aw->aw_buff != NULL)
 283                 mdb_free(aw->aw_buff, aw->aw_tree.avl_size);
 284 
 285         mdb_free(aw, sizeof (struct aw_info));
 286 }
 287 
 288 /*
 289  * This function is named avl_walk_mdb to avoid a naming conflict with the
 290  * existing avl_walk function.
 291  */
 292 int
 293 avl_walk_mdb(uintptr_t addr, mdb_walk_cb_t callback, void *cbdata)
 294 {
 295         mdb_walk_state_t ws;
 296         int ret;
 297 
 298         ws.walk_addr = addr;
 299         ws.walk_callback = callback;
 300         ws.walk_cbdata = cbdata;
 301 
 302         avl_walk_init(&ws);
 303         while ((ret = avl_walk_step(&ws)) == WALK_NEXT)
 304                 continue;
 305         avl_walk_fini(&ws);
 306 
 307         return (ret);
 308 }