File 2691-Add-missing-dtrace-return-invocations.patch of Package erlang
From cf766a6e82e07e520c98f087965f024e76dac0dd Mon Sep 17 00:00:00 2001
From: Luis Rascao <luis.rascao@miniclip.com>
Date: Fri, 13 Sep 2019 14:51:33 +0100
Subject: [PATCH 1/2] Add missing dtrace return invocations
Some return paths were not going through dtrace
hooks so no function-return probes were being triggered
on dtrace/systemtap.
The return probe will now inform the user of which function
it returns *from* as opposed the previous behaviour of
informing where it returns *to*.
---
 erts/emulator/beam/beam_emu.c | 6 +++---
 erts/emulator/beam/instrs.tab | 5 +++--
 2 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/erts/emulator/beam/beam_emu.c b/erts/emulator/beam/beam_emu.c
index e8a0c666e3..ee70b138e5 100644
--- a/erts/emulator/beam/beam_emu.c
+++ b/erts/emulator/beam/beam_emu.c
@@ -437,10 +437,10 @@ init_emulator(void)
         }                                                                                      \
     } while(0)
 
-#define DTRACE_RETURN_FROM_PC(p)                                                        \
+#define DTRACE_RETURN_FROM_PC(p, i)                                                        \
     do {                                                                                \
         ErtsCodeMFA* cmfa;                                                                  \
-        if (DTRACE_ENABLED(function_return) && (cmfa = find_function_from_pc(cp_val((p)->stop[0])))) { \
+        if (DTRACE_ENABLED(function_return) && (cmfa = find_function_from_pc(i))) { \
             DTRACE_RETURN((p), cmfa);                               \
         }                                                                               \
     } while(0)
@@ -450,7 +450,7 @@ init_emulator(void)
 #define DTRACE_GLOBAL_CALL(p, mfa)       do {} while (0)
 #define DTRACE_GLOBAL_CALL_FROM_EXPORT(p, e) do {} while (0)
 #define DTRACE_RETURN(p, mfa)            do {} while (0)
-#define DTRACE_RETURN_FROM_PC(p)             do {} while (0)
+#define DTRACE_RETURN_FROM_PC(p, i)      do {} while (0)
 #define DTRACE_BIF_ENTRY(p, mfa)         do {} while (0)
 #define DTRACE_BIF_RETURN(p, mfa)        do {} while (0)
 #define DTRACE_NIF_ENTRY(p, mfa)         do {} while (0)
diff --git a/erts/emulator/beam/instrs.tab b/erts/emulator/beam/instrs.tab
index 9396c09182..f53d60a5db 100644
--- a/erts/emulator/beam/instrs.tab
+++ b/erts/emulator/beam/instrs.tab
@@ -135,6 +135,7 @@ move_deallocate_return(Src, Deallocate) {
     Eterm src = $Src;
     E = ADD_BYTE_OFFSET(E, bytes_to_pop);
     x(0) = src;
+    DTRACE_RETURN_FROM_PC(c_p, I);
     $RETURN();
     CHECK_TERM(x(0));
     $DISPATCH_RETURN();
@@ -374,9 +375,8 @@ i_call_fun_last(Fun, Deallocate) {
 
 return() {
     //| -no_next
+    DTRACE_RETURN_FROM_PC(c_p, I);
     $RETURN();
-
-    DTRACE_RETURN_FROM_PC(c_p);
     CHECK_TERM(r(0));
     HEAP_SPACE_VERIFIED(0);
 
@@ -672,6 +672,7 @@ move_window5(S1, S2, S3, S4, S5, D) {
 move_return(Src) {
     //| -no_next
     x(0) = $Src;
+    DTRACE_RETURN_FROM_PC(c_p, I);
     $RETURN();
     $DISPATCH_RETURN();
 }
-- 
2.16.4