LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-30-2005, 08:23 AM   #1
aikempshall
Member
 
Registered: Nov 2003
Location: Bristol, Britain
Distribution: Slackware
Posts: 900

Rep: Reputation: 153Reputation: 153
KDevelop and debugging


I'm adding an enhancement to kooka using KDevelop. The enhancement is working as expected. However, in getting there, it would have simplified matters if I could have used the KDevelop debugger.

How?

In the C++ tab of Project Options -> Configure Options I added -ggdb to the compiler flags text box.

I can use gdb at the command line to debug the program.

If I Debug -> Start in KDevelop the KDevelop application refreshes itself very fast with what looks like a message at the bottom of the screen in the vicinity of the application, diff, messages tab.

Also I can't run kooka from within KDevelop using Build -> Execute Program

Can anyone help?
 
Old 12-01-2005, 04:57 PM   #2
TruongAn
Member
 
Registered: Dec 2004
Location: Vietnam (Việt Nam)
Distribution: Gentoo (desktop), Arch linux (laptop)
Posts: 728

Rep: Reputation: 33
My problem is similar to yours.
I don't build add-in but I write a program.
When I want to start the program inside KDevelop to debug it, I cann't interact with it.
How can you debug a program without interaction.
I have no solution.
I just avoid using KDevlop for debugging
 
Old 12-01-2005, 05:06 PM   #3
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
kdevelop 3.2.92 on KDE 3.4.2 fedora core 4

I've got a C++ project to debug as follows:

Project->Project Options

To bring up the Project Options dialog box.

Select the Configure Options page

On the general tab select Debug from the configuration drop down list.

This adds the following switch
Code:
--enable-debug=full
I hope that helps.

graeme.
 
Old 12-02-2005, 10:58 AM   #4
TruongAn
Member
 
Registered: Dec 2004
Location: Vietnam (Việt Nam)
Distribution: Gentoo (desktop), Arch linux (laptop)
Posts: 728

Rep: Reputation: 33
This line was there.
It has been always there.
No need to add it.
I got the problem even with these line.
 
Old 12-02-2005, 11:49 AM   #5
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
Hi,

Once I have compiled mu project with the debug switch all I need to do is to add break points from within kDevelop and I can trace through the program. I've not had any major problems debugging, occasionally I have needed to rebuild the project file because I have messed it up somewhere. The other problem is trying to debug a subproject which doesn't have the debug compile switch set. I find this happens because when I run Kdevelop on some of my projects it defaults to a sub project which hasn't got any debug info set.

Also note that the start in debugger doesn't recompile your source code.

What is your version of kdevelop and gdb?

graeme.
 
Old 12-04-2005, 05:55 AM   #6
aikempshall
Member
 
Registered: Nov 2003
Location: Bristol, Britain
Distribution: Slackware
Posts: 900

Original Poster
Rep: Reputation: 153Reputation: 153
I've gone back to basics an created a new project

C++ -> KDE -> Simple KDE Application

called myWorld3

Built project

Set breakpoints

Debug -> Start

The debugger didn't stop at any of the breakpoints! The only code file open was myWorld3.cpp

So opened the file main.cpp an set a breakpoint on the line -

KCmdLineArgs::init(argc, argv, &about);

then Debug -> Start

and hey it stopped at the appropriate line

Then clicked on the "Step into next statement" icon loads of times. Eventually it moved into kaapplication.h and qapplication.h and then back to main.cpp before eventually dropping into the myWorld3.cpp file.

I then let the program run but it wouldn't stop at the breakpoint. This may be due to something graemef indicated -

Quote:
The other problem is trying to debug a subproject which doesn't have the debug compile switch set. I find this happens because when I run Kdevelop on some of my projects it defaults to a sub project which hasn't got any debug info set.
Anyway made some progress. I will let you know how I get on.


Thanks
 
Old 12-04-2005, 12:21 PM   #7
aikempshall
Member
 
Registered: Nov 2003
Location: Bristol, Britain
Distribution: Slackware
Posts: 900

Original Poster
Rep: Reputation: 153Reputation: 153
If I debug from the command line with

gdb myworld3

I can set breakpoints in main.cpp and also in myworld3.cpp. gdb stops at breakpoints in main.cpp but always continues past the breakpoints in myworld3.cpp, even though I can step through and see the code in myworld3.cpp.

Is there a problem with the way myworld3.cpp is being compiled in that I can step through the code but not use breakpoint?

Thansk in anticipation.
 
Old 12-05-2005, 05:14 AM   #8
aikempshall
Member
 
Registered: Nov 2003
Location: Bristol, Britain
Distribution: Slackware
Posts: 900

Original Poster
Rep: Reputation: 153Reputation: 153
I've now made a simple program with two files

main.cpp which contains

