Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Catalog · How the catalog works

Random project

pascal-diagnostics-reporter

Thread-safe diagnostics, log encryption, and remote crash reporting framework in pure Object Pascal

View on GitHub

Anyone may press Interesting, signed in or not. It helps others find this project.

Member rating

No ratings yet.

Sign in to rate this project.

README

Pascal Diagnostics & Crash Reporter

A professional-grade, multi-threaded system diagnostics and automated remote crash reporting framework written in pure Object Pascal.

This repository demonstrates production-ready Pascal engineering, system programming, concurrency, network sockets, exception trapping, and low-level stack unwinding. It is designed to be highly compatible with Embarcadero RAD Studio (Delphi/C++Builder) and the Free Pascal Compiler (FPC).


Key Features

  • Thread-Safe Logging: Utilizes a background worker thread (TLogWriterThread) with a critical section-guarded queue to process logs asynchronously, ensuring that disk write operations never block the main application or UI thread.
  • Secure Log Obfuscation: Encrypts logs using a rolling-key symmetric stream cipher. Obfuscated binary data is serialized into hexadecimal strings to prevent platform-specific carriage-return or line-feed (\r\n) translations from corrupting the ciphertext.
  • System Telemetry: Queries operating system details, CPU core count, total physical memory, and available memory at startup.
  • Runtime Exception Hooking: Overrides the Pascal runtime exception vector (ExceptProc) to trap global unhandled exceptions and software failures.
  • Call Stack Resolution: Decodes the exception instruction pointer and walking call frames into human-readable symbols, including function names, source files, and exact line numbers (resolves dwarf symbols).
  • Automated Remote Upload: On application crash, the exception handler automatically flushes background logs and uploads the encrypted diagnostic log to a support server over TCP.
  • Diagnostics Server: A low-level TCP socket server written in Object Pascal that runs 24/7, accepts crash uploads, decrypts them, and logs the parsed stack traces for support teams.

Project Structure

pascal
????????? src/
???   ????????? Diagnostics.pas    - Thread-safe logging, system stats, encryption, and stack trace format
???   ????????? CrashReporter.pas  - TCP client socket code to upload log files
???   ????????? Server.pas         - Standalone TCP receiver that decrypts and saves uploaded logs
???   ????????? TestApp.pas        - Test program simulating thread logging, unhandled exception, and upload
????????? build.sh               - Script to compile Server and TestApp using FPC
????????? .gitignore             - Version control exclusions

How to Build and Run

1. Compile the Project

Make sure the Free Pascal Compiler (fpc) is installed on your system. Run the build script:

bash
./build.sh

This compiles the code with the -gl compiler switch to include dwarf line information and debug symbols (necessary for backtrace line numbers). Executables will be placed in the bin/ directory.

2. Start the Support Server

In one terminal window, start the central diagnostics server:

bash
./bin/Server

The server listens on port 8080 for crash uploads.

3. Run the Client Application

In another terminal window, run the test application:

bash
./bin/TestApp

The application will:

  1. Initialize the thread-safe diagnostic log.
  2. Query and log system telemetry.
  3. Spawn 3 concurrent threads logging iterations to demonstrate safety.
  4. Raise a software exception to simulate a critical application crash.
  5. Traps the exception, resolves the call stack, and uploads app_crash.log to the server.

4. Review the Crash Report

Check the server terminal output or look inside the received_crashes/ folder. You will find the fully decrypted log file detailing the system stats, worker thread operations, and the resolved crash call stack:

pascal
2026-07-18 22:42:21.047 [CRITICAL] [Thread 00007A2C401EB740]: Unhandled Exception Exception: Simulated critical crash!
Call Stack:
  at   $0000000000401974  TRIGGERCRASH,  line 80 of src/TestApp.pas
  at   $0000000000401DB0  main,  line 109 of src/TestApp.pas

Cross-Platform Compatibility

This framework is written in standard Object Pascal. The logging and networking routines run natively on:

  • Windows (Delphi / RAD Studio C++Builder)
  • Linux (Free Pascal Compiler)
  • macOS (Free Pascal Compiler)

License

This project is licensed under the MIT License.