This is an archive of the discontinued LLVM Phabricator instance.

[lldb] [DynamicRegisterInfo] Unset value_regs/invalidate_regs before Finalize()
ClosedPublic

Authored by mgorny on Sep 16 2021, 6:15 AM.

Details

Summary

Set value_regs and invalidate_regs in RegisterInfo pushed onto m_regs
to nullptr, to ensure that the temporaries passed there are not
accidentally used.

Diff Detail

Event Timeline

mgorny requested review of this revision.Sep 16 2021, 6:15 AM
mgorny created this revision.

Now, a fun fact: ProcessGDBRemote has already been passing temporaries. We probably didn't notice it's broken simply because lldb-server didn't send value_regs.

So, does this fix like an existing test or something? Maybe you could write a unit test for it?

mgorny updated this revision to Diff 372919.Sep 16 2021, 6:43 AM

Now with a trivial unit test.

mgorny abandoned this revision.Sep 16 2021, 11:20 AM

Ok, I see now that I was wrong. DynamicRegisterInfo::Finalize() already does that. I've finally managed to figure out what this scary code does ;-).

FWIW, I think that doing this stuff immediately is a actually good idea. It avoids having a time window where info->value_regs is a dangling pointer, and it doesn't save us any work, since this is something we have to do anyway...

(Though, if we're going to be modifying/expanding these lists in subsequent AddRegister calls, then maybe it does not make that much sense...)

mgorny updated this revision to Diff 373412.Sep 18 2021, 6:30 AM
mgorny retitled this revision from [lldb] [DynamicRegisterInfo] Update RegisterInfo with copy of value_regs/invalidate_regs to [lldb] [DynamicRegisterInfo] Replace value_regs/invalidate_regs in AddRegister().
mgorny edited the summary of this revision. (Show Details)

Revive. Move sorting & making unique into AddRegister(). Add a unittest.

mgorny updated this revision to Diff 373426.Sep 18 2021, 11:07 AM

clang-format

As I alluded to in the second comment, I'm not sure this is really that much helpful, since it's also nice to have all invalidate_regs handling happen in a single function. Maybe AddRegister should just set this field to null (to give a more predictable behavior (crash) if anyone accesses it), and have a comment saying that it will be filled in in Finalize ?

Sure, I suppose either way works for me.

mgorny updated this revision to Diff 373511.Sep 20 2021, 1:39 AM
mgorny retitled this revision from [lldb] [DynamicRegisterInfo] Replace value_regs/invalidate_regs in AddRegister() to [lldb] [DynamicRegisterInfo] Unset value_regs/invalidate_regs before Finalize().
mgorny edited the summary of this revision. (Show Details)

Unset the pointers instead.

labath accepted this revision.Sep 20 2021, 2:02 AM
This revision is now accepted and ready to land.Sep 20 2021, 2:02 AM
This revision was landed with ongoing or failed builds.Sep 20 2021, 6:03 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptSep 20 2021, 6:03 AM