Hi Marc-Andre,
Could you include a gdb/NEWS change as well, please?
On 02/03/2017 05:15 PM, Marc-Andre Laperle wrote:
> @item =library-loaded,...
> Reports that a new library file was loaded by the program. This
> -notification has 4 fields---@var{id}, @var{target-name},
> -@var{host-name}, and @var{symbols-loaded}. The @var{id} field is an
> +notification has 5 fields---@var{id}, @var{target-name},
> +@var{host-name}, @var{symbols-loaded} and @var{ranges}. The @var{id} field is an
> opaque identifier of the library. For remote debugging case,
> @var{target-name} and @var{host-name} fields give the name of the
> library file on the target, and on the host respectively. For native
> @@ -26556,7 +26556,8 @@ and should not be relied on to convey any useful information. The
> @var{thread-group} field, if present, specifies the id of the thread
> group in whose context the library was loaded. If the field is
> absent, it means the library was loaded in the context of all present
> -thread groups.
> +thread groups. The @var{ranges} field specifies the ranges of addresses belonging
> +to this library.
Could you add some description of the subfields of the ranges
field? Something like "each range has the following fields", or some
such. Particularly important to mention I think is
whether "to" is inclusive or exclusive.
E.g., from the "Memory Region Attributes" section of the manual:
@item Lo Address
The address defining the inclusive lower bound of the memory region.
@item Hi Address
The address defining the exclusive upper bound of the memory region.
Another from range stepping vCont action description:
@item r @var{start},@var{end}
Step once, and then keep stepping as long as the thread stops at
addresses between @var{start} (inclusive) and @var{end} (exclusive).
It should be inclusive, in order to handle a range that covers all
the way to the end of the address space correctly (otherwise
one-past-the-end wraps around). However, seems like the current
code puts an exclusive end range in high_addr, since
"target_section::endaddr" is one-past-the-end. :-(
This comment in struct so_list would be nice to update somehow too:
/* Record the range of addresses belonging to this shared library.
There may not be just one (e.g. if two segments are relocated
differently); but this is only used for "info sharedlibrary". */
CORE_ADDR addr_low, addr_high;
The "only used for" part is now inaccurate.
I'd suggest adding some small comment about the multiple-segments
case to the MI code that prints the ranges, so other folks running
into that code understand that there's something to be improved there.
> --- a/gdb/mi/mi-cmd-file.c
> +++ b/gdb/mi/mi-cmd-file.c
> @@ -20,11 +20,15 @@
> #include "defs.h"
> #include "mi-cmds.h"
> #include "mi-getopt.h"
> +#include "mi-interp.h"
> #include "ui-out.h"
> #include "symtab.h"
> #include "source.h"
> #include "objfiles.h"
> #include "psymtab.h"
> +#include "solib.h"
> +#include "solist.h"
> +#include "xregex.h"
Don't include "xregex.h", include gdb_regex.h:
gdb/contrib/ari/gdb_ari.sh:318:BEGIN { doc["xregex.h"] = "\
gdb/contrib/ari/gdb_ari.sh:319:Do not include xregex.h, instead include gdb_regex.h"
gdb/contrib/ari/gdb_ari.sh:320: category["xregex.h"] = ari_regression
> +
> +void
> +mi_cmd_file_list_shared_libraries (char *command, char **argv, int argc)
Add a
/* See foo.h. */
comment.
> +{
> + struct ui_out *uiout = current_uiout;
> + const char *pattern;
> + struct so_list *so = NULL;
> + struct gdbarch *gdbarch = target_gdbarch ();
> +
> + switch (argc)
> + {
> + case 0:
> + pattern = NULL;
> + break;
> + case 1:
> + pattern = argv[0];
> + break;
> + default:
> + error (_("Usage: -file-list-shared-libraries [REGEXP]"));
> + }
> +
> + if (pattern != NULL)
> + {
> + const char *re_err = re_comp (pattern);
> +
> + if (re_err != NULL)
> + error (_("Invalid regexp: %s"), re_err);
> + }
> +
> + update_solib_list (1);
> +
> + /* Print the table header. */
> + struct cleanup* cleanup = make_cleanup_ui_out_list_begin_end (uiout, "shared-libraries");
Formatting:
- Space before '*', not after.
- Too long line.
Write:
struct cleanup *cleanup
= make_cleanup_ui_out_list_begin_end (uiout, "shared-libraries");
> +
> + ALL_SO_LIBS (so)
> + {
> + if (so->so_name[0] == '\0')
> + continue;
> + if (pattern != NULL && !re_exec (so->so_name))
> + continue;
> +
> + struct cleanup * tuple_clean_up
No space after *.
> + = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
> + mi_output_solib_attribs (uiout, so);
> +
> + do_cleanups (tuple_clean_up);
> + }
> +
> + do_cleanups (cleanup);
> +}
+
> +void
> +mi_output_solib_attribs (ui_out *uiout, struct so_list *solib)
/* See bar.h. */
> +{
> + struct gdbarch *gdbarch = target_gdbarch ();
> +
> + uiout->field_string ("id", solib->so_original_name);
> + uiout->field_string ("target-name", solib->so_original_name);
> + uiout->field_string ("host-name", solib->so_name);
> + uiout->field_int ("symbols-loaded", solib->symbols_loaded);
> + if (!gdbarch_has_global_solist (target_gdbarch ()))
> + {
> + uiout->field_fmt ("thread-group", "i%d", current_inferior ()->num);
> + }
While at it, please remove the unnecessary {}. (I know you're just
moving that code.)
Thanks,
Pedro Alves
@@ -26545,8 +26545,8 @@ that thread.
@item =library-loaded,...
Reports that a new library file was loaded by the program. This
-notification has 4 fields---@var{id}, @var{target-name},
-@var{host-name}, and @var{symbols-loaded}. The @var{id} field is an
+notification has 5 fields---@var{id}, @var{target-name},
+@var{host-name}, @var{symbols-loaded} and @var{ranges}. The @var{id} field is an
opaque identifier of the library. For remote debugging case,
@var{target-name} and @var{host-name} fields give the name of the
library file on the target, and on the host respectively. For native
@@ -26556,7 +26556,8 @@ and should not be relied on to convey any useful information. The
@var{thread-group} field, if present, specifies the id of the thread
group in whose context the library was loaded. If the field is
absent, it means the library was loaded in the context of all present
-thread groups.
+thread groups. The @var{ranges} field specifies the ranges of addresses belonging
+to this library.
@item =library-unloaded,...
Reports that a library was unloaded by the program. This notification
@@ -31477,26 +31478,36 @@ The @value{GDBN} equivalent is @samp{info sources}.
(gdb)
@end smallexample
-@ignore
@subheading The @code{-file-list-shared-libraries} Command
@findex -file-list-shared-libraries
@subsubheading Synopsis
@smallexample
- -file-list-shared-libraries
+ -file-list-shared-libraries [ @var{regexp} ]
@end smallexample
List the shared libraries in the program.
+With a regular expression @var{regexp}, only those libraries whose
+names match @var{regexp} are listed.
@subsubheading @value{GDBN} Command
-The corresponding @value{GDBN} command is @samp{info shared}.
+The corresponding @value{GDBN} command is @samp{info shared}. The fields
+have a similar meaning than the @code{=library-loaded} notification.
@subsubheading Example
-N.A.
+@smallexample
+(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)
+@end smallexample
+@ignore
@subheading The @code{-file-list-symbol-files} Command
@findex -file-list-symbol-files
@@ -20,11 +20,15 @@
#include "defs.h"
#include "mi-cmds.h"
#include "mi-getopt.h"
+#include "mi-interp.h"
#include "ui-out.h"
#include "symtab.h"
#include "source.h"
#include "objfiles.h"
#include "psymtab.h"
+#include "solib.h"
+#include "solist.h"
+#include "xregex.h"
/* Return to the client the absolute path and line number of the
current file being executed. */
@@ -106,3 +110,53 @@ mi_cmd_file_list_exec_source_files (char *command, char **argv, int argc)
uiout->end (ui_out_type_list);
}
+
+void
+mi_cmd_file_list_shared_libraries (char *command, char **argv, int argc)
+{
+ struct ui_out *uiout = current_uiout;
+ const char *pattern;
+ struct so_list *so = NULL;
+ struct gdbarch *gdbarch = target_gdbarch ();
+
+ switch (argc)
+ {
+ case 0:
+ pattern = NULL;
+ break;
+ case 1:
+ pattern = argv[0];
+ break;
+ default:
+ error (_("Usage: -file-list-shared-libraries [REGEXP]"));
+ }
+
+ if (pattern != NULL)
+ {
+ const char *re_err = re_comp (pattern);
+
+ if (re_err != NULL)
+ error (_("Invalid regexp: %s"), re_err);
+ }
+
+ update_solib_list (1);
+
+ /* Print the table header. */
+ struct cleanup* cleanup = make_cleanup_ui_out_list_begin_end (uiout, "shared-libraries");
+
+ ALL_SO_LIBS (so)
+ {
+ if (so->so_name[0] == '\0')
+ continue;
+ if (pattern != NULL && !re_exec (so->so_name))
+ continue;
+
+ struct cleanup * tuple_clean_up
+ = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
+ mi_output_solib_attribs (uiout, so);
+
+ do_cleanups (tuple_clean_up);
+ }
+
+ do_cleanups (cleanup);
+}
@@ -115,6 +115,8 @@ static struct mi_cmd mi_cmds[] =
mi_cmd_file_list_exec_source_file),
DEF_MI_CMD_MI ("file-list-exec-source-files",
mi_cmd_file_list_exec_source_files),
+ DEF_MI_CMD_MI ("file-list-shared-libraries",
+ mi_cmd_file_list_shared_libraries),
DEF_MI_CMD_CLI ("file-symbol-file", "symbol-file", 1),
DEF_MI_CMD_MI ("gdb-exit", mi_cmd_gdb_exit),
DEF_MI_CMD_CLI_1 ("gdb-set", "set", 1,
@@ -70,6 +70,7 @@ extern mi_cmd_argv_ftype mi_cmd_exec_step;
extern mi_cmd_argv_ftype mi_cmd_exec_step_instruction;
extern mi_cmd_argv_ftype mi_cmd_file_list_exec_source_file;
extern mi_cmd_argv_ftype mi_cmd_file_list_exec_source_files;
+extern mi_cmd_argv_ftype mi_cmd_file_list_shared_libraries;
extern mi_cmd_argv_ftype mi_cmd_gdb_exit;
extern mi_cmd_argv_ftype mi_cmd_inferior_tty_set;
extern mi_cmd_argv_ftype mi_cmd_inferior_tty_show;
@@ -1119,6 +1119,32 @@ mi_on_resume (ptid_t ptid)
}
}
+void
+mi_output_solib_attribs (ui_out *uiout, struct so_list *solib)
+{
+ struct gdbarch *gdbarch = target_gdbarch ();
+
+ uiout->field_string ("id", solib->so_original_name);
+ uiout->field_string ("target-name", solib->so_original_name);
+ uiout->field_string ("host-name", solib->so_name);
+ uiout->field_int ("symbols-loaded", solib->symbols_loaded);
+ if (!gdbarch_has_global_solist (target_gdbarch ()))
+ {
+ uiout->field_fmt ("thread-group", "i%d", current_inferior ()->num);
+ }
+ struct cleanup *cleanup
+ = make_cleanup_ui_out_list_begin_end (uiout, "ranges");
+ struct cleanup *tuple_clean_up
+ = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
+ if (solib->addr_high != 0)
+ {
+ uiout->field_core_addr ("from", gdbarch, solib->addr_low);
+ uiout->field_core_addr ("to", gdbarch, solib->addr_high);
+ }
+ do_cleanups (tuple_clean_up);
+ do_cleanups (cleanup);
+}
+
static void
mi_solib_loaded (struct so_list *solib)
{
@@ -1140,14 +1166,7 @@ mi_solib_loaded (struct so_list *solib)
uiout->redirect (mi->event_channel);
- uiout->field_string ("id", solib->so_original_name);
- uiout->field_string ("target-name", solib->so_original_name);
- uiout->field_string ("host-name", solib->so_name);
- uiout->field_int ("symbols-loaded", solib->symbols_loaded);
- if (!gdbarch_has_global_solist (target_gdbarch ()))
- {
- uiout->field_fmt ("thread-group", "i%d", current_inferior ()->num);
- }
+ mi_output_solib_attribs (uiout, solib);
uiout->redirect (NULL);
new file mode 100644
@@ -0,0 +1,27 @@
+/* MI Interpreter Definitions and Commands for GDB, the GNU debugger.
+
+ Copyright (C) 2017 Free Software Foundation, Inc.
+
+ This file is part of GDB.
+
+ 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 3 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, see <http://www.gnu.org/licenses/>. */
+
+#ifndef MI_INTERP_H
+#define MI_INTERP_H
+
+/* Output the shared object attributes to UIOUT. */
+
+void mi_output_solib_attribs (ui_out *uiout, struct so_list *solib);
+
+#endif
@@ -89,9 +89,6 @@ set_solib_ops (struct gdbarch *gdbarch, const struct target_so_ops *new_ops)
configuration needs to call set_solib_ops. */
struct target_so_ops *current_target_so_ops;
-/* List of known shared objects */
-#define so_list_head current_program_space->so_list
-
/* Local function prototypes */
/* If non-empty, this is a search path for loading non-absolute shared library
@@ -749,21 +746,7 @@ solib_used (const struct so_list *const known)
return 0;
}
-/* Synchronize GDB's shared object list with inferior's.
-
- Extract the list of currently loaded shared objects from the
- inferior, and compare it with the list of shared objects currently
- in GDB's so_list_head list. Edit so_list_head to bring it in sync
- with the inferior's new list.
-
- If we notice that the inferior has unloaded some shared objects,
- free any symbolic info GDB had read about those shared objects.
-
- Don't load symbolic info for any new shared objects; just add them
- to the list, and leave their symbols_loaded flag clear.
-
- If FROM_TTY is non-null, feel free to print messages about what
- we're doing. */
+/* See solib.h. */
void
update_solib_list (int from_tty)
@@ -1105,7 +1088,7 @@ info_sharedlibrary_command (char *pattern, int from_tty)
uiout->table_body ();
- for (so = so_list_head; so; so = so->next)
+ ALL_SO_LIBS (so)
{
struct cleanup *lib_cleanup;
@@ -28,6 +28,9 @@ struct program_space;
#include "symfile-add-flags.h"
+/* List of known shared objects */
+#define so_list_head current_program_space->so_list
+
/* Called when we free all symtabs, to free the shared library information
as well. */
@@ -75,6 +78,24 @@ extern void no_shared_libraries (char *ignored, int from_tty);
extern void set_solib_ops (struct gdbarch *gdbarch,
const struct target_so_ops *new_ops);
+/* Synchronize GDB's shared object list with inferior's.
+
+ Extract the list of currently loaded shared objects from the
+ inferior, and compare it with the list of shared objects currently
+ in GDB's so_list_head list. Edit so_list_head to bring it in sync
+ with the inferior's new list.
+
+ If we notice that the inferior has unloaded some shared objects,
+ free any symbolic info GDB had read about those shared objects.
+
+ Don't load symbolic info for any new shared objects; just add them
+ to the list, and leave their symbols_loaded flag clear.
+
+ If FROM_TTY is non-null, feel free to print messages about what
+ we're doing. */
+
+extern void update_solib_list (int from_tty);
+
/* Return non-zero if NAME is the libpthread shared library. */
extern int libpthread_name_p (const char *name);
@@ -24,6 +24,11 @@
#include "symtab.h"
#include "gdb_bfd.h"
+#define ALL_SO_LIBS(so) \
+ for (so = so_list_head; \
+ so != NULL; \
+ so = so->next)
+
/* Forward declaration for target specific link map information. This
struct is opaque to all but the target specific file. */
struct lm_info;
@@ -48,27 +48,46 @@ if { [gdb_compile_shlib ${srcfile_lib} ${binfile_lib} $lib_flags] != ""
mi_delete_breakpoints
mi_gdb_reinitialize_dir $srcdir/$subdir
-mi_gdb_reinitialize_dir $srcdir/$subdir
mi_gdb_load ${binfile}
mi_load_shlibs $binfile_lib
-mi_gdb_test "777-gdb-set stop-on-solib-events 1" "777\\^done" \
- "set stop-on-solib-events"
+proc_with_prefix test_stop_on_solib_events {} {
+ mi_gdb_test "777-gdb-set stop-on-solib-events 1" "777\\^done" \
+ "set stop-on-solib-events"
-# We use "run" rather than "-exec-run" here in order to test that CLI
-# commands still cause the correct MI output to be generated.
-mi_run_with_cli
+ # We use "run" rather than "-exec-run" here in order to test that CLI
+ # commands still cause the correct MI output to be generated.
+ mi_run_with_cli
-# Also test that the CLI solib event note is output.
-set test "CLI prints solib event"
-gdb_expect {
- -re "~\"Stopped due to shared library event \\(no libraries added or removed\\)\\\\n" {
- pass "$test"
- }
- timeout {
- fail "$test (timeout)"
+ # Also test that the CLI solib event note is output.
+ set test "CLI prints solib event"
+ gdb_expect {
+ -re "~\"Stopped due to shared library event \\(no libraries added or removed\\)\\\\n" {
+ pass "$test"
+ }
+ timeout {
+ fail "$test (timeout)"
+ }
}
+
+ mi_expect_stop solib-event .* .* .* .* .* "check for solib event"
+
+ # Unset solib events to avoid interfering with other tests.
+ mi_gdb_test "778-gdb-set stop-on-solib-events 0" "778\\^done" \
+ "unset stop-on-solib-events"
+}
+
+proc_with_prefix test_file_list_shared_libraries {} {
+ global libname
+ global binfile
+
+ mi_continue_to main
+
+ mi_gdb_test "222-file-list-shared-libraries" \
+ "222\\^done,shared-libraries=\\\[\{id=\".*${libname}.so\",target-name=\".*${libname}.so\",host-name=\".*${libname}.so\",symbols-loaded=\"1\",thread-group=\".*\",ranges=\\\[\{from=\".*\",to=\".*\"\}]\}]" \
+ "get the list of shared libraries"
}
-mi_expect_stop solib-event .* .* .* .* .* "check for solib event"
+test_stop_on_solib_events
+test_file_list_shared_libraries