Recent

Author Topic: How to debug issues with shared library libBearLibTerminal.dylib  (Read 177 times)

d-_-b

  • New Member
  • *
  • Posts: 24
So I got BearLibTerminal working on linux and windows using the prebuilt shared library, but with no success on macos.

I'm using their pascal interface in my unit and after figuring out the `-k'-lBearLibTerminal'` switch to tell linker where to find the dylib I can compile my program on macos but it raises a exception if I try to execute it, as seen below:

Code: [Select]
air:tui d-_-b$ fpc -k-t -k'-lBearLibTerminal' -B -Mobjfpc engine.lpr
Free Pascal Compiler version 3.0.4 [2018/09/30] for x86_64
Copyright (c) 1993-2017 by Florian Klaempfl and others
Target OS: Darwin for x86_64
Compiling engine.lpr
Compiling bltcrt.pas
Compiling BearLibTerminal.pas
Assembling (pipe) BearLibTerminal.s
bltcrt.pas(32,3) Note: Local variable "r" is assigned but never used
bltcrt.pas(40,3) Note: Local variable "r" is assigned but never used
Assembling (pipe) bltcrt.s
Compiling input_handlers.pas
Assembling (pipe) input_handlers.s
Compiling entity.pas
Assembling (pipe) entity.s
Compiling render_functions.pas
Compiling map_objects.pas
map_objects.pas(122,6) Note: Local variable "j" not used
Assembling (pipe) map_objects.s
Assembling (pipe) render_functions.s
Compiling fov_functions.pas
Assembling (pipe) fov_functions.s
Compiling game_states.pas
Assembling (pipe) game_states.s
Assembling (pipe) engine.s
Linking engine
./libBearLibTerminal.dylib
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/crt1.10.5.o
engine.o
/usr/local/lib/fpc/3.0.4/units/x86_64-darwin/rtl/objpas.o
/usr/local/lib/fpc/3.0.4/units/x86_64-darwin/rtl/system.o
bltcrt.o
input_handlers.o
entity.o
render_functions.o
map_objects.o
fov_functions.o
game_states.o
BearLibTerminal.o
/usr/local/lib/fpc/3.0.4/units/x86_64-darwin/rtl/types.o
/usr/local/lib/fpc/3.0.4/units/x86_64-darwin/rtl/math.o
/usr/local/lib/fpc/3.0.4/units/x86_64-darwin/rtl/unix.o
/usr/local/lib/fpc/3.0.4/units/x86_64-darwin/rtl/sysutils.o
/usr/local/lib/fpc/3.0.4/units/x86_64-darwin/rtl/errors.o
/usr/local/lib/fpc/3.0.4/units/x86_64-darwin/rtl/sysconst.o
/usr/local/lib/fpc/3.0.4/units/x86_64-darwin/rtl/unixtype.o
/usr/local/lib/fpc/3.0.4/units/x86_64-darwin/rtl/baseunix.o
/usr/local/lib/fpc/3.0.4/units/x86_64-darwin/rtl/sysctl.o
/usr/local/lib/fpc/3.0.4/units/x86_64-darwin/rtl/unixutil.o
/usr/local/lib/fpc/3.0.4/units/x86_64-darwin/rtl/initc.o
/usr/local/lib/fpc/3.0.4/units/x86_64-darwin/rtl/ctypes.o
/usr/local/lib/fpc/3.0.4/units/x86_64-darwin/rtl/classes.o
/usr/local/lib/fpc/3.0.4/units/x86_64-darwin/rtl/typinfo.o
/usr/local/lib/fpc/3.0.4/units/x86_64-darwin/rtl/rtlconsts.o
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib//libc.tbd
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/system/libcache.tbd
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/system/libcommonCrypto.tbd
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/system/libcompiler_rt.tbd
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/system/libcopyfile.tbd
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/system/libcorecrypto.tbd
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/system/libdispatch.tbd
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/system/libdyld.tbd
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/system/libkeymgr.tbd
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/system/liblaunch.tbd
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/system/libmacho.tbd
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/system/libquarantine.tbd
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/system/libremovefile.tbd
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/system/libsystem_asl.tbd
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/system/libsystem_blocks.tbd
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/system/libsystem_c.tbd
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/system/libsystem_configuration.tbd
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/system/libsystem_coreservices.tbd
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/system/libsystem_darwin.tbd
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/system/libsystem_dnssd.tbd
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/system/libsystem_info.tbd
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/system/libsystem_kernel.tbd
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/system/libsystem_m.tbd
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/system/libsystem_malloc.tbd
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/system/libsystem_networkextension.tbd
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/system/libsystem_notify.tbd
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/system/libsystem_platform.tbd
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/system/libsystem_pthread.tbd
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/system/libsystem_sandbox.tbd
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/system/libsystem_secinit.tbd
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/system/libsystem_symptoms.tbd
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/system/libsystem_trace.tbd
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/system/libunwind.tbd
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/system/libxpc.tbd
1567 lines compiled, 1.2 sec
3 note(s) issued
air:tui d-_-b$ ./engine
An unhandled exception occurred at $00007FFF441DE132:
EInvalidOp: Invalid floating point operation
  $00007FFF441DE132
  $00007FFF441DDF78
  $00007FFF2E5348B1
  $00007FFF2E534856
  $00007FFF2E533BBB
  $00007FFF2E53065A
  $00007FFF2E53015E
  $00007FFF2E52FBA2
  $00007FFF2E52FB3A
  $00007FFF2E4FD8D9
  $00007FFF2E4FCC16
  $00007FFF2E4FCA9C
  $00007FFF2E52F6AD
  $00007FFF2E52F111
  $00007FFF2E52F35F
  $00007FFF2E52EB63
  $00007FFF2E52E7F0

