From 68b25a74aa492fa84bc530b471036d762cf772bf Mon Sep 17 00:00:00 2001 From: Tom de Vries Date: Tue, 16 May 2023 17:40:32 +0200 Subject: [gdb/tui] Don't show line number for lines not in source file Currently, for a source file containing only 5 lines, we also show line numbers 6 and 7 if they're in scope of the source window: ... 0 +-compact-source.c----------------+ 1 |___3_{ | 2 |___4_ return 0; | 3 |___5_} | 4 |___6_ | 5 |___7_ | 6 +---------------------------------+ ... Fix this by not showing line numbers not in a source file, such that we have instead: ... 0 +-compact-source.c----------------+ 1 |___3_{ | 2 |___4_ return 0; | 3 |___5_} | 4 | | 5 | | 6 +---------------------------------+ ... Tested on x86_64-linux. Suggested-By: Simon Marchi Approved-By: Tom Tromey --- gdb/tui/tui-source.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'gdb/tui/tui-source.c') diff --git a/gdb/tui/tui-source.c b/gdb/tui/tui-source.c index 9d03760..55cde25 100644 --- a/gdb/tui/tui-source.c +++ b/gdb/tui/tui-source.c @@ -80,7 +80,7 @@ tui_source_window::set_contents (struct gdbarch *arch, /* Solaris 11+gcc 5.5 has ambiguous overloads of log10, so we cast to double to get the right one. */ int lines_in_file = offsets->size (); - int max_line_nr = lines_in_file + nlines - 1; + int max_line_nr = lines_in_file; int digits_needed = 1 + (int)log10 ((double) max_line_nr); int trailing_space = 1; m_digits = digits_needed + trailing_space; @@ -100,6 +100,11 @@ tui_source_window::set_contents (struct gdbarch *arch, text = tui_copy_source_line (&iter, &line_len); m_max_length = std::max (m_max_length, line_len); } + else + { + /* Line not in source file. */ + cur_line_no = -1; + } /* Set whether element is the execution point and whether there is a break point on it. */ @@ -233,11 +238,20 @@ tui_source_window::display_start_addr (struct gdbarch **gdbarch_p, void tui_source_window::show_line_number (int offset) const { - int lineno = m_content[0].line_or_addr.u.line_no + offset; + int lineno = m_content[offset].line_or_addr.u.line_no; char text[20]; char space = tui_left_margin_verbose ? '_' : ' '; - xsnprintf (text, sizeof (text), - tui_left_margin_verbose ? "%0*d%c" : "%*d%c", m_digits - 1, - lineno, space); + if (lineno == -1) + { + /* Line not in source file, don't show line number. */ + for (int i = 0; i <= m_digits; ++i) + text[i] = (i == m_digits) ? '\0' : space; + } + else + { + xsnprintf (text, sizeof (text), + tui_left_margin_verbose ? "%0*d%c" : "%*d%c", m_digits - 1, + lineno, space); + } waddstr (handle.get (), text); } -- cgit v1.1