Files
haiku-beta6/src/bin/debug/strace/Context.cpp
T
Trung Nguyen a2cb4665de strace: Improvements
- Added some utility functions to the `Context` class.
- Updated the `sockaddr` handler to retrieve the next sibling
rather than the sibling at index 2. This allows the handler to
work for syscalls where the `socklen_t` argument is not the third
one, for example, `_kern_recvfrom`.
- Added the ability to print the `flatArgs` for `_kern_exec` and
`_kern_load_image`.

Change-Id: Ia4cf0a30a5cf972274820bbf068101450db52189
Reviewed-on: https://review.haiku-os.org/c/haiku/+/6498
Reviewed-by: waddlesplash <[email protected]>
2023-06-06 15:10:35 +00:00

83 lines
1.5 KiB
C++

/*
* 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>
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];
// decimal
if (fDecimal) {
snprintf(tmp, sizeof(tmp), "%" B_PRId64, value);
return tmp;
}
// hex
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';
}
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;
}