Bram Moolenaar | eead75c | 2019-04-21 11:35:00 +0200 | [diff] [blame] | 1 | /* vi:set ts=8 sts=4 sw=4 noet: |
| 2 | * |
| 3 | * VIM - Vi IMproved by Bram Moolenaar |
| 4 | * |
| 5 | * Do ":help uganda" in Vim to read copying and usage conditions. |
| 6 | * Do ":help credits" in Vim to see a list of people who contributed. |
| 7 | * See README.txt for an overview of the Vim source code. |
| 8 | */ |
| 9 | |
| 10 | /* |
| 11 | * debugger.c: Vim script debugger functions |
| 12 | */ |
| 13 | |
| 14 | #include "vim.h" |
| 15 | |
| 16 | #if defined(FEAT_EVAL) || defined(PROTO) |
Bram Moolenaar | 31fc39e | 2019-04-23 18:39:49 +0200 | [diff] [blame] | 17 | static int debug_greedy = FALSE; // batch mode debugging: don't save |
| 18 | // and restore typeahead. |
Bram Moolenaar | eead75c | 2019-04-21 11:35:00 +0200 | [diff] [blame] | 19 | static void do_setdebugtracelevel(char_u *arg); |
| 20 | static void do_checkbacktracelevel(void); |
| 21 | static void do_showbacktrace(char_u *cmd); |
| 22 | |
Bram Moolenaar | 31fc39e | 2019-04-23 18:39:49 +0200 | [diff] [blame] | 23 | static char_u *debug_oldval = NULL; // old and newval for debug expressions |
Bram Moolenaar | eead75c | 2019-04-21 11:35:00 +0200 | [diff] [blame] | 24 | static char_u *debug_newval = NULL; |
Bram Moolenaar | 31fc39e | 2019-04-23 18:39:49 +0200 | [diff] [blame] | 25 | static int debug_expr = 0; // use debug_expr |
Bram Moolenaar | eead75c | 2019-04-21 11:35:00 +0200 | [diff] [blame] | 26 | |
| 27 | int |
| 28 | has_watchexpr(void) |
| 29 | { |
| 30 | return debug_expr; |
| 31 | } |
| 32 | |
| 33 | /* |
| 34 | * do_debug(): Debug mode. |
| 35 | * Repeatedly get Ex commands, until told to continue normal execution. |
| 36 | */ |
| 37 | void |
| 38 | do_debug(char_u *cmd) |
| 39 | { |
| 40 | int save_msg_scroll = msg_scroll; |
| 41 | int save_State = State; |
| 42 | int save_did_emsg = did_emsg; |
| 43 | int save_cmd_silent = cmd_silent; |
| 44 | int save_msg_silent = msg_silent; |
| 45 | int save_emsg_silent = emsg_silent; |
| 46 | int save_redir_off = redir_off; |
| 47 | tasave_T typeaheadbuf; |
| 48 | int typeahead_saved = FALSE; |
| 49 | int save_ignore_script = 0; |
| 50 | int save_ex_normal_busy; |
| 51 | int n; |
| 52 | char_u *cmdline = NULL; |
| 53 | char_u *p; |
Bram Moolenaar | 1a47ae3 | 2019-12-29 23:04:25 +0100 | [diff] [blame] | 54 | char_u *sname; |
Bram Moolenaar | eead75c | 2019-04-21 11:35:00 +0200 | [diff] [blame] | 55 | char *tail = NULL; |
| 56 | static int last_cmd = 0; |
| 57 | #define CMD_CONT 1 |
| 58 | #define CMD_NEXT 2 |
| 59 | #define CMD_STEP 3 |
| 60 | #define CMD_FINISH 4 |
| 61 | #define CMD_QUIT 5 |
| 62 | #define CMD_INTERRUPT 6 |
| 63 | #define CMD_BACKTRACE 7 |
| 64 | #define CMD_FRAME 8 |
| 65 | #define CMD_UP 9 |
| 66 | #define CMD_DOWN 10 |
| 67 | |
| 68 | #ifdef ALWAYS_USE_GUI |
Bram Moolenaar | 31fc39e | 2019-04-23 18:39:49 +0200 | [diff] [blame] | 69 | // Can't do this when there is no terminal for input/output. |
Bram Moolenaar | eead75c | 2019-04-21 11:35:00 +0200 | [diff] [blame] | 70 | if (!gui.in_use) |
| 71 | { |
Bram Moolenaar | 31fc39e | 2019-04-23 18:39:49 +0200 | [diff] [blame] | 72 | // Break as soon as possible. |
Bram Moolenaar | eead75c | 2019-04-21 11:35:00 +0200 | [diff] [blame] | 73 | debug_break_level = 9999; |
| 74 | return; |
| 75 | } |
| 76 | #endif |
| 77 | |
Bram Moolenaar | 31fc39e | 2019-04-23 18:39:49 +0200 | [diff] [blame] | 78 | // Make sure we are in raw mode and start termcap mode. Might have side |
| 79 | // effects... |
Bram Moolenaar | eead75c | 2019-04-21 11:35:00 +0200 | [diff] [blame] | 80 | settmode(TMODE_RAW); |
| 81 | starttermcap(); |
| 82 | |
Bram Moolenaar | 31fc39e | 2019-04-23 18:39:49 +0200 | [diff] [blame] | 83 | ++RedrawingDisabled; // don't redisplay the window |
| 84 | ++no_wait_return; // don't wait for return |
| 85 | did_emsg = FALSE; // don't use error from debugged stuff |
| 86 | cmd_silent = FALSE; // display commands |
| 87 | msg_silent = FALSE; // display messages |
| 88 | emsg_silent = FALSE; // display error messages |
| 89 | redir_off = TRUE; // don't redirect debug commands |
Bram Moolenaar | eead75c | 2019-04-21 11:35:00 +0200 | [diff] [blame] | 90 | |
| 91 | State = NORMAL; |
| 92 | debug_mode = TRUE; |
| 93 | |
| 94 | if (!debug_did_msg) |
| 95 | msg(_("Entering Debug mode. Type \"cont\" to continue.")); |
| 96 | if (debug_oldval != NULL) |
| 97 | { |
| 98 | smsg(_("Oldval = \"%s\""), debug_oldval); |
| 99 | vim_free(debug_oldval); |
| 100 | debug_oldval = NULL; |
| 101 | } |
| 102 | if (debug_newval != NULL) |
| 103 | { |
| 104 | smsg(_("Newval = \"%s\""), debug_newval); |
| 105 | vim_free(debug_newval); |
| 106 | debug_newval = NULL; |
| 107 | } |
Bram Moolenaar | 4f25b1a | 2020-09-10 19:25:05 +0200 | [diff] [blame] | 108 | sname = estack_sfile(ESTACK_NONE); |
Bram Moolenaar | 1a47ae3 | 2019-12-29 23:04:25 +0100 | [diff] [blame] | 109 | if (sname != NULL) |
| 110 | msg((char *)sname); |
| 111 | vim_free(sname); |
| 112 | if (SOURCING_LNUM != 0) |
| 113 | smsg(_("line %ld: %s"), SOURCING_LNUM, cmd); |
Bram Moolenaar | eead75c | 2019-04-21 11:35:00 +0200 | [diff] [blame] | 114 | else |
| 115 | smsg(_("cmd: %s"), cmd); |
Bram Moolenaar | 31fc39e | 2019-04-23 18:39:49 +0200 | [diff] [blame] | 116 | |
| 117 | // Repeat getting a command and executing it. |
Bram Moolenaar | eead75c | 2019-04-21 11:35:00 +0200 | [diff] [blame] | 118 | for (;;) |
| 119 | { |
| 120 | msg_scroll = TRUE; |
| 121 | need_wait_return = FALSE; |
| 122 | |
Bram Moolenaar | 31fc39e | 2019-04-23 18:39:49 +0200 | [diff] [blame] | 123 | // Save the current typeahead buffer and replace it with an empty one. |
| 124 | // This makes sure we get input from the user here and don't interfere |
| 125 | // with the commands being executed. Reset "ex_normal_busy" to avoid |
| 126 | // the side effects of using ":normal". Save the stuff buffer and make |
| 127 | // it empty. Set ignore_script to avoid reading from script input. |
Bram Moolenaar | eead75c | 2019-04-21 11:35:00 +0200 | [diff] [blame] | 128 | save_ex_normal_busy = ex_normal_busy; |
| 129 | ex_normal_busy = 0; |
| 130 | if (!debug_greedy) |
| 131 | { |
| 132 | save_typeahead(&typeaheadbuf); |
| 133 | typeahead_saved = TRUE; |
| 134 | save_ignore_script = ignore_script; |
| 135 | ignore_script = TRUE; |
| 136 | } |
| 137 | |
| 138 | vim_free(cmdline); |
| 139 | cmdline = getcmdline_prompt('>', NULL, 0, EXPAND_NOTHING, NULL); |
| 140 | |
| 141 | if (typeahead_saved) |
| 142 | { |
Bram Moolenaar | c41badb | 2021-06-07 22:04:52 +0200 | [diff] [blame] | 143 | restore_typeahead(&typeaheadbuf, TRUE); |
Bram Moolenaar | eead75c | 2019-04-21 11:35:00 +0200 | [diff] [blame] | 144 | ignore_script = save_ignore_script; |
| 145 | } |
| 146 | ex_normal_busy = save_ex_normal_busy; |
| 147 | |
| 148 | cmdline_row = msg_row; |
| 149 | msg_starthere(); |
| 150 | if (cmdline != NULL) |
| 151 | { |
Bram Moolenaar | 31fc39e | 2019-04-23 18:39:49 +0200 | [diff] [blame] | 152 | // If this is a debug command, set "last_cmd". |
| 153 | // If not, reset "last_cmd". |
| 154 | // For a blank line use previous command. |
Bram Moolenaar | eead75c | 2019-04-21 11:35:00 +0200 | [diff] [blame] | 155 | p = skipwhite(cmdline); |
| 156 | if (*p != NUL) |
| 157 | { |
| 158 | switch (*p) |
| 159 | { |
| 160 | case 'c': last_cmd = CMD_CONT; |
| 161 | tail = "ont"; |
| 162 | break; |
| 163 | case 'n': last_cmd = CMD_NEXT; |
| 164 | tail = "ext"; |
| 165 | break; |
| 166 | case 's': last_cmd = CMD_STEP; |
| 167 | tail = "tep"; |
| 168 | break; |
| 169 | case 'f': |
| 170 | last_cmd = 0; |
| 171 | if (p[1] == 'r') |
| 172 | { |
| 173 | last_cmd = CMD_FRAME; |
| 174 | tail = "rame"; |
| 175 | } |
| 176 | else |
| 177 | { |
| 178 | last_cmd = CMD_FINISH; |
| 179 | tail = "inish"; |
| 180 | } |
| 181 | break; |
| 182 | case 'q': last_cmd = CMD_QUIT; |
| 183 | tail = "uit"; |
| 184 | break; |
| 185 | case 'i': last_cmd = CMD_INTERRUPT; |
| 186 | tail = "nterrupt"; |
| 187 | break; |
| 188 | case 'b': last_cmd = CMD_BACKTRACE; |
| 189 | if (p[1] == 't') |
| 190 | tail = "t"; |
| 191 | else |
| 192 | tail = "acktrace"; |
| 193 | break; |
| 194 | case 'w': last_cmd = CMD_BACKTRACE; |
| 195 | tail = "here"; |
| 196 | break; |
| 197 | case 'u': last_cmd = CMD_UP; |
| 198 | tail = "p"; |
| 199 | break; |
| 200 | case 'd': last_cmd = CMD_DOWN; |
| 201 | tail = "own"; |
| 202 | break; |
| 203 | default: last_cmd = 0; |
| 204 | } |
| 205 | if (last_cmd != 0) |
| 206 | { |
Bram Moolenaar | 31fc39e | 2019-04-23 18:39:49 +0200 | [diff] [blame] | 207 | // Check that the tail matches. |
Bram Moolenaar | eead75c | 2019-04-21 11:35:00 +0200 | [diff] [blame] | 208 | ++p; |
| 209 | while (*p != NUL && *p == *tail) |
| 210 | { |
| 211 | ++p; |
| 212 | ++tail; |
| 213 | } |
| 214 | if (ASCII_ISALPHA(*p) && last_cmd != CMD_FRAME) |
| 215 | last_cmd = 0; |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | if (last_cmd != 0) |
| 220 | { |
Bram Moolenaar | b69c6fb | 2021-06-14 20:40:37 +0200 | [diff] [blame] | 221 | // Execute debug command: decide where to break next and |
Bram Moolenaar | 31fc39e | 2019-04-23 18:39:49 +0200 | [diff] [blame] | 222 | // return. |
Bram Moolenaar | eead75c | 2019-04-21 11:35:00 +0200 | [diff] [blame] | 223 | switch (last_cmd) |
| 224 | { |
| 225 | case CMD_CONT: |
| 226 | debug_break_level = -1; |
| 227 | break; |
| 228 | case CMD_NEXT: |
| 229 | debug_break_level = ex_nesting_level; |
| 230 | break; |
| 231 | case CMD_STEP: |
| 232 | debug_break_level = 9999; |
| 233 | break; |
| 234 | case CMD_FINISH: |
| 235 | debug_break_level = ex_nesting_level - 1; |
| 236 | break; |
| 237 | case CMD_QUIT: |
| 238 | got_int = TRUE; |
| 239 | debug_break_level = -1; |
| 240 | break; |
| 241 | case CMD_INTERRUPT: |
| 242 | got_int = TRUE; |
| 243 | debug_break_level = 9999; |
Bram Moolenaar | 31fc39e | 2019-04-23 18:39:49 +0200 | [diff] [blame] | 244 | // Do not repeat ">interrupt" cmd, continue stepping. |
Bram Moolenaar | eead75c | 2019-04-21 11:35:00 +0200 | [diff] [blame] | 245 | last_cmd = CMD_STEP; |
| 246 | break; |
| 247 | case CMD_BACKTRACE: |
| 248 | do_showbacktrace(cmd); |
| 249 | continue; |
| 250 | case CMD_FRAME: |
| 251 | if (*p == NUL) |
| 252 | { |
| 253 | do_showbacktrace(cmd); |
| 254 | } |
| 255 | else |
| 256 | { |
| 257 | p = skipwhite(p); |
| 258 | do_setdebugtracelevel(p); |
| 259 | } |
| 260 | continue; |
| 261 | case CMD_UP: |
| 262 | debug_backtrace_level++; |
| 263 | do_checkbacktracelevel(); |
| 264 | continue; |
| 265 | case CMD_DOWN: |
| 266 | debug_backtrace_level--; |
| 267 | do_checkbacktracelevel(); |
| 268 | continue; |
| 269 | } |
Bram Moolenaar | 31fc39e | 2019-04-23 18:39:49 +0200 | [diff] [blame] | 270 | // Going out reset backtrace_level |
Bram Moolenaar | eead75c | 2019-04-21 11:35:00 +0200 | [diff] [blame] | 271 | debug_backtrace_level = 0; |
| 272 | break; |
| 273 | } |
| 274 | |
Bram Moolenaar | 31fc39e | 2019-04-23 18:39:49 +0200 | [diff] [blame] | 275 | // don't debug this command |
Bram Moolenaar | eead75c | 2019-04-21 11:35:00 +0200 | [diff] [blame] | 276 | n = debug_break_level; |
| 277 | debug_break_level = -1; |
| 278 | (void)do_cmdline(cmdline, getexline, NULL, |
| 279 | DOCMD_VERBOSE|DOCMD_EXCRESET); |
| 280 | debug_break_level = n; |
| 281 | } |
| 282 | lines_left = Rows - 1; |
| 283 | } |
| 284 | vim_free(cmdline); |
| 285 | |
| 286 | --RedrawingDisabled; |
| 287 | --no_wait_return; |
| 288 | redraw_all_later(NOT_VALID); |
| 289 | need_wait_return = FALSE; |
| 290 | msg_scroll = save_msg_scroll; |
| 291 | lines_left = Rows - 1; |
| 292 | State = save_State; |
| 293 | debug_mode = FALSE; |
| 294 | did_emsg = save_did_emsg; |
| 295 | cmd_silent = save_cmd_silent; |
| 296 | msg_silent = save_msg_silent; |
| 297 | emsg_silent = save_emsg_silent; |
| 298 | redir_off = save_redir_off; |
| 299 | |
Bram Moolenaar | 31fc39e | 2019-04-23 18:39:49 +0200 | [diff] [blame] | 300 | // Only print the message again when typing a command before coming back |
| 301 | // here. |
Bram Moolenaar | eead75c | 2019-04-21 11:35:00 +0200 | [diff] [blame] | 302 | debug_did_msg = TRUE; |
| 303 | } |
| 304 | |
| 305 | static int |
Bram Moolenaar | 1a47ae3 | 2019-12-29 23:04:25 +0100 | [diff] [blame] | 306 | get_maxbacktrace_level(char_u *sname) |
Bram Moolenaar | eead75c | 2019-04-21 11:35:00 +0200 | [diff] [blame] | 307 | { |
| 308 | char *p, *q; |
| 309 | int maxbacktrace = 0; |
| 310 | |
Bram Moolenaar | 1a47ae3 | 2019-12-29 23:04:25 +0100 | [diff] [blame] | 311 | if (sname != NULL) |
Bram Moolenaar | eead75c | 2019-04-21 11:35:00 +0200 | [diff] [blame] | 312 | { |
Bram Moolenaar | 1a47ae3 | 2019-12-29 23:04:25 +0100 | [diff] [blame] | 313 | p = (char *)sname; |
Bram Moolenaar | eead75c | 2019-04-21 11:35:00 +0200 | [diff] [blame] | 314 | while ((q = strstr(p, "..")) != NULL) |
| 315 | { |
| 316 | p = q + 2; |
| 317 | maxbacktrace++; |
| 318 | } |
| 319 | } |
| 320 | return maxbacktrace; |
| 321 | } |
| 322 | |
| 323 | static void |
| 324 | do_setdebugtracelevel(char_u *arg) |
| 325 | { |
| 326 | int level; |
| 327 | |
| 328 | level = atoi((char *)arg); |
| 329 | if (*arg == '+' || level < 0) |
| 330 | debug_backtrace_level += level; |
| 331 | else |
| 332 | debug_backtrace_level = level; |
| 333 | |
| 334 | do_checkbacktracelevel(); |
| 335 | } |
| 336 | |
| 337 | static void |
| 338 | do_checkbacktracelevel(void) |
| 339 | { |
| 340 | if (debug_backtrace_level < 0) |
| 341 | { |
| 342 | debug_backtrace_level = 0; |
| 343 | msg(_("frame is zero")); |
| 344 | } |
| 345 | else |
| 346 | { |
Bram Moolenaar | 4f25b1a | 2020-09-10 19:25:05 +0200 | [diff] [blame] | 347 | char_u *sname = estack_sfile(ESTACK_NONE); |
Bram Moolenaar | 1a47ae3 | 2019-12-29 23:04:25 +0100 | [diff] [blame] | 348 | int max = get_maxbacktrace_level(sname); |
Bram Moolenaar | eead75c | 2019-04-21 11:35:00 +0200 | [diff] [blame] | 349 | |
| 350 | if (debug_backtrace_level > max) |
| 351 | { |
| 352 | debug_backtrace_level = max; |
| 353 | smsg(_("frame at highest level: %d"), max); |
| 354 | } |
Bram Moolenaar | 1a47ae3 | 2019-12-29 23:04:25 +0100 | [diff] [blame] | 355 | vim_free(sname); |
Bram Moolenaar | eead75c | 2019-04-21 11:35:00 +0200 | [diff] [blame] | 356 | } |
| 357 | } |
| 358 | |
| 359 | static void |
| 360 | do_showbacktrace(char_u *cmd) |
| 361 | { |
Bram Moolenaar | 1a47ae3 | 2019-12-29 23:04:25 +0100 | [diff] [blame] | 362 | char_u *sname; |
Bram Moolenaar | eead75c | 2019-04-21 11:35:00 +0200 | [diff] [blame] | 363 | char *cur; |
| 364 | char *next; |
| 365 | int i = 0; |
Bram Moolenaar | 1a47ae3 | 2019-12-29 23:04:25 +0100 | [diff] [blame] | 366 | int max; |
Bram Moolenaar | eead75c | 2019-04-21 11:35:00 +0200 | [diff] [blame] | 367 | |
Bram Moolenaar | 4f25b1a | 2020-09-10 19:25:05 +0200 | [diff] [blame] | 368 | sname = estack_sfile(ESTACK_NONE); |
Bram Moolenaar | 1a47ae3 | 2019-12-29 23:04:25 +0100 | [diff] [blame] | 369 | max = get_maxbacktrace_level(sname); |
| 370 | if (sname != NULL) |
Bram Moolenaar | eead75c | 2019-04-21 11:35:00 +0200 | [diff] [blame] | 371 | { |
Bram Moolenaar | 1a47ae3 | 2019-12-29 23:04:25 +0100 | [diff] [blame] | 372 | cur = (char *)sname; |
Bram Moolenaar | eead75c | 2019-04-21 11:35:00 +0200 | [diff] [blame] | 373 | while (!got_int) |
| 374 | { |
| 375 | next = strstr(cur, ".."); |
| 376 | if (next != NULL) |
| 377 | *next = NUL; |
| 378 | if (i == max - debug_backtrace_level) |
| 379 | smsg("->%d %s", max - i, cur); |
| 380 | else |
| 381 | smsg(" %d %s", max - i, cur); |
| 382 | ++i; |
| 383 | if (next == NULL) |
| 384 | break; |
| 385 | *next = '.'; |
| 386 | cur = next + 2; |
| 387 | } |
Bram Moolenaar | 1a47ae3 | 2019-12-29 23:04:25 +0100 | [diff] [blame] | 388 | vim_free(sname); |
Bram Moolenaar | eead75c | 2019-04-21 11:35:00 +0200 | [diff] [blame] | 389 | } |
Bram Moolenaar | 1a47ae3 | 2019-12-29 23:04:25 +0100 | [diff] [blame] | 390 | |
| 391 | if (SOURCING_LNUM != 0) |
| 392 | smsg(_("line %ld: %s"), (long)SOURCING_LNUM, cmd); |
Bram Moolenaar | eead75c | 2019-04-21 11:35:00 +0200 | [diff] [blame] | 393 | else |
| 394 | smsg(_("cmd: %s"), cmd); |
| 395 | } |
| 396 | |
| 397 | /* |
| 398 | * ":debug". |
| 399 | */ |
| 400 | void |
| 401 | ex_debug(exarg_T *eap) |
| 402 | { |
| 403 | int debug_break_level_save = debug_break_level; |
| 404 | |
| 405 | debug_break_level = 9999; |
| 406 | do_cmdline_cmd(eap->arg); |
| 407 | debug_break_level = debug_break_level_save; |
| 408 | } |
| 409 | |
| 410 | static char_u *debug_breakpoint_name = NULL; |
| 411 | static linenr_T debug_breakpoint_lnum; |
| 412 | |
| 413 | /* |
| 414 | * When debugging or a breakpoint is set on a skipped command, no debug prompt |
| 415 | * is shown by do_one_cmd(). This situation is indicated by debug_skipped, and |
| 416 | * debug_skipped_name is then set to the source name in the breakpoint case. If |
| 417 | * a skipped command decides itself that a debug prompt should be displayed, it |
| 418 | * can do so by calling dbg_check_skipped(). |
| 419 | */ |
| 420 | static int debug_skipped; |
| 421 | static char_u *debug_skipped_name; |
| 422 | |
| 423 | /* |
| 424 | * Go to debug mode when a breakpoint was encountered or "ex_nesting_level" is |
| 425 | * at or below the break level. But only when the line is actually |
| 426 | * executed. Return TRUE and set breakpoint_name for skipped commands that |
| 427 | * decide to execute something themselves. |
| 428 | * Called from do_one_cmd() before executing a command. |
| 429 | */ |
| 430 | void |
| 431 | dbg_check_breakpoint(exarg_T *eap) |
| 432 | { |
| 433 | char_u *p; |
| 434 | |
| 435 | debug_skipped = FALSE; |
| 436 | if (debug_breakpoint_name != NULL) |
| 437 | { |
| 438 | if (!eap->skip) |
| 439 | { |
Bram Moolenaar | 31fc39e | 2019-04-23 18:39:49 +0200 | [diff] [blame] | 440 | // replace K_SNR with "<SNR>" |
Bram Moolenaar | eead75c | 2019-04-21 11:35:00 +0200 | [diff] [blame] | 441 | if (debug_breakpoint_name[0] == K_SPECIAL |
| 442 | && debug_breakpoint_name[1] == KS_EXTRA |
| 443 | && debug_breakpoint_name[2] == (int)KE_SNR) |
| 444 | p = (char_u *)"<SNR>"; |
| 445 | else |
| 446 | p = (char_u *)""; |
| 447 | smsg(_("Breakpoint in \"%s%s\" line %ld"), |
| 448 | p, |
| 449 | debug_breakpoint_name + (*p == NUL ? 0 : 3), |
| 450 | (long)debug_breakpoint_lnum); |
| 451 | debug_breakpoint_name = NULL; |
| 452 | do_debug(eap->cmd); |
| 453 | } |
| 454 | else |
| 455 | { |
| 456 | debug_skipped = TRUE; |
| 457 | debug_skipped_name = debug_breakpoint_name; |
| 458 | debug_breakpoint_name = NULL; |
| 459 | } |
| 460 | } |
| 461 | else if (ex_nesting_level <= debug_break_level) |
| 462 | { |
| 463 | if (!eap->skip) |
| 464 | do_debug(eap->cmd); |
| 465 | else |
| 466 | { |
| 467 | debug_skipped = TRUE; |
| 468 | debug_skipped_name = NULL; |
| 469 | } |
| 470 | } |
| 471 | } |
| 472 | |
| 473 | /* |
| 474 | * Go to debug mode if skipped by dbg_check_breakpoint() because eap->skip was |
| 475 | * set. Return TRUE when the debug mode is entered this time. |
| 476 | */ |
| 477 | int |
| 478 | dbg_check_skipped(exarg_T *eap) |
| 479 | { |
| 480 | int prev_got_int; |
| 481 | |
| 482 | if (debug_skipped) |
| 483 | { |
Bram Moolenaar | 31fc39e | 2019-04-23 18:39:49 +0200 | [diff] [blame] | 484 | // Save the value of got_int and reset it. We don't want a previous |
| 485 | // interruption cause flushing the input buffer. |
Bram Moolenaar | eead75c | 2019-04-21 11:35:00 +0200 | [diff] [blame] | 486 | prev_got_int = got_int; |
| 487 | got_int = FALSE; |
| 488 | debug_breakpoint_name = debug_skipped_name; |
Bram Moolenaar | 31fc39e | 2019-04-23 18:39:49 +0200 | [diff] [blame] | 489 | // eap->skip is TRUE |
Bram Moolenaar | eead75c | 2019-04-21 11:35:00 +0200 | [diff] [blame] | 490 | eap->skip = FALSE; |
| 491 | (void)dbg_check_breakpoint(eap); |
| 492 | eap->skip = TRUE; |
| 493 | got_int |= prev_got_int; |
| 494 | return TRUE; |
| 495 | } |
| 496 | return FALSE; |
| 497 | } |
| 498 | |
| 499 | /* |
| 500 | * The list of breakpoints: dbg_breakp. |
| 501 | * This is a grow-array of structs. |
| 502 | */ |
| 503 | struct debuggy |
| 504 | { |
Bram Moolenaar | 31fc39e | 2019-04-23 18:39:49 +0200 | [diff] [blame] | 505 | int dbg_nr; // breakpoint number |
| 506 | int dbg_type; // DBG_FUNC, DBG_FILE or DBG_EXPR |
| 507 | char_u *dbg_name; // function, expression or file name |
| 508 | regprog_T *dbg_prog; // regexp program |
| 509 | linenr_T dbg_lnum; // line number in function or file |
| 510 | int dbg_forceit; // ! used |
Bram Moolenaar | eead75c | 2019-04-21 11:35:00 +0200 | [diff] [blame] | 511 | #ifdef FEAT_EVAL |
Bram Moolenaar | 31fc39e | 2019-04-23 18:39:49 +0200 | [diff] [blame] | 512 | typval_T *dbg_val; // last result of watchexpression |
Bram Moolenaar | eead75c | 2019-04-21 11:35:00 +0200 | [diff] [blame] | 513 | #endif |
Bram Moolenaar | 31fc39e | 2019-04-23 18:39:49 +0200 | [diff] [blame] | 514 | int dbg_level; // stored nested level for expr |
Bram Moolenaar | eead75c | 2019-04-21 11:35:00 +0200 | [diff] [blame] | 515 | }; |
| 516 | |
| 517 | static garray_T dbg_breakp = {0, 0, sizeof(struct debuggy), 4, NULL}; |
| 518 | #define BREAKP(idx) (((struct debuggy *)dbg_breakp.ga_data)[idx]) |
| 519 | #define DEBUGGY(gap, idx) (((struct debuggy *)gap->ga_data)[idx]) |
Bram Moolenaar | 31fc39e | 2019-04-23 18:39:49 +0200 | [diff] [blame] | 520 | static int last_breakp = 0; // nr of last defined breakpoint |
Bram Moolenaar | eead75c | 2019-04-21 11:35:00 +0200 | [diff] [blame] | 521 | |
| 522 | #ifdef FEAT_PROFILE |
Bram Moolenaar | 31fc39e | 2019-04-23 18:39:49 +0200 | [diff] [blame] | 523 | // Profiling uses file and func names similar to breakpoints. |
Bram Moolenaar | eead75c | 2019-04-21 11:35:00 +0200 | [diff] [blame] | 524 | static garray_T prof_ga = {0, 0, sizeof(struct debuggy), 4, NULL}; |
| 525 | #endif |
| 526 | #define DBG_FUNC 1 |
| 527 | #define DBG_FILE 2 |
| 528 | #define DBG_EXPR 3 |
| 529 | |
| 530 | static linenr_T debuggy_find(int file,char_u *fname, linenr_T after, garray_T *gap, int *fp); |
| 531 | |
| 532 | /* |
| 533 | * Parse the arguments of ":profile", ":breakadd" or ":breakdel" and put them |
| 534 | * in the entry just after the last one in dbg_breakp. Note that "dbg_name" |
| 535 | * is allocated. |
| 536 | * Returns FAIL for failure. |
| 537 | */ |
| 538 | static int |
| 539 | dbg_parsearg( |
| 540 | char_u *arg, |
Bram Moolenaar | 31fc39e | 2019-04-23 18:39:49 +0200 | [diff] [blame] | 541 | garray_T *gap) // either &dbg_breakp or &prof_ga |
Bram Moolenaar | eead75c | 2019-04-21 11:35:00 +0200 | [diff] [blame] | 542 | { |
| 543 | char_u *p = arg; |
| 544 | char_u *q; |
| 545 | struct debuggy *bp; |
| 546 | int here = FALSE; |
| 547 | |
| 548 | if (ga_grow(gap, 1) == FAIL) |
| 549 | return FAIL; |
| 550 | bp = &DEBUGGY(gap, gap->ga_len); |
| 551 | |
Bram Moolenaar | 31fc39e | 2019-04-23 18:39:49 +0200 | [diff] [blame] | 552 | // Find "func" or "file". |
Bram Moolenaar | eead75c | 2019-04-21 11:35:00 +0200 | [diff] [blame] | 553 | if (STRNCMP(p, "func", 4) == 0) |
| 554 | bp->dbg_type = DBG_FUNC; |
| 555 | else if (STRNCMP(p, "file", 4) == 0) |
| 556 | bp->dbg_type = DBG_FILE; |
| 557 | else if ( |
| 558 | #ifdef FEAT_PROFILE |
| 559 | gap != &prof_ga && |
| 560 | #endif |
| 561 | STRNCMP(p, "here", 4) == 0) |
| 562 | { |
| 563 | if (curbuf->b_ffname == NULL) |
| 564 | { |
Bram Moolenaar | e29a27f | 2021-07-20 21:07:36 +0200 | [diff] [blame] | 565 | emsg(_(e_no_file_name)); |
Bram Moolenaar | eead75c | 2019-04-21 11:35:00 +0200 | [diff] [blame] | 566 | return FAIL; |
| 567 | } |
| 568 | bp->dbg_type = DBG_FILE; |
| 569 | here = TRUE; |
| 570 | } |
| 571 | else if ( |
| 572 | #ifdef FEAT_PROFILE |
| 573 | gap != &prof_ga && |
| 574 | #endif |
| 575 | STRNCMP(p, "expr", 4) == 0) |
| 576 | bp->dbg_type = DBG_EXPR; |
| 577 | else |
| 578 | { |
| 579 | semsg(_(e_invarg2), p); |
| 580 | return FAIL; |
| 581 | } |
| 582 | p = skipwhite(p + 4); |
| 583 | |
Bram Moolenaar | 31fc39e | 2019-04-23 18:39:49 +0200 | [diff] [blame] | 584 | // Find optional line number. |
Bram Moolenaar | eead75c | 2019-04-21 11:35:00 +0200 | [diff] [blame] | 585 | if (here) |
| 586 | bp->dbg_lnum = curwin->w_cursor.lnum; |
| 587 | else if ( |
| 588 | #ifdef FEAT_PROFILE |
| 589 | gap != &prof_ga && |
| 590 | #endif |
| 591 | VIM_ISDIGIT(*p)) |
| 592 | { |
| 593 | bp->dbg_lnum = getdigits(&p); |
| 594 | p = skipwhite(p); |
| 595 | } |
| 596 | else |
| 597 | bp->dbg_lnum = 0; |
| 598 | |
Bram Moolenaar | 31fc39e | 2019-04-23 18:39:49 +0200 | [diff] [blame] | 599 | // Find the function or file name. Don't accept a function name with (). |
Bram Moolenaar | eead75c | 2019-04-21 11:35:00 +0200 | [diff] [blame] | 600 | if ((!here && *p == NUL) |
| 601 | || (here && *p != NUL) |
| 602 | || (bp->dbg_type == DBG_FUNC && strstr((char *)p, "()") != NULL)) |
| 603 | { |
| 604 | semsg(_(e_invarg2), arg); |
| 605 | return FAIL; |
| 606 | } |
| 607 | |
| 608 | if (bp->dbg_type == DBG_FUNC) |
Bram Moolenaar | 4f8f542 | 2021-06-20 19:28:14 +0200 | [diff] [blame] | 609 | bp->dbg_name = vim_strsave(STRNCMP(p, "g:", 2) == 0 ? p + 2 : p); |
Bram Moolenaar | eead75c | 2019-04-21 11:35:00 +0200 | [diff] [blame] | 610 | else if (here) |
| 611 | bp->dbg_name = vim_strsave(curbuf->b_ffname); |
| 612 | else if (bp->dbg_type == DBG_EXPR) |
| 613 | { |
| 614 | bp->dbg_name = vim_strsave(p); |
| 615 | if (bp->dbg_name != NULL) |
| 616 | bp->dbg_val = eval_expr(bp->dbg_name, NULL); |
| 617 | } |
| 618 | else |
| 619 | { |
Bram Moolenaar | 31fc39e | 2019-04-23 18:39:49 +0200 | [diff] [blame] | 620 | // Expand the file name in the same way as do_source(). This means |
| 621 | // doing it twice, so that $DIR/file gets expanded when $DIR is |
| 622 | // "~/dir". |
Bram Moolenaar | eead75c | 2019-04-21 11:35:00 +0200 | [diff] [blame] | 623 | q = expand_env_save(p); |
| 624 | if (q == NULL) |
| 625 | return FAIL; |
| 626 | p = expand_env_save(q); |
| 627 | vim_free(q); |
| 628 | if (p == NULL) |
| 629 | return FAIL; |
| 630 | if (*p != '*') |
| 631 | { |
| 632 | bp->dbg_name = fix_fname(p); |
| 633 | vim_free(p); |
| 634 | } |
| 635 | else |
| 636 | bp->dbg_name = p; |
| 637 | } |
| 638 | |
| 639 | if (bp->dbg_name == NULL) |
| 640 | return FAIL; |
| 641 | return OK; |
| 642 | } |
| 643 | |
| 644 | /* |
| 645 | * ":breakadd". Also used for ":profile". |
| 646 | */ |
| 647 | void |
| 648 | ex_breakadd(exarg_T *eap) |
| 649 | { |
| 650 | struct debuggy *bp; |
| 651 | char_u *pat; |
| 652 | garray_T *gap; |
| 653 | |
| 654 | gap = &dbg_breakp; |
| 655 | #ifdef FEAT_PROFILE |
| 656 | if (eap->cmdidx == CMD_profile) |
| 657 | gap = &prof_ga; |
| 658 | #endif |
| 659 | |
| 660 | if (dbg_parsearg(eap->arg, gap) == OK) |
| 661 | { |
| 662 | bp = &DEBUGGY(gap, gap->ga_len); |
| 663 | bp->dbg_forceit = eap->forceit; |
| 664 | |
| 665 | if (bp->dbg_type != DBG_EXPR) |
| 666 | { |
| 667 | pat = file_pat_to_reg_pat(bp->dbg_name, NULL, NULL, FALSE); |
| 668 | if (pat != NULL) |
| 669 | { |
| 670 | bp->dbg_prog = vim_regcomp(pat, RE_MAGIC + RE_STRING); |
| 671 | vim_free(pat); |
| 672 | } |
| 673 | if (pat == NULL || bp->dbg_prog == NULL) |
| 674 | vim_free(bp->dbg_name); |
| 675 | else |
| 676 | { |
Bram Moolenaar | 31fc39e | 2019-04-23 18:39:49 +0200 | [diff] [blame] | 677 | if (bp->dbg_lnum == 0) // default line number is 1 |
Bram Moolenaar | eead75c | 2019-04-21 11:35:00 +0200 | [diff] [blame] | 678 | bp->dbg_lnum = 1; |
| 679 | #ifdef FEAT_PROFILE |
| 680 | if (eap->cmdidx != CMD_profile) |
| 681 | #endif |
| 682 | { |
| 683 | DEBUGGY(gap, gap->ga_len).dbg_nr = ++last_breakp; |
| 684 | ++debug_tick; |
| 685 | } |
| 686 | ++gap->ga_len; |
| 687 | } |
| 688 | } |
| 689 | else |
| 690 | { |
Bram Moolenaar | 31fc39e | 2019-04-23 18:39:49 +0200 | [diff] [blame] | 691 | // DBG_EXPR |
Bram Moolenaar | eead75c | 2019-04-21 11:35:00 +0200 | [diff] [blame] | 692 | DEBUGGY(gap, gap->ga_len++).dbg_nr = ++last_breakp; |
| 693 | ++debug_tick; |
| 694 | } |
| 695 | } |
| 696 | } |
| 697 | |
| 698 | /* |
| 699 | * ":debuggreedy". |
| 700 | */ |
| 701 | void |
| 702 | ex_debuggreedy(exarg_T *eap) |
| 703 | { |
| 704 | if (eap->addr_count == 0 || eap->line2 != 0) |
| 705 | debug_greedy = TRUE; |
| 706 | else |
| 707 | debug_greedy = FALSE; |
| 708 | } |
| 709 | |
| 710 | /* |
| 711 | * ":breakdel" and ":profdel". |
| 712 | */ |
| 713 | void |
| 714 | ex_breakdel(exarg_T *eap) |
| 715 | { |
| 716 | struct debuggy *bp, *bpi; |
| 717 | int nr; |
| 718 | int todel = -1; |
| 719 | int del_all = FALSE; |
| 720 | int i; |
| 721 | linenr_T best_lnum = 0; |
| 722 | garray_T *gap; |
| 723 | |
| 724 | gap = &dbg_breakp; |
| 725 | if (eap->cmdidx == CMD_profdel) |
| 726 | { |
| 727 | #ifdef FEAT_PROFILE |
| 728 | gap = &prof_ga; |
| 729 | #else |
| 730 | ex_ni(eap); |
| 731 | return; |
| 732 | #endif |
| 733 | } |
| 734 | |
| 735 | if (vim_isdigit(*eap->arg)) |
| 736 | { |
Bram Moolenaar | 31fc39e | 2019-04-23 18:39:49 +0200 | [diff] [blame] | 737 | // ":breakdel {nr}" |
Bram Moolenaar | eead75c | 2019-04-21 11:35:00 +0200 | [diff] [blame] | 738 | nr = atol((char *)eap->arg); |
| 739 | for (i = 0; i < gap->ga_len; ++i) |
| 740 | if (DEBUGGY(gap, i).dbg_nr == nr) |
| 741 | { |
| 742 | todel = i; |
| 743 | break; |
| 744 | } |
| 745 | } |
| 746 | else if (*eap->arg == '*') |
| 747 | { |
| 748 | todel = 0; |
| 749 | del_all = TRUE; |
| 750 | } |
| 751 | else |
| 752 | { |
Bram Moolenaar | 31fc39e | 2019-04-23 18:39:49 +0200 | [diff] [blame] | 753 | // ":breakdel {func|file|expr} [lnum] {name}" |
Bram Moolenaar | eead75c | 2019-04-21 11:35:00 +0200 | [diff] [blame] | 754 | if (dbg_parsearg(eap->arg, gap) == FAIL) |
| 755 | return; |
| 756 | bp = &DEBUGGY(gap, gap->ga_len); |
| 757 | for (i = 0; i < gap->ga_len; ++i) |
| 758 | { |
| 759 | bpi = &DEBUGGY(gap, i); |
| 760 | if (bp->dbg_type == bpi->dbg_type |
| 761 | && STRCMP(bp->dbg_name, bpi->dbg_name) == 0 |
| 762 | && (bp->dbg_lnum == bpi->dbg_lnum |
| 763 | || (bp->dbg_lnum == 0 |
| 764 | && (best_lnum == 0 |
| 765 | || bpi->dbg_lnum < best_lnum)))) |
| 766 | { |
| 767 | todel = i; |
| 768 | best_lnum = bpi->dbg_lnum; |
| 769 | } |
| 770 | } |
| 771 | vim_free(bp->dbg_name); |
| 772 | } |
| 773 | |
| 774 | if (todel < 0) |
| 775 | semsg(_("E161: Breakpoint not found: %s"), eap->arg); |
| 776 | else |
| 777 | { |
| 778 | while (gap->ga_len > 0) |
| 779 | { |
| 780 | vim_free(DEBUGGY(gap, todel).dbg_name); |
| 781 | #ifdef FEAT_EVAL |
| 782 | if (DEBUGGY(gap, todel).dbg_type == DBG_EXPR |
| 783 | && DEBUGGY(gap, todel).dbg_val != NULL) |
| 784 | free_tv(DEBUGGY(gap, todel).dbg_val); |
| 785 | #endif |
| 786 | vim_regfree(DEBUGGY(gap, todel).dbg_prog); |
| 787 | --gap->ga_len; |
| 788 | if (todel < gap->ga_len) |
| 789 | mch_memmove(&DEBUGGY(gap, todel), &DEBUGGY(gap, todel + 1), |
| 790 | (gap->ga_len - todel) * sizeof(struct debuggy)); |
| 791 | #ifdef FEAT_PROFILE |
| 792 | if (eap->cmdidx == CMD_breakdel) |
| 793 | #endif |
| 794 | ++debug_tick; |
| 795 | if (!del_all) |
| 796 | break; |
| 797 | } |
| 798 | |
Bram Moolenaar | 31fc39e | 2019-04-23 18:39:49 +0200 | [diff] [blame] | 799 | // If all breakpoints were removed clear the array. |
Bram Moolenaar | eead75c | 2019-04-21 11:35:00 +0200 | [diff] [blame] | 800 | if (gap->ga_len == 0) |
| 801 | ga_clear(gap); |
| 802 | } |
| 803 | } |
| 804 | |
| 805 | /* |
| 806 | * ":breaklist". |
| 807 | */ |
| 808 | void |
| 809 | ex_breaklist(exarg_T *eap UNUSED) |
| 810 | { |
| 811 | struct debuggy *bp; |
| 812 | int i; |
| 813 | |
| 814 | if (dbg_breakp.ga_len == 0) |
| 815 | msg(_("No breakpoints defined")); |
| 816 | else |
| 817 | for (i = 0; i < dbg_breakp.ga_len; ++i) |
| 818 | { |
| 819 | bp = &BREAKP(i); |
| 820 | if (bp->dbg_type == DBG_FILE) |
| 821 | home_replace(NULL, bp->dbg_name, NameBuff, MAXPATHL, TRUE); |
| 822 | if (bp->dbg_type != DBG_EXPR) |
| 823 | smsg(_("%3d %s %s line %ld"), |
| 824 | bp->dbg_nr, |
| 825 | bp->dbg_type == DBG_FUNC ? "func" : "file", |
| 826 | bp->dbg_type == DBG_FUNC ? bp->dbg_name : NameBuff, |
| 827 | (long)bp->dbg_lnum); |
| 828 | else |
| 829 | smsg(_("%3d expr %s"), |
| 830 | bp->dbg_nr, bp->dbg_name); |
| 831 | } |
| 832 | } |
| 833 | |
| 834 | /* |
| 835 | * Find a breakpoint for a function or sourced file. |
| 836 | * Returns line number at which to break; zero when no matching breakpoint. |
| 837 | */ |
| 838 | linenr_T |
| 839 | dbg_find_breakpoint( |
Bram Moolenaar | 31fc39e | 2019-04-23 18:39:49 +0200 | [diff] [blame] | 840 | int file, // TRUE for a file, FALSE for a function |
| 841 | char_u *fname, // file or function name |
| 842 | linenr_T after) // after this line number |
Bram Moolenaar | eead75c | 2019-04-21 11:35:00 +0200 | [diff] [blame] | 843 | { |
| 844 | return debuggy_find(file, fname, after, &dbg_breakp, NULL); |
| 845 | } |
| 846 | |
| 847 | #if defined(FEAT_PROFILE) || defined(PROTO) |
| 848 | /* |
| 849 | * Return TRUE if profiling is on for a function or sourced file. |
| 850 | */ |
| 851 | int |
| 852 | has_profiling( |
Bram Moolenaar | 31fc39e | 2019-04-23 18:39:49 +0200 | [diff] [blame] | 853 | int file, // TRUE for a file, FALSE for a function |
| 854 | char_u *fname, // file or function name |
| 855 | int *fp) // return: forceit |
Bram Moolenaar | eead75c | 2019-04-21 11:35:00 +0200 | [diff] [blame] | 856 | { |
| 857 | return (debuggy_find(file, fname, (linenr_T)0, &prof_ga, fp) |
| 858 | != (linenr_T)0); |
| 859 | } |
| 860 | #endif |
| 861 | |
| 862 | /* |
| 863 | * Common code for dbg_find_breakpoint() and has_profiling(). |
| 864 | */ |
| 865 | static linenr_T |
| 866 | debuggy_find( |
Bram Moolenaar | b204990 | 2021-01-24 12:53:53 +0100 | [diff] [blame] | 867 | int is_file, // TRUE for a file, FALSE for a function |
Bram Moolenaar | 31fc39e | 2019-04-23 18:39:49 +0200 | [diff] [blame] | 868 | char_u *fname, // file or function name |
| 869 | linenr_T after, // after this line number |
| 870 | garray_T *gap, // either &dbg_breakp or &prof_ga |
| 871 | int *fp) // if not NULL: return forceit |
Bram Moolenaar | eead75c | 2019-04-21 11:35:00 +0200 | [diff] [blame] | 872 | { |
| 873 | struct debuggy *bp; |
| 874 | int i; |
| 875 | linenr_T lnum = 0; |
Bram Moolenaar | b204990 | 2021-01-24 12:53:53 +0100 | [diff] [blame] | 876 | char_u *name = NULL; |
| 877 | char_u *short_name = fname; |
Bram Moolenaar | eead75c | 2019-04-21 11:35:00 +0200 | [diff] [blame] | 878 | int prev_got_int; |
| 879 | |
Bram Moolenaar | 31fc39e | 2019-04-23 18:39:49 +0200 | [diff] [blame] | 880 | // Return quickly when there are no breakpoints. |
Bram Moolenaar | eead75c | 2019-04-21 11:35:00 +0200 | [diff] [blame] | 881 | if (gap->ga_len == 0) |
| 882 | return (linenr_T)0; |
| 883 | |
Bram Moolenaar | b204990 | 2021-01-24 12:53:53 +0100 | [diff] [blame] | 884 | // For a script-local function remove the prefix, so that |
| 885 | // "profile func Func" matches "Func" in any script. Otherwise it's very |
| 886 | // difficult to profile/debug a script-local function. It may match a |
| 887 | // function in the wrong script, but that is much better than not being |
| 888 | // able to profile/debug a function in a script with unknown ID. |
| 889 | // Also match a script-specific name. |
| 890 | if (!is_file && fname[0] == K_SPECIAL) |
Bram Moolenaar | eead75c | 2019-04-21 11:35:00 +0200 | [diff] [blame] | 891 | { |
Bram Moolenaar | b204990 | 2021-01-24 12:53:53 +0100 | [diff] [blame] | 892 | short_name = vim_strchr(fname, '_') + 1; |
Bram Moolenaar | 964b374 | 2019-05-24 18:54:09 +0200 | [diff] [blame] | 893 | name = alloc(STRLEN(fname) + 3); |
Bram Moolenaar | b204990 | 2021-01-24 12:53:53 +0100 | [diff] [blame] | 894 | if (name != NULL) |
Bram Moolenaar | eead75c | 2019-04-21 11:35:00 +0200 | [diff] [blame] | 895 | { |
| 896 | STRCPY(name, "<SNR>"); |
| 897 | STRCPY(name + 5, fname + 3); |
| 898 | } |
| 899 | } |
| 900 | |
| 901 | for (i = 0; i < gap->ga_len; ++i) |
| 902 | { |
Bram Moolenaar | 31fc39e | 2019-04-23 18:39:49 +0200 | [diff] [blame] | 903 | // Skip entries that are not useful or are for a line that is beyond |
| 904 | // an already found breakpoint. |
Bram Moolenaar | eead75c | 2019-04-21 11:35:00 +0200 | [diff] [blame] | 905 | bp = &DEBUGGY(gap, i); |
Bram Moolenaar | b204990 | 2021-01-24 12:53:53 +0100 | [diff] [blame] | 906 | if (((bp->dbg_type == DBG_FILE) == is_file |
| 907 | && bp->dbg_type != DBG_EXPR && ( |
Bram Moolenaar | eead75c | 2019-04-21 11:35:00 +0200 | [diff] [blame] | 908 | #ifdef FEAT_PROFILE |
| 909 | gap == &prof_ga || |
| 910 | #endif |
| 911 | (bp->dbg_lnum > after && (lnum == 0 || bp->dbg_lnum < lnum))))) |
| 912 | { |
Bram Moolenaar | 31fc39e | 2019-04-23 18:39:49 +0200 | [diff] [blame] | 913 | // Save the value of got_int and reset it. We don't want a |
| 914 | // previous interruption cancel matching, only hitting CTRL-C |
| 915 | // while matching should abort it. |
Bram Moolenaar | eead75c | 2019-04-21 11:35:00 +0200 | [diff] [blame] | 916 | prev_got_int = got_int; |
| 917 | got_int = FALSE; |
Bram Moolenaar | b204990 | 2021-01-24 12:53:53 +0100 | [diff] [blame] | 918 | if ((name != NULL |
| 919 | && vim_regexec_prog(&bp->dbg_prog, FALSE, name, (colnr_T)0)) |
| 920 | || vim_regexec_prog(&bp->dbg_prog, FALSE, |
| 921 | short_name, (colnr_T)0)) |
Bram Moolenaar | eead75c | 2019-04-21 11:35:00 +0200 | [diff] [blame] | 922 | { |
| 923 | lnum = bp->dbg_lnum; |
| 924 | if (fp != NULL) |
| 925 | *fp = bp->dbg_forceit; |
| 926 | } |
| 927 | got_int |= prev_got_int; |
| 928 | } |
| 929 | #ifdef FEAT_EVAL |
| 930 | else if (bp->dbg_type == DBG_EXPR) |
| 931 | { |
| 932 | typval_T *tv; |
| 933 | int line = FALSE; |
| 934 | |
| 935 | prev_got_int = got_int; |
| 936 | got_int = FALSE; |
| 937 | |
| 938 | tv = eval_expr(bp->dbg_name, NULL); |
| 939 | if (tv != NULL) |
| 940 | { |
| 941 | if (bp->dbg_val == NULL) |
| 942 | { |
Bram Moolenaar | 3445320 | 2021-01-31 13:08:38 +0100 | [diff] [blame] | 943 | debug_oldval = typval_tostring(NULL, TRUE); |
Bram Moolenaar | eead75c | 2019-04-21 11:35:00 +0200 | [diff] [blame] | 944 | bp->dbg_val = tv; |
Bram Moolenaar | 3445320 | 2021-01-31 13:08:38 +0100 | [diff] [blame] | 945 | debug_newval = typval_tostring(bp->dbg_val, TRUE); |
Bram Moolenaar | eead75c | 2019-04-21 11:35:00 +0200 | [diff] [blame] | 946 | line = TRUE; |
| 947 | } |
| 948 | else |
| 949 | { |
Bram Moolenaar | 8739607 | 2019-12-31 22:36:18 +0100 | [diff] [blame] | 950 | if (typval_compare(tv, bp->dbg_val, EXPR_IS, FALSE) == OK |
Bram Moolenaar | eead75c | 2019-04-21 11:35:00 +0200 | [diff] [blame] | 951 | && tv->vval.v_number == FALSE) |
| 952 | { |
| 953 | typval_T *v; |
| 954 | |
| 955 | line = TRUE; |
Bram Moolenaar | 3445320 | 2021-01-31 13:08:38 +0100 | [diff] [blame] | 956 | debug_oldval = typval_tostring(bp->dbg_val, TRUE); |
Bram Moolenaar | 31fc39e | 2019-04-23 18:39:49 +0200 | [diff] [blame] | 957 | // Need to evaluate again, typval_compare() overwrites |
| 958 | // "tv". |
Bram Moolenaar | eead75c | 2019-04-21 11:35:00 +0200 | [diff] [blame] | 959 | v = eval_expr(bp->dbg_name, NULL); |
Bram Moolenaar | 3445320 | 2021-01-31 13:08:38 +0100 | [diff] [blame] | 960 | debug_newval = typval_tostring(v, TRUE); |
Bram Moolenaar | eead75c | 2019-04-21 11:35:00 +0200 | [diff] [blame] | 961 | free_tv(bp->dbg_val); |
| 962 | bp->dbg_val = v; |
| 963 | } |
| 964 | free_tv(tv); |
| 965 | } |
| 966 | } |
| 967 | else if (bp->dbg_val != NULL) |
| 968 | { |
Bram Moolenaar | 3445320 | 2021-01-31 13:08:38 +0100 | [diff] [blame] | 969 | debug_oldval = typval_tostring(bp->dbg_val, TRUE); |
| 970 | debug_newval = typval_tostring(NULL, TRUE); |
Bram Moolenaar | eead75c | 2019-04-21 11:35:00 +0200 | [diff] [blame] | 971 | free_tv(bp->dbg_val); |
| 972 | bp->dbg_val = NULL; |
| 973 | line = TRUE; |
| 974 | } |
| 975 | |
| 976 | if (line) |
| 977 | { |
| 978 | lnum = after > 0 ? after : 1; |
| 979 | break; |
| 980 | } |
| 981 | |
| 982 | got_int |= prev_got_int; |
| 983 | } |
| 984 | #endif |
| 985 | } |
| 986 | if (name != fname) |
| 987 | vim_free(name); |
| 988 | |
| 989 | return lnum; |
| 990 | } |
| 991 | |
| 992 | /* |
| 993 | * Called when a breakpoint was encountered. |
| 994 | */ |
| 995 | void |
| 996 | dbg_breakpoint(char_u *name, linenr_T lnum) |
| 997 | { |
Bram Moolenaar | 31fc39e | 2019-04-23 18:39:49 +0200 | [diff] [blame] | 998 | // We need to check if this line is actually executed in do_one_cmd() |
Bram Moolenaar | eead75c | 2019-04-21 11:35:00 +0200 | [diff] [blame] | 999 | debug_breakpoint_name = name; |
| 1000 | debug_breakpoint_lnum = lnum; |
| 1001 | } |
| 1002 | #endif |