GDB, stackdump errors

Ok, I did have a post about this a week ago or so, and someone told me to use gdb, which I went away and learned all about (handy). At the time I realized my mistakes went away and fixed them and marked topic as solved, after some testing though I seem to have the same problem, and gdb is not letting me know which line of code this stackdump error is occurring. code is as follows.
if anyone has any ideas? I am completely dumbfounded.

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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48

#include "a2.h"

int main(int argc,char argv[])
{
    int row=1;
    string iparam="";   // name for input file
    string oparam="";   // name for output file
    string usage="Usage: -i input_file -o ouptut_file";
    string sw;

    while (row<argc)
    {
        if (row<argc)
            sw = argv[row];
        if (sw == "-i")
        {
            row++;
            if (row < argc)
                iparam = argv[row];
        }
        else if (sw == "-o")
        {
            row ++;
            if (row < argc)
                oparam = argv[row];
        }
        else
        {
            cerr << endl;
            cerr << "Unkown switch: " << argv[row] << endl;
            cerr << usage << endl;
            exit(1);
        }
        row++;
    }
    // check for duplicate filenames
    if (iparam==oparam)
    {
        cerr << endl;
        cerr << "Duplicate filenames!" << endl;
        cerr << usage << endl;
        exit(1);
    }

    StringSort ss(iparam,oparam);
    ss.runApp();
}


gdb error is:


[New thread 4016.0xf84]
[New thread 4016.0xf64]
    25 [main] a 4016 _cygtls::handle_exceptions: Exception: STATUS_ACCESS_VIOLATION
  1737 [main] a 4016 open_stackdumpfile: Dumping stack trace to a.exe.stackdump
128246 [main] a 4016 _cygtls::handle_exceptions: Exception: STATUS_ACCESS_VIOLATION
147587 [main] a 4016 _cygtls::handle_exceptions: Error while dumping state (Probably corrupted stack)

Program received signal SIGSEGV, Segmentation fault.
0x61016583 in stack_info::walk ( ) from /usr/bin/cygwin1.dll
forgot to add the reason this stackdump occurs is on params 1 or 3, (or specifically including filename argc then 2 and 4) so less than 5.
eg:


./a 

filenames " " are duplicates!

./a  -i

** stackdump **


./a -i input

processes array, tries to write to file and exits on no file exists for ""; as expected, and wanted.

./a -i input -o

** stackdump **

./a -i input -o output

works as intented.

./a -i aName  -i someOtherName -i ILikEpIE -i -k -i asdas -i input_file -o -o -o -o -o output_file

works as intended and processes the last 2 switches, input_file and output_file


the way it should work is if 1 switch "-i" then output filenames are duplicates.
if 3 switches "-i input -o" then process as normal until writing to output is reached, then exits on that condition.
Last edited on
To clarify, will go through it step by step.

lets say we use 1 arg. "-i".

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
while (row<argc)                     // filename "a" is first argument as always: while 1<2
    {
        if (row<argc)                   // true   if 1< 2
            sw = argv[row];          // assigns sw to the second element in array [1]
        if (sw == "-i")                  // which is "-i"
        {  
            row++;                       // row is now 2. 3rd element in array which does not exist.
            if (row < argc)             //   if  2 < 2  false....
                iparam = argv[row];
        }
        else if (sw == "-o")
        {
            row ++;
            if (row < argc)
                oparam = argv[row];
        }
        else
        {
            cerr << endl;
            cerr << "Unkown switch: " << argv[row] << endl;
            cerr << usage << endl;
            exit(1);
        }
        row++;                       //  2++ so now 3  4th element in array, and drops out of loop
    }



so far, makes sense.... where's the stackdump come from???? this is driving me crazy
Last edited on
ok figured it out, silly VIM error the condition was still stuck on

1
2
3
4
5
6
7
8
if (sw == "-i")      
{  
    row++;                
    if (row <= argc)         // <---------- smaller than equals to, which I meant to remove :s
         iparam = argv[row];
}
else if (sw == "-o")


thanks for your help gcampton your the man *pats self on back*
Last edited on
Topic archived. No new replies allowed.