Introducing Kate GDB Plugin

Have you, like me, had to switch to an external debugger or run raw gdb in the terminal plugin to debug the C/C++ application you develop with Kate? That might not be necessary any more. There is now a “GDB Plugin” in trunk that gives you the power of raw GDB with some QAction candy for the most common actions.

I have always been a bit frustrated with not having a debugger directly in Kate, but too lazy/busy to start a debugger plugin project. Fortunately Ian Wakeling started this GDB plugin and got it off the ground. When I got introduced to it at Akademy, it triggered an itch in me to get this plugin into kdesdk and to add some features for the more point and click type of persons. As it seemed I had a bit more free time to spend on the plugin, Ian let me take over as maintainer.

Main features of the plugin:
– Jump to the corresponding file and line whenever gdb stops.
– Insert and remove breakpoints.
– Tool-bar buttons for the most often used actions like step into/over/out. Those actions can of course also be assigned to keyboard shortcuts.
– Execution markers and breakpoint markers on the icon border.
– A call stack tab for point and click navigation of the call stack.
– Optional IO redirection to a separate tab.
– Printing the value of the currently selected variable or expression. QStrings and friends are not supported (yet?).
– And last but not least. A GDB console for the full power of GDB.

And now the screen-shots

GDB Console, execution marker and a breakpoint marker.


The current call stack.


Settings tab.


Redirected IO.


The selected variable and the GDB value output.


The debug menu.

21 thoughts on “Introducing Kate GDB Plugin”

  1. To get QString etc. pp. printing going, you’ll have to setup pretty printing in your ~/.gdbinit

    KDevelop ships with the required pretty printer files, you should take a look there. Though imo they should not be copied all over the place…

    1. Those pretty printer files are just brilliant!

      I have seen something similar somewhere, in kdelibs I think, but they needed separate commands for the different types of variables.

      I think Niko Sams qt merge request should not have been rejected. (http://qt.gitorious.org/qt/qt/merge_requests/699)

      Maybe kdesdk/scripts/ would be the correct place for them?

  2. I’m using the plugin now but gdb seems to do its own thing while my code sits there. How do I get the breakpoints and current location to show up in the actual editor? And coding in Kate is now even better- thanks!

    1. Have you enabled the icon border (F6)?
      If you have and you are not moved to breakpoints whenthey are hit you might have hit a little bug where kate does not find the file to jump to. This should be fixed in trunk and will be part of KDE SC 4.7. The problem was/is relative file paths in stead of absolute paths in the application binary. CMake projects have absolute paths which makesiteasier to find and that was what I had tested with 🙂

  3. This is really sweet. I’ve always been a big fan of kate but now I am starting to use it as an IDE replacement for some of my daily work. The only short-coming I have run into with the GDB plugin is that I can not select which instance of gdb to execute.

    For instance; when doing embedded work, I want to run ‘arm-none-eabi-gdb’ instead of ‘gdb’, and sometimes pass some custom command line arguments such as a gdb init script for instance something like; “arm-none-eabi-gdb -x my-openocd-gdb-init.gdb” or so.

    So if, along the way you might find your way to provide us with a means to enable one to customize the gdb command and arguments, I think would really complete this feature.

    PS I’ve just made a quick and dirty hack where I fetch an environment variable with getenv() and plug it into the place of this statement; m_debugProcess.setShellCommand(“gdb”); I’m just starting to test that out, so far so good.

    1. That is definitely on my todo list. 🙂 If you check the KDE feature plan for 4.8 you will notice it there (“Add convenience options for remote debugging”). Unfortunately I did not manage to get it done in time for 4.8

  4. Thanks a lot for this plugin!

    I’m using this with Kate on Ubuntu. The one aspect that I’m having problems with is that the current execution marker and breakpoint marker don’t seem to be showing on the icon border. Any ideas what may be the cause for this? I’m using Kate 3.8.5.

    1. I think the plugin works best with builds that include the full path to the files in the debug symbols. Some times the debugger just does not know where to search for the sources. Setting a working directory close to the sources might help.

  5. I’ve been trying out gdb with Kate and think this will be really brilliant (:-( if I can get it to work). Kate has become my go-to editor. It is now good enough that I don’t use vim very much.

    Having said that, I have two suggestions:
    First: I’m having a few problems debugging cpp code in kate using gdb – I get a SIGSEGV (yes, I can debug my code in gdb). I am unable to copy the output out of the gdb console. Please can you enable that. It will help us to capture issues and post them. And please let us know where to post issues.

    Second: Is it possible to swap gdb with a variant (such as cuda-gdb)? I couldn’t figure out how to do this. I suggest allowing such a (re)configuration.

    1. Hi,

      Actually I never thought about needing the copy option as I use the mark + middle-click to paste 😉

      But yes a lot of people are used to the Ctrl-C/Ctrl-V vor copy paste…. Can you create a wish report at bugs.kde.org?

      The gdb command can be changed in the “Advanced Settings”, but note tho that the plugin is quite dependent on the gdb output format.

      /Kåre

      1. Thanks, I’ll create the wish report & will also try to capture the screenshot of the bug.

        re: changing gdb
        Yes I realize that the plugin will be very dependent on parsing the gdb output but I think it should not be limited by cuda-gdb – the output is essentially the same. I’ll try that and let you know here.

  6. Thank you for the nice work. I miss however some documentation on special cases. E.g. I am trying to use kate to debug a user library call from python. In this case I need to attach gdb to a running process (my python session calling the library). In a normal gdb session this is done starting gdb with -p or, with the attach command.
    I have try a few options to do this from kate but without success. Is this possible to do in kate?

    Thanks

    1. Hi,

      I was able to attach to a running instance. The only problem is that I need to do it as root and that is not so nice 🙂

      What I did was to start Kate as root, configure the GDB plugin for my application, run “Start Debugging” and then issue a “attach ” in the gdb lineedit. Then just debug ass normal.

      /Kåre

Leave a Reply