From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from sonic309-24.consmr.mail.ir2.yahoo.com (sonic309-24.consmr.mail.ir2.yahoo.com [77.238.179.82]) by sourceware.org (Postfix) with ESMTPS id ACA5E3858C27 for ; Sat, 7 May 2022 15:44:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org ACA5E3858C27 X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1651938294; bh=QeZ504ej145o7w6XaMMZswi/NaCrUUix2yrfu1SeNAL=; h=X-Sonic-MF:Date:From:To:Subject:From:Subject; b=WA75O1EkyQPP37HuFUC+VTM/HJH8AMYHGlx+lSrLi/ksKJ+GuDA8ICA7H90xdZLG6bzXnHCZ4/EMqFPZQEfvb187AiSQ+j1dchUvwO0UprF4oz9rR+BfI/tk522+iihBhyWj7bmgg9bUVCLN96U3ivGPVDli7IGuN7scpVU1yJMz91aiITyV0YBSXxMtV8j+VVsKrjQwjxG6Lu2+FOWbsep6bsVEZpyDrT1oiRzElQ8DHsF+KW0T64YrNLfXyOlCiaWFqYfUIqFGMH85gD89lcq0NVpE2N7IdfmRANEAQVYplD2yhXb2XtUQaSjjGEiRVYFJ0w8mTrqrgJn12Ceqvg== X-YMail-OSG: 3wQ33fwVM1lSZkPVG9pdlg8LZCqr5POz1wph7gVJOLN7JkwMJFi4ZzGO6Vc92Jt gV73IYpHlMsovhLevVlkAZc2cAhytFTWbIxZBwnECxFhc5ggiM47n6_haqR743T55RBlIc3AHGPj qPZ1daKTyiKPntoTTG9MmxNR9JcN9VWJnQJy.2w4Tnl61eqmck1V1wruD3gEvKgUrS3cK9.vQ7oS 8UykOalaFMx1CRYq.Zoz2RabAdGnqovkozzSBFZsFYrwyJnTI8MZoYRDkmjqft0y_M_VtSsUokVf eDsSBcZBKm9zDVdgzBpq20Awl1yIlq6Gf3G0OijLhycfaicUpKge5LIKpLqe7H_MFXw_PMjU1LJN vQB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2EDxIT2VpO_3t8ijC0Ov9EPQIoNwJh.3wURFgX..F_tVf3ew8Owfeh. uEphqVC1Ltxd62wiqDl8twFQKF4G6FC6iaRO.7xam5vFZlCK5g8ikSe3a5o.5WQtinxnbX8lEaXt nKKVc0sH8ASib6Td7BJEGINihBlDZsykesSMt8AVgygsyhXqTE.e80WsZ5.mWwkdpfavSXZkk6Zs CtURLeeRe5sqJQ6Qd3So6uJLbrgPeb2.SFUshOYevVF.k8l6DCn8qd34sZeenl3s_0Bdawy5yYoO o3biwlPY1Pbhc_5Ew.LZKuUVCVGpZYpVoW47e3Xul8AGiAGthlpNoPMUjuIx1DqLXb0zD8h1Ke9Y KaJxac31pQXI4PkgmaoZNXrOgELPD7aRoEQz_4P281neZ01GYApW4oDYtfwMSugEpNt2sn40nIF1 BcLs6yYh.m_KDX8CTtCHa3SWYwXdk3Fl0UCXVjrjHiMWa8dEGVSgUA2C6Ae4Cb3GMXTZnmbDGiIc LPIlKIXrQZLxos.aVgZH_doA7QZM8gfwlZsr.rXuk0hGA6MIoHMvrex8rdybWLHnIhGEN4JUxRbW M0FrbhFBXlxBYZLTsbh6yKSV2sbzJHgipYmeuFaum.ZzrkZdNMw5ZnDQ_2iJIACVxPk24kWuw7xF pdOcPmfO.Mvb.0iY._RLIQeWEj5SF1mioNsjrP6WMd.Nk5FW2eTZ6QiloXBmT5XkFDhcQrLnOjlq lXMLTZgGaxK1sJIg7mrgnqig1xJWVFui.y_O5sJ.m3nu5Ucnn7EtsbO0go09mFXQqrcQTWvgTSQI z76VHAO3y2O1NdHHTxRXoZ.i52A-- X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic309.consmr.mail.ir2.yahoo.com with HTTP; Sat, 7 May 2022 15:44:54 +0000 Date: Sat, 7 May 2022 15:44:54 +0000 (UTC) From: Hannes Domani To: "gcc-help@gcc.gnu.org" , Paul Smith Message-ID: <1686815596.231220.1651938294012@mail.yahoo.com> In-Reply-To: References: <5568db74d0acb198a3e8121ee75e3cfa02ea0c6f.camel@mad-scientist.net> <453082091.802975.1651922375216@mail.yahoo.com> Subject: Re: Help using the GDB C++ STL pretty-printers / xmethods MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Mailer: WebService/1.1.20188 YMailNorrin X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00, BODY_8BITS, 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:44:57 -0000 Am Samstag, 7. Mai 2022, 17:06:49 MESZ hat Paul Smith Folgendes geschrieben: > 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: > > > > > >=C2=A0=C2=A0=C2=A0 (gdb) p *((Mgr*)0x7f519a24e000) > > >=C2=A0=C2=A0=C2=A0 $8 =3D { > > >=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ... > > >=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 initialized =3D true > > >=C2=A0=C2=A0=C2=A0 } > > > > > >=C2=A0=C2=A0=C2=A0 (gdb) p ((Mgr*)0x7f519a24e000)->initialized > > >=C2=A0=C2=A0=C2=A0 $9 =3D 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.=C2=A0 I should have mentioned this; what I do is: > >=C2=A0=C2=A0 python >=C2=A0=C2=A0 from libstdcxx.v6 import register_libstdcxx_printers >=C2=A0=C2=A0 register_libstdcxx_printers(None) >=C2=A0=C2=A0 end > > That method loads both the pretty printers AND the xmethods: > >=C2=A0=C2=A0 # Load the xmethods if GDB supports them. >=C2=A0=C2=A0 def gdb_has_xmethods(): >=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 try: >=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 import gdb.xm= ethod >=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return True >=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 except ImportError: >=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return False > >=C2=A0=C2=A0 def register_libstdcxx_printers(obj): >=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 # Load the pretty-printers. >=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 from .printers import register_libstd= cxx_printers >=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 register_libstdcxx_printers(obj) > >=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if gdb_has_xmethods(): >=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 from .xmethod= s import register_libstdcxx_xmethods >=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 register_libs= tdcxx_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. Yes, this works for me. But maybe you could show a small example program. Do you see a list of available xmethods if you try `info xmethod` in gdb? > > > 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. > > 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.=C2=A0 How do I do that?=C2=A0 Is the= re 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. With working xmethods, calling e.g. gdb.parse_and_eval("$mp->mgr->initializ= ed") should give you the variable. Again, a small reproducer would be helpful. Hannes