PDA

View Full Version : C++ Debug system


bladder
12-12-2003, 07:44 AM
the debug kit was just released on Triple Buffer (http://triplebuffer.devmaster.net). The dbg kit features a memory manager, a logfile, a custom assert library, and a mini profiler. It can be used to aid in finding

memory leaks
memory usage
application bottleknecks
assertion variable values
logging warnings/errors/info

and more.

anubis
12-12-2003, 07:58 AM
you could as well have posted a link to paul nettles memory manager :)

bladder
12-12-2003, 08:43 AM
hmm? why would I do that?

anubis
12-12-2003, 09:22 AM
i meant instead of putting it into your dbg kit :)

bladder
12-12-2003, 09:32 AM
nah, I've modified it to suit the dbg kit. And you cant export pauls into a dll without redesigning it like I did. Also the way ive done has made it easier to undefine and redefine the memory operators.

And besides it's not like I've taken credit for his work, all the copyright notices are intact :) (and if you went to the dbg kit page, you'll see that there IS a link to his site)

It's just nice to have the memory manager along with the rest of the components to make a complete kit of the sorts. heh, I assume you already use pauls and that's why you would rather have a link to his instead of it being directly included with the kit?

besides, html memory leak detection logging is way prettier...

anubis
12-12-2003, 10:40 AM
i wasn't implying anything ;)

Ajarn
12-13-2003, 10:49 AM
I was wondering if you could provide the std headers ctime, new, and hash_map. I have VC++ 6.0 and my versions are incorrect. (That is, if you can provide them, I don't know if there is anything wrong with that or not.)

bladder
12-13-2003, 01:30 PM
if I sent you the hash_map header file that came with msvc 7, then I'd have to send all the files that hash_map uses, this would end up completely replacing your STL :sigh:

You might as well the template library at stlport (http://www.stlport.org/) and try using that one and see if it helps.

though why do you need the header files for new, and I've never heard of ctime...

What's the problem exactly? Are you getting errors when compiling? what are the errors, maybe I can help you fix them without having to replace your compiler.

Ajarn
12-13-2003, 03:06 PM
For hash_map:
c:\c++\test_dbg\profiler.hpp(17) : fatal error C1083: Cannot open include file: 'hash_map': No such file or directory

And for ctime (in logfile.cpp):
c:\c++\test_dbg\logfile.cpp(75) : error C2039: 'time_t' : is not a member of 'std'
c:\c++\test_dbg\logfile.cpp(75) : error C2039: 'time' : is not a member of 'std'
c:\c++\test_dbg\logfile.cpp(76) : error C2039: 'tm' : is not a member of 'std'
c:\c++\test_dbg\logfile.cpp(76) : error C2039: 'localtime' : is not a member of 'std'

And for new (mmgr.cpp and .hpp):
c:\c++\test_dbg\mmgr.hpp(168) : error C2562: 'delete' : 'void' function returning a value
C:\WINDOWS\TEMP\a95485if(74) : see declaration of 'delete'
c:\c++\test_dbg\mmgr.hpp(173) : error C2562: 'delete[]' : 'void' function returning a value
c:\c++\test_dbg\mmgr.hpp(171) : see declaration of 'delete[]'
c:\c++\test_dbg\mmgr.cpp(758) : error C2039: 'new_handler' : is not a member of 'std'
c:\c++\test_dbg\mmgr.cpp(758) : error C2039: 'set_new_handler' : is not a member of 'std'
c:\c++\test_dbg\mmgr.cpp(759) : error C2039: 'set_new_handler' : is not a member of 'std'
c:\c++\test_dbg\mmgr.cpp(816) : error C2039: 'new_handler' : is not a member of 'std'
c:\c++\test_dbg\mmgr.cpp(816) : error C2039: 'set_new_handler' : is not a member of 'std'
c:\c++\test_dbg\mmgr.cpp(817) : error C2039: 'set_new_handler' : is not a member of 'std'
c:\c++\test_dbg\mmgr.cpp(871) : error C2039: 'new_handler' : is not a member of 'std'
c:\c++\test_dbg\mmgr.cpp(871) : error C2039: 'set_new_handler' : is not a member of 'std'
c:\c++\test_dbg\mmgr.cpp(872) : error C2039: 'set_new_handler' : is not a member of 'std'
c:\c++\test_dbg\mmgr.cpp(921) : error C2039: 'new_handler' : is not a member of 'std'
c:\c++\test_dbg\mmgr.cpp(921) : error C2039: 'set_new_handler' : is not a member of 'std'
c:\c++\test_dbg\mmgr.cpp(922) : error C2039: 'set_new_handler' : is not a member of 'std'


:huh:

Ajarn
12-13-2003, 04:02 PM
With Stl-port I get these errors:

demo.cpp
c:\c++\test_dbg\profiler.hpp(61) : error C2039: 'hash_compare' : is not a member of '_STL'
c:\c++\test_dbg\profiler.hpp(61) : error C2143: syntax error : missing ';' before '<'
c:\c++\test_dbg\profiler.hpp(61) : error C2059: syntax error : '<'
c:\c++\test_dbg\profiler.hpp(73) : error C2065: 'char_hash_compare' : undeclared identifier
c:\c++\test_dbg\profiler.hpp(74) : error C2955: 'hash_map' : use of class template requires template argument list
c:\c++\stlport-4.6\stlport\stl\_hash_map.h(212) : see declaration of 'hash_map'
c:\c++\test_dbg\profiler.hpp(74) : fatal error C1903: unable to recover from previous error(s); stopping compilation
logfile.cpp
c:\c++\test_dbg\logfile.cpp(75) : error C2039: 'time' : is not a member of '_STL'
c:\c++\test_dbg\logfile.cpp(76) : error C2039: 'localtime' : is not a member of '_STL'
mmgr.cpp
c:\c++\test_dbg\mmgr.hpp(168) : error C2562: 'delete' : 'void' function returning a value
C:\WINDOWS\TEMP\a05353if(74) : see declaration of 'delete'
c:\c++\test_dbg\mmgr.hpp(173) : error C2562: 'delete[]' : 'void' function returning a value
c:\c++\test_dbg\mmgr.hpp(171) : see declaration of 'delete[]'
profiler.cpp
c:\c++\test_dbg\profiler.hpp(61) : error C2039: 'hash_compare' : is not a member of '_STL'
c:\c++\test_dbg\profiler.hpp(61) : error C2143: syntax error : missing ';' before '<'
c:\c++\test_dbg\profiler.hpp(61) : error C2059: syntax error : '<'
c:\c++\test_dbg\profiler.hpp(73) : error C2065: 'char_hash_compare' : undeclared identifier
c:\c++\test_dbg\profiler.hpp(74) : error C2955: 'hash_map' : use of class template requires template argument list
c:\c++\stlport-4.6\stlport\stl\_hash_map.h(212) : see declaration of 'hash_map'



(I'm sticking with the compilier stl...)

bladder
12-13-2003, 09:24 PM
oop. ctime, of course.

ok, try removing all the places I have "std::" (just remove the std:: part. and replace #include ctime with #include time.h

That should fix most problems, as for the hash_map, well, you could look into making your own hash map :P and replacing the one I use with yours... can't promise you anything, but I'll change the implimentation (Ill write a custom hash map class or something) when I get the time.

Also you might need to replace various header files that dont end in a '.h' with the same name minus the 'c' and with an added '.h' at the end.

Ajarn
12-13-2003, 11:27 PM
Everything works now... except for the hash_map. I even tried to use only stlport for it... but it doesn't have hash_compare, othewise it would compile.

c:\c++\test_dbg\profiler.hpp(61) : error C2039: 'hash_compare' : is not a member of '_STL'
c:\c++\test_dbg\profiler.hpp(61) : error C2143: syntax error : missing ';' before '<'
c:\c++\test_dbg\profiler.hpp(61) : error C2059: syntax error : '<'
c:\c++\test_dbg\profiler.hpp(73) : error C2065: 'char_hash_compare' : undeclared identifier
c:\c++\test_dbg\profiler.hpp(74) : error C2955: 'hash_map' : use of class template requires template argument list
c:\c++\stlport-4.6\stlport\stl\_hash_map.h(212) : see declaration of 'hash_map'

bladder
12-14-2003, 01:56 AM
Here are a few things you can try to fix those errors. First you have to get rid of the line with the hash_compare typedef in it. Then,

- Replace the third hash_map template parameter with '_char_hash_compare'

- Try excluding the 3rd template parameter, and see if the demo still works without it.

- I *think* that you might be able to use std::hash<char*> as the 3rd template parameter.

Ajarn
12-14-2003, 09:00 AM
After i did number two, I had to convert a lot of files to .h and even had to add the iostream.h and fstream.h in places... but then it alll came down to some weird compile errors.
I'm giving up. Maybe I should just get VC++.NET... but me got no money... :(

bladder
12-14-2003, 04:35 PM
nah, dont give up. I'm also trying to figure this out you know. The thing is that I've hardly ever used stlport, so I dont know what they use for a custom hash compare function, let me check...

Here! Check out this page ( http://www.sgi.com/tech/stl/hash_map.html ) Do what they do and see if it helps you.

Ajarn
12-14-2003, 05:03 PM
I set up the hash_map like this:
typedef std::hash_map<const char*, profile_info*, std::hash<const char*>/*char_hash_compare*/> hash_t;

Now all I have is 30 errors that you can proably tell me how to fix
demo.cpp
c:\c++\test_dbg\profiler.hpp(94) : warning C4786: '?output_profile_info@profiler@dbg@@CAXPAV?$hash_m ap@PBDPAUprofile_info@profiler@dbg@@U?$hash@PBD@_S TL@@U?$equal_to@PBD@5@V?$allocator@U?$pair@QBDPAUp rofile_info@profiler@dbg@@@_STL@@@5@@_STL@@AAV?$b
asic_ofstream@DV?$char_traits@D@_STL@@@4@PAUprofil e_info@12@@Z' : identifier was truncated to '255' characters in the browser information
c:\c++\test_dbg\demo.cpp(37) : error C2065: '__FUNCTION__' : undeclared identifier
c:\c++\test_dbg\demo.cpp(58) : error C2872: 'cout' : ambiguous symbol
c:\c++\test_dbg\demo.cpp(59) : error C2872: 'cerr' : ambiguous symbol
c:\c++\test_dbg\demo.cpp(61) : error C2872: 'clog' : ambiguous symbol
c:\c++\test_dbg\demo.cpp(63) : error C2872: 'clog' : ambiguous symbol
c:\c++\test_dbg\demo.cpp(65) : error C2228: left of '.m_custom_assert_a' must have class/struct/union type
c:\c++\test_dbg\demo.cpp(67) : error C2228: left of '.m_custom_assert_a' must have class/struct/union type
c:\c++\test_dbg\demo.cpp(67) : error C2228: left of '.print_val' must have class/struct/union type
c:\c++\test_dbg\demo.cpp(67) : error C2228: left of '.m_custom_assert_a' must have class/struct/union type
c:\c++\test_dbg\demo.cpp(67) : error C2228: left of '.print_val' must have class/struct/union type
c:\c++\test_dbg\demo.cpp(67) : error C2228: left of '.m_custom_assert_a' must have class/struct/union type
c:\c++\test_dbg\demo.cpp(67) : error C2228: left of '.print_val' must have class/struct/union type
c:\c++\test_dbg\demo.cpp(67) : error C2228: left of '.m_custom_assert_a' must have class/struct/union type
c:\c++\test_dbg\demo.cpp(67) : error C2228: left of '.print_val' must have class/struct/union type
c:\c++\test_dbg\demo.cpp(67) : error C2228: left of '.m_custom_assert_a' must have class/struct/union type
c:\c++\test_dbg\demo.cpp(67) : error C2228: left of '.print_val' must have class/struct/union type
c:\c++\test_dbg\demo.cpp(67) : error C2228: left of '.m_custom_assert_b' must have class/struct/union type
c:\c++\test_dbg\demo.cpp(67) : error C2228: left of '.msg' must have class/struct/union type
c:\c++\test_dbg\demo.cpp(69) : error C2872: 'clog' : ambiguous symbol
c:\c++\test_dbg\demo.cpp(91) : error C2374: 'i' : redefinition; multiple initialization
c:\c++\test_dbg\demo.cpp(85) : see declaration of 'i'
c:\c++\test_dbg\demo.cpp(103) : error C2872: 'clog' : ambiguous symbol
c:\c++\test_dbg\demo.cpp(106) : error C2228: left of '.m_custom_assert_a' must have class/struct/union type
c:\c++\test_dbg\demo.cpp(106) : error C2228: left of '.print_val' must have class/struct/union type
c:\c++\test_dbg\demo.cpp(106) : error C2228: left of '.m_custom_assert_a' must have class/struct/union type
c:\c++\test_dbg\demo.cpp(106) : error C2228: left of '.print_val' must have class/struct/union type
c:\c++\test_dbg\demo.cpp(106) : error C2228: left of '.m_custom_assert_a' must have class/struct/union type
c:\c++\test_dbg\demo.cpp(106) : error C2228: left of '.print_val' must have class/struct/union type
c:\c++\test_dbg\demo.cpp(106) : error C2228: left of '.m_custom_assert_b' must have class/struct/union type
c:\c++\test_dbg\demo.cpp(106) : error C2228: left of '.msg' must have class/struct/union type
c:\c++\test_dbg\demo.cpp(106) : error C2228: left of '.fatal' must have class/struct/union type


Then if I can run it, we have a VC6++ port to put on the website.

bladder
12-15-2003, 03:52 AM
Now all I have is 30 errors that you can proably tell me how to fix
:P

Ill give it a shot...

the ambiguous calls can be fixed by putting 'dbg::' in front of the calls. Becuase in VC 6 cout/cin/clog are in the global namespace instead of in 'std' so the compiler is confused as to whether to use the cout/clog in the global namespace or in the dbg namespace.

This error... "c:\c++\test_dbg\demo.cpp(37) : error C2065: '__FUNCTION__' : undeclared identifier" I have no idea why you get this error, Im 100% sure that VC6 has the __FUNCTION__ macro predefined. I suppose if you absolutely cant fix this error, you can put a

#define __FUNCTION__ "???"

somewhere and it will at least get rid of the error that way.

you get this

"c:\c++\test_dbg\demo.cpp(91) : error C2374: 'i' : redefinition; multiple initialization
c:\c++\test_dbg\demo.cpp(85) : see declaration of 'i'"

error because VC6 dosnt follow the C++ for loop scoping rules. You can fix this by just decalring 'i' at the beginning ot main or something and then just setting it to '0' before using it in the for loops instead of declaring it in the for loop.

as for 'error C2228' :sigh: I cant see what the problem is. Maybe the pre-processor in VC6 is foobared or something. Try fixing the other errors first and hopefully *prays* this error will leave you alone without a fight :P

A few things you can try though incase that error is a leech:

try replacing the

#define cassert [blah blah blah]

with

#define choose_some_other_name [blah blah blah]

or you can try changing the smart_assert variable name that's declared as extern and right above the macros. But then dont forget to change the variables name inside the macros as well.

Ajarn
12-15-2003, 08:29 AM
Error 2228 has something to do with __FUNCTION__
I've tried three different versions of it
#define __FUNCTION__
#define __FUNCTION__ (
#define __FUNCTION__ )
#define __FUNCTION__;


and got these results (same order
demo.cpp
C:\C++\test_dbg\demo.cpp(41) : error C2059: syntax error : ')'
C:\C++\test_dbg\demo.cpp(43) : error C2059: syntax error : ')'
C:\C++\test_dbg\demo.cpp(45) : error C2059: syntax error : ')'
C:\C++\test_dbg\demo.cpp(48) : error C2059: syntax error : ')'
C:\C++\test_dbg\demo.cpp(69) : error C2059: syntax error : ','
C:\C++\test_dbg\demo.cpp(71) : error C2059: syntax error : ','
C:\C++\test_dbg\demo.cpp(110) : error C2059: syntax error : ','


demo.cpp
C:\C++\test_dbg\demo.cpp(41) : error C2059: syntax error : ')'
C:\C++\test_dbg\demo.cpp(43) : error C2059: syntax error : ')'
C:\C++\test_dbg\demo.cpp(43) : error C2143: syntax error : missing ')' before ';'
C:\C++\test_dbg\demo.cpp(45) : error C2059: syntax error : ')'
C:\C++\test_dbg\demo.cpp(45) : error C2143: syntax error : missing ')' before ';'
C:\C++\test_dbg\demo.cpp(48) : error C2059: syntax error : ')'
C:\C++\test_dbg\demo.cpp(48) : error C2143: syntax error : missing ')' before ';'
C:\C++\test_dbg\demo.cpp(60) : error C2143: syntax error : missing ')' before '{'
C:\C++\test_dbg\demo.cpp(60) : error C2059: syntax error : ')'
C:\C++\test_dbg\demo.cpp(60) : error C2143: syntax error : missing ';' before '{'
C:\C++\test_dbg\demo.cpp(60) : error C2143: syntax error : missing ';' before '}'
C:\C++\test_dbg\demo.cpp(69) : error C2059: syntax error : ','
C:\C++\test_dbg\demo.cpp(71) : error C2059: syntax error : ','
C:\C++\test_dbg\demo.cpp(71) : error C2143: syntax error : missing ')' before ';'
C:\C++\test_dbg\demo.cpp(76) : error C2143: syntax error : missing ')' before '{'
C:\C++\test_dbg\demo.cpp(76) : error C2143: syntax error : missing ';' before ')'
C:\C++\test_dbg\demo.cpp(76) : error C2143: syntax error : missing ';' before '{'
C:\C++\test_dbg\demo.cpp(110) : error C2059: syntax error : ','
C:\C++\test_dbg\demo.cpp(114) : error C2143: syntax error : missing ')' before '}'
C:\C++\test_dbg\demo.cpp(114) : error C2143: syntax error : missing ';' before ')'


demo.cpp
C:\C++\test_dbg\demo.cpp(41) : error C2059: syntax error : ')'
C:\C++\test_dbg\demo.cpp(41) : error C2059: syntax error : ')'
C:\C++\test_dbg\demo.cpp(43) : error C2059: syntax error : ')'
C:\C++\test_dbg\demo.cpp(43) : error C2059: syntax error : ')'
C:\C++\test_dbg\demo.cpp(45) : error C2059: syntax error : ')'
C:\C++\test_dbg\demo.cpp(45) : error C2059: syntax error : ')'
C:\C++\test_dbg\demo.cpp(48) : error C2059: syntax error : ')'
C:\C++\test_dbg\demo.cpp(48) : error C2059: syntax error : ')'
C:\C++\test_dbg\demo.cpp(69) : error C2059: syntax error : ')'
C:\C++\test_dbg\demo.cpp(69) : error C2059: syntax error : ')'
C:\C++\test_dbg\demo.cpp(71) : error C2059: syntax error : ')'
C:\C++\test_dbg\demo.cpp(71) : error C2059: syntax error : ')'
C:\C++\test_dbg\demo.cpp(110) : error C2059: syntax error : ')'
C:\C++\test_dbg\demo.cpp(110) : error C2059: syntax error : ')'


demo.cpp
C:\C++\test_dbg\demo.cpp(41) : error C2143: syntax error : missing ')' before ';'
C:\C++\test_dbg\demo.cpp(41) : error C2059: syntax error : ')'
C:\C++\test_dbg\demo.cpp(41) : error C2143: syntax error : missing ';' before ')'
C:\C++\test_dbg\demo.cpp(41) : error C2059: syntax error : ')'
C:\C++\test_dbg\demo.cpp(43) : error C2143: syntax error : missing ')' before ';'
C:\C++\test_dbg\demo.cpp(43) : error C2059: syntax error : ')'
C:\C++\test_dbg\demo.cpp(43) : error C2143: syntax error : missing ';' before ')'
C:\C++\test_dbg\demo.cpp(43) : error C2059: syntax error : ')'
C:\C++\test_dbg\demo.cpp(45) : error C2143: syntax error : missing ')' before ';'
C:\C++\test_dbg\demo.cpp(45) : error C2059: syntax error : ')'
C:\C++\test_dbg\demo.cpp(45) : error C2143: syntax error : missing ';' before ')'
C:\C++\test_dbg\demo.cpp(45) : error C2059: syntax error : ')'
C:\C++\test_dbg\demo.cpp(48) : error C2143: syntax error : missing ')' before ';'
C:\C++\test_dbg\demo.cpp(48) : error C2059: syntax error : ')'
C:\C++\test_dbg\demo.cpp(48) : error C2143: syntax error : missing ';' before ')'
C:\C++\test_dbg\demo.cpp(48) : error C2059: syntax error : ')'
C:\C++\test_dbg\demo.cpp(69) : error C2059: syntax error : ';'
C:\C++\test_dbg\demo.cpp(69) : error C2143: syntax error : missing ';' before ','
C:\C++\test_dbg\demo.cpp(71) : error C2059: syntax error : ';'
C:\C++\test_dbg\demo.cpp(71) : error C2143: syntax error : missing ';' before ','
C:\C++\test_dbg\demo.cpp(110) : error C2059: syntax error : ';'
C:\C++\test_dbg\demo.cpp(110) : error C2143: syntax error : missing ';' before ','


If I could only figure out what __FUNCTION__ should be set too. Then, all of my errors are solved!

Ajarn
12-15-2003, 08:31 AM
Then... I go and set it as "???" like you said and it works.... hmmm.

Thanks for everything!!! :D

anubis
12-15-2003, 10:40 AM
_FUNCTION_ is a compiler macro (like _DEBUG or __FILE__) that contains the name of the function you are currently in. so if it isn't defined any string should be ok usually "???".

Ajarn
12-15-2003, 04:13 PM
Got it o' working. Now, I'm converting my engine to work with stl-port so I can use it! Unless... unless I can build it in DLL form? Meh.

bladder
12-15-2003, 08:50 PM
Great! Now send the vc6 files to k9eks at hotmail dot com so that I can put it up on the site.

Though Im pretty sure that __FUNCTION__ is supposed to be available in VC6. It's strange that it's not there :huh:

Ajarn
12-15-2003, 09:17 PM
Will do, but remember, they have to have stl-port to have it working ( for the hash_map). (Converted to stl-port, and it only took 30 mins! )

DrunkenCoder
12-16-2003, 03:05 AM
I havent looked at the source but wouldn't it be a good idea to make it optional to use hash_map since that really isn't in the standard yet.

Give it a nice std::map fallback although a bit slower it would probably ease the pain quite much for people that either don't want to or not know how to or simply can't just switch over to STLPort.

bladder
12-16-2003, 05:26 AM
that's a good idea. I suppose it would be handy to have a fallback to a standard container. But I originally made the thing for the MSVC7 compiler so...you know...

I'll probably add in the std::map support when I get time. It can be easily changed by anyone who wants to, it works almost the exact same way as the hash_map.

Also about your other comments... If someone dosnt know how to use stlport, well, then, they really shouldnt use this kit until they've learnt how to download stuff from the internet and add directories to their compilers search path...

DrunkenCoder
12-16-2003, 12:45 PM
Well really in many companies you don't have the option to choose STL implementation because company policy may say "we use dinkumware" or whatever so you can very well know how to use another vendors STL but locked to another implementation not because of that you don't know how to handle stuff but because of outside factors.

The debug toolkit sounds like it would have been a good tool where I worked this summer but because of some dll issues and reliance on an STL implementation besides STLPort it would be impossible to adopt it with out rewriting.

Making your stuff work with something that is standard compliant is just a nice thing todo if you want people to use it, having the option to make it faster using a specific implementation is a great option but I would say portability is more important specificly when it comes to reliance on an STL platform.

donBerto
12-17-2003, 07:12 AM
in addition to what bladder posted, also make sure your ENVIRONMENTS are set properly. I remember having a problem like that with STL and VisualStudio some time back. and it was due to an unset ENVIRONMENT PATH.

I can't fully remember how you do it in windows, but it's along the lines of going to the control panel, systems, and then in one of the tabs, there's an option "environment paths" or just "paths", i can't remember. anyway, just make sure the directory of the STL is also included in the path.

I hope that helps.

:yes: