-
Notifications
You must be signed in to change notification settings - Fork 222
Add Zydis x86/x86-64 disassembler support #5128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
I have been using his locally to help me understand some SMC code. I wonder if it makes sense upstream. I understand it adds a dependency which is unwelcome though. Here's what the print out looks like when enabled: (some Crysis2 SMC code) |
|
If this is to be done it would want to walk the actual decoded blocks or instructions rather than just decode the whole range. I think this might be useful though, albeit I think gdb is pretty equally good here especially for SMC debugging etc |
What do you mean by 'walk the actual decoded blocks' ? |
Like just printing in the |
@bylaws is this related to SMC? That we might display code that's later modified and that we therefore are printing code that is not what's going to be executed and therefore is misleading? |
|
No - this is as a single decoded multiblock has no guarantee of being contiguous in memory and may contain padding bytes etc that would be jumped over, this current approach assumes fully linear code. |
neobrain
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of course the moment I "start a review", I run out of things to comment on :)
Nice feature to have, thanks for implementing it!
Integrate Zydis as an optional dependency to enable x86/x86-64 guest instruction disassembly during JIT compilation. Build with -DENABLE_ZYDIS=TRUE. Use FEX_X86DISASSEMBLE=1 at runtime to output guest x86 instructions for each compiled block.
| endif() | ||
|
|
||
| if (ENABLE_ZYDIS) | ||
| list (APPEND LIBS Zydis) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should use the namespaced variant: Zydis::Zydis or Zycore::Zycore (they are robust against typos and unintentionally undeclared build targets; "Zydis" may fall back to purely linking against libZydis.so without propagating include directories etc)
| find_package(Zydis QUIET) | ||
| if (Zydis_FOUND) | ||
| message(STATUS "Using system Zydis") | ||
| else() | ||
| message(STATUS "Using bundled Zydis") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately I realized Fedora does not actually ship a CMake config for Zydis, but only pkgconfig files. To add insult to injury, zycore uses a separate pkgconfig file, so this must be used instead:
| find_package(Zydis QUIET) | |
| if (Zydis_FOUND) | |
| message(STATUS "Using system Zydis") | |
| else() | |
| message(STATUS "Using bundled Zydis") | |
| pkg_search_module(Zydis QUIET IMPORTED_TARGET zydis) | |
| pkg_search_module(Zycore QUIET IMPORTED_TARGET zycore) | |
| if (TARGET PkgConfig::Zydis AND TARGET PkgConfig::Zycore AND NOT CMAKE_CROSSCOMPILING) | |
| add_library(Zydis::Zydis ALIAS PkgConfig::Zydis) | |
| add_library(Zycore::Zycore ALIAS PkgConfig::Zycore) | |
| message(STATUS "Using system Zydis") | |
| else() | |
| message(STATUS "Using bundled Zydis") |
None of the other distros that I use have that package to begin with so I don't know if CMake files are shipped anywhere. Might be interesting to check quickly on your systems, otherwise I wouldn't spend too much energy researching this.
One day we'll have nice things :(
| "\tstats: Will print stats when disassembling the code" | ||
| ] | ||
| }, | ||
| "X86Disassemble": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you also briefly update the description of the Disassemble option to distinguish from this option / make it clear it only covers generated arm code?
| LogMan::Msg::IFmt("{:#x}: {}", InstAddress, ZydisInst.text); | ||
| } else { | ||
| LogMan::Msg::IFmt("{:#x}: (decode failed, {} bytes)", InstAddress, DecodedInfo->InstSize); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| LogMan::Msg::IFmt("{:#x}: {}", InstAddress, ZydisInst.text); | |
| } else { | |
| LogMan::Msg::IFmt("{:#x}: (decode failed, {} bytes)", InstAddress, DecodedInfo->InstSize); | |
| LogMan::Msg::IFmt(" {:#x}: {}", InstAddress, ZydisInst.text); | |
| } else { | |
| LogMan::Msg::IFmt(" {:#x}: (decode failed, {} bytes)", InstAddress, DecodedInfo->InstSize); |
neobrain
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(just highlighting there's items left to do here; luckily this doesn't block any other work)
Integrate Zydis as an optional dependency to enable x86/x86-64 guest instruction disassembly during JIT compilation.
Build with -DENABLE_ZYDIS=TRUE.
Use FEX_X86DISASSEMBLE=1 at runtime to output guest x86 instructions for each compiled block.