AVL trees for opdis addresses and instructions. More...
Data Structures | |
struct | opdis_tree_node_t |
A node in an AVL tree. More... | |
struct | opdis_tree_base_t |
The base of the tree. More... | |
Typedefs | |
typedef void *(* | OPDIS_TREE_KEY_FN )(void *item) |
Callback to get the key for an item stored in a tree. | |
typedef int(* | OPDIS_TREE_CMP_FN )(void *a, void *b) |
Callback to compare two keys. | |
typedef void(* | OPDIS_TREE_FREE_FN )(void *item) |
Callback to free items stored in the tree. | |
typedef opdis_tree_base_t * | opdis_tree_t |
A generic AVL tree. | |
typedef opdis_tree_base_t * | opdis_vma_tree_t |
An AVL tree for storing opdis addresses. | |
typedef opdis_tree_base_t * | opdis_insn_tree_t |
An AVL tree for storing opdis instructions. | |
typedef int(* | OPDIS_TREE_FOREACH_FN )(void *item, void *arg) |
Callback invoked by opdis_tree_foreach. | |
typedef int(* | OPDIS_ADDR_TREE_FOREACH_FN )(opdis_vma_t addr, void *arg) |
Callback invoked for every address emitted by opdis_vma_tree_foreach. | |
typedef int(* | OPDIS_INSN_TREE_FOREACH_FN )(opdis_insn_t *insn, void *arg) |
Callback invoked for each insn emitted by opdis_insn_tree_foreach. | |
Functions | |
opdis_tree_t LIBCALL | opdis_tree_init (OPDIS_TREE_KEY_FN key_fn, OPDIS_TREE_CMP_FN cmp_fn, OPDIS_TREE_FREE_FN free_fn) |
Allocate and initialize for an AVL tree. | |
int LIBCALL | opdis_tree_add (opdis_tree_t tree, void *data) |
Insert a node into the tree. | |
int LIBCALL | opdis_tree_update (opdis_tree_t tree, void *data) |
Insert or overwrite a node in the tree. | |
int LIBCALL | opdis_tree_delete (opdis_tree_t tree, void *key) |
Remove an item from the tree. | |
int LIBCALL | opdis_tree_contains (opdis_tree_t tree, void *key) |
Determine if tree contains data. | |
void *LIBCALL | opdis_tree_find (opdis_tree_t tree, void *key) |
Find data in a tree. | |
void * | opdis_tree_closest (opdis_tree_t tree, void *key) |
Find closest match to data in a tree. This returns the item that matches the key, or the item that is closest to (but less than) the key, or NULL if there is no item less than or equal to the key. | |
void * | opdis_tree_next (opdis_tree_t tree, void *key) |
Find the data succeeding the key in a tree. This returns the item that occurs immediately after key in the tree, or immediately after where key would be if it were in the tree. If there are no items greater than key in the tree, this returns NULL. | |
void LIBCALL | opdis_tree_foreach (opdis_tree_t tree, OPDIS_TREE_FOREACH_FN fn, void *arg) |
Iterate over the tree, invoking a callback for each item. | |
size_t LIBCALL | opdis_tree_count (opdis_tree_t tree) |
Return the number of items in the tree. | |
void LIBCALL | opdis_tree_free (opdis_tree_t tree) |
Free an AVL tree. | |
opdis_vma_tree_t LIBCALL | opdis_vma_tree_init (void) |
Allocate an Address Tree. | |
int LIBCALL | opdis_vma_tree_add (opdis_vma_tree_t tree, opdis_vma_t addr) |
Insert an address into the tree. | |
int LIBCALL | opdis_vma_tree_delete (opdis_vma_tree_t tree, opdis_vma_t addr) |
Delete an address from the tree. | |
int LIBCALL | opdis_vma_tree_contains (opdis_vma_tree_t tree, opdis_vma_t addr) |
Determine if an address is in the tree. | |
opdis_vma_t LIBCALL | opdis_vma_tree_find (opdis_vma_tree_t tree, opdis_vma_t addr) |
Find an address in the tree. | |
void LIBCALL | opdis_vma_tree_foreach (opdis_vma_tree_t tree, OPDIS_ADDR_TREE_FOREACH_FN fn, void *arg) |
Invoke a callback for every item in the tree. | |
void LIBCALL | opdis_vma_tree_free (opdis_vma_tree_t tree) |
Free the address tree. | |
opdis_insn_tree_t LIBCALL | opdis_insn_tree_init (int manage) |
Allocate an Instruction Tree. | |
int LIBCALL | opdis_insn_tree_add (opdis_insn_tree_t tree, opdis_insn_t *insn) |
Insert an instruction into the tree. | |
int LIBCALL | opdis_insn_tree_delete (opdis_insn_tree_t tree, opdis_vma_t addr) |
Delete an instruction from the tree. | |
int LIBCALL | opdis_insn_tree_contains (opdis_insn_tree_t tree, opdis_vma_t addr) |
Determine if an instruction is in the tree. | |
opdis_insn_t *LIBCALL | opdis_insn_tree_find (opdis_insn_tree_t tree, opdis_vma_t addr) |
Find an instruction in the tree. | |
void LIBCALL | opdis_insn_tree_foreach (opdis_insn_tree_t tree, OPDIS_INSN_TREE_FOREACH_FN fn, void *arg) |
Invoke a callback for every item in the tree. | |
void LIBCALL | opdis_insn_tree_free (opdis_insn_tree_t tree) |
Free the instruction tree. |
AVL trees for opdis addresses and instructions.
int(* OPDIS_ADDR_TREE_FOREACH_FN)(opdis_vma_t, void *) |
Callback invoked for every address emitted by opdis_vma_tree_foreach.
addr | The address. | |
arg | Argument provided to opdis_vma_tree_foreach |
int(* OPDIS_INSN_TREE_FOREACH_FN)(opdis_insn_t *, void *) |
Callback invoked for each insn emitted by opdis_insn_tree_foreach.
addr | The instruction. | |
arg | Argument provided to opdis_insn_tree_foreach |
int(* OPDIS_TREE_CMP_FN)(void *, void *) |
Callback to compare two keys.
a | The first key. | |
b | The second key. |
This function is called to determine if the first item is before, after, or equal in order to the second item.
int(* OPDIS_TREE_FOREACH_FN)(void *, void *) |
Callback invoked by opdis_tree_foreach.
item | The current item. | |
arg | The argument provided to opdis_tree_foreach. |
void(* OPDIS_TREE_FREE_FN)(void *) |
Callback to free items stored in the tree.
item | The item to free. |
void *(* OPDIS_TREE_KEY_FN)(void *) |
Callback to get the key for an item stored in a tree.
item | The item in the tree. |
This function is invoked in order to retrieve the key for an item stored in the tree.
int opdis_insn_tree_add | ( | opdis_insn_tree_t | tree, | |
opdis_insn_t * | insn | |||
) |
Insert an instruction into the tree.
tree | The Instruction Tree. | |
insn | The instruction to insert. |
int opdis_insn_tree_contains | ( | opdis_insn_tree_t | tree, | |
opdis_vma_t | addr | |||
) |
Determine if an instruction is in the tree.
tree | The Instruction Tree. | |
addr | The address to search for. |
int opdis_insn_tree_delete | ( | opdis_insn_tree_t | tree, | |
opdis_vma_t | addr | |||
) |
Delete an instruction from the tree.
tree | The Instruction Tree. | |
insn | The instruction to delete. |
opdis_insn_t * opdis_insn_tree_find | ( | opdis_insn_tree_t | tree, | |
opdis_vma_t | addr | |||
) |
Find an instruction in the tree.
tree | The Instruction Tree. | |
addr | The address of the instruction. |
void opdis_insn_tree_foreach | ( | opdis_insn_tree_t | tree, | |
OPDIS_INSN_TREE_FOREACH_FN | fn, | |||
void * | arg | |||
) |
Invoke a callback for every item in the tree.
tree | The Instruction Tree. | |
fn | The callback to invoke for each instruction. | |
arg | An optional argument to pass to the callback function. |
void opdis_insn_tree_free | ( | opdis_insn_tree_t | tree | ) |
Free the instruction tree.
tree | The instruction Tree. |
opdis_tree_t opdis_insn_tree_init | ( | int | manage | ) |
Allocate an Instruction Tree.
manage | 1 if tree should free items on deletion; 0 otherwise. |
This creates a balanced binary tree of instructions keyed by VMA (NOT offset).
int opdis_tree_add | ( | opdis_tree_t | tree, | |
void * | data | |||
) |
Insert a node into the tree.
tree | The AVL tree. | |
data | The data to insert. |
void * opdis_tree_closest | ( | opdis_tree_t | tree, | |
void * | key | |||
) |
Find closest match to data in a tree. This returns the item that matches the key, or the item that is closest to (but less than) the key, or NULL if there is no item less than or equal to the key.
tree | The AVL tree. | |
key | The key of the item to match. |
int opdis_tree_contains | ( | opdis_tree_t | tree, | |
void * | key | |||
) |
Determine if tree contains data.
tree | The AVL tree. | |
key | The key of the item to search for. |
This function returns true (1) if tree contains a node with the given key. This is used instead of opdis_tree_find in trees where the node data (e.g. integers or pointers) could be zero, as the opdis_tree_find return value of NULL for not found will be zero regardless of whether the data is in the tree.
size_t opdis_tree_count | ( | opdis_tree_t | tree | ) |
Return the number of items in the tree.
tree | The AVL tree. |
int opdis_tree_delete | ( | opdis_tree_t | tree, | |
void * | key | |||
) |
Remove an item from the tree.
tree | The AVL tree. | |
key | The key of the item to remove. |
This routine removes the item from the tree and invokes the OPDIS_TREE_FREE_FN to free it.
void * opdis_tree_find | ( | opdis_tree_t | tree, | |
void * | key | |||
) |
Find data in a tree.
tree | The AVL tree. | |
key | The key of the item to return. |
void opdis_tree_foreach | ( | opdis_tree_t | tree, | |
OPDIS_TREE_FOREACH_FN | fn, | |||
void * | arg | |||
) |
Iterate over the tree, invoking a callback for each item.
tree | The AVL tree. | |
fn | The callback function to invoke. | |
arg | An optional argument to pass to the callback. |
void opdis_tree_free | ( | opdis_tree_t | tree | ) |
Free an AVL tree.
tree | The AVL tree to free. |
opdis_tree_t opdis_tree_init | ( | OPDIS_TREE_KEY_FN | key_fn, | |
OPDIS_TREE_CMP_FN | cmp_fn, | |||
OPDIS_TREE_FREE_FN | free_fn | |||
) |
Allocate and initialize for an AVL tree.
key_fn | Callback to use for key retrieval. | |
cmp_fn | Callback to use for key comparison. | |
free_fn | Callback to use to free items or NULL. |
void * opdis_tree_next | ( | opdis_tree_t | tree, | |
void * | key | |||
) |
Find the data succeeding the key in a tree. This returns the item that occurs immediately after key in the tree, or immediately after where key would be if it were in the tree. If there are no items greater than key in the tree, this returns NULL.
tree | The AVL tree. | |
key | The key of the item to match. |
int opdis_tree_update | ( | opdis_tree_t | tree, | |
void * | data | |||
) |
Insert or overwrite a node in the tree.
tree | The AVL tree. | |
data | The data to insert. |
This routine will insert a node into the tree. If the data already exists in the tree (i.e. the key compare callback returns 0), then the data in the tree is freed and replaced.
int opdis_vma_tree_add | ( | opdis_vma_tree_t | tree, | |
opdis_vma_t | addr | |||
) |
Insert an address into the tree.
tree | The Address Tree. | |
addr | The address to insert. |
int opdis_vma_tree_contains | ( | opdis_vma_tree_t | tree, | |
opdis_vma_t | addr | |||
) |
Determine if an address is in the tree.
tree | The Address Tree. | |
addr | The address to search for. |
int opdis_vma_tree_delete | ( | opdis_vma_tree_t | tree, | |
opdis_vma_t | addr | |||
) |
Delete an address from the tree.
tree | The Address Tree. | |
addr | The address to delete. |
opdis_vma_t opdis_vma_tree_find | ( | opdis_vma_tree_t | tree, | |
opdis_vma_t | addr | |||
) |
Find an address in the tree.
tree | The Address Tree. | |
addr | The address to search for. |
void opdis_vma_tree_foreach | ( | opdis_vma_tree_t | tree, | |
OPDIS_ADDR_TREE_FOREACH_FN | fn, | |||
void * | arg | |||
) |
Invoke a callback for every item in the tree.
tree | The Address Tree. | |
fn | The callback to invoke for each address. | |
arg | An optional argument to pass to the callback function. |
void opdis_vma_tree_free | ( | opdis_vma_tree_t | tree | ) |
opdis_vma_tree_t opdis_vma_tree_init | ( | void | ) |
Allocate an Address Tree.
This creates a balanced binary tree of addresses. In this tree, the key is the same as the data: its primary use is to keep track of addresses which have been visited.