gdbpy_ref<> textobj (PyUnicode_Decode (text, strlen (text), host_charset (),
NULL));
if (textobj == NULL)
- error (_("Could not convert argument to Python string."));
+ {
+ gdbpy_print_stack ();
+ error (_("Could not convert argument to Python string."));
+ }
gdbpy_ref<> wordobj;
if (word == NULL)
wordobj.reset (PyUnicode_Decode (word, strlen (word), host_charset (),
NULL));
if (wordobj == NULL)
- error (_("Could not convert argument to Python string."));
+ {
+ gdbpy_print_stack ();
+ error (_("Could not convert argument to Python string."));
+ }
}
gdbpy_ref<> resultobj (PyObject_CallMethodObjArgs ((PyObject *) obj,
complete_cst,
textobj.get (),
wordobj.get (), NULL));
- if (resultobj == NULL)
+
+ /* Check if an exception was raised by the Command.complete method. */
+ if (resultobj == nullptr)
{
- /* Just swallow errors here. */
- PyErr_Clear ();
+ gdbpy_print_stack_or_quit ();
+ error (_("exception raised during Command.complete method"));
}
return resultobj;
long value;
if (!gdb_py_int_as_long (resultobj.get (), &value))
- {
- /* Ignore. */
- PyErr_Clear ();
- }
+ gdbpy_print_stack ();
else if (value >= 0 && value < (long) N_COMPLETERS)
{
completer_handle_brkchars_ftype *brkchars_fn;
long value;
if (! gdb_py_int_as_long (resultobj.get (), &value))
- {
- /* Ignore. */
- PyErr_Clear ();
- }
+ gdbpy_print_stack ();
else if (value >= 0 && value < (long) N_COMPLETERS)
completers[value].completer (command, tracker, text, word);
}
gdbpy_ref<> iter (PyObject_GetIter (resultobj.get ()));
if (iter == NULL)
- return;
+ {
+ gdbpy_print_stack ();
+ return;
+ }
- bool got_matches = false;
while (true)
{
gdbpy_ref<> elt (PyIter_Next (iter.get ()));
if (elt == NULL)
- break;
+ {
+ if (PyErr_Occurred() != nullptr)
+ gdbpy_print_stack ();
+ break;
+ }
if (! gdbpy_is_string (elt.get ()))
{
/* Skip problem elements. */
continue;
}
+
gdb::unique_xmalloc_ptr<char>
item (python_string_to_host_string (elt.get ()));
if (item == NULL)
{
- /* Skip problem elements. */
- PyErr_Clear ();
+ gdbpy_print_stack ();
continue;
}
tracker.add_completion (std::move (item));
- got_matches = true;
}
-
- /* If we got some results, ignore problems. Otherwise, report
- the problem. */
- if (got_matches && PyErr_Occurred ())
- PyErr_Clear ();
}
}
gdb_start
gdb_test_no_output "source ${pyfile}" "load python file again"
+# Check that GDB prints exceptions raised by Command.complete calls.
+# This first command raises an exception during the brkchars phase of
+# completion.
+gdb_test "complete complete_brkchar_exception " \
+ "Python Exception <class 'gdb\\.GdbError'>: brkchars exception"
+
+# In this test the brkchars phase of completion is fine, but an
+# exception is raised during the actual completion phase.
+gdb_test "complete complete_raise_exception " \
+ "Python Exception <class 'gdb\\.GdbError'>: completion exception"
+
gdb_test_sequence "complete completel" \
"list all completions of 'complete completel'" {
"completelimit1"
]
+class CompleteBrkCharException(gdb.Command):
+ def __init__(self):
+ gdb.Command.__init__(self, "complete_brkchar_exception", gdb.COMMAND_USER)
+
+ def invoke(self, argument, from_tty):
+ raise gdb.GdbError("not implemented")
+
+ def complete(self, text, word):
+ if word is None:
+ raise gdb.GdbError("brkchars exception")
+ else:
+ raise gdb.GdbError("completion exception")
+
+
+class CompleteRaiseException(gdb.Command):
+ def __init__(self):
+ gdb.Command.__init__(self, "complete_raise_exception", gdb.COMMAND_USER)
+
+ def invoke(self, argument, from_tty):
+ raise gdb.GdbError("not implemented")
+
+ def complete(self, text, word):
+ if word is None:
+ return []
+ else:
+ raise gdb.GdbError("completion exception")
+
+
CompleteFileInit()
CompleteFileNone()
CompleteFileMethod()
CompleteLimit5()
CompleteLimit6()
CompleteLimit7()
+CompleteBrkCharException()
+CompleteRaiseException()