From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from alt-proxy28.mail.unifiedlayer.com (alt-proxy28.mail.unifiedlayer.com [74.220.216.123]) by sourceware.org (Postfix) with ESMTPS id 6D21B3858C27 for ; Sat, 7 May 2022 15:07:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6D21B3858C27 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=mad-scientist.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mad-scientist.net Received: from cmgw13.mail.unifiedlayer.com (unknown [10.0.90.128]) by progateway1.mail.pro1.eigbox.com (Postfix) with ESMTP id 887161003FA2B for ; Sat, 7 May 2022 15:07:23 +0000 (UTC) Received: from box5922.bluehost.com ([162.241.30.80]) by cmsmtp with ESMTP id nM1jnIue4Y8ycnM1jnrqDQ; Sat, 07 May 2022 15:07:23 +0000 X-Authority-Reason: nr=8 X-Authority-Analysis: v=2.4 cv=TZJTCTch c=1 sm=1 tr=0 ts=62768b2b a=u+82WREdhvUKZ7QTvcqjvQ==:117 a=u+82WREdhvUKZ7QTvcqjvQ==:17 a=dLZJa+xiwSxG16/P+YVxDGlgEgI=:19 a=IkcTkHD0fZMA:10:nop_charset_1 a=oZkIemNP1mAA:10:nop_rcvd_month_year a=3EOfIcITIxQA:10:endurance_base64_authed_username_1 a=PfU_NOtO25mLA8KMyF8A:9 a=QEXdDO2ut3YA:10:nop_charset_2 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mad-scientist.us; s=default; h=MIME-Version:Content-Transfer-Encoding: Content-Type:References:In-Reply-To:Date:To:Reply-To:From:Subject:Message-ID: Sender:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=ceryMo4ApvvXDc3pwby6p1G4jVWkvU55nZtIzwn8w2c=; b=lSUZwwG/Tk+fF/l3FjmZOAim38 HzJevejj58wToFUtKWXmYx7vJLONkt9/6kpj/hM3mhFnOo9Ev5U3hNrsGCpGR/FMu/VVN47b212zx xdjSO0VFIkM3Lny5juNNN/fTm; Received: from static-11-191-147-69.axsne.net ([69.147.191.11]:10403 helo=[10.200.118.216]) by box5922.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1nnM1i-002pqW-ME; Sat, 07 May 2022 09:07:22 -0600 Message-ID: Subject: Re: Help using the GDB C++ STL pretty-printers / xmethods From: Paul Smith Reply-To: paul@mad-scientist.net To: Hannes Domani , "gcc-help@gcc.gnu.org" Date: Sat, 07 May 2022 11:07:21 -0400 In-Reply-To: <453082091.802975.1651922375216@mail.yahoo.com> References: <5568db74d0acb198a3e8121ee75e3cfa02ea0c6f.camel@mad-scientist.net> <453082091.802975.1651922375216@mail.yahoo.com> Organization: Please remain calm--I may be mad but I am a professional! Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.44.1 (by Flathub.org)) MIME-Version: 1.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5922.bluehost.com X-AntiAbuse: Original Domain - gcc.gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - mad-scientist.net X-BWhitelist: no X-Source-IP: 69.147.191.11 X-Source-L: No X-Exim-ID: 1nnM1i-002pqW-ME X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: static-11-191-147-69.axsne.net ([10.200.118.216]) [69.147.191.11]:10403 X-Source-Auth: paul@mad-scientist.us X-Email-Count: 1 X-Source-Cap: bWFkc2NpZTE7bWFkc2NpZTE7Ym94NTkyMi5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=0.6 required=5.0 tests=BAYES_00, BODY_8BITS, DKIM_SIGNED, DKIM_VALID, JMQ_SPF_NEUTRAL, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=no 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:07:25 -0000 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: > >=20 > > =C2=A0=C2=A0 (gdb) p *((Mgr*)0x7f519a24e000) > > =C2=A0=C2=A0 $8 =3D { > > =C2=A0=C2=A0=C2=A0=C2=A0 ... > > =C2=A0=C2=A0=C2=A0=C2=A0 initialized =3D true > > =C2=A0=C2=A0 } > >=20 > > =C2=A0=C2=A0 (gdb) p ((Mgr*)0x7f519a24e000)->initialized > > =C2=A0=C2=A0 $9 =3D true > >=20 > > Is that really what we have to do? >=20 > 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 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? 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? >=20 > 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. 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? 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.