[v10,04/10] Create empty common/linux-maps.[ch] and common/target-utils.[ch]

Message ID 20150715212028.GA22133@host1.jankratochvil.net
State New, archived
Headers

Commit Message

Jan Kratochvil July 15, 2015, 9:20 p.m. UTC
  On Mon, 08 Jun 2015 10:37:33 +0200, Gary Benson wrote:
> A bunch of stuff has changed in the way common code is laid out since
> May 2014, so while Tom approved this back then, it's not suitable any
> more.  Please update the series as follows:
> 
> > 	* common/linux-maps.c: New file.
> > 	* common/linux-maps.h: New file.
> 
> Nothing os-specific should be in common.  These files should be
> nat/linux-maps.[ch].

While I have done so I do not share this opinion.  linux-maps.[ch] is used
from linux-tdep.c and not from linux-nat.c.  linux-tdep.c is using common/*
files a lot but it uses no function from nat/*:
	$ for i in $(for i in common/*.c;do nm `basename $i .c`.o;done|sed -n 's/^.* T //p');do grep -q "\<$i (" linux-tdep.c && echo $i;done|wc -l
	17
	$ for i in $(for i in    nat/*.c;do nm `basename $i .c`.o;done|sed -n 's/^.* T //p');do grep -q "\<$i (" linux-tdep.c && echo $i;done|wc -l
	0
	(commands above assume in-src-tree build)

Additionally linux-maps.o should not be in config/**.mh::NATDEPFILES (like
linux-namespaces.o from nat/ ) but it needs to be in configure.tgt instead.

Should be linux-maps.[ch] therefore in nat/ or in common/ ?
If it matters, though.


Jan
commit 0f08cd383c254274afe44a5a87edc4435977ef22
Author: Jan Kratochvil <jan.kratochvil@redhat.com>
Date:   Wed Jul 15 17:37:27 2015 +0200

    Create empty nat/linux-maps.[ch] and common/target-utils.[ch]
    
    Prepare new files for later move.
    
    gdb/ChangeLog
    2015-07-15  Aleksandar Ristovski  <aristovski@qnx.com
    	    Jan Kratochvil  <jan.kratochvil@redhat.com>
    
    	Create empty nat/linux-maps.[ch] and common/target-utils.[ch].
    	* Makefile.in (HFILES_NO_SRCDIR); Add nat/linux-maps.h,
    	common/target-utils.h.
    	(COMMON_OBS): Add target-utils.o.
    	(linux-maps.o, target-utils.o): New.
    	* target/target-utils.c: New file.
    	* target/target-utils.h: New file.
    	* nat/linux-maps.c: New file.
    	* nat/linux-maps.h: New file.
    	* configure.tgt (aarch64*-*-linux*, alpha*-*-linux*)
    	(am33_2.0*-*-linux*, arm*-*-linux*, bfin-*-*linux*, cris*, frv-*-*)
    	(hppa*-*-linux*, i[34567]86-*-linux*, ia64-*-linux*, m32r*-*-linux*)
    	(m68*-*-linux*, microblaze*-linux-*, microblaze*-*-linux*)
    	(mips*-*-linux*, nios2*-*-linux*, powerpc*-*-linux*, s390*-*-linux*)
    	(sh*-*-linux*, sparc-*-linux*, sparc64-*-linux*, tic6x-*-*linux)
    	(tilegx-*-linux*, x86_64-*-linux*, xtensa*-*-linux*): Add linux-maps.o
    	to gdb_target_obs.
    
    gdb/gdbserver/ChangeLog
    2015-07-15  Aleksandar Ristovski  <aristovski@qnx.com
    	    Jan Kratochvil  <jan.kratochvil@redhat.com>
    
    	Create empty nat/linux-maps.[ch] and common/target-utils.[ch].
    	* Makefile.in (OBS): Add target-utils.o.
    	(linux-maps.o, target-utils.o): New.
    	* configure.srv (srv_linux_obj): Add linux-maps.o.
  

Comments

Gary Benson July 16, 2015, 8:14 a.m. UTC | #1
Jan Kratochvil wrote:
> On Mon, 08 Jun 2015 10:37:33 +0200, Gary Benson wrote:
> > A bunch of stuff has changed in the way common code is laid out
> > since May 2014, so while Tom approved this back then, it's not
> > suitable any more.  Please update the series as follows:
> > 
> > > 	* common/linux-maps.c: New file.
> > > 	* common/linux-maps.h: New file.
> > 
> > Nothing os-specific should be in common.  These files should be
> > nat/linux-maps.[ch].
> 
> While I have done so I do not share this opinion.  linux-maps.[ch]
> is used from linux-tdep.c and not from linux-nat.c.  linux-tdep.c is
> using common/* files a lot but it uses no function from nat/*:
> 
> 	$ for i in $(for i in common/*.c;do nm `basename $i .c`.o;done|sed -n 's/^.* T //p');do grep -q "\<$i (" linux-tdep.c && echo $i;done|wc -l
> 	17
> 	$ for i in $(for i in    nat/*.c;do nm `basename $i .c`.o;done|sed -n 's/^.* T //p');do grep -q "\<$i (" linux-tdep.c && echo $i;done|wc -l
> 	0
> 	(commands above assume in-src-tree build)
> 
> Additionally linux-maps.o should not be in config/**.mh::NATDEPFILES
> (like linux-namespaces.o from nat/ ) but it needs to be in
> configure.tgt instead.
> 
> Should be linux-maps.[ch] therefore in nat/ or in common/ ?
> If it matters, though.

I don't fully understand the tdep/non-tdep split very well.
Pedro, could you comment?

Cheers,
Gary

> commit 0f08cd383c254274afe44a5a87edc4435977ef22
> Author: Jan Kratochvil <jan.kratochvil@redhat.com>
> Date:   Wed Jul 15 17:37:27 2015 +0200
> 
>     Create empty nat/linux-maps.[ch] and common/target-utils.[ch]
>     
>     Prepare new files for later move.
>     
>     gdb/ChangeLog
>     2015-07-15  Aleksandar Ristovski  <aristovski@qnx.com
>     	    Jan Kratochvil  <jan.kratochvil@redhat.com>
>     
>     	Create empty nat/linux-maps.[ch] and common/target-utils.[ch].
>     	* Makefile.in (HFILES_NO_SRCDIR); Add nat/linux-maps.h,
>     	common/target-utils.h.
>     	(COMMON_OBS): Add target-utils.o.
>     	(linux-maps.o, target-utils.o): New.
>     	* target/target-utils.c: New file.
>     	* target/target-utils.h: New file.
>     	* nat/linux-maps.c: New file.
>     	* nat/linux-maps.h: New file.
>     	* configure.tgt (aarch64*-*-linux*, alpha*-*-linux*)
>     	(am33_2.0*-*-linux*, arm*-*-linux*, bfin-*-*linux*, cris*, frv-*-*)
>     	(hppa*-*-linux*, i[34567]86-*-linux*, ia64-*-linux*, m32r*-*-linux*)
>     	(m68*-*-linux*, microblaze*-linux-*, microblaze*-*-linux*)
>     	(mips*-*-linux*, nios2*-*-linux*, powerpc*-*-linux*, s390*-*-linux*)
>     	(sh*-*-linux*, sparc-*-linux*, sparc64-*-linux*, tic6x-*-*linux)
>     	(tilegx-*-linux*, x86_64-*-linux*, xtensa*-*-linux*): Add linux-maps.o
>     	to gdb_target_obs.
>     
>     gdb/gdbserver/ChangeLog
>     2015-07-15  Aleksandar Ristovski  <aristovski@qnx.com
>     	    Jan Kratochvil  <jan.kratochvil@redhat.com>
>     
>     	Create empty nat/linux-maps.[ch] and common/target-utils.[ch].
>     	* Makefile.in (OBS): Add target-utils.o.
>     	(linux-maps.o, target-utils.o): New.
>     	* configure.srv (srv_linux_obj): Add linux-maps.o.
> 
> diff --git a/gdb/Makefile.in b/gdb/Makefile.in
> index dfaa8a3..237da9d 100644
> --- a/gdb/Makefile.in
> +++ b/gdb/Makefile.in
> @@ -903,7 +903,7 @@ LINTFILES = $(SFILES) $(YYFILES) $(CONFIG_SRCS) init.c
>  # right, it is probably easiest just to list .h files here directly.
>  
>  HFILES_NO_SRCDIR = \
> -common/gdb_signals.h nat/gdb_thread_db.h common/gdb_vecs.h \
> +common/gdb_signals.h nat/gdb_thread_db.h common/gdb_vecs.h nat/linux-maps.h \
>  common/x86-xstate.h nat/linux-ptrace.h nat/mips-linux-watch.h \
>  proc-utils.h aarch64-tdep.h arm-tdep.h ax-gdb.h ppcfbsd-tdep.h \
>  ppcnbsd-tdep.h cli-out.h gdb_expat.h breakpoint.h infcall.h obsd-tdep.h \
> @@ -983,7 +983,7 @@ common/common-debug.h common/cleanups.h common/gdb_setjmp.h \
>  common/common-exceptions.h target/target.h common/symbol.h \
>  common/common-regcache.h fbsd-tdep.h nat/linux-personality.h \
>  common/fileio.h nat/x86-linux.h nat/x86-linux-dregs.h \
> -nat/linux-namespaces.h
> +nat/linux-namespaces.h target/target-utils.h
>  
>  # Header files that already have srcdir in them, or which are in objdir.
>  
> @@ -1083,7 +1083,7 @@ COMMON_OBS = $(DEPFILES) $(CONFIG_OBS) $(YYOBJ) \
>  	common-utils.o buffer.o ptid.o gdb-dlfcn.o common-agent.o \
>  	format.o registry.o btrace.o record-btrace.o waitstatus.o \
>  	print-utils.o rsp-low.o errors.o common-debug.o debug.o \
> -	common-exceptions.o btrace-common.o fileio.o \
> +	common-exceptions.o btrace-common.o fileio.o target-utils.o \
>  	$(SUBDIR_GCC_COMPILE_OBS)
>  
>  TSOBS = inflow.o
> @@ -2221,6 +2221,10 @@ common-agent.o: $(srcdir)/common/agent.c
>  	$(COMPILE) $(srcdir)/common/agent.c
>  	$(POSTCOMPILE)
>  
> +linux-maps.o: ${srcdir}/nat/linux-maps.c
> +	$(COMPILE) $(srcdir)/nat/linux-maps.c
> +	$(POSTCOMPILE)
> +
>  vec.o: ${srcdir}/common/vec.c
>  	$(COMPILE) $(srcdir)/common/vec.c
>  	$(POSTCOMPILE)
> @@ -2237,6 +2241,10 @@ errors.o: ${srcdir}/common/errors.c
>  	$(COMPILE) $(srcdir)/common/errors.c
>  	$(POSTCOMPILE)
>  
> +target-utils.o: ${srcdir}/target/target-utils.c
> +	$(COMPILE) $(srcdir)/target/target-utils.c
> +	$(POSTCOMPILE)
> +
>  common-debug.o: ${srcdir}/common/common-debug.c
>  	$(COMPILE) $(srcdir)/common/common-debug.c
>  	$(POSTCOMPILE)
> diff --git a/gdb/configure.tgt b/gdb/configure.tgt
> index f2c1a2d..20873c3 100644
> --- a/gdb/configure.tgt
> +++ b/gdb/configure.tgt
> @@ -45,7 +45,7 @@ aarch64*-*-linux*)
>  	# Target: AArch64 linux
>  	gdb_target_obs="aarch64-tdep.o aarch64-linux-tdep.o \
>  			arm-tdep.o arm-linux-tdep.o \
> -			glibc-tdep.o linux-tdep.o solib-svr4.o \
> +			glibc-tdep.o linux-tdep.o linux-maps.o solib-svr4.o \
>  			symfile-mem.o linux-record.o"
>  	build_gdbserver=yes
>  	;;
> @@ -53,7 +53,7 @@ aarch64*-*-linux*)
>  alpha*-*-linux*)
>  	# Target: Little-endian Alpha running Linux
>  	gdb_target_obs="alpha-tdep.o alpha-mdebug-tdep.o alpha-linux-tdep.o \
> -			linux-tdep.o solib-svr4.o"
> +			linux-tdep.o linux-maps.o solib-svr4.o"
>  	;;
>  alpha*-*-freebsd* | alpha*-*-kfreebsd*-gnu)
>  	# Target: FreeBSD/alpha
> @@ -79,7 +79,7 @@ alpha*-*-*)
>  am33_2.0*-*-linux*)
>  	# Target: Matsushita mn10300 (AM33) running Linux
>  	gdb_target_obs="mn10300-tdep.o mn10300-linux-tdep.o linux-tdep.o \
> -			solib-svr4.o"
> +			linux-maps.o solib-svr4.o"
>  	;;
>  
>  arm*-wince-pe | arm*-*-mingw32ce*)
> @@ -90,7 +90,8 @@ arm*-wince-pe | arm*-*-mingw32ce*)
>  arm*-*-linux*)
>  	# Target: ARM based machine running GNU/Linux
>  	gdb_target_obs="arm-tdep.o arm-linux-tdep.o glibc-tdep.o \
> -			solib-svr4.o symfile-mem.o linux-tdep.o linux-record.o"
> +			solib-svr4.o symfile-mem.o linux-tdep.o linux-maps.o \
> +			linux-record.o"
>  	build_gdbserver=yes
>  	;;
>  arm*-*-netbsd* | arm*-*-knetbsd*-gnu)
> @@ -120,7 +121,7 @@ avr-*-*)
>  
>  bfin-*-*linux*)
>  	# Target: Blackfin Linux
> -	gdb_target_obs="bfin-tdep.o bfin-linux-tdep.o linux-tdep.o"
> +	gdb_target_obs="bfin-tdep.o bfin-linux-tdep.o linux-tdep.o linux-maps.o"
>  	gdb_sim=../sim/bfin/libsim.a
>  	build_gdbserver=yes
>  	;;
> @@ -132,12 +133,14 @@ bfin-*-*)
>  
>  cris*)
>  	# Target: CRIS
> -	gdb_target_obs="cris-tdep.o cris-linux-tdep.o linux-tdep.o solib-svr4.o"
> +	gdb_target_obs="cris-tdep.o cris-linux-tdep.o linux-tdep.o \
> +			linux-maps.o solib-svr4.o"
>  	;;
>  
>  frv-*-*)
>  	# Target: Fujitsu FRV processor
> -	gdb_target_obs="frv-tdep.o frv-linux-tdep.o linux-tdep.o solib-frv.o"
> +	gdb_target_obs="frv-tdep.o frv-linux-tdep.o linux-tdep.o linux-maps.o \
> +			solib-frv.o"
>  	gdb_sim=../sim/frv/libsim.a
>  	;;
>  
> @@ -155,7 +158,7 @@ h8300-*-*)
>  hppa*-*-linux*)
>  	# Target: HP PA-RISC running Linux
>  	gdb_target_obs="hppa-tdep.o hppa-linux-tdep.o glibc-tdep.o \
> -			linux-tdep.o solib-svr4.o symfile-mem.o"
> +			linux-tdep.o linux-maps.o solib-svr4.o symfile-mem.o"
>  	;;
>  hppa*-*-netbsd*)
>  	# Target: NetBSD/hppa
> @@ -218,7 +221,7 @@ i[34567]86-*-linux*)
>  	# Target: Intel 386 running GNU/Linux
>  	gdb_target_obs="i386-tdep.o i386-linux-tdep.o glibc-tdep.o i387-tdep.o \
>  			solib-svr4.o symfile-mem.o \
> -			linux-tdep.o linux-record.o"
> +			linux-tdep.o linux-maps.o linux-record.o"
>  	if test "x$enable_64_bit_bfd" = "xyes"; then
>  	    # Target: GNU/Linux x86-64
>  	    gdb_target_obs="amd64-tdep.o amd64-linux-tdep.o ${gdb_target_obs}"
> @@ -249,7 +252,7 @@ i[34567]86-*-*)
>  ia64-*-linux*)
>  	# Target: Intel IA-64 running GNU/Linux
>  	gdb_target_obs="ia64-tdep.o ia64-linux-tdep.o linux-tdep.o \
> -			solib-svr4.o symfile-mem.o"
> +			linux-maps.o solib-svr4.o symfile-mem.o"
>  	build_gdbserver=yes
>  	;;
>  ia64-*-*vms*)
> @@ -283,7 +286,7 @@ m32r*-*-linux*)
>  	# Target: Renesas M32R running GNU/Linux
>  	gdb_target_obs="m32r-tdep.o m32r-linux-tdep.o remote-m32r-sdi.o \
>  			glibc-tdep.o solib-svr4.o symfile-mem.o \
> -			linux-tdep.o"
> +			linux-tdep.o linux-maps.o"
>  	gdb_sim=../sim/m32r/libsim.a
>  	build_gdbserver=yes
>  	;;
> @@ -308,7 +311,7 @@ fido-*-elf*)
>  m68*-*-linux*)
>  	# Target: Motorola m68k with a.out and ELF
>  	gdb_target_obs="m68k-tdep.o m68klinux-tdep.o solib-svr4.o \
> -			linux-tdep.o glibc-tdep.o symfile-mem.o"
> +			linux-tdep.o linux-maps.o glibc-tdep.o symfile-mem.o"
>  	build_gdbserver=yes
>  	;;
>  m68*-*-netbsd* | m68*-*-knetbsd*-gnu)
> @@ -334,7 +337,8 @@ mep-*-*)
>  microblaze*-linux-*|microblaze*-*-linux*)
>  	# Target: Xilinx MicroBlaze running Linux
>  	gdb_target_obs="microblaze-tdep.o microblaze-linux-tdep.o microblaze-rom.o \
> -			monitor.o dsrec.o solib-svr4.o symfile-mem.o linux-tdep.o"
> +			monitor.o dsrec.o solib-svr4.o symfile-mem.o \
> +			linux-tdep.o linux-maps.o"
>  	gdb_sim=../sim/microblaze/libsim.a
>  	;;
>  microblaze*-*-*)
> @@ -346,7 +350,7 @@ microblaze*-*-*)
>  mips*-*-linux*)
>  	# Target: Linux/MIPS
>  	gdb_target_obs="mips-tdep.o mips-linux-tdep.o glibc-tdep.o \
> -			solib-svr4.o symfile-mem.o linux-tdep.o"
> +			solib-svr4.o symfile-mem.o linux-tdep.o linux-maps.o"
>  	gdb_sim=../sim/mips/libsim.a
>  	build_gdbserver=yes
>  	;;
> @@ -394,7 +398,7 @@ mt-*-*)
>  nios2*-*-linux*)
>  	# Target: Altera Nios II running Linux
>  	gdb_target_obs="nios2-tdep.o nios2-linux-tdep.o solib-svr4.o \
> -			symfile-mem.o glibc-tdep.o linux-tdep.o"
> +			symfile-mem.o glibc-tdep.o linux-tdep.o linux-maps.o"
>  	;;
>  
>  nios2*-*-*)
> @@ -433,7 +437,7 @@ powerpc*-*-linux*)
>  	gdb_target_obs="rs6000-tdep.o ppc-linux-tdep.o ppc-sysv-tdep.o \
>  			ppc64-tdep.o solib-svr4.o solib-spu.o \
>  			spu-multiarch.o \
> -			glibc-tdep.o symfile-mem.o linux-tdep.o \
> +			glibc-tdep.o symfile-mem.o linux-tdep.o linux-maps.o \
>  			ravenscar-thread.o ppc-ravenscar-thread.o \
>  			linux-record.o "
>  	gdb_sim=../sim/ppc/libsim.a
> @@ -457,7 +461,7 @@ powerpc*-*-*)
>  
>  s390*-*-linux*)
>  	# Target: S390 running Linux
> -	gdb_target_obs="s390-linux-tdep.o solib-svr4.o linux-tdep.o"
> +	gdb_target_obs="s390-linux-tdep.o solib-svr4.o linux-tdep.o linux-maps.o"
>  	build_gdbserver=yes
>  	;;
>  
> @@ -486,7 +490,7 @@ sh*-*-linux*)
>  	# Target: GNU/Linux Super-H
>  	gdb_target_obs="sh-tdep.o sh64-tdep.o sh-linux-tdep.o monitor.o \
>  			dsrec.o solib-svr4.o symfile-mem.o \
> -			glibc-tdep.o linux-tdep.o"
> +			glibc-tdep.o linux-tdep.o linux-maps.o"
>  	gdb_sim=../sim/sh/libsim.a
>  	build_gdbserver=yes
>  	;;
> @@ -514,7 +518,7 @@ sparc-*-linux*)
>  	# Target: GNU/Linux SPARC
>  	gdb_target_obs="sparc-tdep.o sparc-sol2-tdep.o sol2-tdep.o \
>  			sparc-linux-tdep.o solib-svr4.o symfile-mem.o \
> -			linux-tdep.o \
> +			linux-tdep.o linux-maps.o \
>  			ravenscar-thread.o sparc-ravenscar-thread.o"
>  	if test "x$enable_64_bit_bfd" = "xyes"; then
>  	    # Target: GNU/Linux UltraSPARC
> @@ -528,7 +532,8 @@ sparc64-*-linux*)
>  	gdb_target_obs="sparc64-tdep.o sparc64-sol2-tdep.o sol2-tdep.o \
>  			sparc64-linux-tdep.o sparc-tdep.o sparc-sol2-tdep.o \
>  			sparc-linux-tdep.o solib-svr4.o linux-tdep.o \
> -			ravenscar-thread.o sparc-ravenscar-thread.o"
> +			linux-maps.o ravenscar-thread.o \
> +			sparc-ravenscar-thread.o"
>  	build_gdbserver=yes
>  	;;
>  sparc*-*-freebsd* | sparc*-*-kfreebsd*-gnu)
> @@ -595,7 +600,7 @@ spu*-*-*)
>  tic6x-*-*linux)
>  	# Target: GNU/Linux TI C6x
>  	gdb_target_obs="tic6x-tdep.o tic6x-linux-tdep.o solib-dsbt.o \
> -			glibc-tdep.o linux-tdep.o"
> +			glibc-tdep.o linux-tdep.o linux-maps.o"
>  	;;
>  
>  tic6x-*-*)
> @@ -606,7 +611,7 @@ tic6x-*-*)
>  tilegx-*-linux*)
>  	# Target: TILE-Gx
>  	gdb_target_obs="tilegx-tdep.o tilegx-linux-tdep.o solib-svr4.o \
> -			symfile-mem.o glibc-tdep.o linux-tdep.o"
> +			symfile-mem.o glibc-tdep.o linux-tdep.o linux-maps.o"
>  	build_gdbserver=yes
>  	;;
>  
> @@ -656,7 +661,8 @@ x86_64-*-linux*)
>  	# Target: GNU/Linux x86-64
>  	gdb_target_obs="amd64-tdep.o amd64-linux-tdep.o i386-tdep.o \
>  			i387-tdep.o i386-linux-tdep.o glibc-tdep.o \
> -			solib-svr4.o symfile-mem.o linux-tdep.o linux-record.o"
> +			solib-svr4.o symfile-mem.o linux-tdep.o linux-maps.o \
> +			linux-record.o"
>  	build_gdbserver=yes
>  	;;
>  x86_64-*-freebsd* | x86_64-*-kfreebsd*-gnu)
> @@ -686,7 +692,7 @@ x86_64-*-openbsd*)
>  xtensa*-*-linux*)	gdb_target=linux
>  	# Target: GNU/Linux Xtensa
>  	gdb_target_obs="xtensa-tdep.o xtensa-config.o xtensa-linux-tdep.o \
> -			solib-svr4.o symfile-mem.o linux-tdep.o"
> +			solib-svr4.o symfile-mem.o linux-tdep.o linux-maps.o"
>  	build_gdbserver=yes
>  	;;
>  xtensa*)
> diff --git a/gdb/gdbserver/Makefile.in b/gdb/gdbserver/Makefile.in
> index fc250fb..908061a 100644
> --- a/gdb/gdbserver/Makefile.in
> +++ b/gdb/gdbserver/Makefile.in
> @@ -194,7 +194,7 @@ OBS = agent.o ax.o inferiors.o regcache.o remote-utils.o server.o signals.o \
>        mem-break.o hostio.o event-loop.o tracepoint.o xml-utils.o \
>        common-utils.o ptid.o buffer.o format.o filestuff.o dll.o notif.o \
>        tdesc.o print-utils.o rsp-low.o errors.o common-debug.o cleanups.o \
> -      common-exceptions.o symbol.o btrace-common.o fileio.o \
> +      common-exceptions.o symbol.o btrace-common.o fileio.o target-utils.o \
>        $(XML_BUILTIN) $(DEPFILES) $(LIBOBJS)
>  GDBREPLAY_OBS = gdbreplay.o version.o
>  GDBSERVER_LIBS = @GDBSERVER_LIBS@
> @@ -519,6 +519,9 @@ ax.o: ax.c
>  signals.o: ../common/signals.c
>  	$(COMPILE) $<
>  	$(POSTCOMPILE)
> +linux-maps.o: ../nat/linux-maps.c
> +	$(COMPILE) $<
> +	$(POSTCOMPILE)
>  print-utils.o: ../common/print-utils.c
>  	$(COMPILE) $<
>  	$(POSTCOMPILE)
> @@ -531,6 +534,9 @@ common-utils.o: ../common/common-utils.c
>  posix-strerror.o: ../common/posix-strerror.c
>  	$(COMPILE) $<
>  	$(POSTCOMPILE)
> +target-utils.o: ../target/target-utils.c
> +	$(COMPILE) $<
> +	$(POSTCOMPILE)
>  mingw-strerror.o: ../common/mingw-strerror.c
>  	$(COMPILE) $<
>  	$(POSTCOMPILE)
> diff --git a/gdb/gdbserver/configure.srv b/gdb/gdbserver/configure.srv
> index 7f89f2f..ac324ff 100644
> --- a/gdb/gdbserver/configure.srv
> +++ b/gdb/gdbserver/configure.srv
> @@ -42,7 +42,7 @@ srv_amd64_linux_xmlfiles="i386/amd64-linux.xml i386/amd64-avx-linux.xml i386/amd
>  
>  # Linux object files.  This is so we don't have to repeat
>  # these files over and over again.
> -srv_linux_obj="linux-low.o linux-osdata.o linux-procfs.o linux-ptrace.o linux-waitpid.o linux-personality.o linux-namespaces.o"
> +srv_linux_obj="linux-low.o linux-osdata.o linux-procfs.o linux-maps.o linux-ptrace.o linux-waitpid.o linux-personality.o linux-namespaces.o"
>  
>  # Input is taken from the "${target}" variable.
>  
> diff --git a/gdb/nat/linux-maps.c b/gdb/nat/linux-maps.c
> new file mode 100644
> index 0000000..01c8836
> --- /dev/null
> +++ b/gdb/nat/linux-maps.c
> @@ -0,0 +1,20 @@
> +/* Linux-specific memory maps manipulation routines.
> +   Copyright (C) 2015 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/>.  */
> +
> +#include "common-defs.h"
> +#include "linux-maps.h"
> diff --git a/gdb/nat/linux-maps.h b/gdb/nat/linux-maps.h
> new file mode 100644
> index 0000000..2cff321
> --- /dev/null
> +++ b/gdb/nat/linux-maps.h
> @@ -0,0 +1,22 @@
> +/* Linux-specific memory maps manipulation routines.
> +   Copyright (C) 2015 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 NAT_LINUX_MAPS_H
> +#define NAT_LINUX_MAPS_H
> +
> +#endif /* NAT_LINUX_MAPS_H */
> diff --git a/gdb/target/target-utils.c b/gdb/target/target-utils.c
> new file mode 100644
> index 0000000..4e8fae7
> --- /dev/null
> +++ b/gdb/target/target-utils.c
> @@ -0,0 +1,21 @@
> +/* Utility target functions for GDB, and GDBserver.
> +
> +   Copyright (C) 2015 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/>.  */
> +
> +#include "common-defs.h"
> +#include "target/target-utils.h"
> diff --git a/gdb/target/target-utils.h b/gdb/target/target-utils.h
> new file mode 100644
> index 0000000..443ffc3
> --- /dev/null
> +++ b/gdb/target/target-utils.h
> @@ -0,0 +1,23 @@
> +/* Utility target functions for GDB, and GDBserver.
> +
> +   Copyright (C) 2015 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 TARGET_TARGET_UTILS_H
> +#define TARGET_TARGET_UTILS_H
> +
> +#endif /* TARGET_TARGET_UTILS_H */
  
