Adjust debug API to address some x86-64 concerns.
- The argument buffer contained in the debug_{pre,post}_syscall message structures wasn't large enough to accomodate all arguments for some syscalls on x86-64, which could potentially have led to kernel memory corruption when using syscall tracing via the debug API. As such, enlarge it to accomodate 64-bit platforms as well. - Adjust TeamDebugger/SyscallInfo to discriminate the target architecture and read the arguments when trapping console output. Gets the latter working on x86-64.
This commit is contained in:
parent
277945a648
commit
77ea49f4f2
|
@ -487,7 +487,7 @@ typedef struct {
|
||||||
typedef struct {
|
typedef struct {
|
||||||
debug_origin origin;
|
debug_origin origin;
|
||||||
uint32 syscall; // the syscall number
|
uint32 syscall; // the syscall number
|
||||||
uint32 args[16]; // syscall arguments
|
uint8 args[128]; // syscall arguments
|
||||||
} debug_pre_syscall;
|
} debug_pre_syscall;
|
||||||
|
|
||||||
// B_DEBUGGER_MESSAGE_POST_SYSCALL
|
// B_DEBUGGER_MESSAGE_POST_SYSCALL
|
||||||
|
@ -498,7 +498,7 @@ typedef struct {
|
||||||
bigtime_t end_time; // time of syscall completion
|
bigtime_t end_time; // time of syscall completion
|
||||||
uint64 return_value; // the syscall's return value
|
uint64 return_value; // the syscall's return value
|
||||||
uint32 syscall; // the syscall number
|
uint32 syscall; // the syscall number
|
||||||
uint32 args[16]; // syscall arguments
|
uint8 args[128]; // syscall arguments
|
||||||
} debug_post_syscall;
|
} debug_post_syscall;
|
||||||
|
|
||||||
// B_DEBUGGER_MESSAGE_SIGNAL_RECEIVED
|
// B_DEBUGGER_MESSAGE_SIGNAL_RECEIVED
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
#include "debug_utils.h"
|
#include "debug_utils.h"
|
||||||
#include "syscall_numbers.h"
|
#include "syscall_numbers.h"
|
||||||
|
|
||||||
|
#include "Architecture.h"
|
||||||
#include "BreakpointManager.h"
|
#include "BreakpointManager.h"
|
||||||
#include "BreakpointSetting.h"
|
#include "BreakpointSetting.h"
|
||||||
#include "CpuState.h"
|
#include "CpuState.h"
|
||||||
|
@ -1415,16 +1416,37 @@ bool
|
||||||
TeamDebugger::_HandlePostSyscall(PostSyscallEvent* event)
|
TeamDebugger::_HandlePostSyscall(PostSyscallEvent* event)
|
||||||
{
|
{
|
||||||
const SyscallInfo& info = event->GetSyscallInfo();
|
const SyscallInfo& info = event->GetSyscallInfo();
|
||||||
const uint32* args = info.Arguments();
|
|
||||||
|
|
||||||
switch (info.Syscall()) {
|
switch (info.Syscall()) {
|
||||||
case SYSCALL_WRITE:
|
case SYSCALL_WRITE:
|
||||||
{
|
{
|
||||||
int32 fd = (int32)args[0];
|
int32 fd;
|
||||||
|
target_addr_t address;
|
||||||
|
size_t size;
|
||||||
|
// TODO: decoding the syscall arguments should probably be
|
||||||
|
// factored out into an Architecture method of its own, since
|
||||||
|
// there's no guarantee the target architecture has the same
|
||||||
|
// endianness as the host. This could re-use the syscall
|
||||||
|
// argument parser that strace uses, though that would need to
|
||||||
|
// be adapted to handle the aforementioned endian differences.
|
||||||
|
// This works for x86{-64} for now though.
|
||||||
|
if (fTeam->GetArchitecture()->AddressSize() == 4) {
|
||||||
|
const uint32* args = (const uint32*)info.Arguments();
|
||||||
|
fd = args[0];
|
||||||
|
address = args[3];
|
||||||
|
size = args[4];
|
||||||
|
} else {
|
||||||
|
const uint64* args = (const uint64*)info.Arguments();
|
||||||
|
fd = args[0];
|
||||||
|
address = args[2];
|
||||||
|
size = args[3];
|
||||||
|
}
|
||||||
|
|
||||||
if (fd == 1 || fd == 2) {
|
if (fd == 1 || fd == 2) {
|
||||||
BString data;
|
BString data;
|
||||||
|
|
||||||
ssize_t result = fDebuggerInterface->ReadMemoryString(
|
ssize_t result = fDebuggerInterface->ReadMemoryString(
|
||||||
(target_addr_t)args[3], (size_t)args[4], data);
|
address, size, data);
|
||||||
if (result >= 0)
|
if (result >= 0)
|
||||||
fTeam->NotifyConsoleOutputReceived(fd, data);
|
fTeam->NotifyConsoleOutputReceived(fd, data);
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ SyscallInfo::SyscallInfo(const SyscallInfo& other)
|
||||||
|
|
||||||
|
|
||||||
SyscallInfo::SyscallInfo(bigtime_t startTime, bigtime_t endTime,
|
SyscallInfo::SyscallInfo(bigtime_t startTime, bigtime_t endTime,
|
||||||
uint64 returnValue, uint32 syscall, const uint32* args)
|
uint64 returnValue, uint32 syscall, const uint8* args)
|
||||||
:
|
:
|
||||||
fStartTime(startTime),
|
fStartTime(startTime),
|
||||||
fEndTime(endTime),
|
fEndTime(endTime),
|
||||||
|
@ -44,7 +44,7 @@ SyscallInfo::SyscallInfo(bigtime_t startTime, bigtime_t endTime,
|
||||||
|
|
||||||
void
|
void
|
||||||
SyscallInfo::SetTo(bigtime_t startTime, bigtime_t endTime, uint64 returnValue,
|
SyscallInfo::SetTo(bigtime_t startTime, bigtime_t endTime, uint64 returnValue,
|
||||||
uint32 syscall, const uint32* args)
|
uint32 syscall, const uint8* args)
|
||||||
{
|
{
|
||||||
fStartTime = startTime;
|
fStartTime = startTime;
|
||||||
fEndTime = endTime;
|
fEndTime = endTime;
|
||||||
|
|
|
@ -16,27 +16,27 @@ public:
|
||||||
bigtime_t endTime,
|
bigtime_t endTime,
|
||||||
uint64 returnValue,
|
uint64 returnValue,
|
||||||
uint32 syscall,
|
uint32 syscall,
|
||||||
const uint32* args);
|
const uint8* args);
|
||||||
|
|
||||||
void SetTo(bigtime_t startTime,
|
void SetTo(bigtime_t startTime,
|
||||||
bigtime_t endTime,
|
bigtime_t endTime,
|
||||||
uint64 returnValue,
|
uint64 returnValue,
|
||||||
uint32 syscall,
|
uint32 syscall,
|
||||||
const uint32* args);
|
const uint8* args);
|
||||||
|
|
||||||
bigtime_t StartTime() const { return fStartTime; }
|
bigtime_t StartTime() const { return fStartTime; }
|
||||||
bigtime_t EndTime() const { return fEndTime; }
|
bigtime_t EndTime() const { return fEndTime; }
|
||||||
uint64 ReturnValue() const { return fReturnValue; }
|
uint64 ReturnValue() const { return fReturnValue; }
|
||||||
uint32 Syscall() const { return fSyscall; }
|
uint32 Syscall() const { return fSyscall; }
|
||||||
|
|
||||||
const uint32* Arguments() const { return fArguments; }
|
const uint8* Arguments() const { return fArguments; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bigtime_t fStartTime;
|
bigtime_t fStartTime;
|
||||||
bigtime_t fEndTime;
|
bigtime_t fEndTime;
|
||||||
uint64 fReturnValue;
|
uint64 fReturnValue;
|
||||||
uint32 fSyscall;
|
uint32 fSyscall;
|
||||||
uint32 fArguments[16];
|
uint8 fArguments[128];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue