From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-yb1-xb33.google.com (mail-yb1-xb33.google.com [IPv6:2607:f8b0:4864:20::b33]) by sourceware.org (Postfix) with ESMTPS id 7EE173858D28 for ; Fri, 5 Nov 2021 19:55:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7EE173858D28 Received: by mail-yb1-xb33.google.com with SMTP id v64so25514895ybi.5 for ; Fri, 05 Nov 2021 12:55:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=rlecgTZ6iZz+DAGNHHBp7hBhvjtmber77FZ0qc2mlYs=; b=TbokrRHrHfB3RbV5TBC/5KWGLxHEVEw6tNvookr8zm+oPqi9qZrqsGgOK6Tk5ybwSh H5hWhjJiZ3B3UJGE16WCB+/xYlUdTbwx37bM9WL2v0DAi2sQOKyP3EdvWE5l0e2zsjW6 NRKO765zOE/PoYkcTsi7D6tEQTECxsYnDNRpoo/9+jfcCvwRbBoxyrzks5xNCVr4ZgIa 0LWA6gduLfPkKKLhojnsueBRP2N8mP9D27C3iqSoYdowcROv8JZTwSmhAxV4mRA7HS7X eV61GoyEE0VwxMd2R4W7ZcQXAQRCVkurmpgpewl//WUe4IqCXdqoILOa95+7FWCEVcKz 96jw== X-Gm-Message-State: AOAM530OQep7AD+OS55tzA5WBXHs04FuQGurqQKTxbgDijPW7uo3Jxtz hoE51Ja7XEtltQuUV84aAuvMVrDdInxlPONy9Fhoe7gG X-Google-Smtp-Source: ABdhPJyUOPnFoVjMR756KsgVjq+mLH22L6vn5JB8YLnJrb2bWhkTHUzhcUGUrF5ZAGQytsoo8UMRiax2EXkiTlO2SFI= X-Received: by 2002:a25:183:: with SMTP id 125mr36970947ybb.143.1636142138121; Fri, 05 Nov 2021 12:55:38 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: David Blaikie Date: Fri, 5 Nov 2021 12:55:27 -0700 Message-ID: Subject: Re: Concatenating LazyStrings To: Luke Drummond , Tom Tromey Cc: gdb X-Spam-Status: No, score=0.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, HTML_MESSAGE, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: gdb@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 05 Nov 2021 19:55:40 -0000 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 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 >