Home | History | Annotate | Line # | Download | only in guile
scm-symtab.c revision 1.4.4.1
      1 /* Scheme interface to symbol tables.
      2 
      3    Copyright (C) 2008-2017 Free Software Foundation, Inc.
      4 
      5    This file is part of GDB.
      6 
      7    This program is free software; you can redistribute it and/or modify
      8    it under the terms of the GNU General Public License as published by
      9    the Free Software Foundation; either version 3 of the License, or
     10    (at your option) any later version.
     11 
     12    This program is distributed in the hope that it will be useful,
     13    but WITHOUT ANY WARRANTY; without even the implied warranty of
     14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15    GNU General Public License for more details.
     16 
     17    You should have received a copy of the GNU General Public License
     18    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
     19 
     20 /* See README file in this directory for implementation notes, coding
     21    conventions, et.al.  */
     22 
     23 #include "defs.h"
     24 #include "symtab.h"
     25 #include "source.h"
     26 #include "objfiles.h"
     27 #include "block.h"
     28 #include "guile-internal.h"
     29 
     30 /* A <gdb:symtab> smob.  */
     31 
     32 typedef struct
     33 {
     34   /* This always appears first.
     35      eqable_gdb_smob is used so that symtabs are eq?-able.
     36      Also, a symtab object is associated with an objfile.  eqable_gdb_smob
     37      lets us track the lifetime of all symtabs associated with an objfile.
     38      When an objfile is deleted we need to invalidate the symtab object.  */
     39   eqable_gdb_smob base;
     40 
     41   /* The GDB symbol table structure.
     42      If this is NULL the symtab is invalid.  This can happen when the
     43      underlying objfile is freed.  */
     44   struct symtab *symtab;
     45 } symtab_smob;
     46 
     47 /* A <gdb:sal> smob.
     48    A smob describing a gdb symtab-and-line object.
     49    A sal is associated with an objfile.  All access must be gated by checking
     50    the validity of symtab_scm.
     51    TODO: Sals are not eq?-able at the moment, or even comparable.  */
     52 
     53 typedef struct
     54 {
     55   /* This always appears first.  */
     56   gdb_smob base;
     57 
     58   /* The <gdb:symtab> object of the symtab.
     59      We store this instead of a pointer to the symtab_smob because it's not
     60      clear GC will know the symtab_smob is referenced by us otherwise, and we
     61      need quick access to symtab_smob->symtab to know if this sal is valid.  */
     62   SCM symtab_scm;
     63 
     64   /* The GDB symbol table and line structure.
     65      This object is ephemeral in GDB, so keep our own copy.
     66      The symtab pointer in this struct is not usable: If the symtab is deleted
     67      this pointer will not be updated.  Use symtab_scm instead to determine
     68      if this sal is valid.  */
     69   struct symtab_and_line sal;
     70 } sal_smob;
     71 
     72 static const char symtab_smob_name[] = "gdb:symtab";
     73 /* "symtab-and-line" is pretty long, and "sal" is short and unique.  */
     74 static const char sal_smob_name[] = "gdb:sal";
     75 
     76 /* The tags Guile knows the symbol table smobs by.  */
     77 static scm_t_bits symtab_smob_tag;
     78 static scm_t_bits sal_smob_tag;
     79 
     80 static const struct objfile_data *stscm_objfile_data_key;
     81 
     82 /* Administrivia for symtab smobs.  */
     84 
     85 /* Helper function to hash a symbol_smob.  */
     86 
     87 static hashval_t
     88 stscm_hash_symtab_smob (const void *p)
     89 {
     90   const symtab_smob *st_smob = (const symtab_smob *) p;
     91 
     92   return htab_hash_pointer (st_smob->symtab);
     93 }
     94 
     95 /* Helper function to compute equality of symtab_smobs.  */
     96 
     97 static int
     98 stscm_eq_symtab_smob (const void *ap, const void *bp)
     99 {
    100   const symtab_smob *a = (const symtab_smob *) ap;
    101   const symtab_smob *b = (const symtab_smob *) bp;
    102 
    103   return (a->symtab == b->symtab
    104 	  && a->symtab != NULL);
    105 }
    106 
    107 /* Return the struct symtab pointer -> SCM mapping table.
    108    It is created if necessary.  */
    109 
    110 static htab_t
    111 stscm_objfile_symtab_map (struct symtab *symtab)
    112 {
    113   struct objfile *objfile = SYMTAB_OBJFILE (symtab);
    114   htab_t htab = (htab_t) objfile_data (objfile, stscm_objfile_data_key);
    115 
    116   if (htab == NULL)
    117     {
    118       htab = gdbscm_create_eqable_gsmob_ptr_map (stscm_hash_symtab_smob,
    119 						 stscm_eq_symtab_smob);
    120       set_objfile_data (objfile, stscm_objfile_data_key, htab);
    121     }
    122 
    123   return htab;
    124 }
    125 
    126 /* The smob "free" function for <gdb:symtab>.  */
    127 
    128 static size_t
    129 stscm_free_symtab_smob (SCM self)
    130 {
    131   symtab_smob *st_smob = (symtab_smob *) SCM_SMOB_DATA (self);
    132 
    133   if (st_smob->symtab != NULL)
    134     {
    135       htab_t htab = stscm_objfile_symtab_map (st_smob->symtab);
    136 
    137       gdbscm_clear_eqable_gsmob_ptr_slot (htab, &st_smob->base);
    138     }
    139 
    140   /* Not necessary, done to catch bugs.  */
    141   st_smob->symtab = NULL;
    142 
    143   return 0;
    144 }
    145 
    146 /* The smob "print" function for <gdb:symtab>.  */
    147 
    148 static int
    149 stscm_print_symtab_smob (SCM self, SCM port, scm_print_state *pstate)
    150 {
    151   symtab_smob *st_smob = (symtab_smob *) SCM_SMOB_DATA (self);
    152 
    153   gdbscm_printf (port, "#<%s ", symtab_smob_name);
    154   gdbscm_printf (port, "%s",
    155 		 st_smob->symtab != NULL
    156 		 ? symtab_to_filename_for_display (st_smob->symtab)
    157 		 : "<invalid>");
    158   scm_puts (">", port);
    159 
    160   scm_remember_upto_here_1 (self);
    161 
    162   /* Non-zero means success.  */
    163   return 1;
    164 }
    165 
    166 /* Low level routine to create a <gdb:symtab> object.  */
    167 
    168 static SCM
    169 stscm_make_symtab_smob (void)
    170 {
    171   symtab_smob *st_smob = (symtab_smob *)
    172     scm_gc_malloc (sizeof (symtab_smob), symtab_smob_name);
    173   SCM st_scm;
    174 
    175   st_smob->symtab = NULL;
    176   st_scm = scm_new_smob (symtab_smob_tag, (scm_t_bits) st_smob);
    177   gdbscm_init_eqable_gsmob (&st_smob->base, st_scm);
    178 
    179   return st_scm;
    180 }
    181 
    182 /* Return non-zero if SCM is a symbol table smob.  */
    183 
    184 static int
    185 stscm_is_symtab (SCM scm)
    186 {
    187   return SCM_SMOB_PREDICATE (symtab_smob_tag, scm);
    188 }
    189 
    190 /* (symtab? object) -> boolean */
    191 
    192 static SCM
    193 gdbscm_symtab_p (SCM scm)
    194 {
    195   return scm_from_bool (stscm_is_symtab (scm));
    196 }
    197 
    198 /* Create a new <gdb:symtab> object that encapsulates SYMTAB.  */
    199 
    200 SCM
    201 stscm_scm_from_symtab (struct symtab *symtab)
    202 {
    203   htab_t htab;
    204   eqable_gdb_smob **slot;
    205   symtab_smob *st_smob, st_smob_for_lookup;
    206   SCM st_scm;
    207 
    208   /* If we've already created a gsmob for this symtab, return it.
    209      This makes symtabs eq?-able.  */
    210   htab = stscm_objfile_symtab_map (symtab);
    211   st_smob_for_lookup.symtab = symtab;
    212   slot = gdbscm_find_eqable_gsmob_ptr_slot (htab, &st_smob_for_lookup.base);
    213   if (*slot != NULL)
    214     return (*slot)->containing_scm;
    215 
    216   st_scm = stscm_make_symtab_smob ();
    217   st_smob = (symtab_smob *) SCM_SMOB_DATA (st_scm);
    218   st_smob->symtab = symtab;
    219   gdbscm_fill_eqable_gsmob_ptr_slot (slot, &st_smob->base);
    220 
    221   return st_scm;
    222 }
    223 
    224 /* Returns the <gdb:symtab> object in SELF.
    225    Throws an exception if SELF is not a <gdb:symtab> object.  */
    226 
    227 static SCM
    228 stscm_get_symtab_arg_unsafe (SCM self, int arg_pos, const char *func_name)
    229 {
    230   SCM_ASSERT_TYPE (stscm_is_symtab (self), self, arg_pos, func_name,
    231 		   symtab_smob_name);
    232 
    233   return self;
    234 }
    235 
    236 /* Returns a pointer to the symtab smob of SELF.
    237    Throws an exception if SELF is not a <gdb:symtab> object.  */
    238 
    239 static symtab_smob *
    240 stscm_get_symtab_smob_arg_unsafe (SCM self, int arg_pos, const char *func_name)
    241 {
    242   SCM st_scm = stscm_get_symtab_arg_unsafe (self, arg_pos, func_name);
    243   symtab_smob *st_smob = (symtab_smob *) SCM_SMOB_DATA (st_scm);
    244 
    245   return st_smob;
    246 }
    247 
    248 /* Return non-zero if symtab ST_SMOB is valid.  */
    249 
    250 static int
    251 stscm_is_valid (symtab_smob *st_smob)
    252 {
    253   return st_smob->symtab != NULL;
    254 }
    255 
    256 /* Throw a Scheme error if SELF is not a valid symtab smob.
    257    Otherwise return a pointer to the symtab_smob object.  */
    258 
    259 static symtab_smob *
    260 stscm_get_valid_symtab_smob_arg_unsafe (SCM self, int arg_pos,
    261 					const char *func_name)
    262 {
    263   symtab_smob *st_smob
    264     = stscm_get_symtab_smob_arg_unsafe (self, arg_pos, func_name);
    265 
    266   if (!stscm_is_valid (st_smob))
    267     {
    268       gdbscm_invalid_object_error (func_name, arg_pos, self,
    269 				   _("<gdb:symtab>"));
    270     }
    271 
    272   return st_smob;
    273 }
    274 
    275 /* Helper function for stscm_del_objfile_symtabs to mark the symtab
    276    as invalid.  */
    277 
    278 static int
    279 stscm_mark_symtab_invalid (void **slot, void *info)
    280 {
    281   symtab_smob *st_smob = (symtab_smob *) *slot;
    282 
    283   st_smob->symtab = NULL;
    284   return 1;
    285 }
    286 
    287 /* This function is called when an objfile is about to be freed.
    288    Invalidate the symbol table as further actions on the symbol table
    289    would result in bad data.  All access to st_smob->symtab should be
    290    gated by stscm_get_valid_symtab_smob_arg_unsafe which will raise an
    291    exception on invalid symbol tables.  */
    292 
    293 static void
    294 stscm_del_objfile_symtabs (struct objfile *objfile, void *datum)
    295 {
    296   htab_t htab = (htab_t) datum;
    297 
    298   if (htab != NULL)
    299     {
    300       htab_traverse_noresize (htab, stscm_mark_symtab_invalid, NULL);
    301       htab_delete (htab);
    302     }
    303 }
    304 
    305 /* Symbol table methods.  */
    307 
    308 /* (symtab-valid? <gdb:symtab>) -> boolean
    309    Returns #t if SELF still exists in GDB.  */
    310 
    311 static SCM
    312 gdbscm_symtab_valid_p (SCM self)
    313 {
    314   symtab_smob *st_smob
    315     = stscm_get_symtab_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
    316 
    317   return scm_from_bool (stscm_is_valid (st_smob));
    318 }
    319 
    320 /* (symtab-filename <gdb:symtab>) -> string */
    321 
    322 static SCM
    323 gdbscm_symtab_filename (SCM self)
    324 {
    325   symtab_smob *st_smob
    326     = stscm_get_valid_symtab_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
    327   struct symtab *symtab = st_smob->symtab;
    328 
    329   return gdbscm_scm_from_c_string (symtab_to_filename_for_display (symtab));
    330 }
    331 
    332 /* (symtab-fullname <gdb:symtab>) -> string */
    333 
    334 static SCM
    335 gdbscm_symtab_fullname (SCM self)
    336 {
    337   symtab_smob *st_smob
    338     = stscm_get_valid_symtab_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
    339   struct symtab *symtab = st_smob->symtab;
    340 
    341   return gdbscm_scm_from_c_string (symtab_to_fullname (symtab));
    342 }
    343 
    344 /* (symtab-objfile <gdb:symtab>) -> <gdb:objfile> */
    345 
    346 static SCM
    347 gdbscm_symtab_objfile (SCM self)
    348 {
    349   symtab_smob *st_smob
    350     = stscm_get_valid_symtab_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
    351   const struct symtab *symtab = st_smob->symtab;
    352 
    353   return ofscm_scm_from_objfile (SYMTAB_OBJFILE (symtab));
    354 }
    355 
    356 /* (symtab-global-block <gdb:symtab>) -> <gdb:block>
    357    Return the GLOBAL_BLOCK of the underlying symtab.  */
    358 
    359 static SCM
    360 gdbscm_symtab_global_block (SCM self)
    361 {
    362   symtab_smob *st_smob
    363     = stscm_get_valid_symtab_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
    364   const struct symtab *symtab = st_smob->symtab;
    365   const struct blockvector *blockvector;
    366   const struct block *block;
    367 
    368   blockvector = SYMTAB_BLOCKVECTOR (symtab);
    369   block = BLOCKVECTOR_BLOCK (blockvector, GLOBAL_BLOCK);
    370 
    371   return bkscm_scm_from_block (block, SYMTAB_OBJFILE (symtab));
    372 }
    373 
    374 /* (symtab-static-block <gdb:symtab>) -> <gdb:block>
    375    Return the STATIC_BLOCK of the underlying symtab.  */
    376 
    377 static SCM
    378 gdbscm_symtab_static_block (SCM self)
    379 {
    380   symtab_smob *st_smob
    381     = stscm_get_valid_symtab_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
    382   const struct symtab *symtab = st_smob->symtab;
    383   const struct blockvector *blockvector;
    384   const struct block *block;
    385 
    386   blockvector = SYMTAB_BLOCKVECTOR (symtab);
    387   block = BLOCKVECTOR_BLOCK (blockvector, STATIC_BLOCK);
    388 
    389   return bkscm_scm_from_block (block, SYMTAB_OBJFILE (symtab));
    390 }
    391 
    392 /* Administrivia for sal (symtab-and-line) smobs.  */
    394 
    395 /* The smob "print" function for <gdb:sal>.  */
    396 
    397 static int
    398 stscm_print_sal_smob (SCM self, SCM port, scm_print_state *pstate)
    399 {
    400   sal_smob *s_smob = (sal_smob *) SCM_SMOB_DATA (self);
    401   symtab_smob *st_smob = (symtab_smob *) SCM_SMOB_DATA (s_smob->symtab_scm);
    402 
    403   gdbscm_printf (port, "#<%s ", symtab_smob_name);
    404   scm_write (s_smob->symtab_scm, port);
    405   if (s_smob->sal.line != 0)
    406     gdbscm_printf (port, " line %d", s_smob->sal.line);
    407   scm_puts (">", port);
    408 
    409   scm_remember_upto_here_1 (self);
    410 
    411   /* Non-zero means success.  */
    412   return 1;
    413 }
    414 
    415 /* Low level routine to create a <gdb:sal> object.  */
    416 
    417 static SCM
    418 stscm_make_sal_smob (void)
    419 {
    420   sal_smob *s_smob
    421     = (sal_smob *) scm_gc_malloc (sizeof (sal_smob), sal_smob_name);
    422   SCM s_scm;
    423 
    424   s_smob->symtab_scm = SCM_BOOL_F;
    425   memset (&s_smob->sal, 0, sizeof (s_smob->sal));
    426   s_scm = scm_new_smob (sal_smob_tag, (scm_t_bits) s_smob);
    427   gdbscm_init_gsmob (&s_smob->base);
    428 
    429   return s_scm;
    430 }
    431 
    432 /* Return non-zero if SCM is a <gdb:sal> object.  */
    433 
    434 static int
    435 stscm_is_sal (SCM scm)
    436 {
    437   return SCM_SMOB_PREDICATE (sal_smob_tag, scm);
    438 }
    439 
    440 /* (sal? object) -> boolean */
    441 
    442 static SCM
    443 gdbscm_sal_p (SCM scm)
    444 {
    445   return scm_from_bool (stscm_is_sal (scm));
    446 }
    447 
    448 /* Create a new <gdb:sal> object that encapsulates SAL.  */
    449 
    450 SCM
    451 stscm_scm_from_sal (struct symtab_and_line sal)
    452 {
    453   SCM st_scm, s_scm;
    454   sal_smob *s_smob;
    455 
    456   st_scm = SCM_BOOL_F;
    457   if (sal.symtab != NULL)
    458     st_scm = stscm_scm_from_symtab (sal.symtab);
    459 
    460   s_scm = stscm_make_sal_smob ();
    461   s_smob = (sal_smob *) SCM_SMOB_DATA (s_scm);
    462   s_smob->symtab_scm = st_scm;
    463   s_smob->sal = sal;
    464 
    465   return s_scm;
    466 }
    467 
    468 /* Returns the <gdb:sal> object in SELF.
    469    Throws an exception if SELF is not a <gdb:sal> object.  */
    470 
    471 static SCM
    472 stscm_get_sal_arg (SCM self, int arg_pos, const char *func_name)
    473 {
    474   SCM_ASSERT_TYPE (stscm_is_sal (self), self, arg_pos, func_name,
    475 		   sal_smob_name);
    476 
    477   return self;
    478 }
    479 
    480 /* Returns a pointer to the sal smob of SELF.
    481    Throws an exception if SELF is not a <gdb:sal> object.  */
    482 
    483 static sal_smob *
    484 stscm_get_sal_smob_arg (SCM self, int arg_pos, const char *func_name)
    485 {
    486   SCM s_scm = stscm_get_sal_arg (self, arg_pos, func_name);
    487   sal_smob *s_smob = (sal_smob *) SCM_SMOB_DATA (s_scm);
    488 
    489   return s_smob;
    490 }
    491 
    492 /* Return non-zero if the symtab in S_SMOB is valid.  */
    493 
    494 static int
    495 stscm_sal_is_valid (sal_smob *s_smob)
    496 {
    497   symtab_smob *st_smob;
    498 
    499   /* If there's no symtab that's ok, the sal is still valid.  */
    500   if (gdbscm_is_false (s_smob->symtab_scm))
    501     return 1;
    502 
    503   st_smob = (symtab_smob *) SCM_SMOB_DATA (s_smob->symtab_scm);
    504 
    505   return st_smob->symtab != NULL;
    506 }
    507 
    508 /* Throw a Scheme error if SELF is not a valid sal smob.
    509    Otherwise return a pointer to the sal_smob object.  */
    510 
    511 static sal_smob *
    512 stscm_get_valid_sal_smob_arg (SCM self, int arg_pos, const char *func_name)
    513 {
    514   sal_smob *s_smob = stscm_get_sal_smob_arg (self, arg_pos, func_name);
    515 
    516   if (!stscm_sal_is_valid (s_smob))
    517     {
    518       gdbscm_invalid_object_error (func_name, arg_pos, self,
    519 				   _("<gdb:sal>"));
    520     }
    521 
    522   return s_smob;
    523 }
    524 
    525 /* sal methods */
    527 
    528 /* (sal-valid? <gdb:sal>) -> boolean
    529    Returns #t if the symtab for SELF still exists in GDB.  */
    530 
    531 static SCM
    532 gdbscm_sal_valid_p (SCM self)
    533 {
    534   sal_smob *s_smob = stscm_get_sal_smob_arg (self, SCM_ARG1, FUNC_NAME);
    535 
    536   return scm_from_bool (stscm_sal_is_valid (s_smob));
    537 }
    538 
    539 /* (sal-pc <gdb:sal>) -> address */
    540 
    541 static SCM
    542 gdbscm_sal_pc (SCM self)
    543 {
    544   sal_smob *s_smob = stscm_get_valid_sal_smob_arg (self, SCM_ARG1, FUNC_NAME);
    545   const struct symtab_and_line *sal = &s_smob->sal;
    546 
    547   return gdbscm_scm_from_ulongest (sal->pc);
    548 }
    549 
    550 /* (sal-last <gdb:sal>) -> address
    551    Returns #f if no ending address is recorded.  */
    552 
    553 static SCM
    554 gdbscm_sal_last (SCM self)
    555 {
    556   sal_smob *s_smob = stscm_get_valid_sal_smob_arg (self, SCM_ARG1, FUNC_NAME);
    557   const struct symtab_and_line *sal = &s_smob->sal;
    558 
    559   if (sal->end > 0)
    560     return gdbscm_scm_from_ulongest (sal->end - 1);
    561   return SCM_BOOL_F;
    562 }
    563 
    564 /* (sal-line <gdb:sal>) -> integer
    565    Returns #f if no line number is recorded.  */
    566 
    567 static SCM
    568 gdbscm_sal_line (SCM self)
    569 {
    570   sal_smob *s_smob = stscm_get_valid_sal_smob_arg (self, SCM_ARG1, FUNC_NAME);
    571   const struct symtab_and_line *sal = &s_smob->sal;
    572 
    573   if (sal->line > 0)
    574     return scm_from_int (sal->line);
    575   return SCM_BOOL_F;
    576 }
    577 
    578 /* (sal-symtab <gdb:sal>) -> <gdb:symtab>
    579    Returns #f if no symtab is recorded.  */
    580 
    581 static SCM
    582 gdbscm_sal_symtab (SCM self)
    583 {
    584   sal_smob *s_smob = stscm_get_valid_sal_smob_arg (self, SCM_ARG1, FUNC_NAME);
    585   const struct symtab_and_line *sal = &s_smob->sal;
    586 
    587   return s_smob->symtab_scm;
    588 }
    589 
    590 /* (find-pc-line address) -> <gdb:sal> */
    591 
    592 static SCM
    593 gdbscm_find_pc_line (SCM pc_scm)
    594 {
    595   ULONGEST pc_ull;
    596   struct symtab_and_line sal;
    597 
    598   init_sal (&sal); /* -Wall */
    599 
    600   gdbscm_parse_function_args (FUNC_NAME, SCM_ARG1, NULL, "U", pc_scm, &pc_ull);
    601 
    602   TRY
    603     {
    604       CORE_ADDR pc = (CORE_ADDR) pc_ull;
    605 
    606       sal = find_pc_line (pc, 0);
    607     }
    608   CATCH (except, RETURN_MASK_ALL)
    609     {
    610       GDBSCM_HANDLE_GDB_EXCEPTION (except);
    611     }
    612   END_CATCH
    613 
    614   return stscm_scm_from_sal (sal);
    615 }
    616 
    617 /* Initialize the Scheme symbol support.  */
    619 
    620 static const scheme_function symtab_functions[] =
    621 {
    622   { "symtab?", 1, 0, 0, as_a_scm_t_subr (gdbscm_symtab_p),
    623     "\
    624 Return #t if the object is a <gdb:symtab> object." },
    625 
    626   { "symtab-valid?", 1, 0, 0, as_a_scm_t_subr (gdbscm_symtab_valid_p),
    627     "\
    628 Return #t if the symtab still exists in GDB.\n\
    629 Symtabs are deleted when the corresponding objfile is freed." },
    630 
    631   { "symtab-filename", 1, 0, 0, as_a_scm_t_subr (gdbscm_symtab_filename),
    632     "\
    633 Return the symtab's source file name." },
    634 
    635   { "symtab-fullname", 1, 0, 0, as_a_scm_t_subr (gdbscm_symtab_fullname),
    636     "\
    637 Return the symtab's full source file name." },
    638 
    639   { "symtab-objfile", 1, 0, 0, as_a_scm_t_subr (gdbscm_symtab_objfile),
    640     "\
    641 Return the symtab's objfile." },
    642 
    643   { "symtab-global-block", 1, 0, 0,
    644     as_a_scm_t_subr (gdbscm_symtab_global_block),
    645     "\
    646 Return the symtab's global block." },
    647 
    648   { "symtab-static-block", 1, 0, 0,
    649     as_a_scm_t_subr (gdbscm_symtab_static_block),
    650     "\
    651 Return the symtab's static block." },
    652 
    653   { "sal?", 1, 0, 0, as_a_scm_t_subr (gdbscm_sal_p),
    654     "\
    655 Return #t if the object is a <gdb:sal> (symtab-and-line) object." },
    656 
    657   { "sal-valid?", 1, 0, 0, as_a_scm_t_subr (gdbscm_sal_valid_p),
    658     "\
    659 Return #t if the symtab for the sal still exists in GDB.\n\
    660 Symtabs are deleted when the corresponding objfile is freed." },
    661 
    662   { "sal-symtab", 1, 0, 0, as_a_scm_t_subr (gdbscm_sal_symtab),
    663     "\
    664 Return the sal's symtab." },
    665 
    666   { "sal-line", 1, 0, 0, as_a_scm_t_subr (gdbscm_sal_line),
    667     "\
    668 Return the sal's line number, or #f if there is none." },
    669 
    670   { "sal-pc", 1, 0, 0, as_a_scm_t_subr (gdbscm_sal_pc),
    671     "\
    672 Return the sal's address." },
    673 
    674   { "sal-last", 1, 0, 0, as_a_scm_t_subr (gdbscm_sal_last),
    675     "\
    676 Return the last address specified by the sal, or #f if there is none." },
    677 
    678   { "find-pc-line", 1, 0, 0, as_a_scm_t_subr (gdbscm_find_pc_line),
    679     "\
    680 Return the sal corresponding to the address, or #f if there isn't one.\n\
    681 \n\
    682   Arguments: address" },
    683 
    684   END_FUNCTIONS
    685 };
    686 
    687 void
    688 gdbscm_initialize_symtabs (void)
    689 {
    690   symtab_smob_tag
    691     = gdbscm_make_smob_type (symtab_smob_name, sizeof (symtab_smob));
    692   scm_set_smob_free (symtab_smob_tag, stscm_free_symtab_smob);
    693   scm_set_smob_print (symtab_smob_tag, stscm_print_symtab_smob);
    694 
    695   sal_smob_tag = gdbscm_make_smob_type (sal_smob_name, sizeof (sal_smob));
    696   scm_set_smob_print (sal_smob_tag, stscm_print_sal_smob);
    697 
    698   gdbscm_define_functions (symtab_functions, 1);
    699 
    700   /* Register an objfile "free" callback so we can properly
    701      invalidate symbol tables, and symbol table and line data
    702      structures when an object file that is about to be deleted.  */
    703   stscm_objfile_data_key
    704     = register_objfile_data_with_cleanup (NULL, stscm_del_objfile_symtabs);
    705 }
    706