[RFA,testsuite,4/5] Introduce mi_make_breakpoint_table

Message ID 53580D54.4070104@redhat.com
State Committed
Headers

Commit Message

Keith Seitz April 23, 2014, 6:58 p.m. UTC
  On 04/17/2014 01:44 PM, Tom Tromey wrote:
>>>>>> "Keith" == Keith Seitz <keiths@redhat.com> writes:
>
> Keith> 2014-04-15  Keith Seitz  <keiths@redhat.com>
>
> Keith> 	* lib/mi-support.exp (mi_list_breakpoints): Delete.
> Keith> 	(mi_make_breakpoint_table): New procedure.
>
> Thanks, this is ok.
>
> Keith> +	lappend hl "{[mi_build_kv_pairs [list width .* alignment .* \
> Keith> +				       col_name $nm colhdr $hdr]]}"
>
> I found this line a bit weird, at first thinking that it should probably
> be [list...], but then I realized the "{..}" is probably to match MI output.
> So I guess a comment wouldn't hurt here.

V2 changes:
* Added comment explaining header format

I've attached what I will be pushing.

Keith

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

	* lib/mi-support.exp (mi_list_breakpoints): Delete.
	(mi_make_breakpoint_table): New procedure.
  

Patch

diff --git a/gdb/testsuite/lib/mi-support.exp b/gdb/testsuite/lib/mi-support.exp
index a497208..8fd5935 100644
--- a/gdb/testsuite/lib/mi-support.exp
+++ b/gdb/testsuite/lib/mi-support.exp
@@ -1242,33 +1242,6 @@  proc mi_create_breakpoint {location test args} {
     return $bp
 }
 
-proc mi_list_breakpoints { expected test } {
-    set fullname ".*"
-
-    set body ""
-    set first 1
-
-    foreach item $expected {
-	if {$first == 0} {
-	    set body "$body,"
-	    set first 0
-	}
-	set number [lindex $item 0]
-	set disp [lindex $item 1]
-	set func [lindex $item 2]
-	set file [lindex $item 3]
-	set line [lindex $item 4]
-	set address [lindex $item 5]
-	set body "${body}bkpt=\{number=\"$number\",type=\"breakpoint\",disp=\"$disp\",enabled=\"y\",addr=\"$address\",func=\"$func\",file=\".*$file\",${fullname},line=\"$line\",thread-groups=\\\[\"i1\"\\\],times=\"0\",original-location=\".*\"\}"
-	set first 0
-    }
-
-    verbose -log "Expecting: 666\\\^done,BreakpointTable=\{nr_rows=\".\",nr_cols=\".\",hdr=\\\[\{width=\".*\",alignment=\".*\",col_name=\"number\",colhdr=\"Num\"\}.*colhdr=\"Type\".*colhdr=\"Disp\".*colhdr=\"Enb\".*colhdr=\"Address\".*colhdr=\"What\".*\\\],body=\\\[$body\\\]\}"
-    mi_gdb_test "666-break-list" \
-	"666\\\^done,BreakpointTable=\{nr_rows=\".\",nr_cols=\".\",hdr=\\\[\{width=\".*\",alignment=\".*\",col_name=\"number\",colhdr=\"Num\"\}.*colhdr=\"Type\".*colhdr=\"Disp\".*colhdr=\"Enb\".*colhdr=\"Address\".*colhdr=\"What\".*\\\],body=\\\[$body\\\]\}" \
-	$test
-}
-
 # Creates varobj named NAME for EXPRESSION.
 # Name cannot be "-".
 proc mi_create_varobj { name expression testname } {
@@ -2431,3 +2404,43 @@  proc mi_make_breakpoint {args} {
     append result "}"
     return $result
 }
+
+# Build a breakpoint table regexp given the list of breakpoints in `bp_list',
+# constructed by mi_make_breakpoint.
+#
+# Example:  Construct a breakpoint table where the only attributes we
+# test for are the existence of three breakpoints numbered 1, 2, and 3.
+#
+# set bps {}
+# lappend bps [mi_make_breakpoint -number 1]
+# lappend bps [mi_make_breakpoint -number 2]
+# lappned bps [mi_make_breakpoint -number 3]
+# mi_make_breakpoint_table $bps
+# will return (abbreviated for clarity):
+# BreakpointTable={nr_rows="3",nr_cols="6",hdr=[{width=".*",...} ...],
+#   body=[bkpt={number="1",...},bkpt={number="2",...},bkpt={number="3",...}]}
+
+proc mi_make_breakpoint_table {bp_list} {
+    # Build header -- assume a standard header for all breakpoint tables.
+    set hl {}
+    foreach {nm hdr} [list number Num type Type disp Disp enabled Enb \
+			  addr Address what What] {
+	# The elements here are the MI table headers, which have the
+	# format:
+	# {width="7",alignment="-1",col_name="number",colhdr="Num"}
+
+	lappend hl "{[mi_build_kv_pairs [list width .* alignment .* \
+				       col_name $nm colhdr $hdr]]}"
+    }
+    set header "hdr=\\\[[join $hl ,]\\\]"
+
+    # The caller has implicitly supplied the number of columns and rows.
+    set nc [llength $hl]
+    set nr [llength $bp_list]
+
+    # Build body -- mi_make_breakpoint has done most of the work.
+    set body "body=\\\[[join $bp_list ,]\\\]"
+
+    # Assemble the final regexp.
+    return "BreakpointTable={nr_rows=\"$nr\",nr_cols=\"$nc\",$header,$body}"
+}