aboutsummaryrefslogtreecommitdiff
path: root/gdb/cli/cli-cmds.c
diff options
context:
space:
mode:
Diffstat (limited to 'gdb/cli/cli-cmds.c')
-rw-r--r--gdb/cli/cli-cmds.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c
index a5ef9c6..e5d34a7 100644
--- a/gdb/cli/cli-cmds.c
+++ b/gdb/cli/cli-cmds.c
@@ -874,6 +874,27 @@ list_command (char *arg, int from_tty)
{
set_default_source_symtab_and_line ();
cursal = get_current_source_symtab_and_line ();
+
+ /* If this is the first "list" since we've set the current
+ source line, center the listing around that line. */
+ if (get_first_line_listed () == 0)
+ {
+ int first;
+
+ first = max (cursal.line - get_lines_to_list () / 2, 1);
+
+ /* A small special case --- if listing backwards, and we
+ should list only one line, list the preceding line,
+ instead of the exact line we've just shown after e.g.,
+ stopping for a breakpoint. */
+ if (arg != NULL && arg[0] == '-'
+ && get_lines_to_list () == 1 && first > 1)
+ first -= 1;
+
+ print_source_lines (cursal.symtab, first,
+ first + get_lines_to_list (), 0);
+ return;
+ }
}
/* "l" or "l +" lists next ten lines. */