Mercurial > vim
comparison src/debugger.c @ 18991:847cc7932c42 v8.2.0056
patch 8.2.0056: execution stack is incomplete and inefficient
Commit: https://github.com/vim/vim/commit/1a47ae32cdc19b0fd5a82e19fe5fddf45db1a506
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Dec 29 23:04:25 2019 +0100
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.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 29 Dec 2019 23:15:04 +0100 |
parents | 6bd715870e32 |
children | d9ea4f0bfd34 |
comparison
equal
deleted
inserted
replaced
18990:1219ae40b086 | 18991:847cc7932c42 |
---|---|
49 int save_ignore_script = 0; | 49 int save_ignore_script = 0; |
50 int save_ex_normal_busy; | 50 int save_ex_normal_busy; |
51 int n; | 51 int n; |
52 char_u *cmdline = NULL; | 52 char_u *cmdline = NULL; |
53 char_u *p; | 53 char_u *p; |
54 char_u *sname; | |
54 char *tail = NULL; | 55 char *tail = NULL; |
55 static int last_cmd = 0; | 56 static int last_cmd = 0; |
56 #define CMD_CONT 1 | 57 #define CMD_CONT 1 |
57 #define CMD_NEXT 2 | 58 #define CMD_NEXT 2 |
58 #define CMD_STEP 3 | 59 #define CMD_STEP 3 |
102 { | 103 { |
103 smsg(_("Newval = \"%s\""), debug_newval); | 104 smsg(_("Newval = \"%s\""), debug_newval); |
104 vim_free(debug_newval); | 105 vim_free(debug_newval); |
105 debug_newval = NULL; | 106 debug_newval = NULL; |
106 } | 107 } |
107 if (sourcing_name != NULL) | 108 sname = estack_sfile(); |
108 msg((char *)sourcing_name); | 109 if (sname != NULL) |
109 if (sourcing_lnum != 0) | 110 msg((char *)sname); |
110 smsg(_("line %ld: %s"), (long)sourcing_lnum, cmd); | 111 vim_free(sname); |
112 if (SOURCING_LNUM != 0) | |
113 smsg(_("line %ld: %s"), SOURCING_LNUM, cmd); | |
111 else | 114 else |
112 smsg(_("cmd: %s"), cmd); | 115 smsg(_("cmd: %s"), cmd); |
113 | 116 |
114 // Repeat getting a command and executing it. | 117 // Repeat getting a command and executing it. |
115 for (;;) | 118 for (;;) |
298 // here. | 301 // here. |
299 debug_did_msg = TRUE; | 302 debug_did_msg = TRUE; |
300 } | 303 } |
301 | 304 |
302 static int | 305 static int |
303 get_maxbacktrace_level(void) | 306 get_maxbacktrace_level(char_u *sname) |
304 { | 307 { |
305 char *p, *q; | 308 char *p, *q; |
306 int maxbacktrace = 0; | 309 int maxbacktrace = 0; |
307 | 310 |
308 if (sourcing_name != NULL) | 311 if (sname != NULL) |
309 { | 312 { |
310 p = (char *)sourcing_name; | 313 p = (char *)sname; |
311 while ((q = strstr(p, "..")) != NULL) | 314 while ((q = strstr(p, "..")) != NULL) |
312 { | 315 { |
313 p = q + 2; | 316 p = q + 2; |
314 maxbacktrace++; | 317 maxbacktrace++; |
315 } | 318 } |
339 debug_backtrace_level = 0; | 342 debug_backtrace_level = 0; |
340 msg(_("frame is zero")); | 343 msg(_("frame is zero")); |
341 } | 344 } |
342 else | 345 else |
343 { | 346 { |
344 int max = get_maxbacktrace_level(); | 347 char_u *sname = estack_sfile(); |
348 int max = get_maxbacktrace_level(sname); | |
345 | 349 |
346 if (debug_backtrace_level > max) | 350 if (debug_backtrace_level > max) |
347 { | 351 { |
348 debug_backtrace_level = max; | 352 debug_backtrace_level = max; |
349 smsg(_("frame at highest level: %d"), max); | 353 smsg(_("frame at highest level: %d"), max); |
350 } | 354 } |
355 vim_free(sname); | |
351 } | 356 } |
352 } | 357 } |
353 | 358 |
354 static void | 359 static void |
355 do_showbacktrace(char_u *cmd) | 360 do_showbacktrace(char_u *cmd) |
356 { | 361 { |
362 char_u *sname; | |
357 char *cur; | 363 char *cur; |
358 char *next; | 364 char *next; |
359 int i = 0; | 365 int i = 0; |
360 int max = get_maxbacktrace_level(); | 366 int max; |
361 | 367 |
362 if (sourcing_name != NULL) | 368 sname = estack_sfile(); |
363 { | 369 max = get_maxbacktrace_level(sname); |
364 cur = (char *)sourcing_name; | 370 if (sname != NULL) |
371 { | |
372 cur = (char *)sname; | |
365 while (!got_int) | 373 while (!got_int) |
366 { | 374 { |
367 next = strstr(cur, ".."); | 375 next = strstr(cur, ".."); |
368 if (next != NULL) | 376 if (next != NULL) |
369 *next = NUL; | 377 *next = NUL; |
375 if (next == NULL) | 383 if (next == NULL) |
376 break; | 384 break; |
377 *next = '.'; | 385 *next = '.'; |
378 cur = next + 2; | 386 cur = next + 2; |
379 } | 387 } |
380 } | 388 vim_free(sname); |
381 if (sourcing_lnum != 0) | 389 } |
382 smsg(_("line %ld: %s"), (long)sourcing_lnum, cmd); | 390 |
391 if (SOURCING_LNUM != 0) | |
392 smsg(_("line %ld: %s"), (long)SOURCING_LNUM, cmd); | |
383 else | 393 else |
384 smsg(_("cmd: %s"), cmd); | 394 smsg(_("cmd: %s"), cmd); |
385 } | 395 } |
386 | 396 |
387 /* | 397 /* |