Changeset 80565 in vbox
- Timestamp:
- Sep 3, 2019 12:51:00 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
-
include/iprt/string.h (modified) (1 diff)
-
src/VBox/Runtime/common/string/strformatrt.cpp (modified) (4 diffs)
-
src/VBox/Runtime/testcase/tstRTStrFormat.cpp (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/string.h
r80496 r80565 1471 1471 * Use the precision to specify the length. Default length is 16 bytes. 1472 1472 * The width, if specified, is ignored. 1473 * - \%RhXd - Same as \%Rhxd, but takes an additional uint64_t 1474 * value with the memory start address/offset after 1475 * the memory pointer. 1476 * - \%RhXD - Same as \%RhxD, but takes an additional uint64_t 1477 * value with the memory start address/offset after 1478 * the memory pointer. 1479 * - \%RhXs - Same as \%Rhxs, but takes an additional uint64_t 1480 * value with the memory start address/offset after 1481 * the memory pointer. 1473 1482 * 1474 1483 * - \%Rhcb - Human readable byte size formatting, using -
trunk/src/VBox/Runtime/common/string/strformatrt.cpp
r80496 r80565 832 832 */ 833 833 case 'x': 834 case 'X': 834 835 { 835 836 uint8_t *pu8 = va_arg(*pArgs, uint8_t *); 837 uint64_t uMemAddr; 838 int cchMemAddrWidth; 839 836 840 if (cchPrecision < 0) 837 841 cchPrecision = 16; 842 843 if (ch == 'x') 844 { 845 uMemAddr = (uintptr_t)pu8; 846 cchMemAddrWidth = sizeof(pu8) * 2; 847 } 848 else 849 { 850 uMemAddr = va_arg(*pArgs, uint64_t); 851 cchMemAddrWidth = uMemAddr > UINT32_MAX || uMemAddr + cchPrecision > UINT32_MAX ? 16 : 8; 852 } 853 838 854 if (pu8) 839 855 { … … 854 870 { 855 871 int i; 856 cch += RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, 857 "%s%0*p %04x:", off ? "\n" : "", sizeof(pu8) * 2, (uintptr_t)pu8, off);872 cch += RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, "%s%0*llx/%04x:", 873 off ? "\n" : "", cchMemAddrWidth, uMemAddr + off, off); 858 874 for (i = 0; i < cchWidth && off + i < cchPrecision ; i++) 859 875 cch += RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, … … 904 920 if (cDuplicates > 0) 905 921 { 906 cch += RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, 907 "\n%.*s **** <ditto x %u>", 908 sizeof(pu8) * 2, "****************", cDuplicates); 922 cch += RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, "\n%.*s **** <ditto x %u>", 923 cchMemAddrWidth, "****************", cDuplicates); 909 924 cDuplicates = 0; 910 925 } 911 926 912 cch += RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, 913 "%s%0*p %04x:", off ? "\n" : "", sizeof(pu8) * 2, (uintptr_t)pu8, off);927 cch += RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, "%s%0*llx/%04x:", 928 off ? "\n" : "", cchMemAddrWidth, uMemAddr + off, off); 914 929 for (i = 0; i < cchWidth && off + i < cchPrecision ; i++) 915 930 cch += RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, … … 945 960 if (cchPrecision-- > 0) 946 961 { 947 cch = RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, "%02x", *pu8++); 962 if (ch == 'x') 963 cch = RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, "%02x", *pu8++); 964 else 965 cch = RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, "%0*llx: %02x", 966 cchMemAddrWidth, uMemAddr, *pu8++); 948 967 for (; cchPrecision > 0; cchPrecision--, pu8++) 949 968 cch += RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, " %02x", *pu8); -
trunk/src/VBox/Runtime/testcase/tstRTStrFormat.cpp
r80496 r80565 732 732 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%256.*Rhxs", sizeof(s_abHex1), s_abHex1); 733 733 CHECKSTR("00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14"); 734 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%256.*RhXs", sizeof(s_abHex1), s_abHex1, (uint64_t)0x1234); 735 CHECKSTR("00001234: 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14"); 736 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%256.*RhXs", sizeof(s_abHex1), s_abHex1, (uint64_t)0x987654321abcdef); 737 CHECKSTR("0987654321abcdef: 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14"); 734 738 735 739 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%4.8Rhxd", s_abHex1); 736 740 RTStrPrintf(pszBuf2, BUF_SIZE, 737 "%p 0000: 00 01 02 03 ....\n"738 "%p 0004: 04 05 06 07 ....",741 "%p/0000: 00 01 02 03 ....\n" 742 "%p/0004: 04 05 06 07 ....", 739 743 &s_abHex1[0], &s_abHex1[4]); 740 744 CHECKSTR(pszBuf2); … … 742 746 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%4.6Rhxd", s_abHex1); 743 747 RTStrPrintf(pszBuf2, BUF_SIZE, 744 "%p 0000: 00 01 02 03 ....\n"745 "%p 0004: 04 05 ..",748 "%p/0000: 00 01 02 03 ....\n" 749 "%p/0004: 04 05 ..", 746 750 &s_abHex1[0], &s_abHex1[4]); 747 751 CHECKSTR(pszBuf2); … … 749 753 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%.*Rhxd", sizeof(s_abHex1), s_abHex1); 750 754 RTStrPrintf(pszBuf2, BUF_SIZE, 751 "%p 0000: 00 01 02 03 04 05 06 07-08 09 0a 0b 0c 0d 0e 0f ................\n"752 "%p 0010: 10 11 12 13 14 ....."755 "%p/0000: 00 01 02 03 04 05 06 07-08 09 0a 0b 0c 0d 0e 0f ................\n" 756 "%p/0010: 10 11 12 13 14 ....." 753 757 , 754 758 &s_abHex1[0], &s_abHex1[0x10]); 759 CHECKSTR(pszBuf2); 760 761 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%.*RhXd", sizeof(s_abHex1), s_abHex1, (uint64_t)0xf304); 762 RTStrPrintf(pszBuf2, BUF_SIZE, 763 "0000f304/0000: 00 01 02 03 04 05 06 07-08 09 0a 0b 0c 0d 0e 0f ................\n" 764 "0000f314/0010: 10 11 12 13 14 ....."); 765 CHECKSTR(pszBuf2); 766 767 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%.*RhXd", sizeof(s_abHex1), s_abHex1, (uint64_t)0x123456789abcdef); 768 RTStrPrintf(pszBuf2, BUF_SIZE, 769 "0123456789abcdef/0000: 00 01 02 03 04 05 06 07-08 09 0a 0b 0c 0d 0e 0f ................\n" 770 "0123456789abcdff/0010: 10 11 12 13 14 ....."); 755 771 CHECKSTR(pszBuf2); 756 772
Note:
See TracChangeset
for help on using the changeset viewer.

