]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
[EDF31153] : Attempt to debug inside singularity container
authorAnthony Geay <anthony.geay@edf.fr>
Fri, 11 Oct 2024 08:58:03 +0000 (10:58 +0200)
committerAnthony Geay <anthony.geay@edf.fr>
Fri, 11 Oct 2024 10:05:49 +0000 (12:05 +0200)
idl/SALOME_PyNode.idl
src/Container/CMakeLists.txt
src/Container/SALOME_GlobalsImpl.py [new file with mode: 0644]
src/Container/salome_process_attach [new file with mode: 0644]
src/Container/salome_process_launcher [new file with mode: 0644]

index 2953a51427e10afbaa723236e5fb20489a95d60c..5f371df413718251a83694fc5e5074466c513c1c 100644 (file)
@@ -71,7 +71,7 @@ module Engines
     */
     pickledArgs execute(in string functionName, in pickledArgs inargs) raises (SALOME::SALOME_Exception);
 
-  } ;
+  };
 
   interface PyScriptNode : PyNodeBase
   {
@@ -118,6 +118,15 @@ module Engines
     void finishPushContext() raises (SALOME::SALOME_Exception);
   };
 
+  interface GlobalsHolder
+  {
+  /*!
+  Simply a key / val holder.
+  */
+    void setAttr(in string ctx, in pickledArgs glbsAttachedToCtx) raises (SALOME::SALOME_Exception);
+    pickledArgs getAttr(in string ctx) raises (SALOME::SALOME_Exception);
+    void execute(in listofstring args, out long returncode, out pickledArgs stdout, out pickledArgs stderr) raises (SALOME::SALOME_Exception);
+  };
 };
 
 #endif
index 616b4e348bc092f210dbe1f60cbcdc174f713af4..17d8f05564a2fc69f76baa5ff1870d8a42b11ef3 100644 (file)
@@ -47,6 +47,7 @@ SET(SCRIPTS
   SALOME_Container.py
   SALOME_ContainerHelper.py
   SALOME_ContainerPy.py
+  SALOME_GlobalsImpl.py
 )
 
 ADD_DEFINITIONS(${HDF5_DEFINITIONS} ${OMNIORB_DEFINITIONS})
@@ -161,4 +162,5 @@ install(TARGETS _KernelContainer DESTINATION ${SALOME_INSTALL_LIBS})
 install(FILES ${KernelContainer_HEADERS} DESTINATION ${SALOME_INSTALL_HEADERS})
 SALOME_INSTALL_SCRIPTS("${_swig_SCRIPTS}"  ${SALOME_INSTALL_BINS} EXTRA_DPYS "${SWIG_MODULE_KernelContainer_REAL_NAME}")
 
-INSTALL(DIRECTORY ScriptsTemplate DESTINATION ${SALOME_KERNEL_INSTALL_RES_DATA})
\ No newline at end of file
+INSTALL(DIRECTORY ScriptsTemplate DESTINATION ${SALOME_KERNEL_INSTALL_RES_DATA})
+INSTALL(FILES salome_process_launcher salome_process_attach PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ DESTINATION ${SALOME_INSTALL_BINS} )
diff --git a/src/Container/SALOME_GlobalsImpl.py b/src/Container/SALOME_GlobalsImpl.py
new file mode 100644 (file)
index 0000000..44cc05e
--- /dev/null
@@ -0,0 +1,38 @@
+# -*- coding: utf-8 -*-
+# Copyright (C) 2024  CEA, EDF
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library 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
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+#
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+#
+
+import Engines__POA
+
+class SALOME_GlobalsImpl(Engines__POA.GlobalsHolder):
+  def __init__(self):
+    self._map = {}
+  
+  def setAttr(self, ctx, glbsAttachedToCtx):
+    self._map[ctx] = glbsAttachedToCtx
+
+  def getAttr(self, ctx):
+    return self._map[ctx]
+  
+  def execute(self, args):
+    import subprocess as sp
+    proc = sp.Popen(args,stdout = sp.PIPE, stderr = sp.PIPE)
+    stdout, stderr = proc.communicate()
+    returncode = proc.returncode
+    return returncode, stdout, stderr
diff --git a/src/Container/salome_process_attach b/src/Container/salome_process_attach
new file mode 100644 (file)
index 0000000..2656ef7
--- /dev/null
@@ -0,0 +1,44 @@
+#! /usr/bin/env python3
+# -*- coding: utf-8 -*-
+# Copyright (C) 2024  CEA, EDF
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library 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
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+#
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+#
+
+# -ex bt
+# -x script.gdb
+# -nx to skip .gdbinit
+
+def GetRendezVous():
+  import sys
+  if len( sys.argv ) != 3:
+      raise RuntimeError("salome_process_attach have to take a rendez-vous file and gdb script")
+  return sys.argv[1],sys.argv[2]
+
+import salome
+salome.salome_init()
+rdv,gdbfile = GetRendezVous()
+remoteNS = salome.naming_service.LoadIORInFile(rdv)
+remoteGlbs = salome.orb.string_to_object( remoteNS.Resolve("PID_TO_TRACK").decode() )
+import pickle
+pidToTrack = pickle.loads( remoteGlbs.getAttr("CTX0") )["pid"]
+returncode, stdout, stderr = remoteGlbs.execute(["gdb","-batch","-x",gdbfile,"attach",str(pidToTrack)])
+st = f"""returnCode = {returncode}
+stdout = {stdout.decode()}
+stderr = {stderr.decode()}
+"""
+print(st)
diff --git a/src/Container/salome_process_launcher b/src/Container/salome_process_launcher
new file mode 100644 (file)
index 0000000..cc4ca74
--- /dev/null
@@ -0,0 +1,58 @@
+#! /usr/bin/env python3
+# -*- coding: utf-8 -*-
+# Copyright (C) 2024  CEA, EDF
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library 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
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+#
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+#
+
+import signal
+import salome
+import sys
+import os
+
+salome.salome_init()
+
+proc = None
+
+def handler(signum, frame):
+  os.kill( proc.pid, signal.SIGKILL )
+
+from pathlib import Path
+import argparse
+parser = argparse.ArgumentParser()
+parser.add_argument("-rdv","--rendz-vous",dest = "rdv", type=Path, help="Mandatory filename used as a rendez-vous file",required=True)
+parser.add_argument('rest', nargs=argparse.REMAINDER, help="Process to be launched. Attachable using salome_process_attach")
+args = parser.parse_args()
+if args.rest[0] != "--":
+    raise RuntimeError("You have to preappend -- before commande to be launched")
+args.rest = args.rest[1:]
+salome.naming_service.DumpIORInFile( args.rdv )
+
+signal.signal(signal.SIGINT, handler)
+signal.signal(signal.SIGTERM, handler)
+import subprocess as sp
+proc = sp.Popen(args.rest ,cwd = os.getcwd())
+from SALOME_GlobalsImpl import SALOME_GlobalsImpl
+glbs = SALOME_GlobalsImpl()
+import pickle
+glbs.setAttr("CTX0",pickle.dumps({"pid":proc.pid}))
+poa = salome.orb.resolve_initial_references("RootPOA")
+id_o = poa.activate_object(glbs)
+refPtr = poa.id_to_reference(id_o)
+salome.naming_service.Register(refPtr,"PID_TO_TRACK")
+proc.communicate()
+sys.exit( proc.returncode )