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