RE: [PATCH v10 05/10] python: Introduce gdb.RecordAuxiliary class.

Willgerodt, Felix via Gdb-patches
2023-08-09T09:33:19Z

> >> >@@ -455,10 +511,10 @@ btpy_list_item (PyObject *self, Py_ssize_t index)
> >> >
> >> > number = obj->first + (obj->step * index);
> >> >
> >> >- if (obj->element_type == &recpy_insn_type)
> >> >- return recpy_insn_new (obj->thread, RECORD_METHOD_BTRACE,
> number);
> >> >- else
> >> >+ if (obj->element_type == &recpy_func_type)
> >> > return recpy_func_new (obj->thread, RECORD_METHOD_BTRACE,
> number);
> >> >+ else
> >> >+ return btpy_item_new (obj->thread, number);
> >> > }
> >>
> >> Why do we need to change the order?
> >
> >Because we no longer call recpy_insn_new only for recpy_insn_type but also for
> >recpy_aux_type.
>
> I think it would be clearer if we checked each type separately and errored
> out by default. Like a switch.

I can put something like this:

if (obj->element_type == &recpy_func_type)
return recpy_func_new (obj->thread, RECORD_METHOD_BTRACE, number);
else if (obj->element_type == &recpy_insn_type
|| obj->element_type == &recpy_aux_type)
return btpy_item_new (obj->thread, number);
else
return PyErr_Format (gdbpy_gdb_error, _("Not a valid BtraceList object."));

I don't think we can reach the error case right now though.

Felix