这是一篇相当复杂的帖子。我有一个简单的应用程序在Haxe制作。这个应用程序正在被hxcpp转换为C ++,这是一个自动化工具,用于通过将Haxe代码转换为C ++来在不同系统上编译和部署应用程序。
这个相同的应用程序,在为Windows或Linux编译时工作正常。 为OSX编译时,它会从系统库中抛出错误。
有一段很长的thread about it on GitHub。
总结是由于某种原因我无法理解,将结构序列化为字符串的代码(它是一个递归函数)正在使snprintf()抛出异常而没有明显的原因。
堆栈跟踪如下:
MBP-di-Valerio:test-snow-empty tanis$ lldb bin/mac64/snow_empty.app/Contents/MacOS/snow_empty
(lldb) target create "bin/mac64/snow_empty.app/Contents/MacOS/snow_empty"
Current executable set to 'bin/mac64/snow_empty.app/Contents/MacOS/snow_empty' (x86_64).
(lldb) run
Process 9216 launched: '/Users/tanis/Documents/test-snow-empty/bin/mac64/snow_empty.app/Contents/MacOS/snow_empty' (x86_64)
Debugger:Starting App side debugger support.
Debugger:Connected to debugging server at localhost:6972.
Process 9216 stopped
* thread #2: tid = 0xee65, 0x00007fff96d94d6d libsystem_c.dylib`_vsnprintf + 20, stop reason = EXC_BAD_ACCESS (code=2, address=0x102100f68)
frame #0: 0x00007fff96d94d6d libsystem_c.dylib`_vsnprintf + 20
libsystem_c.dylib`_vsnprintf:
-> 0x7fff96d94d6d <+20>: movq %r9, -0x1e8(%rbp)
0x7fff96d94d74 <+27>: movq %r8, %r15
0x7fff96d94d77 <+30>: movq %rcx, %rbx
0x7fff96d94d7a <+33>: movq %rdx, %r14
(lldb) bt
warning: could not load any Objective-C class information. This will significantly reduce the quality of type information available.
* thread #2: tid = 0xee65, 0x00007fff96d94d6d libsystem_c.dylib`_vsnprintf + 20, stop reason = EXC_BAD_ACCESS (code=2, address=0x102100f68)
* frame #0: 0x00007fff96d94d6d libsystem_c.dylib`_vsnprintf + 20
frame #1: 0x00007fff96d9500c libsystem_c.dylib`vsnprintf_l + 41
frame #2: 0x00007fff96d853b2 libsystem_c.dylib`snprintf + 188
frame #3: 0x000000010041da73 snow_empty`String::String(this=0x00000001021014c0, inRHS=0x0000000100d3710c) + 83 at String.cpp:311
frame #4: 0x000000010041dbcd snow_empty`String::String(this=0x00000001021014c0, inRHS=0x0000000100d3710c) + 29 at String.cpp:309
frame #5: 0x0000000100417aa3 snow_empty`hx::IntData::toString(this=0x0000000100d37104) + 35 at Dynamic.cpp:55
frame #6: 0x000000010036b779 snow_empty`Std_obj::string(s=Dynamic @ 0x00000001021014b8) + 361 at Std.cpp:67
frame #7: 0x000000010036a0fb snow_empty`StringBuf_obj::add(this=0x0000000100e40a18, x=Dynamic @ 0x0000000102101690) + 315 at StringBuf.cpp:44
frame #8: 0x00000001002ac50a snow_empty`haxe::Serializer_obj::serializeString(this=0x0000000100e409ec, s=(length = 20, __s = "snow%2Fapi%2FLibs.hx")) + 1530 at Serializer.cpp:123
frame #9: 0x00000001002ae8a9 snow_empty`haxe::Serializer_obj::serialize(this=0x0000000100e409ec, v=Dynamic @ 0x0000000102104958) + 4409 at Serializer.cpp:300
frame #10: 0x00000001002b5ef0 snow_empty`haxe::Serializer_obj::serialize(this=0x0000000100e409ec, v=Dynamic @ 0x0000000102107128) + 34688 at Serializer.cpp:796
frame #11: 0x00000001002b5ef0 snow_empty`haxe::Serializer_obj::serialize(this=0x0000000100e409ec, v=Dynamic @ 0x00000001021098f8) + 34688 at Serializer.cpp:796
frame #12: 0x00000001002b5ef0 snow_empty`haxe::Serializer_obj::serialize(this=0x0000000100e409ec, v=Dynamic @ 0x000000010210c0c8) + 34688 at Serializer.cpp:796
frame #13: 0x00000001002b5ef0 snow_empty`haxe::Serializer_obj::serialize(this=0x0000000100e409ec, v=Dynamic @ 0x000000010210e898) + 34688 at Serializer.cpp:796
frame #14: 0x00000001002b5ef0 snow_empty`haxe::Serializer_obj::serialize(this=0x0000000100e409ec, v=Dynamic @ 0x0000000102111068) + 34688 at Serializer.cpp:796
frame #15: 0x00000001002b5ef0 snow_empty`haxe::Serializer_obj::serialize(this=0x0000000100e409ec, v=Dynamic @ 0x0000000102113838) + 34688 at Serializer.cpp:796
frame #16: 0x00000001002b5ef0 snow_empty`haxe::Serializer_obj::serialize(this=0x0000000100e409ec, v=Dynamic @ 0x0000000102116008) + 34688 at Serializer.cpp:796
frame #17: 0x00000001002b5ef0 snow_empty`haxe::Serializer_obj::serialize(this=0x0000000100e409ec, v=Dynamic @ 0x00000001021187d8) + 34688 at Serializer.cpp:796
frame #18: 0x00000001002b5ef0 snow_empty`haxe::Serializer_obj::serialize(this=0x0000000100e409ec, v=Dynamic @ 0x000000010211afa8) + 34688 at Serializer.cpp:796
frame #19: 0x00000001002b5ef0 snow_empty`haxe::Serializer_obj::serialize(this=0x0000000100e409ec, v=Dynamic @ 0x000000010211d778) + 34688 at Serializer.cpp:796
frame #20: 0x00000001002b5ef0 snow_empty`haxe::Serializer_obj::serialize(this=0x0000000100e409ec, v=Dynamic @ 0x000000010211ff48) + 34688 at Serializer.cpp:796
frame #21: 0x00000001002b5ef0 snow_empty`haxe::Serializer_obj::serialize(this=0x0000000100e409ec, v=Dynamic @ 0x0000000102122718) + 34688 at Serializer.cpp:796
frame #22: 0x00000001002b5ef0 snow_empty`haxe::Serializer_obj::serialize(this=0x0000000100e409ec, v=Dynamic @ 0x0000000102124ee8) + 34688 at Serializer.cpp:796
frame #23: 0x00000001002b5ef0 snow_empty`haxe::Serializer_obj::serialize(this=0x0000000100e409ec, v=Dynamic @ 0x00000001021276b8) + 34688 at Serializer.cpp:796
frame #24: 0x00000001002b5ef0 snow_empty`haxe::Serializer_obj::serialize(this=0x0000000100e409ec, v=Dynamic @ 0x0000000102129e88) + 34688 at Serializer.cpp:796
frame #25: 0x00000001002b5ef0 snow_empty`haxe::Serializer_obj::serialize(this=0x0000000100e409ec, v=Dynamic @ 0x000000010212c658) + 34688 at Serializer.cpp:796
frame #26: 0x00000001002b5ef0 snow_empty`haxe::Serializer_obj::serialize(this=0x0000000100e409ec, v=Dynamic @ 0x000000010212ee28) + 34688 at Serializer.cpp:796
frame #27: 0x00000001002b5ef0 snow_empty`haxe::Serializer_obj::serialize(this=0x0000000100e409ec, v=Dynamic @ 0x00000001021315f8) + 34688 at Serializer.cpp:796
frame #28: 0x00000001002b5ef0 snow_empty`haxe::Serializer_obj::serialize(this=0x0000000100e409ec, v=Dynamic @ 0x0000000102133dc8) + 34688 at Serializer.cpp:796
frame #29: 0x00000001002b5ef0 snow_empty`haxe::Serializer_obj::serialize(this=0x0000000100e409ec, v=Dynamic @ 0x0000000102136598) + 34688 at Serializer.cpp:796
frame #30: 0x00000001002b5ef0 snow_empty`haxe::Serializer_obj::serialize(this=0x0000000100e409ec, v=Dynamic @ 0x0000000102138d68) + 34688 at Serializer.cpp:796
frame #31: 0x00000001002b5ef0 snow_empty`haxe::Serializer_obj::serialize(this=0x0000000100e409ec, v=Dynamic @ 0x000000010213b538) + 34688 at Serializer.cpp:796
frame #32: 0x00000001002b5ef0 snow_empty`haxe::Serializer_obj::serialize(this=0x0000000100e409ec, v=Dynamic @ 0x000000010213dd08) + 34688 at Serializer.cpp:796
frame #33: 0x00000001002b5ef0 snow_empty`haxe::Serializer_obj::serialize(this=0x0000000100e409ec, v=Dynamic @ 0x00000001021404d8) + 34688 at Serializer.cpp:796
frame #34: 0x00000001002b5ef0 snow_empty`haxe::Serializer_obj::serialize(this=0x0000000100e409ec, v=Dynamic @ 0x0000000102142ca8) + 34688 at Serializer.cpp:796
frame #35: 0x00000001002b5ef0 snow_empty`haxe::Serializer_obj::serialize(this=0x0000000100e409ec, v=Dynamic @ 0x0000000102145478) + 34688 at Serializer.cpp:796
frame #36: 0x00000001002b5ef0 snow_empty`haxe::Serializer_obj::serialize(this=0x0000000100e409ec, v=Dynamic @ 0x0000000102147c48) + 34688 at Serializer.cpp:796
frame #37: 0x00000001002b5ef0 snow_empty`haxe::Serializer_obj::serialize(this=0x0000000100e409ec, v=Dynamic @ 0x000000010214a418) + 34688 at Serializer.cpp:796
frame #38: 0x00000001002b5ef0 snow_empty`haxe::Serializer_obj::serialize(this=0x0000000100e409ec, v=Dynamic @ 0x000000010214cbe8) + 34688 at Serializer.cpp:796
frame #39: 0x00000001002b5ef0 snow_empty`haxe::Serializer_obj::serialize(this=0x0000000100e409ec, v=Dynamic @ 0x000000010214f3b8) + 34688 at Serializer.cpp:796
frame #40: 0x00000001002b5ef0 snow_empty`haxe::Serializer_obj::serialize(this=0x0000000100e409ec, v=Dynamic @ 0x0000000102151b88) + 34688 at Serializer.cpp:796
frame #41: 0x00000001002b5ef0 snow_empty`haxe::Serializer_obj::serialize(this=0x0000000100e409ec, v=Dynamic @ 0x0000000102154358) + 34688 at Serializer.cpp:796
frame #42: 0x00000001002b5ef0 snow_empty`haxe::Serializer_obj::serialize(this=0x0000000100e409ec, v=Dynamic @ 0x0000000102156b28) + 34688 at Serializer.cpp:796
frame #43: 0x00000001002b5ef0 snow_empty`haxe::Serializer_obj::serialize(this=0x0000000100e409ec, v=Dynamic @ 0x00000001021592f8) + 34688 at Serializer.cpp:796
frame #44: 0x00000001002b5ef0 snow_empty`haxe::Serializer_obj::serialize(this=0x0000000100e409ec, v=Dynamic @ 0x000000010215bac8) + 34688 at Serializer.cpp:796
frame #45: 0x00000001002b5ef0 snow_empty`haxe::Serializer_obj::serialize(this=0x0000000100e409ec, v=Dynamic @ 0x000000010215e298) + 34688 at Serializer.cpp:796
frame #46: 0x00000001002b5ef0 snow_empty`haxe::Serializer_obj::serialize(this=0x0000000100e409ec, v=Dynamic @ 0x0000000102160a68) + 34688 at Serializer.cpp:796
frame #47: 0x00000001002b5ef0 snow_empty`haxe::Serializer_obj::serialize(this=0x0000000100e409ec, v=Dynamic @ 0x0000000102163238) + 34688 at Serializer.cpp:796
frame #48: 0x00000001002b5ef0 snow_empty`haxe::Serializer_obj::serialize(this=0x0000000100e409ec, v=Dynamic @ 0x0000000102165a08) + 34688 at Serializer.cpp:796
frame #49: 0x00000001002b5ef0 snow_empty`haxe::Serializer_obj::serialize(this=0x0000000100e409ec, v=Dynamic @ 0x00000001021681d8) + 34688 at Serializer.cpp:796
frame #50: 0x00000001002b5ef0 snow_empty`haxe::Serializer_obj::serialize(this=0x0000000100e409ec, v=Dynamic @ 0x000000010216a9a8) + 34688 at Serializer.cpp:796
frame #51: 0x00000001002b5ef0 snow_empty`haxe::Serializer_obj::serialize(this=0x0000000100e409ec, v=Dynamic @ 0x000000010216d178) + 34688 at Serializer.cpp:796
frame #52: 0x00000001002b5ef0 snow_empty`haxe::Serializer_obj::serialize(this=0x0000000100e409ec, v=Dynamic @ 0x000000010216f948) + 34688 at Serializer.cpp:796
frame #53: 0x00000001002b5ef0 snow_empty`haxe::Serializer_obj::serialize(this=0x0000000100e409ec, v=Dynamic @ 0x0000000102172118) + 34688 at Serializer.cpp:796
frame #54: 0x00000001002b5ef0 snow_empty`haxe::Serializer_obj::serialize(this=0x0000000100e409ec, v=Dynamic @ 0x00000001021748e8) + 34688 at Serializer.cpp:796
frame #55: 0x00000001002b5ef0 snow_empty`haxe::Serializer_obj::serialize(this=0x0000000100e409ec, v=Dynamic @ 0x00000001021770b8) + 34688 at Serializer.cpp:796
frame #56: 0x00000001002b5ef0 snow_empty`haxe::Serializer_obj::serialize(this=0x0000000100e409ec, v=Dynamic @ 0x0000000102179888) + 34688 at Serializer.cpp:796
frame #57: 0x00000001002b5ef0 snow_empty`haxe::Serializer_obj::serialize(this=0x0000000100e409ec, v=Dynamic @ 0x000000010217c058) + 34688 at Serializer.cpp:796
frame #58: 0x00000001002b5ef0 snow_empty`haxe::Serializer_obj::serialize(this=0x0000000100e409ec, v=Dynamic @ 0x000000010217e828) + 34688 at Serializer.cpp:796
frame #59: 0x00000001002b5ef0 snow_empty`haxe::Serializer_obj::serialize(this=0x0000000100e409ec, v=Dynamic @ 0x0000000102180710) + 34688 at Serializer.cpp:796
frame #60: 0x00000001002b6747 snow_empty`haxe::Serializer_obj::run(v=Dynamic @ 0x0000000102180980) + 423 at Serializer.cpp:842
frame #61: 0x00000001002e4f30 snow_empty`debugger::HaxeProtocol_obj::writeDynamic(output=(mPtr = 0x0000000100e36cd0), value=Dynamic @ 0x0000000102180a98) + 304 at HaxeProtocol.cpp:237
frame #62: 0x00000001002e56e4 snow_empty`debugger::HaxeProtocol_obj::writeMessage(output=(mPtr = 0x0000000100e36cd0), message=debugger::Message @ 0x0000000102180cb0) + 340 at HaxeProtocol.cpp:148
frame #63: 0x00000001002df947 snow_empty`debugger::HaxeRemote_obj::writeThreadLoop(this=0x0000000100e36be8) + 759 at HaxeRemote.cpp:233
frame #64: 0x00000001002e1a09 snow_empty`debugger::HaxeRemote_obj::__construct(this=0x0000000100e36fc8)::_Function_1_1::run() + 217 at HaxeRemote.cpp:75
frame #65: 0x00000001002e18f3 snow_empty`debugger::HaxeRemote_obj::__construct(this=0x0000000100e36fc8)::_Function_1_1::__run() + 35 at HaxeRemote.cpp:79
frame #66: 0x00000001003eb018 snow_empty`hxThreadFunc(inInfo=0x0000000100e36fdc) + 184 at Thread.cpp:255
frame #67: 0x00007fff8dbac05a libsystem_pthread.dylib`_pthread_body + 131
frame #68: 0x00007fff8dbabfd7 libsystem_pthread.dylib`_pthread_start + 176
frame #69: 0x00007fff8dba93ed libsystem_pthread.dylib`thread_start + 13
(lldb)
我尝试检查变量,因为调用snprintf()的函数归结为:
typedef char buf[100];
snprintf(buf, 100, "%d", 12);
其中12
只是传递给函数的int(它是序列化的字符串的长度)
由于OSX上的snprintf在内部使用了vsnprintf,我甚至冒险在我自己的代码中重写,只是为了检查传递了什么参数以及它们是否正常:
int String::snprintf(char *str,size_t count,const char *fmt,...)
{
va_list ap;
va_start(ap, fmt);
(void) vsnprintf(str, count, fmt, ap);
va_end(ap);
return(strlen(str));
}
事实上一切似乎都很好。但它仍然在内部libsystem_c.dylib
_ vsnprintf`崩溃。
我真的无法理解发生了什么,为什么会发生在OSX而不是其他系统上。
This is the original offending code。我愿意接受任何建议,试图缩小这个问题。