public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
From: Mark Wielaard <mark@klomp.org>
To: elfutils-devel@sourceware.org
Cc: Mark Wielaard <mark@klomp.org>
Subject: [PATCH] tests: Allow an extra pthread_kill frame in backtrace tests
Date: Wed,  4 Aug 2021 21:04:12 +0200	[thread overview]
Message-ID: <20210804190412.14041-1-mark@klomp.org> (raw)

glibc 2.34 calls pthread_kill from the raise function. Before raise
directly called the (tg)kill syscall. So allow pthread_kill to be the
first frame in a backtrace where raise is expected. Also change some
asserts to fprintf plus abort to make it more clear why the testcase
fails.

https://sourceware.org/bugzilla/show_bug.cgi?id=28190

Signed-off-by: Mark Wielaard <mark@klomp.org>
---
 tests/ChangeLog   |  6 +++++
 tests/backtrace.c | 62 +++++++++++++++++++++++++++++++++++++++++------
 2 files changed, 61 insertions(+), 7 deletions(-)

diff --git a/tests/ChangeLog b/tests/ChangeLog
index 34666609..3bfd1ca2 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,9 @@
+2021-08-04  Mark Wielaard  <mark@klomp.org>
+
+	PR28190
+	* backtrace.c (callback_verify): Check for pthread_kill as first
+	frame. Change asserts to fprintf plus abort.
+
 2021-07-26  Noah Sanci  <nsanci@redhat.com>
 
 	PR27982
diff --git a/tests/backtrace.c b/tests/backtrace.c
index 36c8b8c4..779335df 100644
--- a/tests/backtrace.c
+++ b/tests/backtrace.c
@@ -97,6 +97,9 @@ callback_verify (pid_t tid, unsigned frameno, Dwarf_Addr pc,
   static bool reduce_frameno = false;
   if (reduce_frameno)
     frameno--;
+  static bool pthread_kill_seen = false;
+  if (pthread_kill_seen)
+    frameno--;
   if (! use_raise_jmp_patching && frameno >= 2)
     frameno += 2;
   const char *symname2 = NULL;
@@ -107,11 +110,27 @@ callback_verify (pid_t tid, unsigned frameno, Dwarf_Addr pc,
 	       && (strcmp (symname, "__kernel_vsyscall") == 0
 		   || strcmp (symname, "__libc_do_syscall") == 0))
 	reduce_frameno = true;
+      else if (! pthread_kill_seen && symname
+	       && strncmp (symname, "pthread_kill",
+			   strlen ("pthread_kill")) == 0)
+	pthread_kill_seen = true;
       else
-	assert (symname && strcmp (symname, "raise") == 0);
+	{
+	  if (!symname || strcmp (symname, "raise") != 0)
+	    {
+	      fprintf (stderr,
+		       "case 0: expected symname 'raise' got '%s'\n", symname);
+	      abort ();
+	    }
+	}
       break;
     case 1:
-      assert (symname != NULL && strcmp (symname, "sigusr2") == 0);
+      if (symname == NULL || strcmp (symname, "sigusr2") != 0)
+	{
+	  fprintf (stderr,
+		   "case 1: expected symname 'sigusr2' got '%s'\n", symname);
+	  abort ();
+	}
       break;
     case 2: // x86_64 only
       /* __restore_rt - glibc maybe does not have to have this symbol.  */
@@ -120,11 +139,21 @@ callback_verify (pid_t tid, unsigned frameno, Dwarf_Addr pc,
       if (use_raise_jmp_patching)
 	{
 	  /* Verify we trapped on the very first instruction of jmp.  */
-	  assert (symname != NULL && strcmp (symname, "jmp") == 0);
+	  if (symname == NULL || strcmp (symname, "jmp") != 0)
+	    {
+	      fprintf (stderr,
+		       "case 3: expected symname 'raise' got '%s'\n", symname);
+	      abort ();
+	    }
 	  mod = dwfl_addrmodule (dwfl, pc - 1);
 	  if (mod)
 	    symname2 = dwfl_module_addrname (mod, pc - 1);
-	  assert (symname2 == NULL || strcmp (symname2, "jmp") != 0);
+	  if (symname2 == NULL || strcmp (symname2, "jmp") != 0)
+	    {
+	      fprintf (stderr,
+		       "case 3: expected symname2 'jmp' got '%s'\n", symname2);
+	      abort ();
+	    }
 	  break;
 	}
       FALLTHROUGH;
@@ -137,11 +166,22 @@ callback_verify (pid_t tid, unsigned frameno, Dwarf_Addr pc,
 	  duplicate_sigusr2 = true;
 	  break;
 	}
-      assert (symname != NULL && strcmp (symname, "stdarg") == 0);
+      if (symname == NULL || strcmp (symname, "stdarg") != 0)
+	{
+	  fprintf (stderr,
+		   "case 4: expected symname 'stdarg' got '%s'\n", symname);
+	  abort ();
+	}
       break;
     case 5:
       /* Verify we trapped on the very last instruction of child.  */
-      assert (symname != NULL && strcmp (symname, "backtracegen") == 0);
+      if (symname == NULL || strcmp (symname, "backtracegen") != 0)
+	{
+	  fprintf (stderr,
+		   "case 5: expected symname 'backtracegen' got '%s'\n",
+		   symname);
+	  abort ();
+	}
       mod = dwfl_addrmodule (dwfl, pc);
       if (mod)
 	symname2 = dwfl_module_addrname (mod, pc);
@@ -151,7 +191,15 @@ callback_verify (pid_t tid, unsigned frameno, Dwarf_Addr pc,
       // instructions or even inserts some padding instructions at the end
       // (which apparently happens on ppc64).
       if (use_raise_jmp_patching)
-        assert (symname2 == NULL || strcmp (symname2, "backtracegen") != 0);
+	{
+          if (symname2 != NULL && strcmp (symname2, "backtracegen") == 0)
+	    {
+	      fprintf (stderr,
+		       "use_raise_jmp_patching didn't expect symname2 "
+		       "'backtracegen'\n");
+	      abort ();
+	    }
+	}
       break;
   }
 }
-- 
2.18.4


             reply	other threads:[~2021-08-04 19:04 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-04 19:04 Mark Wielaard [this message]
2021-08-05 11:04 ` [PATCHv2] " Mark Wielaard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210804190412.14041-1-mark@klomp.org \
    --to=mark@klomp.org \
    --cc=elfutils-devel@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).