[llvm] r335561 - [gdb] Escape unprintable bytes in SmallString and StringRef
David Blaikie via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 5 12:58:06 PDT 2021
On Wed, Nov 3, 2021 at 3:02 PM Fāng-ruì Sòng <maskray at google.com> wrote:
> On Wed, Nov 3, 2021 at 2:23 PM David Blaikie <dblaikie at gmail.com> wrote:
> >
> > Hey Ray - do you recall what the motivation for this patch was/is? I ask
> because this breaks gdb's ability to truncate long strings (which means
> printing out data structures with StringRefs that refer to, for instance,
> the entire contents of an object/executable, or of a section in such a file
> - is unfortunate/locks up the debugger for ages printing things out) and it
> looks like gdb escapes unprintable characters itself, without the need to
> do this manually so far as I can tell?
>
> It's been 3 years so I cannot remember. If I made the change, likely
> because gdb at that time did not display strings correctly and this
> commit fixed the problem.
> It's possible that gdb's behavior changed or somehow the commit's
> behavior becomes harmful now.
>
> I think I do notice some string stuff does not look pretty, but
> haven't spent time investigating the problem.
>
Sure sure - yeah, eventually did find the sort of problems this was
addressing. Not sure why I didn't reproduce it earlier.
In any case the libstdc++ pretty printer works around/addresses this by
using lazy_string/gdb.LazyString - which mostly addresses our uses too,
though Twine still presents a problem (std::string's pretty printer can
produce a lazy string and I don't know how to concatenate that with a
normal string (or another lazy string, for that matter) - I sent mail to
the gdb list about that, maybe they'll have some suggestions).
Committed
https://github.com/llvm/llvm-project/commit/def232915f81ce391ef54b8a7af85c6729a6d359
and
https://github.com/llvm/llvm-project/commit/baa820c510d027911b464ee018e15217d09568da
which should hopefully help things a bit.
> On Mon, Jun 25, 2018 at 5:46 PM Fangrui Song via llvm-commits <
> llvm-commits at lists.llvm.org> wrote:
> >>
> >> Author: maskray
> >> Date: Mon Jun 25 17:41:49 2018
> >> New Revision: 335561
> >>
> >> URL: http://llvm.org/viewvc/llvm-project?rev=335561&view=rev
> >> Log:
> >> [gdb] Escape unprintable bytes in SmallString and StringRef
> >>
> >> Modified:
> >> llvm/trunk/utils/gdb-scripts/prettyprinters.py
> >>
> >> Modified: llvm/trunk/utils/gdb-scripts/prettyprinters.py
> >> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/gdb-scripts/prettyprinters.py?rev=335561&r1=335560&r2=335561&view=diff
> >>
> ==============================================================================
> >> --- llvm/trunk/utils/gdb-scripts/prettyprinters.py (original)
> >> +++ llvm/trunk/utils/gdb-scripts/prettyprinters.py Mon Jun 25 17:41:49
> 2018
> >> @@ -11,6 +11,8 @@ class Iterator:
> >> def children(self):
> >> return self
> >>
> >> +def escape_bytes(val, l):
> >> + return '"' + val.string(encoding='Latin-1',
> length=l).encode('unicode_escape').decode() + '"'
> >>
> >> class SmallStringPrinter:
> >> """Print an llvm::SmallString object."""
> >> @@ -21,10 +23,7 @@ class SmallStringPrinter:
> >> def to_string(self):
> >> begin = self.val['BeginX']
> >> end = self.val['EndX']
> >> - return begin.cast(gdb.lookup_type("char").pointer()).string(length
> = end - begin)
> >> -
> >> - def display_hint (self):
> >> - return 'string'
> >> + return escape_bytes(begin.cast(gdb.lookup_type('char').pointer()),
> end - begin)
> >>
> >> class StringRefPrinter:
> >> """Print an llvm::StringRef object."""
> >> @@ -33,10 +32,7 @@ class StringRefPrinter:
> >> self.val = val
> >>
> >> def to_string(self):
> >> - return self.val['Data'].string(encoding='Latin-1',
> length=self.val['Length'])
> >> -
> >> - def display_hint (self):
> >> - return 'string'
> >> + return escape_bytes(self.val['Data'], self.val['Length'])
> >>
> >> class SmallVectorPrinter:
> >> """Print an llvm::SmallVector object."""
> >>
> >>
> >> _______________________________________________
> >> llvm-commits mailing list
> >> llvm-commits at lists.llvm.org
> >> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
>
>
> --
> 宋方睿
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211105/2d5bbc9f/attachment.html>
More information about the llvm-commits
mailing list