diff mbox series

[for-3.2,29/41] slirp: improve a bit the debug macros

Message ID 20181114123643.24091-30-marcandre.lureau@redhat.com
State New
Headers show
Series RFC: slirp: make it again a standalone project | expand

Commit Message

Marc-André Lureau Nov. 14, 2018, 12:36 p.m. UTC
Let them accept multiple arguments. Simplify the inner argument
handling of DEBUG_ARGS/DEBUG_MISC_DEBUG_ERROR.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 slirp/debug.h      | 47 ++++++++++++++++++++++++++++++++++++----------
 slirp/arp_table.c  | 12 ++++++------
 slirp/bootp.c      |  3 +--
 slirp/cksum.c      |  4 ++--
 slirp/dhcpv6.c     | 11 +++++------
 slirp/ip6_icmp.c   |  2 +-
 slirp/ip_icmp.c    | 18 +++++++++---------
 slirp/mbuf.c       |  2 +-
 slirp/ndp_table.c  | 18 +++++++++---------
 slirp/slirp.c      | 12 ++++++------
 slirp/socket.c     | 32 +++++++++++++++----------------
 slirp/tcp_input.c  | 15 +++++++--------
 slirp/tcp_output.c |  2 +-
 slirp/tcp_subr.c   |  4 ++--
 slirp/udp.c        |  6 +++---
 slirp/udp6.c       |  6 +++---
 16 files changed, 109 insertions(+), 85 deletions(-)

Comments

Daniel P. Berrangé Nov. 14, 2018, 2:04 p.m. UTC | #1
On Wed, Nov 14, 2018 at 04:36:31PM +0400, Marc-André Lureau wrote:
> Let them accept multiple arguments. Simplify the inner argument
> handling of DEBUG_ARGS/DEBUG_MISC_DEBUG_ERROR.
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  slirp/debug.h      | 47 ++++++++++++++++++++++++++++++++++++----------
>  slirp/arp_table.c  | 12 ++++++------
>  slirp/bootp.c      |  3 +--
>  slirp/cksum.c      |  4 ++--
>  slirp/dhcpv6.c     | 11 +++++------
>  slirp/ip6_icmp.c   |  2 +-
>  slirp/ip_icmp.c    | 18 +++++++++---------
>  slirp/mbuf.c       |  2 +-
>  slirp/ndp_table.c  | 18 +++++++++---------
>  slirp/slirp.c      | 12 ++++++------
>  slirp/socket.c     | 32 +++++++++++++++----------------
>  slirp/tcp_input.c  | 15 +++++++--------
>  slirp/tcp_output.c |  2 +-
>  slirp/tcp_subr.c   |  4 ++--
>  slirp/udp.c        |  6 +++---
>  slirp/udp6.c       |  6 +++---
>  16 files changed, 109 insertions(+), 85 deletions(-)
> 
> diff --git a/slirp/debug.h b/slirp/debug.h
> index 6cfa61edb3..ca3a4b04da 100644
> --- a/slirp/debug.h
> +++ b/slirp/debug.h
> @@ -17,18 +17,45 @@
>  
>  extern int slirp_debug;
>  
> -#define DEBUG_CALL(x) if (slirp_debug & DBG_CALL) { fprintf(dfd, "%s...\n", x); fflush(dfd); }
> -#define DEBUG_ARG(x, y) if (slirp_debug & DBG_CALL) { fputc(' ', dfd); fprintf(dfd, x, y); fputc('\n', dfd); fflush(dfd); }
> -#define DEBUG_ARGS(x) if (slirp_debug & DBG_CALL) { fprintf x ; fflush(dfd); }
> -#define DEBUG_MISC(x) if (slirp_debug & DBG_MISC) { fprintf x ; fflush(dfd); }
> -#define DEBUG_ERROR(x) if (slirp_debug & DBG_ERROR) {fprintf x ; fflush(dfd); }
> +#define DEBUG_CALL(fmt, ...) do {               \
> +    if (slirp_debug & DBG_CALL) {               \
> +        fprintf(dfd, fmt, ##__VA_ARGS__);       \
> +        fprintf(dfd, "...\n");                  \
> +        fflush(dfd);                            \
> +    }                                           \
> +} while (0)
> +
> +#define DEBUG_ARG(fmt, ...) do {                \
> +    if (slirp_debug & DBG_CALL) {               \
> +        fputc(' ', dfd);                        \
> +        fprintf(dfd, fmt, ##__VA_ARGS__);       \
> +        fputc('\n', dfd);                       \
> +        fflush(dfd);                            \
> +    }                                           \
> +} while (0)
> +
> +#define DEBUG_ARGS(fmt, ...) DEBUG_ARG(fmt, ##__VA_ARGS__)
> +
> +#define DEBUG_MISC(fmt, ...) do {               \
> +    if (slirp_debug & DBG_MISC) {               \
> +        fprintf(dfd, fmt, ##__VA_ARGS__);       \
> +        fflush(dfd);                            \
> +    }                                           \
> +} while (0)
> +
> +#define DEBUG_ERROR(fmt, ...) do {              \
> +    if (slirp_debug & DBG_ERROR) {              \
> +        fprintf(dfd, fmt, ##__VA_ARGS__);       \
> +        fflush(dfd);                            \
> +    }                                           \
> +} while (0)

