public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Andrew Fish" <afish@apple.com>
To: edk2-devel-groups-io <devel@edk2.groups.io>
Subject: Re: A gdb pretty print for CHAR16 question. Need some gdb help.
Date: Thu, 15 Jul 2021 12:53:23 -0700	[thread overview]
Message-ID: <97ADFF09-B38E-484B-B584-0D5DA916AA81@apple.com> (raw)
In-Reply-To: <6008E409-0BC9-45B9-B0E7-8E42ED089F96@apple.com>

[-- Attachment #1: Type: text/plain, Size: 3211 bytes --]

Resending without attachments….

> On Jul 14, 2021, at 10:15 PM, Andrew Fish <afish@apple.com> wrote:
> 
> I’ve 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    = L'X';
> CHAR16 gStr[]   = L"1234567890\x23f3"; 
> CHAR16 *gStrPtr = gStr;      
> 
> For lldb I get:
> L’X’
> L”1234567890⏳”
> (CHAR16 *)L”1234567890⏳”
> 
> The default for gdb is:
> (gdb) p /r gChar
> $8 = 88
> (gdb) p /r gStr
> $9 = {49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 9203, 0}
> (gdb) p /r gStrPtr
> $10 = (CHAR16 *) 0x100008030 <gStr>
> 
> I’ve figured out how to teach GDB to pretty print CHAR16, but I can’t figure out how to hook CHAR16 * or CHAR16 {}?
> 
> This is what I’ve got (vs what gdb does for char):
> $1 = 88 'X'
> $2 = L'X'
>  
> $3 = "1234567890"
> $4 = {L'1', L'2', L'3', L'4', L'5', L'6', L'7', L'8', L'9', L'0', L'⏳', L'\x00'}
>  
> $5 = 0x100008058 <Str> "1234567890"
> $6 = (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 = 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)
> 
> $ 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    = 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;
> }
> 
> $ 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”
> 
> 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>
> 


[-- Attachment #2: Type: text/html, Size: 11545 bytes --]

      reply	other threads:[~2021-07-15 19:53 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-15  5:15 A gdb pretty print for CHAR16 question. Need some gdb help Andrew Fish
2021-07-15 19:53 ` Andrew Fish [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=97ADFF09-B38E-484B-B584-0D5DA916AA81@apple.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox