Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » DSDP - Real-Time Software Components (RTSC) » Can XDC script get a list of names of functions in a module?(XDCscript)
Can XDC script get a list of names of functions in a module? [message #499077] Thu, 19 November 2009 18:04 Go to next message
Brian Cruickshank is currently offline Brian CruickshankFriend
Messages: 19
Registered: September 2009
Junior Member
In CCStudio, you can create a GEL script that can define aliases for long function names:
e.g.
#define Log_write xdc_runtime_Log_write__F

Once CCStudio has loaded this script, you can use the short module name to set breakpoints or to view the code in the disassembly view, memory view or whatever instead of having to type in the fully qualified name with a __F appended to it.

I'd like to create an xs script that auto-generates a GEL file that has #define statements for all of the functions in the package I'm developing, but I haven't been able to find a way to get the function names. Is there a way to access a list of function names from within an .xs script?

Regards,
Brian
Re: Can XDC script get a list of names of functions in a module? [message #499099 is a reply to message #499077] Thu, 19 November 2009 20:05 Go to previous messageGo to next message
Dave Russo is currently offline Dave RussoFriend
Messages: 172
Registered: July 2009
Senior Member
Brian Cruickshank wrote:
> In CCStudio, you can create a GEL script that can define aliases for
> long function names: e.g. #define Log_write xdc_runtime_Log_write__F
>
> Once CCStudio has loaded this script, you can use the short module name
> to set breakpoints or to view the code in the disassembly view, memory
> view or whatever instead of having to type in the fully qualified name
> with a __F appended to it.
>
> I'd like to create an xs script that auto-generates a GEL file that has
> #define statements for all of the functions in the package I'm
> developing, but I haven't been able to find a way to get the function
> names. Is there a way to access a list of function names from within an
> .xs script?
Yes. The following script prints the name and return type of every
function specified by xdc.runtime.System:

var Mod = xdc.module("xdc.runtime.System");
var fxns = Mod.$spec.getFxns().toArray();
for (var i = 0; i < fxns.length; i++) {
var f = fxns[i];
print(f.getName() + ": " + f.getType().tsig());
}

The docs for the $spec object are weak, but a little experimentation
will probably get you what you need. See
http://rtsc.eclipse.org/docs-tip/XDCscript_-_Module-Object.% 24spec

Note that ti.targets already generate a .gel script; see
http://rtsc.eclipse.org/cdoc-tip/index.html#ti/targets/ITarg et.html#debug.Gen

You can can replace/enhance the templates used by ti.targets by setting
the ti.target's debugGen properties in your config.bld script. There is
no need to modify the ti.targets package (of course).

>
> Regards,
> Brian
Re: Can XDC script get a list of names of functions in a module? [message #502473 is a reply to message #499077] Tue, 08 December 2009 12:58 Go to previous messageGo to next message
Brian Cruickshank is currently offline Brian CruickshankFriend
Messages: 19
Registered: September 2009
Junior Member
Thanks Dave, that works very well. The script function below can be called from a package.xs file's close() function to generate a GEL file that defines short name aliases for functions in a RTSC program. It helps make debugging a package's functions in CCS a bit easier.

Is there a way to determine the type names that have been defined so that the GEL script can be extended to define short name aliases for types as well? Should I add any __V or whatever suffixes to the long names for the types??

e.g. #define Types_Timestamp64 xdc_runtime_Types_Timestamp64
#define LoggerBuf_Object xdc_runtime_LoggerBuf_Object
etc.

Regards,
Brian

/*
* ======== genShortNameAliasGELfile ========
* generates configPkg\shortNames.gel, which contains a GEL hotmenu
* function that defines short name aliases for the fully qualified
* Module method names
*/
function genShortNameAliasGELfile(){
var strFuncName = "";
var strShortModName = "";
var strLongModName = "";
var strShortDeclName = "";
var strLongDeclName = "";
var decl;
var lastDotIndex = 0;
var uuFindex = 0;
var strToWrite = "";
var modName = "";
var enablePrintMsgs = false;

gelFile = new java.io.FileWriter("shortNames.gel");
print("package.xs: generating shortNames.gel");
gelFile.write("menuitem \"Short Names\"\;\n\n");
gelFile.write("hotmenu AddShortFunctionNames(){\n");

for each (var mod in Program.targetModules()) {
modName = mod.$name;
lastDotIndex = mod.$name.lastIndexOf('.')+1;
strShortModName = mod.$name.substring(lastDotIndex,mod.$name.length);
strLongModName = mod.$name;
while (strLongModName.indexOf('.') > 0){
strLongModName = strLongModName.replace(".","_");
}
if (enablePrintMsgs) {
print("======== "+strLongModName+" ========");
}
var fxns = mod.$spec.getFxns().toArray();

for (var i = 0; i < fxns.length; i++) {
var f = fxns[i];
strFuncName = f.getName();
if (strFuncName.indexOf("__") < 0){

strShortDeclName = strShortModName + "_"+strFuncName;
if (strShortDeclName.indexOf("_Module_") < 0){
strLongDeclName = strLongModName + "_"+strFuncName+"__F";
strToWrite = "#define "+strShortDeclName+ " " + strLongDeclName+"\n";
gelFile.write(strToWrite);
if (enablePrintMsgs) {
print("GEL: "+strToWrite);
}
}
}
}
}
gelFile.write("}\n");

gelFile.flush();
gelFile.close();

}

[Updated on: Tue, 08 December 2009 13:03]

Report message to a moderator

Re: Can XDC script get a list of names of functions in a module? [message #505240 is a reply to message #502473] Mon, 28 December 2009 21:03 Go to previous messageGo to next message
Dave Russo is currently offline Dave RussoFriend
Messages: 172
Registered: July 2009
Senior Member
comments below

Brian Cruickshank wrote:
> Thanks Dave, that works very well. The attached script function can be
> called from a package.xs file's close() function to generate a GEL file
> that defines short name aliases for functions in a RTSC program. It
> helps make debugging a package's functions in CCS a bit easier.
Cool.

BTW: in your script, the following loop:
while (strLongModName.indexOf('.') > 0) {
strLongModName = strLongModName.replace(".", "_");
}

can be replaced by a single line:
strLongModName = strLongModName.replace(/\./g, "_");

The JavaScript replace() function can take a regular expression and this
regular expression can be applied "globally".

Also, the variable modName is unused.

> Is there a way to determine the type names that have been defined so
> that the GEL script can be extended to define short name aliases for
> types as well?
I don't know what type names would be useful to GEL, but the types
defined for any module are described by the "Module Binary Contract";
see
http://rtsc.eclipse.org/docs-tip/C_Language_Binding#Module_B inary_Contract

Of course, just like getting a module's functions, you can get all of
the types declared by a module via its $spec object. For example:

var Mod = xdc.module("my.fav.Mod");
var decls = Mod.$spec.getDecls().toArray();
for (var i = 0; i < decls.length; i++) {
var decl = decls[i];
if (decl.isMeta()) {
continue; /* skip meta-only decls */
}

var name = decl.getName();
if ("getTypeSig" in decl) {
print(name + ": " + decl.getTypeSig());
}
else if (decl instanceof Packages.xdc.services.spec.Decl.Struct) {
: /* handle structure decl */
}
}
}

>Should I add any __V or whatever suffixes to the long
> names for the types??
>
> e.g. #define Types_Timestamp64 xdc_runtime_Types_Timestamp64 #define
> LoggerBuf_Object xdc_runtime_LoggerBuf_Object
> etc.
>
> Regards,
> Brian
>
Re: Can XDC script get a list of names of functions in a module? [message #505265 is a reply to message #505240] Mon, 28 December 2009 21:52 Go to previous message
Dave Russo is currently offline Dave RussoFriend
Messages: 172
Registered: July 2009
Senior Member
One more note about the posted script: I notice that you are filtering
declarations based on their names. For example:
strFuncName = f.getName();
if (strFuncName.indexOf("__") < 0) {
strShortDeclName = strShortModName + "_" + strFuncName;
if (strShortDeclName.indexOf("_Module_") < 0) {
:
}
}

You probably mean to use the isSys() method of a Decl instead. For example:
strFuncName = f.getName();
if (!f.isSys()) {
strShortDeclName = strShortModName + "_" + strFuncName;
:
}


On 12/28/2009 1:03 PM, dave russo wrote:
> comments below
>
> Brian Cruickshank wrote:
>> Thanks Dave, that works very well. The attached script function can be
>> called from a package.xs file's close() function to generate a GEL
>> file that defines short name aliases for functions in a RTSC program.
>> It helps make debugging a package's functions in CCS a bit easier.
> Cool.
>
> BTW: in your script, the following loop:
> while (strLongModName.indexOf('.') > 0) {
> strLongModName = strLongModName.replace(".", "_");
> }
>
> can be replaced by a single line:
> strLongModName = strLongModName.replace(/\./g, "_");
>
> The JavaScript replace() function can take a regular expression and this
> regular expression can be applied "globally".
>
> Also, the variable modName is unused.
>
Previous Topic:Errors Creating a RTSC Project
Next Topic:XDCtools 3.16.02 is available
Goto Forum:
  


Current Time: Tue Apr 23 07:41:32 GMT 2024

Powered by FUDForum. Page generated in 0.03028 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top