MI: Allow non-raw varobj evaluation
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.python / py-prettyprint.c
index e1f696ff72343785b4aedba951e9f6ab50a641b0..35ef5e0756b182c56145bd11961046407f22dede 100644 (file)
@@ -1,6 +1,6 @@
 /* This testcase is part of GDB, the GNU debugger.
 
-   Copyright 2008, 2009, 2010 Free Software Foundation, Inc.
+   Copyright 2008-2018 Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -29,6 +29,12 @@ struct ss
   struct s b;
 };
 
+struct arraystruct
+{
+  int y;
+  struct s x[2];
+};
+
 struct ns {
   const char *null_str;
   int length;
@@ -36,6 +42,16 @@ struct ns {
 
 struct lazystring {
   const char *lazy_str;
+  /* If -1, don't pass length to gdb.lazy_string().  */
+  int len;
+};
+
+struct hint_error {
+  int x;
+};
+
+struct children_as_list {
+  int x;
 };
 
 #ifdef __cplusplus
@@ -84,8 +100,28 @@ class Derived : public Vbase1, public Vbase2, public Vbase3
     }
 };
 
+class Fake
+{
+  int sname;
+  
+ public:
+  Fake (const int name = 0):
+  sname (name)
+  {
+  }
+};
 #endif
 
+struct to_string_returns_value_inner
+{
+  int val;
+};
+
+struct to_string_returns_value_wrapper
+{
+  struct to_string_returns_value_inner inner;
+};
+
 struct substruct {
   int a;
   int b;
@@ -119,6 +155,20 @@ typedef struct string_repr
 
 /* This lets us avoid malloc.  */
 int array[100];
+int narray[10];
+
+struct justchildren
+{
+  int len;
+  int *elements;
+};
+
+typedef struct justchildren nostring_type;
+
+struct memory_error
+{
+  const char *s;
+};
 
 struct container
 {
@@ -158,6 +208,13 @@ add_item (zzz_type *c, int val)
   ++c->len;
 }
 
+void
+set_item(zzz_type *c, int i, int val)
+{
+  if (i < c->len)
+    c->elements[i] = val;
+}
+
 void init_s(struct s *s, int a)
 {
   s->a = a;
@@ -185,30 +242,90 @@ struct nullstr
 struct string_repr string_1 = { { "one" } };
 struct string_repr string_2 = { { "two" } };
 
+int
+eval_func (int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8)
+{
+  return p1;
+}
+
+static void
+eval_sub (void)
+{
+  struct eval_type_s { int x; } eval1 = { 1 }, eval2 = { 2 }, eval3 = { 3 },
+                               eval4 = { 4 }, eval5 = { 5 }, eval6 = { 6 },
+                               eval7 = { 7 }, eval8 = { 8 }, eval9 = { 9 };
+
+  eval1.x++; /* eval-break */
+}
+
+static void
+bug_14741()
+{
+  zzz_type c = make_container ("bug_14741");
+  add_item (&c, 71);
+  set_item(&c, 0, 42); /* breakpoint bug 14741 */
+  set_item(&c, 0, 5);
+}
+
+/* Some typedefs/variables for checking that GDB doesn't lose typedefs
+   when looking for a printer.  */
+typedef int int_type;
+typedef int_type int_type2;
+
+int an_int = -1;
+int_type an_int_type = 1;
+int_type2 an_int_type2 = 2;
+
 int
 main ()
 {
   struct ss  ss;
   struct ss  ssa[2];
+  struct arraystruct arraystruct;
   string x = make_string ("this is x");
   zzz_type c = make_container ("container");
   zzz_type c2 = make_container ("container2");
   const struct string_repr cstring = { { "const string" } };
   /* Clearing by being `static' could invoke an other GDB C++ bug.  */
   struct nullstr nullstr;
+  nostring_type nstype, nstype2;
+  struct memory_error me;
+  struct ns ns, ns2;
+  struct lazystring estring, estring2, estring3;
+  struct hint_error hint_error;
+  struct children_as_list children_as_list;
+  struct to_string_returns_value_wrapper tsrvw = { { 1989 } };
+
+  nstype.elements = narray;
+  nstype.len = 0;
 
+  me.s = "blah";
 
   init_ss(&ss, 1, 2);
   init_ss(ssa+0, 3, 4);
   init_ss(ssa+1, 5, 6);
   memset (&nullstr, 0, sizeof nullstr);
 
-  struct ns  ns;
+  arraystruct.y = 7;
+  init_s (&arraystruct.x[0], 23);
+  init_s (&arraystruct.x[1], 24);
+
   ns.null_str = "embedded\0null\0string";
   ns.length = 20;
 
-  struct lazystring estring;
-  estring.lazy_str = "embedded x\201\202\203\204" ;
+  /* Make a "corrupted" string.  */
+  ns2.null_str = NULL;
+  ns2.length = 20;
+
+  estring.lazy_str = "embedded x\201\202\203\204";
+  estring.len = -1;
+
+  /* Incomplete UTF-8, but ok Latin-1.  */
+  estring2.lazy_str = "embedded x\302";
+  estring2.len = -1;
+
+  estring3.lazy_str = NULL;
+  estring3.len = 42;
 
 #ifdef __cplusplus
   S cps;
@@ -232,6 +349,7 @@ main ()
 
   Derived derived;
   
+  Fake fake (42);
 #endif
 
   add_item (&c, 23);           /* MI breakpoint here */
@@ -249,5 +367,14 @@ main ()
   do_nothing ();
 #endif
 
-  return 0;      /* break to inspect struct and union */
+  nstype.elements[0] = 7;
+  nstype.elements[1] = 42;
+  nstype.len = 2;
+  
+  nstype2 = nstype;
+
+  eval_sub ();
+
+  bug_14741();      /* break to inspect struct and union */
+  return 0;
 }
This page took 0.032124 seconds and 4 git commands to generate.