根据 Xcode 中的堆栈跟踪,我的程序在此处中断并给出 EXC_BAD_ACCESS:
int main (int argc, const char * argv[]) {
float usd,btc,bid,ask,order_price,possible_price;
DateData * prices = load_prices(); <---
DateData * load_prices(){
FILE * file = fopen("price.dat", "rb"); <---
我确定这与那行代码无关,而是与后面的代码有关。在一个直到稍后才被调用的函数中,有一行代码似乎破坏了程序。当它在执行该行之前从函数返回时,程序没有这个问题,但是如果它应该从该行之后的函数返回,就会出现这个问题。
这行代码是对 OpenCL 的调用。它是否以某种方式破坏了程序?
err = clEnqueueReadBuffer(ocl_data->commands, ocl_data->output, CL_TRUE, 0, sizeof(CombinationResult) * PPO_COMBINATIONS, (*PPO_results)[x] + PPO_COMBINATIONS*(p + 5), 0, NULL, NULL);
PPO_COMBINATIONS 定义为整数宏,PPO_results 的类型为 CombinationResult (*)[3][PPO_COMBINATIONS * 11]。ocl_data->commands 的类型为 cl_command_queue,ocl_data->output 的类型为 cl_mem。err、p 和 x 的类型为 int。
我将 Xcode 与“Apple LLVM Compiler 3.0”一起使用。出于某种原因,“LLVM GCC 4.2”编译器给出了“架构 i386 的格式错误的元数据记录”。
这是使用命令行使用gdb编译运行时的结果:
Matthew-Mitchell:Parrallel BitCoin Trading Algorithm matt$ gcc -g cmain.c -o test -lcurl -framework OpenCL -std=c99 -arch i386
Matthew-Mitchell:Parrallel BitCoin Trading Algorithm matt$ gdb testGNU gdb 6.3.50-20050815 (Apple version gdb-1708) (Mon Aug 15 16:03:10 UTC 2011)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin"...Reading symbols for shared libraries .... done
(gdb) run
Starting program: /Users/matt/Programming/Bit Coin algorithm/Parrallel BitCoin Trading Algorithm/test
Reading symbols for shared libraries .+++.................................................................. done
Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_PROTECTION_FAILURE at address: 0xbea7d7cc
0x00003e9a in main (argc=0, argv=0x1000) at cmain.c:572
572 int main (int argc, const char * argv[]) {
直接在命令行中运行时,程序会立即退出。