* Renamed the ROUNDOWN macro to ROUNDDOWN. Also changed the implementation of
ROUNDUP to use '*' and '/' -- the compiler will optimize that for powers of two anyway and this implementation works for other numbers as well. * The thread::fault_handler use in C[++] code was broken with gcc 4. At least when other functions were invoked. Trying to trick the compiler wasn't a particularly good idea anyway, since the next compiler version could break the trick again. So the general policy is to use the fault handlers only in assembly code where we have full control. Changed that for x86 (save for the vm86 mode, which has a similar mechanism), but not for the other architectures. * Introduced fault_handler, fault_handler_stack_pointer, and fault_jump_buffer fields in the cpu_ent structure, which must be used instead of thread::fault_handler in the kernel debugger. Consequently user_memcpy() must not be used in the kernel debugger either. Introduced a debug_memcpy() instead. * Introduced debug_call_with_fault_handler() function which calls a function in a setjmp() and fault handler context. The architecture specific backend arch_debug_call_with_fault_handler() has only been implemented for x86 yet. * Introduced debug_is_kernel_memory_accessible() for use in the kernel debugger. It determines whether a range of memory can be accessed in the way specified. The architecture specific back end arch_vm_translation_map_is_kernel_page_accessible() has only been implemented for x86 yet. * Added arch_debug_unset_current_thread() (only implemented for x86) to unset the current thread pointer in the kernel debugger. When entering the kernel debugger we do some basic sanity checks of the currently set thread structure and unset it, if they fail. This allows certain commands (most importantly the stack trace command) to avoid accessing the thread structure. * x86: When handling a double fault, we do now install a special handler for page faults. This allows us to gracefully catch faulting commands, even if e.g. the thread structure is toast. We are now in much better shape to deal with double faults. Hopefully avoiding the triple faults that some people have been experiencing on their hardware and ideally even allowing to use the kernel debugger normally. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@32073 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -29,6 +29,14 @@
|
||||
#define INVOKE_COMMAND_ERROR 2
|
||||
|
||||
|
||||
struct invoke_command_parameters {
|
||||
debugger_command* command;
|
||||
int argc;
|
||||
char** argv;
|
||||
int result;
|
||||
};
|
||||
|
||||
|
||||
static const int32 kMaxInvokeCommandDepth = 5;
|
||||
static const int32 kOutputBufferSize = 1024;
|
||||
|
||||
@@ -153,6 +161,16 @@ static PipeDebugOutputFilter sPipeOutputFilters[
|
||||
MAX_DEBUGGER_COMMAND_PIPE_LENGTH - 1];
|
||||
|
||||
|
||||
static void
|
||||
invoke_command_trampoline(void* _parameters)
|
||||
{
|
||||
invoke_command_parameters* parameters
|
||||
= (invoke_command_parameters*)_parameters;
|
||||
parameters->result = parameters->command->func(parameters->argc,
|
||||
parameters->argv);
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
invoke_pipe_segment(debugger_command_pipe* pipe, int32 index, char* argument)
|
||||
{
|
||||
@@ -268,9 +286,6 @@ invoke_debugger_command(struct debugger_command *command, int argc, char** argv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct thread* thread = thread_get_current_thread();
|
||||
addr_t oldFaultHandler = thread->fault_handler;
|
||||
|
||||
// replace argv[0] with the actual command name
|
||||
argv[0] = (char *)command->name;
|
||||
|
||||
@@ -284,26 +299,18 @@ invoke_debugger_command(struct debugger_command *command, int argc, char** argv)
|
||||
|
||||
sInCommand = true;
|
||||
|
||||
switch (setjmp(sInvokeCommandEnv[sInvokeCommandLevel++])) {
|
||||
invoke_command_parameters parameters;
|
||||
parameters.command = command;
|
||||
parameters.argc = argc;
|
||||
parameters.argv = argv;
|
||||
|
||||
switch (debug_call_with_fault_handler(
|
||||
sInvokeCommandEnv[sInvokeCommandLevel++],
|
||||
&invoke_command_trampoline, ¶meters)) {
|
||||
case 0:
|
||||
int result;
|
||||
thread->fault_handler = (addr_t)&&error;
|
||||
// Fake goto to trick the compiler not to optimize the code at the
|
||||
// label away.
|
||||
if (!thread)
|
||||
goto error;
|
||||
|
||||
result = command->func(argc, argv);
|
||||
|
||||
thread->fault_handler = oldFaultHandler;
|
||||
sInvokeCommandLevel--;
|
||||
sInCommand = false;
|
||||
return result;
|
||||
|
||||
error:
|
||||
// jump to INVOKE_COMMAND_FAULT case, cleaning up the stack
|
||||
longjmp(sInvokeCommandEnv[--sInvokeCommandLevel],
|
||||
INVOKE_COMMAND_FAULT);
|
||||
return parameters.result;
|
||||
|
||||
case INVOKE_COMMAND_FAULT:
|
||||
{
|
||||
@@ -324,7 +331,6 @@ invoke_debugger_command(struct debugger_command *command, int argc, char** argv)
|
||||
break;
|
||||
}
|
||||
|
||||
thread->fault_handler = oldFaultHandler;
|
||||
sInCommand = false;
|
||||
return B_KDEBUG_ERROR;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user