Mirror of the gdb mailing list
 help / color / mirror / Atom feed
From: Vladimir Prus <ghost@cs.msu.su>
To: gdb@sources.redhat.com
Subject: Symbols/blocks questions
Date: Sat, 19 Sep 2009 11:52:00 -0000	[thread overview]
Message-ID: <200909191552.02677.ghost@cs.msu.su> (raw)


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;
                                  }
                              }
                          }
                    }               
                }


             reply	other threads:[~2009-09-19 11:52 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-19 11:52 Vladimir Prus [this message]
2009-09-19 14:34 ` Matt Rice
2009-09-19 16:34 ` Joel Brobecker
2009-09-19 16:41   ` Vladimir Prus
2009-09-19 17:02     ` Joel Brobecker
2009-09-19 18:35       ` Vladimir Prus
2009-09-20 15:52         ` Joel Brobecker
2009-09-20 20:30           ` Daniel Jacobowitz
2009-09-22  9:47   ` Jerome Guitton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200909191552.02677.ghost@cs.msu.su \
    --to=ghost@cs.msu.su \
    --cc=gdb@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox