1 /*
2 Set a breakpoint at a target.  With a target name, set a break before
3 running commands of that target.  Without argument, list all breaks.
4 */
5 /*
6 Copyright (C) 2004-2005, 2007-2009, 2011, 2020 R. Bernstein
7 <rocky@gnu.org>
8 This file is part of GNU Make (remake variant).
9 
10 GNU Make is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2, or (at your option)
13 any later version.
14 
15 GNU Make is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 GNU General Public License for more details.
19 
20 You should have received a copy of the GNU General Public License
21 along with GNU Make; see the file COPYING.  If not, write to
22 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 Boston, MA 02111-1307, USA.  */
24 
25 static debug_return_t
dbg_cmd_break(char * psz_args)26 dbg_cmd_break (char *psz_args)
27 {
28   if (!psz_args || !*psz_args) {
29     list_breakpoints();
30     return debug_readloop;
31   } else {
32     char *psz_target = get_word(&psz_args);
33     char *psz_break_type;
34     file_t *p_target;
35     unsigned int i_brkpt_mask = BRK_NONE;
36 
37     /** FIXME: DRY with code in continue.h **/
38     if (p_stack && p_stack->p_target) {
39       unsigned int u_lineno=0;
40       f2l_entry_t entry_type;
41       if (get_uint(psz_target, &u_lineno, false)) {
42           p_target = target_for_file_and_line(p_stack->p_target->floc.filenm,
43                                               u_lineno, &entry_type);
44           if (F2L_TARGET == entry_type) {
45             if (!p_target) {
46               dbg_errmsg("Can't find target or pattern on line %s.\n"
47                          "Use 'info lines' to get a list of breakpoint lines.",
48                          psz_target);
49               return debug_cmd_error;
50             }
51           } else {
52             dbg_errmsg("No support of breakpoints on target patterns yet.");
53             return debug_cmd_error;
54           }
55       } else
56         p_target =
57           lookup_file(variable_expand_set(psz_target,
58                                             p_stack->p_target->variables));
59     } else {
60       p_target = lookup_file(psz_target);
61     }
62 
63     if (!p_target) {
64 	dbg_errmsg("Can't find target %s; breakpoint not set.", psz_target);
65 	return debug_cmd_error;
66     }
67 
68     /* FIXME: Combine with code in continue. */
69     if (!(psz_args && *psz_args))
70       i_brkpt_mask = BRK_ALL;
71     else {
72       while ((psz_break_type = get_word(&psz_args))) {
73         if (!(psz_break_type && *psz_break_type)) break;
74         i_brkpt_mask |= get_brkpt_option(psz_break_type) ;
75       }
76     }
77     add_breakpoint(p_target, i_brkpt_mask);
78   }
79 
80   return debug_readloop;
81 };
82 
83 static void
dbg_cmd_break_init(unsigned int c)84 dbg_cmd_break_init(unsigned int c)
85 {
86   short_command[c].func = &dbg_cmd_break;
87   short_command[c].use  = _("break [TARGET|LINENUM] [all|run|prereq|end]*");
88 }
89 
90 /*
91  * Local variables:
92  * eval: (c-set-style "gnu")
93  * indent-tabs-mode: nil
94  * End:
95  */
96