1 Replies - 1484 Views - Last Post: 24 January 2007 - 12:17 PM Rate Topic: -----

#1 sshallen   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 23-January 07

Segmentation Fault accessing base public variable in gcc but not Visua

Posted 23 January 2007 - 02:04 PM

I tried to take out or not include all the non-relavent code (if I took out too much let me know). I have an "instruction" which is decoded and executed. NP_instruction should inherit everything from the base class OP_instruction and NP_instruction only needs to re-define the "Execute" section of code.

First there is a call into the base source code at OP_instruction::OP_instruction and a public variable regX is given a value. At this point in ddd on linux (gcc 3.2) if you print regX or this.regX you get a value of 0x2. Then you return to the higher level flow and a call to NP_instruction::Execute() occurs. At the line where the code wants to check the value of regX if you print regX or this.regX I get a value of 0x0. Somehow regX is not avaliable to me even though it was marked public in the base class from which NP_instruction was derived.

In visual C++ regX is avaliable to me and if I look at this it contains the OP_instruction variables including regX. Executing this code compiled in Visual C++ I get the value of 0x2 and "instruction" executes correctly. Executing this code in linux compiled in gcc the 0x0 for regX causes me to take a segmentation fault as it is trying to load from a memory location that does not exist. Any ideas what is going on here?

Base Instruction Header File
------------------------------
class OP_instruction : public OP_Inst
{
   public:
	  static OP_InstInfo info;
	  static OP_Inst *Construct(OP_Helper, OP_InstDecode &decode)
	  {
		 return new OP_instruction(helper, decode);
	  };

   public:
	  u1byte regX;

   public:
	  OP_instruction(OP_Helper &helper, OP_InstDecode &decode);
	  virtual void Execute();
	  void DstSrc(opInfo *dsts, opInfo *srcs);

};

Base Instruction Source File
--------------------------------
OP_InstInfo OP_instruction::info = {"instruction", OP_instruction::Construct};

OP_instruction::OP_instruction(OP_Helper &helper, OP_InstDecode &decode) : OP_Inst(helper, decode)
{
   instInfo = &OP_instruction::info
   regX = u1byte(decode.reg[0]);
   // code ...
}

void OP_instruction::DstSrc(opInfo *dsts, opINfo *srcs)
{
   // code ...
}

void OP_instruction::Execute()
{
   // code ...
}

Derived Instruction Header File
-------------------------------
class NP_instruction : public OP_instruction
{
  public:
	static OP_InstInfo info;
	static OP_Inst *Construct(OP_Helper &helper, OP_InstDecode &decode)
	{
	  return new OP_instruction(helper, decode);
	};

  public:
	NP_instruction(OP_Helper &helper, OP_InstDecode &decode) :
		OP_instruction(helper, decode) {};
	virtual void Execute();
};

Derived Instruction Source File
-------------------------------

OP_InstInfo NP_instruction::info = {"instruction", NP_instruction::Construct};

void OP_instruction::Execute()
{
  // code which includes usage of regX...
}



Is This A Good Question/Topic? 0
  • +

Replies To: Segmentation Fault accessing base public variable in gcc but not Visua

#2 sshallen   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 23-January 07

Re: Segmentation Fault accessing base public variable in gcc but not Visua

Posted 24 January 2007 - 12:17 PM

I tried gcc 3.2.3 (vs. 3.2) and looks like the issue went away. Appeared too basic to be an issue in 3.2 but I will need to look at the release notes and hope the issue does not occur again.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1