RE: [PATCH v10 08/10] btrace, linux: Enable ptwrite packets.

Metzger, Markus T via Gdb-patches
2023-09-06T14:08:31Z

Hello Felix,

>> >I looked at doing it when installing the extension language callback
>> >for ptwrite in btrace.c, e.g. something similar to this:
>> >
>> > /* Register the ptwrite filter. */
>> > if (btinfo->target->conf.pt.ptwrite)
>> > apply_ext_lang_ptwrite_filter (btinfo);
>> > else
>> > warning (_("Can't decode ptwrite events."));
>> >
>> >This we do regardless of libipt. But then we would get a warning
>> >regardless of the user trying to use ptwrite or not (with old libipt
>> >versions). Plus this doesn't compile, as struct btrace_target_info
>> >is forward declared, and we probably can't change that as btrace.c
>> >should be target independent.
>>
>> We'd want the check inside gdbpy_load_ptwrite_filter(), which gets
>> called by apply_ext_lang_ptwrite_filter() to install the btrace callback.
>
>If I add a similar warning to what I posted above for btrace.c, to
>python/py-record-btrace.c:gdbpy_load_ptwrite_filter(), I still can't
>compile. I get the following error:
>
>py-record-btrace.c:906:22: error: invalid use of incomplete type ?struct
>btrace_target_info?
> 906 | if (!btinfo->target->conf.pt.ptwrite)
>
>The solution would be to include nat/linux-btrace.h to the file, or to move
>that struct to some other common header, e.g. btrace-common.h.
>I don't think either is possible, it is adding linux specific things to common files.
>Or is there any other solution that I missed?
>
>Another point is, even if I would put it there, gdbpy_load_ptwrite_filter()
>is called regardless of the user having installed a python filter.
>But I think we could additionally check that get_ptwrite_filter() didn't return
>Py_None to avoid that issue.

Yes, that's what I meant. Warn if a ptwrite filter is installed but ptwrite is not
supported.

We cannot use btrace_target_info directly, so we'd need to add another function
to check whether ptwrite is supported/enabled on the target.

regards,
markus.