Tcl Source Code

Check-in [ffd6477611]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Better conform to Tcl style guidelines.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | bug-3485833
Files: files | file ages | folders
SHA1: ffd647761102c991229b23502e46480d6d79ece9
User & Date: dgp 2012-03-05 20:47:18
Context
2012-03-07
15:40
experimental trying to use TclGetSrcInfoForCmd without special sentinel ENSEMBLE_PSEUDO_COMMAND check-in: 0331a1cb8f user: sebres tags: bug-3485833
2012-03-05
20:47
Better conform to Tcl style guidelines. check-in: ffd6477611 user: dgp tags: bug-3485833
19:11
Backdoor kludge to let traced ensemble subcommands gain access to the string command of the original... check-in: a96d145418 user: dgp tags: bug-3485833
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to generic/tclBasic.c.

3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011




3012
3013
3014
3015
3016
3017
3018
 *----------------------------------------------------------------------
 *
 * GetCommandSource --
 *
 *	This function returns a Tcl_Obj with the full source string for the
 *	command. This insures that traces get a correct NUL-terminated command
 *	string.
 *	If parameter 'command' is (char*)-1 it returns a pointer to the command's 
 *	source using TclGetSrcInfoForCmd. As parameter 'numChars' could be used 
 *	an ENSEMBLE_PSEUDO_COMMAND to advise call of the ensemble command.
 *




 *----------------------------------------------------------------------
 */

static Tcl_Obj *
GetCommandSource(
    Interp *iPtr,
    const char *command,







<
<
<

>
>
>
>







3001
3002
3003
3004
3005
3006
3007



3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
 *----------------------------------------------------------------------
 *
 * GetCommandSource --
 *
 *	This function returns a Tcl_Obj with the full source string for the
 *	command. This insures that traces get a correct NUL-terminated command
 *	string.



 *
 *	If 'command' has value (char*)-1, this function calls
 *	TclGetSrcInfoForCmd() to obtain the source string.  This is used
 *	to retrieve suitable source strings for bytecode exection and
 *	ensemble subcommand dispatch.
 *----------------------------------------------------------------------
 */

static Tcl_Obj *
GetCommandSource(
    Interp *iPtr,
    const char *command,
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
				 * the words that make up the command. */
    const char *command,	/* Points to the beginning of the string
				 * representation of the command; this is used
				 * for traces. NULL if the string
				 * representation of the command is unknown is
				 * to be generated from (objc,objv), -1 if it
				 * is to be generated from bytecode source,
				 * with length ENSEMBLE_PSEUDO_COMMAND it is 
				 * to be determined from the ensemble context. 
				 * This is only needed the traces. */
    int length,			/* Number of bytes in command; if -1, all
				 * characters up to the first null byte are
				 * used. */
    int flags)			/* Collection of OR-ed bits that control the
				 * evaluation of the script. Only
				 * TCL_EVAL_GLOBAL and TCL_EVAL_INVOKE are







|
|







3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
				 * the words that make up the command. */
    const char *command,	/* Points to the beginning of the string
				 * representation of the command; this is used
				 * for traces. NULL if the string
				 * representation of the command is unknown is
				 * to be generated from (objc,objv), -1 if it
				 * is to be generated from bytecode source,
				 * or, when length is ENSEMBLE_PSEUDO_COMMAND,
				 * determined from the ensemble context. 
				 * This is only needed the traces. */
    int length,			/* Number of bytes in command; if -1, all
				 * characters up to the first null byte are
				 * used. */
    int flags)			/* Collection of OR-ed bits that control the
				 * evaluation of the script. Only
				 * TCL_EVAL_GLOBAL and TCL_EVAL_INVOKE are

Changes to generic/tclExecute.c.

7753
7754
7755
7756
7757
7758
7759

7760
7761
7762
7763
7764
7765
7766
7767
7768
7769
7770
7771
7772
7773
7774
7775
7776
7777
7778
7779
7780

7781
7782
7783
7784
7785

7786
7787
7788
7789
7790
7791
7792
7793
7794
7795

7796
7797
7798
7799
7800
7801
7802
7803
7804
7805

7806
7807
7808
7809
7810
7811
7812
 * Results:
 *	If a command is found that encloses the program counter value, a
 *	pointer to the command's source is returned and the length of the
 *	source is stored at *lengthPtr. If multiple commands resulted in code
 *	at pc, information about the closest enclosing command is returned. If
 *	no matching command is found, NULL is returned and *lengthPtr is
 *	unchanged.

 *	As input parameter '*lengthPtr' could be used an ENSEMBLE_PSEUDO_COMMAND 
 *	to advise call of the ensemble command.
 *
 * Side effects:
 *	The CmdFrame at *cfPtr is updated.
 *
 *----------------------------------------------------------------------
 */

const char *
TclGetSrcInfoForCmd(
    Interp *iPtr,
    int *lenPtr)
{
    CmdFrame *cfPtr = iPtr->cmdFramePtr;
    const char *command;
    ByteCode *codePtr;
    int len;

    if (!cfPtr)
	return NULL;

    codePtr = (ByteCode *) cfPtr->data.tebc.codePtr;
    if (!codePtr)
	return NULL;
    if (!cfPtr->data.tebc.pc)
	return NULL;


    command = GetSrcInfoForPc((unsigned char *) cfPtr->data.tebc.pc,
	    codePtr, &len);

    /*
     * [sebres]: If ensemble call (sentinel length == ENSEMBLE_PSEUDO_COMMAND), 
     * shift string ptr to subcommand (string range -> range).
     */

    if (command && len && (lenPtr && *lenPtr == ENSEMBLE_PSEUDO_COMMAND) && codePtr->objArrayPtr) {

	Tcl_Obj *objPtr = codePtr->objArrayPtr[0];

	if (len > objPtr->length) {
	    command += objPtr->length + 1;
	    len -= objPtr->length + 1;
	}
    }

    if (lenPtr != NULL)
	*lenPtr = len;

    return command;
}

void
TclGetSrcInfoForPc(
    CmdFrame *cfPtr)
{







>
|
|

















|

>

|

<
<
>









|
>








|

>







7753
7754
7755
7756
7757
7758
7759
7760
7761
7762
7763
7764
7765
7766
7767
7768
7769
7770
7771
7772
7773
7774
7775
7776
7777
7778
7779
7780
7781
7782
7783
7784
7785


7786
7787
7788
7789
7790
7791
7792
7793
7794
7795
7796
7797
7798
7799
7800
7801
7802
7803
7804
7805
7806
7807
7808
7809
7810
7811
7812
7813
7814
7815
 * Results:
 *	If a command is found that encloses the program counter value, a
 *	pointer to the command's source is returned and the length of the
 *	source is stored at *lengthPtr. If multiple commands resulted in code
 *	at pc, information about the closest enclosing command is returned. If
 *	no matching command is found, NULL is returned and *lengthPtr is
 *	unchanged.
 *
 *	If input parameter '*lengthPtr' has value ENSEMBLE_PSEUDO_COMMAND,
 *	we're servicing a subcomand dispatch.
 *
 * Side effects:
 *	The CmdFrame at *cfPtr is updated.
 *
 *----------------------------------------------------------------------
 */

const char *
TclGetSrcInfoForCmd(
    Interp *iPtr,
    int *lenPtr)
{
    CmdFrame *cfPtr = iPtr->cmdFramePtr;
    const char *command;
    ByteCode *codePtr;
    int len;

    if (!cfPtr) {
	return NULL;
    }
    codePtr = (ByteCode *) cfPtr->data.tebc.codePtr;
    if (!codePtr || !cfPtr->data.tebc.pc) {
	return NULL;


    }

    command = GetSrcInfoForPc((unsigned char *) cfPtr->data.tebc.pc,
	    codePtr, &len);

    /*
     * [sebres]: If ensemble call (sentinel length == ENSEMBLE_PSEUDO_COMMAND), 
     * shift string ptr to subcommand (string range -> range).
     */

    if (command && len && lenPtr && *lenPtr == ENSEMBLE_PSEUDO_COMMAND
	    && codePtr->objArrayPtr) {
	Tcl_Obj *objPtr = codePtr->objArrayPtr[0];

	if (len > objPtr->length) {
	    command += objPtr->length + 1;
	    len -= objPtr->length + 1;
	}
    }

    if (lenPtr != NULL) {
	*lenPtr = len;
    }
    return command;
}

void
TclGetSrcInfoForPc(
    CmdFrame *cfPtr)
{