### 27.19 GDB/MI File Commands ¶

This section describes the GDB/MI commands to specify executable file names and to read in and obtain symbol table information.

#### The `-file-exec-and-symbols` Command ¶

#### Synopsis ¶

     -file-exec-and-symbols file

Specify the executable file to be debugged. This file is the one from which the symbol table is also read. If no file is specified, the command clears the executable and symbol information. If breakpoints are set when using this command with no arguments, GDB will produce error messages. Otherwise, no output is produced, except a completion notification.

#### GDB Command ¶

The corresponding GDB command is ‘`file`’.

#### Example ¶

    (gdb)
    -file-exec-and-symbols /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
    ^done
    (gdb)

#### The `-file-exec-file` Command ¶

#### Synopsis ¶

     -file-exec-file file

Specify the executable file to be debugged. Unlike ‘`-file-exec-and-symbols`’, the symbol table is not read from this file. If used without argument, GDB clears the information about the executable file. No output is produced, except a completion notification.

#### GDB Command ¶

The corresponding GDB command is ‘`exec-file`’.

#### Example ¶

    (gdb)
    -file-exec-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
    ^done
    (gdb)

#### The `-file-list-exec-source-file` Command ¶

#### Synopsis ¶

     -file-list-exec-source-file

List the line number, the current source file, and the absolute path to the current source file for the current executable. The macro information field has a value of ‘`1`’ or ‘`0`’ depending on whether or not the file includes preprocessor macro information.

#### GDB Command ¶

The GDB equivalent is ‘`info source`’

#### Example ¶

    (gdb)
    123-file-list-exec-source-file
    123^done,line="1",file="foo.c",fullname="/home/bar/foo.c,macro-info="1"
    (gdb)

#### The `-file-list-exec-source-files` Command ¶

#### Synopsis ¶

     -file-list-exec-source-files [ --group-by-objfile ]
                                  [ --dirname | --basename ]
                                  [ -- ]
                                  [ regexp ]

This command returns information about the source files GDB knows about, it will output both the filename and fullname (absolute file name) of a source file, though the fullname can be elided if this information is not known to GDB.

With no arguments this command returns a list of source files. Each source file is represented by a tuple with the fields; file, fullname, and debug-fully-read. The file is the display name for the file, while fullname is the absolute name of the file. The fullname field can be elided if the absolute name of the source file can’t be computed. The field debug-fully-read will be a string, either `true` or `false`. When `true`, this indicates the full debug information for the compilation unit describing this file has been read in. When `false`, the full debug information has not yet been read in. While reading in the full debug information it is possible that GDB could become aware of additional source files.

The optional regexp can be used to filter the list of source files returned. The regexp will be matched against the full source file name. The matching is case-sensitive, except on operating systems that have case-insensitive filesystem (e.g., MS-Windows). ‘`--`’ can be used before regexp to prevent GDB interpreting regexp as a command option (e.g. if regexp starts with ‘`-`’).

If `--dirname` is provided, then regexp is matched only against the directory name of each source file. If `--basename` is provided, then regexp is matched against the basename of each source file. Only one of `--dirname` or `--basename` may be given, and if either is given then regexp is required.

If `--group-by-objfile` is used then the format of the results is changed. The results will now be a list of tuples, with each tuple representing an object file (executable or shared library) loaded into GDB. The fields of these tuples are; filename, debug-info, and sources. The filename is the absolute name of the object file, debug-info is a string with one of the following values:

`none`

  This object file has no debug information.

`partially-read`

  This object file has debug information, but it is not fully read in yet. When it is read in later, GDB might become aware of additional source files.

`fully-read`

  This object file has debug information, and this information is fully read into GDB. The list of source files is complete.

The sources is a list or tuples, with each tuple describing a single source file with the same fields as described previously. The sources list can be empty for object files that have no debug information.

#### GDB Command ¶

The GDB equivalent is ‘`info sources`’. `gdbtk` has an analogous command ‘`gdb_listfiles`’.

