GDB (xrefs)
mi-cmd-file.c
Go to the documentation of this file.
1 /* MI Command Set - file commands.
2  Copyright (C) 2000-2018 Free Software Foundation, Inc.
3  Contributed by Cygnus Solutions (a Red Hat company).
4 
5  This file is part of GDB.
6 
7  This program is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 3 of the License, or
10  (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program. If not, see <http://www.gnu.org/licenses/>. */
19 
20 #include "defs.h"
21 #include "mi-cmds.h"
22 #include "mi-getopt.h"
23 #include "mi-interp.h"
24 #include "ui-out.h"
25 #include "symtab.h"
26 #include "source.h"
27 #include "objfiles.h"
28 #include "psymtab.h"
29 #include "solib.h"
30 #include "solist.h"
31 #include "gdb_regex.h"
32 
33 /* Return to the client the absolute path and line number of the
34  current file being executed. */
35 
36 void
37 mi_cmd_file_list_exec_source_file (const char *command, char **argv, int argc)
38 {
39  struct symtab_and_line st;
40  struct ui_out *uiout = current_uiout;
41 
42  if (!mi_valid_noargs ("-file-list-exec-source-file", argc, argv))
43  error (_("-file-list-exec-source-file: Usage: No args"));
44 
45  /* Set the default file and line, also get them. */
48 
49  /* We should always get a symtab. Apparently, filename does not
50  need to be tested for NULL. The documentation in symtab.h
51  suggests it will always be correct. */
52  if (!st.symtab)
53  error (_("-file-list-exec-source-file: No symtab"));
54 
55  /* Print to the user the line, filename and fullname. */
56  uiout->field_int ("line", st.line);
58 
59  uiout->field_string ("fullname", symtab_to_fullname (st.symtab));
60 
61  uiout->field_int ("macro-info",
63 }
64 
65 /* A callback for map_partial_symbol_filenames. */
66 
67 static void
68 print_partial_file_name (const char *filename, const char *fullname,
69  void *ignore)
70 {
71  struct ui_out *uiout = current_uiout;
72 
73  uiout->begin (ui_out_type_tuple, NULL);
74 
75  uiout->field_string ("file", filename);
76 
77  if (fullname)
78  uiout->field_string ("fullname", fullname);
79 
80  uiout->end (ui_out_type_tuple);
81 }
82 
83 void
84 mi_cmd_file_list_exec_source_files (const char *command, char **argv, int argc)
85 {
86  struct ui_out *uiout = current_uiout;
87  struct compunit_symtab *cu;
88  struct symtab *s;
89  struct objfile *objfile;
90 
91  if (!mi_valid_noargs ("-file-list-exec-source-files", argc, argv))
92  error (_("-file-list-exec-source-files: Usage: No args"));
93 
94  /* Print the table header. */
95  uiout->begin (ui_out_type_list, "files");
96 
97  /* Look at all of the file symtabs. */
98  ALL_FILETABS (objfile, cu, s)
99  {
100  uiout->begin (ui_out_type_tuple, NULL);
101 
102  uiout->field_string ("file", symtab_to_filename_for_display (s));
103  uiout->field_string ("fullname", symtab_to_fullname (s));
104 
105  uiout->end (ui_out_type_tuple);
106  }
107 
109  1 /*need_fullname*/);
110 
111  uiout->end (ui_out_type_list);
112 }
113 
114 /* See mi-cmds.h. */
115 
116 void
117 mi_cmd_file_list_shared_libraries (const char *command, char **argv, int argc)
118 {
119  struct ui_out *uiout = current_uiout;
120  const char *pattern;
121  struct so_list *so = NULL;
122 
123  switch (argc)
124  {
125  case 0:
126  pattern = NULL;
127  break;
128  case 1:
129  pattern = argv[0];
130  break;
131  default:
132  error (_("Usage: -file-list-shared-libraries [REGEXP]"));
133  }
134 
135  if (pattern != NULL)
136  {
137  const char *re_err = re_comp (pattern);
138 
139  if (re_err != NULL)
140  error (_("Invalid regexp: %s"), re_err);
141  }
142 
143  update_solib_list (1);
144 
145  /* Print the table header. */
146  ui_out_emit_list list_emitter (uiout, "shared-libraries");
147 
148  ALL_SO_LIBS (so)
149  {
150  if (so->so_name[0] == '\0')
151  continue;
152  if (pattern != NULL && !re_exec (so->so_name))
153  continue;
154 
155  ui_out_emit_tuple tuple_emitter (uiout, NULL);
156  mi_output_solib_attribs (uiout, so);
157  }
158 }
const char * symtab_to_filename_for_display(struct symtab *symtab)
Definition: source.c:1168
#define SYMTAB_COMPUNIT(symtab)
Definition: symtab.h:1331
void mi_cmd_file_list_exec_source_file(const char *command, char **argv, int argc)
Definition: mi-cmd-file.c:37
void field_string(const char *fldname, const char *string)
Definition: ui-out.c:544
void set_default_source_symtab_and_line(void)
Definition: source.c:193
void map_symbol_filenames(symbol_filename_ftype *fun, void *data, int need_fullname)
Definition: symfile.c:3826
struct symtab_and_line get_current_source_symtab_and_line(void)
Definition: source.c:171
#define COMPUNIT_MACRO_TABLE(cust)
Definition: symtab.h:1470
Definition: solist.h:38
#define _(String)
Definition: gdb_locale.h:35
const char * symtab_to_fullname(struct symtab *s)
Definition: source.c:1131
void mi_cmd_file_list_shared_libraries(const char *command, char **argv, int argc)
Definition: mi-cmd-file.c:117
void mi_output_solib_attribs(ui_out *uiout, struct so_list *solib)
Definition: mi-interp.c:1064
void end(ui_out_type type)
Definition: ui-out.c:434
objfile(bfd *, const char *, objfile_flags)
Definition: objfiles.c:373
void mi_cmd_file_list_exec_source_files(const char *command, char **argv, int argc)
Definition: mi-cmd-file.c:84
#define current_uiout
Definition: ui-out.h:39
char so_name[SO_NAME_MAX_PATH_SIZE]
Definition: solist.h:60
int mi_valid_noargs(const char *prefix, int argc, char **argv)
Definition: mi-getopt.c:99
struct symtab * symtab
Definition: symtab.h:1751
static void print_partial_file_name(const char *filename, const char *fullname, void *ignore)
Definition: mi-cmd-file.c:68
#define ALL_FILETABS(objfile, ps, s)
Definition: objfiles.h:613
void update_solib_list(int from_tty)
Definition: solib.c:747
Definition: ui-out.h:77
void field_int(const char *fldname, int value)
Definition: ui-out.c:486
EXTERN_C char * re_comp(const char *)
static int ignore(struct target_ops *ops, struct gdbarch *gdbarch, struct bp_target_info *bp_tgt)
Definition: corelow.c:879
argv
Definition: __init__.py:63
#define ALL_SO_LIBS(so)
Definition: solist.h:27
void error(const char *fmt,...)
Definition: errors.c:38
void begin(ui_out_type type, const char *id)
Definition: ui-out.c:404