]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb: add core file name to 'info inferiors' output
authorAndrew Burgess <aburgess@redhat.com>
Wed, 10 Sep 2025 16:05:26 +0000 (17:05 +0100)
committerAndrew Burgess <aburgess@redhat.com>
Thu, 2 Oct 2025 18:25:44 +0000 (19:25 +0100)
This commit builds on the previous commit.  In the future I am
proposing to move the core file BFD from the program_space into the
core_target.  In the last commit I updated 'maint info program-spaces'
to remove the core file name from the output.

In this commit I'm adding the core file name to the 'info inferiors'
output.

My proposal is to add the core file as auxiliary information beneath
an inferior's line in the 'info inferiors' output.  We already do
this vfork parent/child information.

The alternative would be to add the core file as an additional column
in the 'info inferiors' output, indeed, I did initially propose this:

  https://inbox.sourceware.org/gdb-patches/e3e040272a0f8f5fd826298331da4c19d01f3a5e.1757615333.git.aburgess@redhat.com

But the problem with this is that the 'info inferiors' output can
easily become very long, and the line wrapping gets very messy, making
the output much harder to parse.  The feedback on this initial
approach wasn't super strong, so I'm trying the auxiliary information
approach to see if this is liked more.

The new output looks like this:

  (gdb) info inferiors
    Num  Description       Connection           Executable
  * 1    process 54313     1 (core)             /tmp/executable
          core file /tmp/core.54313

The only other option I can think of, if this approach is not liked,
would be to add an entirely new command, 'info core-files', with
output like:

    Num  Core File
  * 1    /tmp/corefile.core

The 'Num' column here would just be the inferior number again.  In
effect this new command is just splitting the 'info inferiors' into
two commands.

I extended gdb.base/corefile.exp to check the current output style,
and updated the gdb.multi/multi-target-info-inferiors.exp test to take
the new output into account.

Approved-By: Tom Tromey <tom@tromey.com>
gdb/NEWS
gdb/doc/gdb.texinfo
gdb/inferior.c
gdb/testsuite/gdb.base/corefile.exp
gdb/testsuite/gdb.multi/multi-target-info-inferiors.exp

index ff66adb20ef384d8e2e2ab5ea2df9d87de9ea57a..aa1105cfe57829b22a1180e7c04ddb4d0594e014 100644 (file)
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -38,6 +38,11 @@ maintenance test-remote-args ARGS
 maintenance info program-spaces
   This command no longer displays the core file name.
 
+info inferiors
+  If an inferior has a core file loaded, then this will be displayed
+  as an additional line under the inferior's table entry in the
+  output.
+
 * Changed remote packets
 
 single-inf-arg in qSupported
index 1e1893f02bc649819f252fb400ded3cad1b2a5bd..a955f72213b6745c0f0fca572927dfd85aed35b0 100644 (file)
@@ -3367,6 +3367,7 @@ elements, even duplicates or overlapping ranges are valid.  E.g.@:
 To find out what inferiors exist at any moment, use @w{@code{info
 inferiors}}:
 
+@anchor{info inferiors command}
 @table @code
 @kindex info inferiors [ @var{id}@dots{} ]
 @item info inferiors
@@ -3390,9 +3391,13 @@ the connection.
 
 @item
 the name of the executable the inferior is running.
-
 @end enumerate
 
+@noindent
+If an inferior is currently debugging a core file, then an additional
+line will be printed after the line describing the inferior, this
+additional line gives the file name of the core file being debugged.
+
 @noindent
 An asterisk @samp{*} preceding the @value{GDBN} inferior number
 indicates the current inferior.
@@ -3401,11 +3406,23 @@ For example,
 @end table
 @c end table here to get a little more width for example
 
+@smallexample
+(@value{GDBP}) info inferiors
+  Num  Description       Connection                      Executable
+* 1    process 3401      1 (native)                      goodbye
+  2    process 2307      2 (extended0remote host:10000)  hello
+@end smallexample
+
+Adding an additional inferior that is debugging a core file causes the
+additional core file line to be displayed, for example@:
+
 @smallexample
 (@value{GDBP}) info inferiors
   Num  Description       Connection                      Executable
 * 1    process 3401      1 (native)                      goodbye
   2    process 2307      2 (extended-remote host:10000)  hello
+  3    process 1578      3 (core)                        broken
+        core file core.1578
 @end smallexample
 
 To get information about the current inferior, use @code{inferior}:
