[nemiver] Quote arguments passed to gdb (Closes: #575889)



commit a82d2566f8ee58fd7f3d9a6c1ccc48163febe481
Author: Jonathon Jongsma <jonathon jongsma collabora co uk>
Date:   Sun Apr 19 22:46:17 2009 -0500

    Quote arguments passed to gdb (Closes: #575889)
    
        * src/dbgengine/nmv-gdb-engine.cc: add a helper function that will
          properly shell-quote the arguments passed to gdb so that things
          won't get expanded twice (e.g. by the shell when invoking nemiver
          on the command line and then again when executing the program)
---
 src/dbgengine/nmv-gdb-engine.cc |   45 +++++++++++++++++++++-----------------
 1 files changed, 25 insertions(+), 20 deletions(-)

diff --git a/src/dbgengine/nmv-gdb-engine.cc b/src/dbgengine/nmv-gdb-engine.cc
index 2e4b9f6..64128cd 100644
--- a/src/dbgengine/nmv-gdb-engine.cc
+++ b/src/dbgengine/nmv-gdb-engine.cc
@@ -54,6 +54,22 @@ static const UString CONF_KEY_GDB_BINARY = "/apps/nemiver/dbgperspective/gdb-bin
 
 NEMIVER_BEGIN_NAMESPACE (nemiver)
 
+// Helper function to handle escaping the arguments 
+static UString
+quote_args (const vector<UString> &a_prog_args)
+{
+    UString args;
+    if (!a_prog_args.empty ()) {
+        for (vector<UString>::size_type i=1;
+             i < a_prog_args.size ();
+             ++i) {
+            args += Glib::shell_quote (a_prog_args[i].raw ()) + " ";
+        }
+    }
+    return args;
+}
+
+
 //*************************
 //<GDBEngine::Priv struct>
 //*************************
@@ -603,19 +619,11 @@ public:
                 << "\ngdboptions:" << UString::join (a_gdb_options));
 
         if (!result) {return false;}
-
-        if (!a_prog_args.empty ()) {
-            UString args;
-            for (vector<UString>::size_type i=1;
-                 i < a_prog_args.size ();
-                 ++i) {
-                args += a_prog_args[i] + " ";
-            }
-
-            if (args != "") {
-                return issue_command (Command ("set args " + args));
-            }
+        UString args = quote_args (a_prog_args);
+        if (!args.empty ()) {
+            return issue_command (Command ("set args " + args));
         }
+
         return true;
     }
 
@@ -2081,18 +2089,15 @@ GDBEngine::load_program (const vector<UString> &a_argv,
             LOG_DD ("not setting LD_BIND_NOW environment variable ");
         }
     } else {
-        UString args;
-        UString::size_type len (argv.size ());
-        for (UString::size_type i = 1; i < len; ++i) {
-            args += " " + argv[i];
-        }
-
         Command command ("load-program",
                          UString ("-file-exec-and-symbols ") + argv[0]);
         queue_command (command);
 
-        command.value ("set args " + args);
-        queue_command (command);
+        UString args = quote_args (argv);
+        if (!args.empty ()) {
+            command.value ("set args " + args);
+            queue_command (command);
+        }
     }
     if (!a_tty_path.empty ()) {
         queue_command (Command ("set inferior-tty " + a_tty_path));



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