C++ LP64 中通过引用更改我的指针值传递.我应该看什么

C++ pass by reference changing pointer values on me in LP64. What should I look at?

本文关键字:值传 指针 我应该 什么 我的 LP64 引用 C++      更新时间:2023-10-16

我深入到 synergy-project.org 的旧版本(1.3.4)中,在Solaris Studio 12.4上构建它该程序中有 2 个地方使用参数指针调用函数,并且指针在进入的路上被破坏了。在 -m64 中进行编译和链接。 我可以在构建标志中看到什么或者其他来弄清楚为什么这是混乱的?在下面的日志中,程序在看到错误指针的函数内被断点。它的父级(堆栈上的"up")具有正确的数据:

(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如何随着通信协议的移动而重新加载。

在回答有关单步执行函数的问题时:它在进入函数时被破坏,并导致函数在不久后崩溃。 如果我将"parseHandshakeMessage()"硬编码到handleData(),它可以正常工作。但是,我在此系统中还有其他依赖于函数指针才能正常工作的示例。我可能会发布编译标志,它们是冗余且广泛的。

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

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