From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gproxy2-pub.mail.unifiedlayer.com (gproxy2-pub.mail.unifiedlayer.com [69.89.18.3]) by sourceware.org (Postfix) with ESMTPS id B639D3858C27 for ; Sat, 7 May 2022 23:08:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B639D3858C27 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 cmgw12.mail.unifiedlayer.com (unknown [10.0.90.127]) by progateway4.mail.pro1.eigbox.com (Postfix) with ESMTP id C3515100477BA for ; Sat, 7 May 2022 23:08:55 +0000 (UTC) Received: from box5922.bluehost.com ([162.241.30.80]) by cmsmtp with ESMTP id nTXjnQLN2b2WGnTXjnhJTa; Sat, 07 May 2022 23:08:55 +0000 X-Authority-Reason: nr=8 X-Authority-Analysis: v=2.4 cv=SqtVVNC0 c=1 sm=1 tr=0 ts=6276fc07 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=pBbsfl06AAAA:8 a=CCpqsmhAAAAA:8 a=6om16fKZyAX8RHC2GycA:9 a=QEXdDO2ut3YA:10:nop_charset_2 a=Pykvx6M6Og9ney6Qs4Vj:22 a=ul9cdbp4aOFLsgKbc677:22 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=mHE+ocqgwy1KASlvZqOhGYodVjMLPUaLwtNCV10b+4M=; b=sYELJuSOnj49Kuw3hg6MkifNfP AmLfgy5lQ0X7ESkFCf0QuUWePdPFT/4Ogy+RLe10SXSSIV+5h3+a7KxFAOGjWmhkbuAzt35yBs8m6 u56BXbJJGhqjPvYq8ugeFzt45; Received: from static-11-191-147-69.axsne.net ([69.147.191.11]:10405 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 1nnTXj-003Y4O-2S for gcc-help@gcc.gnu.org; Sat, 07 May 2022 17:08:55 -0600 Message-ID: <27202f68e59e9a17aaa96d39659ce73005325cd7.camel@mad-scientist.net> Subject: Re: Help using the GDB C++ STL pretty-printers / xmethods From: Paul Smith Reply-To: paul@mad-scientist.net To: "gcc-help@gcc.gnu.org" Date: Sat, 07 May 2022 19:08:53 -0400 In-Reply-To: References: <5568db74d0acb198a3e8121ee75e3cfa02ea0c6f.camel@mad-scientist.net> <453082091.802975.1651922375216@mail.yahoo.com> <222e7c9b9ac74aa886c1501792e677a0dfa1f268.camel@mad-scientist.net> 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: 1nnTXj-003Y4O-2S 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]:10405 X-Source-Auth: paul@mad-scientist.us X-Email-Count: 1 X-Source-Cap: bWFkc2NpZTE7bWFkc2NpZTE7Ym94NTkyMi5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-1.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, JMQ_SPF_NEUTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, 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 23:08:58 -0000 On Sat, 2022-05-07 at 20:51 +0100, Jonathan Wakely wrote: > On Sat, 7 May 2022 at 20:07, Paul Smith > wrote: > GCC's 'make install' should do everything needed. That installs > $prefix/lib64/libstdc++.so.6.0.30-gdb.py alongside the .so file, and > gdb auto-loads that when debugging a process linked to the > libstdc++.so.6.0.30 library. That python script imports the > register_libstdcxx_printers function and runs it. >=20 > Maybe you're only linking statically to libstdc++.a? Ah. Yes I'm linking statically. > Hmm, that's reminiscent of > https://sourceware.org/bugzilla/show_bug.cgi?id=3D25234 I checked and when I first attach I do see: (gdb) show lang The current source language is "auto; currently c". and things don't work, then after I change to a C++ frame I see: (gdb) show lang The current source language is "auto; currently c++". and things work. I discovered that if I add: set language c++ to my init, that it all works properly. For my purposes this is a sufficient workaround. It's a bit strange (confusing) that the C++ pretty-printers work without having to do that, but the C++ xmethods do not. Also just a data point, my previous GDB (10.2) didn't require this: when I attach with that version, GDB chose the auto language as "c++" immediately. I suppose it's worth a bugzilla report. > All the logic to do that in Python is already present in the > printers, I figured so I'd hoped there was something here already. I get what you're saying of course. Maybe I'll find some time to dig into this... at some point... > > (b) Ways to access the contents of containers like unique_ptr, > > shared_ptr, etc. from python functions.=C2=A0 So if in my class I have > > "std::unique_ptr fooPtr" and in my python functions I have a > > variable "fooPtr" which refers to this object, I would like a way > > to retrieve a gdb.Value containing its pointer. >=20 > The UniquePtrGetWorker Xmethod already does that. You should be able > to just do: >=20 > =C2=A0py ptr =3D gdb.parse_and_eval('uniqptr.get()') xmethods don't help me (IIUC) because I'm in the middle of some Python function and the value I want to retrieve is in a Python variable, not in a GDB variable, so I can't easily access it with parse_and_eval(). For instance in my examples here I'd have a python method: def find_obj(val): if val['mgr']['initialized']: return val['mgr'] return val['otherMgr'] or whatever, but of course I can't do this because val['mgr'] is a std::unique_ptr and I don't know how to dig out the object it points to. The above doesn't need to work as-is: something like: def find_obj(val): mgr =3D StdUnique(val['mgr']).get() if mgr['initialized']: return mgr return val['otherMgr'] or whatever would be fine.