diff mbox series

libstdc++: Install libstdc++*-gdb.py more robustly [PR 99453]

Message ID 20210403185659.279992-1-levraiphilippeblain@gmail.com
State New
Headers show
Series libstdc++: Install libstdc++*-gdb.py more robustly [PR 99453] | expand

Commit Message

Philippe Blain April 3, 2021, 6:56 p.m. UTC
In order for GDB to auto-load the pretty printers, they must be installed
as "libstdc++.$ext-gdb.py", where 'libstdc++.$ext' is the name of the
object file that is loaded by GDB [1], i.e. the libstdc++ shared library.

The approach taken in libstdc++-v3/python/Makefile.am is to loop over
files matching 'libstdc++*' in $(DESTDIR)$(toolexeclibdir) and choose
the last file matching that glob that is not a symlink, the Libtool
'*.la' file or a Python file.

That works fine for ELF targets where the matching names are:

  libstdc++.a
  libstdc++.so
  libstdc++.so.6
  libstdc++.so.6.0.29

But not for macOS with:

  libstdc++.6.dylib
  libstdc++.a

Or MinGW with:

  libstdc++-6.dll
  libstdc++.dll.a

Try to make a better job at installing the pretty printers with the
correct name by copying the approach taken by isl [2], that is, using
a sed invocation on the the Libtool-generated 'libstdc++.la' to read the
correct name for the current platform.

[1] https://sourceware.org/gdb/onlinedocs/gdb/objfile_002dgdbdotext-file.html
[2] https://repo.or.cz/isl.git/blob/HEAD:/Makefile.am#l611

libstdc++-v3/
	PR libstdc++/99453
	* python/Makefile.am: Install libstdc++*-gdb.py more robustly
	* python/Makefile.in: Regenerate

Co-authored-by: Jonathan Wakely <jwakely@redhat.com>
---

Notes:
    Hello, this is my first patch to this project.
    
    This patch aims to install the GDB Python file for libstdc++ more robustly so
    that it is automatically loaded on more platforms. I tested that it gets
    installed with the correct name on Ubuntu (x86_64-pc-linux-gnu) and macOS
    (x86_64-apple-darwin19.6.0). I did not succeed in building GCC on Windows, I'm
    very new to this platform.
    
    Here are examples of successful builds on these two platforms (you must be
    logged in on GitHub to see the details):
    
    Ubuntu: https://github.com/phil-blain/gcc/runs/2103367197?check_suite_focus=true#step:6:5
    macOS: https://github.com/phil-blain/gcc/runs/2103367199?check_suite_focus=true#step:6:5
    
    Fetch-It-Via: git fetch https://github.com/phil-blain/gcc libstdcxx-pretty-printers-install-filename

 libstdc++-v3/python/Makefile.am | 20 ++++----------------
 1 file changed, 4 insertions(+), 16 deletions(-)


base-commit: 6e885ad3287388192e52e9b524dbaa408507c0a4

Comments

Jonathan Wakely April 21, 2021, 3:56 p.m. UTC | #1
On 03/04/21 14:56 -0400, Philippe Blain wrote:
>In order for GDB to auto-load the pretty printers, they must be installed
>as "libstdc++.$ext-gdb.py", where 'libstdc++.$ext' is the name of the
>object file that is loaded by GDB [1], i.e. the libstdc++ shared library.
>
>The approach taken in libstdc++-v3/python/Makefile.am is to loop over
>files matching 'libstdc++*' in $(DESTDIR)$(toolexeclibdir) and choose
>the last file matching that glob that is not a symlink, the Libtool
>'*.la' file or a Python file.
>
>That works fine for ELF targets where the matching names are:
>
>  libstdc++.a
>  libstdc++.so
>  libstdc++.so.6
>  libstdc++.so.6.0.29
>
>But not for macOS with:
>
>  libstdc++.6.dylib
>  libstdc++.a
>
>Or MinGW with:
>
>  libstdc++-6.dll
>  libstdc++.dll.a
>
>Try to make a better job at installing the pretty printers with the
>correct name by copying the approach taken by isl [2], that is, using
>a sed invocation on the the Libtool-generated 'libstdc++.la' to read the
>correct name for the current platform.
>
>[1] https://sourceware.org/gdb/onlinedocs/gdb/objfile_002dgdbdotext-file.html
>[2] https://repo.or.cz/isl.git/blob/HEAD:/Makefile.am#l611
>
>libstdc++-v3/
>	PR libstdc++/99453
>	* python/Makefile.am: Install libstdc++*-gdb.py more robustly
>	* python/Makefile.in: Regenerate
>
>Co-authored-by: Jonathan Wakely <jwakely@redhat.com>
>---

Hi Philippe,

Now that gcc-11 has branched from trunk we can go ahead with this.
The change is small enough to not require a copyright assignment, so
I've pushed your patch to trunk.

I would expect this to get backported to the release branches once
it's had some time to bake on the trunk.

