From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by sourceware.org (Postfix) with ESMTPS id 6E0783857C4A for ; Sun, 8 May 2022 08:14:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6E0783857C4A Received: by mail-wr1-x42d.google.com with SMTP id b19so15515803wrh.11 for ; Sun, 08 May 2022 01:14:11 -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=0627IOzNJxJ5qf8eTZdJHoEoSInPzueBBTF7VTij08g=; b=bdSUJn9dFakooZcfvcALq7g4gyCohYAi82fcMpuQj3U1AZXVimEvnJl2vIczlY5+OC kLxsacF/POlarum8PBJTFen4fKB56/qINGUC03sGPvAl1Gj4gPvVojQAur5RjW4C9BW1 m4TCrn149/yKveXeivyHazLAFx4TY+SgSjgZ4YroIrOA8Ve0kxFG167GRoA68r6PUfh9 Gm0S4p23zZLlS1388l8gNEN0+v+IxKiMADL7X6nsswgLZqzNxoYV8VqAyolJSbQsgj45 o8ISGd5HlzmMY1h2edhwvTOBAIP659n51sgti9pL5xjByEsR1v4k+9rCP1BnLZuPlId/ B0UA== X-Gm-Message-State: AOAM531RmUG7EwlGYWDRg2y2U1X63JM38MLaRxjY8XhJrffH6Si8P5Ot kupLxq6bxLYJ6iO4idPZDA18I3YHC5Pzl8iDmr7v1cDb X-Google-Smtp-Source: ABdhPJyy+M3nk8pdfJwWiLgbKSNyH9CptyTWOAnjn40ASOAOt2Cp18xIWxLqHLOFbYmgpdSEWJlqA3Cg3Rz4LEZm2tM= X-Received: by 2002:adf:f943:0:b0:203:b456:c71d with SMTP id q3-20020adff943000000b00203b456c71dmr9251019wrr.568.1651997650215; Sun, 08 May 2022 01:14:10 -0700 (PDT) MIME-Version: 1.0 References: <5568db74d0acb198a3e8121ee75e3cfa02ea0c6f.camel@mad-scientist.net> <453082091.802975.1651922375216@mail.yahoo.com> <222e7c9b9ac74aa886c1501792e677a0dfa1f268.camel@mad-scientist.net> <27202f68e59e9a17aaa96d39659ce73005325cd7.camel@mad-scientist.net> In-Reply-To: <27202f68e59e9a17aaa96d39659ce73005325cd7.camel@mad-scientist.net> From: Jonathan Wakely Date: Sun, 8 May 2022 09:13:57 +0100 Message-ID: Subject: Re: Help using the GDB C++ STL pretty-printers / xmethods To: Paul Smith Cc: gcc-help 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, HTML_MESSAGE, 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 Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.29 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 08:14:13 -0000 On Sun, 8 May 2022, 00:09 Paul Smith, wrote: > 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. > > > > 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=25234 > > 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. 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. > > > > The UniquePtrGetWorker Xmethod already does that. You should be able > > to just do: > > > > py ptr = 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 = StdUnique(val['mgr']).get() > if mgr['initialized']: > return mgr > return val['otherMgr'] > > or whatever would be fine. > gdb.set_convenience_variable('mgr', val['mgr']) init = gdb.parse_and_eval('$mgr->initialized') This will use the xmethod to evaluate the expression. >