From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 117488 invoked by alias); 16 Mar 2019 14:25:54 -0000 Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org Received: (qmail 117470 invoked by uid 89); 16 Mar 2019 14:25:54 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-4.6 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.1 spammy=H*UA:Webmail, H*UA:Roundcube, H*u:Webmail, H*u:Roundcube X-HELO: smtp.polymtl.ca Received: from smtp.polymtl.ca (HELO smtp.polymtl.ca) (132.207.4.11) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 16 Mar 2019 14:25:52 +0000 Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id x2GEPjP5014903 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Sat, 16 Mar 2019 10:25:50 -0400 Received: by simark.ca (Postfix, from userid 112) id 7D9351E78F; Sat, 16 Mar 2019 10:25:45 -0400 (EDT) Received: from simark.ca (localhost [127.0.0.1]) by simark.ca (Postfix) with ESMTP id F18F31E4A5; Sat, 16 Mar 2019 10:25:43 -0400 (EDT) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Sat, 16 Mar 2019 14:25:00 -0000 From: Simon Marchi To: Eli Zaretskii Cc: asmwarrior , gdb@sourceware.org Subject: Re: How to load C++ pretty-printers In-Reply-To: <83sgvnx9g1.fsf@gnu.org> References: <835zsjz0f8.fsf@gnu.org> <83sgvnx9g1.fsf@gnu.org> Message-ID: X-Sender: simon.marchi@polymtl.ca User-Agent: Roundcube Webmail/1.3.6 X-IsSubscribed: yes X-SW-Source: 2019-03/txt/msg00040.txt.bz2 On 2019-03-16 08:58, Eli Zaretskii wrote: >> From: asmwarrior >> Date: Sat, 16 Mar 2019 20:41:13 +0800 >> >> Under My Windows 7 system, I'm using such commands(I put them in a >> my.gdb script file) to load and register the pretty printers. >> I put the libstdcxx folder in the same folder as the my.gdb file. >> >> >> set auto-load safe-path $debugdir;$datadir/auto-load >> python >> import sys >> sys.path.insert(0, '') >> from libstdcxx.v6.printers import register_libstdcxx_printers >> # load other pretty printers >> end > > Thanks, but I don't think I understand which part(s) of this are > necessary in my case. E.g., is the "set auto-load" command > needed/relevant? And what is the my.gdb file, I don't think I have > such a file on my system. The pretty-printers that came with GCC are > installed where the GCC installation puts them, and I'd prefer not to > change that if possible. > > Also, which of the commands you've shown actually loads the > pretty-printers from their file? > > Thanks again for your response. If it can help, I have something similar to that in my .gdbinit (whereas asmwarrior has put the same content in a separate file, my.gdb, which they then source by hand). When libstdc++ is linked dynamically with a program and you debug that program, GDB will "auto-load" the file corresponding to the libstdc++ shared library. In my case, it's at "/usr/share/gdb/auto-load/usr/lib/libstdc++.so.6.0.25-gdb.py". This file tries to find where the GCC-provided libstdc++ pretty printers are installed, and adds this path to the Python import path. It then calls register_libstdcxx_printers, a function provided by the libstdc++ pretty printers. When libstdc++ is linked statically, the auto-load does not happen, as you mentioned. So the idea here is to replicate what the auto-load script does, but by hand. In my case, I have these lines to adjust the Python import path to add GCC's pretty printers directory: python import sys python sys.path.insert(0, '/usr/share/gcc-8.2.1/python') And then I manually trigger the GDB auto-load script, that would normally be sourced automatically when loading the libstdc++ shared lib: source /usr/share/gdb/auto-load/usr/lib/libstdc++.so.6.0.25-gdb.py The "set auto-load safe-path" line is to define it is safe to auto-load things from. If you are missing something, you should know quickly enough, as GDB will print you a warning, saying it didn't auto-load X, because X is not in a safe path (as well as information about how to adjust it). Hope this helps, Simon