|Welcome to the Monastery|
Identifying a location with finer granularity than a line numberby rockyb (Scribe)
|on Aug 14, 2012 at 05:51 UTC||Need Help??|
rockyb has asked for the
wisdom of the Perl Monks concerning the following question:
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