0

I'm deep inside an old rev (1.3.4) of synergy-project.org, building it on Solaris Studio 12.4 There are 2 places in this program where a function is called with a pointer for argument, and the pointer gets mangled on the way in. Compiling and linking in -m64. What can I look at in build flags or other to figure out why this is haywire? In the log below, the program is breakpointed inside the function that sees the wrong pointer. It's parent ("up" on the stack) has the correct data:

(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
}

The code:

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)) {

...where m_parser resolves to:

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;
}
}

... Notice how m_parser gets reloaded as the comm protocol moves along.

In answer to the question about stepping into the function: it is broken upon entry to the function, and causes the function to crash soon after. If I hardcode "parseHandshakeMessage() into handleData(), it works correctly. However, I have other examples in this system that rely on function pointers to work correctly. I might post the compile flags, they're redundant and extensive.

  • 2
    Could you post the relevant corresponding C++ code fragment as well? Also, are you sure you have stopped the program at a point the argument is actually initialized? Maybe you need to step over the first line of the callee or something… – The Paramagnetic Croissant Jan 09 '15 at 05:49
  • Producing an [MCVE](http://stackoverflow.com/help/mcve) is the best thing you could do. If you can't make one (i.e. the bug goes away when you remove some code) then that is a strong clue as to where the bug is comign from. – M.M Apr 06 '15 at 23:57

1 Answers1

0

Try compiling everything with "+W2 -xport64".

That might generate a lot of errors/warnings. Ideally your code should be clean of all warnings, especially those generated from "-xport64".

gsamaras
  • 71,951
  • 46
  • 188
  • 305
Andrew Henle
  • 32,625
  • 3
  • 24
  • 56