This patch refactors the way the XState type is checked and, in order to
simplify the code, it removes the usage of the 'cpuid' instruction: just checking
if the ptrace calls done throuhg ReadFPR is enough to verify both if there is
HW support and if there is kernel support. Also the XCR0 bits are enough to check if
there is both HW and kernel support for AVX and MPX.
Details
Diff Detail
Event Timeline
source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.cpp | ||
---|---|---|
816 | Is the AVX case supposed to fall-through to the mpx case? |
I am going to assume you know more about the exact details of the intel cpu's than me, so I am not going comment on the technical details. The code seems cleaner, so this looks like a good thing to do. Just please try to avoid using the const_cast if it's no absolutely necessary (and it almost never is).
source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.cpp | ||
---|---|---|
805 | I don't think the const_cast here is a good idea. How about we just make this functions non-const ? | |
808 | I remember you #including some header to get the __get_cpuid function. Can that be removed now? |
source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.cpp | ||
---|---|---|
805 | Then I think we should make that non-const as well. I mean, what's the point of making it const if it does actually modify the state of the object. Either that, or implement it in a way that does not modify the state. |
source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.cpp | ||
---|---|---|
805 | This involves changing the interface of NativeRegisterContextLinux just because NativeRegisterContextLinux_x86_64 has some specific needs that make GetRegisterCount use a non-const function. Also, I don't have all the hardware to test such a cross-platform change. |
source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.cpp | ||
---|---|---|
805 | Anyway I guess I can submit a follow-up patch with this, I will do it today ;) |
source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.cpp | ||
---|---|---|
805 | So I have looked into this and actually in "source/Host/common/NativeRegisterContextRegisterInfo.cpp" the method GetRegisterCount() is implemented as const (and the pure virtual method is defined in "include/lldb/Host/common/NativeRegisterContext.h"). Unfortunately I don't see an easy way 1. to make the method non-const or 2. to avoid that GetRegisterSetCount() in NativeRegisterContextLinux_x86_64 needs to call a non const function: in order to get the register set count, it must know if the XState type is XSAVE, and in order to do that it must call ReadFPR(), or directly PtraceWrapper(), which are both non-const. |
So, the thing is that you already are changing the interface. The difference is that you are using the const cast to hide that fact, which is why I dont approve of it.
Also, since this is not an existing problem but rather something you are introducing in this change, I dont thinl it's appropriate to do it as a follow-up, but rather as a prep work for this change.
One possibility I would consider is to do any work you need to do before this function even executes (e.g. in the constructor - the result of IsCpuFeatureAvailable cannot change during the lifetime of the process anyway, right?). I am OOO today so I cannot really tell how feasible that ideaIis. I can look at It tomorrow.
Thechnically it's not correct that I am introducing this issue, because the old code already used a cast. It was done in the old and now not existing method "GetFPRType()", long before I introduced the MPX changes, and then I later moved it into HasXSave()/HasXSave() and now with this current refactoring patch I am moving it into IsCPUFeatureAvailable().
I'm sorry, I did not notice that. Go ahead with this patch in that case. It looks great apart from this eexisting problem. If you're going to do further cleanups here,, I would recommend looking at the cast problem as well.
I remember you #including some header to get the __get_cpuid function. Can that be removed now?