File 0221-erts-Do-not-set-debug-breakpoints-on-BIFs.patch of Package erlang

From 3fb897ac8cc7bc161dc50c1f141addcf8c8c1915 Mon Sep 17 00:00:00 2001
From: Sverker Eriksson <sverker@erlang.org>
Date: Wed, 3 Dec 2025 14:48:52 +0100
Subject: [PATCH] erts: Do not set debug breakpoints on BIFs

Debug breakpoints on BIFs are pointless (I think)
and would just complicate the logic for when
Export.is_bif_traced should be set/cleared.
---
 erts/emulator/beam/beam_bp.c       | 12 +++++++++++-
 erts/emulator/beam/beam_bp.h       |  2 +-
 erts/emulator/beam/beam_debug.c    |  3 ++-
 erts/emulator/beam/erl_bif_trace.c |  4 ++--
 4 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/erts/emulator/beam/beam_bp.c b/erts/emulator/beam/beam_bp.c
index 0e7b49a6f4..4edeea12e4 100644
--- a/erts/emulator/beam/beam_bp.c
+++ b/erts/emulator/beam/beam_bp.c
@@ -178,7 +178,8 @@ erts_bp_init(void) {
 
 
 void
-erts_bp_match_functions(BpFunctions* f, ErtsCodeMFA *mfa, int specified)
+erts_bp_match_functions(BpFunctions* f, ErtsCodeMFA *mfa, int specified,
+                        int ignore_bifs)
 {
     ErtsCodeIndex code_ix = erts_active_code_ix();
     Uint max_funcs = 0;
@@ -232,6 +233,15 @@ erts_bp_match_functions(BpFunctions* f, ErtsCodeMFA *mfa, int specified)
             case 0:
                 break;
             }
+
+            if (ignore_bifs) {
+                Export *ep = erts_active_export_entry(ci->mfa.module,
+                                                      ci->mfa.function,
+                                                      ci->mfa.arity);
+                if (ep && ep->bif_number >= 0) {
+                    continue;
+                }
+            }
             /* Store match */
             f->matching[i].code_info = ci;
             f->matching[i].mod = module[current];
diff --git a/erts/emulator/beam/beam_bp.h b/erts/emulator/beam/beam_bp.h
index 6a5b4b5b8b..ef5a08aeef 100644
--- a/erts/emulator/beam/beam_bp.h
+++ b/erts/emulator/beam/beam_bp.h
@@ -132,7 +132,7 @@ void erts_commit_staged_bp(void);
 ERTS_GLB_INLINE ErtsBpIndex erts_active_bp_ix(void);
 ERTS_GLB_INLINE ErtsBpIndex erts_staging_bp_ix(void);
 
-void erts_bp_match_functions(BpFunctions* f, ErtsCodeMFA *mfa, int specified);
+void erts_bp_match_functions(BpFunctions* f, ErtsCodeMFA *mfa, int specified, int ignore_bifs);
 void erts_bp_match_export(BpFunctions* f, ErtsCodeMFA *mfa, int specified);
 void erts_bp_free_matched_functions(BpFunctions* f);
 
diff --git a/erts/emulator/beam/beam_debug.c b/erts/emulator/beam/beam_debug.c
index dfc6e2fc8c..50a123238e 100644
--- a/erts/emulator/beam/beam_debug.c
+++ b/erts/emulator/beam/beam_debug.c
@@ -246,7 +246,8 @@ erts_debug_breakpoint_2(BIF_ALIST_2)
     ASSERT(erts_staging_trace_session == NULL);
     erts_staging_trace_session = &erts_trace_session_0;
 
-    erts_bp_match_functions(&finish_debug_bp.f, &mfa, specified);
+    erts_bp_match_functions(&finish_debug_bp.f, &mfa, specified,
+                            1); // ignore bifs
 
     ASSERT(finish_debug_bp.f.matched >= 0);
     ASSERT(finish_debug_bp.process == NULL);
diff --git a/erts/emulator/beam/erl_bif_trace.c b/erts/emulator/beam/erl_bif_trace.c
index 6c965ba36a..bb94cf73b4 100644
--- a/erts/emulator/beam/erl_bif_trace.c
+++ b/erts/emulator/beam/erl_bif_trace.c
@@ -2394,7 +2394,7 @@ erts_set_trace_pattern(ErtsCodeMFA *mfa, int specified,
     /*
      * First do "local" code breakpoint tracing
      */
-    erts_bp_match_functions(&finish_bp.f, mfa, specified);
+    erts_bp_match_functions(&finish_bp.f, mfa, specified, 0);
 
     if (on) {
 	if (! flags.breakpoint) {
@@ -2527,7 +2527,7 @@ prepare_clear_all_trace_pattern(ErtsTraceSession* session)
     /*
      * Clear all breakpoints in code for session
      */
-    erts_bp_match_functions(&finish_bp.f, NULL, 0);
+    erts_bp_match_functions(&finish_bp.f, NULL, 0, 0);
     erts_clear_all_breaks(&finish_bp.f);
 
     clear_event_trace(erts_staging_trace_session->send_tracing);
-- 
2.51.0

openSUSE Build Service is sponsored by