Debian Codegraph @

libdebugger/command/load.c

raw symbols SCIP
1 /*
2 Copyright (C) 2020 R. Bernstein <[email protected]>
3
4 This file is part of GNU Make (remake variant).
5
6 GNU Make is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 GNU Make is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GNU Make; see the file COPYING. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
20
21 /** \file libdebugger/command/load.c
22 *
23 * \brief Debugger `load` command.
24 *
25 * Debugger command to read and evaluate a Makefile.
26 */
27
28 #include "../../src/trace.h"
29 #include "../msg.h"
30
31 #include <glob.h>
32 #include "read.h"
33 #include "filedef.h"
34
35 extern debug_return_t
36 dbg_cmd_load(char *psz_filename)
37 {
38 if (psz_filename && *psz_filename) {
39 glob_t p;
40 char *psz_expanded_file;
41 struct goaldep *p_goaldep;
42
43 glob(psz_filename, 0, NULL, &p);
44 if (0 == p.gl_pathc) {
45 struct stat stat_buf;
46 int ret = stat(psz_filename, &stat_buf);
47 if (ret != 0) {
48 dbg_errmsg("Can't find file %s:\n\t%s", psz_filename, strerror(errno));
49 return debug_cmd_error;
50 }
51 psz_expanded_file = psz_filename;
52
53 } else if (1 != p.gl_pathc) {
54 dbg_errmsg("Expansion of %s doesn't lead to a single filename. \n"
55 "Got %zu matches",
56 psz_filename, p.gl_pathc);
57 return debug_cmd_error;
58
59 } else {
60 psz_expanded_file = p.gl_pathv[0];
61 }
62
63 snapped_deps = 0;
64 p_goaldep = eval_makefile(psz_expanded_file, 0);
65
66 if (p_goaldep == NULL) {
67 dbg_errmsg("error reading Makefile %s (expanded to %s):",
68 psz_filename, psz_expanded_file);
69 snapped_deps = 1;
70 return debug_cmd_error;
71 } else {
72 snap_deps();
73 free_goaldep(p_goaldep);
74 }
75 globfree(&p);
76 } else {
77 dbg_errmsg("load command expects a filename");
78 }
79 return debug_readloop;
80 }
81
82
83 /*
84 * Local variables:
85 * eval: (c-set-style "gnu")
86 * indent-tabs-mode: nil
87 * End:
88 */