I tend to think it would be nicer to change these to
use  g_debug, and #define G_LOG_DOMAIN  "libslirp" in
the .c files.

This would allow apps to intercept the debug messages
via a custom log handler.

Regards,
Daniel
Marc-André Lureau Nov. 14, 2018, 8:51 p.m. UTC | #2
Hi

On Wed, Nov 14, 2018 at 6:04 PM Daniel P. Berrangé <berrange@redhat.com> wrote:
>
> On Wed, Nov 14, 2018 at 04:36:31PM +0400, Marc-André Lureau wrote:
> > Let them accept multiple arguments. Simplify the inner argument
> > handling of DEBUG_ARGS/DEBUG_MISC_DEBUG_ERROR.
> >
> > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> > ---
> >  slirp/debug.h      | 47 ++++++++++++++++++++++++++++++++++++----------
> >  slirp/arp_table.c  | 12 ++++++------
> >  slirp/bootp.c      |  3 +--
> >  slirp/cksum.c      |  4 ++--
> >  slirp/dhcpv6.c     | 11 +++++------
> >  slirp/ip6_icmp.c   |  2 +-
> >  slirp/ip_icmp.c    | 18 +++++++++---------
> >  slirp/mbuf.c       |  2 +-
> >  slirp/ndp_table.c  | 18 +++++++++---------
> >  slirp/slirp.c      | 12 ++++++------
> >  slirp/socket.c     | 32 +++++++++++++++----------------
> >  slirp/tcp_input.c  | 15 +++++++--------
> >  slirp/tcp_output.c |  2 +-
> >  slirp/tcp_subr.c   |  4 ++--
> >  slirp/udp.c        |  6 +++---
> >  slirp/udp6.c       |  6 +++---
> >  16 files changed, 109 insertions(+), 85 deletions(-)
> >
> > diff --git a/slirp/debug.h b/slirp/debug.h
> > index 6cfa61edb3..ca3a4b04da 100644
> > --- a/slirp/debug.h
> > +++ b/slirp/debug.h
> > @@ -17,18 +17,45 @@
> >
> >  extern int slirp_debug;
> >
> > -#define DEBUG_CALL(x) if (slirp_debug & DBG_CALL) { fprintf(dfd, "%s...\n", x); fflush(dfd); }
> > -#define DEBUG_ARG(x, y) if (slirp_debug & DBG_CALL) { fputc(' ', dfd); fprintf(dfd, x, y); fputc('\n', dfd); fflush(dfd); }
> > -#define DEBUG_ARGS(x) if (slirp_debug & DBG_CALL) { fprintf x ; fflush(dfd); }
> > -#define DEBUG_MISC(x) if (slirp_debug & DBG_MISC) { fprintf x ; fflush(dfd); }
> > -#define DEBUG_ERROR(x) if (slirp_debug & DBG_ERROR) {fprintf x ; fflush(dfd); }
> > +#define DEBUG_CALL(fmt, ...) do {               \
> > +    if (slirp_debug & DBG_CALL) {               \
> > +        fprintf(dfd, fmt, ##__VA_ARGS__);       \
> > +        fprintf(dfd, "...\n");                  \
> > +        fflush(dfd);                            \
> > +    }                                           \
> > +} while (0)
> > +
> > +#define DEBUG_ARG(fmt, ...) do {                \
> > +    if (slirp_debug & DBG_CALL) {               \
> > +        fputc(' ', dfd);                        \
> > +        fprintf(dfd, fmt, ##__VA_ARGS__);       \
> > +        fputc('\n', dfd);                       \
> > +        fflush(dfd);                            \
> > +    }                                           \
> > +} while (0)
> > +
> > +#define DEBUG_ARGS(fmt, ...) DEBUG_ARG(fmt, ##__VA_ARGS__)
> > +
> > +#define DEBUG_MISC(fmt, ...) do {               \
> > +    if (slirp_debug & DBG_MISC) {               \
> > +        fprintf(dfd, fmt, ##__VA_ARGS__);       \
> > +        fflush(dfd);                            \
> > +    }                                           \
> > +} while (0)
> > +
> > +#define DEBUG_ERROR(fmt, ...) do {              \
> > +    if (slirp_debug & DBG_ERROR) {              \
> > +        fprintf(dfd, fmt, ##__VA_ARGS__);       \
> > +        fflush(dfd);                            \
> > +    }                                           \
> > +} while (0)
>
> I tend to think it would be nicer to change these to
> use  g_debug, and #define G_LOG_DOMAIN  "libslirp" in
> the .c files.
>
> This would allow apps to intercept the debug messages
> via a custom log handler.

Yes, even better would be structured logging, but it requires glib 2.50

One issue with the replacement is that we may want to keep the
slirp_debug filtering. If not, then we lose the classification.
Second issue is that slirp issues several debug calls and write \n in
the end. This is something you can't do with g_log. So it would need
some debug calls rewrite.

