This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFA testsuite 2/5] Introduce build_kv_pairs


Hi,

This patch is a simple utility function to build lists of key/value pairs. It is used by subsequent patches.

Keith

testsuite/ChangeLog
2014-04-15  Keith Seitz  <keiths@redhat.com>

	* lib/mi-support.exp (mi_build_kv_pairs): New procedure.


diff --git a/gdb/testsuite/lib/mi-support.exp b/gdb/testsuite/lib/mi-support.exp
index 7c234c0..abbcd8d 100644
--- a/gdb/testsuite/lib/mi-support.exp
+++ b/gdb/testsuite/lib/mi-support.exp
@@ -2354,3 +2354,25 @@ proc mi_walk_varobj_tree {language tree \
 				   mi_varobj_tree_test_children_callback}} {
   ::varobj_tree::walk_tree $language $tree $callback
 }
+
+# Build a list of key-value pairs given by the list ATTR_LIST.  Flatten
+# this list using the optional JOINER, a comma by default.
+#
+# The list must contain an even number of elements, which are the key-value
+# pairs.  Each value will be surrounded by quotes, according to the grammar,
+# except if the value starts with \[ or \{, when the quotes will be omitted.
+#
+# Example: mi_build_kv_pairs {a b c d e f g \[.*\]}
+# returns a=\"b\",c=\"d\",e=\"f\",g=\[.*\]
+proc mi_build_kv_pairs {attr_list {joiner ,}} {
+    set l {}
+    foreach {var value} $attr_list {
+	if {[string range $value 0 1] == "\\\["
+	    || [string range $value 0 1] == "\\\{"} {
+	    lappend l "$var=$value"
+	} else {
+	    lappend l "$var=\"$value\""
+	}
+    }
+    return "[join $l $joiner]"
+}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]