]> Git Repo - binutils.git/blob - gdb/testsuite/gdb.python/py-nested-maps.c
Update copyright year range in all GDB files.
[binutils.git] / gdb / testsuite / gdb.python / py-nested-maps.c
1 /* This testcase is part of GDB, the GNU debugger.
2
3    Copyright 2019-2020 Free Software Foundation, Inc.
4
5    This program is free software; you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation; either version 3 of the License, or
8    (at your option) any later version.
9
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU General Public License for more details.
14
15    You should have received a copy of the GNU General Public License
16    along with this program.  If not, see  <http://www.gnu.org/licenses/>.  */
17
18 #include <stdlib.h>
19 #include <string.h>
20
21 #define FIXED_MAP_SIZE 10
22
23 struct key_t
24 {
25   int a;
26   int b;
27 };
28
29 struct value_t
30 {
31   int x;
32   int y;
33   int z;
34 };
35
36 struct map_t
37 {
38   const char *name;
39   int length;
40   struct key_t *keys;
41   struct value_t *values;
42
43   /* This field is used only by the pretty printer.  */
44   int show_header;
45 };
46
47 struct map_map_t
48 {
49   int length;
50   struct map_t **values;
51
52   /* This field is used only by the pretty printer.  */
53   int show_header;
54 };
55
56 struct map_t *
57 create_map (const char *name)
58 {
59   struct map_t *m = malloc (sizeof (struct map_t));
60   m->name = strdup (name);
61   m->length = 0;
62   m->keys = NULL;
63   m->values = NULL;
64   m->show_header = 0;
65 }
66
67 void
68 add_map_element (struct map_t *m, struct key_t k, struct value_t v)
69 {
70   if (m->length == 0)
71     {
72       m->keys = malloc (sizeof (struct key_t) * FIXED_MAP_SIZE);
73       m->values = malloc (sizeof (struct value_t) * FIXED_MAP_SIZE);
74     }
75
76   m->keys[m->length] = k;
77   m->values[m->length] = v;
78   m->length++;
79 }
80
81 struct map_map_t *
82 create_map_map (void)
83 {
84   struct map_map_t *mm = malloc (sizeof (struct map_map_t));
85   mm->length = 0;
86   mm->values = NULL;
87   mm->show_header = 0;
88 }
89
90 void
91 add_map_map_element (struct map_map_t *mm, struct map_t *map)
92 {
93   if (mm->length == 0)
94     mm->values = malloc (sizeof (struct map_t *) * FIXED_MAP_SIZE);
95
96   mm->values[mm->length] = map;
97   mm->length++;
98 }
99
100 int
101 main (void)
102 {
103   struct map_t *m1 = create_map ("m1");
104   struct key_t k1 = {3, 4};
105   struct key_t k2 = {4, 5};
106   struct key_t k3 = {5, 6};
107   struct key_t k4 = {6, 7};
108   struct key_t k5 = {7, 8};
109   struct key_t k6 = {8, 9};
110   struct value_t v1 = {0, 1, 2};
111   struct value_t v2 = {3, 4, 5};
112   struct value_t v3 = {6, 7, 8};
113   struct value_t v4 = {9, 0, 1};
114   struct value_t v5 = {2, 3, 4};
115   struct value_t v6 = {5, 6, 7};
116   add_map_element (m1, k1, v1);
117   add_map_element (m1, k2, v2);
118   add_map_element (m1, k3, v3);
119
120   struct map_t *m2 = create_map ("m2");
121   add_map_element (m2, k4, v4);
122   add_map_element (m2, k5, v5);
123   add_map_element (m2, k6, v6);
124
125   struct map_map_t *mm = create_map_map ();
126   add_map_map_element (mm, m1);
127   add_map_map_element (mm, m2);
128
129   return 0; /* Break here.  */
130 }
This page took 0.032036 seconds and 4 git commands to generate.