I would like to see this clean up patch applied before we decide how
to replace it with glog.

And yes, we should have a Slirp G_LOG_DOMAIN (I meant to do that, and forgot)

>
> Regards,
> Daniel
> --
> |: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
> |: https://libvirt.org         -o-            https://fstop138.berrange.com :|
> |: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
Samuel Thibault Nov. 20, 2018, 1:19 a.m. UTC | #3
Marc-André Lureau, le mer. 14 nov. 2018 16:36:31 +0400, a ecrit:
> Let them accept multiple arguments. Simplify the inner argument
> handling of DEBUG_ARGS/DEBUG_MISC_DEBUG_ERROR.
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>

Applied to my tree, thanks!
diff mbox series

Patch

diff --git a/slirp/debug.h b/slirp/debug.h
index 6cfa61edb3..ca3a4b04da 100644
--- a/slirp/debug.h
+++ b/slirp/debug.h
@@ -17,18 +17,45 @@ 
 
 extern int slirp_debug;
 
-#define DEBUG_CALL(x) if (slirp_debug & DBG_CALL) { fprintf(dfd, "%s...\n", x); fflush(dfd); }
-#define DEBUG_ARG(x, y) if (slirp_debug & DBG_CALL) { fputc(' ', dfd); fprintf(dfd, x, y); fputc('\n', dfd); fflush(dfd); }
-#define DEBUG_ARGS(x) if (slirp_debug & DBG_CALL) { fprintf x ; fflush(dfd); }
-#define DEBUG_MISC(x) if (slirp_debug & DBG_MISC) { fprintf x ; fflush(dfd); }
-#define DEBUG_ERROR(x) if (slirp_debug & DBG_ERROR) {fprintf x ; fflush(dfd); }
+#define DEBUG_CALL(fmt, ...) do {               \
+    if (slirp_debug & DBG_CALL) {               \
+        fprintf(dfd, fmt, ##__VA_ARGS__);       \
+        fprintf(dfd, "...\n");                  \
+        fflush(dfd);                            \
+    }                                           \
+} while (0)
+
+#define DEBUG_ARG(fmt, ...) do {                \
+    if (slirp_debug & DBG_CALL) {               \
+        fputc(' ', dfd);                        \
+        fprintf(dfd, fmt, ##__VA_ARGS__);       \
+        fputc('\n', dfd);                       \
+        fflush(dfd);                            \
+    }                                           \
+} while (0)
+
+#define DEBUG_ARGS(fmt, ...) DEBUG_ARG(fmt, ##__VA_ARGS__)
+
+#define DEBUG_MISC(fmt, ...) do {               \
+    if (slirp_debug & DBG_MISC) {               \
+        fprintf(dfd, fmt, ##__VA_ARGS__);       \
+        fflush(dfd);                            \
+    }                                           \
+} while (0)
+
+#define DEBUG_ERROR(fmt, ...) do {              \
+    if (slirp_debug & DBG_ERROR) {              \
+        fprintf(dfd, fmt, ##__VA_ARGS__);       \
+        fflush(dfd);                            \
+    }                                           \
+} while (0)
 
 #else
 
-#define DEBUG_CALL(x)
-#define DEBUG_ARG(x, y)
-#define DEBUG_ARGS(x)
-#define DEBUG_MISC(x)
-#define DEBUG_ERROR(x)
+#define DEBUG_CALL(fmt, ...)
+#define DEBUG_ARG(fmt, ...)
+#define DEBUG_ARGS(fmt, ...)
+#define DEBUG_MISC(fmt, ...)
+#define DEBUG_ERROR(fmt, ...)
 
 #endif
diff --git a/slirp/arp_table.c b/slirp/arp_table.c
index f81963bb88..ce19e6e7c0 100644
--- a/slirp/arp_table.c
+++ b/slirp/arp_table.c
@@ -34,9 +34,9 @@  void arp_table_add(Slirp *slirp, uint32_t ip_addr, uint8_t ethaddr[ETH_ALEN])
 
     DEBUG_CALL("arp_table_add");
     DEBUG_ARG("ip = %s", inet_ntoa((struct in_addr){.s_addr = ip_addr}));
