[patch] PR python/12438

Phil Muldoon
2011-06-30T09:38:11Z

This patch addresses bug PR python/12438. Mark - and other users - have
asked that maint set python print-stack is off by default. This makes
sense to me, as while stack-traces are useful, they can impact
readability of GDB output. Python developers can always turn it back on
again.

Additionally, I have deprecated maint set/show python print-stack and
promoted the setting to the more user visible set/show python
print-backtrace. Finally a note on the name change. I wanted to keep
print-stack, but it appears when you deprecate a command it deprecates
it among all command lists. Deprecating it and adding it back after
just un-deprecates the maint settings. I could not find a way of just
deprecating maint set/show python print-stack, and leaving the user
visible set python print-stack alone. If someone knows a way,
I'll happily change it.

Cheers,

Phil

--

2011-06-30 Phil Muldoon <pmuldoon@redhat.com>

PR python/12438
* python/python.c: Set gdbpy_should_print_stack default to off.
(set_python): Deprecate maint set python print-stack to
class_deprecate.
(_initialize_python): Deprecate maint set/show python print-stack.
Add new prefix command, python. Add new setting, print-backtrace.

2011-06-30 Phil Muldoon <pmuldoon@redhat.com>

PR python/12438
* gdb.python/python.exp: Add maint set/show python print-stack
deprecated tests. Add set/show python print-backtrace tests.

2011-06-30 Phil Muldoon <pmuldoon@redhat.com>

PR python/12438
* gdb.texinfo (Python Commands): Add deprecate note to maint
set/show python print-stack. Document set/show python
print-backtrace.

--

diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 3a705c2..61419b0 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -20791,11 +20791,21 @@ End with a line saying just "end".

@kindex maint set python print-stack
@item maint set python print-stack
-By default, @value{GDBN} will print a stack trace when an error occurs
-in a Python script. This can be controlled using @code{maint set
-python print-stack}: if @code{on}, the default, then Python stack
-printing is enabled; if @code{off}, then Python stack printing is
-disabled.
+This command is now deprecated. Instead use @code{set python print
+backtrace} (@pxref{set python print-backtrace}). By default,
+@value{GDBN} will not print a stack trace when an error occurs in a
+Python script. This can be controlled using @code{maint set python
+print-stack}: if @code{on}, then Python stack printing is enabled; if
+@code{off}, the default, then Python stack printing is disabled.
+
+@kindex set python print-backtrace
+@item set python print-backtrace
+@anchor{set python print-backtrace}
+By default, @value{GDBN} will not print a backtrace when an error
+occurs in a Python script. This can be controlled using @code{set
+python print-backtrace}: if @code{on}, then Python backtrace printing
+is enabled; if @code{off}, the default, then Python backtrace printing
+is disabled.
@end table

It is also possible to execute a Python script from the @value{GDBN}
diff --git a/gdb/python/python.c b/gdb/python/python.c
index ddfe9ba..5c2ff40 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -36,7 +36,7 @@

/* True if we should print the stack when catching a Python error,
false otherwise. */
-static int gdbpy_should_print_stack = 1;
+static int gdbpy_should_print_stack = 0;

#ifdef HAVE_PYTHON

@@ -944,7 +944,10 @@ struct cmd_list_element *show_python_list;
static void
set_python (char *args, int from_tty)
{
- help_list (set_python_list, "maintenance set python ", -1, gdb_stdout);
+ help_list (set_python_list, "maintenance set python ",
+ class_deprecated, gdb_stdout);
+ help_list (set_python_list, "set python ", all_commands,
+ gdb_stdout);
}

/* Function for use by 'maint show python' prefix command. */
@@ -963,6 +966,9 @@ extern initialize_file_ftype _initialize_python;
void
_initialize_python (void)
{
+ char *cmd_name;
+ struct cmd_list_element *cmd;
+
add_com ("python", class_obscure, python_command,
#ifdef HAVE_PYTHON
_("\
@@ -1002,6 +1008,35 @@ Enables or disables printing of Python stack traces."),
&set_python_list,
&show_python_list);

+ /* Deprecate maint set/show python print-stack in favour of
+ non-maintenance alternatives. */
+ cmd_name = "python print-stack";
+ cmd = lookup_cmd (&cmd_name, maintenance_set_cmdlist, "", -1, 0);
+ deprecate_cmd (cmd, "set python print-backtrace");
+ cmd_name = "python print-stack"; /* Reset name. */
+ cmd = lookup_cmd (&cmd_name, maintenance_show_cmdlist, "", -1, 0);
+ deprecate_cmd (cmd, "show python print-backtrace");
+
+ /* Add set/show python print-stack. */
+ add_prefix_cmd ("python", no_class, show_python,
+ _("Prefix command for python preference settings."),
+ &show_python_list, "show python ", 0,
+ &showlist);
+
+ add_prefix_cmd ("python", no_class, set_python,
+ _("Prefix command for python preference settings."),
+ &set_python_list, "set python ", 0,
+ &setlist);
+
+ add_setshow_boolean_cmd ("print-backtrace", no_class,
+ &gdbpy_should_print_stack, _("\
+Enable or disable printing of Python backtraces on error."), _("\
+Show whether Python backtraces will be printed on error."), _("\
+Enables or disables printing of Python backtraces."),
+ NULL, NULL,
+ &set_python_list,
+ &show_python_list);
+
#ifdef HAVE_PYTHON
#ifdef WITH_PYTHON_PATH
/* Work around problem where python gets confused about where it is,
diff --git a/gdb/testsuite/gdb.python/python.exp b/gdb/testsuite/gdb.python/python.exp
index a68dd24..a36c622 100644
--- a/gdb/testsuite/gdb.python/python.exp
+++ b/gdb/testsuite/gdb.python/python.exp
@@ -178,3 +178,19 @@ gdb_test "python gdb.write(\"Foo\\n\")" "Foo" "Test default write"
gdb_test "python gdb.write(\"Error stream\\n\", stream=gdb.STDERR)" "Error stream" "Test stderr write"
gdb_test "python gdb.write(\"Normal stream\\n\", stream=gdb.STDOUT)" "Normal stream" "Test stdout write"
gdb_test "python gdb.write(\"Log stream\\n\", stream=gdb.STDLOG)" "Log stream" "Test stdlog write"
+
+# Deprecate maint set/show python print-stack
+gdb_test "maint show python print-stack" \
+ "Warning: command 'maintenance show python print-stack' is deprecated.*Use 'show python print-backtrace'.*" \
+ "Test deprecation maint show warning."
+gdb_test "set python print-stack off" \
+ "Warning: command 'set python print-stack' is deprecated.*Use 'set python print-backtrace'.*" \
+ "Test deprecation maint set warning."
+gdb_test "show python print-backtrace" \
+ "Whether Python backtraces will be printed on error is off.*" \
+ "Test print-backtrace show setting. Default off."
+gdb_py_test_silent_cmd "set python print-backtrace on" \
+ "Test print-backtrace set setting" 1
+gdb_test "show python print-backtrace" \
+ "Whether Python backtraces will be printed on error is on.*" \
+ "Test print-backtrace show setting. Check On."