[haiku-commits] haiku: hrev48106 - in src/apps/debugger: user_interface/gui/team_window source_language

  • From: anevilyak@xxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Sun, 26 Oct 2014 21:27:20 +0100 (CET)

hrev48106 adds 3 changesets to branch 'master'
old head: c9dd05ff400733baf569ee023c05d48fdbcf4ef1
new head: e3581569c7fc447ee4dafece19dadb2d6e484406
overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=e358156+%5Ec9dd05f

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

02bb190: Debugger: Style fix.

a1cad33: Debugger: Implement evaluation hook for CLanguageFamily.
  
  - Add override for EvaluateExpression(), and hook it up to
    CLanguageExpressionEvaluator. Note that for the moment it assumes
    the expression will result in an integer value.

e358156: Debugger: Hook in expression evaluation window.
  
  - Adjust expression window interface so it can report being closed
    to TeamWindow or whoever else invokes it.
  - Add a menu item to Tools to request expression evaluation. This
    now attempts to get the expression evaluator for the current language,
    and subsequently opens the expression evaluation window with it.
  
  With these changes, basic numerical expression evaluation works.
  Resolution of variable values and condition operators aren't yet
  handled.

                                         [ Rene Gollent <rene@xxxxxxxxxxx> ]

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

8 files changed, 132 insertions(+), 9 deletions(-)
src/apps/debugger/MessageCodes.h                 |  2 +
.../debugger/source_language/CLanguageFamily.cpp | 34 ++++++++++-
.../debugger/source_language/CLanguageFamily.h   |  4 ++
.../debugger/source_language/SourceLanguage.h    |  2 +-
.../team_window/ExpressionEvaluationWindow.cpp   | 20 +++++--
.../gui/team_window/ExpressionEvaluationWindow.h |  8 ++-
.../gui/team_window/TeamWindow.cpp               | 63 ++++++++++++++++++++
.../user_interface/gui/team_window/TeamWindow.h  |  8 ++-

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

Commit:      02bb190861329a0cc7291141a02ab144cc4a4c58
URL:         http://cgit.haiku-os.org/haiku/commit/?id=02bb190
Author:      Rene Gollent <rene@xxxxxxxxxxx>
Date:        Sun Oct 26 20:16:20 2014 UTC

Debugger: Style fix.

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

diff --git a/src/apps/debugger/source_language/SourceLanguage.h 
b/src/apps/debugger/source_language/SourceLanguage.h
index c883e9d..2f607ad 100644
--- a/src/apps/debugger/source_language/SourceLanguage.h
+++ b/src/apps/debugger/source_language/SourceLanguage.h
@@ -27,7 +27,7 @@ public:
                                                                        // 
returns a reference,
                                                                        // may 
return NULL, if not available
 
