This is an archive of the discontinued LLVM Phabricator instance.

Set error message if ValueObjectRegister fails to write back to register
ClosedPublic

Authored by ilya-nozhkin on Feb 22 2022, 4:43 AM.

Details

Summary

SetValueFromCString and SetData methods return false if register can't
be written but they don't set a error message. It sometimes confuses callers of
these methods because they try to get the error message in case of failure but
Status::AsCString returns nullptr.

For example, lldb-vscode crashes due to this bug if some register can't be
written. It invokes SBError::GetCString in case of error and doesn't check
whether the result is nullptr (see request_setVariable implementation in
lldb-vscode.cpp for more info).

Diff Detail

Event Timeline

ilya-nozhkin created this revision.Feb 22 2022, 4:43 AM
ilya-nozhkin requested review of this revision.Feb 22 2022, 4:43 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 22 2022, 4:43 AM

Core files have read-only registers. Would that help? (you could just throw in a SetValueFromCString call into one of the existing core file tests)

Core files have read-only registers. Would that help? (you could just throw in a SetValueFromCString call into one of the existing core file tests)

Actually I believe we allow writing registers for core files. This was requested so that people could fix the registers like SP or FP and the get a real backtrace. Since core files contain crashes, people wanted to be able to make sure they could get a backtrace.

Code looks good. Lets see if we can test it with a core file. I am guessing we can't from my previous comment, but it would be worth checking

ilya-nozhkin edited the summary of this revision. (Show Details)

Added a test based on core files debugging. RegisterContextCorePOSIX_x86_64 indeed forbids writing registers.

So, it seems we were all correct. The mach-o core file implementation does permit writing registers, while the elf one doesn't. I guess we never got that feature request for elf.

I don't think that's a blocker for writing this test though. If we decide to support writing registers in for elf too, we can always change/remove the test.

Another possibility is to use the gdb-client test infrastructure to simulate a server which refuses to write to a register, but those tests are slightly tricky to write, so I don't think that's worth it here (unless you're interested in getting to know that infra, that is).

lldb/test/API/functionalities/postmortem/elf-core/TestLinuxCore.py
151–152

I don't think there's a valid reason for why should this ever fail.

Replaced redundant check in the test with assert. Also, I've removed type annotations to be consistent with the code around.

Another possibility is to use the gdb-client test infrastructure to simulate a server which refuses to write to a register

It would be the most proper way, I agree, but I think that it is an overkill for such a simple case.

labath accepted this revision.Feb 25 2022, 2:33 AM
This revision is now accepted and ready to land.Feb 25 2022, 2:33 AM
clayborg accepted this revision.Feb 27 2022, 11:57 AM

Great, thanks for adding the test.

Could someone, please, commit these changes to the main repository? I still don't have commit access. I'll apply for it right after merging these changes (LLVM Developer Policy states that it'd be better to have several patches already submitted before applying for commit access).

Could someone, please, commit these changes to the main repository? I still don't have commit access. I'll apply for it right after merging these changes (LLVM Developer Policy states that it'd be better to have several patches already submitted before applying for commit access).

What's your name and email address for this patch? I'd love to commit it.

What's your name and email address for this patch?

Ilya Nozhkin
nozhkin.ii@gmail.com

What's your name and email address for this patch?

Ilya Nozhkin
nozhkin.ii@gmail.com

Done~