Re: [PATCH 3/4] gdbserver: Ensure all debug output uses debug functions

Tom de Vries
2019-06-19T09:30:00Z

On 16-04-19 21:43, Tom Tromey wrote:
>>>>>> "Alan" == Alan Hayward <Alan.Hayward@arm.com> writes:
>
> Alan> All debug output needs to go via debug functions to ensure it writes to the
> Alan> correct output stream.
>
> Alan> gdb/ChangeLog:
>
> Alan> 2019-04-16 Alan Hayward <alan.hayward@arm.com>
>
> Alan> * nat/linux-waitpid.c (linux_debug): Call debug_vprintf.
>
> Alan> gdb/gdbserver/ChangeLog:
>
> Alan> 2019-04-16 Alan Hayward <alan.hayward@arm.com>
>
> Alan> * ax.c (ax_vdebug): Call debug_printf.
> Alan> * debug.c (debug_write): New function.
> Alan> * debug.h (debug_write): New declaration.
> Alan> * linux-low.c (sigchld_handler): Call debug_write.
>

Building gdb with clang, I run into:
...
src/gdb/gdbserver/linux-low.c:6190:41: error: comparison of unsigned
expression < 0 is always false [-Werror,-Wtautological-compare]
sizeof ("sigchld_handler\n") - 1) < 0)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^ ~
...

This seems to fix it.

Thanks,
- Tom

diff --git a/gdb/gdbserver/debug.c b/gdb/gdbserver/debug.c
index a1cf5dbf7a..19f11fc17c 100644
--- a/gdb/gdbserver/debug.c
+++ b/gdb/gdbserver/debug.c
@@ -133,7 +133,7 @@ do_debug_exit (const char *function_name)

/* See debug.h. */

-size_t
+ssize_t
debug_write (const void *buf, size_t nbyte)
{
int fd = fileno (debug_file);
diff --git a/gdb/gdbserver/debug.h b/gdb/gdbserver/debug.h
index 29e58ad8a4..07e94eac6e 100644
--- a/gdb/gdbserver/debug.h
+++ b/gdb/gdbserver/debug.h
@@ -36,7 +36,7 @@ void do_debug_enter (const char *function_name);
void do_debug_exit (const char *function_name);

/* Async signal safe debug output function that calls write directly. */
-size_t debug_write (const void *buf, size_t nbyte);
+ssize_t debug_write (const void *buf, size_t nbyte);

/* These macros are for use in major functions that produce a lot of
debugging output. They help identify in the mass of debugging output