* Copyright 2007, Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Hugo Santos <hugosantos@gmail.com>
* Ingo Weinhold <bonefish@cs.tu-berlin.de>
*/
#include "Context.h"
#include <stdio.h>
#include <string.h>
Parameter *
Context::GetNextSibling(Parameter *param) const
{
for (int32 i = 0; i + 1 < fSyscall->CountParameters(); i++) {
if (fSyscall->ParameterAt(i) == param)
return fSyscall->ParameterAt(i + 1);
}
return NULL;
}
string
Context::FormatSigned(int64 value, int bytes) const
{
char tmp[32];
if (fDecimal) {
snprintf(tmp, sizeof(tmp), "%" B_PRId64, value);
return tmp;
}
snprintf(tmp, sizeof(tmp), "0x%" B_PRIx64, value);
int len = strlen(tmp);
int offset = len - min_c(len, bytes * 2);
if (offset <= 2) {
offset = 0;
} else {
tmp[--offset] = 'x';
tmp[--offset] = '0';
}
return tmp + offset;
}
string
Context::FormatUnsigned(uint64 value) const
{
char tmp[32];
snprintf(tmp, sizeof(tmp), fDecimal ? "%" B_PRIu64 : "0x%" B_PRIx64, value);
return tmp;
}
string
Context::FormatFlags(uint64 value) const
{
char tmp[32];
snprintf(tmp, sizeof(tmp), "0x%" B_PRIx64, value);
return tmp;
}
string
Context::FormatPointer(const void *address) const
{
char buffer[32];
sprintf(buffer, "%p", address);
return buffer;
}