-
Notifications
You must be signed in to change notification settings - Fork 663
How to debug ogr2ogr2 (and other C and C packages)
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.
- Get the sources
- Figure out how to build the binaries
- Figure out how to configure the build in order to produce debugging symbols and non-optimized code
- Debug a problem: inspect a coredump or trace a live execution with a debugger
There are two options:
- get the debian source package
- get the source code from its repo.
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.
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.
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
sourceYou 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
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 buildotherwise check the README or INSTALL files.
TODO
TODO
TODO