Files
haiku-beta6/src/bin/debug/strace/Context.cpp
T

83 lines
1.5 KiB
C++
Raw Normal View History

2007-03-26 02:02:18 +00:00
/*
* Copyright 2007, Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Hugo Santos <[email protected]>
* Ingo Weinhold <[email protected]>
*/
#include "Context.h"
#include <stdio.h>
#include <string.h>
2023-06-06 01:47:01 +10:00
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;
}
2007-03-26 02:02:18 +00:00
string
Context::FormatSigned(int64 value, int bytes) const
2007-03-26 02:02:18 +00:00
{
char tmp[32];
2007-03-26 02:02:18 +00:00
// decimal
2007-03-26 02:02:18 +00:00
if (fDecimal) {
2012-08-07 20:24:55 +01:00
snprintf(tmp, sizeof(tmp), "%" B_PRId64, value);
return tmp;
}
// hex
2012-08-07 20:24:55 +01:00
snprintf(tmp, sizeof(tmp), "0x%" B_PRIx64, 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';
}
2007-03-26 22:27:15 +00:00
return tmp + offset;
2007-03-26 02:02:18 +00:00
}
string
Context::FormatUnsigned(uint64 value) const
{
char tmp[32];
2012-08-07 20:24:55 +01:00
snprintf(tmp, sizeof(tmp), fDecimal ? "%" B_PRIu64 : "0x%" B_PRIx64, value);
2007-03-26 02:02:18 +00:00
return tmp;
}
string
Context::FormatFlags(uint64 value) const
{
char tmp[32];
2012-08-07 20:24:55 +01:00
snprintf(tmp, sizeof(tmp), "0x%" B_PRIx64, value);
2007-03-26 02:02:18 +00:00
return tmp;
}
2007-03-26 22:27:15 +00:00
string
Context::FormatPointer(const void *address) const
{
char buffer[32];
sprintf(buffer, "%p", address);
return buffer;
}