Author
Topic: Code::Blocks developint hints (Read 11865 times)

If you have tried to debug Code::Blocks, or have any hint related to development, please post it here.

First hint: If you add the following linker options (found experimentally), debugging under GDB shows more info than normally. This is because the linker doesn't rellocate addresses so they're available to the debugger. It's not perfect, but helps alot.

cd C:\mingw\bindrmingw -i -vthis will install drmingw as the jit debugger (drmingw -u to later uninstall)(windbg can be installed as the jit debugger with windbg -I but it doesn't support gccgcc debug symbols. it does support vc5/6/7 .pdb files and provides true source leveldebugging)

to test:- create a win32 project using the gcc compiler as default- place __asm("int3"); somewhere in the code- compile & run gcc -g

NEVER use "#define" to declare a constant or a macro, especially in header files! This could be tolerated in cpp files but it's a bad habit anyway!Prefer either an "static const", an "enum" or a template function instead (or better, a non-template inline function)

Why not make the template functions inline? They have no disadvantage with respect to non-template functions. (Yes, old compilers ALWAYS bloated the code before, but not anymore nowadays.) Using this kind of templates is both simple and advisable:

Please allow me to complement zieQ's coding style advice by supplying a "textbook example" of how a macro can mess up your code.Suppose you define a macro that expands your variables to be squared, i.e.:

int n = 5;...int m = SQR(n++);So m should end up being equal to 25 while n finishes as 6, right? Wrong. A macro makes a _textual_ replacement of the expression in the parenthesis by its definition. The compiler replaces what you wrote by

int m = (n++) * (n++);So, in fact, m is equal to 30, and n is equal to 7.You can easily conclude what might happen with complicated expressions. The consequences of systematically using macros to handle pointers can be much worse, with hard to track segmentation faults.Needless to say, the above example, with the inline function template shown above, ( my:: sqr() ) would be parsed normally as any function, without any surprises. Type safety is a Good Thing(TM).

Another tip, though maybe not so useful, would be the use of namespaces separation for code clarity. I'd like to see further use of namespaces in the SDK, so I'm posting that as a feature request in sourceforge. Though low priority, I know.

That should be it. There's a mpatrol.pdf that installs with the mpatrol installer. Basically just run codeblocks.exe and look for a mpatrol.log afterwards. Compiling right now, will test the results later.

Edit: looks like bfd is the wrong object file format for windows. I'll try recompiling mpatrol and see if it works then

Edit: nevermind, it looks like mpatrol doesn't want to work. I just tried the above flags with a simple win32gui app and then putting int* abc = new int[10]; (so that the mpatrol libs are actually linked in)

change to the codeblocks bin directory (add2line currently needs to be in the same directory as the codeblocks binary to load debugging symbols):

cd /usr/local/bin./codeblocks

now when an assertion triggers, you can hit yes to stop the program. it will dump core (also when the program crashes it dumps core...)you can then load the core dump with all debugging symbols and stack trace information using:gdb codeblocks core

The most obvious thing: Learn C++. This sounds like a really stupid tip, but hey

If you think you know your Kung Fu, then have a look at http://www.gotw.ca/gotw/ and work through all 87 questions (or go to a similar site, there are a couple).A lot of these problems look quite trivial at first glance, and a few solutions are arguable, but overall, you will probably find that you missed a significant thing in almost every other question.If afterwards, you feel like hiding in a dark corner for all the things you didn't know, that's ok. It means you have learned a lot.

Logged

"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."