[nemiver/better-variable-format: 5/10] Add preferences for GDB pretty printing



commit a36364b90ec8b4d8f35713e5dc3d4342d067eeea
Author: Dodji Seketeli <dodji seketeli org>
Date:   Sun Jan 23 01:09:08 2011 +0100

    Add preferences for GDB pretty printing
    
    	* src/confmgr/nmv-conf-keys.h (CONF_KEY_PRETTY_PRINTING): Declare
    	new conf key.
    	* src/confmgr/nmv-conf-keys.cc (CONF_KEY_PRETTY_PRINTING): Define
    	it.
    	* src/dbgengine/nmv-gdb-engine.cc
    	(GDBEngine::Priv::enable_pretty_printing): Rename
    	GDBEngine::Priv::disable_pretty_printing into this.
    	(GDBEngine::Priv::Priv, GDBEngine::load_program): Adjust.
    	(GDB::Engine::Priv::read_default_config): Read the value of key
    	CONF_KEY_PRETTY_PRINTING as well.
    	(GDB::Engine::Priv::on_conf_key_changed_signal): Update
    	GDB::Engine::Priv::enable_pretty_printing.
    	(GDBEngine::disable_pretty_printing): Update remote conf setting.
    	* src/persp/dbgperspective/nmv-preferences-dialog.cc
    	(PreferencesDialog::Priv::pretty_printing_check_button): New check
    	button.
    	(PreferencesDialog::Priv::on_pretty_printing_toggled_signal)
    	(PreferencesDialog::Priv::update_pretty_printing_key): New
    	functions.
    	(PreferencesDialog::Priv::init): Deserialize the new
    	PreferencesDialog::Priv::pretty_printing_check_button.
    	(PreferencesDialog::Priv::update_widget_from_debugger_keys): Read
    	the new CONF_KEY_PRETTY_PRINTING key.
    	* src/persp/dbgperspective/schemas/nemiver-dbgperspective.schemas:
    	Add new schema for key
    	/schemas/apps/nemiver/dbgperspective/pretty-printing.
    	* src/persp/dbgperspective/ui/preferencesdialog.ui: Add a check
    	button to enable pretty printing in the debugger preference tab.

 src/confmgr/nmv-conf-keys.cc                       |    3 +
 src/confmgr/nmv-conf-keys.h                        |    1 +
 src/dbgengine/nmv-gdb-engine.cc                    |   25 ++++++++----
 src/persp/dbgperspective/nmv-preferences-dialog.cc |   33 ++++++++++++++++
 .../schemas/nemiver-dbgperspective.schemas         |   13 ++++++
 src/persp/dbgperspective/ui/preferencesdialog.ui   |   40 ++++++++++++++++++++
 6 files changed, 107 insertions(+), 8 deletions(-)
---
diff --git a/src/confmgr/nmv-conf-keys.cc b/src/confmgr/nmv-conf-keys.cc
index b3f13b5..7f3bcdd 100644
--- a/src/confmgr/nmv-conf-keys.cc
+++ b/src/confmgr/nmv-conf-keys.cc
@@ -66,6 +66,9 @@ const char* CONF_KEY_DEFAULT_NUM_ASM_INSTRS =
 const char *CONF_KEY_GDB_BINARY = "/apps/nemiver/dbgperspective/gdb-binary";
 const char *CONF_KEY_FOLLOW_FORK_MODE = "/apps/nemiver/dbgperspective"
                                         "/follow-fork-mode";
+const char* CONF_KEY_PRETTY_PRINTING =
+    "/apps/nemiver/dbgperspective/pretty-printing";
+
 const char* CONF_KEY_CONTEXT_PANE_LOCATION =
                 "/apps/nemiver/dbgperspective/context-pane-location";
 NEMIVER_END_NAMESPACE (nemiver)
diff --git a/src/confmgr/nmv-conf-keys.h b/src/confmgr/nmv-conf-keys.h
index 68c29cb..46e6dca 100644
--- a/src/confmgr/nmv-conf-keys.h
+++ b/src/confmgr/nmv-conf-keys.h
@@ -50,6 +50,7 @@ extern const char* CONF_KEY_ASM_STYLE_PURE;
 extern const char* CONF_KEY_GDB_BINARY;
 extern const char* CONF_KEY_DEFAULT_NUM_ASM_INSTRS;
 extern const char* CONF_KEY_FOLLOW_FORK_MODE;
+extern const char* CONF_KEY_PRETTY_PRINTING;
 extern const char* CONF_KEY_CONTEXT_PANE_LOCATION;
 
 NEMIVER_END_NAMESPACE (nemiver)
diff --git a/src/dbgengine/nmv-gdb-engine.cc b/src/dbgengine/nmv-gdb-engine.cc
index 3a03944..e87cf6a 100644
--- a/src/dbgengine/nmv-gdb-engine.cc
+++ b/src/dbgengine/nmv-gdb-engine.cc
@@ -57,6 +57,7 @@ NEMIVER_BEGIN_NAMESPACE (nemiver)
 
 extern const char* CONF_KEY_GDB_BINARY;
 extern const char* CONF_KEY_FOLLOW_FORK_MODE;
