O great Monks— with elation from the last encounter, I have come for more enlightenment.

I seek a means to express a location in a Perl program with more than simply a line number in a file. No doubt you are aware of the Obfuscated Perl and JAPH koans whose mysteries contains several Perl statements on a single line. I have come to believe that mere journeyman programmers are wont to emulate such behavior and sometimes place more than one statement on a line.

I am not so naive to imagine that it easy or likely that, for example, column number information would stored somewhere; although I'd welcome that. Straining my feeble brain, the only other possibility I can come up with is to obtain a COP address by giving a trace location. By trace location, I mean a location that is called in single stepping; or it could be the location the caller was at before making a call. Consider introspecting inside fn when the calling source line looks like:

 fn(); fn(); fn();

Although COP is low-level, perhaps even in the untouchable caste, let me attempt motivate to why even that might be useful for the purpose of obtaining a more detailed understanding of a location inside a program.

Suppose one could figure out the cardinal number of the COP of those that have the same line number and file name. That gives a hint whether the program was situated at towards the first statement or the towards the last statement of the line in question. The first statement is a no brainer. In the presence of conditional code, subsequent COP addresses may be hard.

The second reason why this might be useful is really for a somewhat limited situation. Suppose one were stopped in debugger (or a handler for a profiler, or code coverage analyzer) and the debugged/traced/profiled program was somewhere in multi-statement line. In the case of a debugger, supposed one wanted to set a breakpoint at the same point again. I understand that Perl's breakpoint mechanism works only on a line bases at the level of support from the runtime. However, if one could get a COP address or some other unique identifier for the location of the program — something equivalent to program counter — the debugger could sort out whether the detailed location was obtained if it could query, say, the COP address.

But beggars can't be choosers and perhaps there are other possibilities unimaginable by me. So I seek your wisdom

Respectfully,
   unenlightened


In reply to Identifying a location with finer granularity than a line number by rockyb

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.