Skip to content

How to debug ogr2ogr2 (and other C and C packages)

rafatower edited this page Dec 19, 2014 · 4 revisions

How to debug ogr2ogr2

Intro

In order to debug a C or C++ program, in general two conditions must be met:

  • The package must contain debugging symbols
  • The code shouldn't be optimized

These imply that a binary package suitable for production won't be in general suitable for debugging.

In this guide I'll describe the process, focusing on ogr2ogr2 binary, but similar steps can be applied to debug any other C or C++ in general.

High level overview

  1. Get the sources
  2. Figure out how to build the binaries
  3. Figure out how to configure the build in order to produce debugging symbols and non-optimized code
  4. Debug a problem: inspect a coredump or trace a live execution with a debugger

Get the sources

There are two options:

The debian source package differs from the source in that it usually contains specific build options and potentially some patches, plus some other information such as dependencies on other packages.

The ogr2ogr2 binary is actually part of the gdal project. You can get the sources from:

(the mirror works just great so most likely you won't need to use svn, commits are cross-referenced)

I forked the gdal project and added the debian stuff in a branch to ease maintenance of the package. You can find the debian source package in github here:

https://github.com/rafatower/gdal/tree/ogr2ogr2

That is probably your best option for ogr2ogr2 particular case.

Get the dependencies

If you use a debian system for building, then the debian source package contains all the information you need to get the dependencies automatically:

sudo apt-get build-dep ogr2ogr2-static-bin

Otherwise, the source code usually contains information about the dependencies in a README or INSTALL file, always worth reading. If you don't have them all, you'll get a failure at compilation time that will hint you about the missing dependency.

Figure out how to build the binaries

From the debian source package

The debian source package will always contain enough information to build the binary package in a reproducible way. You can deduce a lot about how the package is built by taking a look at the debian directory:

$ cd gdal/debian
$ ls -1
changelog # description of different versions of the package
compat 
control # description of source and binary packages, dependencies and other stuff
ogr2ogr2-static-bin.install
rules # <-- build rules
source

You can find more about debian files here: https://www.debian.org/doc/manuals/maint-guide/dreq.en.html

If you have the debian directory then you can use its tools to build the binary package. More on this here: https://github.com/CartoDB/cartodb/wiki/How-to-build-gdal-&-ogr2ogr2

From the vanilla sources

Many, many packages use autoconf & autotools plus make to manage their builds. I won't get into details but essentially:

./configure --help # displays a lot of configuration options
./configure # actually configure sources for build
make # trigger the build

otherwise check the README or INSTALL files.

Configure the build

TODO

Trace a live execution with gdb

TODO

Debug a coredump

TODO

Clone this wiki locally