This is the mail archive of the gdb-patches@sources.redhat.com 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: [RFA] new GDB/MI command: -symbol-info-linetable


Thierry Schneider writes:
 > Hello,
 > 
 > To follow a suggestion made by Joel in this message:
 > http://sources.redhat.com/ml/gdb-patches/2003-03/msg00000.html
 > 
 > I have implemented in a new command that dumps the linetable
 > for a given source file. As recommended, I have made it a GDB/MI
 > command, intead of a CLI command.
 > 
 > Here is an example (from the documentation I wrote) of this command in
 > action:
 > 
 >     (gdb)
 >     -symbol-info-linetable basics.c
 >     ^done,linetable=[{pc="0x08048554",line="7"},{pc="0x0804855a",line="8"}]
 >     (gdb)
 > 
 > Here is the ChangeLog:
 > 
 > 2003-03-09  Thierry Schneider  <tpschneider1 at yahoo dot com>
 > 
 >         * mi-main.c (mi_cmd_symbol_info_linetable): New function.
 >         * mi-cmds.h (mi_cmd_symbol_info_linetable): Add declaration.
 >         * mi-cmds.c (mi_cmds): Add entry for new MI command.
 >         * gdbmi.texinfo (GDB/MI Symbol Query): Add documentation for
 >         new MI command.
 > 
 > Regarding new mi_cmd_symbol_info_linetable(), I think it should be
 > located in a new file, named mi-cmd-symbol.c. For the moment, I took
 > a simpler approach (less changes required) of putting it in mi-main.c,
 > which seems to be hosting a few orphan command implementations. But
 > I can certainly modify this patch to add this new file.
 > 

I would like to start a new mi-cmd-symbol.c file, if we decide to have
the new command in the symbol category.

 > I have also created a small testcase in gdb.mi:
 > 
 > 2003-03-09  Thierry Schneider  <tpschneider1 at yahoo dot com>
 > 
 >         * mi1-linetable.exp: New file.
 > 
 > I unfortunately do not have a valid FSF assignement on file, yet.
 > I have sent my application to the FSF, and I am waiting for the papers
 > to arrive by mail.
 > 

I think this has been sorted out now, right?

Approved, but see below for a few issues, mainly the name of the command....

 > FYI: Since I do not have the priviledge to commit these changes myself
 > if/when they are approved, Joel Brobecker has offered to do it for me.
 > 
 > Finally, those of us who are still using GDB 5.3 won't be able to use
 > this MI command from the CLI, since the interpreter command has been
 > implemented after 5.3 has been released. For these people, I hacked
 > a CLI command "-symbol-info-linetable" which produces the exact same
 > output than the equivalent MI command. This will certainly be useful
 > to the GVD developpers :-). The patch to source.c is attached.
 > 
 > Thierry S.
 > (GDB newbie)
 > Index: mi-cmds.h
 > ===================================================================
 > RCS file: /cvs/src/src/gdb/mi/mi-cmds.h,v
 > retrieving revision 1.7
 > diff -c -3 -p -r1.7 mi-cmds.h
 > *** mi-cmds.h	6 Feb 2003 01:19:12 -0000	1.7
 > --- mi-cmds.h	10 Mar 2003 00:21:50 -0000
 > *************** extern mi_cmd_argv_ftype mi_cmd_stack_li
 > *** 87,92 ****
 > --- 87,93 ----
 >   extern mi_cmd_argv_ftype mi_cmd_stack_list_frames;
 >   extern mi_cmd_argv_ftype mi_cmd_stack_list_locals;
 >   extern mi_cmd_argv_ftype mi_cmd_stack_select_frame;
 > + extern mi_cmd_argv_ftype mi_cmd_symbol_info_linetable;
 >   extern mi_cmd_args_ftype mi_cmd_target_download;
 >   extern mi_cmd_args_ftype mi_cmd_target_select;
 >   extern mi_cmd_argv_ftype mi_cmd_thread_list_ids;
 > Index: mi-cmds.c
 > ===================================================================
 > RCS file: /cvs/src/src/gdb/mi/mi-cmds.c,v
 > retrieving revision 1.10
 > diff -c -3 -p -r1.10 mi-cmds.c
 > *** mi-cmds.c	6 Feb 2003 01:19:12 -0000	1.10
 > --- mi-cmds.c	10 Mar 2003 00:21:50 -0000
 > *************** struct mi_cmd mi_cmds[] =
 > *** 116,121 ****
 > --- 116,122 ----
 >     {"symbol-info-file", 0, 0},
 >     {"symbol-info-function", 0, 0},
 >     {"symbol-info-line", 0, 0},
 > +   {"symbol-info-linetable", 0, 0, mi_cmd_symbol_info_linetable},
 >     {"symbol-info-symbol", 0, 0},
 >     {"symbol-list-functions", 0, 0},
 >     {"symbol-list-types", 0, 0},


