runtime icon indicating copy to clipboard operation
runtime copied to clipboard

[Question] Type information in gdb is mixed and incorrect when debugging multiple JIT module

Open hqueue opened this issue 9 years ago • 6 comments

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 GenTree has different members for each JIT with #ifdef LEGACY_BACKEND and etc. (https://github.com/dotnet/coreclr/blob/master/src/jit/gentree.h#L743-L745)
  • Another example is enum genTreeOps where 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.so is loaded and type information of struct GenTree and enum genTReeOp are also loaded from libclrjit.so
  • later libprotojit.so is 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 in libprotojit.so. When debugging libprotoji.so, gdb show wrong enumeration value and refer to wrong offset address of struct which sometimes cause Segmentation fault in 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

hqueue avatar Jun 07 '17 06:06 hqueue

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.

mskvortsov avatar Jun 07 '17 07:06 mskvortsov

@janvorli @mikem8361 Any suggestions?

BruceForstall avatar Jun 07 '17 07:06 BruceForstall

@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

hqueue avatar Jun 07 '17 11:06 hqueue

I don't know very little about gdb and next to nothing about the gdb JIT support. Sorry.

mikem8361 avatar Jun 07 '17 17:06 mikem8361

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.

ghost avatar Oct 27 '22 00:10 ghost

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.

ghost avatar Nov 10 '22 12:11 ghost