I am trying to push the values of 1 class vector to other class vector using dynamic casting. But I am getting a segmentation fault.
When I debugged the program using gdb I found that dynamic_cast
is not happening so there is no value to push to the vector.
Here I am trying to copy the elements from std::vector<BPatch_point *> *points
to std::vector<ldframework::Point *> *lpoints
.
BPatch_point
and Point
are completely unrelated classes.
Could you please help me on this?
int main(int argc , char *argv[])
{
BPatch bpatch;
int pid;
if (argc != 3) {
exit(1);
}
pid=atoi(argv[1]);
char name[ 40 ];
cout<<"The attached pid is "<<pid<<endl;
BPatch_process *appProc = bpatch.processAttach("",pid);
BPatch_image *img = appProc->getImage();
std::vector<BPatch_function *> functions;
std::vector<BPatch_point *> *points;
img->findFunction(argv[2], functions);
if(functions.size()==0) {
cout<<"unable to find the function "<<argv[2]<<endl;
return -1;
}
else {
cout<<"The "<<argv[2]<<" function is found"<<endl;
}
points = functions[0]->findPoint(BPatch_entry);
if ((*points).size() == 0) {
cout<<"Not able to find the points"<<endl;
}
cout<<"The points is "<<(*points)[0];
std::vector<ldframework::Point *> *lpoints=NULL;
for(unsigned int i=0; i<(*points).size();i++)
{
lpoints->push_back(dynamic_cast<ldframework::Point *>((*points).at(i)));
}
}
BPatch_point
andldframework::Point
; the fact that they're stored in vectors is irrelevant.