Recent

Author Topic: Unable to start application  (Read 485 times)

Grahame Grieve

  • Full Member
  • ***
  • Posts: 110
Unable to start application
« on: October 23, 2020, 11:50:34 pm »
while I can run some applications, one of them fails to start:

#0 __pthread_kill at :-1
#1 pthread_kill at :-1
#2 abort at :-1
#3 __report_load at :-1
#4 ImageLoaderMachO::doModInitFunctions at :-1
#5 ImageLoaderMachO::doInitialization at :-1
#6 ImageLoader::recursiveInitialization at :-1
#7 ImageLoader::processInitializers at :-1
#8 ImageLoader::runInitializers at :-1
#9 dyld::runInitializers at :-1
#10  at :0
#11  at :0

This happens after some of my unit initialization code has run, but before all of it has run. But not during a unit initialization - step out of the last one that runs ok, but stepping from there never finds any code before this error happens.

What can I do to investigate?

details: Lazarus = 2.1.0, FPC = 3.3.1, MacOS = 10.15.7. Code = https://github.com/grahamegrieve/fhirserver/blob/master/server/FHIRServerFPC.lpi. It runs ok on windows and linux, so it's something OSX related but there's lot's of possibilities.

Full debugger output:

>> settings set -- frame-format "frame #${frame.index}: ${frame.pc}, {${frame.sp}}, {${frame.fp}} &&//FULL: {${line.file.fullpath}} &&//SHORT: {${line.file.basename}} &&//LINE: {${line.number}} &&//MOD: {${module.file.basename}} &&//FUNC: {${function.name-with-args}} <<&&//FRAME\n"
(lldb) settings set -- frame-format "frame #${frame.index}: ${frame.pc}, {${frame.sp}}, {${frame.fp}} &&//FULL: {${line.file.fullpath}} &&//SHORT: {${line.file.basename}} &&//LINE: {${line.number}} &&//MOD: {${module.file.basename}} &&//FUNC: {${function.name-with-args}} <<&&//FRAME\n"
>> settings set -- thread-format "thread #${thread.index}: tid=${thread.id%tid}: ${frame.pc}, {${frame.sp}}, {${frame.fp}} &&//FULL: {${line.file.fullpath}} &&//SHORT: {${line.file.basename}} &&//LINE: {${line.number}} &&//MOD: {${module.file.basename}} &&//FUNC: {${function.name-with-args}} <<&&//FRAME{, stop reason = ${thread.stop-reason}}\n"
(lldb) settings set -- thread-format "thread #${thread.index}: tid=${thread.id%tid}: ${frame.pc}, {${frame.sp}}, {${frame.fp}} &&//FULL: {${line.file.fullpath}} &&//SHORT: {${line.file.basename}} &&//LINE: {${line.number}} &&//MOD: {${module.file.basename}} &&//FUNC: {${function.name-with-args}} <<&&//FRAME{, stop reason = ${thread.stop-reason}}\n"
>> settings set -- thread-stop-format "thread #${thread.index}: tid=${thread.id%tid}: ${frame.pc}, {${frame.sp}}, {${frame.fp}} &&//FULL: {${line.file.fullpath}} &&//SHORT: {${line.file.basename}} &&//LINE: {${line.number}} &&//MOD: {${module.file.basename}} &&//FUNC: {${function.name-with-args}} <<&&//FRAME{, stop reason = ${thread.stop-reason}}\n"
(lldb) settings set -- thread-stop-format "thread #${thread.index}: tid=${thread.id%tid}: ${frame.pc}, {${frame.sp}}, {${frame.fp}} &&//FULL: {${line.file.fullpath}} &&//SHORT: {${line.file.basename}} &&//LINE: {${line.number}} &&//MOD: {${module.file.basename}} &&//FUNC: {${function.name-with-args}} <<&&//FRAME{, stop reason = ${thread.stop-reason}}\n"
>> target stop-hook add -o "thread list"
(lldb) target stop-hook add -o "thread list"
Stop hook #1 added.
>> settings set -- stop-line-count-after 0
(lldb) settings set -- stop-line-count-after 0
>> settings set -- stop-line-count-before 0
(lldb) settings set -- stop-line-count-before 0
>> settings set -- stop-disassembly-count 0
(lldb) settings set -- stop-disassembly-count 0
>> settings set -- target.env-vars "USER=grahamegrieve"
(lldb) settings set -- target.env-vars "USER=grahamegrieve"
>> settings set -- target.env-vars "PATH=/usr/bin:/bin:/usr/sbin:/sbin"
(lldb) settings set -- target.env-vars "PATH=/usr/bin:/bin:/usr/sbin:/sbin"
>> settings set -- target.env-vars "LOGNAME=grahamegrieve"
(lldb) settings set -- target.env-vars "LOGNAME=grahamegrieve"
>> settings set -- target.env-vars "SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.peYB4OazWr/Listeners"
(lldb) settings set -- target.env-vars "SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.peYB4OazWr/Listeners"
>> settings set -- target.env-vars "HOME=/Users/grahamegrieve"
(lldb) settings set -- target.env-vars "HOME=/Users/grahamegrieve"
>> settings set -- target.env-vars "SHELL=/bin/zsh"
(lldb) settings set -- target.env-vars "SHELL=/bin/zsh"
>> settings set -- target.env-vars "__CF_USER_TEXT_ENCODING=0x1F5:0:15"
(lldb) settings set -- target.env-vars "__CF_USER_TEXT_ENCODING=0x1F5:0:15"
>> settings set -- target.env-vars "TMPDIR=/var/folders/ws/60wjzhsn6d31zr63zf5f74yc0000gn/T/"
(lldb) settings set -- target.env-vars "TMPDIR=/var/folders/ws/60wjzhsn6d31zr63zf5f74yc0000gn/T/"
>> settings set -- target.env-vars "XPC_SERVICE_NAME=lazarus.freepascal.ide.6572"
(lldb) settings set -- target.env-vars "XPC_SERVICE_NAME=lazarus.freepascal.ide.6572"
>> settings set -- target.env-vars "XPC_FLAGS=0x0"
(lldb) settings set -- target.env-vars "XPC_FLAGS=0x0"
>> target create /Users/grahamegrieve/work/fhirserver/exec/64/FhirServerFPC
(lldb) target create /Users/grahamegrieve/work/fhirserver/exec/64/FhirServerFPC
Current executable set to '/Users/grahamegrieve/work/fhirserver/exec/64/FhirServerFPC' (x86_64).
>> settings set -- target.run-args -tests -gui
(lldb) settings set -- target.run-args -tests -gui
>> breakpoint set --func fpc_break_error -K false
(lldb) breakpoint set --func fpc_break_error -K false
Breakpoint 1: no locations (pending).
>> breakpoint set --func fpc_runerror -K false
WARNING:  Unable to resolve breakpoint to any actual locations.
(lldb) breakpoint set --func fpc_runerror -K false
Breakpoint 2: no locations (pending).
>> breakpoint set --func fpc_raiseexception -K false
WARNING:  Unable to resolve breakpoint to any actual locations.
(lldb) breakpoint set --func fpc_raiseexception -K false
Breakpoint 3: where = FhirServerFPC`FPC_RAISEEXCEPTION, address = 0x000000010000cf00
>> breakpoint command add 3
>> p/x $rdi
>> p/x $rdx
>> p ((char ***)$rdi)[0][3]
>> p ((char **)$rdi)[1]
>> DONE
>> version
(lldb) breakpoint command add 3
(lldb) version
>> breakpoint command add 2
>> p/x $rdi
>> DONE
>> version
lldb-1200.0.32.1
Apple Swift version 5.3 (swiftlang-1200.0.29.2 clang-1200.0.30.1)
(lldb) breakpoint command add 2
(lldb) version
>> breakpoint command add 1
>> p/x $rdi
>> DONE
>> version
lldb-1200.0.32.1
Apple Swift version 5.3 (swiftlang-1200.0.29.2 clang-1200.0.30.1)
(lldb) breakpoint command add 1
(lldb) version
>> process launch -n
lldb-1200.0.32.1
Apple Swift version 5.3 (swiftlang-1200.0.29.2 clang-1200.0.30.1)
(lldb) process launch -n
Process 17032 launched: '/Users/grahamegrieve/work/fhirserver/exec/64/FhirServerFPC' (x86_64)
Process 17032 stopped
* thread #1: tid=0xf311f: 0x00007fff6da1033a, 0x00007ffeefbfc1b8, 0x00007ffeefbfc1e0 &&//FULL:  &&//SHORT:  &&//LINE:  &&//MOD: libsystem_kernel.dylib &&//FUNC: __pthread_kill <<&&//FRAME, stop reason = signal SIGABRT
  thread #2: tid=0xf313c: 0x00007fff6da0b4ce, 0x000070000d519b18, 0x000070000d519b40 &&//FULL:  &&//SHORT:  &&//LINE:  &&//MOD: libsystem_kernel.dylib &&//FUNC: __workq_kernreturn <<&&//FRAME
  thread #3: tid=0xf313d: 0x00007fff6da09dfa, 0x000070000d59c608, 0x000070000d59c660 &&//FULL:  &&//SHORT:  &&//LINE:  &&//MOD: libsystem_kernel.dylib &&//FUNC: mach_msg_trap <<&&//FRAME

Process 17032 stopped
* thread #1: tid=0xf311f: 0x00007fff6da1033a, 0x00007ffeefbfc1b8, 0x00007ffeefbfc1e0 &&//FULL:  &&//SHORT:  &&//LINE:  &&//MOD: libsystem_kernel.dylib &&//FUNC: __pthread_kill <<&&//FRAME, stop reason = signal SIGABRT
    frame #0: 0x00007fff6da1033a, 0x00007ffeefbfc1b8, 0x00007ffeefbfc1e0 &&//FULL:  &&//SHORT:  &&//LINE:  &&//MOD: libsystem_kernel.dylib &&//FUNC: __pthread_kill <<&&//FRAME
>> frame variable -P 1 -D 5
>> version
Target 0: (FhirServerFPC) stopped.
(lldb) frame variable -P 1 -D 5
(lldb) version
>> thread backtrace -c 10
>> version
lldb-1200.0.32.1
Apple Swift version 5.3 (swiftlang-1200.0.29.2 clang-1200.0.30.1)
(lldb) thread backtrace -c 10
* thread #1: tid=0xf311f: 0x00007fff6da1033a, 0x00007ffeefbfc1b8, 0x00007ffeefbfc1e0 &&//FULL:  &&//SHORT:  &&//LINE:  &&//MOD: libsystem_kernel.dylib &&//FUNC: __pthread_kill <<&&//FRAME, stop reason = signal SIGABRT
  * frame #0: 0x00007fff6da1033a, 0x00007ffeefbfc1b8, 0x00007ffeefbfc1e0 &&//FULL:  &&//SHORT:  &&//LINE:  &&//MOD: libsystem_kernel.dylib &&//FUNC: __pthread_kill <<&&//FRAME
    frame #1: 0x00007fff6dacce60, 0x00007ffeefbfc1c0, 0x00007ffeefbfc1e0 &&//FULL:  &&//SHORT:  &&//LINE:  &&//MOD: libsystem_pthread.dylib &&//FUNC: pthread_kill <<&&//FRAME
    frame #2: 0x00007fff6d997808, 0x00007ffeefbfc1f0, 0x00007ffeefbfc220 &&//FULL:  &&//SHORT:  &&//LINE:  &&//MOD: libsystem_c.dylib &&//FUNC: abort <<&&//FRAME
    frame #3: 0x00007fff6b4c17e4, 0x00007ffeefbfc230, 0x00007ffeefbfc6f0 &&//FULL:  &&//SHORT:  &&//LINE:  &&//MOD: libcrypto.dylib &&//FUNC: __report_load <<&&//FRAME
    frame #4: 0x0000000106cc31d3, 0x00007ffeefbfc700, 0x00007ffeefbfc850 &&//FULL:  &&//SHORT:  &&//LINE:  &&//MOD: dyld &&//FUNC: ImageLoaderMachO::doModInitFunctions(ImageLoader::LinkContext const&) <<&&//FRAME
    frame #5: 0x0000000106cc35de, 0x00007ffeefbfc860, 0x00007ffeefbfc870 &&//FULL:  &&//SHORT:  &&//LINE:  &&//MOD: dyld &&//FUNC: ImageLoaderMachO::doInitialization(ImageLoader::LinkContext const&) <<&&//FRAME
    frame #6: 0x0000000106cbdffb, 0x00007ffeefbfc880, 0x00007ffeefbfc8d0 &&//FULL:  &&//SHORT:  &&//LINE:  &&//MOD: dyld &&//FUNC: ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, char const*, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&) <<&&//FRAME
    frame #7: 0x0000000106cbc0b4, 0x00007ffeefbfc8e0, 0x00007ffeefbfe030 &&//FULL:  &&//SHORT:  &&//LINE:  &&//MOD: dyld &&//FUNC: ImageLoader::processInitializers(ImageLoader::LinkContext const&, unsigned int, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&) <<&&//FRAME
    frame #8: 0x0000000106cbc154, 0x00007ffeefbfe040, 0x00007ffeefbfe080 &&//FULL:  &&//SHORT:  &&//LINE:  &&//MOD: dyld &&//FUNC: ImageLoader::runInitializers(ImageLoader::LinkContext const&, ImageLoader::InitializerTimingList&) <<&&//FRAME
    frame #9: 0x0000000106cadef2, 0x00007ffeefbfe090, 0x00007ffeefbff770 &&//FULL:  &&//SHORT:  &&//LINE:  &&//MOD: dyld &&//FUNC: dyld::runInitializers(ImageLoader*) <<&&//FRAME
(lldb) version
>> thread list
>> version
lldb-1200.0.32.1
Apple Swift version 5.3 (swiftlang-1200.0.29.2 clang-1200.0.30.1)
(lldb) thread list
Process 17032 stopped
* thread #1: tid=0xf311f: 0x00007fff6da1033a, 0x00007ffeefbfc1b8, 0x00007ffeefbfc1e0 &&//FULL:  &&//SHORT:  &&//LINE:  &&//MOD: libsystem_kernel.dylib &&//FUNC: __pthread_kill <<&&//FRAME, stop reason = signal SIGABRT
  thread #2: tid=0xf313c: 0x00007fff6da0b4ce, 0x000070000d519b18, 0x000070000d519b40 &&//FULL:  &&//SHORT:  &&//LINE:  &&//MOD: libsystem_kernel.dylib &&//FUNC: __workq_kernreturn <<&&//FRAME
  thread #3: tid=0xf313d: 0x00007fff6da09dfa, 0x000070000d59c608, 0x000070000d59c660 &&//FULL:  &&//SHORT:  &&//LINE:  &&//MOD: libsystem_kernel.dylib &&//FUNC: mach_msg_trap <<&&//FRAME
(lldb) version
lldb-1200.0.32.1
Apple Swift version 5.3 (swiftlang-1200.0.29.2 clang-1200.0.30.1)



Jonas Maebe

  • Hero Member
  • *****
  • Posts: 803
Re: Unable to start application
« Reply #1 on: October 24, 2020, 12:00:08 am »
It looks like an issue with a modinit function, probably from a dynamic library. Can you try starting it with the environment variable DYLD_PRINT_INITIALIZERS=1 set to see from which library it comes?
« Last Edit: October 24, 2020, 12:07:36 am by Jonas Maebe »

Grahame Grieve

  • Full Member
  • ***
  • Posts: 110
Re: Unable to start application
« Reply #2 on: October 24, 2020, 03:11:44 am »
actually, it's IdSSLOpenSSLHeaders tying to load openSSL. (found it the hard way; DYLD_PRINT_INITIALIZERS didn't seem to make any difference or I didn't set the envirnment variable correctly).

Now I have to figure out what to do about it - I see some forum posts about this but they require knowledge I do not yet have to figure out what they mean

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1053
  • Former Delphi 1-7, 10.2 User
Re: Unable to start application
« Reply #3 on: October 24, 2020, 04:13:06 am »
If you want to observe the dynamic linker in action, you can use the command line utility dtruss. See the Wiki Observe the dynamic linker in action.
o Lazarus v2.1.0 r63871, FPC v3.3.1 r47164, macOS 10.14.6, Xcode 11.3.1
o Lazarus v2.1.0 r64160, FPC v3.3.1 Nov 27 21:16:31, macOS 11.0.1 (aarch64), Xcode 12.2
o Lazarus v2.1.0 r61574, FPC v3.3.1 r42318, FreeBSD 12.1 amd64 (VMware VM)
o Lazarus v2.1.0 r61574, FPC v3.0.4, Ubuntu 20.04 (PD VM)

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1053
  • Former Delphi 1-7, 10.2 User
Re: Unable to start application
« Reply #4 on: October 24, 2020, 04:32:00 am »
This OpenSSL macOS Bug might also be relevant: https://bugs.freepascal.org/view.php?id=36484
o Lazarus v2.1.0 r63871, FPC v3.3.1 r47164, macOS 10.14.6, Xcode 11.3.1
o Lazarus v2.1.0 r64160, FPC v3.3.1 Nov 27 21:16:31, macOS 11.0.1 (aarch64), Xcode 12.2
o Lazarus v2.1.0 r61574, FPC v3.3.1 r42318, FreeBSD 12.1 amd64 (VMware VM)
o Lazarus v2.1.0 r61574, FPC v3.0.4, Ubuntu 20.04 (PD VM)

Grahame Grieve

  • Full Member
  • ***
  • Posts: 110
Re: Unable to start application
« Reply #5 on: October 24, 2020, 03:05:54 pm »
ok, got past that... now TStringList.create is causing sudden cessation of my program. No errors - simply stops running. weird... (It's the first TStringlist being created, but not the first object being created

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 803
Re: Unable to start application
« Reply #6 on: October 24, 2020, 03:13:19 pm »
Try setting a breakpoint on _exit (including the underscore).

Grahame Grieve

  • Full Member
  • ***
  • Posts: 110
Re: Unable to start application
« Reply #7 on: October 25, 2020, 11:24:30 am »
This (terminating on creating a stringlist) is what happens when you accidently $IFDEF cmem out in the .lpr

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 803
Re: Unable to start application
« Reply #8 on: October 25, 2020, 12:23:13 pm »
Are you allocating memory in a dynamic library that then gets freed in another library or the main program, or vice versa? Or are you passing reference-counted types, like ansistrings, across such borders?

If so, then you indeed need to use cmem in all such libraries/main program (or sharemem on Windows), because otherwise every (FPC) library and application uses its own copy of the heap manager, and allocating memory in one heap manager and freeing it using another is indeed a recipe for crashes.

 

TinyPortal © 2005-2018