param_set: addresses can't be set
[smatch.git] / gdbhelpers
blob9488a6070be91346b2ce3bf544a103c22587b158
2 # Don't forget to rebuild sparse with uncommented debug options
3 # in the Makefile. Also, gcc 3 is known to screw up with the
4 # cpp macros in the debugging info.
7 # If a gdb_show_* function is running at a non-zero recursion
8 # level, only a short summary is shown, preventing further
9 # recursion. Also note that gdb has only one, global, scope
10 # for variables, so we need to be careful with recursions.
13 set $showing_token = 0
14 set $showing_ident = 0
15 set $showing_symbol = 0
17 set $ntabs = 0
19 define gdb_tabs
20         set $tmp = $ntabs
21         while ($tmp--)
22                 printf "\t"
23         end
24 end
27 # Ptr list handling
28 define ptr_entry
29         set $ptr = $arg0
30         set $index = $arg1
31         set $entry = &($arg2)
33         set *($entry) = (void *) (~3UL & (unsigned long)$ptr->list[$index])
34 end
37 # Ptr list looping skeleton
38 define gdb_ptr_list_for_each
40         set $my_head = (struct ptr_list *) $arg0
41         set $my_list = $my_head
44         if ($my_head)
45                 while (1)
46                         set $my_nr = 0
47                         while ($my_nr < $my_list->nr)
49                                 # Put your iterator code here
50                                 set $my_nr++
51                         end
53                         if (($my_list = $my_list->next) == $my_head)
54                                 loop_break
55                         end
56                 end
57         end
58 end
60 # Show symbols in a symbol_list. Non-recursive
61 define gdb_ptr_list_for_each_show_symbol
63         set $my_head = (struct ptr_list *) $arg0
64         set $my_list = $my_head
67         if ($my_head)
68                 while (1)
69                         set $my_nr = 0
70                         while ($my_nr < ($my_list)->nr)
71                                 set $my_symbol = (struct symbol *) ((~3UL) & (unsigned long)($my_list)->list[$my_nr])
72                                 gdb_show_symbol($my_symbol)
74                                 set $my_nr++
75                         end
77                         set $my_list = ($my_list)->next
78                         if ($my_list == $my_head)
79                                 loop_break
80                         end
81                 end
82         end
83 end
86 #define gdb_show_statement
89 # Recursive
90 define gdb_show_ctype
91         printf "modifiers: "
92         if ($arg0->modifiers & MOD_AUTO)
93                 printf "MOD_AUTO "
94         end
95         if ($arg0->modifiers & MOD_REGISTER)
96                 printf "MOD_REGISTER "
97         end
98         if ($arg0->modifiers & MOD_STATIC)
99                 printf "MOD_STATIC "
100         end
101         if ($arg0->modifiers & MOD_EXTERN)
102                 printf "MOD_EXTERN "
103         end
104         if ($arg0->modifiers & MOD_CONST)
105                 printf "MOD_CONST "
106         end
107         if ($arg0->modifiers & MOD_VOLATILE)
108                 printf "MOD_VOLATILE "
109         end
110         if ($arg0->modifiers & MOD_RESTRICT)
111                 printf "MOD_RESTRICT "
112         end
113         if ($arg0->modifiers & MOD_ATOMIC)
114                 printf "MOD_ATOMIC "
115         end
116         if ($arg0->modifiers & MOD_SIGNED)
117                 printf "MOD_SIGNED "
118         end
119         if ($arg0->modifiers & MOD_UNSIGNED)
120                 printf "MOD_UNSIGNED "
121         end
122         if ($arg0->modifiers & MOD_INLINE)
123                 printf "MOD_INLINE "
124         end
125         if ($arg0->modifiers & MOD_ADDRESSABLE)
126                 printf "MOD_ADDRESSABLE "
127         end
128         if ($arg0->modifiers & MOD_NOCAST)
129                 printf "MOD_NOCAST "
130         end
131         if ($arg0->modifiers & MOD_NODEREF)
132                 printf "MOD_NODEREF "
133         end
134         if ($arg0->modifiers & MOD_TOPLEVEL)
135                 printf "MOD_TOPLEVEL "
136         end
137         if ($arg0->modifiers & MOD_ASSIGNED)
138                 printf "MOD_ASSIGNED "
139         end
140         if ($arg0->modifiers & MOD_SAFE)
141                 printf "MOD_SAFE "
142         end
143         if ($arg0->modifiers & MOD_USERTYPE)
144                 printf "MOD_USERTYPE "
145         end
146         if ($arg0->modifiers & MOD_EXPLICITLY_SIGNED)
147                 printf "MOD_EXPLICITLY_SIGNED"
148         end
149         if ($arg0->modifiers & MOD_BITWISE)
150                 printf "MOD_BITWISE "
151         end
152         if (!$arg0->modifiers)
153                 printf "0"
154         end
156         printf ", alignment = %d", $arg0->alignment
157         if ($arg0->as)
158                 printf ", address_space = %d", $arg0->as
159         end
160         printf "\n"
163         set $ntabs++
164         if ($arg0->base_type)
165                 gdb_tabs
166                 printf "base_type = "
167                 gdb_show_symbol($arg0->base_type)
168         end
170         set $ntabs--
175 define gdb_show_symbol
176         printf "(%x) type = ", $arg0
177         output $arg0->type
178         printf ", namespace = "
179         output $arg0->namespace
180         if ($arg0->ident)
181                 printf ", ident = %s\n", show_ident($arg0->ident)
182         else
183                 printf ", ident = NULL\n"
184         end
186 #       print "zz"
188         gdb_tabs
189         printf "dump:\n"
190         call show_symbol($arg0)
192         set $ntabs++
193         if ($arg0->namespace == NS_SYMBOL)
194                 gdb_tabs
195                 printf "ctype = "
196                 gdb_show_ctype(&($arg0->ctype))
197         end
198         set $ntabs--
202 # non-recursive
203 define gdb_show_symbols_next_id
204         set $sym = $arg0
205         printf "{\n"
206         set $ntabs++
207         while ($sym)
208                 gdb_tabs
209                 printf "symbol = "
210                 gdb_show_symbol($sym)
211                 set $sym = $sym->next_id
212         end
213         set $ntabs--
214         gdb_tabs
215         printf "}\n"
218 define gdb_show_ident
219         if ($arg0)
220                 printf "(%p) '%s'\n", $arg0, show_ident($arg0)
221         else
222                 printf "NULL\n"
223         end
225         if (! $showing_ident)
226                 set $showing_ident = 1
227                 set $ntabs++
229                 set $ident = $arg0
231                 if ($ident->symbols)
232                         gdb_tabs
233                         printf "symbols = "
234                         gdb_show_symbols_next_id($ident->symbols)
235                 end
237                 set $ntabs--
238                 set $showing_ident = 0
239         end
242 define gdb_show_token
243         printf "%p: '%s', type = ", $arg0, show_token($arg0)
244         output (enum token_type) ($arg0)->pos.type
245         printf "\n"
247         if (! $showing_token)
248                 set $showing_token = 1
249                 set $ntabs++
251                 set $token = $arg0
253                 if ($token->pos.type == TOKEN_IDENT)
254                         gdb_tabs
255                         printf "ident = "
256                         gdb_show_ident $token.ident
257                 end
259                 if ($token->pos.type == TOKEN_MACRO_ARGUMENT)
260                         gdb_tabs
261                         printf "argnum = %d\n", $token->argnum
262                 end
264                 if ($token->pos.type == TOKEN_SPECIAL)
265                         gdb_tabs
266                         printf "special = \"%s\"\n", show_special($token.special)
267                 end
269                 set $ntabs--
270                 set $showing_token = 0
271         end
274 # non-recursive
275 define gdb_show_tokens
276         set $t = $arg0
277         printf "{\n"
278         set $ntabs++
279         while ($t != &eof_token_entry)
280                 gdb_tabs
281                 printf "token = "
282                 gdb_show_token($t)
283                 set $t = ($t)->next
284         end
285         set $ntabs--
286         gdb_tabs
287         printf "}\n"