Skip to content

Instantly share code, notes, and snippets.

@pmelsted
Last active November 2, 2015 15:03
Show Gist options
  • Save pmelsted/84714319c6a9b17945b3 to your computer and use it in GitHub Desktop.
Save pmelsted/84714319c6a9b17945b3 to your computer and use it in GitHub Desktop.
Debugging kallisto with gdb

You can debug kallisto with gdb and valgrind even if you can't compile it on your machine.

In order to do this you need to download the Debuggable binary, which is found on this gist.

You also need to place the source code in the same directory as where you will be debugging

wget https://github.com/pachterlab/kallisto/archive/v0.42.4.tar.gz
tar xzvf v0.42.4.tar.gz

this will enable gdb to see the source code.

First check that you can really run and debug the code

#check for running code
./kallisto_bin_Debug_0.42.4
kallisto 0.42.4

Usage: kallisto <CMD> [arguments] ..

Where <CMD> can be one of:

    index         Builds a kallisto index
    quant         Runs the quantification algorithm
    h5dump        Converts HDF5-formatted results to plaintext
    version       Prints version information

Running kallisto <CMD> without arguments prints usage information for <CMD>

and now for debugging

gdb ./kallisto_bin_Debug_0.42.4
GNU gdb (GDB) Red Hat Enterprise Linux (7.2-75.el6)
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/pmelsted/kallisto/debug/kallisto_bin_Debug_0.42.4...done.
(gdb) list main
719
720	  // chomp off the newline
721	  return ret.substr(0, ret.size() - 1);
722	}
723
724	int main(int argc, char *argv[]) {
725	  std::cout.sync_with_stdio(false);
726	  setvbuf(stdout, NULL, _IOFBF, 1048576);
727
728
(gdb)

If you don't see the source code, like line 724 for main, then gdb is not finding the source directories.

Now for some basic debugging, first we set a breakpoint in main and run the program.

(gdb) b main
Breakpoint 1 at 0x475035: file /kallisto-0.42.4/src/main.cpp, line 725.
(gdb) r
Starting program: /home/pmelsted/kallisto/debug/kallisto_bin_Debug_0.42.4
[Thread debugging using libthread_db enabled]

Breakpoint 1, main (argc=1, argv=0x7fffffffdf48) at /kallisto-0.42.4/src/main.cpp:725
725	  std::cout.sync_with_stdio(false);
Missing separate debuginfos, use: debuginfo-install glibc-2.12-1.149.el6.x86_64 libgcc-4.4.7-11.el6.x86_64

It complains about not having debugging info for some libraries, but that's normal. Now let's see the source code with l and step through the lines with n.

(gdb) l
720	  // chomp off the newline
721	  return ret.substr(0, ret.size() - 1);
722	}
723
724	int main(int argc, char *argv[]) {
725	  std::cout.sync_with_stdio(false);
726	  setvbuf(stdout, NULL, _IOFBF, 1048576);
727
728
729	  if (argc < 2) {
(gdb) n
726	  setvbuf(stdout, NULL, _IOFBF, 1048576);
(gdb) n
729	  if (argc < 2) {
(gdb)

Finally when we're ready to continue we hit c

(gdb) c
Continuing.
kallisto 0.42.4

Usage: kallisto <CMD> [arguments] ..

Where <CMD> can be one of:

    index         Builds a kallisto index
    quant         Runs the quantification algorithm
    h5dump        Converts HDF5-formatted results to plaintext
    version       Prints version information

Running kallisto <CMD> without arguments prints usage information for <CMD>


Program exited with code 01.
(gdb)

which shows that nothing went wrong.

There are many excellent tutorials on debugging, but the most useful information is usually from the backtrace bt and if an assert is hit you can navigate to the kallisto function that was potentially misbehaving by goint up or down the call stack.

This file has been truncated, but you can view the full file.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment