]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
[EDF31153] : add --pid optionnal parameter to salome_process_attach
authorAnthony Geay <anthony.geay@edf.fr>
Thu, 7 Nov 2024 12:59:19 +0000 (13:59 +0100)
committerAnthony Geay <anthony.geay@edf.fr>
Thu, 7 Nov 2024 12:59:19 +0000 (13:59 +0100)
src/Container/salome_process_attach
src/Container/salome_process_launcher
src/KernelHelpers/KernelServices.cxx
src/KernelHelpers/KernelServices.hxx
src/KernelHelpers/KernelServices.i

index 2656ef7f3db30170dbd3e5a2c96bfd6359efea63..7a2ff89b431d5ff27752dc37fea6232962e3fadd 100644 (file)
 # -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]
+from pathlib import Path
 
-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)
+def main():
+  DFT_PID_VALUE = -1
+
+  import argparse
+  from pathlib import Path
+  import salome
+  salome.salome_init()
+  parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter, description = "To be used in association of a process launched nested inside a salome_process_launcher session.")
+  parser.add_argument("rendez_vous_file", type=Path, help="Rendez vous file specified in corresponding salome_process_launcher.")
+  parser.add_argument("gdb_cmds_file", type=Path, help="GDB commands to be executed remotely.")
+  parser.add_argument("--pid", dest="pid_to_track", type=int, default=DFT_PID_VALUE, help="PID of process, the debugger will be attached on ( typically a son or a little son process of process whose PID is registred inside salome_process_launcher process)")
+  args = parser.parse_args()
+  rdv, gdbfile = args.rendez_vous_file, args.gdb_cmds_file
+  if not rdv.exists():
+    raise RuntimeError(f"Rendez-vous file {rdv} does not exist !")
+  gdbfile = gdbfile.absolute()
+  if not gdbfile.exists():
+    raise RuntimeError(f"GDB commands file {gdbfile} does not exist !")
+  gdbfile = gdbfile.absolute()
+  remoteNS = salome.naming_service.LoadIORInFile(f"{rdv}")
+  remoteGlbs = salome.orb.string_to_object( remoteNS.Resolve("PID_TO_TRACK").decode() )
+  import pickle
+  pidToTrack = pickle.loads( remoteGlbs.getAttr("CTX0") )["pid"]
+  if args.pid_to_track != DFT_PID_VALUE:
+    pidToTrack = args.pid_to_track
+  print(f"PID tracked : {pidToTrack}")
+  returncode, stdout, stderr = remoteGlbs.execute(["gdb","-batch","-x",f"{gdbfile}","attach",str(pidToTrack)])
+  st = f"""returnCode = {returncode}
+  stdout = {stdout.decode()}
+  stderr = {stderr.decode()}
+  """
+  print(st)
+
+if __name__ == "__main__":
+  main()
index cc4ca744f575a828697b8df3af6c36ae6e21eefb..ab485ac20d7c5c3468d66947e9319c62870eba21 100644 (file)
@@ -31,28 +31,32 @@ 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 )
+def main():
+  from pathlib import Path
+  import argparse
+  parser = argparse.ArgumentParser(description = "Process launcher hosting a servant that can execute system command in the same context than command launched.")
+  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 )
+  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 )
+
+if __name__ == "__main__":
+  main()
index 889d067608be71b47521e059d21f437f4347e331..e91e815a268fd349ed21739d50f2e8cb9fbc4d87 100644 (file)
 #include "SALOME_KernelServices.hxx"
 
 #include <iostream>
+#include <mutex>
+#include <thread>
+
+static std::mutex global_mut;
 
 void RegisterCompoInternal(const std::string& compoName, const std::string& compoIOR)
 {
@@ -45,10 +49,27 @@ void GenerateViolentMemoryFaultForTestPurpose()
     *a = 0;
 }
 
+void goForLock()
+{
+    std::cout << "Start thread" << std::endl;
+    std::cout << "going to deadlock" << std::endl;
+    global_mut.lock();
+}
+
 /*!
  * This method wrapped into Python is useful to have a break point in C++ when complex python script is invoked in the stack
  */
 void EntryForDebuggerBreakPoint()
 {
-    std::cout << "b KernelServices.cxx:53" << std::endl;
+    std::cout << "b KernelServices.cxx:64" << std::endl;
+}
+
+/*!
+ * This method leads to a deadlock to test robustness of higher level layers.
+ */
+void GenerateDeadLockForTestPurpose()
+{
+    global_mut.lock();
+    std::thread t1(goForLock);
+    t1.join();
 }
index 17bb5ed463d3f9657f1349e71ce2e79b11612f24..311a309ca336a316a111dd111ddb32bf8e8dcf37 100644 (file)
 //
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
-#ifndef __KERNELSERVICES_HXX__
-#define __KERNELSERVICES_HXX__
+
+#pragma once
 
 #include <string>
 
 void RegisterCompoInternal(const std::string& compoName, const std::string& compoIOR);
 std::string RetrieveCompoInternal(const std::string& compoName);
 void GenerateViolentMemoryFaultForTestPurpose();
+void GenerateDeadLockForTestPurpose();
 void EntryForDebuggerBreakPoint();
-
-#endif
index 392adec9bd48358dabde34f347f9b794da4e2e9e..4d4d8f3c4f9b7244c61658a8b78be0a036290aab 100644 (file)
@@ -59,6 +59,7 @@ public:
     void RegisterCompoInternal(const std::string& compoName, const std::string& compoIOR);
     std::string RetrieveCompoInternal(const std::string& compoName);
     void GenerateViolentMemoryFaultForTestPurpose();
+    void GenerateDeadLockForTestPurpose();
     void EntryForDebuggerBreakPoint();
 }