about summary refs log tree commit diff stats
path: root/miasm2/core/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'miasm2/core/utils.py')
-rw-r--r--miasm2/core/utils.py16
1 files changed, 13 insertions, 3 deletions
diff --git a/miasm2/core/utils.py b/miasm2/core/utils.py
index 70520c1b..0512f4aa 100644
--- a/miasm2/core/utils.py
+++ b/miasm2/core/utils.py
@@ -17,6 +17,19 @@ pck = {8:pck8,
        16:pck16,
        32:pck32,
        64:pck64}
+def get_caller_name(caller_num=0):
+    """Get the nth caller's name
+    @caller_num: 0 = the caller of get_caller_name, 1 = next parent, ..."""
+    pystk = inspect.stack()
+    if len(pystk) > 1 + caller_num:
+        return pystk[1 + caller_num][3]
+    else:
+        return "Bad caller num"
+
+
+def whoami():
+    """Returns the caller's name"""
+    return get_caller_name(1)
 
 
 class Disasm_Exception(Exception):
@@ -48,9 +61,6 @@ class keydefaultdict(collections.defaultdict):
         value = self[key] = self.default_factory(key)
         return value
 
-def whoami():
-    return inspect.stack()[2][3]
-
 
 class BoundedDict(UserDict.DictMixin):
     """Limited in size dictionary.