[Question] Type information in gdb is mixed and incorrect when debugging multiple JIT module
I want to share difficulties when debugging multiple JIT module together in coreclr and I'm looking for help if there is any workaround or solution for this issue. This is not a coreclr issue but gdb issue. However it seems that current structure of coreclr make it harder to debug multiple JIT module at the same time.
For ARM32, I'm using two JIT module in coreclr to run application, i.e. legacy backend and Ryujit, because Ryujit is still incomplete for ARM32.
And these two JIT module use same type name with different layout.
- For example,
struct GenTreehas different members for each JIT with#ifdef LEGACY_BACKENDand etc. (https://github.com/dotnet/coreclr/blob/master/src/jit/gentree.h#L743-L745) - Another example is
enum genTreeOpswhere legacy JIT and RyuJIT use same enumeration type name but different enumeration, e.g. https://github.com/dotnet/coreclr/blob/master/src/jit/gtlist.h#L148-L158
For arm32, there are two JIT module defined in libclrjit.so(legacy backend) and libprotojit.so(ryujit).
When coreclr runs, each JIT module is loaded using dlopen when necessary and gdb load type information together when debugging. However when there is a same type, it seems that gdb doesn't load new type information from newly loaded module or maintain correct type information for each module.
As a result, following situations occur when debugging multiple JIT module in gdb for example.
libclrjit.sois loaded and type information ofstruct GenTreeandenum genTReeOpare also loaded fromlibclrjit.so- later
libprotojit.sois also loaded when Ryujit is requested. - When debugging
libcljit.so(legacy JIT), there is no problem - However when debugging
libprotojit.so(ryujit), gdb use type information of legacy backend to parse types inlibprotojit.so. When debugginglibprotoji.so, gdb show wrong enumeration value and refer to wrong offset address of struct which sometimes causeSegmentation faultin gdb.
Due to above behavior, we have to be cautious using gdb when debugging ryujit/arm32 and legacy JIT at the same time and can't trust gdb 100%.
Also I think R2R may have similar issue, because I found that there is several FEATURE_READYTORUN_COMPILER used in common types.
Do you have any solution or workaround to load correct type information for each module in gdb with current coreclr sturcture, i.e. loading multiple JIT module with dlopen ?
Or any idea that we can debug multiple JIT module correctly in gdb ?
I understand that this is a minor issue related to debugging coreclr itself though.
I also opened a question at stackoverflow with simple example to see if there is any trick available.
/cc: @dotnet/jit-contrib @dotnet/arm32-contrib
The documentation (https://sourceware.org/gdb/current/onlinedocs/gdb/Files.html) mentions these commands for example:
info sharedlibrary regex
Print the names of the shared libraries which are currently loaded that match regex. If regex is omitted then print all shared libraries that are loaded.
sharedlibrary regex
Load shared object library symbols for files matching a Unix regular expression. As with files loaded automatically, it only loads shared libraries required by your program for a core file or after typing run. If regex is omitted all shared libraries required by your program are loaded.
nosharedlibrary
Unload all shared object library symbols. This discards all symbols that have been loaded from all shared libraries. Symbols from shared libraries that were loaded by explicit user requests are not discarded.
@janvorli @mikem8361 Any suggestions?
@mskvortsov Thanks it works :)
We can manually exploit nosharedlibrary and sharedlibrary regex to unload existing type information and load new symbol from libprotojit.so as below, although we have to manually unload/load information on demand.
CodeGen::genConsumeReg (this=0x932d4, tree=0xa067c) at /opt/code/github/hqueue/coreclr/src/jit/codegenlinear.cpp:1128
1128 if (tree->OperGet() == GT_COPY)
(gdb) p tree->gtOper
$6 = genTreeOps::GT_PROF_HOOK
(gdb) nosharedlibrary
(gdb) p tree->gtOper
No symbol "tree" in current context.
(gdb) sharedlibrary libprotojit.so
Reading symbols from /mnt/albireo/mywork/device/rpi3/unittests/coreoverlays/coreoverlay.test20170523.debug.working/libprotojit.so...done.
(gdb) p tree->gtOper
$7 = genTreeOps::GT_FIELD_LIST
I don't know very little about gdb and next to nothing about the gdb JIT support. Sorry.
Due to lack of recent activity, this issue has been marked as a candidate for backlog cleanup. It will be closed if no further activity occurs within 14 more days. Any new comment (by anyone, not necessarily the author) will undo this process.
This process is part of our issue cleanup automation.
This issue will now be closed since it had been marked no-recent-activity but received no further activity in the past 14 days. It is still possible to reopen or comment on the issue, but please note that the issue will be locked if it remains inactive for another 30 days.