[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference turris::c_plus_plus

Title:C++
Notice:Read 1.* and use keywords (e.g. SHOW KEY/FULL KIT_CXX_VAX_VMS)
Moderator:DECCXX::AMARTIN
Created:Fri Nov 06 1987
Last Modified:Thu Jun 05 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:3604
Total number of notes:18242

3422.0. "How to specify a line number in a template function when using ladebug??" by GALVIA::STONES (Tom Stones) Mon Feb 03 1997 10:46

I'm having trouble setting a breakpoint at a particular line in a member
function of a template class.

I have a template class:
	
template<class CACHE_DATA_T> 
class Cache_t {
private:
  struct Entry_t {		
    CACHE_DATA_T data;
    Entry_t      *nextEntry;
  };

  //Entries are allocated in blocks.
  struct CbListEntry_t{
    void *cacheblock;
    CbListEntry_t *nextCbListEntry;
  };
  
  Entry_t *firstEntry;
  Entry_t *freeEntry;
  CbListEntry_t  cb;

  //MoreEntries - Allocates space for cache entries and updates freeEntry.
  //Returns 1 if one or more entries added to free list.
  //Returns 0 if no memory.
  int MoreEntries();
 
public:
  //Add a new entry to the cache.
  //Returns 1 if ok.  0 if not enough memory.  
  int Added(const CACHE_DATA_T &newEntry);

  //Delete an entry from the cache.
  void Delete(const CACHE_DATA_T &selectedEntry);
  
  //Search the cache.
  //Returns 1 and result in selectedEntry if found.
  //Returns 0 if not found.
  int Found(CACHE_DATA_T *selectedEntry);

  //Constructor.
  Cache_t();

  //Destructor.
  ~Cache_t();

};

I have 3 instantiations:

void main() {
  Cache_t<EpMcMapEntry_t> tcc;
  Cache_t<TxBufMapEntry_t> tbc;
  Cache_t<RxBufMapEntry_t> rbc;
  ...

Using ladebug I step into the constructor for the tcc object.  The constructor
calls MoreEntries.  I step into MoreEntries.  I then attempt to set a 
breakpoint at line 27,which is in MoreEntries.  Ladebug reports 

(ladebug) b 27
Warning: More than one file named './cache.cpp' found in the binary.
Warning: Breakpoint not set

I tried
(ladebug) set $overloadmenu=1

I tried
(ladebug) class Cache_t<EpMcMapEntry_t>

I tried qualifying the line number in the same way as ladebug does:
stopped at [int Cache_t<EpMcMapEntry_t>::MoreEntries(void):11 0x1200029b8]
(ladebug) stop in Cache_t<EpMcMapEntry_t>::MoreEntries(void):27



None of these do the trick.   Is there a way of doing this?

Ta,
Tom.
T.RTitleUserPersonal
Name
DateLines
3422.1couldn't reproduce the problem...DECC::J_WARDMon Feb 03 1997 14:4977
Is MoreEntries() inlined? Did you compile with -g?
"If a program is no compiled with the -g flag, a breakpoint
set on an inline member function may confuse the debugger." 
(From ladebug manual)

Since you didn't give a complete source code example, I tried
reproducing your problem with this and it seemed to work just
fine...

// cache.cpp
#include <stdio.h>

template<class CACHE_DATA_T> 
class Cache_t {
private:
  struct Entry_t {		
    CACHE_DATA_T data;
    Entry_t      *nextEntry;
  };

  //Entries are allocated in blocks.
  struct CbListEntry_t{
    void *cacheblock;
    CbListEntry_t *nextCbListEntry;
  };
  
  Entry_t *firstEntry;
  Entry_t *freeEntry;
  CbListEntry_t  cb;

  //MoreEntries - Allocates space for cache entries and updates freeEntry.
  //Returns 1 if one or more entries added to free list.
  //Returns 0 if no memory.
  int MoreEntries() { printf("inside MoreEntries\n"); return 0; }
 
public:
  //Add a new entry to the cache.
  //Returns 1 if ok.  0 if not enough memory.  
  int Added(const CACHE_DATA_T &newEntry);

  //Delete an entry from the cache.
  void Delete(const CACHE_DATA_T &selectedEntry);
  
  //Search the cache.
  //Returns 1 and result in selectedEntry if found.
  //Returns 0 if not found.
  int Found(CACHE_DATA_T *selectedEntry);

  //Constructor.
  Cache_t() { MoreEntries();}

  //Destructor.
  ~Cache_t() {;}

};

void main() {
  Cache_t<int> tcc;
  Cache_t<char> tbc;
  Cache_t<float> rbc;
}

cosf.zko.dec.com> cxx -g cache.cpp
cosf.zko.dec.com> ladebug a.out
Welcome to the Ladebug Debugger Version 4.0-26
------------------
object file name: a.out
Reading symbolic information ...done
(ladebug) b 24
[#1: stop at "cache.cpp":24 ]
(ladebug) run
[1] stopped at [int Cache_t<int>::MoreEntries(void):24 0x120002390]
     24   int MoreEntries() { printf("inside MoreEntries\n"); return 0; }
(ladebug) quit


3422.2The source is in multiple files...GALVIA::STONESTom StonesMon Feb 03 1997 15:3493
Here's what happened with a shortened version of my code:

zen> cxx -g trash.cxx cache.cxx -I.
trash.cxx:
cache.cxx:
zen> ladebug a.out
Welcome to the Ladebug Debugger Version 4.0-19
------------------ 
object file name: a.out 
Reading symbolic information ...done
(ladebug) bp main
[#1: stop in int main(void) ]
(ladebug) r
[1] stopped at [int main(void):6 0x120002418]
      6   Cache_t<int> tcc;
(ladebug) s
stopped at [Cache_t<int>::Cache_t<int>(void):31 0x1200023e0]
     31   Cache_t() { MoreEntries();}
(ladebug) s
stopped at [int Cache_t<int>::MoreEntries(void):6 0x120002318]
      6 int  Cache_t<CACHE_DATA_T>::MoreEntries() {
(ladebug) l
      7         int i;
      8         printf("inside MoreEntries\n");
      9         i = 99;
     10         return 0;
     11    }
     12  
(ladebug) b 9
Warning: More than one file named './cache.cxx' found in the binary.
Warning: Breakpoint not set
(ladebug) q



Here's the code:

//main.cxx
#include <cache.h>
void  main() {
  Cache_t<int> tcc;
  Cache_t<char> tbc;
  Cache_t<float> rbc;
}


// cache.cpp
#include <stdio.h>
#include "cache.h"

template<class CACHE_DATA_T> 
int  Cache_t<CACHE_DATA_T>::MoreEntries() {
        int i;
        printf("inside MoreEntries\n");
        i = 99;
        return 0;
   }


// cache.h
#ifndef CACHE_
#define CACHE_

template<class CACHE_DATA_T> 
class Cache_t {
private:
  struct Entry_t {
    CACHE_DATA_T data;
    Entry_t      *nextEntry;
  };

  //Entries are allocated in blocks.
  struct CbListEntry_t{
    void *cacheblock;
    CbListEntry_t *nextCbListEntry;
  };
  
  Entry_t *firstEntry;
  Entry_t *freeEntry;
  CbListEntry_t  cb;

  //MoreEntries - Allocates space for cache entries and updates freeEntry.
  //Returns 1 if one or more entries added to free list.
  //Returns 0 if no memory.
  int MoreEntries();
 
public:

  //Constructor.
  Cache_t() { MoreEntries();}

};
#endif
3422.3I see the problem...DECC::J_WARDMon Feb 03 1997 17:0711
But I don't know of a solution.

You should probably try posting your example
in .2 to the ladebug notes conference,

TURRIS::DECLADEBUG

I'd be curious to find out how to do this too...
I'm sure it has something to do with the
instantiations being in repository files.
3422.4FYIDECC::J_WARDThu Feb 06 1997 20:093
This note was cross-posted in decladebug notes conference 
note 808. No answer yet.