1
(5) 0x1c6235e1 in ProxyClass::Method_C (this=0xb3a0c8, sendFilePath=...) at ./src/ProxyClass.cpp:112

(6) 0x2c8706c1 in Class1::Method_B (this=0x1fc5a1, profile=0x2c8f2340 "fileProfile1", filePathAndFileName=0x0) at ./src/Class1.cpp:860

(7) 0x2c4ae4c0 in Method_B (profile=0x42c <Address 0x42c out of bounds>, filePathAndFileName=0x0) at ./src/Class1_interface.cpp:310

(8) 0x2c1e5c3c in Method_A (profile=0x42c <Address 0x42c out of bounds>, filename=0x2c601c1c "/tmp/temporaryfile.tmp") at ./src/file.cpp:890

我有上面用 gnu gdb 调试的核心文件片段。该核心文件是在运行 Linux 的嵌入式系统上创建的。函数调用中的变量没有任何操作......
我的问题如下:

  1. 为什么配置文件在第 8 帧看起来像这样Address 0x42c out of bounds,而在第 9 帧之前配置文件没有变化,这怎么能变得有意义(“fileSchema”)?

  2. 我的嵌入式系统崩溃,因为filename(char *)等于,0x2c601c1c并且路径在第 8 帧“/tmp/temporaryfile.tmp”上像这样打印。然而,再次没有对文件名变量进行操作,Method_A 调用 Method_B 但 char 指针在第 7 帧突然变为空 (filePathAndFileName=0x0)。然后,我的系统崩溃了。char * 指针如何通过操作转换为 NULL?

崩溃发生在第 6 帧,因为在Class1::Method_B以下行中执行"std::string filePath( filePathAndFileName);"。正在尝试将空字符指针初始化为字符串,我认为它会导致崩溃和中止信号(程序以信号 6 终止,已中止。)。如何避免 char * 在方法之间的该变量的传递中变为 null?知道为什么它变为空吗?

static TUint16 Method_A(char* profile, char* filename)
{
    TUint16 a; //after the call of Method_B,the other part of this method being processed but anyway the code never passes to there because of th crash..
    Method_B(profile,filename);
    ...
    ...
    ...
    return a;
}

unsigned char Method_B_interface(char* profile, char* filePathAndFileName)
{
    unsigned char returnValue = 0;

    if ( callbackObject->Method_B( profile, filePathAndFileName ) )
    {
        returnValue = 1;
    }
    return returnValue;
}

bool Class1::Method_B(char* profile, char* filePathAndFileName)
{
    bool returnValue = true;

    std::string   filePathString( filePathAndFileName );
    std::string   profileString( profile );

    if(profileString == "fileProfile1")
    {
        if(xClass != NULL)
        {
            returnValue = xClass->Method_C(filePathString);
        }
    }
    ...
    ...
    ...
    return returnValue;
}

bool ProxyClass::Method_C(const std::string& exportFilePathAndFileName)
{
    bool returnValue;
    std::string message = "dummy", parameters;

    Serializer::serialize( message, exportFilePathAndFileName );
    proxyRequest->synchCall( message, parameters );

    getResponse(parameters);
    Serializer::deserialize( parameters, returnValue );

    return returnValue;
}
4

0 回答 0