This is the mail archive of the gdb-patches@sources.redhat.com 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]

RFA: also return exact PC used to choose block



Preliminary patch for macro support.  This change should have no
visible effect on GDB's behavior.

To decide which macros are in scope, it's not enough to know the
scoping block.  You need to know the exact PC, so you can find the
corresponding source line number and see which macros are in scope
there.

2002-03-29  Jim Blandy  <jimb@redhat.com>

	* stack.c (get_selected_block): Add new argument `pc_in_block',
	used to return the exact PC value we used to select the block, not
	just the block.
	* blockframe.c (get_frame_block, get_current_block): Same.
	* frame.h (get_frame_block, get_current_block,
	get_selected_block): Update declarations.
	* linespec.c, stack.c, blockframe.c, breakpoint.c, findvar.c,
	linespec.c, varobj.c, printcmd.c, symtab.c: Callers changed.

Index: gdb/blockframe.c
===================================================================
RCS file: /cvs/src/src/gdb/blockframe.c,v
retrieving revision 1.21
diff -c -r1.21 blockframe.c
*** gdb/blockframe.c	2002/02/27 20:04:29	1.21
--- gdb/blockframe.c	2002/03/29 23:51:08
***************
*** 504,513 ****
  #endif
  
  /* Return the innermost lexical block in execution
!    in a specified stack frame.  The frame address is assumed valid.  */
  
  struct block *
! get_frame_block (struct frame_info *frame)
  {
    CORE_ADDR pc;
  
--- 504,516 ----
  #endif
  
  /* Return the innermost lexical block in execution
!    in a specified stack frame.  The frame address is assumed valid.
  
+    If PC_IN_BLOCK is non-zero, set *PC_IN_BLOCK to the exact PC we
+    used to choose the block.  */
+ 
  struct block *
! get_frame_block (struct frame_info *frame, CORE_ADDR *pc_in_block)
  {
    CORE_ADDR pc;
  
***************
*** 520,532 ****
         after the call insn, we probably want to make frame->pc point after
         the call insn anyway.  */
      --pc;
    return block_for_pc (pc);
  }
  
  struct block *
! get_current_block (void)
  {
!   return block_for_pc (read_pc ());
  }
  
  CORE_ADDR
--- 523,544 ----
         after the call insn, we probably want to make frame->pc point after
         the call insn anyway.  */
      --pc;
+ 
+   if (pc_in_block)
+     *pc_in_block = pc;
+ 
    return block_for_pc (pc);
  }
  
  struct block *
! get_current_block (CORE_ADDR *pc_in_block)
  {
!   CORE_ADDR pc = read_pc ();
! 
!   if (pc_in_block)
!     *pc_in_block = pc;
! 
!   return block_for_pc (pc);
  }
  
  CORE_ADDR
***************
*** 559,565 ****
  struct symbol *
  get_frame_function (struct frame_info *frame)
  {
!   register struct block *bl = get_frame_block (frame);
    if (bl == 0)
      return 0;
    return block_function (bl);
--- 571,577 ----
  struct symbol *
  get_frame_function (struct frame_info *frame)
  {
!   register struct block *bl = get_frame_block (frame, 0);
    if (bl == 0)
      return 0;
    return block_function (bl);
Index: gdb/breakpoint.c
===================================================================
RCS file: /cvs/src/src/gdb/breakpoint.c,v
retrieving revision 1.68
diff -c -r1.68 breakpoint.c
*** gdb/breakpoint.c	2002/03/28 01:35:55	1.68
--- gdb/breakpoint.c	2002/03/29 23:51:12
***************
*** 5621,5627 ****
       but it's better than a core dump.  */
    if (selected_frame == NULL)
      error ("No selected frame.");
!   block = get_frame_block (selected_frame);
    pc = selected_frame->pc;
  
    sals.nelts = 0;
--- 5621,5627 ----
       but it's better than a core dump.  */
    if (selected_frame == NULL)
      error ("No selected frame.");
!   block = get_frame_block (selected_frame, 0);
    pc = selected_frame->pc;
  
    sals.nelts = 0;
Index: gdb/findvar.c
===================================================================
RCS file: /cvs/src/src/gdb/findvar.c,v
retrieving revision 1.29
diff -c -r1.29 findvar.c
*** gdb/findvar.c	2002/03/16 02:57:42	1.29
--- gdb/findvar.c	2002/03/29 23:51:13
***************
*** 551,557 ****
  
  	if (frame == NULL)
  	  return 0;
! 	b = get_frame_block (frame);
  
  	if (SYMBOL_CLASS (var) == LOC_REGPARM_ADDR)
  	  {
--- 551,557 ----
  
  	if (frame == NULL)
  	  return 0;
! 	b = get_frame_block (frame, 0);
  
  	if (SYMBOL_CLASS (var) == LOC_REGPARM_ADDR)
  	  {
Index: gdb/frame.h
===================================================================
RCS file: /cvs/src/src/gdb/frame.h,v
retrieving revision 1.9
diff -c -r1.9 frame.h
*** gdb/frame.h	2002/02/18 15:59:13	1.9
--- gdb/frame.h	2002/03/29 23:51:13
***************
*** 196,206 ****
  
  extern struct frame_info *get_next_frame (struct frame_info *);
  
! extern struct block *get_frame_block (struct frame_info *);
  
! extern struct block *get_current_block (void);
  
! extern struct block *get_selected_block (void);
  
  extern struct symbol *get_frame_function (struct frame_info *);
  
--- 196,207 ----
  
  extern struct frame_info *get_next_frame (struct frame_info *);
  
! extern struct block *get_frame_block (struct frame_info *,
!                                       CORE_ADDR *pc_in_block);
  
! extern struct block *get_current_block (CORE_ADDR *pc_in_block);
  
! extern struct block *get_selected_block (CORE_ADDR *pc_in_block);
  
  extern struct symbol *get_frame_function (struct frame_info *);
  
Index: gdb/linespec.c
===================================================================
RCS file: /cvs/src/src/gdb/linespec.c,v
retrieving revision 1.17
diff -c -r1.17 linespec.c
*** gdb/linespec.c	2002/03/22 18:57:07	1.17
--- gdb/linespec.c	2002/03/29 23:51:15
***************
*** 1187,1193 ****
  
    sym = lookup_symbol (copy,
  		       (s ? BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK)
! 			: get_selected_block ()),
  		       VAR_NAMESPACE, 0, &sym_symtab);
  
  symbol_found:			/* We also jump here from inside the C++ class/namespace 
--- 1187,1193 ----
  
    sym = lookup_symbol (copy,
  		       (s ? BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK)
! 			: get_selected_block (0)),
  		       VAR_NAMESPACE, 0, &sym_symtab);
  
  symbol_found:			/* We also jump here from inside the C++ class/namespace 
Index: gdb/parse.c
===================================================================
RCS file: /cvs/src/src/gdb/parse.c,v
retrieving revision 1.19
diff -c -r1.19 parse.c
*** gdb/parse.c	2002/01/31 02:13:56	1.19
--- gdb/parse.c	2002/03/29 23:51:15
***************
*** 1134,1140 ****
    old_chain = make_cleanup (free_funcalls, 0 /*ignore*/);
    funcall_chain = 0;
  
!   expression_context_block = block ? block : get_selected_block ();
  
    namecopy = (char *) alloca (strlen (lexptr) + 1);
    expout_size = 10;
--- 1134,1140 ----
    old_chain = make_cleanup (free_funcalls, 0 /*ignore*/);
    funcall_chain = 0;
  
!   expression_context_block = block ? block : get_selected_block (0);
  
    namecopy = (char *) alloca (strlen (lexptr) + 1);
    expout_size = 10;
Index: gdb/printcmd.c
===================================================================
RCS file: /cvs/src/src/gdb/printcmd.c,v
retrieving revision 1.37
diff -c -r1.37 printcmd.c
*** gdb/printcmd.c	2002/03/06 06:28:33	1.37
--- gdb/printcmd.c	2002/03/29 23:51:16
***************
*** 1113,1119 ****
    if (exp == 0)
      error ("Argument required.");
  
!   sym = lookup_symbol (exp, get_selected_block (), VAR_NAMESPACE,
  		       &is_a_field_of_this, (struct symtab **) NULL);
    if (sym == NULL)
      {
--- 1113,1119 ----
    if (exp == 0)
      error ("Argument required.");
  
!   sym = lookup_symbol (exp, get_selected_block (0), VAR_NAMESPACE,
  		       &is_a_field_of_this, (struct symtab **) NULL);
    if (sym == NULL)
      {
***************
*** 1549,1555 ****
      return;
  
    if (d->block)
!     within_current_scope = contained_in (get_selected_block (), d->block);
    else
      within_current_scope = 1;
    if (!within_current_scope)
--- 1549,1555 ----
      return;
  
    if (d->block)
!     within_current_scope = contained_in (get_selected_block (0), d->block);
    else
      within_current_scope = 1;
    if (!within_current_scope)
***************
*** 1683,1689 ****
        else if (d->format.format)
  	printf_filtered ("/%c ", d->format.format);
        print_expression (d->exp, gdb_stdout);
!       if (d->block && !contained_in (get_selected_block (), d->block))
  	printf_filtered (" (cannot be evaluated in the current context)");
        printf_filtered ("\n");
        gdb_flush (gdb_stdout);
--- 1683,1689 ----
        else if (d->format.format)
  	printf_filtered ("/%c ", d->format.format);
        print_expression (d->exp, gdb_stdout);
!       if (d->block && !contained_in (get_selected_block (0), d->block))
  	printf_filtered (" (cannot be evaluated in the current context)");
        printf_filtered ("\n");
        gdb_flush (gdb_stdout);
Index: gdb/stack.c
===================================================================
RCS file: /cvs/src/src/gdb/stack.c,v
retrieving revision 1.30
diff -c -r1.30 stack.c
*** gdb/stack.c	2002/03/23 17:38:13	1.30
--- gdb/stack.c	2002/03/29 23:51:17
***************
*** 1238,1244 ****
  print_frame_local_vars (register struct frame_info *fi, register int num_tabs,
  			register struct ui_file *stream)
  {
!   register struct block *block = get_frame_block (fi);
    register int values_printed = 0;
  
    if (block == 0)
--- 1238,1244 ----
  print_frame_local_vars (register struct frame_info *fi, register int num_tabs,
  			register struct ui_file *stream)
  {
!   register struct block *block = get_frame_block (fi, 0);
    register int values_printed = 0;
  
    if (block == 0)
***************
*** 1272,1278 ****
  			register struct ui_file *stream)
  {
    register struct blockvector *bl;
!   register struct block *block = get_frame_block (fi);
    register int values_printed = 0;
    int index, have_default = 0;
    char *blocks_printed;
--- 1272,1278 ----
  			register struct ui_file *stream)
  {
    register struct blockvector *bl;
!   register struct block *block = get_frame_block (fi, 0);
    register int values_printed = 0;
    int index, have_default = 0;
    char *blocks_printed;
***************
*** 1501,1517 ****
  }
  
  /* Return the symbol-block in which the selected frame is executing.
!    Can return zero under various legitimate circumstances.  */
  
  struct block *
! get_selected_block (void)
  {
    if (!target_has_stack)
      return 0;
  
    if (!selected_frame)
!     return get_current_block ();
!   return get_frame_block (selected_frame);
  }
  
  /* Find a frame a certain number of levels away from FRAME.
--- 1501,1521 ----
  }
  
  /* Return the symbol-block in which the selected frame is executing.
!    Can return zero under various legitimate circumstances.
  
+    If PC_IN_BLOCK is non-zero, set *PC_IN_BLOCK to the relevant PC
+    value within the block returned.  We use this to decide which
+    macros are in scope.  */
+ 
  struct block *
! get_selected_block (CORE_ADDR *pc_in_block)
  {
    if (!target_has_stack)
      return 0;
  
    if (!selected_frame)
!     return get_current_block (pc_in_block);
!   return get_frame_block (selected_frame, pc_in_block);
  }
  
  /* Find a frame a certain number of levels away from FRAME.
Index: gdb/symtab.c
===================================================================
RCS file: /cvs/src/src/gdb/symtab.c,v
retrieving revision 1.59
diff -c -r1.59 symtab.c
*** gdb/symtab.c	2002/03/27 23:10:23	1.59
--- gdb/symtab.c	2002/03/29 23:51:19
***************
*** 3279,3285 ****
    /* Search upwards from currently selected frame (so that we can
       complete on local vars.  */
  
!   for (b = get_selected_block (); b != NULL; b = BLOCK_SUPERBLOCK (b))
      {
        if (!BLOCK_SUPERBLOCK (b))
  	{
--- 3279,3285 ----
    /* Search upwards from currently selected frame (so that we can
       complete on local vars.  */
  
!   for (b = get_selected_block (0); b != NULL; b = BLOCK_SUPERBLOCK (b))
      {
        if (!BLOCK_SUPERBLOCK (b))
  	{
***************
*** 3812,3818 ****
    /* Search upwards from currently selected frame (so that we can
       complete on local vars.  */
  
!   for (b = get_selected_block (); b != NULL; b = BLOCK_SUPERBLOCK (b))
      {
        if (!BLOCK_SUPERBLOCK (b))
  	{
--- 3812,3818 ----
    /* Search upwards from currently selected frame (so that we can
       complete on local vars.  */
  
!   for (b = get_selected_block (0); b != NULL; b = BLOCK_SUPERBLOCK (b))
      {
        if (!BLOCK_SUPERBLOCK (b))
  	{
Index: gdb/varobj.c
===================================================================
RCS file: /cvs/src/src/gdb/varobj.c,v
retrieving revision 1.26
diff -c -r1.26 varobj.c
*** gdb/varobj.c	2002/01/13 20:17:55	1.26
--- gdb/varobj.c	2002/03/29 23:51:20
***************
*** 426,432 ****
  
        block = NULL;
        if (fi != NULL)
! 	block = get_frame_block (fi);
  
        p = expression;
        innermost_block = NULL;
--- 426,432 ----
  
        block = NULL;
        if (fi != NULL)
! 	block = get_frame_block (fi, 0);
  
        p = expression;
        innermost_block = NULL;
Index: gdb/mi/ChangeLog
===================================================================
RCS file: /cvs/src/src/gdb/mi/ChangeLog,v
retrieving revision 1.58
diff -c -r1.58 ChangeLog
*** gdb/mi/ChangeLog	2002/03/19 02:51:08	1.58
--- gdb/mi/ChangeLog	2002/03/29 23:51:22
***************
*** 1,3 ****
--- 1,8 ----
+ 2002-03-29  Jim Blandy  <jimb@redhat.com>
+ 
+ 	* mi-cmd-stack.c (list_args_or_locals): Pass new arg to
+ 	get_frame_block.  (See entry in gdb/ChangeLog.)
+ 
  2002-03-15  Andrew Cagney  <ac131313@redhat.com>
  
  	* mi-main.c (XMALLOC): Delete macro.
Index: gdb/mi/mi-cmd-stack.c
===================================================================
RCS file: /cvs/src/src/gdb/mi/mi-cmd-stack.c,v
retrieving revision 1.10
diff -c -r1.10 mi-cmd-stack.c
*** gdb/mi/mi-cmd-stack.c	2002/02/05 19:28:36	1.10
--- gdb/mi/mi-cmd-stack.c	2002/03/29 23:51:22
***************
*** 218,224 ****
  
    stb = ui_out_stream_new (uiout);
  
!   block = get_frame_block (fi);
  
    ui_out_list_begin (uiout, locals ? "locals" : "args");
  
--- 218,224 ----
  
    stb = ui_out_stream_new (uiout);
  
!   block = get_frame_block (fi, 0);
  
    ui_out_list_begin (uiout, locals ? "locals" : "args");
  


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