From: Anthony Geay Date: Fri, 11 Oct 2024 08:58:03 +0000 (+0200) Subject: [EDF31153] : Attempt to debug inside singularity container X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=2ff93594f4c815f570f1c1456e9d38f4ee6c9f2c;p=modules%2Fkernel.git [EDF31153] : Attempt to debug inside singularity container --- diff --git a/idl/SALOME_PyNode.idl b/idl/SALOME_PyNode.idl index 2953a5142..5f371df41 100644 --- a/idl/SALOME_PyNode.idl +++ b/idl/SALOME_PyNode.idl @@ -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 diff --git a/src/Container/CMakeLists.txt b/src/Container/CMakeLists.txt index 616b4e348..17d8f0556 100644 --- a/src/Container/CMakeLists.txt +++ b/src/Container/CMakeLists.txt @@ -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 index 000000000..44cc05e04 --- /dev/null +++ b/src/Container/SALOME_GlobalsImpl.py @@ -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 index 000000000..2656ef7f3 --- /dev/null +++ b/src/Container/salome_process_attach @@ -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 index 000000000..cc4ca744f --- /dev/null +++ b/src/Container/salome_process_launcher @@ -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 )