Code:
#include "myworld3.h"
#include <stdio.h>

int main(int argc, char **argv)
{
    myWorld3 *mainWin = 0;
    int i;
    i=99;
    printf("%d\n",i);
    mainWin = new myWorld3();

}
and myworld3.cpp which contains

Code:
#include "myworld3.h"
#include <stdio.h>

myWorld3::myWorld3()
{
    printf("Hello World\n");
}

myWorld3::~myWorld3()
{
}

Possibly the relevant part of the compilation for the two files is

if g++ -DHAVE_CONFIG_H -I. -I/home/alex/myworld3/src -I.. -I/opt/kde/include -I/usr/lib/qt/include -I/usr/X11R6/include -DQT_THREAD_SUPPORT -D_REENTRANT -Wnon-virtual-dtor -Wno-long-long -Wundef -Wall -W -Wpointer-arith -Wwrite-strings -ansi -D_XOPEN_SOURCE=500 -D_BSD_SOURCE -Wcast-align -Wconversion -Wchar-subscripts -ggdb3 -Wformat-security -Wmissing-format-attribute -fno-exceptions -fno-check-new -fno-common -MT main.o -MD -MP -MF ".deps/main.Tpo" -c -o main.o /home/alex/myworld3/src/main.cpp;

and

if g++ -DHAVE_CONFIG_H -I. -I/home/alex/myworld3/src -I.. -I/opt/kde/include -I/usr/lib/qt/include -I/usr/X11R6/include -DQT_THREAD_SUPPORT -D_REENTRANT -Wnon-virtual-dtor -Wno-long-long -Wundef -Wall -W -Wpointer-arith -Wwrite-strings -ansi -D_XOPEN_SOURCE=500 -D_BSD_SOURCE -Wcast-align -Wconversion -Wchar-subscripts -ggdb3 -Wformat-security -Wmissing-format-attribute -fno-exceptions -fno-check-new -fno-common -MT myworld3.o -MD -MP -MF ".deps/myworld3.Tpo" -c -o myworld3.o /home/alex/myworld3/src/myworld3.cpp;

then for libtool - not sure where this comes into the picture -

/bin/sh ../libtool --silent --tag=CXX --mode=link g++ -Wnon-virtual-dtor -Wno-long-long -Wundef -Wall -W -Wpointer-arith -Wwrite-strings -ansi -D_XOPEN_SOURCE=500 -D_BSD_SOURCE -Wcast-align -Wconversion -Wchar-subscripts -ggdb3 -Wformat-security -Wmissing-format-attribute -fno-exceptions -fno-check-new -fno-common -o myworld3 -R /opt/kde/lib -R /usr/lib/qt/lib -R /usr/X11R6/lib -L/usr/X11R6/lib -L/usr/lib/qt/lib -L/opt/kde/lib main.o myworld3.o -lkdeui


I then run gdb on the executable setting 1 breakpoint in main.cpp and another in myworld3.cpp. gdb stops at the first breakpoint but not the second.


alex@LINUX:~/myworld3/debug/src$ gdb myworld3
GNU gdb 6.3
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i486-slackware-linux"...Using host libthread_db library "/lib/libthread_db.so.1".

(gdb) b main.cpp:10
Breakpoint 1 at 0x8048766: file /home/alex/myworld3/src/main.cpp, line 10.
(gdb) b myworld3.cpp:6
Breakpoint 2 at 0x804879f: file /home/alex/myworld3/src/myworld3.cpp, line 6.
(gdb) run
Starting program: /home/alex/myworld3/debug/src/myworld3
[Thread debugging using libthread_db enabled]
[New Thread 16384 (LWP 25813)]
99
[Switching to Thread 16384 (LWP 25813)]

Breakpoint 1, main (argc=1, argv=0xbfffe924) at /home/alex/myworld3/src/main.cpp:10
10 mainWin = new myWorld3();
(gdb) c
Continuing.
Hello World

Program exited normally.
(gdb) quit
alex@LINUX:~/myworld3/debug/src$


Also I can step from the first breakpoint(in main.cpp) into myworld3.cpp like so

alex@LINUX:~/myworld3/debug/src$ gdb myworld3
GNU gdb 6.3
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i486-slackware-linux"...Using host libthread_db library "/lib/libthread_db.so.1".

(gdb) b main.cpp:10
Breakpoint 1 at 0x8048766: file /home/alex/myworld3/src/main.cpp, line 10.
(gdb) b myworld3.cpp:6
Breakpoint 2 at 0x804879f: file /home/alex/myworld3/src/myworld3.cpp, line 6.
(gdb) run
Starting program: /home/alex/myworld3/debug/src/myworld3
[Thread debugging using libthread_db enabled]
[New Thread 16384 (LWP 26441)]
99
[Switching to Thread 16384 (LWP 26441)]

