From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from ma1-aaemail-dr-lapp01.apple.com (ma1-aaemail-dr-lapp01.apple.com [17.171.2.60]) by mx.groups.io with SMTP id smtpd.web08.120.1626378810476514733 for ; Thu, 15 Jul 2021 12:53:30 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@apple.com header.s=20180706 header.b=vrTzS9By; spf=pass (domain: apple.com, ip: 17.171.2.60, mailfrom: afish@apple.com) Received: from pps.filterd (ma1-aaemail-dr-lapp01.apple.com [127.0.0.1]) by ma1-aaemail-dr-lapp01.apple.com (8.16.0.42/8.16.0.42) with SMTP id 16FJmnCb018359 for ; Thu, 15 Jul 2021 12:53:29 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=apple.com; h=from : content-type : mime-version : subject : date : references : to : in-reply-to : message-id; s=20180706; bh=BWME0k6vux1fxlwApod1ICp4BgS8lor1iAc2clu4TBo=; b=vrTzS9Byw6zKNa8kC/nRkhmuqQ28NFT3R22mBgoDV3yRlTcOatlJ0M4n50N4mdAUau0B MfEafgQ5JUXeUD04iYTQuMMz5FdXue0EM6ORguMXxZOr+czUxxFttZmtS9sjbdvO6ooQ k9FIiO8zMN/OhzsN3Hq/QrMlOio0Uu+303r8HHJU4VKhjYnbY4qQP04SQ3UZsuwjHapn geGhxNiApoviD5dDu/ZgTMxCMjH+gTAfH3q8oF9TW1bE01lmqP8uVQNwf6OKTwz9Mag7 f85FBzgAYz/6xx4QlCxIa490Uj4Liwj84lLGUO5jZfk2ltgqowuuF/wrOJUUlF8UEX8J wA== Received: from rn-mailsvcp-mta-lapp02.rno.apple.com (rn-mailsvcp-mta-lapp02.rno.apple.com [10.225.203.150]) by ma1-aaemail-dr-lapp01.apple.com with ESMTP id 39qa747nwa-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NO) for ; Thu, 15 Jul 2021 12:53:29 -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-lapp02.rno.apple.com (Oracle Communications Messaging Server 8.1.0.9.20210415 64bit (built Apr 15 2021)) with ESMTPS id <0QWA00L84XX5ZT00@rn-mailsvcp-mta-lapp02.rno.apple.com> for devel@edk2.groups.io; Thu, 15 Jul 2021 12:53:29 -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 <0QWA00X00XRZFF00@rn-mailsvcp-mmp-lapp02.rno.apple.com> for devel@edk2.groups.io; Thu, 15 Jul 2021 12:53:29 -0700 (PDT) X-Va-A: X-Va-T-CD: 5975dd1eaec8696b379f33739df9e0a8 X-Va-E-CD: 057cb313fb39e76e2fb909683d50b512 X-Va-R-CD: e64290f2d0b74a68d17bad7660ed5419 X-Va-CD: 0 X-Va-ID: 79b8624d-d5f9-4fd8-9911-cece136a6e53 X-V-A: X-V-T-CD: 5975dd1eaec8696b379f33739df9e0a8 X-V-E-CD: 057cb313fb39e76e2fb909683d50b512 X-V-R-CD: e64290f2d0b74a68d17bad7660ed5419 X-V-CD: 0 X-V-ID: 567e681c-722e-4894-9a18-b186f1241034 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.790 definitions=2021-07-15_14:2021-07-14,2021-07-15 signatures=0 Received: from [17.235.39.14] (unknown [17.235.39.14]) 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 <0QWA00N9XXWZA800@rn-mailsvcp-mmp-lapp02.rno.apple.com> for devel@edk2.groups.io; Thu, 15 Jul 2021 12:53:28 -0700 (PDT) From: "Andrew Fish" MIME-version: 1.0 (Mac OS X Mail 14.0 \(3654.20.0.2.1\)) Subject: Re: A gdb pretty print for CHAR16 question. Need some gdb help. Date: Thu, 15 Jul 2021 12:53:23 -0700 References: <6008E409-0BC9-45B9-B0E7-8E42ED089F96@apple.com> To: edk2-devel-groups-io In-reply-to: <6008E409-0BC9-45B9-B0E7-8E42ED089F96@apple.com> Message-id: <97ADFF09-B38E-484B-B584-0D5DA916AA81@apple.com> 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_14:2021-07-14,2021-07-15 signatures=0 Content-type: multipart/alternative; boundary="Apple-Mail=_4DD85C72-2756-4BDC-A4BB-167237D78EE1" --Apple-Mail=_4DD85C72-2756-4BDC-A4BB-167237D78EE1 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 Resending without attachments=E2=80=A6. > On Jul 14, 2021, at 10:15 PM, Andrew Fish wrote: >=20 > 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 >=20 > For lldb I have Pretty Printer and for CHAR16 things like this: >=20 > CHAR16 gChar =3D L'X'; > CHAR16 gStr[] =3D L"1234567890\x23f3";=20 > CHAR16 *gStrPtr =3D gStr; =20 >=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 >=20 > 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 >=20 > 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 {}? >=20 > 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 >=20 > This is the script... > $ cat CHAR16.py > import gdb >=20 > from gdb.printing import register_pretty_printer > from gdb.printing import RegexpCollectionPrettyPrinter >=20 >=20 > class CHAR16_PrettyPrinter(object): >=20 > def __init__(self, val): > self.val =3D val >=20 > 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}'" >=20 >=20 > def build_pretty_printer(): > pp =3D RegexpCollectionPrettyPrinter("EFI") > pp.add_printer('CHAR16', '^CHAR16$', CHAR16_PrettyPrinter) > return pp >=20 >=20 > register_pretty_printer(None, build_pretty_printer(), replace=3DTrue) >=20 > $ cat CHAR16.c > #include >=20 > /// > /// 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; >=20 > CHAR16 gChar =3D L'X'; > CHAR16 gChar2 =3D L'\x23f3'; > CHAR16 gStr[] =3D L"1234567890\x23f3";=20 > CHAR16 *gStrPtr =3D gStr; =20 >=20 > char Char =3D 'X'; > char Str[] =3D "1234567890"; > char *StrPtr =3D Str; >=20 > int > main(int argc, char **argv) > { > printf ("hello world!\n"); > return 0; > } >=20 > $ 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 >=20 > 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? >=20 > 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 >=20 > Thanks, >=20 > Andrew Fish >=20 >=20 > > > >=20 --Apple-Mail=_4DD85C72-2756-4BDC-A4BB-167237D78EE1 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8 Resending without attachments=E2=80=A6.

On Jul = 14, 2021, at 10:15 PM, Andrew Fish <afish@apple.com> wrote:

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. 

For lldb I have Pretty = Printer and for CHAR16 things like this:

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

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 <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> = "1234567890"
$6 =3D (CHAR16 *) 0x100008030 = <gStr>

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 = <stdio.h>

///
/// 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"; 
CHAR16 *gStrPtr =3D gStr;      

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. 

Thanks,

Andrew Fish


<CHAR16.py>
<CHAR16.c>
<CHAR16.sh>


= --Apple-Mail=_4DD85C72-2756-4BDC-A4BB-167237D78EE1--