-       virtual status_t                        ParseTypeExpression(const 
BString &expression,
+       virtual status_t                        ParseTypeExpression(const 
BString& expression,
                                                                        
TeamTypeInformation* info,
                                                                        Type*& 
_resultType) const;
 

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

Commit:      a1cad33d1e859d906ab72932573eb242e9a9a07e
URL:         http://cgit.haiku-os.org/haiku/commit/?id=a1cad33
Author:      Rene Gollent <rene@xxxxxxxxxxx>
Date:        Sun Oct 26 20:16:50 2014 UTC

Debugger: Implement evaluation hook for CLanguageFamily.

- Add override for EvaluateExpression(), and hook it up to
  CLanguageExpressionEvaluator. Note that for the moment it assumes
  the expression will result in an integer value.

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

diff --git a/src/apps/debugger/source_language/CLanguageFamily.cpp 
b/src/apps/debugger/source_language/CLanguageFamily.cpp
index 142ecc6..b56e2bc 100644
--- a/src/apps/debugger/source_language/CLanguageFamily.cpp
+++ b/src/apps/debugger/source_language/CLanguageFamily.cpp
@@ -1,13 +1,18 @@
 /*
- * Copyright 2013, Rene Gollent, rene@xxxxxxxxxxx.
+ * Copyright 2013-2014, Rene Gollent, rene@xxxxxxxxxxx.
  * Copyright 2009, Ingo Weinhold, ingo_weinhold@xxxxxx.
  * Distributed under the terms of the MIT License.
  */
 
 #include "CLanguageFamily.h"
 
+#include <new>
+
 #include <stdlib.h>
 
+#include "CLanguageExpressionEvaluator.h"
+#include "IntegerValue.h"
+#include "StringValue.h"
 #include "TeamTypeInformation.h"
 #include "Type.h"
 #include "TypeLookupConstraints.h"
@@ -157,3 +162,30 @@ CLanguageFamily::ParseTypeExpression(const BString& 
expression,
 
        return result;
 }
+
+
+status_t
+CLanguageFamily::EvaluateExpression(const BString& expression, Value*& _output)
+{
+       _output = NULL;
+       CLanguageExpressionEvaluator evaluator;
+       evaluator.SetSupportHexInput(true);
+       int64 resultValue;
+       try {
+               resultValue = evaluator.EvaluateToInt64(expression);
+               BVariant variantValue(resultValue);
+               _output = new(std::nothrow) IntegerValue(variantValue);
+               if (_output == NULL)
+                       return B_NO_MEMORY;
+
+               return B_OK;
+       } catch (ParseException ex) {
+               BString stringValue;
+               stringValue.SetToFormat("Parse error at position %" B_PRId32 ": 
%s",
+                       ex.position, ex.message.String());
+               _output = new(std::nothrow) StringValue(stringValue);
+               return B_BAD_DATA;
+       }
+
+       return B_OK;
+}
diff --git a/src/apps/debugger/source_language/CLanguageFamily.h 
b/src/apps/debugger/source_language/CLanguageFamily.h
index 250639b..e7e9f28 100644
--- a/src/apps/debugger/source_language/CLanguageFamily.h
+++ b/src/apps/debugger/source_language/CLanguageFamily.h
@@ -1,5 +1,6 @@
 /*
  * Copyright 2009, Ingo Weinhold, ingo_weinhold@xxxxxx.
+ * Copyright 2014, Rene Gollent, rene@xxxxxxxxxxx.
  * Distributed under the terms of the MIT License.
  */
 #ifndef C_LANGUAGE_FAMILY_H
@@ -20,6 +21,9 @@ public:
                                                                        
TeamTypeInformation* lookup,
                                                                        Type*& 
_resultType) const;
 
+       virtual status_t                        EvaluateExpression(const 
BString& expression,
+                                                                       Value*& 
_output);
+
 protected:
        virtual bool                            IsModifierValid(char modifier) 
const = 0;
 };

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

Revision:    hrev48106
Commit:      e3581569c7fc447ee4dafece19dadb2d6e484406
URL:         http://cgit.haiku-os.org/haiku/commit/?id=e358156
Author:      Rene Gollent <rene@xxxxxxxxxxx>
Date:        Sun Oct 26 20:21:28 2014 UTC

Debugger: Hook in expression evaluation window.

- Adjust expression window interface so it can report being closed
  to TeamWindow or whoever else invokes it.
- Add a menu item to Tools to request expression evaluation. This
  now attempts to get the expression evaluator for the current language,
  and subsequently opens the expression evaluation window with it.

With these changes, basic numerical expression evaluation works.
Resolution of variable values and condition operators aren't yet
handled.

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

diff --git a/src/apps/debugger/MessageCodes.h b/src/apps/debugger/MessageCodes.h
index ab6d8c5..ca68f7a 100644
--- a/src/apps/debugger/MessageCodes.h
+++ b/src/apps/debugger/MessageCodes.h
@@ -65,6 +65,8 @@ enum {
        MSG_DEBUG_THIS_TEAM                                                     
= 'dbtt',
        MSG_SHOW_INSPECTOR_WINDOW                                       = 
'sirw',
        MSG_INSPECTOR_WINDOW_CLOSED                                     = 
'irwc',
+       MSG_SHOW_EXPRESSION_WINDOW                                      = 
'seww',
+       MSG_EXPRESSION_WINDOW_CLOSED                            = 'ewwc',
        MSG_INSPECT_ADDRESS                                                     
= 'isad',
        MSG_SHOW_TYPECAST_NODE_PROMPT                           = 'stnp',
        MSG_TYPECAST_TO_ARRAY                                           = 
'stta',
diff --git 
a/src/apps/debugger/user_interface/gui/team_window/ExpressionEvaluationWindow.cpp
 
b/src/apps/debugger/user_interface/gui/team_window/ExpressionEvaluationWindow.cpp
index fa66aa1..1458d7a 100644
--- 
a/src/apps/debugger/user_interface/gui/team_window/ExpressionEvaluationWindow.cpp
+++ 
b/src/apps/debugger/user_interface/gui/team_window/ExpressionEvaluationWindow.cpp
@@ -23,12 +23,14 @@ enum {
 
 
 ExpressionEvaluationWindow::ExpressionEvaluationWindow(
-       SourceLanguage* language, UserInterfaceListener* listener)
+       SourceLanguage* language, UserInterfaceListener* listener,
+       BHandler* target)
        :
        BWindow(BRect(), "Evaluate Expression", B_FLOATING_WINDOW,
                B_AUTO_UPDATE_SIZE_LIMITS | B_CLOSE_ON_ESCAPE),
        fLanguage(language),
-       fListener(listener)
+       fListener(listener),
+       fCloseTarget(target)
 {
        fLanguage->AcquireReference();
 }
@@ -42,10 +44,10 @@ ExpressionEvaluationWindow::~ExpressionEvaluationWindow()
 
 ExpressionEvaluationWindow*
 ExpressionEvaluationWindow::Create(SourceLanguage* language,
-       UserInterfaceListener* listener)
+       UserInterfaceListener* listener, BHandler* target)
 {
        ExpressionEvaluationWindow* self = new ExpressionEvaluationWindow(
-               language, listener);
+               language, listener, target);
 
        try {
                self->_Init();
@@ -95,6 +97,16 @@ ExpressionEvaluationWindow::Show()
 }
 
 
