| 60 | |
| 61 | == Debugging techniques == |
| 62 | |
| 63 | === Using a logging LIBC DLL === |
| 64 | |
| 65 | Modern 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 | |
| 67 | There 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. |
| 68 | In order to use it in place of the normal version, do the following: |
| 69 | |
| 70 | 1. Make sure you have `LIBCxyz.logchk` installed and that `xyz` matches the version of LIBC you normally use. |
| 71 | 2. Put this fragment to your CONFIG.SYS: |
| 72 | {{{ |
| 73 | REM // Disable all LIBC logging in the logchk dll by default |
| 74 | SET LIBC_LOGGING=-ALL |
| 75 | }}} |
| 76 | 3. Unlock `LIBCxyz.dll` and rename it to `LIBCxyz.dll.normal`. |
| 77 | 4. Rename `LIBCxyz.logchk` to `LIBCxyz.dll`. |
| 78 | 5. Reboot. |
| 79 | |
| 80 | Note 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 | |
| 82 | In 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 | {{{ |
| 84 | SET LIBC_LOGGING=+ALL |
| 85 | }}} |
| 86 | before 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 | {{{ |
| 88 | SET LIBC_LOGGING=+ALL-IO |
| 89 | }}} |
| 90 | |
| 91 | If 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 | |
| 93 | Note 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). |