I also built their library from source on my machine using cmake and xcode, but that also did not resolve the issue.

Any insight or suggestions?

Thanks,

Edit:

Finally got it to work in laz-ide. Shows this error(screenshot cmd+c does not seem to copy the text) and then the assembler window breaks here:

Code: [Select]
00007FFF441DE122                          : 66 0f 28 0d 56 32 0c 00  movapd 0xc3256(%rip), %xmm1      ; __ASTC_encodeToData.backgroundColor + 94
00007FFF441DE12A                          : 66 0f 57 cb              xorpd  %xmm3, %xmm1
00007FFF441DE12E                          : 66 0f 28 e3              movapd %xmm3, %xmm4
00007FFF441DE132                          : f2 0f 51 c9              sqrtsd %xmm1, %xmm1

Call stack:

Code: [Select]
#0 CUIRenderer::Draw at :-1
#1 CUIDraw at :-1
#2 _HIThemeCUIDrawWithOptions at :-1
#3 _HIThemeCUIDrawWithRenderer at :-1
#4 _HIThemeDrawAppleMenuTitle at :-1
#5 HIMenuBarView::DrawOnce at :-1
#6 HIMenuBarView::DrawSelf at :-1
#7 HIMenuBarView::DrawWithoutCustomization at :-1
#8 HIMenuBarView::DrawingDelegateHandler at :-1
#9 DispatchEventToHandlers at :-1

To make sure the issue is related to fpc and not a problem with the library im using i tested the python package bearlibterminal-0.15.7-py2.py3-none-macosx_10_9_universal.whl and created a hello world application that works.
« Last Edit: August 09, 2019, 05:15:22 pm by d-_-b »
Code: Pascal  [Select]
  1. mov     ax,0013h
  2. int     10h
Denthor thanks for the vga programming tutorials | Download all tutorials

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 659
Re: How to debug issues with shared library libBearLibTerminal.dylib
« Reply #1 on: August 09, 2019, 05:22:06 pm »
So I got BearLibTerminal working on linux and windows using the prebuilt shared library, but with no success on macos.

I'm using their pascal interface in my unit and after figuring out the `-k'-lBearLibTerminal'`
It's better to add {$linklib BearLibTerminal} to your source code instead.

Quote
air:tui d-_-b$ ./engine
An unhandled exception occurred at $00007FFF441DE132:
EInvalidOp: Invalid floating point operation
FPC enables all floating point exceptions by default, because that's what Delphi does and what Pascal programmers expect. Much C code is written with the assumption that all floating point exceptions are disabled. If you need to make use of a C library that triggers floating point exceptions, include the "Math" unit and call SetExceptionMask([exDenormalized,exInvalidOp,exOverflow,exPrecision,exUnderflow,exZeroDivide]);

Note that this will also disable any floating point exceptions in your Pascal code, as this changes a CPU configuration register.

d-_-b

  • New Member
  • *
  • Posts: 24
Re: How to debug issues with shared library libBearLibTerminal.dylib
« Reply #2 on: August 09, 2019, 06:00:00 pm »
Much C code is written with the assumption that all floating point exceptions are disabled. If you need to make use of a C library that triggers floating point exceptions, include the "Math" unit and call SetExceptionMask([exDenormalized,exInvalidOp,exOverflow,exPrecision,exUnderflow,exZeroDivide]);

Sweet! Added the Math unit and called SetExceptionMask as recommend and now it works!
Code: Pascal  [Select]
  1. mov     ax,0013h
  2. int     10h
Denthor thanks for the vga programming tutorials | Download all tutorials