I have a C++ console project in Code::Blocks and I have set breakpoints to test an error. I have set the build for the project to produce debugging symbols for the debug build. I built it, then when I hit debug it just ignored my breakpoints and skipped to the end of the program. The debugging window said "(no debugging symbols found)" what is wrong with my Code::Blocks?

I did install MinGW with Code::Blocks and I even tried reinstalling. I have tested the debugger with a bunch of different programs now and it just doesnt work for any of them. The program I currently need the debugger for is this one that is designed to parse code for HTML output:

#include <stdio.h>
#define IFNAME "input.txt"
#define OFNAME "output.txt"
int len(char *str)
{
    int i;
    for (i=0; str[i]; i++){}
    return i;
}
char *read(char *fname)
{
    FILE *file=fopen(fname,"r");
    printf("Opening input file...\n");
    if (file==NULL)
        return NULL;
    int length=0;
    char *ret=new char[length];
    while (!feof(file))
    {
        char ch=fgetc(file);
        char *temp=new char[length+1];
        for (int i=0; i<length; i++)
            temp[i]=ret[i];
        delete[]ret;
        temp[length]=ch;
        length++;
        ret=temp;
    }
    fclose(file);
    return ret;
}
void write(char *text, char *fname)
{
    if (text==NULL)
        return;
    FILE *file=fopen(fname,"w");
    printf("Opening output file...\n");
    if (file==NULL)
        return;
    for (int i=0; text[i]; i++)
        fputc(text[i],file);
    fclose(file);
}
void replaceAll(char *text, const char *find, const char *replace)
{
// TODO (lburke#1#): Create this function!
}
void replaceAll(char *text, char  find, const char *replace)
{
    for (int i=0; text[i]; i++)
    {
        if (text[i]==find)
        {
            //return text[0->i],replace,replaceAll(text[i->end],find,replace)
            char *end=new char[len(text)-i];
            for (int ii=i; text[ii]; ii++)
                end[ii-i]=text[ii];
            replaceAll(end,find,replace);
            char *ret=new char[i+len(end)];
            char *start=new char[i];
            for (int ii=0; ii<i; ii++)
                start[ii]=text[ii];
            sprintf(ret,"%s%s",start,end);
            delete[]start;
            delete[]end;
            delete[]text;
            text=ret;
        }
    }
}
void insertBefore(char *text, int index, char insert)
{
    char *ret=new char[len(text)+1];
    for (int i=0; i<index; i++)
        ret[i]=text[i];
    ret[index]=insert;
    for (int i=index; text[i-1]; i++)
        ret[i]=text[i-1];
    delete[]text;
    text=ret;
}

void highlight(char *text)
{
    if (text==NULL)
        return;
    int length=len(text);
    replaceAll(text,"&nbsp"," ");
    replaceAll(text,"&gt",">");
    replaceAll(text,"&lt","<");
    replaceAll(text,"&quot","\"");
    replaceAll(text,"&amp","&");
    char *keywords[]={
        "asm ", "auto ", "bool ", "break ", "case ", "catch ",
        "char ", "class ", "const ", "const_cast ", "continue ",
        "default ", "delete ", "do ", "double ", "dynamic_cast ",
        "else ", "enum ", "explicit ", "export ", "extern ",
        "false ", "float ", "for ", "friend ", "goto ", "if ",
        "inline ", "int ", "long ", "mutable ", "namespace ",
        "new ", "operator ", "private ", "protected ", "public ",
        "register ", "reinterpret_cast ", "restrict ", "return ",
        "short ", "signed ", "sizeof ", "static ", "static_cast ",
        "struct ", "switch ", "template ", "this ", "throw ",
        "true ", "try ", "typedef ", "typeid ", "typename ",
        "union ", "unsigned ", "using ", "virtual ", "void ",
        "volatile ", "while ", "int8_t ", "uint8_t ", "int16_t ",
        "uint16_t ", "int32_t ", "uint32_t ", "int64_t ", "uint64_t ",
        "int_least8_t ", "uint_least8_t ", "int_least16_t ",
        "uint_least16_t ", "int_least32_t ", "uint_least32_t ",
        "int_least64_t ", "uint_least64_t ", "int_fast8_t ",
        "uint_fast8_t ", "int_fast16_t ", "uint_fast16_t ",
        "int_fast32_t ", "uint_fast32_t ", "int_fast64_t ",
        "uint_fast64_t ", "intptr_t ", "uintptr_t ", "intmax_t ",
        "uintmax_t ", "wint_t ", "wchar_t ", "wctrans_t ",
        "wctype_t ", "size_t ", "time_t ", "and ", "and_eq ",
        "bitand ", "bitor ", "compl ", "not ", "not_eq ", "or ",
        "or_eq ", "xor ", "xor_eq ", "complex ", "imaginary ",
        "_Complex ", "_Imaginary ", "_Bool ", "_Pragma ", 0
    };
    char *dockeywords[]={
        "a", "addindex", "addtogroup", "anchor", "arg", "attention",
        "author", "b", "brief", "bug", "c", "class", "code", "date",
        "def", "defgroup", "deprecated", "dontinclude", "e", "em",
        "endcode", "endhtmlonly", "endif", "endlatexonly", "endlink",
        "endverbatim", "enum", "example", "exception", "f$", "f[", "f]",
        "file", "fn", "hideinitializer", "htmlinclude", "htmlonly", "if",
        "image", "include", "ingroup", "internal", "invariant",
        "interface", "latexonly", "li", "line", "link", "mainpage", "name",
        "namespace", "nosubgrouping", "note", "overload", "p", "page",
        "par", "param", "post", "pre", "ref", "relates", "remarks", "return",
        "retval", "sa", "section", "see", "showinitializer", "since", "skip",
        "skipline", "struct", "subsection", "test", "throw", "todo",
        "typedef", "union", "until", "var", "verbatim", "verbinclude",
        "version", "warning", "weakgroup", "$", "@", "\"", "<", ">", "#",
        "{", "}", 0
    };
    #define CODE 1
    #define COMMENT 2
    #define MLCOMMENT 3
    #define DOC 4
    #define MLDOC 5
    #define PREPROCESSOR 6
    #define STR 7
    #define CHR 8
    #define KEYWORD 9
    #define DOCKEYWORD 10
    #define OPERATOR 11
    #define NUMBER 12
    char *format=new char[len(text)];
    char state=CODE;
    for (int i=0; text[i]; i++)
        format[i]=CODE;
    printf("Loading format string...\n");
    for (int i=0; text[i]; i++)
    {
        if ((i*100)/length&5==0)
            printf("%i%% formatted...\n",(i*100)/length);
        if (text[i]=='\n')
        {
            if (state!=MLCOMMENT&&state!=MLDOC)
                state=CODE;
        }
        switch (state)
        {
            case OPERATOR:
            case CODE:
            switch (text[i])
            {
                case '#':
                    if (i==0||text[i-1]=='\n')
                        state=PREPROCESSOR;
                    break;
                case '/':
                    if (text[i+1]=='/')
                    {
                        if (text[i+2]=='/'||text[i+2]=='!')
                            state=DOC;
                        else
                            state=COMMENT;
                    }
                    else if (text[i+1]=='*')
                    {
                        if (text[i+2]=='*'||text[i+2]=='!')
                            state=MLDOC;
                        else
                            state=MLCOMMENT;
                    }
                    else
                        state=OPERATOR;
                    break;
                case '1':
                case '2':
                case '3':
                case '4':
                case '5':
                case '6':
                case '7':
                case '8':
                case '9':
                case '0':
                    state=NUMBER;
                    break;
                case '\"':
                    state=STR;
                    break;
                case '\'':
                    state=CHR;
                    break;
                case '<':
                case '>':
                case '=':
                case '|':
                case '%':
                case '^':
                case '&':
                case '*':
                case '(':
                case ')':
                case '+':
                case '-':
                case '~':
                case '.':
                case '{':
                case '}':
                case '[':
                case ']':
                case ':':
                case ';':
                case '!':
                    state=OPERATOR;
                    break;
                default://check for keyword
                    for (int ii=0; keywords[ii]!=0; ii++)
                    {
                        bool hit=true;
                        for (int iii=0; keywords[ii][iii]&&text[i+iii]&&hit; iii++)
                        {
                            if (text[i+iii]!=keywords[ii][iii])
                                hit=false;
                        }
                        if (hit)
                        {
                            state=KEYWORD;
                            break;
                        }
                    }
                    break;
            }
            break;
            case MLCOMMENT:
                if (text[i]=='*'&&text[i+1]=='/')
                    state=CODE;
                break;
            case MLDOC:
                if (text[i]=='*'&&text[i+1]=='/')
                {
                    state=CODE;
                    break;
                }
            case DOC:
                if (text[i]=='@')
                {
                    for (int ii=0; dockeywords[ii]!=0; ii++)
                    {
                        bool hit=true;
                        for (int iii=0; dockeywords[ii][iii]&&text[i+iii]&&hit; iii++)
                        {
                            if (text[i+iii]!=dockeywords[ii][iii])
                                hit=false;
                        }
                        if (hit)
                        {
                            state=DOCKEYWORD;
                            break;
                        }
                    }
                }
                break;
            case PREPROCESSOR:
                if (text[i]=='/')
                {
                    if (text[i+1]=='/')
                    {
                        if (text[i+2]=='/'||text[i+2]=='!')
                            state=DOC;
                        else
                            state=COMMENT;
                    }
                    else if (text[i+1]=='*')
                    {
                        if (text[i+2]=='*'||text[i+2]=='!')
                            state=DOC;
                        else
                            state=COMMENT;
                    }
                }
                break;
            case STR:
                if (text[i]=='\"')
                    state=CODE;
                break;
            case CHR:
                if (text[i]=='\'')
                    state=CODE;
                break;
            case NUMBER:
                switch (text[i])
                {
                    case '<':
                    case '>':
                    case '=':
                    case '|':
                    case '%':
                    case '^':
                    case '&':
                    case '*':
                    case '(':
                    case ')':
                    case '/':
                    case '+':
                    case '-':
                    case '~':
                    case '.':
                    case '{':
                    case '}':
                    case '[':
                    case ']':
                    case ':':
                    case ';':
                    case '!':
                    state=OPERATOR;
                    case ' ':
                    state=CODE;
                }
        }
        format[i]=state;
    }
    state=0;
    int offset=0;
    for (int i=0; format[i]; i++)
    {
        if (format[i]!=state)
        {
            state=format[i];
            insertBefore(text,offset+i,-state);
            offset++;
        }
    }
    printf("Formatting for html...\n");
    replaceAll(text,' ',"&nbsp");
    replaceAll(text,'>',"&gt");
    replaceAll(text,'<',"&lt");
    replaceAll(text,'\"',"&quot");
    replaceAll(text,'&',"&amp");
    replaceAll(text,-CODE,"</span><span class=\"Code\">");
    replaceAll(text,-COMMENT,"</span><span class=\"Comment\">");
    replaceAll(text,-MLCOMMENT,"</span><span class=\"Comment\">");
    replaceAll(text,-DOC,"</span><span class=\"DocComment\">");
    replaceAll(text,-MLDOC,"</span><span class=\"DocComment\">");
    replaceAll(text,-PREPROCESSOR,"</span><span class=\"Preprocessor\">");
    replaceAll(text,-STR,"</span><span class=\"String\">");
    replaceAll(text,-CHR,"</span><span class=\"Character\">");
    replaceAll(text,-KEYWORD,"</span><span class=\"Keyword\">");
    replaceAll(text,-DOCKEYWORD,"</span><span class=\"DocCommentKeyword\">");
    replaceAll(text,-OPERATOR,"</span><span class=\"Operator\">");
    replaceAll(text,-NUMBER,"</span><span class=\"Constant\">");
    replaceAll(text,'\n',"</tr>\n<td>#.</td>\n<td bgcolor=\"#FFFFFF\"><span class=\"Code\">");
    char *temp=new char[len(text)+107];
    sprintf(temp,"<table width=\"100%%\" border=\"0\" cellspacing=\"0\">\n<tr>\n<td>1.</td>\n<td bgcolor=\"#FFFFFF\">%s</td>\n</tr>\n</table>",text);
    delete[]text;
    text=temp;
    #undef CODE
    #undef COMMENT
    #undef MLCOMMENT
    #undef DOC
    #undef MLDOC
    #undef PREPROCESSOR
    #undef STR
    #undef CHR
    #undef KEYWORD
    #undef DOCKEYWORD
    #undef OPERATOR
    #undef NUMBER
}
int main()
{
    printf("Initializing...\n");
    char *text=read(IFNAME);
    highlight(text);
    printf("Saving to file...\n");
    write(text,OFNAME);
    printf("All done!\nPress ENTER...\n");
    getchar();
    return 0;
}

If it will help here is the output in the debug window:

Building to ensure sources are up-to-date
Build succeeded
Selecting target: 
Debug
Adding source dir: D:\Programming\C++\SyntaxHighlighter\
Adding source dir: D:\Programming\C++\SyntaxHighlighter\
Adding file: bin\Debug\SyntaxHighlighter.exe
Starting debugger: 
done
Registered new type: wxString
Registered new type: STL String
Registered new type: STL Vector
Setting breakpoints
(no debugging symbols found)
Debugger name and version: GNU gdb 6.8
Child process PID: 9312
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
Program received signal SIGTRAP, Trace/breakpoint trap.
In ntdll!DbgUiConnectToDbg () (C:\WINDOWS\system32\ntdll.dll)
Debugger finished with status 0

In CodeBlocks look at this;
Settings -> Compiler and Debugger Settings -> Global Compiler Settings
Default Compiler: GNU GCC
In toolchain executables; click auto-detect comp. then c comp: mingw32-gcc.exe...etc control them.

If it not helps;
Did you change any settings after installing CB?
What is your OS?

I tried what you said. I even made a new project to no avail. I have a Windows XP Professional (Build 2600.xpsp_sp3_gdr.101209-1647 if you need to know). I really need a debugger, what can I do?

Hi if your free to use any IDE then have you tried Eclipse CDT, its very much like code blocks, built in GCC with GDB debugger, can also be used to compile Java, GWT web applications and more.

I used CodeBlocks a while ago i dont recall having any issues with compiling can you give console output from compliation.

And just to be super sure your compiling natively and not cross compiling right?

A) How do I check if I am compiling natively.
B) I thought Eclipse was just for Java
C) Are you sure that I can't fix Code::Blocks?

Hi again.

Registered new type: wxString
Registered new type: STL String
Registered new type: STL Vector

This output looks really weird. It can be my fault; but I think, standart c code with stdio.h only, doesn't know STL. STL is C++ Standart Template Library. How it would be?

Sorry for the unnecessary things. Simply your problem is about WindowsNT parent process and GDB Child Process and it will solve your problem I think.
In compiler debugger settings -> Debugger Options -> Debugger Initialization Commands: Write following:

m_Pid = wxExecute(cmd, wxEXEC_ASYNC, m_pProcess);
m_Pid = wxExecute(cmd, wxEXEC_ASYNC | wxEXEC_NOHIDE, m_pProcess);

Now, if you hit ctrl-c on debug console, the debugger breaks as expected.

I tried adding that, it still ignores my breakpoints though, and the output doesn't change. I am really confused now... Code::Blocks y u no debug?!

Based on that terribly hard to decipher picture, you can see your program is executing (the printf's are in the console output), the issue is that its not hitting breakpoints, make sure than you are starting a debug session and no just running the code the two are beside each other as far as i remember, run wont hit breakpoints and debug will.

Also check you are running in debug mode and not release mode, there should be two configurations in your project make sure you are using the right one.

That just what i remember from the short time i used it and it might be the problem, if not sorry.

I got it working, I changed my debugger settings and had to close Code::Blocks and re-open the project. Then I rebuilt it, and the debugger worked properly. Thanks for the help!

Hello!

I have the same problem. I'm new to CodeBlocks.
Could you explain accurately what you changed in your debugger settings?

Thanks,

Dora.

It's simple, the problem is there aren't compiler (mingw), i have the same problem too. Then i download the codeblocks-10.05mingw-setup.exe, remember -> with mingw, about 70Mb. Finished :)

Hello!

I finally could solve the problem.
Reinstalling 10.05mingw-setup.exe does not help. I had already tried a couple of times,
and I also tried to change the install path so that there are no blanks in path names,
I tried to reboot, etc. But it doesn't help either. Still no debugger on my windows machine,
but debugger works well on Mac / VmWare -> Windows 7.

The solution was to install the latest nightly build (build 7932 from 14th april).
So to summarize the fix:
- Install 10.05mingw-setup.exe;
- Download nightly build and the other necessary files as described on Code::Blocks forum
- Once decompressed, it was not explained anywhere (or I didn't notice), but I just copied
all the files over the existing files in C:\Program files(x86)\Codeblocks
I simply relaunched CodeBlocks, and it just worked. The debugger is now working, there are
a couple of changes in the debug navigation icons, and probably many new features and bug
fixes that I'm not aware of.

Now it works even on the native windows machine.

That's it!

Dora.

This question has already been answered. Start a new discussion instead.