From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from rn-mailsvcp-ppex-lapp34.apple.com (rn-mailsvcp-ppex-lapp34.apple.com [17.179.253.43]) by mx.groups.io with SMTP id smtpd.web09.4043.1626326147306054316 for ; Wed, 14 Jul 2021 22:15:47 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@apple.com header.s=20180706 header.b=kVhgpUZ7; spf=pass (domain: apple.com, ip: 17.179.253.43, mailfrom: afish@apple.com) Received: from pps.filterd (rn-mailsvcp-ppex-lapp34.rno.apple.com [127.0.0.1]) by rn-mailsvcp-ppex-lapp34.rno.apple.com (8.16.1.2/8.16.1.2) with SMTP id 16F5DZxH014242 for ; Wed, 14 Jul 2021 22:15:46 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=apple.com; h=from : content-type : mime-version : subject : message-id : date : to; s=20180706; bh=M0iirqr3iJPdRst2+Oz9OaWdHsqt7I4Lw1/PDyzxy80=; b=kVhgpUZ7fTIJ+Pq02SNRHartX0BrRTXpsmpGlu3PQ1oMgKBotY6MrsHuK+THrzxzzJ2M /fxZAywWgV593mUlUAFyuF620TeEDxH77TGYni9uWbIYOp/fxxE9QoXcM4/bEX2YBOnG eqRzSxhc3USBsMw0sX7JlRlsMAxpBXY5pdkNZ6hsmGkE6pcm6jpsi1uoocg3d8ChZAFR fJNk75R3M16fwJYMqUHhULPScvXYgyus3hGaAGjKfNp0hFYAsuAWVpRIuH05ck9GG2nr /Lpjb++ijhCc5W4ERQOXYKCZ6RRI5CwzXpeffypPawjh+jda78KDKvPOMAscJpQEpCJe Ew== Received: from rn-mailsvcp-mta-lapp04.rno.apple.com (rn-mailsvcp-mta-lapp04.rno.apple.com [10.225.203.152]) by rn-mailsvcp-ppex-lapp34.rno.apple.com with ESMTP id 39q7d27j60-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NO) for ; Wed, 14 Jul 2021 22:15:46 -0700 Received: from rn-mailsvcp-mmp-lapp02.rno.apple.com (rn-mailsvcp-mmp-lapp02.rno.apple.com [17.179.253.15]) by rn-mailsvcp-mta-lapp04.rno.apple.com (Oracle Communications Messaging Server 8.1.0.9.20210415 64bit (built Apr 15 2021)) with ESMTPS id <0QW900X50TAA2A90@rn-mailsvcp-mta-lapp04.rno.apple.com> for devel@edk2.groups.io; Wed, 14 Jul 2021 22:15:46 -0700 (PDT) Received: from process_milters-daemon.rn-mailsvcp-mmp-lapp02.rno.apple.com by rn-mailsvcp-mmp-lapp02.rno.apple.com (Oracle Communications Messaging Server 8.1.0.9.20210415 64bit (built Apr 15 2021)) id <0QW900Z00T1XHN00@rn-mailsvcp-mmp-lapp02.rno.apple.com> for devel@edk2.groups.io; Wed, 14 Jul 2021 22:15:46 -0700 (PDT) X-Va-A: X-Va-T-CD: 5975dd1eaec8696b379f33739df9e0a8 X-Va-E-CD: 9c8656c7ecd10c3886d407f53927fc25 X-Va-R-CD: 132f41ba71fdfad35f4ffdfe1149a889 X-Va-CD: 0 X-Va-ID: fe4745c3-815d-4b91-9436-bb51d0ac37a2 X-V-A: X-V-T-CD: 5975dd1eaec8696b379f33739df9e0a8 X-V-E-CD: 9c8656c7ecd10c3886d407f53927fc25 X-V-R-CD: 132f41ba71fdfad35f4ffdfe1149a889 X-V-CD: 0 X-V-ID: 2ceb3b90-362a-4dca-a523-236a74e72ccd X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.790 definitions=2021-07-15_02:2021-07-14,2021-07-15 signatures=0 Received: from [17.235.46.184] (unknown [17.235.46.184]) by rn-mailsvcp-mmp-lapp02.rno.apple.com (Oracle Communications Messaging Server 8.1.0.9.20210415 64bit (built Apr 15 2021)) with ESMTPSA id <0QW900NEITA92K00@rn-mailsvcp-mmp-lapp02.rno.apple.com> for devel@edk2.groups.io; Wed, 14 Jul 2021 22:15:46 -0700 (PDT) From: "Andrew Fish" MIME-version: 1.0 (Mac OS X Mail 14.0 \(3654.20.0.2.1\)) Subject: A gdb pretty print for CHAR16 question. Need some gdb help. Message-id: <6008E409-0BC9-45B9-B0E7-8E42ED089F96@apple.com> Date: Wed, 14 Jul 2021 22:15:45 -0700 To: edk2-devel-groups-io X-Mailer: Apple Mail (2.3654.20.0.2.1) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.790 definitions=2021-07-15_02:2021-07-14,2021-07-15 signatures=0 X-Groupsio-MsgNum: 77806 Content-type: multipart/alternative; boundary="Apple-Mail=_E94CA158-A8FA-4AEF-9DD6-0233FF520BE9" --Apple-Mail=_E94CA158-A8FA-4AEF-9DD6-0233FF520BE9 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 I=E2=80=99ve been watching the Le Tour replays and playing around with = gdb scripts. I was trying to figure out how to do stuff I know how to do = in lldb.=20 For lldb I have Pretty Printer and for CHAR16 things like this: CHAR16 gChar =3D L'X'; CHAR16 gStr[] =3D L"1234567890\x23f3";=20 CHAR16 *gStrPtr =3D gStr; =20 For lldb I get: L=E2=80=99X=E2=80=99 L=E2=80=9D1234567890=E2=8F=B3=E2=80=9D (CHAR16 *)L=E2=80=9D1234567890=E2=8F=B3=E2=80=9D The default for gdb is: (gdb) p /r gChar $8 =3D 88 (gdb) p /r gStr $9 =3D {49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 9203, 0} (gdb) p /r gStrPtr $10 =3D (CHAR16 *) 0x100008030 I=E2=80=99ve figured out how to teach GDB to pretty print CHAR16, but I = can=E2=80=99t figure out how to hook CHAR16 * or CHAR16 {}? This is what I=E2=80=99ve got (vs what gdb does for char): $1 =3D 88 'X' $2 =3D L'X' =20 $3 =3D "1234567890" $4 =3D {L'1', L'2', L'3', L'4', L'5', L'6', L'7', L'8', L'9', L'0', = L'=E2=8F=B3', L'\x00'} =20 $5 =3D 0x100008058 "1234567890" $6 =3D (CHAR16 *) 0x100008030 This is the script... $ cat CHAR16.py import gdb from gdb.printing import register_pretty_printer from gdb.printing import RegexpCollectionPrettyPrinter class CHAR16_PrettyPrinter(object): def __init__(self, val): self.val =3D val def to_string(self): if int(self.val) < 0x20: return f"L'\\x{int(self.val):02x}'" else: return f"L'{chr(self.val):s}'" def build_pretty_printer(): pp =3D RegexpCollectionPrettyPrinter("EFI") pp.add_printer('CHAR16', '^CHAR16$', CHAR16_PrettyPrinter) return pp register_pretty_printer(None, build_pretty_printer(), replace=3DTrue) $ cat CHAR16.c #include /// /// 2-byte Character. Unless otherwise specified all strings are stored = in the /// UTF-16 encoding format as defined by Unicode 2.1 and ISO/IEC 10646 = standards. /// typedef unsigned short CHAR16; CHAR16 gChar =3D L'X'; CHAR16 gChar2 =3D L'\x23f3'; CHAR16 gStr[] =3D L"1234567890\x23f3";=20 CHAR16 *gStrPtr =3D gStr; =20 char Char =3D 'X'; char Str[] =3D "1234567890"; char *StrPtr =3D Str; int main(int argc, char **argv) { printf ("hello world!\n"); return 0; } $ cat CHAR16.sh gcc -fshort-wchar -g CHAR16.c gdb -ex "source CHAR16.py" -ex "p Char" -ex "p gChar" -ex "shell echo ' = '" -ex "p Str" -ex "p gStr" -ex "shell echo ' '" -ex "p StrPtr" -ex "p = gStrPtr=E2=80=9D Given the above example you should be able to experiment with just the = code in this email to figure out how to get CHAR16 working. No edk2 or = EFI knowledge required, in case you have a friend who is good with gdb = pretty print? If you have CHAR16.sh, CHAR16.c, and CHAR16.py you can just run = ./CHAR16.sh and it will print out the results for char and CHAR16 if you = modify the CHAR16.py gdb Python script it will show you the results.=20 Thanks, Andrew Fish --Apple-Mail=_E94CA158-A8FA-4AEF-9DD6-0233FF520BE9 Content-Type: multipart/mixed; boundary="Apple-Mail=_6E3973CC-E2B7-49A8-959C-807B079AEDD4" --Apple-Mail=_6E3973CC-E2B7-49A8-959C-807B079AEDD4 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8 I=E2=80=99ve been watchin= g the Le Tour replays and playing around with gdb scripts. I was trying to = figure out how to do stuff I know how to do in lldb. 
<= br class=3D"">
For lldb I have Pretty Printer and for = CHAR16 things like this:

CHAR16 gChar    =3D L'X';
CHAR16 gStr[]   =3D L"1234567890\x23f3";&n= bsp;
CHAR16 *gStrPtr =3D gStr;      

= For lldb I get:
L=E2=80=99X=E2=80=99
<= div class=3D"">L=E2=80=9D1234567890=E2=8F=B3=E2=80=9D
= (CHAR16 *)L=E2=80=9D1234567890=E2=8F=B3<= span style=3D"font-size: 11px;" class=3D"">=E2=80=9D

The default for gdb= is:
(gdb) p /= r gChar
$8 =3D 88
(gdb) p /r gStr
$9 =3D {49, 50, 51, 52, 53, 54, 55= , 56, 57, 48, 9203, 0}
(gdb) p /r gStrPtr
$= 10 =3D (CHAR16 *) 0x100008030 <gStr>

I=E2=80=99ve figured out how to teach GDB to pretty print CHAR16,= but I can=E2=80=99t figure out how to hook CHAR16 * or CHAR16 {}?

This is what I=E2=80=99ve= got (vs what gdb does for char):
$1 =3D 88 'X'
$2 =3D L'X'

 

$3 =3D "1234567890"
$4 =3D {L'1', L'2', L'3', L'4', L'5', L'6= ', L'7', L'8', L'9', L'0', L'=E2=8F=B3', L'\x00'}

 

