Reputation: 29
I got a segmentation fault(core dumped) error and tried debugging using gdb. I found out where the error occurred:
Program received signal SIGSEGV, Segmentation fault.
0x08048edb in state_update2 () at xxx.cpp:333
333 if (rob.head->is_complete == 1 && rob.head->ready_to_retire == 1 )
A few lines of the code are:
if(rob.head->is_complete == 1 && rob.head->ready_to_retire == 1) {
reorder_buffer_node *temp = new reorder_buffer_node[sizeof(struct reorder_buffer_node)];
temp = rob.head;
for(uint64_t i=0; i<f_; i++) {
if(temp->is_complete == 1 && temp->ready_to_retire == 1) {
rob.pop();
retired_inst++;
temp = temp->next;
}
else break;
}
}
ROB is a cyclic queue and head is a pointer to a structure which is of the form:
struct reorder_buffer_node {
int is_complete;
uint64_t instr_num;
uint64_t dest_reg;
uint64_t index;
reorder_buffer_node *next;
int ready_to_retire;
};
Am I not accessing the members of the structure in the right way? Please let me know!
Upvotes: 0
Views: 413
Reputation: 2244
reorder_buffer_node *temp = new reorder_buffer_node[sizeof(struct reorder_buffer_node)];
//Are you trying to create an array of reorder_buffer_node and name as temp??
temp = rob.head;
//With the above comment this line will not happen
temp = temp->next;
//You have not written any constructor for the structure, hence with default constructor, it temp will be assigned to garbage or NULL. When you do the above step it might provide segmentation fault or crash. So better to write a constructor.
If following steps taken care of it will run correctly.
Upvotes: 2
Reputation: 1503
If I understand you correctly crash happens at if()? So, as you mentioned that head is a pointer, then maybe it is not allocated? If so following code gives a segmentation fault:
if(rob.head->is_complete == 1 && rob.head->ready_to_retire == 1)
To check it you can just a print out pointer or add check for NULL for this pointer.
Upvotes: 0
Reputation: 96311
I don't have enough context to say for sure but I would start with these two lines:
reorder_buffer_node *temp = new reorder_buffer_node[sizeof(struct reorder_buffer_node)];
temp = rob.head;
Which destroy the value of the new
in a way similar to:
int temp = 15;
temp = 5;
Upvotes: 1