Re: gdb and loading a realtime library with dlopen()

2021-05-17 Thread Jan Kiszka via Xenomai
On 17.05.21 11:38, Grau, Gunter wrote:
> 
> 
>> -Original Message-
>> From: Grau, Gunter
>> Sent: Mittwoch, 12. Mai 2021 08:32
>> To: xenomai@xenomai.org
>> Subject: gdb and loading a realtime library with dlopen()
>>
>> Hi,
>>
>> We currently porting a Xenomai application from 2.6 to 3.1. The platform is
>> arm. The hardware is imx6.
>> We are using xenomai 3.1.x branch on git.
>>
>> The application startup is done by a "loader" which is not linked with
>> Xenomai, but it loads a shared library which contains the Xenomai realtime
>> part.
>> Because of this, the Xenomai userspace is configured with --enable-dlopen-
>> libs.
>> The complete configuration line is:
>> ../configure --host=arm-linux-gnueabi --enable-smp --build=i686-pc-linux-
>> gnu --prefix=/usr/xenomai --enable-dlopen-libs --enable-async-cancel
>>
>> Since the realtime part uses posix skin and alchemy (was native) skin as 
>> well,
>> we enable both. Also auto-init-solib.
>> xeno-config --rtdm --skin posix --skin alchemy --auto-init-solib --ldflags
>>
>> When we start the loader / application via command line everything works
>> fine. The dlopen call is successful and we can jump into the library using
>> dlsym() for symbol lookup.
>>
>> But when we try to start the same application in gdb, the application hangs
>> on dlopen(). Gdb backtrace look like it is waiting vor a mutex in the heap 
>> init
>> part of xenomai.
>> I  wrote a short test loader and library (attached). The same happens here.
>> You can find the backtrace below. Gdb revision is 8.2.1.
>>
>> Any hints, what may be wrong?
>>
>> Thanks in advance,
>> Gunter
>>
>>
> [...]
>>
> 
> Hi,
> 
> Since Jan asked me, but it was not CC on the mailing list.
> This also happens to me with the dlopen test in smokey. So there is no need 
> to use my example code:
> 
> root@x:~/smokey/dlopen# gdb ./dlopentest GNU gdb (GDB) 8.2.1 Copyright 
> (C) 2018 Free Software Foundation, Inc.
> License GPLv3+: GNU GPL version 3 or later 
> This is free software: you are free to change and redistribute it.
> There is NO WARRANTY, to the extent permitted by law.
> Type "show copying" and "show warranty" for details.
> This GDB was configured as "arm-poky-linux-gnueabi".
> Type "show configuration" for configuration details.
> For bug reporting instructions, please see:
> .
> Find the GDB manual and other documentation resources online at:
> .
> 
> For help, type "help".
> Type "apropos word" to search for commands related to "word"...
> Reading symbols from ./dlopentest...done.
> (gdb) run
> Starting program: /home/root/smokey/dlopen/dlopentest
> warning: Unable to find libthread_db matching inferior's thread library, 
> thread debugging will not be available.
> [New LWP 4050]
> 
> Thread 1 "dlopentest" received signal SIGINT, Interrupt.
> 0x76e47360 in __cobalt_pthread_mutex_lock (mutex=mutex@entry=0x76e07410 
> ) at ../../../lib/cobalt/mutex.c:375
> 375 ../../../lib/cobalt/mutex.c: No such file or directory.
> (gdb) backtrace
> #0  0x76e47360 in __cobalt_pthread_mutex_lock (mutex=mutex@entry=0x76e07410 
> ) at ../../../lib/cobalt/mutex.c:375
> #1  0x76e4d8e8 in add_extent (heap=heap@entry=0x76e07410 , 
> mem=mem@entry=0x762f3008, size=size@entry=2146400) at 
> ../../../lib/boilerplate/heapmem.c:679
> #2  0x76e4dec4 in heapmem_init (heap=0x76e07410 , 
> mem=mem@entry=0x762f3008, size=size@entry=2146400) at 
> ../../../lib/boilerplate/heapmem.c:711
> #3  0x76df625c in heapobj_pkg_init_private () at 
> ../../../lib/copperplate/heapobj-heapmem.c:111
> #4  0x76df2b08 in copperplate_init () at ../../../lib/copperplate/init.c:204
> #5  0x76e4ee18 in __xenomai_init (argcp=argcp@entry=0x7effe624, 
> argvp=argvp@entry=0x7effe628, me=0x54abe2a0 "\230\336\253T") at 
> ../../../lib/boilerplate/setup.c:631
> #6  0x76e4f390 in xenomai_init_dso (argcp=argcp@entry=0x7effe624, 
> argvp=argvp@entry=0x7effe628) at ../../../lib/boilerplate/setup.c:693
> #7  0x76e68738 in call_init (argvp=0x7effe628, argcp=0x7effe624) at 
> ../../../../lib/boilerplate/init/bootstrap.c:169
> #8  xenomai_bootstrap () at ../../../../lib/boilerplate/init/bootstrap.c:169
> #9  0x76fddc1c in call_init (l=, argc=argc@entry=1, 
> argv=argv@entry=0x7efffca4, env=env@entry=0x7efffcac) at dl-init.c:72
> #10 0x76fddd20 in call_init (env=, argv=, 
> argc=, l=) at dl-init.c:30
> #11 _dl_init (main_map=main_map@entry=0x54abc1b8, argc=1, argv=0x7efffca4, 
> env=0x7efffcac) at dl-init.c:119
> #12 0x76fe1bd8 in dl_open_worker (a=) at dl-open.c:506
> #13 0x76f85c5c in __GI__dl_catch_exception (exception=0x76f85c5c 
> <__GI__dl_catch_exception+96>, operate=0x7effe930, args=0x7effe8ac) at 
> dl-error-skeleton.c:196
> #14 0x76fe1460 in _dl_open (file=0x7effeb28 
> "/usr/xenomai3/bin/libalchemy-test.so", mode=-2147483391, 
> caller_dlopen=0x54aaa7cc , nsid=-2, argc=1, argv=0x7efffca4, 
> env=0x7efffcac) at dl-open.c:588
> 

