VirtualBox

Changeset 80565 in vbox


Ignore:
Timestamp:
Sep 3, 2019 12:51:00 PM (5 years ago)
Author:
vboxsync
Message:

IPRT/string.h: Added hexformatting variants that takes an additional 64-bit offset/address argument to be used instead of the memory pointer: %RhXd, %RhXD, %RhXs Also changed space between the pointer and offset to a slash.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/string.h

    r80496 r80565  
    14711471 *                            Use the precision to specify the length. Default length is 16 bytes.
    14721472 *                            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.
    14731482 *
    14741483 *      - \%Rhcb            - Human readable byte size formatting, using
  • trunk/src/VBox/Runtime/common/string/strformatrt.cpp

    r80496 r80565  
    832832                     */
    833833                    case 'x':
     834                    case 'X':
    834835                    {
    835836                        uint8_t *pu8 = va_arg(*pArgs, uint8_t *);
     837                        uint64_t uMemAddr;
     838                        int      cchMemAddrWidth;
     839
    836840                        if (cchPrecision < 0)
    837841                            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
    838854                        if (pu8)
    839855                        {
     
    854870                                    {
    855871                                        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);
    858874                                        for (i = 0; i < cchWidth && off + i < cchPrecision ; i++)
    859875                                            cch += RTStrFormat(pfnOutput, pvArgOutput, NULL, 0,
     
    904920                                            if (cDuplicates > 0)
    905921                                            {
    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);
    909924                                                cDuplicates = 0;
    910925                                            }
    911926
    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);
    914929                                            for (i = 0; i < cchWidth && off + i < cchPrecision ; i++)
    915930                                                cch += RTStrFormat(pfnOutput, pvArgOutput, NULL, 0,
     
    945960                                    if (cchPrecision-- > 0)
    946961                                    {
    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++);
    948967                                        for (; cchPrecision > 0; cchPrecision--, pu8++)
    949968                                            cch += RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, " %02x", *pu8);
  • trunk/src/VBox/Runtime/testcase/tstRTStrFormat.cpp

    r80496 r80565  
    732732    cch = RTStrPrintf(pszBuf, BUF_SIZE, "%256.*Rhxs", sizeof(s_abHex1), s_abHex1);
    733733    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");
    734738
    735739    cch = RTStrPrintf(pszBuf, BUF_SIZE, "%4.8Rhxd", s_abHex1);
    736740    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 ....",
    739743                &s_abHex1[0], &s_abHex1[4]);
    740744    CHECKSTR(pszBuf2);
     
    742746    cch = RTStrPrintf(pszBuf, BUF_SIZE, "%4.6Rhxd", s_abHex1);
    743747    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       ..",
    746750                &s_abHex1[0], &s_abHex1[4]);
    747751    CHECKSTR(pszBuf2);
     
    749753    cch = RTStrPrintf(pszBuf, BUF_SIZE, "%.*Rhxd", sizeof(s_abHex1), s_abHex1);
    750754    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                                  ....."
    753757                ,
    754758                &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                                  .....");
    755771    CHECKSTR(pszBuf2);
    756772
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette