Re: concrete hints on debugging C++ code (compiled with GCC) using GDB (Linux) ?

Arsen Arsenović via Gcc-help <[email protected]> Sun, 25 Jan 2026 11:48:08 +0100
Newsgroups gmane.comp.gcc.help
Message-ID <[email protected]>
Basile Starynkevitch <[email protected]> writes:

> Hello all,
>
>
> In relation to https://github.com/RefPerSys/RefPerSys/issues/30
>
> what are concrete hints to debug such kind of bugs?
>
> How should I configure then compile GCC 16 (e.g. gcc-16-20260118 recent snapshot, symlinked as gcc-16snap)
>
> I did configure it as (in an external build tree, '/usr/src/Lang/_BuildGcc16') with
>
>  /usr/src/Lang/gcc-16snap/configure '-v' '--prefix=/usr/local'
> '--with-gcc-major-version-only' '--program-suffix=-16' '--enable-shared'
> '--enable-plugin' '--enable-default-pie' '--with-system-zlib'
> '--disable-multilib' '--with-tune=native' '--enable-checking=release'
> '--enable-host-shared' '--build=x86_64-linux-gnu' '--host=x86_64-linux-gnu'
> '--target=x86_64-linux-gnu' 'CFLAGS=-g -O2' 'CXXFLAGS=-g -O2' '--enable-werror'
> 'build_alias=x86_64-linux-gnu'
> 'host_alias=x86_64-linux-gnu' 'target_alias=x86_64-linux-gnu'
> '--enable-languages=c,c++,jit,lto' : '/usr/src/Lang/gcc-16snap/configure' '-v'
> '--prefix=/usr/local' '--with-gcc-major-version-only' '--program-suffix=-16'
> '--enable-shared' '--enable-plugin' '--enable-default-pie' '--with-system-zlib'
> '--disable-multilib' '--with-tune=native' '--enable-checking=release'
> '--enable-host-shared' '--build=x86_64-linux-gnu' '--host=x86_64-linux-gnu'
> '--target=x86_64-
> linux-gnu' 'CFLAGS=-g -O2' 'CXXFLAGS=-g -O2' '--enable-werror'
> 'build_alias=x86_64-linux-gnu' 'host_alias=x86_64-linux-gnu'
> 'target_alias=x86_64-linux-gnu' '--enable-languages=c,c++,jit,lto'
>
> How should I configure GDB 17.1 (perhaps also compile it)?
>
> In particular, I want GDB to be able to print/display nicely instances of std::string
> (and maybe even instances of templates like std::map<std::string,int>....)

GCC installs a script for this purpose.  On my machine, it's:

  /usr/share/gdb/auto-load/usr/lib/gcc/x86_64-pc-linux-gnu/16/libstdc++.so.6.0.35-gdb.py

With your --prefix, it's probably /usr/local/share/... or something.

In either case, if placed in the 'auto-load scripts-directory'[1] path
(default: $debugdir:$datadir/auto-load) of gdb, it should just auto-load
it after the subprocess loads libstdc++.

If you let GDB auto-load that file, this should just work:

  (gdb) list
  7       
  8       int
  9       main ()
  10      {
  11        std::string foo {"abcd"};
  12        fn (foo);
  13      }
  (gdb) p foo
  $2 = "abcd"
  (gdb) 

[1] https://sourceware.org/gdb/current/onlinedocs/gdb.html/objfile_002dgdbdotext-file.html
-- 
Arsen Arsenović
signature.asc (application/pgp-signature, 418 B)
-----BEGIN PGP SIGNATURE-----

iQECBAEWCgCqFiEE/uKz0RP8AKMWLWBhUsKUMB6ixJMFAml19OgbFIAAAAAABAAO
bWFudTIsMi41KzEuMTEsMiwyXxSAAAAAAC4AKGlzc3Vlci1mcHJAbm90YXRpb25z
Lm9wZW5wZ3AuZmlmdGhob3JzZW1hbi5uZXRGRUUyQjNEMTEzRkMwMEEzMTYyRDYw
NjE1MkMyOTQzMDFFQTJDNDkzEBxhcnNlbkBhYXJzZW4ubWUACgkQUsKUMB6ixJPK
MAD+PONdVh1OK6eU8y5yxrPfuWrmRHh13I0f3VFiTlqwGa8BALmueT0nfUdHZedy
WLtRFF7HtoWNlxsTcEOiZj4tvG8G
=b+ZQ
-----END PGP SIGNATURE-----