Permalink
Switch branches/tags
android-wear-5.1.1_r1 android-wear-5.1.0_r1 android-wear-5.0.0_r1 android-sdk-support_r11 android-sdk-adt_r20 android-sdk-adt_r16.0.1 android-sdk-4.4.2_r1.0.1 android-sdk-4.4.2_r1 android-sdk-4.0.3_r1 android-sdk-4.0.3-tools_r1 android-l-preview_r2 android-cts-verifier-4.0.3_r1 android-cts-verifier-4.0_r1 android-cts-5.1_r28 android-cts-5.1_r27 android-cts-5.1_r26 android-cts-5.1_r25 android-cts-5.1_r24 android-cts-5.1_r23 android-cts-5.1_r22 android-cts-5.1_r21 android-cts-5.1_r20 android-cts-5.1_r19 android-cts-5.1_r18 android-cts-5.1_r17 android-cts-5.1_r16 android-cts-5.1_r15 android-cts-5.1_r14 android-cts-5.1_r13 android-cts-5.1_r10 android-cts-5.1_r9 android-cts-5.1_r8 android-cts-5.1_r7 android-cts-5.1_r6 android-cts-5.1_r5 android-cts-5.1_r4 android-cts-5.1_r3 android-cts-5.1_r2 android-cts-5.1_r1 android-cts-5.0_r9 android-cts-5.0_r8 android-cts-5.0_r7 android-cts-5.0_r6 android-cts-5.0_r5 android-cts-5.0_r4 android-cts-5.0_r3 android-cts-4.4_r4 android-cts-4.4_r1 android-cts-4.2_r2 android-cts-4.2_r1 android-cts-4.1_r4 android-cts-4.1_r2 android-cts-4.1_r1 android-cts-4.0.3_r2 android-cts-4.0.3_r1 android-cts-4.0_r1 android-cts-2.3_r12 android-cts-2.3_r11 android-cts-2.3_r10 android-cts-2.2_r8 android-5.1.1_r38 android-5.1.1_r37 android-5.1.1_r36 android-5.1.1_r35 android-5.1.1_r34 android-5.1.1_r33 android-5.1.1_r30 android-5.1.1_r29 android-5.1.1_r28 android-5.1.1_r26 android-5.1.1_r25 android-5.1.1_r24 android-5.1.1_r23 android-5.1.1_r22 android-5.1.1_r20 android-5.1.1_r19 android-5.1.1_r18 android-5.1.1_r17 android-5.1.1_r16 android-5.1.1_r15 android-5.1.1_r14 android-5.1.1_r13 android-5.1.1_r12 android-5.1.1_r10 android-5.1.1_r9 android-5.1.1_r8 android-5.1.1_r7 android-5.1.1_r6 android-5.1.1_r5 android-5.1.1_r4 android-5.1.1_r3 android-5.1.1_r2 android-5.1.1_r1 android-5.1.0_r5 android-5.1.0_r4 android-5.1.0_r3 android-5.1.0_r1 android-5.0.2_r3 android-5.0.2_r1 android-5.0.1_r1
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
133 lines (106 sloc) 2.75 KB
/**
* @file db_debug.c
* Debug routines for libdb
*
* @remark Copyright 2002 OProfile authors
* @remark Read the file COPYING
*
* @author Philippe Elie
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "odb.h"
static int check_circular_list(odb_data_t const * data)
{
odb_node_nr_t pos;
int do_abort = 0;
unsigned char * bitmap = malloc(data->descr->current_size);
memset(bitmap, '\0', data->descr->current_size);
for (pos = 0 ; pos < data->descr->size * BUCKET_FACTOR ; ++pos) {
odb_index_t index = data->hash_base[pos];
if (index && !do_abort) {
while (index) {
if (bitmap[index])
do_abort = 1;
bitmap[index] = 1;
index = data->node_base[index].next;
}
}
if (do_abort) {
printf("circular list detected size: %d\n",
data->descr->current_size);
memset(bitmap, '\0', data->descr->current_size);
index = data->hash_base[pos];
while (index) {
printf("%d ", index);
if (bitmap[index])
exit(1);
bitmap[index] = 1;
index = data->node_base[index].next;
}
}
/* purely an optimization: intead of memset the map reset only
* the needed part: not my use to optimize test but here the
* test was so slow it was useless */
index = data->hash_base[pos];
while (index) {
bitmap[index] = 1;
index = data->node_base[index].next;
}
}
free(bitmap);
return do_abort;
}
static int check_redundant_key(odb_data_t const * data, odb_key_t max)
{
odb_node_nr_t pos;
unsigned char * bitmap = malloc(max + 1);
memset(bitmap, '\0', max + 1);
for (pos = 1 ; pos < data->descr->current_size ; ++pos) {
if (bitmap[data->node_base[pos].key]) {
printf("redundant key found %lld\n",
(unsigned long long)data->node_base[pos].key);
return 1;
}
bitmap[data->node_base[pos].key] = 1;
}
free(bitmap);
return 0;
}
int odb_check_hash(odb_t const * odb)
{
odb_node_nr_t pos;
odb_node_nr_t nr_node = 0;
odb_node_nr_t nr_node_out_of_bound = 0;
int ret = 0;
odb_key_t max = 0;
odb_data_t * data = odb->data;
for (pos = 0 ; pos < data->descr->size * BUCKET_FACTOR ; ++pos) {
odb_index_t index = data->hash_base[pos];
while (index) {
if (index >= data->descr->current_size) {
nr_node_out_of_bound++;
break;
}
++nr_node;
if (data->node_base[index].key > max)
max = data->node_base[index].key;
index = data->node_base[index].next;
}
}
if (nr_node != data->descr->current_size - 1) {
printf("hash table walk found %d node expect %d node\n",
nr_node, data->descr->current_size - 1);
ret = 1;
}
if (nr_node_out_of_bound) {
printf("out of bound node index: %d\n", nr_node_out_of_bound);
ret = 1;
}
if (ret == 0)
ret = check_circular_list(data);
if (ret == 0)
ret = check_redundant_key(data, max);
return ret;
}