[OB PATCH] Use pulongest for printing ssize_t

Gary Benson
2015-06-11T12:42:26Z

Pedro Alves wrote:
> On 06/11/2015 09:40 AM, James Greenhalgh wrote:
> > I would expect that to mean this is broken for any "long int !=
> > ssize_t" target. I'm not sure which C standards GDB requires
> > compatability with, but I believe the portable C99 way of printing
> > a ssize_t would be "%zd".
>
> GDB is written in C90 currently.
>
> The usual way to handle this is to use plongest (with %s). As this
> is native GNU/Linux code, casting to long (thus keep %ld) would be
> fine too.

This commit changes the debug printing code in linux-namespaces.c
to use pulongest instead of "%ld".

Pushed as obvious.

Thanks,
Gary

--
gdb/ChangeLog:

* nat/linux-namespaces.c (mnsh_send_message): Use pulongest.
(mnsh_recv_message): Likewise.
---
gdb/ChangeLog | 5 +++++
gdb/nat/linux-namespaces.c | 9 +++++----
2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/gdb/nat/linux-namespaces.c b/gdb/nat/linux-namespaces.c
index 98ae104..f18e40d 100644
--- a/gdb/nat/linux-namespaces.c
+++ b/gdb/nat/linux-namespaces.c
@@ -374,7 +374,7 @@ mnsh_send_message (int sock, enum mnsh_msg_type type,
{
debug_printf ("mnsh: send: ");
mnsh_debug_print_message (type, fd, int1, int2, buf, bufsiz);
- debug_printf (" -> %ld\n", size);
+ debug_printf (" -> %s\n", pulongest (size));
}

return size;
@@ -426,7 +426,8 @@ mnsh_recv_message (int sock, enum mnsh_msg_type *type,
if (size < 0)
{
if (debug_linux_namespaces)
- debug_printf ("namespace-helper: recv failed (%ld)\n", size);
+ debug_printf ("namespace-helper: recv failed (%s)\n",
+ pulongest (size));

mnsh_maybe_mourn_peer ();

@@ -437,8 +438,8 @@ mnsh_recv_message (int sock, enum mnsh_msg_type *type,
if (size < fixed_size || (msg.msg_flags & (MSG_TRUNC | MSG_CTRUNC)))
{
if (debug_linux_namespaces)
- debug_printf ("namespace-helper: recv truncated (%ld 0x%x)\n",
- size, msg.msg_flags);
+ debug_printf ("namespace-helper: recv truncated (%s 0x%x)\n",
+ pulongest (size), msg.msg_flags);

mnsh_maybe_mourn_peer ();

--
1.7.1