diff options
author | Jan Kratochvil <jan.kratochvil@redhat.com> | 2015-06-03 21:22:56 +0200 |
---|---|---|
committer | Jan Kratochvil <jan.kratochvil@redhat.com> | 2015-06-03 21:26:04 +0200 |
commit | 7f36105668d57c26b52037202f5d97dbad91336b (patch) | |
tree | 2407b3a87ac36d7cdf19708fbec9669b55810203 /gdb/gdbarch.c | |
parent | f277626b45b9d4af76e5d61a7efe09ce417ac200 (diff) | |
download | gdb-7f36105668d57c26b52037202f5d97dbad91336b.zip gdb-7f36105668d57c26b52037202f5d97dbad91336b.tar.gz gdb-7f36105668d57c26b52037202f5d97dbad91336b.tar.bz2 |
compile: Use also inferior munmap
Currently inferior memory is allocated by inferior mmap() but it is never
deallocated; despite the injected objfile incl. its symbols is freed. This was
intentional so that one can do for example:
inferior:
char *str = "foo";
GDB:
(gdb) compile code str = "bar";
I believe later patches will be needed to introduce full control over keeping
vs. discarding the injected module as being discussed in:
compile: objfiles lifetime UI
https://sourceware.org/ml/gdb/2015-04/msg00051.html
Message-ID: <20150429135735.GA16974@host1.jankratochvil.net>
https://sourceware.org/ml/gdb/2015-05/msg00007.html
As decided by Phil it is better not to leak inferior pages as users can
workaround the issue above for example by:
(gdb) compile code str = strdup ("bar");
I have checked that in fact gdb/doc/ (written by Phil) already expects the
injected code will be unmapped so that does not need to be changed:
compile code int ff = 5; p = &ff;
In this example, @code{p} would point to @code{ff} when the
@code{compile} command is executing the source code provided to it.
However, as variables in the (example) program persist with their
assigned values, the variable @code{p} would point to an invalid
location when the command exists.
gdb/ChangeLog
2015-04-28 Jan Kratochvil <jan.kratochvil@redhat.com>
* arch-utils.c (default_infcall_munmap): New.
* arch-utils.h (default_infcall_munmap): New declaration.
* compile/compile-object-load.c (struct munmap_list, munmap_list_add)
(munmap_list_free, munmap_listp_free_cleanup): New.
(struct setup_sections_data): Add field munmap_list_headp.
(setup_sections): Call munmap_list_add.
(compile_object_load): New variable munmap_list_head, initialize
setup_sections_data.munmap_list_headp, return munmap_list_head.
* compile/compile-object-load.h (struct munmap_list): New declaration.
(struct compile_module): Add field munmap_list_head.
(munmap_list_free): New declaration.
* compile/compile-object-run.c (struct do_module_cleanup): Add field
munmap_list_head.
(do_module_cleanup): Call munmap_list_free.
(compile_object_run): Pass munmap_list_head to do_module_cleanup.
* gdbarch.c: Regenerate.
* gdbarch.h: Regenerate.
* gdbarch.sh (infcall_munmap): New.
* linux-tdep.c (linux_infcall_munmap): New.
(linux_init_abi): Install it.
gdb/testsuite/ChangeLog
2015-04-28 Jan Kratochvil <jan.kratochvil@redhat.com>
* gdb.compile/compile.exp (keep jit in memory): Rename to ...
(do not keep jit in memory): ... this.
(expect 5): Change it to ...
(expect no 5): ... this.
Diffstat (limited to 'gdb/gdbarch.c')
-rw-r--r-- | gdb/gdbarch.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/gdb/gdbarch.c b/gdb/gdbarch.c index 821ad5e..ebff510 100644 --- a/gdb/gdbarch.c +++ b/gdb/gdbarch.c @@ -326,6 +326,7 @@ struct gdbarch gdbarch_auxv_parse_ftype *auxv_parse; gdbarch_vsyscall_range_ftype *vsyscall_range; gdbarch_infcall_mmap_ftype *infcall_mmap; + gdbarch_infcall_munmap_ftype *infcall_munmap; gdbarch_gcc_target_options_ftype *gcc_target_options; gdbarch_gnu_triplet_regexp_ftype *gnu_triplet_regexp; }; @@ -426,6 +427,7 @@ gdbarch_alloc (const struct gdbarch_info *info, gdbarch->insn_is_jump = default_insn_is_jump; gdbarch->vsyscall_range = default_vsyscall_range; gdbarch->infcall_mmap = default_infcall_mmap; + gdbarch->infcall_munmap = default_infcall_munmap; gdbarch->gcc_target_options = default_gcc_target_options; gdbarch->gnu_triplet_regexp = default_gnu_triplet_regexp; /* gdbarch_alloc() */ @@ -658,6 +660,7 @@ verify_gdbarch (struct gdbarch *gdbarch) /* Skip verify of auxv_parse, has predicate. */ /* Skip verify of vsyscall_range, invalid_p == 0 */ /* Skip verify of infcall_mmap, invalid_p == 0 */ + /* Skip verify of infcall_munmap, invalid_p == 0 */ /* Skip verify of gcc_target_options, invalid_p == 0 */ /* Skip verify of gnu_triplet_regexp, invalid_p == 0 */ buf = ui_file_xstrdup (log, &length); @@ -1029,6 +1032,9 @@ gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file) "gdbarch_dump: infcall_mmap = <%s>\n", host_address_to_string (gdbarch->infcall_mmap)); fprintf_unfiltered (file, + "gdbarch_dump: infcall_munmap = <%s>\n", + host_address_to_string (gdbarch->infcall_munmap)); + fprintf_unfiltered (file, "gdbarch_dump: gdbarch_info_proc_p() = %d\n", gdbarch_info_proc_p (gdbarch)); fprintf_unfiltered (file, @@ -4673,6 +4679,23 @@ set_gdbarch_infcall_mmap (struct gdbarch *gdbarch, gdbarch->infcall_mmap = infcall_mmap; } +void +gdbarch_infcall_munmap (struct gdbarch *gdbarch, CORE_ADDR addr, CORE_ADDR size) +{ + gdb_assert (gdbarch != NULL); + gdb_assert (gdbarch->infcall_munmap != NULL); + if (gdbarch_debug >= 2) + fprintf_unfiltered (gdb_stdlog, "gdbarch_infcall_munmap called\n"); + gdbarch->infcall_munmap (addr, size); +} + +void +set_gdbarch_infcall_munmap (struct gdbarch *gdbarch, + gdbarch_infcall_munmap_ftype infcall_munmap) +{ + gdbarch->infcall_munmap = infcall_munmap; +} + char * gdbarch_gcc_target_options (struct gdbarch *gdbarch) { |