>
>Notes:
>    Hello, this is my first patch to this project.
>
>    This patch aims to install the GDB Python file for libstdc++ more robustly so
>    that it is automatically loaded on more platforms. I tested that it gets
>    installed with the correct name on Ubuntu (x86_64-pc-linux-gnu) and macOS
>    (x86_64-apple-darwin19.6.0). I did not succeed in building GCC on Windows, I'm
>    very new to this platform.

I checked my x86_64-w64-mingw32 cross-compiler and I see this in
libstdc++.la:

# The name that we can dlopen(3).
dlname='libstdc++-6.dll'

# Names of this library.
library_names='libstdc++.dll.a'

# The name of the static archive.
old_library='libstdc++.a'


That means this patch won't have any effect on Windows, because it
already installs the hook file as libstdc++.dll.a-gdb.py

I don't know if that is correct, or whether it should be installed as
libstdc++-6.dll-gdb.py, but either way this change isn't going to make
it any worse. If we need to do something different for Windows we can
improve it further later.

Thanks for the fix!



>    Here are examples of successful builds on these two platforms (you must be
>    logged in on GitHub to see the details):
>
>    Ubuntu: https://github.com/phil-blain/gcc/runs/2103367197?check_suite_focus=true#step:6:5
>    macOS: https://github.com/phil-blain/gcc/runs/2103367199?check_suite_focus=true#step:6:5
>
>    Fetch-It-Via: git fetch https://github.com/phil-blain/gcc libstdcxx-pretty-printers-install-filename


> libstdc++-v3/python/Makefile.am | 20 ++++----------------
> 1 file changed, 4 insertions(+), 16 deletions(-)
>
>diff --git a/libstdc++-v3/python/Makefile.am b/libstdc++-v3/python/Makefile.am
>index 01517a2a5..0c2b207b8 100644
>--- a/libstdc++-v3/python/Makefile.am
>+++ b/libstdc++-v3/python/Makefile.am
>@@ -44,21 +44,9 @@ gdb.py: hook.in Makefile
> install-data-local: gdb.py
> 	@$(mkdir_p) $(DESTDIR)$(toolexeclibdir)
> ## We want to install gdb.py as SOMETHING-gdb.py.  SOMETHING is the
>-## full name of the final library.  We want to ignore symlinks, the
>-## .la file, and any previous -gdb.py file.  This is inherently
>-## fragile, but there does not seem to be a better option, because
>-## libtool hides the real names from us.
>-	@here=`pwd`; cd $(DESTDIR)$(toolexeclibdir); \
>-	  for file in libstdc++.*; do \
>-	    case $$file in \
>-	      *-gdb.py) ;; \
>-	      *.la) ;; \
>-	      *) if test -h $$file; then \
>-	           continue; \
>-	         fi; \
>-	         libname=$$file;; \
>-	    esac; \
>-	  done; \
>-	cd $$here; \
>+## full name of the final library.  We use the libtool .la file to get
>+## the correct name.
>+	@libname=`sed -ne "/^library_names=/{s/.*='//;s/'$$//;s/ .*//;p;}" \
>+	          $(DESTDIR)$(toolexeclibdir)/libstdc++.la`; \
> 	echo " $(INSTALL_DATA) gdb.py $(DESTDIR)$(toolexeclibdir)/$$libname-gdb.py"; \
> 	$(INSTALL_DATA) gdb.py $(DESTDIR)$(toolexeclibdir)/$$libname-gdb.py
>
>base-commit: 6e885ad3287388192e52e9b524dbaa408507c0a4
>-- 
>2.31.1
>
diff mbox series

Patch

diff --git a/libstdc++-v3/python/Makefile.am b/libstdc++-v3/python/Makefile.am
index 01517a2a5..0c2b207b8 100644
--- a/libstdc++-v3/python/Makefile.am
+++ b/libstdc++-v3/python/Makefile.am
@@ -44,21 +44,9 @@  gdb.py: hook.in Makefile
 install-data-local: gdb.py
 	@$(mkdir_p) $(DESTDIR)$(toolexeclibdir)
 ## We want to install gdb.py as SOMETHING-gdb.py.  SOMETHING is the
-## full name of the final library.  We want to ignore symlinks, the
-## .la file, and any previous -gdb.py file.  This is inherently
-## fragile, but there does not seem to be a better option, because
-## libtool hides the real names from us.
-	@here=`pwd`; cd $(DESTDIR)$(toolexeclibdir); \
-	  for file in libstdc++.*; do \
-	    case $$file in \
-	      *-gdb.py) ;; \
-	      *.la) ;; \
-	      *) if test -h $$file; then \
-	           continue; \
-	         fi; \
-	         libname=$$file;; \
-	    esac; \
-	  done; \
-	cd $$here; \
+## full name of the final library.  We use the libtool .la file to get
+## the correct name.
+	@libname=`sed -ne "/^library_names=/{s/.*='//;s/'$$//;s/ .*//;p;}" \
+	          $(DESTDIR)$(toolexeclibdir)/libstdc++.la`; \
 	echo " $(INSTALL_DATA) gdb.py $(DESTDIR)$(toolexeclibdir)/$$libname-gdb.py"; \
 	$(INSTALL_DATA) gdb.py $(DESTDIR)$(toolexeclibdir)/$$libname-gdb.py