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...
}

New Topic/Question
Reply



MultiQuote


|