From 4dc355e9a98bf91d5e0851e432692fb267839de0 Mon Sep 17 00:00:00 2001 From: Rene Gollent Date: Thu, 27 Jun 2013 19:20:42 -0400 Subject: [PATCH] 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. --- .../debugger_interface/DebuggerInterface.cpp | 10 +-- src/bin/debug/debug_utils.cpp | 64 ++++++++++--------- src/bin/debug/debug_utils.h | 6 +- src/bin/debug/profile/Team.cpp | 12 +++- src/bin/debug/profile/profile.cpp | 10 ++- src/bin/debug/strace/strace.cpp | 17 +++-- 6 files changed, 70 insertions(+), 49 deletions(-) diff --git a/src/apps/debugger/debugger_interface/DebuggerInterface.cpp b/src/apps/debugger/debugger_interface/DebuggerInterface.cpp index 0af3105aff..9d413a4fbc 100644 --- a/src/apps/debugger/debugger_interface/DebuggerInterface.cpp +++ b/src/apps/debugger/debugger_interface/DebuggerInterface.cpp @@ -351,8 +351,10 @@ DebuggerInterface::GetNextDebugEvent(DebugEvent*& _event) if (ignore) { 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); + if (error != B_OK) + return error; continue; } @@ -373,16 +375,14 @@ DebuggerInterface::GetNextDebugEvent(DebugEvent*& _event) status_t DebuggerInterface::SetTeamDebuggingFlags(uint32 flags) { - set_team_debugging_flags(fNubPort, flags); - return B_OK; + return set_team_debugging_flags(fNubPort, flags); } status_t DebuggerInterface::ContinueThread(thread_id thread) { - continue_thread(fNubPort, thread); - return B_OK; + return continue_thread(fNubPort, thread); } diff --git a/src/bin/debug/debug_utils.cpp b/src/bin/debug/debug_utils.cpp index fa9d431b43..e91bf36ace 100644 --- a/src/bin/debug/debug_utils.cpp +++ b/src/bin/debug/debug_utils.cpp @@ -1,5 +1,6 @@ /* * Copyright 2005-2008, Ingo Weinhold, ingo_weinhold@gmx.de. + * Copyright 2013, Rene Gollent, rene@gollent.com. * 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 -void +status_t set_team_debugging_flags(port_id nubPort, int32 flags) { debug_nub_set_team_flags message; message.flags = flags; - while (true) { - status_t error = write_port(nubPort, B_DEBUG_MESSAGE_SET_TEAM_FLAGS, + status_t error = B_OK; + do { + error = write_port(nubPort, B_DEBUG_MESSAGE_SET_TEAM_FLAGS, &message, sizeof(message)); - if (error == B_OK) - return; + } while (error == B_INTERRUPTED); - if (error != B_INTERRUPTED) { - fprintf(stderr, "%s: Failed to set team debug flags: %s\n", - kCommandName, strerror(error)); - exit(1); - } + if (error != B_OK) { + fprintf(stderr, "%s: Failed to set team debug flags: %s\n", + kCommandName, strerror(error)); } + + return error; } // set_thread_debugging_flags -void +status_t set_thread_debugging_flags(port_id nubPort, thread_id thread, int32 flags) { debug_nub_set_thread_flags message; message.thread = thread; message.flags = flags; - while (true) { - status_t error = write_port(nubPort, B_DEBUG_MESSAGE_SET_THREAD_FLAGS, + status_t error = B_OK; + do { + error = write_port(nubPort, B_DEBUG_MESSAGE_SET_THREAD_FLAGS, &message, sizeof(message)); - if (error == B_OK) - return; + } while (error == B_INTERRUPTED); - if (error != B_INTERRUPTED) { - fprintf(stderr, "%s: Failed to set thread debug flags: %s\n", - kCommandName, strerror(error)); - exit(1); - } + if (error != B_OK) { + fprintf(stderr, "%s: Failed to set thread debug flags: %s\n", + kCommandName, strerror(error)); } + + return error; } // continue_thread -void +status_t continue_thread(port_id nubPort, thread_id thread) { 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.single_step = false; - while (true) { - status_t error = write_port(nubPort, B_DEBUG_MESSAGE_CONTINUE_THREAD, - &message, sizeof(message)); - if (error == B_OK) - return; + status_t error = B_OK; - if (error != B_INTERRUPTED) { - fprintf(stderr, "%s: Failed to run thread %" B_PRId32 ": %s\n", - kCommandName, thread, strerror(error)); - exit(1); - } + 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", + kCommandName, thread, strerror(error)); } + + return error; } diff --git a/src/bin/debug/debug_utils.h b/src/bin/debug/debug_utils.h index 0228360de8..b4c4f67f9e 100644 --- a/src/bin/debug/debug_utils.h +++ b/src/bin/debug/debug_utils.h @@ -11,10 +11,10 @@ thread_id load_program(const char* const* args, int32 argCount, bool traceLoading); -void set_team_debugging_flags(port_id nubPort, int32 flags); -void set_thread_debugging_flags(port_id nubPort, thread_id thread, +status_t set_team_debugging_flags(port_id nubPort, int32 flags); +status_t set_thread_debugging_flags(port_id nubPort, thread_id thread, 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 diff --git a/src/bin/debug/profile/Team.cpp b/src/bin/debug/profile/Team.cpp index 331b28e9dd..433fde1269 100644 --- a/src/bin/debug/profile/Team.cpp +++ b/src/bin/debug/profile/Team.cpp @@ -1,5 +1,6 @@ /* * Copyright 2008-2010, Ingo Weinhold, ingo_weinhold@gmx.de. + * Copyright 2013, Rene Gollent, rene@gollent.com. * Distributed under the terms of the MIT License. */ @@ -86,7 +87,9 @@ Team::Init(team_id teamID, port_id debuggerPort) // set team debugging flags int32 teamDebugFlags = B_TEAM_DEBUG_THREADS | 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; } @@ -138,7 +141,10 @@ Team::InitThread(Thread* thread) // | (traceChildThreads // ? 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 debug_nub_start_profiler message; @@ -150,7 +156,7 @@ Team::InitThread(Thread* thread) message.variable_stack_depth = gOptions.analyze_full_stack; 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, sizeof(reply)); if (error != B_OK || (error = reply.error) != B_OK) { diff --git a/src/bin/debug/profile/profile.cpp b/src/bin/debug/profile/profile.cpp index dd50dcd81e..22f6338be3 100644 --- a/src/bin/debug/profile/profile.cpp +++ b/src/bin/debug/profile/profile.cpp @@ -1,5 +1,6 @@ /* * Copyright 2008-2010, Ingo Weinhold, ingo_weinhold@gmx.de. + * Copyright 2013, Rene Gollent, rene@gollent.com. * 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*)buffer; - threadManager.AddTeam(event); + if (threadManager.AddTeam(event) != B_OK) + exit(1); break; } @@ -575,8 +577,10 @@ process_event_buffer(ThreadManager& threadManager, uint8* buffer, system_profiler_thread_added* event = (system_profiler_thread_added*)buffer; - threadManager.AddThread(event->team, event->thread, - event->name); + if (threadManager.AddThread(event->team, event->thread, + event->name) != B_OK) { + exit(1); + } break; } diff --git a/src/bin/debug/strace/strace.cpp b/src/bin/debug/strace/strace.cpp index 046efbdf13..a232a9c101 100644 --- a/src/bin/debug/strace/strace.cpp +++ b/src/bin/debug/strace/strace.cpp @@ -1,5 +1,6 @@ /* * Copyright 2005-2011, Ingo Weinhold, ingo_weinhold@gmx.de. + * Copyright 2013, Rene Gollent, rene@gollent.com. * Distributed under the terms of the MIT License. */ @@ -144,7 +145,8 @@ struct Team { int32 teamDebugFlags = (traceTeam ? B_TEAM_DEBUG_POST_SYSCALL : 0) | (traceChildTeams ? B_TEAM_DEBUG_TEAM_CREATION : 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); } @@ -568,7 +570,10 @@ main(int argc, const char *const *argv) | (traceChildThreads ? 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_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 // message was synchronous) - if (message.origin.thread >= 0 && message.origin.nub_port >= 0) - continue_thread(message.origin.nub_port, message.origin.thread); + if (message.origin.thread >= 0 && message.origin.nub_port >= 0) { + if (continue_thread(message.origin.nub_port, + message.origin.thread) != B_OK) { + exit(1); + } + } } if (outputFile != NULL && outputFile != stdout)