$5 =3D 0x100008058 <Str> "12345678= 90"
$6 =3D (CHAR16 *) <= /span>0x100008030 <gStr><= /div>

This is = the script...
$ cat CHAR16.py
import gdb

from gdb.printing import register_pretty_printer
from gdb.printing import RegexpCollectionPrettyPrinter


class CHAR16_PrettyPrinter(object):

    def __init__(self, val):
        self.val =3D val

    def to_string(sel= f):
        if int(self.val) < = 0x20:
            return= f"L'\\x{int(self.val):02x}'"
      &nb= sp; else:
            re= turn f"L'{chr(self.val):s}'"


def build_pretty_printer()= :
    pp =3D RegexpCollectionPrettyPrinter("= EFI")
    pp.add_printer('CHAR16', '^CHAR16$= ', CHAR16_PrettyPrinter)
    return pp
=


<= div class=3D"">register_pretty_printer(None, build_pretty_printer(), replac= e=3DTrue)

$= cat CHAR16.c
#include <stdio.h>=

///
/// 2-byte Character.  Unless otherwise specified all strings= are stored in the
/// UTF-16 encoding format as defin= ed by Unicode 2.1 and ISO/IEC 10646 standards.
///
typedef unsigned short      CHAR16;
<= div class=3D"">
CHAR16 gChar   &nb= sp;=3D L'X';
CHAR16 gChar2   =3D L'\x23f3';
=
CHAR16 gStr[]   =3D L"1234567890\x23f3"; 
CHAR16 *gStrPtr =3D gStr;      

