This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Use translated full ftag values
ClosedPublic

Authored by mgorny on Nov 15 2020, 10:26 AM.

Details

Summary

Translate between abridged and full ftag values in order to expose
the latter in the gdb-remote protocol while the former are used by
FXSAVE/XSAVE... This matches the gdb behavior.

Diff Detail

Event Timeline

mgorny requested review of this revision.Nov 15 2020, 10:26 AM
mgorny created this revision.

I'll port to other platforms once we agree on the approach.

lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.cpp
535

@labath, any suggestion what kind of test to use here? Maybe against &m_xstate->fxsave.ftag address?

Looks reasonable to me.

lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.cpp
535

You mean, like, how to detect that we're dealing with the ftag register?

This approach seems reasonable to me..

lldb/source/Plugins/Process/Utility/RegisterContext_x86.h
386

This is probably complex enough to deserve creating a cpp file (and a header comment explaining the high-level purpose of the function).

386

Also, probably ArrayRef<MMSReg> instead of the raw pointer.

lldb/unittests/Process/Utility/RegisterContextTest.cpp
32

Add const, for good measure (I see that will result in additional const qualifications in a bunch of places.

mgorny added inline comments.Nov 16 2020, 8:42 AM
lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.cpp
535

This = checking register number like in the code (in which I suppose we'd have to move distinguishing amd64/i386 to ctor like first_fpr? Or checking for actual pointer as I suggested in the comment?

mgorny marked 3 inline comments as done.Nov 16 2020, 8:53 AM
mgorny updated this revision to Diff 305536.Nov 16 2020, 8:59 AM

Move the functions into a new file, add comment, use llvm::ArrayRef.

mgorny updated this revision to Diff 305545.Nov 16 2020, 10:07 AM

Port NetBSD plugin.

labath added inline comments.Nov 18 2020, 2:12 AM
lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.cpp
535

I originally meant the register number approach, but I see what you mean now.

I think that going off of the address is perfectly fine...

mgorny updated this revision to Diff 306159.Nov 18 2020, 10:40 AM
mgorny retitled this revision from [lldb] Use translated full ftag values [WIP] to [lldb] Use translated full ftag values.

Updated Linux to use pointer comparison and FreeBSD. It's ready for review now, though I'd use a better suggestion for FreeBSD.

Looks good. Some minor questions inline.

lldb/source/Plugins/Process/FreeBSDRemote/NativeRegisterContextFreeBSD_x86_64.cpp
521

if you make data a void*, then you can remove the reinterpret_cast two lines below.

526

reuse data from above

lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.cpp
537

Is this really needed? I would have hoped that just passing m_xstate->fxsave.stmm would be enough and that the c array constructor of ArrayRef would do the right thing...

lldb/unittests/Process/Utility/RegisterContextTest.cpp
56

add SCOPED_TRACE macro to make it clear which test case failed, when it fails. You can use llvm::enumerate to produce sequence numbers for the test cases...

mgorny marked 4 inline comments as done.Nov 19 2020, 1:47 AM
mgorny added inline comments.
lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.cpp
537

Indeed. I have missed that ArrayRef can figure the size of a C-style array out.

mgorny updated this revision to Diff 306356.Nov 19 2020, 3:17 AM
mgorny marked an inline comment as done.

Simplified FreeBSD & Linux code as @labath suggested. Also added the scope thingy to tests.

mgorny updated this revision to Diff 306360.Nov 19 2020, 3:22 AM

Declare MMSRegComp type explicitly to avoid warnings:

In file included from /home/mgorny/llvm-project/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextLinux_x86_64.cpp:11:
In file included from /home/mgorny/llvm-project/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_x86.h:12:
/home/mgorny/llvm-project/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContext_x86.h:247:5: warning: anonymous types declared in an anonymous union are an extension [-Wnested-anon-types]
    struct {
    ^
1 warning generated.
labath accepted this revision.Nov 19 2020, 4:05 AM

ship it

This revision is now accepted and ready to land.Nov 19 2020, 4:05 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptNov 19 2020, 4:23 AM

Hi @mgorny! http://lab.llvm.org:8011/#/builders/68/builds/2298 build failed. Could you please fix the test?

I'm sorry about that. I'll look into it.

mgorny updated this revision to Diff 306403.Nov 19 2020, 6:50 AM

Update TestRegisters.py.

mgorny reopened this revision.Nov 19 2020, 6:51 AM

Does this change to TestRegister.py look good? It makes the test pass for me (and seems logically correct).

This revision is now accepted and ready to land.Nov 19 2020, 6:51 AM

Well... I think that will make the test fail on mac, as debugserver hasn't been updated.

This test comes from D12592, and is actually serves a very similar purpose to the test you just wrote. Normally, I would say we don't need both of them, but since we still have debugserver with the old behavior, and your new test is consistent with how we've (you've) been writing other register tests, maybe we could just slap @skipUnlessDarwin on TestRegisters.py, and put some comments (on both tests) that explain the situation and cross-reference each other (?)

Well... I think that will make the test fail on mac, as debugserver hasn't been updated.

This test comes from D12592, and is actually serves a very similar purpose to the test you just wrote. Normally, I would say we don't need both of them, but since we still have debugserver with the old behavior, and your new test is consistent with how we've (you've) been writing other register tests, maybe we could just slap @skipUnlessDarwin on TestRegisters.py, and put some comments (on both tests) that explain the situation and cross-reference each other (?)

I could do that. I suppose it'd also be reasonably easy to make the Python test support both platforms with an if.

mgorny updated this revision to Diff 306647.Nov 20 2020, 3:40 AM

Skipped python test on non-Darwin, xfailed shell test on Darwin, added respective comments.

This revision was automatically updated to reflect the committed changes.