[nemiver/remote-cmdline: 2/14] Initial support for --remote (#624630)



commit 9d285a5e232f3c298205c2914299b2563dd4e135
Author: Dodji Seketeli <dodji seketeli org>
Date:   Sun Oct 3 17:11:53 2010 +0200

    Initial support for --remote (#624630)
    
    	* src/common/nmv-str-utils.h (parse_host_and_port): New public API.
    	* src/common/nmv-str-utils.cc (parse_string_colon_number):
    	New function. Extracted from ...
    	(extract_path_and_line_num_from_location): ... this.
    	(parse_host_and_port): New public fn. Uses
    	parse_string_colon_number.
    	* src/persp/dbgperspective/nmv-dbg-perspective.cc
    	* src/persp/dbgperspective/nmv-dbg-perspective.h
    	(DBGPerspective::connect_to_remote_target): Add this as a public
    	API.
    	(DBGPerspective::connect_to_remote_target): Add new parms to make
    	this callable from outside of the perspective. Clean up the
    	overload with no parm to make it rely on the overloads with parms.
    	* src/main.cc (process_gui_options): Take in account new
    	--remote and --solib-prefix to attach to a target running
    	remotely.

 src/common/nmv-str-utils.cc                     |   99 +++++++++++++++--------
 src/common/nmv-str-utils.h                      |   12 ++-
 src/main.cc                                     |   60 +++++++++++++-
 src/persp/dbgperspective/nmv-dbg-perspective.cc |   42 +++++++---
 src/persp/dbgperspective/nmv-dbg-perspective.h  |    9 ++
 5 files changed, 166 insertions(+), 56 deletions(-)
---
diff --git a/src/common/nmv-str-utils.cc b/src/common/nmv-str-utils.cc
index daffc6b..d54b124 100644
--- a/src/common/nmv-str-utils.cc
+++ b/src/common/nmv-str-utils.cc
@@ -45,57 +45,88 @@ static const char *SUPPORTED_ENCODINGS[] =
 #define SIZE_OF_SUPPORTED_ENCODINGS \
 sizeof (SUPPORTED_ENCODINGS)/sizeof (SUPPORTED_ENCODINGS[0])
 
-// Return true if a_str is a location string of the form
-// "filename:number", where number is string of digits.
-// Keep in mind that filename can also be a path that contains ':'
-// itself. So this function tries hard to make sure what follows the ':'
-// is a real number and ends the string.
-bool
-extract_path_and_line_num_from_location (const std::string &a_str,
-                                         std::string &a_filename,
-                                         std::string &a_line_num)
+
+static bool
+parse_string_colon_number (const std::string &a_str,
+                           std::string &a_resulting_string,
+                           std::string &a_number)
 {
     std::string filename;
     std::string::size_type colon_pos;
     bool result = false;
+
     if ((colon_pos = a_str.find_last_of (":"))
         == std::string::npos) {
         // The string has no ':' character. Let's bail out.
-    } else {
-        // Is what comes after the comma a legit number?
-        bool is_number = true;
-        std::string::size_type str_len = colon_pos;
+        return false;
+    }
 
-        if (colon_pos + 1 >= a_str.length ())
+    // Is what comes after the comma a legit number?
+    bool is_number = true;
+    std::string::size_type str_len = colon_pos;
+
+    if (colon_pos + 1 >= a_str.length ())
+        is_number = false;
+    // Loop to make sure the thing after the ':' is an actual
+    // number.
+    std::string::size_type i;
+    for (i = colon_pos + 1; i < a_str.length (); ++i) {
+        if (!isdigit (a_str[i])) {
             is_number = false;
-        // Loop to make sure the thing after the ':' is an actual
-        // number.
-        std::string::size_type i;
-        for (i = colon_pos + 1; i < a_str.length (); ++i) {
-            if (!isdigit (a_str[i])) {
-                is_number = false;
-                break;
-            }
+            break;
         }
-        bool number_is_at_end_of_str = (i >= a_str.length ());
+    }
+    bool number_is_at_end_of_str = (i >= a_str.length ());
 
-        if (is_number && number_is_at_end_of_str) {
-            string file_name, line_num;
+    if (is_number && number_is_at_end_of_str) {
+        string file_name, line_num;
 
-            for (string::size_type i = 0; i < str_len; ++i)
-                a_filename.push_back (a_str[i]);
+        for (string::size_type i = 0; i < str_len; ++i)
+            a_resulting_string.push_back (a_str[i]);
 
-            for (string::size_type i = colon_pos + 1; i < a_str.length (); ++i)
-                a_line_num.push_back (a_str[i]);
-            result = true;
-        } else {
-            // Bail out because the ':' is either not a legit number or
-            // not at the end of the string.
-        }
+        for (string::size_type i = colon_pos + 1; i < a_str.length (); ++i)
+            a_number.push_back (a_str[i]);
+        result = true;
+    } else {
+        // Bail out because the ':' is either not a legit number or
+        // not at the end of the string.
     }
+    
     return result;
 }
 
+// Return true if a_str is a location string of the form
+// "filename:number", where number is string of digits.
+// Keep in mind that filename can also be a path that contains ':'
+// itself. So this function tries hard to make sure what follows the ':'
+// is a real number and ends the string.
+bool
+extract_path_and_line_num_from_location (const std::string &a_str,
+                                         std::string &a_filename,
+                                         std::string &a_line_num)
+{
+    return parse_string_colon_number (a_str, a_filename, a_line_num);
+}
+
+/// Extract host and post parts from a string of the form host:port.
+/// \param a the string to parse
+/// \param a_host the part that was extracted from
+bool
+parse_host_and_port (const std::string &a_str,
+                     std::string &a_host,
+                     unsigned &a_port)
+{
+    std::string host;
+    std::string port;
+
+    if (!parse_string_colon_number (a_str, host, port))
+        return false;
+
+    a_port = atoi (port.c_str ());
+    a_host = host;
+    return true;
+}
+
 size_t
 hexa_to_int (const string &a_hexa_str)
 {
diff --git a/src/common/nmv-str-utils.h b/src/common/nmv-str-utils.h
index 65b798d..8c72b8c 100644
--- a/src/common/nmv-str-utils.h
+++ b/src/common/nmv-str-utils.h
@@ -31,10 +31,14 @@ NEMIVER_BEGIN_NAMESPACE (str_utils)
 
 using nemiver::common::UString;
 
-bool
-extract_path_and_line_num_from_location (const std::string &a_location,
-                                         std::string &a_file_path,
-                                         std::string &a_line_num);
+bool extract_path_and_line_num_from_location (const std::string &a_location,
+					      std::string &a_file_path,
+					      std::string &a_line_num);
+
+bool parse_host_and_port (const std::string &a,
+			  std::string &a_host,
+			  unsigned &a_port);
+
 size_t hexa_to_int (const string &a_hexa_str);
 std::string int_to_string (size_t an_int);
 bool string_is_number (const string&);
diff --git a/src/main.cc b/src/main.cc
index bc94428..5732ebe 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -27,6 +27,7 @@
 #include <iostream>
 #include <gtkmm/window.h>
 #include <glib/gi18n.h>
+#include "nmv-str-utils.h"
 #include "nmv-exception.h"
 #include "nmv-initializer.h"
 #include "nmv-i-workbench.h"
@@ -53,9 +54,11 @@ static bool gv_purge_sessions=false;
 static int gv_execute_session=0;
 static bool gv_last_session=false;
 static gchar *gv_log_domains=0;
-static bool gv_log_debugger_output=false;
-static bool gv_show_version=false;
-static bool gv_use_launch_terminal=false;
+static bool gv_log_debugger_output = false;
+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 GOptionEntry entries[] =
 {
@@ -133,6 +136,25 @@ static GOptionEntry entries[] =
       _("Use this terminal as the debugee's terminal"),
       NULL
     },
+    {
+      "remote",
+      0,
+      0,
+      G_OPTION_ARG_STRING,
+      &gv_remote,
+      _("Connect to remote target specified by host:port"),
+      NULL,
+    },
+    {
+      "solib-prefix",
+      0,
+      0,
+      G_OPTION_ARG_STRING,
+      &gv_solib_prefix,
+      _("Where to look for shared libraries loaded by the inferior. "
+	"Use in conjunction with --remote"),
+      NULL,
+    },
     { "version",
       0,
       0,
@@ -141,7 +163,7 @@ static GOptionEntry entries[] =
       _("Show the version number of nemiver"),
       NULL
     },
-    {0,0,0,(GOptionArg)0,0,0,0}
+    {0, 0, 0, (GOptionArg)0, 0, 0, 0}
 };
 
 struct GOptionContextUnref {
@@ -266,6 +288,8 @@ parse_command_line (int& a_argc,
     }
 }
 
+// Return true if Nemiver should keep going after the non gui options
+// have been processed.
 static bool
 process_non_gui_options ()
 {
@@ -290,6 +314,8 @@ process_non_gui_options ()
     return true;
 }
 
+/// Return true if Nemiver should keep going after the GUI option(s)
+/// have been processed.
 static bool
 process_gui_options (int& a_argc, char** a_argv)
 {
@@ -469,7 +495,31 @@ process_gui_options (int& a_argc, char** a_argv)
                 env[name] = value;
             }
         }
-        if (!prog_path.empty ()) {
+	if (gv_remote) {
+            // The user asked to connect to a remote target.
+            std::string host;
+            unsigned port = 0;
+            std::string solib_prefix;
+
+            if (gv_solib_prefix)
+                solib_prefix = gv_solib_prefix;
+
+            if (nemiver::str_utils::parse_host_and_port (gv_remote,
+                                                         host, port)) {
+                // So it looks like gv_remote has the form
+                // "host:port", so let's try to connect to that.
+                debug_persp->connect_to_remote_target (host, port,
+                                                       prog_path,
+                                                       solib_prefix);
+            } else {
+                // We think gv_remote contains a serial line address.
+                // Let's try to connect via the serial line then.
+                debug_persp->connect_to_remote_target (gv_remote,
+                                                       prog_path,
+                                                       solib_prefix);
+            }
+	} else if (!prog_path.empty ()) {
+            // The user wants to debug a local program
             debug_persp->uses_launch_terminal (gv_use_launch_terminal);
             debug_persp->execute_program (prog_path,
                                           prog_args,
diff --git a/src/persp/dbgperspective/nmv-dbg-perspective.cc b/src/persp/dbgperspective/nmv-dbg-perspective.cc
index b20cca0..1cc5144 100644
--- a/src/persp/dbgperspective/nmv-dbg-perspective.cc
+++ b/src/persp/dbgperspective/nmv-dbg-perspective.cc
@@ -596,8 +596,12 @@ public:
                             bool a_close_opened_files=false);
     void connect_to_remote_target ();
     void connect_to_remote_target (const UString &a_server_address,
-                                   int a_server_port);
-    void connect_to_remote_target (const UString &a_serial_line);
+                                   unsigned a_server_port,
+                                   const UString &a_prog_path,
+                                   const UString &a_solib_prefix);
+    void connect_to_remote_target (const UString &a_serial_line,
+                                   const UString &a_prog_path,
+                                   const UString &a_solib_prefix);
     void detach_from_program ();
     void load_core_file ();
     void load_core_file (const UString &a_prog_file,
@@ -6289,41 +6293,53 @@ DBGPerspective::connect_to_remote_target ()
 
     UString path = dialog.get_executable_path ();
     LOG_DD ("executable path: '" <<  path << "'");
-    vector<UString> args;
-    debugger ()->load_program (path , args, ".");
-    path = dialog.get_solib_prefix_path ();
-    LOG_DD ("solib prefix path: '" <<  path << "'");
-    debugger ()->set_solib_prefix_path (path);
+    UString solib_prefix = dialog.get_solib_prefix_path ();
 
     if (dialog.get_connection_type ()
         == RemoteTargetDialog::TCP_CONNECTION_TYPE) {
         connect_to_remote_target (dialog.get_server_address (),
-                                  dialog.get_server_port ());
+                                  dialog.get_server_port (),
+                                  path, solib_prefix);
     } else if (dialog.get_connection_type ()
                == RemoteTargetDialog::SERIAL_CONNECTION_TYPE) {
-        connect_to_remote_target (dialog.get_serial_port_name ());
+        connect_to_remote_target (dialog.get_serial_port_name (),
+                                  path, solib_prefix);
     }
 }
 
 void
 DBGPerspective::connect_to_remote_target (const UString &a_server_address,
-                                          int a_server_port)
+                                          unsigned a_server_port,
+                                          const UString &a_prog_path,
+                                          const UString &a_solib_prefix)
 {
     LOG_FUNCTION_SCOPE_NORMAL_DD
     THROW_IF_FAIL (debugger ());
 
     save_current_session ();
-    debugger ()->attach_to_remote_target (a_server_address, a_server_port);
-
+    LOG_DD ("executable path: '" <<  a_prog_path << "'");
+    vector<UString> args;
+    debugger ()->load_program (a_prog_path , args, ".");
+    LOG_DD ("solib prefix path: '" <<  a_solib_prefix << "'");
+    debugger ()->set_solib_prefix_path (a_solib_prefix);
+    debugger ()->attach_to_remote_target (a_server_address,
+                                          a_server_port);
 }
 
 void
-DBGPerspective::connect_to_remote_target (const UString &a_serial_line)
+DBGPerspective::connect_to_remote_target (const UString &a_serial_line,
+                                          const UString &a_prog_path,
+                                          const UString &a_solib_prefix)
 {
     LOG_FUNCTION_SCOPE_NORMAL_DD
     THROW_IF_FAIL (debugger ());
 
     save_current_session ();
+    LOG_DD ("executable path: '" <<  a_prog_path << "'");
+    vector<UString> args;
+    debugger ()->load_program (a_prog_path , args, ".");
+    LOG_DD ("solib prefix path: '" <<  a_solib_prefix << "'");
+    debugger ()->set_solib_prefix_path (a_solib_prefix);
     debugger ()->attach_to_remote_target (a_serial_line);
 }
 
diff --git a/src/persp/dbgperspective/nmv-dbg-perspective.h b/src/persp/dbgperspective/nmv-dbg-perspective.h
index 6bbee41..5e4a34b 100644
--- a/src/persp/dbgperspective/nmv-dbg-perspective.h
+++ b/src/persp/dbgperspective/nmv-dbg-perspective.h
@@ -102,6 +102,15 @@ public:
     virtual void attach_to_program (unsigned int a_pid,
                                     bool a_close_open_files = false) = 0;
 
+    virtual void connect_to_remote_target (const UString &a_server_address,
+					   unsigned a_server_port,
+                                           const UString &a_prog_path,
+                                           const UString &a_solib_prefix) = 0;
+
+    virtual void connect_to_remote_target (const UString &a_serial_line,
+                                           const UString &a_prog_path,
+                                           const UString &a_solib_prefix) = 0;
+
     virtual void load_core_file () = 0;
 
     virtual void load_core_file (const UString &a_prog_path,



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