char Char       = = =3D 'X';
char Str[]      =3D "12345678= 90";
char *StrPtr    =3D Str;

int
main(i= nt argc, char **argv)
{
  pr= intf ("hello world!\n");
  return 0;
}

= $ cat CHAR16.sh
gcc -fshort-wchar -g C= HAR16.c
gdb  -ex "source CHAR16.py" -ex "p Char" = -ex "p gChar" -ex "shell echo ' '" -ex "p Str" -ex "p gStr" -ex "shell echo= ' '" -ex "p StrPtr" -ex "p gStrPtr=E2=80=9D
Given the above example you should be abl= e to experiment with just the code in this email to figure out how to get C= HAR16 working. No edk2 or EFI knowledge required, in case you have a friend= who is good with gdb pretty print?

If you have CHAR16.sh, CHAR16.c, and CHAR16.py you can j= ust run ./CHAR16.sh and it will print out the results for char and CHAR16 i= f you modify the CHAR16.py gdb Python script it will show you the resu= lts. 

Thanks= ,

Andrew Fish


<= /div>

--Apple-Mail=_6E3973CC-E2B7-49A8-959C-807B079AEDD4 Content-Disposition: attachment; filename=CHAR16.py Content-Type: text/x-python-script; x-unix-mode=0755; name="CHAR16.py" Content-Transfer-Encoding: 7bit #!/usr/bin/python3 import gdb from gdb.printing import register_pretty_printer from gdb.printing import RegexpCollectionPrettyPrinter class CHAR16_PrettyPrinter(object): def __init__(self, val): self.val = val def to_string(self): if int(self.val) < 0x20: return f"L'\\x{int(self.val):02x}'" else: return f"L'{chr(self.val):s}'" def build_pretty_printer(): pp = RegexpCollectionPrettyPrinter("EFI") pp.add_printer('CHAR16', '^CHAR16$', CHAR16_PrettyPrinter) return pp register_pretty_printer(None, build_pretty_printer(), replace=True) --Apple-Mail=_6E3973CC-E2B7-49A8-959C-807B079AEDD4 Content-Disposition: attachment; filename=CHAR16.c Content-Type: application/octet-stream; x-unix-mode=0644; name="CHAR16.c" Content-Transfer-Encoding: 7bit #include /// /// 2-byte Character. Unless otherwise specified all strings are stored in the /// UTF-16 encoding format as defined by Unicode 2.1 and ISO/IEC 10646 standards. /// typedef unsigned short CHAR16; CHAR16 gChar = L'X'; CHAR16 gChar2 = L'\x23f3'; CHAR16 gStr[] = L"1234567890\x23f3"; CHAR16 *gStrPtr = gStr; char Char = 'X'; char Str[] = "1234567890"; char *StrPtr = Str; int main(int argc, char **argv) { printf ("hello world!\n"); return 0; } --Apple-Mail=_6E3973CC-E2B7-49A8-959C-807B079AEDD4 Content-Disposition: attachment; filename=CHAR16.sh Content-Type: application/octet-stream; x-unix-mode=0755; name="CHAR16.sh" Content-Transfer-Encoding: 7bit /opt/brew/bin/gcc-11 -fshort-wchar -g CHAR16.c gdb -ex "source CHAR16.py" -ex "p Char" -ex "p gChar" -ex "shell echo ' '" -ex "p Str" -ex "p gStr" -ex "shell echo ' '" -ex "p StrPtr" -ex "p gStrPtr" a.out --Apple-Mail=_6E3973CC-E2B7-49A8-959C-807B079AEDD4-- --Apple-Mail=_E94CA158-A8FA-4AEF-9DD6-0233FF520BE9--