#include "defs.h"
#include "inferior.h"
#include "floatformat.h"
#include "regcache.h"
#include <stdio.h>
#include <mach.h>
#include <mach/message.h>
#include <mach/exception.h>
#include <mach_error.h>
#include <target.h>
void
fetch_inferior_registers (int regno)
{
kern_return_t ret;
thread_state_data_t state;
unsigned int stateCnt = TRACE_FLAVOR_SIZE;
int index;
if (!MACH_PORT_VALID (current_thread))
error ("fetch inferior registers: Invalid thread");
if (must_suspend_thread)
setup_thread (current_thread, 1);
ret = thread_get_state (current_thread,
TRACE_FLAVOR,
state,
&stateCnt);
if (ret != KERN_SUCCESS)
warning ("fetch_inferior_registers: %s ",
mach_error_string (ret));
else
{
for (index = 0; index < NUM_REGS; index++)
supply_register (index, (void *) &state[index]);
}
if (must_suspend_thread)
setup_thread (current_thread, 0);
}
void
store_inferior_registers (int regno)
{
kern_return_t ret;
thread_state_data_t state;
unsigned int stateCnt = TRACE_FLAVOR_SIZE;
register int index;
if (!MACH_PORT_VALID (current_thread))
error ("store inferior registers: Invalid thread");
if (must_suspend_thread)
setup_thread (current_thread, 1);
ret = thread_get_state (current_thread,
TRACE_FLAVOR,
state,
&stateCnt);
if (ret != KERN_SUCCESS)
{
warning ("store_inferior_registers (get): %s",
mach_error_string (ret));
if (must_suspend_thread)
setup_thread (current_thread, 0);
return;
}
if (regno > 0 && regno < NUM_REGS)
{
memcpy (&state[regno], &deprecated_registers[REGISTER_BYTE (regno)],
REGISTER_RAW_SIZE (regno));
}
else
{
for (index = 0; index < NUM_REGS; index++)
memcpy (&state[index], &deprecated_registers[REGISTER_BYTE (index)],
REGISTER_RAW_SIZE (index));
}
ret = thread_set_state (current_thread,
TRACE_FLAVOR,
state,
TRACE_FLAVOR_SIZE);
if (ret != KERN_SUCCESS)
warning ("store_inferior_registers (set): %s",
mach_error_string (ret));
if (must_suspend_thread)
setup_thread (current_thread, 0);
}