Git Product home page Git Product logo

pretty-printk's Introduction

pretty-printk

Build Status

Overview / Usage / Features / License / Links

Debugging the Linux Kernel in a way most developers are familiar with is challenging. Setting breakpoints, stepping through code and watching for the last important variable to change is hard. Sometimes just printing values to the Kernel Ring Buffer can be a better and especially faster approach to debugging. After having print almost the hundredths message with printk it started to feel dull and pointed me to tinker with its output.

When developing for the Web it is quite common to pretty such output and I was wondering why not to take my chances and pretty the printk-ing inside the Kernel. The goal is to ease on the hand the process of printing and on the other one it should increase readability when running dmesg.

#include "pretty_printk.h"

  // [...]

  pp_warn("Shortcut for severity level and flushing '\\n' character");

  // Extended Metadata (function, filename and line number)
  // pp_debug will only print when PP_DEBUG is defined
  // ---
  pp_debug("Extended metadata while printk-ing with debug=1 or PP_DEBUG");

  // Dumping multiple variables with valid type specifiers
  // i: integer, c: character, s: character array (string)
  // ---
  pp_dump("ics", 10, 'a', "some char array");

  // Walking through code
  // ---
  pp_walker();

  // Color Output
  // pp_<color> will only colorize when either PP_COLORS is defined
  // ---
  pp_info("Colorize dmesg output with colors=1 or PP_COLORS");
  pp_info("Example colors: %s, %s, %s... and a few more.", pp_red("red"),
  pp_green("green"), pp_blue("blue"));

  // Shortcut-ed output of condition for tracing not-yet-understood logic
  // ---
  int x_pos = 16;
  int x = 64;

  if (x_pos <= x) {
    pp_true("x_pos <= x");
  } else {
    pp_false("x_pos <= x");

    goto out;
  }

   // [...]
[ 12.300004] pp_demo_module: Shortcut for severity level and flushing '\n' character
[ 12.300006] pp_demo_module (pretty_printk_demo_init @ pretty_printk_demo.c, 61): Extended metadata while printk-ing with debug=1 or PP_DEBUG
[ 12.300010] pp_demo_module: Dumping data
[ 12.300011]  1. 10
[ 12.300012]  2. a
[ 12.300013]  3. some char array
[ 12.300015] pp_demo_module (pretty_printk_demo_init @ pretty_printk_demo.c, 70): It worked up to this line
[ 12.300017] pp_demo_module: Colorize dmesg output with colors=1 or PP_COLORS
[ 12.300018] pp_demo_module: Example colors: red, green, blue... and a few more. Yes, colors are in the output, but not in this README :)
[ 12.300019] pp_demo_module (pretty_printk_demo_init @ pretty_printk_demo.c, 85): x_pos <= x is true

For testing, debugging and looking at the features the repository provides a demo module pp_demo_module to illustrate the different features. For building just call make and insert/remove the module in the common tools. Inside the init function all features are demonstrated.

Feature Issue Merge Commit Status
Metadata when printk-ing #3 7fcb473 done
Severity shortcuts #4 3dfc02d done
Switch for debugging #5 62be4d5 done
Pretty print of multiple variables #6 e11d951 done
Walking Macro #7 ab52416 done
Shortcut for discovering conditional expressions #8 f35b3ec done
Generic testing pipeline with Travis CI #9 5b459c7 done
Testing pipeline for different major Kernel versions #10 - todo
Testing pipeline for different architectures #11 - todo
Convenient throttling of printk #13 - todo
Colorize output #14 530fa57 done

pretty-printk is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version.

pretty-printk is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with pretty-printk. If not, see https://www.gnu.org/licenses/.

pretty-printk's People

Contributors

tpiekarski avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

sam42x 2rr0r4o3

pretty-printk's Issues

Color macros

Brief Description
Colorize output with short little macros, like red(), green(), blue()

Additional context
none

Create toolchain and a skeleton module

Brief Description
For development create mandatory toolchain and later for illustration of features and usage create already a skeleton Linux Kernel Module

Additional context
none

Gather and output surrounding information

Brief Description
Gather and output surrounding information with a handy macro which could be useful in debugging. Which information should be discussed.

Additional context
none

Create a walking print macro

Brief Description
Create a simple macro for walking through code to find the lines which do not work - a Walker :)

Additional context
none

Add licensing information

Brief Description
Add information about licensing information, update README.md and add GPLv2

Additional context
none

Throttling macro

Brief Description
Integrated a convenient throttling for printing to avoid flooding ring buffer

Additional context
none

Banner macro

Brief Description
Macro for generate little ASCII-art banners

Additional context
none

Prettify printing multiple variables

Brief Description
Add a macro for pretty printing of multiple variables like...

| Variable | Value |
| x        | 10    |
| y        | foo   |
| z        | 0x4ff |

Additional context
none

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.