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 F0DA03858C55 for ; Sun, 8 May 2022 19:44:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org F0DA03858C55 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 cmgw14.mail.unifiedlayer.com (unknown [10.0.90.129]) by progateway1.mail.pro1.eigbox.com (Postfix) with ESMTP id C3CF6100401B2 for ; Sun, 8 May 2022 19:44:39 +0000 (UTC) Received: from box5922.bluehost.com ([162.241.30.80]) by cmsmtp with ESMTP id nmpbn3JQq53CXnmpbnirvF; Sun, 08 May 2022 19:44:39 +0000 X-Authority-Reason: nr=8 X-Authority-Analysis: v=2.4 cv=OPfiYQWB c=1 sm=1 tr=0 ts=62781da7 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=udo3KVJ6DhJwFHYo_cQA: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:Cc:To:Reply-To:From:Subject: Message-ID:Sender: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=iQhCObhSpvNjiS6oMfUUfnfT3CdXmHWoNpwzKbyD66o=; b=Pl1ZINnRsh0916yN2LUOs9oVfl PJS3bvNE4iu8zWH7s+C762hXnNxk8GdAaRXZApVAoLvDmYkBzXnbBQzTTrZ0yQNJ/Ri1fqMm0xU3M ilV7QUOsWgydhaYJvSDYWfuEv; Received: from static-11-191-147-69.axsne.net ([69.147.191.11]:10406 helo=[10.200.55.35]) by box5922.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1nnmpb-000RgT-3G; Sun, 08 May 2022 13:44:39 -0600 Message-ID: <7c6d308fdbbcabf83dd5423c33ca851666beaae7.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: Jonathan Wakely Cc: gcc-help Date: Sun, 08 May 2022 15:44:36 -0400 In-Reply-To: References: <5568db74d0acb198a3e8121ee75e3cfa02ea0c6f.camel@mad-scientist.net> <453082091.802975.1651922375216@mail.yahoo.com> <222e7c9b9ac74aa886c1501792e677a0dfa1f268.camel@mad-scientist.net> <27202f68e59e9a17aaa96d39659ce73005325cd7.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: 1nnmpb-000RgT-3G X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: static-11-191-147-69.axsne.net ([10.200.55.35]) [69.147.191.11]:10406 X-Source-Auth: paul@mad-scientist.us X-Email-Count: 1 X-Source-Cap: bWFkc2NpZTE7bWFkc2NpZTE7Ym94NTkyMi5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00, 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: Sun, 08 May 2022 19:44:42 -0000 On Sun, 2022-05-08 at 09:16 +0100, Jonathan Wakely wrote: > > gdb.set_convenience_variable('mgr', val['mgr']) > > init =3D gdb.parse_and_eval('$mgr->initialized') > >=20 > > This will use the xmethod to evaluate the expression. >=20 > And then: >=20 > if init: > =C2=A0 =C2=A0 return gdb.parse_and_eval('*$mgr') Unfortunately, this doesn't work :(. I can't do it from the GDB command line or python (I have tried both with the same results).=20 Something about convenience variables doesn't play well with xmethods=20 (or maybe this xmethod implementation specifically?) Very simple test program: /* /tmp/sleep.cpp */ #include #include class Foo { public: int val =3D 0; }; std::unique_ptr foo; int main() { foo =3D std::make_unique(); sleep(100000); return 0; } Compile it & run it: g++ -ggdb3 -o /tmp/sleep /tmp/sleep.cpp /tmp/sleep & Now attach with GDB (probably you can just run it in GDB but I did it like this so I could detach/reattach): gdb -p Switch to main, set an convenience variable to "foo", then try to use xmethods on it and no joy: (gdb) fr 3 11 sleep(100000); (gdb) p foo $1 =3D std::unique_ptr =3D { get() =3D 0x105aeb0 } (gdb) p foo->val $2 =3D 0 (gdb) set $xx =3D foo (gdb) p $xx $3 =3D std::unique_ptr =3D { get() =3D 0x105aeb0 } (gdb) p $xx->val Attempt to take address of value not located in memory. Same behavior with GDB 10.2 and 12.1.