- Debug output under qemu is unchanged and building with debug support us unchanged (-DDEBUG) - Add the ability to dynamically change the active debug flags in slirp_debug by defining a SLIRP_DEBUG environment variable which, if defined, sets the value of slirp_debug in slirp_init() - simh debugging support is enabled when compiling with -DUSE_SIMH_SLIRP_DEBUG
Signed-off-by: Mark Pizzolato <m...@infocomm.com> --- slirp/arp_table.c | 8 ++++---- slirp/bootp.c | 7 ------- slirp/cksum.c | 4 ++-- slirp/debug.h | 57 +++++++++++++++++++++++++++++++++++++++--------------- slirp/ip_icmp.c | 18 ++++++++--------- slirp/mbuf.c | 2 +- slirp/misc.c | 5 ++++- slirp/slirp.c | 5 +++++ slirp/socket.c | 32 +++++++++++++++--------------- slirp/tcp_input.c | 16 +++++++-------- slirp/tcp_output.c | 2 +- slirp/tcp_subr.c | 6 +++--- slirp/udp.c | 6 +++--- 13 files changed, 97 insertions(+), 71 deletions(-) diff --git a/slirp/arp_table.c b/slirp/arp_table.c index bcaeb44..9d01531 100644 --- a/slirp/arp_table.c +++ b/slirp/arp_table.c @@ -33,9 +33,9 @@ void arp_table_add(Slirp *slirp, uint32_t ip_addr, uint8_t ethaddr[ETH_ALEN]) DEBUG_CALL("arp_table_add"); DEBUG_ARG("ip = 0x%x", ip_addr); - DEBUG_ARGS((dfd, " hw addr = %02x:%02x:%02x:%02x:%02x:%02x\n", + DEBUG_ARGS(" hw addr = %02x:%02x:%02x:%02x:%02x:%02x\n", ethaddr[0], ethaddr[1], ethaddr[2], - ethaddr[3], ethaddr[4], ethaddr[5])); + ethaddr[3], ethaddr[4], ethaddr[5]); if (ip_addr == 0 || ip_addr == 0xffffffff || ip_addr == broadcast_addr) { /* Do not register broadcast addresses */ @@ -78,9 +78,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", + 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])); + out_ethaddr[3], out_ethaddr[4], out_ethaddr[5]); return 1; } } diff --git a/slirp/bootp.c b/slirp/bootp.c index b7db9fa..27a4032 100644 --- a/slirp/bootp.c +++ b/slirp/bootp.c @@ -29,13 +29,6 @@ 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) -#else -#define DPRINTF(fmt, ...) do{}while(0) -#endif - static BOOTPClient *get_new_addr(Slirp *slirp, struct in_addr *paddr, const uint8_t *macaddr) { diff --git a/slirp/cksum.c b/slirp/cksum.c index 6328660..1290883 100644 --- a/slirp/cksum.c +++ b/slirp/cksum.c @@ -123,8 +123,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/debug.h b/slirp/debug.h index 6cfa61e..7ee569a 100644 --- a/slirp/debug.h +++ b/slirp/debug.h @@ -1,3 +1,5 @@ +#ifndef SLIRP_DEBUG_H +#define SLIRP_DEBUG_H /* * Copyright (c) 1995 Danny Gasparovski. * @@ -5,30 +7,53 @@ * terms and conditions of the copyright. */ -//#define DEBUG 1 - -#ifdef DEBUG - #define DBG_CALL 0x1 #define DBG_MISC 0x2 #define DBG_ERROR 0x4 -#define dfd stderr - 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); } +#ifndef USE_SIMH_SLIRP_DEBUG /* simh build indicator */ + +#ifdef DEBUG + +#define dfd stderr + +#define DEBUG_CALL(x) do {if (slirp_debug & DBG_CALL) { fprintf (dfd, "%s...\n", x); fflush(dfd); };} while (0) +#define DEBUG_ARG(x, y) do {if (slirp_debug & DBG_CALL) { fprintf (dfd, x, y); _sim_debug (slirp_dbit, slirp_dptr, "\n"); fflush(dfd); };} while (0) +#define DEBUG_ARGS(...) do {if (slirp_debug & DBG_CALL) { fprintf (dfd, ## __VA_ARGS__); fflush(dfd); };} while (0) +#define DEBUG_MISC(...) do {if (slirp_debug & DBG_MISC) { fprintf (dfd, ## __VA_ARGS__); fflush(dfd); };} while (0) +#define DEBUG_ERROR(...) do {if (slirp_debug & DBG_ERROR) { fprintf (dfd, ## __VA_ARGS__); fflush(dfd); };} while (0) +#define DPRINTF(fmt, ...) do {if (slirp_debug & DBG_CALL) { 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(x) do {} while (0) +#define DEBUG_ARG(x, y) do {} while (0) +#define DEBUG_ARGS(...) do {} while (0) +#define DEBUG_MISC(...) do {} while (0) +#define DEBUG_ERROR(...) do {} while (0) +#define DPRINTF(fmt, ...) do {} while (0) + +#endif + +#else /* defined(USE_SIMH_SLIRP_DEBUG) */ + +#include <stdio.h> +#define DEVICE void + +extern void *slirp_dptr; +extern int slirp_dbit; + +extern void _sim_debug (int dbits, DEVICE* dptr, const char* fmt, ...); + +#define DEBUG_CALL(x) do {if (slirp_debug & DBG_CALL) { _sim_debug (slirp_dbit, slirp_dptr, "%s...\n", x); };} while (0) +#define DEBUG_ARG(x, y) do {if (slirp_debug & DBG_CALL) {_sim_debug (slirp_dbit, slirp_dptr, x, y); _sim_debug (slirp_dbit, slirp_dptr, "\n"); };} while (0) +#define DEBUG_ARGS(...) do {if (slirp_debug & DBG_CALL) { _sim_debug (slirp_dbit, slirp_dptr, ## __VA_ARGS__); };} while (0) +#define DEBUG_MISC(...) do {if (slirp_debug & DBG_MISC) { _sim_debug (slirp_dbit, slirp_dptr, ## __VA_ARGS__); };} while (0) +#define DEBUG_ERROR(...) do {if (slirp_debug & DBG_ERROR) { _sim_debug (slirp_dbit, slirp_dptr, ## __VA_ARGS__); };} while (0) +#define DPRINTF(fmt, ...) do {if (slirp_debug & DBG_CALL) { _sim_debug (slirp_dbit, slirp_dptr, fmt, ## __VA_ARGS__); };} while (0) + +#endif #endif diff --git a/slirp/ip_icmp.c b/slirp/ip_icmp.c index 9f1cb08..08024df 100644 --- a/slirp/ip_icmp.c +++ b/slirp/ip_icmp.c @@ -98,8 +98,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_error(m, ICMP_UNREACH, ICMP_UNREACH_NET, 0, strerror(errno)); icmp_detach(so); } @@ -163,8 +163,8 @@ icmp_input(struct mbuf *m, int hlen) return; } if(udp_attach(so) == -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; @@ -195,8 +195,8 @@ icmp_input(struct mbuf *m, int hlen) addr.sin_port = so->so_fport; if(sendto(so->s, icmp_ping_msg, strlen(icmp_ping_msg), 0, (struct sockaddr *)&addr, sizeof(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_error(m, ICMP_UNREACH,ICMP_UNREACH_NET, 0,strerror(errno)); udp_detach(so); } @@ -264,7 +264,7 @@ icmp_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 */ @@ -439,8 +439,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_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 4fefb04..6a414b0 100644 --- a/slirp/mbuf.c +++ b/slirp/mbuf.c @@ -235,7 +235,7 @@ dtom(Slirp *slirp, void *dat) } } - DEBUG_ERROR((dfd, "dtom failed")); + DEBUG_ERROR("dtom failed"); return (struct mbuf *)0; } diff --git a/slirp/misc.c b/slirp/misc.c index 6ec3954..e975c8f 100644 --- a/slirp/misc.c +++ b/slirp/misc.c @@ -12,8 +12,11 @@ #include "qemu/error-report.h" #include "qemu/main-loop.h" +int slirp_debug = #ifdef DEBUG -int slirp_debug = DBG_CALL|DBG_MISC|DBG_ERROR; + DBG_CALL|DBG_MISC|DBG_ERROR; +#else + 0; #endif struct quehead { diff --git a/slirp/slirp.c b/slirp/slirp.c index 8b6fa95..05bb7e0 100644 --- a/slirp/slirp.c +++ b/slirp/slirp.c @@ -208,6 +208,11 @@ Slirp *slirp_init(int restricted, struct in_addr vnetwork, slirp_init_once(); + /* set debug flags (useful when compiled with DEBUG enabled)*/ + /* bitmask values (1 = CALL, 2 = MISC, 3 = ERROR) */ + if (getenv("SLIRP_DEBUG")) + slirp_debug = atoi(getenv("SLIRP_DEBUG")); + slirp->restricted = restricted; if_init(slirp); diff --git a/slirp/socket.c b/slirp/socket.c index 4a20e08..92c9bac 100644 --- a/slirp/socket.c +++ b/slirp/socket.c @@ -165,7 +165,7 @@ soread(struct socket *so) #ifdef HAVE_READV nn = readv(so->s, (struct iovec *)iov, n); - DEBUG_MISC((dfd, " ... read nn = %d bytes\n", nn)); + DEBUG_MISC(" ... read nn = %d bytes\n", nn); #else nn = qemu_recv(so->s, iov[0].iov_base, iov[0].iov_len,0); #endif @@ -173,7 +173,7 @@ soread(struct socket *so) if (nn < 0 && (errno == EINTR || errno == EAGAIN)) return 0; else { - 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); tcp_sockclosed(sototcpcb(so)); return -1; @@ -197,7 +197,7 @@ soread(struct socket *so) nn += ret; } - DEBUG_MISC((dfd, " ... read nn = %d bytes\n", nn)); + DEBUG_MISC(" ... read nn = %d bytes\n", nn); #endif /* Update fields */ @@ -304,7 +304,7 @@ sosendoob(struct socket *so) n = slirp_send(so, sb->sb_rptr, so->so_urgc, (MSG_OOB)); /* |MSG_DONTWAIT)); */ so->so_urgc -= n; - DEBUG_MISC((dfd, " --- sent %d bytes urgent data, %d urgent bytes left\n", n, so->so_urgc)); + DEBUG_MISC(" --- sent %d bytes urgent data, %d urgent bytes left\n", n, so->so_urgc); } else { /* * Since there's no sendv or sendtov like writev, @@ -325,9 +325,9 @@ 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 - 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; @@ -389,7 +389,7 @@ sowrite(struct socket *so) #ifdef HAVE_READV nn = writev(so->s, (const struct iovec *)iov, n); - DEBUG_MISC((dfd, " ... wrote nn = %d bytes\n", nn)); + DEBUG_MISC(" ... wrote nn = %d bytes\n", nn); #else nn = slirp_send(so, iov[0].iov_base, iov[0].iov_len,0); #endif @@ -398,8 +398,8 @@ sowrite(struct socket *so) return 0; if (nn <= 0) { - 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; @@ -412,7 +412,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); #endif /* Update sbuf */ @@ -457,8 +457,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_error(so->so_m, ICMP_UNREACH,code, 0,strerror(errno)); } else { icmp_reflect(so->so_m); @@ -498,15 +498,15 @@ 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) { u_char code=ICMP_UNREACH_PORT; if(errno == EHOSTUNREACH) code=ICMP_UNREACH_HOST; else if(errno == ENETUNREACH) 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_error(so->so_m, ICMP_UNREACH,code, 0,strerror(errno)); m_free(m); } else { @@ -560,7 +560,7 @@ sosendto(struct socket *so, struct mbuf *m) addr.sin_addr = so->so_faddr; addr.sin_port = so->so_fport; - DEBUG_MISC((dfd, " sendto()ing, addr.sin_port=%d, addr.sin_addr.s_addr=%.16s\n", ntohs(addr.sin_port), inet_ntoa(addr.sin_addr))); + DEBUG_MISC(" sendto()ing, addr.sin_port=%d, addr.sin_addr.s_addr=%.16s\n", ntohs(addr.sin_port), inet_ntoa(addr.sin_addr)); /* Don't care what port we get */ ret = sendto(so->s, m->m_data, m->m_len, 0, diff --git a/slirp/tcp_input.c b/slirp/tcp_input.c index 00a77b4..011e48f 100644 --- a/slirp/tcp_input.c +++ b/slirp/tcp_input.c @@ -231,8 +231,8 @@ tcp_input(struct mbuf *m, int iphlen, struct socket *inso) Slirp *slirp; DEBUG_CALL("tcp_input"); - DEBUG_ARGS((dfd, " m = %8lx iphlen = %2d inso = %lx\n", - (long )m, iphlen, (long )inso )); + DEBUG_ARGS(" m = %8lx iphlen = %2d inso = %lx\n", + (long )m, iphlen, (long )inso ); /* * If called with m == 0, then we're continuing the connect @@ -592,8 +592,8 @@ findso: #endif ) { u_char code=ICMP_UNREACH_NET; - 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, @@ -923,8 +923,8 @@ 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 = %lx so = %lx\n", - (long )m, (long )so)); + DEBUG_MISC(" dup ack m = %lx so = %lx\n", + (long )m, (long )so); /* * If we have outstanding data (other than * a window probe), this is a completely @@ -1302,7 +1302,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 = %lx cnt=%i\n", (long)tp, cnt)); + DEBUG_ARGS(" tp = %lx cnt=%i\n", (long)tp, cnt); for (; cnt > 0; cnt -= optlen, cp += optlen) { opt = cp[0]; @@ -1490,7 +1490,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 8aa3d90..74cc682 100644 --- a/slirp/tcp_output.c +++ b/slirp/tcp_output.c @@ -89,7 +89,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 7571c5a..b2f3b07 100644 --- a/slirp/tcp_subr.c +++ b/slirp/tcp_subr.c @@ -355,9 +355,9 @@ int tcp_fconnect(struct socket *so) addr.sin_addr = so->so_faddr; addr.sin_port = so->so_fport; - DEBUG_MISC((dfd, " connect()ing, addr.sin_port=%d, " + DEBUG_MISC(" connect()ing, addr.sin_port=%d, " "addr.sin_addr.s_addr=%.16s\n", - ntohs(addr.sin_port), inet_ntoa(addr.sin_addr))); + ntohs(addr.sin_port), inet_ntoa(addr.sin_addr)); /* We don't care what port we get */ ret = connect(s,(struct sockaddr *)&addr,sizeof (addr)); @@ -913,7 +913,7 @@ int tcp_ctl(struct socket *so) return 1; } do_pty = ex_ptr->ex_pty; - 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, do_pty); } } diff --git a/slirp/udp.c b/slirp/udp.c index f77e00f..4f721b8 100644 --- a/slirp/udp.c +++ b/slirp/udp.c @@ -181,8 +181,8 @@ udp_input(register struct mbuf *m, int iphlen) goto bad; } if(udp_attach(so) == -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; } @@ -216,7 +216,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_error(m, ICMP_UNREACH,ICMP_UNREACH_NET, 0,strerror(errno)); } -- 1.9.5.msysgit.0