gdb/mi/mi-symbol-cmds.c - gdb

Functions defined

Source code

  1. /* MI Command Set - symbol commands.
  2.    Copyright (C) 2003-2015 Free Software Foundation, Inc.

  3.    This file is part of GDB.

  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 3 of the License, or
  7.    (at your option) any later version.

  8.    This program is distributed in the hope that it will be useful,
  9.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11.    GNU General Public License for more details.

  12.    You should have received a copy of the GNU General Public License
  13.    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

  14. #include "defs.h"
  15. #include "mi-cmds.h"
  16. #include "symtab.h"
  17. #include "objfiles.h"
  18. #include "ui-out.h"

  19. /* Print the list of all pc addresses and lines of code for the
  20.    provided (full or base) source file name.  The entries are sorted
  21.    in ascending PC order.  */

  22. void
  23. mi_cmd_symbol_list_lines (char *command, char **argv, int argc)
  24. {
  25.   struct gdbarch *gdbarch;
  26.   char *filename;
  27.   struct symtab *s;
  28.   int i;
  29.   struct cleanup *cleanup_stack, *cleanup_tuple;
  30.   struct ui_out *uiout = current_uiout;

  31.   if (argc != 1)
  32.     error (_("-symbol-list-lines: Usage: SOURCE_FILENAME"));

  33.   filename = argv[0];
  34.   s = lookup_symtab (filename);

  35.   if (s == NULL)
  36.     error (_("-symbol-list-lines: Unknown source file name."));

  37.   /* Now, dump the associated line table.  The pc addresses are
  38.      already sorted by increasing values in the symbol table, so no
  39.      need to perform any other sorting.  */

  40.   gdbarch = get_objfile_arch (SYMTAB_OBJFILE (s));
  41.   cleanup_stack = make_cleanup_ui_out_list_begin_end (uiout, "lines");

  42.   if (SYMTAB_LINETABLE (s) != NULL && SYMTAB_LINETABLE (s)->nitems > 0)
  43.     for (i = 0; i < SYMTAB_LINETABLE (s)->nitems; i++)
  44.     {
  45.       cleanup_tuple = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
  46.       ui_out_field_core_addr (uiout, "pc", gdbarch,
  47.                               SYMTAB_LINETABLE (s)->item[i].pc);
  48.       ui_out_field_int (uiout, "line", SYMTAB_LINETABLE (s)->item[i].line);
  49.       do_cleanups (cleanup_tuple);
  50.     }

  51.   do_cleanups (cleanup_stack);
  52. }