aboutsummaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorPhil Muldoon <pmuldoon@redhat.com>2011-12-16 15:55:40 +0000
committerPhil Muldoon <pmuldoon@redhat.com>2011-12-16 15:55:40 +0000
commit80b6e7564ff0168d392e69a46ded01ce1bf3dd73 (patch)
tree937a8f34be597f9dd4243f2e3691748ead3ef84a /gdb
parentb93a1992f4b3668cae4682e16a8add34f8411a8c (diff)
downloadgdb-80b6e7564ff0168d392e69a46ded01ce1bf3dd73.zip
gdb-80b6e7564ff0168d392e69a46ded01ce1bf3dd73.tar.gz
gdb-80b6e7564ff0168d392e69a46ded01ce1bf3dd73.tar.bz2
2011-12-16 Phil Muldoon <pmuldoon@redhat.com>
* testsuite/gdb.python/py-function.exp: Change "on" to "full" for python print-stack. Add set/show python print-stack off|full|message tests. 2011-12-16 Phil Muldoon <pmuldoon@redhat.com> * python/python.c: Define python_excp_enums. (eval_python_from_control_command): Do not call gdbpy_print_stack. (python_command): Ditto. (gdbpy_print_stack): Rewrite to use new enum constants. (maint_set_python): Remove function. (maint_show_python): Ditto. (_initialize_python): Do not add "maint" commands. Add "set/show python print-stack commands". * NEWS: Update to reflect removal for "maint set/show print-stack" 2011-12-16 Phil Muldoon <pmuldoon@redhat.com> * doc/gdb.texinfo (Python Commands): Remove "maint set/show print stack". Add documentation for "set/show python print-stack".
Diffstat (limited to 'gdb')
-rw-r--r--gdb/ChangeLog13
-rw-r--r--gdb/NEWS7
-rw-r--r--gdb/doc/ChangeLog5
-rw-r--r--gdb/doc/gdb.texinfo16
-rw-r--r--gdb/python/python.c142
-rw-r--r--gdb/testsuite/ChangeLog6
-rw-r--r--gdb/testsuite/gdb.python/py-function.exp2
-rw-r--r--gdb/testsuite/gdb.python/py-prettyprint.exp2
-rw-r--r--gdb/testsuite/gdb.python/python.exp75
9 files changed, 168 insertions, 100 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 7adf981..0ae93e0 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,16 @@
+2011-12-16 Phil Muldoon <pmuldoon@redhat.com>
+
+ * python/python.c: Define python_excp_enums.
+ (eval_python_from_control_command): Do not call gdbpy_print_stack.
+ (python_command): Ditto.
+ (gdbpy_print_stack): Rewrite to use new enum constants.
+ (maint_set_python): Remove function.
+ (maint_show_python): Ditto.
+ (_initialize_python): Do not add "maint" commands. Add "set/show
+ python print-stack commands".
+ * NEWS: Update to reflect removal for "maint set/show
+ print-stack"
+
2011-12-15 Doug Evans <dje@google.com>
* exceptions.c (catcher_list_size): New function.
diff --git a/gdb/NEWS b/gdb/NEWS
index 02f73a5..43345a9 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -31,9 +31,10 @@
existing one.
** The "maint set python print-stack on|off" command has been
- deprecated, and a new command: "set python print-stack on|off" has
- replaced it. Additionally, the default for "print-stack" is now
- "off".
+ removed. A new command: "set python print-stack
+ none|full|message" has replaced it. Additionally, the default
+ for "print-stack" is now "message", which just prints the error
+ message without the stack trace.
** A prompt substitution hook (prompt_hook) is now available to the
Python API.
diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog
index 6cd0b9b..ca4730e 100644
--- a/gdb/doc/ChangeLog
+++ b/gdb/doc/ChangeLog
@@ -1,3 +1,8 @@
+2011-12-16 Phil Muldoon <pmuldoon@redhat.com>
+
+ * doc/gdb.texinfo (Python Commands): Remove "maint set/show print
+ stack". Add documentation for "set/show python print-stack".
+
2011-12-14 Pedro Alves <pedro@codesourcery.com>
* gdb.texinfo (Implementing a Remote Stub): Explain that you
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 925e66a..4787b82 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -21447,18 +21447,14 @@ End with a line saying just "end".
23
@end smallexample
-@kindex maint set python print-stack
-@item maint set python print-stack
-This command is now deprecated. Instead use @code{set python
-print-stack}
-
@kindex set python print-stack
@item set python print-stack
-By default, @value{GDBN} will not print a stack trace when an error
-occurs in a Python script. This can be controlled using @code{set
-python print-stack}: if @code{on}, then Python stack printing is
-enabled; if @code{off}, the default, then Python stack printing is
-disabled.
+By default, @value{GDBN} will print only the message component of a
+Python exception when an error occurs in a Python script. This can be
+controlled using @code{set python print-stack}: if @code{full}, then
+full Python stack printing is enabled; if @code{none}, then Python stack
+and message printing is disabled; if @code{message}, the default, only
+the message component of the error is printed.
@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 b0b9a9c..9b00cdc 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -35,9 +35,25 @@
#include <ctype.h>
-/* True if we should print the stack when catching a Python error,
- false otherwise. */
-static int gdbpy_should_print_stack = 0;
+/* Declared constants and enum for python stack printing. */
+static const char python_excp_none[] = "none";
+static const char python_excp_full[] = "full";
+static const char python_excp_message[] = "message";
+
+/* "set python print-stack" choices. */
+static const char *python_excp_enums[] =
+ {
+ python_excp_none,
+ python_excp_full,
+ python_excp_message,
+ NULL
+ };
+
+/* The exception printing variable. 'full' if we want to print the
+ error message and stack, 'none' if we want to print nothing, and
+ 'message' if we only want to print the error message. 'message' is
+ the default. */
+static const char *gdbpy_should_print_stack = python_excp_message;
#ifdef HAVE_PYTHON
@@ -233,10 +249,7 @@ eval_python_from_control_command (struct command_line *cmd)
ret = PyRun_SimpleString (script);
xfree (script);
if (ret)
- {
- gdbpy_print_stack ();
- error (_("Error while executing Python code."));
- }
+ error (_("Error while executing Python code."));
do_cleanups (cleanup);
}
@@ -258,10 +271,7 @@ python_command (char *arg, int from_tty)
if (arg && *arg)
{
if (PyRun_SimpleString (arg))
- {
- gdbpy_print_stack ();
- error (_("Error while executing Python code."));
- }
+ error (_("Error while executing Python code."));
}
else
{
@@ -881,13 +891,20 @@ gdbpy_flush (PyObject *self, PyObject *args, PyObject *kw)
Py_RETURN_NONE;
}
-/* Print a python exception trace, or print nothing and clear the
- python exception, depending on gdbpy_should_print_stack. Only call
- this if a python exception is set. */
+/* Print a python exception trace, print just a message, or print
+ nothing and clear the python exception, depending on
+ gdbpy_should_print_stack. Only call this if a python exception is
+ set. */
void
gdbpy_print_stack (void)
{
- if (gdbpy_should_print_stack)
+ /* Print "none", just clear exception. */
+ if (gdbpy_should_print_stack == python_excp_none)
+ {
+ PyErr_Clear ();
+ }
+ /* Print "full" message and backtrace. */
+ else if (gdbpy_should_print_stack == python_excp_full)
{
PyErr_Print ();
/* PyErr_Print doesn't necessarily end output with a newline.
@@ -895,8 +912,34 @@ gdbpy_print_stack (void)
printf_filtered. */
begin_line ();
}
+ /* Print "message", just error print message. */
else
- PyErr_Clear ();
+ {
+ PyObject *ptype, *pvalue, *ptraceback;
+ char *msg = NULL, *type = NULL;
+
+ PyErr_Fetch (&ptype, &pvalue, &ptraceback);
+
+ /* Fetch the error message contained within ptype, pvalue. */
+ msg = gdbpy_exception_to_string (ptype, pvalue);
+ type = gdbpy_obj_to_string (ptype);
+ if (msg == NULL)
+ {
+ /* An error occurred computing the string representation of the
+ error message. */
+ fprintf_filtered (gdb_stderr,
+ _("Error occurred computing Python error" \
+ "message.\n"));
+ }
+ else
+ fprintf_filtered (gdb_stderr, "Python Exception %s %s: \n",
+ type, msg);
+
+ Py_XDECREF (ptype);
+ Py_XDECREF (pvalue);
+ Py_XDECREF (ptraceback);
+ xfree (msg);
+ }
}
@@ -1062,33 +1105,11 @@ gdbpy_breakpoint_has_py_cond (struct breakpoint_object *bp_obj)
-/* Lists for 'maint set python' commands. */
-
-static struct cmd_list_element *maint_set_python_list;
-static struct cmd_list_element *maint_show_python_list;
-
/* Lists for 'set python' commands. */
static struct cmd_list_element *user_set_python_list;
static struct cmd_list_element *user_show_python_list;
-/* Function for use by 'maint set python' prefix command. */
-
-static void
-maint_set_python (char *args, int from_tty)
-{
- help_list (maint_set_python_list, "maintenance set python ",
- class_deprecated, gdb_stdout);
-}
-
-/* Function for use by 'maint show python' prefix command. */
-
-static void
-maint_show_python (char *args, int from_tty)
-{
- cmd_show_list (maint_show_python_list, from_tty, "");
-}
-
/* Function for use by 'set python' prefix command. */
static void
@@ -1138,33 +1159,6 @@ This command is only a placeholder.")
#endif /* HAVE_PYTHON */
);
- add_prefix_cmd ("python", no_class, maint_show_python,
- _("Prefix command for python maintenance settings."),
- &maint_show_python_list, "maintenance show python ", 0,
- &maintenance_show_cmdlist);
- add_prefix_cmd ("python", no_class, maint_set_python,
- _("Prefix command for python maintenance settings."),
- &maint_set_python_list, "maintenance set python ", 0,
- &maintenance_set_cmdlist);
-
- add_setshow_boolean_cmd ("print-stack", class_maintenance,
- &gdbpy_should_print_stack, _("\
-Enable or disable printing of Python stack dump on error."), _("\
-Show whether Python stack will be printed on error."), _("\
-Enables or disables printing of Python stack traces."),
- NULL, NULL,
- &maint_set_python_list,
- &maint_show_python_list);
-
- /* Deprecate maint set/show python print-stack in favour of
- non-maintenance alternatives. */
- cmd_name = "print-stack";
- cmd = lookup_cmd (&cmd_name, maint_set_python_list, "", -1, 0);
- deprecate_cmd (cmd, "set python print-stack");
- cmd_name = "print-stack"; /* Reset name. */
- cmd = lookup_cmd (&cmd_name, maint_show_python_list, "", -1, 0);
- deprecate_cmd (cmd, "show python print-stack");
-
/* Add set/show python print-stack. */
add_prefix_cmd ("python", no_class, user_show_python,
_("Prefix command for python preference settings."),
@@ -1176,14 +1170,16 @@ Enables or disables printing of Python stack traces."),
&user_set_python_list, "set python ", 0,
&setlist);
- add_setshow_boolean_cmd ("print-stack", no_class,
- &gdbpy_should_print_stack, _("\
-Enable or disable printing of Python stack dump on error."), _("\
-Show whether Python stack will be printed on error."), _("\
-Enables or disables printing of Python stack traces."),
- NULL, NULL,
- &user_set_python_list,
- &user_show_python_list);
+ add_setshow_enum_cmd ("print-stack", no_class, python_excp_enums,
+ &gdbpy_should_print_stack, _("\
+Set mode for Python stack dump on error."), _("\
+Show the mode of Python stack printing on error."), _("\
+none == no stack or message will be printed.\n\
+full == a message and a stack will be printed.\n\
+message == an error message without a stack will be printed."),
+ NULL, NULL,
+ &user_set_python_list,
+ &user_show_python_list);
#ifdef HAVE_PYTHON
#ifdef WITH_PYTHON_PATH
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index c432e2b..4c98de1 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2011-12-16 Phil Muldoon <pmuldoon@redhat.com>
+
+ * testsuite/gdb.python/py-function.exp: Change "on" to "full" for
+ python print-stack. Add set/show python print-stack
+ off|full|message tests.
+
2011-12-15 Yao Qi <yao@codesourcery.com>
* gdb.trace/strace.c: New
diff --git a/gdb/testsuite/gdb.python/py-function.exp b/gdb/testsuite/gdb.python/py-function.exp
index d579435..f670d52 100644
--- a/gdb/testsuite/gdb.python/py-function.exp
+++ b/gdb/testsuite/gdb.python/py-function.exp
@@ -93,7 +93,7 @@ gdb_py_test_multiple "Test Normal Error" \
"NormalError ()" "" \
"end" ""
-gdb_test_no_output "set python print-stack on"
+gdb_test_no_output "set python print-stack full"
gdb_test "print \$normalerror()" "Traceback.*File.*line 5.*in invoke.*RuntimeError.*This is a Normal Error.*" \
"Test a Runtime error. There should be a stack trace."
diff --git a/gdb/testsuite/gdb.python/py-prettyprint.exp b/gdb/testsuite/gdb.python/py-prettyprint.exp
index b0e7d62..9786d71 100644
--- a/gdb/testsuite/gdb.python/py-prettyprint.exp
+++ b/gdb/testsuite/gdb.python/py-prettyprint.exp
@@ -97,7 +97,7 @@ proc run_lang_tests {exefile lang} {
gdb_test_no_output "python pp_ls_encoding = 'UTF-8'"
gdb_test "print estring2" "\"embedded \", <incomplete sequence \\\\302>"
- gdb_test_no_output "set python print-stack on"
+ gdb_test_no_output "set python print-stack full"
gdb_test "print hint_error" "Exception: hint failed\r\nhint_error_val"
gdb_test "print c" " = container \"container\" with 2 elements = {$nl *.0. = 23,$nl *.1. = 72$nl}"
diff --git a/gdb/testsuite/gdb.python/python.exp b/gdb/testsuite/gdb.python/python.exp
index 94d6d0d..290a083 100644
--- a/gdb/testsuite/gdb.python/python.exp
+++ b/gdb/testsuite/gdb.python/python.exp
@@ -195,20 +195,15 @@ gdb_test "python gdb.write(\"Error stream\\n\", stream=gdb.STDERR)" "Error strea
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-stack'.*" \
- "Test deprecation maint show warning."
-gdb_test "maint set python print-stack off" \
- "Warning: command 'maintenance set python print-stack' is deprecated.*Use 'set python print-stack'.*" \
- "Test deprecation maint set warning."
+# print-stack
gdb_test "show python print-stack" \
- "Whether Python stack will be printed on error is off.*" \
- "Test print-backtrace show setting. Default off."
-gdb_py_test_silent_cmd "set python print-stack on" \
+ "The mode of Python stack printing on error is \"message\".*" \
+ "Test print-backtrace show setting. Default is message."
+gdb_py_test_silent_cmd "set python print-stack full" \
"Test print-backtrace set setting" 1
gdb_test "show python print-stack" \
- "Whether Python stack will be printed on error is on.*" \
+ "The mode of Python stack printing on error is \"full\".*" \
+ "Test print-backtrace show setting to full."
# Test prompt substituion
@@ -313,7 +308,63 @@ gdb_test_multiple "set extended-prompt \\w " \
gdb_test_multiple "set extended-prompt some param \\p{python print-stack} " \
"set extended prompt parameter" {
- -re "\[\r\n\]some param True $" {
+ -re "\[\r\n\]some param full $" {
pass "set extended prompt parameter"
}
}
+
+# Start with a fresh gdb.
+clean_restart ${testfile}
+
+# The following tests require execution.
+
+if ![runto_main] then {
+ fail "Can't run to main"
+ return 0
+}
+
+# print-stack settings
+gdb_test "show python print-stack" \
+ "The mode of Python stack printing on error is \"message\".*" \
+ "Test print-backtrace show setting. Default is message."
+gdb_py_test_silent_cmd "set python print-stack full" \
+ "Test print-backtrace set setting" 1
+gdb_test "show python print-stack" \
+ "The mode of Python stack printing on error is \"full\".*" \
+ "Test print-backtrace show setting to full."
+gdb_py_test_silent_cmd "set python print-stack none" \
+ "Test print-backtrace set setting" 1
+gdb_test "show python print-stack" \
+ "The mode of Python stack printing on error is \"none\".*" \
+ "Test print-backtrace show setting to none."
+
+gdb_py_test_silent_cmd "set python print-stack message" \
+ "Test print-backtrace set setting" 1
+
+gdb_py_test_multiple "prompt substitution readline" \
+ "python" "" \
+ "pCounter = 0" "" \
+ "def error_prompt(current):" "" \
+ " raise RuntimeError(\"Python exception called\")" "" \
+ "end" ""
+
+gdb_test_multiple "python gdb.prompt_hook = error_prompt" "set the hook" {
+ -re "Python Exception <type 'exceptions.RuntimeError'> Python exception called.*" {
+ pass "set hook"
+ }
+}
+
+gdb_py_test_silent_cmd "python gdb.prompt_hook = None" \
+ "set the hook to default" 1
+
+gdb_py_test_silent_cmd "set python print-stack full" \
+ "Test print-backtrace set setting" 1
+
+gdb_test_multiple "python gdb.prompt_hook = error_prompt" "set the hook" {
+ -re "Traceback.*File.*line.*RuntimeError.*Python exception called.*" {
+ pass "set hook"
+ }
+}
+
+gdb_py_test_silent_cmd "python gdb.prompt_hook = None" \
+ "set the hook to default" 1