LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   [debug]what does the following debug information mean (http://www.linuxquestions.org/questions/programming-9/%5Bdebug%5Dwhat-does-the-following-debug-information-mean-184124/)

icoming 05-21-2004 11:00 AM

[debug]what does the following debug information mean
 
the information is made by gcc

main.o(.text+0x0): In function `CommonError::CommonError[not-in-charge](int)':
/storage/tempproject/project/CommonError.h:20: multiple definition of`CommonError::CommonError[not-in-charge](int)'
~~~~~~~~~

StrView.o(.text+0x0):/storage/tempproject/project/CommonError.h:20: first
defined here
main.o(.text+0x126): In function `CommonError::CommonError[in-charge](int)':
/storage/tempproject/project/CommonError.h:20: multiple definition of`CommonError::CommonError[in-charge](int)'
~~~~~~~~
what is the difference between [in-charge] and [not-in-charge]

StrView.o(.text+0x126):/storage/tempproject/project/CommonError.h:20: first
defined here

icoming 05-21-2004 11:05 AM

some more surprising debug information:
i write a class ,compile it with gcc , and get some surprising errors.

cd /storage/tempproject/project/
g++ -ggdb3 -c FileList.cpp
/usr/include/c++/3.2.2/bits/ios_base.h: In copy constructor
`std::basic_ios<char, std::char_traits<char> >::basic_ios(const
std::basic_ios<char, std::char_traits<char> >&)':
/usr/include/c++/3.2.2/bits/stl_construct.h:78: instantiated from `void
std::_Construct(_T1*, const _T2&) [with _T1 = SunMemString, _T2 = SunMemString]'
/usr/include/c++/3.2.2/bits/stl_list.h:328: instantiated from
`std::_List_node<_Tp>* std::list<_Tp, _Alloc>::_M_create_node(const _Tp&) [with
_Tp = SunMemString, _Alloc = std::allocator<SunMemString>]'
/usr/include/c++/3.2.2/bits/stl_list.h:430: instantiated from
`std::_List_iterator<_Tp, _Tp&, _Tp*> std::list<_Tp,
_Alloc>::insert(std::_List_iterator<_Tp, _Tp&, _Tp*>, const _Tp&) [with _Tp =
SunMemString, _Alloc = std::allocator<SunMemString>]'
/usr/include/c++/3.2.2/bits/stl_list.h:479: instantiated from `void
std::list<_Tp, _Alloc>::push_back(const _Tp&) [with _Tp = SunMemString, _Alloc =
std::allocator<SunMemString>]'
FileList.cpp:9: instantiated from here
~~~~~~~~~~~~~~the 8th and 9th lines in my program are:
SunMemString file1(PathStr);
AllFile.push_back(file1);
SunMemString is my class and list<SunMemString> AllFile;
what does information mean?

/usr/include/c++/3.2.2/bits/ios_base.h:424: `std::ios_base::ios_base(const
std::ios_base&)' is private
/usr/include/c++/3.2.2/bits/stl_construct.h:78: within this context
/usr/include/c++/3.2.2/streambuf: In copy constructor `std::basic_filebuf<char,
std::char_traits<char> >::basic_filebuf(const std::basic_filebuf<char,
std::char_traits<char> >&)':
/usr/include/c++/3.2.2/streambuf:479: `std::basic_streambuf<_CharT,
_Traits>::basic_streambuf(const std::basic_streambuf<_CharT, _Traits>&)
[with _CharT = char, _Traits = std::char_traits<char>]' is private
/usr/include/c++/3.2.2/bits/stl_construct.h:78: within this context

Compilation exited abnormally with code 1 at Fri May 21 16:06:50

bluie 05-21-2004 12:14 PM

Hi icoming!
Could you reveal your source or even better create a minimal example to be able to reconstruct the compile-failure of your post #1?

bluie

icoming 05-21-2004 12:39 PM

ok!
#include"All.h"
#include"SunMemstring.h"

class FileList
{
list<SunMemString> AllFile;
list<SunMemString>::iterator pos;
public:
FileList(char *);
FileList(){pos=AllFile.begin();}
~FileList(){free(PathStr);}
bool AddFile(const char *);
bool DeleteFile(const char *);
};

FileList::FileList(char *filename)
{
GetPathStr();
SunMemString file1(PathStr);
AllFile.push_back(file1);//if i make this line and another line which has 'push_back' comments ,there is no error
pos=AllFile.begin();
}

bool FileList::AddFile(const char *filename)
{
GetPathStr();
SunMemString file1(PathStr);
AllFile.push_back(file1);
pos=AllFile.end();
advance(pos , -1);
return true;
}

do you want me to reveal the class SunMemString?

bluie 05-21-2004 01:06 PM

Hm. Can't find any sign of CommonError in the posted code.
So please reveal the parts where CommonError occurs and also reveal
the includes. StrView.h and/or StrView.cpp and main.cpp are very
suspicious to use CommonError.

icoming 05-22-2004 05:07 AM

oh,i'm sorry the first two error informations posted are made when i compiled two programs.
so there is no relation between two error informations.
in the first error information,what i want to know is what does [not-in-charge] in 'CommonError::CommonError[not-in-charge](int)' mean.
and in the second error information is what really puzzled me,and the example is posted for the second error.but the example is not good.
so i want post all my program here.my program is an editor which simulate 'vi'


icoming 05-22-2004 05:12 AM

All.h:

#ifndef __ALL_H__
#define __ALL_H__

#include<iostream>
#include<string>
#include<sstream>
#include<fstream>
#include<list>
using namespace std;
#include<curses.h>
#include<termio.h>
#include<sys/ioctl.h>
#include<signal.h>
#include<errno.h>
#include<string.h>
#include<limits.h>
#include<unistd.h>

#include"CommonError.h"

#define KEY_ESC 27
#define KEY_DELETE 263

const int MAXCOMMANDSIZE=100;
const int EDITMODE=0;
const int COMMANDMODE=1;
const int UP=1;
const int DOWN=0;

extern int errno;

struct winsize GetWinSize();

struct Location
{
int x;
int y;
};


class FatalError
{
string str;
public:
FatalError(char *ch):str(ch){}
string GetStr(){return str;}
};

#endif

icoming 05-22-2004 05:13 AM

CommonError.h:

#ifndef __COMMONERROR_H__
#define __COMMONERROR_H__

class CommonError
{
public:
static const int NOPATHNAME=0;
static const int UNDERBUF=1;
static const int OVERBUF=2;
static const int MAXERROR=10;
CommonError(int i)
{
error=i;
ErrorStr[0]="can't open file because can't get pathname";
ErrorStr[1]="the index get under buffer";
ErrorStr[2]="the index get over buffer";
}
CommonError(){}
string GetStr(){return ErrorStr[error];}
private:
string ErrorStr[MAXERROR];
int error;
};

#endif

icoming 05-22-2004 05:14 AM

Control.cpp:

#include"Control.h"
#include"StrView.h"
#include"All.h"

void Control::EditFile()
{
for(;;)
{
int ch=getch();
if(Files.EditFile(ch) == 0)
break;
}
Mode=COMMANDMODE;
}

bool Control::ReadStr()
{
for(;;)
{
int ch=getch();
if(ch == KEY_ESC)
break;
else if(ch == 10)
return true;
else if(ch == KEY_LEFT)
FirstView.KeyLeft(Command);
else if(ch == KEY_RIGHT)
FirstView.KeyRight(Command);
else if(ch == KEY_UP)
History.KeyDownUp(Command , FirstView , UP);
else if(ch == KEY_DOWN)
History.KeyDownUp(Command , FirstView , DOWN);
else
{
Command.Insert((char)ch);
FirstView.GetLocat();
FirstView.DisplayCommand(Command);
FirstView.KeyRightAuto(Command);
History.ReplaceEnd(Command.GetBuffer());
}
}
return false;
}

void Control::Find(istringstream &is)
{
string str;
string parament;
for(;;)
{
is>>str;
if(!is)
{
FirstView.DisplayCommand("there is too few parament");
return;
}
else if(str[0] == '\"')
{
parament+=str;
if(parament[parament.size()-1] == '\"')
{
parament.erase(parament.size()-1 , 1);
is>>str;
if(is)
{
FirstView.DisplayCommand("there are too many parament");
return;
}
//call the function of StrMem
}
else
continue;
}
else
{
is>>str;
if(is)
{
FirstView.DisplayCommand("there are too many parament");
return;
}
else
; //call the function of StrMem
}
}//for
}

void Control::CommSet(istringstream &is)
{
string str;
is>>str;
if(is)
{
}
else
FirstView.DisplayCommand("there are too few parament");
}

void Control::CommOpen(istringstream &is)
{
}

void Control::TranComm(string strcommand)
{
strcommand.erase(0 , 1);//remove the ':'
istringstream is(strcommand);
string str;
is>>str;
if(str == "find")
Find(is);
else if(str == "set")
CommSet(is);
else if(str == "open")
CommOpen(is);
else if(str == "replace")
{
}
else if(str == "replace all")
{
}
else if(str == "close")
{
}
else if(str == "split")
{
}
else if(str == "showbuf")
{
}
else if(str == "changbuf")
{
}
else if(str == "q")
{
NowExit=true;
return;
}
else if(str == "x")
{
}
else
{
FirstView.DisplayCommand("there is no such a commmand");
}

}

void Control::ReadCommand()
{
int ch;
bool inputcomm=false;
for(;!NowExit;)
{
bool esc_press_twice=false;
ch=getch();
switch (ch)
{
case 'i':
{
FirstView.ClearComLine();
FirstView.DisplayCommand("insert");
Mode=EDITMODE;//change to edit mode
return;
}
case ':':
{
FirstView.ClearComLine();
Command.Insert(':');
FirstView.DisplayCommand(Command);
FirstView.GetLocat();
inputcomm=true;
esc_press_twice=false;
break;
}
case KEY_ESC:
{
KeyEsc:
if(esc_press_twice == false && inputcomm)
{
Command.Clear();
FirstView.ClearComLine();
move(EditLocat.x , EditLocat.y);
esc_press_twice=true;
}
else
beep();
break;
}//case KEY_ESC
default:
{
if(inputcomm)
{
echochar(ch);
Command.Insert((char)ch);
if(ReadStr())
{
History.KeyEnter(Command.GetBuffer());
TranComm(Command.GetBuffer());
}
else
goto KeyEsc;
Command.Clear();
inputcomm=false;
}
else
beep();
}
}//switch
}//for
}

icoming 05-22-2004 05:17 AM

Control.h

#ifndef __CONTROL_H__
#define __CONTROL_H__

#include"All.h"
#include"StrView.h"
#include"HistoryCommand.h"
#include"SunMemstring.h"
#include"FileList.h"

extern StrView FirstView;

class Control
{
MemString Command;
HistoryCommand History;
FileList Files;
/*
??
*/
string FindRecord;
int Mode;
bool NowExit;

struct Location EditLocat;//remember the edit location of guangbiao
public:
Control()
{
Mode=COMMANDMODE;//when it's command mode ,Mode is true.or Mode is false
NowExit=false;
}
Control(char *filename)
{
try
{
SunMemString file1(filename);
}
catch(int error)
{

}
}
~Control(){}
void SetEditLocat();
bool GetNowExit(){return NowExit;}
int GetMode();
void ReadCode();
void ReadCommand();
void MyMain();
void EditFile();
void TranComm(string);
bool ReadStr();
void Find(istringstream &);//??????
void CommSet(istringstream &);
void CommOpen(istringstream &);
void Replace();//??
void SetIfAuto();//??????????
void OpenFile();//????.
void SaveFile();//????
void Help();//??
void ChangeFile();//????
};

inline int Control::GetMode()
{
return Mode;
}

inline void Control::SetEditLocat()
{
EditLocat=FirstView.GetLocat();
}

#endif

icoming 05-22-2004 05:18 AM

FileList.cpp

#include"FileList.h"
#include"StrView.h"

extern StrView FirstView;

FileList::FileList(char *filename)
{
try
{
GetPathStr();
SunMemString file1(PathStr);
AllFile.push_back(file1);
}
catch(int)
{
char *errorstr=strerror(errno);
FirstView.DisplayCommand(errorstr);
}
#ifdef PATH_MAX
PathStrLen=PATH_MAX;
#else
PathStrLen=1024;
#endif
PathStr=(char *)malloc(sizeof(char)*PathStrLen);
if(PathStr == NULL)
{
throw FatalError("there isn't enough memory space\n");
}
pos=AllFile.begin();
}

int FileList::TestFileName(const char *filename) const
{
if(filename[0] == '/')
return WHOLEPATH;
else
{
while(filename != 0)
if(*filename == '/')
return RELATIVEPATH;
return ONLYFILE;
}
}

bool FileList::HaveFile(const char *testfilename)
{
temp=AllFile.begin();
string filename;
ToWhole(testfilename); //get the whole path of testfilename
while(temp != AllFile.end())
{
filename=temp->GetFileName();
if(filename == testfilename)
return true;
}
return false;
}

bool FileList::GetPathStr()
{
for(;;)
{
errno=0;
if(getcwd(PathStr , PathStrLen) == NULL)
{
if(errno == ERANGE)
{
PathStr=(char *)realloc(PathStr , PathStrLen*8);
if(PathStr == NULL)
throw FatalError("there isn't enough memory space\n");
PathStrLen*=8;
continue;
}
else
throw CommonError(0);
}
else
return true;
}
}

void FileList::ToWhole(const char *filename)
{
int sign=TestFileName(filename);
if(sign == WHOLEPATH)
return;
else
{
GetPathStr();
int len=strlen(filename)+strlen(PathStr)+1;
if(PathStrLen < len)
{
PathStr=(char *)realloc(PathStr , len);
PathStrLen=len;
}
if(PathStr == NULL)
throw FatalError("there isn't enough memory space\n");
if(sign == RELATIVEPATH)
{
if(filename[0] == '.' && filename[1] == '/')
strcat(PathStr , filename+2);
else if(filename[0] == '.' && filename[1] == '.' && filename[2] == '/')
strcat(PathStr , filename+3);
else
strcat(PathStr , filename);
}
else
strcat(PathStr , filename);
}
}

bool FileList::AddFile(const char *filename)
{
try
{
GetPathStr();
SunMemString file1(PathStr);
AllFile.push_back(file1);
pos=AllFile.end();
advance(pos , -1);
return true;
}
catch(int)
{
char *errorstr=strerror(errno);
FirstView.DisplayCommand(errorstr);
return false;
}
}

bool FileList::DeleteFile(const char *filename)
{
if(HaveFile(filename))
{
bool samefile=false;
if(pos == temp)
samefile=true;
AllFile.erase(temp);
if(samefile)
pos=AllFile.begin();
return true;
}
else
return false;
}

int FileList::EditFile(const int ch)
{
switch (ch)
{
/*
case KEY_DELETE:
FirstView.KeyDelete(*pos);
break;
*/
case KEY_ESC:
return 0;
case 10:
FirstView.KeyEnter(*pos);
break;
case KEY_LEFT:
FirstView.KeyLeft(*pos);
break;
case KEY_RIGHT:
FirstView.KeyRight(*pos);
break;
case KEY_UP:
FirstView.KeyUp(*pos);
break;
case KEY_DOWN:
FirstView.KeyDown(*pos);
break;
case KEY_BACKSPACE:
FirstView.KeyBackSpace(*pos);
break;
case KEY_PPAGE:
FirstView.KeyPageUp(*pos);
break;
case KEY_NPAGE:
FirstView.KeyPageUp(*pos);
break;
case KEY_HOME:
FirstView.KeyHome(*pos);
break;
case KEY_END:
FirstView.KeyEnd(*pos);
break;
case KEY_IC:
FirstView.KeyInsert();
break;
default:
{
if(ch >= 0 && ch <= 255)
{
pos->Insert(ch);
FirstView.GetLocat();
FirstView.DisplayCommand(*pos);
FirstView.KeyRightAuto(*pos);
}
else
beep();
}
}
return 1;
}

icoming 05-22-2004 05:20 AM

FileList.h


#ifndef __FILELIST_H__
#define __FILELIST_H__

#include"All.h"
#include"SunMemstring.h"

class FileList
{
static const int WHOLEPATH=1;
static const int RELATIVEPATH=2;
static const int ONLYFILE=4;
list<SunMemString> AllFile;
list<SunMemString>::iterator pos;
list<SunMemString>::iterator temp;
char *PathStr;
int PathStrLen;
bool HaveFile(const char *);
void ToWhole(const char *);
bool GetPathStr();
int TestFileName(const char *filename) const;
public:
FileList(char *);
FileList(){pos=AllFile.begin();}
~FileList(){free(PathStr);}
bool AddFile(const char *);
bool DeleteFile(const char *);
bool IsEmpty();
int TestFileName(char *);
int EditFile(const int);
};

inline bool FileList::IsEmpty()
{
if(AllFile.size() == 0)
return true;
else
return false;
}

#endif

icoming 05-22-2004 05:21 AM

HistoryCommand.h:

#ifndef __HISTORYCOMMAND_H__
#define __HISTORYCOMMAND_H__

#include"All.h"
#include"Memstring.h"

class HistoryCommand
{
static const int MAXLEN=100;
list<string> HisCom;
list<string>::iterator pos;
public:
HistoryCommand()
{
HisCom.push_back(" ");
pos=HisCom.begin();
}
void ReplaceEnd(const string &str);
//void PushHis(const string &str);
void KeyDownUp(MemString &Command , StrView &view , int sign);
void KeyEnter(const string &str);
};

inline void HistoryCommand::ReplaceEnd(const string &str)
{
HisCom.pop_back();
HisCom.push_back(str);
}

/*
inline void HistoryCommand::PushHis(const string &str)
{
if(HisCom.size() < HisComLen)
{
HisCom.push_back(str);
HisComLen++;
}
else
{
HisCom.pop_front();
HisCom.push_back(str);
}
}
*/

inline void HistoryCommand::KeyDownUp(MemString &Command , StrView &view , int sign)
{
if(sign == DOWN)
{
if(pos == HisCom.end())
{
beep();
return;
}
pos++;
if(pos == HisCom.end())
{
beep();
return;
}
}
else
{
if(pos == HisCom.begin())
{
beep();
return;
}
pos--;
}
Command.Clear();
Command.Insert(*pos);
view.DisplayCommand(Command);
struct winsize WinSize=view.GetWinSize();
int len=Command.GetLength()%WinSize.ws_col;
move(WinSize.ws_row-1 , len);
}

inline void HistoryCommand::KeyEnter(const string &str)
{
if(HisCom.size() == MAXLEN)
HisCom.pop_front();
HisCom.push_back(" ");
pos=HisCom.end();
advance(pos , -1);
}

#endif

icoming 05-22-2004 05:21 AM

main.cpp:

#include "All.h"
#include "Control.h"
#include "StrView.h"

struct winsize GetWinSize()
{
struct winsize size;
if(ioctl(1 , TIOCGWINSZ , (char *)&size) < 0)
cout<<"TIOCGWINSZ error";
return size;
}

StrView FirstView;

int main (int argc , char *argv)
{
try
{
Control control;
//signal(SIGWINCH , FirstView.SigWinch);
//signal(SIGALRM , control.SigAlrm);
for(;!control.GetNowExit();)
{
control.SetEditLocat();
if(control.GetMode() == COMMANDMODE)
control.ReadCommand();
else
control.EditFile();
}
}
catch(FatalError error)
{
cout<<error.GetStr();
}
}

icoming 05-22-2004 05:22 AM

Memstring.cpp:


#include"Memstring.h"
#include"StrView.h"

extern StrView FirstView;

string& MemString::CopyString(int i,int j)
{
char temp[BUFFERSIZE];
TempBuffer.copy(temp,i,j-i);
int n;
for(n=0;n<j-i;n++)
{
stemp+=temp[n];
}
return stemp;
}

MemString::MemString()
{
Locate=0;
LineLen=0;
OneLine=NULL;
StartLocate=0;
StartPage=0;
}

MemString::MemString(const char* s):TempBuffer(s)
{
Locate=0;
LineLen=0;
OneLine=NULL;
StartLocate=0;
StartPage=0;
}

char* MemString::GetLine(const int ScreenWidth)
{
if(ScreenWidth > LineLen)
{
OneLine=(char *)realloc(OneLine , (ScreenWidth+1)*sizeof(char));//haven't consider about '\t'
LineLen=ScreenWidth;
}

int i,j;
if(StartLocate >= TempBuffer.size())
return NULL;
else
{
if(FirstView.GetAutoEndl())
{
int index=TempBuffer.find("\n" , StartLocate , ScreenWidth);
if(index == -1)
{
if(StartLocate+ScreenWidth > TempBuffer.size())
{
TempBuffer.copy(OneLine , TempBuffer.size()-StartLocate , StartLocate);
OneLine[TempBuffer.size()-StartLocate]=0;
StartLocate=TempBuffer.size();
}
else
{
TempBuffer.copy(OneLine , ScreenWidth , StartLocate);
OneLine[ScreenWidth]=0;
StartLocate+=ScreenWidth;
}
}//there is no '\n' in the line
else
{
TempBuffer.copy(OneLine , index-StartLocate+1 , StartLocate);
OneLine[index-StartLocate+1]=0;
StartLocate=index+1;
}//there is '\n' in the line
}//if AutoEndl
else
{
int index=TempBuffer.find("\n" , StartLocate);
if(index == -1)
{
if(TempBuffer.size()-StartLocate-1 <= ScreenWidth)
{
TempBuffer.copy(OneLine , TempBuffer.size()-StartLocate , StartLocate);
OneLine[TempBuffer.size()-StartLocate]=0;
}
else
{
TempBuffer.copy(OneLine , ScreenWidth , StartLocate);
OneLine[ScreenWidth]=0;
}
StartLocate=TempBuffer.size();
}//there is no '\n' in the buffer
else
{
if(index-StartLocate <= ScreenWidth)
{
TempBuffer.copy(OneLine , index-StartLocate , StartLocate);
OneLine[index-StartLocate+1]=0;
}
else
{
TempBuffer.copy(OneLine , ScreenWidth , StartLocate);
OneLine[ScreenWidth]=0;
}
StartLocate=index+1;
}//there is '\n' in the buffer
}//if nonAutoEndl
}//StartLocate doesn't reach the end of buffer
return OneLine;
}


All times are GMT -5. The time now is 11:57 AM.