#!/usr/bin/env slsh

private define usage ()
{
   () = fprintf (stdout, "Usage: %s script args...\n", path_basename (__argv[0]));
   () = fprintf (stdout, " -or-: %s --pid pid\n", path_basename (__argv[0]));
   exit (1);
}

if (__argc == 1)
  usage ();

autoload ("sldbsock_attach", "sldbsock.sl");

if (__argv[1] == "--pid")
{
   private variable pid;

   if (__argc != 3)
     usage ();
   if (1 != sscanf (__argv[2], "%d", &pid))
     usage ();
   
   public variable __SLDB_CLIENT__ = 1;
   if (-1 == sldbsock_attach (pid))
     exit (1);
   exit (0);
}

__set_argc_argv (__argv[[1:]]);
$0 = __argv[0];
if (not path_is_absolute ($0))
  $0 = path_concat (getcwd (), $0);
sldb ($0);

#ifexists slsh_main
slsh_main ();
#endif

exit (0);
