patch 8.2.0056: execution stack is incomplete and inefficient
Problem: Execution stack is incomplete and inefficient.
Solution: Introduce a proper execution stack and use it instead of
sourcing_name/sourcing_lnum. Create a string only when used.
diff --git a/src/debugger.c b/src/debugger.c
index 0a25e0b..5dfc54e 100644
--- a/src/debugger.c
+++ b/src/debugger.c
@@ -51,6 +51,7 @@
int n;
char_u *cmdline = NULL;
char_u *p;
+ char_u *sname;
char *tail = NULL;
static int last_cmd = 0;
#define CMD_CONT 1
@@ -104,10 +105,12 @@
vim_free(debug_newval);
debug_newval = NULL;
}
- if (sourcing_name != NULL)
- msg((char *)sourcing_name);
- if (sourcing_lnum != 0)
- smsg(_("line %ld: %s"), (long)sourcing_lnum, cmd);
+ sname = estack_sfile();
+ if (sname != NULL)
+ msg((char *)sname);
+ vim_free(sname);
+ if (SOURCING_LNUM != 0)
+ smsg(_("line %ld: %s"), SOURCING_LNUM, cmd);
else
smsg(_("cmd: %s"), cmd);
@@ -300,14 +303,14 @@
}
static int
-get_maxbacktrace_level(void)
+get_maxbacktrace_level(char_u *sname)
{
char *p, *q;
int maxbacktrace = 0;
- if (sourcing_name != NULL)
+ if (sname != NULL)
{
- p = (char *)sourcing_name;
+ p = (char *)sname;
while ((q = strstr(p, "..")) != NULL)
{
p = q + 2;
@@ -341,27 +344,32 @@
}
else
{
- int max = get_maxbacktrace_level();
+ char_u *sname = estack_sfile();
+ int max = get_maxbacktrace_level(sname);
if (debug_backtrace_level > max)
{
debug_backtrace_level = max;
smsg(_("frame at highest level: %d"), max);
}
+ vim_free(sname);
}
}
static void
do_showbacktrace(char_u *cmd)
{
+ char_u *sname;
char *cur;
char *next;
int i = 0;
- int max = get_maxbacktrace_level();
+ int max;
- if (sourcing_name != NULL)
+ sname = estack_sfile();
+ max = get_maxbacktrace_level(sname);
+ if (sname != NULL)
{
- cur = (char *)sourcing_name;
+ cur = (char *)sname;
while (!got_int)
{
next = strstr(cur, "..");
@@ -377,9 +385,11 @@
*next = '.';
cur = next + 2;
}
+ vim_free(sname);
}
- if (sourcing_lnum != 0)
- smsg(_("line %ld: %s"), (long)sourcing_lnum, cmd);
+
+ if (SOURCING_LNUM != 0)
+ smsg(_("line %ld: %s"), (long)SOURCING_LNUM, cmd);
else
smsg(_("cmd: %s"), cmd);
}