You can, but manually inserting that kind of info every time gets old. That's why it's worth the initial trouble to set it up so that contextual information gets inserted automatically.
package MyFoo; use strict; use warnings; use Inline C => Config => BUILD_NOISY => 1; use Inline C => <<'EOC'; #line 9 "die_in_context.plx" #define MY_PACKAGE "MyFoo" #define kick_bucket(...) \ do_kick_bucket(__FILE__, __LINE__, MY_PACKAGE, __func__, __VA_ARGS +__) void do_kick_bucket(const char *file, I32 line, const char *package, const char *func, const char *pat, ...) { va_list args; SV *error_sv = newSVpvn("", 0); va_start(args, pat); sv_vcatpvf(error_sv, pat, &args); va_end(args); sv_catpvf(error_sv, " at function %s::%s at %s line %d\n", package, func, file, line); die(SvPVX(error_sv)); } void foo() { kick_bucket("Bad Juju"); } EOC MyFoo::foo(); __END__ Outputs: Bad Juju at function MyFoo::foo at die_in_context.plx line 30

The package in XS functions you ordinarily get for free, because it's part of the function name and thus gets picked up by the __func__ macro. For example when I insert a call to my Confess macro into KinoSearch::Store::InStream::new, the stack trace starts like this...

Error in function XS_KinoSearch__Store__InStream_new at lib/KinoSearch +.xs:1742: Kill me now

__VA_ARGS__ and __func__ are C99, though, so if you need portability you have to probe for them at build time and set up alternatives for when they aren't available.

--
Marvin Humphrey
Rectangular Research ― http://www.rectangular.com

In reply to Re^2: Output package and function name as well as linenum in a die in XS by creamygoodness
in thread Output package and function name as well as linenum in a die in XS by tbusch

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.