aboutsummaryrefslogtreecommitdiff
path: root/gdb/python
diff options
context:
space:
mode:
Diffstat (limited to 'gdb/python')
-rw-r--r--gdb/python/python-cmd.c12
-rw-r--r--gdb/python/python-value.c24
-rw-r--r--gdb/python/python.c11
3 files changed, 26 insertions, 21 deletions
diff --git a/gdb/python/python-cmd.c b/gdb/python/python-cmd.c
index 36cde34..8f59a22 100644
--- a/gdb/python/python-cmd.c
+++ b/gdb/python/python-cmd.c
@@ -336,16 +336,16 @@ parse_command_name (char *text, struct cmd_list_element ***base_list)
/* Object initializer; sets up gdb-side structures for command.
- Use: __init__(NAME, CMDCLASS, [COMPLETERCLASS, [PREFIX]]).
+ Use: __init__(NAME, COMMAND_CLASS [, COMPLETER_CLASS][, PREFIX]]).
NAME is the name of the command. It may consist of multiple words,
in which case the final word is the name of the new command, and
earlier words must be prefix commands.
- CMDCLASS is the kind of command. It should be one of the COMMAND_*
+ COMMAND_CLASS is the kind of command. It should be one of the COMMAND_*
constants defined in the gdb module.
- COMPLETERCLASS is the kind of completer. If not given, the
+ COMPLETER_CLASS is the kind of completer. If not given, the
"complete" method will be used. Otherwise, it should be one of the
COMPLETE_* constants defined in the gdb module.
@@ -356,7 +356,7 @@ parse_command_name (char *text, struct cmd_list_element ***base_list)
*/
static int
-cmdpy_init (PyObject *self, PyObject *args, PyObject *kwds)
+cmdpy_init (PyObject *self, PyObject *args, PyObject *kw)
{
cmdpy_object *obj = (cmdpy_object *) self;
char *name;
@@ -366,6 +366,8 @@ cmdpy_init (PyObject *self, PyObject *args, PyObject *kwds)
volatile struct gdb_exception except;
struct cmd_list_element **cmd_list;
char *cmd_name, *pfx_name;
+ static char *keywords[] = { "name", "command_class", "completer_class",
+ "prefix", NULL };
PyObject *is_prefix = NULL;
int cmp;
@@ -378,7 +380,7 @@ cmdpy_init (PyObject *self, PyObject *args, PyObject *kwds)
return -1;
}
- if (! PyArg_ParseTuple (args, "si|iO", &name, &cmdtype,
+ if (! PyArg_ParseTupleAndKeywords (args, kw, "si|iO", keywords, &name, &cmdtype,
&completetype, &is_prefix))
return -1;
diff --git a/gdb/python/python-value.c b/gdb/python/python-value.c
index bc077b6..cbc481f 100644
--- a/gdb/python/python-value.c
+++ b/gdb/python/python-value.c
@@ -143,10 +143,11 @@ valpy_address (PyObject *self, PyObject *args)
return value_to_value_object (res_val);
}
-/* Return Unicode string with value contents (assumed to be encoded in the
- target's charset). */
+/* Implementation of gdb.Value.string ([encoding] [, errors]) -> string
+ Return Unicode string with value contents. If ENCODING is not given,
+ the string is assumed to be encoded in the target's charset. */
static PyObject *
-valpy_string (PyObject *self, PyObject *args)
+valpy_string (PyObject *self, PyObject *args, PyObject *kw)
{
int length, ret = 0;
gdb_byte *buffer;
@@ -157,8 +158,10 @@ valpy_string (PyObject *self, PyObject *args)
const char *errors = NULL;
const char *user_encoding = NULL;
const char *la_encoding = NULL;
+ static char *keywords[] = { "encoding", "errors" };
- if (!PyArg_ParseTuple (args, "|ss", &user_encoding, &errors))
+ if (!PyArg_ParseTupleAndKeywords (args, kw, "|ss", keywords,
+ &user_encoding, &errors))
return NULL;
TRY_CATCH (except, RETURN_MASK_ALL)
@@ -306,11 +309,11 @@ valpy_binop (enum valpy_opcode opcode, PyObject *self, PyObject *other)
a gdb.Value object and need to convert it from python as well. */
arg1 = convert_value_from_python (self);
if (arg1 == NULL)
- return NULL;
+ break;
arg2 = convert_value_from_python (other);
if (arg2 == NULL)
- return NULL;
+ break;
switch (opcode)
{
@@ -387,7 +390,7 @@ valpy_binop (enum valpy_opcode opcode, PyObject *self, PyObject *other)
}
GDB_PY_HANDLE_EXCEPTION (except);
- return value_to_value_object (res_val);
+ return res_val ? value_to_value_object (res_val) : NULL;
}
static PyObject *
@@ -774,7 +777,7 @@ convert_value_from_python (PyObject *obj)
}
}
else if (PyObject_TypeCheck (obj, &value_object_type))
- value = ((value_object *) obj)->value;
+ value = value_copy (((value_object *) obj)->value);
else
PyErr_Format (PyExc_TypeError, _("Could not convert Python object: %s"),
PyString_AsString (PyObject_Str (obj)));
@@ -825,8 +828,9 @@ gdbpy_initialize_values (void)
static PyMethodDef value_object_methods[] = {
{ "address", valpy_address, METH_NOARGS, "Return the address of the value." },
{ "dereference", valpy_dereference, METH_NOARGS, "Dereferences the value." },
- { "string", valpy_string, METH_VARARGS,
- "Return Unicode string representation of the value." },
+ { "string", (PyCFunction) valpy_string, METH_VARARGS | METH_KEYWORDS,
+ "string ([encoding] [, errors]) -> string\n\
+Return Unicode string representation of the value." },
{NULL} /* Sentinel */
};
diff --git a/gdb/python/python.c b/gdb/python/python.c
index 29f83bb..b48cf05 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -206,6 +206,7 @@ get_parameter (PyObject *self, PyObject *args)
{
struct cmd_list_element *alias, *prefix, *cmd;
char *arg, *newarg;
+ int found = -1;
volatile struct gdb_exception except;
if (! PyArg_ParseTuple (args, "s", &arg))
@@ -215,15 +216,13 @@ get_parameter (PyObject *self, PyObject *args)
TRY_CATCH (except, RETURN_MASK_ALL)
{
- if (! lookup_cmd_composition (newarg, &alias, &prefix, &cmd))
- {
- xfree (newarg);
- return PyErr_Format (PyExc_RuntimeError,
- "could not find variable `%s'", arg);
- }
+ found = lookup_cmd_composition (newarg, &alias, &prefix, &cmd);
}
xfree (newarg);
GDB_PY_HANDLE_EXCEPTION (except);
+ if (!found)
+ return PyErr_Format (PyExc_RuntimeError,
+ "could not find parameter `%s'", arg);
if (! cmd->var)
return PyErr_Format (PyExc_RuntimeError, "`%s' is not a variable", arg);