Fixed printing of signed numbers. If a long long is passed to snprintf()
the correct modifier ("ll") has to be used. On x86 it doesn't make a
difference, if that's the last argument, but with other ABIs it might.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20425 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -9,19 +9,41 @@
|
|||||||
|
|
||||||
#include "Context.h"
|
#include "Context.h"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
|
||||||
string
|
string
|
||||||
Context::FormatSigned(int64 value, const char *type) const
|
Context::FormatSigned(int64 value, int bytes) const
|
||||||
{
|
{
|
||||||
char modifier[16], tmp[32];
|
char tmp[32];
|
||||||
|
|
||||||
if (fDecimal)
|
// decimal
|
||||||
snprintf(modifier, sizeof(modifier), "%%%si", type);
|
|
||||||
else
|
|
||||||
snprintf(modifier, sizeof(modifier), "0x%%%sx", type);
|
|
||||||
|
|
||||||
snprintf(tmp, sizeof(tmp), modifier, value);
|
if (fDecimal) {
|
||||||
return tmp;
|
snprintf(tmp, sizeof(tmp), "%lld", value);
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
// hex
|
||||||
|
|
||||||
|
snprintf(tmp, sizeof(tmp), "0x%llx", value);
|
||||||
|
|
||||||
|
// Negative numbers are expanded when being converted to int64. Hence
|
||||||
|
// we skip all but the last 2 * bytes hex digits to retain the original
|
||||||
|
// type's width.
|
||||||
|
int len = strlen(tmp);
|
||||||
|
int offset = len - min_c(len, bytes * 2);
|
||||||
|
|
||||||
|
// use the existing "0x" prefix or prepend it again
|
||||||
|
if (offset <= 2) {
|
||||||
|
offset = 0;
|
||||||
|
} else {
|
||||||
|
tmp[--offset] = 'x';
|
||||||
|
tmp[--offset] = '0';
|
||||||
|
}
|
||||||
|
|
||||||
|
return tmp + offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
string
|
string
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ public:
|
|||||||
MemoryReader &Reader() { return fReader; }
|
MemoryReader &Reader() { return fReader; }
|
||||||
bool GetContents(uint32 what) const { return fFlags & what; }
|
bool GetContents(uint32 what) const { return fFlags & what; }
|
||||||
|
|
||||||
string FormatSigned(int64 value, const char *modifier = "ll") const;
|
string FormatSigned(int64 value, int bytes = 8) const;
|
||||||
string FormatUnsigned(uint64 value) const;
|
string FormatUnsigned(uint64 value) const;
|
||||||
string FormatFlags(uint64 value) const;
|
string FormatFlags(uint64 value) const;
|
||||||
|
|
||||||
|
|||||||
@@ -441,22 +441,16 @@ format_pointer(Context &context, msghdr *h)
|
|||||||
template<typename Type>
|
template<typename Type>
|
||||||
class SignedIntegerTypeHandler : public TypeHandler {
|
class SignedIntegerTypeHandler : public TypeHandler {
|
||||||
public:
|
public:
|
||||||
SignedIntegerTypeHandler(const char *modifier)
|
|
||||||
: fModifier(modifier) {}
|
|
||||||
|
|
||||||
string GetParameterValue(Context &context, Parameter *,
|
string GetParameterValue(Context &context, Parameter *,
|
||||||
const void *address)
|
const void *address)
|
||||||
{
|
{
|
||||||
return context.FormatSigned(get_value<Type>(address), fModifier);
|
return context.FormatSigned(get_value<Type>(address), sizeof(Type));
|
||||||
}
|
}
|
||||||
|
|
||||||
string GetReturnValue(Context &context, uint64 value)
|
string GetReturnValue(Context &context, uint64 value)
|
||||||
{
|
{
|
||||||
return context.FormatSigned(value, fModifier);
|
return context.FormatSigned(value, sizeof(Type));
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
|
||||||
const char *fModifier;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename Type>
|
template<typename Type>
|
||||||
@@ -494,12 +488,12 @@ class SpecializedPointerTypeHandler : public TypeHandler {
|
|||||||
return new TypeHandlerImpl<type>(); \
|
return new TypeHandlerImpl<type>(); \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define SIGNED_INTEGER_TYPE(type, modifier) \
|
#define SIGNED_INTEGER_TYPE(type) \
|
||||||
template<> \
|
template<> \
|
||||||
TypeHandler * \
|
TypeHandler * \
|
||||||
TypeHandlerFactory<type>::Create() \
|
TypeHandlerFactory<type>::Create() \
|
||||||
{ \
|
{ \
|
||||||
return new SignedIntegerTypeHandler<type>(modifier); \
|
return new SignedIntegerTypeHandler<type>(); \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define UNSIGNED_INTEGER_TYPE(type) \
|
#define UNSIGNED_INTEGER_TYPE(type) \
|
||||||
@@ -516,11 +510,11 @@ class SpecializedPointerTypeHandler : public TypeHandler {
|
|||||||
return new SpecializedPointerTypeHandler<type>(); \
|
return new SpecializedPointerTypeHandler<type>(); \
|
||||||
}
|
}
|
||||||
|
|
||||||
SIGNED_INTEGER_TYPE(char, "hh");
|
SIGNED_INTEGER_TYPE(char);
|
||||||
SIGNED_INTEGER_TYPE(short, "h");
|
SIGNED_INTEGER_TYPE(short);
|
||||||
SIGNED_INTEGER_TYPE(int, "");
|
SIGNED_INTEGER_TYPE(int);
|
||||||
SIGNED_INTEGER_TYPE(long, "l");
|
SIGNED_INTEGER_TYPE(long);
|
||||||
SIGNED_INTEGER_TYPE(long long, "ll");
|
SIGNED_INTEGER_TYPE(long long);
|
||||||
|
|
||||||
UNSIGNED_INTEGER_TYPE(unsigned char);
|
UNSIGNED_INTEGER_TYPE(unsigned char);
|
||||||
UNSIGNED_INTEGER_TYPE(unsigned short);
|
UNSIGNED_INTEGER_TYPE(unsigned short);
|
||||||
|
|||||||
Reference in New Issue
Block a user