public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Force generation of an uncalled method?
@ 2008-02-22 20:00 stepleton
  2008-02-22 20:57 ` Brian Dessent
  0 siblings, 1 reply; 4+ messages in thread
From: stepleton @ 2008-02-22 20:00 UTC (permalink / raw)
  To: gcc-help

Greetings,

I hope this question isn't too elementary. I have a program that maintains 
objects from a number of templated classes. When debugging, it is 
particularly useful to print out information in one of these objects with 
a method I've written---this method digests the information in the object 
and prints it out in a useful way. So, if the program hits a snag, I'd 
like to call this method within gdb, as in "p myobject.dumpInfo()". 
Ordinarily the code will not use this method ever---it's only for me to 
call in the debugger.

The problem is that I can't get g++ to generate code for this method 
unless I actually call it in somewhere the code (in which case everything 
works as intended). I've tried the "used" attribute in the declaration, 
and optimization is already off. Is there any way to force this method to 
be compiled?

Thanks,
--Tom
+-----------+----------------+            ____
| Stepleton | tss@ri.cmu.edu |>-------|\__/_/__
+-----------+----------------+        \________}

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Force generation of an uncalled method?
  2008-02-22 20:00 Force generation of an uncalled method? stepleton
@ 2008-02-22 20:57 ` Brian Dessent
  2008-02-22 21:23   ` stepleton
  0 siblings, 1 reply; 4+ messages in thread
From: Brian Dessent @ 2008-02-22 20:57 UTC (permalink / raw)
  To: stepleton; +Cc: gcc-help

stepleton@gmail.com wrote:

> The problem is that I can't get g++ to generate code for this method
> unless I actually call it in somewhere the code (in which case everything
> works as intended). I've tried the "used" attribute in the declaration,
> and optimization is already off. Is there any way to force this method to
> be compiled?

I think you will need to explicitly instantiate a copy of the debug
method for each type that you expect to want to use from gdb, because
normally g++ only instantiates implicitly.  You might find this page
helpful:
<http://gcc.gnu.org/onlinedocs/gcc/Template-Instantiation.html>.

Brian

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Force generation of an uncalled method?
  2008-02-22 20:57 ` Brian Dessent
@ 2008-02-22 21:23   ` stepleton
  2008-02-23  1:05     ` Brian Dessent
  0 siblings, 1 reply; 4+ messages in thread
From: stepleton @ 2008-02-22 21:23 UTC (permalink / raw)
  To: gcc-help

On Fri, 22 Feb 2008, Brian Dessent wrote:

> I think you will need to explicitly instantiate a copy of the debug
> method for each type that you expect to want to use from gdb, because
> normally g++ only instantiates implicitly.  You might find this page
> helpful:
> <http://gcc.gnu.org/onlinedocs/gcc/Template-Instantiation.html>.

Thanks, Brian, this is it! For now I am getting by placing something like 
"if(false) debugMethod();" into the constructor. If there is a convention 
for this sort of thing, I'd be happy to know about it.

--Tom

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Force generation of an uncalled method?
  2008-02-22 21:23   ` stepleton
@ 2008-02-23  1:05     ` Brian Dessent
  0 siblings, 0 replies; 4+ messages in thread
From: Brian Dessent @ 2008-02-23  1:05 UTC (permalink / raw)
  To: stepleton; +Cc: gcc-help

stepleton@gmail.com wrote:

> Thanks, Brian, this is it! For now I am getting by placing something like
> "if(false) debugMethod();" into the constructor. If there is a convention
> for this sort of thing, I'd be happy to know about it.

You should be able to explicitly instantiate it as e.g. "template class
Foo<int>;" which if I understand correctly would tell g++ to compile and
emit bodies for all non-inline methods of Foo<int> at that point.

Brian

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2008-02-22 21:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-02-22 20:00 Force generation of an uncalled method? stepleton
2008-02-22 20:57 ` Brian Dessent
2008-02-22 21:23   ` stepleton
2008-02-23  1:05     ` Brian Dessent

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).