Nice little gotcha when loading SOS after launching .Net executable
When you launch .Net executable with WinDBG, in order to “catch” something nasty like AccessViolationExcetion, the application will stop after loading with a “debugger break”, and you will see something like this:
123(6b8.37dc): Break instruction exception - code 80000003 (first chance)ntdll!LdrpDoDebuggerBreak+0x30:00007ffc`391d121c cc int 3
At this point, if you try to load SOS, you will see an error.
120:000> .loadby sos coreclrUnable to find module 'coreclr'
Th ...
Setting up WinDBG for analyzing memory dumps
When I needed to investigate a memory dump for a first time, I stared at WinDBG window, not knowing how to begin. My google-fu yielded mixed results - I had to sift through lots of information, sometimes incorrect, sometimes outdated, only after some experimentation, I was able to actually understand what was going on.Though, in a hindsight, WinDBG is much less complex than it seemed in the first place.
A word (or three) on WinDBGWinDBG wikipedia article states that WinDbg is a multipurpose deb ...
Segmentation faults when using P/Invoke = pointer issues? Not necessarily
When debugging new RavenDB’s 32-bit pager for Linux-based ARM environments, which has platform specific functionality implemented in C and P/Invoked from C# code, I ran into an issue: when starting, RavenDB was throwing a segmentation fault and crashing. Since the C# code didn’t change much, my immediate suspect was some sort of pointer issue in C code, such as trying to dereference a null pointer.
GDB is awesome for handling segfaultsThe GNU Debugger or GDB is very good at tracing such issues. ...
Hunter, C++ package management made easy
In a previous post, I detailed involved and frustrating process I needed to go through to compile OpenCV as part of my application. You can see the post in this link.All the trouble I describe there could have been avoided by using Hunter - a CMake based package manager for C++ projects. The idea is to have a sort-of repository of configuration and install scripts for different packages that would handle configuring 3rd-party dependencies (and their dependencies) for your project. Kinda like NuG ...
OpenCV + Visual Studio + CMake = Adventure time
In theory, configuring a popular library like OpenCV in CMake should be easy. In practice, sadly, it is anything BUT easy. Why? Let me show you…
Note that I am not very knowledgeable in CMake, so it is possible I am doing something stupid. If so, it is even worse - as far as I understand the intent behind CMake, it should make developers lives easier, not harder.
This post is documentation of a frustrating journey of performing what should have been a trivial task - make dependency compile as ...
Hello ANTLR (writing parsers is easier than you think!)
After playing around with the awesome ANTLR for a while (it is a parser generator, in case you are not familiar with it), I decided to write something that could have helped me before I started looking into parsers. This post assumes you have heard of parsers but never actually wrote one.
A word (or two) on what parsers areWhen you have a text with known syntax, be it structured logging, programming language or configuration files and you want to parse it with an application, you can use a parse ...
Even simple stuff, like C# TPL can surprise you!
What do you think would happen if you run this code? Can you guess without actually running it?Now try running it and see what happens. It might actually surprise you…
I know I was surprised by this, it took me a minute or two and a glimpse into relevant documentation page to understand what happened here.The backgroundTask in the above code is actually a continuation task, and not the background worker. Since the background worker runs successfully, the continuation task is canceled, as it ...
Yet Another (Cryptic) CMake Error
I like CMake. I really do. But sometimes… it is frustrating.The samples found online are understandable and easy to follow and everything compiles fine until you try something non-trivial.Like having an external project compile as part of your own so including and linking can be done easier.I have created a new CMake project, then added sources of OpenCV with as a git submodule.The resulting CMake file looked like this:
123456cmake_minimum_required (VERSION 3.13)project ("[some project name ...
Adventures of a C# dev in C++ land - dependency injection
I stumbled upon Boost.DI by accident and was instantly intrigued: for a developer used to C#, dependency injection during compilation time sounds crazy.
Boost.DI uses C++ template metaprogramming to implement its functionality. If you are not familiar with it, take a look here.
Dependency InjectionResolves dependencies during compilation sounds great as an optimization. The biggest problem with DI libraries in C# is performance.Just take a look at IOC/DI library benchmarks!
In case you are n ...
Synchronization primitives + async/await = trouble
Recently, my colleague was investigating an interesting issue. A ReaderWriterLockSlim was sometimes throwing the following exception when releasing a read lock.
1System.Threading.SynchronizationLockException: 'The read lock is being released without being held.'
The code looked fairly straightforward and it should have worked properly, but after some meditation on the mysteries of C# and the universe, he noticed something interesting. An await call between taking the lock and releasin ...