Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xcode glibstdc++vsnprintf中pthread_setspecific中的Mac OS X端口崩溃-如何排除故障?_Xcode_Macos_Pthreads_Ostringstream_Printf - Fatal编程技术网

Xcode glibstdc++vsnprintf中pthread_setspecific中的Mac OS X端口崩溃-如何排除故障?

Xcode glibstdc++vsnprintf中pthread_setspecific中的Mac OS X端口崩溃-如何排除故障?,xcode,macos,pthreads,ostringstream,printf,Xcode,Macos,Pthreads,Ostringstream,Printf,我正在测试我的多线程服务器的MacOSX端口。它启动,但在工作线程接收第一个客户端请求后不久,它就在vsnprintf中消失 似乎vsnprintf正试图使用pthread_setspecific操作一些线程本地内存。这将取消对错误指针的引用。 然后,gdb捕获一个dlopen调用,得到一个错误,并在尝试格式化自己的错误消息时终止。 因为,要格式化错误,它需要设置一些线程本地内存 在此之前,我自己的代码成功地使用了pthread_create_key、pthread_getspecific和pt

我正在测试我的多线程服务器的MacOSX端口。它启动,但在工作线程接收第一个客户端请求后不久,它就在vsnprintf中消失

似乎vsnprintf正试图使用pthread_setspecific操作一些线程本地内存。这将取消对错误指针的引用。 然后,gdb捕获一个dlopen调用,得到一个错误,并在尝试格式化自己的错误消息时终止。 因为,要格式化错误,它需要设置一些线程本地内存

在此之前,我自己的代码成功地使用了pthread_create_key、pthread_getspecific和pthread_setspecific。我仔细地记录了我自己的访问,我不认为它们会破坏任何东西

是否有可能glibstdc++中的某些静态文件没有及时初始化?我怎么知道

此外,我使用g++-pthread进行编译和链接,但在可执行清单中没有看到libpthread

    otool -L myExecutable

libboost_thread-xgcc40-mt-1_39.dylib (compatibility version 0.0.0, current version 0.0.0)
/Users/eolson//lib/libgsl.0.dylib (compatibility version 14.0.0, current version 14.0.0)
/Users/eolson//lib/libgslcblas.0.dylib (compatibility version 1.0.0, current version 1.0.0)
/Users/eolson/mico-2.3.12/lib/libmico2.3.12.dylib (compatibility version 0.0.0, current version 0.0.0)
/usr/local/lib/libModelsCorba.dylib (compatibility version 1.0.0, current version 1.0.0)
/usr/local/lib/libModelsBigLibrary.dylib (compatibility version 1.0.0, current version 1.0.0)
/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 7.4.0)
/usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 111.1.4)
有人知道如何进一步调试吗

堆栈跟踪:

[Switching to process 37784]
Program received signal:  “EXC_BAD_ACCESS”.
[Switching to process 37784]
sharedlibrary apply-load-rules all
Data Formatters temporarily unavailable, will re-try after a 'continue'. (The program being debugged was signaled while in a function called from GDB.
GDB remains in the frame where the signal was received.
To change this behavior use "set unwindonsignal on"
Evaluation of the expression containing the function (dlopen) will be abandoned.)
(gdb) where

#0  0x9232f03b in pthread_setspecific ()
#1  0x9232efe6 in getPerThreadBufferFor_dlerror ()
#2  0x8fe0b0cd in __dyld_dlopen ()
#3  0x9232ef48 in dlopen ()
#4  <function called from gdb>
#5  0x9232f03b in pthread_setspecific ()
#6  0x9233ed64 in __Balloc_D2A ()
#7  0x9233eb92 in __d2b_D2A ()
#8  0x9233dc5e in __dtoa ()
#9  0x92335975 in __vfprintf ()
#10 0x92355886 in vsnprintf ()
#11 0x96eb526b in std::__convert_from_v ()
#12 0x96eaeb5e in std::num_put<char, std::ostreambuf_iterator<char, std::char_traits<char> > >::_M_insert_float<double> ()
#13 0x96eaedb4 in std::num_put<char, std::ostreambuf_iterator<char, std::char_traits<char> > >::do_put ()
#14 0x96ea9583 in std::num_put<char, std::ostreambuf_iterator<char, std::char_traits<char> > >::put ()
#15 0x96eb79dd in std::ostream::_M_insert<double> ()
#16 0x012db6a8 in MyCode ...
触发崩溃的代码:

std::ostringstream buf;
buf << myObjectWithOutputOperator << endl;
double x = 1;
buf << "x: " << x << endl; // crashes during __vfprintf

编辑:我相信这与ostringstream中带有XCode 3.2调试配置的错误有关。请参见

Mac OS X不使用单独的libpthread。所有pthread函数都在libSystem中:


在没有定义_GLICXX_DEBUG=1的情况下编译是否可以解决问题,正如编辑中链接的问题所建议的那样?

x真的没有设置为值吗?对不起,我只是简化了。是的,坠机前x=1。如果x未初始化,printf将有问题!此外,该代码已经在Linux上部署了一段时间,因此我正在寻找MacOSX特有的陷阱。
$ nm -g /usr/lib/libSystem.dylib | grep ' _pthread_' | wc -l
     113