c++在cygwin下gdb调试时出现的问题 编译没问题。学生党已经无力搞这个了,只能上这里来求救
这是代码:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<iostream>
#include<cstring>
using namespace std;
typedef char status;
typedef struct lnode
{
struct lnode *next;
struct lnode *down;
char data[20];
char name[20];
char sex[20];
}lnode, *linklist;
void creatlist_zy(linklist &l, int n);
void creatlist_nj(linklist &l, int n);
void creatlist_bj(linklist &l, int n);
void creatlist_stu(linklist &l, int n);
void insert_zy(linklist &l);
void insert_nj(linklist &l);
void insert_bj(linklist &l);
void insert_stu(linklist &l);
void creatlist_zy(linklist &l, int n) {
linklist p, q;
int m;
l = (linklist) malloc (sizeof (lnode));
l -> next = NULL;
l -> down = NULL;
for (int i = n; i > 0; -- i)
{
p = (linklist) malloc (sizeof (lnode));
cout << "输入专业" << i << ":";
cin >> p -> data;
p -> next = l -> next;
l -> next = p;
cout << "请输入该专业年级数目:" ;
cin >> m;
creatlist_nj(q, m);
p -> down = q;
}
}
void creatlist_nj(linklist &l, int n) {
linklist p, q;
int m;
l = (linklist) malloc (sizeof (lnode));
l -> next = NULL;
l -> down = NULL;
for (int i = n; i > 0; -- i)
{
p = (linklist) malloc (sizeof (lnode));
cout << "输入年级" << i << ":";
cin >> p -> data;
p -> next = l -> next;
l -> next = p;
cout << "请输入该年级班级数目:";
cin >> m;
creatlist_bj(q, m);
p -> down = q;
}
}
void creatlist_bj(linklist &l, int n) {
linklist p;
linklist q;
int m;
l = (linklist) malloc (sizeof (lnode));
l -> next = NULL;
l -> down = NULL;
for (int i = n; i > 0; -- i)
{
p = (linklist) malloc (sizeof (lnode));
cout << "输入班级" << i << ":";
cin >> p -> data;
p -> next = l -> next;
l -> next = p;
cout << "请输入班级人数目:";
cin >> m;
creatlist_stu(q, m);
q = p -> down;
}
}
void creatlist_stu(linklist &l, int n) {
linklist p;
l = (linklist) malloc (sizeof (lnode));
l -> next = NULL;
l -> down = NULL;
for (int i = n; i > 0; -- i)
{
p = (linklist) malloc (sizeof (lnode));
cout << "姓名" << i << ":";
cin >> p -> name;
cout << "性别" << i << ":";
cin >> p -> sex;
p -> next = l ->next;
l -> next = p;
}
}
void insert_zy(linklist &l){
linklist p,q;
p = l-> next;
char zym[20];
cout << "专业名:";
cin >> zym;
while (p)
{
if (strcmp(p -> data, zym) == 0)
{
q = p -> down;
insert_nj(q);
}
p = p -> next;
if (p = NULL)
{
cout << "输入新的专业:" << endl;
creatlist_nj(q,1);
}
}
}
void insert_nj(linklist &l){
linklist p,q;
p = l -> next;
char njm[20];
cout << "年级名:";
cin >> njm;
while (p)
{
if (strcmp(p -> data, njm) == 0)
{
q = p -> down;
insert_bj(q);
}
p = p -> next;
if (p = NULL)
{
cout << "输入新的年级:" << endl;
creatlist_nj(q,1);
}
}
}
void insert_bj(linklist &l){
linklist p;
linklist q;
p = l -> next;
char bjm[20];
cout << "班级名:";
cin >> bjm;
while (p)
{
if (strcmp(p -> data, bjm) == 0)
{
q = p -> down;
insert_stu(q);
}
p = p -> next;
if (p = NULL)
{
cout << "输入新的班级:" << endl;
creatlist_nj(q,1);
}
}
}
void insert_stu(linklist &l){
linklist p;
p = (linklist) malloc (sizeof(lnode));
l = l -> next;
cout << "姓名:";
cin >> p -> name;
cout << "性别:";
cin >> p -> sex;
p -> next = l -> next;
p = l -> next;
cout << "插入成功!" << endl;
}
int main() {
linklist l;
int n,choice;
cout << "你想要进行的操作:1:新建学生表;2:插入学生信息;" <<endl;
cin >> choice;
while (1)
{
switch (choice)
{
case 1:
cout << "输入专业数目:";
cin >> n;
creatlist_zy(l,n);
break;
case 2:
insert_zy(l);
break;
default: cout << "请输入1,2!" <<endl; break;
}
cout << "你想要进行的操作:1:新建学生表;2:插入学生信息;" <<endl;
cin >> choice;
}
return 0;
}
一下是gdb:
GNU gdb (GDB) 7.8
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-pc-cygwin".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from stu.exe...done.
(gdb) break insert_stu
Breakpoint 1 at 0x1004017c1
(gdb) r
Starting program: /cygdrive/d/cygwin/home/cppwork/stu.exe
[New Thread 1928.0x7d0]
[New Thread 1928.0x1bd4]
[New Thread 1928.0xec8]
[New Thread 1928.0x2380]
[New Thread 1928.0x21bc]
你想要进行的操作:1:新建学生表;2:插入学生信息;
1
输入专业数目:1
输入专业1:jisuanji
请输入该专业年级数目:1
输入年级1:daer
请输入该年级班级数目:sa[New Thread 1928.0x1154]
[New Thread 1928.0x173c] Quit
(gdb) r
The program being debugged has been started already.
Start it from the beginning? (y or n) y
Starting program: /cygdrive/d/cygwin/home/cppwork/stu.exe
[New Thread 3144.0x1944]
[New Thread 3144.0x200c]
[New Thread 3144.0x204]
[New Thread 3144.0x17a8]
[New Thread 3144.0x22cc]
你想要进行的操作:1:新建学生表;2:插入学生信息;
1
输入专业数目:1
输入专业1:jisuanji
请输入该专业年级数目:1
输入年级1:daer
请输入该年级班级数目:1
输入班级1:sanban
请输入班级人数目:1
姓名1:hiro
性别1:nan
你想要进行的操作:1:新建学生表;2:插入学生信息;
2
专业名:jisuanji
年级名:[New Thread 3144.0xc90]
[New Thread 3144.0xad0]
daer
班级名:
[Thread 3144.0x17a8 exited with code 0]
[Thread 3144.0x204 exited with code 0]
[Thread 3144.0x200c exited with code 0]
sanban
Breakpoint 1, 0x00000001004017c1 in insert_stu(lnode*&) ()
(gdb) n
Single stepping until exit from function _Z10insert_stuRP5lnode,
which has no line number information.
姓名:fangyuan
性别:nan
Program received signal SIGSEGV, Segmentation fault.
0x000000010040182e in insert_stu(lnode*&) ()