[haiku-commits] haiku: hrev53104 - src/apps/debugger/user_interface/gui/team_window src/system/kernel/locks headers/private/kernel src/servers/debug

  • From: waddlesplash <waddlesplash@xxxxxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Thu, 2 May 2019 17:05:24 -0400 (EDT)

hrev53104 adds 3 changesets to branch 'master'
old head: c19086408321f47e3778755934d9ca862cd27e28
new head: 02079c66f3cff4cced9df077650aec79696aee6f
overview: 
https://git.haiku-os.org/haiku/log/?qt=range&q=02079c66f3cf+%5Ec19086408321

----------------------------------------------------------------------------

c2cbf95810ba: kernel: Add and fix ownership checks in mutex_destroy and 
mutex_transfer.
  
   * mutex_destroy() only checked wether or not there were waiters,
     not if the lock itself was presently held by another thread.
     Now we do, which should make #15015 panic much earlier instead
     of trying to use freed memory.
   * mutex_transfer_lock() and recursive_lock_transfer_lock() did
     not check that the calling thread actually owned the lock.
     Now it does, which should trigger asserts if anyone tries
     to do this.

5ef0649658e5: Debugger: Add a "Write core file" menu item alongside "Save debug 
report".

02079c66f3cf: debug_server: Remove the "Write core file" button.
  
  It is very, very rarely used, and is extremely wide on some locales
  (i.e. almost 2x the width of the other buttons combined), making it
  appear out of place. Now that it can be done from Debugger, having
  it here does not seem to make a lot of sense.
  
  As requested and discussed in #14777.

                              [ Augustin Cavalier <waddlesplash@xxxxxxxxx> ]

----------------------------------------------------------------------------

5 files changed, 71 insertions(+), 22 deletions(-)
headers/private/kernel/lock.h                    | 12 +----
.../gui/team_window/TeamWindow.cpp               | 53 ++++++++++++++++++--
.../user_interface/gui/team_window/TeamWindow.h  |  2 +
src/servers/debug/DebugServer.cpp                |  8 +--
src/system/kernel/locks/lock.cpp                 | 18 +++++--

############################################################################

Commit:      c2cbf95810ba5aeaae3ec3f9bc276f27593c69e8
URL:         https://git.haiku-os.org/haiku/commit/?id=c2cbf95810ba
Author:      Augustin Cavalier <waddlesplash@xxxxxxxxx>
Date:        Thu May  2 20:07:39 2019 UTC

Ticket:      https://dev.haiku-os.org/ticket/15015

kernel: Add and fix ownership checks in mutex_destroy and mutex_transfer.

 * mutex_destroy() only checked wether or not there were waiters,
   not if the lock itself was presently held by another thread.
   Now we do, which should make #15015 panic much earlier instead
   of trying to use freed memory.
 * mutex_transfer_lock() and recursive_lock_transfer_lock() did
   not check that the calling thread actually owned the lock.
   Now it does, which should trigger asserts if anyone tries
   to do this.

----------------------------------------------------------------------------

diff --git a/headers/private/kernel/lock.h b/headers/private/kernel/lock.h
index 46d1585239..004a0b5fb0 100644
--- a/headers/private/kernel/lock.h
+++ b/headers/private/kernel/lock.h
@@ -138,6 +138,7 @@ extern void mutex_init(mutex* lock, const char* name);
 extern void mutex_init_etc(mutex* lock, const char* name, uint32 flags);
 extern void mutex_destroy(mutex* lock);
 extern status_t mutex_switch_lock(mutex* from, mutex* to);
+extern void mutex_transfer_lock(mutex* lock, thread_id thread);
        // Unlocks "from" and locks "to" such that unlocking and starting to 
wait
        // for the lock is atomically. I.e. if "from" guards the object "to" 
belongs
        // to, the operation is safe as long as "from" is held while destroying
@@ -260,15 +261,6 @@ mutex_unlock(mutex* lock)
 }
 
 
