Skip to main content

Posts

Setting up OS X for kernel debugging

Here are the steps to prepare an OS X system for debugging kernel modules such as drivers. The instructions are deliberately brief to save the reader from tons of text.
If you search the web, you will come across may resources that point to using GDB to debug the kernel. These resources were written in the early days of OS X when versions 10.4 or 10.5 were prevalent. Since around v10.9 (or thereabouts), Mac moved to lldb as their debugger of choice and have continually improved it to enable easier setup & more efficient workflow.

This short post has the instructions to setting up lldb for debugging OS X kernel versions 10.11 and above.

My setup is using a Parallels VM as the target on the development system. But it should work on a separate hardware that is connected via network to the host.

Debuggee is the target system where drivers are deployed and tested. This also referred to as the target system. Debugger is the host system, typically running your development tools with the …

How to view kernel logs in OS X

How to view kernel logs is OS X You can use the command line tool log for this.

This command accepts a predicate argument that can be used to , well build predicates, that when evaluates to true, the log message will be printed. It takes a command argument that decides how the logs are to be displayed. For instance

log stream

produces a streaming output of the log. That is new log messages are displayed as they come (asynchronously).

log show

displays messages from the log history.

log --process 0

displays messages from process with ID 0, which is kernel. This can be used to display all kext log messages.

log show --predicate 'processID == 0'

displays messages printed by processID 0, which is the kernel process. This is the same as the previous command.

To display messages from a driver, you may use the sender predicate filter argument. So if your driver is named mytestdriver, you may display messages from it using the command:

log stream --predicate 'sender == "mytestdri…

Ionic 4 HTTP CORS Issue

