This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[RFA testsuite 2/5] Introduce build_kv_pairs
- From: Keith Seitz <keiths at redhat dot com>
- To: "gdb-patches at sourceware dot org ml" <gdb-patches at sourceware dot org>
- Date: Wed, 16 Apr 2014 11:51:44 -0700
- Subject: [RFA testsuite 2/5] Introduce build_kv_pairs
- Authentication-results: sourceware.org; auth=none
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]"
+}