[Lldb-commits] [lldb] r238850 - Added utility function to get correct signal number from remote platform.

Chaoren Lin chaorenl at google.com
Tue Jun 2 09:46:28 PDT 2015


Author: chaoren
Date: Tue Jun  2 11:46:28 2015
New Revision: 238850

URL: http://llvm.org/viewvc/llvm-project?rev=238850&view=rev
Log:
Added utility function to get correct signal number from remote platform.

Summary:
This change adds a utility that uses the `kill -l` command to get the
correct signal number. Falls back to using `SBUnixSignals`, and finally
`signal.SIG<signal>` if all else fails.

Reviewers: tberghammer, clayborg, ovyalov

Reviewed By: clayborg, ovyalov

Subscribers: tberghammer, lldb-commits

Differential Revision: http://reviews.llvm.org/D10171

Modified:
    lldb/trunk/test/lldbutil.py

Modified: lldb/trunk/test/lldbutil.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lldbutil.py?rev=238850&r1=238849&r2=238850&view=diff
==============================================================================
--- lldb/trunk/test/lldbutil.py (original)
+++ lldb/trunk/test/lldbutil.py Tue Jun  2 11:46:28 2015
@@ -922,3 +922,44 @@ def join_remote_paths(*paths):
 
 def append_to_remote_wd(*paths):
     return join_remote_paths(lldb.remote_platform.GetWorkingDirectory(), *paths)
+
+# ==================================================
+# Utility functions to get the correct signal number
+# ==================================================
+
+import signal
+
+def get_signal_number(signal_name):
+    platform = lldb.remote_platform
+    if platform:
+        if platform.GetName() == 'remote-linux':
+            command = lldb.SBPlatformShellCommand('kill -l %d' % signal_name)
+            if platform.Run(command).Success() and command.GetStatus() == 0:
+                try:
+                    return int(command.GetOutput())
+                except ValueError:
+                    pass
+        elif platform.GetName() == 'remote-android':
+            for signal_number in range(1, 65):
+                command = lldb.SBPlatformShellCommand('kill -l %d' % signal_number)
+                if platform.Run(command).Fail() or command.GetStatus() != 0:
+                    continue
+                output = command.GetOutput().strip().upper()
+                if not output.startswith('SIG'):
+                    output = 'SIG' + output
+                if output == signal_name:
+                    return signal_number
+    for target_index in range(lldb.debugger.GetNumTargets()):
+        target = lldb.debugger.GetTargetAtIndex(target_index)
+        if not target.IsValid():
+            continue
+        process = target.GetProcess()
+        if not process.IsValid():
+            continue
+        signals = process.GetUnixSignals()
+        if not signals.IsValid():
+            continue
+        signal_number = signals.GetSignalNumberFromName(signal_name)
+        if signal_number > 0:
+            return signal_number
+    return getattr(signal, signal_name)





More information about the lldb-commits mailing list