-    DEBUG_ARGS((dfd, " hw addr = %02x:%02x:%02x:%02x:%02x:%02x\n",
-                ethaddr[0], ethaddr[1], ethaddr[2],
-                ethaddr[3], ethaddr[4], ethaddr[5]));
+    DEBUG_ARGS(" hw addr = %02x:%02x:%02x:%02x:%02x:%02x\n",
+               ethaddr[0], ethaddr[1], ethaddr[2],
+               ethaddr[3], ethaddr[4], ethaddr[5]);
 
     if (ip_addr == 0 || ip_addr == 0xffffffff || ip_addr == broadcast_addr) {
         /* Do not register broadcast addresses */
@@ -79,9 +79,9 @@  bool arp_table_search(Slirp *slirp, uint32_t ip_addr,
     for (i = 0; i < ARP_TABLE_SIZE; i++) {
         if (arptbl->table[i].ar_sip == ip_addr) {
             memcpy(out_ethaddr, arptbl->table[i].ar_sha,  ETH_ALEN);
-            DEBUG_ARGS((dfd, " found hw addr = %02x:%02x:%02x:%02x:%02x:%02x\n",
-                        out_ethaddr[0], out_ethaddr[1], out_ethaddr[2],
-                        out_ethaddr[3], out_ethaddr[4], out_ethaddr[5]));
+            DEBUG_ARGS(" found hw addr = %02x:%02x:%02x:%02x:%02x:%02x\n",
+                       out_ethaddr[0], out_ethaddr[1], out_ethaddr[2],
+                       out_ethaddr[3], out_ethaddr[4], out_ethaddr[5]);
             return 1;
         }
     }
diff --git a/slirp/bootp.c b/slirp/bootp.c
index 7b1af73c95..5ab6692038 100644
--- a/slirp/bootp.c
+++ b/slirp/bootp.c
@@ -37,8 +37,7 @@ 
 static const uint8_t rfc1533_cookie[] = { RFC1533_COOKIE };
 
 #ifdef DEBUG
-#define DPRINTF(fmt, ...) \
-do if (slirp_debug & DBG_CALL) { fprintf(dfd, fmt, ##  __VA_ARGS__); fflush(dfd); } while (0)
+#define DPRINTF(fmt, ...) DEBUG_CALL(fmt, ##__VA_ARGS__)
 #else
 #define DPRINTF(fmt, ...) do{}while(0)
 #endif
diff --git a/slirp/cksum.c b/slirp/cksum.c
index 6d73abf4a0..b9466485b5 100644
--- a/slirp/cksum.c
+++ b/slirp/cksum.c
@@ -124,8 +124,8 @@  int cksum(struct mbuf *m, int len)
 cont:
 #ifdef DEBUG
 	if (len) {
-		DEBUG_ERROR((dfd, "cksum: out of data\n"));
-		DEBUG_ERROR((dfd, " len = %d\n", len));
+		DEBUG_ERROR("cksum: out of data\n");
+		DEBUG_ERROR(" len = %d\n", len);
 	}
 #endif
 	if (mlen == -1) {
diff --git a/slirp/dhcpv6.c b/slirp/dhcpv6.c
index d266611e85..943a13bca8 100644
--- a/slirp/dhcpv6.c
+++ b/slirp/dhcpv6.c
@@ -92,14 +92,14 @@  static int dhcpv6_parse_info_request(uint8_t *odata, int olen,
                     ri->want_boot_url = true;
                     break;
                 default:
-                    DEBUG_MISC((dfd, "dhcpv6: Unsupported option request %d\n",
-                                req_opt));
+                    DEBUG_MISC("dhcpv6: Unsupported option request %d\n",
+                               req_opt);
                 }
             }
             break;
         default:
-            DEBUG_MISC((dfd, "dhcpv6 info req: Unsupported option %d, len=%d\n",
-                        option, len));
+            DEBUG_MISC("dhcpv6 info req: Unsupported option %d, len=%d\n",
+                       option, len);
         }
 
         odata += len + 4;
@@ -203,7 +203,6 @@  void dhcpv6_input(struct sockaddr_in6 *srcsas, struct mbuf *m)
         dhcpv6_info_request(m->slirp, srcsas, xid, &data[4], data_len - 4);
         break;
     default:
-        DEBUG_MISC((dfd, "dhcpv6_input: Unsupported message type 0x%x\n",
-                    data[0]));
+        DEBUG_MISC("dhcpv6_input: Unsupported message type 0x%x\n", data[0]);
     }
 }
diff --git a/slirp/ip6_icmp.c b/slirp/ip6_icmp.c
index e2e23d57bd..6f20190a0a 100644
--- a/slirp/ip6_icmp.c
+++ b/slirp/ip6_icmp.c
@@ -77,7 +77,7 @@  void icmp6_send_error(struct mbuf *m, uint8_t type, uint8_t code)
     struct ip6 *ip = mtod(m, struct ip6 *);
 
     DEBUG_CALL("icmp6_send_error");
-    DEBUG_ARGS((dfd, " type = %d, code = %d\n", type, code));
+    DEBUG_ARGS(" type = %d, code = %d\n", type, code);
 
     if (IN6_IS_ADDR_MULTICAST(&ip->ip_src) ||
             in6_zero(&ip->ip_src)) {
diff --git a/slirp/ip_icmp.c b/slirp/ip_icmp.c
index 9210eef3f3..af11cfcefe 100644
--- a/slirp/ip_icmp.c
+++ b/slirp/ip_icmp.c
@@ -99,8 +99,8 @@  static int icmp_send(struct socket *so, struct mbuf *m, int hlen)
 
     if (sendto(so->s, m->m_data + hlen, m->m_len - hlen, 0,
                (struct sockaddr *)&addr, sizeof(addr)) == -1) {
-        DEBUG_MISC((dfd, "icmp_input icmp sendto tx errno = %d-%s\n",
-                    errno, strerror(errno)));
+        DEBUG_MISC("icmp_input icmp sendto tx errno = %d-%s\n",
+                   errno, strerror(errno));
         icmp_send_error(m, ICMP_UNREACH, ICMP_UNREACH_NET, 0, strerror(errno));
         icmp_detach(so);
     }
@@ -165,8 +165,8 @@  icmp_input(struct mbuf *m, int hlen)
         return;
       }
       if (udp_attach(so, AF_INET) == -1) {
-	DEBUG_MISC((dfd,"icmp_input udp_attach errno = %d-%s\n",
-		    errno,strerror(errno)));
+	DEBUG_MISC("icmp_input udp_attach errno = %d-%s\n",
+               errno,strerror(errno));
 	sofree(so);
 	m_free(m);
 	goto end_error;
@@ -188,8 +188,8 @@  icmp_input(struct mbuf *m, int hlen)
 
       if(sendto(so->s, icmp_ping_msg, strlen(icmp_ping_msg), 0,
 		(struct sockaddr *)&addr, sockaddr_size(&addr)) == -1) {
-	DEBUG_MISC((dfd,"icmp_input udp sendto tx errno = %d-%s\n",
-		    errno,strerror(errno)));
+	DEBUG_MISC("icmp_input udp sendto tx errno = %d-%s\n",
+               errno,strerror(errno));
 	icmp_send_error(m, ICMP_UNREACH, ICMP_UNREACH_NET, 0, strerror(errno));
 	udp_detach(so);
       }
@@ -257,7 +257,7 @@  icmp_send_error(struct mbuf *msrc, u_char type, u_char code, int minsize,
   { char bufa[20], bufb[20];
     strcpy(bufa, inet_ntoa(ip->ip_src));
     strcpy(bufb, inet_ntoa(ip->ip_dst));
-    DEBUG_MISC((dfd, " %.16s to %.16s\n", bufa, bufb));
+    DEBUG_MISC(" %.16s to %.16s\n", bufa, bufb);
   }
 #endif
   if(ip->ip_off & IP_OFFMASK) goto end_error;    /* Only reply to fragment 0 */
@@ -457,8 +457,8 @@  void icmp_receive(struct socket *so)
         } else {
             error_code = ICMP_UNREACH_HOST;
         }
-        DEBUG_MISC((dfd, " udp icmp rx errno = %d-%s\n", errno,
-                    strerror(errno)));
+        DEBUG_MISC(" udp icmp rx errno = %d-%s\n", errno,
+                   strerror(errno));
         icmp_send_error(so->so_m, ICMP_UNREACH, error_code, 0, strerror(errno));
     } else {
         icmp_reflect(so->so_m);
diff --git a/slirp/mbuf.c b/slirp/mbuf.c
index aa1f28afb1..d8d275e0e7 100644
--- a/slirp/mbuf.c
+++ b/slirp/mbuf.c
@@ -232,7 +232,7 @@  dtom(Slirp *slirp, void *dat)
 	  }
 	}
 
-	DEBUG_ERROR((dfd, "dtom failed"));
+	DEBUG_ERROR("dtom failed");
 
 	return (struct mbuf *)0;
 }
diff --git a/slirp/ndp_table.c b/slirp/ndp_table.c
index e1676a0a7b..a4e6421fd3 100644
--- a/slirp/ndp_table.c
+++ b/slirp/ndp_table.c
@@ -19,9 +19,9 @@  void ndp_table_add(Slirp *slirp, struct in6_addr ip_addr,
     inet_ntop(AF_INET6, &(ip_addr), addrstr, INET6_ADDRSTRLEN);
     DEBUG_ARG("ip = %s", addrstr);
 #endif
-    DEBUG_ARGS((dfd, " hw addr = %02x:%02x:%02x:%02x:%02x:%02x\n",
-                ethaddr[0], ethaddr[1], ethaddr[2],
-                ethaddr[3], ethaddr[4], ethaddr[5]));
+    DEBUG_ARGS(" hw addr = %02x:%02x:%02x:%02x:%02x:%02x\n",
+               ethaddr[0], ethaddr[1], ethaddr[2],
+               ethaddr[3], ethaddr[4], ethaddr[5]);
 
     if (IN6_IS_ADDR_MULTICAST(&ip_addr) || in6_zero(&ip_addr)) {
         /* Do not register multicast or unspecified addresses */
@@ -69,18 +69,18 @@  bool ndp_table_search(Slirp *slirp, struct in6_addr ip_addr,
         out_ethaddr[3] = ip_addr.s6_addr[13];
         out_ethaddr[4] = ip_addr.s6_addr[14];
         out_ethaddr[5] = ip_addr.s6_addr[15];
-        DEBUG_ARGS((dfd, " multicast addr = %02x:%02x:%02x:%02x:%02x:%02x\n",
-                    out_ethaddr[0], out_ethaddr[1], out_ethaddr[2],
-                    out_ethaddr[3], out_ethaddr[4], out_ethaddr[5]));
+        DEBUG_ARGS(" multicast addr = %02x:%02x:%02x:%02x:%02x:%02x\n",
+                   out_ethaddr[0], out_ethaddr[1], out_ethaddr[2],
+                   out_ethaddr[3], out_ethaddr[4], out_ethaddr[5]);
         return 1;
     }
 
     for (i = 0; i < NDP_TABLE_SIZE; i++) {
         if (in6_equal(&ndp_table->table[i].ip_addr, &ip_addr)) {
             memcpy(out_ethaddr, ndp_table->table[i].eth_addr,  ETH_ALEN);
-            DEBUG_ARGS((dfd, " found hw addr = %02x:%02x:%02x:%02x:%02x:%02x\n",
-                        out_ethaddr[0], out_ethaddr[1], out_ethaddr[2],
-                        out_ethaddr[3], out_ethaddr[4], out_ethaddr[5]));
+            DEBUG_ARGS(" found hw addr = %02x:%02x:%02x:%02x:%02x:%02x\n",
+                       out_ethaddr[0], out_ethaddr[1], out_ethaddr[2],
+                       out_ethaddr[3], out_ethaddr[4], out_ethaddr[5]);
             return 1;
         }
     }
diff --git a/slirp/slirp.c b/slirp/slirp.c
index b1270a0309..9a87abee27 100644
--- a/slirp/slirp.c
+++ b/slirp/slirp.c
@@ -985,12 +985,12 @@  int if_encap(Slirp *slirp, struct mbuf *ifm)
     }
 
     memcpy(eh->h_dest, ethaddr, ETH_ALEN);
-    DEBUG_ARGS((dfd, " src = %02x:%02x:%02x:%02x:%02x:%02x\n",
-                eh->h_source[0], eh->h_source[1], eh->h_source[2],
-                eh->h_source[3], eh->h_source[4], eh->h_source[5]));
-    DEBUG_ARGS((dfd, " dst = %02x:%02x:%02x:%02x:%02x:%02x\n",
-                eh->h_dest[0], eh->h_dest[1], eh->h_dest[2],
-                eh->h_dest[3], eh->h_dest[4], eh->h_dest[5]));
+    DEBUG_ARGS(" src = %02x:%02x:%02x:%02x:%02x:%02x\n",
+               eh->h_source[0], eh->h_source[1], eh->h_source[2],
+               eh->h_source[3], eh->h_source[4], eh->h_source[5]);
+    DEBUG_ARGS(" dst = %02x:%02x:%02x:%02x:%02x:%02x\n",
+               eh->h_dest[0], eh->h_dest[1], eh->h_dest[2],
+               eh->h_dest[3], eh->h_dest[4], eh->h_dest[5]);
     memcpy(buf + sizeof(struct ethhdr), ifm->m_data, ifm->m_len);
     slirp->cb->output(slirp->opaque, buf, ifm->m_len + ETH_HLEN);
     return 1;
diff --git a/slirp/socket.c b/slirp/socket.c
index 7012c7c07d..677fd20c9d 100644
--- a/slirp/socket.c
+++ b/slirp/socket.c
@@ -208,7 +208,7 @@  soread(struct socket *so)
 				}
 			}
 
