1 /* MI Command Set - symbol commands.
2 Copyright (C) 2003-2019 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program 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 3 of the License, or
9 (at your option) any later version.
11 This program 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.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
25 #include "mi-getopt.h"
27 /* Print the list of all pc addresses and lines of code for the
28 provided (full or base) source file name. The entries are sorted
29 in ascending PC order. */
32 mi_cmd_symbol_list_lines (const char *command
, char **argv
, int argc
)
34 struct gdbarch
*gdbarch
;
38 struct ui_out
*uiout
= current_uiout
;
41 error (_("-symbol-list-lines: Usage: SOURCE_FILENAME"));
44 s
= lookup_symtab (filename
);
47 error (_("-symbol-list-lines: Unknown source file name."));
49 /* Now, dump the associated line table. The pc addresses are
50 already sorted by increasing values in the symbol table, so no
51 need to perform any other sorting. */
53 gdbarch
= get_objfile_arch (SYMTAB_OBJFILE (s
));
55 ui_out_emit_list
list_emitter (uiout
, "lines");
56 if (SYMTAB_LINETABLE (s
) != NULL
&& SYMTAB_LINETABLE (s
)->nitems
> 0)
57 for (i
= 0; i
< SYMTAB_LINETABLE (s
)->nitems
; i
++)
59 ui_out_emit_tuple
tuple_emitter (uiout
, NULL
);
60 uiout
->field_core_addr ("pc", gdbarch
, SYMTAB_LINETABLE (s
)->item
[i
].pc
);
61 uiout
->field_signed ("line", SYMTAB_LINETABLE (s
)->item
[i
].line
);
65 /* Used by the -symbol-info-* and -symbol-info-module-* commands to print
66 information about the symbol SYM in a block of index BLOCK (either
67 GLOBAL_BLOCK or STATIC_BLOCK). KIND is the kind of symbol we searched
68 for in order to find SYM, which impact which fields are displayed in the
72 output_debug_symbol (ui_out
*uiout
, enum search_domain kind
,
73 struct symbol
*sym
, int block
)
75 ui_out_emit_tuple
tuple_emitter (uiout
, NULL
);
77 if (SYMBOL_LINE (sym
) != 0)
78 uiout
->field_unsigned ("line", SYMBOL_LINE (sym
));
79 uiout
->field_string ("name", sym
->print_name ());
81 if (kind
== FUNCTIONS_DOMAIN
|| kind
== VARIABLES_DOMAIN
)
83 string_file tmp_stream
;
84 type_print (SYMBOL_TYPE (sym
), "", &tmp_stream
, -1);
85 uiout
->field_string ("type", tmp_stream
.string ());
87 std::string str
= symbol_to_info_string (sym
, block
, kind
);
88 uiout
->field_string ("description", str
);
92 /* Actually output one nondebug symbol, puts a tuple emitter in place
93 and then outputs the fields for this msymbol. */
96 output_nondebug_symbol (ui_out
*uiout
,
97 const struct bound_minimal_symbol
&msymbol
)
99 struct gdbarch
*gdbarch
= get_objfile_arch (msymbol
.objfile
);
100 ui_out_emit_tuple
tuple_emitter (uiout
, NULL
);
102 uiout
->field_core_addr ("address", gdbarch
,
103 BMSYMBOL_VALUE_ADDRESS (msymbol
));
104 uiout
->field_string ("name", msymbol
.minsym
->print_name ());
107 /* This is the guts of the commands '-symbol-info-functions',
108 '-symbol-info-variables', and '-symbol-info-types'. It searches for
109 symbols matching KING, NAME_REGEXP, TYPE_REGEXP, and EXCLUDE_MINSYMS,
110 and then prints the matching [m]symbols in an MI structured format. */
113 mi_symbol_info (enum search_domain kind
, const char *name_regexp
,
114 const char *type_regexp
, bool exclude_minsyms
)
116 global_symbol_searcher
sym_search (kind
, name_regexp
);
117 sym_search
.set_symbol_type_regexp (type_regexp
);
118 sym_search
.set_exclude_minsyms (exclude_minsyms
);
119 std::vector
<symbol_search
> symbols
= sym_search
.search ();
120 ui_out
*uiout
= current_uiout
;
123 ui_out_emit_tuple
outer_symbols_emitter (uiout
, "symbols");
125 /* Debug symbols are placed first. */
126 if (i
< symbols
.size () && symbols
[i
].msymbol
.minsym
== nullptr)
128 ui_out_emit_list
debug_symbols_list_emitter (uiout
, "debug");
130 /* As long as we have debug symbols... */
131 while (i
< symbols
.size () && symbols
[i
].msymbol
.minsym
== nullptr)
133 symtab
*symtab
= symbol_symtab (symbols
[i
].symbol
);
134 ui_out_emit_tuple
symtab_tuple_emitter (uiout
, nullptr);
136 uiout
->field_string ("filename",
137 symtab_to_filename_for_display (symtab
));
138 uiout
->field_string ("fullname", symtab_to_fullname (symtab
));
140 ui_out_emit_list
symbols_list_emitter (uiout
, "symbols");
142 /* As long as we have debug symbols from this symtab... */
143 for (; (i
< symbols
.size ()
144 && symbols
[i
].msymbol
.minsym
== nullptr
145 && symbol_symtab (symbols
[i
].symbol
) == symtab
);
148 symbol_search
&s
= symbols
[i
];
150 output_debug_symbol (uiout
, kind
, s
.symbol
, s
.block
);
155 /* Non-debug symbols are placed after. */
156 if (i
< symbols
.size ())
158 ui_out_emit_list
nondebug_symbols_list_emitter (uiout
, "nondebug");
160 /* As long as we have nondebug symbols... */
161 for (; i
< symbols
.size (); i
++)
163 gdb_assert (symbols
[i
].msymbol
.minsym
!= nullptr);
164 output_nondebug_symbol (uiout
, symbols
[i
].msymbol
);
169 /* Helper for mi_cmd_symbol_info_{functions,variables} - depending on KIND.
170 Processes command line options from ARGV and ARGC. */
173 mi_info_functions_or_variables (enum search_domain kind
, char **argv
, int argc
)
175 const char *regexp
= nullptr;
176 const char *t_regexp
= nullptr;
177 bool exclude_minsyms
= true;
181 INCLUDE_NONDEBUG_OPT
, TYPE_REGEXP_OPT
, NAME_REGEXP_OPT
183 static const struct mi_opt opts
[] =
185 {"-include-nondebug" , INCLUDE_NONDEBUG_OPT
, 0},
186 {"-type", TYPE_REGEXP_OPT
, 1},
187 {"-name", NAME_REGEXP_OPT
, 1},
192 char *oarg
= nullptr;
196 const char *cmd_string
197 = ((kind
== FUNCTIONS_DOMAIN
)
198 ? "-symbol-info-functions" : "-symbol-info-variables");
199 int opt
= mi_getopt (cmd_string
, argc
, argv
, opts
, &oind
, &oarg
);
202 switch ((enum opt
) opt
)
204 case INCLUDE_NONDEBUG_OPT
:
205 exclude_minsyms
= false;
207 case TYPE_REGEXP_OPT
:
210 case NAME_REGEXP_OPT
:
216 mi_symbol_info (kind
, regexp
, t_regexp
, exclude_minsyms
);
219 /* Implement -symbol-info-functions command. */
222 mi_cmd_symbol_info_functions (const char *command
, char **argv
, int argc
)
224 mi_info_functions_or_variables (FUNCTIONS_DOMAIN
, argv
, argc
);
227 /* Implement -symbol-info-types command. */
230 mi_cmd_symbol_info_types (const char *command
, char **argv
, int argc
)
232 const char *regexp
= nullptr;
238 static const struct mi_opt opts
[] =
240 {"-name", NAME_REGEXP_OPT
, 1},
245 char *oarg
= nullptr;
249 int opt
= mi_getopt ("-symbol-info-types", argc
, argv
, opts
,
253 switch ((enum opt
) opt
)
255 case NAME_REGEXP_OPT
:
261 mi_symbol_info (TYPES_DOMAIN
, regexp
, nullptr, true);
264 /* Implement -symbol-info-variables command. */
267 mi_cmd_symbol_info_variables (const char *command
, char **argv
, int argc
)
269 mi_info_functions_or_variables (VARIABLES_DOMAIN
, argv
, argc
);
This page took 0.034617 seconds and 4 git commands to generate.