{
const auto gdbarch = arch_object_to_gdbarch (self);
if (gdbarch == nullptr)
- return PyUnicode_FromFormat ("<%s (invalid)>", Py_TYPE (self)->tp_name);
+ return gdb_py_invalid_object_repr (self);
auto arch_info = gdbarch_bfd_arch_info (gdbarch);
return PyUnicode_FromFormat ("<%s arch_name=%s printable_name=%s>",
{
const auto block = block_object_to_block (self);
if (block == nullptr)
- return PyUnicode_FromFormat ("<%s (invalid)>", Py_TYPE (self)->tp_name);
+ return gdb_py_invalid_object_repr (self);
const auto name = block->function () ?
block->function ()->print_name () : "<anonymous>";
{
const auto self = (gdbpy_breakpoint_location_object *) py_self;
if (self->owner == nullptr || self->owner->bp == nullptr
- || self->owner->bp != self->bp_loc->owner)
- return PyUnicode_FromFormat ("<%s (invalid)>", Py_TYPE (self)->tp_name);
+ || self->owner->bp != self->bp_loc->owner)
+ return gdb_py_invalid_object_repr (py_self);
const auto enabled = self->bp_loc->enabled ? "enabled" : "disabled";
process_stratum_target *target = self->target;
if (target == nullptr)
- return PyUnicode_FromFormat ("<%s (invalid)>", Py_TYPE (obj)->tp_name);
+ return gdb_py_invalid_object_repr (obj);
return PyUnicode_FromFormat ("<%s num=%d, what=\"%s\">",
Py_TYPE (obj)->tp_name,
inferior *inf = self->inferior;
if (inf == nullptr)
- return PyUnicode_FromString ("<gdb.Inferior (invalid)>");
+ return gdb_py_invalid_object_repr (obj);
return PyUnicode_FromFormat ("<gdb.Inferior num=%d, pid=%d>",
inf->num, inf->pid);
objfile *obj = self->objfile;
if (obj == nullptr)
- return PyUnicode_FromString ("<gdb.Objfile (invalid)>");
+ return gdb_py_invalid_object_repr (self_);
return PyUnicode_FromFormat ("<gdb.Objfile filename=%s>",
objfile_name (obj));
{
const auto symbol = symbol_object_to_symbol (self);
if (symbol == nullptr)
- return PyUnicode_FromFormat ("<%s (invalid)>", Py_TYPE (self)->tp_name);
+ return gdb_py_invalid_object_repr (self);
return PyUnicode_FromFormat ("<%s print_name=%s>", Py_TYPE (self)->tp_name,
symbol->print_name ());
{
const auto type = type_object_to_type (self);
if (type == nullptr)
- return PyUnicode_FromFormat ("<%s (invalid)>",
- Py_TYPE (self)->tp_name);
+ return gdb_py_invalid_object_repr (self);
const char *code = pyty_codes[type->code ()].name;
string_file type_name;
frame_info_ptr frame = pending_frame->frame_info;
if (frame == nullptr)
- return PyUnicode_FromFormat ("<%s (invalid)>", Py_TYPE (self)->tp_name);
+ return gdb_py_invalid_object_repr (self);
const char *sp_str = nullptr;
const char *pc_str = nullptr;
return doc;
}
+
+/* See python-internal.h. */
+
+PyObject *
+gdb_py_invalid_object_repr (PyObject *self)
+{
+ return PyUnicode_FromFormat ("<%s (invalid)>", Py_TYPE (self)->tp_name);
+}
PyObject *object)
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+
+/* Return a Python string (str) object that represents SELF. SELF can be
+ any object type, but should be in an "invalid" state. What "invalid"
+ means is up to the caller. The returned string will take the form
+ "<TYPENAME (invalid)>", without the quotes, and with TYPENAME replaced
+ with the type of SELF. */
+
+PyObject *gdb_py_invalid_object_repr (PyObject *self);
+
struct varobj_iter;
struct varobj;
std::unique_ptr<varobj_iter> py_varobj_get_iterator