Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

95 lines
1.8 KiB

  1. /*
  2. see copyright notice in sqrdbg.h
  3. */
  4. #include <windows.h>
  5. #include <winsock.h>
  6. #include <squirrel.h>
  7. #include <stdlib.h>
  8. #include <stdio.h>
  9. #include <sqstdblob.h>
  10. #include <sqstdio.h>
  11. #include <sqstdaux.h>
  12. #include "sqrdbg.h"
  13. #include "sqdbgserver.h"
  14. #pragma comment (lib ,"Ws2_32.lib")
  15. #ifdef _UNICODE
  16. #define scfprintf fwprintf
  17. #define scvprintf vwprintf
  18. #else
  19. #define scfprintf fprintf
  20. #define scvprintf vprintf
  21. #endif
  22. void printfunc(HSQUIRRELVM v,const SQChar *s,...)
  23. {
  24. va_list vl;
  25. va_start(vl, s);
  26. scvprintf( s, vl);
  27. va_end(vl);
  28. }
  29. void PrintError(HSQUIRRELVM v)
  30. {
  31. const SQChar *err;
  32. sq_getlasterror(v);
  33. if(SQ_SUCCEEDED(sq_getstring(v,-1,&err))) {
  34. scprintf(_SC("SQDBG error : %s"),err);
  35. }else {
  36. scprintf(_SC("SQDBG error"),err);
  37. }
  38. sq_pop(v,1);
  39. }
  40. int main(int argc, char *argv[])
  41. {
  42. if(argc < 2){
  43. scprintf(_SC("SQDBG error : no file specified"));
  44. return -1;
  45. }
  46. HSQUIRRELVM v = sq_open(1024);
  47. sqstd_seterrorhandlers(v);
  48. //!! INITIALIZES THE DEBUGGER ON THE TCP PORT 1234
  49. //!! ENABLES AUTOUPDATE
  50. HSQREMOTEDBG rdbg = sq_rdbg_init(v,1234,SQTrue);
  51. if(rdbg) {
  52. //!! ENABLES DEBUG INFO GENERATION(for the compiler)
  53. sq_enabledebuginfo(v,SQTrue);
  54. sq_setprintfunc(v,printfunc);
  55. //!! SUSPENDS THE APP UNTIL THE DEBUGGER CLIENT CONNECTS
  56. if(SQ_SUCCEEDED(sq_rdbg_waitforconnections(rdbg))) {
  57. scprintf(_SC("connected\n"));
  58. const SQChar *fname=NULL;
  59. #ifdef _UNICODE
  60. SQChar sTemp[256];
  61. mbstowcs(sTemp,argv[1],(int)strlen(argv[1])+1);
  62. fname=sTemp;
  63. #else
  64. fname=argv[1];
  65. #endif
  66. //!!REGISTERS STANDARDS LIBS
  67. sq_pushroottable(v);
  68. sqstd_register_bloblib(v);
  69. sqstd_register_iolib(v);
  70. //!!EXECUTE A SCTIPT
  71. if(SQ_FAILED(sqstd_dofile(v,fname,SQFalse,SQTrue))) {
  72. PrintError(v);
  73. }
  74. }
  75. //!! CLEANUP
  76. sq_rdbg_shutdown(rdbg);
  77. }
  78. else {
  79. PrintError(v);
  80. }
  81. sq_close(v);
  82. return 0;
  83. }