#include "defs.h"
#include <sys/param.h>
#include <fcntl.h>
-#if HAVE_SYS_XATTR_H
+#ifdef HAVE_SYS_XATTR_H
# include <sys/xattr.h>
#endif
#include <sys/uio.h>
}
void
-printnum_long(struct tcb *tcp, long addr, const char *fmt)
+printaddr(const long addr)
{
- long num;
-
- if (!addr) {
+ if (!addr)
tprints("NULL");
- return;
- }
- if (umove(tcp, addr, &num) < 0) {
+ else
tprintf("%#lx", addr);
- return;
- }
- tprints("[");
- tprintf(fmt, num);
- tprints("]");
}
-void
-printnum_int(struct tcb *tcp, long addr, const char *fmt)
-{
- int num;
+#define DEF_PRINTNUM(name, type) \
+void \
+printnum_ ## name(struct tcb *tcp, const long addr, const char *fmt) \
+{ \
+ type num; \
+ if (!umove_or_printaddr(tcp, addr, &num)) { \
+ tprints("["); \
+ tprintf(fmt, num); \
+ tprints("]"); \
+ } \
+}
- if (!addr) {
- tprints("NULL");
- return;
- }
- if (umove(tcp, addr, &num) < 0) {
- tprintf("%#lx", addr);
- return;
- }
- tprints("[");
- tprintf(fmt, num);
- tprints("]");
+#define DEF_PRINTPAIR(name, type) \
+void \
+printpair_ ## name(struct tcb *tcp, const long addr, const char *fmt) \
+{ \
+ type pair[2]; \
+ if (!umove_or_printaddr(tcp, addr, &pair)) { \
+ tprints("["); \
+ tprintf(fmt, pair[0]); \
+ tprints(", "); \
+ tprintf(fmt, pair[1]); \
+ tprints("]"); \
+ } \
}
+DEF_PRINTNUM(long, long)
+DEF_PRINTPAIR(long, long)
+DEF_PRINTNUM(int, int)
+DEF_PRINTPAIR(int, int)
+DEF_PRINTNUM(short, short)
+#if SIZEOF_LONG != 8
+DEF_PRINTNUM(int64, uint64_t)
+DEF_PRINTPAIR(int64, uint64_t)
+#endif
+
const char *
sprinttime(time_t t)
{
static char *
getfdproto(struct tcb *tcp, int fd, char *buf, unsigned bufsize)
{
-#if HAVE_SYS_XATTR_H
+#ifdef HAVE_SYS_XATTR_H
ssize_t r;
char path[sizeof("/proc/%u/fd/%u") + 2 * sizeof(int)*3];
if (outstr_size / 4 != max_strlen)
die_out_of_memory();
- str = malloc(max_strlen + 1);
- if (!str)
- die_out_of_memory();
- outstr = malloc(outstr_size);
- if (!outstr)
- die_out_of_memory();
+ str = xmalloc(max_strlen + 1);
+ outstr = xmalloc(outstr_size);
}
size = max_strlen;
/* Assuming no sane program has millions of iovs */
if ((unsigned)len > 1024*1024 /* insane or negative size? */
|| (iov = malloc(size)) == NULL) {
- fprintf(stderr, "Out of memory\n");
+ error_msg("Out of memory");
return;
}
if (umoven(tcp, addr, size, iov) >= 0) {
str = malloc(len + 16);
if (!str) {
strsize = -1;
- fprintf(stderr, "Out of memory\n");
+ error_msg("Out of memory");
return;
}
strsize = len + 16;
return 0;
}
+int
+umoven_or_printaddr(struct tcb *tcp, const long addr, const unsigned int len,
+ void *our_addr)
+{
+ if (!addr) {
+ tprints("NULL");
+ return -1;
+ }
+ if (!verbose(tcp) || (exiting(tcp) && syserror(tcp)) ||
+ umoven(tcp, addr, len, our_addr) < 0) {
+ tprintf("%#lx", addr);
+ return -1;
+ }
+ return 0;
+}
+
/*
* Like `umove' but make the additional effort of looking
* for a terminating zero byte.