The size of the strace executable was ridiculous (1.8 MB). This attempt
to trim the templatized interface improves the situation, but we're still quite heavy (400 KB). git-svn-id: file:///srv/svn/repos/haiku/trunk/current@11496 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
50ff751805
commit
11fcd6e40a
@ -6,6 +6,81 @@
|
||||
#include "MemoryReader.h"
|
||||
#include "TypeHandler.h"
|
||||
|
||||
|
||||
// TypeHandlerImpl
|
||||
template<typename Type>
|
||||
class TypeHandlerImpl : public TypeHandler {
|
||||
public:
|
||||
virtual string GetParameterValue(const void *address, bool getContents,
|
||||
MemoryReader &reader);
|
||||
|
||||
virtual string GetReturnValue(uint64 value, bool getContents,
|
||||
MemoryReader &reader);
|
||||
};
|
||||
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
// get_number_value
|
||||
template<typename value_t>
|
||||
static inline
|
||||
string
|
||||
get_number_value(const void *address, const char *format)
|
||||
{
|
||||
if (sizeof(align_t) > sizeof(value_t))
|
||||
return get_number_value<value_t>(value_t(*(align_t*)address), format);
|
||||
else
|
||||
return get_number_value<value_t>(*(value_t*)address, format);
|
||||
}
|
||||
|
||||
// get_number_value
|
||||
template<typename value_t>
|
||||
static inline
|
||||
string
|
||||
get_number_value(value_t value, const char *format)
|
||||
{
|
||||
char buffer[32];
|
||||
sprintf(buffer, format, value);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
// get_pointer_value
|
||||
static inline
|
||||
string
|
||||
get_pointer_value(const void *address)
|
||||
{
|
||||
char buffer[32];
|
||||
sprintf(buffer, "%p", *(void **)address);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
// get_pointer_value
|
||||
static inline
|
||||
string
|
||||
get_pointer_value(uint64 value)
|
||||
{
|
||||
char buffer[32];
|
||||
sprintf(buffer, "%p", (void*)value);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
// create_pointer_type_handler
|
||||
TypeHandler *
|
||||
create_pointer_type_handler()
|
||||
{
|
||||
return new TypeHandlerImpl<const void*>();
|
||||
}
|
||||
|
||||
// create_string_type_handler
|
||||
TypeHandler *
|
||||
create_string_type_handler()
|
||||
{
|
||||
return new TypeHandlerImpl<const char*>();
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
// complete specializations
|
||||
|
||||
// void
|
||||
@ -25,6 +100,13 @@ TypeHandlerImpl<void>::GetReturnValue(uint64 value, bool getContents,
|
||||
return "";
|
||||
}
|
||||
|
||||
template<>
|
||||
TypeHandler *
|
||||
TypeHandlerFactory<void>::Create()
|
||||
{
|
||||
return new TypeHandlerImpl<void>();
|
||||
}
|
||||
|
||||
// bool
|
||||
template<>
|
||||
string
|
||||
@ -42,6 +124,13 @@ TypeHandlerImpl<bool>::GetReturnValue(uint64 value, bool getContents,
|
||||
return (value ? "true" : "false");
|
||||
}
|
||||
|
||||
template<>
|
||||
TypeHandler *
|
||||
TypeHandlerFactory<bool>::Create()
|
||||
{
|
||||
return new TypeHandlerImpl<bool>();
|
||||
}
|
||||
|
||||
// char
|
||||
template<>
|
||||
string
|
||||
@ -59,6 +148,13 @@ TypeHandlerImpl<char>::GetReturnValue(uint64 value, bool getContents,
|
||||
return get_number_value<char>(value, "0x%x");
|
||||
}
|
||||
|
||||
template<>
|
||||
TypeHandler *
|
||||
TypeHandlerFactory<char>::Create()
|
||||
{
|
||||
return new TypeHandlerImpl<char>();
|
||||
}
|
||||
|
||||
// short
|
||||
template<>
|
||||
string
|
||||
@ -76,6 +172,14 @@ TypeHandlerImpl<short>::GetReturnValue(uint64 value, bool getContents,
|
||||
return get_number_value<short>(value, "0x%x");
|
||||
}
|
||||
|
||||
template<>
|
||||
TypeHandler *
|
||||
TypeHandlerFactory<short>::Create()
|
||||
{
|
||||
return new TypeHandlerImpl<short>();
|
||||
}
|
||||
|
||||
|
||||
// unsigned short
|
||||
template<>
|
||||
string
|
||||
@ -93,6 +197,13 @@ TypeHandlerImpl<unsigned short>::GetReturnValue(uint64 value, bool getContents,
|
||||
return get_number_value<unsigned short>(value, "0x%x");
|
||||
}
|
||||
|
||||
template<>
|
||||
TypeHandler *
|
||||
TypeHandlerFactory<unsigned short>::Create()
|
||||
{
|
||||
return new TypeHandlerImpl<unsigned short>();
|
||||
}
|
||||
|
||||
// int
|
||||
template<>
|
||||
string
|
||||
@ -110,6 +221,13 @@ TypeHandlerImpl<int>::GetReturnValue(uint64 value, bool getContents,
|
||||
return get_number_value<int>(value, "0x%x");
|
||||
}
|
||||
|
||||
template<>
|
||||
TypeHandler *
|
||||
TypeHandlerFactory<int>::Create()
|
||||
{
|
||||
return new TypeHandlerImpl<int>();
|
||||
}
|
||||
|
||||
// unsigned int
|
||||
template<>
|
||||
string
|
||||
@ -127,6 +245,13 @@ TypeHandlerImpl<unsigned int>::GetReturnValue(uint64 value, bool getContents,
|
||||
return get_number_value<unsigned int>(value, "0x%x");
|
||||
}
|
||||
|
||||
template<>
|
||||
TypeHandler *
|
||||
TypeHandlerFactory<unsigned int>::Create()
|
||||
{
|
||||
return new TypeHandlerImpl<unsigned int>();
|
||||
}
|
||||
|
||||
// long
|
||||
template<>
|
||||
string
|
||||
@ -144,6 +269,13 @@ TypeHandlerImpl<long>::GetReturnValue(uint64 value, bool getContents,
|
||||
return get_number_value<long>(value, "0x%lx");
|
||||
}
|
||||
|
||||
template<>
|
||||
TypeHandler *
|
||||
TypeHandlerFactory<long>::Create()
|
||||
{
|
||||
return new TypeHandlerImpl<long>();
|
||||
}
|
||||
|
||||
// unsigned long
|
||||
template<>
|
||||
string
|
||||
@ -161,6 +293,13 @@ TypeHandlerImpl<unsigned long>::GetReturnValue(uint64 value, bool getContents,
|
||||
return get_number_value<unsigned long>(value, "0x%lx");
|
||||
}
|
||||
|
||||
template<>
|
||||
TypeHandler *
|
||||
TypeHandlerFactory<unsigned long>::Create()
|
||||
{
|
||||
return new TypeHandlerImpl<unsigned long>();
|
||||
}
|
||||
|
||||
// long long
|
||||
template<>
|
||||
string
|
||||
@ -178,6 +317,13 @@ TypeHandlerImpl<long long>::GetReturnValue(uint64 value, bool getContents,
|
||||
return get_number_value<long long>(value, "0x%llx");
|
||||
}
|
||||
|
||||
template<>
|
||||
TypeHandler *
|
||||
TypeHandlerFactory<long long>::Create()
|
||||
{
|
||||
return new TypeHandlerImpl<long long>();
|
||||
}
|
||||
|
||||
// unsigned long
|
||||
template<>
|
||||
string
|
||||
@ -195,6 +341,13 @@ TypeHandlerImpl<unsigned long long>::GetReturnValue(uint64 value,
|
||||
return get_number_value<unsigned long long>(value, "0x%llx");
|
||||
}
|
||||
|
||||
template<>
|
||||
TypeHandler *
|
||||
TypeHandlerFactory<unsigned long long>::Create()
|
||||
{
|
||||
return new TypeHandlerImpl<unsigned long long>();
|
||||
}
|
||||
|
||||
// read_string
|
||||
static
|
||||
string
|
||||
@ -224,6 +377,22 @@ read_string(MemoryReader &reader, void *data)
|
||||
return get_pointer_value(&data) + " (" + strerror(error) + ")";
|
||||
}
|
||||
|
||||
// const void*
|
||||
template<>
|
||||
string
|
||||
TypeHandlerImpl<const void*>::GetParameterValue(const void *address,
|
||||
bool getContents, MemoryReader &reader)
|
||||
{
|
||||
return get_pointer_value(address);
|
||||
}
|
||||
|
||||
template<>
|
||||
string
|
||||
TypeHandlerImpl<const void*>::GetReturnValue(uint64 value, bool getContents,
|
||||
MemoryReader &reader)
|
||||
{
|
||||
return get_pointer_value(value);
|
||||
}
|
||||
|
||||
// const char*
|
||||
template<>
|
||||
@ -249,3 +418,4 @@ TypeHandlerImpl<const char*>::GetReturnValue(uint64 value,
|
||||
|
||||
return get_pointer_value(&data);
|
||||
}
|
||||
|
||||
|
@ -27,98 +27,34 @@ public:
|
||||
MemoryReader &reader) = 0;
|
||||
};
|
||||
|
||||
// TypeHandlerImpl
|
||||
// templatized TypeHandler factory class
|
||||
// (I tried a simple function first, but then the compiler complains for
|
||||
// the partial instantiation. Not sure, if I'm missing something or this is
|
||||
// a compiler bug).
|
||||
template<typename Type>
|
||||
class TypeHandlerImpl : public TypeHandler {
|
||||
public:
|
||||
virtual string GetParameterValue(const void *address, bool getContents,
|
||||
MemoryReader &reader);
|
||||
|
||||
virtual string GetReturnValue(uint64 value, bool getContents,
|
||||
MemoryReader &reader);
|
||||
struct TypeHandlerFactory {
|
||||
static TypeHandler *Create();
|
||||
};
|
||||
|
||||
extern TypeHandler *create_pointer_type_handler();
|
||||
extern TypeHandler *create_string_type_handler();
|
||||
|
||||
// TypeHandlerImpl
|
||||
template<typename Type>
|
||||
class TypeHandlerImpl<Type*> : public TypeHandler {
|
||||
public:
|
||||
virtual string GetParameterValue(const void *address, bool getContents,
|
||||
MemoryReader &reader);
|
||||
|
||||
virtual string GetReturnValue(uint64 value, bool getContents,
|
||||
MemoryReader &reader);
|
||||
// specialization for "const char*"
|
||||
template<>
|
||||
struct TypeHandlerFactory<const char*> {
|
||||
static inline TypeHandler *Create()
|
||||
{
|
||||
return create_string_type_handler();
|
||||
}
|
||||
};
|
||||
|
||||
//// TypeHandlerImpl
|
||||
//template<>
|
||||
//class TypeHandlerImpl<const char*> : public TypeHandler {
|
||||
//public:
|
||||
// virtual string GetParameterValue(const void *address, bool getContents,
|
||||
// MemoryReader &reader);
|
||||
//
|
||||
// virtual string GetReturnValue(uint64 value, bool getContents,
|
||||
// MemoryReader &reader);
|
||||
//};
|
||||
|
||||
// get_number_value
|
||||
template<typename value_t>
|
||||
static inline
|
||||
string
|
||||
get_number_value(const void *address, const char *format)
|
||||
{
|
||||
if (sizeof(align_t) > sizeof(value_t))
|
||||
return get_number_value<value_t>(value_t(*(align_t*)address), format);
|
||||
else
|
||||
return get_number_value<value_t>(*(value_t*)address, format);
|
||||
}
|
||||
|
||||
// get_number_value
|
||||
template<typename value_t>
|
||||
static inline
|
||||
string
|
||||
get_number_value(value_t value, const char *format)
|
||||
{
|
||||
char buffer[32];
|
||||
sprintf(buffer, format, value);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
// get_pointer_value
|
||||
static inline
|
||||
string
|
||||
get_pointer_value(const void *address)
|
||||
{
|
||||
char buffer[32];
|
||||
sprintf(buffer, "%p", *(void **)address);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
// get_pointer_value
|
||||
static inline
|
||||
string
|
||||
get_pointer_value(uint64 value)
|
||||
{
|
||||
char buffer[32];
|
||||
sprintf(buffer, "%p", (void*)value);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
// generic pointer
|
||||
// partial specialization for generic pointers
|
||||
template<typename Type>
|
||||
string
|
||||
TypeHandlerImpl<Type*>::GetParameterValue(const void *address, bool getContents,
|
||||
MemoryReader &reader)
|
||||
{
|
||||
return get_pointer_value(address);
|
||||
}
|
||||
|
||||
template<typename Type>
|
||||
string
|
||||
TypeHandlerImpl<Type*>::GetReturnValue(uint64 value, bool getContents,
|
||||
MemoryReader &reader)
|
||||
{
|
||||
return get_pointer_value(value);
|
||||
}
|
||||
struct TypeHandlerFactory<Type*> {
|
||||
static inline TypeHandler *Create()
|
||||
{
|
||||
return create_pointer_type_handler();
|
||||
}
|
||||
};
|
||||
|
||||
#endif // STRACE_TYPE_HANDLER_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user