Best way to run LLVM to debug optimized binaries

It seems like I get "<optimized out>" back from gdb when running on
clang -O2 binaries much more so than with gcc -O2. So much so that I
think it's not that they're optimized out but that I'm missing some
key flag to include some key piece of debugging info. I can't believe
that "t" here is optimized out entirely given that it's one of the
function parameters and it's a pointer to a complex structure. The
function is static so it is possible it was inlined but if the assert
is failing it's hard to see how the structure would be entirely
optimized out.

#2 0x00000000010ac7c7 in cdissect (v=<optimized out>, t=<optimized

, begin=<optimized out>, end=<optimized out>) at regexec.c:653

653 assert(er != REG_NOMATCH || (t->flags & BACKR));
(gdb) p er
$1 = <optimized out>
(gdb) p t
$2 = <optimized out>

Is there some flag I should be giving to clang to get binaries that
will perform reasonably fast but still be possible to debug? How can I
tell why this variable is showing as optimized out?

It seems like I get “” back from gdb when running on
clang -O2 binaries much more so than with gcc -O2. So much so that I
think it’s not that they’re optimized out but that I’m missing some
key flag to include some key piece of debugging info. I can’t believe
that “t” here is optimized out entirely given that it’s one of the
function parameters and it’s a pointer to a complex structure. The
function is static so it is possible it was inlined but if the assert
is failing it’s hard to see how the structure would be entirely
optimized out.

#2 0x00000000010ac7c7 in cdissect (v=, t=<optimized

, begin=, end=) at regexec.c:653
653 assert(er != REG_NOMATCH || (t->flags & BACKR));
(gdb) p er
$1 =
(gdb) p t
$2 =

Is there some flag I should be giving to clang to get binaries that
will perform reasonably fast but still be possible to debug? How can I
tell why this variable is showing as optimized out?

Sorry answer to all the questions is, unfortunately, ‘no’. Optimized debug info produced by llvm isn’t ideal. There’s still a lot of work to be done to make it good and it just hasn’t been a priority for any of the contributors so far.