Ionic 4 is a major upgrade to previous version of Ionic. One of the primary differences between Ionic 4 and its previous incarnations is that Ionic 4 uses web components, which are custom HTML elements written using web standards (as opposed to using a slap-on framework such as Angular).
Ionic 4 also makes a fundamental change in how the created app is rendered (I use rendered as apps are essentially HTML which is rendered using the native WebView control of the device's UI framework) in a device. While earlier versions used to refer to the top level index.html using file:// URI scheme, Ionic 4 internally spins up an HTTP server on localhost (yes for each app) and then loads the index.html through a standard HTTP request such as http://localhost:port/index.html.
Problem I'm not sure what necessitated this change, but I reckon it probably had something to do with native API restrictions, which in turn was prompted by need for improved security. This, however, introduces a new (…

Notes of the day

A recent project requirement from a customer for a cross-platform solution prompted me to look into viable frameworks for this. Based on my knowledge of languages (C++, Python & Javascript), I narrowed the potential solutions to wxWidgets & Git Electron. Since I have been spending some time with Python over the last two years and given its ease of use, I through I'll look into wxPython, the Python projection of wxWidgets framework.

Here are my notes from this research today morning:
wxPython provides a genuine means to build cross platform GUI apps (installed through PyPi pip install wxpython).Python code can be compiled into distributable binaries using cx_Freeze, another cross-platform tool that can generate binaries for Windows, Mac & Linux. cx_Freeze can provide executable files as well as installable binaries such as MSI or DMG files.cx_Freeze source repo has sample code for various deployment scenarios. One of them is wxPython based application.Py2Exe is a popula…

Downloading & opening a file in an Ionic app

If you search the Internet for examples to achieve the above, you'll get a number of resources that suggest using the cordova-file-transfer plugin. However, with Ionic 3+ and its native API, you can do this directly using a mix of Angular and Ionic File API.

Essentially, you need to use Angular HttpClient to download a URL as a Blob using the responseType option and then save the resultant Blob to a file on the device using the File API. Finally, open the saved file using the Ionic native FileOpener API.

Here's the method in a provider that is used to download files from a website. Note that this.http is an instance of HttpClient.

/** * Download a file from the given url. * * Params: * url - the URL to download the file from * Returns: * A promise which upon resolution returns a dictionary * { * fileEntry: FileEntry, * type: The content-type string for the file * } */ download(url): Promise<{ fileEntry: FileEntry, type: s…

Cordova build errors

Had this unusual errors crop up when building a cordova app for android. This started appearing after I installed cordova-plugin-file-opener2.

ERROR: In <declare-styleable> FontFamilyFont, unable to find attribute android:fontVariationSettings ERROR: In <declare-styleable> FontFamilyFont, unable to find attribute android:ttcIndex
Going through platforms/android/project.properties file, I realized that there was something quite odd about it.

cordova.system.library.1=com.android.support:support-v13:26.+ cordova.system.library.2=me.leolin:ShortcutBadger:1.1.17@aar cordova.system.library.3=com.google.firebase:firebase-messaging:11.0.1 cordova.system.library.4=com.android.support:support-v4:27.1.0 cordova.system.library.5=com.android.support:support-v4:24.1.1+ cordova.system.library.6=com.android.support:support-v4:+
There were multiple versions of the same library being defined.

I removed the last three lines -- library.4, library.5 & library.6, ensuring that the the high…

Celery on Windows

Running celery on Windows, shows the following error when tasks are queued to be executed:
ValueError: not enough values to unpack (expected 3, got 0)
The way to fix this is to add --pool=solo to the celery daemon command line. This makes celery run as a solo process and without concurrency, which for development purposes shouldn't be a big deal.

So the entire daemon command would look something like this:
python -m celery -A config worker --pool=solo -l info
Taken from this Github thread.

Steps to Install Redis server

Few steps necessary to build and install Redis on a server. There are no pre-built packages available for you to apt-get install it. So you have to grab the source, compile and install the generated binaries. Fortunately it all goes pretty smooth. $ wget http://download.redis.io/releases/redis-4.0.2.tar.gz $ tar xzf redis-4.0.2.tar.gz $ cd redis-4.0.2 $ make $ make test # install compiled binaries to /ur/lib/bin $ sudo make install # setup redis-server as daemon $ cd utils $ sudo ./install_server.sh # setup redis-server to autostart $ sudo update-rc.d redis_6379 defaults
That ought to do it!

Volvo Door Mirror Mismatched Folding

One of the problems that I encountered with the S80 is that when I unlocked the car and pressed the button to unfold the door mirrors, they would be out of sync with each other. That is one would open and at the same time the other would close. You can open the closed mirror manually, but when you press the button to fold then mirrors, one would close and the the other would remain open.

After some research online, I figured out the problem -- the mirror's folded/open position is stored in memory and the car uses this position to instruct the mirror motors on what action to perform (fold/unfold) when you press the button to unfold the mirrors again. Now if you're in a hurry and happen to switch off the vehicle before the mirror folding operation could be completed, storing of the mirror position in memory cannot be completed accurately.

The solution to the problem turns out to be very simple.
Turn off the car.Locate the fuse box in the passenger compartment. Locate fuses for l…

How to Integrate Sphinx with a Django Project for Automatic Documentation Generation

A few points on integrating Sphinx with a Django redistributable project for generating documentation embedded in the source files.
Project directory structure should look like this:
django-redistributable/ demo/ demo/ settings.py urls.py wsgi.py templates/ manage.py docs/ conf.py index.rst Makefile make.bat redistributable/ models.py views.py templates/ static/ tests/ setup.py MANIFEST.in README.rst LICENSE requirements.txt Install sphinx and sphinx-autobuild using pip.Run sphinx-quickstart from the docs folder. Provide default answers for all prompts.Edit docs/conf.py such that the redistributable package and the demo project's apps are importable from the docs folder. At the top of the conf.py file:import os import sys import django sys.path.insert(0, os.path.dirname(os.path.dirname(__file__))) sys.path.append(os.path.join(os.path.dirname(os.path.dirname(__file__)), 'demo')) Setup sphinx such…