V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
deepkolos
V2EX  ›  问与答

[求助]如何 Debug C++ release build 报 Address boundary error, debug build 正常运行的 bug?

  •  
  •   deepkolos · 2022-01-27 18:05:08 +08:00 · 900 次点击
    这是一个创建于 812 天前的主题,其中的信息可能已经有所发展或是发生改变。

    如题 RT

    5 条回复    2022-02-08 14:50:35 +08:00
    SJ2050cn
        1
    SJ2050cn  
       2022-01-27 18:42:03 +08:00 via Android
    这种 release 模式报错,debug 模式没报错我之前遇到过,简单的说就是 debug 模式会默认做一些事情,譬如内存初始化,而 release 不会做这些默认的事情,我当时是发现自己的数组从 1 开始初始化了,好好检查一下自己程序中变量的初始化情况吧。
    ysc3839
        2
    ysc3839  
       2022-01-27 18:55:47 +08:00
    发代码
    BrettD
        3
    BrettD  
       2022-01-27 20:53:59 +08:00 via iPhone   ❤️ 3
    开 Sanitizer 调试测试
    lixile
        4
    lixile  
       2022-01-28 10:16:41 +08:00
    方向太多了
    1 、编译选项不一样会导致有不同的机器码
    2 、debug 和 release 在代码内部编译宏差异
    3 、dgb 也能稍微调一点没有 strip 过的 release 版本
    deepkolos
        5
    deepkolos  
    OP
       2022-02-08 14:50:35 +08:00
    @ysc3839 定位的是一个 union 导致

    ```cpp
    struct Matrix4 {
    union {
    float elements[16] {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1};
    struct {
    float m0; float m1; float m2; float m3;
    float m4; float m5; float m6; float m7;
    float m8; float m9; float m10; float m11;
    float m12; float m13; float m14; float m15;
    };
    struct {
    float col0[4];
    float col1[4];
    float col2[4];
    float col3[4];
    };
    // 定位到是这里, 把这个删除就可以了...
    struct {
    _m128 simd_t[4];
    };
    };

    // 方法省略了
    }
    ```
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5153 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 08:18 · PVG 16:18 · LAX 01:18 · JFK 04:18
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.