+2015-11-24  Pedro Alves  <palves@redhat.com>
+
+       PR 17539
+       * printcmd.c (display_command): Append new display at the end of
+       the list.
+
 2015-11-24  Pedro Alves  <palves@redhat.com>
 
        PR 17539
 
   newobj->exp = expr;
   newobj->block = innermost_block;
   newobj->pspace = current_program_space;
-  newobj->next = display_chain;
   newobj->number = ++display_number;
   newobj->format = fmt;
   newobj->enabled_p = 1;
-  display_chain = newobj;
+  newobj->next = NULL;
+
+  if (display_chain == NULL)
+    display_chain = newobj;
+  else
+    {
+      struct display *last;
+
+      for (last = display_chain; last->next != NULL; last = last->next)
+       ;
+      last->next = newobj;
+    }
 
   if (from_tty)
     do_one_display (newobj);
 
+2015-11-24  Pedro Alves  <palves@redhat.com>
+
+       PR 17539
+       * gdb.base/display.exp: Expect displays to be sorted in ascending
+       order.  Use multi_line.
+       * gdb.base/solib-display.exp: Likewise.
+
 2015-11-24  Pedro Alves  <palves@redhat.com>
 
        PR 17539
 
 
 # Hit the displays
 #
-gdb_test "cont" ".*\[Ww\]atchpoint 3: sum.*\[1-9\]*: x/s &sum.*\[1-9\]*: /f f = 3.1415\r\n\[1-9\]*: x/i &k.*\r\n\[1-9\]*: /x j = 0x0\r\n\[1-9\]*: i = 0.*" "first disp"
-gdb_test "cont" ".*\[Ww\]atchpoint 3: sum.*\[1-9\]*: x/s &sum.*\[1-9\]*: /f f = 4.1415\r\n\[1-9\]*: x/i &k.*\r\n\[1-9\]*: /x j = 0x0.*\[1-9\]*: i = 0.*" "second disp"
+gdb_test "cont" [multi_line \
+                    ".*\[Ww\]atchpoint 3: sum.*" \
+                    "\[1-9\]*: i = 0.*" \
+                    "\[1-9\]*: /x j = 0x0" \
+                    "\[1-9\]*: x/i &k.*" \
+                    "\[1-9\]*: /f f = 3.1415" \
+                    "\[1-9\]*: x/s &sum.*" \
+                   ] "first disp"
+
+gdb_test "cont" [multi_line \
+                    ".*\[Ww\]atchpoint 3: sum.*" \
+                    "\[1-9\]*: i = 0.*" \
+                    "\[1-9\]*: /x j = 0x0.*" \
+                    "\[1-9\]*: x/i &k.*" \
+                    "\[1-9\]*: /f f = 4.1415" \
+                    "\[1-9\]*: x/s &sum.*" \
+                   ] "second disp"
 
 gdb_test "enab  disp 6" ".*No display number 6..*" "catch err"
 gdb_test_no_output "disab disp 1" "disab disp 1"
 gdb_test_no_output "enab disp 1"  "re-enab"
 gdb_test_no_output "enab disp 1"  "re-enab of enab"
 gdb_test_no_output "undisp 5"     "undisp"
-gdb_test "info disp"    ".*Auto-display expressions now in effect.*y  /f f.*y  /1bi &k.*n  /x j.*y  i.*" "info disp"
-
-gdb_test "cont" ".*\[Ww\]atch.*5.1415.*.*i = 0.*" "next hit"
+gdb_test "info disp" [multi_line \
+                         "Auto-display expressions now in effect.*" \
+                         ".*y  i" \
+                         ".*n  /x j" \
+                         ".*y  /1bi &k" \
+                         ".*y  /f f" \
+                        ] "info disp"
+
+gdb_test "cont" [multi_line \
+                    ".*\[Ww\]atch.*" \
+                    ".*i = 0" \
+                    ".*5.1415" \
+                   ] "next hit"
 
 gdb_test "undisp" \
     "" \
 
        continue
     }
 
-    gdb_test "" "3: c_global = 43\\r\\n2: b_global = 42\\r\\n1: a_global = 41" "after rerun"
+    gdb_test "" [multi_line \
+                    "1: a_global = 41" \
+                    "2: b_global = 42"  \
+                    "3: c_global = 43" \
+                   ] "after rerun"
 
     # Now rebuild the library without b_global
     if { [gdb_compile_shlib ${srcfile_lib} ${binfile_lib} \
        continue
     }
 
-    gdb_test "" "3: c_global = 43\\r\\nwarning: .*b_global.*\\r\\n1: a_global = 41" "after rerun (2)"
+
+    gdb_test "" [multi_line \
+                    "1: a_global = 41" \
+                    "warning: .*b_global.*"  \
+                    "3: c_global = 43" \
+                   ] "after rerun (2)"
 
     # Now verify that displays which are not in the shared library
     # are not cleared permaturely.
     gdb_test "" "6: a_static = 46\\r\\n4: main_global = 44\\r\\n.*"
     gdb_test "break [gdb_get_line_number "break here" ${testfile}.c]" \
            ".*Breakpoint.* at .*" 
-    gdb_test "continue" "6: a_static = 46\\r\\n5: a_local = 45\\r\\n4: main_global = 44\\r\\n.*"
+    gdb_test "continue" [multi_line \
+                            "4: main_global = 44" \
+                            "5: a_local = 45" \
+                            "6: a_static = 46" \
+                           ]
 }}