FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Debian > Debian User

 
 
LinkBack Thread Tools
 
Old 01-29-2009, 05:47 PM
"H.S."
 
Default C++ templates and debugging (limitations) in Linux

Hello,

This is related to templates in C++ and debugging tools we have in Linux
(I use gdb, is there any other comparable open source tool?).


What do C++ programmers here think about the usefulness of using
templates in C++ while keeping in mind how it would work with debugging
that program using gdb.

I recall that a few years ago (a few version of gdb and gcc ago) I was
having trouble debugging an algorithm I implemented in C++ using
templates. I do not recall the exact problems but after a few online
searches it appeared that the easiest way was to not to use templates
(one problem was that I has having difficulty to examine template
variables). IIRC, gdb was not very friendly while debugging C++ code
with templates.

Can C++ programmers here share their recent experience in this regard? I
have a program for an engineering problem of around 5000 lines and I
need to change some of the data variable from one type to another.
Currently I am of the mind to just change the variable type. Would it be
worthwhile instead to use templates in this situation so that I can then
maintain only one copy for different data types? I am debugging the
source code using gdb and I am not sure if it will become much more
tedious to debug if I use templates. Comments and feedback are welcome.

Regards.

--

Please reply to this list only. I read this list on its corresponding
newsgroup on gmane.org. Replies sent to my email address are just
filtered to a folder in my mailbox and get periodically deleted without
ever having been read.


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 01-29-2009, 05:54 PM
Nelson Castillo
 
Default C++ templates and debugging (limitations) in Linux

On Thu, Jan 29, 2009 at 1:47 PM, H.S. <hs.samix@gmail.com> wrote:
> Hello,
>
> This is related to templates in C++ and debugging tools we have in Linux
> (I use gdb, is there any other comparable open source tool?).
>
>
> What do C++ programmers here think about the usefulness of using
> templates in C++ while keeping in mind how it would work with debugging
> that program using gdb.
>
> I recall that a few years ago (a few version of gdb and gcc ago) I was
> having trouble debugging an algorithm I implemented in C++ using
> templates. I do not recall the exact problems but after a few online
> searches it appeared that the easiest way was to not to use templates
> (one problem was that I has having difficulty to examine template
> variables). IIRC, gdb was not very friendly while debugging C++ code
> with templates.

This is for the STL but I think it is useful for other templates.
When I had that issue that is the best I could do for examining
template variables and I think it just works.

http://wiki.freaks-unidos.net/weblogs/arhuaco/debugging-stl-code-with-gdb

I am also interested in your experiences (I use more C than C++ now
but I guess I might use C++ once in a while).

N.-


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 01-29-2009, 05:58 PM
"Eugene V. Lyubimkin"
 
Default C++ templates and debugging (limitations) in Linux

H.S. wrote:
> Hello,
>
> This is related to templates in C++ and debugging tools we have in Linux
> (I use gdb, is there any other comparable open source tool?).
>
>
> What do C++ programmers here think about the usefulness of using
> templates in C++ while keeping in mind how it would work with debugging
> that program using gdb.
>
> I recall that a few years ago (a few version of gdb and gcc ago) I was
> having trouble debugging an algorithm I implemented in C++ using
> templates. I do not recall the exact problems but after a few online
> searches it appeared that the easiest way was to not to use templates
> (one problem was that I has having difficulty to examine template
> variables). IIRC, gdb was not very friendly while debugging C++ code
> with templates.
>
> Can C++ programmers here share their recent experience in this regard? I
> have a program for an engineering problem of around 5000 lines and I
> need to change some of the data variable from one type to another.
> Currently I am of the mind to just change the variable type. Would it be
> worthwhile instead to use templates in this situation so that I can then
> maintain only one copy for different data types? I am debugging the
> source code using gdb and I am not sure if it will become much more
> tedious to debug if I use templates. Comments and feedback are welcome.
IIRC things are slightly better than several ago. I had been debugging several C++
problems with templates without significant problems during last years. However, some
things are not debuggable by design - template variables are compile-time things, I doubt
where can gdb find values of even non-type variables.

