From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by sourceware.org (Postfix) with ESMTPS id 574903858C27 for ; Sat, 7 May 2022 15:25:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 574903858C27 Received: by mail-wr1-x432.google.com with SMTP id d5so13741421wrb.6 for ; Sat, 07 May 2022 08:25:56 -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=9CclwbN6Z+TkiQ5XQTCHELOsSKj5yQ+jmaOvUAcAoso=; b=tD+gEUF/IgDB8KYx5h5OLJU41jfzlb9RwJHtpdzVGaHMSN0o84fV5XJU+qZr0JpNrq KuJY8mPU52vQq5wta/x1fr5F0pkQRjzUf5f3GwWpZhEwAWxQVruC6QyurKfTPIrFa9xp iIWo1nMLU2QCcT50Nqe5i1PLH3J+84mTGqDC68iLgFm7lS45J4N+6HqqJMXreFbrKk3V nB45RL17s4DLts+C2syZM0ctMiP6mlF0E+caQ+aUA2VcxLwAlzg00dP0ELGLWKXdd2kv +E/NidII69daozc7AL6v5QAyvnSnzdZF+c7TiQm9fBVtor6XcSegGIMdXOSpKYRP9ss3 FpRQ== X-Gm-Message-State: AOAM533p6KHk8aAcU6qGCJRqNFVRbkGTqBc86+pPFNeDikyULnp+wnAy D+1OrmhqZYLD1Hhp1w13RR0m2peGlMpu5ol/V+gGplqBmtA= X-Google-Smtp-Source: ABdhPJy6e8JSQ4qz39phJYbtey3OHp/BW3WvqWNS+1Wkbo93tP7PjkeXkNq/yLNUWZrrERGfwfC6nPboLOeoqT4ETbA= X-Received: by 2002:adf:f943:0:b0:203:b456:c71d with SMTP id q3-20020adff943000000b00203b456c71dmr7099254wrr.568.1651937154946; Sat, 07 May 2022 08:25:54 -0700 (PDT) MIME-Version: 1.0 References: <5568db74d0acb198a3e8121ee75e3cfa02ea0c6f.camel@mad-scientist.net> In-Reply-To: <5568db74d0acb198a3e8121ee75e3cfa02ea0c6f.camel@mad-scientist.net> From: Jonathan Wakely Date: Sat, 7 May 2022 16:25:43 +0100 Message-ID: Subject: Re: Help using the GDB C++ STL pretty-printers / xmethods To: Paul Smith Cc: gcc-help 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:25:58 -0000 On Sat, 7 May 2022 at 02:24, Paul Smith wrote: > > Are there any docs or other information about how to use the GDB > pretty-printers for C++ STL that come with GCC? > > I have them installed and they work for displaying data, but they don't > work for accessing data. > > Just as one very simple example, is there a way to dereference a > unique_ptr? I see xmethods defined but nothing I've tried works. > Suppose I have: > > (gdb) p $mp->mgr > $6 = std::unique_ptr = { > get() = 0x7f519a24e000 > } > > (so you can see the pretty-printers are installed). Now, how do I > extract out this object pointer so I can see what's in it? These don't > work: > > (gdb) p *$mp->mgr > One of the arguments you tried to pass to operator* could not be > converted to what the function wants. > > (gdb) p $mp->mgr->initialized > One of the arguments you tried to pass to operator-> could not be > converted to what the function wants. > > It used to work in GCC 10.2 / GDB 10.1 to access the pointer directly > if you knew, or deciphered, the internal structor of unique_ptr: > > (gdb) p $mp->mgr._M_t._M_t._M_head_impl > > However, with GCC 11.3 / GDB 12.1 this no longer works: I get this > error: > > Request for member '_M_head_impl' is ambiguous in type > 'std::tuple >'. > Candidates are: > 'std::default_delete std::_Head_base<1ul, > std::default_delete, true>::_M_head_impl' (std::tuple std::default_delete > -> std::_Tuple_impl<0ul, Mgr*, > std::default_delete > -> std::_Tuple_impl<1ul, > std::default_delete > -> std::_Head_base<1ul, > std::default_delete, true>) > ' std::_Head_base<0ul, Mgr*, false>::_M_head_impl' > (std::tuple > -> std::_Tuple_impl<0ul, > Mgr*, std::default_delete > -> std::_Head_base<0ul, Mgr*, false>) > > I have found no way to resolve this ambiguity to GDB's satisfaction. The new GDB is correct, see https://sourceware.org/bugzilla/show_bug.cgi?id=28480 To make it work you need to disambiguate the member access by qualifying it with the class you want to access, but you shouldn't need to so I'm not going to waste time figuring out the right voodoo. > > 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? No, your Xmethods aren't working. This works perfectly for me: #include struct Mgr { bool initialized = true; }; struct X { std::unique_ptr mgr; }; int main() { X x; X* p = &x; x.mgr.reset(new Mgr); return 0; // line 18 } (gdb) file a.out Reading symbols from a.out... (gdb) br 18 Breakpoint 1 at 0x401193: file up.C, line 18. (gdb) r Starting program: /tmp/a.out Breakpoint 1, main () at up.C:18 18 return 0; (gdb) set $mp = p (gdb) p *$mp->mgr $1 = {initialized = true} (gdb) p $mp->mgr->initialized $2 = true > Secondly, is there some interface that is defined by the libstdcxx.v6 > Python macros for GDB that people who are doing their own python (Aside: There are no macros involved in any of this) > scripting for their own C++ programs can take advantage of to avoid too > much groveling through the depths of the C++ STL implementation? No. What sort of thing do you have in mind?