Farewell to this blog

I no longer write Symbian code, work as a CS researcher and might not even be quite as angsty as before.

I’ve written a post-mortem on the technology that was Symbian.

New blog posts will live on my new blog. See you all there!

Posted in Symbian | 2 Comments

mkswigfile: easy loading of C++ code into clojure, like mkoctfile

Octave has mkoctfile which allows you to load and reload C/C++ code into the environment. Java has JNI and with SWIG it’s fairly easy to access code written in C++, but there’s no built-in hot loading for clojure.

The code in
shows an example on how to do this.

Posted in Uncategorized | Comments Off

Debugging crashes in JNI code on windows

If you run into an access violation in your native code called from java you normally get a hs_err_pid<pid>.log file that may or may contain a usable stack trace. This text is about how to do better than that: launch a debugger (or create a real crash dump) at the point of the crash.The (sun) jvm installs an exception filter. The jvm also uses/handles structured exceptions internally: there are a lot of first-chance exceptions that are part of the normal running of the jvm and you are not interested in. You don’t want to break on all first-chance exceptions (as, e.g., gdb would by default do).

Hence, you need to let the jvm notice that this is not the kind of exception it can handle, but is a real problem.

A windows process can pass on an exception it can’t handle. This is called a second-chance exception and it can be handed over to a debugger.

If you use -XX:OnError or -XX:+ShowMessageBoxOnError the jvm _doesn’t_ generate a second-chance exception. You can use these options to attach a debugger or to generate a core dump, but the exception and its context are gone.

