Saturday, June 19, 2010

Kate: Debugging with Qt-Creator

Let's have a quick look at how to debug Kate and KWrite with Qt-Creator. First, make sure you meet the requirements:
  1. build Kate according to this tutorial
  2. install Qt-Creator (in my case this is version 2.0.0rc1)
Setup the Kate project Qt-Creator once like this
  1. start Qt-Creator: ~/kde/ /path/to/qtcreator/bin/qtcreator
  2. invoke File > Open File or Project and choose ~/kde/kate/CMakeLists.txt
  3. Build Location: choose ~/kde/build
  4. Run CMake arguments: choose ../kate -DCMAKE_BUILD_TYPE=debugfull -DCMAKE_INSTALL_PREFIX=~/kde/usr
  5. click the button "Run CMake" and then "Finish"
Start debugging like this
  1. click the "hammer" icon button on the very bottom left to compile Kate
  2. click the "computer" icon button (3 icons above the hammer icon) and choose "kate" (or "kwrite") in the Run combo box
  3. choose the "Debug" icon in the left pane
  4. invoke "Debug > Start Debugging (F5)", now Kate starts
  5. open part/document/katedocument.cpp in the file tree view on the left
  6. go to the line "KateDocument::insertText" and click "Debug > Toggle Breakpoint (F9)"
  7. now if you type a character in Kate, Qt-Crator will halt in KateDocument::insertText
  8. chose "Debug > Step Opver (F10)" (and "Debug > Stip Into (F11)") to step through the code
  9. click on "Locals and Watchers" in the debugging pane on the bottom and you see the values of local variables
Happy debugging :)


vivo said...

with qtcreator 1.3.1 and an a system installed kate it's a bit more complex than this.

you need to tell qtcreator the right paths for it not to use /usr/lib64/

I've just no idea how to do that though :p

git compiled kate is started from command line the with the following bash script:

export KATE_DIR=~/usr
export PATH=$KATE_DIR/bin:$PATH
# update KDE's system configuration cache
# start app
kate $@

vivo said...

but you can start kate as an aeternal application and then attach to it later from Debug->Start Debugging->Attach to running exernal application

dhaumann said...

@vivo: if i undestand correctly, that's why you simply should start qt-crator already with the script:

~/kde/ /path/to/qtcreator/bin/qtcreator

Now, qt-creator has automatically all paths set correctly out of the box.

vivo said...

@dhaumann oops