extra, db: we have to record every function call in the db
[smatch.git] / gdbhelpers
blob86347863aea7c477fc60deff02631ed98e687b34
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_SIGNED)
111                 printf "MOD_SIGNED "
112         end
113         if ($arg0->modifiers & MOD_UNSIGNED)
114                 printf "MOD_UNSIGNED "
115         end
116         if ($arg0->modifiers & MOD_CHAR)
117                 printf "MOD_CHAR "
118         end
119         if ($arg0->modifiers & MOD_SHORT)
120                 printf "MOD_SHORT "
121         end
122         if ($arg0->modifiers & MOD_LONG)
123                 printf "MOD_LONG "
124         end
125         if ($arg0->modifiers & MOD_LONGLONG)
126                 printf "MOD_LONGLONG "
127         end
128         if ($arg0->modifiers & MOD_LONGLONGLONG)
129                 printf "MOD_LONGLONGLONG "
130         end
131         if ($arg0->modifiers & MOD_TYPEDEF)
132                 printf "MOD_TYPEDEF "
133         end
134         if ($arg0->modifiers & MOD_INLINE)
135                 printf "MOD_INLINE "
136         end
137         if ($arg0->modifiers & MOD_ADDRESSABLE)
138                 printf "MOD_ADDRESSABLE "
139         end
140         if ($arg0->modifiers & MOD_NOCAST)
141                 printf "MOD_NOCAST "
142         end
143         if ($arg0->modifiers & MOD_NODEREF)
144                 printf "MOD_NODEREF "
145         end
146         if ($arg0->modifiers & MOD_ACCESSED)
147                 printf "MOD_ACCESSED "
148         end
149         if ($arg0->modifiers & MOD_TOPLEVEL)
150                 printf "MOD_TOPLEVEL "
151         end
152         if ($arg0->modifiers & MOD_ASSIGNED)
153                 printf "MOD_ASSIGNED "
154         end
155         if ($arg0->modifiers & MOD_TYPE)
156                 printf "MOD_TYPE "
157         end
158         if ($arg0->modifiers & MOD_SAFE)
159                 printf "MOD_SAFE "
160         end
161         if ($arg0->modifiers & MOD_USERTYPE)
162                 printf "MOD_USERTYPE "
163         end
164         if ($arg0->modifiers & MOD_EXPLICITLY_SIGNED)
165                 printf "MOD_EXPLICITLY_SIGNED"
166         end
167         if ($arg0->modifiers & MOD_BITWISE)
168                 printf "MOD_BITWISE "
169         end
170         if (!$arg0->modifiers)
171                 printf "0"
172         end
174         printf ", alignment = %d", $arg0->alignment
175         if ($arg0->as)
176                 printf ", address_space = %d", $arg0->as
177         end
178         printf "\n"
181         set $ntabs++
182         if ($arg0->base_type)
183                 gdb_tabs
184                 printf "base_type = "
185                 gdb_show_symbol($arg0->base_type)
186         end
188         set $ntabs--
193 define gdb_show_symbol
194         printf "(%x) type = ", $arg0
195         output $arg0->type
196         printf ", namespace = "
197         output $arg0->namespace
198         if ($arg0->ident)
199                 printf ", ident = %s\n", show_ident($arg0->ident)
200         else
201                 printf ", ident = NULL\n"
202         end
204 #       print "zz"
206         gdb_tabs
207         printf "dump:\n"
208         call show_symbol($arg0)
210         set $ntabs++
211         if ($arg0->namespace == NS_SYMBOL)
212                 gdb_tabs
213                 printf "ctype = "
214                 gdb_show_ctype(&($arg0->ctype))
215         end
216         set $ntabs--
220 # non-recursive
221 define gdb_show_symbols_next_id
222         set $sym = $arg0
223         printf "{\n"
224         set $ntabs++
225         while ($sym)
226                 gdb_tabs
227                 printf "symbol = "
228                 gdb_show_symbol($sym)
229                 set $sym = $sym->next_id
230         end
231         set $ntabs--
232         gdb_tabs
233         printf "}\n"
236 define gdb_show_ident
237         if ($arg0)
238                 printf "(%p) '%s'\n", $arg0, show_ident($arg0)
239         else
240                 printf "NULL\n"
241         end
243         if (! $showing_ident)
244                 set $showing_ident = 1
245                 set $ntabs++
247                 set $ident = $arg0
249                 if ($ident->symbols)
250                         gdb_tabs
251                         printf "symbols = "
252                         gdb_show_symbols_next_id($ident->symbols)
253                 end
255                 set $ntabs--
256                 set $showing_ident = 0
257         end
260 define gdb_show_token
261         printf "%p: '%s', type = ", $arg0, show_token($arg0)
262         output (enum token_type) ($arg0)->pos.type
263         printf "\n"
265         if (! $showing_token)
266                 set $showing_token = 1
267                 set $ntabs++
269                 set $token = $arg0
271                 if ($token->pos.type == TOKEN_IDENT)
272                         gdb_tabs
273                         printf "ident = "
274                         gdb_show_ident $token.ident
275                 end
277                 if ($token->pos.type == TOKEN_MACRO_ARGUMENT)
278                         gdb_tabs
279                         printf "argnum = %d\n", $token->argnum
280                 end
282                 if ($token->pos.type == TOKEN_SPECIAL)
283                         gdb_tabs
284                         printf "special = \"%s\"\n", show_special($token.special)
285                 end
287                 set $ntabs--
288                 set $showing_token = 0
289         end
292 # non-recursive
293 define gdb_show_tokens
294         set $t = $arg0
295         printf "{\n"
296         set $ntabs++
297         while ($t != &eof_token_entry)
298                 gdb_tabs
299                 printf "token = "
300                 gdb_show_token($t)
301                 set $t = ($t)->next
302         end
303         set $ntabs--
304         gdb_tabs
305         printf "}\n"