[PATCH 2/8] gdb: Use a virtual environment if present

chrisj at rtems.org chrisj at rtems.org
Wed Apr 5 01:30:56 UTC 2023


From: Chris Johns <chris at contemporary.net.au>

- Detect and use a virtual environment if present

- Supports MacOS with python.org in a venv

Updates #4892
---
 rtems/config/tools/rtems-gdb-13.1.cfg  |  4 ++
 source-builder/config/gdb-common-1.cfg | 58 ++++++++++++++++----------
 2 files changed, 39 insertions(+), 23 deletions(-)

diff --git a/rtems/config/tools/rtems-gdb-13.1.cfg b/rtems/config/tools/rtems-gdb-13.1.cfg
index 5766594..1fd0f1c 100644
--- a/rtems/config/tools/rtems-gdb-13.1.cfg
+++ b/rtems/config/tools/rtems-gdb-13.1.cfg
@@ -14,4 +14,8 @@
 %hash sha512 gdb-13-freebsd-include.diff \
    2oKUpRyZIwXwyKHXn5lxXte+jV853Zvg5UHLKLfmVCW4QLrLMFsnO5LvPamIqjXnqPztB8IPEY18pdw8vOYaOw==
 
+%patch add gdb -p1 --rsb-file=gdb-14067-python-config.diff https://sourceware.org/bugzilla/attachment.cgi?id=14783&format=raw
+%hash sha512 gdb-14067-python-config.diff \
+   HiCV0eQulk0W+G5uu1gCvUn5Ns6bF6RxqOO9kcSi8zpfEHOMzphlOv5cz0IDN5Q8m94na1kRVy++4z6qc43t3w==
+
 %include %{_configdir}/gdb-common-1.cfg
diff --git a/source-builder/config/gdb-common-1.cfg b/source-builder/config/gdb-common-1.cfg
index 9d67da0..a52e64d 100644
--- a/source-builder/config/gdb-common-1.cfg
+++ b/source-builder/config/gdb-common-1.cfg
@@ -58,7 +58,7 @@
         %define gdb-enable-python %(command -v python2 || true)
       %endif
       %if %{gdb-enable-python} == %{nil}
-          %define gdb-enable-python %(command -v python || true})
+        %define gdb-enable-python %(command -v python || true})
       %endif
     %endif
     %if %{gdb-enable-python} == %{nil}
@@ -79,6 +79,9 @@
 %endif
 %if %{gdb-python-config} == %{nil}
  %define gdb-python-config %(command -v %{gdb-enable-python}-config || true)
+ %if %{gdb-python-config} == %{nil}
+  %define gdb-python-config %(command -v %(basename %{gdb-enable-python})-config || true)
+ %endif
 %endif
 %define gdb-python-ver-mm %(%{gdb-enable-python} --version 2>&1 | sed -e 's/.* //g' | rev | cut -d'.' -f2- | rev)
 %define gdb-python-ver-major %(echo "%{gdb-python-ver-mm}" | sed -e 's/\..*//')
@@ -100,30 +103,39 @@
 %if %{gdb-python-header-check} == not-found && !%{_rsb_getting_source}
   %error "gdb: python: header file not found: %{gdb-python-ver-header}, please install"
 %endif
-#
-# Too hard to find on MacOS (darwin), the header is good enough.
-#
-%ifnos darwin
-  %if %{host_ldflags} == %{nil}
-    %define gdb-host-libs %{nil}
-  %else
-    %define gdb-host-libs -L '%{host_ldflags}'
-  %endif
-  %if %{gdb-python-config} != %{nil}
-    %define gdb-python-lib-filter awk 'BEGIN{FS=" "}/python/{for(i=1;i<NF;++i)if(match($i,".*lpython.*")) print "lib"substr($i,3)"*";}'
-    %if %{gdb-python-ver-major} < 3 || \
-        %{gdb-python-ver-major} == 3 && %{gdb-python-ver-minor} < 8
-        %define gdb-python-config-lib-check-flags --ldflags
-    %else
-        %define gdb-python-config-lib-check-flags --ldflags --embed
-    %endif
-    %define gdb-python-config-libs %(%{gdb-python-config} %{gdb-python-config-lib-check-flags} | %{gdb-python-lib-filter})
-    %define gdb-python-lib-check %(%{_sbdir}/sb/rtems-build-dep -c %{__cc} %{gdb-host-libs} -l %{gdb-python-config-libs})
+%if %{host_ldflags} == %{nil}
+  %define gdb-host-libs %{nil}
+%else
+  %define gdb-host-libs -L '%{host_ldflags}'
+%endif
+%if %{gdb-python-config} != %{nil}
+  %define gdb-python-lib-filter awk 'BEGIN{FS=" "}/python/{for(i=1;i<NF;++i)if(match($i,".*lpython.*")) print "lib"substr($i,3)"\\*";}'
+  %define gdb-python-libpath-filter awk 'BEGIN{FS=" "}/python/{for(i=1;i<NF;++i)if(match($i,".*L.*")) print substr($i,3);}'
+  %if %{gdb-python-ver-major} < 3 || \
+      %{gdb-python-ver-major} == 3 && %{gdb-python-ver-minor} < 8
+      %define gdb-python-config-lib-check-flags --ldflags
   %else
-    %define gdb-python-lib-check %(%{_sbdir}/sb/rtems-build-dep -c %{__cc} %{gdb-host-libs} -l %{gdb-python-ver-lib})
+      %define gdb-python-config-lib-check-flags --ldflags --embed
   %endif
-  %if %{gdb-python-lib-check} == not-found && !%{_rsb_getting_source}
-    %error "gdb: python: library file not found: %{gdb-python-ver-lib}, please install"
+  %define gdb-python-config-libs %(%{gdb-python-config} %{gdb-python-config-lib-check-flags} | %{gdb-python-lib-filter})
+  %define gdb-python-config-libpath %(%{gdb-python-config} %{gdb-python-config-lib-check-flags} | %{gdb-python-libpath-filter} | uniq)
+  %define gdb-python-lib-check %(%{_sbdir}/sb/rtems-build-dep -c %{__cc} %{gdb-host-libs} -L %{gdb-python-config-libpath} -l %{gdb-python-config-libs})
+%else
+  %define gdb-python-lib-check %(%{_sbdir}/sb/rtems-build-dep -c %{__cc} %{gdb-host-libs} -l %{gdb-python-ver-lib})
+%endif
+%if %{gdb-python-lib-check} == not-found && !%{_rsb_getting_source}
+  %error "gdb: python: library file not found: %{gdb-python-ver-lib}, please install"
+%endif
+
+#
+# If in a virtual environment use that as GDB will look 'bin/python' under it
+# Supportted in GDB 13 and later.
+#
+%define gdb_version_major %(echo "%{gdb_version}" | sed -e 's/\..*//')
+%if %{gdb_version_major} >= 13
+  %define python-venv %(echo $VIRTUAL_ENV)
+  %if %{python-venv} != %{nil}
+    %define gdb-enable-python %{python-venv}
   %endif
 %endif
 
-- 
2.37.1



More information about the devel mailing list