Hello,

the main problem with your code is the declaration of the array which
should be an array of void pointers:
        void*[] array = new void*[10];

Here a snippet that works, but the are some other problems with the
bindings:

1) The length of strings can't be known by vala and foreach wouldn't work
2) The strings is not freed because is declared as unowned.


private static void print_backtrace () {
        void*[] array = new void*[10];

        int size = Linux.backtrace (array, 10);

        string[] strings = Linux.backtrace_symbols (array, size);
        for(int i=0; i< size; i++) {
                print ("(%d): %s\n", i, strings[i]);
        }

        /* this can't work because the array length in unknown by vala
        foreach (string trace in strings) {
            stdout.printf("%s\n", trace);
        }*/
}

HTH,
Andrea



On Wed, Nov 27, 2013 at 11:27 PM, Christian Johnson <[email protected]> wrote:

> Hey!
>
> I'm trying to print out stacktrace, Linux.backtrace and
> Linux.backtrace_symbols look like they would work but them being part of
> libc I can't seam to discover how to use them from vala. The GNU manual has
> this example:
>
> void *array[10];
> size_t size;
> char **strings;
> size_t i;
>
> size = backtrace (array, 10);
> strings = backtrace_symbols (array, size);
>
> printf ("Obtained %zd stack frames.\n", size);
>
> for (i = 0; i < size; i++)
>      printf ("%s\n", strings[i]);
>
> free (strings);
>
> So trying to convert this to vala:
>
> void[] array = new void[10];
> int size = Linux.backtrace (&array, 10);
> string[] strings = Linux.backtrace_symbols (array, size);
>
> foreach (string trace in strings) {
>     stdout.printf("%s\n", trace);
> }
>
> This produces the fallow error:
> *** Error in `valac': munmap_chunk(): invalid pointer: 0xb76d1069 ***
>
>
> So...What am I doing wrong?
>
> _______________________________________________
> vala-list mailing list
> [email protected]
> https://mail.gnome.org/mailman/listinfo/vala-list
>
_______________________________________________
vala-list mailing list
[email protected]
https://mail.gnome.org/mailman/listinfo/vala-list

Reply via email to