From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by sourceware.org (Postfix) with ESMTPS id B74EE3858C27 for ; Sat, 7 May 2022 15:35:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B74EE3858C27 Received: by mail-wm1-x331.google.com with SMTP id c190-20020a1c35c7000000b0038e37907b5bso8483919wma.0 for ; Sat, 07 May 2022 08:35:41 -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=bk60QSKTGzMtP10JJ4SHqj/kdWdqUsXRqb65Ppn9csI=; b=IMdSnAfUg7L8rt9mKgXXutxvIHfnjEhnrqX1KHODCiYWN+02G0/YLEAPDShQ/mdYnA rvccWYKNCQ37GBy1G8I5fHQQsquAoyZ98LajprtIb5BiaHWFHUQ4Pmt8bfUqeDrNV62Q shp97mj1ejRSp+MFtAMwKxaHiSE5cbjFehY1h/xDhOoGmWjmEruCTzYe/AZo3Tk5lp5B Z15vsKw1K+C/8MkgbQd+g/7HCX7jNUJgHmkLxsbeCmLH8H4/X7gbql0OsuWYGRuD8JOU VAEvZpAv0z9L+kUUTNJzfyRD9/jh+nwruTUdk0JhcPLobnCyvHhLNfdE1ARzYT82NpAY o5WA== X-Gm-Message-State: AOAM533y67PdqGeEyg0fopge19L1yqg/z4nxscWGAnaFf3IM87o/7fhl AWeRCHoPd/TaKYb1YNOxcZweWAILjMmCHph5GFM= X-Google-Smtp-Source: ABdhPJxOq1bGhePMmjmDdZbkocBMBVLdrvyZzYNqvbsxtxY1rXA2TjCZymaRLHLorqlYMJ+PQYGp2ukK0WhbWTBZk8Q= X-Received: by 2002:a7b:c4cc:0:b0:394:7d6c:fdf4 with SMTP id g12-20020a7bc4cc000000b003947d6cfdf4mr7028115wmk.163.1651937740382; Sat, 07 May 2022 08:35:40 -0700 (PDT) MIME-Version: 1.0 References: <5568db74d0acb198a3e8121ee75e3cfa02ea0c6f.camel@mad-scientist.net> <453082091.802975.1651922375216@mail.yahoo.com> In-Reply-To: From: Jonathan Wakely Date: Sat, 7 May 2022 16:35:29 +0100 Message-ID: Subject: Re: Help using the GDB C++ STL pretty-printers / xmethods To: Paul Smith Cc: Hannes Domani , "gcc-help@gcc.gnu.org" Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-help@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-help mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 07 May 2022 15:35:43 -0000 On Sat, 7 May 2022 at 16:08, Paul Smith wrote: > > On Sat, 2022-05-07 at 11:19 +0000, Hannes Domani wrote: > > > The only thing I've found that works is just to access the pointer > > > value directly by cutting and pasting it with a cast: > > > > > > (gdb) p *((Mgr*)0x7f519a24e000) > > > $8 = { > > > ... > > > initialized = true > > > } > > > > > > (gdb) p ((Mgr*)0x7f519a24e000)->initialized > > > $9 = true > > > > > > Is that really what we have to do? > > > > I'm assuming you installed the pretty printers with a call to > > register_libstdcxx_printers() somewhere. > > For access to C++ STL objects there is another set of gdb helpers, > > called xmethods, which you need to install with a call to > > register_libstdcxx_xmethods(). > > Thanks for the reply. I should have mentioned this; what I do is: > > python > from libstdcxx.v6 import register_libstdcxx_printers > register_libstdcxx_printers(None) > end Why are you doing this by hand? That should not be necessary. > > That method loads both the pretty printers AND the xmethods: > > # Load the xmethods if GDB supports them. > def gdb_has_xmethods(): > try: > import gdb.xmethod > return True > except ImportError: > return False > > def register_libstdcxx_printers(obj): > # Load the pretty-printers. > from .printers import register_libstdcxx_printers > register_libstdcxx_printers(obj) > > if gdb_has_xmethods(): > from .xmethods import register_libstdcxx_xmethods > register_libstdcxx_xmethods(obj) > > Just to verify I've tried explicitly loading and calling > register_libstdcxx_xmethods() and I get an error saying they're already > loaded. > > Just to clarify are you saying that one or both of the methods I've > tried (using * or -> operators) _should_ work, and that they do work > for you when you try them? Yes. > > If so then I guess I'm doing something wrong and I will have to look > more deeply. > > > > Secondly, is there some interface that is defined by the > > > libstdcxx.v6 Python macros for GDB that people who are doing their > > > own python scripting for their own C++ programs can take advantage > > > of to avoid too much groveling through the depths of the C++ STL > > > implementation? > > > > Depends on what you want to do with it, but you can get access to the > > pretty printers in gdb with a call to gdb.default_visualizer() [1]. > > I'm not talking about printing things per se, I'm talking about writing > my own python macros that help me examine my own data structures, which > are built with STL types. > > For example I have a complex structure that uses std::vector, > std::list, std:unordered_map, unique_ptr, etc. and I want to write my > own methods that examine these structures, either to print them in a > different way (not just the standard pretty-printer output) or > whatever. That sounds useful, but it's unlikely anybody else is going to provide it. If you want it, you get to build it :-) > > So I have a Python variable containing a pointer to this object that > contains a unique_ptr, and I want to get a variable containing the > pointer contained in the unique_ptr. How do I do that? Is there some > Python function available in the macros that will do that for me? Still no macros anywhere here :-) > > As I said in my previous message, with GCC 11 it doesn't seem like I > can just get the _M_head_impl value any longer, as I get these > "ambiguous" failures. > > Basically I can't use any of the new versions of GCC until I can figure > out how to debug them in a reasonable way. (gdb) p *static_cast&>(p->mgr._M_t._M_t)._M_head_impl $10 = {initialized = true}