-			DEBUG_MISC((dfd, " --- soread() disconnected, nn = %d, errno = %d-%s\n", nn, errno,strerror(errno)));
+			DEBUG_MISC(" --- soread() disconnected, nn = %d, errno = %d-%s\n", nn, errno,strerror(errno));
 			sofcantrcvmore(so);
 
 			if (err == ECONNRESET || err == ECONNREFUSED
@@ -237,7 +237,7 @@  soread(struct socket *so)
                 nn += ret;
         }
 
-	DEBUG_MISC((dfd, " ... read nn = %d bytes\n", nn));
+	DEBUG_MISC(" ... read nn = %d bytes\n", nn);
 
 	/* Update fields */
 	sb->sb_cc += nn;
@@ -370,7 +370,7 @@  sosendoob(struct socket *so)
 		n = slirp_send(so, buff, len, (MSG_OOB)); /* |MSG_DONTWAIT)); */
 #ifdef DEBUG
 		if (n != len) {
-			DEBUG_ERROR((dfd, "Didn't send all data urgently XXXXX\n"));
+			DEBUG_ERROR("Didn't send all data urgently XXXXX\n");
 		}
 #endif
 	}
@@ -379,7 +379,7 @@  sosendoob(struct socket *so)
 		return n;
 	}
 	so->so_urgc -= n;
-	DEBUG_MISC((dfd, " ---2 sent %d bytes urgent data, %d urgent bytes left\n", n, so->so_urgc));
+	DEBUG_MISC(" ---2 sent %d bytes urgent data, %d urgent bytes left\n", n, so->so_urgc);
 
 	sb->sb_cc -= n;
 	sb->sb_rptr += n;
@@ -460,7 +460,7 @@  sowrite(struct socket *so)
             if (ret > 0)
                 nn += ret;
         }
-        DEBUG_MISC((dfd, "  ... wrote nn = %d bytes\n", nn));
+        DEBUG_MISC("  ... wrote nn = %d bytes\n", nn);
 
 	/* Update sbuf */
 	sb->sb_cc -= nn;
@@ -478,8 +478,8 @@  sowrite(struct socket *so)
 	return nn;
 
 err_disconnected:
-	DEBUG_MISC((dfd, " --- sowrite disconnected, so->so_state = %x, errno = %d\n",
-		    so->so_state, errno));
+	DEBUG_MISC(" --- sowrite disconnected, so->so_state = %x, errno = %d\n",
+               so->so_state, errno);
 	sofcantsendmore(so);
 	tcp_sockclosed(sototcpcb(so));
 	return -1;
@@ -512,8 +512,8 @@  sorecvfrom(struct socket *so)
 	    if(errno == EHOSTUNREACH) code=ICMP_UNREACH_HOST;
 	    else if(errno == ENETUNREACH) code=ICMP_UNREACH_NET;
 
-	    DEBUG_MISC((dfd," udp icmp rx errno = %d-%s\n",
-			errno,strerror(errno)));
+	    DEBUG_MISC(" udp icmp rx errno = %d-%s\n",
+                   errno,strerror(errno));
 	    icmp_send_error(so->so_m, ICMP_UNREACH, code, 0, strerror(errno));
 	  } else {
 	    icmp_reflect(so->so_m);
@@ -564,8 +564,8 @@  sorecvfrom(struct socket *so)
 
 	  m->m_len = recvfrom(so->s, m->m_data, len, 0,
 			      (struct sockaddr *)&addr, &addrlen);
-	  DEBUG_MISC((dfd, " did recvfrom %d, errno = %d-%s\n",
-		      m->m_len, errno,strerror(errno)));
+	  DEBUG_MISC(" did recvfrom %d, errno = %d-%s\n",
+                 m->m_len, errno,strerror(errno));
 	  if(m->m_len<0) {
 	    /* Report error as ICMP */
 	    switch (so->so_lfamily) {
@@ -579,7 +579,7 @@  sorecvfrom(struct socket *so)
 		code = ICMP_UNREACH_NET;
 	      }
 
-	      DEBUG_MISC((dfd, " rx error, tx icmp ICMP_UNREACH:%i\n", code));
+	      DEBUG_MISC(" rx error, tx icmp ICMP_UNREACH:%i\n", code);
 	      icmp_send_error(so->so_m, ICMP_UNREACH, code, 0, strerror(errno));
 	      break;
 	    case AF_INET6:
@@ -591,7 +591,7 @@  sorecvfrom(struct socket *so)
 		code = ICMP6_UNREACH_NO_ROUTE;
 	      }
 
-	      DEBUG_MISC((dfd, " rx error, tx icmp6 ICMP_UNREACH:%i\n", code));
+	      DEBUG_MISC(" rx error, tx icmp6 ICMP_UNREACH:%i\n", code);
 	      icmp6_send_error(so->so_m, ICMP6_UNREACH, code);
 	      break;
 	    default:
@@ -839,9 +839,9 @@  void sotranslate_out(struct socket *so, struct sockaddr_storage *addr)
             }
         }
 
-        DEBUG_MISC((dfd, " addr.sin_port=%d, "
-            "addr.sin_addr.s_addr=%.16s\n",
-            ntohs(sin->sin_port), inet_ntoa(sin->sin_addr)));
+        DEBUG_MISC(" addr.sin_port=%d, "
+                   "addr.sin_addr.s_addr=%.16s\n",
+                   ntohs(sin->sin_port), inet_ntoa(sin->sin_addr));
         break;
 
     case AF_INET6:
diff --git a/slirp/tcp_input.c b/slirp/tcp_input.c
index 922dbe32eb..e33fb83df5 100644
--- a/slirp/tcp_input.c
+++ b/slirp/tcp_input.c
@@ -236,8 +236,8 @@  tcp_input(struct mbuf *m, int iphlen, struct socket *inso, unsigned short af)
     Slirp *slirp;
 
 	DEBUG_CALL("tcp_input");
