示例#1
0
文件: debug.c 项目: shenzhe/bspd
void debug_object(BSP_OBJECT *obj)
{
    if (!obj)
    {
        fprintf(stderr, "\n\033[1;37m === [NO OBJECT INPUT] ===\033[0m\n\n");

        return;
    }

    fprintf(stderr, "\n\033[1;37m=== [Debug Object] === < START > ===\033[0m\n");
    _dump_object(obj, 0);
    fprintf(stderr, "\033[1;37m=== [Debug Object] === < END > ===\033[0m\n\n");

    return;
}
示例#2
0
文件: debugger.c 项目: drnp/bsp
void debug_object(BSP_OBJECT *obj)
{
    if (!obj)
    {
        bsp_spin_lock(&debug_lock);
        fprintf(stderr, "\n\033[1;37m === [NOTHING TO DEBUG] ===\033[0m\n\n");
        bsp_spin_unlock(&debug_lock);

        return;
    }

    bsp_spin_lock(&debug_lock);
    fprintf(stderr, "\n\033[1;37m=== [Debug Object] === < START > ===\033[0m\n");
    _dump_object(obj, 0);
    fprintf(stderr, "\033[1;37m=== [Debug Object] === < END > ===\033[0m\n\n");
    bsp_spin_unlock(&debug_lock);

    return;
}
示例#3
0
static int _dump_object(struct object_instance *instance, FILE *file, int depth)
{
	struct list_head *list;
	int res;
	int i;
	struct object_instance *find_instance = NULL;
	struct object_key *object_key = NULL;
	char stringbuf1[1024];
	char stringbuf2[1024];

	memcpy(stringbuf1, instance->object_name, instance->object_name_len);
	stringbuf1[instance->object_name_len] = '\0';

	for (i=0; i<depth; i++)
		fprintf(file, "    ");

	if (instance->object_handle != OBJECT_PARENT_HANDLE)
		fprintf(file, "%s {\n", stringbuf1);

	for (list = instance->key_head.next;
	     list != &instance->key_head; list = list->next) {

                object_key = list_entry (list, struct object_key,
					 list);

		memcpy(stringbuf1, object_key->key_name, object_key->key_len);
		stringbuf1[object_key->key_len] = '\0';

		switch (object_key->value_type) {
		case OBJDB_VALUETYPE_INT16:
			snprintf (stringbuf2, sizeof(int), "%hd",
				*(unsigned int*)object_key->value);
			break;
		case OBJDB_VALUETYPE_UINT16:
			snprintf (stringbuf2, sizeof(int), "%hu",
				*(unsigned int*)object_key->value);
			break;
		case OBJDB_VALUETYPE_INT32:
			snprintf (stringbuf2, sizeof(int), "%d",
				*(int*)object_key->value);
			break;
		case OBJDB_VALUETYPE_UINT32:
			snprintf (stringbuf2, sizeof(int), "%u",
				*(unsigned int*)object_key->value);
			break;
		case OBJDB_VALUETYPE_INT64:
			snprintf (stringbuf2, sizeof(int), "%ld",
				*(long int*)object_key->value);
			break;
		case OBJDB_VALUETYPE_UINT64:
			snprintf (stringbuf2, sizeof(int), "%lu",
				*(unsigned long int*)object_key->value);
			break;
		default:
		case OBJDB_VALUETYPE_STRING:
		case OBJDB_VALUETYPE_ANY:
			memcpy(stringbuf2, object_key->value, object_key->value_len);
			stringbuf2[object_key->value_len] = '\0';
			break;
		}

		for (i=0; i<depth+1; i++)
			fprintf(file, "    ");

		fprintf(file, "%s: %s\n", stringbuf1, stringbuf2);
	}

	for (list = instance->child_head.next;
	     list != &instance->child_head; list = list->next) {

                find_instance = list_entry (list, struct object_instance,
					    child_list);
		res = _dump_object(find_instance, file, depth+1);
		if (res)
			return res;
	}
	for (i=0; i<depth; i++)
		fprintf(file, "    ");

	if (instance->object_handle != OBJECT_PARENT_HANDLE)
		fprintf(file, "}\n");

	return 0;
}
示例#4
0
文件: debugger.c 项目: drnp/bsp
static void _dump_value(BSP_VALUE *val, int layer)
{
    if (!val)
    {
        fprintf(stderr, "\033[1;35m### NO VALUE ###\033[0m\n");
        return;
    }

    switch (val->type)
    {
        case BSP_VAL_NULL : 
            fprintf(stderr, "\033[1;31m(NULL)\033[0m\n");
            break;
        case BSP_VAL_INT : 
            fprintf(stderr, "\033[1;33m(INTEGER)\033[0m => %lld\n", (long long int) get_vint(val->lval, NULL));
            break;
        case BSP_VAL_INT29 : 
            fprintf(stderr, "\033[1;33m(INTEGER29)\033[0m => %d\n", (int) get_vint29(val->lval, NULL));
            break;
        case BSP_VAL_FLOAT : 
            fprintf(stderr, "\033[1;34m(FLOAT)\033[0m => %f\n", get_float(val->lval));
            break;
        case BSP_VAL_DOUBLE : 
            fprintf(stderr, "\033[1;34m(DOUBLE)\033[0m => %g\n", get_double(val->lval));
            break;
        case BSP_VAL_BOOLEAN_TRUE : 
            fprintf(stderr, "\033[1;35m(BOOLEAN_TRUE)\033[0m\n");
            break;
        case BSP_VAL_BOOLEAN_FALSE : 
            fprintf(stderr, "\033[1;35m(BOOLEAN_FALSE)\033[0m\n");
            break;
        case BSP_VAL_STRING : 
            fprintf(stderr, "\033[1;32m(STRING)\033[0m => ");
            BSP_STRING *str = (BSP_STRING *) val->rval;
            if (str && STR_STR(str))
            {
                write(STDERR_FILENO, STR_STR(str), STR_LEN(str));
            }
            else
            {
                fprintf(stderr, "\033[1;31m### NULL_STRING ###\033[0m");
            }
            fprintf(stderr, "\n");
            break;
        case BSP_VAL_POINTER : 
            fprintf(stderr, "\033[1;36m(POINTER)\033[0m => %p\n", (void *) val->rval);
            break;
        case BSP_VAL_OBJECT : 
            fprintf(stderr, "\033[1;36m(OBJECT)\033[0m => ");
            BSP_OBJECT *sub_obj = (BSP_OBJECT *) val->rval;
            _dump_object(sub_obj, layer + 1);
            break;
        case BSP_VAL_UNKNOWN : 
            fprintf(stderr, "\033[1;31m(UNKNOWN)\033[0m\n");
            break;
        default : 
            break;
    }

    return;
}
示例#5
0
文件: debug.c 项目: shenzhe/bspd
static void _dump_value(BSP_VALUE *val, int layer)
{
    if (!val)
    {
        fprintf(stderr, "\033[1;35m### NO VALUE ###\033[0m\n");

        return;
    }

    BSP_STRING *str = NULL;
    BSP_OBJECT *sub_obj = NULL;
    switch (val->type)
    {
        case BSP_VALUE_NULL : 
            fprintf(stderr, "\033[1;31m(NULL)\033[0m\n");
            break;
        case BSP_VALUE_INT8 : 
        case BSP_VALUE_INT16 : 
        case BSP_VALUE_INT32 : 
        case BSP_VALUE_INT64 : 
        case BSP_VALUE_INT29 : 
        case BSP_VALUE_INT : 
            fprintf(stderr, "\033[1;33m(INTEGER)\033[0m : %lld\n", (long long int) (V_GET_INT(val)));
            break;
        case BSP_VALUE_UINT8 : 
        case BSP_VALUE_UINT16 : 
        case BSP_VALUE_UINT32 : 
        case BSP_VALUE_UINT64 : 
            fprintf(stderr, "\033[1;33m(UNSIGNED INTEGER)\033[0m : %llu\n", (unsigned long long int) (V_GET_INT(val)));
            break;
        case BSP_VALUE_FLOAT : 
        case BSP_VALUE_DOUBLE : 
            fprintf(stderr, "\033[1;33m(FLOAT)\033[0m : %g\n", (double) V_GET_FLOAT(val));
            break;
        case BSP_VALUE_BOOLEAN : 
            fprintf(stderr, "\033[1;33m(BOOLEAN)\033[0m : %s\n", (BSP_TRUE == V_GET_BOOLEAN(val)) ? "true" : "false");
            break;
        case BSP_VALUE_STRING : 
            fprintf(stderr, "\033[1;32m(STRING)\033[0m : ");
            str = V_GET_STRING(val);
            if (str && STR_STR(str))
            {
                write(STDERR_FILENO, STR_STR(str), STR_LEN(str));
            }
            else
            {
                fprintf(stderr, "\033[1;31m### NULL_STRING ###\033[0m");
            }

            fprintf(stderr, "\n");
            break;
        case BSP_VALUE_OBJECT : 
            fprintf(stderr, "\033[1;36m(OBJECT)\033[0m : ");
            sub_obj = V_GET_OBJECT(val);
            _dump_object(sub_obj, layer + 1);
            break;
        case BSP_VALUE_POINTER : 
            fprintf(stderr, "\033[1;36m(POINTER)\033[0m : %p\n", V_GET_POINTER(val));
            break;
        case BSP_VALUE_UNKNOWN : 
        default : 
            fprintf(stderr, "\033[1;31m(NOTHING)\033[0m\n");
            break;
    }

    return;
}