strace: Move TypeHandler for iovec back to NetworkTypes.

Takes advantage of some of its macros.
This commit is contained in:
Augustin Cavalier
2024-07-16 18:43:50 -04:00
parent 72b440df7d
commit 6c4e414fe6
3 changed files with 47 additions and 52 deletions
+47
View File
@@ -51,6 +51,52 @@ format_number(uint32 value)
}
static 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 + "]";
}
template<>
string
TypeHandlerImpl<iovec *>::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));
}
template<>
string
TypeHandlerImpl<iovec *>::GetReturnValue(Context &context, uint64 value)
{
return context.FormatPointer((void *)value);
}
static string
read_fdset(Context &context, void *data)
{
@@ -731,6 +777,7 @@ class SpecializedPointerTypeHandler : public TypeHandler {
return new SpecializedPointerTypeHandler<type>(); \
}
DEFINE_TYPE(iovec_ptr, iovec *);
DEFINE_TYPE(fdset_ptr, fd_set *);
POINTER_TYPE(flock_ptr, flock);
POINTER_TYPE(ifconf_ptr, ifconf);
-50
View File
@@ -126,56 +126,6 @@ create_status_t_type_handler()
}
// 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
-2
View File
@@ -100,8 +100,6 @@ 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*> {