1130803Smarcel/* MI Command Set - breakpoint and watchpoint commands.
2130803Smarcel   Copyright 2000, 2001, 2002 Free Software Foundation, Inc.
3130803Smarcel   Contributed by Cygnus Solutions (a Red Hat company).
4130803Smarcel
5130803Smarcel   This file is part of GDB.
6130803Smarcel
7130803Smarcel   This program is free software; you can redistribute it and/or modify
8130803Smarcel   it under the terms of the GNU General Public License as published by
9130803Smarcel   the Free Software Foundation; either version 2 of the License, or
10130803Smarcel   (at your option) any later version.
11130803Smarcel
12130803Smarcel   This program is distributed in the hope that it will be useful,
13130803Smarcel   but WITHOUT ANY WARRANTY; without even the implied warranty of
14130803Smarcel   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15130803Smarcel   GNU General Public License for more details.
16130803Smarcel
17130803Smarcel   You should have received a copy of the GNU General Public License
18130803Smarcel   along with this program; if not, write to the Free Software
19130803Smarcel   Foundation, Inc., 59 Temple Place - Suite 330,
20130803Smarcel   Boston, MA 02111-1307, USA.  */
21130803Smarcel
22130803Smarcel#include "defs.h"
23130803Smarcel#include "mi-cmds.h"
24130803Smarcel#include "mi-getopt.h"
25130803Smarcel#include "ui-out.h"
26130803Smarcel#include "symtab.h"
27130803Smarcel#include "source.h"
28130803Smarcel
29130803Smarcel/* Return to the client the absolute path and line number of the
30130803Smarcel   current file being executed. */
31130803Smarcel
32130803Smarcelenum mi_cmd_result
33130803Smarcelmi_cmd_file_list_exec_source_file(char *command, char **argv, int argc)
34130803Smarcel{
35130803Smarcel  struct symtab_and_line st;
36130803Smarcel  int optind = 0;
37130803Smarcel  char *optarg;
38130803Smarcel
39130803Smarcel  if ( !mi_valid_noargs("mi_cmd_file_list_exec_source_file", argc, argv) )
40130803Smarcel    error ("mi_cmd_file_list_exec_source_file: Usage: No args");
41130803Smarcel
42130803Smarcel
43130803Smarcel  /* Set the default file and line, also get them */
44130803Smarcel  set_default_source_symtab_and_line();
45130803Smarcel  st = get_current_source_symtab_and_line();
46130803Smarcel
47130803Smarcel  /* We should always get a symtab.
48130803Smarcel     Apparently, filename does not need to be tested for NULL.
49130803Smarcel     The documentation in symtab.h suggests it will always be correct */
50130803Smarcel  if (!st.symtab)
51130803Smarcel    error ("mi_cmd_file_list_exec_source_file: No symtab");
52130803Smarcel
53130803Smarcel  /* Extract the fullname if it is not known yet */
54130803Smarcel  if (st.symtab->fullname == NULL)
55130803Smarcel    symtab_to_filename (st.symtab);
56130803Smarcel
57130803Smarcel  /* We may not be able to open the file (not available). */
58130803Smarcel  if (st.symtab->fullname == NULL)
59130803Smarcel    error ("mi_cmd_file_list_exec_source_file: File not found");
60130803Smarcel
61130803Smarcel  /* Print to the user the line, filename and fullname */
62130803Smarcel  ui_out_field_int (uiout, "line", st.line);
63130803Smarcel  ui_out_field_string (uiout, "file", st.symtab->filename);
64130803Smarcel  ui_out_field_string (uiout, "fullname", st.symtab->fullname);
65130803Smarcel
66130803Smarcel  return MI_CMD_DONE;
67130803Smarcel}
68