QtCreator提示ptrace不允许的操作

os : ubuntu 12.04 qt : qt4.8.4

sudo vi /etc/sysctl.d/10-ptrace.conf
kernel.yama.ptrace_scope = 0

Linux coredump 调试

os : ubuntu 12.04

开启coredump:

ulimit -c 1024

g++ 添加编译参数:

 g++ -g -ggdb 

执行程序,crash后会在项目文件夹中生成core文件,使用core文件调试:

 gdb --core=core

接下来就是常规gdb调试, 如需要导入源代码,在gdb中执行:

 file <程序名> 

QT token is not a valid bin

修改 Qt5.0.1/5.0.1/clang_64/include/QtCore/qisenum.h 如下:

     42#include <QtCore/qglobal.h>
     43 
     44 #ifndef QISENUM_H
     45 #define QISENUM_H
     46 
     47 #ifndef Q_IS_ENUM   
     48 #  if defined(Q_CC_GNU) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)) 
     49 #    define Q_IS_ENUM(x) __is_enum(x)   
     50 #  elif defined(Q_CC_MSVC) && defined(_MSC_FULL_VER) && (_MSC_FULL_VER >=140050215) 
     51 #    define Q_IS_ENUM(x) __is_enum(x)   
     52 #  else
     53 #    include <QtCore/qtypetraits.h> 
     54 #    define Q_IS_ENUM(x) QtPrivate::is_enum<x>::value   
     55 #  endif    
     56 #endif

cpp中delete数组

例1:

#include <iostream>
using namespace std;
class A {
public:
   A() { cout << "constructor" << endl; }
   ~A() { cout << "desconstructor" << endl; }
};

int main() {
   A* p = new A[3] ;
   delete[] p;
}

输出:

constructor constructor constructor desconstructor desconstructor desconstructor

结论:正确释放内存。

例2:

    #include <iostream>

    using namespace std;

    class A { 
    public:
        A() { cout << "constructor" << endl; }
        ~A() { cout << "desconstructor" << endl; }
    };

    int main() {
        A** p = new A*[3] ;
        for(int i = 0; i < 3; i++)
          p[i] = new A;

        delete[] p;
    }

输出:

constructor constructor constructor

结论:没有如想象正确调用虚构函数

例3:

    #include <iostream>

    using namespace std;

    class A { 
    public:
        A() { cout << "constructor" << endl; }
        ~A() { cout << "desconstructor" << endl; }
    };

    int main() {
        A** p = new A*[3] ;
        for(int i = 0; i < 3; i++)
          p[i] = new A;
        for(int i = 0; i < 3; i++)
          delete p[i];

        delete[] p;
    }

输出:

constructor constructor constructor desconstructor desconstructor desconstructor

结论:正确调用虚构函数

MacOS使用ZThread错误 lazy symbol binding failed

OS: macos

使用编译命令:

g++ -Wall -g -o a a.cpp  -lzthread

编译顺利通过,运行时出现如下报错:

dyld: lazy symbol binding failed: Symbol not found: _MPCreateCriticalRegion Referenced from: /usr/local/lib/libZThread-2.3.2.dylib Expected in: flat namespace

dyld: Symbol not found: _MPCreateCriticalRegion Referenced from: /usr/local/lib/libZThread-2.3.2.dylib Expected in: flat namespace

Trace/BPT trap: 5

解决方法: 需要在编译时加入carbon framework:

g++ -Wall -g -o a a.cpp -framework Carbon -lzthread