unsigned char *buf;
|
|
|
|
malloc returns a void *. to use it needs a cast. |
You don't need, nor is it advised, to cast the return value from malloc() when using a C compiler as that cast can mask serious issues. |
(gdb) run 1048576 Starting program: /root/phung/dpoverlay/fifo 1048576 [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib/arm-linux-gnueabihf/libthread_db.so.1". [New Thread 0xb6bcd470 (LWP 4995)] [New Thread 0xb63cd470 (LWP 4996)] [Thread 0xb6bcd470 (LWP 4995) exited] [New Thread 0xb5bcd470 (LWP 4997)] [Thread 0xb63cd470 (LWP 4996) exited] 18.000000 [Thread 0xb5bcd470 (LWP 4997) exited] read, 1048576 written Program received signal SIGSEGV, Segmentation fault. 0x00009466 in main (argc=2, argv=0xbefff7a4) at fifo.c:459 459 if( array_input[i] != array_hardware[i] ){ (gdb) print i $1 = 0 (gdb) print array_input[i] Cannot access memory at address 0xb6ed0008 (gdb) run 32 The program being debugged has been started already. Start it from the beginning? (y or n) y Starting program: /root/phung/dpoverlay/fifo 32 [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib/arm-linux-gnueabihf/libthread_db.so.1". [New Thread 0xb6ed0470 (LWP 4999)] [Thread 0xb6ed0470 (LWP 4999) exited] [New Thread 0xb66d0470 (LWP 5000)] [New Thread 0xb5ed0470 (LWP 5001)] 147.000000 [Thread 0xb66d0470 (LWP 5000) exited] Test is successful!! [Thread 0xb5ed0470 (LWP 5001) exited] [Inferior 1 (process 4998) exited normally] (gdb) |
phung@UbuntuHW15:~/Documents/fpga_overlay/xillybus_demoapps$ gcc -g fifo_testcase.c -o fifo_testcase phung@UbuntuHW15:~/Documents/fpga_overlay/xillybus_demoapps$ ./fifo_testcase Segmentation fault (core dumped) phung@UbuntuHW15:~/Documents/fpga_overlay/xillybus_demoapps$ gdb GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.5) 7.11.1 Copyright (C) 2016 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-linux-gnu". Type "show configuration" for configuration details. For bug reporting instructions, please see: <http://www.gnu.org/software/gdb/bugs/>. Find the GDB manual and other documentation resources online at: <http://www.gnu.org/software/gdb/documentation/>. For help, type "help". Type "apropos word" to search for commands related to "word". (gdb) file fifo_testcase Reading symbols from fifo_testcase...done. (gdb) run Starting program: /home/phung/Documents/fpga_overlay/xillybus_demoapps/fifo_testcase Program received signal SIGSEGV, Segmentation fault. 0x00000000004004fe in main () at fifo_testcase.c:20 20 array_input[i] = i; (gdb) print i $1 = 0 (gdb) print array_input[i] Cannot access memory at address 0x0 (gdb) |
|
|