The Linux Page

Debug a package crashing while being compiled on a PPA.

I have a CMakeLists.txt file and I run a command while building and if one of my libraries has an issue, then it will crash and it becomes close to impossible to debug unless you can run the debugger.

The fact is that I could tweak my CMakeLists.txt to run the command with gdb and get a stacktrace which helped much.

Here is the command I ran:

     add_custom_command(
        OUTPUT
            ${CMAKE_CURRENT_BINARY_DIR}/${ATOMIC_NAMES_BASENAME}.cpp
            ${CMAKE_CURRENT_BINARY_DIR}/${ATOMIC_NAMES_BASENAME}.h

        COMMAND
           "gdb"
                "-batch"
                "-ex"
                "run"
                "-ex"
                "bt"
                "--args"
                "${ATOMIC_NAMES_PROGRAM}"
                    "--output-path"
                        "${CMAKE_CURRENT_BINARY_DIR}"
                    "${CMAKE_CURRENT_SOURCE_DIR}/${ATOMIC_NAMES}"
                    "--verbose"

        WORKING_DIRECTORY
            ${PROJECT_SOURCE_DIR}

        MAIN_DEPENDENCY
            ${ATOMIC_NAMES}
    )

That's it!

With that script, instead of running my atomic-names command as is, it ran inside gdb and the result is that I get a stack trace (the "bt" command).

The options are:

-batch -- run as a batch (i.e. execute commands and then exit)

-ex run -- run the command

-ex bt -- display the stack trace

--args ... -- the command and its arguments