[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Breakpoints in C++ templates

From: Nick Roberts
Subject: Breakpoints in C++ templates
Date: Wed, 14 Nov 2007 22:19:53 +1300

On Thu, 19 Oct 2006 13:46:35 +0200, Frank Schmitt wrote:

> First for those who have no idea about what we are talking about: In C++
> you can write something like
> -----------------------------------------------------------------------------
> template <typename imgtype1, typename imgtype2>
> void doSomething(imgtype1* img1, imgtype2* img2){
>   //do something with image img1 and image img2 which can both be either
>   //8 or 16 bits per pixel
> }
> int main(){
>   unsigned char* image1 = getRawImageData1();
>   int bpp1 = getBitsPerPixel1();
>   unsigned char* image2 = getRawImageData2():
>   int bpp2 = getBitsPerPixel2();
>   if (bpp1==8 && bpp2==8)
>      doSomething<unsigned char, unsigned char>(image1, image2);
>   if (bpp1==8 && bpp2==16)
>      doSomething<unsigned char, unsigned short>(image1, (unsigned 
> short*)image2);
>   if (bpp1==16 && bpp2==8)
>      doSomething<unsigned short, unsigned char>((unsigned short*)image1, 
> image2);
>   if (bpp1==16 && bpp2==16)
>      doSomething<unsigned short, unsigned short>((unsigned short*)image1, 
> (unsigned short*)image2);
> }
> -----------------------------------------------------------------------------

> If you compile this, four instances of the function doSomething are
> generated, in each imgtype1 and imgtype2 is substituted with a real data
> type. If you now start the program in gdb and say "break doSomething",
> the breakpoint will always be set at the first instance of the function
> which gdb finds. If this isn't the instance your program is just using,
> you can't debug the function. (Ok, there are some tricks, but even if
> you managed to set the breakpoint correctly there's still reakage in
> e.g. "until".)

GDB now handles these breakpoints correctly and the breakpoints buffer
in Emacs' Graphical Interface should also work with this new code.  Could
you please test these two programs and send feedback to the appropriate
mailing list?  You will need a recent checkout from the CVS repositories
of both GDB and Emacs.

> If gdb had a leader who said "we don't ship broken code", gdb developers
> would be at annoyed because their favorite new feature of which they are
> proud and fond isn't released to the public and would eventually sit
> down and fix it, just as it happens in Emacs.

Yes, and all without the need for such a leader.

Nick                                           http://www.inet.net.nz/~nickrob

reply via email to

[Prev in Thread] Current Thread [Next in Thread]