Support for printing fd_sets. Patch by Hugo Santos.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20414 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
6376aa3f7a
commit
af9825c29c
@ -1,6 +1,10 @@
|
||||
/*
|
||||
* Copyright 2005, Ingo Weinhold, bonefish@users.sf.net.
|
||||
* Copyright 2005-2007, Haiku Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Ingo Weinhold <bonefish@cs.tu-berlin.de>
|
||||
* Hugo Santos <hugosantos@gmail.com>
|
||||
*/
|
||||
|
||||
#include "MemoryReader.h"
|
||||
@ -78,6 +82,12 @@ create_string_type_handler()
|
||||
return new TypeHandlerImpl<const char*>();
|
||||
}
|
||||
|
||||
TypeHandler *
|
||||
create_fdset_type_handler()
|
||||
{
|
||||
return new TypeHandlerImpl<struct fd_set *>();
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
@ -377,6 +387,43 @@ read_string(MemoryReader &reader, void *data)
|
||||
return get_pointer_value(&data) + " (" + strerror(error) + ")";
|
||||
}
|
||||
|
||||
static string
|
||||
read_fdset(MemoryReader &reader, void *data)
|
||||
{
|
||||
/* default FD_SETSIZE is 1024 */
|
||||
unsigned long tmp[1024 / (sizeof(unsigned long) * 8)];
|
||||
int32 bytesRead;
|
||||
|
||||
status_t err = reader.Read(data, &tmp, sizeof(tmp), bytesRead);
|
||||
if (err != B_OK)
|
||||
return get_pointer_value(&data);
|
||||
|
||||
/* implicitly align to unsigned long lower boundary */
|
||||
int count = bytesRead / sizeof(unsigned long);
|
||||
int added = 0;
|
||||
|
||||
string r = "[";
|
||||
|
||||
for (int i = 0; i < count && added < 8; i++) {
|
||||
for (int j = 0;
|
||||
j < (int)(sizeof(unsigned long) * 8) && added < 8; j++) {
|
||||
if (tmp[i] & (1 << j)) {
|
||||
if (added > 0)
|
||||
r += ", ";
|
||||
r += get_number_value<unsigned long>(
|
||||
i * (sizeof(unsigned long) * 8) + j,
|
||||
"%u");
|
||||
added++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (added >= 8)
|
||||
r += " ...";
|
||||
|
||||
return r + "]";
|
||||
}
|
||||
|
||||
// const void*
|
||||
template<>
|
||||
string
|
||||
@ -419,3 +466,26 @@ TypeHandlerImpl<const char*>::GetReturnValue(uint64 value,
|
||||
return get_pointer_value(&data);
|
||||
}
|
||||
|
||||
// struct fd_set *
|
||||
template<>
|
||||
string
|
||||
TypeHandlerImpl<struct fd_set *>::GetParameterValue(const void *address,
|
||||
bool getContents, MemoryReader &reader)
|
||||
{
|
||||
void *data = *(void **)address;
|
||||
if (getContents && data)
|
||||
return read_fdset(reader, data);
|
||||
return get_pointer_value(&data);
|
||||
}
|
||||
|
||||
template<>
|
||||
string
|
||||
TypeHandlerImpl<struct fd_set *>::GetReturnValue(uint64 value,
|
||||
bool getContents, MemoryReader &reader)
|
||||
{
|
||||
void *data = (void *)value;
|
||||
if (getContents && data)
|
||||
return read_fdset(reader, data);
|
||||
|
||||
return get_pointer_value(&data);
|
||||
}
|
||||
|
@ -1,6 +1,10 @@
|
||||
/*
|
||||
* Copyright 2005, Ingo Weinhold, bonefish@users.sf.net.
|
||||
* Copyright 2005-2007, Haiku Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Ingo Weinhold <bonefish@cs.tu-berlin.de>
|
||||
* Hugo Santos <hugosantos@gmail.com>
|
||||
*/
|
||||
#ifndef STRACE_TYPE_HANDLER_H
|
||||
#define STRACE_TYPE_HANDLER_H
|
||||
@ -40,6 +44,7 @@ struct TypeHandlerFactory {
|
||||
|
||||
extern TypeHandler *create_pointer_type_handler();
|
||||
extern TypeHandler *create_string_type_handler();
|
||||
extern TypeHandler *create_fdset_type_handler();
|
||||
|
||||
// specialization for "const char*"
|
||||
template<>
|
||||
@ -50,6 +55,15 @@ struct TypeHandlerFactory<const char*> {
|
||||
}
|
||||
};
|
||||
|
||||
// specialization for 'struct fdset *'
|
||||
template<>
|
||||
struct TypeHandlerFactory<struct fd_set *> {
|
||||
static inline TypeHandler *Create()
|
||||
{
|
||||
return create_fdset_type_handler();
|
||||
}
|
||||
};
|
||||
|
||||
// partial specialization for generic pointers
|
||||
template<typename Type>
|
||||
struct TypeHandlerFactory<Type*> {
|
||||
|
Loading…
x
Reference in New Issue
Block a user