2

当我调试我的 PRJ 时,我收到此错误:

args 错误:报告了多个错误。\ 无法执行 MI 命令:-var-create -

args 来自调试器后端的错误消息:尝试取消引用通用指针。\ 无法创建变量对象

从 void* args 转换为 Mapper* arg 时出现错误。

更新 1

KMaster、KMapper 分别实现了 Master、Mapper 但它们并没有添加任何相关的内容。有效的是调用方法的 KMapper work()。这是代码:

int main(){
    int np=1,K=4;
    string path="lucca.gps";
    KMaster* master=new KMaster(path,np,K);
    KMapper* mapper[np];
    master->splitting();
    for(int i=0;i<np;i++){
            mapper[i]=new KMapper(master,master->mData[i].key,master->mData[i].value);
            while(mapper[i]->work()!=0){
                cout<<"failed creating mapper, retry..."<<endl;
                sleep(1000);
            }
    }
}

int KMaster::splitting(){
    cout<<"start splitting"<<endl;
    fstream is(path.c_str());
    string s="";
    getline(is,s);
    while(!is.eof()){
        for(int i=0;i<nProc;i++){
            pair<double,double> res;
            is>>res.first;
            is>>res.second;
            is>>s;
            mapData[i].push_back(res);
            Data.push_back(res);
            if(is.eof()) break;
        }
    }        
    list<pair<double,double> >::iterator it=Data.begin();
    int increment=Data.size()/K;
    for(int i=0;i<K;i++){
        Klusters.push_back(*it);
        advance(it,increment);
    }
    for(int i=0;i<nProc;i++){
        mData[i].key=&Klusters;
        mData[i].value=&mapData[i];
    }
    cout<<"splitting completed"<<endl;
    return 0;
}

int Mapper::work(){
    Mapper* m=this;
    void* p=m;
    return pthread_create(&thread,NULL,start,p);
}

void* start(void* args){
    cout<<"start()"<<endl;
    Mapper* arg= reinterpret_cast<Mapper*>(args);
    arg->mapResult=arg->map(arg->k,arg->v);
    cout<<"Mapper finish, sending result..."<<endl;
    arg->send(arg->mapResult);
}

希望有人能帮忙!

更新 2

调试器截图:

日食调试

4

1 回答 1

0

的值arg是 24,没有正常的对象会存在,因此强制转换与此无关。

不幸的是,这个“答案”只能是一个疯狂的猜测,因为您没有显示调用代码。

如果arg总是24,我检查类似的东西:

class Something
{
public:
    void dostuff() { mapper.work(); }
private:
    // 24 bytes of "stuff" before this member (including possibly a vtable)
    Mapper mapper;
};

Something *thing = 0;
thing->dostuff(); // Thing->mapper will have address 24.

您也可能有一个未初始化的变量

Mapper* mapper;
mapper->work(); // Oops, uninitialised

恰好是24。

于 2013-01-24T21:08:23.310 回答