LogoopenSUSE Build Service > Projects
Sign Up | Log In

View File 0563-erts-Expand-rr-support-in-cerl-and-etp.patch of Package erlang (Project home:Ledest:erlang:20)

From 9ad981a6184ee9b111f7526c4c9fc9c77d235241 Mon Sep 17 00:00:00 2001
From: Lukas Larsson <lukas@erlang.org>
Date: Thu, 10 Jan 2019 11:18:19 +0100
Subject: [PATCH] erts: Expand rr support in cerl and etp

---
 erts/etc/unix/Makefile                 |  3 ++-
 erts/etc/unix/cerl.src                 | 29 ++++++++++++++++++++--
 erts/etc/unix/etp-commands.in          | 32 ++++++++++++++++++++----
 erts/etc/unix/etp-rr-run-until-beam.py | 45 ++++++++++++++++++++++++++++++++++
 4 files changed, 101 insertions(+), 8 deletions(-)
 create mode 100644 erts/etc/unix/etp-rr-run-until-beam.py

diff --git a/erts/etc/unix/Makefile b/erts/etc/unix/Makefile
index 83c64d35fd..21a725cb88 100644
--- a/erts/etc/unix/Makefile
+++ b/erts/etc/unix/Makefile
@@ -30,7 +30,8 @@ opt debug lcnt: etc
 etc: etp-commands
 
 etp-commands: etp-commands.in
-	$(gen_verbose)sed 's:@ERL_TOP@:${ERL_TOP}:g' etp-commands.in > etp-commands
+	$(gen_verbose)sed -e 's:@ERL_TOP@:${ERL_TOP}:g' \
+	etp-commands.in > etp-commands
 
 .PHONY: docs
 docs:
diff --git a/erts/etc/unix/cerl.src b/erts/etc/unix/cerl.src
index 2e034513b0..bcd64d242e 100644
--- a/erts/etc/unix/cerl.src
+++ b/erts/etc/unix/cerl.src
@@ -224,7 +224,13 @@ while [ $# -gt 0 ]; do
 	    shift
 	    cargs="$cargs -rr"
 	    run_rr=yes
-	    skip_erlexec=yes
+            case "$1" in
+                "replay"|"ps")
+                    ;;
+                *)
+	            skip_erlexec=yes
+                    ;;
+            esac
 	    ;;
 	*)
 	    break
@@ -307,7 +313,26 @@ if [ "x$GDB" = "x" ]; then
 	exec $taskset1 valgrind $valgrind_xml $valgrind_log $valgrind_misc_flags $BINDIR/$EMU_NAME $sched_arg $emu_xargs "$@"
 
     elif [ $run_rr = yes ]; then
-	exec rr record --ignore-nested $BINDIR/$EMU_NAME $emu_xargs "$@"
+        if [ $1 = replay ]; then
+            shift
+            cmdfile="/tmp/.cerlgdb.$$"
+            echo "set \$etp_beam_executable = \"$BINDIR/$EMU_NAME\"" > $cmdfile
+            if [ "$1" = "-p" ]; then
+                echo 'set $etp_rr_run_until_beam = 1' >> $cmdfile
+            fi
+            cat $ROOTDIR/erts/etc/unix/etp-commands.in >> $cmdfile
+            exec rr replay -x $cmdfile $*
+        elif [ $1 = ps ]; then
+            shift
+            rr ps $* | head -1
+            ChildSetup=`rr ps $* | grep 'erl_child_setup' | awk '{ print $2 }'`
+            for CS in $ChildSetup; do
+                rr ps $* | grep -E "^$CS"
+            done
+            exit 0
+        else
+	    exec rr record --ignore-nested $BINDIR/$EMU_NAME $emu_xargs "$@"
+        fi
     else
 	exec $EXEC $xargs ${1+"$@"}
     fi
diff --git a/erts/etc/unix/etp-commands.in b/erts/etc/unix/etp-commands.in
index b12a205ba7..54b7628137 100644
--- a/erts/etc/unix/etp-commands.in
+++ b/erts/etc/unix/etp-commands.in
@@ -149,7 +149,7 @@ define etp-1
       else
         # (($arg0) & 0x3) == 0
         if (($arg0) == etp_the_non_value)
-          printf "<the non-value>"
+          printf "<the-non-value>"
         else
           etp-cp-1 ($arg0)
         end
@@ -4281,6 +4281,20 @@ document etp-show
 %---------------------------------------------------------------------------
 end
 
+define etp-rr-run-until-beam
+  source @ERL_TOP@/erts/etc/unix/etp-rr-run-until-beam.py
+end
+
+document etp-rr-run-until-beam
+%---------------------------------------------------------------------------
+% etp-rr-run-until-beam
+%
+% Use this gdb macro to make cerl -rr replay -p PID walk until
+% the correct execute has been made. You may have to change the
+% file that is used to debug with.
+%---------------------------------------------------------------------------
+end
+
 ############################################################################
 # Init
 #
@@ -4314,7 +4328,15 @@ document etp-init
 %---------------------------------------------------------------------------
 end
 
+macro define offsetof(t, f) &((t *) 0)->f)
+
+handle SIGPIPE nostop
+
 etp-init
 help etp-init
-etp-show
-etp-system-info
+if $etp_rr_run_until_beam
+  help etp-rr-run-until-beam
+else
+  etp-show
+  etp-system-info
+end
diff --git a/erts/etc/unix/etp-rr-run-until-beam.py b/erts/etc/unix/etp-rr-run-until-beam.py
new file mode 100644
index 0000000000..078998b910
--- /dev/null
+++ b/erts/etc/unix/etp-rr-run-until-beam.py
@@ -0,0 +1,45 @@
+#
+# %CopyrightBegin%
+#
+# Copyright Ericsson AB 2013-2016. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# %CopyrightEnd%
+#
+
+has_exited = False
+
+def stop_handler (event):
+  global has_exited
+  if isinstance(event, gdb.SignalEvent):
+    print("exit code: %s" % (event.stop_signal))
+    has_exited = True
+
+gdb.events.stop.connect (stop_handler)
+
+gdb.execute('continue')
+
+while not has_exited:
+  r = gdb.execute('when', to_string=True)
+  m = re.match("[^0-9]*([0-9]+)", r)
+  if m:
+    event = int(m.group(1));
+    gdb.execute('start ' + str(event + 1));
+    gdb.execute('continue')
+
+gdb.events.stop.disconnect (stop_handler)
+
+gdb.execute('file ' + str(gdb.parse_and_eval("$etp_beam_executable")))
+gdb.execute('break main')
+gdb.execute('reverse-continue')
-- 
2.16.4