1 /* 2 * Copyright 2007, Haiku Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Hugo Santos <hugosantos@gmail.com> 7 * Ingo Weinhold <bonefish@cs.tu-berlin.de> 8 */ 9 #ifndef STRACE_CONTEXT_H 10 #define STRACE_CONTEXT_H 11 12 #include "Syscall.h" 13 14 class Context { 15 public: 16 enum { 17 STRINGS = 1 << 0, 18 ENUMERATIONS = 1 << 1, 19 SIMPLE_STRUCTS = 1 << 2, 20 COMPLEX_STRUCTS = 1 << 3, 21 POINTER_VALUES = 1 << 4, 22 INPUT_VALUES = 1 << 5, 23 OUTPUT_VALUES = 1 << 6, 24 ALL = 0xffffff9f 25 }; 26 27 Context(Syscall *sc, char *data, MemoryReader &reader, 28 uint32 flags, bool decimal, uint64 returnValue = 0) fSyscall(sc)29 : fSyscall(sc), fData(data), fReader(reader), 30 fFlags(flags), fDecimal(decimal), fReturnValue(returnValue) {} 31 GetSibling(int32 index)32 Parameter *GetSibling(int32 index) const { 33 return fSyscall->ParameterAt(index); 34 } 35 36 Parameter *GetNextSibling(Parameter *param) const; 37 GetValue(Parameter * param)38 const void *GetValue(Parameter *param) const { 39 return fData + param->Offset(); 40 } 41 42 template<typename value_t> ReadValue(Parameter * param)43 value_t ReadValue(Parameter *param) const { 44 const void *address = GetValue(param); 45 if (sizeof(align_t) > sizeof(value_t)) 46 return value_t(*(align_t*)address); 47 else 48 return *(value_t*)address; 49 } 50 GetReturnValue()51 uint64 GetReturnValue() const { 52 return fReturnValue; 53 } 54 Reader()55 MemoryReader &Reader() { return fReader; } GetContents(uint32 what)56 bool GetContents(uint32 what) const { return fFlags & what; } 57 58 string FormatSigned(int64 value, int bytes = 8) const; 59 string FormatUnsigned(uint64 value) const; 60 string FormatFlags(uint64 value) const; 61 62 string FormatPointer(const void *address) const; 63 64 private: 65 Syscall *fSyscall; 66 char *fData; 67 MemoryReader &fReader; 68 uint32 fFlags; 69 bool fDecimal; 70 uint64 fReturnValue; 71 }; 72 73 #endif // STRACE_CONTEXT_H 74