+bool
+ExpressionEvaluationWindow::QuitRequested()
+{
+       BMessenger messenger(fCloseTarget);
+       messenger.SendMessage(MSG_EXPRESSION_WINDOW_CLOSED);
+
+       return BWindow::QuitRequested();
+}
+
+
 void
 ExpressionEvaluationWindow::MessageReceived(BMessage* message)
 {
diff --git 
a/src/apps/debugger/user_interface/gui/team_window/ExpressionEvaluationWindow.h 
b/src/apps/debugger/user_interface/gui/team_window/ExpressionEvaluationWindow.h
index ba28df4..b2b8ef1 100644
--- 
a/src/apps/debugger/user_interface/gui/team_window/ExpressionEvaluationWindow.h
+++ 
b/src/apps/debugger/user_interface/gui/team_window/ExpressionEvaluationWindow.h
@@ -23,19 +23,22 @@ class ExpressionEvaluationWindow : public BWindow
 public:
                                                                
ExpressionEvaluationWindow(
                                                                        
SourceLanguage* language,
-                                                                       
UserInterfaceListener* listener);
+                                                                       
UserInterfaceListener* listener,
+                                                                       
BHandler* target);
 
                                                                
~ExpressionEvaluationWindow();
 
        static  ExpressionEvaluationWindow* Create(
                                                                        
SourceLanguage* language,
-                                                                       
UserInterfaceListener* listener);
+                                                                       
UserInterfaceListener* listener,
+                                                                       
BHandler* target);
                                                                        // 
throws
 
 
        virtual void                            MessageReceived(BMessage* 
message);
 
        virtual void                            Show();
+       virtual bool                            QuitRequested();
 
 private:
                        void                            _Init();
@@ -47,6 +50,7 @@ private:
                        BStringView*            fExpressionOutput;
                        BButton*                        fEvaluateButton;
                        UserInterfaceListener* fListener;
+                       BHandler*                       fCloseTarget;
 };
 
 #endif // EXPRESSION_EVALUATION_WINDOW_H
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 c554974..0aa5fc3 100644
--- a/src/apps/debugger/user_interface/gui/team_window/TeamWindow.cpp
+++ b/src/apps/debugger/user_interface/gui/team_window/TeamWindow.cpp
@@ -35,9 +35,11 @@
 
 #include "Breakpoint.h"
 #include "ConsoleOutputView.h"
+#include "CppLanguage.h"
 #include "CpuState.h"
 #include "DisassembledCode.h"
 #include "BreakConditionConfigWindow.h"
+#include "ExpressionEvaluationWindow.h"
 #include "FileSourceCode.h"
 #include "GuiSettingsUtils.h"
 #include "GuiTeamUiSettings.h"
@@ -135,6 +137,7 @@ TeamWindow::TeamWindow(::Team* team, UserInterfaceListener* 
listener)
        fConsoleSplitView(NULL),
        fBreakConditionConfigWindow(NULL),
        fInspectorWindow(NULL),
+       fExpressionWindow(NULL),
        fFilePanel(NULL),
        fActiveSourceWorker(-1)
 {
@@ -162,6 +165,11 @@ TeamWindow::~TeamWindow()
                if (messenger.LockTarget())
                        fInspectorWindow->Quit();
        }
+       if (fExpressionWindow != NULL) {
+               BMessenger messenger(fExpressionWindow);
+               if (messenger.LockTarget())
+                       fExpressionWindow->Quit();
+       }
 
        fTeam->RemoveListener(this);
 
@@ -334,6 +342,33 @@ TeamWindow::MessageReceived(BMessage* message)
                        break;
 
                }
+               case MSG_SHOW_EXPRESSION_WINDOW:
+               {
+                       if (fExpressionWindow != NULL)
+                               fExpressionWindow->Activate(true);
+                       else {
+                               try {
+                                       SourceLanguage* language = NULL;
+                                       if (_GetActiveSourceLanguage(language) 
!= B_OK)
+                                               break;
+
+                                       BReference<SourceLanguage> 
languageReference(language,
+                                               true);
+                                       fExpressionWindow = 
ExpressionEvaluationWindow::Create(
+                                               language, fListener, this);
+                                       if (fExpressionWindow != NULL)
+                                               fExpressionWindow->Show();
+                       } catch (...) {
+                               // TODO: notify user
+                       }
+                       }
+                       break;
+               }
+               case MSG_EXPRESSION_WINDOW_CLOSED:
+               {
+                       fExpressionWindow = NULL;
+                       break;
+               }
                case MSG_SHOW_BREAK_CONDITION_CONFIG_WINDOW:
                {
                        if (fBreakConditionConfigWindow) {
@@ -1000,6 +1035,10 @@ TeamWindow::_Init()
                new BMessage(MSG_SHOW_INSPECTOR_WINDOW), 'I');
        menu->AddItem(item);
        item->SetTarget(this);
+       item = new BMenuItem("Evaluate expression",
+               new BMessage(MSG_SHOW_EXPRESSION_WINDOW), 'E');
+       menu->AddItem(item);
+       item->SetTarget(this);
 
        AutoLocker< ::Team> locker(fTeam);
        _UpdateRunButtons();
@@ -1771,3 +1810,27 @@ TeamWindow::_SaveInspectorSettings(const BMessage* 
settings)
 
        return B_OK;
 }
+
+
+status_t
+TeamWindow::_GetActiveSourceLanguage(SourceLanguage*& _language)
+{
+       AutoLocker< ::Team> locker(fTeam);
+
+       if (!locker.IsLocked())
+               return B_ERROR;
+
+       if (fActiveSourceCode != NULL) {
+               _language = fActiveSourceCode->GetSourceLanguage();
+               return B_OK;
+       }
+
+       // if we made it this far, we were unable to acquire a source
+       // language corresponding to the active function. As such,
+       // try to fall back to the C++-style parser.
+       _language = new(std::nothrow) CppLanguage();
+       if (_language == NULL)
+               return B_NO_MEMORY;
+
+       return B_OK;
+}
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 4934149..91a414e 100644
--- a/src/apps/debugger/user_interface/gui/team_window/TeamWindow.h
+++ b/src/apps/debugger/user_interface/gui/team_window/TeamWindow.h
@@ -1,6 +1,6 @@
 /*
  * Copyright 2009, Ingo Weinhold, ingo_weinhold@xxxxxx.
- * Copyright 2010-2013, Rene Gollent, rene@xxxxxxxxxxx.
+ * Copyright 2010-2014, Rene Gollent, rene@xxxxxxxxxxx.
  * Distributed under the terms of the MIT License.
  */
 #ifndef TEAM_WINDOW_H
@@ -33,10 +33,12 @@ class BStringView;
 class BTabView;
 class ConsoleOutputView;
 class BreakConditionConfigWindow;
+class ExpressionEvaluationWindow;
 class Image;
 class InspectorWindow;
 class RegistersView;
 class SourceCode;
+class SourceLanguage;
 class StackFrame;
 class UserBreakpoint;
 class UserInterfaceListener;
@@ -180,6 +182,9 @@ private:
 
                        status_t                        _SaveInspectorSettings(
                                                                        const 
BMessage* settings);
+
+                       status_t                        
_GetActiveSourceLanguage(
+                                                                       
SourceLanguage*& language);
 private:
                        ::Team*                         fTeam;
                        ::Thread*                       fActiveThread;
@@ -216,6 +221,7 @@ private:
                        BSplitView*                     fConsoleSplitView;
                        BreakConditionConfigWindow* fBreakConditionConfigWindow;
                        InspectorWindow*        fInspectorWindow;
+                       ExpressionEvaluationWindow* fExpressionWindow;
                        GuiTeamUiSettings       fUiSettings;
                        BFilePanel*                     fFilePanel;
                        thread_id                       fActiveSourceWorker;


Other related posts: