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
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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"
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright 2007, Haiku Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Hugo Santos <[email protected]>
|
||||
* Ingo Weinhold <[email protected]>
|
||||
*/
|
||||
#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
|
||||
@@ -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.
|
||||
|
||||
@@ -106,50 +106,10 @@ public:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static Syscall *GetSyscall(const char *);
|
||||
|
||||
private:
|
||||
string fName;
|
||||
Type *fReturnType;
|
||||
vector<Parameter*> 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
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
#include <net_stack_driver.h>
|
||||
|
||||
#include "Context.h"
|
||||
#include "MemoryReader.h"
|
||||
#include "Syscall.h"
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include <net_stack_driver.h>
|
||||
#include <termios.h>
|
||||
|
||||
#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));
|
||||
|
||||
+13
-40
@@ -17,6 +17,7 @@
|
||||
#include <image.h>
|
||||
#include <syscalls.h>
|
||||
|
||||
#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<string, Syscall *>::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<string, Syscall *>::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;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Copyright 2007, Haiku Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Hugo Santos <hugosantos@gmail.com>
|
||||
* Ingo Weinhold <bonefish@cs.tu-berlin.de>
|
||||
*/
|
||||
#ifndef STRACE_H
|
||||
#define STRACE_H
|
||||
|
||||
class Syscall;
|
||||
|
||||
Syscall *get_syscall(const char *name);
|
||||
|
||||
#endif // STRACE_H
|
||||
Reference in New Issue
Block a user