This is the mail archive of the gdb@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Symbols/blocks questions


I am trying to port some MI improvement from the Apple GDB,
and got some questions about symbol/block handling. I'd 
appreciate if somebody comment on it.

1. Given 'struct block *b', is it true that

    block_for_pc (b.startaddr) == b

?

2. Uness I am mistaken, in case of lines inside templates,
inline functions, and constructors, decode_line_1 returns 
just one sal. (And breakpoint.c explicitly expands thsoe in
expand_line_sal). In what cases will decode_line_1 actually
return multiple sals? For overloaded functions? Anything else?
Would it be sensible, eventually, to make decode_line_1
return all locations corresponding to file:line?

3. The code below, from Apple GDB, first calls decode_line_1
and then checks, for each sal, if the line passed to decode_line_1
is less then sal.line. How could this happen at all? I though that
if I ask decode_line_1 for line 10, then either it returns sals
for line 10, or it returns no sal at all.

(For context, the purpose of the code is, given file:line, to find
block in which variables should be looked up and evaluated, for -var-create)

Thanks,
Volodya

              TRY_CATCH (except, RETURN_MASK_ALL)
                {
                  /* The variable 's' will be advanced by decode_line_1.  */
                  char *s = block_addr; 
                  sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, NULL, 
                                        NULL);
                }

              if (except.reason >= 0 && sals.nelts >= 1)
                {
                  old_chain = make_cleanup (xfree, sals.sals);
                  
                  /* Default to global scope unless we find a better match.  */
                  var_type = NO_FRAME_NEEDED;
                  block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (sals.sals[0].symtab), 
                                                 GLOBAL_BLOCK);

                  unsigned long line = 0;
                  char *line_number_str = colon + 1;
                  if (strlen (line_number_str) > 0)
                      line = strtoul (line_number_str, NULL, 0);
                
                  /* Get the currently selected frame for reference.  */
                  struct frame_info *selected_frame = get_selected_frame (NULL);
                  if (selected_frame)
                    {
                      unsigned i;
                      struct symbol *func_sym;
                      func_sym = get_frame_function (selected_frame);
                      if (func_sym)
                        /* Iterate through all symtab_and_line structures 
                           returned and find the one that has the same  
                           function symbol as our frame.  */
                        for (i = 0; i < sals.nelts; i++)
                          {
                            struct symbol *sal_sym = 
                              find_pc_sect_function (sals.sals[i].pc, 
                                                     sals.sals[i].section);

                            if (func_sym == sal_sym)
                              {
                                /* If the requested line is less than the line
                                   found in the matching symtab_and_line 
                                   struct then we must use a global or static 
                                   as the scope since it doesn't fall within  
                                   the symtab_and_line struct that was 
                                   returned.  */
                                if (line && line < sal_sym->line)
                                  {
                                    /* Use a global scope.  */
                                    var_type = NO_FRAME_NEEDED;
                                    block = BLOCKVECTOR_BLOCK 
                                              (BLOCKVECTOR (sals.sals[i].symtab), 
                                               GLOBAL_BLOCK);
                                  }
                                else
                                  {
                                    /* We got a valid block match.  */
                                    var_type = USE_BLOCK_IN_FRAME;
                                    block = block_for_pc (sals.sals[i].pc);
                                    break;
                                  }
                              }
                          }
                    }               
                }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]