[nemiver] 646698 Add cmd line option to choose the gdb binary



commit a7ae7d98edb9462e22e520861ec0e5683224b7bf
Author: Fabien Parent <parent f gmail com>
Date:   Thu Oct 6 21:56:43 2011 +0200

    646698 Add cmd line option to choose the gdb binary
    
    	* src/dbgengine/nmv-gdb-engine.cc
    	(GDBEngine::Priv::get_debugger_full_path): Return the path of the debugger
    	from the command line if specified
    	(GDBEngine::set_non_persistent_debugger_path): New API
    	* src/dbgengine/nmv-i-debugger.h
    	(GDBEngine::set_non_persistent_debugger_path): New API
    	* src/main.cc (process_gui_options): Set the debugger path from the command
    	line if specified in it

 src/dbgengine/nmv-gdb-engine.cc |   22 ++++++++++++++++------
 src/dbgengine/nmv-gdb-engine.h  |    2 +-
 src/dbgengine/nmv-i-debugger.h  |    3 +++
 src/main.cc                     |   26 ++++++++++++++++++++++++++
 4 files changed, 46 insertions(+), 7 deletions(-)
---
diff --git a/src/dbgengine/nmv-gdb-engine.cc b/src/dbgengine/nmv-gdb-engine.cc
index 29534e6..b9b7436 100644
--- a/src/dbgengine/nmv-gdb-engine.cc
+++ b/src/dbgengine/nmv-gdb-engine.cc
@@ -224,7 +224,8 @@ public:
     int cur_thread_num;
     Address cur_frame_address;
     ILangTraitSafePtr lang_trait;
-    UString debugger_full_path;
+    UString non_persistent_debugger_path;
+    mutable UString debugger_full_path;
     UString follow_fork_mode;
     UString disassembly_flavor;
     GDBMIParser gdbmi_parser;
@@ -422,16 +423,18 @@ public:
 
     const UString& get_debugger_full_path () const
     {
+        debugger_full_path = non_persistent_debugger_path;
+
         NEMIVER_TRY
-        get_conf_mgr ()->get_key_value (CONF_KEY_GDB_BINARY,
-                                        const_cast<Priv*>
-                                                (this)->debugger_full_path);
+        if (debugger_full_path.empty()) {
+            get_conf_mgr ()->get_key_value (CONF_KEY_GDB_BINARY,
+                                            debugger_full_path);
+        }
         NEMIVER_CATCH_NOX
 
         if (debugger_full_path == "" ||
             debugger_full_path == DEFAULT_GDB_BINARY) {
-            const_cast<Priv*> (this)->debugger_full_path =
-                                                    env::get_gdb_program ();
+            debugger_full_path = env::get_gdb_program ();
         }
         LOG_DD ("debugger: '" << debugger_full_path << "'");
         return debugger_full_path;
@@ -4044,6 +4047,13 @@ GDBEngine::busy () const
     return false;
 }
 
+void
+GDBEngine::set_non_persistent_debugger_path (const UString &a_full_path)
+{
+    THROW_IF_FAIL (m_priv);
+    m_priv->non_persistent_debugger_path = a_full_path;
+}
+
 const UString&
 GDBEngine::get_debugger_full_path () const
 {
diff --git a/src/dbgengine/nmv-gdb-engine.h b/src/dbgengine/nmv-gdb-engine.h
index a817da8..11b1668 100644
--- a/src/dbgengine/nmv-gdb-engine.h
+++ b/src/dbgengine/nmv-gdb-engine.h
@@ -270,7 +270,7 @@ public:
     void execute_command (const Command &a_command);
     bool queue_command (const Command &a_command);
     bool busy () const;
-    void set_debugger_full_path (const UString &a_full_path);
+    void set_non_persistent_debugger_path (const UString &a_full_path);
     const UString& get_debugger_full_path () const;
     void set_debugger_parameter (const UString &a_name,
                                  const UString &a_value);
diff --git a/src/dbgengine/nmv-i-debugger.h b/src/dbgengine/nmv-i-debugger.h
index 4e8b2ed..1576a1f 100644
--- a/src/dbgengine/nmv-i-debugger.h
+++ b/src/dbgengine/nmv-i-debugger.h
@@ -1113,6 +1113,9 @@ public:
 
     virtual bool busy () const = 0;
 
+    virtual void set_non_persistent_debugger_path
+                (const UString &a_full_path) = 0;
+
     virtual const UString& get_debugger_full_path () const  = 0;
 
     virtual void set_solib_prefix_path (const UString &a_name) = 0;
diff --git a/src/main.cc b/src/main.cc
index de6927b..303ee65 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -25,6 +25,7 @@
 #include "config.h"
 #include <signal.h>
 #include <unistd.h>
+#include <stdlib.h>
 #include <iostream>
 #include <gtkmm/window.h>
 #include <glib/gi18n.h>
@@ -62,6 +63,7 @@ static bool gv_show_version = false;
 static bool gv_use_launch_terminal = false;
 static gchar *gv_remote = 0;
 static gchar *gv_solib_prefix = 0;
+static gchar *gv_gdb_binary_filepath = 0;
 
 static GOptionEntry entries[] =
 {
@@ -158,6 +160,15 @@ static GOptionEntry entries[] =
 	"Use in conjunction with --remote"),
       "</path/to/prefix>"
     },
+    {
+      "gdb-binary",
+      0,
+      0,
+      G_OPTION_ARG_STRING,
+      &gv_gdb_binary_filepath,
+      _("Set the path of the GDB binary to use to debug the inferior"),
+      "</path/to/gdb>"
+    },
     { "version",
       0,
       0,
@@ -530,6 +541,21 @@ process_gui_options (int& a_argc, char** a_argv)
         dynamic_cast<IDBGPerspective*> (s_workbench->get_perspective
                                             (DBGPERSPECTIVE_PLUGIN_NAME));
     if (debug_persp) {
+        if (gv_gdb_binary_filepath) {
+            char *debugger_full_path = realpath (gv_gdb_binary_filepath, 0);
+            if (debugger_full_path) {
+                nemiver::IDebuggerSafePtr debugger = debug_persp->debugger ();
+                if (!debugger) {
+                    cerr << "Could not get the debugger instance" << endl;
+                    return false;
+                }
+                debugger->set_non_persistent_debugger_path (debugger_full_path);
+                free (debugger_full_path);
+            } else {
+                LOG_ERROR ("Could not resolve the full path of the debugger");
+            }
+        }
+
         map<UString, UString> env;
         if (gv_env_vars) {
             vector<UString> env_vars =



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