-static inline void
-mutex_transfer_lock(mutex* lock, thread_id thread)
-{
-#if KDEBUG
-       lock->holder = thread;
-#endif
-}
-
-
 static inline void
 recursive_lock_transfer_lock(recursive_lock* lock, thread_id thread)
 {
@@ -276,7 +268,7 @@ recursive_lock_transfer_lock(recursive_lock* lock, 
thread_id thread)
                panic("invalid recursion level for lock transfer!");
 
 #if KDEBUG
-       lock->lock.holder = thread;
+       mutex_transfer_lock(&lock->lock, thread);
 #else
        lock->holder = thread;
 #endif
diff --git a/src/system/kernel/locks/lock.cpp b/src/system/kernel/locks/lock.cpp
index ab62a1ac49..db0f0dc1e0 100644
--- a/src/system/kernel/locks/lock.cpp
+++ b/src/system/kernel/locks/lock.cpp
@@ -628,10 +628,9 @@ mutex_destroy(mutex* lock)
        InterruptsSpinLocker locker(lock->lock);
 
 #if KDEBUG
-       if (lock->waiters != NULL && thread_get_current_thread_id()
-                       != lock->holder) {
-               panic("mutex_destroy(): there are blocking threads, but caller 
doesn't "
-                       "hold the lock (%p)", lock);
+       if (lock->holder != -1 && thread_get_current_thread_id() != 
lock->holder) {
+               panic("mutex_destroy(): the lock (%p) is held by %" B_PRId32 ", 
not "
+                       "by the caller", lock, lock->holder);
                if (_mutex_lock(lock, &locker) != B_OK)
                        return;
                locker.Lock();
@@ -691,6 +690,17 @@ mutex_switch_lock(mutex* from, mutex* to)
 }
 
 
+void
+mutex_transfer_lock(mutex* lock, thread_id thread)
+{
+#if KDEBUG
+       if (thread_get_current_thread_id() != lock->holder)
+               panic("mutex_transfer_lock(): current thread is not the lock 
holder!");
+       lock->holder = thread;
+#endif
+}
+
+
 status_t
 mutex_switch_from_read_lock(rw_lock* from, mutex* to)
 {

############################################################################

Commit:      5ef0649658e5e41d2fa524980b3ece064e1ba93a
URL:         https://git.haiku-os.org/haiku/commit/?id=5ef0649658e5
Author:      Augustin Cavalier <waddlesplash@xxxxxxxxx>
Date:        Thu May  2 20:35:25 2019 UTC

Debugger: Add a "Write core file" menu item alongside "Save debug report".

----------------------------------------------------------------------------

diff --git a/src/apps/debugger/user_interface/gui/team_window/TeamWindow.cpp 
b/src/apps/debugger/user_interface/gui/team_window/TeamWindow.cpp
index 54ecd762da..50c8b4e6cb 100644
--- a/src/apps/debugger/user_interface/gui/team_window/TeamWindow.cpp
+++ b/src/apps/debugger/user_interface/gui/team_window/TeamWindow.cpp
@@ -74,6 +74,8 @@ enum {
 enum {
        MSG_CHOOSE_DEBUG_REPORT_LOCATION        = 'ccrl',
        MSG_DEBUG_REPORT_SAVED                          = 'drsa',
+       MSG_CHOOSE_CORE_FILE_LOCATION           = 'ccfl',
+       MSG_CORE_FILE_WRITTEN                           = 'cfsa',
        MSG_LOCATE_SOURCE_IF_NEEDED                     = 'lsin',
        MSG_SOURCE_ENTRY_QUERY_COMPLETE         = 'seqc',
        MSG_CLEAR_STACK_TRACE                           = 'clst',
@@ -375,13 +377,19 @@ TeamWindow::MessageReceived(BMessage* message)
                        break;
                }
                case MSG_CHOOSE_DEBUG_REPORT_LOCATION:
+               case MSG_CHOOSE_CORE_FILE_LOCATION:
                {
                        try {
                                char filename[B_FILE_NAME_LENGTH];
-                               UiUtils::ReportNameForTeam(fTeam, filename, 
sizeof(filename));
+                               if (message->what == 
MSG_CHOOSE_DEBUG_REPORT_LOCATION)
+                                       UiUtils::ReportNameForTeam(fTeam, 
filename, sizeof(filename));
+                               else
+                                       UiUtils::CoreFileNameForTeam(fTeam, 
filename, sizeof(filename));
                                BMessenger msgr(this);
                                fFilePanel = new BFilePanel(B_SAVE_PANEL, &msgr,
-                                       NULL, 0, false, new 
BMessage(MSG_GENERATE_DEBUG_REPORT));
+                                       NULL, 0, false, new BMessage(
+                                               message->what == 
MSG_CHOOSE_DEBUG_REPORT_LOCATION ?
+                                                       
MSG_GENERATE_DEBUG_REPORT : MSG_WRITE_CORE_FILE));
                                fFilePanel->SetSaveText(filename);
                                fFilePanel->Show();
                        } catch (...) {
@@ -391,6 +399,7 @@ TeamWindow::MessageReceived(BMessage* message)
                        break;
                }
                case MSG_GENERATE_DEBUG_REPORT:
+               case MSG_WRITE_CORE_FILE:
                {
                        delete fFilePanel;
                        fFilePanel = NULL;
@@ -401,8 +410,12 @@ TeamWindow::MessageReceived(BMessage* message)
                                && message->HasString("name")) {
                                path.SetTo(&ref);
                                path.Append(message->FindString("name"));
-                               if (get_ref_for_path(path.Path(), &ref) == B_OK)
-                                       fListener->DebugReportRequested(&ref);
+                               if (get_ref_for_path(path.Path(), &ref) == 
B_OK) {
+                                       if (message->what == 
MSG_GENERATE_DEBUG_REPORT)
+                                               
fListener->DebugReportRequested(&ref);
+                                       else
+                                               
fListener->WriteCoreFileRequested(&ref);
+                               }
                        }
                        break;
                }
@@ -427,6 +440,27 @@ TeamWindow::MessageReceived(BMessage* message)
                        alert->Go();
                        break;
                }
+               case MSG_CORE_FILE_WRITTEN:
+               {
+                       status_t finalStatus = message->GetInt32("status", 
B_OK);
+                       BString data;
+                       if (finalStatus == B_OK) {
+                               data.SetToFormat("Core file successfully 
written to '%s'",
+                                       message->FindString("path"));
+                       } else {
+                               data.SetToFormat("Failed to write core file: 
'%s'",
+                                       strerror(finalStatus));
+                       }
+
+                       BAlert *alert = new(std::nothrow) BAlert("Core file 
written",
+                               data.String(), "Close");
+                       if (alert == NULL)
+                               break;
+
+                       alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
+                       alert->Go();
+                       break;
+               }
                case MSG_SHOW_INSPECTOR_WINDOW:
                {
                        if (fInspectorWindow) {
@@ -1079,6 +1113,15 @@ TeamWindow::DebugReportChanged(const 
Team::DebugReportEvent& event)
 }
 
 
+void
+TeamWindow::CoreFileChanged(const Team::CoreFileChangedEvent& event)
+{
+       BMessage message(MSG_CORE_FILE_WRITTEN);
+       message.AddString("path", event.GetTargetPath());
+       PostMessage(&message);
+}
+
+
 void
 TeamWindow::FunctionSourceCodeChanged(Function* function)
 {
@@ -1233,6 +1276,8 @@ TeamWindow::_Init()
        fMenuBar->AddItem(menu);
        item = new BMenuItem("Save debug report",
                new BMessage(MSG_CHOOSE_DEBUG_REPORT_LOCATION));
+       item = new BMenuItem("Write core file",
+               new BMessage(MSG_CHOOSE_CORE_FILE_LOCATION));
        menu->AddItem(item);
        item->SetTarget(this);
        item = new BMenuItem("Inspect memory",
diff --git a/src/apps/debugger/user_interface/gui/team_window/TeamWindow.h 
b/src/apps/debugger/user_interface/gui/team_window/TeamWindow.h
index c54aee03fb..9efae754d2 100644
--- a/src/apps/debugger/user_interface/gui/team_window/TeamWindow.h
+++ b/src/apps/debugger/user_interface/gui/team_window/TeamWindow.h
@@ -164,6 +164,8 @@ private:
                                                                        const 
Team::WatchpointEvent& event);
        virtual void                            DebugReportChanged(
                                                                        const 
Team::DebugReportEvent& event);
+       virtual void                            CoreFileChanged(
+                                                                       const 
Team::CoreFileChangedEvent& event);
 
 
        // Function::Listener

############################################################################

Revision:    hrev53104
Commit:      02079c66f3cff4cced9df077650aec79696aee6f
URL:         https://git.haiku-os.org/haiku/commit/?id=02079c66f3cf
Author:      Augustin Cavalier <waddlesplash@xxxxxxxxx>
Date:        Thu May  2 20:59:39 2019 UTC

Ticket:      https://dev.haiku-os.org/ticket/14777

debug_server: Remove the "Write core file" button.

It is very, very rarely used, and is extremely wide on some locales
(i.e. almost 2x the width of the other buttons combined), making it
appear out of place. Now that it can be done from Debugger, having
it here does not seem to make a lot of sense.

As requested and discussed in #14777.

----------------------------------------------------------------------------

diff --git a/src/servers/debug/DebugServer.cpp 
b/src/servers/debug/DebugServer.cpp
index 22dece4a0a..19dad0e6ff 100644
--- a/src/servers/debug/DebugServer.cpp
+++ b/src/servers/debug/DebugServer.cpp
@@ -39,8 +39,8 @@
 enum {
        kActionKillTeam,
        kActionDebugTeam,
-       kActionWriteCoreFile,
        kActionSaveReportTeam,
+       kActionWriteCoreFile,
        kActionPromptUser
 };
 
@@ -903,10 +903,10 @@ TeamDebugHandler::_HandleMessage(DebugMessage *message)
                // if someone else kills our teams.
                BAlert *alert = new BAlert(NULL, buffer.String(),
                        B_TRANSLATE("Terminate"), B_TRANSLATE("Debug"),
-                       B_TRANSLATE("Write core file"),
+                       HANDOVER_USE_DEBUGGER ? B_TRANSLATE("Save report") : 
NULL,
                        B_WIDTH_AS_USUAL, B_WARNING_ALERT);
-#ifdef HANDOVER_USE_DEBUGGER
-               alert->AddButton(B_TRANSLATE("Save report"));
+#if 0
+               alert->AddButton(B_TRANSLATE("Write core file"));
 #endif
                alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
                debugAction = alert->Go();


Other related posts: