]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Created a new module, m_aspacehl. Factored out three(!) copies of
authorNicholas Nethercote <njn@valgrind.org>
Fri, 8 May 2009 00:39:31 +0000 (00:39 +0000)
committerNicholas Nethercote <njn@valgrind.org>
Fri, 8 May 2009 00:39:31 +0000 (00:39 +0000)
get_seg_starts() into it.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@9796

coregrind/Makefile.am
coregrind/m_aspacehl.c [new file with mode: 0644]
coregrind/m_coredump/coredump-elf.c
coregrind/m_main.c
coregrind/pub_core_aspacehl.h [new file with mode: 0644]
include/Makefile.am
include/pub_tool_aspacehl.h [new file with mode: 0644]
memcheck/mc_leakcheck.c

index d1b1b096049da4a31db1cf254c3769409465a143..c783cd3abd82b18fd951618cbdfca8ec54133112 100644 (file)
@@ -102,6 +102,7 @@ no_op_client_for_valgrind_LDFLAGS   = $(AM_CFLAGS_PRI)
 
 
 noinst_HEADERS = \
+       pub_core_aspacehl.h     \
        pub_core_aspacemgr.h    \
        pub_core_basics.h       \
        pub_core_basics_asm.h   \
@@ -221,6 +222,7 @@ COREGRIND_SOURCES_COMMON = \
        m_vkiscnums.c \
        m_wordfm.c \
        m_xarray.c \
+       m_aspacehl.c \
        m_aspacemgr/aspacemgr-common.c \
        m_debuginfo/misc.c \
        m_debuginfo/d3basics.c \
diff --git a/coregrind/m_aspacehl.c b/coregrind/m_aspacehl.c
new file mode 100644 (file)
index 0000000..52eb57a
--- /dev/null
@@ -0,0 +1,71 @@
+
+/*--------------------------------------------------------------------*/
+/*--- Services layered on top of m_aspacemgr.         m_aspacehl.c ---*/
+/*--------------------------------------------------------------------*/
+
+/*
+   This file is part of Valgrind, a dynamic binary instrumentation
+   framework.
+
+   Copyright (C) 2006-2009 Julian Seward
+      jseward@acm.org
+
+   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 2 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, write to the Free Software
+   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307, USA.
+
+   The GNU General Public License is contained in the file COPYING.
+*/
+
+#include "pub_core_basics.h"
+#include "pub_core_aspacemgr.h"
+#include "pub_core_mallocfree.h"
+
+#include "pub_core_aspacehl.h"
+
+// Extract from aspacem a vector of the current segment start
+// addresses.  The vector is dynamically allocated and should be freed
+// by the caller when done.  REQUIRES m_mallocfree to be running.
+// Writes the number of addresses required into *n_acquired.
+Addr* VG_(get_segment_starts) ( /*OUT*/Int* n_acquired )
+{
+   Addr* starts;
+   Int   n_starts, r = 0;
+
+   n_starts = 1;
+   while (True) {
+      starts = VG_(malloc)( "main.gss.1", n_starts * sizeof(Addr) );
+      if (starts == NULL)
+         break;
+      r = VG_(am_get_segment_starts)( starts, n_starts );
+      if (r >= 0)
+         break;
+      VG_(free)(starts);
+      n_starts *= 2;
+   }
+
+   if (starts == NULL) {
+     *n_acquired = 0;
+     return NULL;
+   }
+
+   *n_acquired = r;
+   return starts;
+}
+
+
+
+/*--------------------------------------------------------------------*/
+/*--- end                                                          ---*/
+/*--------------------------------------------------------------------*/
index f9b036a15597fcab407da0d962ce56ac2cb04a1c..5ce480147319dfa520b3eb67042bcb5f4f0f845d 100644 (file)
@@ -30,6 +30,7 @@
 
 #include "pub_core_basics.h"
 #include "pub_core_vki.h"
+#include "pub_core_aspacehl.h"
 #include "pub_core_aspacemgr.h"
 #include "pub_core_libcbase.h"
 #include "pub_core_machine.h"
 #error VG_WORDSIZE needs to ==4 or ==8
 #endif
 
-/* TODO: GIVE THIS A PROPER HOME
-   TODO: MERGE THIS WITH DUPLICATES IN m_main.c and mc_leakcheck.c
-   Extract from aspacem a vector of the current segment start
-   addresses.  The vector is dynamically allocated and should be freed
-   by the caller when done.  REQUIRES m_mallocfree to be running.
-   Writes the number of addresses required into *n_acquired. */
-
-static Addr* get_seg_starts ( /*OUT*/Int* n_acquired )
-{
-   Addr* starts;
-   Int   n_starts, r = 0;
-
-   n_starts = 1;
-   while (True) {
-      starts = VG_(malloc)( "coredump-elf.gss.1", n_starts * sizeof(Addr) );
-      if (starts == NULL)
-         break;
-      r = VG_(am_get_segment_starts)( starts, n_starts );
-      if (r >= 0)
-         break;
-      VG_(free)(starts);
-      n_starts *= 2;
-   }
-
-   if (starts == NULL) {
-     *n_acquired = 0;
-     return NULL;
-   }
-
-   *n_acquired = r;
-   return starts;
-}
-
 /* If true, then this Segment may be mentioned in the core */
 static Bool may_dump(const NSegment *seg)
 {
@@ -342,7 +310,7 @@ void make_elf_coredump(ThreadId tid, const vki_siginfo_t *si, UInt max_size)
    }
 
    /* Get the segments */
-   seg_starts = get_seg_starts(&n_seg_starts);
+   seg_starts = VG_(get_segment_starts)(&n_seg_starts);
 
    /* First, count how many memory segments to dump */
    num_phdrs = 1;              /* start with notes */
index 0f9aac644d23a3d3ee6c7d136a7630c6998bd5b5..c8f271daaf54052642d0115cc1118e263c806c1b 100644 (file)
@@ -35,6 +35,7 @@
 #include "pub_core_xarray.h"
 #include "pub_core_clientstate.h"
 #include "pub_core_aspacemgr.h"
+#include "pub_core_aspacehl.h"
 #include "pub_core_commandline.h"
 #include "pub_core_debuglog.h"
 #include "pub_core_errormgr.h"
