]> granicus.if.org Git - strace/commitdiff
mmap_cache: move code for searching a mmap cache from unwind
authorMasatake YAMATO <yamato@redhat.com>
Fri, 16 Feb 2018 19:37:10 +0000 (04:37 +0900)
committerDmitry V. Levin <ldv@altlinux.org>
Mon, 26 Feb 2018 23:22:24 +0000 (23:22 +0000)
print_stack_frame function in unwind.c searches a mmap entry in mmap
cache.  The found entry is then used for unwinding.  However, a function
searching for a mmap entry may be useful for other purposes than
unwinding.

This change re-factors the function; code for searching an entry is
now defined as a stand-alone function named mmap_cache_search.

* defs.h (mmap_cache_search): New function prototype.
print_stack_frame.
* mmap_cached.c (mmap_cache_search): New function derived from
print_stack_frame.
* unwind.c (print_stack_frame): Use it.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
defs.h
mmap_cache.c
unwind.c

diff --git a/defs.h b/defs.h
index 403b20aa1e42a191d75704f1e599f00b36adc369..97bdcd805bcc526d67da4c7c0a592c2a7bd11c04 100644 (file)
--- a/defs.h
+++ b/defs.h
@@ -750,6 +750,7 @@ enum mmap_cache_rebuild_result {
 extern void mmap_cache_invalidate(struct tcb *tcp);
 extern void mmap_cache_delete(struct tcb *tcp, const char *caller);
 extern enum mmap_cache_rebuild_result mmap_cache_rebuild_if_invalid(struct tcb *tcp, const char *caller);
+extern struct mmap_cache_t *mmap_cache_search(struct tcb *tcp, unsigned long ip);
 
 static inline int
 printstrn(struct tcb *tcp, kernel_ulong_t addr, kernel_ulong_t len)
index eadfe28301fd9d33582aade629e5dbb13aa53de1..0c6e2b7e8d4d4acd72362e7a85ae97003da8958c 100644 (file)
@@ -183,3 +183,26 @@ mmap_cache_invalidate(struct tcb *tcp)
                       mmap_cache_generation,
                       tcp, tcp->mmap_cache);
 }
+
+struct mmap_cache_t *
+mmap_cache_search(struct tcb *tcp, unsigned long ip)
+{
+       int lower = 0;
+       int upper = (int) tcp->mmap_cache_size - 1;
+
+       while (lower <= upper) {
+               struct mmap_cache_t *cur_mmap_cache;
+               int mid = (upper + lower) / 2;
+
+               cur_mmap_cache = &tcp->mmap_cache[mid];
+
+               if (ip >= cur_mmap_cache->start_addr &&
+                   ip < cur_mmap_cache->end_addr)
+                       return cur_mmap_cache;
+               else if (ip < cur_mmap_cache->start_addr)
+                       upper = mid - 1;
+               else
+                       lower = mid + 1;
+       }
+       return NULL;
+}
index 77fb23780cc58dda4d2c94d70ae17a8c2f2ad54a..56a7b9cebe9635b4a6ecca2082eb9bb4dc78258e 100644 (file)
--- a/unwind.c
+++ b/unwind.c
@@ -131,53 +131,40 @@ print_stack_frame(struct tcb *tcp,
                  size_t *symbol_name_size)
 {
        unw_word_t ip;
-       int lower = 0;
-       int upper = (int) tcp->mmap_cache_size - 1;
+       struct mmap_cache_t *cur_mmap_cache;
 
        if (unw_get_reg(cursor, UNW_REG_IP, &ip) < 0) {
                perror_msg("Can't walk the stack of process %d", tcp->pid);
                return -1;
        }
 
-       while (lower <= upper) {
-               struct mmap_cache_t *cur_mmap_cache;
-               int mid = (upper + lower) / 2;
-
-               cur_mmap_cache = &tcp->mmap_cache[mid];
-
-               if (ip >= cur_mmap_cache->start_addr &&
-                   ip < cur_mmap_cache->end_addr) {
-                       unsigned long true_offset;
-                       unw_word_t function_offset;
-
-                       get_symbol_name(cursor, symbol_name, symbol_name_size,
-                                       &function_offset);
-                       true_offset = ip - cur_mmap_cache->start_addr +
-                               cur_mmap_cache->mmap_offset;
+       cur_mmap_cache = mmap_cache_search(tcp, ip);
+       if (cur_mmap_cache) {
+               unsigned long true_offset;
+               unw_word_t function_offset;
 
+               get_symbol_name(cursor, symbol_name, symbol_name_size,
+                               &function_offset);
+               true_offset = ip - cur_mmap_cache->start_addr +
+                       cur_mmap_cache->mmap_offset;
 #ifdef USE_DEMANGLE
-                       char *demangled_name =
-                               cplus_demangle(*symbol_name,
-                                              DMGL_AUTO | DMGL_PARAMS);
+               char *demangled_name =
+                       cplus_demangle(*symbol_name,
+                                      DMGL_AUTO | DMGL_PARAMS);
 #endif
-
-                       call_action(data,
-                                   cur_mmap_cache->binary_filename,
+               call_action(data,
+                           cur_mmap_cache->binary_filename,
 #ifdef USE_DEMANGLE
-                                   demangled_name ? demangled_name :
+                           demangled_name ? demangled_name :
 #endif
-                                   *symbol_name,
-                                   function_offset,
-                                   true_offset);
+                           *symbol_name,
+                           function_offset,
+                           true_offset);
 #ifdef USE_DEMANGLE
-                       free(demangled_name);
+               free(demangled_name);
 #endif
 
-                       return 0;
-               } else if (ip < cur_mmap_cache->start_addr)
-                       upper = mid - 1;
-               else
-                       lower = mid + 1;
+               return 0;
        }
 
        /*