RE: gdb and loading a realtime library with dlopen()

2021-05-17 Thread Grau, Gunter via Xenomai



> -Original Message-
> From: Grau, Gunter
> Sent: Mittwoch, 12. Mai 2021 08:32
> To: xenomai@xenomai.org
> Subject: gdb and loading a realtime library with dlopen()
>
> Hi,
>
> We currently porting a Xenomai application from 2.6 to 3.1. The platform is
> arm. The hardware is imx6.
> We are using xenomai 3.1.x branch on git.
>
> The application startup is done by a "loader" which is not linked with
> Xenomai, but it loads a shared library which contains the Xenomai realtime
> part.
> Because of this, the Xenomai userspace is configured with --enable-dlopen-
> libs.
> The complete configuration line is:
> ../configure --host=arm-linux-gnueabi --enable-smp --build=i686-pc-linux-
> gnu --prefix=/usr/xenomai --enable-dlopen-libs --enable-async-cancel
>
> Since the realtime part uses posix skin and alchemy (was native) skin as well,
> we enable both. Also auto-init-solib.
> xeno-config --rtdm --skin posix --skin alchemy --auto-init-solib --ldflags
>
> When we start the loader / application via command line everything works
> fine. The dlopen call is successful and we can jump into the library using
> dlsym() for symbol lookup.
>
> But when we try to start the same application in gdb, the application hangs
> on dlopen(). Gdb backtrace look like it is waiting vor a mutex in the heap 
> init
> part of xenomai.
> I  wrote a short test loader and library (attached). The same happens here.
> You can find the backtrace below. Gdb revision is 8.2.1.
>
> Any hints, what may be wrong?
>
> Thanks in advance,
> Gunter
>
>
[...]
>

