[pypy-commit] pypy vmprof-resolve_addr: WIP: expose vmp_resolve_addr in rlib.rvmprof

antocuni pypy.commits at gmail.com
Thu Feb 1 18:32:16 EST 2018


Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: vmprof-resolve_addr
Changeset: r93731:55632ddaa2c1
Date: 2018-02-02 00:22 +0100
http://bitbucket.org/pypy/pypy/changeset/55632ddaa2c1/

Log:	WIP: expose vmp_resolve_addr in rlib.rvmprof

diff --git a/rpython/rlib/rvmprof/__init__.py b/rpython/rlib/rvmprof/__init__.py
--- a/rpython/rlib/rvmprof/__init__.py
+++ b/rpython/rlib/rvmprof/__init__.py
@@ -61,6 +61,9 @@
 def start_sampling():
     return _get_vmprof().start_sampling()
 
+def resolve_addr(addr):
+    return _get_vmprof().resolve_addr(addr)
+
 # ----------------
 # stacklet support
 # ----------------
@@ -80,3 +83,4 @@
 def restore_stack(x):
     vmprof_tl_stack.setraw(x)
     start_sampling()
+
diff --git a/rpython/rlib/rvmprof/cintf.py b/rpython/rlib/rvmprof/cintf.py
--- a/rpython/rlib/rvmprof/cintf.py
+++ b/rpython/rlib/rvmprof/cintf.py
@@ -146,6 +146,11 @@
                                             lltype.Void, compilation_info=eci,
                                             _nowrapper=True)
 
+    vmp_resolve_addr = rffi.llexternal("vmp_resolve_addr",
+                                       [rffi.VOIDP, rffi.CCHARP, rffi.INT,
+                                        rffi.INTP, rffi.CCHARP, rffi.INT],
+                                       rffi.INT, compilation_info=eci)
+
     return CInterface(locals())
 
 
diff --git a/rpython/rlib/rvmprof/rvmprof.py b/rpython/rlib/rvmprof/rvmprof.py
--- a/rpython/rlib/rvmprof/rvmprof.py
+++ b/rpython/rlib/rvmprof/rvmprof.py
@@ -186,6 +186,26 @@
         """
         self.cintf.vmprof_start_sampling()
 
+    def resolve_addr(self, addr):
+        name_len = 128
+        srcfile_len = 256
+        with lltype.scoped_alloc(rffi.CCHARP.TO, name_len) as name_p:
+            with lltype.scoped_alloc(rffi.CCHARP.TO, srcfile_len) as srcfile_p:
+                with lltype.scoped_alloc(rffi.INTP.TO, 1) as lineno_p:
+                    # XXX vmp_resolve_addr checks whether the first char is 0
+                    # before calling dladdr, not sure why. Investigate before
+                    # merging.
+                    name_p[0] = '\0'
+                    srcfile_p[0] = '\0'
+                    res = self.cintf.vmp_resolve_addr(addr, name_p, name_len,
+                                                      lineno_p, srcfile_p, srcfile_len)
+                    if res != 0:
+                        raise ValueError("Cannot resolve name")
+                    #
+                    name = rffi.charp2strn(name_p, name_len)
+                    srcfile = rffi.charp2strn(srcfile_p, srcfile_len)
+                    lineno = lineno_p[0]
+                    return name, lineno, srcfile
 
 def vmprof_execute_code(name, get_code_fn, result_class=None,
                         _hack_update_stack_untranslated=False):
diff --git a/rpython/rlib/rvmprof/src/rvmprof.h b/rpython/rlib/rvmprof/src/rvmprof.h
--- a/rpython/rlib/rvmprof/src/rvmprof.h
+++ b/rpython/rlib/rvmprof/src/rvmprof.h
@@ -41,6 +41,9 @@
 RPY_EXTERN int vmprof_stop_sampling(void);
 RPY_EXTERN void vmprof_start_sampling(void);
 
+RPY_EXTERN int vmp_resolve_addr(void * addr, char * name, int name_len, int * lineno,
+                                char * srcfile, int srcfile_len);
+
 long vmprof_write_header_for_jit_addr(intptr_t *result, long n,
                                       intptr_t addr, int max_depth);
 
diff --git a/rpython/rlib/rvmprof/test/test_rvmprof.py b/rpython/rlib/rvmprof/test/test_rvmprof.py
--- a/rpython/rlib/rvmprof/test/test_rvmprof.py
+++ b/rpython/rlib/rvmprof/test/test_rvmprof.py
@@ -199,3 +199,13 @@
                     del not_found[i]
                     break
         assert not_found == []
+
+
+class TestSymbolTable(object):
+
+    def test_vmp_resolve_addr(self):
+        # XXX: don't hardcode this addr
+        addr = rffi.cast(rffi.VOIDP, 0x517450)
+        name, lineno, srcfile = rvmprof.resolve_addr(addr)
+        assert name == 'PyLong_AsLong'
+


More information about the pypy-commit mailing list