From adf895acad8e129c060a553bc393ea3b2a60d8d4 Mon Sep 17 00:00:00 2001 From: Christian Prochaska Date: Mon, 29 Jul 2013 16:56:08 +0200 Subject: [PATCH] Print pthread stub messages to Genode log console With this patch, the 'not implemented' messages of the pthread function stubs always get printed to the Genode log console instead of stdout. Issue #815. --- libports/lib/mk/libc-gen.inc | 3 ++ libports/lib/mk/libc.mk | 3 +- libports/src/lib/libc/libc_pdbg.cc | 22 ++++++++++ libports/src/lib/libc/libc_pdbg.h | 39 ++++++++++++++++++ .../patches/pthread_not_implemented.patch | 40 +++++-------------- 5 files changed, 75 insertions(+), 32 deletions(-) create mode 100644 libports/src/lib/libc/libc_pdbg.cc create mode 100644 libports/src/lib/libc/libc_pdbg.h diff --git a/libports/lib/mk/libc-gen.inc b/libports/lib/mk/libc-gen.inc index 9471ac35b..b18db1f59 100644 --- a/libports/lib/mk/libc-gen.inc +++ b/libports/lib/mk/libc-gen.inc @@ -8,6 +8,9 @@ SRC_C = $(filter-out $(FILTER_OUT_C),$(notdir $(wildcard $(LIBC_GEN_DIR)/*.c))) # 'sysconf.c' includes the local 'stdtime/tzfile.h' INC_DIR += $(REP_DIR)/src/lib/libc/stdtime +# '_pthread_stubs.c' includes the local 'libc_pdbg.h' +INC_DIR += $(REP_DIR)/src/lib/libc + include $(REP_DIR)/lib/mk/libc-common.inc vpath %.c $(LIBC_GEN_DIR) diff --git a/libports/lib/mk/libc.mk b/libports/lib/mk/libc.mk index ff3bcf0f9..0db85d841 100644 --- a/libports/lib/mk/libc.mk +++ b/libports/lib/mk/libc.mk @@ -13,7 +13,8 @@ SRC_CC = atexit.cc dummies.cc rlimit.cc sysctl.cc \ issetugid.cc errno.cc gai_strerror.cc clock_gettime.cc \ gettimeofday.cc malloc.cc progname.cc fd_alloc.cc file_operations.cc \ plugin.cc plugin_registry.cc select.cc exit.cc environ.cc nanosleep.cc \ - libc_mem_alloc.cc pread_pwrite.cc readv_writev.cc poll.cc + libc_mem_alloc.cc pread_pwrite.cc readv_writev.cc poll.cc \ + libc_pdbg.cc # # Files from string library that are not included in libc-raw_string because diff --git a/libports/src/lib/libc/libc_pdbg.cc b/libports/src/lib/libc/libc_pdbg.cc new file mode 100644 index 000000000..1853f9662 --- /dev/null +++ b/libports/src/lib/libc/libc_pdbg.cc @@ -0,0 +1,22 @@ +/* + * \brief C implementation of 'Genode::printf()' + * \author Christian Prochaska + * \date 2013-07-29 + */ + +/* + * Copyright (C) 2013 Genode Labs GmbH + * + * This file is part of the Genode OS framework, which is distributed + * under the terms of the GNU General Public License version 2. + */ + +#include + +extern "C" void genode_printf(const char *format, ...) +{ + va_list list; + va_start(list, format); + Genode::vprintf(format, list); + va_end(list); +} diff --git a/libports/src/lib/libc/libc_pdbg.h b/libports/src/lib/libc/libc_pdbg.h new file mode 100644 index 000000000..72b04219a --- /dev/null +++ b/libports/src/lib/libc/libc_pdbg.h @@ -0,0 +1,39 @@ +/* + * \brief 'PDBG()' implementation for use in '.c' files + * \author Christian Prochaska + * \date 2013-07-29 + */ + +/* + * Copyright (C) 2013 Genode Labs GmbH + * + * This file is part of the Genode OS framework, which is distributed + * under the terms of the GNU General Public License version 2. + */ + +#ifndef _LIBC_PDBG_H_ +#define _LIBC_PDBG_H_ + +extern void genode_printf(const char *format, ...) __attribute__((format(printf, 1, 2))); + +/** + * Suppress debug messages in release version + */ +#ifdef GENODE_RELEASE +#define DO_PDBG 0 +#else +#define DO_PDBG 1 +#endif /* GENODE_RELEASE */ + +#define ESC_DBG "\033[33m" +#define ESC_END "\033[0m" + +/** + * Print debug message with function name + */ +#define PDBG(fmt, ...) \ + if (DO_PDBG) {\ + genode_printf("%s: " ESC_DBG fmt ESC_END "\n", \ + __PRETTY_FUNCTION__, ##__VA_ARGS__ ); } + +#endif /* _LIBC_DEBUG_H_ */ diff --git a/libports/src/lib/libc/patches/pthread_not_implemented.patch b/libports/src/lib/libc/patches/pthread_not_implemented.patch index 58702f8fa..ff569c521 100644 --- a/libports/src/lib/libc/patches/pthread_not_implemented.patch +++ b/libports/src/lib/libc/patches/pthread_not_implemented.patch @@ -4,45 +4,23 @@ From: Christian Prochaska --- - libc/gen/_pthread_stubs.c | 29 +++++++++++++++++++++++++++++ - 1 file changed, 29 insertions(+) + libc/gen/_pthread_stubs.c | 10 ++++++++++ + 1 file changed, 10 insertions(+) diff --git a/libc/gen/_pthread_stubs.c b/libc/gen/_pthread_stubs.c -index 063676f..c5112c5 100644 +index 063676f..5a79231 100644 --- libc/gen/_pthread_stubs.c +++ libc/gen/_pthread_stubs.c -@@ -30,9 +30,30 @@ __FBSDID("$FreeBSD$"); - #include - #include - #include -+#include +@@ -33,6 +33,8 @@ __FBSDID("$FreeBSD$"); #include "libc_private.h" -+#define ESC_DBG "\033[33m" -+#define ESC_END "\033[0m" -+ -+/** -+ * Suppress debug messages in release version -+ */ -+#ifdef GENODE_RELEASE -+#define DO_PDBG 0 -+#else -+#define DO_PDBG 1 -+#endif /* GENODE_RELEASE */ -+ -+/** -+ * Print debug message with function name -+ */ -+#define PDBG(fmt, ...) \ -+ if (DO_PDBG) \ -+ printf("%s: " ESC_DBG fmt ESC_END "\n", \ -+ __PRETTY_FUNCTION__, ##__VA_ARGS__ ) ++#include + /* * Weak symbols: All libc internal usage of these functions should * use the weak symbol versions (_pthread_XXX). If libpthread is -@@ -138,12 +159,14 @@ pthread_func_entry_t __thr_jtable[PJT_MAX] = { +@@ -138,12 +140,14 @@ pthread_func_entry_t __thr_jtable[PJT_MAX] = { typedef ret (*FUNC_TYPE(name))(void); \ static ret FUNC_EXP(name)(void) \ { \ @@ -57,7 +35,7 @@ index 063676f..c5112c5 100644 FUNC_TYPE(name) func; \ func = (FUNC_TYPE(name))__thr_jtable[idx][1]; \ return (func()); \ -@@ -157,12 +180,14 @@ pthread_func_entry_t __thr_jtable[PJT_MAX] = { +@@ -157,12 +161,14 @@ pthread_func_entry_t __thr_jtable[PJT_MAX] = { typedef ret (*FUNC_TYPE(name))(p0_type); \ static ret FUNC_EXP(name)(p0_type p0) \ { \ @@ -72,7 +50,7 @@ index 063676f..c5112c5 100644 FUNC_TYPE(name) func; \ func = (FUNC_TYPE(name))__thr_jtable[idx][1]; \ return (func(p0)); \ -@@ -176,12 +201,14 @@ pthread_func_entry_t __thr_jtable[PJT_MAX] = { +@@ -176,12 +182,14 @@ pthread_func_entry_t __thr_jtable[PJT_MAX] = { typedef ret (*FUNC_TYPE(name))(p0_type, p1_type); \ static ret FUNC_EXP(name)(p0_type p0, p1_type p1) \ { \ @@ -87,7 +65,7 @@ index 063676f..c5112c5 100644 FUNC_TYPE(name) func; \ func = (FUNC_TYPE(name))__thr_jtable[idx][1]; \ return (func(p0, p1)); \ -@@ -195,12 +222,14 @@ pthread_func_entry_t __thr_jtable[PJT_MAX] = { +@@ -195,12 +203,14 @@ pthread_func_entry_t __thr_jtable[PJT_MAX] = { typedef ret (*FUNC_TYPE(name))(p0_type, p1_type, p2_type); \ static ret FUNC_EXP(name)(p0_type p0, p1_type p1, p2_type p2) \ { \