*/
#include "tool.h"
+#include "pub_tool_hashtable.h"
#include "pub_tool_mallocfree.h"
#include "pub_tool_tooliface.h"
pub_core_dispatch_asm.h \
pub_core_errormgr.h \
pub_core_execontext.h \
+ pub_core_hashtable.h \
pub_core_mallocfree.h \
pub_core_replacemalloc.h\
pub_core_sigframe.h \
m_debuglog.c \
m_errormgr.c \
m_execontext.c \
+ m_hashtable.c \
m_mallocfree.c \
m_skiplist.c \
m_stacktrace.c \
ume.c \
\
vg_scheduler.c \
- vg_hashtable.c \
vg_main.c \
vg_messages.c \
vg_mylibc.c \
/*--------------------------------------------------------------------*/
-/*--- A separately chained hash table. vg_hashtable.c ---*/
+/*--- A separately chained hash table. m_hashtable.c ---*/
/*--------------------------------------------------------------------*/
/*
*/
#include "core.h"
+#include "pub_core_hashtable.h"
/*--------------------------------------------------------------------*/
/*--- Declarations ---*/
}
/*--------------------------------------------------------------------*/
-/*--- end vg_hashtable.c ---*/
+/*--- end ---*/
/*--------------------------------------------------------------------*/
--- /dev/null
+
+/*--------------------------------------------------------------------*/
+/*--- A separately-chained hash table. pub_core_hashtable.h ---*/
+/*--------------------------------------------------------------------*/
+
+/*
+ This file is part of Valgrind, a dynamic binary instrumentation
+ framework.
+
+ Copyright (C) 2000-2005 Julian Seward
+ jseward@acm.org
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307, USA.
+
+ The GNU General Public License is contained in the file COPYING.
+*/
+
+#ifndef __PUB_CORE_HASHTABLE_H
+#define __PUB_CORE_HASHTABLE_H
+
+//--------------------------------------------------------------------
+// PURPOSE: A generic data structure with fairly fast lookup for not too
+// many elements, eg. up to a few thousand.
+//--------------------------------------------------------------------
+
+#include "pub_tool_hashtable.h"
+
+// No core-only exports; everything in this module is visible to both
+// the core and tools.
+
+#endif // __PUB_CORE_HASHTABLE_H
+
+/*--------------------------------------------------------------------*/
+/*--- end ---*/
+/*--------------------------------------------------------------------*/
*/
#include "tool.h"
+#include "pub_tool_hashtable.h"
#include "pub_tool_mallocfree.h"
#include "pub_tool_replacemalloc.h"
#include "pub_tool_tooliface.h"
tool_asm.h \
pub_tool_errormgr.h \
pub_tool_execontext.h \
+ pub_tool_hashtable.h \
pub_tool_mallocfree.h \
pub_tool_replacemalloc.h\
pub_tool_skiplist.h \
--- /dev/null
+
+/*--------------------------------------------------------------------*/
+/*--- A hash table implementation. pub_tool_hashtable.h ---*/
+/*--------------------------------------------------------------------*/
+
+/*
+ This file is part of Valgrind, a dynamic binary instrumentation
+ framework.
+
+ Copyright (C) 2000-2005 Julian Seward
+ jseward@acm.org
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307, USA.
+
+ The GNU General Public License is contained in the file COPYING.
+*/
+
+#ifndef __PUB_TOOL_HASHTABLE_H
+#define __PUB_TOOL_HASHTABLE_H
+
+/* Generic type for a separately-chained hash table. Via a kind of dodgy
+ C-as-C++ style inheritance, tools can extend the VgHashNode type, so long
+ as the first two fields match the sizes of these two fields. Requires
+ a bit of casting by the tool. */
+
+// Problems with this type:
+// - Table is fixed-size.
+// - Separate chaining gives bad cache behaviour. Hash tables with linear
+// probing give better cache behaviour.
+// - It's not very abstract, eg. deleting nodes exposes more internals than
+// I'd like.
+
+typedef
+ struct _VgHashNode {
+ struct _VgHashNode * next;
+ UWord key;
+ }
+ VgHashNode;
+
+typedef
+ VgHashNode**
+ VgHashTable;
+
+/* Make a new table. Allocates the memory with VG_(calloc)(), so can be freed
+ * with VG_(free)(). */
+extern VgHashTable VG_(HT_construct) ( void );
+
+/* Count the number of nodes in a table. */
+extern Int VG_(HT_count_nodes) ( VgHashTable table );
+
+/* Add a node to the table. */
+extern void VG_(HT_add_node) ( VgHashTable t, VgHashNode* node );
+
+/* Looks up a node in the hash table. Also returns the address of the
+ previous node's `next' pointer which allows it to be removed from the
+ list later without having to look it up again. */
+extern VgHashNode* VG_(HT_get_node) ( VgHashTable t, UWord key,
+ /*OUT*/VgHashNode*** next_ptr );
+
+/* Allocates an array of pointers to all the shadow chunks of malloc'd
+ blocks. Must be freed with VG_(free)(). */
+extern VgHashNode** VG_(HT_to_array) ( VgHashTable t, /*OUT*/ UInt* n_shadows );
+
+/* Returns first node that matches predicate `p', or NULL if none do.
+ Extra arguments can be implicitly passed to `p' using `d' which is an
+ opaque pointer passed to `p' each time it is called. */
+extern VgHashNode* VG_(HT_first_match) ( VgHashTable t,
+ Bool (*p)(VgHashNode*, void*),
+ void* d );
+
+/* Applies a function f() once to each node. Again, `d' can be used
+ to pass extra information to the function. */
+extern void VG_(HT_apply_to_all_nodes)( VgHashTable t,
+ void (*f)(VgHashNode*, void*),
+ void* d );
+
+/* Destroy a table. */
+extern void VG_(HT_destruct) ( VgHashTable t );
+
+
+#endif // __PUB_TOOL_HASHTABLE_H
+
+/*--------------------------------------------------------------------*/
+/*--- end ---*/
+/*--------------------------------------------------------------------*/
extern VgSectKind VG_(seg_sect_kind)(Addr);
-/*====================================================================*/
-/*=== Generic hash table ===*/
-/*====================================================================*/
-
-/* Generic type for a separately-chained hash table. Via a kind of dodgy
- C-as-C++ style inheritance, tools can extend the VgHashNode type, so long
- as the first two fields match the sizes of these two fields. Requires
- a bit of casting by the tool. */
-typedef
- struct _VgHashNode {
- struct _VgHashNode * next;
- UWord key;
- }
- VgHashNode;
-
-typedef
- VgHashNode**
- VgHashTable;
-
-/* Make a new table. Allocates the memory with VG_(calloc)(), so can be freed
- * with VG_(free)(). */
-extern VgHashTable VG_(HT_construct) ( void );
-
-/* Count the number of nodes in a table. */
-extern Int VG_(HT_count_nodes) ( VgHashTable table );
-
-/* Add a node to the table. */
-extern void VG_(HT_add_node) ( VgHashTable t, VgHashNode* node );
-
-/* Looks up a node in the hash table. Also returns the address of the
- previous node's `next' pointer which allows it to be removed from the
- list later without having to look it up again. */
-extern VgHashNode* VG_(HT_get_node) ( VgHashTable t, UWord key,
- /*OUT*/VgHashNode*** next_ptr );
-
-/* Allocates an array of pointers to all the shadow chunks of malloc'd
- blocks. Must be freed with VG_(free)(). */
-extern VgHashNode** VG_(HT_to_array) ( VgHashTable t, /*OUT*/ UInt* n_shadows );
-
-/* Returns first node that matches predicate `p', or NULL if none do.
- Extra arguments can be implicitly passed to `p' using `d' which is an
- opaque pointer passed to `p' each time it is called. */
-extern VgHashNode* VG_(HT_first_match) ( VgHashTable t,
- Bool (*p)(VgHashNode*, void*),
- void* d );
-
-/* Applies a function f() once to each node. Again, `d' can be used
- to pass extra information to the function. */
-extern void VG_(HT_apply_to_all_nodes)( VgHashTable t,
- void (*f)(VgHashNode*, void*),
- void* d );
-
-/* Destroy a table. */
-extern void VG_(HT_destruct) ( VgHashTable t );
-
-
/*====================================================================*/
/*=== Functions for shadow registers ===*/
/*====================================================================*/
// structures below for more info on how things work.
#include "tool.h"
+#include "pub_tool_hashtable.h"
#include "pub_tool_mallocfree.h"
#include "pub_tool_replacemalloc.h"
#include "pub_tool_stacktrace.h"
#define __MAC_SHARED_H
#include "tool.h"
+#include "pub_tool_hashtable.h"
#include "pub_tool_mallocfree.h"
#include "pub_tool_replacemalloc.h"
#include "pub_tool_tooliface.h"