static int scalar_tostrd(struct vbuf *vbuf, int type, void *v) { switch (type & DB_MSK) { case DB_INT8: return vbuf_printf(vbuf, "%d", (int)*((int8_t *)v)); case DB_UCHAR: case DB_UINT8: return vbuf_printf(vbuf, "%u", (unsigned)*((unsigned char *)v)); case DB_SHORT: case DB_INT16: return vbuf_printf(vbuf, "%hd", *((short *)v)); case DB_USHORT: case DB_UINT16: return vbuf_printf(vbuf, "%hu", *((unsigned short *)v)); case DB_INT: case DB_INT32: return vbuf_printf(vbuf, "%d", *((int *)v)); case DB_UINT: case DB_UINT32: return vbuf_printf(vbuf, "%u", *((unsigned int *)v)); case DB_LONG: return vbuf_printf(vbuf, "%ld", *((long *)v)); case DB_ULONG: return vbuf_printf(vbuf, "%lu", *((unsigned long *)v)); case DB_LONGLONG: case DB_INT64: return vbuf_printf(vbuf, "%lld", *((long long *)v)); case DB_ULONGLONG: case DB_UINT64: return vbuf_printf(vbuf, "%llu", *((unsigned long long *)v)); default: BUG(); return -EINVAL; } }
static int ptr_tostr(struct vbuf *vbuf, int type, void *v) { if (v != NULL) { if ((type & DB_MSK) == DB_VOID) return vbuf_printf(vbuf, "%p", v); else return scalar_tostr(vbuf, type, v); } else return vbuf_printf(vbuf, "(null)"); }
static int scalar_tostr(struct vbuf *vbuf, int type, void *v) { char c; switch (type & DB_MSK) { case DB_CHAR: c = *((char *)v); return vbuf_printf(vbuf, "%c", isprint(c) ? c : '.'); case DB_STRING: return vbuf_printf(vbuf, "%s", (char *)v); default: if (type & DB_HEX) return scalar_tostrx(vbuf, type, v); else return scalar_tostrd(vbuf, type, v); } }
static int scalar_tostrx(struct vbuf *vbuf, int type, void *v) { switch (type & DB_MSK) { case DB_INT8: return vbuf_printf(vbuf, "%#x", (int)*((int8_t *)v)); case DB_UCHAR: case DB_UINT8: return vbuf_printf(vbuf, "%#x", (unsigned)*((unsigned char *)v)); case DB_SHORT: case DB_INT16: case DB_USHORT: case DB_UINT16: return vbuf_printf(vbuf, "%#hx", *((unsigned short *)v)); case DB_INT: case DB_INT32: case DB_UINT: case DB_UINT32: return vbuf_printf(vbuf, "%#x", *((unsigned int *)v)); case DB_LONG: case DB_ULONG: return vbuf_printf(vbuf, "%#lx", *((unsigned long *)v)); case DB_LONGLONG: case DB_INT64: case DB_ULONGLONG: case DB_UINT64: return vbuf_printf(vbuf, "%#llx", *((unsigned long long *)v)); default: ERROR(); return -EINVAL; } }
static int array_tostr(struct vbuf *vbuf, int type, int nent, int size, void *v) { int n; for (; nent > 1; nent--) { n = elem_tostr(vbuf, type, v); if (n < 0) return n; n = vbuf_printf(vbuf, ", "); /* Array element separator. */ if (n < 0) return n; v = (void *)((unsigned long)v + size); } return elem_tostr(vbuf, type, v); }