Jan Kratochvil July 16, 2015, 8:32 a.m. UTC | #2
On Thu, 16 Jul 2015 10:14:12 +0200, Gary Benson wrote:
> I don't fully understand the tdep/non-tdep split very well.

I understand that *-tdep.c is all of the support that makes sense for all the
arch support that can be done cross-arch for loading/examining files plus all
the arch support usable with remote gdbserver (cross-arch in general, with
gdbserver it can be also native-arch but that does not matter).

linux-maps.[ch] provides linux_find_memory_regions_full() which is used in
linux-tdep.c and in gdbserver but for mostly unrelated purposes, so it is
rather just a code reuse and it is not architecturally the same functionality
called from both linux-nat+gdbserver just because linux-nat hasn't been
dropped yet.

linux-maps.[ch] also exports its read_mapping() to linux-tdep.c which is again
only arbitrary code reuse from two unrelated places of code.


Jan
  
Pedro Alves July 21, 2015, 10:28 a.m. UTC | #3
On 07/16/2015 09:14 AM, Gary Benson wrote:
> Jan Kratochvil wrote:
>> On Mon, 08 Jun 2015 10:37:33 +0200, Gary Benson wrote:
>>> A bunch of stuff has changed in the way common code is laid out
>>> since May 2014, so while Tom approved this back then, it's not
>>> suitable any more.  Please update the series as follows:
>>>
>>>> 	* common/linux-maps.c: New file.
>>>> 	* common/linux-maps.h: New file.
>>>
>>> Nothing os-specific should be in common.  These files should be
>>> nat/linux-maps.[ch].
>>
>> While I have done so I do not share this opinion.  linux-maps.[ch]
>> is used from linux-tdep.c and not from linux-nat.c.  linux-tdep.c is
>> using common/* files a lot but it uses no function from nat/*:
>>
>> 	$ for i in $(for i in common/*.c;do nm `basename $i .c`.o;done|sed -n 's/^.* T //p');do grep -q "\<$i (" linux-tdep.c && echo $i;done|wc -l
>> 	17
>> 	$ for i in $(for i in    nat/*.c;do nm `basename $i .c`.o;done|sed -n 's/^.* T //p');do grep -q "\<$i (" linux-tdep.c && echo $i;done|wc -l
>> 	0
>> 	(commands above assume in-src-tree build)
>>
>> Additionally linux-maps.o should not be in config/**.mh::NATDEPFILES
>> (like linux-namespaces.o from nat/ ) but it needs to be in
>> configure.tgt instead.
>>
>> Should be linux-maps.[ch] therefore in nat/ or in common/ ?
>> If it matters, though.
> 
> I don't fully understand the tdep/non-tdep split very well.
> Pedro, could you comment?

TL;DR: roughly, nat/ holds native target_ops code, while tdep
files hold gdbarch code.

The idea of nat/ is to hold host-dependent code that implements
the native target (target_ops) backends.  Code in that directory makes use
of native system debug APIs, constants, etc..  Such code cannot be used
on a cross debugger that targets the OS the code is for, because it
e.g., relies on headers that will only exist on that target OS.
nat/ code is used by either gdb's native target_ops target, or, gdbserver's.
E.g., a --host=mingw32 --target=x86_64-linux gdb can't build the native
Linux code in nat/.

In contrast, the tdep files files contain code that _must_ be
host-independent.  The same --host=mingw32 --target=x86_64-linux gdb
build includes the linux-specific -tdep files.

A -tdep.c file including a "nat/foo.h" header thus raises
the abstraction-violation alarm bell.  It's at the same level of
a -tdep.c file including <sys/ptrace.h>.

So seems to me this maps code should not be in nat/.

Thanks,
Pedro Alves
  

Patch

diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index dfaa8a3..237da9d 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -903,7 +903,7 @@  LINTFILES = $(SFILES) $(YYFILES) $(CONFIG_SRCS) init.c
 # right, it is probably easiest just to list .h files here directly.
 
 HFILES_NO_SRCDIR = \
-common/gdb_signals.h nat/gdb_thread_db.h common/gdb_vecs.h \
+common/gdb_signals.h nat/gdb_thread_db.h common/gdb_vecs.h nat/linux-maps.h \
 common/x86-xstate.h nat/linux-ptrace.h nat/mips-linux-watch.h \
 proc-utils.h aarch64-tdep.h arm-tdep.h ax-gdb.h ppcfbsd-tdep.h \
 ppcnbsd-tdep.h cli-out.h gdb_expat.h breakpoint.h infcall.h obsd-tdep.h \
@@ -983,7 +983,7 @@  common/common-debug.h common/cleanups.h common/gdb_setjmp.h \
 common/common-exceptions.h target/target.h common/symbol.h \
 common/common-regcache.h fbsd-tdep.h nat/linux-personality.h \
 common/fileio.h nat/x86-linux.h nat/x86-linux-dregs.h \
-nat/linux-namespaces.h
+nat/linux-namespaces.h target/target-utils.h
 
 # Header files that already have srcdir in them, or which are in objdir.
 
@@ -1083,7 +1083,7 @@  COMMON_OBS = $(DEPFILES) $(CONFIG_OBS) $(YYOBJ) \
 	common-utils.o buffer.o ptid.o gdb-dlfcn.o common-agent.o \
 	format.o registry.o btrace.o record-btrace.o waitstatus.o \
 	print-utils.o rsp-low.o errors.o common-debug.o debug.o \
-	common-exceptions.o btrace-common.o fileio.o \
+	common-exceptions.o btrace-common.o fileio.o target-utils.o \
 	$(SUBDIR_GCC_COMPILE_OBS)
 
 TSOBS = inflow.o
@@ -2221,6 +2221,10 @@  common-agent.o: $(srcdir)/common/agent.c
 	$(COMPILE) $(srcdir)/common/agent.c
 	$(POSTCOMPILE)
 
+linux-maps.o: ${srcdir}/nat/linux-maps.c
+	$(COMPILE) $(srcdir)/nat/linux-maps.c
+	$(POSTCOMPILE)
+
 vec.o: ${srcdir}/common/vec.c
 	$(COMPILE) $(srcdir)/common/vec.c
 	$(POSTCOMPILE)
@@ -2237,6 +2241,10 @@  errors.o: ${srcdir}/common/errors.c
 	$(COMPILE) $(srcdir)/common/errors.c
 	$(POSTCOMPILE)
 
+target-utils.o: ${srcdir}/target/target-utils.c
+	$(COMPILE) $(srcdir)/target/target-utils.c
+	$(POSTCOMPILE)
+
 common-debug.o: ${srcdir}/common/common-debug.c
 	$(COMPILE) $(srcdir)/common/common-debug.c
 	$(POSTCOMPILE)
diff --git a/gdb/configure.tgt b/gdb/configure.tgt
index f2c1a2d..20873c3 100644
--- a/gdb/configure.tgt
+++ b/gdb/configure.tgt
@@ -45,7 +45,7 @@  aarch64*-*-linux*)
 	# Target: AArch64 linux
 	gdb_target_obs="aarch64-tdep.o aarch64-linux-tdep.o \
 			arm-tdep.o arm-linux-tdep.o \
-			glibc-tdep.o linux-tdep.o solib-svr4.o \
+			glibc-tdep.o linux-tdep.o linux-maps.o solib-svr4.o \
 			symfile-mem.o linux-record.o"
 	build_gdbserver=yes
 	;;
@@ -53,7 +53,7 @@  aarch64*-*-linux*)
 alpha*-*-linux*)
 	# Target: Little-endian Alpha running Linux
 	gdb_target_obs="alpha-tdep.o alpha-mdebug-tdep.o alpha-linux-tdep.o \
-			linux-tdep.o solib-svr4.o"
+			linux-tdep.o linux-maps.o solib-svr4.o"
 	;;
 alpha*-*-freebsd* | alpha*-*-kfreebsd*-gnu)
 	# Target: FreeBSD/alpha
@@ -79,7 +79,7 @@  alpha*-*-*)
 am33_2.0*-*-linux*)
 	# Target: Matsushita mn10300 (AM33) running Linux
 	gdb_target_obs="mn10300-tdep.o mn10300-linux-tdep.o linux-tdep.o \
-			solib-svr4.o"
+			linux-maps.o solib-svr4.o"
 	;;
 
 arm*-wince-pe | arm*-*-mingw32ce*)
@@ -90,7 +90,8 @@  arm*-wince-pe | arm*-*-mingw32ce*)
 arm*-*-linux*)
 	# Target: ARM based machine running GNU/Linux
 	gdb_target_obs="arm-tdep.o arm-linux-tdep.o glibc-tdep.o \
-			solib-svr4.o symfile-mem.o linux-tdep.o linux-record.o"
+			solib-svr4.o symfile-mem.o linux-tdep.o linux-maps.o \
+			linux-record.o"
 	build_gdbserver=yes
 	;;
 arm*-*-netbsd* | arm*-*-knetbsd*-gnu)
@@ -120,7 +121,7 @@  avr-*-*)
 
 bfin-*-*linux*)
 	# Target: Blackfin Linux
-	gdb_target_obs="bfin-tdep.o bfin-linux-tdep.o linux-tdep.o"
+	gdb_target_obs="bfin-tdep.o bfin-linux-tdep.o linux-tdep.o linux-maps.o"
 	gdb_sim=../sim/bfin/libsim.a
 	build_gdbserver=yes
 	;;
@@ -132,12 +133,14 @@  bfin-*-*)
 
 cris*)
 	# Target: CRIS
-	gdb_target_obs="cris-tdep.o cris-linux-tdep.o linux-tdep.o solib-svr4.o"
+	gdb_target_obs="cris-tdep.o cris-linux-tdep.o linux-tdep.o \
+			linux-maps.o solib-svr4.o"
 	;;
 
 frv-*-*)
 	# Target: Fujitsu FRV processor
-	gdb_target_obs="frv-tdep.o frv-linux-tdep.o linux-tdep.o solib-frv.o"
+	gdb_target_obs="frv-tdep.o frv-linux-tdep.o linux-tdep.o linux-maps.o \
+			solib-frv.o"
 	gdb_sim=../sim/frv/libsim.a
 	;;
 
@@ -155,7 +158,7 @@  h8300-*-*)
 hppa*-*-linux*)
 	# Target: HP PA-RISC running Linux
 	gdb_target_obs="hppa-tdep.o hppa-linux-tdep.o glibc-tdep.o \
-			linux-tdep.o solib-svr4.o symfile-mem.o"
+			linux-tdep.o linux-maps.o solib-svr4.o symfile-mem.o"
 	;;
 hppa*-*-netbsd*)
 	# Target: NetBSD/hppa
@@ -218,7 +221,7 @@  i[34567]86-*-linux*)
 	# Target: Intel 386 running GNU/Linux
 	gdb_target_obs="i386-tdep.o i386-linux-tdep.o glibc-tdep.o i387-tdep.o \
 			solib-svr4.o symfile-mem.o \
-			linux-tdep.o linux-record.o"
+			linux-tdep.o linux-maps.o linux-record.o"
 	if test "x$enable_64_bit_bfd" = "xyes"; then
 	    # Target: GNU/Linux x86-64
 	    gdb_target_obs="amd64-tdep.o amd64-linux-tdep.o ${gdb_target_obs}"
@@ -249,7 +252,7 @@  i[34567]86-*-*)
 ia64-*-linux*)
 	# Target: Intel IA-64 running GNU/Linux
 	gdb_target_obs="ia64-tdep.o ia64-linux-tdep.o linux-tdep.o \
-			solib-svr4.o symfile-mem.o"
+			linux-maps.o solib-svr4.o symfile-mem.o"
 	build_gdbserver=yes
 	;;
 ia64-*-*vms*)
@@ -283,7 +286,7 @@  m32r*-*-linux*)
 	# Target: Renesas M32R running GNU/Linux
 	gdb_target_obs="m32r-tdep.o m32r-linux-tdep.o remote-m32r-sdi.o \
 			glibc-tdep.o solib-svr4.o symfile-mem.o \
-			linux-tdep.o"
+			linux-tdep.o linux-maps.o"
 	gdb_sim=../sim/m32r/libsim.a
 	build_gdbserver=yes
 	;;
@@ -308,7 +311,7 @@  fido-*-elf*)
 m68*-*-linux*)
 	# Target: Motorola m68k with a.out and ELF
 	gdb_target_obs="m68k-tdep.o m68klinux-tdep.o solib-svr4.o \
-			linux-tdep.o glibc-tdep.o symfile-mem.o"
+			linux-tdep.o linux-maps.o glibc-tdep.o symfile-mem.o"
 	build_gdbserver=yes
 	;;
 m68*-*-netbsd* | m68*-*-knetbsd*-gnu)
@@ -334,7 +337,8 @@  mep-*-*)
 microblaze*-linux-*|microblaze*-*-linux*)
 	# Target: Xilinx MicroBlaze running Linux
 	gdb_target_obs="microblaze-tdep.o microblaze-linux-tdep.o microblaze-rom.o \
-			monitor.o dsrec.o solib-svr4.o symfile-mem.o linux-tdep.o"
+			monitor.o dsrec.o solib-svr4.o symfile-mem.o \
+			linux-tdep.o linux-maps.o"
 	gdb_sim=../sim/microblaze/libsim.a
 	;;
 microblaze*-*-*)
@@ -346,7 +350,7 @@  microblaze*-*-*)
 mips*-*-linux*)
 	# Target: Linux/MIPS
 	gdb_target_obs="mips-tdep.o mips-linux-tdep.o glibc-tdep.o \
-			solib-svr4.o symfile-mem.o linux-tdep.o"
+			solib-svr4.o symfile-mem.o linux-tdep.o linux-maps.o"
 	gdb_sim=../sim/mips/libsim.a
 	build_gdbserver=yes
 	;;
@@ -394,7 +398,7 @@  mt-*-*)
 nios2*-*-linux*)
 	# Target: Altera Nios II running Linux
 	gdb_target_obs="nios2-tdep.o nios2-linux-tdep.o solib-svr4.o \
-			symfile-mem.o glibc-tdep.o linux-tdep.o"
+			symfile-mem.o glibc-tdep.o linux-tdep.o linux-maps.o"
 	;;
 
 nios2*-*-*)
@@ -433,7 +437,7 @@  powerpc*-*-linux*)
 	gdb_target_obs="rs6000-tdep.o ppc-linux-tdep.o ppc-sysv-tdep.o \
 			ppc64-tdep.o solib-svr4.o solib-spu.o \
 			spu-multiarch.o \
-			glibc-tdep.o symfile-mem.o linux-tdep.o \
+			glibc-tdep.o symfile-mem.o linux-tdep.o linux-maps.o \
 			ravenscar-thread.o ppc-ravenscar-thread.o \
 			linux-record.o "
 	gdb_sim=../sim/ppc/libsim.a
@@ -457,7 +461,7 @@  powerpc*-*-*)
 
 s390*-*-linux*)
 	# Target: S390 running Linux
-	gdb_target_obs="s390-linux-tdep.o solib-svr4.o linux-tdep.o"
+	gdb_target_obs="s390-linux-tdep.o solib-svr4.o linux-tdep.o linux-maps.o"
 	build_gdbserver=yes
 	;;
 
@@ -486,7 +490,7 @@  sh*-*-linux*)
 	# Target: GNU/Linux Super-H
 	gdb_target_obs="sh-tdep.o sh64-tdep.o sh-linux-tdep.o monitor.o \
 			dsrec.o solib-svr4.o symfile-mem.o \
-			glibc-tdep.o linux-tdep.o"
+			glibc-tdep.o linux-tdep.o linux-maps.o"
 	gdb_sim=../sim/sh/libsim.a
 	build_gdbserver=yes
 	;;
@@ -514,7 +518,7 @@  sparc-*-linux*)
 	# Target: GNU/Linux SPARC
 	gdb_target_obs="sparc-tdep.o sparc-sol2-tdep.o sol2-tdep.o \
 			sparc-linux-tdep.o solib-svr4.o symfile-mem.o \
-			linux-tdep.o \
+			linux-tdep.o linux-maps.o \
 			ravenscar-thread.o sparc-ravenscar-thread.o"
 	if test "x$enable_64_bit_bfd" = "xyes"; then
 	    # Target: GNU/Linux UltraSPARC
@@ -528,7 +532,8 @@  sparc64-*-linux*)
 	gdb_target_obs="sparc64-tdep.o sparc64-sol2-tdep.o sol2-tdep.o \
 			sparc64-linux-tdep.o sparc-tdep.o sparc-sol2-tdep.o \
 			sparc-linux-tdep.o solib-svr4.o linux-tdep.o \
-			ravenscar-thread.o sparc-ravenscar-thread.o"
+			linux-maps.o ravenscar-thread.o \
+			sparc-ravenscar-thread.o"
 	build_gdbserver=yes
 	;;
 sparc*-*-freebsd* | sparc*-*-kfreebsd*-gnu)
@@ -595,7 +600,7 @@  spu*-*-*)
 tic6x-*-*linux)
 	# Target: GNU/Linux TI C6x
 	gdb_target_obs="tic6x-tdep.o tic6x-linux-tdep.o solib-dsbt.o \
-			glibc-tdep.o linux-tdep.o"
+			glibc-tdep.o linux-tdep.o linux-maps.o"
 	;;
 
 tic6x-*-*)
@@ -606,7 +611,7 @@  tic6x-*-*)
 tilegx-*-linux*)
 	# Target: TILE-Gx
 	gdb_target_obs="tilegx-tdep.o tilegx-linux-tdep.o solib-svr4.o \
-			symfile-mem.o glibc-tdep.o linux-tdep.o"
+			symfile-mem.o glibc-tdep.o linux-tdep.o linux-maps.o"
 	build_gdbserver=yes
 	;;
 
@@ -656,7 +661,8 @@  x86_64-*-linux*)
 	# Target: GNU/Linux x86-64
 	gdb_target_obs="amd64-tdep.o amd64-linux-tdep.o i386-tdep.o \
 			i387-tdep.o i386-linux-tdep.o glibc-tdep.o \
-			solib-svr4.o symfile-mem.o linux-tdep.o linux-record.o"
+			solib-svr4.o symfile-mem.o linux-tdep.o linux-maps.o \
+			linux-record.o"
 	build_gdbserver=yes
 	;;
 x86_64-*-freebsd* | x86_64-*-kfreebsd*-gnu)
@@ -686,7 +692,7 @@  x86_64-*-openbsd*)
 xtensa*-*-linux*)	gdb_target=linux
 	# Target: GNU/Linux Xtensa
 	gdb_target_obs="xtensa-tdep.o xtensa-config.o xtensa-linux-tdep.o \
-			solib-svr4.o symfile-mem.o linux-tdep.o"
+			solib-svr4.o symfile-mem.o linux-tdep.o linux-maps.o"
 	build_gdbserver=yes
 	;;
 xtensa*)
diff --git a/gdb/gdbserver/Makefile.in b/gdb/gdbserver/Makefile.in
index fc250fb..908061a 100644
--- a/gdb/gdbserver/Makefile.in
+++ b/gdb/gdbserver/Makefile.in
@@ -194,7 +194,7 @@  OBS = agent.o ax.o inferiors.o regcache.o remote-utils.o server.o signals.o \
       mem-break.o hostio.o event-loop.o tracepoint.o xml-utils.o \
       common-utils.o ptid.o buffer.o format.o filestuff.o dll.o notif.o \
       tdesc.o print-utils.o rsp-low.o errors.o common-debug.o cleanups.o \
-      common-exceptions.o symbol.o btrace-common.o fileio.o \
+      common-exceptions.o symbol.o btrace-common.o fileio.o target-utils.o \
       $(XML_BUILTIN) $(DEPFILES) $(LIBOBJS)
 GDBREPLAY_OBS = gdbreplay.o version.o
 GDBSERVER_LIBS = @GDBSERVER_LIBS@
@@ -519,6 +519,9 @@  ax.o: ax.c
 signals.o: ../common/signals.c
 	$(COMPILE) $<
 	$(POSTCOMPILE)
+linux-maps.o: ../nat/linux-maps.c
+	$(COMPILE) $<
+	$(POSTCOMPILE)
 print-utils.o: ../common/print-utils.c
 	$(COMPILE) $<
 	$(POSTCOMPILE)
@@ -531,6 +534,9 @@  common-utils.o: ../common/common-utils.c
 posix-strerror.o: ../common/posix-strerror.c
 	$(COMPILE) $<
 	$(POSTCOMPILE)
+target-utils.o: ../target/target-utils.c
+	$(COMPILE) $<
+	$(POSTCOMPILE)
 mingw-strerror.o: ../common/mingw-strerror.c
 	$(COMPILE) $<
 	$(POSTCOMPILE)
diff --git a/gdb/gdbserver/configure.srv b/gdb/gdbserver/configure.srv
index 7f89f2f..ac324ff 100644
--- a/gdb/gdbserver/configure.srv
+++ b/gdb/gdbserver/configure.srv
@@ -42,7 +42,7 @@  srv_amd64_linux_xmlfiles="i386/amd64-linux.xml i386/amd64-avx-linux.xml i386/amd
 
 # Linux object files.  This is so we don't have to repeat
 # these files over and over again.
-srv_linux_obj="linux-low.o linux-osdata.o linux-procfs.o linux-ptrace.o linux-waitpid.o linux-personality.o linux-namespaces.o"
+srv_linux_obj="linux-low.o linux-osdata.o linux-procfs.o linux-maps.o linux-ptrace.o linux-waitpid.o linux-personality.o linux-namespaces.o"
 
 # Input is taken from the "${target}" variable.
 
diff --git a/gdb/nat/linux-maps.c b/gdb/nat/linux-maps.c
new file mode 100644
index 0000000..01c8836
--- /dev/null
+++ b/gdb/nat/linux-maps.c
@@ -0,0 +1,20 @@ 
+/* Linux-specific memory maps manipulation routines.
+   Copyright (C) 2015 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/>.  */
+
+#include "common-defs.h"
+#include "linux-maps.h"
diff --git a/gdb/nat/linux-maps.h b/gdb/nat/linux-maps.h
new file mode 100644
index 0000000..2cff321
--- /dev/null
+++ b/gdb/nat/linux-maps.h
@@ -0,0 +1,22 @@ 
+/* Linux-specific memory maps manipulation routines.
+   Copyright (C) 2015 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 NAT_LINUX_MAPS_H
+#define NAT_LINUX_MAPS_H
+
+#endif /* NAT_LINUX_MAPS_H */
diff --git a/gdb/target/target-utils.c b/gdb/target/target-utils.c
new file mode 100644
index 0000000..4e8fae7
--- /dev/null
+++ b/gdb/target/target-utils.c
@@ -0,0 +1,21 @@ 
+/* Utility target functions for GDB, and GDBserver.
+
+   Copyright (C) 2015 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/>.  */
+
+#include "common-defs.h"
+#include "target/target-utils.h"
diff --git a/gdb/target/target-utils.h b/gdb/target/target-utils.h
new file mode 100644
index 0000000..443ffc3
--- /dev/null
+++ b/gdb/target/target-utils.h
@@ -0,0 +1,23 @@ 
+/* Utility target functions for GDB, and GDBserver.
+
+   Copyright (C) 2015 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 TARGET_TARGET_UTILS_H
+#define TARGET_TARGET_UTILS_H
+
+#endif /* TARGET_TARGET_UTILS_H */