--
Eugene V. Lyubimkin aka JackYF, JID: jackyf.devel(maildog)gmail.com
Ukrainian C++ developer, Debian Maintainer, APT contributor
 
Old 01-29-2009, 06:05 PM
Mike Bird
 
Default C++ templates and debugging (limitations) in Linux

On Thu January 29 2009 10:47:27 H.S. wrote:
> Can C++ programmers here share their recent experience in this regard? I
> have a program for an engineering problem of around 5000 lines and I
> need to change some of the data variable from one type to another.
> Currently I am of the mind to just change the variable type. Would it be
> worthwhile instead to use templates in this situation so that I can then
> maintain only one copy for different data types? I am debugging the
> source code using gdb and I am not sure if it will become much more
> tedious to debug if I use templates. Comments and feedback are welcome.

Maintaining one copy instead of two is (almost) always a good idea,
and one of the reasons why templates are so valuable.

Start with a working program. Make a small change. Fix compilation
errors. Test it. Fix any problems. Commit to VCS. Repeat.

Occasional misbehavior is usually resolved with the assistance of
"std::cerr << foo;" or a more sophisticated variant. About the only
time I use gdb is to find a clue if a bug causes a segfault.

In your case it may be possible to incrementally convert the code
for the original datatype to templated code, and then once that is
done add the second datatype.

There are more appropriate places than debian-user for C++ questions.

--Mike Bird


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 01-29-2009, 06:34 PM
"H.S."
 
Default C++ templates and debugging (limitations) in Linux

Mike Bird wrote:

>
> Maintaining one copy instead of two is (almost) always a good idea,
> and one of the reasons why templates are so valuable.

Yes, it is. But here there is this other factor of the suitability of
gdb with templates and STL for debugging. I not sure I know the
intricacies involved to weigh the costs. My past experience was not very
positive.

>
> Start with a working program. Make a small change. Fix compilation
> errors. Test it. Fix any problems. Commit to VCS. Repeat.

Yes, that is what I do already.

>
> Occasional misbehavior is usually resolved with the assistance of
> "std::cerr << foo;" or a more sophisticated variant. About the only
> time I use gdb is to find a clue if a bug causes a segfault.

I also ended up printing variables when I tried to use templates a few
years ago. At that time I thought that that was inefficient, having a
lot of print statements, but it was the only way I could actually see
inside a template variable involving STL.


> In your case it may be possible to incrementally convert the code
> for the original datatype to templated code, and then once that is
> done add the second datatype.

Yup, I agree.

>
> There are more appropriate places than debian-user for C++ questions.

Yes. There is a news group for C++, but the people there are topic
nazis. Anything not strictly related to the standard is promptly
flogged, hanged, skinned and left to dry.

My query, however, was related to the behaviour of combination of C++,
templates, STL and gdb.

The proper place for this query would probably be the newsgroup for gdb.
But that is extremely low traffic.

Hence my post here with the OT warning.



--

Please reply to this list only. I read this list on its corresponding
newsgroup on gmane.org. Replies sent to my email address are just
filtered to a folder in my mailbox and get periodically deleted without
ever having been read.


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 01-30-2009, 02:35 AM
Daniel Burrows
 
Default C++ templates and debugging (limitations) in Linux

On Thu, Jan 29, 2009 at 01:47:27PM -0500, "H.S." <hs.samix@gmail.com> was heard to say:
> This is related to templates in C++ and debugging tools we have in Linux
> (I use gdb, is there any other comparable open source tool?).

Not that I know of.

> I recall that a few years ago (a few version of gdb and gcc ago) I was
> having trouble debugging an algorithm I implemented in C++ using
> templates. I do not recall the exact problems but after a few online
> searches it appeared that the easiest way was to not to use templates
> (one problem was that I has having difficulty to examine template
> variables). IIRC, gdb was not very friendly while debugging C++ code
> with templates.

Personally, I almost only use a debugger to get backtraces after a
crash. I find logging statements to be easier, more reliable, and more
useful. If you write cout<< statements directly into your code, of
course, it gets cluttered and unwieldly -- I would suggest taking a look
at a logging framework like log4cxx (available in Debian, even ).
That also means that log statements you insert will stick around for
later re-use should you ever have more questions about that bit of the
code.

