strace: Handle ssize_t differently than status_t.
It's 64-bit on 64-bit architectures and must be handled as such. Fixes strace outputs seen in #16861. Also clean up style a bit.
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
#include "MemoryReader.h"
|
||||
#include "Syscall.h"
|
||||
|
||||
|
||||
template<typename value_t>
|
||||
static inline value_t
|
||||
get_value(const void *address)
|
||||
@@ -27,25 +28,28 @@ get_value(const void *address)
|
||||
return *(value_t*)address;
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
// create_pointer_type_handler
|
||||
|
||||
// const void *
|
||||
TypeHandler *
|
||||
create_pointer_type_handler()
|
||||
{
|
||||
return new TypeHandlerImpl<const void*>();
|
||||
}
|
||||
|
||||
// create_string_type_handler
|
||||
|
||||
// const char *
|
||||
TypeHandler *
|
||||
create_string_type_handler()
|
||||
{
|
||||
return new TypeHandlerImpl<const char*>();
|
||||
}
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
// complete specializations
|
||||
// #pragma mark - complete specializations
|
||||
|
||||
|
||||
// void
|
||||
template<>
|
||||
@@ -55,6 +59,7 @@ TypeHandlerImpl<void>::GetParameterValue(Context &, Parameter *, const void *)
|
||||
return "void";
|
||||
}
|
||||
|
||||
|
||||
template<>
|
||||
string
|
||||
TypeHandlerImpl<void>::GetReturnValue(Context &, uint64 value)
|
||||
@@ -62,6 +67,7 @@ TypeHandlerImpl<void>::GetReturnValue(Context &, uint64 value)
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
template<>
|
||||
TypeHandler *
|
||||
TypeHandlerFactory<void>::Create()
|
||||
@@ -69,6 +75,7 @@ TypeHandlerFactory<void>::Create()
|
||||
return new TypeHandlerImpl<void>();
|
||||
}
|
||||
|
||||
|
||||
// bool
|
||||
template<>
|
||||
string
|
||||
@@ -92,14 +99,16 @@ TypeHandlerFactory<bool>::Create()
|
||||
return new TypeHandlerImpl<bool>();
|
||||
}
|
||||
|
||||
|
||||
// status_t
|
||||
template<typename T>
|
||||
class StatusTypeHandler : public TypeHandler {
|
||||
public:
|
||||
StatusTypeHandler() {}
|
||||
|
||||
string GetParameterValue(Context &context, Parameter *, const void *address)
|
||||
{
|
||||
return RenderValue(context, get_value<status_t>(address));
|
||||
return RenderValue(context, get_value<T>(address));
|
||||
}
|
||||
|
||||
string GetReturnValue(Context &context, uint64 value)
|
||||
@@ -111,7 +120,7 @@ private:
|
||||
string RenderValue(Context &context, uint64 value) const
|
||||
{
|
||||
string rendered = context.FormatUnsigned(value);
|
||||
if (value <= UINT32_MAX && (status_t)value <= 0) {
|
||||
if (value <= UINT32_MAX && (T)value <= 0) {
|
||||
rendered += " ";
|
||||
rendered += strerror(value);
|
||||
}
|
||||
@@ -122,7 +131,13 @@ private:
|
||||
TypeHandler *
|
||||
create_status_t_type_handler()
|
||||
{
|
||||
return new StatusTypeHandler;
|
||||
return new StatusTypeHandler<status_t>;
|
||||
}
|
||||
|
||||
TypeHandler *
|
||||
create_ssize_t_type_handler()
|
||||
{
|
||||
return new StatusTypeHandler<ssize_t>;
|
||||
}
|
||||
|
||||
|
||||
@@ -179,8 +194,10 @@ TypeHandlerImpl<const char*>::GetReturnValue(Context &context, uint64 value)
|
||||
return read_string(context, (void *)value);
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark - enums, flags, enum_flags
|
||||
|
||||
|
||||
EnumTypeHandler::EnumTypeHandler(const EnumMap &m) : fMap(m) {}
|
||||
|
||||
string
|
||||
|
||||
@@ -108,6 +108,7 @@ struct TypeHandlerFactory {
|
||||
extern TypeHandler *create_pointer_type_handler();
|
||||
extern TypeHandler *create_string_type_handler();
|
||||
extern TypeHandler *create_status_t_type_handler();
|
||||
extern TypeHandler *create_ssize_t_type_handler();
|
||||
|
||||
// specialization for "const char*"
|
||||
template<>
|
||||
|
||||
@@ -243,10 +243,10 @@ patch_syscalls()
|
||||
|
||||
// patch return type handlers
|
||||
const string returnTypeName = syscall->ReturnType()->TypeName();
|
||||
if (returnTypeName == "status_t" || returnTypeName == "ssize_t"
|
||||
|| returnTypeName == "int") {
|
||||
if (returnTypeName == "status_t" || returnTypeName == "int")
|
||||
syscall->ReturnType()->SetHandler(create_status_t_type_handler());
|
||||
}
|
||||
else if (returnTypeName == "ssize_t")
|
||||
syscall->ReturnType()->SetHandler(create_ssize_t_type_handler());
|
||||
}
|
||||
|
||||
patch_area();
|
||||
|
||||
Reference in New Issue
Block a user