【问题标题】:C++ pass by reference changing pointer values on me in LP64. What should I look at?C++ 通过引用在 LP64 中更改我的指针值。我应该看什么?
【发布时间】:2015-01-09 05:45:42
【问题描述】:

我深入了解 synergy-project.org 的旧版本 (1.3.4),在 Solaris Studio 12.4 上构建它 在这个程序中有两个地方使用参数指针调用函数,并且 指针在进入的过程中被破坏。在 -m64 中编译和链接。我可以在构建标志中查看什么 或其他找出为什么这是乱七八糟的? 在下面的日志中,程序在看到错误指针的函数内部设置了断点。 它的父级(堆栈上的“向上”)具有正确的数据:

(dbx) print &event
&event = 0x948d30
(dbx) up          
Current function is TMethodEventJob<CXWindowsScreen>::run
 66                   (m_object->*m_method)(event, m_arg);
(dbx) print &event
&event = 0xffff80f8be958a60

(dbx) down
(dbx) print event
event = {
m_type   = 7354752U
m_target = 0x7091a0
m_data   = 0x7036a0
m_flags  = 6257120U
}
(dbx) up        
Current function is TMethodEventJob<CXWindowsScreen>::run
   66                   (m_object->*m_method)(event, m_arg);
(dbx) print event
event = {
m_type   = 2U
m_target = 0x94ee80
m_data   = 0xc838b0d68
m_flags  = 0
}

代码:

void
CClientProxy1_0::handleData(const CEvent&, void*)
{
    // handle messages until there are no more.  first read message code.
    UInt8 code[4];
    UInt32 n = getStream()->read(code, 4);
    while (n != 0) {
            // verify we got an entire code
            if (n != 4) {
                    LOG((CLOG_ERR "incomplete message from \"%s\": %d bytes", getName().c_str(), n));
                    disconnect();
                    return;
            }

            // parse message
            LOG((CLOG_DEBUG2 "msg from \"%s\": %c%c%c%c", getName().c_str(), code[0], code[1], code[2], code[3]));
          if (!(this->*m_parser)(code)) {

...m_parser 解析为:

bool
CClientProxy1_0::parseHandshakeMessage(const UInt8* code)
{
    if (memcmp(code, kMsgCNoop, 4) == 0) {
            // discard no-ops
            LOG((CLOG_DEBUG2 "no-op from", getName().c_str()));
            return true;
    }
    else if (memcmp(code, kMsgDInfo, 4) == 0) {
            // future messages get parsed by parseMessage
            m_parser = &CClientProxy1_0::parseMessage;
            if (recvInfo()) {
                    EVENTQUEUE->addEvent(CEvent(getReadyEvent(), getEventTarget()));
                    addHeartbeatTimer();
                    return true;
            }
    }
    return false;
}
}

...注意 m_parser 是如何随着 comm 协议的移动而重新加载的。

回答关于进入函数的问题:进入函数时它会被破坏, 并导致该功能很快崩溃。如果我将“parseHandshakeMessage() 硬编码到 handleData() 中,它可以正常工作。但是,我在这个系统中有其他示例依赖函数指针才能正常工作。我可能会发布编译标志,它们是多余的和广泛的。

【问题讨论】:

  • 您能否也发布相关的相应C++代码片段?另外,你确定你已经在参数实际初始化的时候停止了程序吗?也许你需要跨过被调用者的第一行之类的……
  • 生成MCVE 是您能做的最好的事情。如果你不能做一个(即当你删除一些代码时错误消失了),那么这是一个关于错误来自哪里的强有力的线索。

标签: c++ pass-by-reference solaris-studio


【解决方案1】:

尝试使用“+W2 -xport64”编译所有内容。

这可能会产生很多错误/警告。理想情况下,您的代码应该清除所有警告,尤其是从“-xport64”生成的警告。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-07-25
    • 1970-01-01
    • 2011-04-20
    • 1970-01-01
    • 1970-01-01
    • 2010-11-13
    • 2019-12-06
    相关资源
    最近更新 更多