This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Fix MI -symbol-list-lines


On 10/17/2012 12:37 PM, Pedro Alves wrote:
Unfortunately, the patch is bounced back, as it does a lot of unnecessary
(and unfortunately wrong, according to the GNU coding conventions)
reformatting.

Thanks Pedro, sorry for being sloppy.  Here is an updated patch.  Also, if
I were going to provide a test for this, it would probably involve an executable
file and a script that invokes GDB in MI mode.  Does this sound like an appropriate
test?  Are there existing tests somewhere like this that I can use as an example?

A more precise description of the problem:  The previous version of -symbol-list-lines
made a call to "lookup_symtab" to find the corresponding symtab; which really only
returns the first symtab it encounters.  While in a perfect world it would be nice
if their were only one symbol table that correlated with a CU, this is not a perfect
world and sometimes more that one GDB symbol table is created for a given file.

Also, previously, -symbol-list-lines was deficient in returning a list of executable
line numbers when the symbol table had only partially been loaded.


~Jason




diff --git a/gdb/mi/mi-symbol-cmds.c b/gdb/mi/mi-symbol-cmds.c
index 2fdea91..309181c 100644
--- a/gdb/mi/mi-symbol-cmds.c
+++ b/gdb/mi/mi-symbol-cmds.c
@@ -30,36 +30,52 @@ void
mi_cmd_symbol_list_lines (char *command, char **argv, int argc)
{
struct gdbarch *gdbarch;
- char *filename;
+ const char *filename, *filebase;
struct symtab *s;
int i;
struct cleanup *cleanup_stack, *cleanup_tuple;
struct ui_out *uiout = current_uiout;
+ struct program_space *pspace = 0;
+ struct objfile *objfile = 0;
- if (argc != 1)
+ if (argc != 1 || argv[0] == '\0')
error (_("-symbol-list-lines: Usage: SOURCE_FILENAME"));
filename = argv[0];
+ filebase = lbasename(filename);
s = lookup_symtab (filename);
if (s == NULL)
error (_("-symbol-list-lines: Unknown source file name."));
+ /* This creates the "demand" for a symbol table associated with
+ "filename". Although we do not use 's', this is an important
+ step because it forces and partial symbol tables associated
+ with "filename" to be expanded into full symbol tables. */
+ find_line_symtab(s, 1, NULL, NULL);
+
/* Now, dump the associated line table. The pc addresses are
already sorted by increasing values in the symbol table, so no
need to perform any other sorting. */
gdbarch = get_objfile_arch (s->objfile);
cleanup_stack = make_cleanup_ui_out_list_begin_end (uiout, "lines");
+ pspace = current_program_space;
+
+ ALL_PSPACE_SYMTABS (pspace, objfile, s) {
+ if (!s || !s->filename || s->filename[0] == '\0')
+ continue;
- if (LINETABLE (s) != NULL && LINETABLE (s)->nitems > 0)
- for (i = 0; i < LINETABLE (s)->nitems; i++)
- {
- cleanup_tuple = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
- ui_out_field_core_addr (uiout, "pc", gdbarch, LINETABLE (s)->item[i].pc);
- ui_out_field_int (uiout, "line", LINETABLE (s)->item[i].line);
- do_cleanups (cleanup_tuple);
- }
+ if (!strcmp(filebase, lbasename(s->filename)))
+ if (LINETABLE (s) != NULL && LINETABLE (s)->nitems > 0)
+ for (i = 0; i < LINETABLE (s)->nitems; i++)
+ {
+ cleanup_tuple = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
+ ui_out_field_core_addr (uiout, "pc", gdbarch, LINETABLE (s)->item[i].pc);
+ ui_out_field_int (uiout, "line", LINETABLE (s)->item[i].line);
+ do_cleanups (cleanup_tuple);
+ }
+ }
do_cleanups (cleanup_stack);
}



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]