// Import the DSS packages into our namespace to save on typing importPackage(Packages.com.ti.debug.engine.scripting) importPackage(Packages.com.ti.ccstudio.scripting.environment) importPackage(Packages.java.lang) importPackage(Packages.java.net) importPackage(Packages.java.util) importPackage(Packages.java.text) importPackage(Packages.java.scripting) importPackage(Packages.com.ti.ctoolstrace.scripting) importPackage(Packages.java.io) var dateFormatter = new SimpleDateFormat("HH:mm:ss:SSS dd/MM/yyyy"); var deviceCCXMLFile = ""; var channelXMLFile = ""; var symbolFile = ""; var breakpointFile = ""; var receiverName = "Pro Trace" var socketPort = 5002; var socketTimeOut = 2* 60 * 1000; var traceFile = "/tmp/autotrace/output_files/trace.bin" var scriptTimeout = 30 * 1000 var actTraceOnBreakpoint = false; var traceRecordingTimeout = 30000; // Create our scripting environment object - which is the main entry point into any script and // the factory for creating other Scriptable ervers and Sessions var script = ScriptingEnvironment.instance(); // wait for every call to ccs max scriptTimeout (at the moment 30s) myEcho("Setting script timeout to: " + scriptTimeout + "ms"); script.setScriptTimeout(scriptTimeout); //Create a log file in the current directory to log script execution script.traceBegin("/tmp/AutomaticTraceLog.xml", "DefaultStylesheet.xsl"); script.traceSetConsoleLevel(TraceLevel.OFF); script.traceSetFileLevel(TraceLevel.ALL); parseArguments(arguments); myEcho("Setting trace recording timeout to: " + traceRecordingTimeout + "s"); // Create a debug server var debugServer = script.getServer("DebugServer.1"); // Set the device ccxml debugServer.setConfig(deviceCCXMLFile); var cpuList = debugServer.getListOfCPUs(); var cpuName = cpuList[fetchLastDigit(symbolFile)]; myEcho("Using cpuName: " + cpuName); // Open a debug session debugSession = debugServer.openSession(cpuName); debugSession.options.setBoolean("AllowInterruptsWhenHalted", true); debugSession.options.setBoolean("PoliteRealtimeMode", true); debugSession.target.connect(); myEcho("Target connected"); myEcho("Loading symbols"); debugSession.symbol.load(symbolFile); // Create a ctool trace server. myEcho("Creating trace server"); var ts = new CToolsTraceServer(); // Initialize the newly create trace server object ts.initialize(); myEcho("Creating trace channel"); var traceChannel = ts.createChannel(receiverName); myEcho("Adding target"); stringArray = java.lang.reflect.Array.newInstance(java.lang.String, 1) stringArray[0] = new java.lang.String(cpuName); traceChannel.addTraceTargets(stringArray); traceChannel.setupTraceChannel(channelXMLFile); var channelStatus = traceChannel.getStatus(); myEcho("Channel status: " + channelStatus.description()); if (!channelStatus.isEnabled()) { myEcho("Channel is not enabled, quitting!"); terminateSession(); throw "exit"; } myEcho("Removing old breakpoints"); debugSession.breakpoint.removeAll(); communicateReadyToTrace(); myEcho("Everything is set up, waiting for triggering"); waitOnTraceTriggering(); if (cpuName.indexOf("C66") !== -1) { myEcho("Nyquist environment detected, addind Mfence workaround"); var mfenceWorkaround = mfenceWorkaround(); debugSession.breakpoint.add(mfenceWorkaround); } if (breakpointFile !== "") { myEcho("Loading breakpoint from file: " + breakpointFile); var bkpt = debugSession.breakpoint.loadConfig(breakpointFile); if (actTraceOnBreakpoint) { activateTraceOnBreakpoint(); } } else { activateTraceOnBreakpoint(); } myEcho("Recording"); var recordingRoundsCounter = 0; while (!channelStatus.isRecordingStopped()) { Thread.sleep(1000); channelStatus = traceChannel.getStatus(); if (recordingRoundsCounter >= traceRecordingTimeout) { traceChannel.stopTraceRecording(); terminateSession(); throw "Max recording time " + traceRecordingTimeout + "s exceeded!"; } recordingRoundsCounter = recordingRoundsCounter + 1; } myEcho("Saving trace data to file: " + traceFile); traceChannel.getBinaryTraceData(traceFile); myEcho("All done, completed successfully"); terminateSession(); function activateTraceOnBreakpoint() { myEcho("Creating trace on breakpoint"); var bkpPropTraceOn = createTraceOnBreakpoint(); var res = debugSession.breakpoint.add(bkpPropTraceOn); } function createTraceOnBreakpoint() { var traceOnBkpProperties = debugSession.breakpoint.createProperties(1); traceOnBkpProperties.setString("Hardware Configuration.Type", "Trace"); traceOnBkpProperties.setString("Hardware Configuration.Type.Trace Type", "Standard"); traceOnBkpProperties.setString("Hardware Configuration.Type.Actions", "Trace On"); traceOnBkpProperties.setBoolean("Hardware Configuration.Type.What to Trace.Program Address", true); traceOnBkpProperties.setBoolean("Hardware Configuration.Type.What to Trace.Time Stamp", true); traceOnBkpProperties.setString("Miscellaneous.Group", "Default Group"); traceOnBkpProperties.setString("Miscellaneous.Name", "OnTrace"); return traceOnBkpProperties; } function mfenceWorkaround() { // Trace MFENCE bug workaround var ignoreMarks = debugSession.breakpoint.createProperties(1); // 1 = AET breakpoint ignoreMarks.setString("Hardware Configuration.Type", "Trace"); ignoreMarks.setString("Hardware Configuration.Type.Trace Type", "Standard"); ignoreMarks.setString("Hardware Configuration.Type.Actions", "Don't Store Sample"); ignoreMarks.setString("Hardware Configuration.Type.Trigger Type", "Event"); ignoreMarks.setString("Hardware Configuration.Type.Trigger Type.Event Category", "System"); ignoreMarks.setBoolean("Hardware Configuration.Type.Trigger Type.Event Category.MARK Instruction", true); ignoreMarks.setBoolean("Hardware Configuration.Type.Trigger Type.Event Category.MARK Instruction.MARK 0", true); ignoreMarks.setBoolean("Hardware Configuration.Type.Trigger Type.Event Category.MARK Instruction.MARK 1", false); ignoreMarks.setBoolean("Hardware Configuration.Type.Trigger Type.Event Category.MARK Instruction.MARK 2", false); ignoreMarks.setBoolean("Hardware Configuration.Type.Trigger Type.Event Category.MARK Instruction.MARK 3", false); ignoreMarks.setBoolean("Hardware Configuration.Type.What to Not Store.Program Address", true); // requires emupack SR M5 to be installed in CCS ignoreMarks.setBoolean("Hardware Configuration.Type.What to Not Store.Time Stamp", false); // requires emupack SR M5 to be installed in CCS return ignoreMarks; } function createHandleMacUserSetupReqBreakpoint() { traceOnBkpProperties = debugSession.breakpoint.createProperties(1); traceOnBkpProperties.setString("Hardware Configuration.Type", "Trace"); traceOnBkpProperties.setString("Hardware Configuration.Type.Trace Type", "Standard"); traceOnBkpProperties.setString("Hardware Configuration.Type.Actions", "Start Trace"); traceOnBkpProperties.setString("Hardware Configuration.Type.Trigger Type", "PC"); traceOnBkpProperties.setString("Hardware Configuration.Type.Trigger Type.Location Type", "Point"); traceOnBkpProperties.setString("Hardware Configuration.Type.Trigger Type.Location Type.Location", "handleMacUserSetupReq") traceOnBkpProperties.setBoolean("Hardware Configuration.Type.What to Trace.Program Address", true); traceOnBkpProperties.setBoolean("Hardware Configuration.Type.What to Trace.Time Stamp", true); traceOnBkpProperties.setString("Miscellaneous.Group", "Default Group"); traceOnBkpProperties.setString("Miscellaneous.Name", "handleMacUserSetupReq"); return traceOnBkpProperties; } function myEcho(msg) { var str = "[" + dateFormatter.format(new Date()) + "]\t" + msg; System.out.println(str); script.traceWrite(msg); } function usage() { var str = "\nAutomaticTrace.js\n"; str += " Mandatory parameters:\n"; str += " -o=\n"; str += " Example: -o=/home/sct/RobotTests/dspbin/OUT/DlUlDspNyCpu2.out\n"; str += " -d=\n"; str += " Example: -d=/tmp/traceDeviceConfig.ccxml\n"; str += " -c=\n"; str += " Example: -c=/tmp/traceChannelConfig.xml\n"; str += " Optional parameters:\n"; str += " -b=\n"; str += " Example: -b=/tmp/traceFunctionBreakpoint.xml\n"; str += " -a=\n"; str += " Example: -a=True\n"; str += " -t=