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)

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

TODO

Configure the build

TODO

Trace a live execution with gdb

TODO

Debug a coredump

TODO

Clone this wiki locally