From 95ebbeb153442c8378e91f4dd9710945a91ce19f Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Mon, 26 Mar 2007 02:02:18 +0000 Subject: [PATCH] Reorganized sources a bit: * Context got its own source and header files. * Syscall::GetSyscall() had little to do with the Syscall class itself; it's get_syscall() now. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20424 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/bin/strace/Context.cpp | 41 ++++++++++++++++++++++++++ src/bin/strace/Context.h | 52 +++++++++++++++++++++++++++++++++ src/bin/strace/Jamfile | 4 ++- src/bin/strace/Syscall.h | 40 ------------------------- src/bin/strace/TypeHandler.cpp | 1 + src/bin/strace/ioctl.cpp | 3 +- src/bin/strace/strace.cpp | 53 +++++++++------------------------- src/bin/strace/strace.h | 16 ++++++++++ 8 files changed, 128 insertions(+), 82 deletions(-) create mode 100644 src/bin/strace/Context.cpp create mode 100644 src/bin/strace/Context.h create mode 100644 src/bin/strace/strace.h diff --git a/src/bin/strace/Context.cpp b/src/bin/strace/Context.cpp new file mode 100644 index 0000000000..301990dba2 --- /dev/null +++ b/src/bin/strace/Context.cpp @@ -0,0 +1,41 @@ +/* + * Copyright 2007, Haiku Inc. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Hugo Santos + * Ingo Weinhold + */ + +#include "Context.h" + + +string +Context::FormatSigned(int64 value, const char *type) const +{ + char modifier[16], tmp[32]; + + if (fDecimal) + snprintf(modifier, sizeof(modifier), "%%%si", type); + else + snprintf(modifier, sizeof(modifier), "0x%%%sx", type); + + snprintf(tmp, sizeof(tmp), modifier, value); + return tmp; +} + +string +Context::FormatUnsigned(uint64 value) const +{ + char tmp[32]; + snprintf(tmp, sizeof(tmp), fDecimal ? "%llu" : "0x%llx", value); + return tmp; +} + +string +Context::FormatFlags(uint64 value) const +{ + char tmp[32]; + snprintf(tmp, sizeof(tmp), "0x%llx", value); + return tmp; +} diff --git a/src/bin/strace/Context.h b/src/bin/strace/Context.h new file mode 100644 index 0000000000..ba766a9698 --- /dev/null +++ b/src/bin/strace/Context.h @@ -0,0 +1,52 @@ +/* + * Copyright 2007, Haiku Inc. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Hugo Santos + * Ingo Weinhold + */ +#ifndef STRACE_CONTEXT_H +#define STRACE_CONTEXT_H + +#include "Syscall.h" + +class Context { +public: + enum { + STRINGS = 1 << 0, + ENUMERATIONS = 1 << 1, + SIMPLE_STRUCTS = 1 << 2, + COMPLEX_STRUCTS = 1 << 3, + ALL = 0xffffffff + }; + + Context(Syscall *sc, char *data, MemoryReader &reader, + uint32 flags, bool decimal) + : fSyscall(sc), fData(data), fReader(reader), + fFlags(flags), fDecimal(decimal) {} + + Parameter *GetSibling(int32 index) const { + return fSyscall->ParameterAt(index); + } + + const void *GetValue(Parameter *param) const { + return fData + param->Offset(); + } + + MemoryReader &Reader() { return fReader; } + bool GetContents(uint32 what) const { return fFlags & what; } + + string FormatSigned(int64 value, const char *modifier = "ll") const; + string FormatUnsigned(uint64 value) const; + string FormatFlags(uint64 value) const; + +private: + Syscall *fSyscall; + char *fData; + MemoryReader &fReader; + uint32 fFlags; + bool fDecimal; +}; + +#endif // STRACE_CONTEXT_H diff --git a/src/bin/strace/Jamfile b/src/bin/strace/Jamfile index 6ee19c6888..b8da2b1592 100644 --- a/src/bin/strace/Jamfile +++ b/src/bin/strace/Jamfile @@ -8,7 +8,9 @@ UsePrivateHeaders net ; # find headers generated by gensyscalls SubDirHdrs $(TARGET_COMMON_DEBUG_LOCATE_TARGET) ; -local straceSources = strace.cpp MemoryReader.cpp TypeHandler.cpp ioctl.cpp ; +local straceSources = + Context.cpp ioctl.cpp MemoryReader.cpp strace.cpp TypeHandler.cpp +; # Our compiler badly chokes when compiling the generated file. So will # split up the job into 20 pieces. diff --git a/src/bin/strace/Syscall.h b/src/bin/strace/Syscall.h index b7b00207b9..a59904ea76 100644 --- a/src/bin/strace/Syscall.h +++ b/src/bin/strace/Syscall.h @@ -106,50 +106,10 @@ public: return NULL; } - static Syscall *GetSyscall(const char *); - private: string fName; Type *fReturnType; vector fParameters; }; -class Context { -public: - enum { - STRINGS = 1 << 0, - ENUMERATIONS = 1 << 1, - SIMPLE_STRUCTS = 1 << 2, - COMPLEX_STRUCTS = 1 << 3, - ALL = 0xffffffff - }; - - Context(Syscall *sc, char *data, MemoryReader &reader, - uint32 flags, bool decimal) - : fSyscall(sc), fData(data), fReader(reader), - fFlags(flags), fDecimal(decimal) {} - - Parameter *GetSibling(int32 index) const { - return fSyscall->ParameterAt(index); - } - - const void *GetValue(Parameter *param) const { - return fData + param->Offset(); - } - - MemoryReader &Reader() { return fReader; } - bool GetContents(uint32 what) const { return fFlags & what; } - - string FormatSigned(int64 value, const char *modifier = "ll") const; - string FormatUnsigned(uint64 value) const; - string FormatFlags(uint64 value) const; - -private: - Syscall *fSyscall; - char *fData; - MemoryReader &fReader; - uint32 fFlags; - bool fDecimal; -}; - #endif // STRACE_SYSCALL_H diff --git a/src/bin/strace/TypeHandler.cpp b/src/bin/strace/TypeHandler.cpp index 2a9e57c896..ebe887453a 100644 --- a/src/bin/strace/TypeHandler.cpp +++ b/src/bin/strace/TypeHandler.cpp @@ -16,6 +16,7 @@ #include +#include "Context.h" #include "MemoryReader.h" #include "Syscall.h" diff --git a/src/bin/strace/ioctl.cpp b/src/bin/strace/ioctl.cpp index 36abb1a11b..e2bc1a6744 100644 --- a/src/bin/strace/ioctl.cpp +++ b/src/bin/strace/ioctl.cpp @@ -9,6 +9,7 @@ #include #include +#include "strace.h" #include "Syscall.h" #include "TypeHandler.h" @@ -80,7 +81,7 @@ patch_ioctl() kIoctlTypeHandlers[kIOCtls[i].index] = kIOCtls[i].handler; } - Syscall *ioctl = Syscall::GetSyscall("_kern_ioctl"); + Syscall *ioctl = get_syscall("_kern_ioctl"); ioctl->GetParameter("cmd")->SetHandler( new EnumTypeHandler(kIoctlNames)); diff --git a/src/bin/strace/strace.cpp b/src/bin/strace/strace.cpp index daa8b7e1a0..7ed3396b98 100644 --- a/src/bin/strace/strace.cpp +++ b/src/bin/strace/strace.cpp @@ -17,6 +17,7 @@ #include #include +#include "Context.h" #include "MemoryReader.h" #include "Syscall.h" #include "TypeHandler.h" @@ -268,6 +269,18 @@ continue_thread(port_id nubPort, thread_id thread) } } +// get_syscall +Syscall * +get_syscall(const char *name) +{ + map::const_iterator i = sSyscallMap.find(name); + if (i == sSyscallMap.end()) + return NULL; + + return i->second; +} + +// patch_syscalls static void patch_syscalls() { @@ -661,43 +674,3 @@ main(int argc, const char *const *argv) return 0; } - -Syscall * -Syscall::GetSyscall(const char *name) -{ - map::const_iterator i = sSyscallMap.find(name); - if (i == sSyscallMap.end()) - return NULL; - - return i->second; -} - -string -Context::FormatSigned(int64 value, const char *type) const -{ - char modifier[16], tmp[32]; - - if (fDecimal) - snprintf(modifier, sizeof(modifier), "%%%si", type); - else - snprintf(modifier, sizeof(modifier), "0x%%%sx", type); - - snprintf(tmp, sizeof(tmp), modifier, value); - return tmp; -} - -string -Context::FormatUnsigned(uint64 value) const -{ - char tmp[32]; - snprintf(tmp, sizeof(tmp), fDecimal ? "%llu" : "0x%llx", value); - return tmp; -} - -string -Context::FormatFlags(uint64 value) const -{ - char tmp[32]; - snprintf(tmp, sizeof(tmp), "0x%llx", value); - return tmp; -} diff --git a/src/bin/strace/strace.h b/src/bin/strace/strace.h new file mode 100644 index 0000000000..ec559ce4b1 --- /dev/null +++ b/src/bin/strace/strace.h @@ -0,0 +1,16 @@ +/* + * Copyright 2007, Haiku Inc. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Hugo Santos + * Ingo Weinhold + */ +#ifndef STRACE_H +#define STRACE_H + +class Syscall; + +Syscall *get_syscall(const char *name); + +#endif // STRACE_H