Crash on function call in Android NDK
I am developing an Android based project that requires some components to run via the NDK because I'm using code already written in C. I am having a very weird problem where the program crashes when calling a specific function:
numin_read(ns,values+data_spec->N_inputs*i+j0);
ns is a pointer to a struct and values is a pointer to a double array, the rest is just an integer offset, all of which are valid (ns has been used already by the time this function is called and the malloc call is checked for a NULL-pointer). The function is located in another *.c file (numin.c) and the declaration of it (in numin.h) is
void numin_read (numin_source *, double *);
It isn't even the first time the program calls a function from numin.c but the only one that crashes. I know it's not something in the function that's causing the crash because it still does it if I return in the first line.
I'm struggling to get the debugger to attach to the program (despite doing everything described here) so I really have no idea what's going on in there. Anybody have any idea why this isn't working? I've used this code on Linux and it works fine.
Sorry if there's very little to go on, will keep trying to get the debugger to attach so I can give more details. Please let me know what other info you need.
Edit: I don't know if this makes a difference but in order to build the program, I compile each of the individual c files into a series of object files (using the NDK standalone toolchain), archive these object files into an ar archive and then call upon this as a PREBUILT_STA开发者_开发百科TIC_LIBRARY when making the main c file into the shared library that I call via the NDK...
Edit: This is beyond weird. I changed the definition of numin_read to void numin_read()
and commented out all the code except for a single return statement. Essentially I'm calling a function that takes in no parameters and just returns... and it still crashes!
I did manage to get something out of LogCat though: signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 00000004
As far as I understand it has to do with memory allocation? But I'm not malloc-ing, I'm calling a just function... What am I missing?
The expression
values+data_spec->N_inputs*i+j0
is the same as
values[data_spec->N_inputs * i + j0]
I suspect you try to access an element you don't really have access to ... or maybe an uninitialized element.
Not my brightest moment ever, the .h files that I was using to build the final NDK shared library were not symlinks to the original .h files that I was using to build the object files. This meant that any changes I made to those weren't being propagated through... still have to check that everything's now fine but sorry for wasting your time...
精彩评论