Re: [PATCH v3 16/24] AArch64: Report tag violation error information

Luis Machado via Gdb-patches
2020-12-30T00:51:10Z

On 12/26/20 7:23 PM, Simon Marchi wrote:
>
>
> On 2020-11-09 12:04 p.m., Luis Machado via Gdb-patches wrote:
>> Whenever a memory tag violation occurs, we get a SIGSEGV. Additional
>> information can be obtained through the siginfo data structure.
>>
>> For AArch64 the Linux kernel may expose the fault address and tag
>> information, if we have a synchronous event. Otherwise there is
>> no fault address available.
>
> Can you give an example of the end result message?
>

I've attached it to the commit message.

The synchronous event looks like this:

--
(gdb) continue
Continuing.

Program received signal SIGSEGV, Segmentation fault
Memory tag violation while accessing address 0x0000fffff7ff8000
Allocation tag 0x1.
--

The asynchronous event looks like this:

--
(gdb) continue
Continuing.

Program received signal SIGSEGV, Segmentation fault
Memory tag violation
Fault address unavailable.
--

>>
>> gdb/ChangeLog:
>>
>> YYYY-MM-DD Luis Machado <luis.machado@linaro.org>
>>
>> * aarch64-linux-tdep.c
>> (aarch64_linux_report_signal_info): New function.
>> (aarch64_linux_init_abi): Register
>> aarch64_linux_report_signal_info as the report_signal_info hook.
>> * arch/aarch64-linux.h (SEGV_MTEAERR): Define.
>> (SEGV_MTESERR): Define.
>> ---
>> gdb/aarch64-linux-tdep.c | 64 ++++++++++++++++++++++++++++++++++++
>> gdb/arch/aarch64-mte-linux.h | 6 ++++
>> 2 files changed, 70 insertions(+)
>>
>> diff --git a/gdb/aarch64-linux-tdep.c b/gdb/aarch64-linux-tdep.c
>> index 39b1790263..70e180e1cb 100644
>> --- a/gdb/aarch64-linux-tdep.c
>> +++ b/gdb/aarch64-linux-tdep.c
>> @@ -1626,6 +1626,67 @@ aarch64_linux_memtag_to_string (struct gdbarch *gdbarch,
>> return string_printf ("0x%s", phex_nz (tag, sizeof (tag)));
>> }
>>
>> +/* AArch64 Linux implementation of the report_signal_info gdbarch
>> + hook. Displays information about possible memory tag violations. */
>> +
>> +static void
>> +aarch64_linux_report_signal_info (struct gdbarch *gdbarch,
>> + struct ui_out *uiout,
>> + enum gdb_signal siggnal)
>> +{
>> + struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
>> +
>> + if (!tdep->has_mte () || siggnal != GDB_SIGNAL_SEGV)
>> + return;
>> +
>> + CORE_ADDR fault_addr = 0;
>> + long si_code = 0;
>> +
>> + try
>> + {
>> + /* Sigcode tells us if the segfault is actually a memory tag
>> + violation. */
>> + si_code = parse_and_eval_long ("$_siginfo.si_code\n");
>
> Is the \n necessary?
>

No. Fixed now.

>> +
>> + fault_addr
>> + = parse_and_eval_long ("$_siginfo._sifields._sigfault.si_addr");
>> + }
>> + catch (const gdb_exception &exception)
>> + {
>> + return;
>> + }
>
> I think it's better to catch gdb_exception_error, to avoid catching ^C
> (gdb_exception_quit).
>
> And if there's an error doing the evaluation... do we want to print
> a warning of some sort?
>

I went with printing the exception with...

exception_print (gdb_stderr, exception);

> Simon
>