mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2024-12-27 04:52:05 +08:00
7f36105668
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.
61 lines
1.9 KiB
C
61 lines
1.9 KiB
C
/* Header file to load module for 'compile' command.
|
|
Copyright (C) 2014-2015 Free Software Foundation, Inc.
|
|
|
|
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 GDB_COMPILE_OBJECT_LOAD_H
|
|
#define GDB_COMPILE_OBJECT_LOAD_H
|
|
|
|
struct munmap_list;
|
|
|
|
struct compile_module
|
|
{
|
|
/* objfile for the compiled module. */
|
|
struct objfile *objfile;
|
|
|
|
/* .c file OBJFILE was built from. It needs to be xfree-d. */
|
|
char *source_file;
|
|
|
|
/* Inferior function GCC_FE_WRAPPER_FUNCTION. */
|
|
struct symbol *func_sym;
|
|
|
|
/* Inferior registers address or NULL if the inferior function does not
|
|
require any. */
|
|
CORE_ADDR regs_addr;
|
|
|
|
/* The "scope" of this compilation. */
|
|
enum compile_i_scope_types scope;
|
|
|
|
/* User data for SCOPE in use. */
|
|
void *scope_data;
|
|
|
|
/* Inferior parameter out value type or NULL if the inferior function does not
|
|
have one. */
|
|
struct type *out_value_type;
|
|
|
|
/* If the inferior function has an out value, this is its address.
|
|
Otherwise it is zero. */
|
|
CORE_ADDR out_value_addr;
|
|
|
|
/* Track inferior memory reserved by inferior mmap. */
|
|
struct munmap_list *munmap_list_head;
|
|
};
|
|
|
|
extern struct compile_module *compile_object_load
|
|
(const char *object_file, const char *source_file,
|
|
enum compile_i_scope_types scope, void *scope_data);
|
|
extern void munmap_list_free (struct munmap_list *head);
|
|
|
|
#endif /* GDB_COMPILE_OBJECT_LOAD_H */
|