C++ LP64 中通过引用更改我的指针值传递.我应该看什么
C++ pass by reference changing pointer values on me in LP64. What should I look at?
我深入到 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"生成的警告。
相关文章:
- 调整大小后指向元素值的指针unordered_map有效?
- 为什么可以将左值传递给"std::async",即使它引用了右值
- 当成员值从指针更改为非指针时,C++常量问题
- C++数据成员:值与指针
- 返回数组中值的指针地址
- 当值传递给C++中的运算符重载函数时会发生什么
- 将值从指针复制到常量对象参数
- 为什么值不同?C++指针
- 具有相同内存地址但具有不同值的指针
- 如何将值从指针永久赋值到变量
- 数组是如何通过引用、值或指针传递C++的?
- 存储指向函数返回值的指针
- 通过嵌套的lambda中的值捕获指针导致Segfault
- 在c#和c函数之间传递值和指针
- 如何将非可变参数值传递给 fmt::format?
- 将 qml 项目值传递给 cpp 后如何与它们进行交互?
- NDK:将文本字段值传递给 c++ 字符串
- 在循环中设置指向 int 值的指针
- 如何判断 std::vector 是否调整了自身大小,以及如何解释指向向量内值的指针不再有效
- 使用指向输出值的指针