Adjust debug_utils functions.

The functions in question now return an error rather than simply calling
exit() directly when they fail, as this behavior wasn't acceptable for
e.g. Debugger. Adjusted all calling apps accordingly.
This commit is contained in:
Rene Gollent
2013-06-28 18:49:28 -04:00
parent 23f48a24d0
commit 4dc355e9a9
6 changed files with 70 additions and 49 deletions
@@ -351,8 +351,10 @@ DebuggerInterface::GetNextDebugEvent(DebugEvent*& _event)
if (ignore) { if (ignore) {
if (message.origin.thread >= 0 && message.origin.nub_port >= 0) if (message.origin.thread >= 0 && message.origin.nub_port >= 0)
continue_thread(message.origin.nub_port, error = continue_thread(message.origin.nub_port,
message.origin.thread); message.origin.thread);
if (error != B_OK)
return error;
continue; continue;
} }
@@ -373,16 +375,14 @@ DebuggerInterface::GetNextDebugEvent(DebugEvent*& _event)
status_t status_t
DebuggerInterface::SetTeamDebuggingFlags(uint32 flags) DebuggerInterface::SetTeamDebuggingFlags(uint32 flags)
{ {
set_team_debugging_flags(fNubPort, flags); return set_team_debugging_flags(fNubPort, flags);
return B_OK;
} }
status_t status_t
DebuggerInterface::ContinueThread(thread_id thread) DebuggerInterface::ContinueThread(thread_id thread)
{ {
continue_thread(fNubPort, thread); return continue_thread(fNubPort, thread);
return B_OK;
} }
+27 -25
View File
@@ -1,5 +1,6 @@
/* /*
* Copyright 2005-2008, Ingo Weinhold, ingo_weinhold@gmx.de. * Copyright 2005-2008, Ingo Weinhold, ingo_weinhold@gmx.de.
* Copyright 2013, Rene Gollent, rene@gollent.com.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
@@ -116,52 +117,52 @@ load_program(const char* const* args, int32 argCount, bool traceLoading)
// set_team_debugging_flags // set_team_debugging_flags
void status_t
set_team_debugging_flags(port_id nubPort, int32 flags) set_team_debugging_flags(port_id nubPort, int32 flags)
{ {
debug_nub_set_team_flags message; debug_nub_set_team_flags message;
message.flags = flags; message.flags = flags;
while (true) { status_t error = B_OK;
status_t error = write_port(nubPort, B_DEBUG_MESSAGE_SET_TEAM_FLAGS, do {
error = write_port(nubPort, B_DEBUG_MESSAGE_SET_TEAM_FLAGS,
&message, sizeof(message)); &message, sizeof(message));
if (error == B_OK) } while (error == B_INTERRUPTED);
return;
if (error != B_INTERRUPTED) { if (error != B_OK) {
fprintf(stderr, "%s: Failed to set team debug flags: %s\n", fprintf(stderr, "%s: Failed to set team debug flags: %s\n",
kCommandName, strerror(error)); kCommandName, strerror(error));
exit(1);
}
} }
return error;
} }
// set_thread_debugging_flags // set_thread_debugging_flags
void status_t
set_thread_debugging_flags(port_id nubPort, thread_id thread, int32 flags) set_thread_debugging_flags(port_id nubPort, thread_id thread, int32 flags)
{ {
debug_nub_set_thread_flags message; debug_nub_set_thread_flags message;
message.thread = thread; message.thread = thread;
message.flags = flags; message.flags = flags;
while (true) { status_t error = B_OK;
status_t error = write_port(nubPort, B_DEBUG_MESSAGE_SET_THREAD_FLAGS, do {
error = write_port(nubPort, B_DEBUG_MESSAGE_SET_THREAD_FLAGS,
&message, sizeof(message)); &message, sizeof(message));
if (error == B_OK) } while (error == B_INTERRUPTED);
return;
if (error != B_INTERRUPTED) { if (error != B_OK) {
fprintf(stderr, "%s: Failed to set thread debug flags: %s\n", fprintf(stderr, "%s: Failed to set thread debug flags: %s\n",
kCommandName, strerror(error)); kCommandName, strerror(error));
exit(1);
}
} }
return error;
} }
// continue_thread // continue_thread
void status_t
continue_thread(port_id nubPort, thread_id thread) continue_thread(port_id nubPort, thread_id thread)
{ {
debug_nub_continue_thread message; debug_nub_continue_thread message;
@@ -169,16 +170,17 @@ continue_thread(port_id nubPort, thread_id thread)
message.handle_event = B_THREAD_DEBUG_HANDLE_EVENT; message.handle_event = B_THREAD_DEBUG_HANDLE_EVENT;
message.single_step = false; message.single_step = false;
while (true) { status_t error = B_OK;
status_t error = write_port(nubPort, B_DEBUG_MESSAGE_CONTINUE_THREAD,
&message, sizeof(message));
if (error == B_OK)
return;
if (error != B_INTERRUPTED) { do {
error = write_port(nubPort, B_DEBUG_MESSAGE_CONTINUE_THREAD,
&message, sizeof(message));
} while (error == B_INTERRUPTED);
if (error != B_OK) {
fprintf(stderr, "%s: Failed to run thread %" B_PRId32 ": %s\n", fprintf(stderr, "%s: Failed to run thread %" B_PRId32 ": %s\n",
kCommandName, thread, strerror(error)); kCommandName, thread, strerror(error));
exit(1);
}
} }
return error;
} }
+3 -3
View File
@@ -11,10 +11,10 @@
thread_id load_program(const char* const* args, int32 argCount, thread_id load_program(const char* const* args, int32 argCount,
bool traceLoading); bool traceLoading);
void set_team_debugging_flags(port_id nubPort, int32 flags); status_t set_team_debugging_flags(port_id nubPort, int32 flags);
void set_thread_debugging_flags(port_id nubPort, thread_id thread, status_t set_thread_debugging_flags(port_id nubPort, thread_id thread,
int32 flags); int32 flags);
void continue_thread(port_id nubPort, thread_id thread); status_t continue_thread(port_id nubPort, thread_id thread);
#endif // BIN_DEBUG_DEBUG_UTILS_H #endif // BIN_DEBUG_DEBUG_UTILS_H
+9 -3
View File
@@ -1,5 +1,6 @@
/* /*
* Copyright 2008-2010, Ingo Weinhold, ingo_weinhold@gmx.de. * Copyright 2008-2010, Ingo Weinhold, ingo_weinhold@gmx.de.
* Copyright 2013, Rene Gollent, rene@gollent.com.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
@@ -86,7 +87,9 @@ Team::Init(team_id teamID, port_id debuggerPort)
// set team debugging flags // set team debugging flags
int32 teamDebugFlags = B_TEAM_DEBUG_THREADS int32 teamDebugFlags = B_TEAM_DEBUG_THREADS
| B_TEAM_DEBUG_TEAM_CREATION | B_TEAM_DEBUG_IMAGES; | B_TEAM_DEBUG_TEAM_CREATION | B_TEAM_DEBUG_IMAGES;
set_team_debugging_flags(fNubPort, teamDebugFlags); error = set_team_debugging_flags(fNubPort, teamDebugFlags);
if (error != B_OK)
return error;
return B_OK; return B_OK;
} }
@@ -138,7 +141,10 @@ Team::InitThread(Thread* thread)
// | (traceChildThreads // | (traceChildThreads
// ? B_THREAD_DEBUG_SYSCALL_TRACE_CHILD_THREADS : 0); // ? B_THREAD_DEBUG_SYSCALL_TRACE_CHILD_THREADS : 0);
// } // }
set_thread_debugging_flags(fNubPort, thread->ID(), threadDebugFlags); status_t error = set_thread_debugging_flags(fNubPort, thread->ID(),
threadDebugFlags);
if (error != B_OK)
return error;
// start profiling // start profiling
debug_nub_start_profiler message; debug_nub_start_profiler message;
@@ -150,7 +156,7 @@ Team::InitThread(Thread* thread)
message.variable_stack_depth = gOptions.analyze_full_stack; message.variable_stack_depth = gOptions.analyze_full_stack;
debug_nub_start_profiler_reply reply; debug_nub_start_profiler_reply reply;
status_t error = send_debug_message(&fDebugContext, error = send_debug_message(&fDebugContext,
B_DEBUG_START_PROFILER, &message, sizeof(message), &reply, B_DEBUG_START_PROFILER, &message, sizeof(message), &reply,
sizeof(reply)); sizeof(reply));
if (error != B_OK || (error = reply.error) != B_OK) { if (error != B_OK || (error = reply.error) != B_OK) {
+7 -3
View File
@@ -1,5 +1,6 @@
/* /*
* Copyright 2008-2010, Ingo Weinhold, ingo_weinhold@gmx.de. * Copyright 2008-2010, Ingo Weinhold, ingo_weinhold@gmx.de.
* Copyright 2013, Rene Gollent, rene@gollent.com.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
@@ -542,7 +543,8 @@ process_event_buffer(ThreadManager& threadManager, uint8* buffer,
system_profiler_team_added* event system_profiler_team_added* event
= (system_profiler_team_added*)buffer; = (system_profiler_team_added*)buffer;
threadManager.AddTeam(event); if (threadManager.AddTeam(event) != B_OK)
exit(1);
break; break;
} }
@@ -575,8 +577,10 @@ process_event_buffer(ThreadManager& threadManager, uint8* buffer,
system_profiler_thread_added* event system_profiler_thread_added* event
= (system_profiler_thread_added*)buffer; = (system_profiler_thread_added*)buffer;
threadManager.AddThread(event->team, event->thread, if (threadManager.AddThread(event->team, event->thread,
event->name); event->name) != B_OK) {
exit(1);
}
break; break;
} }
+13 -4
View File
@@ -1,5 +1,6 @@
/* /*
* Copyright 2005-2011, Ingo Weinhold, ingo_weinhold@gmx.de. * Copyright 2005-2011, Ingo Weinhold, ingo_weinhold@gmx.de.
* Copyright 2013, Rene Gollent, rene@gollent.com.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
@@ -144,7 +145,8 @@ struct Team {
int32 teamDebugFlags = (traceTeam ? B_TEAM_DEBUG_POST_SYSCALL : 0) int32 teamDebugFlags = (traceTeam ? B_TEAM_DEBUG_POST_SYSCALL : 0)
| (traceChildTeams ? B_TEAM_DEBUG_TEAM_CREATION : 0) | (traceChildTeams ? B_TEAM_DEBUG_TEAM_CREATION : 0)
| (traceSignal ? B_TEAM_DEBUG_SIGNALS : 0); | (traceSignal ? B_TEAM_DEBUG_SIGNALS : 0);
set_team_debugging_flags(fNubPort, teamDebugFlags); if (set_team_debugging_flags(fNubPort, teamDebugFlags) != B_OK)
exit(1);
return fMemoryReader.Init(fNubPort); return fMemoryReader.Init(fNubPort);
} }
@@ -568,7 +570,10 @@ main(int argc, const char *const *argv)
| (traceChildThreads | (traceChildThreads
? B_THREAD_DEBUG_SYSCALL_TRACE_CHILD_THREADS : 0); ? B_THREAD_DEBUG_SYSCALL_TRACE_CHILD_THREADS : 0);
} }
set_thread_debugging_flags(nubPort, threadID, threadDebugFlags); if (set_thread_debugging_flags(nubPort, threadID, threadDebugFlags)
!= B_OK) {
exit(1);
}
// resume the target thread to be sure, it's running // resume the target thread to be sure, it's running
resume_thread(threadID); resume_thread(threadID);
@@ -672,8 +677,12 @@ main(int argc, const char *const *argv)
// tell the thread to continue (only when there is a thread and the // tell the thread to continue (only when there is a thread and the
// message was synchronous) // message was synchronous)
if (message.origin.thread >= 0 && message.origin.nub_port >= 0) if (message.origin.thread >= 0 && message.origin.nub_port >= 0) {
continue_thread(message.origin.nub_port, message.origin.thread); if (continue_thread(message.origin.nub_port,
message.origin.thread) != B_OK) {
exit(1);
}
}
} }
if (outputFile != NULL && outputFile != stdout) if (outputFile != NULL && outputFile != stdout)