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:
@@ -6,6 +6,81 @@
|
|||||||
#include "MemoryReader.h"
|
#include "MemoryReader.h"
|
||||||
#include "TypeHandler.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
|
// complete specializations
|
||||||
|
|
||||||
// void
|
// void
|
||||||
@@ -25,6 +100,13 @@ TypeHandlerImpl<void>::GetReturnValue(uint64 value, bool getContents,
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<>
|
||||||
|
TypeHandler *
|
||||||
|
TypeHandlerFactory<void>::Create()
|
||||||
|
{
|
||||||
|
return new TypeHandlerImpl<void>();
|
||||||
|
}
|
||||||
|
|
||||||
// bool
|
// bool
|
||||||
template<>
|
template<>
|
||||||
string
|
string
|
||||||
@@ -42,6 +124,13 @@ TypeHandlerImpl<bool>::GetReturnValue(uint64 value, bool getContents,
|
|||||||
return (value ? "true" : "false");
|
return (value ? "true" : "false");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<>
|
||||||
|
TypeHandler *
|
||||||
|
TypeHandlerFactory<bool>::Create()
|
||||||
|
{
|
||||||
|
return new TypeHandlerImpl<bool>();
|
||||||
|
}
|
||||||
|
|
||||||
// char
|
// char
|
||||||
template<>
|
template<>
|
||||||
string
|
string
|
||||||
@@ -59,6 +148,13 @@ TypeHandlerImpl<char>::GetReturnValue(uint64 value, bool getContents,
|
|||||||
return get_number_value<char>(value, "0x%x");
|
return get_number_value<char>(value, "0x%x");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<>
|
||||||
|
TypeHandler *
|
||||||
|
TypeHandlerFactory<char>::Create()
|
||||||
|
{
|
||||||
|
return new TypeHandlerImpl<char>();
|
||||||
|
}
|
||||||
|
|
||||||
// short
|
// short
|
||||||
template<>
|
template<>
|
||||||
string
|
string
|
||||||
@@ -76,6 +172,14 @@ TypeHandlerImpl<short>::GetReturnValue(uint64 value, bool getContents,
|
|||||||
return get_number_value<short>(value, "0x%x");
|
return get_number_value<short>(value, "0x%x");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<>
|
||||||
|
TypeHandler *
|
||||||
|
TypeHandlerFactory<short>::Create()
|
||||||
|
{
|
||||||
|
return new TypeHandlerImpl<short>();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// unsigned short
|
// unsigned short
|
||||||
template<>
|
template<>
|
||||||
string
|
string
|
||||||
@@ -93,6 +197,13 @@ TypeHandlerImpl<unsigned short>::GetReturnValue(uint64 value, bool getContents,
|
|||||||
return get_number_value<unsigned short>(value, "0x%x");
|
return get_number_value<unsigned short>(value, "0x%x");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<>
|
||||||
|
TypeHandler *
|
||||||
|
TypeHandlerFactory<unsigned short>::Create()
|
||||||
|
{
|
||||||
|
return new TypeHandlerImpl<unsigned short>();
|
||||||
|
}
|
||||||
|
|
||||||
// int
|
// int
|
||||||
template<>
|
template<>
|
||||||
string
|
string
|
||||||
@@ -110,6 +221,13 @@ TypeHandlerImpl<int>::GetReturnValue(uint64 value, bool getContents,
|
|||||||
return get_number_value<int>(value, "0x%x");
|
return get_number_value<int>(value, "0x%x");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<>
|
||||||
|
TypeHandler *
|
||||||
|
TypeHandlerFactory<int>::Create()
|
||||||
|
{
|
||||||
|
return new TypeHandlerImpl<int>();
|
||||||
|
}
|
||||||
|
|
||||||
// unsigned int
|
// unsigned int
|
||||||
template<>
|
template<>
|
||||||
string
|
string
|
||||||
@@ -127,6 +245,13 @@ TypeHandlerImpl<unsigned int>::GetReturnValue(uint64 value, bool getContents,
|
|||||||
return get_number_value<unsigned int>(value, "0x%x");
|
return get_number_value<unsigned int>(value, "0x%x");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<>
|
||||||
|
TypeHandler *
|
||||||
|
TypeHandlerFactory<unsigned int>::Create()
|
||||||
|
{
|
||||||
|
return new TypeHandlerImpl<unsigned int>();
|
||||||
|
}
|
||||||
|
|
||||||
// long
|
// long
|
||||||
template<>
|
template<>
|
||||||
string
|
string
|
||||||
@@ -144,6 +269,13 @@ TypeHandlerImpl<long>::GetReturnValue(uint64 value, bool getContents,
|
|||||||
return get_number_value<long>(value, "0x%lx");
|
return get_number_value<long>(value, "0x%lx");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<>
|
||||||
|
TypeHandler *
|
||||||
|
TypeHandlerFactory<long>::Create()
|
||||||
|
{
|
||||||
|
return new TypeHandlerImpl<long>();
|
||||||
|
}
|
||||||
|
|
||||||
// unsigned long
|
// unsigned long
|
||||||
template<>
|
template<>
|
||||||
string
|
string
|
||||||
@@ -161,6 +293,13 @@ TypeHandlerImpl<unsigned long>::GetReturnValue(uint64 value, bool getContents,
|
|||||||
return get_number_value<unsigned long>(value, "0x%lx");
|
return get_number_value<unsigned long>(value, "0x%lx");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<>
|
||||||
|
TypeHandler *
|
||||||
|
TypeHandlerFactory<unsigned long>::Create()
|
||||||
|
{
|
||||||
|
return new TypeHandlerImpl<unsigned long>();
|
||||||
|
}
|
||||||
|
|
||||||
// long long
|
// long long
|
||||||
template<>
|
template<>
|
||||||
string
|
string
|
||||||
@@ -178,6 +317,13 @@ TypeHandlerImpl<long long>::GetReturnValue(uint64 value, bool getContents,
|
|||||||
return get_number_value<long long>(value, "0x%llx");
|
return get_number_value<long long>(value, "0x%llx");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<>
|
||||||
|
TypeHandler *
|
||||||
|
TypeHandlerFactory<long long>::Create()
|
||||||
|
{
|
||||||
|
return new TypeHandlerImpl<long long>();
|
||||||
|
}
|
||||||
|
|
||||||
// unsigned long
|
// unsigned long
|
||||||
template<>
|
template<>
|
||||||
string
|
string
|
||||||
@@ -195,6 +341,13 @@ TypeHandlerImpl<unsigned long long>::GetReturnValue(uint64 value,
|
|||||||
return get_number_value<unsigned long long>(value, "0x%llx");
|
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
|
// read_string
|
||||||
static
|
static
|
||||||
string
|
string
|
||||||
@@ -224,6 +377,22 @@ read_string(MemoryReader &reader, void *data)
|
|||||||
return get_pointer_value(&data) + " (" + strerror(error) + ")";
|
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*
|
// const char*
|
||||||
template<>
|
template<>
|
||||||
@@ -249,3 +418,4 @@ TypeHandlerImpl<const char*>::GetReturnValue(uint64 value,
|
|||||||
|
|
||||||
return get_pointer_value(&data);
|
return get_pointer_value(&data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,98 +27,34 @@ public:
|
|||||||
MemoryReader &reader) = 0;
|
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>
|
template<typename Type>
|
||||||
class TypeHandlerImpl : public TypeHandler {
|
struct TypeHandlerFactory {
|
||||||
public:
|
static TypeHandler *Create();
|
||||||
virtual string GetParameterValue(const void *address, bool getContents,
|
|
||||||
MemoryReader &reader);
|
|
||||||
|
|
||||||
virtual string GetReturnValue(uint64 value, bool getContents,
|
|
||||||
MemoryReader &reader);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extern TypeHandler *create_pointer_type_handler();
|
||||||
|
extern TypeHandler *create_string_type_handler();
|
||||||
|
|
||||||
// TypeHandlerImpl
|
// specialization for "const char*"
|
||||||
template<typename Type>
|
template<>
|
||||||
class TypeHandlerImpl<Type*> : public TypeHandler {
|
struct TypeHandlerFactory<const char*> {
|
||||||
public:
|
static inline TypeHandler *Create()
|
||||||
virtual string GetParameterValue(const void *address, bool getContents,
|
{
|
||||||
MemoryReader &reader);
|
return create_string_type_handler();
|
||||||
|
}
|
||||||
virtual string GetReturnValue(uint64 value, bool getContents,
|
|
||||||
MemoryReader &reader);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//// TypeHandlerImpl
|
// partial specialization for generic pointers
|
||||||
//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
|
|
||||||
template<typename Type>
|
template<typename Type>
|
||||||
string
|
struct TypeHandlerFactory<Type*> {
|
||||||
TypeHandlerImpl<Type*>::GetParameterValue(const void *address, bool getContents,
|
static inline TypeHandler *Create()
|
||||||
MemoryReader &reader)
|
{
|
||||||
{
|
return create_pointer_type_handler();
|
||||||
return get_pointer_value(address);
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
template<typename Type>
|
|
||||||
string
|
|
||||||
TypeHandlerImpl<Type*>::GetReturnValue(uint64 value, bool getContents,
|
|
||||||
MemoryReader &reader)
|
|
||||||
{
|
|
||||||
return get_pointer_value(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // STRACE_TYPE_HANDLER_H
|
#endif // STRACE_TYPE_HANDLER_H
|
||||||
|
|||||||
Reference in New Issue
Block a user