* Concatenating LazyStrings
@ 2021-11-05 3:14 David Blaikie
2021-11-05 12:22 ` Luke Drummond
0 siblings, 1 reply; 3+ messages in thread
From: David Blaikie @ 2021-11-05 3:14 UTC (permalink / raw)
To: gdb
If I've got a pretty printer (for instance, for llvm's Twine type (
https://github.com/llvm/llvm-project/blob/6d03227c16ee1950db0e1aa05fbc3201770248eb/llvm/utils/gdb-scripts/prettyprinters.py#L354
+ https://llvm.org/doxygen/classllvm_1_1Twine.html ) that wants to pretty
print a string made up of other strings (from other pretty printers) - how
would I do that?
Specifically, I can't figure out how to correctly concatenate a gdb
LazyString value with another string. (even if I have to stringify the
LazyString (making it unlazy) in the process - calling ".value()" on the
LazyString doesn't seem to be enough - I can't seem to figure out how to
to-string-ify that resulting gdb Value (it doesn't have a pretty printer
that I can find - nor a to_string/str/string() function) to then
concatenate it with another string)
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Concatenating LazyStrings
2021-11-05 3:14 Concatenating LazyStrings David Blaikie
@ 2021-11-05 12:22 ` Luke Drummond
2021-11-05 19:55 ` David Blaikie
0 siblings, 1 reply; 3+ messages in thread
From: Luke Drummond @ 2021-11-05 12:22 UTC (permalink / raw)
To: David Blaikie, gdb
Hi David
On Fri Nov 5, 2021 at 3:14 AM GMT, David Blaikie via Gdb wrote:
> If I've got a pretty printer (for instance, for llvm's Twine type (
> https://github.com/llvm/llvm-project/blob/6d03227c16ee1950db0e1aa05fbc3201770248eb/llvm/utils/gdb-scripts/prettyprinters.py#L354
> + https://llvm.org/doxygen/classllvm_1_1Twine.html ) that wants to
> pretty
> print a string made up of other strings (from other pretty printers) -
> how
> would I do that?
>
> Specifically, I can't figure out how to correctly concatenate a gdb
> LazyString value with another string. (even if I have to stringify the
> LazyString (making it unlazy) in the process - calling ".value()" on the
> LazyString doesn't seem to be enough - I can't seem to figure out how to
> to-string-ify that resulting gdb Value (it doesn't have a pretty printer
> that I can find - nor a to_string/str/string() function) to then
> concatenate it with another string)
`LazyString.value().format_string()` might be what you want. I've also found the
python builtin `str()` function to be usable in many places.
https://sourceware.org/gdb/onlinedocs/gdb/Values-From-Inferior.html#Values-From-Inferior
has the documentation if you haven't already seen it.
As an example, here's how I format an enumeration that's made up of bit-flags:
def fmt_flags_enum(enum_type, val):
val = int(val)
return ' | '.join(
gdb.Value((1 << x) & val).cast(enum_type).format_string()
for x in range(val.bit_length())
if (1 << x) & val
)
The `format_string()` converts the individual enumerators into a string that
python can concatenate with `str.join`.
Hope that helps.
All the Best
Luke
--
Codeplay Software Ltd.
Company registered in England and Wales, number: 04567874
Registered office: Regent House, 316 Beulah Hill, London, SE19 3HF
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Concatenating LazyStrings
2021-11-05 12:22 ` Luke Drummond
@ 2021-11-05 19:55 ` David Blaikie
0 siblings, 0 replies; 3+ messages in thread
From: David Blaikie @ 2021-11-05 19:55 UTC (permalink / raw)
To: Luke Drummond, Tom Tromey; +Cc: gdb
Oh, huh, just gdb::Value's "string()" worked for me in the end - I was
dealing with some other layers of indirection/existing oddities in my
pretty printer codebase that had complicated things.
Thanks for the nudges in the right direction!
On Fri, Nov 5, 2021 at 5:22 AM Luke Drummond <luke.drummond@codeplay.com>
wrote:
> Hi David
>
> On Fri Nov 5, 2021 at 3:14 AM GMT, David Blaikie via Gdb wrote:
> > If I've got a pretty printer (for instance, for llvm's Twine type (
> >
> https://github.com/llvm/llvm-project/blob/6d03227c16ee1950db0e1aa05fbc3201770248eb/llvm/utils/gdb-scripts/prettyprinters.py#L354
> > + https://llvm.org/doxygen/classllvm_1_1Twine.html ) that wants to
> > pretty
> > print a string made up of other strings (from other pretty printers) -
> > how
> > would I do that?
> >
> > Specifically, I can't figure out how to correctly concatenate a gdb
> > LazyString value with another string. (even if I have to stringify the
> > LazyString (making it unlazy) in the process - calling ".value()" on the
> > LazyString doesn't seem to be enough - I can't seem to figure out how to
> > to-string-ify that resulting gdb Value (it doesn't have a pretty printer
> > that I can find - nor a to_string/str/string() function) to then
> > concatenate it with another string)
>
>
> `LazyString.value().format_string()` might be what you want. I've also
> found the
> python builtin `str()` function to be usable in many places.
>
> https://sourceware.org/gdb/onlinedocs/gdb/Values-From-Inferior.html#Values-From-Inferior
>
> has the documentation if you haven't already seen it.
>
> As an example, here's how I format an enumeration that's made up of
> bit-flags:
>
> def fmt_flags_enum(enum_type, val):
> val = int(val)
> return ' | '.join(
> gdb.Value((1 << x) &
> val).cast(enum_type).format_string()
> for x in range(val.bit_length())
> if (1 << x) & val
> )
>
>
> The `format_string()` converts the individual enumerators into a string
> that
> python can concatenate with `str.join`.
>
> Hope that helps.
>
> All the Best
>
> Luke
>
>
> --
> Codeplay Software Ltd.
> Company registered in England and Wales, number: 04567874
> Registered office: Regent House, 316 Beulah Hill, London, SE19 3HF
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-11-05 19:55 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-05 3:14 Concatenating LazyStrings David Blaikie
2021-11-05 12:22 ` Luke Drummond
2021-11-05 19:55 ` David Blaikie
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).