LinuxQuestions.org
Visit Jeremy's Blog.
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 08-12-2001, 09:36 PM   #1
jiangdir
LQ Newbie
 
Registered: Aug 2001
Posts: 1

Rep: Reputation: 0
Lightbulb more about gdb


My question about gdb is that I hope it can provide more details.For example, we have a program like this:

#include <stdio.h>

main( ) {
char* a=new char[100];
a="I love music."; //line 3
printf("%s\n",a);
delete [] a; //line 5


}

and it is easy to find that this program has some problem. gcc can pass it, but after running, the program gives out "segmentation fault". Right, line 3 is where the problem is in.
In my opinion, in line 3, compiler will generate a temporary object which holds "I love music".
and compiler will then give the address of this temporary object to char* a. This is terrible.
First, this temporary object is not dynamicly created, so it can not be destroyed by "delete".
Second , the resource generated by "new char[100]" may never be free, so this cause memory leak. The first problem is easy to deal with. Just delete line 5 is ok. But this will not help dealing with the second problem. Because the true problem happens in line 3. If gdb can provide more details about program , such as show us the generation of temporary object, we can deal with the programs more effectively.
Another program:

class KApplication : public QApplication, public KInstance
{
KApplication::KApplication( ) : QApplicatin( ), KInstance( ) {

.......//do something
} //constructor end

}

So if we write "KApplication app = new Kapplication( );" , we know what will happen. First, QApplication::QApplication( ) and KInstance::KInstance( ) will be called. And then,
KApplication::Kapplication it self will be called. (we not think about _new(size_t size ) which will malloc memory for our object) . Soon before , I can see all this process happen by "step" in gdb. But now, I can not see the process of QApplication::QApplication( ) and KInstance::KInstance( ). I don't know what has happened to my gdb. And even more, few days ago,
when I use "step" to watch my program, I can even see the process of constructor and destructor of temporary object. And now, nothing. Can you give some hint ?

really thanks. If you can tell me some forum about gdb, it will also help.


Jiang
 
  


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
gdb sabeel Programming 2 03-26-2007 07:58 PM
normal gdb and spec gdb for kgdb Igor007 Programming 1 09-23-2005 04:15 PM
normal gdb and spec gdb for kgdb Igor007 Linux - Newbie 1 09-23-2005 01:41 PM
gdb .. looking for 32 bit gdb.. for ia64 suse.. nkshirsagar SUSE / openSUSE 0 12-09-2004 03:02 AM
gdb vose Programming 1 07-17-2004 11:08 PM

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

All times are GMT -5. The time now is 12:01 PM.

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