libstdc++-6.dll SIGSEGV

Hi, can anyone help me debug this problem:

1
2
3
4
(gdb) step
  PProgram received signal SIGSEGV, Segmentation fault.
0x6fe66a4f in ?? () from C:\MinGW\bin\libstdc++-6.dll
(gdb)


I'm trying to use the Borland Graphics Library. I'm using Eclipse to manage the build, but using standalone GDB via MSYS to debug.

My source code is:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

#include <iostream>
#include <graphics.h>


using namespace std;

int main() {
        int bigX = 200;                    /* largest x-coordinate */
        int bigY = 300;                    /* largest y-coordinate */

        std::cout << "bigX=" << bigX <<"\n";

        char myStr[] = " ";
        char* sp = myStr;
        int gdriver=DETECT,gmode;
        initgraph(&gdriver,&gmode,sp);

        initwindow(bigX, bigY,
                     "Full screen window - press a key to close");

        getch();                   /* pause until user presses a key */
        closegraph();              /* close the window */
        return 0;
}

thank you,
Scott
That's where the crash happened, but the problem is in your code.

Use gdb command bt to see all frames. Use up and down to traverse the frames to get to the frame in your code. That will tell you the line number. Examine the line and see what you've done wrong.

http://www.cplusplus.com/articles/iwTbqMoL/
Hi, yes, I can see the line number where the code is crashing:

1
2
3
4
5
6
(gdb) s
55                 initgraph(&gdriver,&gmode,sp);
(gdb) s

Program received signal SIGSEGV, Segmentation fault.
0x6fe66a4f in ?? () from C:\MinGW\bin\libstdc++-6.dll


And I can see that it happens during call to initgraph(). I've tried the gdb commands you suggested (thank you) but I don't see how looking at the stack trace helps because the function is defined in a precompiled library, so I can't see the source code. Am I missing something?
thank you,
Scott
Last edited on
Now you can suspect the parameters you're passing in.

gdriver is set to DETECT, which seems sensible.

gmode is set to some random int value, which does not seem sensible. Shouldn't you be setting that to a sensible value?

sp is pointing at a string consisting of a single blank space, which also doesn't seem very sensible but the documentation suggests the function will also look in the current directory for driver file, which may or a not be sensible depending on where you put it.

Basically, you've identified the line of your code containing the mistake. Now you know where to concentrate your attention. That line.
Hi Repeater, thank you again for your help...and good call on noticing gmode not being initialized.

The only other thing I found is:
1
2
3
4
5
6
(gdb) s
59                 initwindow(bigX, bigY, "Full screen window - press a key to close");
(gdb) s

Program received signal SIGSEGV, Segmentation fault.
0x0046ddc0 in std::string::assign(char const*, unsigned int) ()

It seems like there's an issue with passing parms to string::assign. It would be interesting to figure out why...but in the meantime it's a moot point because recompiling the source code fixed it!

I realized I do have access to the source code, so I just rebuilt the thing instead of trying to using the library.

The GNU compiler came back with some narrowing errors, but I hacked them away and then recompiled. Now it seems to work!

thanks again for all your help,
Scott
Topic archived. No new replies allowed.