+extern const char* CONF_KEY_PRETTY_PRINTING;
 
 // Helper function to handle escaping the arguments 
 static UString
@@ -128,7 +129,7 @@ public:
     UString debugger_full_path;
     UString follow_fork_mode;
     GDBMIParser gdbmi_parser;
-    bool disable_pretty_printing;
+    bool enable_pretty_printing;
     sigc::signal<void> gdb_died_signal;
     sigc::signal<void, const UString& > master_pty_signal;
     sigc::signal<void, const UString& > gdb_stdout_signal;
@@ -447,10 +448,11 @@ public:
         cur_thread_num (1),
         follow_fork_mode ("parent"),
         gdbmi_parser (GDBMIParser::BROKEN_MODE),
-        disable_pretty_printing (false)
+        enable_pretty_printing (true)
     {
-        disable_pretty_printing =
-            g_getenv ("NMV_DISABLE_PRETTY_PRINTING") != 0;
+
+        enable_pretty_printing =
+            g_getenv ("NMV_DISABLE_PRETTY_PRINTING") == 0;
 
         gdb_stdout_signal.connect (sigc::mem_fun
                 (*this, &Priv::on_gdb_stdout_signal));
@@ -784,6 +786,9 @@ public:
     {
         get_conf_mgr ()->get_key_value (CONF_KEY_FOLLOW_FORK_MODE,
                                         follow_fork_mode);
+        
+        get_conf_mgr ()->get_key_value (CONF_KEY_PRETTY_PRINTING,
+                                        enable_pretty_printing);
     }
 
     void list_frames (int a_low_frame,
@@ -1008,6 +1013,8 @@ public:
         if (a_key == CONF_KEY_FOLLOW_FORK_MODE) {
             follow_fork_mode = boost::get<UString> (a_value).raw ();
             set_debugger_parameter ("follow-fork-mode", follow_fork_mode);
+        } else if (a_key == CONF_KEY_PRETTY_PRINTING) {
+            enable_pretty_printing = boost::get<bool> (a_value);
         }
 
         NEMIVER_CATCH_NOX
@@ -2760,7 +2767,7 @@ GDBEngine::load_program (const UString &a_prog,
         } else {
             LOG_DD ("not setting LD_BIND_NOW environment variable ");
         }
-        if (!m_priv->disable_pretty_printing)
+        if (m_priv->enable_pretty_printing)
             queue_command (Command ("-enable-pretty-printing"));
     } else {
         Command command ("load-program",
@@ -3473,8 +3480,6 @@ GDBEngine::do_init (IConfMgrSafePtr a_conf_mgr)
 IConfMgr&
 GDBEngine::get_conf_mgr ()
 {
-
-
     return *m_priv->get_conf_mgr ();
 }
 
@@ -5144,7 +5149,11 @@ GDBEngine::set_variable_format (const VariableSafePtr a_var,
 void
 GDBEngine::disable_pretty_printing ()
 {
-    m_priv->disable_pretty_printing = true;
+    // Doing it this way for now b/c you can't change this in GDB on
+    // the fly at the moment.
+    m_priv->enable_pretty_printing = false;
+    get_conf_mgr ().get_key_value (CONF_KEY_PRETTY_PRINTING,
+                                   m_priv->enable_pretty_printing);
 }
 
 /// Set the variable vizualizer used by the GDB Pretty Printing system
diff --git a/src/persp/dbgperspective/nmv-preferences-dialog.cc b/src/persp/dbgperspective/nmv-preferences-dialog.cc
index c880804..d6ab3ef 100644
--- a/src/persp/dbgperspective/nmv-preferences-dialog.cc
+++ b/src/persp/dbgperspective/nmv-preferences-dialog.cc
@@ -93,6 +93,7 @@ public:
     Gtk::RadioButton *follow_child_radio_button;
     Gtk::SpinButton  *default_num_asm_instrs_spin_button;
     Gtk::FileChooserButton *gdb_binary_path_chooser_button;
+    Gtk::CheckButton *pretty_printing_check_button;
     Glib::RefPtr<Gtk::Builder> gtkbuilder;
 
     Priv (const Glib::RefPtr<Gtk::Builder> &a_gtkbuilder,
@@ -115,6 +116,7 @@ public:
         follow_child_radio_button (0),
         default_num_asm_instrs_spin_button (0),
         gdb_binary_path_chooser_button (0),
+        pretty_printing_check_button (0),
         gtkbuilder (a_gtkbuilder)
     {
         init ();
@@ -226,6 +228,11 @@ public:
         update_follow_fork_mode_key ();
     }
 
+    void on_pretty_printing_toggled_signal ()
+    {
+        update_pretty_printing_key ();
+    }
+
     void init ()
     {
 
@@ -432,6 +439,16 @@ public:
             (sigc::mem_fun
                  (*this,
                   &PreferencesDialog::Priv::on_follow_fork_mode_toggle_signal));
+
+        pretty_printing_check_button =
+            ui_utils::get_widget_from_gtkbuilder<Gtk::CheckButton> (gtkbuilder,
+                                                                    "prettyprintingcheckbutton");
+        THROW_IF_FAIL (pretty_printing_check_button);
+        pretty_printing_check_button->signal_toggled ().connect
+            (sigc::mem_fun
+             (*this,
+              &PreferencesDialog::Priv::on_pretty_printing_toggled_signal));
+        
     }
 
     void collect_source_dirs ()
@@ -611,6 +628,14 @@ public:
         conf_manager ().set_key_value (CONF_KEY_FOLLOW_FORK_MODE, mode);
     }
 
+    void update_pretty_printing_key ()
+    {
+        THROW_IF_FAIL (pretty_printing_check_button);
+        
+        bool is_on = pretty_printing_check_button->get_active ();
+        conf_manager ().set_key_value (CONF_KEY_PRETTY_PRINTING, is_on);
+    }
+
     void update_widget_from_editor_keys ()
     {
         THROW_IF_FAIL (show_lines_check_button);
@@ -737,6 +762,14 @@ public:
         } else if (follow_fork_mode == "child") {
             follow_child_radio_button->set_active (true);
         }
+
+        bool is_on = true;
+        if (!conf_manager ().get_key_value (CONF_KEY_PRETTY_PRINTING,
+                                            is_on)) {
+            LOG_ERROR ("failed to get gconf key "
+                       << CONF_KEY_PRETTY_PRINTING);
+        }
+        pretty_printing_check_button->set_active (is_on);
     }
 
     void update_widget_from_conf ()
diff --git a/src/persp/dbgperspective/schemas/nemiver-dbgperspective.schemas b/src/persp/dbgperspective/schemas/nemiver-dbgperspective.schemas
index a31eba5..9dc1dcd 100644
--- a/src/persp/dbgperspective/schemas/nemiver-dbgperspective.schemas
+++ b/src/persp/dbgperspective/schemas/nemiver-dbgperspective.schemas
@@ -218,6 +218,19 @@ key is set to 'parent', or follow the child process if the key is set to
       </locale>
     </schema>
     <schema>
+      <key>/schemas/apps/nemiver/dbgperspective/pretty-printing</key>
+      <applyto>/apps/nemiver/dbgperspective/pretty-printing</applyto>
+      <owner>nemiver</owner>
+      <type>bool</type>
+      <default>true</default>
+      <locale name="C">
+	<short>Activate GDB pretty printing</short>
+	<long>Activate the GDB printing feature. Under that mode the
+content of many types of containers is displayed in a human friendly
+manner</long>
+      </locale>
+    </schema>
+    <schema>
       <key>/schemas/apps/nemiver/dbgperspective/callstack-expansion-chunk</key>
       <applyto>/apps/nemiver/dbgperspective/callstack-expansion-chunk</applyto>
       <owner>nemiver</owner>
diff --git a/src/persp/dbgperspective/ui/preferencesdialog.ui b/src/persp/dbgperspective/ui/preferencesdialog.ui
index 01c6661..9ede5eb 100644
--- a/src/persp/dbgperspective/ui/preferencesdialog.ui
+++ b/src/persp/dbgperspective/ui/preferencesdialog.ui
@@ -629,6 +629,8 @@
                     </child>
                   </object>
                   <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">False</property>
                     <property name="position">2</property>
                   </packing>
                 </child>
@@ -690,9 +692,47 @@
                     </child>
                   </object>
                   <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">False</property>
                     <property name="position">3</property>
                   </packing>
                 </child>
+                <child>
+                  <object class="GtkFrame" id="frame11">
+                    <property name="visible">True</property>
+                    <property name="label_xalign">0</property>
+                    <property name="shadow_type">none</property>
+                    <child>
+                      <object class="GtkAlignment" id="alignment12">
+                        <property name="visible">True</property>
+                        <property name="top_padding">6</property>
+                        <property name="left_padding">12</property>
+                        <child>
+                          <object class="GtkCheckButton" id="prettyprintingcheckbutton">
+                            <property name="label" translatable="yes">Enable pretty printing (requires debugger restart)</property>
+                            <property name="visible">True</property>
+                            <property name="can_focus">True</property>
+                            <property name="receives_default">False</property>
+                            <property name="active">True</property>
+                            <property name="draw_indicator">True</property>
+                          </object>
+                        </child>
+                      </object>
+                    </child>
+                    <child type="label">
+                      <object class="GtkLabel" id="label18">
+                        <property name="visible">True</property>
+                        <property name="label" translatable="yes">&lt;b&gt;GDB pretty printing&lt;/b&gt;</property>
+                        <property name="use_markup">True</property>
+                      </object>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">False</property>
+                    <property name="position">4</property>
+                  </packing>
+                </child>
               </object>
               <packing>
                 <property name="position">2</property>



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]