From: Ralf Habacker <ralf.habacker@freenet.de> With this commit, the TRACE and TRACE_RAW macros are available in the wine server code to generate messages on stderr similar to the support for dlls. Messages generated by TRACE are prefixed with “trace:server” to distinguish them from other channels or outputs in combination with strace. --- server/Makefile.in | 1 + server/debug.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++ server/debug.h | 49 ++++++++++++++++++++++++++++++++ 3 files changed, 119 insertions(+) create mode 100644 server/debug.c create mode 100644 server/debug.h diff --git a/server/Makefile.in b/server/Makefile.in index 84a6bd74d9d..30da239d4c7 100644 --- a/server/Makefile.in +++ b/server/Makefile.in @@ -9,6 +9,7 @@ SOURCES = \ completion.c \ console.c \ d3dkmt.c \ + debug.c \ debugger.c \ device.c \ directory.c \ diff --git a/server/debug.c b/server/debug.c new file mode 100644 index 00000000000..ef2b1e86593 --- /dev/null +++ b/server/debug.c @@ -0,0 +1,69 @@ +/* + * Wine server debug and error support + * + * Copyright (C) 2025 Ralf Habacker + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include <stdarg.h> +#include <stdlib.h> + +#include "debug.h" + +#pragma GCC diagnostic ignored "-Wdeclaration-after-statement" +#pragma GCC diagnostic ignored "-Wvla" + +/* die on a fatal error */ +void fatal_error( const char *err, ... ) +{ + va_list args; + + va_start( args, err ); + fprintf( stderr, "wineserver: " ); + vfprintf( stderr, err, args ); + va_end( args ); + exit(1); +} + +void _trace(const char *file, int line, const char *func, const char *fmt, ...) +{ + va_list args1; + va_list args2; + + va_start( args1, fmt ); + va_copy( args2, args1 ); + char buf[1+vsnprintf( NULL, 0, fmt, args1 )]; + va_end( args1 ); + vsnprintf( buf, sizeof buf, fmt, args2 ); + va_end( args2 ); + + fprintf( stderr, "trace:server:%s %s", func, buf ); +} + +void _trace_raw(const char *fmt, ...) +{ + va_list args1; + va_list args2; + + va_start( args1, fmt ); + va_copy( args2, args1 ); + char buf[1+vsnprintf( NULL, 0, fmt, args1 )]; + va_end( args1 ); + vsnprintf( buf, sizeof buf, fmt, args2 ); + va_end( args2 ); + + fprintf( stderr, "%s", buf ); +} diff --git a/server/debug.h b/server/debug.h new file mode 100644 index 00000000000..7a8cabf67f2 --- /dev/null +++ b/server/debug.h @@ -0,0 +1,49 @@ +/* + * Wine server debug and error support + * + * Copyright (C) 2025 Ralf Habacker + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#ifndef __WINE_SERVER_DEBUG_H +#define __WINE_SERVER_DEBUG_H + +#include <stdio.h> + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef WINE_NO_TRACE_MSGS +void _trace(const char *file, int line, const char *func, const char *fmt, ...); +void _trace_raw(const char *fmt, ...); +#define TRACE(...) _trace(__FILE__, __LINE__, __func__, __VA_ARGS__) +#define TRACE_RAW(...) _trace_raw(__VA_ARGS__) +#else +#define TRACE(...) do { } while(0) +#endif + +#ifdef __GNUC__ +extern void fatal_error( const char *err, ... ) __attribute__((noreturn,format(printf,1,2))); +#else +extern void fatal_error( const char *err, ... ); +#endif + +#ifdef __cplusplus +} +#endif + +#endif -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/9835