-	DEBUG_ARGS((dfd, " m = %p  iphlen = %2d  inso = %p\n",
-		    m, iphlen, inso));
+	DEBUG_ARGS(" m = %p  iphlen = %2d  inso = %p\n",
+               m, iphlen, inso);
 
 	/*
 	 * If called with m == 0, then we're continuing the connect
@@ -662,8 +662,8 @@  findso:
               (errno != EINPROGRESS) && (errno != EWOULDBLOCK)
           ) {
 	    uint8_t code;
-	    DEBUG_MISC((dfd, " tcp fconnect errno = %d-%s\n",
-			errno,strerror(errno)));
+	    DEBUG_MISC(" tcp fconnect errno = %d-%s\n",
+                   errno,strerror(errno));
 	    if(errno == ECONNREFUSED) {
 	      /* ACK the SYN, send RST to refuse the connection */
 	      tcp_respond(tp, ti, m, ti->ti_seq + 1, (tcp_seq) 0,
@@ -1032,8 +1032,7 @@  trimthenstep6:
 
 		if (SEQ_LEQ(ti->ti_ack, tp->snd_una)) {
 			if (ti->ti_len == 0 && tiwin == tp->snd_wnd) {
-			  DEBUG_MISC((dfd, " dup ack  m = %p  so = %p\n",
-				      m, so));
+			  DEBUG_MISC(" dup ack  m = %p  so = %p\n", m, so);
 				/*
 				 * If we have outstanding data (other than
 				 * a window probe), this is a completely
@@ -1411,7 +1410,7 @@  tcp_dooptions(struct tcpcb *tp, u_char *cp, int cnt, struct tcpiphdr *ti)
 	int opt, optlen;
 
 	DEBUG_CALL("tcp_dooptions");
-	DEBUG_ARGS((dfd, " tp = %p  cnt=%i\n", tp, cnt));
+	DEBUG_ARGS(" tp = %p  cnt=%i\n", tp, cnt);
 
 	for (; cnt > 0; cnt -= optlen, cp += optlen) {
 		opt = cp[0];
@@ -1611,7 +1610,7 @@  tcp_mss(struct tcpcb *tp, u_int offer)
                                                (mss - (TCP_RCVSPACE % mss)) :
                                                0));
 
-	DEBUG_MISC((dfd, " returning mss = %d\n", mss));
+	DEBUG_MISC(" returning mss = %d\n", mss);
 
 	return mss;
 }
diff --git a/slirp/tcp_output.c b/slirp/tcp_output.c
index 90b5c376f7..44da8a4e47 100644
--- a/slirp/tcp_output.c
+++ b/slirp/tcp_output.c
@@ -92,7 +92,7 @@  again:
 
 	flags = tcp_outflags[tp->t_state];
 
-	DEBUG_MISC((dfd, " --- tcp_output flags = 0x%x\n",flags));
+	DEBUG_MISC(" --- tcp_output flags = 0x%x\n", flags);
 
 	/*
 	 * If in persist timeout with window of 0, send 1 byte.
diff --git a/slirp/tcp_subr.c b/slirp/tcp_subr.c
index 8d97f1f54e..98bceea9f6 100644
--- a/slirp/tcp_subr.c
+++ b/slirp/tcp_subr.c
@@ -420,7 +420,7 @@  int tcp_fconnect(struct socket *so, unsigned short af)
     qemu_setsockopt(s, IPPROTO_TCP, TCP_NODELAY, &opt, sizeof(opt));
 
     addr = so->fhost.ss;
-    DEBUG_CALL(" connect()ing")
+    DEBUG_CALL(" connect()ing");
     sotranslate_out(so, &addr);
 
     /* We don't care what port we get */
@@ -964,7 +964,7 @@  int tcp_ctl(struct socket *so)
                     so->chardev = ex_ptr->ex_chardev;
                     return 1;
                 }
-                DEBUG_MISC((dfd, " executing %s\n", ex_ptr->ex_exec));
+                DEBUG_MISC(" executing %s\n", ex_ptr->ex_exec);
                 return fork_exec(so, ex_ptr->ex_exec);
             }
         }
diff --git a/slirp/udp.c b/slirp/udp.c
index c47870a61b..a45ad81dda 100644
--- a/slirp/udp.c
+++ b/slirp/udp.c
@@ -172,8 +172,8 @@  udp_input(register struct mbuf *m, int iphlen)
 	   */
 	  so = socreate(slirp);
 	  if (udp_attach(so, AF_INET) == -1) {
-	    DEBUG_MISC((dfd," udp_attach errno = %d-%s\n",
-			errno,strerror(errno)));
+	    DEBUG_MISC(" udp_attach errno = %d-%s\n",
+                   errno, strerror(errno));
 	    sofree(so);
 	    goto bad;
 	  }
@@ -209,7 +209,7 @@  udp_input(register struct mbuf *m, int iphlen)
 	  m->m_len += iphlen;
 	  m->m_data -= iphlen;
 	  *ip=save_ip;
-	  DEBUG_MISC((dfd,"udp tx errno = %d-%s\n",errno,strerror(errno)));
+	  DEBUG_MISC("udp tx errno = %d-%s\n", errno, strerror(errno));
 	  icmp_send_error(m, ICMP_UNREACH, ICMP_UNREACH_NET, 0,
 	                  strerror(errno));
 	  goto bad;
diff --git a/slirp/udp6.c b/slirp/udp6.c
index 986010f0d3..473ba1586e 100644
--- a/slirp/udp6.c
+++ b/slirp/udp6.c
@@ -92,8 +92,8 @@  void udp6_input(struct mbuf *m)
         /* If there's no socket for this packet, create one. */
         so = socreate(slirp);
         if (udp_attach(so, AF_INET6) == -1) {
-            DEBUG_MISC((dfd, " udp6_attach errno = %d-%s\n",
-                        errno, strerror(errno)));
+            DEBUG_MISC(" udp6_attach errno = %d-%s\n",
+                       errno, strerror(errno));
             sofree(so);
             goto bad;
         }
@@ -119,7 +119,7 @@  void udp6_input(struct mbuf *m)
         m->m_len += iphlen;
         m->m_data -= iphlen;
         *ip = save_ip;
-        DEBUG_MISC((dfd, "udp tx errno = %d-%s\n", errno, strerror(errno)));
+        DEBUG_MISC("udp tx errno = %d-%s\n", errno, strerror(errno));
         icmp6_send_error(m, ICMP6_UNREACH, ICMP6_UNREACH_NO_ROUTE);
         goto bad;
     }