From 99e7387736ccd6912382b05b3c4b1e327d3e0ed1 Mon Sep 17 00:00:00 2001 From: Gene Cooperman Date: Fri, 28 Jun 2024 01:03:11 -0400 Subject: [PATCH] Patch gdbinit_commands.py for old GDB/Python --- Makefile.in | 1 + configure | 17 ++++++++++++++++- configure.ac | 17 ++++++++++++++++- oldsys-patch.sh | 34 ++++++++++++++++++++++++++++++++++ 4 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 oldsys-patch.sh diff --git a/Makefile.in b/Makefile.in index 77bbf1d1..b9912845 100644 --- a/Makefile.in +++ b/Makefile.in @@ -72,6 +72,7 @@ clean: rm -f NO-GDB-G3 distclean: clean rm -f Makefile mcmini-gdb config.log config.status + rm -f oldsys_was_patched.txt dist: distclean dir=`basename $$PWD` && cd .. && \ diff --git a/configure b/configure index 6b38bc0e..29c63b0c 100755 --- a/configure +++ b/configure @@ -5366,7 +5366,22 @@ PYTHON_VERSION_MINOR=`$PYTHON -c 'import sys; print("%d" % (sys.version_info.min if $PYTHON -c 'import sys; sys.exit('$GDB_VERSION' >= 12 and '$PYTHON_VERSION_MINOR' >= 7)'; then echo '*** Python or GDB Python API is older: patching Python code' echo '*** There may be some smaller missing features for mcminig-gdb.' - # patch -p1 < mcmini-oldsys.patch + if test -e oldsys_was_patched.txt && which lsb_release > /dev/null && \ + ! lsb_release -ir | diff - oldsys_was_patched.txt > /dev/null; then + rm oldsys_was_patched.txt.txt + fi + if test ! -e oldsys_was_patched.txt && which lsb_release > /dev/null; then + if git diff --quiet HEAD -- gdbinit_commands.py ; then + sh oldsys-patch.sh + lsb_release -ir > oldsys_was_patched.txt + else + echo configure: This seems to be an older O/S; + echo " " but not patching because gdbinit_commands.py is already modified. + fi + elif test -e oldsys_was_patched.txt; then + echo configure: oldsys_was_patched.txt found: Will not patch again. + echo " " To patch again, do: rm oldsys_was_patched.txt + fi fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if process_vm_readv/process_vm_writev (CMA) available" >&5 diff --git a/configure.ac b/configure.ac index adda8ab6..fc694903 100644 --- a/configure.ac +++ b/configure.ac @@ -91,7 +91,22 @@ PYTHON_VERSION_MINOR=`$PYTHON -c 'import sys; print("%d" % (sys.version_info.min if $PYTHON -c 'import sys; sys.exit('$GDB_VERSION' >= 12 and '$PYTHON_VERSION_MINOR' >= 7)'; then echo '*** Python or GDB Python API is older: patching Python code' echo '*** There may be some smaller missing features for mcminig-gdb.' - # patch -p1 < mcmini-oldsys.patch + if test -e oldsys_was_patched.txt && which lsb_release > /dev/null && \ + ! lsb_release -ir | diff - oldsys_was_patched.txt > /dev/null; then + rm oldsys_was_patched.txt.txt + fi + if test ! -e oldsys_was_patched.txt && which lsb_release > /dev/null; then + if git diff --quiet HEAD -- gdbinit_commands.py ; then + sh oldsys-patch.sh + lsb_release -ir > oldsys_was_patched.txt + else + echo configure: This seems to be an older O/S; + echo " " but not patching because gdbinit_commands.py is already modified. + fi + elif test -e oldsys_was_patched.txt; then + echo configure: oldsys_was_patched.txt found: Will not patch again. + echo " " To patch again, do: rm oldsys_was_patched.txt + fi fi dnl CMA (Cross Memory Attach) brought in with Linux 3.2.0 and glibc 2.15 diff --git a/oldsys-patch.sh b/oldsys-patch.sh new file mode 100644 index 00000000..fba1e3f2 --- /dev/null +++ b/oldsys-patch.sh @@ -0,0 +1,34 @@ +#!/bin/sh + +sed --in-place \ + -e 's^capture_output=True,^stdout=subprocess.PIPE, stderr=subprocess.PIPE,^'\ + gdbinit_commands.py + +sed --in-place -e 's^\([a-z._\(\)]*\)\.level()^level(\1)^' gdbinit_commands.py + +sed --in-place -e '/show style enabled/N; s/^\( *\)[^ ].*show style enabled.*$/\1if False:/' gdbinit_commands.py + +sed --in-place -e 's/^\( *\)gdb.set_parameter.*$/\1pass/' gdbinit_commands.py + +sed --in-place -e 's/^\( *\)cur_pagination = gdb.parameter.*$/\1pass/' gdbinit_commands.py + +sed --in-place -e 's/^\( *\).*print frame-info.*$/\1pass/' gdbinit_commands.py + +sed --in-place -e 's/^\( *\)cur_frame_info = .*$/\1cur_frame_info = ""/' gdbinit_commands.py + +sed --in-place -e 's/^\( *\)context = redirect_prolog(inferior=1).*$/\1gdb.execute("inferior 1")/' gdbinit_commands.py + +sed --in-place -e 's/^\( *\)context = redirect_prolog().*$/\1pass/' gdbinit_commands.py + +sed --in-place -e 's/^\( *\)redirect_epilog(.*$/\1pass/' gdbinit_commands.py + +cat <<'EOF' | cat - >> gdbinit_commands.py + +def level(frame): + frame2 = gdb.newest_frame() + count = 0 + while frame != frame2 and frame2.older(): + frame2 = frame2.older() + count += 1 + return count +EOF