From 31b7ab1f107b36bf440f89f732e4b46d96d0faa2 Mon Sep 17 00:00:00 2001 From: Tom de Vries Date: Thu, 11 May 2023 19:43:32 +0200 Subject: [PATCH] [gdb/tui] Don't show line number for lines not in source file --- gdb/testsuite/gdb.tui/compact-source.exp | 2 +- gdb/tui/tui-source.c | 20 +++++++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/gdb/testsuite/gdb.tui/compact-source.exp b/gdb/testsuite/gdb.tui/compact-source.exp index f972d961d72..59e858a503f 100644 --- a/gdb/testsuite/gdb.tui/compact-source.exp +++ b/gdb/testsuite/gdb.tui/compact-source.exp @@ -64,7 +64,7 @@ foreach_with_prefix src_window_size {7 8} { if { $max_line_nr_in_source_window == 9 } { set re_left_margin "___4_" } elseif { $max_line_nr_in_source_window == 10 } { - set re_left_margin "___04_" + set re_left_margin "___4_" } else { error "unhandled max_line_nr_in_source_window" } diff --git a/gdb/tui/tui-source.c b/gdb/tui/tui-source.c index 9d0376000de..57f9a62c659 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,8 @@ 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 + cur_line_no = -1; /* Set whether element is the execution point and whether there is a break point on it. */ @@ -233,11 +235,19 @@ 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) + { + 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); } base-commit: 38b95a529385e32adc39428231c6fc8b0e8d6f21 -- 2.35.3