2017-04-05 Pedro Alves <palves@redhat.com>
+ * python/python-internal.h (gdb_PyGetSetDef): New type.
+ * python/py-block.c (block_object_getset)
+ (breakpoint_object_getset): Now a gdb_PyGetSetDef array.
+ * python/py-event.c (event_object_getset)
+ (finish_breakpoint_object_getset): Likewise.
+ * python/py-inferior.c (inferior_object_getset): Likewise.
+ * python/py-infthread.c (thread_object_getset): Likewise.
+ * python/py-lazy-string.c (lazy_string_object_getset): Likewise.
+ * python/py-linetable.c (linetable_entry_object_getset): Likewise.
+ * python/py-objfile.c (objfile_getset): Likewise.
+ * python/py-progspace.c (pspace_getset): Likewise.
+ * python/py-record-btrace.c (btpy_insn_getset, btpy_call_getset):
+ Likewise.
+ * python/py-record.c (recpy_record_getset): Likewise.
+ * python/py-symbol.c (symbol_object_getset): Likewise.
+ * python/py-symtab.c (symtab_object_getset, sal_object_getset):
+ Likewise.
+ * python/py-type.c (type_object_getset, field_object_getset):
+ Likewise.
+ * python/py-value.c (value_object_getset): Likewise.
+
+2017-04-05 Pedro Alves <palves@redhat.com>
+
* python/python-internal.h (gdb_PyObject_CallMethod)
(gdb_PyErr_NewException, gdb_PySys_GetObject, gdb_PySys_SetPath):
New functions.
{NULL} /* Sentinel */
};
-static PyGetSetDef block_object_getset[] = {
+static gdb_PyGetSetDef block_object_getset[] = {
{ "start", blpy_get_start, NULL, "Start address of the block.", NULL },
{ "end", blpy_get_end, NULL, "End address of the block.", NULL },
{ "function", blpy_get_function, NULL,
return PyObject_GenericSetAttr ((PyObject *)self, name, v);
}
-static PyGetSetDef breakpoint_object_getset[] = {
+static gdb_PyGetSetDef breakpoint_object_getset[] = {
{ "enabled", bppy_get_enabled, bppy_set_enabled,
"Boolean telling whether the breakpoint is enabled.", NULL },
{ "silent", bppy_get_silent, bppy_set_silent,
return 0;
}
-static PyGetSetDef event_object_getset[] =
+static gdb_PyGetSetDef event_object_getset[] =
{
{ "__dict__", gdb_py_generic_dict, NULL,
"The __dict__ for this event.", &event_object_type },
return 0;
}
-static PyGetSetDef finish_breakpoint_object_getset[] = {
+static gdb_PyGetSetDef finish_breakpoint_object_getset[] = {
{ "return_value", bpfinishpy_get_returnvalue, NULL,
"gdb.Value object representing the return value, if any. \
None otherwise.", NULL },
&membuf_object_type);
}
-static PyGetSetDef inferior_object_getset[] =
+static gdb_PyGetSetDef inferior_object_getset[] =
{
{ "num", infpy_get_num, NULL, "ID of inferior, as assigned by GDB.", NULL },
{ "pid", infpy_get_pid, NULL, "PID of inferior, as assigned by the OS.",
(PyObject *) &thread_object_type);
}
-static PyGetSetDef thread_object_getset[] =
+static gdb_PyGetSetDef thread_object_getset[] =
{
{ "name", thpy_get_name, thpy_set_name,
"The name of the thread, as set by the user or the OS.", NULL },
};
-static PyGetSetDef lazy_string_object_getset[] = {
+static gdb_PyGetSetDef lazy_string_object_getset[] = {
{ "address", stpy_get_address, NULL, "Address of the string.", NULL },
{ "encoding", stpy_get_encoding, NULL, "Encoding of the string.", NULL },
{ "length", stpy_get_length, NULL, "Length of the string.", NULL },
};
-static PyGetSetDef linetable_entry_object_getset[] = {
+static gdb_PyGetSetDef linetable_entry_object_getset[] = {
{ "line", ltpy_entry_get_line, NULL,
"The line number in the source file.", NULL },
{ "pc", ltpy_entry_get_pc, NULL,
{ NULL }
};
-static PyGetSetDef objfile_getset[] =
+static gdb_PyGetSetDef objfile_getset[] =
{
{ "__dict__", gdb_py_generic_dict, NULL,
"The __dict__ for this objfile.", &objfile_object_type },
\f
-static PyGetSetDef pspace_getset[] =
+static gdb_PyGetSetDef pspace_getset[] =
{
{ "__dict__", gdb_py_generic_dict, NULL,
"The __dict__ for this progspace.", &pspace_object_type },
/* BtraceInstruction members. */
-struct PyGetSetDef btpy_insn_getset[] =
+struct gdb_PyGetSetDef btpy_insn_getset[] =
{
{ "number", btpy_number, NULL, "instruction number", NULL},
{ "error", btpy_insn_error, NULL, "error number for gaps", NULL},
/* BtraceFunctionCall members. */
-static PyGetSetDef btpy_call_getset[] =
+static gdb_PyGetSetDef btpy_call_getset[] =
{
{ "number", btpy_number, NULL, "function call number", NULL},
{ "level", btpy_call_level, NULL, "call stack level", NULL},
/* Record member list. */
-static PyGetSetDef recpy_record_getset[] = {
+static gdb_PyGetSetDef recpy_record_getset[] = {
{ "ptid", recpy_ptid, NULL, "Current thread.", NULL },
{ "method", recpy_method, NULL, "Current recording method.", NULL },
{ "format", recpy_format, NULL, "Current recording format.", NULL },
\f
-static PyGetSetDef symbol_object_getset[] = {
+static gdb_PyGetSetDef symbol_object_getset[] = {
{ "type", sympy_get_type, NULL,
"Type of the symbol.", NULL },
{ "symtab", sympy_get_symtab, NULL,
\f
-static PyGetSetDef symtab_object_getset[] = {
+static gdb_PyGetSetDef symtab_object_getset[] = {
{ "filename", stpy_get_filename, NULL,
"The symbol table's source filename.", NULL },
{ "objfile", stpy_get_objfile, NULL, "The symtab's objfile.",
symtab_object_getset /*tp_getset */
};
-static PyGetSetDef sal_object_getset[] = {
+static gdb_PyGetSetDef sal_object_getset[] = {
{ "symtab", salpy_get_symtab, NULL, "Symtab object.", NULL },
{ "pc", salpy_get_pc, NULL, "Return the symtab_and_line's pc.", NULL },
{ "last", salpy_get_last, NULL,
\f
-static PyGetSetDef type_object_getset[] =
+static gdb_PyGetSetDef type_object_getset[] =
{
{ "code", typy_get_code, NULL,
"The code for this type.", NULL },
0, /* tp_new */
};
-static PyGetSetDef field_object_getset[] =
+static gdb_PyGetSetDef field_object_getset[] =
{
{ "__dict__", gdb_py_generic_dict, NULL,
"The __dict__ for this field.", &field_object_type },
\f
-static PyGetSetDef value_object_getset[] = {
+static gdb_PyGetSetDef value_object_getset[] = {
{ "address", valpy_get_address, NULL, "The address of the value.",
NULL },
{ "is_optimized_out", valpy_get_is_optimized_out, NULL,
#define PySys_SetPath gdb_PySys_SetPath
+/* Wrap PyGetSetDef to allow convenient construction with string
+ literals. Unfortunately, PyGetSetDef's 'name' and 'doc' members
+ are 'char *' instead of 'const char *', meaning that in order to
+ list-initialize PyGetSetDef arrays with string literals (and
+ without the wrapping below) would require writing explicit 'char *'
+ casts. Instead, we extend PyGetSetDef and add constexpr
+ constructors that accept const 'name' and 'doc', hiding the ugly
+ casts here in a single place. */
+
+struct gdb_PyGetSetDef : PyGetSetDef
+{
+ constexpr gdb_PyGetSetDef (const char *name_, getter get_, setter set_,
+ const char *doc_, void *closure_)
+ : PyGetSetDef {const_cast<char *> (name_), get_, set_,
+ const_cast<char *> (doc_), closure_}
+ {}
+
+ /* Alternative constructor that allows omitting the closure in list
+ initialization. */
+ constexpr gdb_PyGetSetDef (const char *name_, getter get_, setter set_,
+ const char *doc_)
+ : gdb_PyGetSetDef {name_, get_, set_, doc_, NULL}
+ {}
+
+ /* Constructor for the sentinel entries. */
+ constexpr gdb_PyGetSetDef (std::nullptr_t)
+ : gdb_PyGetSetDef {NULL, NULL, NULL, NULL, NULL}
+ {}
+};
+
/* In order to be able to parse symtab_and_line_to_sal_object function
a real symtab_and_line structure is needed. */
#include "symtab.h"