in reply to [Ceph::RADOS] Help Debugging Inline C

int buf_sz = rados_pool_list(clu,NULL,0); char buf[buf_sz];

With some compilers, that won't assign buf_sz chars to buf. I would expect that, on such compilers, that piece of code would cause an error - and the module would not compile.
However, if it didn't throw a compile-time exception, then you would most likely experience a runtime segfault.

It's safer, IMO, to assign the memory dynamically - something like (UNTESTED):
use Inline C => Config => BUILD_NOISY => 1; __C__ void list_pools_c (rados_t clu) { Inline_Stack_Vars; int buf_sz = rados_pool_list(clu,NULL,0); char *b; int r; Newx(b, buf_sz, char); r = rados_pool_list(clu,b,buf_sz); if (r != buf_sz) { printf("buffer size mismatch: got %d the first time, but %d " "the second.\n", buf_sz, r); } Inline_Stack_Reset; while(1) { if(b[0] == '\0') { Inline_Stack_Done; Safefree(b); break; } Inline_Stack_Push(sv_2mortal(newSVpv(b,0))); b += strlen(b) +1; } }
I've moved the Inline_Stack_Vars to the top as is my usual practice - though I don't think that matters here.
And I've also added the BUILD_NOISY option so that any warnings from the compilation of the C code can be seen. (FAIK, the module might already have turned BUILD_NOISY on, in which case my re-iteration of it can be removed.)
Not sure if any of that will help - if it doesn't you could try inserting printf("Got to A\n"); statements into the C code in order to locate the segfault more precisely.

Cheers,
Rob

Replies are listed 'Best First'.
Re^2: [Ceph::RADOS] Help Debugging Inline C
by three18ti (Monk) on Nov 07, 2013 at 07:29 UTC

    Hey Rob,

    Well... I'm not getting a segfault anymore! :)

    Now it get "Out of memory"...

    root@kitt:~/Ceph-RADOS-0.01# perl testrados2.pl connected Kbytes: 4880394048 Kbytes used: 1327705520 Kbytes avail: 3552688528 Objects: 164563 error(17) in create_pool:File exists create pool this_test_pool success Testing list_pools Out of memory!

    I'm not sure how to enable build_noisy, but this is what my use Inline::C declaration looks like:

    use Inline C => 'DATA', VERSION => '0.01', NAME => 'Ceph::RADOS', LIBS => '-L/usr/lib -lrados', INC => '-I/usr/include/rados', TYPEMAPS => 'lib/Ceph/types', BUILD_NOISY => 1;

    I think that's what you were getting at.

    Anyway, this is a giant stack trace, so I'm not sure if a) any of it's relevant and b) how to share it effectively. (I guess I can just paste it in a code block...)

    also the gdb seession is relatively useless:

    Starting program: /usr/bin/perl testrados2.pl [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so +.1". [New Thread 0x7ffff3901700 (LWP 9280)] [New Thread 0x7ffff298e700 (LWP 9281)] [New Thread 0x7ffff218d700 (LWP 9282)] [New Thread 0x7ffff198c700 (LWP 9283)] [New Thread 0x7ffff118b700 (LWP 9284)] [New Thread 0x7ffff098a700 (LWP 9285)] [New Thread 0x7ffff7fe7700 (LWP 9286)] [New Thread 0x7ffff0189700 (LWP 9289)] [New Thread 0x7fffe3fff700 (LWP 9290)] [New Thread 0x7fffe37fe700 (LWP 9291)] connected Kbytes: 4880394048 Kbytes used: 1327705520 Kbytes avail: 3552688528 Objects: 164563 error(17) in create_pool:File exists create pool this_test_pool success Testing list_pools Out of memory! [Thread 0x7ffff7fe7700 (LWP 9286) exited] [Thread 0x7fffe37fe700 (LWP 9291) exited] [Thread 0x7fffe3fff700 (LWP 9290) exited] [Thread 0x7ffff0189700 (LWP 9289) exited] [Thread 0x7ffff098a700 (LWP 9285) exited] [Thread 0x7ffff118b700 (LWP 9284) exited] [Thread 0x7ffff198c700 (LWP 9283) exited] [Thread 0x7ffff218d700 (LWP 9282) exited] [Thread 0x7ffff298e700 (LWP 9281) exited] [Thread 0x7ffff3901700 (LWP 9280) exited] [Inferior 1 (process 9276) exited with code 01]
    <pThanks for your help! At least I'm getting a different error. We're making progress! :)

      Greetings,
      Thanks for the additional info.

      While still groping in the dark a bit...
      BUILD_NOISY || VERBOSE || DEBUG = 1 || TRUE;
      Just thinking out loud.

      "Out of memory!"
      Any chance you can flush some, or all of this data to disk, and use it there? That would at least prevent memory exhaustion.
      Hmm...

      connected Kbytes: 4880394048 Kbytes used: 1327705520 Kbytes avail: 3552688528 Objects: 164563 error(17) in create_pool:File exists create pool this_test_pool success Testing list_pools Out of memory!
      error(17) in create_pool:File exists Is it possible that File is/has been created too early? This might mean that the buffers/pools are filling up, causing the memory exhaustion. As they are expecting File, which can't be operated on, because it can't be re-created.
      Best guess given the data I have available.

      HTH

      --Chris

      #!/usr/bin/perl -Tw
      use perl::always;
      my $perl_version = (5.12.5);
      print $perl_version;

        Hey Chris

        Thanks for the advice. What does this bit do?

        BUILD_NOISY || VERBOSE || DEBUG = 1 || TRUE

        I was unable to get that to work when pasted in as it sits, adjusting to:

        BUILD_NOISY=> 1, VERBOSE => 1, DEBUG => 1,

        Gives me an error that Verbose and Debug are not valid config directives for Inline::C. A quick check of the Inline documentation confirms this. While I've solved this specific error (see below), I intend to continue working on this module, so if I can enable more verbose error messaging I think it may help down the line.

        Thanks again for your help!