strace: TypeHandler for iovec*.

Useful for readv, writev, and writev_port_etc.
This commit is contained in:
Augustin Cavalier
2024-06-25 20:20:15 -04:00
parent 0caf909cec
commit 32c59a45e1
3 changed files with 59 additions and 28 deletions
+1 -28
View File
@@ -616,33 +616,6 @@ format_pointer(Context &context, message_args *msg)
#endif
static string
get_iovec(Context &context, iovec *iov, int iovlen)
{
if (iov == NULL && iovlen == 0)
return "(empty)";
iovec vecs[iovlen];
int32 bytesRead;
string r = "[";
status_t err = context.Reader().Read(iov, vecs, sizeof(vecs), bytesRead);
if (err != B_OK) {
r += context.FormatPointer(iov);
r += ", " + context.FormatSigned(iovlen);
} else {
for (int i = 0; i < iovlen; i++) {
if (i > 0)
r += ", ";
r += "{iov_base=" + context.FormatPointer(vecs[i].iov_base);
r += ", iov_len=" + context.FormatUnsigned(vecs[i].iov_len);
r += "}";
}
}
return r + "]";
}
static string
format_pointer(Context &context, msghdr *h)
{
@@ -650,7 +623,7 @@ format_pointer(Context &context, msghdr *h)
r = "name = " + format_pointer_value<sockaddr>(context, h->msg_name);
r += ", name_len = " + context.FormatUnsigned(h->msg_namelen);
r += ", iov = " + get_iovec(context, h->msg_iov, h->msg_iovlen);
r += ", iov = " + format_iovecs(context, h->msg_iov, h->msg_iovlen);
if (h->msg_control != NULL || h->msg_controllen != 0) {
r += ", control = " + context.FormatPointer(h->msg_control);
r += ", control_len = " + context.FormatUnsigned(h->msg_controllen);
+54
View File
@@ -11,6 +11,7 @@
#include <string.h>
#include <String.h>
#include <sys/uio.h>
#include "Context.h"
#include "MemoryReader.h"
@@ -124,6 +125,57 @@ create_status_t_type_handler()
return new StatusTypeHandler;
}
// iovec*
string
format_iovecs(Context &context, const iovec *iov, int iovlen)
{
if (iov == NULL && iovlen == 0)
return "(empty)";
iovec vecs[iovlen];
int32 bytesRead;
string r = "[";
status_t err = context.Reader().Read((void*)iov, vecs, sizeof(vecs), bytesRead);
if (err != B_OK) {
r += context.FormatPointer(iov);
r += ", " + context.FormatSigned(iovlen);
} else {
for (int i = 0; i < iovlen; i++) {
if (i > 0)
r += ", ";
r += "{iov_base=" + context.FormatPointer(vecs[i].iov_base);
r += ", iov_len=" + context.FormatUnsigned(vecs[i].iov_len);
r += "}";
}
}
return r + "]";
}
class IovecTypeHandler : public TypeHandler {
public:
IovecTypeHandler() {}
string GetParameterValue(Context &context, Parameter *param, const void *address)
{
Parameter *size = context.GetNextSibling(param);
return format_iovecs(context, (const iovec*)*(void **)address,
context.ReadValue<size_t>(size));
}
string GetReturnValue(Context &context, uint64 value)
{
return context.FormatPointer((void *)value);
}
};
TypeHandler *
create_iovec_ptr_type_handler()
{
return new IovecTypeHandler;
}
// read_string
static
string
@@ -177,6 +229,8 @@ TypeHandlerImpl<const char*>::GetReturnValue(Context &context, uint64 value)
return read_string(context, (void *)value);
}
// #pragma mark - enums, flags
EnumTypeHandler::EnumTypeHandler(const EnumMap &m) : fMap(m) {}
string
+4
View File
@@ -100,6 +100,8 @@ extern TypeHandler *create_pointer_type_handler();
extern TypeHandler *create_string_type_handler();
extern TypeHandler *create_status_t_type_handler();
extern string format_iovecs(Context &context, const struct iovec *iov, int iovlen);
// specialization for "const char*"
template<>
struct TypeHandlerFactory<const char*> {
@@ -123,6 +125,7 @@ struct fd_set;
struct flock;
struct ifconf;
struct ifreq;
struct iovec;
struct msghdr;
struct message_args;
struct pollfd;
@@ -135,6 +138,7 @@ DEFINE_FACTORY(fdset_ptr, fd_set *);
DEFINE_FACTORY(flock_ptr, flock *);
DEFINE_FACTORY(ifconf_ptr, ifconf *);
DEFINE_FACTORY(ifreq_ptr, ifreq *);
DEFINE_FACTORY(iovec_ptr, const iovec *);
DEFINE_FACTORY(msghdr_ptr, msghdr *);
DEFINE_FACTORY(msghdr_ptr, const msghdr *);
DEFINE_FACTORY(message_args_ptr, message_args *);