Page MenuHomePhabricator

[LLDB] Round XML register bitsize to byte boundary

Authored by omjavaid on Oct 5 2021, 3:36 AM.



This patch allows LLDB to accept register sizes which are not aligned
to 8 bits bitsize boundary. This fixes a crash in LLDB when connecting
to OpenOCD stub. GDB xml description allows for non-aligned bit lengths
but they are rounded off to nearest byte during transfer. In case of
OpenOCD some of SOC specific system registers were less than a single
byte in length and were causing LLDB to crash.

Diff Detail

Event Timeline

omjavaid requested review of this revision.Oct 5 2021, 3:36 AM
omjavaid created this revision.
mgorny added inline comments.Oct 5 2021, 3:39 AM

I suppose LLDB crashed because byte_size was zero? Maybe add an assert for that then.

omjavaid added inline comments.Oct 5 2021, 3:44 AM

@mgorny the assert already exists but then we also want to allow bit sized registers although they ll be viewed as byte length for now.

mgorny added inline comments.Oct 5 2021, 3:47 AM

Ah, right. I suppose you could skip zero-byte registers though. That should amend the assert with better release behavior.

omjavaid added inline comments.Oct 5 2021, 4:00 AM

on a second thought, I dont see a zero sized register being sent by stub as a big enough reason to abort the whole debug session unless its one of GPRs. May be we skip the assert altogether and replace it with an error message.
What do you think?

mgorny added inline comments.Oct 5 2021, 4:02 AM

Yes, you are correct. Probably LLDB_LOG would go in line with how we handle these things.

omjavaid added inline comments.Oct 5 2021, 4:06 AM

LLDB_LOG will hide message from user unless log is enabled. I think user must be notified that register is zero sized and thats why you wont be able to see it in register read. Similar to the way we notify user about unhandled register attibutes like "save-restore".

labath accepted this revision.Oct 5 2021, 4:06 AM
labath added inline comments.

llvm::divideCeil(reg_info.byte_size, CHAR_BIT), perhaps


Yeah, I don't think crashing is a good response to the stub sending us nonsensical register definitions. Though that seems like a separate issue..

This revision is now accepted and ready to land.Oct 5 2021, 4:06 AM
labath added inline comments.Oct 5 2021, 4:10 AM

BTW, I came very close to deleting that printf when I was touching this code last month.
FWIW, my hierarchy is:
user-facing warning (though I don't know how would that be implemented here) >> log entry >> nothing >> raw printf

ted added a subscriber: ted.Oct 5 2021, 7:38 AM
ted added inline comments.

+1 on not crashing. The remote sending us garbage shouldn't cause us to crash - we should try to make sense of the garbage, and if we can't, error out gracefully. Better to print an error and ignore the register than crash or abort the session.

omjavaid updated this revision to Diff 377470.Oct 6 2021, 1:55 AM

This addresses review comments converts printfs to log messages.

This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptOct 6 2021, 2:04 AM