From c0a43216c6376095a10b45da8b66a30f08193d9a Mon Sep 17 00:00:00 2001 From: Zardshard <0azrune6@zard.anonaddy.com> Date: Mon, 3 Apr 2023 09:57:33 -0400 Subject: [PATCH] Debugger: add support for executable file refs Adds support for handling executable files in the Debugger::RefsReceived function. This change * makes Deskbar menu->Recent Applications->Debugger->A recently opened executable open the executable instead of simply opening the Teams window, and * allows dragging and dropping an executable onto the application's icon. Change-Id: I8e70e7929188301ce976f1f14e885236d3cb2b0a Reviewed-on: https://review.haiku-os.org/c/haiku/+/6299 Reviewed-by: Rene Gollent Tested-by: Automation --- src/apps/debugger/Debugger.cpp | 68 +++++++++++++------ src/apps/debugger/Debugger.rdef | 1 + .../gui/utility_windows/StartTeamWindow.cpp | 12 +++- .../gui/utility_windows/StartTeamWindow.h | 6 ++ 4 files changed, 65 insertions(+), 22 deletions(-) diff --git a/src/apps/debugger/Debugger.cpp b/src/apps/debugger/Debugger.cpp index 8ced015a2d..8d3b02d0d9 100644 --- a/src/apps/debugger/Debugger.cpp +++ b/src/apps/debugger/Debugger.cpp @@ -254,6 +254,7 @@ private: virtual void TeamDebuggerCountChanged(int32 count); private: + status_t _ShowStartTeamWindow(TargetHostInterface* interface); status_t _StartNewTeam(TargetHostInterface* interface, const char* teamPath, const char* args); status_t _HandleOptions(const Options& options); @@ -371,19 +372,13 @@ Debugger::MessageReceived(BMessage* message) ->ActiveInterfaceAt(0); } - BMessenger messenger(fStartTeamWindow); - if (!messenger.IsValid()) { - fStartTeamWindow = StartTeamWindow::Create(hostInterface); - if (fStartTeamWindow == NULL) - break; - fStartTeamWindow->Show(); - } else - fStartTeamWindow->Activate(); + _ShowStartTeamWindow(hostInterface); break; } case MSG_START_TEAM_WINDOW_CLOSED: { fStartTeamWindow = NULL; + Quit(); break; } case MSG_SHOW_CONNECTION_CONFIG_WINDOW: @@ -489,7 +484,7 @@ Debugger::ReadyToRun() { TargetHostInterfaceRoster* roster = TargetHostInterfaceRoster::Default(); AutoLocker lock(roster); - if (roster->CountRunningTeamDebuggers() == 0) + if (roster->CountRunningTeamDebuggers() == 0 && fStartTeamWindow == NULL) PostMessage(MSG_SHOW_TEAMS_WINDOW); } @@ -517,17 +512,35 @@ Debugger::RefsReceived(BMessage* message) if (path.SetTo(&ref) != B_OK) continue; - // check, whether this is a core file - { - ElfFile elfFile; - if (elfFile.Init(path.Path()) != B_OK || elfFile.Type() != ET_CORE) - continue; - } + ElfFile elfFile; + if (elfFile.Init(path.Path()) != B_OK) + continue; - // handle the core file - Options options; - options.coreFilePath = path.Path(); - _HandleOptions(options); + switch (elfFile.Type()) { + case ET_CORE: + { + // open the core file + Options options; + options.coreFilePath = path.Path(); + _HandleOptions(options); + break; + } + case ET_EXEC: + case ET_DYN: + { + // ask the user for arguments to pass to the executable + TargetHostInterface* hostInterface = TargetHostInterfaceRoster::Default() + ->ActiveInterfaceAt(0); + status_t error = _ShowStartTeamWindow(hostInterface); + if (error != B_OK) + continue; + + BMessage message(MSG_SET_TEAM_PATH); + message.AddRef("refs", &ref); + fStartTeamWindow->PostMessage(&message); + break; + } + } } } @@ -570,6 +583,23 @@ Debugger::TeamDebuggerCountChanged(int32 count) } +status_t +Debugger::_ShowStartTeamWindow(TargetHostInterface* interface) +{ + if (fStartTeamWindow == NULL) { + TargetHostInterface* hostInterface = TargetHostInterfaceRoster::Default() + ->ActiveInterfaceAt(0); + fStartTeamWindow = StartTeamWindow::Create(hostInterface); + if (fStartTeamWindow == NULL) + return B_NO_MEMORY; + fStartTeamWindow->Show(); + } else + fStartTeamWindow->Activate(); + + return B_OK; +} + + status_t Debugger::_StartNewTeam(TargetHostInterface* interface, const char* path, const char* args) diff --git a/src/apps/debugger/Debugger.rdef b/src/apps/debugger/Debugger.rdef index a141067703..f5872ad101 100644 --- a/src/apps/debugger/Debugger.rdef +++ b/src/apps/debugger/Debugger.rdef @@ -4,6 +4,7 @@ resource(1, "BEOS:APP_SIG") #'MIMS' "application/x-vnd.Haiku-Debugger"; resource app_name_catalog_entry "x-vnd.Haiku-Debugger:System name:Debugger"; resource file_types message { + "types" = "application/x-vnd.Be-elfexecutable", "types" = "application/x-vnd.haiku-core-file" }; diff --git a/src/apps/debugger/user_interface/gui/utility_windows/StartTeamWindow.cpp b/src/apps/debugger/user_interface/gui/utility_windows/StartTeamWindow.cpp index 2ddbfec397..68b7b6888a 100644 --- a/src/apps/debugger/user_interface/gui/utility_windows/StartTeamWindow.cpp +++ b/src/apps/debugger/user_interface/gui/utility_windows/StartTeamWindow.cpp @@ -19,8 +19,7 @@ enum { - MSG_BROWSE_TEAM = 'brte', - MSG_SET_TEAM_PATH = 'setp' + MSG_BROWSE_TEAM = 'brte' }; @@ -161,7 +160,6 @@ StartTeamWindow::MessageReceived(BMessage* message) if (alert != NULL) alert->Go(); } else { - be_app->PostMessage(MSG_START_TEAM_WINDOW_CLOSED); PostMessage(B_QUIT_REQUESTED); } break; @@ -172,3 +170,11 @@ StartTeamWindow::MessageReceived(BMessage* message) } } + + +bool +StartTeamWindow::QuitRequested() +{ + be_app->PostMessage(MSG_START_TEAM_WINDOW_CLOSED); + return true; +} diff --git a/src/apps/debugger/user_interface/gui/utility_windows/StartTeamWindow.h b/src/apps/debugger/user_interface/gui/utility_windows/StartTeamWindow.h index 1f08f8e868..3c4bb438f7 100644 --- a/src/apps/debugger/user_interface/gui/utility_windows/StartTeamWindow.h +++ b/src/apps/debugger/user_interface/gui/utility_windows/StartTeamWindow.h @@ -16,6 +16,11 @@ class BTextControl; class TargetHostInterface; +enum { + MSG_SET_TEAM_PATH = 'setp' +}; + + class StartTeamWindow : public BWindow { public: @@ -29,6 +34,7 @@ public: virtual void MessageReceived(BMessage* message); + virtual bool QuitRequested(); virtual void Show();