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

Re: [patch+7.6] [TUI] Fix scrolling missing '>' 7.6 regression [Re: [PATCH] Fix gdb crash with tui]


On 03/13/2013 06:55 PM, Jan Kratochvil wrote:
> On Tue, 12 Mar 2013 19:36:02 +0100, Pedro Alves wrote:
>> Just doing any of these does fix the issue with the highlighted
>> current line disappearing, so there's something else that needs
>> fixing in addition.
> 
> That is the second patch for a regression by me.

Thanks.

> #0  __memset_sse2 () at ../sysdeps/x86_64/memset.S:360
> #1  in freehook (ptr=0x3a61ba0, caller=0x879de9 <xfree+31>) at mcheck.c:193
> #2  in xfree (ptr=0x3a61ba0) at ./common/common-utils.c:108
> #3  in find_and_open_source (filename=0x23c2010 "gdb.c", dirname=0x289cec0 "/home/jkratoch/redhat/gdb-clean/gdb", fullname=0x289cde0) at source.c:1008
> #4  in open_source_file (s=0x289cd80) at source.c:1088
> #5  in tui_set_source_content (s=0x289cd80, line_no=16, noerror=0) at ./tui/tui-source.c:61
> #6  in tui_update_source_window_as_is (win_info=0x3a51a80, gdbarch=0x22d0000, s=0x289cd80, line_or_addr=..., noerror=0) at ./tui/tui-winsource.c:99
> #7  in tui_show_symtab_source (gdbarch=0x22d0000, s=0x289cd80, line=..., noerror=0) at ./tui/tui-source.c:339 
> #8  in tui_update_source_windows_with_line (s=0x289cd80, line=16) at ./tui/tui-winsource.c:201
> #9  in tui_show_source (fullname=0x3a61ba0 "\225\225\225\225\225\225\225\225ratoch/redhat/gdb-clean/gdb/gdb.c", line=16) at ./tui/tui.c:542
> #10 in tui_field_string (uiout=0x2296dc0, fldno=3, width=0, align=ui_noalign, fldname=0xfa09d9 "fullname", string=0x3a61ba0 "\225\225\225\225\225\225\225\225ratoch/redhat/gdb-clean/gdb/gdb.c") at ./tui/tui-out.c:92
> #11 in uo_field_string (uiout=0x2296dc0, fldno=3, width=0, align=ui_noalign, fldname=0xfa09d9 "fullname", string=0x3a61ba0 "\225\225\225\225\225\225\225\225ratoch/redhat/gdb-clean/gdb/gdb.c") at ui-out.c:854
> #12 in ui_out_field_string (uiout=0x2296dc0, fldname=0xfa09d9 "fullname", string=0x3a61ba0 "\225\225\225\225\225\225\225\225ratoch/redhat/gdb-clean/gdb/gdb.c") at ui-out.c:544
> #13 in print_source_lines_base (s=0x289cd80, line=16, stopline=17, flags=PRINT_SOURCE_LINES_NOERROR) at source.c:1357
> #14 in print_source_lines (s=0x289cd80, line=16, stopline=17, flags=(unknown: 0)) at source.c:1442
> #15 in tui_vertical_source_scroll (scroll_direction=BACKWARD_SCROLL, num_to_scroll=1) at ./tui/tui-source.c:393
> #16 in tui_scroll_backward (win_to_scroll=0x3a51a80, num_to_scroll=1) at ./tui/tui-win.c:538
> #17 in tui_dispatch_ctrl_char (ch=259) at ./tui/tui-command.c:118
> #18 in tui_getc (fp=0x7ffff663b660 <_IO_2_1_stdin_>) at ./tui/tui-io.c:692
> #19 in rl_read_key () at input.c:448
> 
> 
> I did not expect this may happen...

Took me a bit to realize why this was a problem, and
why the copy fixed it.  For the archives, the issue is
here:

void
tui_show_source (const char *fullname, int line)
{
  struct symtab_and_line cursal = get_current_source_symtab_and_line ();

  /* Make sure that the source window is displayed.  */
  tui_add_win_to_layout (SRC_WIN);

  tui_update_source_windows_with_line (cursal.symtab, line);
  tui_update_locator_fullname (fullname);
}

Where tui_update_locator_fullname is using a dangling
pointer -- FULLNAME ends up released by
tui_update_source_windows_with_line, as seen in the backtrace above.

> 2013-03-13  Jan Kratochvil  <jan.kratochvil@redhat.com>
> 
> 	* source.c (print_source_lines_base): Make a local copy of
> 	symtab_to_fullname.

This is fine with me.

> @@ -1355,11 +1355,17 @@ print_source_lines_base (struct symtab *s, int line, int stopline,
>  				 symtab_to_filename_for_display (s));
>  	  if (ui_out_is_mi_like_p (uiout)
>  	      || !ui_out_test_flags (uiout, ui_source_list))
> -	    {
> -	      const char *fullname = symtab_to_fullname (s);
> + 	    {
> +	      const char *s_fullname = symtab_to_fullname (s);
> +	      char *local_fullname;
>  
> -	      ui_out_field_string (uiout, "fullname", fullname);
> -	    }
> +	      /* ui_out_field_string may free S_FULLNAME by calling
> +	         open_source_file for it again.  */

I wouldn't mind a mention of the TUI here to make future
readers a bit less surprised:

	      /* ui_out_field_string may free S_FULLNAME by calling
	         open_source_file for it again.  See e.g.,
                 tui_field_string->tui_show_source.  */


> +	      local_fullname = alloca (strlen (s_fullname) + 1);
> +	      strcpy (local_fullname, s_fullname);
> +
> +	      ui_out_field_string (uiout, "fullname", local_fullname);
> + 	    }
>  
>  	  ui_out_text (uiout, "\n");
>  	}

-- 
Pedro Alves


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