Advertisement
Guest User

Untitled

a guest
Jul 24th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.66 KB | None | 0 0
  1. diff --git src/eval.c src/eval.c
  2. index 53c188b..3d2c22b 100644
  3. --- src/eval.c
  4. +++ src/eval.c
  5. @@ -187,6 +187,7 @@ static struct vimvar
  6. {VV_NAME("t_none", VAR_NUMBER), VV_RO},
  7. {VV_NAME("t_job", VAR_NUMBER), VV_RO},
  8. {VV_NAME("t_channel", VAR_NUMBER), VV_RO},
  9. + {VV_NAME("stacktrace", VAR_LIST), VV_RO},
  10. };
  11.  
  12. /* shorthand */
  13. @@ -296,6 +297,7 @@ eval_init(void)
  14. set_vim_var_nr(VV_HLSEARCH, 1L);
  15. set_vim_var_dict(VV_COMPLETED_ITEM, dict_alloc());
  16. set_vim_var_list(VV_ERRORS, list_alloc());
  17. + set_vim_var_list(VV_STACKTRACE, list_alloc());
  18.  
  19. set_vim_var_nr(VV_FALSE, VVAL_FALSE);
  20. set_vim_var_nr(VV_TRUE, VVAL_TRUE);
  21. @@ -6655,6 +6657,63 @@ v_throwpoint(char_u *oldval)
  22. return NULL;
  23. }
  24.  
  25. + void
  26. +pop_stacktrace()
  27. +{
  28. + list_T *li = NULL;
  29. +
  30. + li = vimvars[VV_STACKTRACE].vv_list;
  31. + if (li == NULL)
  32. + return;
  33. +
  34. + if (0 < li->lv_len && li->lv_last != NULL)
  35. + listitem_remove(li, li->lv_last);
  36. +}
  37. +
  38. + void
  39. +push_stacktrace(char_u *name, linenr_T lnum, scid_T id)
  40. +{
  41. + list_T *li = NULL;
  42. + dict_T *di = NULL;
  43. + typval_T tv;
  44. + int idx = 0;
  45. +
  46. + if (name == NULL)
  47. + return;
  48. +
  49. + li = vimvars[VV_STACKTRACE].vv_list;
  50. + if (li == NULL)
  51. + return;
  52. +
  53. + di = dict_alloc();
  54. + if (di == NULL)
  55. + return;
  56. +
  57. + if (STRNCMP("function ", name, 9) == 0)
  58. + {
  59. + // get the function name without callstack.
  60. + idx = STRLEN(name);
  61. + while (0 < idx)
  62. + if (name[idx - 1] == '.' || name[idx - 1] == ' ')
  63. + break;
  64. + else
  65. + idx--;
  66. + }
  67. + else
  68. + // 'name' is a filepath.
  69. + idx = 0;
  70. +
  71. + tv.v_type = VAR_DICT;
  72. + tv.v_lock = VAR_LOCKED;
  73. + tv.vval.v_dict = di;
  74. +
  75. + dict_add_nr_str(di, "name", 0L, name + idx);
  76. + dict_add_nr_str(di, "lnum", lnum, NULL);
  77. + dict_add_nr_str(di, "path", 0L, get_scriptname(id));
  78. +
  79. + list_append_tv(li, &tv);
  80. +}
  81. +
  82. #if defined(FEAT_AUTOCMD) || defined(PROTO)
  83. /*
  84. * Set v:cmdarg.
  85. diff --git src/userfunc.c src/userfunc.c
  86. index af1863f..019f4f7 100644
  87. --- src/userfunc.c
  88. +++ src/userfunc.c
  89. @@ -480,8 +480,10 @@ get_func_tv(
  90. &argvars[i];
  91. }
  92.  
  93. + push_stacktrace(sourcing_name, sourcing_lnum, current_SID);
  94. ret = call_func(name, len, rettv, argcount, argvars, NULL,
  95. firstline, lastline, doesrange, evaluate, partial, selfdict);
  96. + pop_stacktrace();
  97.  
  98. funcargs.ga_len -= i;
  99. }
  100. diff --git src/vim.h src/vim.h
  101. index e2d4cc4..c5f35a3 100644
  102. --- src/vim.h
  103. +++ src/vim.h
  104. @@ -1981,7 +1981,8 @@ typedef int sock_T;
  105. #define VV_TYPE_NONE 78
  106. #define VV_TYPE_JOB 79
  107. #define VV_TYPE_CHANNEL 80
  108. -#define VV_LEN 81 /* number of v: vars */
  109. +#define VV_STACKTRACE 81
  110. +#define VV_LEN 82 /* number of v: vars */
  111.  
  112. /* used for v_number in VAR_SPECIAL */
  113. #define VVAL_FALSE 0L
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement