2543 ssize_t size;
2544 mdb_ctf_id_t base;
2545 ctf_encoding_t e;
2546
2547 union {
2548 uint64_t ui8;
2549 uint32_t ui4;
2550 uint16_t ui2;
2551 uint8_t ui1;
2552 int64_t i8;
2553 int32_t i4;
2554 int16_t i2;
2555 int8_t i1;
2556 } u;
2557
2558 if (mdb_ctf_type_resolve(id, &base) == -1) {
2559 mdb_warn("could not resolve type");
2560 return (DCMD_ABORT);
2561 }
2562
2563 if (mdb_ctf_type_kind(base) != CTF_K_INTEGER) {
2564 mdb_warn("expected integer type\n");
2565 return (DCMD_ABORT);
2566 }
2567
2568 if (mdb_ctf_type_encoding(base, &e) != 0) {
2569 mdb_warn("could not get type encoding");
2570 return (DCMD_ABORT);
2571 }
2572
2573 if (sign)
2574 sign = e.cte_format & CTF_INT_SIGNED;
2575
2576 size = e.cte_bits / NBBY;
2577
2578 /*
2579 * Check to see if our life has been complicated by the presence of
2580 * a bitfield. If it has, we will print it using logic that is only
2581 * slightly different than that found in print_bitfield(), above. (In
2582 * particular, see the comments there for an explanation of the
2583 * endianness differences in this code.)
2584 */
2585 if (size > 8 || (e.cte_bits % NBBY) != 0 ||
2586 (size & (size - 1)) != 0) {
2587 uint64_t mask = (1ULL << e.cte_bits) - 1;
2588 uint64_t value = 0;
2589 uint8_t *buf = (uint8_t *)&value;
2590 uint8_t shift;
2591
2734 if (mdb_ctf_type_resolve(id, &base) == -1) {
2735 mdb_warn("could not resolve type");
2736 return (DCMD_ABORT);
2737 }
2738
2739 if (mdb_ctf_type_kind(base) == CTF_K_POINTER) {
2740 uintptr_t value;
2741
2742 if (mdb_vread(&value, sizeof (value), addr) == -1) {
2743 mdb_warn("failed to read pointer at %llx", addr);
2744 return (DCMD_ERR);
2745 }
2746
2747 if (mdb_readstr(buf, sizeof (buf) - 1, value) < 0) {
2748 mdb_warn("failed to read string at %llx", value);
2749 return (DCMD_ERR);
2750 }
2751
2752 mdb_printf(fmt, buf);
2753 return (0);
2754 }
2755
2756 if (mdb_ctf_type_kind(base) != CTF_K_ARRAY) {
2757 mdb_warn("exepected pointer or array type\n");
2758 return (DCMD_ABORT);
2759 }
2760
2761 if (mdb_ctf_array_info(base, &r) == -1 ||
2762 mdb_ctf_type_resolve(r.mta_contents, &base) == -1 ||
2763 (size = mdb_ctf_type_size(base)) == -1) {
2764 mdb_warn("can't determine array type");
2765 return (DCMD_ABORT);
2766 }
2767
2768 if (size != 1) {
2769 mdb_warn("string format specifier requires "
2770 "an array of characters\n");
2771 return (DCMD_ABORT);
2772 }
2773
|
2543 ssize_t size;
2544 mdb_ctf_id_t base;
2545 ctf_encoding_t e;
2546
2547 union {
2548 uint64_t ui8;
2549 uint32_t ui4;
2550 uint16_t ui2;
2551 uint8_t ui1;
2552 int64_t i8;
2553 int32_t i4;
2554 int16_t i2;
2555 int8_t i1;
2556 } u;
2557
2558 if (mdb_ctf_type_resolve(id, &base) == -1) {
2559 mdb_warn("could not resolve type");
2560 return (DCMD_ABORT);
2561 }
2562
2563 switch (mdb_ctf_type_kind(base)) {
2564 case CTF_K_ENUM:
2565 e.cte_format = CTF_INT_SIGNED;
2566 e.cte_offset = 0;
2567 e.cte_bits = sizeof(int) * NBBY; /* XXX: get size from CTF? */
2568 break;
2569 case CTF_K_INTEGER:
2570 if (mdb_ctf_type_encoding(base, &e) != 0) {
2571 mdb_warn("could not get type encoding");
2572 return (DCMD_ABORT);
2573 }
2574 break;
2575 default:
2576 mdb_warn("expected integer type\n");
2577 return (DCMD_ABORT);
2578 }
2579
2580 if (sign)
2581 sign = e.cte_format & CTF_INT_SIGNED;
2582
2583 size = e.cte_bits / NBBY;
2584
2585 /*
2586 * Check to see if our life has been complicated by the presence of
2587 * a bitfield. If it has, we will print it using logic that is only
2588 * slightly different than that found in print_bitfield(), above. (In
2589 * particular, see the comments there for an explanation of the
2590 * endianness differences in this code.)
2591 */
2592 if (size > 8 || (e.cte_bits % NBBY) != 0 ||
2593 (size & (size - 1)) != 0) {
2594 uint64_t mask = (1ULL << e.cte_bits) - 1;
2595 uint64_t value = 0;
2596 uint8_t *buf = (uint8_t *)&value;
2597 uint8_t shift;
2598
2741 if (mdb_ctf_type_resolve(id, &base) == -1) {
2742 mdb_warn("could not resolve type");
2743 return (DCMD_ABORT);
2744 }
2745
2746 if (mdb_ctf_type_kind(base) == CTF_K_POINTER) {
2747 uintptr_t value;
2748
2749 if (mdb_vread(&value, sizeof (value), addr) == -1) {
2750 mdb_warn("failed to read pointer at %llx", addr);
2751 return (DCMD_ERR);
2752 }
2753
2754 if (mdb_readstr(buf, sizeof (buf) - 1, value) < 0) {
2755 mdb_warn("failed to read string at %llx", value);
2756 return (DCMD_ERR);
2757 }
2758
2759 mdb_printf(fmt, buf);
2760 return (0);
2761 }
2762
2763 if (mdb_ctf_type_kind(base) == CTF_K_ENUM) {
2764 const char *strval;
2765 int value;
2766
2767 if (mdb_vread(&value, sizeof (value), addr) == -1) {
2768 mdb_warn("failed to read pointer at %llx", addr);
2769 return (DCMD_ERR);
2770 }
2771
2772 if ((strval = mdb_ctf_enum_name(id, value))) {
2773 mdb_printf(fmt, strval);
2774 } else {
2775 mdb_snprintf(buf, sizeof (buf), "<%d>", value);
2776 mdb_printf(fmt, buf);
2777 }
2778
2779 return (DCMD_OK);
2780 }
2781
2782 if (mdb_ctf_type_kind(base) != CTF_K_ARRAY) {
2783 mdb_warn("exepected pointer or array type\n");
2784 return (DCMD_ABORT);
2785 }
2786
2787 if (mdb_ctf_array_info(base, &r) == -1 ||
2788 mdb_ctf_type_resolve(r.mta_contents, &base) == -1 ||
2789 (size = mdb_ctf_type_size(base)) == -1) {
2790 mdb_warn("can't determine array type");
2791 return (DCMD_ABORT);
2792 }
2793
2794 if (size != 1) {
2795 mdb_warn("string format specifier requires "
2796 "an array of characters\n");
2797 return (DCMD_ABORT);
2798 }
2799
|