[master] a3129a534 thread info for panic where pthread_getattr_np() available

Nils Goroll nils.goroll at uplex.de
Wed Mar 6 23:05:08 UTC 2019


commit a3129a5340566d17192de8058a9c1dbb051a7039
Author: Nils Goroll <nils.goroll at uplex.de>
Date:   Wed Mar 6 23:24:46 2019 +0100

    thread info for panic where pthread_getattr_np() available

diff --git a/bin/varnishd/cache/cache_panic.c b/bin/varnishd/cache/cache_panic.c
index 3a4fae5f4..fbae9dadf 100644
--- a/bin/varnishd/cache/cache_panic.c
+++ b/bin/varnishd/cache/cache_panic.c
@@ -650,6 +650,33 @@ pan_backtrace(struct vsb *vsb)
 	VSB_indent(vsb, -2);
 }
 
+#ifdef HAVE_PTHREAD_GETATTR_NP
+static void
+pan_threadattr(struct vsb *vsb)
+{
+	pthread_attr_t attr[1];
+	size_t sz;
+	void *addr;
+
+	if (pthread_getattr_np(pthread_self(), attr) != 0)
+		return;
+
+	VSB_cat(vsb, "pthread.attr = {\n");
+	VSB_indent(vsb, 2);
+
+	if (pthread_attr_getguardsize(attr, &sz) == 0)
+		VSB_printf(vsb, "guard = %zu,\n", sz);
+	if (pthread_attr_getstack(attr, &addr, &sz) == 0) {
+		VSB_printf(vsb, "stack_bottom = %p,\n", addr);
+		VSB_printf(vsb, "stack_top = %p,\n", (char *)addr + sz);
+		VSB_printf(vsb, "stack_size = %zu,\n", sz);
+	}
+	VSB_indent(vsb, -2);
+	VSB_cat(vsb, "}\n");
+	(void) pthread_attr_destroy(attr);
+}
+#endif
+
 /*--------------------------------------------------------------------*/
 
 static void __attribute__((__noreturn__))
@@ -722,6 +749,10 @@ pan_ic(const char *func, const char *file, int line, const char *cond,
 	if (q != NULL)
 		VSB_printf(pan_vsb, "thread = (%s)\n", q);
 
+#ifdef HAVE_PTHREAD_GETATTR_NP
+	pan_threadattr(pan_vsb);
+#endif
+
 	if (!FEATURE(FEATURE_SHORT_PANIC)) {
 		req = THR_GetRequest();
 		VSB_cat(pan_vsb, "thr.");
diff --git a/configure.ac b/configure.ac
index 24956aaca..fbe5032ce 100644
--- a/configure.ac
+++ b/configure.ac
@@ -239,6 +239,7 @@ LIBS="${PTHREAD_LIBS}"
 AC_CHECK_FUNCS([pthread_set_name_np])
 AC_CHECK_FUNCS([pthread_setname_np])
 AC_CHECK_FUNCS([pthread_mutex_isowned_np])
+AC_CHECK_FUNCS([pthread_getattr_np])
 LIBS="${save_LIBS}"
 
 AC_CHECK_DECL([__SUNPRO_C], [SUNCC="yes"], [SUNCC="no"])


More information about the varnish-commit mailing list