[PATCH 4/6] Fix PR gdb/15294: list with unlimited listsize broken
Pedro Alves
palves@redhat.com
Thu Mar 21 18:29:00 GMT 2013
Currently, "set listsize -1" is supposed to mean "unlimited" source
lines, but, alas, it doesn't actually work:
(gdb) set listsize -1
(gdb) show listsize
Number of source lines gdb will list by default is unlimited.
(gdb) list 1
(gdb) list 1
(gdb) list 1
(gdb) set listsize 10
(gdb) list 1
1 /* Main function for CLI gdb.
2 Copyright (C) 2002-2013 Free Software Foundation, Inc.
3
4 This file is part of GDB.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
10
Before this patch
http://sourceware.org/ml/gdb-patches/2012-08/msg00021.html
the "set listsize" command was a var_integer command, and "unlimited"
was set with 0. Internally, var_integer maps 0 to INT_MAX
case var_integer:
{
...
if (val == 0 && c->var_type == var_integer)
val = INT_MAX;
The change to zuinteger_unlimited command, meant that -1 is left as -1
in the command's control variable (lines_to_list), and the code in
source.c isn't expecting that -- it only expects positive numbers. I
find that the simplest and clearest to handle this is the approach of
this patch. Keep the command as zuinteger_unlimited and have source.c
itself map -1 to a largest source line number GDB could handle, which
is the same as "unlimited" in practice, which is what also was done
(albeit not explicitly) when the command was var_integer.
This results in actually passing the old "set listsize -1; list 1"
test:
-XFAIL: gdb.base/list.exp: list line 1 with unlimited listsize
+XPASS: gdb.base/list.exp: list line 1 with unlimited listsize
gdb/
2013-03-21 Pedro Alves <palves@redhat.com>
PR gdb/15294
* source.c (lines_to_list): Rename to ...
(setshow_listsize_var): ... this. Update comment.
(get_lines_to_list): Update comment. Return INT_MAX when "set
listsize" is -1.
(select_source_symtab, forward_search_command)
(reverse_search_command): Use get_lines_to_list instead of the
command variable directly.
(_initialize_source): Adjust to command variable rename.
---
gdb/source.c | 36 ++++++++++++++++++++++--------------
1 file changed, 22 insertions(+), 14 deletions(-)
diff --git a/gdb/source.c b/gdb/source.c
index 2d9410e..108c2ee 100644
--- a/gdb/source.c
+++ b/gdb/source.c
@@ -92,13 +92,15 @@ static int current_source_line;
static struct program_space *current_source_pspace;
-/* Default number of lines to print with commands like "list".
- This is based on guessing how many long (i.e. more than chars_per_line
- characters) lines there will be. To be completely correct, "list"
- and friends should be rewritten to count characters and see where
- things are wrapping, but that would be a fair amount of work. */
+/* The variable registered in the "set listsize" command, which
+ controls the default number of lines to print with commands like
+ "list". Don't read the value of this variable directly -- use
+ get_lines_to_list instead. */
+
+static int setshow_listsize_var = 10;
+
+/* "Show" hook for "set listsize". */
-int lines_to_list = 10;
static void
show_lines_to_list (struct ui_file *file, int from_tty,
struct cmd_list_element *c, const char *value)
@@ -156,14 +158,20 @@ get_first_line_listed (void)
}
/* Return the default number of lines to print with commands like the
- cli "list". The caller of print_source_lines must use this to
- calculate the end line and use it in the call to print_source_lines
- as it does not automatically use this value. */
+ cli "list". This is based on guessing how many long (i.e. more
+ than chars_per_line characters) lines there will be. To be
+ completely correct, "list" and friends should be rewritten to count
+ characters and see where things are wrapping, but that would be a
+ fair amount of work. The caller of print_source_lines must use
+ this to calculate the end line and use it in the call to
+ print_source_lines as it does not automatically use this value. */
int
get_lines_to_list (void)
{
- return lines_to_list;
+ /* In the user command, -1 means unlimited. In practice, we just
+ handle that as a very large number. */
+ return (setshow_listsize_var < 0 ? INT_MAX : setshow_listsize_var);
}
/* Return the current source file for listing and next line to list.
@@ -270,7 +278,7 @@ select_source_symtab (struct symtab *s)
xfree (sals.sals);
current_source_pspace = sal.pspace;
current_source_symtab = sal.symtab;
- current_source_line = max (sal.line - (lines_to_list - 1), 1);
+ current_source_line = max (sal.line - (get_lines_to_list () - 1), 1);
if (current_source_symtab)
return;
}
@@ -1644,7 +1652,7 @@ forward_search_command (char *regex, int from_tty)
do_cleanups (cleanups);
print_source_lines (current_source_symtab, line, line + 1, 0);
set_internalvar_integer (lookup_internalvar ("_"), line);
- current_source_line = max (line - lines_to_list / 2, 1);
+ current_source_line = max (line - get_lines_to_list () / 2, 1);
return;
}
line++;
@@ -1722,7 +1730,7 @@ reverse_search_command (char *regex, int from_tty)
do_cleanups (cleanups);
print_source_lines (current_source_symtab, line, line + 1, 0);
set_internalvar_integer (lookup_internalvar ("_"), line);
- current_source_line = max (line - lines_to_list / 2, 1);
+ current_source_line = max (line - get_lines_to_list () / 2, 1);
return;
}
line--;
@@ -2045,7 +2053,7 @@ The matching line number is also stored as the value of \"$_\"."));
}
add_setshow_zuinteger_unlimited_cmd ("listsize", class_support,
- &lines_to_list, _("\
+ &setshow_listsize_var, _("\
Set number of source lines gdb will list by default."), _("\
Show number of source lines gdb will list by default."), NULL,
NULL, show_lines_to_list,
More information about the Gdb-patches
mailing list