@@ -22070,6 +22087,9 @@ wish to debug a core file instead, you must kill the subprocess in which
 the program is running.  To do this, use the @code{kill} command
 (@pxref{Kill Process, ,Killing the Child Process}).
 
+To see which core files are loaded into which inferiors, use the
+@kbd{info inferiors} command (@pxref{info inferiors command}).
+
 @kindex add-symbol-file
 @cindex dynamic linking
 @item add-symbol-file @var{filename} @r{[} -readnow @r{|} -readnever @r{]} @r{[} -o @var{offset} @r{]} @r{[} @var{textaddress} @r{]} @r{[} -s @var{section} @var{address} @dots{} @r{]}
index 78ecb162228cac883c85a70cb914ac7a8647ffbd..a387d3c4c9f562ba56456db616f2288fb741180a 100644 (file)
@@ -634,6 +634,13 @@ print_inferior (struct ui_out *uiout, const char *requested_inferiors)
          uiout->text (_("\n\tis vfork parent of inferior "));
          uiout->field_signed ("vfork-child", inf->vfork_child->num);
        }
+      if (inf->pspace->core_bfd () != nullptr)
+       {
+         uiout->text (_("\n\tcore file "));
+         uiout->field_string ("core-file",
+                              bfd_get_filename (inf->pspace->core_bfd ()),
+                              file_name_style.style ());
+       }
 
       uiout->text ("\n");
     }
index ae1e8bf95dc1ad5887c82c4468d0c6cd7e23bae4..6e44df845d0a2fc43dda0568ebfc752a43d81d59 100644 (file)
@@ -60,7 +60,7 @@ proc start_gdb_with_corefile { testname coreopt corefile {binfile ""} } {
            -re -wrap "Couldn't find .* registers in core file.*" {
                fail "$gdb_test_name (couldn't find regs)"
            }
-           -re -wrap "Core was generated by `[string_to_regexp $corefile]'\\.\r\n.*\#0  \[^\r\n\]+\(\).*" {
+           -re -wrap "Core was generated by `[string_to_regexp $binfile]'\\.\r\n.*\#0  \[^\r\n\]+\(\).*" {
                pass $gdb_test_name
            }
            -re -wrap "Core was generated by .*\r\n\#0  .*\(\).*" {
@@ -75,6 +75,16 @@ proc start_gdb_with_corefile { testname coreopt corefile {binfile ""} } {
                fail "$gdb_test_name (core not loaded)"
            }
        }
+
+       # COREFILE will have whitespace quoted ready for use on the command
+       # line.  But for the 'info inferiors' output whitespace is not quoted,
+       # so remote the quoting now.
+       regsub -all "\\\\ " $corefile " " corefile
+       gdb_test "info inferiors" \
+           [multi_line \
+                "\\* 1\[^\r\n\]+\\(core\\)\\s+.*[string_to_regexp $binfile]\\s*" \
+                "\\s+core file [string_to_regexp $corefile]"] \
+           "$testname, info inferiors"
     }
 }
 
index e03dc6011be4b80fcb49c48a1029e553b2f4d2df..b9cd212bce58b4c75bc133410d1e60b9fe71e0b8 100644 (file)
@@ -75,7 +75,7 @@ proc test_info_inferiors {multi_process} {
     }
 
     set ws "\[ \t\]+"
-    global decimal binfile
+    global decimal binfile gcorefile
 
     # Test "info connections" and "info inferior" by switching to each
     # inferior one by one.
@@ -105,15 +105,19 @@ proc test_info_inferiors {multi_process} {
                        ]
            }
 
+           set gcorefile_re [string_to_regexp $gcorefile]
+
            gdb_test "info inferiors" \
                [multi_line \
                     "Num${ws}Description${ws}Connection${ws}Executable${ws}" \
                     "[inf_desc 1 $inf]1 \\(native\\)${ws}${binfile}${ws}" \
                     "[inf_desc 2 $inf]2 \\(extended-remote localhost:$decimal\\)${ws}${binfile}${ws}" \
                     "[inf_desc 3 $inf]3 \\(core\\)${ws}${binfile}${ws}" \
+                    "${ws}core file ${gcorefile_re}" \
                     "[inf_desc 4 $inf]1 \\(native\\)${ws}${binfile}${ws}" \
                     "[inf_desc 5 $inf]4 \\(extended-remote localhost:$decimal\\)${ws}${binfile}${ws}" \
                     "[inf_desc 6 $inf]5 \\(core\\)${ws}${binfile}${ws}" \
+                    "${ws}core file ${gcorefile_re}"
                    ]
 
            if { $::run_python_tests } {