How to break in debugger when -fsanitize=undefined prints something?

Hello,

I'm trying out the -fsanitize=undefined option with clang
(Linux, x86-64) and I'm getting a few runtime warnings
with the code I'm working with.

I'd like to set a breakpoint on a function that prints these
warnings so that I can actually see the backtrace, but
I can't figure out how to do that.

I know there's -fsanitize-undefined-trap-on-error, but it
causes "Illegal Instruction" on the first warning, and due
to this warning being in another library, I cannot fix it and
continue to my own code.

Here's one of the warnings I get, but cannot debug because
I cannot find the actual location:
liblocal_qwt.so:0x4732fe: runtime error: load of value 4294967199, which is not a valid value for type 'Qt::AlignmentFlag'

Thanks in advance,
Alexander

For this error, you can break on __ubsan_handle_type_mismatch.

We don’t have documentation explaining how the checks map to handler functions yet. To find the handler name in general, you can build a program which exhibits the diagnostic with -fno-sanitize-recover, break on calls to ‘__sanitizer::Die()’, and find the _ubsan_handle* function in the backtrace.

I would also like to include a backtrace with the ubsan warnings, but that is not implemented yet. Patches very much welcome! (The backtrace functionality from the other sanitizers could almost certainly be reused here.)

Hello,

> Here's one of the warnings I get, but cannot debug because
> I cannot find the actual location:
> liblocal_qwt.so:0x4732fe: runtime error: load of value 4294967199,
> which is not a valid value for type 'Qt::AlignmentFlag'

For this error, you can break on __ubsan_handle_type_mismatch.

For this particular warning I found that the correct function is
__ubsan_handle_load_invalid_value.

We don't have documentation explaining how the checks map to handler
functions yet. To find the handler name in general, you can build a
program which exhibits the diagnostic with -fno-sanitize-recover, break
on calls to '__sanitizer::Die()', and find the __ubsan_handle_*
function in the backtrace.

Yes, the lack of documentation (including on the switch you mention)
is unfortunate. I found that an easier way to do this is to search the
warning text in "projects/compiler-rt/lib/ubsan/ubsan_handlers.cc" and
just break on the function name it's mentioned in.

I would also like to include a backtrace with the ubsan warnings, but
that is not implemented yet. Patches very much welcome! (The backtrace
functionality from the other sanitizers could almost certainly be reused
here.)

Yes, a backtrace would be great! Not sure I'm able to provide any
patches at this point though.

Thanks a lot for your help,
Alexander