This is an archive of the discontinued LLVM Phabricator instance.

[lldb] DynamicRegisterInfo: fix wrong regnos in Dump()
AbandonedPublic

Authored by mgorny on Aug 26 2021, 8:20 AM.

Details

Summary

Fix the DynamicRegisterInfo::Dump() method to correctly assume that
the register numbers in value_regs and invalidate_regs arrays are
remote (eRegisterKindProcessPlugin) rather than local
(eRegisterKindLLDB). This fixes invalid memory references when the two
register numbers are not in sync.

Diff Detail

Event Timeline

mgorny requested review of this revision.Aug 26 2021, 8:20 AM
mgorny created this revision.
mgorny planned changes to this revision.Aug 26 2021, 8:30 AM

TestRemoteRegNums suggests that there's also code relying on remote regnums being used there. What a mess :-(.

mgorny abandoned this revision.Aug 26 2021, 12:04 PM

Ok, I think it might just be Dump() being broken. I've found another bug with my code, and things seem to work after fixing it, so I suppose the problem is not really worth my effort right now.

mgorny updated this revision to Diff 369042.Aug 27 2021, 1:21 AM
mgorny retitled this revision from [lldb] [DynamicRegisterInfo] Fix mistaken reg type when calculating offsets to [lldb] DynamicRegisterInfo: fix wrong regnos in Dump().
mgorny edited the summary of this revision. (Show Details)

So I've given it some thought and found a simple fix.

mgorny updated this revision to Diff 369048.Aug 27 2021, 2:22 AM

Also updated the comments in struct RegisterInfo to indicate what kind of numbers go in these arrays.

I'm not sure if this is correct, or if I want it to be correct. I think that a lot of the confusion comes from the fact that this structure is used both in lldb-server and lldb, and I'm not sure that the fields have the same meaning in both cases (specifically, the "process plugin" concept is not really a thing in lldb-server). I think it would be better to standardize on the "lldb" numbers, as those should be available everywhere, but I may be forgetting some important issues. Omair may remember this in more detail.

This is complicated mainly because we are trying to merge two different register numbering scheme. On LLDB (host) side we try to construct register number from parsing register xml assigning register numbers in the increasing order. But we also have target supplied register numbers in regnum field. However registers on LLDB server side have fixed numbering although it may look like assigned in increasing order but this may not always be the case. Presence of optional register sets also doesnt help so we have the mess on managing target vs host register numbers not always in sync.

For invalidate_regs and value_regs register numbers should always be the ones assigned by remote i-e eRegisterKindProcessPlugin. So I would say this patch is ok as it corrects that info.

Broadly speaking we should do something about integrating user typed registers which may be unions of various other registers but should not require numbering.

mgorny abandoned this revision.Sep 19 2021, 11:13 AM

Replaced by D110027.