#### Example ¶

    (gdb)
    -file-list-exec-source-files
    ^done,files=[{file="foo.c",fullname="/home/foo.c",debug-fully-read="true"},
                 {file="/home/bar.c",fullname="/home/bar.c",debug-fully-read="true"},
                 {file="gdb_could_not_find_fullpath.c",debug-fully-read="true"}]
    (gdb)
    -file-list-exec-source-files
    ^done,files=[{file="test.c",
                  fullname="/tmp/info-sources/test.c",
                  debug-fully-read="true"},
                 {file="/usr/include/stdc-predef.h",
                  fullname="/usr/include/stdc-predef.h",
                  debug-fully-read="true"},
                 {file="header.h",
                  fullname="/tmp/info-sources/header.h",
                  debug-fully-read="true"},
                 {file="helper.c",
                  fullname="/tmp/info-sources/helper.c",
                  debug-fully-read="true"}]
    (gdb)
    -file-list-exec-source-files -- \\.c
    ^done,files=[{file="test.c",
                  fullname="/tmp/info-sources/test.c",
                  debug-fully-read="true"},
                 {file="helper.c",
                  fullname="/tmp/info-sources/helper.c",
                  debug-fully-read="true"}]
    (gdb)
    -file-list-exec-source-files --group-by-objfile
    ^done,files=[{filename="/tmp/info-sources/test.x",
                  debug-info="fully-read",
                  sources=[{file="test.c",
                            fullname="/tmp/info-sources/test.c",
                            debug-fully-read="true"},
                           {file="/usr/include/stdc-predef.h",
                            fullname="/usr/include/stdc-predef.h",
                            debug-fully-read="true"},
                           {file="header.h",
                            fullname="/tmp/info-sources/header.h",
                            debug-fully-read="true"}]},
                 {filename="/lib64/ld-linux-x86-64.so.2",
                  debug-info="none",
                  sources=[]},
                 {filename="system-supplied DSO at 0x7ffff7fcf000",
                  debug-info="none",
                  sources=[]},
                 {filename="/tmp/info-sources/libhelper.so",
                  debug-info="fully-read",
                  sources=[{file="helper.c",
                            fullname="/tmp/info-sources/helper.c",
                            debug-fully-read="true"},
                           {file="/usr/include/stdc-predef.h",
                            fullname="/usr/include/stdc-predef.h",
                            debug-fully-read="true"},
                           {file="header.h",
                            fullname="/tmp/info-sources/header.h",
                            debug-fully-read="true"}]},
                 {filename="/lib64/libc.so.6",
                  debug-info="none",
                  sources=[]}]

#### The `-file-list-shared-libraries` Command ¶

#### Synopsis ¶

     -file-list-shared-libraries [ regexp ]

List the shared libraries in the program. With a regular expression regexp, only those libraries whose names match regexp are listed.

#### GDB Command ¶

The corresponding GDB command is ‘`info shared`’. The fields have a similar meaning to the `=library-loaded` notification. The `ranges` field specifies the multiple segments belonging to this library. Each range has the following fields:

‘`from`’

  The address defining the inclusive lower bound of the segment.

‘`to`’

  The address defining the exclusive upper bound of the segment.

#### Example ¶

    (gdb)
    -file-list-exec-source-files
    ^done,shared-libraries=[
    {id="/lib/libfoo.so",target-name="/lib/libfoo.so",host-name="/lib/libfoo.so",symbols-loaded="1",thread-group="i1",ranges=[{from="0x72815989",to="0x728162c0"}]},
    {id="/lib/libbar.so",target-name="/lib/libbar.so",host-name="/lib/libbar.so",symbols-loaded="1",thread-group="i1",ranges=[{from="0x76ee48c0",to="0x76ee9160"}]}]
    (gdb)

#### The `-file-symbol-file` Command ¶

#### Synopsis ¶

     -file-symbol-file file

Read symbol table info from the specified file argument. When used without arguments, clears GDB’s symbol table info. No output is produced, except for a completion notification.

#### GDB Command ¶

The corresponding GDB command is ‘`symbol-file`’.

#### Example ¶

    (gdb)
    -file-symbol-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
    ^done
    (gdb)