Why do I find logging statements more useful? Because

(a) you can output information in a way that's useful for you, not
just however the debugger wants to print it (think about, e.g.,
sets stored as binary trees...),
(b) logging statements let you analyze the whole flow of a program
at once -- I once tracked a bug down by running a simple
statistical analysis to calculate which lines were most likely
to precede a crash,
(c) logging statements can be enabled by users and the output sent
to you; much easier than convincing them to install and use a
debugger, and
(d) last but not least, debugger sessions are very ephemeral -- step
too far or let the program exit and you've lost your chance.
Logging statements can be stored and reviewed at leisure,
compared easily between different versions of the program, etc.

The one place where logging fails is when you have some sort of race
condition or another timing-sensitive bug.

Probably a sufficiently complex debugger could emulate that, but why
should I inject a complicated piece of software into my debug process
(injecting also a good chance of bugs in the tool itself), when I can
just write a few log output lines?

Daniel


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 01-30-2009, 11:49 AM
"H.S."
 
Default C++ templates and debugging (limitations) in Linux

Daniel Burrows wrote:

>
> Personally, I almost only use a debugger to get backtraces after a
> crash. I find logging statements to be easier, more reliable, and more
> useful. If you write cout<< statements directly into your code, of
> course, it gets cluttered and unwieldly -- I would suggest taking a look
> at a logging framework like log4cxx (available in Debian, even ).
> That also means that log statements you insert will stick around for
> later re-use should you ever have more questions about that bit of the
> code.


Very interesting. I think I will take a look see at log4cxx.

Thanks.


--

Please reply to this list only. I read this list on its corresponding
newsgroup on gmane.org. Replies sent to my email address are just
filtered to a folder in my mailbox and get periodically deleted without
ever having been read.


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 01-30-2009, 03:36 PM
Robert Baron
 
Default C++ templates and debugging (limitations) in Linux

When I have developed template code, I have always started by implementing
the same algorithms without the templates.* Once the non-template code works
and is debugged, I convert it to the template.* I have just found using real

types is more convenient to think about, and to debug.

gdb can be slightly confusing if you don't use it all of the time, however,
there are gui interfaces for it.* Logging statements, as well as, sending

debugging statements to stderr, stdout or to a file can also be useful.

On Fri, Jan 30, 2009 at 7:49 AM, H.S. <hs.samix@gmail.com> wrote:

Daniel Burrows wrote:



>

> * Personally, I almost only use a debugger to get backtraces after a

> crash. *I find logging statements to be easier, more reliable, and more

> useful. *If you write cout<< statements directly into your code, of

> course, it gets cluttered and unwieldly -- I would suggest taking a look

> at a logging framework like log4cxx (available in Debian, even ).

> That also means that log statements you insert will stick around for

> later re-use should you ever have more questions about that bit of the

> code.





Very interesting. I think I will take a look see at log4cxx.



Thanks.





--



Please reply to this list only. I read this list on its corresponding

newsgroup on gmane.org. Replies sent to my email address are just

filtered to a folder in my mailbox and get periodically deleted without

ever having been read.





--

To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org

with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 02-01-2009, 10:44 PM
Kamaraju S Kusumanchi
 
Default C++ templates and debugging (limitations) in Linux

H.S. wrote:
>> There are more appropriate places than debian-user for C++ questions.
>
> Yes. There is a news group for C++, but the people there are topic
> nazis. Anything not strictly related to the standard is promptly
> flogged, hanged, skinned and left to dry.
>
> My query, however, was related to the behaviour of combination of C++,
> templates, STL and gdb.
>
> The proper place for this query would probably be the newsgroup for gdb.
> But that is extremely low traffic.
>
> Hence my post here with the OT warning.
>

I could not have put it more clearly. I am very thankful for bringing this
up on d-u.

raju
--
Kamaraju S Kusumanchi
http://malayamaarutham.blogspot.com/


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 

Thread Tools




All times are GMT. The time now is 06:43 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org