I wonder if it would be more pertinent to call it symbol-list-lines
or make it part of the file commands, even though the distinction is blurry.

 > Index: mi-main.c
 > ===================================================================
 > RCS file: /cvs/src/src/gdb/mi/mi-main.c,v
 > retrieving revision 1.41
 > diff -c -3 -p -r1.41 mi-main.c
 > *** mi-main.c	1 Mar 2003 17:03:19 -0000	1.41
 > --- mi-main.c	10 Mar 2003 00:21:50 -0000
 > *************** mi_cmd_data_write_memory (char *command,
 > *** 1070,1075 ****
 > --- 1070,1127 ----
 >     return MI_CMD_DONE;
 >   }
 >   
 > + /* SYMBOL-INFO-LINETABLE:
 > + 
 > +    Print the table of all pc addresses and lines of code for
 > +    the provided (full or base) source file name.  The entries
 > +    are sorted in ascending PC order.  */
 > + 
 > + enum mi_cmd_result
 > + mi_cmd_symbol_info_linetable (char *command, char **argv, int argc)
 > + {
 > +   char *filename;
 > +   struct symtab *s;
 > +   int i;
 > +   struct cleanup *cleanup_stack, *cleanup_tuple;
 > +   
 > +   if (argc != 1)
 > +     {
 > +       xasprintf (&mi_error_message,
 > + 		 "Usage: %s filename.", command);
 > +       return MI_CMD_ERROR;
 > +     }
 > + 
 > +   filename = argv[0];
 > + 
 > +   s = lookup_symtab (filename);
 > + 
 > +   if (s == NULL)
 > +     {
 > +       xasprintf (&mi_error_message,
 > + 		 "Unknown source file: '%s'", filename);
 > +       return MI_CMD_ERROR;
 > +     }
 > +   
 > +   /* 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.  */
 > + 
 > +   cleanup_stack = make_cleanup_ui_out_list_begin_end (uiout, "linetable");
 > + 
 > +   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", LINETABLE (s)->item[i].pc);
 > +         ui_out_field_int (uiout, "line", LINETABLE (s)->item[i].line);
 > +         do_cleanups (cleanup_tuple);
 > +       }
 > + 
 > +   do_cleanups (cleanup_stack);
 > + 
 > +   return MI_CMD_DONE;
 > + }
 > + 
 >   /* Execute a command within a safe environment.
 >      Return <0 for error; >=0 for ok.
 >   
 > Index: gdbmi.texinfo
 > ===================================================================
 > RCS file: /cvs/src/src/gdb/mi/gdbmi.texinfo,v
 > retrieving revision 1.33
 > diff -c -3 -r1.33 gdbmi.texinfo
 > *** gdbmi.texinfo	4 Feb 2003 18:41:29 -0000	1.33
 > --- gdbmi.texinfo	10 Mar 2003 01:25:21 -0000
 > ***************
 > *** 2998,3003 ****
 > --- 2998,3029 ----
 >   N.A.
 >   
 >   
 > + @subheading The @code{-symbol-info-linetable} Command
 > + @findex -symbol-info-linetable
 > + 
 > + @subsubheading Synopsis
 > + 
 > + @example
 > +  -symbol-info-linetable @var{filename}
 > + @end example
 > + 
 > + Print the list of lines that contain code and their associated program
 > + addresses for the given source filename.  The entries are sorted in
 > + ascending PC order.
 > + 
 > + @subsubheading @value{GDBN} Command
 > + 
 > + There is no corresponding @value{GDBN} comamnd.
 > + 
 > + @subsubheading Example
 > + @smallexample
 > + (@value{GDBP})
 > + -symbol-info-linetable basics.c
 > + ^done,linetable=[{pc="0x08048554",line="7"},{pc="0x0804855a",line="8"}]
 > + (@value{GDBP})
 > + @end smallexample
 > + 
 > + 
 >   @subheading The @code{-symbol-info-symbol} Command
 >   @findex -symbol-info-symbol
 >   
 > # Copyright 1999, 2000, 2002 Free Software Foundation, Inc.
 > 


Copyright year is just 2003.


 > # This program is free software; you can redistribute it and/or modify
 > # it under the terms of the GNU General Public License as published by
 > # the Free Software Foundation; either version 2 of the License, or
 > # (at your option) any later version.
 > # 
 > # This program is distributed in the hope that it will be useful,
 > # but WITHOUT ANY WARRANTY; without even the implied warranty of
 > # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 > # GNU General Public License for more details.
 > # 
 > # You should have received a copy of the GNU General Public License
 > # along with this program; if not, write to the Free Software
 > # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  
 > 
 > # Please email any bugs, comments, and/or additions to this file to:
 > # bug-gdb at prep dot ai dot mit dot edu
 > 
 > #
 > # Test Machine interface (MI) operations for disassembly.
 > #
 > # The goal is not to test gdb functionality, which is done by other tests,
 > # but to verify the correct output response to MI operations.
 > #
 > 
 > load_lib mi-support.exp
 > set MIFLAGS "-i=mi1"
 > 
 > gdb_exit
 > if [mi_gdb_start] {
 >     continue
 > }
 > 
 > set testfile "basics"
 > set srcfile ${testfile}.c
 > set binfile ${objdir}/${subdir}/${testfile}
 > if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-DFAKEARGV}] != "" } {
 >      gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
 > }
 > 
 > mi_delete_breakpoints
 > mi_gdb_reinitialize_dir $srcdir/$subdir
 > mi_gdb_load ${binfile}
 > 

Use mi_run_to_main which does all of the above for you. I know you
don't need a running program, but, might as well.


 > proc test_linetable {} {
 >     global mi_gdb_prompt
 >     global hex
 >     global decimal
 > 
 >     # Test linetable.
 >     # Tests:
 >     # -symbol-info-linetable basics.c
 > 
 >     mi_gdb_test "-symbol-info-linetable basics.c" \

Don't use basics.c, use ${srcfile}. 

 > 	    "\\^done,linetable=\[\{pc=\"$hex\",line=\"$decimal\"\}.*\]" \
 >              "symbol-info-linetable for source file basics.c"
 > 

Same here.

 > }
 > 
 > test_linetable
 > 
 > mi_gdb_exit
 > return 0

Ok otherwise.

The below shouldn't be committed.


 > Index: source.c
 > ===================================================================
 > RCS file: /nile.c/cvs/Dev/gdb/gdb-5.3/gdb/source.c,v
 > retrieving revision 1.2
 > diff -c -3 -p -r1.2 source.c
 > *** source.c	16 Jan 2003 10:40:07 -0000	1.2
 > --- source.c	10 Mar 2003 01:41:30 -0000
 > *************** line_info (char *arg, int from_tty)
 > *** 1438,1443 ****
 > --- 1438,1477 ----
 >     xfree (sals.sals);
 >   }
 >   
 > + 
 > + /* Print the table of all pc addresses and lines of code
 > +    for the provided (full or base) source file name.  */
 > + 
 > + static void
 > + symbol_info_linetable_command (char *arg, int from_tty)
 > + {
 > +   char *filename = arg;
 > +   struct symtab *s;
 > +   int i;
 > +   
 > +   if (filename == NULL)
 > +     error ("Missing source file name");
 > + 
 > +   s = lookup_symtab (filename);
 > +  
 > +   if (s == NULL)
 > +     error ("Unknown source file");
 > +   
 > +   printf_filtered ("^done,linetable=[");
 > +   
 > +   if (LINETABLE (s) != NULL && LINETABLE (s)->nitems > 0)
 > +     for (i = 0; i < LINETABLE (s)->nitems; i++)
 > +       {
 > +         printf_filtered ("{pc=\"");
 > +         print_address_numeric (LINETABLE (s)->item[i].pc, 1, gdb_stdout);
 > +         printf_filtered ("\",line=\"%d\"}", LINETABLE (s)->item[i].line);
 > +         if (i != LINETABLE (s)->nitems - 1)
 > +           printf_filtered (",");
 > +       }
 > + 
 > +   printf_filtered ("]\n");
 > + }
 > + 
 >   /* Commands to search the source file for a regexp.  */
 >   
 >   /* ARGSUSED */
 > *************** Default is to describe the last source l
 > *** 1684,1689 ****
 > --- 1718,1726 ----
 >   This sets the default address for \"x\" to the line's first instruction\n\
 >   so that \"x/i\" suffices to start examining the machine code.\n\
 >   The address is also stored as the value of \"$_\".", NULL));
 > + 
 > +   add_cmd ("-symbol-info-linetable", no_class, symbol_info_linetable_command, 
 > +            "Print the line table for a given source file.", &cmdlist);
 >   
 >     add_com ("forward-search", class_files, forward_search_command,
 >   	   "Search for regular expression (see regex(3)) from last line listed.\n\


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