Changes between Version 12 and Version 13 of PortingTips


Ignore:
Timestamp:
Jun 26, 2017, 2:12:44 PM (7 years ago)
Author:
dmik
Comment:

Add LIBC logchk usage info

Legend:

Unmodified
Added
Removed
Modified
  • PortingTips

    v12 v13  
    5858
    5959Note though that if you need to add such a block more than once, it makes sense to add AC_CANONICAL_TARGET right after AC_INIT to `configure.ac` and go with //Method 1// described above.
     60
     61== Debugging techniques ==
     62
     63=== Using a logging LIBC DLL ===
     64
     65Modern OS/2 programs are built with GCC which uses [http://trac.netlabs.org/libc/ kLIBC] as its POSIX-like C runtime library. This library provides a powerful logging facility where it logs a lot of internal actions as well as entry and exit from each public function it provides. Sometimes, especially when debugging application crashes that can't be caught by other means, it is very handy to get this logging for your application.
     66
     67There are several versions of the LIBC DLL in each release. The normal version, `LIBCxyz.dll`, is an optimized build that doesn't provide any logging or debug info. The logging version is called `LIBCxyz.logchk`. In the RPM environment this DLL lives in the `libc-devel` package.
     68In order to use it in place of the normal version, do the following:
     69
     701. Make sure you have `LIBCxyz.logchk` installed and that `xyz` matches the version of LIBC you normally use.
     712. Put this fragment to your CONFIG.SYS:
     72{{{
     73REM // Disable all LIBC logging in the logchk dll by default
     74SET LIBC_LOGGING=-ALL
     75}}}
     763. Unlock `LIBCxyz.dll` and rename it to `LIBCxyz.dll.normal`.
     774. Rename `LIBCxyz.logchk` to `LIBCxyz.dll`.
     785. Reboot.
     79
     80Note that this will cause **all** applications linked against `LIBCxyz.dll` to create a log file named `libc-ABCD.log` in the application's current directory where ABCD is a hex number of a running process. Given that we disabled all logging by `SET LIBC_LOGGING=-ALL` in CONFIG.SYS, these files will only contain a small log header and won't grow at runtime — this is done to avoid excessive logging for unneeded applications and unnecessary slowdown caused by this logging.
     81
     82In order to get anything useful in the log file, you need to enable logging for your application. This is done by overriding the `LIBC_LOGGING` environment value before starting it. To enable full logging, just do
     83{{{
     84SET LIBC_LOGGING=+ALL
     85}}}
     86before starting the application. Not that this will produce a huge amount of logs especially if your application starts other processes which will also have all logging enabled. You may fine-tune what to log using log groups as defined in http://svn.netlabs.org/repos/libc/branches/libc-0.6/src/emx/src/lib/sys/logstrict.c (look for `aDefGrps`). For example, in order to enable all but I/O logging, you do
     87{{{
     88SET LIBC_LOGGING=+ALL-IO
     89}}}
     90
     91If you want to go back to the normal LIBC version, just unlock `LIBCxyz.dll`, rename it back to `LIBCxyz.logchk`, rename `LIBCxyz.dll.normal` to `LIBCxyz.dll` and reboot.
     92
     93Note that while technically you could copy `LIBCxyz.logchk` to a separate directory, rename it to `LIBCxyz.dll` there and then set BEGINLIBPATH=<DIR> and LIBPATHSTRICT=T in the environment to have this version of LIBC used for your process without rebooting, this will not work well. Doing so will lead to having two **different** LIBC copies in memory which don't cooperate because of the LIBC design that assumes there is only one active LIBC DLL at a time. In particular, having more than one DLL it is known to make forked children crash with some weird errors (even if one manages to separate shared structures of different LIBC versions by using unique mutex and shared memory names).