@@ -1122,40 +1123,6 @@ void shutdown_actions_NORETURN( ThreadId tid,
 /* --- end of Forwards decls to do with shutdown --- */
 
 
-/* TODO: GIVE THIS A PROPER HOME
-   TODO: MERGE THIS WITH DUPLICATE IN mc_leakcheck.c and coredump-elf.c.
-   Extract from aspacem a vector of the current segment start
-   addresses.  The vector is dynamically allocated and should be freed
-   by the caller when done.  REQUIRES m_mallocfree to be running.
-   Writes the number of addresses required into *n_acquired. */
-
-static Addr* get_seg_starts ( /*OUT*/Int* n_acquired )
-{
-   Addr* starts;
-   Int   n_starts, r = 0;
-
-   n_starts = 1;
-   while (True) {
-      starts = VG_(malloc)( "main.gss.1", n_starts * sizeof(Addr) );
-      if (starts == NULL)
-         break;
-      r = VG_(am_get_segment_starts)( starts, n_starts );
-      if (r >= 0)
-         break;
-      VG_(free)(starts);
-      n_starts *= 2;
-   }
-
-   if (starts == NULL) {
-     *n_acquired = 0;
-     return NULL;
-   }
-
-   *n_acquired = r;
-   return starts;
-}
-
-
 /* By the time we get to valgrind_main, the_iicii should already have
    been filled in with any important details as required by whatever
    OS we have been built for.
@@ -1730,7 +1697,7 @@ Int valgrind_main ( Int argc, HChar **argv, HChar **envp )
      Int   n_seg_starts;
      Addr_n_ULong anu;
 
-     seg_starts = get_seg_starts( &n_seg_starts );
+     seg_starts = VG_(get_segment_starts)( &n_seg_starts );
      vg_assert(seg_starts && n_seg_starts >= 0);
 
      /* show them all to the debug info reader.  allow_SkFileV has to
@@ -1842,7 +1809,7 @@ Int valgrind_main ( Int argc, HChar **argv, HChar **envp )
      tl_assert(VG_(running_tid) == VG_INVALID_THREADID);
      VG_(running_tid) = tid_main;
 
-     seg_starts = get_seg_starts( &n_seg_starts );
+     seg_starts = VG_(get_segment_starts)( &n_seg_starts );
      vg_assert(seg_starts && n_seg_starts >= 0);
 
      /* show interesting ones to the tool */
diff --git a/coregrind/pub_core_aspacehl.h b/coregrind/pub_core_aspacehl.h
new file mode 100644 (file)
index 0000000..c3bf8e4
--- /dev/null
@@ -0,0 +1,46 @@
+
+/*--------------------------------------------------------------------*/
+/*--- Services layered on top of m_aspacemgr.  pub_core_aspacehl.h ---*/
+/*--------------------------------------------------------------------*/
+
+/*
+   This file is part of Valgrind, a dynamic binary instrumentation
+   framework.
+
+   Copyright (C) 2009-2009 Julian Seward
+      jseward@acm.org
+
+   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 2 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, write to the Free Software
+   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307, USA.
+
+   The GNU General Public License is contained in the file COPYING.
+*/
+
+#ifndef __PUB_CORE_ASPACEHL_H
+#define __PUB_CORE_ASPACEHL_H
+
+//--------------------------------------------------------------------
+// PURPOSE: This module contains services that would be in m_aspacemgr,
+// except that they use dynamic memory management or something similar
+// that we don't allow in m_aspacemgr.  The "hl" is short for "high level".
+//--------------------------------------------------------------------
+
+#include "pub_tool_aspacehl.h"
+
+#endif   // __PUB_CORE_ASPACEHL_H
+
+/*--------------------------------------------------------------------*/
+/*--- end                                                          ---*/
+/*--------------------------------------------------------------------*/
index e73f5cd63332a7699d8d2d1e0692ef0d467925ce..540e856b7ede5341cc00ef984d305fd6ea30b26f 100644 (file)
@@ -6,6 +6,7 @@ incincdir = $(includedir)/valgrind
 incinc_HEADERS = \
        pub_tool_basics.h               \
        pub_tool_basics_asm.h           \
+       pub_tool_aspacehl.h             \
        pub_tool_aspacemgr.h            \
        pub_tool_clientstate.h          \
        pub_tool_clreq.h                \
diff --git a/include/pub_tool_aspacehl.h b/include/pub_tool_aspacehl.h
new file mode 100644 (file)
index 0000000..6df2376
--- /dev/null
@@ -0,0 +1,44 @@
+
+/*--------------------------------------------------------------------*/
+/*--- Services layered on top of m_aspacemgr.  pub_tool_aspacehl.h ---*/
+/*--------------------------------------------------------------------*/
+
+/*
+   This file is part of Valgrind, a dynamic binary instrumentation
+   framework.
+
+   Copyright (C) 2009-2009 Julian Seward
+      jseward@acm.org
+
+   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 2 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, write to the Free Software
+   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307, USA.
+
+   The GNU General Public License is contained in the file COPYING.
+*/
+
+#ifndef __PUB_TOOL_ASPACEHL_H
+#define __PUB_TOOL_ASPACEHL_H
+
+// Extract from aspacem a vector of the current segment start
+// addresses.  The vector is dynamically allocated and should be freed
+// by the caller when done.  REQUIRES m_mallocfree to be running.
+// Writes the number of addresses required into *n_acquired.
+extern Addr* VG_(get_segment_starts) ( /*OUT*/Int* n_acquired );
+
+#endif   // __PUB_TOOL_ASPACEHL_H
+
+/*--------------------------------------------------------------------*/
+/*--- end                                                          ---*/
+/*--------------------------------------------------------------------*/
index 1a402df6807c8e7dd12d15b1fa728e7d6caba222..a10a84242712c57c28962862fb5eb31fdbd1d9a4 100644 (file)
@@ -30,6 +30,7 @@
 
 #include "pub_tool_basics.h"
 #include "pub_tool_vki.h"
+#include "pub_tool_aspacehl.h"
 #include "pub_tool_aspacemgr.h"
 #include "pub_tool_execontext.h"
 #include "pub_tool_hashtable.h"
@@ -467,40 +468,6 @@ SizeT MC_(blocks_reachable)  = 0;
 SizeT MC_(blocks_suppressed) = 0;
 
 
-/* TODO: GIVE THIS A PROPER HOME
-   TODO: MERGE THIS WITH DUPLICATE IN m_main.c and coredump-elf.c.
-   Extract from aspacem a vector of the current segment start
-   addresses.  The vector is dynamically allocated and should be freed
-   by the caller when done.  REQUIRES m_mallocfree to be running.
-   Writes the number of addresses required into *n_acquired. */
-
-static Addr* get_seg_starts ( /*OUT*/Int* n_acquired )
-{
-   Addr* starts;
-   Int   n_starts, r = 0;
-
-   n_starts = 1;
-   while (True) {
-      starts = VG_(malloc)( "mc.gss.1", n_starts * sizeof(Addr) );
-      if (starts == NULL)
-         break;
-      r = VG_(am_get_segment_starts)( starts, n_starts );
-      if (r >= 0)
-         break;
-      VG_(free)(starts);
-      n_starts *= 2;
-   }
-
-   if (starts == NULL) {
-     *n_acquired = 0;
-     return NULL;
-   }
-
-   *n_acquired = r;
-   return starts;
-}
-
-
 // Determines if a pointer is to a chunk.  Returns the chunk number et al
 // via call-by-reference.
 static Bool
@@ -1007,7 +974,7 @@ void MC_(detect_memory_leaks) ( ThreadId tid, LeakCheckMode mode )
    // pointed to.
    {
       Int   n_seg_starts;
-      Addr* seg_starts = get_seg_starts( &n_seg_starts );
+      Addr* seg_starts = VG_(get_segment_starts)( &n_seg_starts );
 
       tl_assert(seg_starts && n_seg_starts > 0);