Breakpoint 1, main (argc=1, argv=0xbfffef24) at /home/alex/myworld3/src/main.cpp:10
10 mainWin = new myWorld3();
(gdb) s
myWorld3 (this=0x804fad8) at /home/alex/myworld3/src/myworld3.cpp:5
5 {
(gdb) s
6 printf("Hello World\n");
(gdb) c
Continuing.
Hello World

Program exited normally.
(gdb)

Notice that it didn't stop at
Code:
printf("Hello World\n");
Has anyone any suggestions as to why this should be so?

Last edited by aikempshall; 12-05-2005 at 05:15 AM.
 
Old 12-05-2005, 06:10 AM   #9
aikempshall
Member
 
Registered: Nov 2003
Location: Bristol, Britain
Distribution: Slackware
Posts: 900

Original Poster
Rep: Reputation: 153Reputation: 153
I am now using this Makefile -

Code:
myworld3: myworld3.o main.o
        g++ -ggdb -o myworld3 main.o myworld3.o
main.o:   main.cpp myworld3.h
        g++ -ggdb -c -o main.o main.cpp
myworld3.o: myworld3.cpp myworld3.h
        g++ -ggdb -c -o myworld3.o myworld3.cpp

Cannot get gdb to acknowledge a breakpoint in myworld.cpp
 
Old 12-05-2005, 07:37 AM   #10
aikempshall
Member
 
Registered: Nov 2003
Location: Bristol, Britain
Distribution: Slackware
Posts: 900

Original Poster
Rep: Reputation: 153Reputation: 153
gdb breakpoints ignored

Solved. Well sort of.

In the Announcement for gdb 6.3 see

http://www.gnu.org/software/gdb/download/ANNOUNCEMENT

It states

g
Quote:
db/1091: Constructor breakpoints ignored
gdb/1193: g++ 3.3 creates multiple constructors: gdb 5.3 can't set breakpoints

When gcc 3.x compiles a C++ constructor or C++ destructor, it generates
2 or 3 different versions of the object code. These versions have
unique mangled names (they have to, in order for linking to work), but
they have identical source code names, which leads to a great deal of
confusion. Specifically, if you set a breakpoint in a constructor or a
destructor, gdb will put a breakpoint in one of the versions, but your
program may execute the other version. This makes it impossible to set
breakpoints reliably in constructors or destructors.
I therefore changed my code, in myworld3.cpp, to

Code:
myWorld3::myWorld3()
{
 mycode();
}

void myWorld3::mycode(void )
{
    int i;
    i=58;
    printf("%d\n",i);
    printf("Hello World\n");
}

myWorld3::~myWorld3()
{
}

I then ran gdb setting the breakpoints in mycode and gdb stopped at the appropriate breakpoint. I found it be searching on
Quote:
gdb breakpoints
in google groups - 225 out of 2,200 whereas
Quote:
gdb breakpoints ignored
gave 8 hits on the first page!
 
Old 12-05-2005, 08:46 AM   #11
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
Quote:
When gcc 3.x compiles a C++ constructor or C++ destructor...


... This makes it impossible to set breakpoints reliably in constructors or destructors.
Interesting...

I've actually got it working on my machine (sorry for having been so quiet but I was on Windows all weekend).

I was using version 4.0.2 of g++ and 6.3.0 of gdb.

So maybe an upgrade of g++ would solve it for you but obviously the separate initialisation function also works. Whilst I'd say that a separate initialisation function is good design you probably would like to add breakpoints in the constructor. So maybe that would be your next step...?

all the best.

graeme.
 
Old 12-05-2005, 09:13 AM   #12
aikempshall
Member
 
Registered: Nov 2003
Location: Bristol, Britain
Distribution: Slackware
Posts: 900

Original Poster
Rep: Reputation: 153Reputation: 153
I'm sure at some stage I will need to add breakpoints to constructors. Hopefully by then Slackware will have incoprorated gcc 4.0.2 or later. It currently uses 3.3.6. I would expect that the next slackware release to be out about April/May 2006.

Thanks for your help. I still can't debug Kooka from within KDevelop. But can, with gdb, from the command line. As I've picked up the source from the kdegraphics-3.4.2 package I probably need to craft the appropriate directory structure to debug the program by trying to emulate what the myworld programs are doing.

Thanks for your help.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Debugging Mercurius Programming 3 10-19-2005 02:59 PM
Visual Debugging and Linux Kernel Debugging Igor007 Programming 0 09-30-2005 10:33 AM
Debugging Evgeny Linux - Networking 1 02-15-2005 01:32 PM
Wvdial debugging jato Linux - Networking 2 12-30-2004 03:14 AM
debugging devit Programming 1 02-10-2004 11:49 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:53 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration