run6x.js 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #!/usr/bin/env dss.sh
  2. //
  3. // Debug Server Scripting C6x launcher.
  4. //
  5. importPackage(Packages.com.ti.debug.engine.scripting);
  6. importPackage(Packages.com.ti.ccstudio.scripting.environment);
  7. importPackage(Packages.java.lang);
  8. if (arguments.length == 0) {
  9. // Extract script name from eclipse
  10. var regex = new RegExp("-dss\\.rhinoArgs\n(.*)");
  11. var matches = regex.exec(environment["eclipse.commands"]);
  12. System.err.println("Usage: " + matches[1] + " executable [args]");
  13. System.err.println();
  14. System.err.println("You're also required to set CCSTARGETCONFIG " +
  15. "environment variable to appoint");
  16. System.err.println("proper .ccxml file, customarily one of " +
  17. "$HOME/ti/CCSTargetConfigurations/*.ccxml");
  18. quit(1);
  19. }
  20. try {
  21. var prog = arguments[0];
  22. var script = ScriptingEnvironment.instance();
  23. var debugServer = script.getServer("DebugServer.1");
  24. // CCSTARGETCONFIG environment variable should point at proper .ccxml,
  25. // customarily one of $HOME/ti/CCSTargetConfigurations/*.ccxml.
  26. debugServer.setConfig(System.getenv("CCSTARGETCONFIG"));
  27. var debugSession = debugServer.openSession("*", "*");
  28. // Redirect GEL output to |prog|.gel file, so that it doesn't clobber
  29. // standard output from the program...
  30. var dot = prog.lastIndexOf(".");
  31. var gel_out = prog + ".gel";
  32. if (dot > 0) {
  33. gel_out = prog.substr(0,dot) + ".gel";
  34. }
  35. debugSession.expression.evaluate('GEL_EnableFileOutput("'
  36. + gel_out + '", 0, 0)');
  37. debugSession.target.connect();
  38. // It should be noted that "current working directory" for program
  39. // executed on the target system is one where |prog| resides, and
  40. // not where script executed [as one would expect]...
  41. debugSession.memory.loadProgram(prog, arguments);
  42. // Pull exit()'s address and set breakpoint, then just execute till
  43. // it's reached...
  44. var exitAddr = debugSession.symbol.getAddress("exit");
  45. debugSession.breakpoint.add(exitAddr);
  46. while (1) {
  47. debugSession.target.run();
  48. var PC = debugSession.expression.evaluate("PC");
  49. if (PC == exitAddr) {
  50. break;
  51. }
  52. }
  53. // Snatch value passed to exit(), so that it can be passed down to
  54. // shell as exit code from this script...
  55. var exitCode = debugSession.expression.evaluate("A4");
  56. // Last run to termination...
  57. debugSession.target.run();
  58. // Clean up...
  59. debugSession.terminate();
  60. debugServer.stop();
  61. // It should be noted that there is kind of a bug in C6x run-time.
  62. // Return value from main() is not passed to last implicit exit()
  63. // call [as it would on other systems], but instead constant 1 is
  64. // passed, which conventionally indicates an error. So that if one
  65. // wants to pass specific exit code, or even 0 indicating "success",
  66. // one has to call exit() explicitly instead of relying on value
  67. // returned by main()...
  68. quit(exitCode);
  69. } catch (e) {
  70. // We catch everything, because default handler terminates script with
  71. // "success" exit code upon exception...
  72. System.err.println(e.rhinoException);
  73. quit(139);
  74. }