The only option (AFAICT) that doesn’t lose the exception context is -XX:+UseOSErrorReporting. This lets the second-chance exception bubble up to normal windows error handling: Windows Error Reporting (http://support.microsoft.com/kb/310414) and/or Just-in-time debugging (http://support.microsoft.com/kb/103861) (and generates a hs_err<pid>.log file).

For the debugger you can use windbg (free-as-in-beer, from Windows Debugging Tools, now distributed as a part of the Platform SDK) or Visual Studio (the non-free version, Express editions cannot be used for just-in-time debugging), or some other debugger like OllyDbg or watcom debugger.

You need to choose a debugger that supports the symbol information for your executables. This pretty much means that if you want to compile with gcc you need to use gdb or drmingw (the normal gcc debug information formats, stabs and DWARF2 are not supported by microsoft debuggers, and although some people claim that the COFF symbol table produced by ‘gcc -gcoff’ can be read by windbg I’ve never been able to make that work) – if you want to use Microsoft’s debuggers you need to build with Microsoft compilers (from Visual Studio or Platform SDK (or WinDDK)) or something else that creates windows symbols, like Intel compilers.

BTW1, the jvm won’t read symbols from gcc-compiled code either, so if you want symbols in the hs_err_pid<pid>.log files, you need to compile with something that produces windows-like symbols.

BTW2, if you launch a process under cygwin, it doesn’t use the platform just-in-time debugging configuration and hence -XX:+UseOSErrorReporting doesn’t work either. You can fix this by calling ::SetErrorMode(0) somewhere. See https://bugs.webkit.org/show_bug.cgi?id=55222

BTW3, this is all on the (currently latest) JDK 6u27. The release notes claim there were improvements to exception handling in native code.

Posted in Uncategorized | Comments Off

E32USER-CBase 65 misdocumentation

The SDK documents E32USER-CBase 65 as

The panic is raised as a result of a call to the Pop() and PopAndDestroy() static member functions of the CleanupStack class. The panic occurs when an attempt is made to pop more items from the cleanup stack than are on the cleanup stack.

That’s not true. E32USER-CBase 65 is triggered from PopAll() or PopAndDestroyAll() if the current cleanup stack is not the one for which TRAP was called. PopAndDestroyAll() is called when you call User::Leave().

I triggered this when I had no new TRAP() around a leaving piece of code after having created a CEikonEnv, which creates a new cleanup stack.

Simple thing, but the documentation pointed me in the wrong direction so took a while to figure out.

Posted in Symbian | Comments Off

My Phd thesis is on sale on amazon

I wanted to play with Amazon’s seller side and the only thing I could reasonably put up for sale is my thesis, Exploring privacy for ubiquitous computing: Tools, methods and experiments (I, like many Finnish PhDs, have a stack of them lying around).

Get yours from http://www.amazon.co.uk/gp/product/9521039868 :-)

Posted in CS, Privacy | Comments Off

Inspecting UI state / windows /controls on Symbian

On Win32 and other windowing systems you can walk the window tree and ask windows for their type, state, contents etc. On Symbian there is no such built-in introspection.

However, it is possible to get access to a lot of information with enough hacks:

  • Use a FEP so your code gets loaded into all apps
  • Use various methods (control stack, window tree, container structure) to find out about windows and controls
  • Detect/Guess/hardcode the control class and use the native methods to ask it for contents

http://github.com/mikaraento/tts has a complete example. It’s the code from a project I did for a client that refused to pay in the end. Enjoy.

(note that the code is by no means complete and will for example crash on FP2 AFAIK)

Posted in Symbian | Comments Off

Symbian HTTP POST and KErrCorrupt

This is something I guess everybody who writes a HTTP POST using MHTTPDataSupplier goes through… (at least that’s what it looks like on the forums). I didn’t find a clear answer so I thought I’d write it down myself.

GetNextDataPart() needs to return _the same buffer_ until ReleaseData() is called, and it will get called several times for the same part. If you don’t respect that the transaction will terminate with KErrCorrupt.

Posted in Symbian | Comments Off

Example SConstruct for googletest + tip on UI tests

This slots into a project based on hello_openc

from scons_symbian import *

target     = "googletest_main"
targettype = "exe"
libraries  = ['libstdcpp', 'libc', 'euser']

# Static libs
staticlibs = ['libcrt0.lib']

uid3 = 0xA0001314

sources = ['../src/googletest_main.cpp',

includes    = ['../data', '../inc', '../../../third_party/googletest', '../../..']
sysincludes = [
  join(EPOC32_INCLUDE, "stdapis"),
  join(EPOC32_INCLUDE, "stdapis/stlport"),
defines     = ['_STLP_NO_WCHAR_T']

SymbianProgram( target, targettype,
    sources = sources,
    includes    = includes,
    sysincludes = sysincludes,
    libraries   = staticlibs+libraries,
    defines     = defines,
    epocstacksize = 8192,
    epocheapsize  = (0x1000,0x100000),
    uid3 = uid3,
    resources = [ "../data/googletest_main_reg.rss" ]

BTW, for running tests that use UI in the emulator you want to wait for the emulator to start up some more than it has by the time you hit your main(). Use something like

void WaitForMenuExe() {
#ifdef __WINS__
  scoped_ptr<TFullName> fulln(new TFullName);
  TUint32 menu_uid = 0x101f4cd2;
  while(true) {
    TFindProcess find;
    while (find.Next(*fulln) == KErrNone) {
      RProcess p;
      if (p.SecureId().iId == menu_uid) {
    User::After(10 * 1000);
#endif  // __WINS__
Posted in Symbian | Comments Off

Heap/leak checking googletest tests

Leak checking is part of good programming practice (as leaked objects normally point to bugs in general). Symbian has its leak checking macros, but they aren’t completely trivial to use with Googletest (googletest has been designed with a whole-program reachability-based leak checker in mind, like OS X’s ‘leaks’) – googletest itself allocates memory in some cases.

The easiest way to add Symbian-style leak checking is to use a test fixture. Just add an instance of HeapChecker as the first member of your test fixture. HeapChecker looks like:



#include "third_party/googletest/include/gtest/gtest.h"

// HeapChecker is a scoped object that checks whether any memory has been
// leaked over its lifetime. It is used together with googletest test fixtures:
// it checks whether the test had any failures which cause allocations and
// in that case doesn't do the checking. It is meant to be held as
// the first member of a test fixture.
class HeapChecker {
  HeapChecker(testing::Test* test);

  testing::Test* test_;
  int alloc_count_;


#include "testing/public/heapcheck.h"

#include <e32std.h>
#include <ecom/ecom.h>

#include "third_party/googletest/include/gtest/gtest.h"

namespace {
bool any_failures = false;

HeapChecker::HeapChecker(testing::Test* test) : test_(test) {
  if (any_failures) return;
  User::__DbgMarkStart(EFalse /* aKernel */);
  alloc_count_ = User::Heap().Count();

HeapChecker::~HeapChecker() {
  if (any_failures) return;
  TInt ignore_alloc_count = 0;
  if (test_->HasFailure()) {
    ignore_alloc_count = User::Heap().Count() - alloc_count_;
  User::__DbgMarkEnd(EFalse /* aKernel */, ignore_alloc_count);
  if (test_->HasFailure()) {
    any_failures = true;

Using a base test fixture for all your tests is good practice, as it’s the best way to insert custom checks – the actual test runner in Googletest doesn’t have (enough) hooks.

Posted in Symbian | 3 Comments

Googlemock 1.4.0 works on Symbian!

Googlemock – arguably the best C++ mocking framework now works on Symbian (winscw and gcc-e – I haven’t tried rvct). Although I’m obviously biased I really recommend it for all your mocking needs. Requires a recent OpenC.

If you have problems getting everything working on Symbian I’d be interested in hearing them – here or via e-mail.

Posted in Symbian | Comments Off