Hi,

Since Jan asked me, but it was not CC on the mailing list.
This also happens to me with the dlopen test in smokey. So there is no need to 
use my example code:

root@x:~/smokey/dlopen# gdb ./dlopentest GNU gdb (GDB) 8.2.1 Copyright (C) 
2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later 
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "arm-poky-linux-gnueabi".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
.
Find the GDB manual and other documentation resources online at:
.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./dlopentest...done.
(gdb) run
Starting program: /home/root/smokey/dlopen/dlopentest
warning: Unable to find libthread_db matching inferior's thread library, thread 
debugging will not be available.
[New LWP 4050]

Thread 1 "dlopentest" received signal SIGINT, Interrupt.
0x76e47360 in __cobalt_pthread_mutex_lock (mutex=mutex@entry=0x76e07410 
) at ../../../lib/cobalt/mutex.c:375
375 ../../../lib/cobalt/mutex.c: No such file or directory.
(gdb) backtrace
#0  0x76e47360 in __cobalt_pthread_mutex_lock (mutex=mutex@entry=0x76e07410 
) at ../../../lib/cobalt/mutex.c:375
#1  0x76e4d8e8 in add_extent (heap=heap@entry=0x76e07410 , 
mem=mem@entry=0x762f3008, size=size@entry=2146400) at 
../../../lib/boilerplate/heapmem.c:679
#2  0x76e4dec4 in heapmem_init (heap=0x76e07410 , 
mem=mem@entry=0x762f3008, size=size@entry=2146400) at 
../../../lib/boilerplate/heapmem.c:711
#3  0x76df625c in heapobj_pkg_init_private () at 
../../../lib/copperplate/heapobj-heapmem.c:111
#4  0x76df2b08 in copperplate_init () at ../../../lib/copperplate/init.c:204
#5  0x76e4ee18 in __xenomai_init (argcp=argcp@entry=0x7effe624, 
argvp=argvp@entry=0x7effe628, me=0x54abe2a0 "\230\336\253T") at 
../../../lib/boilerplate/setup.c:631
#6  0x76e4f390 in xenomai_init_dso (argcp=argcp@entry=0x7effe624, 
argvp=argvp@entry=0x7effe628) at ../../../lib/boilerplate/setup.c:693
#7  0x76e68738 in call_init (argvp=0x7effe628, argcp=0x7effe624) at 
../../../../lib/boilerplate/init/bootstrap.c:169
#8  xenomai_bootstrap () at ../../../../lib/boilerplate/init/bootstrap.c:169
#9  0x76fddc1c in call_init (l=, argc=argc@entry=1, 
argv=argv@entry=0x7efffca4, env=env@entry=0x7efffcac) at dl-init.c:72
#10 0x76fddd20 in call_init (env=, argv=, 
argc=, l=) at dl-init.c:30
#11 _dl_init (main_map=main_map@entry=0x54abc1b8, argc=1, argv=0x7efffca4, 
env=0x7efffcac) at dl-init.c:119
#12 0x76fe1bd8 in dl_open_worker (a=) at dl-open.c:506
#13 0x76f85c5c in __GI__dl_catch_exception (exception=0x76f85c5c 
<__GI__dl_catch_exception+96>, operate=0x7effe930, args=0x7effe8ac) at 
dl-error-skeleton.c:196
#14 0x76fe1460 in _dl_open (file=0x7effeb28 
"/usr/xenomai3/bin/libalchemy-test.so", mode=-2147483391, 
caller_dlopen=0x54aaa7cc , nsid=-2, argc=1, argv=0x7efffca4, 
env=0x7efffcac) at dl-open.c:588
#15 0x76fbbcdc in dlopen_doit (a=0x7effeb08) at dlopen.c:66
#16 0x76f85c5c in __GI__dl_catch_exception (exception=0x76f85c5c 
<__GI__dl_catch_exception+96>, exception@entry=0x7effeac4, operate=0x0, 
args=0x7effeacc,