Skip to content
0-8-15 edited this page Oct 11, 2020 · 10 revisions

Log file location

By default LambdaNative sets the current-exception-handler to log:exception-handler. This results in all errors and additional desired logging information to be written to the applications log/ folder.

Note for Android and iOS Devices

Debug log files will only be created on Android and iOS devices if the log directory exists. You can either create this directory at /log on your device or through some other means or you can place the following code at the beginning of your init method:

(let ((logdir (string-append (system-directory) "/log")))
  (if (not (file-exists? logdir)) (create-directory logdir)))

Which will create the directory if it doesn't exist. N.B.: that you will have to run your program a second time after the creation of the log directory in order for the log to appear there, as the decision as to whether to log or not is made before the init method.

Advanced debugging

If the regular logfile doesn't show the error, the following procedure can be attempted: Configure the application in debug mode, using ./configure <appname> debug. Clean the cache, so that gambit-c is rebuild in with source lines, using make scrub. The following make; make install will take a while as the entire system is rebuild in debug mode. Logfiles will now contain the trace of the error to the line, where it occured.

Syntax error example

If DemoConsole is changed to include(sin 2.3 3.3), and invalid command for the (sin x) function it will compile without errors when using ./configure DemoConsole; make; However, when run with make install it will exit without an error. When followed up with cat ~/Desktop/DemoConsole.app/log/* the following errors are found:

[SYSTEM] 2015-01-28 09:58:15: Application DemoConsole built 2015-01-28 09:58:09
[SYSTEM] 2015-01-28 09:58:15: Git hash lambdanative: 6c06e2b,parts: 3f70dff
[ERROR] 2015-01-28 09:58:15: primordial: (sin 2.3 3.3): Wrong number of arguments passed to procedure
[ERROR] 2015-01-28 09:58:15: HALT

Undefined variable example using debug mode

If DemoConsole is changed to include(sin undef), whereby undef is not defined, it will throw a warning during compilation with ./configure DemoConsole debug; make;

 => creating gsc link..
 *** WARNING -- "undef" is not defined,
 ***            referenced in: ("/home/mg/documents/Programming/lambdanative-cache/linux/build/4285167665.c")
  => generating hook..

However, when run with make install it will cause a segmentation fault. When followed up with cat ~/Desktop/DemoConsole.app/log/* the following errors are found, which point to the location of the error:

[SYSTEM] 2015-02-01 00:24:08: Git hash lambdanative: 7443b12,parts: 4dc8857
[ERROR] 2015-02-01 00:24:08: primordial: (sin #!unbound): (Argument 1) NUMBER expected
[ERROR] 2015-02-01 00:24:08: trace: /home/mg/documents/Programming/lambdanative/apps/DemoConsole/main.scm line=40 col=1
[ERROR] 2015-02-01 00:24:08: HALT

Low-level debugging with C debugger

Sometimes the higher level debugging facilities are inadequate, either because of errors in linked C code, or disabled safety checks due to optimization. In that case it is possible to use the system C debugger (gdb or lldb) to find the location of a crash. To do so the entire LambdaNative cache must be built with debug enabled. To ensure this is the case, perform a make scrub followed by ./configure yourApp debug and make. Once complete, all C code in the application binary will have debug information, and running the app through the system C debugger will reveal the location of low-level crashes with references to the Scheme source.

On Linux profiling is enabled in debug mode. After running the application a file gmon.out is written in the current directory, which can be analyses using gprof program-image.

On Android, it is possible to to analyze stack dumps in the log through a debug symbol database, the location of which will be reported as part of the build output (only when debug is enabled), e.g.

...
DEBUG: android build is in /Users/you/.lambdanative/tmp.MmHdYt
...

You can now get crash debug information as follows:

adb logcat | $NDK/ndk-stack -sym /Users/you/.lambdanative/tmp.MmHdYt/obj/local/armeabi

where $NDK is the location of the Android NDK.

Clone this wiki locally